FM控制ALV单元格可编辑

原文地址:http://blog.sina.com.cn/s/blog_557efd260100cb6p.html

 

ECC6 测试OK!

 

REPORT ZALV_EDIT.

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.

 

"第3步:设置第六行两个单元都不能输入

SY-TABIX = 6.

LS_EDIT-FIELDNAME = 'VBELN'.

LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.

LS_EDIT-STYLE2 = SPACE.

LS_EDIT-STYLE3 = SPACE.

LS_EDIT-STYLE4 = SPACE.

LS_EDIT-MAXLEN = 10.

INSERT LS_EDIT INTO TABLE LT_EDIT.

 

LS_EDIT-FIELDNAME = 'POSNR'.

LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.

LS_EDIT-STYLE2 = SPACE.

LS_EDIT-STYLE3 = SPACE.

LS_EDIT-STYLE4 = SPACE.

LS_EDIT-MAXLEN = 6.

INSERT LS_EDIT INTO TABLE LT_EDIT.

 

INSERT LINES OF LT_EDIT INTO TABLE LS_OUTTAB-STYLE.

 

"第4步:将控制数据写到内表

 

MODIFY IT_VBAP INDEX SY-TABIX FROM LS_OUTTAB TRANSPORTING STYLE .

 

 

 

"设置第10行只有项目不能输入

 

clear LS_OUTTAB.

refresh LT_EDIT.

LS_EDIT-FIELDNAME = 'POSNR'.

LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.

LS_EDIT-STYLE2 = SPACE.

LS_EDIT-STYLE3 = SPACE.

LS_EDIT-STYLE4 = SPACE.

LS_EDIT-MAXLEN = 6.

INSERT LS_EDIT INTO TABLE LT_EDIT.

 

INSERT LINES OF LT_EDIT INTO TABLE LS_OUTTAB-STYLE.

 

SY-TABIX = 10.

 

 

"将控制数据写到内表

 

MODIFY IT_VBAP INDEX SY-TABIX FROM LS_OUTTAB TRANSPORTING STYLE .

 

"第5步:设置控制字段

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值