*&---------------------------------------------------------------------* *& Report ZPPR2033 *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT zppr2033. *---------------------------------------------------------------------* * Table define *---------------------------------------------------------------------* TABLES: makt, mara. *---------------------------------------------------------------------* * Type define *---------------------------------------------------------------------* * 反查物料清单要用到的明细 DATA: stb TYPE STANDARD TABLE OF stpox. DATA: gs_wultb LIKE stpov, gt_wultb LIKE STANDARD TABLE OF stpov, gt_equicat LIKE TABLE OF cscequi, gt_kndcat LIKE TABLE OF cscknd, gt_matcat LIKE TABLE OF cscmat, gt_stdcat LIKE TABLE OF cscstd, gt_tplcat LIKE TABLE OF csctpl, gt_prjcat LIKE TABLE OF cscprj. DATA: cscmat TYPE STANDARD TABLE OF cscmat. DATA: mehrs. *---------------------------------------------------------------------* * ALV define *---------------------------------------------------------------------* DATA: gt_fieldcat TYPE lvc_t_fcat, gs_fieldcat TYPE lvc_s_fcat, gs_layout TYPE lvc_s_layo. *---------------------------------------------------------------------* * SELECTION-SCREEN define *---------------------------------------------------------------------* SELECTION-SCREEN BEGIN OF BLOCK 001 WITH FRAME TITLE TEXT-001. PARAMETERS:p_werks TYPE werks_d, p_matnr TYPE matnr. SELECTION-SCREEN:SKIP. PARAMETERS:p_menge TYPE menge_d DEFAULT '1', p_datum TYPE d DEFAULT sy-datum. SELECTION-SCREEN:SKIP. PARAMETERS:r1 RADIOBUTTON GROUP g1 DEFAULT 'X', r2 RADIOBUTTON GROUP g1, r3 RADIOBUTTON GROUP g1, r4 RADIOBUTTON GROUP g1. SELECTION-SCREEN END OF BLOCK 001. *---------------------------------------------------------------------* * INITIALIZATION *---------------------------------------------------------------------* INITIALIZATION. %_r1_%_app_%-text = '展开单层'(s01). %_r2_%_app_%-text = '展开多层'(s02). %_r3_%_app_%-text = '反查单层'(s03). %_r4_%_app_%-text = '反查多层'(s04). %_p_werks_%_app_%-text = '工厂'(s05). %_p_matnr_%_app_%-text = '物料'(s06). %_p_menge_%_app_%-text = '展开基础数量'(s07). %_p_datum_%_app_%-text = '展开日期'(s08). *---------------------------------------------------------------------* * START_OF_SELECTION *---------------------------------------------------------------------* START-OF-SELECTION. PERFORM sub_get_data. PERFORM sub_display_data. *&---------------------------------------------------------------------* *& FORM SUB_GET_DATA *&---------------------------------------------------------------------* * 获取数据 *----------------------------------------------------------------------* FORM sub_get_data. data:ls_bom type stpov. IF r1 = 'X' OR r2 = 'X'."展开单层或多层BOM表 IF r1 = 'X'. mehrs = ''. ELSE. mehrs = 'X'. ENDIF. PERFORM expandbom. ELSEIF r3 = 'X'."反查单层BOM表 PERFORM where_user_bom. ELSEIF r4 = 'X'."反查多层BOM表 ls_bom = VALUE #( level = 1 matnr = p_matnr ). append ls_bom to gt_wultb. PERFORM where_user_bom_mulit USING ls_bom 1. ENDIF. ENDFORM. "GET_DATA *&---------------------------------------------------------------------* *& FORM SUB_BUILD_ALV_FILEDCAT *&---------------------------------------------------------------------* * 显示数据 *----------------------------------------------------------------------* FORM sub_build_alv_filedcat. * gt_fieldcat = VALUE #( * ( fieldname = 'MATNR' scrtext_l = '物料编号'(t01) ) * ). ENDFORM. *&---------------------------------------------------------------------* *& FORM SUB_DISPLAY_DATA *&---------------------------------------------------------------------* * 显示数据 *----------------------------------------------------------------------* FORM sub_display_data. * PERFORM sub_build_alv_filedcat. gs_layout-cwidth_opt = 'X'. gs_layout-zebra = 'X'. IF r1 = 'X' OR r2 = 'X'."展开单层或多层BOM表 CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' EXPORTING i_callback_program = sy-repid * gt_fieldcat_lvc = gt_fieldcat i_structure_name = 'STPOX' is_layout_lvc = gs_layout i_default = 'X' i_save = 'A' TABLES t_outtab = stb[] EXCEPTIONS OTHERS = 1. ELSEIF r3 = 'X'."反查单层BOM表 CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' EXPORTING i_callback_program = sy-repid * gt_fieldcat_lvc = gt_fieldcat i_structure_name = 'STPOV' is_layout_lvc = gs_layout i_default = 'X' i_save = 'A' TABLES t_outtab = gt_wultb EXCEPTIONS OTHERS = 1. ELSEIF r4 = 'X'."反查多层BOM表 CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' EXPORTING i_callback_program = sy-repid * gt_fieldcat_lvc = gt_fieldcat i_structure_name = 'ZSPP2033A' is_layout_lvc = gs_layout i_default = 'X' i_save = 'A' TABLES t_outtab = gt_wultb[] EXCEPTIONS OTHERS = 1. ENDIF. ENDFORM. "DISPLAY_DATA *&---------------------------------------------------------------------* *& Form EXPANDBOM *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* *1) 虚拟件 MDMPS - * 多层 MEHRS X * 结果: 全展(显示包含虚拟件) * *2)虚拟件 MDMPS X * 多层 MEHRS X * 结果: 展1或2层(下层遇虚拟件则展开至其下一层,显示包含虚拟件) * *3) 虚拟件 MDMPS - * 多层 MEHRS - * 结果: 展一层(下层为虚拟件,不再向下展开) * *4) 虚拟件 MDMPS X * 多层 MEHRS - * 结果:展一层 (同3,下层为虚拟件,不再向下展开) * 即:MEHRS置空,不论MDMPS如何设置,都只展一层,并且如果下层就是虚拟件,不展开虚拟件至其更下一层,与2)要区别开来 FORM expandbom . CALL FUNCTION 'CS_BOM_EXPL_MAT_V2' EXPORTING ftrel = 'X' * ALEKZ = ' ' * ALTVO = ' ' * AUFSW = ' ' * AUMGB = ' ' * AUMNG = 0 * AUSKZ = ' ' * AMIND = ' ' * BAGRP = ' ' * BEIKZ = ' ' * BESSL = ' ' * BGIXO = ' ' * BREMS = ' ' capid = 'PP01' "表示查询的是生产BOM, * CHLST = ' ' * COSPR = ' ' * CUOBJ = 000000000000000 * CUOVS = 0 * CUOLS = ' ' datuv = p_datum "BOM的有效起始日期,一般指定为当前日,表示读取当前有效的BOM表,如果一个物料有多个版本的BOM表,不同的日期会查出不同版本的BOM * DELNL = ' ' * DRLDT = ' ' ehndl = '1' emeng = p_menge "如果这里填写数量,到时候会用这个数*BOM定额作为组件的数量。,即如果定额为2,传入10,则展开时组件的定额为20 * ERSKZ = ' ' * ERSSL = ' ' * FBSTP = ' ' * KNFBA = ' ' * KSBVO = ' ' * MBWLS = ' ' * MKTLS = 'X' * MDMPS = 'X' "X表示展开虚拟件,为空表示不展开虚拟件 mehrs = mehrs "X表示展开多层,' '表示展开单层,其中还受参数MDMPS影响,MEHRS与MDMPS4种组合见上面所述 * MKMAT = ' ' * MMAPS = ' ' * SALWW = ' ' * SPLWW = ' ' * MMORY = ' ' “是否使用缓存 mtnrv = p_matnr "要展开BOM的物料号码 * NLINK = ' ' * POSTP = ' ' * RNDKZ = ' ' * RVREL = ' ' * SANFR = ' ' * SANIN = ' ' * SANKA = ' ' * SANKO = ' ' * SANVS = ' ' * SCHGT = ' ' * STKKZ = ' ' stlal = '1' "可选BOM的编号 * STLAN = ' ' * STPST = 0 * SVWVO = 'X' werks = p_werks * NORVL = ' ' * MDNOT = ' ' * PANOT = ' ' * QVERW = ' ' * VERID = ' ' * VRSVO = 'X' * IMPORTING * TOPMAT = * DSTST = TABLES stb = stb matcat = cscmat 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. 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. " EXPANDBOM *&---------------------------------------------------------------------* *& Form WHERE_USER_BOM *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM where_user_bom . CLEAR:gt_wultb,gt_wultb[]. CALL FUNCTION 'CS_WHERE_USED_MAT' EXPORTING datub = sy-datum datuv = sy-datum matnr = p_matnr * POSTP = ' ' * RETCODE_ONLY = ' ' * STLAN = ' ' mclmt = '00000000' werks = p_werks * IMPORTING * TOPMAT = TABLES wultb = gt_wultb equicat = gt_equicat kndcat = gt_kndcat matcat = gt_matcat stdcat = gt_stdcat tplcat = gt_tplcat EXCEPTIONS call_invalid = 1 material_not_found = 2 no_where_used_rec_found = 3 no_where_used_rec_selected = 4 no_where_used_rec_valid = 5 OTHERS = 6. 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. " WHERE_USER_BOM *&---------------------------------------------------------------------* *& Form WHERE_USER_BOM_MULIT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM where_user_bom_mulit USING us_bom type stpov VALUE(uv_index) type i. DATA:lt_wultb LIKE STANDARD TABLE OF stpov. DATA:lv_index TYPE i. DATA:lv_matnr TYPE matnr. lv_matnr = us_bom-matnr. lv_index = uv_index + 1. IF lv_matnr is INITIAL or lv_index = 4. RETURN. ENDIF. CALL FUNCTION 'CS_WHERE_USED_MAT' EXPORTING datub = sy-datum datuv = sy-datum matnr = lv_matnr * POSTP = ' ' * RETCODE_ONLY = ' ' * STLAN = ' ' mclmt = '00000000' werks = p_werks * IMPORTING * TOPMAT = TABLES wultb = lt_wultb equicat = gt_equicat kndcat = gt_kndcat matcat = gt_matcat stdcat = gt_stdcat tplcat = gt_tplcat EXCEPTIONS call_invalid = 1 material_not_found = 2 no_where_used_rec_found = 3 no_where_used_rec_selected = 4 no_where_used_rec_valid = 5 OTHERS = 6. IF sy-subrc = 0. LOOP AT lt_wultb INTO DATA(ls_wultb). ls_wultb-level = lv_index. APPEND ls_wultb TO gt_wultb. PERFORM where_user_bom_mulit USING ls_wultb lv_index. ENDLOOP. ENDIF. ENDFORM. " WHERE_USER_BOM_MULIT
标签:反查,sy,gt,&------------------------------------------------------------------ From: https://www.cnblogs.com/yangliu11223/p/18540392