abapalv

ALV Grid doesn't check for cross-structure foreign keys


I have an editable ALV Grid. The line type consists of two include types, both defined in the DDIC. A field from one structure has a foreign key in the other.

When I edit that field in the ALV, the foreign key from the other structure is not checked by the standard routines.

The fieldcat references the DDIC structures (in fields ref_table and ref_field)

Method CL_GUI_ALV_GRID=>foreign_key_check() fails to find the value of the foreign key because lp_ref_table->* only contains the structure of the modified field and not the entire line.

Is this a bug or is there a special way to make sure the ALV Grid check for foreign keys ?


Solution

  • The two or more fields of the foreign key should refer to the same DDIC object. It's how F4 works in the Dynpro technology, and what ALV Grid implements.

    So, not a bug.

    If needed, create your own DDIC structure with the foreign keys, and fill REF_TABLE with the name of this DDIC structure.

    Minimal code to reproduce:

    REPORT z_demo.
    DATA go_alv   TYPE REF TO cl_gui_alv_grid.
    DATA gt_sbook TYPE TABLE OF sbook.
    
    PARAMETERS dummy.
    
    AT SELECTION-SCREEN OUTPUT.
      IF go_alv IS NOT BOUND.
        go_alv = NEW #( i_parent = cl_gui_container=>screen0 ).
        SELECT * FROM sbook UP TO 10 ROWS INTO TABLE gt_sbook.
        go_alv->set_table_for_first_display( EXPORTING i_structure_name = 'SBOOK'
                                                       is_layout        = VALUE #( edit = 'X' )
                                             CHANGING  it_outtab        = gt_sbook ).
      ENDIF.
    

    SBOOK has these foreign keys:

      @AbapCatalog.foreignKey.label : 'Prüfung gegen Flugverbindung'
      @AbapCatalog.foreignKey.screenCheck : true
      key connid : s_conn_id not null
        with foreign key spfli
          where mandt = sbook.mandt
            and carrid = sbook.carrid
            and connid = sbook.connid;
      @AbapCatalog.foreignKey.label : 'Prüfung gegen Flugtabelle'
      @AbapCatalog.foreignKey.keyType : #KEY
      @AbapCatalog.foreignKey.screenCheck : true
      key fldate : s_date not null
        with foreign key [0..*,1] sflight
          where mandt = sbook.mandt
            and carrid = sbook.carrid
            and connid = sbook.connid
            and fldate = sbook.fldate;
    

    Example: enter 23 in the CONNID field, it gets AA from the CARRID field, and issues the adequate error:

    ALV Grid foreign key check multiple fields