Application Development and Automation 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: 
Read only

ALV: Editable cell in Dynamic internal table

Former Member
0 Likes
4,995

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

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

8 REPLIES 8
Read only

Former Member
0 Likes
2,724

This message was moderated.

Read only

Former Member
0 Likes
2,724

Hi friend,

I think your requirement is creating an editable ALV.

There are many links available is SDN also many sample code available in SDN Wiki for your requirement please check that.

This is a simple wiki post which contains the steps for creating editable ALV and saving it.

Link: [Editable Alv|http://wiki.sdn.sap.com/wiki/display/Snippets/ALV-Editingandsavingtheeditedvaluesin+Database(OOPS)]

If your requirement is different please revert back to me i will help you.

Thanks,

Sri Hari

Read only

0 Likes
2,724

Hi Srihari,

I have searched on net before posting in SDN.

What all I found is:

include style in output internal table. make style ENABLE/ DISBALE. Modify the output internal table and display.

But, in my case, I am using a field symbol. And, there are no output internal tables. I have few hardcoded rows. Against 1 such row, cells should be editable!

Read only

0 Likes
2,724

HI,

Can't you pass EDIT = 'X' to the editable field through your fieldcatalog. Anyway you have that particular field in your fieldcatalog right.

Regards,

Selva M

Read only

Former Member
0 Likes
2,724

Hi,

Please populate CELLTAB field to the (dynamic/normal) internal table

u201C This field will be required to control the ALV settings at cell level.

and the above shared link will help you.

and give condition if the cell is correspond to "Average Utilization factor (util % x length)"

use class metthodsCELLTAB-style = cl_gui_alv_grid=>mc_style_disabled.

Read only

sudheer_ganti
Explorer
2,724

Hi Guys,

Even I faced the same problem and I searched for solution. Nowhere I get. Finally I solved myself.

Its been very late reply but it will be useful for further who may encounter the same problem.

Here is my solution.

For normal internal table which we will be used as output internal table we can pass the cell style as celltab and we can do CELLTAB-style = cl_gui_alv_grid=>mc_style_disabled. and CELLTAB-style = cl_gui_alv_grid=>mc_style_enabled.

But for Dynamic internal table which in some times needs to be prepared on field catalog which itself is dynamic.In this case if you attach cellstyle to the field catalog it will be appeared as a seperate column in output ALV. To over come this we need to prepare the field catalog with desired fields and then for one row you need to append the Cell tab row. Like here

*->Editing only one Row

     LOOP AT gt_fcat_dir INTO gs_fcat_dir.

       gs_field_dir-name = gs_fcat_dir-fieldname.

       gs_field_dir-type ?= cl_abap_datadescr=>describe_by_name( 'LVC_S_FCAT-FIELDNAME' ).

       APPEND gs_field_dir TO gt_field_dir.

     ENDLOOP.

     gs_field_dir-name = 'CELLTAB'.

     gs_field_dir-type ?= cl_abap_datadescr=>describe_by_name( 'LVC_T_STYL' ).

     APPEND gs_field_dir TO gt_field_dir.


Then create dynamic internal table and structure based on field catalog


*->Creating Dynamic Structure based on Field Catalog

     CALL METHOD cl_abap_structdescr=>create

       EXPORTING

         p_components = gt_field_dir

         p_strict     = cl_abap_structdescr=>false

       RECEIVING

         p_result     = gs_struct_descr_dir.

**Create table type based on the structure

     CALL METHOD cl_abap_tabledescr=>create

       EXPORTING

         p_line_type  = gs_struct_descr_dir

         p_table_kind = cl_abap_tabledescr=>tablekind_std

       RECEIVING

         p_result     = gt_tab_descr_dir.

     CREATE DATA gt_table_data_dir TYPE HANDLE gt_tab_descr_dir.

     ASSIGN gt_table_data_dir->* TO <gt_table_dir>.

     CREATE DATA gs_line_data_dir TYPE HANDLE gs_struct_descr_dir.

     ASSIGN gs_line_data_dir->* TO <fs_dyntable_dir>.


so now the creation of dynamic internal table with field catalog is finished.

Now in the loop of output internal table assign the component structure of CELLTAB to that ITAB.

Loop at gt_outtab into gs_outtab.

*->Adding only one cell that will be editable

       ASSIGN COMPONENT 'CELLTAB' OF STRUCTURE <fs_dyntable_dir> TO <gt_comp_dir>.

       REFRESH <gt_comp_dir>.

       IF sy-subrc = 0 AND gs_outtab-field1 IS NOT INITIAL.

         LOOP AT gt_fcat_dir INTO gs_fcat_dir.            "#EC CI_NESTED

           gs_style_dir-fieldname = gs_fcat_dir-fieldname.

           gs_style_dir-style = cl_gui_alv_grid=>mc_style_disabled.

           INSERT gs_style_dir INTO TABLE <gt_comp_dir>.

         ENDLOOP.

       ENDIF.

endloop.


Do not forget to assign layout.

  gs_layout_dir-stylefname = 'CELLTAB'.

CALL METHOD go_grid_dir->register_edit_event

       EXPORTING

         i_event_id = cl_gui_alv_grid=>mc_evt_modified.

     CALL METHOD go_grid_dir->set_table_for_first_display

       EXPORTING

         is_layout                     = gs_layout_dir

       CHANGING

         it_outtab                     = <gt_table_dir> "gt_et_afcu

         it_fieldcatalog               = gt_fcat_dir

       EXCEPTIONS

         invalid_parameter_combination = 1

         program_error                 = 2

         too_many_lines                = 3

         OTHERS                        = 4.

output will be like


Hence the problem solved.

Cheers Happy ABAPing.

Read only

0 Likes
2,724

hi,

can you tell me what is the data declaration for

gs_field_dir

gt_field_dir

Read only

0 Likes
2,724

    Hi Santosh,

FYI...

DATA:          gt_field_dir                 TYPE cl_abap_structdescr=>component_table,

                    gt_field_indir               TYPE cl_abap_structdescr=>component_table,

                    gs_field_dir                 LIKE LINE OF gt_field_dir,

                    gs_field_indir              LIKE LINE OF gt_field_dir.