ABAP ALV红绿黄灯5步详解编程语言

1.TYPE-POOL引入ICON;

TYPE-POOLS:SLIS,ICON.

2.定义一个指示灯字段;

FLG       TYPE CHAR4,

3.ALV FIELD_SET显示指示灯;

USING ‘FLG’  ”   ’15’ ” ” ”,

4.FORM FIELD_SET指示灯传值;

FORM FIELD_SET USING P_FIELDNAME
                     P_ICON.
  GW_FIELDCAT-ICON          = P_ICON.
  APPEND GW_FIELDCAT TO GT_FIELDCAT.
  CLEAR GW_FIELDCAT.
ENDFORM.

5.根据数据处理逻辑,指示灯字段赋值;

WA_ALV-FLG = ICON_LED_GREEN.

一个具体使用实例

*&---------------------------------------------------------------------* 
*& Report ZEWM006 
*&---------------------------------------------------------------------* 
*& 
*&---------------------------------------------------------------------* 
REPORT ZEWMR007. 
TYPE-POOLS:SLIS,ICON. 
TABLES:LIKP,SSCRFIELDS. 
TYPES:BEGIN OF TY_ALV, 
FLG       TYPE CHAR4, 
SEL       TYPE C, 
ZTYPE     TYPE C, 
ZTITLE    TYPE CHAR30, 
VBELN     TYPE LIKP-VBELN, 
POSNR     TYPE LIPS-POSNR, 
VBELV     TYPE VBFA-VBELV, 
MATNR     TYPE LIPS-MATNR, 
ARKTX     TYPE LIPS-ARKTX, 
LFIMG     TYPE LIPS-LFIMG, 
VRKME     TYPE LIPS-VRKME, 
LGNUM     TYPE LIKP-LGNUM, 
LNUMT     TYPE T300T-LNUMT, 
LGORT     TYPE LIPS-LGORT, 
LGOBE     TYPE T001L-LGOBE, 
KUNNR     TYPE LIKP-KUNNR, 
LIFNR     TYPE LIKP-LIFNR, 
NAME_K    TYPE BUT000-NAME_ORG1, "客户描述 
NAME_L    TYPE BUT000-NAME_ORG1, "供应商描述 
NAME      TYPE BUT000-NAME_ORG1, "打印文件表头 
NAME_ORG1 TYPE BUT000-NAME_ORG1, "ALV最终输出 
END OF TY_ALV, 
BEGIN OF TY_LIKP, 
ZTITLE TYPE CHAR30, 
ZTYPE  TYPE CHAR1, 
VBELN  TYPE LIKP-VBELN, 
VBELV  TYPE VBFA-VBELV, 
LGNUM  TYPE LIKP-LGNUM, 
LNUMT  TYPE T300T-LNUMT, 
LGORT  TYPE LIPS-LGORT, 
LGOBE  TYPE T001L-LGOBE, 
KUNNR  TYPE LIKP-KUNNR, 
LIFNR  TYPE LIKP-LIFNR, 
NAME_K TYPE BUT000-NAME_ORG1, 
NAME_L TYPE BUT000-NAME_ORG1, 
NAME   TYPE BUT000-NAME_ORG1, 
END OF TY_LIKP, 
BEGIN OF TY_LIPS, 
VBELN TYPE LIPS-VBELN, 
POSNR TYPE LIPS-POSNR, 
MATNR TYPE LIPS-MATNR, 
ARKTX TYPE LIPS-ARKTX, 
LFIMG TYPE LIPS-LFIMG, 
VRKME TYPE LIPS-VRKME, 
LGORT TYPE LIPS-LGORT, 
END OF TY_LIPS. 
DATA:GT_LIKP   TYPE TABLE OF TY_LIKP, 
WA_LIKP   TYPE TY_LIKP, 
GT_T300T  TYPE TABLE OF T300T, 
WA_T300T  TYPE T300T, 
GT_T001L  TYPE TABLE OF T001L, 
WA_T001L  TYPE T001L, 
GT_BUT_K  TYPE TABLE OF BUT000, 
WA_BUT_K  TYPE BUT000, 
GT_BUT_L  TYPE TABLE OF BUT000, 
WA_BUT_L  TYPE BUT000, 
GT_LIPS   TYPE TABLE OF TY_LIPS, 
WA_LIPS   TYPE TY_LIPS, 
GT_ALV    TYPE TABLE OF TY_ALV, 
WA_ALV    TYPE TY_ALV, 
WA_DOCID1 TYPE /SCDL/DB_REFDOC-DOCID, 
WA_DOCID2 TYPE /SCDL/DB_REFDOC-DOCID, 
WA_DOCID3 TYPE /SCDL/DB_REFDOC-DOCID. 
DATA: GW_FIELDCAT TYPE SLIS_FIELDCAT_ALV, 
GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, 
G_LAYOUT    TYPE SLIS_LAYOUT_ALV, 
LS_EVENTS   TYPE SLIS_ALV_EVENT, 
LT_EVENTS   TYPE SLIS_T_EVENT. 
SELECTION-SCREEN BEGIN OF BLOCK BK1 WITH FRAME. 
SELECT-OPTIONS: 
S_VBELN FOR LIKP-VBELN OBLIGATORY. 
SELECTION-SCREEN END OF BLOCK BK1. 
SELECTION-SCREEN BEGIN OF BLOCK BK2 WITH FRAME. 
PARAMETERS:R_JHD RADIOBUTTON GROUP AA DEFAULT 'X'. 
PARAMETERS:R_ZCD RADIOBUTTON GROUP AA. 
SELECTION-SCREEN END OF BLOCK BK2. 
INITIALIZATION."(初始化) 
AT SELECTION-SCREEN."(屏幕跳出前) 
START-OF-SELECTION."(取数据) 
IF R_JHD = 'X'."交货单 
PERFORM FRM_GETDATA. 
ELSE."产成品装车清单 
ENDIF. 
PERFORM FRM_LAYOUT_BUILD. 
PERFORM FRM_FIELD_BUILD. 
PERFORM FRM_DATA_OUT. 
END-OF-SELECTION."(展示数据) 
TOP-OF-PAGE."(普通报表输出页头) 
END-OF-PAGE."(普通报表输出页尾) 
*------------------------------------------------------------------------------- 
*FORM 
*------------------------------------------------------------------------------- 
FORM FRM_GETDATA. 
"取抬头数据 
SELECT A~VBELN 
B~VBELV 
A~LGNUM 
A~KUNNR 
A~LIFNR 
INTO CORRESPONDING FIELDS OF TABLE GT_LIKP 
FROM LIKP AS A 
LEFT JOIN VBFA AS B ON A~VBELN = B~VBELN 
WHERE A~VBELN IN S_VBELN 
AND A~LGNUM IN ('HZY','HZC'). 
IF GT_LIKP IS NOT INITIAL. 
"获取行项目数据 
SELECT VBELN POSNR MATNR ARKTX LFIMG VRKME 
LGORT 
INTO CORRESPONDING FIELDS OF TABLE GT_LIPS 
FROM LIPS 
FOR ALL ENTRIES IN GT_LIKP 
WHERE VBELN = GT_LIKP-VBELN. 
SELECT * 
INTO CORRESPONDING FIELDS OF TABLE GT_T300T 
FROM T300T 
FOR ALL ENTRIES IN GT_LIKP 
WHERE LGNUM = GT_LIKP-LGNUM 
AND SPRAS = SY-LANGU. 
SELECT * 
INTO CORRESPONDING FIELDS OF TABLE GT_T001L 
FROM T001L 
FOR ALL ENTRIES IN GT_LIPS 
WHERE LGORT = GT_LIPS-LGORT. 
SELECT PARTNER NAME_ORG1 
INTO CORRESPONDING FIELDS OF TABLE GT_BUT_K 
FROM BUT000 
FOR ALL ENTRIES IN GT_LIKP 
WHERE PARTNER = GT_LIKP-KUNNR. 
SELECT PARTNER NAME_ORG1 
INTO CORRESPONDING FIELDS OF TABLE GT_BUT_L 
FROM BUT000 
FOR ALL ENTRIES IN GT_LIKP 
WHERE PARTNER = GT_LIKP-LIFNR. 
ELSE. 
MESSAGE '输入的交货单不存在!' TYPE 'S' DISPLAY LIKE 'E'. 
LEAVE LIST-PROCESSING. 
ENDIF. 
"处理抬头数据 
LOOP AT GT_LIKP INTO WA_LIKP. 
READ TABLE GT_LIPS INTO WA_LIPS WITH KEY VBELN = WA_LIKP-VBELN. 
IF SY-SUBRC = 0. 
WA_LIKP-LGORT = WA_LIPS-LGORT. 
ENDIF. 
READ TABLE GT_T001L INTO WA_T001L WITH KEY LGORT = WA_LIKP-LGORT. 
IF SY-SUBRC = 0. 
WA_LIKP-LGOBE = WA_T001L-LGOBE. 
ENDIF. 
READ TABLE GT_T300T INTO WA_T300T WITH KEY LGNUM = WA_LIKP-LGNUM. 
IF SY-SUBRC = 0 AND WA_T300T-LGNUM NE 'HZY'."原材料仓描述 = 仓库描述+库存地点描述 
WA_LIKP-LNUMT = WA_T300T-LNUMT. 
ELSEIF SY-SUBRC = 0 AND WA_T300T-LGNUM = 'HZY'. 
CONCATENATE WA_T300T-LNUMT WA_LIKP-LGOBE INTO WA_LIKP-LNUMT SEPARATED BY '-'. 
ENDIF. 
READ TABLE GT_BUT_K INTO WA_BUT_K WITH KEY PARTNER = WA_LIKP-KUNNR. 
IF SY-SUBRC = 0. 
WA_LIKP-NAME_K = WA_BUT_K-NAME_ORG1. 
ENDIF. 
READ TABLE GT_BUT_L INTO WA_BUT_L WITH KEY PARTNER = WA_LIKP-LIFNR. 
IF SY-SUBRC = 0. 
WA_LIKP-NAME_L = WA_BUT_L-NAME_ORG1. 
ENDIF. 
IF R_JHD = 'X'. 
SELECT SINGLE DOCID INTO WA_DOCID1 
FROM /SCDL/DB_REFDOC 
WHERE REFDOCNO = WA_LIKP-VBELN. 
SELECT SINGLE DOCID INTO WA_DOCID2 
FROM /SCDL/DB_PROCH_O 
WHERE DOCID = WA_DOCID1. 
SELECT SINGLE DOCID INTO WA_DOCID3 
FROM /SCDL/DB_PROCH_I 
WHERE DOCID = WA_DOCID1. 
IF WA_DOCID2 IS NOT INITIAL. 
WA_LIKP-ZTITLE = '出库交货单'. 
WA_LIKP-NAME = WA_LIKP-NAME_K. 
WA_LIKP-ZTYPE = 'O'. 
ELSEIF WA_DOCID3 IS NOT INITIAL. 
WA_LIKP-ZTITLE = '入库交货单'. 
WA_LIKP-NAME = WA_LIKP-NAME_L. 
WA_LIKP-ZTYPE = 'I'. 
ENDIF. 
ELSE. 
WA_LIKP-ZTITLE = '产成品装车清单'. 
ENDIF. 
MODIFY GT_LIKP FROM WA_LIKP. 
CLEAR:WA_LIKP,WA_T300T,WA_T001L,WA_BUT_K,WA_LIPS,WA_BUT_L, 
WA_DOCID1,WA_DOCID2,WA_DOCID3. 
ENDLOOP. 
LOOP AT GT_LIPS INTO WA_LIPS. 
WA_ALV-VBELN = WA_LIPS-VBELN. 
WA_ALV-POSNR = WA_LIPS-POSNR. 
WA_ALV-MATNR = WA_LIPS-MATNR. 
WA_ALV-ARKTX = WA_LIPS-ARKTX. 
WA_ALV-LFIMG = WA_LIPS-LFIMG. 
WA_ALV-VRKME = WA_LIPS-VRKME. 
READ TABLE GT_LIKP INTO WA_LIKP WITH KEY VBELN = WA_ALV-VBELN. 
WA_ALV-ZTYPE = WA_LIKP-ZTYPE. 
WA_ALV-VBELV = WA_LIKP-VBELV. 
WA_ALV-LGNUM = WA_LIKP-LGNUM. 
WA_ALV-LGORT = WA_LIKP-LGORT. 
WA_ALV-LGOBE = WA_LIKP-LGOBE. 
WA_ALV-ZTITLE = WA_LIKP-ZTITLE. 
WA_ALV-KUNNR = WA_LIKP-KUNNR. 
WA_ALV-LIFNR = WA_LIKP-LIFNR. 
WA_ALV-NAME_K = WA_LIKP-NAME_K. 
WA_ALV-NAME_L = WA_LIKP-NAME_L. 
WA_ALV-NAME = WA_LIKP-NAME. 
IF WA_ALV-ZTYPE = 'O'."出库交货单 
WA_ALV-LNUMT = WA_LIKP-LNUMT."发货方 
WA_ALV-NAME_ORG1 = WA_LIKP-NAME_K."收货方 
ELSEIF WA_ALV-ZTYPE = 'I'."入库交货单 
WA_ALV-LNUMT = WA_LIKP-NAME_L."发货方 
WA_ALV-NAME_ORG1 = WA_LIKP-LNUMT."收货方 
ENDIF. 
APPEND WA_ALV TO GT_ALV. 
CLEAR:WA_LIKP,WA_LIPS,WA_ALV. 
ENDLOOP. 
SORT GT_ALV BY VBELN POSNR. 
ENDFORM. 
FORM FRM_LAYOUT_BUILD . 
G_LAYOUT-BOX_FIELDNAME        = 'SEL'.  " 选择模式,在最左端有选择按钮 
G_LAYOUT-COLWIDTH_OPTIMIZE    = 'X'.    " 自动调整列宽 
G_LAYOUT-ZEBRA                = 'X'.    " 表格斑马线 
G_LAYOUT-INFO_FIELDNAME       = 'CLR'. 
LS_EVENTS-FORM = 'DATA_CHANGED_METHOD'. 
LS_EVENTS-NAME = 'DATA_CHANGED'. 
APPEND LS_EVENTS TO LT_EVENTS. 
ENDFORM. 
FORM FRM_FIELD_BUILD . 
CLEAR GT_FIELDCAT. 
PERFORM FIELD_SET: 
USING 'FLG'  ''   '15' '' '' '', 
USING 'VBELN'  '交货单号'   '15' '' '' '', 
USING 'POSNR'  '行号'   '15' '' '' '', 
USING 'VBELV'  '先前凭证'   '15' '' '' '', 
USING 'MATNR'  '物料编码'   '15' '' '' '', 
USING 'ARKTX'  '物料名称'   '15' '' '' '', 
USING 'LFIMG'  '数量'   '15' '' '' '', 
USING 'VRKME'  '单位'   '15' '' '' '', 
USING 'LNUMT'  '发货方'   '15' '' '' '', 
USING 'NAME_ORG1'  '收货方'   '15' '' '' ''. 
ENDFORM. 
FORM FRM_DATA_OUT. 
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' 
EXPORTING 
I_CALLBACK_PROGRAM       = SY-REPID 
IS_LAYOUT                = G_LAYOUT 
IT_FIELDCAT              = GT_FIELDCAT 
I_SAVE                   = 'A' 
I_CALLBACK_PF_STATUS_SET = 'FRM_STATE' 
I_CALLBACK_USER_COMMAND  = 'FRM_USER_COMMAND' 
IT_EVENTS                = LT_EVENTS 
TABLES 
T_OUTTAB                 = GT_ALV 
EXCEPTIONS 
PROGRAM_ERROR            = 1 
OTHERS                   = 2. 
IF SY-SUBRC <> 0. 
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO 
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. 
ENDIF. 
ENDFORM. 
FORM FRM_STATE USING RT_EXTAB TYPE SLIS_T_EXTAB. 
SET PF-STATUS 'STANDARD'. 
ENDFORM. 
FORM FRM_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM 
SELFIELD TYPE SLIS_SELFIELD. 
DATA: LR_GRID TYPE REF TO CL_GUI_ALV_GRID. 
DATA L_TABIX LIKE SY-TABIX. 
*  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' 
*    IMPORTING 
*      E_GRID = LR_GRID. 
*  CALL METHOD LR_GRID->CHECK_CHANGED_DATA. 
SELFIELD-REFRESH = 'X'. 
*  SELFIELD-ROW_STABLE = 'X'. 
*  SELFIELD-COL_STABLE = 'X'. 
READ TABLE GT_ALV INTO WA_ALV INDEX SELFIELD-TABINDEX. 
CHECK SY-SUBRC = 0. 
CASE R_UCOMM. 
WHEN 'ZPRINT'. 
PERFORM FRM_PRINT. 
ENDCASE. 
ENDFORM. 
FORM FIELD_SET USING P_FIELDNAME 
P_SELTEXT_L 
P_OUTPUTLEN 
P_HOTSPOT 
P_CHECKBOX 
P_ICON. 
GW_FIELDCAT-FIELDNAME     = P_FIELDNAME . 
GW_FIELDCAT-SELTEXT_L     = P_SELTEXT_L . 
GW_FIELDCAT-OUTPUTLEN     = P_OUTPUTLEN . 
GW_FIELDCAT-HOTSPOT       = P_HOTSPOT. 
GW_FIELDCAT-CHECKBOX      = P_CHECKBOX. 
GW_FIELDCAT-ICON          = P_ICON. 
APPEND GW_FIELDCAT TO GT_FIELDCAT. 
CLEAR GW_FIELDCAT. 
ENDFORM. 
FORM FRM_PRINT. 
DATA:FM_NAME               TYPE  RS38L_FNAM, 
GT_LIPS_O             TYPE TABLE OF ZSEWM002, 
WA_LIPS_O             TYPE ZSEWM002, 
WA_LIKP_O             TYPE ZSEWM001, 
LS_OUTPUT_OPTIONS     TYPE SSFCOMPOP, 
LS_CONTROL_PARAMETERS TYPE SSFCTRLOP, 
LS_OUTPUT_INFO        TYPE SSFCRESCL, 
ZLINE                 TYPE CHAR3, 
LS_CHECK              TYPE TY_ALV, 
LT_CHECK              TYPE TABLE OF TY_ALV. 
"检查 
CLEAR:LT_CHECK,LS_CHECK. 
LOOP AT GT_ALV INTO WA_ALV WHERE SEL = 'X'. 
LS_CHECK-VBELN = WA_ALV-VBELN. 
COLLECT LS_CHECK INTO LT_CHECK. 
ENDLOOP. 
IF SY-SUBRC <> 0. 
MESSAGE '请选择需要打印的数据!' TYPE 'E'. 
ENDIF. 
IF LINES( LT_CHECK ) > 1. 
MESSAGE '不同交货单不能一起打印!' TYPE 'E'. 
ENDIF. 
LOOP AT GT_ALV INTO WA_ALV WHERE SEL = 'X'. 
"READ TABLE GT_ALV INTO WA_ALV WITH KEY SEL = 'X'. 
WA_LIKP_O-ZTITLE = WA_ALV-ZTITLE. 
WA_LIKP_O-VBELN = WA_ALV-VBELN. 
WA_LIKP_O-VBELV = WA_ALV-VBELV. 
WA_LIKP_O-LGNUM = WA_ALV-LGNUM. 
WA_LIKP_O-LNUMT = WA_ALV-LNUMT. 
WA_LIKP_O-LGORT = WA_ALV-LGORT. 
WA_LIKP_O-LGOBE = WA_ALV-LGOBE. 
WA_LIKP_O-KUNNR = WA_ALV-KUNNR. 
WA_LIKP_O-LIFNR = WA_ALV-LIFNR. 
WA_LIKP_O-NAME_K = WA_ALV-NAME_K. 
WA_LIKP_O-NAME_L = WA_ALV-NAME_L. 
WA_LIKP_O-NAME = WA_ALV-NAME_ORG1. 
ZLINE = 0. 
LOOP AT GT_LIPS INTO WA_LIPS WHERE VBELN = WA_LIKP_O-VBELN. 
WA_LIPS_O-ZLINE = ZLINE + 1. 
ZLINE = ZLINE + 1. 
WA_LIPS_O-VBELN = WA_LIPS-VBELN. 
WA_LIPS_O-POSNR = WA_LIPS-POSNR. 
WA_LIPS_O-MATNR = WA_LIPS-MATNR. 
WA_LIPS_O-ARKTX = WA_LIPS-ARKTX. 
WA_LIPS_O-LFIMG = WA_LIPS-LFIMG. 
WA_LIPS_O-VRKME = WA_LIPS-VRKME. 
WA_LIPS_O-LGORT = WA_LIPS-LGORT. 
APPEND WA_LIPS_O TO GT_LIPS_O. 
CLEAR:WA_LIPS,WA_LIPS_O. 
ENDLOOP. 
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' 
EXPORTING 
FORMNAME           = 'ZSFEWM010' 
IMPORTING 
FM_NAME            = FM_NAME 
EXCEPTIONS 
NO_FORM            = 1 
NO_FUNCTION_MODULE = 2 
OTHERS             = 3. 
LS_OUTPUT_OPTIONS-TDDEST = 'LP01'.        "假脱机: 输出设备 
LS_OUTPUT_OPTIONS-TDIMMED = 'X'.          "立即假脱机打印 
LS_OUTPUT_OPTIONS-TDDELETE = 'X'.        "立即假脱机删除 
"打开假脱机队列 
CALL FUNCTION 'SSF_OPEN' 
EXPORTING 
OUTPUT_OPTIONS     = LS_OUTPUT_OPTIONS 
CONTROL_PARAMETERS = LS_CONTROL_PARAMETERS 
USER_SETTINGS      = '' 
EXCEPTIONS 
FORMATTING_ERROR   = 1 
INTERNAL_ERROR     = 2 
SEND_ERROR         = 3 
USER_CANCELED      = 4 
OTHERS             = 5. 
IF SY-SUBRC <> 0. 
RETURN. 
ENDIF. 
LS_CONTROL_PARAMETERS-NO_OPEN = 'X'. 
LS_CONTROL_PARAMETERS-NO_CLOSE = 'X'. 
CALL FUNCTION FM_NAME 
EXPORTING 
CONTROL_PARAMETERS = LS_CONTROL_PARAMETERS 
OUTPUT_OPTIONS     = LS_OUTPUT_OPTIONS 
USER_SETTINGS      = ' ' 
WA_LIKP_O          = WA_LIKP_O 
IMPORTING 
JOB_OUTPUT_INFO    = LS_OUTPUT_INFO 
TABLES 
GT_LIPS_O          = GT_LIPS_O 
EXCEPTIONS 
FORMATTING_ERROR   = 1 
INTERNAL_ERROR     = 2 
SEND_ERROR         = 3 
USER_CANCELED      = 4. 
"关闭假脱机队列 
CALL FUNCTION 'SSF_CLOSE' 
IMPORTING 
JOB_OUTPUT_INFO  = LS_OUTPUT_INFO 
EXCEPTIONS 
FORMATTING_ERROR = 1 
INTERNAL_ERROR   = 2 
SEND_ERROR       = 3 
OTHERS           = 4. 
WA_ALV-FLG = ICON_LED_GREEN. 
MODIFY GT_ALV FROM WA_ALV TRANSPORTING FLG. 
CLEAR:WA_ALV, WA_LIKP_O. 
ENDLOOP. 
ENDFORM.

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/19539.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论