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: 

Internal Tables Appending

Former Member
0 Kudos
71

Hi Gurus,

Please solve this problem.

I have 2 internal tables 1) test_hdr

2) test_txt

Both fields have common field 'CHANGENR'.

I have to restrict test_txt table based on test_hdr.

Delete all test_txt records if test_hdr changenr is not equal to test_txt changenr

test_hdr

Changenr Field 2 Field 3 Field 4

111

222

333

Test_txt

Changenr Field 6 Field 7 Field 8

111

111

111

111

555

555

666

o/p internal table

Changenr Field 6 Field 7 Field 8

111

111

111

111

Declared another internal table(delta_txt) and filling this 3rd table if condition satisfies.

Is there any easy way of doing this, without using 3rd table. Directly deleting from the second table?

Thanks & Regrds,

Radha.

6 REPLIES 6

Former Member
0 Kudos
46

Hi,

Just use as of below.

loop at test_txt into wa_txt.

read table test_hdr into wa_hdr with key changenr = wa_txt-changenr.

if sy-subrc <> 0.

delete text_txt from wa_txt.

endif.

endloop.

Reward if useful.

Thanks,

Muthu.

0 Kudos
46

Hi Gurus,

Please solve this problem.

I have 2 internal tables 1) test_hdr

2) test_txt

Both fields have common field 'CHANGENR'.

I have to restrict test_txt table based on test_hdr.

Delete all test_txt records if test_hdr changenr is not equal to test_txt changenr

test_hdr having fields and data like this

Changenr Field 2 Field 3 Field 4

111

222

333

Test_txt having fields and data like this

Changenr Field 6 Field 7 Field 8

111

111

111

111

555

555

666

i want internal table with this data

o/p internal table: this is actually internal table 'Test_txt ' but we delete the record otherthan records in test_hdr .

this is the final output.

Changenr Field 6 Field 7 Field 8

111

111

111

111

i want this output in internal table 'Test_txt ' with deleting other records.

Declared another internal table(delta_txt) and filling this 3rd table if condition satisfies.

Is there any easy way of doing this, without using 3rd table. Directly deleting from the second table?

Thanks & Regrds,

Radha.

0 Kudos
46

Hi Radha,

Have you tried the code which I have given in above comments, It will work as what you are expecting, the test_txt will get modified accordingly.

Thanks,

Muthu.

vinod_vemuru2
Active Contributor
0 Kudos
46

Hi Radhakrishna,

check below logic.

LOOP AT test_hdr.

READ TABLE test_txt INTO wa WITH KEY changnr = test_hdr-changnr.

check sy-subrc IS INITIAL.

APPEND wa TO test_txt_final.

endloop.

Here instead of deleting the records inside loop it is better to append to new table in performance.

Also if u r getting data into text_txt from only one database tabel then select data by using FORR ALL ENTRIES in test_hdr.

eg:

If not test_hdr[] is initial.

Select f1 f2 ..

INTO TABLE test_txt

FROM dbtab

FOR ALL ENTRIES IN test_hdr

WHERE changnr EQ test_hdr-changnr

AND rest of ur conditions.

endif.

Thanks,

Vinod.

Edited by: Vinod Kumar Vemuru on May 21, 2008 3:35 PM

0 Kudos
46

I have those two internal tables.

but i want 2nd internal table dada by comparing 1st internal table without using 3rd internal table

please give me solution for this.

Former Member
0 Kudos
46

Hi,

Are you selecting the data for the txt table?

If yes and that is after you have got the data in the hdr table then you can simply use the

SELECT for all entries extension and reduce your task.

select * from <table name> into table_txt

for all entries in table_hdr

where changnr = table_hdr-changenr.

regards

taher