*&---------------------------------------------------------------------*
*& Report ZPPR0024
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zppr0024.
TYPE-POOLS: slis.
*- Fieldcatalog
DATA: it_fieldcat TYPE lvc_t_fcat.
DATA: x_fieldcat TYPE lvc_s_fcat.
DATA: x_layout TYPE lvc_s_layo.
"第1步:用操作具体单元的是否可编辑的内表和工作区
DATA: ls_edit TYPE lvc_s_styl,
lt_edit TYPE lvc_t_styl,
gr_alvgrid TYPE REF TO cl_gui_alv_grid .
"第2步:在内表定义添加字段,用于控制具体行的具体单元是否可编辑
DATA: BEGIN OF it_vbap OCCURS 0,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
style TYPE lvc_t_styl, "FOR DISABLE
END OF it_vbap.
DATA: ls_outtab LIKE LINE OF it_vbap.
SELECT vbeln posnr
UP TO 100 ROWS
INTO CORRESPONDING FIELDS OF TABLE it_vbap
FROM vbap.
DATA:l_pos TYPE i VALUE 1.
CLEAR: l_pos.
l_pos = l_pos + 1.
x_fieldcat-seltext = 'VBELN'.
x_fieldcat-fieldname = 'VBELN'.
x_fieldcat-tabname = 'ITAB'.
x_fieldcat-col_pos = l_pos.
x_fieldcat-edit = 'X'.
x_fieldcat-outputlen = '10'.
x_fieldcat-ref_field = 'VBELN'.
x_fieldcat-ref_table = 'VBAK'.
APPEND x_fieldcat TO it_fieldcat.
CLEAR x_fieldcat.
l_pos = l_pos + 1.
x_fieldcat-seltext = 'POSNR'.
x_fieldcat-fieldname = 'POSNR'.
x_fieldcat-tabname = 'ITAB'.
x_fieldcat-col_pos = l_pos.
x_fieldcat-edit = 'X'.
x_fieldcat-outputlen = '5'.
APPEND x_fieldcat TO it_fieldcat.
CLEAR x_fieldcat.
l_pos = l_pos + 1.
********************************************************
PERFORM set_status USING 6 'VBELN'.
PERFORM set_status USING 6 'POSNR'.
INSERT LINES OF lt_edit INTO TABLE ls_outtab-style.
MODIFY it_vbap INDEX 6 FROM ls_outtab TRANSPORTING style .
********************************************************
x_layout-stylefname = 'STYLE'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
is_layout_lvc = x_layout
it_fieldcat_lvc = it_fieldcat
TABLES
t_outtab = it_vbap[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
FORM SET_STATUS_DISABLED USING index TYPE sy-tabix fieldname TYPE lvc_s_styl-fieldname .
sy-tabix = index.
ls_edit-fieldname = fieldname.
ls_edit-style = cl_gui_alv_grid=>mc_style_disabled.
ls_edit-style2 = space.