abapalv

Create Fieldcatalog for INCLUDE STRUCTURE types?


I created a structure with "Types":

TYPES: BEGIN OF ty_pers_bst.
     INCLUDE STRUCTURE zieb_pers_bst.
     TYPES: lifname TYPE zieb_lieferant-lifname,
   END OF ty_pers_bst.

data: i_structure_bst_add TYPE ty_pers_bst.

I now want to use 'LVC_FIELDCATALOG_MERGE' to create a fieldcatalog based on this structure. However I get the error, that no fieldcatalog can be found.

Is there an alternative on how I can add a single field to a preexisting fieldcatalog based on my "zieb_pers_bst" DDIC-Structure, or do I have to create a new DDIC-Structure solely for this single field?


Solution

  • Try this sample:

    TYPES: BEGIN OF ty_pers_bst.
            INCLUDE STRUCTURE a900.
            TYPES: lifname TYPE lfa1-name1,
           END OF ty_pers_bst.
    
    DATA: i_structure_bst_add TYPE TABLE OF ty_pers_bst.
    
    DATA: table TYPE REF TO data.
    DATA: fcat  TYPE lvc_t_fcat.
    CREATE DATA table LIKE i_structure_bst_add.
    ASSIGN table->* TO FIELD-SYMBOL(<table>).
    TRY.
        cl_salv_table=>factory( IMPORTING r_salv_table = DATA(salv_table)
                                CHANGING  t_table      = <table> ).
        fcat = cl_salv_controller_metadata=>get_lvc_fieldcatalog(
        r_columns      = salv_table->get_columns( )
        r_aggregations = salv_table->get_aggregations( ) ).
      CATCH cx_root.
    ENDTRY.