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: 

Help with basic ABAP code (merge internal tables, sort of...)

Former Member
0 Kudos

Hello,

Can someone please help write some basic code for a Basis guy with limited ABAP knowledge?

Should be some easy points for an experienced ABAPer!

-


I have identicaly structured internal tables I_A and I_B and I_C which have already been filled by function models I called.

How will I code the following?:

I want to read all the data of I_A into a new internal table I_MASTER (structured the same as I_A,I_B and I_C).

Then I want to read I_B and:

1)Update I_MASTER with NEW records

2)Update existing records if the value of field MYFIELD in I_B is smaller than the value of MYFIELD in I_MASTER.

Then I want to read I_C and:

1)Update I_MASTER with NEW records

2)Update existing records if the value of field MYFIELD in I_C is smaller than the value of MYFIELD in I_MASTER.

Let me know if I can provide anymore information.

Thanks in advance for you help!

Adriaan

Message was edited by: Adriaan

Message was edited by: Adriaan

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Look to t-code ABAPDOCU. It contains many good examples to assist you.

5 REPLIES 5

Former Member
0 Kudos

Look to t-code ABAPDOCU. It contains many good examples to assist you.

Former Member
0 Kudos

Hi Adriaan ,

I want to read all the data of I_A into a new internal table I_MASTER (structured the same as I_A,I_B and I_C).

<b>i_master[] = i_a[] .</b>

loop at i_b .

read table i_master with key myfiled < i_b-myfield .

if sy-subrc = 0 .

append i_master from i_b .

endif.

endloop.

loop at i_c .

read table i_master with key myfiled < i_c-myfield .

if sy-subrc = 0 .

append i_master from i_c .

endif.

endloop.

Let me know if this helped .

Regards,

Varun .

Message was edited by: varun sonu

0 Kudos

Varun,

Thank you very much!

This is sort of what I am looking for.

Just a question:

Will this code also add records from I_B and I_C not existing yet in I_MASTER to I_MASTER?

0 Kudos

Hi,

I guess it will not add those records .

Regards,

Varun .

Former Member
0 Kudos

Hi Adriaan. You could try this:

I_MASTER [] = I_A [].

loop at I_B.

found = 'N'.

loop at I_MASTER where KEY = I_B-KEY.

if I_B-MYFIELD < I_MASTER-MYFIELD.

I_MASTER-MYFIELD = I_B-MYFIELD.

endif.

found = 'Y'.

endloop.

if found = 'N'.

append I_B to I_MASTER.

endif.

endloop.

loop at I_C.

found = 'N'.

loop at I_MASTER where KEY = I_C-KEY.

if I_C-MYFIELD < I_MASTER-MYFIELD.

I_MASTER-MYFIELD = I_C-MYFIELD.

endif.

found = 'Y'.

endloop.

if found = 'N'.

append I_C to I_MASTER.

endif.

endloop.

I hope this helps.

- April King