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

Internal Table Problem

Former Member
0 Likes
977

Hi All,

I am executing these queries in a subroutine but when i execute the program, the previous contents of the internal table t_litem gets cleared up after executing the second query and it only contains kdmat, i want the kdmat value to be assigned to the kdmat field of the same row as posnr matnr arktx fkimg and netwr are.

SELECT posnr matnr arktx fkimg netwr

INTO CORRESPONDING FIELDS OF TABLE t_litem

FROM vbrp

WHERE vbeln = t_xhdr-vbeln.

SELECT kdmat

INTO CORRESPONDING FIELDS OF TABLE t_litem

FROM vbap

WHERE vbeln = t_xhdr-sordno.

please suggest the way to do it.

thanks

1 ACCEPTED SOLUTION
Read only

jayanthi_jayaraman
Active Contributor
0 Likes
945

Hi,

data : begin of t_vbrp occurs 0,

vbeln type vbrp-vbeln,

posnr type vbrp-posnr,

matnr type vbrp-matnr,

arktx type vbrp-arktx,

fkimg type vbrp-fkimg,

netwr type vbrp-netwr,

end of t_vbrp.

data : begin of t_vbap occurs 0,

vbeln type vbap-vbeln,

kdmat type vbap-kdmat,

end of t_vbap.

if not t_xhdr[] is initial.

SELECT vbeln posnr matnr arktx fkimg netwr

INTO TABLE t_vbrp

FROM vbrp

for all entries in t_xdhr

WHERE vbeln = t_xhdr~vbeln.

SELECT vbeln kdmat

INTO TABLE t_vbap

FROM vbap

for all entries in t_xdhr

WHERE vbeln = t_xhdr~sordno.

endif.

loop at t_xhdr.

loop at t_vbrp where key vbeln = t_xhdr-vbeln.

move-corresponding t_vbrp to t_litem.

clear t_vbap.

read table t_vbap with key vbeln = t_xhdr-sordno.

if sy-subrc eq 0.

t_vbrp-kdmat = t_litem-kdmat.

endif.

append t_litem.

endloop.

KIndly reward points by clicking the star on the left of reply,if it helps.

10 REPLIES 10
Read only

Former Member
0 Likes
945

Hi

I guess you should make use of FOR ALL ENTRIES in your second query.

SELECT posnr matnr arktx fkimg netwr

INTO CORRESPONDING FIELDS OF TABLE t_litem

FROM vbrp

WHERE vbeln = t_xhdr-vbeln.

SELECT kdmat

INTO CORRESPONDING FIELDS OF TABLE t_litem

FROM vbap

FOR ALL ENTRIES IN t_litem

WHERE vbeln = t_litem-sordno.

PLZ REWARD POINTS

Message was edited by:

Vijay Kamath

Read only

Former Member
0 Likes
945

When u are using the Select statement it will refresh the internal table data and stores the new vlaues.

So use 2 internal table for your 2 select queries and using Read table fetch the kdmat from the second internal table.

If u want the data in the same table then you can use joins.

Read only

Former Member
0 Likes
945

hi,

Please use appending into CORRESPONDING FIELDS OF TABLE t_litem

in the second select.

SELECT posnr matnr arktx fkimg netwr

INTO CORRESPONDING FIELDS OF TABLE t_litem

FROM vbrp

WHERE vbeln = t_xhdr-vbeln.

SELECT kdmat

appending into CORRESPONDING FIELDS OF TABLE t_litem

FROM vbap

WHERE vbeln = t_xhdr-sordno.

Regards,

Ishaq

Read only

Former Member
0 Likes
945

Hi,

SELECT Aposnr Amatnr Aarktx Afkimg Anetwr Bkdmat

INTO CORRESPONDING FIELDS OF TABLE t_litem

for all entries in T_XHDR

FROM vbrp as A inner join vbap as B

WHERE VBRP~vbeln = t_xhdr-vbeln

and VBAPVBELN = VBRPVBELN .

Hope this helps.

Regards

Subramanian

Read only

Former Member
0 Likes
945

USE APPENDING CLAUSE IN UR SELECT QUERY..

PRESS f1 FOR MORE HELP.

AMIT

Read only

Former Member
0 Likes
945

Hi,

Take 2 internal tables with atleast one common field in both ...

after getting both the tables U can loop at the first one and read the

second one which has the KDMAT field ..

Take both the Internal table contents into Final one.

Loop at i_1.

read i_2 with key c_f1 = i_1-c_f1. " c_f1 = common field

if sy-subrc = 0.

move corresponding i_1 into final.

move corresponding i_2 into final.

append final.

endif.

endloop.

Regards,

GSR.

Read only

Former Member
0 Likes
945

Rahul,

uSE BELOW CODE.

SELECT Aposnr Amatnr Aarktx Afkimg Anetwr Bkdmat

INTO CORRESPONDING FIELDS OF TABLE t_litem

for all entries of table T_XHDR

FROM vbrp as A inner join vbap as B

WHERE VBRP~vbeln = t_xhdr-vbeln

and VBAPVBELN = VBRPVBELN .

Read only

Former Member
0 Likes
945

Hi,

Code as follows:

SELECT posnr matnr arktx fkimg netwr

INTO CORRESPONDING FIELDS OF TABLE t_litem

FROM vbrp

WHERE vbeln = t_xhdr-vbeln.

SELECT kdmat

INTO CORRESPONDING FIELDS OF TABLE t_litem

FROM vbap <b>FOR ALL ENTRIES IN t_litem</b>

WHERE vbeln =<b>t_litem-sordno</b>.

hope this helps.

Reward if helpful.

Regards,

Sipra

Read only

Former Member
0 Likes
945

Hi,

SELECT posnr matnr arktx fkimg netwr

INTO TABLE t_litem

FROM vbrp

WHERE vbeln = t_xhdr-vbeln.

fetch II table into one more ITAB.

SELECT kdmat

INTO CORRESPONDING FIELDS OF TABLE s_litem

FROM vbap

WHERE vbeln = t_xhdr-sordno.

sort t_litem by vbeln.

loop at t_litem into wa.

read table s_item from wa1 index vbeln = wa-vbeln.

if sy-subrc = 0.

wa-kdmat = wa1-kdmat.

endif.

modify i_litem by wa transporting kdmat.

endloop.

hope this will help you.

Thanks

Shiva

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
946

Hi,

data : begin of t_vbrp occurs 0,

vbeln type vbrp-vbeln,

posnr type vbrp-posnr,

matnr type vbrp-matnr,

arktx type vbrp-arktx,

fkimg type vbrp-fkimg,

netwr type vbrp-netwr,

end of t_vbrp.

data : begin of t_vbap occurs 0,

vbeln type vbap-vbeln,

kdmat type vbap-kdmat,

end of t_vbap.

if not t_xhdr[] is initial.

SELECT vbeln posnr matnr arktx fkimg netwr

INTO TABLE t_vbrp

FROM vbrp

for all entries in t_xdhr

WHERE vbeln = t_xhdr~vbeln.

SELECT vbeln kdmat

INTO TABLE t_vbap

FROM vbap

for all entries in t_xdhr

WHERE vbeln = t_xhdr~sordno.

endif.

loop at t_xhdr.

loop at t_vbrp where key vbeln = t_xhdr-vbeln.

move-corresponding t_vbrp to t_litem.

clear t_vbap.

read table t_vbap with key vbeln = t_xhdr-sordno.

if sy-subrc eq 0.

t_vbrp-kdmat = t_litem-kdmat.

endif.

append t_litem.

endloop.

KIndly reward points by clicking the star on the left of reply,if it helps.