Skip to Content
avatar image
Former Member

alv-grid from 2 internal tables with identical fieldnames

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • May 17, 2017 at 06:19 AM

    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.
    
    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 17, 2017 at 10:57 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 17, 2017 at 07:13 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 17, 2017 at 07:39 AM

    Hi Sandra,

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

    Danke, Grüße

    Mario

    Add comment
    10|10000 characters needed characters exceeded