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 not updating IN Sselect between loop-endloop

Former Member
0 Likes
929

I have 2 qs.

1. I tried using for all entries in itab and vbapvbeln = itab-vbeln AND vbapposnr = itab-posnr . I could see the data in itab in debug mode and using write statement with wa. However,

SELECT f1 f2 ....

INTO CORRESPONDING FIELDS OF TABLE itab

FROM ( vbap INNER JOIN vbak ON vbapvbeln = vbakvbeln )

for all entries in itab

WHERE

vbapvbeln = itab-vbeln AND vbapposnr = itab-posnr

endselect.

is throwing an error saying itab does not have the component vbeln. This should work as per the

http://help.sap.com/erp2005_ehp_03/helpdata/EN/fc/eb3a1f358411d1829f0000e829fbfe/frameset.htm

2. I opted to try select in a loop at itab to overcome problem 1. Here the internal table itab2 is storing only the last entry. I tried clearing it but no use.

Please help me with any way you can. Thanks in advance.

DATA: BEGIN OF wa,

vbeln TYPE vbap-vbeln,

posnr TYPE vbap-posnr,

.......

END OF wa,

itab LIKE TABLE OF wa.

itab2 like table of wa.

LOOP AT itab INTO wa.

.....checked by printing itab values .. and data is as expected to meet the where conditions below ****

SELECT f1 f2 ....

INTO CORRESPONDING FIELDS OF TABLE itab2

FROM ( vbap INNER JOIN vbak ON vjoin condition)

WHERE

vbapvbeln = wa-vbeln AND vbapposnr = wa-posnr

ENDLOOP.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
883

Hi,

there seems to be no syntax error in your code. please confirm that the declaration of ITAB table contains the vbeln field and the spell is correct.

Regards,

Nirmal

7 REPLIES 7
Read only

Former Member
0 Likes
883

Hi Suzzie,

Try it in this way.

First populate tow internal table say it_vbak and it_vbap

which is a join of table vbap and vbak.


select f1 f2 into corresponding fields of table it_vbap
for all entries in itab where vbeln = itab-vbeln

select f1 f2 into corresponding fields of table it_vbap
for all entries in itab where vbeln = itab-vbeln
Loop at itab.
  read table it_vbap with key vbeln = itab-vbeln
                                          posnr = itab-posnr.
  if sy-subrc = 0.
   " assign value into the workarea of the table.
endif 
read table it_vbak with key vbeln = itab-vbeln.
  if sy-subrc = 0.
   " assign value into the workarea of the table.
endif 
"append final table.
endloop.

Thanks,

Chidanand

Read only

Former Member
0 Likes
883

- the into table and comparision table should not be the same. (which u have kept as ITAB)

- and in my opinion a join should be like


data: itab2 type STANDARD TABLE OF vbap WITH HEADER LINE, 
      itab type STANDARD TABLE OF vbak WITH HEADER LINE.

select * from vbak into TABLE itab up to 10 rows.

SELECT c~vbeln d~posnr
      INTO CORRESPONDING FIELDS OF TABLE itab2
      FROM ( VBAK AS c
             INNER JOIN VBAP AS d ON c~vbeln = d~vbeln )
      FOR ALL ENTRIES IN itab
      WHERE c~vbeln = itab-vbeln.

this is ofcoz just an example as i dont know exactly from where u are getting itab values.

thanks,

Somu.

Read only

Former Member
0 Likes
883

try this way..

SELECT vbak~vbeln
             vbap~posnr
             vbap~matnr       "i am not sure what fields you are using..?
INTO CORRESPONDING FIELDS OF TABLE itab
FROM ( vbap INNER JOIN vbak ON vbap~vbeln = vbak~vbeln )
for all entries in itab
WHERE
vbap~vbeln = itab-vbeln AND vbap~posnr = itab-posnr.

Read only

Former Member
0 Likes
884

Hi,

there seems to be no syntax error in your code. please confirm that the declaration of ITAB table contains the vbeln field and the spell is correct.

Regards,

Nirmal

Read only

0 Likes
883

SELECT vbak~vbeln

vbap~posnr

vbap~matnr "i am not sure what fields you are using..?

INTO CORRESPONDING FIELDS OF TABLE itab

FROM ( vbap INNER JOIN vbak ON vbapvbeln = vbakvbeln )

for all entries in itab

WHERE

vbapvbeln = itab-vbeln AND vbapposnr = itab-posnr.

Have tried this with both the followng declarations of itab but still no luck.

data: begin of itab occurs 0,

vbeln type vbap-vbelnr,

posnr type vbap-posnr,

end of itab.

and

data: begin of wa,

vbeln type vbap-vbelnr,

posnr type vbap-posnr,

end of wa,

itab like table of wa.

Have also tried using separete itabs in "into corresponding" and in where condition.

I am not able to succesfully do with "for all entries" and with loop-endloop, only the last value is showing up.

BTW does the solution depend on the number of tables in join? I am actually using 3 tables for join ..

Have to try out the following suggestion.

select f1 f2 into corresponding fields of table it_vbap

for all entries in itab where vbeln = itab-vbeln

select f1 f2 into corresponding fields of table it_vbap

for all entries in itab where vbeln = itab-vbeln

Loop at itab.

read table it_vbap with key vbeln = itab-vbeln

posnr = itab-posnr.

if sy-subrc = 0.

" assign value into the workarea of the table.

endif

read table it_vbak with key vbeln = itab-vbeln.

if sy-subrc = 0.

" assign value into the workarea of the table.

endif

"append final table.

endloop.

Read only

0 Likes
883

Make sure to use APPEND in loop-endloop option.

Regards,

Nirmal

Read only

0 Likes
883

Append using work are did the trick in loop-endloop