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

Loop on item table

Former Member
0 Likes
881

Hi all,

I want to loop on required records only in Item table (i_vbap). My code as follows


LOOP AT i_vbak
  READ TABLE i_vbap WITH KEY vbeln = i_vbak-vbeln.
  IF sy-subrc = 0.
 LOOP AT i_vbap.
    IF i_vbap-vbeln = i_vbak-vbeln.
      MOVE i_vbap TO i_vbap1.
      APPEND i_vbap1.
    ENDIF.
  ENDLOOP.
ENDLOOP.

in 2nd loop, it is looping all records in i_vbap. but i want to loop only when vbeln = i_vbak-vbeln (as in read statement ).

Plz help me on this. Thanks in advance.

Regards.

1 ACCEPTED SOLUTION
Read only

former_member386202
Active Contributor
0 Likes
702

Hi,

do like this

LOOP AT i_vbak

READ TABLE i_vbap WITH KEY vbeln = i_vbak-vbeln.

IF sy-subrc = 0.

LOOP AT i_vbap where vbeln = i_vbak-vbeln .

IF i_vbap-vbeln = i_vbak-vbeln.

MOVE i_vbap TO i_vbap1.

APPEND i_vbap1.

ENDIF.

ENDLOOP.

ENDLOOP.

Regards,

Prashant

4 REPLIES 4
Read only

former_member386202
Active Contributor
0 Likes
703

Hi,

do like this

LOOP AT i_vbak

READ TABLE i_vbap WITH KEY vbeln = i_vbak-vbeln.

IF sy-subrc = 0.

LOOP AT i_vbap where vbeln = i_vbak-vbeln .

IF i_vbap-vbeln = i_vbak-vbeln.

MOVE i_vbap TO i_vbap1.

APPEND i_vbap1.

ENDIF.

ENDLOOP.

ENDLOOP.

Regards,

Prashant

Read only

GauthamV
Active Contributor
0 Likes
702

use like this.


LOOP AT i_vbak
  READ TABLE i_vbap WITH KEY vbeln = i_vbak-vbeln.
  IF sy-subrc = 0.
 LOOP AT i_vbap where vbeln = i_vbak-vbeln..
        MOVE i_vbap TO i_vbap1.
      APPEND i_vbap1.
      ENDLOOP.
ENDLOOP.

Read only

Former Member
0 Likes
702

Hi,

Try like this,


LOOP AT i_vbak
 LOOP AT i_vbap where vbeln = i_vbak-vbeln.  "------> Remove the read statement and add the condition in loop itself
    IF i_vbap-vbeln = i_vbak-vbeln.
      MOVE i_vbap TO i_vbap1.
      APPEND i_vbap1.
  ENDLOOP.
ENDLOOP.

Regards,

Vikranth

Read only

Former Member
0 Likes
702

you can use where conditon with loop statement ...press F1 on loop to get more details regarding where clause..