*&---------------------------------------------------------------------*
*& Report YTEST_ALV_EDITABLE
*&
*&---------------------------------------------------------------------*
*& Developed by DEBESH
*& Aim : Make cell editable whereever pincode is empty
*&---------------------------------------------------------------------*
REPORT ytest_alv_editable.
TYPE-POOLS : slis.
TYPES : BEGIN OF ty_kna1,
kunnr TYPE kunnr,
land1 TYPE land1_gp,
name1 TYPE name1_gp,
name2 TYPE name2_gp,
ort01 TYPE ort01_gp,
pstlz TYPE pstlz,
field_style TYPE lvc_t_styl, " For editing
END OF ty_kna1.
DATA: lt_kna1 TYPE STANDARD TABLE OF ty_kna1,
ls_kna1 TYPE ty_kna1,
lt_fieldcat TYPE lvc_t_fcat,
ls_fieldcat TYPE lvc_s_fcat,
ls_stylerow TYPE lvc_s_styl ,
lt_styletab TYPE lvc_t_styl ,
ls_layout TYPE lvc_s_layo.
** Data extraction
SELECT kunnr land1 name1 name2 ort01 pstlz FROM kna1
INTO CORRESPONDING FIELDS OF TABLE lt_kna1 UP TO 10 ROWS.
** Field catalog for ALV
IF sy-subrc IS INITIAL.
ls_fieldcat-fieldname = 'KUNNR'.
ls_fieldcat-scrtext_m = 'Customer Number'.
ls_fieldcat-col_pos = 0.
ls_fieldcat-outputlen = 10.
ls_fieldcat-emphasize = 'X'.
ls_fieldcat-key = 'X'.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat-fieldname = 'LAND1'.
ls_fieldcat-scrtext_m = 'Location'.
ls_fieldcat-col_pos = 0.
ls_fieldcat-outputlen = 10.
ls_fieldcat-emphasize = 'X'.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat-fieldname = 'NAME1'.
ls_fieldcat-scrtext_m = 'First Name'.
ls_fieldcat-col_pos = 0.
ls_fieldcat-outputlen = 10.
ls_fieldcat-emphasize = 'X'.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat-fieldname = 'NAME2'.
ls_fieldcat-scrtext_m = 'Last Name'.
ls_fieldcat-col_pos = 0.
ls_fieldcat-outputlen = 10.
ls_fieldcat-emphasize = 'X'.
APPEND ls_fieldcat TO lt_fieldcat.
CLEAR ls_fieldcat-edit.
ls_fieldcat-fieldname = 'ORT01'.
ls_fieldcat-scrtext_m = 'City'.
ls_fieldcat-col_pos = 0.
ls_fieldcat-outputlen = 10.
ls_fieldcat-emphasize = 'X'.
ls_fieldcat-edit = 'X'. " Make coulmn Editable
APPEND ls_fieldcat TO lt_fieldcat.
CLEAR ls_fieldcat-edit.
ls_fieldcat-fieldname = 'PSTLZ'.
ls_fieldcat-scrtext_m = 'Post Code'.
ls_fieldcat-col_pos = 0.
ls_fieldcat-outputlen = 10.
ls_fieldcat-emphasize = 'X'.
APPEND ls_fieldcat TO lt_fieldcat.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
** Cell Editable
LOOP AT lt_kna1 INTO ls_kna1.
IF ls_kna1-pstlz <> space. " change condition according to your data
ls_stylerow-fieldname = 'ORT01' .
ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
APPEND ls_stylerow TO ls_kna1-field_style.
MODIFY lt_kna1 FROM ls_kna1.
** code to update database can be inserted here
ENDIF.
ENDLOOP.
ls_layout-stylefname = 'FIELD_STYLE'.
a
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
No comments:
Post a Comment