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

Problem looping at VBAP

Former Member
0 Likes
1,368

Hello All,

I have the following code

types: BEGIN OF t_vbap,
          vbeln TYPE vbap-vbeln,
          posnr TYPE vbap-posnr,
          uepos TYPE vbap-uepos,
        END OF t_vbap.

DATA: lit_vbap TYPE TABLE OF t_vbap,
          lwa_vbap TYPE t_vbap,
          lfd_posnr TYPE vbap-posnr.

clear lfd_posnr.

lfd_posnr = gwa_item-posnr.

LOOP AT lit_vbap INTO lwa_vbap WHERE posnr EQ lfd_posnr.
  IF lwa_vbap-uepos IS INITIAL.
    EXIT.
  ELSE.
    lfd_posnr = lwa_vbap-uepos.   
    CLEAR: lwa_vbap.
  ENDIF.
ENDLOOP.

The loop is executed only one time. When I change the value  of lfd_posnr from UEPOS there is another entry in the table LIT_VBAP which satisfies my criteria.

Could you please help me find the problem with the code

Thanks,

Anju

Moderator message : Not enough re-search before posting, discussion locked.

Message was edited by: Vinod Kumar

7 REPLIES 7
Read only

madhu_vadlamani
Active Contributor
0 Likes
1,155

Hi Anju,

Can you explain what report you are developing.What is gwa_item-posnr.What is the selection you are giving.

Regards,

Madhu.

Read only

0 Likes
1,155

Hi Madhu,

My requirement is to fetch the entry from VBAP where the value of UEPOS is initial for a particular sales order number and item.

Thanks,

Anju

Read only

0 Likes
1,155

Hi Anju,

See i think some one already answered.

Regards,

Madhu.

Read only

Former Member
0 Likes
1,155

Hi,

Please elaborate your problem.

Jake.

Read only

Former Member
0 Likes
1,155

Hi,

the problem might be with leading zeroes of lfd_posnr and posnr.

can u check that

Thanks,

Ibrahim

Read only

Kartik2
Contributor
0 Likes
1,155

Hi,

First of all you are using an unnecessary if condition inside the loop. You may do the follwing.

LOOP AT lit_vbap      INTO lwa_vbap
                                 WHERE posnr EQ lfd_posnr
                                 AND   uepose is not initial.

    lfd_posnr = lwa_vbap-uepos.

ENDLOOP.

Hope it helps. Thank you.

Regards,

kartik

Read only

Former Member
0 Likes
1,155

Hi,

In the current code, you are looping with where condition on lfd_posnr. and inside loop changing the variable lfd_posnr and expecting the loop to be continued for the new value.

but the loop statement will not work in this way.

Notes

  • The logical expression specified after WHERE is analyzed once at entry into the loop. Possible changes of the second operand during loop processing are not taken into account.

Try to achive the requirement in some other alternative way. I hope wht ever karthik said will work for u.

Thanks,

Lakshmi