SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF }
.L0S31 { font-style: italic; color: #808080 }
.L0S32 { color: #3399FF }
.L0S33 { color: #4DA619 }
.L0S52 { color: #0000FF }
.L0S55 { color: #800080 }
.L0S70 { color: #808080 }
*&---------------------------------------------------------------------*
*& Report ZTESTXIAO002
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZTESTXIAO002.
TABLES:EKBE,EKPO,EKKO,LFA1.
*定义ALV变量
TYPE-POOLS: SLIS.
DATA: FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
GD_TAB_GROUP TYPE SLIS_T_SP_GROUP_ALV,
GD_LAYOUT TYPE SLIS_LAYOUT_ALV,
GD_REPID LIKE SY-REPID,
GT_EVENTS TYPE SLIS_T_EVENT,
GD_PRNTPARAMS TYPE SLIS_PRINT_ALV,
GT_SORT TYPE SLIS_T_SORTINFO_ALV,
GS_SORT TYPE SLIS_SORTINFO_ALV,
G_TITLE TYPE LVC_TITLE.
DATA:BEGIN OF GT_OUT OCCURS 0,
EBELN LIKE EKBE-EBELN, "采购订单号
WERKS LIKE EKPO-WERKS, "工厂
AEDAT LIKE EKPO-AEDAT, "采购凭证日期
MATNR LIKE EKPO-MATNR, "物料号
TXZ01 LIKE EKPO-TXZ01, "物料描述
NETPR LIKE EKPO-NETPR, "净价
MENGE LIKE EKPO-MENGE, "凭证数量
BUZEI LIKE EKBE-BUZEI, "行项目
VGABE LIKE EKBE-VGABE, "业务\事件类
BELNR LIKE EKBE-BELNR, "凭证号
MENGE1 LIKE EKBE-MENGE, "数量
BWART LIKE EKBE-BWART, "移动类型
BUDAT LIKE EKBE-BUDAT, "过账日期
HSWAE LIKE EKBE-HSWAE, "货币
LIFNR LIKE EKKO-LIFNR, "供应商
NAME1 LIKE LFA1-NAME1, "供应商名称
END OF GT_OUT.
DATA:BEGIN OF GT_EKBE occurs 0,
EBELN LIKE EKBE-EBELN, "采购订单号
BUZEI LIKE EKBE-BUZEI, "行项目
VGABE LIKE EKBE-VGABE, "业务\事件类
BELNR LIKE EKBE-BELNR, "凭证号
MENGE1 LIKE EKBE-MENGE, "数量
BWART LIKE EKBE-BWART, "移动类型
BUDAT LIKE EKBE-BUDAT, "过账日期
HSWAE LIKE EKBE-HSWAE, "货币
MATNR LIKE EKPO-MATNR, "物料号
END OF GT_EKBE.
DATA:BEGIN OF GT_EKKO occurs 0,
EBELN LIKE EKBE-EBELN, "采购订单号
WERKS LIKE EKPO-WERKS, "工厂
AEDAT LIKE EKPO-AEDAT, "采购凭证日期
MATNR LIKE EKPO-MATNR, "物料号
TXZ01 LIKE EKPO-TXZ01, "物料描述
NETPR LIKE EKPO-NETPR, "净价
MENGE LIKE EKPO-MENGE, "凭证数量
LIFNR LIKE EKKO-LIFNR, "供应商
BUZEI LIKE EKBE-BUZEI, "行项目
VGABE LIKE EKBE-VGABE, "业务\事件类
BELNR LIKE EKBE-BELNR, "凭证号
MENGE1 LIKE EKBE-MENGE, "数量
BWART LIKE EKBE-BWART, "移动类型
BUDAT LIKE EKBE-BUDAT, "过账日期
HSWAE LIKE EKBE-HSWAE, "货币
* MATNR LIKE EKPO-MATNR, "物料号
END OF GT_EKKO.
DATA:BEGIN OF GT_LFA1 occurs 0,
LIFNR LIKE EKKO-LIFNR, "供应商
NAME1 LIKE LFA1-NAME1, "供应商名称
END OF GT_LFA1.
"定义选择屏幕(输入条件)
SELECTION-SCREEN BEGIN OF BLOCK BLOCK1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_EBELN for EKBE-EBELN. "采购订单号
SELECTION-SCREEN END OF BLOCK BLOCK1.
START-OF-SELECTION.
"取数
PERFORM GET_DATA.
"处理数据
PERFORM DEAL_DATA.
"alv显示
PERFORM ALV_DIS.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA .
SELECT
EBELN
BUZEI
VGABE
BELNR
MENGE AS MENGE1
BWART
BUDAT
HSWAE
MATNR
INTO CORRESPONDING FIELDS OF TABLE GT_EKBE
FROM EKBE
WHERE EBELN in S_EBELN.
SELECT
A~EBELN
A~WERKS
A~AEDAT
A~MATNR
A~TXZ01
A~NETPR
A~MENGE
B~LIFNR
INTO CORRESPONDING FIELDS OF TABLE GT_EKKO
FROM EKPO AS A
INNER JOIN EKKO AS B ON A~EBELN = B~EBELN
* inner join ekbe as c on A~EBELN = c~EBELN
WHERE B~EBELN in S_EBELN.
SELECT
LIFNR
NAME1
INTO CORRESPONDING FIELDS OF TABLE GT_LFA1
FROM LFA1
FOR ALL ENTRIES IN GT_EKKO
WHERE LIFNR = GT_EKKO-LIFNR.
ENDFORM. " GET_DATA
*&---------------------------------------------------------------------*
*& Form DEAL_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DEAL_DATA . "给需要输出的字段赋值
loop at GT_EKKO.
READ TABLE GT_EKBE WITH KEY EBELN = GT_EKKO-EBELN.
IF SY-SUBRC <> 0.
MOVE-CORRESPONDING GT_EKKO TO GT_out.
READ TABLE GT_LFA1 WITH KEY LIFNR = GT_EKKO-LIFNR.
IF SY-SUBRC = 0.
GT_OUT-NAME1 = GT_LFA1-NAME1.
ENDIF.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = GT_OUT-MATNR
IMPORTING
OUTPUT = GT_OUT-MATNR.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = GT_OUT-LIFNR
IMPORTING
OUTPUT = GT_OUT-LIFNR.
append GT_out.
clear GT_EKKO.
ENDIF.
endloop.
LOOP AT GT_EKBE.
MOVE-CORRESPONDING GT_EKBE TO GT_OUT.
* GT_OUT-EBELN = GT_EKBE-EBELN.
* GT_OUT-BUZEI = GT_EKBE-BUZEI.
* GT_OUT-VGABE = GT_EKBE-VGABE.
* GT_OUT-BELNR = GT_EKBE-BELNR.
* GT_OUT-MENGE1 = GT_EKBE-MENGE1.
* GT_OUT-BWART = GT_EKBE-BWART.
* GT_OUT-BUDAT = GT_EKBE-BUDAT.
* GT_OUT-HSWAE = GT_EKBE-HSWAE.
READ TABLE GT_EKKO WITH KEY EBELN = GT_EKBE-EBELN
matnr = GT_EKBE-matnr.
IF SY-SUBRC = 0.
GT_OUT-WERKS = GT_EKKO-WERKS.
GT_OUT-AEDAT = GT_EKKO-AEDAT.
GT_OUT-MATNR = GT_EKKO-MATNR.
GT_OUT-TXZ01 = GT_EKKO-TXZ01.
GT_OUT-NETPR = GT_EKKO-NETPR.
GT_OUT-MENGE = GT_EKKO-MENGE.
GT_OUT-LIFNR = GT_EKKO-LIFNR.
ENDIF.
READ TABLE GT_LFA1 WITH KEY LIFNR = GT_EKKO-LIFNR.
IF SY-SUBRC = 0.
GT_OUT-NAME1 = GT_LFA1-NAME1.
ENDIF.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = GT_OUT-MATNR
IMPORTING
OUTPUT = GT_OUT-MATNR.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = GT_OUT-LIFNR
IMPORTING
OUTPUT = GT_OUT-LIFNR.
APPEND GT_OUT.
CLEAR GT_OUT.
ENDLOOP.
ENDFORM. " DEAL_DATA
*&---------------------------------------------------------------------*
*& Form ALV_DIS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM ALV_DIS .
*创建字段宏定义和输出字段赋值
PERFORM FRM_BUILD_FIELDCATALOG.
*定义输出模式
GD_LAYOUT-NO_INPUT = 'X'.
GD_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
GD_LAYOUT-F2CODE = '&IC1'. "Sets fcode for when double click(press f2)
"gd_layout-box_fieldname = 'BOX'.
GD_LAYOUT-CELL_MERGE = 'X'.
GD_LAYOUT-ZEBRA = 'X'.
*使用ALV输出函数
GD_REPID = SY-REPID.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = GD_REPID
**用户操作的参数
* I_CALLBACK_USER_COMMAND = 'USER_COMMAND_4000' "自定义指向代码
*ALV输出状态的参数
I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS_3200' "菜单
*输出模式参数
IS_LAYOUT = GD_LAYOUT
IT_FIELDCAT = FIELDCATALOG[]
IS_PRINT = GD_PRNTPARAMS
I_GRID_TITLE = G_TITLE
I_SAVE = 'X'
"it_sort = gt_sort[]
TABLES
*用于输出ALV的内表
T_OUTTAB = GT_OUT
EXCEPTIONS
*定义输出异常时的信息,配合MESSAGE语句使用
PROGRAM_ERROR = 1
OTHERS = 2.
ENDFORM. " ALV_DIS
*&---------------------------------------------------------------------*
*& Form FRM_BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_BUILD_FIELDCATALOG .
"创建字段宏定义
DEFINE ADD_FIELD.
FIELDCATALOG-FIELDNAME = &1. "内表字段名称
FIELDCATALOG-SELTEXT_M = &2. "字段输出名称
FIELDCATALOG-NO_ZERO = &3. "是否显示零
FIELDCATALOG-JUST = &4. "对齐方式
FIELDCATALOG-EMPHASIZE = &5. "是否高亮
FIELDCATALOG-CHECKBOX = &6. "是否带单选框
FIELDCATALOG-EDIT = &7. "可编辑
APPEND FIELDCATALOG.
CLEAR FIELDCATALOG.
END-OF-DEFINITION.
*输出字段赋值
ADD_FIELD 'EBELN' '采购订单号' '' 'L' '' '' ''.
ADD_FIELD 'WERKS' '工厂' '' 'L' '' '' ''.
ADD_FIELD 'AEDAT' '凭证日期' '' 'L' '' '' ''.
ADD_FIELD 'MATNR' '物料号' '' 'L' '' '' ''.
ADD_FIELD 'TXZ01' '物料描述' '' 'L' '' '' ''.
ADD_FIELD 'NETPR' '净价' '' 'L' '' '' ''.
ADD_FIELD 'MENGE' '凭证数量' '' 'L' '' '' ''.
ADD_FIELD 'BUZEI' '行项目' '' 'L' '' '' ''.
ADD_FIELD 'VGABE' '业务\事件类' '' 'L' '' '' ''.
ADD_FIELD 'BELNR' '凭证号' '' 'L' '' '' ''.
ADD_FIELD 'MENGE1' '数量' '' 'L' '' '' ''.
ADD_FIELD 'BWART' '移动类型' '' 'L' '' '' ''.
ADD_FIELD 'BUDAT' '过账日期' '' 'L' '' '' ''.
ADD_FIELD 'HSWAE' '货币' '' 'L' '' '' ''.
ADD_FIELD 'LIFNR' '供应商' '' 'L' '' '' ''.
ADD_FIELD 'NAME1' '供应商名称' '' 'L' '' '' ''.
ENDFORM. " FRM_BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form set_pf_status_3200
*&---------------------------------------------------------------------*
* GUI定义
*----------------------------------------------------------------------*
* -->EXTAB text
*----------------------------------------------------------------------*
FORM SET_PF_STATUS_3200 USING EXTAB TYPE SLIS_T_EXTAB.
DATA: R_UCOMM LIKE SY-UCOMM.
SET PF-STATUS 'MYSTATUS'.
ENDFORM.