CS_BOM_EXPL_MAT_V2 bom展开LOOP AT itab_mast. cnt0 = cnt0 + 1. CALL FUNCTION 'CS_BOM_EXPL_MAT_V2' EXPORTING capid = 'PP01' datuv = sy-datum ehndl = '1' emeng = '1' mehrs = 'X' mkmat = 'X' "限制展开所有阶 mmory = '1' mtnrv = itab_mast-matnr "'000000000210000105' stlan = 'M' werks = '2110' "'1100' IMPORTING topmat = topmat_t * DSTST = TABLES stb = stb1 * MATCAT = EXCEPTIONS alt_not_found = 1 material_not_found = 3 missing_authorization = 4 no_bom_found = 5 OTHERS = 9 . * SORT stb1 BY stufe. * IF sy-subrc <> 0. * MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno * WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. * ENDIF.
DATA:BEGIN OF itab_mast OCCURS 0,
matnr LIKE mast-matnr,
werks LIKE mast-werks,
stlal LIKE mast-stlal,
stlan LIKE mast-stlan,
END OF itab_mast.
FORM get_data .
*******************从MAKT里取数,辅助整理从函数里取数
SELECT matnr maktx INTO CORRESPONDING FIELDS OF TABLE wa_itab01
FROM makt.
*******************从MARC里取数,辅助整理从函数里取数
SELECT matnr plifz werks INTO CORRESPONDING FIELDS OF TABLE wa_itab02
FROM marc.
*****************************取表头数据
SELECT a~matnr a~maktx b~stlnr c~ztext c~stlan
FROM makt AS a
INNER JOIN mast AS b ON a~matnr = b~matnr
INNER JOIN stzu AS c ON b~stlnr = c~stlnr
INTO CORRESPONDING FIELDS OF TABLE itab_head
WHERE a~matnr = p_matnr.
******************************去BOM的主要数据,并根据这做判断
SELECT matnr werks stlan stlal
INTO CORRESPONDING FIELDS OF TABLE itab_mast
FROM mast
WHERE matnr = p_matnr AND werks = p_werks.
********** 检查物料在工厂下存不存在
IF sy-subrc <> 0.
DATA:me01(18) TYPE c,
me02(4) TYPE c,
me03(40) TYPE c.
me01 = p_matnr.
me02 = p_werks.
CONCATENATE '物料' me01 '在工厂' me02 '下不存在' INTO me03.
MESSAGE me03 TYPE 'I'.
STOP.
RETURN.
ENDIF.
********* 检查物料存不存在BOM
LOOP AT itab_mast.
DATA:me04(18) TYPE c,
me05(40) TYPE c,
me06(40) TYPE c.
me04 = p_matnr.
CONCATENATE '物料' me04 '下不存在BOM' INTO me05.
CONCATENATE '物料' me04 '下存在BOM' INTO me06.
IF itab_mast-stlan = ''.
MESSAGE me05 TYPE 'I'.
STOP.
RETURN.
* ELSE.
* MESSAGE me06 TYPE 'I'.
ENDIF.
ENDLOOP.
**************************调用函数去处BOM下的物料清单
*CALL TRANSACTION <cs11>.
CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING
* ALEKZ = ' ' " 是否计算耗损
capid = 'PP01' " BOM应用
datuv = sy-datum " 有效起始日
ehndl = '1'
emeng = '1' " 需求数量
mehrs = 'X' " 多层展开
mmory = '1' " 是否使用缓存
mtnrv = itab_mast-matnr "'000000000090000199' " 展开物料号
stlan = '1' " BOM用途
werks = itab_mast-werks "'1002' " 物料所在工厂
* IMPORTING
* TOPMAT =
* DSTST =
TABLES
stb = stb
* MATCAT =
EXCEPTIONS
alt_not_found = 1
material_not_found = 3
missing_authorization = 4
no_bom_found = 5
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.
**************************根据函数导出的数据整理
LOOP AT stb.
MOVE stb-ojtxp TO wa_itab-maktx.
MOVE stb-mnglg TO wa_itab-menge.
APPEND wa_itab.
ENDLOOP.
LOOP AT wa_itab.
READ TABLE wa_itab01 WITH KEY maktx = wa_itab-maktx.
IF sy-subrc = 0.
MOVE wa_itab01-matnr TO wa_itab-matnr.
ENDIF.
MODIFY wa_itab.
ENDLOOP.
********************整理数据到ALV内表
LOOP AT wa_itab.
MOVE-CORRESPONDING wa_itab TO wa_tab.
APPEND wa_tab.
CLEAR WA_TAB.
ENDLOOP.
2012-10-11 09:47:01 黄健
ENDFORM. " GET_DATA