2008 Jun 17 3:32 AM
hi all,
i got 2 internal table with the following data.
i_tab_a
-
matnr budat
mat1 20080608
mat1 20080601
i_tab_b
-
matnr charg budat flag
mat1 a 20080606 X
mat1 b 20080606
mat1 c 20060606
mat1 d 20060605
mat1 e 20060605
loop i_tab_a
read table i_tab_b with key mat1 = i_tab_a-matnr
budat < i_tab_a-budat (??)
flag = ''.
endloop.
after the first read, the 1st record at i_tab_b will be marked as read.
my question is how to get the second record of i_tab_a to match with the 4th record of the i_tab_b, without hte budat < i_tab_a-budat in the read statement? any alternative can do the same thing?
thanks.
2008 Jun 17 4:49 AM
Hi..
U can use loop with in loop.Thats an alternative.....
loop i_tab_a
loop at i_tab_b where mat1 = i_tab_a-matnr
budat < i_tab_a-budat (??)
flag = ''.
endloop.
endloop.
hope...this is wat ur requirement is...
Reward points..if useful...
Regards..
Rudra
2008 Jun 17 4:49 AM
Hi..
U can use loop with in loop.Thats an alternative.....
loop i_tab_a
loop at i_tab_b where mat1 = i_tab_a-matnr
budat < i_tab_a-budat (??)
flag = ''.
endloop.
endloop.
hope...this is wat ur requirement is...
Reward points..if useful...
Regards..
Rudra
2008 Jun 17 5:41 AM
hi....
you can use nested loop.
each record from your first loop will be compared wih each record from your 2nd loop UNLIKE READ which allows you to read only single record.
hope this helps you.
2008 Jun 17 11:35 AM
hi,
Refer the following pgm
case 1 ) table1 compared
case 2) table 2 compared
-
REPORT ZTEST46.
TYPES : BEGIN OF S_MATRL,
MATNR(18),
WERKS(4),
LGORT(4),
END OF S_MATRL.
DATA : T_MATRL TYPE STANDARD TABLE OF S_MATRL,
WA_MATRL TYPE S_MATRL.
TYPES : BEGIN OF S_MATRL1,
MATNR(18),
WERKS(4),
LGORT(4),
END OF S_MATRL1.
DATA : T_MATRL1 TYPE STANDARD TABLE OF S_MATRL1,
WA_MATRL1 TYPE S_MATRL1.
data : v_index like sy-index .
+ 1st Table fields filling+
wa_matrl-matnr = 1234.
wa_matrl-werks = 'BP01'.
WA_MATRL-LGORT = '0001'.
APPEND WA_MATRL TO T_MATRL.
CLEAR WA_MATRL.
wa_matrl-matnr = 1567.
wa_matrl-werks = 'BK01'.
WA_MATRL-LGORT = '0002'.
APPEND WA_MATRL TO T_MATRL.
CLEAR WA_MATRL.
secon table fields filling
wa_matrl1-matnr = 1234.
wa_matrl1-werks = 'BP01'.
WA_MATRL1-LGORT = '0004'.
APPEND WA_MATRL1 TO T_MATRL1.
CLEAR WA_MATRL1.
wa_matrl1-matnr = 1234.
wa_matrl1-werks = 'BP01'.
WA_MATRL1-LGORT = '0005'.
APPEND WA_MATRL1 TO T_MATRL1.
CLEAR WA_MATRL1.
wa_matrl1-matnr = 1234.
wa_matrl1-werks = 'BK01'.
WA_MATRL1-LGORT = '0004'.
APPEND WA_MATRL1 TO T_MATRL1.
CLEAR WA_MATRL1.
wa_matrl1-matnr = 1567.
wa_matrl1-werks = 'BP01'.
WA_MATRL1-LGORT = '0006'.
APPEND WA_MATRL1 TO T_MATRL1.
CLEAR WA_MATRL1.
wa_matrl1-matnr = 1567.
wa_matrl1-werks = 'BP01'.
WA_MATRL1-LGORT = '1000'.
APPEND WA_MATRL1 TO T_MATRL1.
CLEAR WA_MATRL1.
LOOP AT T_MATRL INTO WA_MATRL1.
WRITE : / WA_MATRL1-MATNR,WA_MATRL1-WERKS,WA_MATRL1-LGORT.
ENDLOOP.
ULINE.
LOOP AT T_MATRL1 INTO WA_MATRL.
WRITE : / WA_MATRL-MATNR,WA_MATRL-WERKS,WA_MATRL-LGORT.
ENDLOOP.
ULINE.
for first table variation after comparing with the second table
*LOOP AT T_MATRL INTO WA_MATRL.
*
READ TABLE T_MATRL1 INTO WA_MATRL1 WITH KEY MATNR = WA_MATRL-MATNR.
IF SY-SUBRC IS INITIAL.
WA_MATRL-MATNR = WA_MATRL1-MATNR + 1.
WA_MATRL-WERKS = WA_MATRL1-WERKS.
WA_MATRL-LGORT = WA_MATRL1-LGORT.
MODIFY table T_MATRL FROM WA_MATRL. "TRANSPORTING MATNR.
modify t_matrl from wa_matrl.
ENDIF.
*
*ENDLOOP.
*
*LOOP AT T_MATRL INTO WA_MATRL.
WRITE : / WA_MATRL-MATNR,WA_MATRL-WERKS,WA_MATRL-LGORT.
*ENDLOOP.
for Second table variation after comparing with the first table
LOOP AT T_MATRL1 INTO WA_MATRL1.
READ TABLE T_MATRL INTO WA_MATRL WITH KEY MATNR = WA_MATRL1-MATNR.
IF SY-SUBRC IS INITIAL.
WA_MATRL1-MATNR = WA_MATRL-MATNR + 1.
WA_MATRL1-WERKS = WA_MATRL-WERKS.
WA_MATRL1-LGORT = WA_MATRL-LGORT.
MODIFY table T_MATRL FROM WA_MATRL. "TRANSPORTING MATNR.
modify t_matrl1 from wa_matrl1.
ENDIF.
ENDLOOP.
LOOP AT T_MATRL1 INTO WA_MATRL1.
WRITE : / WA_MATRL1-MATNR,WA_MATRL1-WERKS,WA_MATRL1-LGORT.
ENDLOOP.
Reward if help ful
Rgds
umakanth
2008 Jun 17 11:57 AM
2008 Jun 17 12:31 PM
hi,
Loop in Loop i,e nested loops is performance issue.
You should not use.
Instead you can use read statement in loop .
Rgds
Umaknth