abap开发-alv基础实现

"先申明ALV需要的变量

TYPE-POOLS:SLIS.
DATA : LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
       LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
       LS_LAYOUT   TYPE SLIS_LAYOUT_ALV. "alv的显示样式

"定义结构:

TYPES:BEGIN OF T_MATNR,
        MATNR TYPE MARC-MATNR,
        MAKTX TYPE MAKT-MAKTX,
      END OF T_MATNR.

"定义内表以及工作区

DATA:LT_MATNR TYPE TABLE OF T_MATNR,
     LS_MATNR TYPE T_MATNR.

"把要显示的数据读取到内表中去

SELECT MARC~MATNR,MAKTX
INTO TABLE @LT_MATNR
"INTO  CORRESPONDING FIELDS OF TABLE LT_MATNR   获取的列比内表的列少时,通过这个语法进行列名的匹配,把值放入内表
FROM MARC
JOIN MAKT ON MARC~MATNR = MAKT~MATNR
WHERE MARC~MATNR = '140800743-001'.

"设置alv显示的样式

LS_LAYOUT-ZEBRA = 'X'.
LS_LAYOUT-DETAIL_POPUP = 'X'.
LS_LAYOUT-DETAIL_TITLEBAR = '详细信息'.
LS_LAYOUT-F2CODE = '&ETA'.
LS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

"设置alv要显示的列名

LS_FIELDCAT-FIELDNAME = 'MATNR'.
LS_FIELDCAT-COL_POS  = '1'.
LS_FIELDCAT-KEY = 'X'.
LS_FIELDCAT-DATATYPE = 'CHAR'.
LS_FIELDCAT-OUTPUTLEN = '18'.
LS_FIELDCAT-SELTEXT_M = '物料号'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'MAKTX'.
LS_FIELDCAT-COL_POS  = '2'.
LS_FIELDCAT-KEY = 'X'.
LS_FIELDCAT-DATATYPE = 'CHAR'.
LS_FIELDCAT-OUTPUTLEN = '100'.
LS_FIELDCAT-SELTEXT_M = '物料描述'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.

"调用alv函数方法显示

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    IS_LAYOUT     = LS_LAYOUT  "样式
    IT_FIELDCAT   = LT_FIELDCAT  "显示的列
  TABLES
    T_OUTTAB      = LT_MATNR "存储数据的内表
  EXCEPTIONS
    PROGRAM_ERROR = 1
    OTHERS        = 2.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值