Skip to Content
avatar image
Former Member

which code would fit well in End Routine?

Hi All,

I found two way of writing end routine in BW. Out of these which one from below would be the right way to code it and what would be reason behind that.

Please help me out to understand more working of 4th generation language.

1) with append statement

LOOP AT RESULT_PACKAGE ASSIGNING <RESULT_FIELDS> .

LOOP AT ITAB2 INTO WA WHERE /BIC/ZORDNUM = <RESULT_FIELDS>-/BIC/ZORDNUM.

<RESULT_FIELDS>-/BIC/ZITEMNUM = WA-/BIC/ZITEMNUM.

<RESULT_FIELDS>-MATERIAL = WA-MATERIAL.

<RESULT_FIELDS>-/BIC/ZITMTYP = WA-/BIC/ZITMTYP.

<RESULT_FIELDS>-QUANT_B = WA-QUANT_B.

<RESULT_FIELDS>-BASE_UOM = WA-BASE_UOM.

APPEND <RESULT_FIELDS> TO ITAB_TARGET.

ENDLOOP.

ENDLOOP

2) with modify statement


LOOP AT RESULT_PACKAGE ASSIGNING WA_RESULT_PACKAGE.

LOOP AT ITAB2 INTO WA WHERE /BIC/ZORDNUM = RESULT_PACKAGE-/BIC/ZORDNUM.

WA_RESULT_PACKAGE-/BIC/ZITEMNUM = WA-/BIC/ZITEMNUM.

WA_RESULT_PACKAGE-MATERIAL = WA-MATERIAL.

WA_RESULT_PACKAGE-/BIC/ZITMTYP = WA-/BIC/ZITMTYP.

WA_RESULT_PACKAGE-QUANT_B = WA-QUANT_B.

WA_RESULT_PACKAGE-BASE_UOM = WA-BASE_UOM.

modify RESULT_PACKAGE from WA_RESULT_PACKAGE.

ENDLOOP.

ENDLOOP

Thanks

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Apr 04, 2016 at 01:10 PM

    Hi Jinal,

    A loop inside another loop is always a bad idea.

    Try to use a READ inside the loop if you are only going to select single records,

    LOOP AT RESULT_PACKAGE ASSIGNING <RESULT_FIELDS> .

    READ TABLE ITAB2 INTO WA WITH KEY /BIC/ZORDNUM = <RESULT_FIELDS>-/BIC/ZORDNUM.

    IF SY-SUBRC = 0.

    <RESULT_FIELDS>-/BIC/ZITEMNUM = WA-/BIC/ZITEMNUM.

    <RESULT_FIELDS>-MATERIAL = WA-MATERIAL.

    <RESULT_FIELDS>-/BIC/ZITMTYP = WA-/BIC/ZITMTYP.

    <RESULT_FIELDS>-QUANT_B = WA-QUANT_B.

    <RESULT_FIELDS>-BASE_UOM = WA-BASE_UOM.

    APPEND <RESULT_FIELDS> TO ITAB_TARGET.

    ENDIF.

    ENDLOOP.

    *Remember that you are modifying the values in RESULT_PACKAGE table as well here

    Benedict

    Add comment
    10|10000 characters needed characters exceeded

    • Hi,

      I'm also using WORKAREA before since I'm used to it..😀

      But many members here are ALWAYS suggesting to use field symbols instead for better performance..So I just ASSUME that field symbols should be used when doing BW routines ONLY..Because I asked several ABAPers and found out that they PREFER to use WORKAREA since field symbol is hard to DEBUG in some cases..

      Hope it gave you an idea.. 😉

      Regards,

      Loed

  • avatar image
    Former Member
    Apr 11, 2016 at 04:34 AM

    Hi,

    The code which you mentioned is correct.

    when we write a code in start routine or end routine it is better to use field instead.

    LOOP AT RESULT_PACKAGE ASSIGNING WA_RESULT_PACKAGE.

    READ TABLE ITAB2 INTO WA WITH KEY /BIC/ZORDNUM =RESULT_PACKAGE-/BIC/ZORDNUM.

    IF SY-SUBRC = 0.

    WA_RESULT_PACKAGE-/BIC/ZITEMNUM = WA-/BIC/ZITEMNUM.

    WA_RESULT_PACKAGE-MATERIAL = WA-MATERIAL.

    WA_RESULT_PACKAGE-/BIC/ZITMTYP = WA-/BIC/ZITMTYP.

    WA_RESULT_PACKAGE-QUANT_B = WA-QUANT_B.

    WA_RESULT_PACKAGE-BASE_UOM = WA-BASE_UOM.

    modify RESULT_PACKAGE from WA_RESULT_PACKAGE.

    ENDIF.

    ENDLOOP

    Regards,

    Priya M

    Add comment
    10|10000 characters needed characters exceeded