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: 

editable records in ALV List output

Sultanuddin
Explorer
0 Kudos

How to make some records editable in output of ALV report

1 ACCEPTED SOLUTION

Former Member
0 Kudos

You can find the code in this program <b>'BCALV_FIELDCAT_TEST'</b>


*&---------------------------------------------------------------------*
*& Report  BCALV_FIELDCAT_TEST                                         *
*&                                                                     *
*&---------------------------------------------------------------------*
* This report allows to modify the fieldcatalog of a corresponding
* output table and to view the effects of your changes directly.
* Note that for some changes you need to newly display the whole
* ALV Grid Control, e.g., DDIC-Fields are read only the first time
* you call SET_READY_FOR_FIRST_DISPLAY.
* Note also that not all scenarios can be tested since the output
* table does not comprise all fields to test available features
* of the fieldcatalog. Copy this program and extend the output
* table accordingly if you want to test such a special feature.
* (The field CARRNAME in 'gt_sflight' was added to test field REF_FIELD
* and TXT_FIELD of the fieldcatalog - see what happens if you
* calculate subtotals by carrier-id).

report  bcalvt_fieldcatalog           .

data: ok_code               type sy-ucomm,
      save_ok_code          type sy-ucomm,
* fieldcatalog for output table
      gt_fieldcat           type lvc_t_fcat,
* fieldcatalog for fieldcatalog itself:
      gt_fcatfcat           type lvc_t_fcat,
      gs_fcatlayo           type lvc_s_layo.

* Output table
data: begin of gt_sflight occurs 0.
data: carrname type s_carrname.
        include structure sflight.
data: end of gt_sflight.
data: g_max type i value 100.
data: g_all type c value SPACE.

* Controls to display gt_sflight and corresponding fieldcatalog
data: g_docking type ref to cl_gui_docking_container,
      g_alv     type ref to cl_gui_alv_grid.

data: g_custom_container type ref to cl_gui_custom_container,
      g_editable_alv     type ref to cl_gui_alv_grid.

**************************************************************
* LOCAL CLASS Definition
**************************************************************
class lcl_event_receiver definition.
  public section.
    methods handle_data_changed
      for event data_changed of cl_gui_alv_grid
      importing er_data_changed.
endclass.
*---------------------------------------------------------
class lcl_event_receiver implementation.
  method handle_data_changed.
* at the time being, no checks are made...

  endmethod.
endclass.

data: event_receiver type ref to lcl_event_receiver.

*****************************************************************
end-of-selection.

  set screen 100.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module status_0100 output.
  set pf-status 'BASIC'.
  set titlebar 'BASICTITLE'.
* create ALV Grid Control in the first run
  if g_docking is initial.
    perform create_and_init_controls.
  endif.

endmodule.                             " STATUS_0100  OUTPUT


*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module user_command_0100 input.

  save_ok_code = ok_code.
  clear ok_code.
  case save_ok_code.
    when 'SUBMIT'.
* set the frontend fieldcatalog
* ATTENTION: DDIC-Fields are not updated using this method!
* (see 'RESTART')
      call method g_alv->set_frontend_fieldcatalog
           exporting
             it_fieldcatalog = gt_fieldcat.
      call method g_alv->refresh_table_display.
      call method cl_gui_cfw=>flush.

    when 'RESTART'.
* Destroy the control currently visible and display it again
* using the changed fieldcatalog.
      perform restart_sflight.

    when '&ALL'.
      perform switch_visibility.

  endcase.

endmodule.                             " USER_COMMAND_0100  INPUT

*&---------------------------------------------------------------------*
*&      Form  CREATE_AND_INIT_CONTROLS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form create_and_init_controls.

  create object g_docking
      exporting
           dynnr = '100'
           extension = 150
           side = cl_gui_docking_container=>dock_at_bottom.

  create object g_alv
      exporting
           i_parent = g_docking.

  create object g_custom_container
      exporting
           container_name = 'CC_0100_FIELDCAT'.

  create object g_editable_alv
      exporting
           i_parent = g_custom_container.

* register events
  create object event_receiver.
  set handler event_receiver->handle_data_changed for g_editable_alv.

  call method g_editable_alv->register_edit_event
                exporting
                   i_event_id = cl_gui_alv_grid=>mc_evt_modified.

  perform build_fieldcatalogs changing gt_fieldcat gt_fcatfcat.
  perform modify_fieldcatalog changing gt_fcatfcat.

  perform select_data.                 "CHANGING gt_sflight

  call method g_alv->set_table_for_first_display
          changing
               it_outtab       = gt_sflight[]
               it_fieldcatalog = gt_fieldcat[].

* optimize column width of grid displaying fieldcatalog
  gs_fcatlayo-cwidth_opt = 'X'.

* Get fieldcatalog of table sflight - alv might have
* modified it after passing.
  call method g_alv->get_frontend_fieldcatalog
            importing et_fieldcatalog = gt_fieldcat[].
  call method cl_gui_cfw=>flush.

* Display fieldcatalog of table sflight:
  call method g_editable_alv->set_table_for_first_display
          exporting
               is_layout       = gs_fcatlayo
          changing
               it_outtab       = gt_fieldcat[]
               it_fieldcatalog = gt_fcatfcat[].


* register events
  create object event_receiver.
  set handler event_receiver->handle_data_changed for g_editable_alv.

endform.                               " CREATE_AND_INIT_CONTROLS
*&---------------------------------------------------------------------*
*&      Form  restart_sflight
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form restart_sflight.
  data: ls_fieldcat type lvc_s_fcat.

* free g_docking and thus g_alv
  call method g_docking->free.
  clear g_docking.
  clear g_alv.

* create new instances
  create object g_docking
      exporting
           dynnr = '100'
           extension = 150
           side = cl_gui_docking_container=>dock_at_bottom.

  create object g_alv
      exporting
           i_parent = g_docking.
*.......................................................................
* This is an _internal_ method to invalidate all fields in the fieldcat
  loop at gt_fieldcat into ls_fieldcat.
    clear ls_fieldcat-tech_comp.
    modify gt_fieldcat from ls_fieldcat.
  endloop.
*.......................................................................

* Newly display the list with current fieldcatalog.
  call method g_alv->set_table_for_first_display
          changing
               it_outtab       = gt_sflight[]
               it_fieldcatalog = gt_fieldcat.

* Get fieldcatalog - it might be changed by ALV in the last call
  call method g_alv->get_frontend_fieldcatalog
          importing
               et_fieldcatalog = gt_fieldcat[].

  call method g_editable_alv->refresh_table_display.
  call method cl_gui_cfw=>flush.

endform.                               " restart_sflight
*&---------------------------------------------------------------------*
*&      Form  select_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form select_data.
  data: lt_sflight type table of sflight with header line,
        ls_scarr type scarr.

* select data of sflight
  select * from sflight into table lt_sflight up to g_max rows.

* copy data to gt_sflight and update CARRNAME
  loop at lt_sflight.
    move-corresponding lt_sflight to gt_sflight.
    select single * from scarr into ls_scarr
       where carrid = gt_sflight-carrid.
    gt_sflight-carrname = ls_scarr-carrname.
    append gt_sflight.
  endloop.

endform.                               " select_data
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOGS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GT_FIELDCAT  text
*      <--P_GT_FCATFCAT  text
*----------------------------------------------------------------------*
form build_fieldcatalogs changing p_fieldcat type lvc_t_fcat
                                  p_fcatfcat type lvc_t_fcat.

  data: ls_fcat     type lvc_s_fcat.

*......................................
* Fieldcatalog for table SFLIGHT: p_fieldcat
*.......................................
* generate fieldcatalog automatically

  call function 'LVC_FIELDCATALOG_MERGE'
      exporting
           i_structure_name       = 'SFLIGHT'
*         I_CLIENT_NEVER_DISPLAY = 'X'
       changing
            ct_fieldcat            = p_fieldcat[]
*    EXCEPTIONS
*         INCONSISTENT_INTERFACE = 1
*         PROGRAM_ERROR          = 2
*         OTHERS                 = 3
            .
  if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.
*..........................................................
* shift all column positions to the right except for MANDT
  loop at p_fieldcat into ls_fcat.
    if ls_fcat-fieldname ne 'MANDT'.
      add 1 to ls_fcat-col_pos.
      if ls_fcat-fieldname = 'CARRID'.
        ls_fcat-txt_field = 'CARRNAME'."link CARRNAME to CARRID
      endif.
      modify p_fieldcat from ls_fcat.
    endif.
  endloop.

*.........................................................
* create a new line for CARRNAME in p_fieldcat
  clear ls_fcat.
  ls_fcat-fieldname = 'CARRNAME'.
  ls_fcat-ref_table = 'SCARR'.
  ls_fcat-col_pos = 1.
* insert new line before CARRID (do not forget MANDT!).
  insert ls_fcat into p_fieldcat index 1.

*----------------------------------------------------
* Fieldcatalog for table LVC_T_FCAT:p_fcatfcat
*----------------------------------------------------
* Generate fieldcatalog of fieldcatalog structure.
* This fieldcatalog is used to display fieldcatalog 'p_fieldcat'
* on the top of the screen.

  call function 'LVC_FIELDCATALOG_MERGE'
      exporting
           i_structure_name       = 'LVC_S_FCAT'
*         I_CLIENT_NEVER_DISPLAY = 'X'
       changing
            ct_fieldcat            = p_fcatfcat[]
*    EXCEPTIONS
*         INCONSISTENT_INTERFACE = 1
*         PROGRAM_ERROR          = 2
*         OTHERS                 = 3
            .
  if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.
*..............................
* Hide all fields that are not documented (valid for release 4.6A)
  perform hide_fields changing p_fcatfcat.


endform.                               " BUILD_FIELDCATALOGS

*&---------------------------------------------------------------------*
*&      Module  EXIT_PROGRAM  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module exit_program input.
  leave program.

endmodule.                             " EXIT_PROGRAM  INPUT

*&---------------------------------------------------------------------*
*&      Form  MODIFY_FIELDCATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GT_FCATFCAT  text
*----------------------------------------------------------------------*
form modify_fieldcatalog changing p_fcatfcat type lvc_t_fcat.
  data ls_fcat type lvc_s_fcat.

  loop at p_fcatfcat into ls_fcat.
    ls_fcat-coltext = ls_fcat-fieldname.
    ls_fcat-edit = 'X'.

    if ls_fcat-fieldname = 'COL_POS' or ls_fcat-fieldname = 'FIELDNAME'.
      ls_fcat-key = 'X'.
    endif.

    modify p_fcatfcat from ls_fcat.
  endloop.

endform.                               " MODIFY_FIELDCATALOG
*-------------------------------------------------------------------
form hide_fields changing p_fieldcat type lvc_t_fcat.
  data: ls_fcat type lvc_s_fcat.
* Only show documented fields of fieldcatalog.
* For a documentation choose "Help->Application Help" in the menu.
  loop at p_fieldcat into ls_fcat.
    if not (
         ls_fcat-fieldname eq 'CFIELDNAME'
    or   ls_fcat-fieldname eq 'COL_POS'
    or   ls_fcat-fieldname eq 'COLDDICTXT'
    or   ls_fcat-fieldname eq 'COLTEXT'
    or   ls_fcat-fieldname eq 'CURRENCY'
    or   ls_fcat-fieldname eq 'DD_OUTLEN'
    or   ls_fcat-fieldname eq 'DECIMALS_O'
    or   ls_fcat-fieldname eq 'DECMLFIELD'
    or   ls_fcat-fieldname eq 'DO_SUM'
    or   ls_fcat-fieldname eq 'DRAGDROPID'
    or   ls_fcat-fieldname eq 'EDIT_MASK'
    or   ls_fcat-fieldname eq 'EMPHASIZE'
    or   ls_fcat-fieldname eq 'EXPONENT'
    or   ls_fcat-fieldname eq 'FIELDNAME'
    or   ls_fcat-fieldname eq 'HOTSPOT'
    or   ls_fcat-fieldname eq 'ICON'
    or   ls_fcat-fieldname eq 'INTLEN'
    or   ls_fcat-fieldname eq 'INTTYPE'
    or   ls_fcat-fieldname eq 'JUST'
    or   ls_fcat-fieldname eq 'KEY'
    or   ls_fcat-fieldname eq 'LOWERCASE'
    or   ls_fcat-fieldname eq 'LZERO'
    or   ls_fcat-fieldname eq 'NO_OUT'
    or   ls_fcat-fieldname eq 'NO_SIGN'
    or   ls_fcat-fieldname eq 'NO_SUM'
    or   ls_fcat-fieldname eq 'NO_ZERO'
    or   ls_fcat-fieldname eq 'OUTPUTLEN'
    or   ls_fcat-fieldname eq 'QFIELDNAME'
    or   ls_fcat-fieldname eq 'QUANTITY'
    or   ls_fcat-fieldname eq 'REF_FIELD'
    or   ls_fcat-fieldname eq 'REF_TABLE'
    or   ls_fcat-fieldname eq 'REPREP'
    or   ls_fcat-fieldname eq 'REPTEXT'
    or   ls_fcat-fieldname eq 'ROLLNAME'
    or   ls_fcat-fieldname eq 'ROUND'
    or   ls_fcat-fieldname eq 'ROUNDFIELD'
    or   ls_fcat-fieldname eq 'SCRTEXT_L'
    or   ls_fcat-fieldname eq 'SCRTEXT_M'
    or   ls_fcat-fieldname eq 'SCRTEXT_S'
    or   ls_fcat-fieldname eq 'SELDDICTXT'
    or   ls_fcat-fieldname eq 'SELTEXT'
    or   ls_fcat-fieldname eq 'SP_GROUP'
    or   ls_fcat-fieldname eq 'SYMBOL'
    or   ls_fcat-fieldname eq 'TECH'
    or   ls_fcat-fieldname eq 'TIPDDICTXT'
    or   ls_fcat-fieldname eq 'TOOLTIP'
    or   ls_fcat-fieldname eq 'TXT_FIELD' ).

      ls_fcat-tech = 'X'.
    endif.
    modify p_fieldcat from ls_fcat.

  endloop.
endform.

*----------------------------------------------------------------------
 form switch_visibility.
 data:  lt_fcatfcat type lvc_t_fcat,
        ls_fcat type lvc_s_fcat.

 call method g_editable_alv->get_frontend_fieldcatalog
             importing ET_FIELDCATALOG = lt_fcatfcat.

 if not g_all is initial.
     perform hide_fields changing lt_fcatfcat.
     g_all = SPACE.
 else.
    loop at lt_fcatfcat into ls_fcat.

       if ls_fcat-tech eq 'X'.
           ls_fcat-tech = SPACE.
           ls_fcat-no_out = 'X'.
           modify lt_fcatfcat from ls_fcat.
       endif.
    endloop.
    g_all = 'X'.

 endif.

 call method g_editable_alv->set_frontend_fieldcatalog
            exporting it_fieldcatalog = lt_fcatfcat.
 call method g_editable_alv->refresh_table_display.

endform.

2 REPLIES 2

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

You might want to look at the example programs. Any program which begins with BCALV_EDIT*

REgards,

Rich Heilman

Former Member
0 Kudos

You can find the code in this program <b>'BCALV_FIELDCAT_TEST'</b>


*&---------------------------------------------------------------------*
*& Report  BCALV_FIELDCAT_TEST                                         *
*&                                                                     *
*&---------------------------------------------------------------------*
* This report allows to modify the fieldcatalog of a corresponding
* output table and to view the effects of your changes directly.
* Note that for some changes you need to newly display the whole
* ALV Grid Control, e.g., DDIC-Fields are read only the first time
* you call SET_READY_FOR_FIRST_DISPLAY.
* Note also that not all scenarios can be tested since the output
* table does not comprise all fields to test available features
* of the fieldcatalog. Copy this program and extend the output
* table accordingly if you want to test such a special feature.
* (The field CARRNAME in 'gt_sflight' was added to test field REF_FIELD
* and TXT_FIELD of the fieldcatalog - see what happens if you
* calculate subtotals by carrier-id).

report  bcalvt_fieldcatalog           .

data: ok_code               type sy-ucomm,
      save_ok_code          type sy-ucomm,
* fieldcatalog for output table
      gt_fieldcat           type lvc_t_fcat,
* fieldcatalog for fieldcatalog itself:
      gt_fcatfcat           type lvc_t_fcat,
      gs_fcatlayo           type lvc_s_layo.

* Output table
data: begin of gt_sflight occurs 0.
data: carrname type s_carrname.
        include structure sflight.
data: end of gt_sflight.
data: g_max type i value 100.
data: g_all type c value SPACE.

* Controls to display gt_sflight and corresponding fieldcatalog
data: g_docking type ref to cl_gui_docking_container,
      g_alv     type ref to cl_gui_alv_grid.

data: g_custom_container type ref to cl_gui_custom_container,
      g_editable_alv     type ref to cl_gui_alv_grid.

**************************************************************
* LOCAL CLASS Definition
**************************************************************
class lcl_event_receiver definition.
  public section.
    methods handle_data_changed
      for event data_changed of cl_gui_alv_grid
      importing er_data_changed.
endclass.
*---------------------------------------------------------
class lcl_event_receiver implementation.
  method handle_data_changed.
* at the time being, no checks are made...

  endmethod.
endclass.

data: event_receiver type ref to lcl_event_receiver.

*****************************************************************
end-of-selection.

  set screen 100.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module status_0100 output.
  set pf-status 'BASIC'.
  set titlebar 'BASICTITLE'.
* create ALV Grid Control in the first run
  if g_docking is initial.
    perform create_and_init_controls.
  endif.

endmodule.                             " STATUS_0100  OUTPUT


*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module user_command_0100 input.

  save_ok_code = ok_code.
  clear ok_code.
  case save_ok_code.
    when 'SUBMIT'.
* set the frontend fieldcatalog
* ATTENTION: DDIC-Fields are not updated using this method!
* (see 'RESTART')
      call method g_alv->set_frontend_fieldcatalog
           exporting
             it_fieldcatalog = gt_fieldcat.
      call method g_alv->refresh_table_display.
      call method cl_gui_cfw=>flush.

    when 'RESTART'.
* Destroy the control currently visible and display it again
* using the changed fieldcatalog.
      perform restart_sflight.

    when '&ALL'.
      perform switch_visibility.

  endcase.

endmodule.                             " USER_COMMAND_0100  INPUT

*&---------------------------------------------------------------------*
*&      Form  CREATE_AND_INIT_CONTROLS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form create_and_init_controls.

  create object g_docking
      exporting
           dynnr = '100'
           extension = 150
           side = cl_gui_docking_container=>dock_at_bottom.

  create object g_alv
      exporting
           i_parent = g_docking.

  create object g_custom_container
      exporting
           container_name = 'CC_0100_FIELDCAT'.

  create object g_editable_alv
      exporting
           i_parent = g_custom_container.

* register events
  create object event_receiver.
  set handler event_receiver->handle_data_changed for g_editable_alv.

  call method g_editable_alv->register_edit_event
                exporting
                   i_event_id = cl_gui_alv_grid=>mc_evt_modified.

  perform build_fieldcatalogs changing gt_fieldcat gt_fcatfcat.
  perform modify_fieldcatalog changing gt_fcatfcat.

  perform select_data.                 "CHANGING gt_sflight

  call method g_alv->set_table_for_first_display
          changing
               it_outtab       = gt_sflight[]
               it_fieldcatalog = gt_fieldcat[].

* optimize column width of grid displaying fieldcatalog
  gs_fcatlayo-cwidth_opt = 'X'.

* Get fieldcatalog of table sflight - alv might have
* modified it after passing.
  call method g_alv->get_frontend_fieldcatalog
            importing et_fieldcatalog = gt_fieldcat[].
  call method cl_gui_cfw=>flush.

* Display fieldcatalog of table sflight:
  call method g_editable_alv->set_table_for_first_display
          exporting
               is_layout       = gs_fcatlayo
          changing
               it_outtab       = gt_fieldcat[]
               it_fieldcatalog = gt_fcatfcat[].


* register events
  create object event_receiver.
  set handler event_receiver->handle_data_changed for g_editable_alv.

endform.                               " CREATE_AND_INIT_CONTROLS
*&---------------------------------------------------------------------*
*&      Form  restart_sflight
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form restart_sflight.
  data: ls_fieldcat type lvc_s_fcat.

* free g_docking and thus g_alv
  call method g_docking->free.
  clear g_docking.
  clear g_alv.

* create new instances
  create object g_docking
      exporting
           dynnr = '100'
           extension = 150
           side = cl_gui_docking_container=>dock_at_bottom.

  create object g_alv
      exporting
           i_parent = g_docking.
*.......................................................................
* This is an _internal_ method to invalidate all fields in the fieldcat
  loop at gt_fieldcat into ls_fieldcat.
    clear ls_fieldcat-tech_comp.
    modify gt_fieldcat from ls_fieldcat.
  endloop.
*.......................................................................

* Newly display the list with current fieldcatalog.
  call method g_alv->set_table_for_first_display
          changing
               it_outtab       = gt_sflight[]
               it_fieldcatalog = gt_fieldcat.

* Get fieldcatalog - it might be changed by ALV in the last call
  call method g_alv->get_frontend_fieldcatalog
          importing
               et_fieldcatalog = gt_fieldcat[].

  call method g_editable_alv->refresh_table_display.
  call method cl_gui_cfw=>flush.

endform.                               " restart_sflight
*&---------------------------------------------------------------------*
*&      Form  select_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form select_data.
  data: lt_sflight type table of sflight with header line,
        ls_scarr type scarr.

* select data of sflight
  select * from sflight into table lt_sflight up to g_max rows.

* copy data to gt_sflight and update CARRNAME
  loop at lt_sflight.
    move-corresponding lt_sflight to gt_sflight.
    select single * from scarr into ls_scarr
       where carrid = gt_sflight-carrid.
    gt_sflight-carrname = ls_scarr-carrname.
    append gt_sflight.
  endloop.

endform.                               " select_data
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOGS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GT_FIELDCAT  text
*      <--P_GT_FCATFCAT  text
*----------------------------------------------------------------------*
form build_fieldcatalogs changing p_fieldcat type lvc_t_fcat
                                  p_fcatfcat type lvc_t_fcat.

  data: ls_fcat     type lvc_s_fcat.

*......................................
* Fieldcatalog for table SFLIGHT: p_fieldcat
*.......................................
* generate fieldcatalog automatically

  call function 'LVC_FIELDCATALOG_MERGE'
      exporting
           i_structure_name       = 'SFLIGHT'
*         I_CLIENT_NEVER_DISPLAY = 'X'
       changing
            ct_fieldcat            = p_fieldcat[]
*    EXCEPTIONS
*         INCONSISTENT_INTERFACE = 1
*         PROGRAM_ERROR          = 2
*         OTHERS                 = 3
            .
  if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.
*..........................................................
* shift all column positions to the right except for MANDT
  loop at p_fieldcat into ls_fcat.
    if ls_fcat-fieldname ne 'MANDT'.
      add 1 to ls_fcat-col_pos.
      if ls_fcat-fieldname = 'CARRID'.
        ls_fcat-txt_field = 'CARRNAME'."link CARRNAME to CARRID
      endif.
      modify p_fieldcat from ls_fcat.
    endif.
  endloop.

*.........................................................
* create a new line for CARRNAME in p_fieldcat
  clear ls_fcat.
  ls_fcat-fieldname = 'CARRNAME'.
  ls_fcat-ref_table = 'SCARR'.
  ls_fcat-col_pos = 1.
* insert new line before CARRID (do not forget MANDT!).
  insert ls_fcat into p_fieldcat index 1.

*----------------------------------------------------
* Fieldcatalog for table LVC_T_FCAT:p_fcatfcat
*----------------------------------------------------
* Generate fieldcatalog of fieldcatalog structure.
* This fieldcatalog is used to display fieldcatalog 'p_fieldcat'
* on the top of the screen.

  call function 'LVC_FIELDCATALOG_MERGE'
      exporting
           i_structure_name       = 'LVC_S_FCAT'
*         I_CLIENT_NEVER_DISPLAY = 'X'
       changing
            ct_fieldcat            = p_fcatfcat[]
*    EXCEPTIONS
*         INCONSISTENT_INTERFACE = 1
*         PROGRAM_ERROR          = 2
*         OTHERS                 = 3
            .
  if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.
*..............................
* Hide all fields that are not documented (valid for release 4.6A)
  perform hide_fields changing p_fcatfcat.


endform.                               " BUILD_FIELDCATALOGS

*&---------------------------------------------------------------------*
*&      Module  EXIT_PROGRAM  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module exit_program input.
  leave program.

endmodule.                             " EXIT_PROGRAM  INPUT

*&---------------------------------------------------------------------*
*&      Form  MODIFY_FIELDCATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GT_FCATFCAT  text
*----------------------------------------------------------------------*
form modify_fieldcatalog changing p_fcatfcat type lvc_t_fcat.
  data ls_fcat type lvc_s_fcat.

  loop at p_fcatfcat into ls_fcat.
    ls_fcat-coltext = ls_fcat-fieldname.
    ls_fcat-edit = 'X'.

    if ls_fcat-fieldname = 'COL_POS' or ls_fcat-fieldname = 'FIELDNAME'.
      ls_fcat-key = 'X'.
    endif.

    modify p_fcatfcat from ls_fcat.
  endloop.

endform.                               " MODIFY_FIELDCATALOG
*-------------------------------------------------------------------
form hide_fields changing p_fieldcat type lvc_t_fcat.
  data: ls_fcat type lvc_s_fcat.
* Only show documented fields of fieldcatalog.
* For a documentation choose "Help->Application Help" in the menu.
  loop at p_fieldcat into ls_fcat.
    if not (
         ls_fcat-fieldname eq 'CFIELDNAME'
    or   ls_fcat-fieldname eq 'COL_POS'
    or   ls_fcat-fieldname eq 'COLDDICTXT'
    or   ls_fcat-fieldname eq 'COLTEXT'
    or   ls_fcat-fieldname eq 'CURRENCY'
    or   ls_fcat-fieldname eq 'DD_OUTLEN'
    or   ls_fcat-fieldname eq 'DECIMALS_O'
    or   ls_fcat-fieldname eq 'DECMLFIELD'
    or   ls_fcat-fieldname eq 'DO_SUM'
    or   ls_fcat-fieldname eq 'DRAGDROPID'
    or   ls_fcat-fieldname eq 'EDIT_MASK'
    or   ls_fcat-fieldname eq 'EMPHASIZE'
    or   ls_fcat-fieldname eq 'EXPONENT'
    or   ls_fcat-fieldname eq 'FIELDNAME'
    or   ls_fcat-fieldname eq 'HOTSPOT'
    or   ls_fcat-fieldname eq 'ICON'
    or   ls_fcat-fieldname eq 'INTLEN'
    or   ls_fcat-fieldname eq 'INTTYPE'
    or   ls_fcat-fieldname eq 'JUST'
    or   ls_fcat-fieldname eq 'KEY'
    or   ls_fcat-fieldname eq 'LOWERCASE'
    or   ls_fcat-fieldname eq 'LZERO'
    or   ls_fcat-fieldname eq 'NO_OUT'
    or   ls_fcat-fieldname eq 'NO_SIGN'
    or   ls_fcat-fieldname eq 'NO_SUM'
    or   ls_fcat-fieldname eq 'NO_ZERO'
    or   ls_fcat-fieldname eq 'OUTPUTLEN'
    or   ls_fcat-fieldname eq 'QFIELDNAME'
    or   ls_fcat-fieldname eq 'QUANTITY'
    or   ls_fcat-fieldname eq 'REF_FIELD'
    or   ls_fcat-fieldname eq 'REF_TABLE'
    or   ls_fcat-fieldname eq 'REPREP'
    or   ls_fcat-fieldname eq 'REPTEXT'
    or   ls_fcat-fieldname eq 'ROLLNAME'
    or   ls_fcat-fieldname eq 'ROUND'
    or   ls_fcat-fieldname eq 'ROUNDFIELD'
    or   ls_fcat-fieldname eq 'SCRTEXT_L'
    or   ls_fcat-fieldname eq 'SCRTEXT_M'
    or   ls_fcat-fieldname eq 'SCRTEXT_S'
    or   ls_fcat-fieldname eq 'SELDDICTXT'
    or   ls_fcat-fieldname eq 'SELTEXT'
    or   ls_fcat-fieldname eq 'SP_GROUP'
    or   ls_fcat-fieldname eq 'SYMBOL'
    or   ls_fcat-fieldname eq 'TECH'
    or   ls_fcat-fieldname eq 'TIPDDICTXT'
    or   ls_fcat-fieldname eq 'TOOLTIP'
    or   ls_fcat-fieldname eq 'TXT_FIELD' ).

      ls_fcat-tech = 'X'.
    endif.
    modify p_fieldcat from ls_fcat.

  endloop.
endform.

*----------------------------------------------------------------------
 form switch_visibility.
 data:  lt_fcatfcat type lvc_t_fcat,
        ls_fcat type lvc_s_fcat.

 call method g_editable_alv->get_frontend_fieldcatalog
             importing ET_FIELDCATALOG = lt_fcatfcat.

 if not g_all is initial.
     perform hide_fields changing lt_fcatfcat.
     g_all = SPACE.
 else.
    loop at lt_fcatfcat into ls_fcat.

       if ls_fcat-tech eq 'X'.
           ls_fcat-tech = SPACE.
           ls_fcat-no_out = 'X'.
           modify lt_fcatfcat from ls_fcat.
       endif.
    endloop.
    g_all = 'X'.

 endif.

 call method g_editable_alv->set_frontend_fieldcatalog
            exporting it_fieldcatalog = lt_fcatfcat.
 call method g_editable_alv->refresh_table_display.

endform.