ABAP FUNCTION ALV简单屏幕红绿灯显示代码分享

如有不好之处请留言,希望追求完美。

接触ABAP时间 第55天

最简单添加展示的红绿灯:直接定义一个C类型接收即可,也可以和字符串拼接使用。

ICON_GREEN_LIGHT.

ICON_YELLOW_LIGHT.

ICON_RED_LIGHT.

" 定义数据类型
TYPES : BEGIN OF WA_ITAB,
          VBELN TYPE VBRK-VBELN,  "发票编号
          GEWEI TYPE C,
          LIGHT TYPE C LENGTH 10, "红路灯接收
        END OF WA_ITAB.

DATA : WA_VBRK   TYPE WA_ITAB,
       WA_OUTPUT LIKE TABLE OF WA_VBRK WITH HEADER LINE.

" 引入宏方式添加屏幕显示字段
DEFINE ADD_FIELD.
  WA_FIELD-FIELDNAME      = &1.
  WA_FIELD-REPTEXT_DDIC   = &2.
  WA_FIELD-KEY            = &3.
  WA_FIELD-NO_ZERO        = &4.
  APPEND WA_FIELD TO IT_FIELD.
END-OF-DEFINITION.

" 声明屏幕显示字段需要的变量
DATA: IT_FIELD TYPE SLIS_T_FIELDCAT_ALV.
DATA: WA_FIELD TYPE SLIS_FIELDCAT_ALV.

"两种写法均可
DATA: IT_FIELD1 TYPE SLIS_T_FIELDCAT_ALV,
      WA_FIELD1 TYPE SLIS_FIELDCAT_ALV.

START-OF-SELECTION.
*  PERFORM ADD_FIELD."调用屏幕显示字段方法1
  PERFORM FIELD_OUTPUT."调用屏幕显示字段方法2  宏方式
  PERFORM DATA_FILL."调用填充虚拟数据方法
  PERFORM DATA_OUTPUT."调用屏幕输出设置方法

  " 处理屏幕显示字段方式1
FORM ADD_FIELD.
  CLEAR WA_FIELD.
  WA_FIELD-FIELDNAME = 'VBELN'.
  WA_FIELD-SELTEXT_L = '物料编号'.
  APPEND WA_FIELD TO IT_FIELD.

  CLEAR WA_FIELD.
  WA_FIELD-FIELDNAME = 'GEWEI'.
  WA_FIELD-SELTEXT_L = '单位'.
  APPEND WA_FIELD TO IT_FIELD.
ENDFORM.

" 处理屏幕显示字段方式2  宏方式
FORM FIELD_OUTPUT.
  CLEAR WA_FIELD.
  CLEAR IT_FIELD.
  ADD_FIELD 'VBELN'       '物料编号' '' ''.
  ADD_FIELD 'GEWEI'       '单位'     '' ''.
  ADD_FIELD 'LIGHT'       '红绿灯'     '' ''.
ENDFORM.

" 屏幕输出展示字段设置
FORM DATA_OUTPUT.
  "定义ALV输入时宽度自动适应
  DATA: WA_LAYOUT TYPE SLIS_LAYOUT_ALV. "设置输出格式,自适应等
  WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' " 调用函数
    EXPORTING
      IT_FIELDCAT = IT_FIELD
      IS_LAYOUT   = WA_LAYOUT  " 设置表单格式
    TABLES
      T_OUTTAB    = WA_OUTPUT.
ENDFORM.

"数据填充
FORM DATA_FILL.
  DO 3 TIMES.
    WA_VBRK-VBELN = '10001'.
    WA_VBRK-GEWEI = '10'.
    " 添加红绿灯简单方式 
*    WA_VBRK-LIGHT = ICON_GREEN_LIGHT."绿
    WA_VBRK-LIGHT = ICON_YELLOW_LIGHT."黄
*    WA_VBRK-LIGHT = ICON_RED_LIGHT.  "红
    APPEND WA_VBRK TO WA_OUTPUT.
    CLEAR WA_VBRK.
  ENDDO.
ENDFORM.

 

你可能感兴趣的:(ABAP)