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: 

alv-grid from 2 internal tables with identical fieldnames

Former Member
0 Kudos

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

5 REPLIES 5

Sandra_Rossi
Active Contributor

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi Sandra,

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

Danke, Grüße

Mario

0 Kudos

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

Former Member

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