Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

ALV: Editable cell in Dynamic internal table

Hi Experts,

REQUIREMENT: To make cell editable. It is not part of output internal table.

CODE:

*-Data declaration
DATA: it_newtable      TYPE REF TO data,
            it_newline        TYPE REF TO data,
            it_fldcat            TYPE lvc_t_fcat,
            wa_fldcat        TYPE lvc_s_fcat,
            wa_colno(2)    TYPE n,
            wa_layout        TYPE lvc_s_layo,
            wa_flname(20) TYPE c,
            wa_stylerow   TYPE lvc_s_styl,
            it_styletab         TYPE lvc_t_styl.

FIELD-SYMBOLS: <it_dyntable>  TYPE STANDARD TABLE,
               <fs_dyntable>,
               <fs_fldval>    TYPE ANY.

* Create fields .
  CLEAR: wa_fcat,
         wa_flname.
  wa_flname         = 'HEAD'.
  wa_fldcat-fieldname = wa_flname.
  wa_fldcat-datatype  = 'CHAR'.
  wa_fldcat-intlen    = 60.
  APPEND wa_fldcat TO it_fldcat.

 CLEAR: wa_fldcat,
         wa_flname.
  wa_flname         = 'PERCENT'.
  wa_fldcat-fieldname = wa_flname.
  wa_fldcat-datatype  = 'CHAR'.
  wa_fldcat-intlen    = 5.
  APPEND wa_fldcat TO it_fldcat.

  CLEAR: wa_fcat,
         wa_flname.
  wa_flname         = 'TOTAL'.
  wa_fldcat-fieldname = wa_flname.
  wa_fldcat-datatype  = 'CHAR'.
  wa_fldcat-intlen    = 15.
  APPEND wa_fldcat TO it_fldcat.

  CLEAR: wa_bukrs,
         wa_flname,
         wa_fldcat.
  LOOP AT it_bukrs INTO wa_bukrs.
    wa_flname         = wa_bukrs-bukrs.
    wa_fldcat-fieldname = wa_flname.
    wa_fldcat-datatype  = 'CHAR'.
    wa_fldcat-intlen    = 15.
    APPEND wa_fldcat TO it_fldcat.

    CLEAR wa_bukrs.
  ENDLOOP.

* Create dynamic internal table and assign to FS
  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = it_fldcat
    IMPORTING
      ep_table        = it_newtable.

  ASSIGN it_newtable->* TO <it_dyntable>.

* Create dynamic work area and assign to FS
  CREATE DATA it_newline LIKE LINE OF <it_dyntable>.
  ASSIGN it_newline->* TO <fs_dyntable>.

Now I am filling the 'HEAD' column with hard coded values.

 CLEAR: wa_flname,
         wa_final.

  FREE <fs_dyntable>.

  wa_flname = 'HEAD'.
* Set up fieldvalue
  ASSIGN COMPONENT wa_flname OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
  <fs_fldval> =  'I. Network Reach:'.
* Append to the dynamic internal table
  APPEND <fs_dyntable> TO <it_dyntable>.

* Set up fieldvalue
  ASSIGN COMPONENT wa_flname OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
  <fs_fldval> =  '  Cable Utilization of major cables'.
* Append to the dynamic internal table
  APPEND <fs_dyntable> TO <it_dyntable>.

* Set up fieldvalue
  ASSIGN COMPONENT wa_flname OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
  <fs_fldval> =  '  Average Utilization factor (util % x length)'.
* Append to the dynamic internal table
  APPEND <fs_dyntable> TO <it_dyntable>.

  • I want to make the cells corresponding to "Average Utilization factor (util % x length)" editable. *

FIELD CATALOG

CLEAR: wa_fldcat,
         wa_flname.

  LOOP AT it_fldcat INTO wa_fldcat.
    IF wa_fldcat-fieldname = 'HEAD'.
      wa_flname = wa_fldcat-fieldname.
      CLEAR wa_fcat.
      wa_fcat-fieldname = wa_flname.
      wa_fcat-scrtext_s = wa_flname.
      wa_fcat-outputlen = '60'.

      APPEND wa_fcat TO it_fcat.
    ELSEIF wa_fldcat-fieldname = 'PERCENT'.
      wa_flname = wa_fldcat-fieldname.
      CLEAR wa_fcat.
      wa_fcat-fieldname = wa_flname.
      wa_fcat-scrtext_s = wa_flname. 
      wa_fcat-outputlen = '5'.

      APPEND wa_fcat TO it_fcat.
    ELSE.
      wa_flname = wa_fldcat-fieldname.
      CLEAR wa_fcat.
      wa_fcat-fieldname = wa_flname.
      wa_fcat-scrtext_s = wa_flname.       wa_fcat-outputlen = '15'.

      APPEND wa_fcat TO it_fcat.
    ENDIF.
  ENDLOOP.

wa_layout-stylefname = 'FIELD_STYLE'.
  wa_layout-zebra      = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_callback_program       = sy-repid
      i_callback_pf_status_set = 'SET_PF_STATUS'
      i_callback_top_of_page   = 'TOP_OF_PAGE'
      is_layout_lvc            = wa_layout
      it_fieldcat_lvc          = it_fcat[]
      i_save                   = 'X'
    TABLES
      t_outtab                 = <it_dyntable>
    EXCEPTIONS
      program_error            = 1
      OTHERS                   = 2.

Regards,

Ajoy

Former Member
Not what you were looking for? View more on this topic or Ask a question