Skip to Content
author's profile photo Former Member
Former Member

how to do comparison with read statement

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    Posted on Jun 17, 2008 at 03: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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 10: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

Add a comment
10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 04: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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 10:57 AM

    thank you all for help.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 11:31 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Before answering

    You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
    You must be Logged in to submit an answer.

    Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.