cancel
Showing results for 
Search instead for 
Did you mean: 

Update key fields

alanfljesus
Explorer
0 Kudos

I implemented an ALV grid for table maintenance and I intend to implement a functionality where key fields are blocked from updates to existing records. However, I want these key fields to be editable when a new row is inserted. I used the LVC_FIELDCATALOG_MERGE function to generate my field catalog.
The CPF is a personal identification number, so it is a key field, it needs to be entered, but blocked for updates

 

METHOD run_collaborator.
    CHECK go_custom_control IS INITIAL.

    go_custom_control = NEW cl_gui_custom_container( 'CC_COLLAB' ).

    go_grid = NEW cl_gui_alv_grid( i_parent = go_custom_control ).

    CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
      EXPORTING
        i_structure_name = 'ZEFSCT_002'
      CHANGING
        ct_fieldcat      = gt_fieldcat.

    LOOP AT gt_fieldcat ASSIGNING FIELD-SYMBOL(<fs_fieldcat>).
      CASE <fs_fieldcat>-fieldname.
        WHEN 'ID'.
        WHEN 'CPF'.
          <fs_fieldcat>-outputlen = 15.
          <fs_fieldcat>-edit      = 'X'.
        WHEN OTHERS.
          <fs_fieldcat>-no_out = 'X'.
      ENDCASE.
    ENDLOOP.

    go_grid->set_table_for_first_display( 
EXPORTING i_structure_name = 'ZEFSCT_002'
          is_layout        = gs_layout
CHANGING  it_fieldcatalog  = gt_fieldcat
          it_outtab        = lo_business_collaborator->lt_collaborator ).

    SET HANDLER handle_data_changed FOR go_grid.

    refresh( ).
ENDMETHOD.
METHOD handle_data_changed.
    ASSIGN er_data_changed->mp_mod_rows->* TO FIELD-SYMBOL(<modified_rows>).
    ASSIGN er_data_changed->mt_deleted_rows TO FIELD-SYMBOL(<deleted_rows>).

    CASE lv_screen.
      WHEN 'RUN_COLLABORATOR'.
        lo_business_collaborator->set_collaborator( <modified_rows> ).
        lo_business_collaborator->delete_collaborator( <deleted_rows> ).
      WHEN OTHERS.
    ENDCASE.
  ENDMETHOD.

 

 

 

 

 

 

 

 

 

Accepted Solutions (0)

Answers (0)