ABAP 报表显示主从表结构
效果图:
查询界面
结果界面
*&---------------------------------------------------------------------* *& Report ZDB_TABLE *&---------------------------------------------------------------------* *&查询及修改记录 *&---------------------------------------------------------------------* REPORT ZDB_TABLE. TABLES:ZDB_HEAD,ZDB_ITEM. TYPES: BEGIN OF TY_HEAD, VBELN TYPE ZDB_HEAD-VBELN, POSNR TYPE ZDB_HEAD-POSNR, ZDEFAU TYPE ZDB_HEAD-ZDEFAU, ZUDATE TYPE ZDB_HEAD-ZUDATE, ZUTIME TYPE ZDB_HEAD-ZUTIME, ZUNAME TYPE ZDB_HEAD-ZUNAME, EXPAND TYPE C, "展开,折叠图标 CBOX TYPE C, "复选框 MSG(100) TYPE C, STUTA TYPE C, END OF TY_HEAD. TYPES: BEGIN OF TY_ITEM, VBELN TYPE ZDB_ITEM-VBELN, POSNR TYPE ZDB_ITEM-POSNR, ZUDATE TYPE ZDB_ITEM-ZUDATE, ZUTIME TYPE ZDB_ITEM-ZUTIME, MSG(100) TYPE C, END OF TY_ITEM. DATA: GT_HEAD TYPE TABLE OF TY_HEAD, GW_HEAD TYPE TY_HEAD, GT_ITEM TYPE TABLE OF TY_ITEM, GW_ITEM TYPE TY_ITEM, IN_ITEM LIKE TABLE OF ZQRGETITEM, WA_ITEM TYPE ZQRGETITEM, MSG TYPE BAPI_MSG, STATUS TYPE ZSTATUS, HL TYPE I, TL TYPE I, COMPNAME TYPE STRING. DATA:GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, GW_FIELDCAT TYPE SLIS_FIELDCAT_ALV, GH_LAYOUT TYPE SLIS_LAYOUT_ALV, GH_KEYINFO TYPE SLIS_KEYINFO_ALV, GW_TNAM_HEAD TYPE SLIS_TABNAME, GW_TNAM_ITEM TYPE SLIS_TABNAME, GW_REPID LIKE SY-REPID. INITIALIZATION. GW_REPID = SY-REPID. GW_TNAM_HEAD = 'GT_HEAD'. GW_TNAM_ITEM = 'GT_ITEM'. CLEAR GH_KEYINFO. GH_KEYINFO-HEADER01 = 'VBELN'. GH_KEYINFO-HEADER02 = 'POSNR'. GH_KEYINFO-ITEM01 = 'VBELN'. GH_KEYINFO-ITEM02 = 'POSNR'. *&---------------------------------------------------------------------* *& 选择屏幕定义 *&---------------------------------------------------------------------* SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001. SELECT-OPTIONS: S_VBELN FOR ZDB_HEAD-VBELN NO INTERVALS, "交货单号 S_POSNR FOR ZDB_HEAD-POSNR NO INTERVALS, "交货项次 S_UDATE FOR ZDB_HEAD-ZUDATE. "提交日期 SELECTION-SCREEN END OF BLOCK B1. PARAMETERS P_CHK AS CHECKBOX. *&---------------------------------------------------------------------* *& 执行查询 *&---------------------------------------------------------------------* START-OF-SELECTION. PERFORM FRM_GET_DATA. PERFORM FRM_ALV_FIELDCAT. "碎料,FIELDCAT PERFORM FRM_OUTPUT_DISPLAY. * PERFORM FRM_ALV_DISPLAY. *&---------------------------------------------------------------------* *& Form FRM_GET_DATA *&---------------------------------------------------------------------* * 获取数据源 *----------------------------------------------------------------------* FORM FRM_GET_DATA . IF P_CHK <> 'X'. CLEAR GT_HEAD. CLEAR GT_ITEM. SELECT * INTO TABLE @GT_HEAD FROM ZDB_HEAD WHERE VBELN IN @S_VBELN AND POSNR IN @S_POSNR AND ZUDATE IN @S_UDATE. SELECT * INTO TABLE @GT_ITEM FROM ZDB_ITEM WHERE VBELN IN @S_VBELN AND POSNR IN @S_POSNR. ENDIF. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_ALV_FIELDCAT *&---------------------------------------------------------------------* FORM FRM_ALV_FIELDCAT . REFRESH GT_FIELDCAT. PERFORM FRM_INIT_FCAT USING: 'EXPAND' 'GT_HEAD' 'EXPAND', 'VBELN' 'GT_HEAD' '交货单号', 'POSNR' 'GT_HEAD' '交货项次', 'ZDEFAU' 'GT_HEAD' '扫描状态', 'ZUNAME' 'GT_HEAD' '提交人员', 'ZUDATE' 'GT_HEAD' '提交日期', 'ZUTIME' 'GT_HEAD' '提交时间', 'MSG' 'GT_HEAD' '消息', 'VBELN' 'GT_ITEM' '交货单号', 'POSNR' 'GT_ITEM' '交货项次', 'PRONO' 'GT_ITEM' '批次号码', 'SPEC' 'GT_ITEM' '物料品名', 'NETWT' 'GT_ITEM' '物料重量', 'PIECE' 'GT_ITEM' '物料条数', 'ZTMDIFF' 'GT_ITEM' '提交时差', 'ZUDATE' 'GT_ITEM' '提交日期', 'ZUTIME' 'GT_ITEM' '提交时间', 'MSG' 'GT_ITEM' '消息'. ENDFORM. *&---------------------------------------------------------------------* *& FORM SET_STATUS GUI状态设置 *&---------------------------------------------------------------------* FORM FRM_SET_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB . SET PF-STATUS 'ZGUI001' ."EXCLUDING RT_EXTAB. “显示所有ALV功能按钮 ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_OUTPUT_DISPLAY *&---------------------------------------------------------------------* FORM FRM_OUTPUT_DISPLAY . GH_LAYOUT-EXPAND_FIELDNAME = 'EXPAND'. "展开/折叠的图标 GH_LAYOUT-DETAIL_INITIAL_LINES = 'X'. GH_LAYOUT-EXPAND_ALL = 'X'. "初始界面,默认展开行 GH_LAYOUT-COLWIDTH_OPTIMIZE = 'X'. GH_LAYOUT-BOX_FIELDNAME = 'CBOX'. CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY' EXPORTING I_CALLBACK_PROGRAM = GW_REPID I_CALLBACK_PF_STATUS_SET = 'FRM_SET_STATUS' "GUI状态 I_CALLBACK_USER_COMMAND = 'FRM_USER_COMMAND' "用户操作 IS_LAYOUT = GH_LAYOUT "布局名称 IT_FIELDCAT = GT_FIELDCAT "FIELDCAT名称 I_TABNAME_HEADER = GW_TNAM_HEAD "Header名,引号里大写 I_TABNAME_ITEM = GW_TNAM_ITEM "Item名,引号里大写 IS_KEYINFO = GH_KEYINFO "关联Header和Item的栏位 TABLES T_OUTTAB_HEADER = GT_HEAD "LIST Header表 T_OUTTAB_ITEM = GT_ITEM "LIST Item表 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_INIT_FCAT *&---------------------------------------------------------------------* FORM FRM_INIT_FCAT USING FU_FNAME FU_REF_TABLE FU_COLTEXT. CLEAR GW_FIELDCAT. "清空FIELDCAT工作区 GW_FIELDCAT-FIELDNAME = FU_FNAME. "FIELDCAT 字段名 GW_FIELDCAT-TABNAME = FU_REF_TABLE. "对应数据库表 GW_FIELDCAT-SELTEXT_M = FU_COLTEXT. "中描述 GW_FIELDCAT-JUST = 'L'. IF GW_FIELDCAT-FIELDNAME = 'EXPAND'. GW_FIELDCAT-NO_OUT = 'X'. ENDIF. APPEND GW_FIELDCAT TO GT_FIELDCAT. "添加到内表 ENDFORM. *&---------------------------------------------------------------------* *& FORM USER_COMMAND 用户自定义按钮 *&---------------------------------------------------------------------* FORM FRM_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM RS_SELFIELD TYPE SLIS_SELFIELD. IF P_CHK = 'X'. CASE R_UCOMM. WHEN '&IN'. PERFORM FRM_INSERT_TABLE. ENDCASE. ELSE. CASE R_UCOMM. WHEN '&UP'. PERFORM FRM_UPDATE_TABLE.ENDCASE. ENDIF. RS_SELFIELD-REFRESH = 'X'. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_UPDATE_QRTABLE *&---------------------------------------------------------------------* FORM FRM_UPDATE_QRTABLE . LOOP AT GT_HEAD INTO GW_HEAD WHERE CBOX = 'X' . UPDATE ZDB_HEAD SET ZUNAME = @SY-UNAME, ZUDATE = @SY-DATUM, ZUTIME = @SY-UZEIT WHERE VBELN = @GW_HEAD-VBELN AND POSNR = @GW_HEAD-POSNR. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING WAIT = 'X'. IF SY-SUBRC = 0. GW_HEAD-MSG = '状态更新成功!'. GW_HEAD-ZDEFAU = SPACE. ELSE. GW_HEAD-MSG = '更新失败,请重试!'. ENDIF. MODIFY GT_HEAD FROM GW_HEAD INDEX SY-TABIX. ENDLOOP. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_INSERT_QRTABLE *&输入记录:将已扫描标识更新入HEAD、ITEM表 *&---------------------------------------------------------------------* FORM FRM_INSERT_QRTABLE . DATA: TEXT(50) TYPE C, L_ANSWER TYPE C, ZCNM TYPE ZCOMPNM, ZUNM TYPE ZUSRNM. HL = LINES( S_VBELN ).CLEAR IN_ITEM. IF HL = 1. WA_ITEM-VBELN = S_VBELN-LOW. WA_ITEM-POSNR = S_POSNR-LOW.APPEND WA_ITEM TO IN_ITEM. CONCATENATE '是否输入交货单' S_VBELN-LOW S_POSNR-LOW '的记录!' INTO TEXT. CALL FUNCTION 'POPUP_TO_CONFIRM' EXPORTING TEXT_QUESTION = TEXT TEXT_BUTTON_1 = 'Yes' TEXT_BUTTON_2 = 'No' DISPLAY_CANCEL_BUTTON = 'X' IMPORTING ANSWER = L_ANSWER EXCEPTIONS TEXT_NOT_FOUND = 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. IF L_ANSWER = 1. "确认输入记录 CALL METHOD CL_GUI_FRONTEND_SERVICES=>GET_COMPUTER_NAME CHANGING COMPUTER_NAME = COMPNAME EXCEPTIONS CNTL_ERROR = 1 ERROR_NO_GUI = 2 NOT_SUPPORTED_BY_GUI = 3 OTHERS = 4. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ELSE. CALL METHOD CL_GUI_CFW=>FLUSH EXCEPTIONS CNTL_SYSTEM_ERROR = 1 CNTL_ERROR = 2 OTHERS = 3. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.ENDIF. ENDIF. ENDIF. ELSE. MESSAGE '输入记录!' TYPE 'E'. ENDIF. ENDFORM.