Skip to Content
0
Former Member
Oct 24, 2008 at 11:17 AM

ALV Editable not working

889 Views

Hello Abapers,

I am not getting the desired output as per example.

I have followed all the steps as per the example but still a looser can anyone help me in this.

When I execute the program I get the following run time error

Field symbol has not been assigned.

I tried commenting the subroutine call

1} perform Change_fieldcatalogue and fetch data.

and i was getting the 2 custom container (top, bottom) on the screen output this time.

I have also created a screen 600 with all the attributes.

But i have doubt with this statement

Create a Custom container and name it CCONT and OK code as OK_CODE.

Save check and Activate the screen painter.

I hope on the layout screen the one which says custom control is only the custom container but i see that the fct code box is not highlighted then how can i assign a fctcode.

Could you plz also clear this.

Thanks in advance.

Ranjith Nambiar

Program code below

A small note about this program

&----


*& AS : ALV report which displays the contents of the table T006

*& (as a docking container in the bottom) along with the

*& editable ALV which contains the ALV fieldcatalogue table structure.

*& With the available toolbar options of the editable ALV in the output,

*& user can change the fieldcatalogue as per his requirement.

*& When the user clicks 'SUBMIT',the display of the ALV with table T006

*& gets modified and customised accordingly to the user's requirement.

&----


REPORT  ZNRD_ALV_EDITABLE.

* Structure declaration for t006
types : begin of ty_t006.
        include structure t006.
types : end of ty_t006.

* Internal table and work area declaration for t006.
data : it_t006 type standard table of ty_t006,
       wa_t006 type ty_t006.

* Declaration for ALV
data : ok_code type sy-ucomm,            " Ok code.
       it_fcat type lvc_t_fcat,          " Fieldcatalogue.
       it_fieldcat type lvc_t_fcat,      "  Fieldcatalogue for Fieldcatalogue itself.
       it_layout type lvc_s_layo.
*Declaration for toolbar functions
data : it_excl_func type ui_functions,
* Controls to display it_t006 and its fieldcatalogue
       cont_dock type ref to cl_gui_docking_container,
       cont_alvgd type ref to cl_gui_alv_grid,
* Controls to display fieldcatalogue as editable alv gridand container
       cont_cust type ref to cl_gui_custom_container,
       cont_editalvgd type ref to cl_gui_alv_grid.

initialization.
start-of-selection.

***************************************************************************************************
* Local class definition for data changed in fieldcatalogue alv
***************************************************************************************************
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.        " lcl_event_receiver definition.

***************************************************************************************************
* Local class implementation for data changed in fieldcatalogue alv
***************************************************************************************************
CLASS lcl_event_receiver implementation.
  method handle_data_changed.
  endmethod.     " handle_data_changed.
endclass.        "lcl_event_receiver implementation

* Data declaration for event receiver
data : event_receiver type ref to lcl_event_receiver.

end-of-selection.

***************************************************************************************************
* Setting the screen for alv output for table display and changed fieldcatalogue display
***************************************************************************************************

set screen 600.
*&---------------------------------------------------------------------*
*&      Module  STATUS_0600  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_0600 OUTPUT.
  SET PF-STATUS 'STATUS600'.
  SET TITLEBAR 'TITLE600'.

* Create ALV grid if doesn't exits.
if cont_dock is initial.
  perform Create_alv.
endif.

ENDMODULE.                 " STATUS_0600  OUTPUT
*&---------------------------------------------------------------------*
*&      Form  Create_alv
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM Create_alv.
* Create a docking container and dock the control at the bottom
create object cont_dock
  exporting
    dynnr = '600'
    extension = 100
    side = cl_gui_docking_container=>dock_at_bottom.
* Create ALV grid for displaying the table
create object cont_alvgd
  exporting
    i_parent = cont_dock.
* Create custom container for ALV
create object cont_cust
  exporting
    container_name = 'CCONT'.
* Create alv editable grid
 create object cont_editalvgd
 exporting
   i_parent = cont_cust.
* Register events for the editable alv
create object event_receiver.
set handler event_receiver->handle_data_changed for cont_editalvgd.
call method cont_editalvgd->register_edit_event
  exporting
    i_event_id = cl_gui_alv_grid=>mc_evt_modified.

*Building fieldcatalogue for the initial display
perform Build_fieldcatalogue changing it_fcat it_fieldcat.
* Building the fieldcatalogue after the user has changed it
perform Change_fieldcatalogue changing it_fieldcat.
* Fetch data from the table.
perform Fetch_data.

* Get excluding functions for the alv editable tool bar
  APPEND cl_gui_alv_grid=>mc_fc_loc_append_row TO it_excl_func.
  APPEND cl_gui_alv_grid=>mc_fc_loc_insert_row TO it_excl_func.
  APPEND cl_gui_alv_grid=>mc_fc_loc_cut TO it_excl_func.
  APPEND cl_gui_alv_grid=>mc_fc_sort TO it_excl_func.
  APPEND cl_gui_alv_grid=>mc_fc_sort_asc TO it_excl_func.
  APPEND cl_gui_alv_grid=>mc_fc_sort_dsc TO it_excl_func.
  APPEND cl_gui_alv_grid=>mc_fc_subtot TO it_excl_func.
  APPEND cl_gui_alv_grid=>mc_fc_sum TO it_excl_func.
  APPEND cl_gui_alv_grid=>mc_fc_graph TO it_excl_func.
  APPEND cl_gui_alv_grid=>mc_fc_info TO it_excl_func.
  APPEND cl_gui_alv_grid=>mc_fc_print TO it_excl_func.
  APPEND cl_gui_alv_grid=>mc_fc_filter TO it_excl_func.
  APPEND cl_gui_alv_grid=>mc_fc_views TO it_excl_func.
  APPEND cl_gui_alv_grid=>mc_mb_export TO it_excl_func.
  APPEND cl_gui_alv_grid=>mc_mb_sum TO it_excl_func.
  APPEND cl_gui_alv_grid=>mc_mb_sum TO it_excl_func.
  APPEND cl_gui_alv_grid=>mc_mb_paste TO it_excl_func.
  APPEND cl_gui_alv_grid=>mc_fc_find TO it_excl_func.
  APPEND cl_gui_alv_grid=>mc_fc_loc_copy  TO it_excl_func.
*Alv display for the T006 table at the bottom
  CALL METHOD cont_alvgd->set_table_for_first_display
    CHANGING
      it_outtab       = it_t006[]
      it_fieldcatalog = it_fcat[].
* optimize column width of grid displaying fieldcatalog
  it_layout-cwidth_opt = 'X'.
* Get fieldcatalog of table T006 - alv might have
* modified it after passing.
  CALL METHOD cont_alvgd->get_frontend_fieldcatalog
    IMPORTING
      et_fieldcatalog = it_fcat[].
*to Send Buffered Automation Queue to Frontend
  CALL METHOD cl_gui_cfw=>flush.
* Display fieldcatalog of table T006 in editable alv grid
  CALL METHOD cont_editalvgd->set_table_for_first_display
    EXPORTING
      is_layout            = it_layout
      it_toolbar_excluding = it_excl_func
    CHANGING
      it_outtab            = it_fcat[]
      it_fieldcatalog      = it_fieldcat[].


ENDFORM.                    " Create_alv
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0600  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0600 INPUT.

case ok_code.
  when 'SUBMIT'.
* To get the current fieldcatalogue from the front end
    call method cont_alvgd->set_frontend_fieldcatalog
    exporting
      it_fieldcatalog = it_fieldcat.
    call method cont_alvgd->refresh_table_display.
    call method cl_gui_cfw=>flush.
  when 'EXIT'.
    leave program.
endcase.
ENDMODULE.                 " USER_COMMAND_0600  INPUT

*&---------------------------------------------------------------------*
*&      Form  Build_fieldcatalogue
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_IT_FCAT  text
*      <--P_IT_FIELDCAT  text
*----------------------------------------------------------------------*
FORM Build_fieldcatalogue  CHANGING P_IT_FCAT
                                    P_IT_FIELDCAT.

* Fieldcatalog for table T006: it_fldcat
* to generate the fields automatically
  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name       = 'T006'
    CHANGING
      ct_fieldcat            = it_fieldcat[]
    EXCEPTIONS
      inconsistent_interface = 1
      program_error          = 2
      OTHERS                 = 3.
*----------------------------------------------------
* Fieldcatalog for table LVC_T_FCAT:it_fcat
*----------------------------------------------------
* Generate fieldcatalog of fieldcatalog structure.
* This fieldcatalog is used to display fieldcatalog 'it_fldcat'
* on the top of the screen.
  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name       = 'LVC_S_FCAT'
    CHANGING
      ct_fieldcat            = it_fcat[]
    EXCEPTIONS
      inconsistent_interface = 1
      program_error          = 2
      OTHERS                 = 3.

ENDFORM.                    " Build_fieldcatalogue

*&---------------------------------------------------------------------*
*&      Form  Change_fieldcatalogue
*&---------------------------------------------------------------------*
* After the user has modified the fieldcatalogue we build another fieldcat
* for the modified alv display
*      <--P_IT_FIELDCAT  text
*----------------------------------------------------------------------*
FORM Change_fieldcatalogue  CHANGING P_IT_FIELDCAT.
  DATA ls_fcat TYPE lvc_s_fcat.
  LOOP AT it_fcat 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 it_fcat FROM ls_fcat.
  ENDLOOP.
ENDFORM.                    " Change_fieldcatalogue

*&---------------------------------------------------------------------*
*&      Form  Fetch_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM Fetch_data .
  select * from t006 into table it_t006 up to 50 rows.

ENDFORM.                    " Fetch_data