**Creation of a standard internal table , filling the values and displaying the values**
types : begin of tab,
name type char10,
address type char10,
state type char10,
country type char10,
mark type i,
end of tab.
data : it_tab type table of tab,
wa_tab like line of it_tab. " wa_tab type tab.
wa_tab-name = 'rahul'.
wa_tab-address = 'kr puram'.
wa_tab-state = 'karnataka'.
wa_tab-country = 'india'.
wa_tab-mark = '20'.
append wa_tab to it_tab.
clear wa_tab.
wa_tab-name = 'ashok'.
wa_tab-address = 'marathali'.
wa_tab-state = 'karnataka'.
wa_tab-country ='india'.
wa_tab-mark = '40'.
append wa_tab to it_tab.
clear wa_tab.
wa_tab-name = 'sidharth'.
wa_tab-address = 'j p nagar'.
wa_tab-state = 'karnataka'.
wa_tab-country = 'ind'.
wa_tab-mark = '47'.
append wa_tab to it_tab.
clear wa_tab.
wa_tab-name = 'arun s'.
wa_tab-address = 'jaynagar'.
wa_tab-state = 'delhi'.
wa_tab-country = 'ind'.
wa_tab-mark = '34'.
collect wa_tab into it_tab.
clear wa_tab.
loop at it_tab into wa_tab.
write :/1 wa_tab-name,
15 wa_tab-address,
30 wa_tab-state,
50 wa_tab-country,
70 wa_tab-mark.
endloop.
******Creation of a standard internal table with non unique key , filling the values and displaying it in different ways***
types : begin of tab,
name type char10,
address type char10,
state type char10,
country type char10,
mark type i,
end of tab.
data : it_tab type standard table of tab with non-unique key name address, " standard table
wa_tab like line of it_tab.
wa_tab-name = 'ajay'.
wa_tab-address = 'krpuram'.
wa_tab-state = 'delhi'.
wa_tab-country = 'india'.
wa_tab-mark = '20'.
append wa_tab to it_tab.
clear wa_tab.
wa_tab-name = 'chaitu'.
wa_tab-address = 'ctct'.
wa_tab-state = 'ap'.
wa_tab-country = 'ind'.
wa_tab-mark = '47'.
append wa_tab to it_tab.
clear wa_tab.
wa_tab-name = 'bijay'.
wa_tab-address = 'ctct'.
wa_tab-state = 'bihar'.
wa_tab-country ='india'.
wa_tab-mark = '40'.
append wa_tab to it_tab.
clear wa_tab.
wa_tab-name = 'ajay'.
wa_tab-address = 'krpuram'.
wa_tab-state = 'delhi'.
wa_tab-country = 'india'.
wa_tab-mark = '20'.
append wa_tab to it_tab.
clear wa_tab.
loop at it_tab into wa_tab.
write :/1 wa_tab-name,
15 wa_tab-address,
30 wa_tab-state,
50 wa_tab-country,
70 wa_tab-mark.
endloop.
uline.
read table it_tab into wa_tab index 2. " index access
write :/1 wa_tab-name,
15 wa_tab-address,
30 wa_tab-state,
50 wa_tab-country,
70 wa_tab-mark.
uline.
read table it_tab into wa_tab with key name = 'bijay'.
write :/1 wa_tab-name,
15 wa_tab-address,
30 wa_tab-state,
50 wa_tab-country,
70 wa_tab-mark.
uline.
sort it_tab ascending by name. " sort it_tab by name.
loop at it_tab into wa_tab.
write :/1 wa_tab-name,
15 wa_tab-address,
30 wa_tab-state,
50 wa_tab-country,
70 wa_tab-mark.
endloop.
uline.
sort it_tab descending by name.
loop at it_tab into wa_tab.
write :/1 wa_tab-name,
15 wa_tab-address,
30 wa_tab-state,
50 wa_tab-country,
70 wa_tab-mark.
endloop.
****Creation of a standard internal table , filling the values , displaying the values , refreshing it and again displaying the values***
types : begin of tab,
name(10),
address(10),
age type i,
end of tab.
data : it_tab type table of tab,
wa_tab type tab.
wa_tab-name = 'venkat'.
wa_tab-address = 'bangalore'.
wa_tab-age = '67'.
write :/ wa_tab-name, 20 wa_tab-address, 40 wa_tab-age.
append wa_tab to it_tab.
clear wa_tab. " clears the work area
write :/ wa_tab-name, 20 wa_tab-address, 40 wa_tab-age.
uline.
loop at it_tab into wa_tab.
write :/ wa_tab-name, 20 wa_tab-address, 40 wa_tab-age.
endloop.
uline.
refresh it_tab. " clears it_tab
loop at it_tab into wa_tab.
write :/ 'no output'.
write :/ wa_tab-name, 20 wa_tab-address, 40 wa_tab-age.
endloop.
**Creation of a sorted internal table , filling the values and displaying the values**
types : begin of tab,
name type char10,
address type char10,
state type char10,
country type char10,
mark type i,
end of tab.
data : it_tab type sorted table of tab with unique key name , " sorted internal table
wa_tab like line of it_tab.
wa_tab-name = 'ajay'.
wa_tab-address = 'krpuram'.
wa_tab-state = 'delhi'.
wa_tab-country = 'india'.
wa_tab-mark = '20'.
insert wa_tab into it_tab index 1.
clear wa_tab.
wa_tab-name = 'bijay'.
wa_tab-address = 'ctct'.
wa_tab-state = 'bihar'.
wa_tab-country ='india'.
wa_tab-mark = '40'.
insert wa_tab into it_tab index 2.
clear wa_tab.
wa_tab-name = 'chaitu'.
wa_tab-address = 'ctct'.
wa_tab-state = 'ap'.
wa_tab-country = 'ind'.
wa_tab-mark = '47'.
insert wa_tab into it_tab index 3.
clear wa_tab.
wa_tab-name = 'joy'.
wa_tab-address = 't nagar'.
wa_tab-state = 'andra p'.
wa_tab-country = 'india'.
wa_tab-mark = '20'.
insert wa_tab into it_tab index 4 .
clear wa_tab.
loop at it_tab into wa_tab.
write :/1 wa_tab-name,
15 wa_tab-address,
30 wa_tab-state,
50 wa_tab-country,
70 wa_tab-mark.
endloop.
uline.
read table it_tab into wa_tab index 3. " index access
write :/1 wa_tab-name,
15 wa_tab-address,
30 wa_tab-state,
50 wa_tab-country,
70 wa_tab-mark.
uline.
read table it_tab into wa_tab with key name = 'bijay'.
write :/1 wa_tab-name,
15 wa_tab-address,
30 wa_tab-state,
50 wa_tab-country,
70 wa_tab-mark.
**Creation of a hashed internal table , filling the values and displaying the values**
types : begin of tab,
name type char10,
address type char10,
state type char10,
country type char10,
mark type i,
end of tab.
data : it_tab type hashed table of tab with unique key name,
wa_tab like line of it_tab.
wa_tab-name = 'ajay'.
wa_tab-address = 'krpuram'.
wa_tab-state = 'delhi'.
wa_tab-country = 'india'.
wa_tab-mark = '20'.
insert wa_tab into table it_tab .
clear wa_tab.
wa_tab-name = 'bijay'.
wa_tab-address = 'ctct'.
wa_tab-state = 'bihar'.
wa_tab-country ='india'.
wa_tab-mark = '40'.
insert wa_tab into table it_tab .
clear wa_tab.
wa_tab-name = 'chaitu'.
wa_tab-address = 'guntur'.
wa_tab-state = 'ap'.
wa_tab-country = 'ind'.
wa_tab-mark = '47'.
insert wa_tab into table it_tab .
clear wa_tab.
wa_tab-name = 'karthik'.
wa_tab-address = 'mumbai'.
wa_tab-state = 'maharastr'.
wa_tab-country = 'india'.
wa_tab-mark = '20'.
insert wa_tab into table it_tab .
clear wa_tab.
loop at it_tab into wa_tab.
write :/1 wa_tab-name,
15 wa_tab-address,
30 wa_tab-state,
50 wa_tab-country,
70 wa_tab-mark.
endloop.
uline.
read table it_tab into wa_tab with key name = 'bijay'.
write :/1 wa_tab-name,
15 wa_tab-address,
30 wa_tab-state,
50 wa_tab-country,
70 wa_tab-mark.
***Creation of a nested internal table , filling the values and displaying the values***
types : begin of tab1,
title(5) type c,
f_name(10),
l_name(10),
end of tab1.
types : begin of tab2,
person type tab1,
address(20),
end of tab2.
data : it_tab type table of tab2,
wa_tab type tab2.
wa_tab-person-title = 'Mr.'.
wa_tab-person-f_name = 'rohit'.
wa_tab-person-l_name = 'sharma'.
wa_tab-address = 'bangalore'.
append wa_tab to it_tab.
loop at it_tab into wa_tab.
write :/ wa_tab-person-title,
wa_tab-person-f_name,
wa_tab-person-l_name,
wa_tab-address.
endloop.
*******Internal Table Comparision******
data : begin of line,
col1 type i,
col2 type i,
end of line.
data : itab1 like table of line.
data : itab2 like table of line.
do 3 times.
line-col1 = sy-index.
line-col1 = sy-index ** 2.
append line to itab1.
enddo .
itab2 = itab1.
if itab1 eq itab2.
write :/ 'itab1 = itab2'.
endif.
line-col1 = 10.
line-col2 = 20.
append line to itab1.
if itab1 gt itab2.
write :/ 'itab1 > itab2'.
endif.
if itab2 lt itab1.
write :/ 'itab2 < itab2'.
endif.
**********Internal Table - Delete with Index **********
DATA : BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.
DO 5 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
ENDDO.
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
ULINE.
DELETE ITAB INDEX : 2, 3.
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
ULINE.
**************OUTPUT **************
1 1
2 4
3 9
4 16
5 25
1 1
3 9
5 25
**********Internal Table - Delete with Condition **********
DATA : BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.
DO 10 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
ENDDO.
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
ULINE.
LOOP AT ITAB INTO LINE.
IF LINE-COL1 > 5.
DELETE ITAB .
ENDIF.
ENDLOOP.
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
ULINE.
*********OUTPUT **************
1 1
2 4
3 9
4 16
5 25
6 36
7 49
8 64
9 81
10 100
1 1
2 4
3 9
4 16
5 25
********DELETE CONDITION WITH AND OPERATOR*****
DATA : BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.
DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
INSERT LINE INTO TABLE ITAB.
ENDDO.
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
ULINE.
DELETE ITAB WHERE ( COL1 > 1 ) AND ( COL1 < 4 ).
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
****************DELETE CONDITION WITH FROM TO ***************
DATA : BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.
DO 10 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
ENDDO.
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
ULINE.
DELETE ITAB FROM 2 TO 8 WHERE COL2 > 10.
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
ULINE.
**********OUTPUT **************
1 1
2 4
3 9
4 16
5 25
6 36
7 49
8 64
9 81
10 100
1 1
2 4
3 9
9 81
10 100
**********Internal Table - Delete with key**********
DATA : BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.
DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
INSERT LINE INTO TABLE ITAB.
ENDDO.
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
ULINE.
DELETE TABLE ITAB WITH TABLE KEY COL1 = 2.
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
**********Internal Table - Delete From workarea**********
DATA : BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.
DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
INSERT LINE INTO TABLE ITAB.
ENDDO.
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
ULINE.
LINE-COL1 = 1.
DELETE TABLE ITAB FROM LINE.
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
********Internal Table - Delete Adjacent Duplicates******
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE C,
END OF LINE.
DATA ITAB LIKE STANDARD TABLE OF LINE WITH NON-UNIQUE KEY COL2.
LINE-COL1 = 1. LINE-COL2 = 'A'.
APPEND LINE TO ITAB.
LINE-COL1 = 1. LINE-COL2 = 'A'.
APPEND LINE TO ITAB.
LINE-COL1 = 1. LINE-COL2 = 'B'.
APPEND LINE TO ITAB.
LINE-COL1 = 2. LINE-COL2 = 'B'.
APPEND LINE TO ITAB.
LINE-COL1 = 3. LINE-COL2 = 'B'.
APPEND LINE TO ITAB.
LINE-COL1 = 4. LINE-COL2 = 'B'.
APPEND LINE TO ITAB.
LINE-COL1 = 5. LINE-COL2 = 'A'.
APPEND LINE TO ITAB.
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
ULINE.
DELETE ADJACENT DUPLICATES FROM ITAB COMPARING ALL FIELDS.
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
ULINE.
DELETE ADJACENT DUPLICATES FROM ITAB COMPARING COL2.
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
ULINE.
DELETE ADJACENT DUPLICATES FROM ITAB COMPARING COL1.
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
ULINE.
DELETE ADJACENT DUPLICATES FROM ITAB COMPARING COL2.
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
*Internal Table - Append Initial line to Internal Table**
DATA: BEGIN OF LINE,
COL1 TYPE C,
COL2 TYPE i,
END OF LINE.
DATA ITAB LIKE TABLE OF LINE .
DO 3 TIMES.
APPEND INITIAL LINE TO ITAB.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
ENDDO.
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
*********OUTPUT **************
0
1 1
0
2 4
0
3 9
***Internal Table - Append and Insert to Internal Table***
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA : ITAB LIKE TABLE OF LINE .
DO 2 TIMES.
LINE-COL1 = SY-INDEX .
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
ENDDO.
LOOP AT ITAB INTO LINE.
LINE-COL1 = SY-TABIX * 4.
LINE-COL2 = SY-TABIX * 5.
INSERT LINE INTO ITAB.
ENDLOOP.
LOOP AT ITAB INTO LINE.
WRITE :/ SY-TABIX , LINE-COL1, LINE-COL2.
ENDLOOP.
ULINE.
*******OUTPUT **************
1 4 5
2 1 1
3 12 15
4 2 4
****Internal Table - Appending from one Internal Table to another Internal Table**
DATA: BEGIN OF LINE,
COL1 TYPE C,
COL2 TYPE I,
END OF LINE.
DATA : ITAB1 LIKE TABLE OF LINE.
DATA : ITAB2 LIKE TABLE OF LINE.
DO 3 TIMES.
LINE-COL1 = SY-INDEX .
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB1.
LINE-COL1 = SY-INDEX .
LINE-COL2 = SY-INDEX ** 3.
APPEND LINE TO ITAB2.
ENDDO.
LOOP AT ITAB1 INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
ULINE.
LOOP AT ITAB2 INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
ULINE.
APPEND LINES OF ITAB2 FROM 2 TO 3 TO ITAB1.
LOOP AT ITAB1 INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
********OUTPUT **************
1 1
2 4
3 9
1 1
2 8
3 27
1 1
2 4
3 9
2 8
3 27
***Internal Table -inserting from one Internal Table to another Internal Table*
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA : ITAB1 LIKE TABLE OF LINE .
DATA : ITAB2 LIKE TABLE OF LINE .
DO 2 TIMES.
LINE-COL1 = SY-INDEX .
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB1.
LINE-COL1 = SY-INDEX .
LINE-COL2 = SY-INDEX ** 3.
APPEND LINE TO ITAB2.
ENDDO.
INSERT LINES OF ITAB1 INTO ITAB2 INDEX 1.
LOOP AT ITAB2 INTO LINE.
WRITE :/ SY-TABIX , LINE-COL1, LINE-COL2.
ENDLOOP.
ULINE.
**********OUTPUT **************
1 1 1
2 2 4
3 1 1
4 2 8
***Internal Table-modifying Internal Table from workarea ***
DATA : BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.
DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
INSERT LINE INTO TABLE ITAB.
ENDDO.
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
ULINE.
CLEAR LINE.
LINE-COL1 = 2.
LINE-COL2 = 100.
MODIFY TABLE ITAB FROM LINE.
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
****Internal Table-modifying Internal Table with transporting ***
DATA : BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.
DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
INSERT LINE INTO TABLE ITAB.
ENDDO.
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
ULINE.
CLEAR LINE.
LINE-COL2 = 200.
MODIFY ITAB FROM LINE TRANSPORTING COL2 WHERE ( COL1 > 1 ) AND ( COL1 < 4 ) .
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
**Internal Table-modifying Internal Table with transporting dynamic ***
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA : ITAB LIKE TABLE OF LINE WITH DEFAULT KEY.
DATA NAME TYPE CHAR4 VALUE 'COL2'.
DO 4 TIMES.
LINE-COL1 = SY-INDEX .
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
ENDDO.
CLEAR LINE.
LINE-COL2 = 300.
MODIFY ITAB FROM LINE INDEX 2.
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
ULINE.
LINE-COL2 = 400.
MODIFY ITAB FROM LINE INDEX 3 TRANSPORTING (NAME).
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
***********OUTPUT *********
1 1
0 300
3 9
4 16
1 1
0 300
3 400
4 16
***Internal Table-read Internal Table with transporting*****
DATA : BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.
DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
INSERT LINE INTO TABLE ITAB.
ENDDO.
CLEAR LINE.
READ TABLE ITAB WITH TABLE KEY COL1 = 4 TRANSPORTING NO FIELDS.
WRITE:/ 'SY-SUBRC =', SY-SUBRC.
WRITE:/ 'SY-TABIX =', SY-TABIX.
***************************************************
DATA : BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.
DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
INSERT LINE INTO TABLE ITAB.
ENDDO.
CLEAR LINE.
READ TABLE ITAB WITH TABLE KEY COL1 = 3 INTO LINE TRANSPORTING COL2.
WRITE:/ 'SY-SUBRC =', SY-SUBRC.
WRITE :/ LINE-COL1, LINE-COL2.
***Internal Table-read Internal Table with compairing ***
DATA : BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE HASHED TABLE OF LINE WITH UNIQUE KEY COL1.
DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
INSERT LINE INTO TABLE ITAB.
ENDDO.
LINE-COL1 = 2.
LINE-COL2 = 3.
READ TABLE ITAB FROM LINE INTO LINE COMPARING COL1. " COL2
WRITE:/ 'SY-SUBRC =', SY-SUBRC.
WRITE :/ LINE-COL1, LINE-COL2.
**Internal Table-read Internal Table using binary search***
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA : ITAB LIKE TABLE OF LINE WITH DEFAULT KEY.
DO 5 TIMES.
LINE-COL1 = SY-INDEX .
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
ENDDO.
CLEAR LINE.
READ TABLE ITAB WITH KEY COL1 = 3 INTO LINE BINARY SEARCH.
WRITE :/ SY-SUBRC , LINE-COL1, LINE-COL2.
******OUTPUT **************
0 3 9
*******Internal Table- collect statement ********
types : begin of tab,
name type char10,
address type char10,
state type char10,
country type char10,
mark type i,
end of tab.
data : it_tab type table of tab,
wa_tab like line of it_tab. " wa_tab type tab.
wa_tab-name = 'ajay'.
wa_tab-address = 'k pur'.
wa_tab-state = 'delhi'.
wa_tab-country = 'india'.
wa_tab-mark = '20'.
append wa_tab to it_tab.
clear wa_tab.
wa_tab-name = 'bijay'.
wa_tab-address = 'ctct'.
wa_tab-state = 'ap'.
wa_tab-country ='india'.
wa_tab-mark = '40'.
append wa_tab to it_tab.
clear wa_tab.
wa_tab-name = 'rahul'.
wa_tab-address = 'ctc'.
wa_tab-state = 'ap'.
wa_tab-country = 'ind'.
wa_tab-mark = '47'.
append wa_tab to it_tab.
clear wa_tab.
wa_tab-name = 'rahul'.
wa_tab-address = 'ctc'.
wa_tab-state = 'ap'.
wa_tab-country = 'ind'.
wa_tab-mark = '34'.
collect wa_tab into it_tab.
clear wa_tab.
loop at it_tab into wa_tab.
write :/1 wa_tab-name,
15 wa_tab-address,
30 wa_tab-state,
50 wa_tab-country,
70 wa_tab-mark.
endloop.
*******Internal Table-field symbol as work area********
DATA : BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.
FIELD-SYMBOLS : <FS> LIKE LINE OF ITAB.
DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
INSERT LINE INTO TABLE ITAB.
ENDDO.
READ TABLE ITAB WITH TABLE KEY COL1 = 2 ASSIGNING <FS>.
<FS>-COL2 = 200.
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2.
ENDLOOP.
**************************************************
DATA : BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.
FIELD-SYMBOLS <FS> LIKE LINE OF ITAB.
DO 5 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
ENDDO.
READ TABLE ITAB INDEX 2 ASSIGNING <FS>.
<FS>-COL2 = 50.
READ TABLE ITAB INDEX 3 ASSIGNING <FS>.
DELETE ITAB INDEX 3.
IF <FS> IS ASSIGNED.
WRITE :/ '<FS> IS ASSIGNED.'.
ENDIF.
LOOP AT ITAB ASSIGNING <FS> .
WRITE :/ <FS>-COL1, <FS>-COL2.
ENDLOOP.
*******Internal Table- write to internal table ********
DATA : TEXT TYPE CHAR40.
DATA ITAB LIKE TABLE OF TEXT.
TEXT = 'THIS IS THE FIRST TEXT'.
APPEND TEXT TO ITAB.
TEXT = 'THIS IS THE SECOND TEXT'.
APPEND TEXT TO ITAB.
TEXT = 'THIS IS THE THIRD TEXT'.
APPEND TEXT TO ITAB.
TEXT = 'THIS IS THE FOURTH TEXT'.
APPEND TEXT TO ITAB.
WRITE 'FIFTH LINE' TO ITAB+12 INDEX 3.
WRITE 'SIXTH' TO ITAB INDEX 4.
LOOP AT ITAB INTO TEXT.
WRITE :/ TEXT.
ENDLOOP.
******OUTPUT **************
THIS IS THE FIRST TEX
THIS IS THE SECOND TE
THIS IS THE FIFTH LIN
SIXTH
*******Internal Table- internal table with header line ********
types : begin of ty_tab,
name(10) type c,
add(10) type c,
end of ty_tab.
data : it_tab type table of ty_tab with header line .
it_tab-name = 'ssss'.
it_tab-add = 'bbsr'.
append it_tab.
it_tab-name = 'pppp'.
it_tab-add = 'bbsr'.
append it_tab.
it_tab-name = 'dddd'.
it_tab-add = 'bbsr'.
append it_tab.
loop at it_tab.
write : / it_tab-name,
it_tab-add.
endloop.
**Internal Table- internal table with control loop statements **
DATA: BEGIN OF LINE,
COL1 TYPE C,
COL2 TYPE i,
COL3 TYPE i,
END OF LINE.
DATA ITAB LIKE HASHED TABLE OF LINE WITH UNIQUE KEY COL1 COL2.
LINE-COL1 = 'A'.
DO 3 TIMES.
LINE-COL2 = SY-INDEX.
LINE-COL3 = SY-INDEX ** 2.
INSERT LINE INTO TABLE ITAB.
ENDDO.
LINE-COL1 = 'B'.
DO 3 TIMES.
LINE-COL2 = 2 * SY-INDEX.
LINE-COL3 = ( 2 * SY-INDEX ) ** 2.
INSERT LINE INTO TABLE ITAB.
ENDDO.
LOOP AT ITAB INTO LINE.
WRITE :/ LINE-COL1, LINE-COL2 , LINE-COL3.
AT END OF COL1.
SUM .
ULINE.
WRITE :/ LINE-COL1, LINE-COL2 , LINE-COL3.
SKIP 2.
ENDAT.
AT LAST.
SUM .
ULINE.
WRITE :/ LINE-COL1, LINE-COL2 , LINE-COL3.
ENDAT.
ENDLOOP.
=========================================
1 comment:
Hello sir, your blog is very useful for beginners and it helped me a lot to clear my doubts. SIr, I am a Non-IT student and learning SAP ABAP, while practicing and doing an assignment I got stuck in matching the fields of different tables. could you please help me to understand how to match the fields of multiple tables(say 4 different tables) into one table as output...please sir. If possible have a look at your mail id. I've sent the assignment (XLS file) attached to a mail. from " hemant.19eee@gmail.com " please have a look sir.
Post a Comment