1.写程序,
2.话屏幕9000,CALL SCREEN 9000.(双击屏幕进去画个容器就ok,+OK_CODE,+去掉注释)
3.处理好ALV 的PBO 初始化,处理用户事件PAO,user command ,定义的按钮都要有用途;
| ||||||||||||||||
*&---------------------------------------------------------------------* *& Report YDEMO_005 *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT Z_BARRY_ALV_TREE1_BOM MESSAGE-ID OO. TABLES: STPOX. INCLUDE <ICON>. CLASS: CL_GUI_COLUMN_TREE DEFINITION LOAD, CL_GUI_CFW DEFINITION LOAD . DATA: TREE1 TYPE REF TO CL_GUI_ALV_TREE , MR_TOOLBAR TYPE REF TO CL_GUI_TOOLBAR . DATA: GS_STPOX TYPE STPOX, GT_STPOX TYPE STPOX OCCURS 0, GT_FIELDCATALOG TYPE LVC_T_FCAT, GT_ITEM_LAYOUT TYPE LVC_T_LACI, GS_ITEM_LAYOUT TYPE LVC_S_LACI, OKCODE LIKE SY-UCOMM . TYPES: BEGIN OF GS_F. INCLUDE STRUCTURE STPOX. TYPES: NODE_KEY TYPE LVC_NKEY, END OF GS_F. DATA: GS_XSTPOX TYPE GS_F , GT_XSTPOX TYPE GS_F OCCURS 0. DATA: L_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER. DATA: WA_TOPMAT TYPE CSTMAT, WA_DSTST TYPE CSDATA-XFELD. DATA: IT_MATCAT TYPE STANDARD TABLE OF CSCMAT. PARAMETERS:P_MATNR LIKE MAST-MATNR OBLIGATORY, P_WERKS LIKE MAST-WERKS OBLIGATORY, P_STLAL LIKE MAST-STLAL OBLIGATORY DEFAULT '01', "可选的 BOM P_CAPID LIKE RC29L-CAPID OBLIGATORY DEFAULT 'PP01'."BOM应用程序 *PARAMETERS: p_matnr LIKE mara-matnr, "DEFAULT 'YW25K', * p_werks LIKE ekpo-werks. "DEFAULT '1010' . START-OF-SELECTION. PERFORM GETDATA. CALL SCREEN 9000. *&---------------------------------------------------------------------* *& Form getdata *&---------------------------------------------------------------------* FORM GETDATA. *&bom explosion * CALL FUNCTION 'CS_BOM_EXPL_MAT_V2' ** EXPORTING ** FTREL = ' ' ** ALEKZ = ' ' ** ALTVO = ' ' ** AUFSW = ' ' ** AUMGB = ' ' ** AUMNG = 0 ** AUSKZ = ' ' ** AMIND = ' ' ** BAGRP = ' ' ** BEIKZ = ' ' ** BESSL = ' ' ** BGIXO = ' ' ** BREMS = ' ' ** CAPID = 'STD1' ** CHLST = ' ' ** COSPR = ' ' ** CUOBJ = 000000000000000 ** CUOVS = 0 ** CUOLS = ' ' ** DATUV = 00000000 ** DELNL = ' ' ** DRLDT = ' ' ** EHNDL = ' ' ** EMENG = 0 ** ERSKZ = ' ' ** ERSSL = ' ' ** FBSTP = ' ' ** KNFBA = ' ' ** KSBVO = ' ' ** MBWLS = ' ' ** MKTLS = 'X' ** MDMPS = ' ' ** MEHRS = ' ' ** MKMAT = ' ' ** MMAPS = ' ' ** SALWW = ' ' ** SPLWW = ' ' ** MMORY = ' ' ** MTNRV = ' ' ** NLINK = ' ' ** POSTP = ' ' ** RNDKZ = ' ' ** RVREL = ' ' ** SANFR = ' ' ** SANIN = ' ' ** SANKA = ' ' ** SANKO = ' ' ** SANVS = ' ' ** SCHGT = ' ' ** STKKZ = ' ' ** STLAL = ' ' ** STLAN = ' ' ** STPST = 0 ** SVWVO = 'X' ** WERKS = ' ' ** NORVL = ' ' ** MDNOT = ' ' ** PANOT = ' ' ** QVERW = ' ' ** VERID = ' ' ** VRSVO = 'X' ** IMPORTING ** TOPMAT = ** DSTST = * TABLES * STB = ** MATCAT = ** EXCEPTIONS ** ALT_NOT_FOUND = 1 ** CALL_INVALID = 2 ** MATERIAL_NOT_FOUND = 3 ** MISSING_AUTHORIZATION = 4 ** NO_BOM_FOUND = 5 ** NO_PLANT_DATA = 6 ** NO_SUITABLE_BOM_FOUND = 7 ** CONVERSION_ERROR = 8 ** OTHERS = 9 CALL FUNCTION 'CS_BOM_EXPL_MAT_V2' EXPORTING CAPID = P_CAPID "'CAD1' DATUV = SY-DATUM EMENG = '1' "基本用量 MTNRV = P_MATNR WERKS = P_WERKS MKTLS = 'X' "p_key MEHRS = 'X' "p_mehrs STLAL = P_STLAL "可选BOM STLAN = '1' "BOM 用途 * emeng = 1 IMPORTING TOPMAT = WA_TOPMAT DSTST = WA_DSTST TABLES STB = GT_STPOX MATCAT = IT_MATCAT EXCEPTIONS ALT_NOT_FOUND = 1 CALL_INVALID = 2 MATERIAL_NOT_FOUND = 3 MISSING_AUTHORIZATION = 4 NO_BOM_FOUND = 5 NO_PLANT_DATA = 6 NO_SUITABLE_BOM_FOUND = 7 CONVERSION_ERROR = 8 OTHERS = 9. * CASE sy-subrc . * WHEN 1 . * MESSAGE e899(fi) WITH 'alt_not_found'. * WHEN 2 . * MESSAGE e899(fi) WITH 'call_invalid '. * WHEN 3 . * MESSAGE e899(fi) WITH 'material_not_found'. * WHEN 4 . * MESSAGE e899(fi) WITH 'missing_authorization'. * WHEN 5 . * MESSAGE e899(fi) WITH 'no_bom_found'. * WHEN 6 . * MESSAGE e899(fi) WITH 'no_plant_data'. * WHEN 7 . * MESSAGE e899(fi) WITH 'no_suitable_bom_found'. * WHEN 8 . * MESSAGE e899(fi) WITH 'conversion_error'. * WHEN 9 . * MESSAGE e899(fi) WITH 'OTHERS Error'. * ENDCASE. LOOP AT GT_STPOX INTO GS_STPOX. MOVE-CORRESPONDING GS_STPOX TO GS_XSTPOX . APPEND GS_XSTPOX TO GT_XSTPOX. ENDLOOP. ENDFORM. "getdata *----------------------------------------------------------------------* * MODULE status_9000 OUTPUT *----------------------------------------------------------------------* MODULE STATUS_9000 OUTPUT. SET PF-STATUS 'MAIN'. SET TITLEBAR 'TITLE'. IF TREE1 IS INITIAL. PERFORM INIT_TREE. ENDIF. CALL METHOD CL_GUI_CFW=>FLUSH. ENDMODULE. " PBO_9000 OUTPUT *----------------------------------------------------------------------* * MODULE user_command_9000 INPUT *----------------------------------------------------------------------* MODULE USER_COMMAND_9000 INPUT. CASE OKCODE. WHEN 'EXIT' OR 'BACK' OR 'CANC'. CALL METHOD TREE1->FREE. LEAVE PROGRAM . WHEN OTHERS. CALL METHOD CL_GUI_CFW=>DISPATCH. ENDCASE. CLEAR OKCODE. CALL METHOD CL_GUI_CFW=>FLUSH. ENDMODULE. " okcode INPUT *&---------------------------------------------------------------------* *& Form init_tree *&---------------------------------------------------------------------* FORM INIT_TREE . PERFORM BUILD_FIELDCATALOG. * IF sy-batch IS INITIAL. * CREATE OBJECT l_custom_container * EXPORTING * container_name = 'TREE1' * EXCEPTIONS * cntl_error = 1 * cntl_system_error = 2 * create_error = 3 * lifetime_error = 4 * lifetime_dynpro_dynpro_link = 5. * IF sy-subrc <> 0. * MESSAGE e000 WITH '创建容器:TREE1 错误'. * ENDIF. * ENDIF. CREATE OBJECT TREE1 EXPORTING * parent = l_custom_container PARENT = CL_GUI_CONTAINER=>SCREEN0 NODE_SELECTION_MODE = CL_GUI_COLUMN_TREE=>NODE_SEL_MODE_SINGLE ITEM_SELECTION = 'X' NO_HTML_HEADER = 'X' NO_TOOLBAR = ' ' EXCEPTIONS CNTL_ERROR = 1 CNTL_SYSTEM_ERROR = 2 CREATE_ERROR = 3 LIFETIME_ERROR = 4 ILLEGAL_NODE_SELECTION_MODE = 5 FAILED = 6 ILLEGAL_COLUMN_NAME = 7. IF SY-SUBRC <> 0. MESSAGE E000 WITH '创建TREE错误'. ENDIF. DATA L_HIERARCHY_HEADER TYPE TREEV_HHDR. PERFORM BUILD_HIERARCHY_HEADER CHANGING L_HIERARCHY_HEADER. DATA: LS_VARIANT TYPE DISVARIANT. LS_VARIANT-REPORT = SY-REPID. CALL METHOD TREE1->SET_TABLE_FOR_FIRST_DISPLAY EXPORTING IS_HIERARCHY_HEADER = L_HIERARCHY_HEADER I_BACKGROUND_ID = 'ALV_BACKGROUND' I_SAVE = 'A' IS_VARIANT = LS_VARIANT CHANGING IT_OUTTAB = GT_STPOX "table must be emty !! IT_FIELDCATALOG = GT_FIELDCATALOG. DATA: L1 TYPE LVC_NKEY ,L2 TYPE LVC_NKEY ,L3 TYPE LVC_NKEY ,L4 TYPE LVC_NKEY , L5 TYPE LVC_NKEY ,L6 TYPE LVC_NKEY ,L7 TYPE LVC_NKEY ,L8 TYPE LVC_NKEY , L_KEY TYPE LVC_NKEY, L_LAST_KEY TYPE LVC_NKEY , ADDED . LOOP AT GT_XSTPOX INTO GS_XSTPOX . MOVE-CORRESPONDING GS_XSTPOX TO GS_STPOX. CASE GS_STPOX-STUFE . WHEN '1'. L_KEY = ''. WHEN '2'. L_KEY = L1. WHEN '3'. L_KEY = L2. WHEN '4'. L_KEY = L3. WHEN '5'. L_KEY = L4. WHEN '6'. L_KEY = L5. ENDCASE. PERFORM ADD_COMPLETE_LINE USING GS_STPOX L_KEY CHANGING L_LAST_KEY. GS_XSTPOX-NODE_KEY = L_LAST_KEY. CASE GS_STPOX-STUFE . WHEN '1'. L1 = L_LAST_KEY. WHEN '2'. L2 = L_LAST_KEY. WHEN '3'. L3 = L_LAST_KEY. WHEN '4'. L4 = L_LAST_KEY. WHEN '5'. L5 = L_LAST_KEY. WHEN '6'. L6 = L_LAST_KEY. ENDCASE. MODIFY GT_XSTPOX FROM GS_XSTPOX . ENDLOOP. CALL METHOD TREE1->UPDATE_CALCULATIONS. CALL METHOD TREE1->FRONTEND_UPDATE. ENDFORM. " init_tree *&---------------------------------------------------------------------* *& Form build_fieldcatalog *&---------------------------------------------------------------------* FORM BUILD_FIELDCATALOG. CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING I_STRUCTURE_NAME = 'STPOX' CHANGING CT_FIELDCAT = GT_FIELDCATALOG. DATA: LS_FIELDCATALOG TYPE LVC_S_FCAT. LOOP AT GT_FIELDCATALOG INTO LS_FIELDCATALOG. * CASE ls_fieldcatalog-fieldname. * WHEN 'CARRID' OR 'CONNID' OR 'FLDATE'. * ls_fieldcatalog-no_out = 'X'. * ls_fieldcatalog-key = ''. * WHEN 'PRICE' OR 'SEATSOCC' OR 'SEATSMAX' OR 'PAYMENTSUM'. ** ls_fieldcatalog-do_sum = 'X'. * WHEN 'PLANETYPE'. * ls_fieldcatalog-edit = 'X'. * ls_fieldcatalog-style = cl_gui_alv_grid=>mc_style_enabled . * ENDCASE. MODIFY GT_FIELDCATALOG FROM LS_FIELDCATALOG. ENDLOOP. ENDFORM. " build_fieldcatalog *&---------------------------------------------------------------------* *& Form build_hierarchy_header *&---------------------------------------------------------------------* FORM BUILD_HIERARCHY_HEADER CHANGING P_HIERARCHY_HEADER TYPE TREEV_HHDR. * P_HIERARCHY_HEADER-HEADING = 'BOM层次'. P_HIERARCHY_HEADER-TOOLTIP = 'ToolTip'. P_HIERARCHY_HEADER-WIDTH = 30. P_HIERARCHY_HEADER-WIDTH_PIX = ''. * ENDFORM. " build_hierarchy_header *&---------------------------------------------------------------------* *& Form add_complete_line *&---------------------------------------------------------------------* FORM ADD_COMPLETE_LINE USING PS_STPOX TYPE STPOX P_RELAT_KEY TYPE LVC_NKEY CHANGING P_NODE_KEY TYPE LVC_NKEY. DATA: L_NODE_TEXT TYPE LVC_VALUE. * set item-layout DATA: LT_ITEM_LAYOUT TYPE LVC_T_LAYI, LS_ITEM_LAYOUT TYPE LVC_S_LAYI. DATA: STUFE_NUM(2) TYPE N. LS_ITEM_LAYOUT-FIELDNAME = TREE1->C_HIERARCHY_COLUMN_NAME. LS_ITEM_LAYOUT-CLASS = CL_GUI_COLUMN_TREE=>ITEM_CLASS_TEXT. * ls_item_layout-editable = 'X'. * ls_item_layout-chosen = 'X'. " 设置为选中状态 APPEND LS_ITEM_LAYOUT TO LT_ITEM_LAYOUT. * l_node_text = ps_stpox-ojtxp. STUFE_NUM = PS_STPOX-STUFE. CONCATENATE STUFE_NUM ',' PS_STPOX-OJTXP INTO L_NODE_TEXT. CALL METHOD TREE1->ADD_NODE EXPORTING I_RELAT_NODE_KEY = P_RELAT_KEY I_RELATIONSHIP = CL_GUI_COLUMN_TREE=>RELAT_LAST_CHILD IS_OUTTAB_LINE = PS_STPOX I_NODE_TEXT = L_NODE_TEXT IT_ITEM_LAYOUT = LT_ITEM_LAYOUT IMPORTING E_NEW_NODE_KEY = P_NODE_KEY. ENDFORM. " add_complete_line