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

Read from Internal Table

Former Member
0 Likes
1,128

Hello,

i have this littel code and for the moment i get a littel problem with this internal table.

I use this code in an infoset. Thats why not all tables are showen here.


TABLES: VBEP,
                VBUP.
DATA:   zamount like vbep-bmeng.
DATA:    BEGIN OF i_tab,
           besta   like vbup-besta,
           vbeln   like vbak-vbeln,
           posnr   like vbap-posnr,
           bmeng   like vbep-bmeng,
           etenr   like vbep-etenr,
         END OF i_tab.
DATA: itab LIKE STANDARD TABLE OF i_tab WITH HEADER LINE.

CLEAR itab.
SELECT besta vbeln posnr INTO CORRESPONDING FIELDS OF itab FROM  vbup
       WHERE  VBELN  = vbak-vbeln
       AND    POSNR  = vbap-posnr
       AND    BESTA  <> 'C'.
ENDSELECT.
SELECT bmeng etenr INTO CORRESPONDING FIELDS OF itab FROM vbep
      WHERE VBELN =  itab-vbeln
      AND   POSNR =  itab-posnr.
ENDSELECT.
clear zamount.
LOOP AT itab INTO i_tab.
   zamount = i_tab-bmeng + zamount.
ENDLOOP.

If i debug this i can see the right values in the itab table. But at the LOOP the value from the table is not

assign to "zamount".

Where is my error?

kind regards,

Bernhard

7 REPLIES 7
Read only

mvoros
Active Contributor
0 Likes
877

Hi,

you selects are wrong. You select line and store it into header of the table itab. So you first select select one line but it does not insert into table itab. The second select overwrites values in the header table but again it does not insert any row into table itab. After that you do loop over empty table so obviously you don't get any values. Don't use tables with header lines if you don't have to. It's obsolete and as you can see it's confusing. I would suggest to chan ge it to


DATA line LIKE i_tab.

SELECT SINGLE besta vbeln posnr INTO CORRESPONDING FIELDS OF line FROM  vbup
       WHERE  VBELN  = vbak-vbeln
       AND    POSNR  = vbap-posnr
       AND    BESTA   'C'.
IF sy-subrc EQ 0.
  APPEND line TO itab.
ENDIF.

CLEAR line.
SELECT SINGLE bmeng etenr INTO CORRESPONDING FIELDS OF line FROM vbep
      WHERE VBELN =  itab-vbeln
      AND   POSNR =  itab-posnr.
IF sy-subrc EQ 0.
  APPEND line TO itab.
ENDIF.

Cheers

Read only

Former Member
0 Likes
877

Hello Martin,

i changed my code to this. If i execute the Query i get the right result. But if i debug it i saw that i now get two lines in ITAB.

What must i do that i onyl get one line out of my selection in ITAB?


TABLES: VBEP,
        VBUP.
DATA:   zamount like vbep-bmeng.
TYPES:    BEGIN OF i_tab,
           besta   like vbup-besta,
           vbeln   like vbak-vbeln,
           posnr   like vbap-posnr,
           bmeng   like vbep-bmeng,
           etenr   like vbep-etenr,
         END OF i_tab.

DATA: itab TYPE TABLE OF i_tab,
      line LIKE LINE OF itab,
      wa Type i_tab.

SELECT besta vbeln posnr FROM  vbup INTO CORRESPONDING FIELDS OF line
       WHERE  VBELN  = vbak-vbeln
       AND    POSNR  = vbap-posnr
       AND    BESTA  <> 'C'.
IF sy-subrc EQ 0.
  APPEND line TO itab.
ENDIF.
ENDSELECT.

CLEAR line.
IF sy-subrc EQ 0.
SELECT bmeng etenr FROM vbep INTO CORRESPONDING FIELDS OF line
      FOR ALL ENTRIES in itab
      WHERE VBELN =  itab-vbeln
      AND   POSNR =  itab-posnr.
IF sy-subrc EQ 0.
  APPEND line TO itab.
ENDIF.
ENDSELECT.
ENDIF.

clear zamount.
LOOP AT itab into wa.
   zamount = wa-bmeng + zamount.
ENDLOOP.

Thanks for you help.

kind regards,

Bernhard

Read only

0 Likes
877

Get rid of the endselects.


try this

TABLES: VBEP,
        VBUP.
DATA:   zamount like vbep-bmeng.
data:in type i.
TYPES:    BEGIN OF i_tab,
           besta   like vbup-besta,
           vbeln   like vbak-vbeln,
           posnr   like vbap-posnr,
           bmeng   like vbep-bmeng,
           etenr   like vbep-etenr,
         END OF i_tab.

TYPES:    BEGIN OF i_tab1,
           vbeln   like vbak-vbeln,
           posnr   like vbap-posnr,
           bmeng   like vbep-bmeng,
           etenr   like vbep-etenr,
         END OF i_tab1.
 
DATA: itab TYPE TABLE OF i_tab,
      itab1 type table of i_tab1,
      line2 type i_tab1.

field-symbols:<fs> type i_tab.
 
SELECT besta vbeln posnr FROM  vbup INTO table itab
       WHERE  VBELN  = vbak-vbeln
       AND    POSNR  = vbap-posnr
       AND    BESTA   'C'.
 
IF sy-subrc EQ 0.
sort itab by vbeln posnr.
SELECT vbeln posnr sum( bmeng ) etenr FROM vbep INTO table i_itab1
      FOR ALL ENTRIES in itab
      WHERE VBELN =  itab-vbeln
      AND   POSNR =  itab-posnr
      group by vbeln posnr etenr.
if sy-subrc = 0.
sort i_itab1 by vbeln posnr.
endif.
ENDIF.
 

LOOP AT itab assigning <fs>.
read table i_itab1 into line2 with key vebln = line-vbeln
			    posnr = line-posnr
			    binary serach.
if sy-subrc = 0.
<fs>-bmeng = line2-bmeng.
endif.
ENDLOOP.

Read only

Former Member
0 Likes
877

Put a break point at loop at itab into wa.

and there put one f5 and see , whter value is coming to wa.

if it is coming then chk wht is the value for the field u need of wa.

then u can do the addition .

and after adding cklear wa also.

Regards

Read only

Former Member
0 Likes
877

Bernhard,

you have a problem with your select statement..

1st error:

INTO CORRESPONDING FIELDS OF itab "here it should be FIELDS OF TABLE itab

2nd error.

your selecting logic is not correct.. dont you think so.. please check the below sample

select x y z from table a into corr fields of table itab_A where .... "=>here we are fetching to itab_a
if sy-subrc =0."=>records found.
  select d e f from table b into corr fields of table itab_B 
                     FOR ALL ENTRIES in itab_A "==>using the entries in A
                     WHERE x = itab_A-x. "etc etc
" now loop.
   loop at itab_B into is_b.
     sum = sum + is_b-d.
   endloop.
 endif.

use this sample logic in your code

Read only

Former Member
0 Likes
877

Use Zamount = zamount + itab-<fieldname>

Read only

Former Member
0 Likes
877

Hi!

try the collect

Thanks,

Raul Natu

Edited by: Raul Natu on Jun 18, 2010 11:46 AM