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

Problems with loop

Former Member
0 Likes
555

Hello! sorry guys but I have the next problem in my code to make a loop. I not understand why? This is my code in my BADI PROCESS_PS_CUST
LOOP AT t_posic INTO wa_posic.

    wa_posic-mandt = SY-MANDT.

    wa_posic-ebeln = im_ebeln.

    MOVE-CORRESPONDING t_posic to ZME21N005.

    MODIFY ZME21N005.

  ENDLOOP.

Error:

Field "ZME21NXXX is unknown. It is neither in one of the specified
1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
498

Your code is incorrect.

MOVE-CORRESPONDING t_posic to ZME21N005. -> you should move this one to work area and not direct to custom table.


Do something like this:


DATA: wa_zmew21n005 TYPE zme21n005.


LOOP AT t_posic INTO wa_posic.

    wa_posic-mandt = SY-MANDT.

    wa_posic-ebeln = im_ebeln.

    MOVE-CORRESPONDING wa_posic TO wa_zmew21n005.

    MODIFY ZME21N005 FROM wa_zmew21n005.

  ENDLOOP.

Performance wise also, it is recommended to modify custom table outside loop.

DATA: wa_zmew21n005 TYPE zme21n005,

            i_zmew21n005 TYPE STANDARD TABLE OF zme21n005.


LOOP AT t_posic INTO wa_posic.

    wa_posic-mandt = SY-MANDT.

    wa_posic-ebeln = im_ebeln.

    MOVE-CORRESPONDING wa_posic TO wa_zmew21n005.

    APPEND wa_zmew21n005 TO i_zmew21n005.

  ENDLOOP.

MODIFY ZME21N005 FROM TABLE i_zmew21n005.

2 REPLIES 2
Read only

Former Member
0 Likes
499

Your code is incorrect.

MOVE-CORRESPONDING t_posic to ZME21N005. -> you should move this one to work area and not direct to custom table.


Do something like this:


DATA: wa_zmew21n005 TYPE zme21n005.


LOOP AT t_posic INTO wa_posic.

    wa_posic-mandt = SY-MANDT.

    wa_posic-ebeln = im_ebeln.

    MOVE-CORRESPONDING wa_posic TO wa_zmew21n005.

    MODIFY ZME21N005 FROM wa_zmew21n005.

  ENDLOOP.

Performance wise also, it is recommended to modify custom table outside loop.

DATA: wa_zmew21n005 TYPE zme21n005,

            i_zmew21n005 TYPE STANDARD TABLE OF zme21n005.


LOOP AT t_posic INTO wa_posic.

    wa_posic-mandt = SY-MANDT.

    wa_posic-ebeln = im_ebeln.

    MOVE-CORRESPONDING wa_posic TO wa_zmew21n005.

    APPEND wa_zmew21n005 TO i_zmew21n005.

  ENDLOOP.

MODIFY ZME21N005 FROM TABLE i_zmew21n005.

Read only

0 Likes
498

Tank you bro!