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

using table types for internal tables

Former Member
0 Likes
503

hi,

I have doubt in displaying the final table using types.in the following code,

when i enter the vbeln value it has to show all the values present.

but it is giving only one value.

for eg if for vbeln there are 4 records it is showng only one record.

i think i made mistake in looping to final table.lpz help me.

((i m getting using joins.but iwant in this manner))

types:begin of st_vbak,

vbeln type vbeln_va,

vkorg type vkorg,

vtweg type vtweg,

end of st_vbak.

types:begin of st_vbap,

vbeln type vbeln_va,

posnr type posnr_va,

matnr type matnr,

end of st_vbap.

types:begin of st_final,

vbeln type vbeln_va,

vkorg type vkorg,

vtweg type vtweg,

posnr type posnr_va,

matnr type matnr,

end of st_final.

data:it_vbak type table of st_vbak,

it_vbap type table of st_vbap,

it_final type table of st_final,

wa_vbak type st_vbak,

wa_vbap type st_vbap,

wa_final type st_final.

parameters:p_vbeln type vbeln_va.

select vbeln

vkorg

vtweg

from

vbak

into

table it_vbak where vbeln = p_vbeln.

if not it_vbak is initial .

select vbeln

posnr

matnr

from vbap

into table it_vbap

for all entries in it_vbak where vbeln = it_vbak-vbeln.

endif.

loop at it_vbak into wa_vbak.

read table it_vbap into wa_vbap with key vbeln = wa_vbak-vbeln.

move-corresponding wa_vbak to wa_final.

move-corresponding wa_vbap to wa_final.

append wa_final to it_final.

endloop.

loop at it_final into wa_final.

write:/ wa_final-vbeln,

wa_final-vkorg,

wa_final-vtweg,

wa_final-posnr,

wa_final-matnr.

endloop.

4 REPLIES 4
Read only

Former Member
0 Likes
432

both the record move into same finial internal table .so it can display all records.

Read only

Former Member
0 Likes
432

this is because of read table it only fetch one record just change the entire loop like this...

loop at it_vbap into wa_vbap.

read table it_vbak into wa_vbak with key vbeln = wa_vbap-vbeln.

if sy-subrc = 0.

move-corresponding wa_vbak to wa_final.

endif.

move-corresponding wa_vbap to wa_final.

append wa_final to it_final.

endloop.

loop at it_vbap and read it_vbak because each line item of same vbelnin in it_vbap the header data must be same in it_vbak.

and chek if not it_vbak[] is initial .

i.e. the body of the table not the header.

regards

shiba dutta

Read only

Former Member
0 Likes
432

Hi Pavan ,

Change the last loop ad follows:

loop at it_vbap into wa_vbap.

read table it_vbak into wa_vbak with key vbeln = wa_vbap-vbeln.

move-corresponding wa_vbak to wa_final.

move-corresponding wa_vbap to wa_final.

append wa_final to it_final.

endloop.

loop at it_final into wa_final.

write:/ wa_final-vbeln,

wa_final-vkorg,

wa_final-vtweg,

wa_final-posnr,

wa_final-matnr.

endloop.

regards,

Navneeth K

Read only

varma_narayana
Active Contributor
0 Likes
432

Hi..

Change your code as below for the last loops.

This will work as per the req with better performance.

<b>CLEAR: WA_VBAP,

WA_VBAK.</b>

<b>SORT IT_VBAK BY VBELN.

Loop at it_vbap into wa_vbap.

move-corresponding wa_vbap to wa_final.

ON CHANGE OF WA_VBAP-VBELN.

Read table it_vbak into wa_vbak

with key vbeln = wa_vbap-vbeln

binary search.

IF SY-SUBRC = 0.

move-corresponding wa_vbak to wa_final.

ENDIF.

ENDON.

Append wa_final to it_final.

endloop.</b>

loop at it_final into wa_final.

write:/ wa_final-vbeln,

wa_final-vkorg,

wa_final-vtweg,

wa_final-posnr,

wa_final-matnr.

endloop.

Reward if Helpful.