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

select statement

Former Member
0 Likes
474

when you are using 2 internal table in program, you have decided to use for all entries statement to retrieve data but unfortunately there are no records in the first internal table. What will be the result? (2nd internal table contains records).

give one example.

4 REPLIES 4
Read only

Former Member
0 Likes
455

Hello.

ALL records from the second table will be recovered. To avoid this, you need to check if the table used in the FOR ALL ENTRIES is filled with some data.


  IF itab1 IS NOT INITIAL.
   SELECT * FROM sflight INTO TABLE itab2 FOR ALL ENTRIES IN itab1 WHERE carrid = itab1-carrid.
  ENDIF.

Regards,

Read only

former_member156446
Active Contributor
0 Likes
455

Hi u need to make this check .. when ever u use for all entries..

  if not i_mseg[] is initial.

    select pspnr fkokr fkstl posid stort
           from prps
           into table i_prps
           for all entries in i_mseg
           where pspnr eq i_mseg-ps_psp_pnr.

endif.

Read only

Former Member
0 Likes
455

Hi,

It's the same when you use a select options.

When you have a select options with no data and use this in a select statement, all possibilities in this select options are selected.

ex:select options so_bukrs is initial

and you have this select:

so_bukrs for t001-bukrs.

select * from t001

into table t_t001

where bukrs in so_burks.

t_t001 will have all records of table t001

The same happens with for all entries:

if you have two internal tables: itab1(initial) and itab2

and you need to select from table bsad using for all entries in itab1 into table itab2.

you will select all data in the bsad table.

It is very important check the internal table (itab1) before use any for all entries with this table.

Regards,

Fernando

Read only

Former Member
0 Likes
455

hi the for all entries is the best way to add the two tables..

suppose you want to relate the two table they must had at lease one field common ...ckeck this example ..

REPORT ZZZZ000000.

tables:mara,marc,mard,makt.

data:begin of it_mara occurs 0,

matnr like mara-matnr,

mtart like mara-mtart,

meins like mara-meins,

end of it_mara.

data:begin of it_marc occurs 0,

matnr like marc-matnr,

pstat like marc-pstat,

werks like marc-werks,

end of it_marc.

data:begin of it_mard occurs 0,

werks like mard-werks,

lgort like mard-lgort,

labst like mard-labst,

end of it_mard.

data:begin of it_final occurs 0,

matnr like mara-matnr,

mtart like mara-mtart,

meins like mara-meins,

pstat like marc-pstat,

werks like marc-werks,

lgort like mard-lgort,

labst like mard-labst,

maktx like makt-maktx,

end of it_final.

select-options:s_matnr for mara-matnr.

select matnr

mtart

meins

from mara

into table it_mara

where matnr in s_matnr.

if not it_mara[] is initial.

select matnr

pstat

werks

from marc

into table it_marc

for all entries in it_mara

where matnr = it_mara-matnr.

if not it_marc[] is initial.

select werks

lgort

labst

from mard

into table it_mard

for all entries in it_marc

where werks = it_marc-werks.

endif.

endif.

loop at it_mara.

it_final-matnr = it_mara-matnr.

it_final-mtart = it_mara-mtart.

it_final-meins = it_mara-meins.

read table it_marc with key matnr = it_mara-matnr.

it_final-werks = it_marc-werks.

it_final-pstat = it_marc-pstat.

read table it_mard with key werks = it_marc-werks.

it_final-lgort = it_mard-lgort.

it_final-labst = it_mard-labst.

if sy-subrc = 0.

select maktx from makt into it_final-maktx where matnr = it_final-matnr.

endselect.

endif.

append it_final.

endloop.

loop at it_final.

write:/ it_final-matnr under 'material',

it_final-mtart under 'material type',

it_final-meins under 'unit of measure',

it_final-werks under 'plant' ,

it_final-pstat under 'status',

it_final-lgort under 'storage loc',

it_final-labst under 'stock',

it_final-maktx.

endloop.

regards,

venkat