REPORT ZP007 no standard page heading
line-size 120
line-count 100
MESSAGE-ID yt.
DATA: L_BOM_HEADER LIKE BICSK,
L_GROUP_DATA LIKE BGR00,
L_MSGID LIKE T100-ARBGB,
L_MSGNO LIKE T100-MSGNR,
L_MSGTY LIKE SY-MSGTY,
L_MSGV1 LIKE SY-MSGV1,
L_MSGV2 LIKE SY-MSGV2,
L_MSGV3 LIKE SY-MSGV3,
L_MSGV4 LIKE SY-MSGV4,
L_POSNR LIKE BICSP-POSNR.
DATA: LT_BOM_ITEM LIKE BICSP OCCURS 0 WITH HEADER LINE,
LT_SUB_ITEM LIKE BICSU OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF T_DOC OCCURS 0 .
INCLUDE STRUCTURE CSXDOC .
DATA END OF T_DOC.
DATA: BEGIN OF T_EQUI OCCURS 0 .
INCLUDE STRUCTURE CSXEQUI .
DATA END OF T_EQUI.
DATA: BEGIN OF T_KLA OCCURS 0 .
INCLUDE STRUCTURE CSXKLA.
DATA END OF T_KLA.
DATA: BEGIN OF T_MAT OCCURS 0 .
INCLUDE STRUCTURE CSXMAT .
DATA END OF T_MAT.
DATA: BEGIN OF T_GEN OCCURS 0 .
INCLUDE STRUCTURE CSXGEN .
DATA END OF T_GEN.
DATA: BEGIN OF T_TPL OCCURS 0 .
INCLUDE STRUCTURE CSXTPL .
DATA END OF T_TPL.
DATA:BEGIN OF I_VBAP OCCURS 0,
VBELN LIKE VBAP-VBELN,
POSNR LIKE VBAP-POSNR,
MATNR LIKE VBAP-MATNR,
WERKS LIKE VBAP-WERKS,
CUOBJ LIKE VBAP-CUOBJ,
END OF I_VBAP.
DATA: BEGIN OF I_TAB OCCURS 0,
MATNR LIKE MARA-MATNR,
MNGKO LIKE MSEG-MENGE,
END OF I_TAB.
PARAMETERS: P_VBELN LIKE VBAP-VBELN OBLIGATORY,
P_POSNR LIKE VBAP-POSNR OBLIGATORY,
P_STLAN LIKE KDST-STLAN OBLIGATORY DEFAULT '1'.
at selection-screen.
PERFORM CHECK_INPUT.
START-OF-SELECTION.
perform get_data.
*---------------------------------------------------------------------*
* FORM CHECK_INPUT *
*---------------------------------------------------------------------*
* CHECK THE INPUT *
*---------------------------------------------------------------------*
FORM CHECK_INPUT.
SELECT VBELN POSNR MATNR WERKS CUOBJ
INTO CORRESPONDING FIELDS OF TABLE I_VBAP
FROM VBAP
WHERE VBELN = P_VBELN
AND POSNR = P_POSNR.
IF I_VBAP[] IS INITIAL.
MESSAGE S999 WITH '该销售订单/行项目不存在!'.
STOP.
ENDIF.
ENDFORM. "CHECK_INPUT
*----------------------------------------------------------------------*
* Form get_data
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM get_data.
LOOP AT I_VBAP.
REFRESH: LT_BOM_ITEM,T_GEN,I_TAB.
CLEAR: LT_BOM_ITEM,T_GEN,I_TAB,L_BOM_HEADER.
PERFORM BOM_EXPLOSION.
loop at T_GEN.
IF T_GEN-OBJNR+0(2) = '47'.
I_TAB-MATNR = T_GEN-OBJNR.
I_TAB-MNGKO = T_GEN-MNGKO.
COLLECT I_TAB.CLEAR I_TAB.
ENDIF.
ENDLOOP.
PERFORM INITIAL_BOM_HEADER USING L_BOM_HEADER.
LOOP AT I_TAB.
ADD '0010' TO L_POSNR.
LT_BOM_ITEM-STYPE = 'K'.
LT_BOM_ITEM-IDNRK = I_TAB-MATNR.
* LT_BOM_ITEM-MEINS = .
LT_BOM_ITEM-MENGE = I_TAB-MNGKO.
LT_BOM_ITEM-POSNR = L_POSNR.
LT_BOM_ITEM-POSTP = 'L'.
LT_BOM_ITEM-XLINE = '0001'.
APPEND LT_BOM_ITEM. CLEAR LT_BOM_ITEM.
ENDLOOP.
PERFORM BOM_CREATE.
ENDLOOP.
ENDFORM. " get_data
*---------------------------------------------------------------------*
* FORM BOM_EXPLOSION *
*---------------------------------------------------------------------*
* BOM EXPLOSION *
*---------------------------------------------------------------------*
FORM BOM_EXPLOSION.
* CALL FUNCTION 'CS_BOM_EXPLOSION'
* EXPORTING
* CAPID = 'PP01'
* CUOBJ = I_VBAP-CUOBJ
* DATUV = SY-DATUM
* MKTLS = SPACE
* MEHRS = 'X'
* MMORY = '1'
* MTNRV = I_VBAP-MATNR
* WERKS = I_VBAP-WERKS
* VBELN = I_VBAP-VBELN
* VBPOS = I_VBAP-POSNR
* TABLES
* STBD = T_DOC
* STBE = T_EQUI
* STBK = T_KLA
* STBM = T_MAT
* STBP = T_GEN
* STBT = T_TPL
* EXCEPTIONS
* ALT_NOT_FOUND = 1
* MISSING_AUTHORIZATION = 3
* NO_BOM_FOUND = 4
* NO_PLANT_DATA = 5
* NO_SUITABLE_BOM_FOUND = 6
* OBJECT_NOT_FOUND = 7.
CALL FUNCTION 'CS_BOM_EXPLOSION'
EXPORTING
CAPID = 'PP01'
DATUV = SY-DATUM
MKTLS = SPACE
MEHRS = 'X'
MMORY = '1'
SVWVO = 'X'
STPST = '0'
MTNRV = I_VBAP-MATNR
WERKS = '1100'
TABLES
STBD = T_DOC
STBE = T_EQUI
STBK = T_KLA
STBM = T_MAT
STBP = T_GEN
STBT = T_TPL
EXCEPTIONS
ALT_NOT_FOUND = 1
MISSING_AUTHORIZATION = 3
NO_BOM_FOUND = 4
NO_PLANT_DATA = 5
NO_SUITABLE_BOM_FOUND = 6
OBJECT_NOT_FOUND = 7.
IF T_GEN[] IS INITIAL.
MESSAGE E368 WITH 'BOM展开时出错!'.
STOP.
ENDIF.
ENDFORM. "BOM_EXPLOSION
*---------------------------------------------------------------------*
* FORM BOM_CREATE *
*---------------------------------------------------------------------*
* CREATE BOM *
*---------------------------------------------------------------------*
FORM BOM_CREATE.
CALL FUNCTION 'CS_BI_BOM_CREATE_BATCH_INPUT1'
EXPORTING
BOM_HEADER = L_BOM_HEADER
* CLOSE_GROUP = 'X'
COMMIT_WORK = 'X'
GROUP_DATA = L_GROUP_DATA
* NEW_GROUP = 'X'
TCODE_MODE = 'E'
TCODE_UPDATE = 'S'
IMPORTING
MSGID = L_MSGID
MSGNO = L_MSGNO
MSGTY = L_MSGTY
MSGV1 = L_MSGV1
MSGV2 = L_MSGV2
MSGV3 = L_MSGV3
MSGV4 = L_MSGV4
TABLES
BOM_ITEM = LT_BOM_ITEM
BOM_SUB_ITEM = LT_SUB_ITEM.
ENDFORM. "BOM_CREATE
*---------------------------------------------------------------------*
* FORM INITIAL_BOM_HEADER *
*---------------------------------------------------------------------*
* --> LP_BOM_HEADER *
*---------------------------------------------------------------------*
FORM INITIAL_BOM_HEADER USING LP_BOM_HEADER LIKE BICSK.
LP_BOM_HEADER-STYPE = 'K'.
LP_BOM_HEADER-TCODE = 'CS61'.
LP_BOM_HEADER-STLAN = P_STLAN.
LP_BOM_HEADER-STLST = '01'.
LP_BOM_HEADER-VBELN = I_VBAP-VBELN.
LP_BOM_HEADER-VBPOS = I_VBAP-POSNR.
LP_BOM_HEADER-MATNR = I_VBAP-MATNR.
LP_BOM_HEADER-DATUV = SY-DATUM.
ENDFORM.