Application Development 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 Table .....

Former Member
0 Kudos

Hi all,

I have one basic dought related to the read table statment, i went through the document but could not clarify

can antbody help me to understand this logic....

for example ...

i am reteriving the records from table i_bkpf.

now usinfg all entries addition i will select he record from bseg into i_bseg for all entries in i_bkpf.

once i get a record.

loop at i_bkpf.

read table i_bseg with key bukrs = i_bkpf-bukrs

belnr = i_bkpf-belnr

gjhar = i_bkpf-gjahr.

if sy-subrc eq 0.

here if i want to move the data...in some other internal table...i have to mobe it from i_bkpf or i_bseg.

for example i am moving from i_bseg table in some other table.

itab-bukrs = i_bseg-bukrs.

itab-gjahr = i_bseg-gjahr.

itab-dmbtr = i_bseg-dmbtr.

now in this cae condition is satisfy in forst line while using read statment..

it wont go for further line...........

normally in this situation how we have to handle.............

can we do like that..please advice

loop at i_bseg.

read table i_bkpf with key .......

?????

Thanks in advance for ur advice..........

6 REPLIES 6

Former Member
0 Kudos

Amit,

A have a few points to address :

1. When you use for all entires addition in your select statement, you`ll have to use a where addition. Thus you can restrict your selection from table <b>BSEG</b> based on <b>BUKRS,BELNR and GJAHR.</b>

2. If you write your select query as mentioned above, the table <i>i_bseg</i> will have entries which will correlate the <i>entries in i_bkpf</i>.

3. The fact is <i>bkpf is the header table</i> and <i>bseg is the item table,</i> hence for every record in i_bkpf you might one or more records in i_bseg ( for one doc. will have several line items).

4. Thus you`ve desired details of a document in its line item table ( here its i_bseg). Now you`ll have to decide which records you would want to have in your third internal table.

5. If you would want the <i>header</i> details :

<b>

append lines of i_bkpf to i_xxxx.

</b>

6. If you would want the <i>line items</i> to be moved :

<b>append lines of i_bseg to i_xxxx.</b>

7. Apart from this, u can also use <u>move-corresponding</u> syntax.

The information will serve your need.

Reward points if convinced with the answer.

Regards

former_member186741
Active Contributor
0 Kudos

you can do this, it might not be very efficient if you have lots of records. Try to declare our table as 'keyed',

something like

data i_bseg type sorted table of bseg with unique key bukrs belnr gjahr.:

loop at i_bkpf.

loop at i_bseg where bukrs = i_bkpf-bukrs

and belnr = i_bkpf-belnr

and gjahr = i_bkpf-gjahr.

endloop.

endloop.

Former Member
0 Kudos

HI AMIT

For this use innerLOOP insted of READ.

Example

loop at i_bkpf

loop at i_bseg where bukrs = i_bkpf-bukrs

and belnr = i_bkpf-belnr

and gjhar = i_bkpf-gjahr.

Here move what ever values you want.

endloop.

endloop.

But be carefull innerLoop is performens issue

and one more thing is that your are woking with table like bseg and bkpf.This table generaly have large number records.so be carefull with where condition try to bring in lot of keys in where condition

Regards

saradhi

Former Member
0 Kudos

Hello all,

my question is if i want to put the records from bkpf and bseg in third internal table......

and i am using the read table statment if my condition is satisfy in first or second line i table i_bseg..

it won't move further.........

as i am taking data from base table bkpf then from bseg for all entries in i_bkpf........

after that

in place of i_bkpf can i do like that..

loop at i_bseg.

read table i_bkpf ..........

is it okay ????

0 Kudos

loop at i_bkpf.

loop at i_bseg where bukrs = i_bkpf-bukrs

belnr = i_bkpf-belnr

gjhar = i_bkpf-gjahr.

*--this loops for all the item records of BSEG for each BKPF record

if sy-subrc eq 0.

itab-bukrs = i_bseg-bukrs.

itab-gjahr = i_bseg-gjahr.

itab-dmbtr = i_bseg-dmbtr.

*--what fields you want you can populate to ITAB

append itab.

endif.

endloop.

endloop.

will solve your problem

added comments

Message was edited by: Srikanth Kidambi

0 Kudos

Hi Amit,

The suggestion which u proposed looks fine.

loop at i_bseg.

read table i_bkpf ..........

endloop.

Here, as u have only 1 entry in i_bkpf for each entry in i_bseg, u can fetch all the desired records in a new internal table.

And this holds good only when the table which u r looping at has not more than 1 corresponding entry in the table from which the records are read.

i.e....

loop at i_table1. "(Item details)

read table i_table2. "(Header detais)

endloop.