Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

how to do comparison with read statement

Former Member
0 Kudos
95

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.

1 ACCEPTED SOLUTION

former_member195383
Active Contributor
0 Kudos
70

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

5 REPLIES 5

former_member195383
Active Contributor
0 Kudos
71

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

Former Member
0 Kudos
70

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.

Former Member
0 Kudos
70

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

Former Member
0 Kudos
70

thank you all for help.

Former Member
0 Kudos
70

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