Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 10482

Re: Problem in editable ALV with checkbox option.

$
0
0

Hi,

 

Here is your solution.

 

* You need to make a few changes, on the FM and the parameters (Field catalog, layout, and the input table) that are being passed to the FM.

 

Changes. : We will be using FM REUSE_ALV_GRID_DISPLAY_LVC

  gt_alv_fieldcat1 TYPE lvc_t_fcat,
gw_alv_fieldcat1 TYPE lvc_s_fcat,
gd_layout1 TYPE lvc_s_layo,

 

REPORT  ZLABEL1.

 

  TABLES : ekbe,
          mseg.

 

TYPE-POOLS : slis.

 

* Add the field field_style to your input table.
TYPES: BEGINOF gtyp_data1,
           werks TYPE char4,

           kostl TYPE anlz-kostl,

           LTEXT TYPE CHAR40,

            txt50 TYPE anla-txt50,
          
flag(1),
           field_style  TYPE lvc_t_styl, "FOR DISABLE
         ENDOF gtyp_data1.

 


data :  gt_alv_fieldcat1 TYPE lvc_t_fcat,
        gw_alv_fieldcat1 TYPE lvc_s_fcat,
        gd_layout1 TYPE lvc_s_layo.

 


DATA :   I_data1     TYPEtableof gtyp_data1,
         wa_data1    LIKELINEOF i_data1.

 

 

SELECTION-SCREEN BEGINOFBLOCK b4 .

*Selection screen parameters

 

SELECTION-SCREEN ENDOFBLOCK b4.

 

 

START-OF-SELECTION.

   PERFORM get_data1. " While populating data, assuming that checkbox would be initial
   PERFORM set_specific_field_attributes. "Set all the values in column txt50 to disabled.
   PERFORM build_layout1.     " Include the field attributes setting
   PERFORM prepare_fieldcatalog1.  "Set hotspot link for checkbox, and edit for TXT50.
   PERFORM display_data1.  " Call the FM.

 


form set_specific_field_attributes .
   DATA ls_stylerow TYPE lvc_s_styl .
   DATA lt_styletab TYPE lvc_t_styl .
* Populate style variable (FIELD_STYLE) with style properties
    LOOPAT i_data1 INTO wa_data1.
     ls_stylerow-fieldname = 'TXT50' .
     ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.   " Disable input for the field initially.
     "set field to disabled
     APPEND ls_stylerow  TO wa_data1-field_style.
     MODIFY i_data1 FROM wa_data1.

   ENDLOOP.
endform.          

 


FORM build_layout1 .
  gd_layout1-stylefname = 'FIELD_STYLE'.   " This should be set in the layout.
ENDFORM

 

 


FORM prepare_fieldcatalog1 .

   DATA: lv_pos TYPEi.

*  Select assets

   lv_pos = 1.

   CLEAR gw_alv_fieldcat1.
   gw_alv_fieldcat1-fieldname = 'WERKS'.
   gw_alv_fieldcat1-tabname   = 'I_DATA1'.
   gw_alv_fieldcat1-scrtext_m = text-h12.
   gw_alv_fieldcat1-col_pos   = lv_pos.
   gw_alv_fieldcat1-outputlen = 10.
   APPEND gw_alv_fieldcat1 TO gt_alv_fieldcat1.

   lv_pos = lv_pos + 1.
   CLEAR gw_alv_fieldcat1.
   gw_alv_fieldcat1-fieldname = 'KOSTL'.
   gw_alv_fieldcat1-tabname   = 'I_DATA1'.
   gw_alv_fieldcat1-scrtext_m = text-h11.
   gw_alv_fieldcat1-col_pos   = lv_pos.
   gw_alv_fieldcat1-outputlen = 12.
   APPEND gw_alv_fieldcat1 TO gt_alv_fieldcat1.
   lv_pos = lv_pos + 1.
   CLEAR gw_alv_fieldcat1.

   lv_pos = lv_pos + 1.
   CLEAR gw_alv_fieldcat1.
   gw_alv_fieldcat1-fieldname = 'LTEXT'.
   gw_alv_fieldcat1-tabname   = 'I_DATA1'.
   gw_alv_fieldcat1-scrtext_m = text-h13.
   gw_alv_fieldcat1-col_pos   = lv_pos.
   gw_alv_fieldcat1-outputlen = 20.
   APPEND gw_alv_fieldcat1 TO gt_alv_fieldcat1.


   lv_pos = lv_pos + 1.
   CLEAR gw_alv_fieldcat1.
   gw_alv_fieldcat1-fieldname = 'TXT50'.
   gw_alv_fieldcat1-tabname   = 'I_DATA1'.
   gw_alv_fieldcat1-scrtext_m = text-h10.
   gw_alv_fieldcat1-col_pos   = lv_pos.
   gw_alv_fieldcat1-edit = 'X' "This should be set for the field that you want to toggle between editable and non editable.
   gw_alv_fieldcat1-outputlen = 45.
   APPEND gw_alv_fieldcat1 TO gt_alv_fieldcat1.

   lv_pos = lv_pos + 1.
   CLEAR gw_alv_fieldcat1.
   gw_alv_fieldcat1-fieldname = 'FLAG'.   " name of field from internal table
   gw_alv_fieldcat1-tabname = 'I_DATA1'. " internal table name
   gw_alv_fieldcat1-outputlen = 6.        " output length on screen
*  gw_alv_fieldcat1-input = 'X'.
   gw_alv_fieldcat1-checkbox = 'X'.   " print as checkbox
   gw_alv_fieldcat1-hotspot = 'X'.
   gw_alv_fieldcat1-edit = 'X'.       " make field open for input
   gw_alv_fieldcat1-scrtext_m = text-h07.      " header information
   gw_alv_fieldcat1-col_pos   = lv_pos.
   APPEND gw_alv_fieldcat1 TO gt_alv_fieldcat1.   " append field catalog internal table

ENDFORM.                    "prepare_fieldcatalog1

 

 


FORM display_data1 .
   CALLFUNCTION'REUSE_ALV_GRID_DISPLAY_LVC'
     EXPORTING
       i_callback_program      = sy-repid
       i_callback_user_command = 'USER_COMMAND'
       is_layout_lvc           = gd_layout1
       it_fieldcat_lvc         = gt_alv_fieldcat1
       i_save                  = 'X'
     TABLES
       t_outtab                = i_data1
     EXCEPTIONS
       program_error           = 1
       OTHERS                  = 2.
  endform.

 

 

* Perform your task in the user command

 


FORM user_command USING r_ucomm     LIKE sy-ucomm
                         rs_selfield TYPE slis_selfield.
   DATA ls_stylerow TYPE lvc_s_styl .
    DATA lt_styletab TYPE lvc_t_styl .


  if r_ucomm = '&IC1'" This is the fcode for hotspot link.

     readtable i_data1 into wa_data1 index rs_selfield-tabindex.
     if wa_data1-flag = ' '.   " The value for checkbox will not be stored with hotspot link, thats why the check on the previous value.
       wa_data1-flag = 'X'.
       ls_stylerow-fieldname = 'TXT50'.
       ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled.
       "set field to disabled
       delete wa_DATA1-field_style where fieldname = 'TXT50'.
       APPEND ls_stylerow  TO wa_data1-field_style.
       MODIFY i_DATA1 from wa_data1 INDEX rs_selfield-tabindex.

   else.
       clear wa_data1-flag.
       MODIFY i_DATA1 from wa_data1 INDEX rs_selfield-tabindex.
     endif.
    ENDIF.

endif.
   rs_selfield-refresh = 'X'.
ENDFORM.      

 

 

Let me know if its working fine.

 

Thanks,

Susmitha



Viewing all articles
Browse latest Browse all 10482

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>