Skip to Content
-3

How can I merge rows of internal tables in another table?

Feb 02 at 03:02 PM

100

avatar image
Former Member

Hi!

I created an own table type:

TYPES: BEGIN OF it_mypartner,
guid TYPE crmt_object_guid,
fullname TYPE bu_name1tx,
number TYPE crmt_partner_no,
END OF it_mypartner.

DATA lt_mypartner TYPE STANDARD TABLE OF it_mypartner.
DATA ls_mypartner TYPE it_mypartner.

Now I want to fill the rows by using local tables. I tried by "move-corresponding". After moving the first row, everything worked as plannend. The GUID was moved. But after moving the fullname, the fullname was moved and the GUID is 0000...

MOVE-CORRESPONDING lt_partner TO lt_mypartner.
MOVE-CORRESPONDING lt_gotpartner TO lt_mypartner.

Obviously move-corresponding is the wrong approach. How can I do this different?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Bertrand DELVALLEE Feb 02 at 04:14 PM
0

Hello,

Your problem is that you have 2 sources of data (lt_partner and lt_gotpartner) and there is no logic decision in you code to deal with the 4 basic logical situations :

- If lt_partner field is empty and lt_gotpartner is empty then lt_mypartner field is empty (obviously)

- If lt_partner field is empty and lt_gotpartner is NOT empty then lt_mypartner field is ...? (you have to decide)

- If lt_partner field is NOT empty and lt_gotpartner is empty then lt_mypartner field is ...? (you have to decide)

- If lt_partner field is NOT empty and lt_gotpartner is NOT empty then lt_mypartner field is ...? (you have to decide)

Moreover, MOVE-CORRESPONDING statements is just a convenient way to write "Destination-field = Source-Field" for every "Field" in common. So 2 statements code is basically just :

t_mypartner-guid = lt_partner-guid.

t_mypartner-fullname = lt_partner-fullname.

t_mypartner-number = lt_partner-number.

t_mypartner-guid = lt_gotpartner-guid.

t_mypartner-fullname = lt_gotpartner-fullname.

t_mypartner-number = lt_gotpartner-number.

So.. yeah 2 move-corresponding is the wrong approach. :)

Best regards

Bertrand

Share
10 |10000 characters needed characters left characters exceeded
Horst Keller
Feb 02 at 04:03 PM
3

There are so many ways.

Read SAP's documentation about structures or internal table processing and play around ...

Especially check the example under

https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abenfor_in_itab.htm

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Maybe you guys should do some kind of ABAP lunch-and-learn event at SAP. Just sayin'...

1
Jelena Perfiljeva

Hey, we have BC400 ...

2
Sandra Rossi Feb 02 at 04:02 PM
1

You have the CORRESPONDING constructor (>= 7.40 SP 8) with the EXCEPT word, and the CL_ABAP_CORRESPONDING class (>= 7.50)

Share
10 |10000 characters needed characters left characters exceeded