CS03_BOM数据展开
一、功能介绍
-
使用事务码CS03进行数据展开
二、程序代码
-
程序代码:
*&---------------------------------------------------------------------* *& Report ZMMR119 *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT zmmr119. TABLES:mara. TYPES: BEGIN OF ty_data, matnr TYPE makt-matnr, ojtxb TYPE stpox-ojtxb, idnrk TYPE stpox-idnrk, ojtxp TYPE stpox-ojtxp, sortf TYPE stpox-sortf, menge TYPE stpox-menge, END OF ty_data. *&----------------------------------------------------------------- * *内表、工作区、变量、常量、指针定义 * *&----------------------------------------------------------------- DATA: gt_data TYPE STANDARD TABLE OF ty_data, gs_data TYPE ty_data. DATA: gt_data1 TYPE STANDARD TABLE OF ty_data, gs_data1 TYPE ty_data. DATA: gs_layout TYPE lvc_s_layo. DATA: gt_fieldcat TYPE lvc_t_fcat, gs_fieldcat TYPE lvc_s_fcat. "弹窗 ******************************* *屏幕处理 ******************************* SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE TEXT-001. PARAMETERS:p_datuv TYPE sy-datum DEFAULT sy-datum. SELECT-OPTIONS s_matnr FOR mara-matnr . SELECTION-SCREEN END OF BLOCK blk1. SELECTION-SCREEN: FUNCTION KEY 1. ******************************* *主程序入口 ******************************* *&-------------------------------------------------------------- **初始化处理 *&-------------------------------------------------------------- INITIALIZATION. *&-------------------------------------------------------------- **选择屏幕控制 *&-------------------------------------------------------------- AT SELECTION-SCREEN OUTPUT. *&-------------------------------------------------------------* *& 参数输入检查 *&-------------------------------------------------------------* AT SELECTION-SCREEN. *&------------------------------------------------------------- **程序开始处理 *&------------------------------------------------------------- START-OF-SELECTION. ******************************** *获取数据 ******************************** PERFORM frm_get_data. * ALV显示 PERFORM frm_set_alv. "设置ALV属性 PERFORM frm_dis_alv. "调用ALV END-OF-SELECTION. ******************************* *FORM子程序 ******************************* *&---------------------------------------------------------------------* *& Form GET_DATA *&---------------------------------------------------------------------* * 获取数据 *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_get_data. DATA :gt_stpox TYPE STANDARD TABLE OF stpox, gs_stpox TYPE stpox, gt_cscmat TYPE STANDARD TABLE OF cscmat, gs_cscmat TYPE cscmat. DATA lv_ojtxb TYPE stpox-ojtxb. DATA lv_menge TYPE stpox-menge. DATA lv_num TYPE i. SELECT matnr FROM mara WHERE matkl = 'Z009' AND matnr IN @s_matnr INTO TABLE @DATA(lt_mara). LOOP AT lt_mara INTO DATA(ls_mara). CLEAR :gt_stpox,gs_stpox, gt_cscmat, gs_cscmat,lv_ojtxb. CALL FUNCTION 'CS_BOM_EXPL_MAT_V2' EXPORTING capid = 'PP01' datuv = p_datuv mehrs = 'X' mtnrv = ls_mara-matnr werks = '1000' TABLES stb = gt_stpox " matcat = gt_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. * Implement suitable error handling here ENDIF. SORT gt_stpox ASCENDING BY msign idnrk ASCENDING dokar ASCENDING doknr ASCENDING dokvr ASCENDING doktl ASCENDING class ASCENDING klart ASCENDING postp ASCENDING potx1 ASCENDING potx2 ASCENDING werks ASCENDING sortf ASCENDING. READ TABLE gt_stpox INTO gs_stpox WITH KEY ttidx = 1. IF sy-subrc = 0. lv_ojtxb = gs_stpox-ojtxb. ENDIF. LOOP AT gt_stpox INTO gs_stpox . gs_data1-matnr = ls_mara-matnr. gs_data1-ojtxb = lv_ojtxb. gs_data1-idnrk = gs_stpox-idnrk. gs_data1-idnrk = |{ gs_data1-idnrk ALPHA = OUT }|. gs_data1-ojtxp = gs_stpox-ojtxp. gs_data1-menge = gs_stpox-menge. gs_data1-sortf = gs_stpox-sortf. APPEND gs_data1 TO gt_data1. CLEAR gs_stpox. ENDLOOP. CLEAR ls_mara. ENDLOOP. LOOP AT gt_data1 INTO gs_data1. lv_menge = lv_menge + gs_data1-menge. lv_num = lv_num + 1. AT END OF sortf. MOVE gs_data1 TO gs_data. gs_data-menge = lv_menge. IF lv_num > 1. gs_data-sortf = ''. ENDIF. APPEND gs_data TO gt_data. CLEAR :gs_data,lv_menge,lv_num. ENDAT. CLEAR gs_data1. ENDLOOP. IF gt_data IS INITIAL. MESSAGE '未查询到符合条件的数据!' TYPE 'S' DISPLAY LIKE 'E'. LEAVE LIST-PROCESSING. ENDIF. ENDFORM. " GET_DATA *&---------------------------------------------------------------------* *& Form FRM_SET_ALV *&---------------------------------------------------------------------* * alv设置 *---------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_set_alv. DATA: l_colpos TYPE lvc_s_fcat-col_pos VALUE 0. *&---------------------------------------------------------------------* *& 定义宏 *&---------------------------------------------------------------------* DEFINE macro_fill_fcat. CLEAR gs_fieldcat. &1 = &1 + 1. gs_fieldcat-col_pos = &1. gs_fieldcat-fieldname = &2. gs_fieldcat-coltext = &3. APPEND gs_fieldcat TO gt_fieldcat. END-OF-DEFINITION. FIELD-SYMBOLS: <fs_fieldcat> TYPE lvc_s_fcat. CLEAR gt_fieldcat. macro_fill_fcat: l_colpos 'MATNR' 'P总成物料号' , l_colpos 'OJTXB' 'P总成物料号描述' , l_colpos 'IDNRK' '下级件' , l_colpos 'OJTXP' '下级件描述' , l_colpos 'MENGE' '下级件装车系数' , l_colpos 'SORTF' '下级件工序落点' . CLEAR gs_layout. gs_layout-zebra = 'X'. gs_layout-cwidth_opt = 'X'. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_DIS_ALV *&---------------------------------------------------------------------* * alv输出 *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_dis_alv . DATA: lv_grid TYPE lvc_s_glay. lv_grid-edt_cll_cb = 'X'. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' EXPORTING i_callback_program = sy-repid i_callback_pf_status_set = 'PF_STATUS_SET' i_callback_user_command = 'FRM_USER_COMMAND' i_grid_settings = lv_grid is_layout_lvc = gs_layout it_fieldcat_lvc = gt_fieldcat TABLES t_outtab = gt_data. ENDFORM. " FRM_ALV *&---------------------------------------------------------------------* *& Form PF_STATUS_SET *&---------------------------------------------------------------------* * gui状态 *----------------------------------------------------------------------* * -->TR_EXTAB text *----------------------------------------------------------------------* FORM pf_status_set USING pr_extab TYPE slis_t_extab. SET PF-STATUS 'STANDARD' . ENDFORM. " PF_STATUS_SET *&---------------------------------------------------------------------* *& Form frm_user_command *&---------------------------------------------------------------------* * 用戶响应事件 *----------------------------------------------------------------------* * -->R_UCOMM text * -->RS_SELFIELD text *----------------------------------------------------------------------* FORM frm_user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield. *刷新alv DATA:lob_grid TYPE REF TO cl_gui_alv_grid. CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' IMPORTING e_grid = lob_grid. CALL METHOD lob_grid->check_changed_data. rs_selfield-refresh = 'X'. gs_layout-cwidth_opt = 'X'. gs_layout-no_toolbar = 'X'. CALL METHOD lob_grid->set_frontend_layout EXPORTING is_layout = gs_layout. CALL METHOD lob_grid->refresh_table_display. ENDFORM.