sap web gui login

http://molgaard.consolut.eu/sap/bc/gui/sap/its/webgui

INTERNAL TABLES



05 internal tables from Brahmaiah Punati



Ex on Internal Table operations
APPEND:
1. This statement is used to append a single record from work area to
Internal Table.
2. The record is always added at the bottom.
SYNTAX:
Append <wa> to <ITAB>.

Ex on APPEND
 Wa_kna1-kunnr = ‘0000001011’.
 Wa_kna1-land1 = ‘US’.
 Wa_kna1-name1 = ‘AAA’.
 Wa_kna1-ort01 = ‘NEWYORK’.
 Append wa_kna1 to i_kna1.
 LOOP AT i_kna1 INTO wa_kna1. WRITE: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01. ENDLOOP.
 Save->Act->test

INSERT:
 This statement is used to INSERT a single record From work area to Internal Table at a specified location.
SYNTAX:
Insert <wa> INTO <ITAB> index <index number>.
Ex on INSERT
 Wa_kna1-kunnr = ‘0000001022’.
 Wa_kna1-land1 = ‘US’.
 Wa_kna1-name1 = ‘BBB’.

 Wa_kna1-ort01 = ‘NEWYORK’.
 Insert wa_kna1 into i_kna1 index 5.
 LOOP AT i_kna1 INTO wa_kna1. WRITE: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01. ENDLOOP.
 Save->Act->test

SORT:
 This statement is used to sort the Internal Table data either in
 ascending order or descending order.
 By default it will sort in ascending order .
 By default it sorts based on field1,field2 , field3…...etc.
Ex on SORT
 *sort i_kna1 by kunnr.
 *sort i_kna1 by land1 descending.
 Sort i_kna1.
 LOOP AT i_kna1 INTO wa_kna1. WRITE: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01. ENDLOOP.
 Save->Act->test

DESCRIBE TABLE:
1. This statement is used to find the total number of records in an Internal
Table.
SYNTAX:
Describe table <ITAB> lines <variable name>.
Ex on Describe table:
 Data v_lines type I.
 Describe table i_kna1 lines v_lines.
 Write: / ‘total customers are:’, v_lines color 1.
 Save->Act->test
Read Table:
1. This statement is used to read a record from Internal Table into work
area specified by either index number or key.
Syntaxes:
Read table with index:
Read table <ITAB> into <wa> index <index number>.
Read table with key:
Read table <ITAB> into <wa> with key <fname1> = <fval>
<fname2> = <fval>
.
.
.
Binary Search.


Read table with index:
 Read table i_kna1 into wa_kna1 index 5.
 WRITE: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01.
 Save->Act->test
Read table with KEY:
 Read table i_kna1 into wa_kna1 with key kunnr = ‘0000001011’
 binary search.
 WRITE: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01.
 Save->Act->test
MODIFY:
1. This statement is used to MODIFY the Internal Table records based on
Condition (or) from work area.
SYNTAX:
Modify <ITAB> from <wa> index sy-tabix transporting F1 F2….etc.
SY-TABIX (System ITAB Index):
It is a system variable which stores the index number of the internal table records which is currently being processed in work area.
TRANSPORTING:
It specifies the list of the fields to be modified from work area to internal table.

Ex to Modify LAND1 from US to USA:
 Sort i_kna1 by kunnr.
 Read table i_kna1 into wa_kna1 with key kunnr = ‘0000001011’ binary search.
 Wa_kna1-land1 = ‘USA’.
 Modify i_kna1 from wa_kna1 index sy-tabix transporting land1.
 LOOP AT i_kna1 INTO wa_kna1. WRITE: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01. ENDLOOP.
 Save->Act->test
 Ex2: (modifying All or multiple records from US to USA)
 Wa_kna1-land1 = ‘USA’.
 Modify i_kna1 from wa_kna1 transporting land1
 where land1 = ‘US’.
 LOOP AT i_kna1 INTO wa_kna1. WRITE: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01. ENDLOOP.
 Save->Act->test

DELETE:
1. This statement is used to DELETE a single record or multiple records
based on Condition.
SYNTAX:
Delete <ITAB> index <N>.
Delete <ITAB> where <condition>.

 Ex on Delete:
 Ex1: (deleting single record)
 Delete i_kna1 index 5.
 Loop …. Endloop.
 Save->Act->test
 Ex2: (deleting single record)
 Delete i_kna1 where kunnr = ‘0000001011’.
 Loop…. Endloop.
 Save->Act->test
 Ex3: (deleting multiple records)
 Delete i_kna1 where land1 = ‘USA’
 Loop…. Endloop
 Save->Act->test

DELETE ADJACENT DUPLICATES:
1. This statement is used to DELETE the Duplicate records which are
adjacent or side by side to each other.
2. The prerequisite for this statement is, the ITAB should be sorted in
ascending order.
SYNTAX:
Delete adjacent duplicates from <ITAB> comparing F1 F2 F3…………
Delete adjacent duplicates from <ITAB> comparing all fields.

 Ex on Delete adjacent duplicates:
 Wa_kna1-kunnr = ‘0000001033’.
 Wa_kna1-land1 = ‘US’.
 Wa_kna1-name1 = ‘CCC’.
 Wa_kna1-ort01 = ‘NEWYORK’.
 Insert wa_kna1 into i_kna1 index 5.
 Insert wa_kna1 into i_kna1 index 8.
 Insert wa_kna1 into i_kna1 index 3.
 Sort i_kna1 by kunnr.
 Delete adjacent duplicates from i_kna1 comparing all fields.
 LOOP AT i_kna1 INTO wa_kna1. WRITE: / wa_kna1-kunnr, wa_kna1-name1,

wa_kna1-land1, wa_kna1-ort01. ENDLOOP.
 Save->Act->test
CLEAR:
1. This statement is used to CLEAR or Delete the data from work area.
2. In older version this clear statement was used to delete the data
from ITAB also.
SYNTAX:
Clear <wa>.
Clear <ITAB>[ ]---- IN older version.

 Ex on Clear:
 Wa_kna1-kunnr = ‘0000001044’.
 Wa_kna1-land1 = ‘US’.
 Wa_kna1-name1 = ‘ARJUN4’.
 Wa_kna1-ort01 = ‘NEWYORK’.
 Append wa_kna1 to i_kna1.
 Clear wa_kna1.
REFRESH:
1. This statement is used to DELETE the ITAB records.
SYNTAX:
Refresh <ITAB>.

 Ex on Refresh:
 Refresh i_kna1 .
 LOOP AT i_kna1 INTO wa_kna1. WRITE: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01. ENDLOOP.
 Save->Act->test
FREE:
1. This statement is used to DELETE the Data from work area and ITAB.
2. It is same as clear and refresh.
3. The difference is, the free statement delete the data as well as memory
Occupied by ITAB or work area, where as clear and refresh will delete
Only the data not the memory.
SYNTAX:
Free <wa/ITAB>.

 Ex on FREE:
 FREE i_kna1 .
 LOOP AT i_kna1 INTO wa_kna1. WRITE: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01. ENDLOOP.
 Save->Act->test

APPEND LINES OF:
1. This statement is used to APPEND Multiple records one internal
table to another internal table.
SYNTAX:
Append lines of ITAB1 to ITAB2.
Append lines of ITAB1 from 3 to 7 to ITAB2.
 Ex on Append lines of
 Data: i_kna1 type table of ty_kna1.
 Data: i_kna1_tmp type table of ty_kna1.
 Data: wa_kna1 type ty_kna1.
 Select kunnr name1 land1
 From kna1 into table i_kna1 Up to 10 rows.
 Append lines of i_kna1 from 3 to 5 to i_kna1_tmp.
 Loop at i_kna1_tmp into wa_kna1.
 WRITE: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01. ENDLOOP.
 Save->Act->test

INSERT LINES OF:
1. This statement is used to INSERT Multiple records one internal
table to another internal table at a specified location.
SYNTAX:
Insert lines of ITAB1 to ITAB2 index <N>.
Insert lines of ITAB1 from 3 to 7 to ITAB2.
 Ex on INSERT lines of
 Insert lines of i_kna1 from 6 to 8 into i_kna1_tmp index 2.
 Loop at i_kna1_tmp into wa_kna1.
 WRITE: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01. ENDLOOP.
 Save->Act->test
MOVE ITAB1 TO ITAB2:
1. This statement is used to move entire internal table records from
one ITAB to another.
SYNTAX:
Move ITAB1 to ITAB2.
ABAP @ ARJUN, Igrow Soft
 Ex on Move itab1 to itab2:
 Refresh i_kna1_tmp.
 I_kna1_tmp [ ] = i_kna1 [ ].
 Loop at i_kna1_tmp into wa_kna1.
 WRITE: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01. ENDLOOP.
 (Or)
 Loop at i_kna1 into wa_kna1.
 Append wa_kna1 to i_kna1_tmp.
 Endloop.
 Loop at i_kna1_tmp into wa_kna1.
 WRITE: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01. ENDLOOP.  What is the output of program?  Loop at i_kna1 into wa_kna1.  Write: / wa_kna1-kunnr,  wa_kna1-name1,  wa_kna1-land1.  Append wa_kna1 to i_kna1.

 Endloop.
COLLECT:
1. This statement checks whether the wa record already exists in the
internal table with the same key.
If YES, it will just add the numerical fields.
If NO, A new record is appended.
SYNTAX:
Collect <wa> into <ITAB>.
NOTE:
KEY means character fields: C,N,D,T.
Numerical fields: I,P,F.

 Ex on COLLECT
 Types: begin of ty_kna1,
 Kunnr type kna1-kunnr,
 Name1 type kna1-name1,
 Amount type I,
 End of ty_kna1.
 Data: i_kna1 type table of ty_kna1.
 Data: wa_kna1 type ty_kna1.

 Wa_kna1-kunnr = ‘1011’.
 Wa_kna1-name1 = ‘reliance’.
 Wa_kna1-amount = ‘100’.
 Collect wa_kna1 into i_kna1.

 Wa_kna1-kunnr = ‘1022’.
 Wa_kna1-name1 = ‘hero motor corp’.
 Wa_kna1-amount = ‘200’.
 Collect wa_kna1 into i_kna1.
 Wa_kna1-kunnr = ‘1011’.

 Wa_kna1-name1 = ‘reliance’.
 Wa_kna1-amount = ‘50’.
 Collect wa_kna1 into i_kna1.
 Loop at i_kna1 into wa_kna1.
Write: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-amount.
Endloop.


Ex on JOINS with 2 Tables
 TYPES : BEGIN OF ty_mara_makt,
               matnr TYPE mara-matnr,
               mtart TYPE mara-mtart,
               mbrsh TYPE mara-mbrsh,
               meins TYPE mara-meins,
               spras TYPE makt-spras,
               maktx TYPE makt-maktx,
               END OF ty_mara_makt.
DATA : i_mara_makt TYPE TABLE OF ty_mara_makt .
DATA : wa_mara_makt TYPE ty_mara_makt .

SELECT mara~matnr mara~mtart mara~mbrsh mara~meins makt~spras makt~maktx INTO TABLE i_mara_makt FROM mara AS mara INNER JOIN makt AS makt
 ON mara~matnr = makt~matnr WHERE mara~mtart = 'FERT' AND makt~spras = 'EN' .


 LOOP AT i_mara_makt INTO wa_mara_makt.
 WRITE : / wa_mara_makt-matnr , wa_mara_makt-mtart COLOR 6, wa_mara_makt-mbrsh , wa_mara_makt-meins , wa_mara_makt-spras COLOR 1, wa_mara_makt-maktx COLOR 1 .
 ENDLOOP.
 The output is :


 Ex on JOINS with 3 Tables

 The output is :

Ex on Select……For All Entries Develop a material master report to display material details along with description details

Save->Act->Test.

Second way: As per performance, this is a good stmt B’coz we are using Binary Search.
Save->Act->Test. Third Way: In Real Time, we always move the data into Final Int.Table
Save->Act->Test.


 Ex on selection-screen commands:
 Selection-screen begin of block b1 with frame title text-001.
   Select-options: s_kunnr for kna1-kunnr.
   Selection-screen uline.
   Parameters: p_land1 type kna1-land1.
   Selection-screen skip.
   Parameters: p_matnr type mara-matnr.
Selection-screen end of block b1.

 Selection-screen begin of block b2 with frame title text-002.
  Selection-screen begin of line.
  Selection-screen comment 2(15) text-003.
  Parameters: p_lifnr type lfa1-lifnr.
  Selection-screen comment 30(10) text-004.
  Parameters: p_land2 type lfa1-land1.
  Selection-screen end of line.
Selection-screen end of block b2.

Ex on INCLUDE program :
Include z_modularization_top.
Selection-screen begin of block b1 with frame title text-001.
 Select-options: s_kunnr for kna1-kunnr.
 Parameters: p_land1 type kna1-land1.
Selection-screen end of block b1.
Include zmodularization_getdata.
Include zmodularization_dispdata.
Tables kna1
Data: i_mara type table of mara Data: wa_mara type mara.
Select * from mara Into table i_mara
Where kunnr in s_kunnr and
land1 = p_land1
Loop at I_KNA1 INTO WA_KNA1 .
WRITE : / wa_kna1-kunner.
ENDLOOP .

0 comments:

Post a Comment