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

fetch data from internal table into another internal table

Former Member
0 Likes
1,436

Dear All,

i am taking name address, and email from lfa1 and adr6 table into IT_LFA1 internal table.

then i use select fro all entries and take data from BSIK table to IT_BSIK.

now i want to add :

name1, ort01, adrnr, pstlz, telf1, smtp_addr fields into IT_BSIK internal table

these all fields are in IT_LFA1.

i am using the code:

loop at it_bsik into wa_bsik.

read table it_lfa1 with key lifnr = it_bsik-lifnr into wa_lfa1 .

wa_bsiK-LIFNR = wa_LFa1-LIFNR.

wa_bsiK-name1 = wa_LFa1-name1.

wa_bsiK-ort01 = wa_LFa1-ort01.

wa_bsiK-adrnr = wa_LFa1-adrnr.

wa_bsiK-pstlz = wa_LFa1-pstlz.

wa_bsiK-TELF1 = wa_LFa1-TELF1.

wa_bsiK-SMTP_ADDR = wa_LFa1-SMTP_ADDR.

modify it_bsiK from wa_bsik.

CLEAR: wa_bsiK ,wa_LFa1.

ENDLOOP.

but in this in wa_lfa1 by default i get last record. so loop runs only for last record not for all the records.

kindly help me for the same.

With Regards,

Sulabh Agrawal

8 REPLIES 8
Read only

Former Member
0 Likes
1,242

Hi

Replace This line only....



read table it_lfa1 with key lifnr = it_bsik-lifnr into wa_lfa1.

to

read table it_lfa1 with key lifnr = wa_bsik-lifnr into wa_lfa1.

regards

Ajit

Read only

venkatesha_n
Product and Topic Expert
Product and Topic Expert
0 Likes
1,242

Hi Sulabh Agrawal,

You have used a selection criteria as a "with key lifnr = it_bsik-lifnr" where it selects only one row.

I would like to tell you one thing about this read table/select statement, it always takes a last row, becoz it was assumed that there will be a unique entry for a given KEY field.

IN your case LIFNR (Account Number of Vendor or Creditor) is the key of the table LFA1.

So, in order fetch all the rows into an internal table, you can use the function module "FI_WT_READ_LFA1" instead of a read table statement.

This might work..

Thanks,

Venky.

Read only

Former Member
0 Likes
1,242

Hi,

Thanks & regards.

Read only

former_member216611
Participant
0 Likes
1,242

HI ,

check the syntax once , in read statement you are using internal table

read table it_lfa1 with key lifnr = *it_bsik-lifnr* into wa_lfa

1

I think you are using for all entries to fetch data from data base tables so you have 2 internal tables think

as Itab1 and Itab2 ,you need to populate all these in in single internal table for this create a new internal table name as it_final

types : begin of tyt_final ,

itab1 fields

itabl2 fields

end of ty_final.

data : it_final type table of ty_final.

data : wa_final type ty_final.

Select statments.

loop at itab1 into wa_itab1.

wa_final-field = wa_itab1-field.

wa_final-field = wa_itab1-field.

wa_final-field = wa_itab1-field.

read itab2 into wa_itab2 with key field = wa_itab1.

if sy-subrc = 0.

wa_final-field = wa_itab2-field.

wa_final-field = wa_itab2-field.

endif.

append wa_final to lt_final.

endloop.

then you will get accurate data in final internal table

Regards

SIva

Read only

Former Member
0 Likes
1,242

change the code like this:

loop at it_bsik into wa_bsik.

read table it_lfa1 with key *lifnr = wa_bsik-lifnr* into wa_lfa1 .

*if sy-subrc = 0.*

wa_bsiK-LIFNR = wa_LFa1-LIFNR.

wa_bsiK-name1 = wa_LFa1-name1.

wa_bsiK-ort01 = wa_LFa1-ort01.

wa_bsiK-adrnr = wa_LFa1-adrnr.

wa_bsiK-pstlz = wa_LFa1-pstlz.

wa_bsiK-TELF1 = wa_LFa1-TELF1.

wa_bsiK-SMTP_ADDR = wa_LFa1-SMTP_ADDR.

modify it_bsiK from wa_bsik.

*endif*

CLEAR: wa_bsiK ,wa_LFa1.

ENDLOOP.

regards,

Priyanka

Read only

Former Member
0 Likes
1,242

hi all,

my problem has solved.

in my code before read statement i use :

clear WA_LFA1.

and i get all the records right in IT_BSIK.

THANKS FOR REPLY.

SULABH

Read only

0 Likes
1,242

Hi

You can also try with the above changes given by me.

Regards

Ajit

Read only

Former Member
0 Likes
1,242

SOLVED BY OWN