Skip to Content
0

alv-grid from 2 internal tables with identical fieldnames

May 17, 2017 at 04:33 AM

61

avatar image
Former Member

Hi all.

asuming I have two DB-tables iwth identical fieldnames

Tablename #1 : Z_HUSBAND

Fields:

  • Name
  • Street

Tablename #1 : Z_WIFE

Fields:

  • Name
  • Street

The demand is to build a ALV Grip with both tables.

There are tow requirements

  1. As the tables field can change in future and we do not want to adapt the ABAP,
  2. The z-Tables have identical fieldnames so we have to fill the ALV-Outputtable with move-corresponding
TYPES: BEGIN OF ty_hausband_wife_join,
         BEGIN OF husband,
           husband TYPE z_husband occurs 0,
         end OF husband,
         BEGIN OF wife,
           wife TYPE z_wife  occurs 0,
         end OF wife,
       data: lt_alv_columns type ty_hausband_wife_join.

My questions is now how to set up the populate the fieldcataloge dynamic an move the value of the z-tables (hausband & wife) by using move-corresponding.

Is there any dynamic workaround?

Regards

Mario

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

4 Answers

Sandra Rossi May 17, 2017 at 06:19 AM
1

First, OCCURS is obsolete.

Use nested structures. For instance, you'll obtain fields husband-name and wife-name.

The field catalog will be generated automatically with SALV.

TYPES: BEGIN OF husband_wife,
  husband TYPE z_husband,
  wife    TYPE z_wife,
END OF husband_wife.
TYPES husbands_wives TYPE TABLE OF husband_wife.

SELECT * INTO TABLE husbands_wives FROM husband INNER JOIN wife ON wife~couple_id = husband~couple_id.
Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member May 17, 2017 at 10:57 AM
1

Hi Mario,

we can generate fieldcatlog from structure by using function module 'REUSE_ALV_FIELDCATALOG_MERGE' . we need to pass the structure name i.e., globally declared structure(SE11).

Regards.

Sridhar. A

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member May 17, 2017 at 07:13 AM
0

HI Sandra,

really great work! It workes fo me.

As there could be divorced couples, I had to change the join INNER JOIN into a LEFT-JOIN

Thanks a lot!

Regards Mario

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member May 17, 2017 at 07:39 AM
0

Hi Sandra,

do you have an idea how to generate the fieldcat from the types?

Danke, Grüße

Mario

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

Use SALV. Nothing to do. You may update the column attributes using the CL_SALV_COLUMN methods (via its subclasses).

0