Application Development and Automation 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: 
Read only

Removing Read Statements

Former Member
0 Likes
1,090

Hi I have to replace the read statements by loop statement in the following code


LOOP AT P_I_IFLO INTO WA_IFLO.
    WA_FINAL-TPLNR = WA_IFLO-TPLNR.
    V_FINAL_IWERK  = WA_IFLO-IWERK.

    READ TABLE P_I_ILOA INTO WA_ILOA WITH KEY TPLNR = WA_FINAL-TPLNR
                                         SWERK = V_FINAL_IWERK.
    IF SY-SUBRC EQ '0'.
      WA_FINAL-EQFNR = WA_ILOA-EQFNR.
      V_FINAL_ILOAN  = WA_ILOA-ILOAN.
    ENDIF.

    READ TABLE  P_I_EQUZ INTO WA_EQUZ  WITH KEY ILOAN = V_FINAL_ILOAN
                                                IWERK = V_FINAL_IWERK.

    IF SY-SUBRC EQ '0'.
      WA_FINAL-EQUNR = WA_EQUZ-EQUNR.
    ENDIF.

    READ TABLE P_I_IFLOTX INTO WA_IFLOTX WITH KEY TPLNR = WA_FINAL-TPLNR.

    IF SY-SUBRC EQ '0'.
      WA_FINAL-PLTXT = WA_IFLOTX-PLTXT.
    ENDIF.

    READ TABLE P_I_EQKT INTO WA_EQKT WITH KEY EQUNR = WA_FINAL-EQUNR.
    IF SY-SUBRC EQ '0'.
      WA_FINAL-EQKTX = WA_EQKT-EQKTX.
    ENDIF.

    APPEND WA_FINAL TO P_I_FINAL.

    CLEAR : WA_FINAL,
            V_FINAL_ILOAN,
            V_FINAL_IWERK,
            WA_ILOA.

  ENDLOOP.

The internal tables P_I_ILOA, P_I_EQUZ and P_I_EQKT have more than 1 entry. Using read statement, only one entry can be read and appended to the final internal table. Now I need to remove this read and put loop. Since there are more than one read statement and they are within a loop, how can i code it using loop?

10 REPLIES 10
Read only

Former Member
0 Likes
1,051

Hi,

What is the problem?

You can loop it, like below,

loop at P_I_ILOA into WA_ILOA  where TPLNR = WA_FINAL-TPLNR
                                       and   SWERK = V_FINAL_IWERK.

code...

code....

endloop.

Read only

0 Likes
1,051

Hi,

They select one field from one internal table and append it to final internal table..

If i use loop, how can i append it?

Ezhil

Read only

Subhankar
Active Contributor
0 Likes
1,051

Hi,

You can use parallel cursor technique for that. It will help you in terms of performance..

Thanks

Subhankar

Read only

Former Member
0 Likes
1,051

hi,

try using all the primary keys in the read statement. then there wil be only one entry for each set. and you do tn need to use loop.

Read only

Former Member
0 Likes
1,051

Hi,

When you are looping in first ,, on P_I_IFLO ,, you will process first record of P_I_IFLO .. and at the end of the Loop ,, you will append this one record to Final table ..

Question here is,, why you like to convert the read from P_I_ILOA into Loop ??

because if you gets 3 records,, then do you like append all the 3 records into final (In P_I_ILOA) ??

Read only

0 Likes
1,051

Yes, I need to append all the records of the table

Read only

Former Member
0 Likes
1,051

Hi,

Its better to use parallel cursor method instead of 'Loop at where' as follows.

LOOP AT P_I_IFLO INTO WA_IFLO.
    WA_FINAL-TPLNR = WA_IFLO-TPLNR.
    V_FINAL_IWERK  = WA_IFLO-IWERK.
 
    READ TABLE P_I_ILOA INTO WA_ILOA WITH KEY TPLNR = WA_FINAL-TPLNR
                                         SWERK = V_FINAL_IWERK.
    IF SY-SUBRC EQ '0'.

      LV_INDEX = SY_TABIX.
      LOOP AT P_I_ILOA INTO WA_ILOA FROM LV_INDEX.
      IF ( WA_ILOA-TPLNR = WA_FINAL-TPLNR)  AND
          (WA_ILOA-SWERK = V_FINAL_IWERK).

          WA_FINAL-EQFNR = WA_ILOA-EQFNR.
          V_FINAL_ILOAN  = WA_ILOA-ILOAN.
      ELSE.
          EXIT.
      ENDIF.
      ENDLOOP.
    ENDIF.
:
: similar code for other READS...
;
ENDLOOP.

Regards,

Karthik

Read only

0 Likes
1,051

Thank you.

But How do I finally append to the final internal table?

Ezhil

Read only

0 Likes
1,051

Hi ,

You may use the same READ statements inside the P_I_ILOA loop for other internal tables.


    LOOP AT P_I_ILOA INTO WA_ILOA FROM LV_INDEX.
      IF ( WA_ILOA-TPLNR = WA_FINAL-TPLNR)  AND
          (WA_ILOA-SWERK = V_FINAL_IWERK).
 
          WA_FINAL-EQFNR = WA_ILOA-EQFNR.
          V_FINAL_ILOAN  = WA_ILOA-ILOAN.

          [other READ statements]

      ELSE.
          EXIT.
      ENDIF.

Regards,

Karthik

Read only

Former Member
0 Likes
1,051

Hi Try this code

LOOP AT P_I_IFLO INTO WA_IFLO.

WA_FINAL-TPLNR = WA_IFLO-TPLNR.

V_FINAL_IWERK = WA_IFLO-IWERK.

loop at P_I_ILOA INTO WA_ILOA where TPLNR = WA_IFLO-TPLNR

and SWERK = WA_IFLO-IWERK.

WA_FINAL-EQFNR = WA_ILOA-EQFNR.

V_FINAL_ILOAN = WA_ILOA-ILOAN.

loop at P_I_EQUZ INTO WA_EQUZ where ILOAN = WA_ILOA-ILOAN

and IWERK = WA_IFLO-IWERK.

WA_FINAL-EQUNR = WA_EQUZ-EQUNR.

loop at P_I_EQKT INTO WA_EQKT where equnr = WA_EQUZ-EQUNR.

WA_FINAL-EQKTX = WA_EQKT-EQKTX.

endloop.

endloop.

endloop.

loop at P_I_IFLOTX INTO WA_IFLOTX where TPLNR = WA_IFLO-TPLNR.

WA_FINAL-PLTXT = WA_IFLOTX-PLTXT.

endloop.

APPEND WA_FINAL TO P_I_FINAL.

CLEAR : WA_FINAL,

V_FINAL_ILOAN,

V_FINAL_IWERK,

WA_ILOA.

endloop.