Skip to Content

Here is a code snippet to update a BOM related to Sales Order or Quotation (transaction CS62).

You can load current BOM an change any field you need, or insert new itens to this BOM.

” Local Vars

DATA: lt_stb     TYPE TABLE OF stpox,

      ls_stb     TYPE stpox,

      lt_matcat  TYPE TABLE OF cscmat,

      ls_vbap    TYPE vbap,

      ls_stko    TYPE stko_api01,

      ls_stpo    TYPE stpo_api03,

      lt_stpo    TYPE TABLE OF stpo_api03,

      ln_item_no TYPE stpo_api03-item_no.

ls_vbap-vbeln = ‘0020000001’.  ” Sales Order/Quotation

ls_vbap-posnr = ‘000010’.      ” Item

” Fetch Salesorder data

SELECT SINGLE *

  FROM vbap

  INTO ls_vbap

  WHERE vbeln = ls_vbap-vbeln AND

        posnr = ls_vbap-posnr.

” Load BOM

CALL FUNCTION ‘CS_BOM_EXPL_KND_V1’

  EXPORTING

    capid                 = ‘PP01’

    cuobj                 = ls_vbap-cuobj

    datuv                 = sy-datum

    ehndl                 = ‘1’

    mktls                 = ‘ ‘

    mehrs                 = ‘X’

    mmory                 = ‘X’

    mtnrv                 = ls_vbap-matnr

    stlan                 = ‘1’

    werks                 = ls_vbap-werks

    vbeln                 = ls_vbap-vbeln

    vbpos                 = ls_vbap-posnr

    vrsvo                 = ‘ ‘

  TABLES

    stb                   = lt_stb

    matcat                = lt_matcat

  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.

CLEAR ln_item_no.

” Loop through BOM Itens

LOOP AT lt_stb INTO ls_stb

  WHERE stufe = ‘1’ AND

        bmtyp = ‘K’.

  ADD 1 TO ln_item_no.

  ” Fill Bom Item to update

  CLEAR ls_stpo.

  ls_stpo-item_categ      = ls_stb-postp.

  ls_stpo-item_no         = ln_item_no.

  ls_stpo-component       = ls_stb-idnrk.

  ” … Fill any fields you need

  ls_stpo-bom_no          = ls_stb-stlnr.

  ls_stpo-item_node       = ls_stb-stlkn.

  ls_stpo-item_count      = ls_stb-stpoz.

  ls_stpo-bom_alt         = ls_stb-stlal.

  APPEND ls_stpo TO lt_stpo.

ENDLOOP.

” Save Order

CALL FUNCTION ‘CSAP_ORD_BOM_MAINTAIN’

  EXPORTING

    order       = ls_vbap-vbeln

    position    = ls_vbap-posnr

    material    = ls_vbap-matnr

    plant       = ls_vbap-werks

    bom_usage   = ‘1’

    valid_from  = ‘01.01.2013’   ” Caution on date format

    i_stko      = ls_stko

    fl_new_item = ‘X’            ” Check this if you insert new itens in BOM

  TABLES

    t_stpo      = lt_stpo

  EXCEPTIONS

    error       = 1

    OTHERS      = 2.

   

   

It’s Done.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply