终于完成了 OO ALV的学习,第一个作品。 一个屏幕上放了2个ALV控件,上面用来显示表头,下面用来显示详细的行项目。
业务背景:
在汽车的售后服务环节,汽车零件在质保期内损坏,维修产生的费用,整车厂会追溯到零件供应商索取。
数据模型简介:
三包索赔单数据从销售系统中传入ERP系统。
对三包索赔原始数据我们设计了2张表来存放,
一张是表头表,存放三包索赔单号及相关信息,另一张是详细项目表,存放详细使用的零件项目。
表头表和详细项目表的关系是一对多,即一条表头表(三包索赔单)对应多条详细项目(结算单)。
ERP系统功能设计:
物流部门需要对三包索赔单数据管理并打印出来发给供应商协商。
1. ABAP程序需要在ERP系统中用2个ALV展示三包索赔数据和行项目,一条三包索赔数据对应多条详细项目。
2. 选中ALV1中的一条三包索赔数据,ALV2中列出相关的详细项目。
3.点击自定义按钮,完成对一个三包索赔单数据的审批和打印单据。
ABAP代码说明:
这次我们要实现一个屏幕放入2个ALV列表控件,点击第一个ALV控件(只能单选),带出数据放入第二个ALV控件中。
使用FUNCTION ALV目前看来已经不能满足要求,需要用OO方式来控制ALV,这样就可以在一个屏幕上画上2个ALV。
所以创建屏幕在所难免,我们创建一个屏幕0100,放2个自定义控件,取名CON1,CON2.
屏幕会带出3个模块,所有这些模块代码,我选择全部放到一个源程序中,这样使用比较方便:
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
MODULE INIT_CON.
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.
STATUS_0100 模块中,我们设置程序主画面的STAUTS,STAUTS是自己准备的,也可以用标准的。
USER_COMMAND_0100 模块,就是对STAUTS上的绿,黄,红工具条按钮按下的效果。
INIT_CON 模块中,是初始化屏幕和ALV控件,第一个ALV控件,我们会把数据也填充到内表,然后交有ALV显示出来。
该模块中,我们可以看到OO ALV的使用方法,即CREATE OBJECT CON1_REF连接到CON1屏幕控件上,CREATE OBJECT G_GRID1再创建ALV对象,然后我们给ALV对象注册几个事件,
1. HANDLE_TOOLBAR这个事件用于给ALV加自定义的工具条按钮。
2. HANDLE_CLICK用于给ALV点击其中一行后的处理代码段。
3. HANDLE_COMMAND事件用于接收用户按了自定义按钮后,触发的代码段。
ABAP中对于事件的使用我分为4步:
1. 定义事件方法
2. 指定事件的执行方法代码
3. 事件变量实例化
4. 把事件指定到ALV控件中(注册事件)
*&---------------------------------------------------------------------*
*& Module INIT_CON OUTPUT
*&---------------------------------------------------------------------*
* text 控件初始化模块
*----------------------------------------------------------------------*
MODULE INIT_CON OUTPUT.
"---------第一个ALV控件-----------------
IF CON1_REF IS INITIAL.
DATA GS_LAYOUT1 TYPE LVC_S_LAYO.
GS_LAYOUT1-CWIDTH_OPT = 'X'.
GS_LAYOUT1-GRID_TITLE = '三包索赔单'.
GS_LAYOUT1-SEL_MODE = 'B'.
GS_LAYOUT1-ZEBRA = 'X'.
DATA GT_FIELDCAT TYPE LVC_T_FCAT.
DATA GS_FIELDCAT TYPE LVC_S_FCAT.
GS_FIELDCAT-COL_POS = 1. GS_FIELDCAT-FIELDNAME = 'BOX'. GS_FIELDCAT-CHECKBOX = 'X'. GS_FIELDCAT-HOTSPOT = 'X'. APPEND GS_FIELDCAT TO GT_FIELDCAT.CLEAR GS_FIELDCAT.
GS_FIELDCAT-COL_POS = 2. GS_FIELDCAT-FIELDNAME = 'TZNUM'. GS_FIELDCAT-COLTEXT = '三包索赔单号'. APPEND GS_FIELDCAT TO GT_FIELDCAT. CLEAR GS_FIELDCAT.
GS_FIELDCAT-COL_POS = 3. GS_FIELDCAT-FIELDNAME = 'LIFNR'. GS_FIELDCAT-COLTEXT = '供应商代码'. APPEND GS_FIELDCAT TO GT_FIELDCAT.CLEAR GS_FIELDCAT.
GS_FIELDCAT-COL_POS = 4. GS_FIELDCAT-FIELDNAME = 'NAME1'. GS_FIELDCAT-COLTEXT = '供应商名称'. APPEND GS_FIELDCAT TO GT_FIELDCAT.CLEAR GS_FIELDCAT.
GS_FIELDCAT-COL_POS = 5. GS_FIELDCAT-FIELDNAME = 'ERDAT'. GS_FIELDCAT-COLTEXT = '日期'. APPEND GS_FIELDCAT TO GT_FIELDCAT.CLEAR GS_FIELDCAT.
GS_FIELDCAT-COL_POS = 6. GS_FIELDCAT-FIELDNAME = 'EINFR'. GS_FIELDCAT-COLTEXT = '运费'. APPEND GS_FIELDCAT TO GT_FIELDCAT.CLEAR GS_FIELDCAT.
* GS_FIELDCAT-COL_POS = 7. GS_FIELDCAT-FIELDNAME = 'SUMME'. GS_FIELDCAT-COLTEXT = '总计'. APPEND GS_FIELDCAT TO GT_FIELDCAT.CLEAR GS_FIELDCAT.
GS_FIELDCAT-COL_POS = 8. GS_FIELDCAT-FIELDNAME = 'CHUKU'. GS_FIELDCAT-COLTEXT = '出库'. APPEND GS_FIELDCAT TO GT_FIELDCAT.CLEAR GS_FIELDCAT.
GS_FIELDCAT-COL_POS = 9. GS_FIELDCAT-FIELDNAME = 'ISSHEN'. GS_FIELDCAT-COLTEXT = '审批'. APPEND GS_FIELDCAT TO GT_FIELDCAT.CLEAR GS_FIELDCAT.
GS_FIELDCAT-COL_POS = 10. GS_FIELDCAT-FIELDNAME = 'ISDEL'. GS_FIELDCAT-COLTEXT = '删除'. APPEND GS_FIELDCAT TO GT_FIELDCAT.CLEAR GS_FIELDCAT.
CREATE OBJECT CON1_REF
EXPORTING
CONTAINER_NAME = 'CON1'.
CREATE OBJECT G_GRID1
EXPORTING
I_PARENT = CON1_REF.
"4 注册事件句柄,图标的还必须加在这里,不然不行
CREATE OBJECT EVENT_RECEIVER2.
SET HANDLER EVENT_RECEIVER2->HANDLE_TOOLBAR FOR G_GRID1.
"4 注册事件句柄
CREATE OBJECT EVENT_RECEIVER.
SET HANDLER EVENT_RECEIVER->HANDLE_CLICK FOR G_GRID1.
"4 注册事件句柄
CREATE OBJECT EVENT_RECEIVER3.
SET HANDLER EVENT_RECEIVER3->HANDLE_COMMAND FOR G_GRID1.
CALL METHOD G_GRID1->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = GS_LAYOUT1
CHANGING
IT_OUTTAB = GT_ITAB_HEAD[]
IT_FIELDCATALOG = GT_FIELDCAT.
ENDIF.
ALV1在非编辑模式单选控制的实现:
用户单击ALV1中的CKECKBOX时,
1. 程序首选清空ALV中的全部CKECKBOX
2. 打上当前用户选的一个CKECKBOX
3. 刷新ALV
全部代码:
*&---------------------------------------------------------------------*
*& Report ZMMR0093
*& 三包索赔单审批及打印程序 潍柴(重庆)汽车
*&---------------------------------------------------------------------*
*& james_lx
*& 2015.12.10
*&---------------------------------------------------------------------*
REPORT ZMMR0093.
TYPE-POOLS: ICON.
TABLES: ZSDT029,ZSDT030.
DATA GS_ZSDT_LOG029 LIKE ZSDT_LOG029.
DATA GT_ZSDT029 LIKE TABLE OF ZSDT029 WITH HEADER LINE.
DATA GT_ZSDT030 LIKE TABLE OF ZSDT030 WITH HEADER LINE.
DATA GT_ITAB LIKE TABLE OF ZSDS045 WITH HEADER LINE.
DATA GT_ITAB_HEAD LIKE TABLE OF ZSDS045 WITH HEADER LINE.
DATA GS_ITAB_HEAD LIKE ZSDS045 .
DATA GT_PRINT LIKE TABLE OF ZSDS045 WITH HEADER LINE.
DATA GV_KNUMH LIKE A017-KNUMH.
DATA GV_KPEIN LIKE KONP-KPEIN.
DATA GV_KBETR LIKE KONP-KBETR.
DATA CON1_REF TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
DATA CON2_REF TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
DATA G_GRID1 TYPE REF TO CL_GUI_ALV_GRID.
DATA G_GRID2 TYPE REF TO CL_GUI_ALV_GRID.
"-------------------------------------
"-----------ALV1的HOTSPOT单击事件------------
"-------------------------------------
"1 定义ALV1的事件
CLASS LCL_EVENT_RECEIVER DEFINITION.
PUBLIC SECTION.
METHODS HANDLE_CLICK
FOR EVENT HOTSPOT_CLICK
OF CL_GUI_ALV_GRID
IMPORTING
E_ROW_ID
E_COLUMN_ID
ES_ROW_NO.
ENDCLASS.
"2 事件的执行方法
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
METHOD HANDLE_CLICK.
MESSAGE E_ROW_ID TYPE 'S'.
"清空原来的X
LOOP AT GT_ITAB_HEAD INTO GS_ITAB_HEAD.
GS_ITAB_HEAD-BOX = ''.
MODIFY GT_ITAB_HEAD FROM GS_ITAB_HEAD.
ENDLOOP.
"补上当前行的X
READ TABLE GT_ITAB_HEAD INTO GS_ITAB_HEAD INDEX E_ROW_ID. "读取当前行
GS_ITAB_HEAD-BOX = 'X'.
MODIFY GT_ITAB_HEAD FROM GS_ITAB_HEAD INDEX E_ROW_ID.
"刷新X
DATA: LS_STABLE TYPE LVC_S_STBL.
LS_STABLE-ROW = 'X'.
LS_STABLE-COL = 'X'.
CALL METHOD G_GRID1->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = LS_STABLE
I_SOFT_REFRESH = 'X'.
"准备和显示第二个ALV的数据
DATA GV_TZNUM LIKE GT_ZSDT030-TZNUM.
"得到用户选的一个数据
LOOP AT GT_ITAB_HEAD INTO GS_ITAB_HEAD.
IF GS_ITAB_HEAD-BOX = 'X'.
GV_TZNUM = GS_ITAB_HEAD-TZNUM.
ENDIF.
ENDLOOP.
IF GV_TZNUM IS NOT INITIAL.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE GT_PRINT
FROM ZSDT029 AS A
INNER JOIN ZSDT030 AS B
ON A~TZNUM = B~TZNUM
WHERE A~TZNUM = GV_TZNUM.
"填充价格数据
LOOP AT GT_PRINT INTO GT_PRINT.
"物料号补零
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
INPUT = GT_PRINT-MATNR
IMPORTING
OUTPUT = GT_PRINT-MATNR.
"供应商补0
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = GT_PRINT-LIFNR
IMPORTING
OUTPUT = GT_PRINT-LIFNR.
SELECT SINGLE KNUMH INTO GV_KNUMH FROM A017 WHERE LIFNR = GT_PRINT-LIFNR AND MATNR = GT_PRINT-MATNR AND WERKS = '1001' AND DATBI > GT_PRINT-ERDAT AND DATAB < GT_PRINT-ERDAT.
IF SY-SUBRC = 0.
SELECT SINGLE KBETR KPEIN INTO (GV_KBETR , GV_KPEIN) FROM KONP WHERE KNUMH = GV_KNUMH.
GT_PRINT-CURR1 = GV_KBETR / GV_KPEIN.
"物料号去零
CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'
EXPORTING
INPUT = GT_PRINT-MATNR
IMPORTING
OUTPUT = GT_PRINT-MATNR.
"供应商去0
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = GT_PRINT-LIFNR
IMPORTING
OUTPUT = GT_PRINT-LIFNR.
MODIFY GT_PRINT FROM GT_PRINT.
ENDIF.
ENDLOOP.
LOOP AT GT_PRINT INTO GT_PRINT.
"求单价(材料单价*1.4 系数)
"供应商补0
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = GT_PRINT-LIFNR
IMPORTING
OUTPUT = GT_PRINT-LIFNR.
SELECT SINGLE NAME4 INTO GT_PRINT-NAME4 FROM LFA1 WHERE LIFNR = GT_PRINT-LIFNR.
"供应商去0
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = GT_PRINT-LIFNR
IMPORTING
OUTPUT = GT_PRINT-LIFNR.
IF SY-SUBRC = 0.
GT_PRINT-CURR2 = GT_PRINT-CURR1 * GT_PRINT-NAME4 .
ENDIF.
"材料费(单价*数量)
GT_PRINT-CURRC = GT_PRINT-CURR2 * GT_PRINT-ZMENG.
"合计
GT_PRINT-SUMME = GT_PRINT-CURRC + GT_PRINT-CURRG + GT_PRINT-CURRJ + GT_PRINT-CURRQ.
MODIFY GT_PRINT FROM GT_PRINT.
ENDLOOP.
DATA GS_LAYOUT2 TYPE LVC_S_LAYO.
GS_LAYOUT2-CWIDTH_OPT = 'X'.
GS_LAYOUT2-GRID_TITLE = '详细项目'.
GS_LAYOUT2-SEL_MODE = 'B'.
GS_LAYOUT2-ZEBRA = 'X'.
CALL METHOD G_GRID2->SET_FRONTEND_LAYOUT
EXPORTING
IS_LAYOUT = GS_LAYOUT2.
CALL METHOD G_GRID2->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = LS_STABLE
I_SOFT_REFRESH = 'X'.
ENDIF.
ENDMETHOD.
ENDCLASS.
"3 事件引用变量
DATA EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER.
"-------------------------------------
"-----------ALV1的加图标事件----------
"-------------------------------------
"1 定义ALV1的事件
CLASS LCL_EVENT_RECEIVER2 DEFINITION.
PUBLIC SECTION.
METHODS HANDLE_TOOLBAR
FOR EVENT TOOLBAR
OF CL_GUI_ALV_GRID
IMPORTING E_OBJECT E_INTERACTIVE.
ENDCLASS.
"2 事件的执行方法
CLASS LCL_EVENT_RECEIVER2 IMPLEMENTATION.
METHOD HANDLE_TOOLBAR.
DATA LS_TOOLBAR TYPE STB_BUTTON.
CLEAR LS_TOOLBAR.
LS_TOOLBAR-BUTN_TYPE = 3.
APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
CLEAR LS_TOOLBAR.
LS_TOOLBAR-FUNCTION = 'MYSHEN'.
LS_TOOLBAR-ICON = ICON_SET_STATE.
LS_TOOLBAR-QUICKINFO = '审批确认'.
LS_TOOLBAR-TEXT = '审批确认'.
LS_TOOLBAR-DISABLED = ''.
APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
CLEAR LS_TOOLBAR.
LS_TOOLBAR-FUNCTION = 'MYSCAN'.
LS_TOOLBAR-ICON = ICON_STORNO.
LS_TOOLBAR-QUICKINFO = '取消审批'.
LS_TOOLBAR-TEXT = '取消审批'.
LS_TOOLBAR-DISABLED = ''.
APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
CLEAR LS_TOOLBAR.
LS_TOOLBAR-FUNCTION = 'MYPRINT'.
LS_TOOLBAR-ICON = ICON_PRINT.
LS_TOOLBAR-QUICKINFO = '单据打印'.
LS_TOOLBAR-TEXT = '单据打印'.
LS_TOOLBAR-DISABLED = ''.
APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
ENDMETHOD.
ENDCLASS.
"3 事件引用变量
DATA EVENT_RECEIVER2 TYPE REF TO LCL_EVENT_RECEIVER2.
"-------------------------------------
"-----------ALV1的加按钮响应事件------
"-------------------------------------
"1 定义ALV1的事件
CLASS LCL_EVENT_RECEIVER3 DEFINITION.
PUBLIC SECTION.
METHODS HANDLE_COMMAND
FOR EVENT USER_COMMAND
OF CL_GUI_ALV_GRID
IMPORTING E_UCOMM.
ENDCLASS.
"2 事件的执行方法
CLASS LCL_EVENT_RECEIVER3 IMPLEMENTATION.
METHOD HANDLE_COMMAND.
CASE E_UCOMM.
WHEN 'MYSHEN'.
PERFORM SHENFORM.
WHEN 'MYSCAN'.
PERFORM SCANCELFORM .
WHEN 'MYPRINT'.
PERFORM PPPFORM .
ENDCASE.
ENDMETHOD.
ENDCLASS.
"3 事件引用变量
DATA EVENT_RECEIVER3 TYPE REF TO LCL_EVENT_RECEIVER3.
"选择屏幕
SELECT-OPTIONS GS_TZNUM FOR ZSDT029-TZNUM. "三包索赔单号
SELECT-OPTIONS GS_JZNUM FOR ZSDT030-JZNUM. "结算单号
SELECT-OPTIONS GS_LIFNR FOR ZSDT029-LIFNR. "供应商
SELECT-OPTIONS GS_ERDAT FOR ZSDT029-ERDAT. "日期
SELECT-OPTIONS GS_MATNR FOR ZSDT030-MATNR. "配件代码
START-OF-SELECTION.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE GT_ITAB
FROM ZSDT029 AS A
INNER JOIN ZSDT030 AS B
ON A~TZNUM = B~TZNUM
WHERE A~TZNUM IN GS_TZNUM
AND A~LIFNR IN GS_LIFNR
AND A~ERDAT IN GS_ERDAT
AND B~JZNUM IN GS_JZNUM
AND B~MATNR IN GS_MATNR.
"为第一个控件准备数据
LOOP AT GT_ITAB.
MOVE GT_ITAB-TZNUM TO GT_ITAB_HEAD-TZNUM.
MOVE GT_ITAB-LIFNR TO GT_ITAB_HEAD-LIFNR.
MOVE GT_ITAB-NAME1 TO GT_ITAB_HEAD-NAME1.
MOVE GT_ITAB-ERDAT TO GT_ITAB_HEAD-ERDAT.
MOVE GT_ITAB-EINFR TO GT_ITAB_HEAD-EINFR.
MOVE GT_ITAB-SUMME TO GT_ITAB_HEAD-SUMME.
MOVE GT_ITAB-CHUKU TO GT_ITAB_HEAD-CHUKU.
MOVE GT_ITAB-ISSHEN TO GT_ITAB_HEAD-ISSHEN.
MOVE GT_ITAB-ISDEL TO GT_ITAB_HEAD-ISDEL.
APPEND GT_ITAB_HEAD.
CLEAR GT_ITAB_HEAD.
ENDLOOP.
SORT GT_ITAB_HEAD.
DELETE ADJACENT DUPLICATES FROM GT_ITAB_HEAD.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'TOPS'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module INIT_CON OUTPUT
*&---------------------------------------------------------------------*
* text 控件初始化模块
*----------------------------------------------------------------------*
MODULE INIT_CON OUTPUT.
"---------第一个ALV控件-----------------
IF CON1_REF IS INITIAL.
DATA GS_LAYOUT1 TYPE LVC_S_LAYO.
GS_LAYOUT1-CWIDTH_OPT = 'X'.
GS_LAYOUT1-GRID_TITLE = '三包索赔单'.
GS_LAYOUT1-SEL_MODE = 'B'.
GS_LAYOUT1-ZEBRA = 'X'.
DATA GT_FIELDCAT TYPE LVC_T_FCAT.
DATA GS_FIELDCAT TYPE LVC_S_FCAT.
GS_FIELDCAT-COL_POS = 1. GS_FIELDCAT-FIELDNAME = 'BOX'. GS_FIELDCAT-CHECKBOX = 'X'. GS_FIELDCAT-HOTSPOT = 'X'. APPEND GS_FIELDCAT TO GT_FIELDCAT.CLEAR GS_FIELDCAT.
GS_FIELDCAT-COL_POS = 2. GS_FIELDCAT-FIELDNAME = 'TZNUM'. GS_FIELDCAT-COLTEXT = '三包索赔单号'. APPEND GS_FIELDCAT TO GT_FIELDCAT. CLEAR GS_FIELDCAT.
GS_FIELDCAT-COL_POS = 3. GS_FIELDCAT-FIELDNAME = 'LIFNR'. GS_FIELDCAT-COLTEXT = '供应商代码'. APPEND GS_FIELDCAT TO GT_FIELDCAT.CLEAR GS_FIELDCAT.
GS_FIELDCAT-COL_POS = 4. GS_FIELDCAT-FIELDNAME = 'NAME1'. GS_FIELDCAT-COLTEXT = '供应商名称'. APPEND GS_FIELDCAT TO GT_FIELDCAT.CLEAR GS_FIELDCAT.
GS_FIELDCAT-COL_POS = 5. GS_FIELDCAT-FIELDNAME = 'ERDAT'. GS_FIELDCAT-COLTEXT = '日期'. APPEND GS_FIELDCAT TO GT_FIELDCAT.CLEAR GS_FIELDCAT.
GS_FIELDCAT-COL_POS = 6. GS_FIELDCAT-FIELDNAME = 'EINFR'. GS_FIELDCAT-COLTEXT = '运费'. APPEND GS_FIELDCAT TO GT_FIELDCAT.CLEAR GS_FIELDCAT.
* GS_FIELDCAT-COL_POS = 7. GS_FIELDCAT-FIELDNAME = 'SUMME'. GS_FIELDCAT-COLTEXT = '总计'. APPEND GS_FIELDCAT TO GT_FIELDCAT.CLEAR GS_FIELDCAT.
GS_FIELDCAT-COL_POS = 8. GS_FIELDCAT-FIELDNAME = 'CHUKU'. GS_FIELDCAT-COLTEXT = '出库'. APPEND GS_FIELDCAT TO GT_FIELDCAT.CLEAR GS_FIELDCAT.
GS_FIELDCAT-COL_POS = 9. GS_FIELDCAT-FIELDNAME = 'ISSHEN'. GS_FIELDCAT-COLTEXT = '审批'. APPEND GS_FIELDCAT TO GT_FIELDCAT.CLEAR GS_FIELDCAT.
GS_FIELDCAT-COL_POS = 10. GS_FIELDCAT-FIELDNAME = 'ISDEL'. GS_FIELDCAT-COLTEXT = '删除'. APPEND GS_FIELDCAT TO GT_FIELDCAT.CLEAR GS_FIELDCAT.
CREATE OBJECT CON1_REF
EXPORTING
CONTAINER_NAME = 'CON1'.
CREATE OBJECT G_GRID1
EXPORTING
I_PARENT = CON1_REF.
"4 注册事件句柄,图标的还必须加在这里,不然不行
CREATE OBJECT EVENT_RECEIVER2.
SET HANDLER EVENT_RECEIVER2->HANDLE_TOOLBAR FOR G_GRID1.
"4 注册事件句柄
CREATE OBJECT EVENT_RECEIVER.
SET HANDLER EVENT_RECEIVER->HANDLE_CLICK FOR G_GRID1.
"4 注册事件句柄
CREATE OBJECT EVENT_RECEIVER3.
SET HANDLER EVENT_RECEIVER3->HANDLE_COMMAND FOR G_GRID1.
CALL METHOD G_GRID1->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = GS_LAYOUT1
CHANGING
IT_OUTTAB = GT_ITAB_HEAD[]
IT_FIELDCATALOG = GT_FIELDCAT.
ENDIF.
"---------第二个ALV控件-----------------
IF CON2_REF IS INITIAL.
DATA GS_LAYOUT2 TYPE LVC_S_LAYO.
GS_LAYOUT2-CWIDTH_OPT = 'X'.
GS_LAYOUT2-GRID_TITLE = '详细项目'.
GS_LAYOUT2-SEL_MODE = 'B'.
GS_LAYOUT2-ZEBRA = 'X'.
DATA GT_FIELDCAT2 TYPE LVC_T_FCAT.
DATA GS_FIELDCAT2 TYPE LVC_S_FCAT.
GS_FIELDCAT2-COL_POS = 2. GS_FIELDCAT2-FIELDNAME = 'JZNUM'. GS_FIELDCAT2-COLTEXT = '结算单号'. APPEND GS_FIELDCAT2 TO GT_FIELDCAT2. CLEAR GS_FIELDCAT2.
GS_FIELDCAT2-COL_POS = 3. GS_FIELDCAT2-FIELDNAME = 'MAKTX'. GS_FIELDCAT2-COLTEXT = '配件名称'. APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
GS_FIELDCAT2-COL_POS = 4. GS_FIELDCAT2-FIELDNAME = 'MATNR'. GS_FIELDCAT2-COLTEXT = '配件代码'. APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
GS_FIELDCAT2-COL_POS = 5. GS_FIELDCAT2-FIELDNAME = 'MEINS'. GS_FIELDCAT2-COLTEXT = '单位'. APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
GS_FIELDCAT2-COL_POS = 6. GS_FIELDCAT2-FIELDNAME = 'ZMENG'. GS_FIELDCAT2-COLTEXT = '数量'. APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
GS_FIELDCAT2-COL_POS = 7. GS_FIELDCAT2-FIELDNAME = 'CURR1'. GS_FIELDCAT2-COLTEXT = '材料单价'. APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
GS_FIELDCAT2-COL_POS = 7. GS_FIELDCAT2-FIELDNAME = 'NAME4'. GS_FIELDCAT2-COLTEXT = '系数'. APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
GS_FIELDCAT2-COL_POS = 8. GS_FIELDCAT2-FIELDNAME = 'CURR2'. GS_FIELDCAT2-COLTEXT = '单价(材料单价*1.4) '. APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
GS_FIELDCAT2-COL_POS = 9. GS_FIELDCAT2-FIELDNAME = 'CURRC'. GS_FIELDCAT2-COLTEXT = '材料费(单价*数量)'. APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
GS_FIELDCAT2-COL_POS = 10. GS_FIELDCAT2-FIELDNAME = 'CURRG'. GS_FIELDCAT2-COLTEXT = '工时费'. APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
GS_FIELDCAT2-COL_POS = 10. GS_FIELDCAT2-FIELDNAME = 'CURRJ'. GS_FIELDCAT2-COLTEXT = '救援费'. APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
GS_FIELDCAT2-COL_POS = 10. GS_FIELDCAT2-FIELDNAME = 'CURRQ'. GS_FIELDCAT2-COLTEXT = '其它费用'. APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
GS_FIELDCAT2-COL_POS = 10. GS_FIELDCAT2-FIELDNAME = 'SUMME'. GS_FIELDCAT2-COLTEXT = '合计'. APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
GS_FIELDCAT2-COL_POS = 10. GS_FIELDCAT2-FIELDNAME = 'OTHER'. GS_FIELDCAT2-COLTEXT = '备注'. APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
GS_FIELDCAT2-COL_POS = 10. GS_FIELDCAT2-FIELDNAME = 'TZNUM'. GS_FIELDCAT2-NO_OUT = 'X'. APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
GS_FIELDCAT2-COL_POS = 10. GS_FIELDCAT2-FIELDNAME = 'LIFNR'. GS_FIELDCAT2-NO_OUT = 'X'. APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
GS_FIELDCAT2-COL_POS = 10. GS_FIELDCAT2-FIELDNAME = 'NAME1'. GS_FIELDCAT2-NO_OUT = 'X'. APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
GS_FIELDCAT2-COL_POS = 10. GS_FIELDCAT2-FIELDNAME = 'ERDAT'. GS_FIELDCAT2-NO_OUT = 'X'. APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
GS_FIELDCAT2-COL_POS = 10. GS_FIELDCAT2-FIELDNAME = 'EINFR'. GS_FIELDCAT2-NO_OUT = 'X'. APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
GS_FIELDCAT2-COL_POS = 10. GS_FIELDCAT2-FIELDNAME = 'CHUKU'. GS_FIELDCAT2-NO_OUT = 'X'. APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
GS_FIELDCAT2-COL_POS = 10. GS_FIELDCAT2-FIELDNAME = 'ISSHEN'. GS_FIELDCAT2-NO_OUT = 'X'. APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
GS_FIELDCAT2-COL_POS = 10. GS_FIELDCAT2-FIELDNAME = 'ISDEL'. GS_FIELDCAT2-NO_OUT = 'X'. APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
GS_FIELDCAT2-COL_POS = 10. GS_FIELDCAT2-FIELDNAME = 'BOX'. GS_FIELDCAT2-NO_OUT = 'X'. APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
CREATE OBJECT CON2_REF
EXPORTING
CONTAINER_NAME = 'CON2'.
CREATE OBJECT G_GRID2
EXPORTING
I_PARENT = CON2_REF.
CALL METHOD G_GRID2->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_STRUCTURE_NAME = 'ZSDS045'
IS_LAYOUT = GS_LAYOUT2
CHANGING
IT_OUTTAB = GT_PRINT[]
IT_FIELDCATALOG = GT_FIELDCAT2.
ENDIF.
ENDMODULE. " INIT_CON OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text 这个用户命令,是最上面的 【标准工具条】上的按钮
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'SCAN'.
LEAVE TO SCREEN 0.
WHEN OTHERS.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
"------------取消审批的FORM--------------------
FORM SCANCELFORM .
DATA GV_ANSWER TYPE C.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
TEXT_QUESTION = '取消审批?'
DEFAULT_BUTTON = '2'
DISPLAY_CANCEL_BUTTON = ''
IMPORTING
ANSWER = GV_ANSWER.
IF GV_ANSWER <> 1.
RETURN.
ENDIF.
"处理保存到LOG表
LOOP AT GT_ITAB_HEAD.
IF GT_ITAB_HEAD-BOX = 'X'.
GS_ITAB_HEAD = GT_ITAB_HEAD.
IF GS_ITAB_HEAD-BOX = 'X' AND GS_ITAB_HEAD-ISSHEN = 'X' AND GS_ITAB_HEAD-ISDEL <> 'X' AND GS_ITAB_HEAD-CHUKU <> 'X'.
GS_ZSDT_LOG029-USRID = SY-UNAME. "用户名
GS_ZSDT_LOG029-CRDAT = SY-DATUM. "日期
GS_ZSDT_LOG029-ANUZT = SY-UZEIT. "时间
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
NR_RANGE_NR = 'A1'
OBJECT = 'ZSDFM020'
IMPORTING
NUMBER = GS_ZSDT_LOG029-AUTONUMBER.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' "去掉前导零
EXPORTING
INPUT = GS_ZSDT_LOG029-AUTONUMBER
IMPORTING
OUTPUT = GS_ZSDT_LOG029-AUTONUMBER.
MOVE-CORRESPONDING GS_ITAB_HEAD TO GS_ZSDT_LOG029.
"写业务数据表
UPDATE ZSDT029
SET ISSHEN = ''
WHERE TZNUM = GS_ITAB_HEAD-TZNUM.
COMMIT WORK .
IF SY-SUBRC = 0.
DATA GV_TABIX LIKE SY-TABIX.
"改一下控件的内表X数据
LOOP AT GT_ITAB_HEAD.
IF GT_ITAB_HEAD-BOX = 'X'.
GV_TABIX = SY-TABIX.
ENDIF.
ENDLOOP.
"补上当前行的X
READ TABLE GT_ITAB_HEAD INTO GS_ITAB_HEAD INDEX GV_TABIX. "读取当前行
GS_ITAB_HEAD-ISSHEN = ''.
MODIFY GT_ITAB_HEAD FROM GS_ITAB_HEAD INDEX GV_TABIX.
"刷新X
DATA: LS_STABLE TYPE LVC_S_STBL.
LS_STABLE-ROW = 'X'.
LS_STABLE-COL = 'X'.
CALL METHOD G_GRID1->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = LS_STABLE
I_SOFT_REFRESH = 'X'.
"传给EAI
DATA GT_HEADER LIKE TABLE OF ZSDS043 WITH HEADER LINE.
DATA GT_RETURN LIKE TABLE OF BAPIRET2 WITH HEADER LINE.
DATA RESULT LIKE TREXS_CONNECTION_CHECK_RESULT.
GT_HEADER-TZNUM = GT_ITAB_HEAD-TZNUM.
GT_HEADER-USRID = SY-UNAME.
GT_HEADER-CRDAT = SY-DATUM.
GT_HEADER-ISSHEN = ''.
APPEND GT_HEADER.
CALL FUNCTION 'TREX_RFC_CONNECT_CHECK_LOCAL'
EXPORTING
TREX_DESTINATION = 'SAPEAI'
IMPORTING
LOCAL_RESULT = RESULT
EXCEPTIONS
SYSTEM_FAILURE = 1
COMMUNICATION_FAILURE = 2
AUTHORITY_NOT_AVAILABLE = 3
SEND_ERROR = 4
OTHERS = 5.
IF RESULT-ERROR_CODE <> 0."无响应
MESSAGE '连接错误,请检查EAI服务是否注册成功' TYPE 'E'.
ELSE.
CALL FUNCTION 'ZSD_IF_FM023' DESTINATION 'SAPJCO'
TABLES
HEADER = GT_HEADER
RETURN = GT_RETURN.
IF GT_RETURN[] IS NOT INITIAL.
READ TABLE GT_RETURN INDEX 1.
IF GT_RETURN-TYPE <> 'S'.
GS_ZSDT_LOG029-MESSAGE = ' [EAI接收失败] '.
ELSEIF GT_RETURN-TYPE = 'S'.
GS_ZSDT_LOG029-MESSAGE = ' [EAI接收成功] '.
ENDIF.
ENDIF.
CLEAR:GT_HEADER,GT_RETURN,GT_HEADER[],GT_RETURN[].
ENDIF.
GS_ZSDT_LOG029-ISSHEN = ''. "
GS_ZSDT_LOG029-ERPDO = 'X'. "ERP处理标志
GS_ZSDT_LOG029-EDATS = SY-DATUM. "ERP处理日期
GS_ZSDT_LOG029-ETIMS = SY-UZEIT. "ERP处理时间
GS_ZSDT_LOG029-MESSAGE = GS_ZSDT_LOG029-MESSAGE && '取消审批'.
"写日志表
INSERT ZSDT_LOG029 FROM GS_ZSDT_LOG029.
COMMIT WORK .
CLEAR GS_ZSDT_LOG029.
ENDIF.
ELSE.
MESSAGE '操作失败,不满足条件!' TYPE 'E'.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM .
"------------SHENFORM的FORM--------------------
FORM SHENFORM .
DATA GV_ANSWER TYPE C.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
TEXT_QUESTION = '确认审批?'
DEFAULT_BUTTON = '2'
DISPLAY_CANCEL_BUTTON = ''
IMPORTING
ANSWER = GV_ANSWER.
IF GV_ANSWER <> 1.
RETURN.
ENDIF.
"处理保存到LOG表
LOOP AT GT_ITAB_HEAD.
IF GT_ITAB_HEAD-BOX = 'X'.
GS_ITAB_HEAD = GT_ITAB_HEAD.
IF GS_ITAB_HEAD-BOX = 'X' AND GS_ITAB_HEAD-ISSHEN <> 'X' AND GS_ITAB_HEAD-ISDEL <> 'X' AND GS_ITAB_HEAD-CHUKU <> 'X'.
GS_ZSDT_LOG029-USRID = SY-UNAME. "用户名
GS_ZSDT_LOG029-CRDAT = SY-DATUM. "日期
GS_ZSDT_LOG029-ANUZT = SY-UZEIT. "时间
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
NR_RANGE_NR = 'A1'
OBJECT = 'ZSDFM020'
IMPORTING
NUMBER = GS_ZSDT_LOG029-AUTONUMBER.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' "去掉前导零
EXPORTING
INPUT = GS_ZSDT_LOG029-AUTONUMBER
IMPORTING
OUTPUT = GS_ZSDT_LOG029-AUTONUMBER.
MOVE-CORRESPONDING GS_ITAB_HEAD TO GS_ZSDT_LOG029.
"写业务数据表
UPDATE ZSDT029
SET ISSHEN = 'X'
WHERE TZNUM = GS_ITAB_HEAD-TZNUM.
COMMIT WORK .
IF SY-SUBRC = 0.
DATA GV_TABIX LIKE SY-TABIX.
"改一下控件的内表X数据
LOOP AT GT_ITAB_HEAD.
IF GT_ITAB_HEAD-BOX = 'X'.
GV_TABIX = SY-TABIX.
ENDIF.
ENDLOOP.
"补上当前行的X
READ TABLE GT_ITAB_HEAD INTO GS_ITAB_HEAD INDEX GV_TABIX. "读取当前行
GS_ITAB_HEAD-ISSHEN = 'X'.
MODIFY GT_ITAB_HEAD FROM GS_ITAB_HEAD INDEX GV_TABIX.
"刷新X
DATA: LS_STABLE TYPE LVC_S_STBL.
LS_STABLE-ROW = 'X'.
LS_STABLE-COL = 'X'.
CALL METHOD G_GRID1->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = LS_STABLE
I_SOFT_REFRESH = 'X'.
"传给EAI
DATA GT_HEADER LIKE TABLE OF ZSDS043 WITH HEADER LINE.
DATA GT_RETURN LIKE TABLE OF BAPIRET2 WITH HEADER LINE.
DATA RESULT LIKE TREXS_CONNECTION_CHECK_RESULT.
GT_HEADER-TZNUM = GT_ITAB_HEAD-TZNUM.
GT_HEADER-USRID = SY-UNAME.
GT_HEADER-CRDAT = SY-DATUM.
GT_HEADER-ISSHEN = 'X'.
APPEND GT_HEADER.
CALL FUNCTION 'TREX_RFC_CONNECT_CHECK_LOCAL'
EXPORTING
TREX_DESTINATION = 'SAPEAI'
IMPORTING
LOCAL_RESULT = RESULT
EXCEPTIONS
SYSTEM_FAILURE = 1
COMMUNICATION_FAILURE = 2
AUTHORITY_NOT_AVAILABLE = 3
SEND_ERROR = 4
OTHERS = 5.
IF RESULT-ERROR_CODE <> 0."无响应
MESSAGE '连接错误,请检查EAI服务是否注册成功' TYPE 'E'.
ELSE.
CALL FUNCTION 'ZSD_IF_FM023' DESTINATION 'SAPJCO'
TABLES
HEADER = GT_HEADER
RETURN = GT_RETURN.
IF GT_RETURN[] IS NOT INITIAL.
READ TABLE GT_RETURN INDEX 1.
IF GT_RETURN-TYPE <> 'S'.
GS_ZSDT_LOG029-MESSAGE = ' [EAI接收失败] '.
ELSEIF GT_RETURN-TYPE = 'S'.
GS_ZSDT_LOG029-MESSAGE = ' [EAI接收成功] '.
ENDIF.
ENDIF.
CLEAR:GT_HEADER,GT_RETURN,GT_HEADER[],GT_RETURN[].
ENDIF.
GS_ZSDT_LOG029-ISSHEN = 'X'. "
GS_ZSDT_LOG029-ERPDO = 'X'. "ERP处理标志
GS_ZSDT_LOG029-EDATS = SY-DATUM. "ERP处理日期
GS_ZSDT_LOG029-ETIMS = SY-UZEIT. "ERP处理时间
GS_ZSDT_LOG029-MESSAGE = GS_ZSDT_LOG029-MESSAGE && '确认审批'.
"写日志表
INSERT ZSDT_LOG029 FROM GS_ZSDT_LOG029.
COMMIT WORK .
CLEAR GS_ZSDT_LOG029.
ENDIF.
ELSE.
MESSAGE '操作失败,不满足条件!' TYPE 'E'.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM .
"-------------打印FORM-----------------
FORM PPPFORM .
DATA GV_FORMNAME TYPE RS38L_FNAM .
DATA GS_CONTROL_PARAMS TYPE SSFCTRLOP.
GS_CONTROL_PARAMS-NO_DIALOG = 'X'.
GS_CONTROL_PARAMS-PREVIEW = 'X'.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
FORMNAME = 'ZMMR0092'
IMPORTING
FM_NAME = GV_FORMNAME.
CALL FUNCTION GV_FORMNAME
EXPORTING
CONTROL_PARAMETERS = GS_CONTROL_PARAMS
USER_SETTINGS = SPACE
TABLES
GT_TAB = GT_PRINT[]
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5.
ENDFORM.