cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP Program

Former Member
0 Kudos

Hi,

I am new to ABAP and i was developiong a program . i have a requirement where i loop vbap table and get all the enrtries for a range of vbeln in a internal table say itab. i want to loop at this internatl table ( itab) and populate another internal table say itab_1 which has data for only one vbeln i.e values for one vebln no. ( as many line items may be present...)

can any body send me a sample code for this.

Thanks in advance

Priya

Accepted Solutions (1)

Accepted Solutions (1)

former_member188685
Active Contributor
0 Kudos

Hi,

i think this is what you are looking..


select *
       from vbak
       into table it_vbak
       where vbeln in s_vbeln.
if sy-subrc = 0.
select * 
       from vbap
       into table it_vbap
       for all entries in it_vbak
       where vbeln = it_vbak-vbeln.
if sy-subrc = 0.
sort it_vbap by vbeln posnr.
endif.

endif.

Regards

vijay

Former Member
0 Kudos

Hi,

Thanks for the reply but i was looking for 2 internal table of vabk one which has the full values for the range provided and other internal table should be a sub set of the first one with values pertaing to only one vbeln.

Rgds

Priya

LucianoBentiveg
Active Contributor
0 Kudos

select *

from vbap

into table itab1

where vbeln in s_vbeln.

if sy-subrc = 0.

loop at vbap where vbeln EQ lv_vbeln.

itab2 = itab1.

append itab2.

endloop.

endif.

former_member188685
Active Contributor
0 Kudos

Hi,

in that case you will end up with so many internal tables.

see i have 10 vbelns(assume), then then i will have (10+1) intenal tables.

but from my code you have all vbeln in one, and items in other.


loop at it_vbak.

loop at it_vbap where vbeln = it_vbak-vbeln.
"here collect the data and append it.
move-corresponding it_vbap to it_vbap_sec.
append it_vbap_sec.
clear it_vbap_sec.
endloop.
then here do some thing and refresh the table.
then next run you will have second set.
endloop.

Regards

vijay

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Priya,

As far as I understood your requirement, this can be achieved by using nested loops.

Select * from Vbak into it_vbak where <conditions>.

Select * from Vbap into it_vbap for all entries in it_vbak where <conditions>.

Loop at it_vbak.

loop at it_vbap where vblen = it_vbak-vbeln.

*populate itab2 with the records of one single vbeln.

itab2 = it_vbap.

append itab2.

endloop.

endloop.

This would give you all the VBAP records for a particular VBELN. Hope this was what u required.

Thanks,

Rashmi.

Former Member
0 Kudos

Re: ABAP Program

Posted: May 5, 2006 10:32 AM Reply E-mail this post

Hi,

select *

from vbap

into table itab

where vbeln in s_vbeln.

if sy-subrc = 0.

sort itab by vbeln

itab1[] = itab[].

delete itab where vbeln <> the vbeln which you requier.

endif.

Former Member
0 Kudos

Well... I am not sure what exactly you want !!

But as per my understanding I am putting you a code snippet.

1. Select query from DB table to fill ITAB1

2. You have 2 choices :

LOOP AT ITAB1 1 TIMES.

  • Select query to fill second ITAB2 based on

first table value.

SELECT * FROM DBTAB INTO TABLE ITAB2

WHERE KEYFIELD = ITAB1-FIELD.

ENDLOOP.

Second Choice:

READ TABLE ITAB1 WITH KEY FIELD = <SOME VALUE>

  • Select query to fill second ITAB2 based on

first table value.

SELECT * FROM DBTAB INTO TABLE ITAB2

WHERE KEYFIELD = ITAB1-FIELD.

Let me know if this is not what you want.

If helpful then reward points !!

Jignesh.