How to expand the BOM using ABAP?

        在某项目中,根据业务部门提出的需求,需要把BOM展开。通过调用系统提供的FM 来实现BOM 展开的函数。以下是实现代码的函数。

 

FUNCTION Z_BOM_EXPAND.

*"---------------------------------------------------------

*"*"Local Interface:

*" IMPORTING

*" VALUE(MATNR) LIKE MARA-MATNR

*" VALUE(WERKS) LIKE MARC-WERKS OPTIONAL

*" VALUE(CAPID) LIKE TC04-CAPID DEFAULT 'PP01'

*" TABLES

*" STB STRUCTURE STPOX

*" RETURN STRUCTURE BAPIRET2

*"---------------------------------------------------------

IF WERKS IS INITIAL."Added in case external call does not know

   WERKS = '3001'.

ENDIF.

IF CAPID IS INITIAL.

   CAPID = 'PP01'.

ENDIF.

CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'

  EXPORTING

    CAPID = CAPID

    DATUV = SY-DATUM

    MEHRS = 'X'

    MTNRV = MATNR

    WERKS = WERKS

  TABLES

    STB = STB

  EXCEPTIONS

    NO_BOM_FOUND = 1.

IF sy-subrc <> 0.

   msg_typ = 'E'.

   msg_id = 'Z_EF'.

   msg_no = '002'.

   msg_v1 = MATNR.

   if not msg_typ is initial.

*     append error to table RETURN

      call function 'BALW_BAPIRETURN_GET2'

        exporting

          type = msg_typ

          cl = msg_id

          number = msg_no

          par1 = msg_v1

          par2 = msg_v2

          par3 = msg_v3

          par4 = msg_v4

          parameter = space

          row = space

          field = space

        importing

          return = wa_return_tmp.

      append wa_return_tmp to return.

   endif.

ENDIF.

ENDFUNCTION.

你可能感兴趣的:(How to expand the BOM using ABAP?)