我需要一个报表,输入超级BOM,把其中的物料的语法相关性展现出来,CS12和CS03都没有这个清单功能。网上很多CS_BOM_EXPL_MAT_V2函数的使用了,我也来一篇我的吧。
*&---------------------------------------------------------------------*
*& Report ZBOM001
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZBOM001.
TABLES:CUOB,CUKN,MARC.
"定义结构体
TYPES: BEGIN OF ty_flight,
index TYPE SY-TABIX,
matnr TYPE STPOX-IDNRK,
KNOBJ TYPE CUOB-knobj,
KNBLK(250) TYPE C,
KNNUM TYPE CUKN-KNNUM,
END OF ty_flight.
DATA gt_flight TYPE TABLE OF ty_flight.
DATA gs_flight TYPE ty_flight.
DATA gt_stb like TABLE OF STPOX.
DATA gt_MAT like TABLE OF CSCMAT.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERS:p_matnr LIKE STPOX-IDNRK.
PARAMETERS:p_w LIKE MARC-werks.
SELECTION-SCREEN END OF BLOCK b1.
CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING
CAPID = 'PP01'
DATUV = '20230814'
* MMORY = ' '
MTNRV = p_matnr
* NLINK = ' '
* STKKZ = ' '
STLAL = '1'
STLAN = '1'
* STPST = 0
* SVWVO = 'X'
WERKS = p_w
* NORVL = ' '
* IMPORTING
* TOPMAT =
* DSTST =
TABLES
stb = gt_stb
MATCAT = gt_MAT
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.
case sy-subrc.
when 1. message 'alt_not_found' type 'S' display like 'E'.
when 2. message 'call_invalid ' type 'S' display like 'E'.
when 3. message 'material_not_found' type 'S' display like 'E'.
when 4. message 'missing_authorization' type 'S' display like 'E'.
when 5. message 'no_bom_found ' type 'S' display like 'E'.
when 6. message 'no_plant_data ' type 'S' display like 'E'.
when 7. message 'no_suitable_bom_found' type 'S' display like 'E'.
when 8. message 'conversion_error' type 'S' display like 'E'.
endcase.
exit.
ENDIF.
DATA gt_CUOB TYPE SORTED TABLE OF CUOB WITH NON-UNIQUE KEY KNOBJ.
DATA gs_CUOB TYPE CUOB.
DATA gt_CUKN TYPE SORTED TABLE OF CUKN WITH NON-UNIQUE KEY KNNUM.
DATA gs_CUKN TYPE CUKN.
SELECT * INTO TABLE gt_CUOB FROM CUOB.
SELECT * INTO TABLE gt_CUKN FROM CUKN.
LOOP AT gt_stb ASSIGNING FIELD-SYMBOL(<FS109>) .
READ TABLE gt_CUOB WITH KEY KNOBJ = <fs109>-KNOBJ INTO gs_CUOB.
IF sy-subrc = 0.
READ TABLE gt_CUKN WITH KEY KNNUM = gs_CUOB-KNNUM INTO gs_CUKN.
IF sy-subrc = 0.
gs_flight-matnr = <FS109>-idnrk.
gs_flight-KNOBJ = <FS109>-KNOBJ.
CONDENSE gs_CUKN-KNBLK.
gs_flight-KNBLK = gs_CUKN-KNBLK+6(1024).
gs_flight-KNNUM = gs_CUKN-KNNUM.
APPEND gs_flight TO gt_flight.
ENDIF.
ENDIF.
ENDLOOP.
LOOP AT gt_flight ASSIGNING FIELD-SYMBOL(<FS144>) .
<FS144>-index = SY-TABIX.
ENDLOOP.
DATA: LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
WS_FIELDGROUPS_TAB TYPE SLIS_T_SP_GROUP_ALV,
WS_LAYOUT TYPE SLIS_LAYOUT_ALV,
WS_SORTFIELDS_TAB TYPE SLIS_T_SORTINFO_ALV WITH HEADER LINE,
WS_EVENTS TYPE SLIS_T_EVENT.
DATA: lv_pos TYPE I VALUE 0.
DATA: TITLE TYPE LVC_TITLE.
DATA: COLOR TYPE SLIS_T_SPECIALCOL_ALV WITH HEADER LINE.
DEFINE macro_fieldcat.
lv_pos = lv_pos + 1.
ls_fieldcat-col_pos = lv_pos.
ls_fieldcat-tabname = 'gt_flight'.
ls_fieldcat-fieldname = &1.
ls_fieldcat-seltext_l = &2.
ls_fieldcat-inttype = &3.
ls_fieldcat-no_zero = &4.
ls_fieldcat-INTLEN = &5.
append ls_fieldcat to lt_fieldcat .
clear ls_fieldcat.
END-OF-DEFINITION.
macro_fieldcat:
'index' 'ID' '' '' '',
'matnr' '物料' '' '' '',
'KNOBJ' 'KNOBJ' '' '' '',
'KNBLK' '语法' '' '' '',
'KNNUM' 'KNNUM' '' '' ''
.
WS_LAYOUT-ZEBRA = 'X'.
WS_LAYOUT-GET_SELINFOS = 'X'.
WS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
WS_LAYOUT-DETAIL_POPUP = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = WS_LAYOUT
IT_FIELDCAT = LT_FIELDCAT
IT_SPECIAL_GROUPS = WS_FIELDGROUPS_TAB[]
IT_SORT = WS_SORTFIELDS_TAB[]
IT_EVENTS = WS_EVENTS[]
I_GRID_TITLE = TITLE
I_DEFAULT = 'X'
I_SAVE = 'A'
TABLES
T_OUTTAB = gt_flight
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.