Quantcast
Channel: SCN : Document List - ABAP Development
Viewing all articles
Browse latest Browse all 935

BILL OF MATERIAL (BOM IN SAP) - CS01

$
0
0
This Documents Defines what is BOM and Creation of BOM in ECC (CS01) with sample Test Case.

 

Definition of BOM:

 

For manufacturing a product or assembling, list of several components (part of product) are needed.


A well-structured list of Items or Components is known as BOM - Bill of Material.


The list will contain object number of each components and its unit of measure with quantity.


A finished product is a combination of several different component parts or Materials.

Types of BOM available in SAP

 

You can create the following BOMs in the SAP system:


  • Material BOMs
  • Equipment BOMs
  • Functional location BOMs
  • Document structures
  • Order BOM
  • Work breakdown structure (WBS) BOM


BOM can be act as basic for several activities in Production department , some of the examples are :


1.MRP Department:


BOM data can be used to calculate cost-effective order quantities for materials.

 

2.Work scheduling department:

BOM data can be used for operation planning and control.

 

3.Production order management department:

          BOM data can be used to plan the provision of materials.

3. Sales Order


4. Reservation


5. Product Costing

 

BOM Usage :


It is a Key which defines different areas of a Company where the BOM can be used.


BOM Item Category :

 

Categorization of the items in a BOM according to set criteria, such as whether they refer to an object or whether they are kept in stock.

 

  • This categorization allows you to process data that is relevant to the individual items in a BOM. The item category is used to control field selection, default values for BOM maintenance, triggering of specific system activities, and so on.

 

  • For Example Documentation Item, Stock Item, Packing Item.


  • SAP R/3 system allows you to create individual BOM depending upon the area in your company.

 

Define BOM Usages:

 

  1. In Customizing for Production, define individual BOM usages for the different areas within your company by choosing Basic data -->Bill of Material --> General data -->BOM usage -->Define BOM usages.

 

You can define BOM usages for the following scenarios:


  • You maintain separate BOMs for different areas within your company, such as design or production.
  • You create just one BOM for all areas within your company.


Alternative BOM:


  • Alt BOM is used to define BOM in a BOM group.


  • By default system will consider next ALT. BOM Number if user won’t enter any Alt BOM Number.


  • If user enter any Alt. BOM , then system will validate Alt BOM.

 

Structure of a BOM:

 

BOM data is structured as below,

 

BOM Header:

 

  •      BOM Header consists of DATA Related to BOM, which consists of Plant, Material,Technical Type, Revision Label, etc…

 

  •      BOM Header maintains data refer to entire object .

 

  •      Refer to single Header Multiple BOM’s would be created which will be maintained by ALT BOM.

 

BOM Item :

 

Each part of a final Product is called BOM Item , A product is a collections BOM Items .It consists of Item Number, component Quantity , Item Category, Unit of Measure, Item id .

 

Sub Items:


Partial quantities of a BOM item may be installed at different points. Sub-items are used to describe the different installation points of these partial quantities. Sub-items have no operational function in the BOM.              

 


BOM Creation in SAP ECC


Transaction for BOM creation  is CS01 .


1.Initial Screen for BOM creation :

 

1.png

 

Mandatory Fields for entering into next screen are Material, Plant and BOM Usage as per Requirement and by default Alt will pick up as next value to available Alt BOM.


3.png


Click on Header Icon for header details :


4.png


As shown below by default system with Pick 1 as base Qty and Base UOM will be picked from Material Base UOM.


5.png

 

Create BOM Items :


Enter Item Components along with component Qty,UOM,Item Category as shown below.

 

 

BOM Creation Sample Code in ECC :

Scenario :


Create material  BOM along with items and define Procustion Version .


Define ztables and structure as per the requirement .


Create a class and method for BOM creation with Importing Parameters and exporting parameters as :


I_BOM HEADER

I_BOM_ITEMS

E_RETURN

 

 

 

*Data Declarations

 

  DATA : lit_bom_header     TYPE TABLE OF zsbom_header,

         wa_bom_header        TYPE zsbom_header,

         wa_bom_head           TYPE zsbom_header,

         lit_bom_head            TYPE TABLE OF zsbom_header,

         wa_bom_h                TYPE zsbom_header,

         lit_bom_items           TYPE TABLE OF ztbom_items,

         wa_bom_items         TYPE ztbom_items,

         wa_bom_i                 TYPE zsbom_items,

         lit_bom_items_table   TYPE TABLE OF zsbom_items,

         lit_bom_item_table     TYPE TABLE OF zsbom_items,

         wa_bom_item_table   LIKE LINE OF lit_bom_item_table,

         lit_cost_bom_items   TYPE TABLE OF ztt_bom_item,

         lit_bom_item             TYPE ztbom_items,

         i_mast              TYPE  TABLE OF mast,

         lv_role             TYPE zrole,

         lv_verid            TYPE mkal-verid,

         lv_verid1           TYPE mkal-verid,

         lv_bstma            TYPE char13,

         lv_bstmi            TYPE char13,

         lv_stlal            TYPE stlal,

         lv_idnrk            TYPE idnrk,

         lv_flag             TYPE char1,

         lv_phassign(4)      TYPE c,

         lv_ph_desc          TYPE string,

         wa_error            TYPE bapiret2,

         lit_error           TYPE TABLE OF bapiret2,

         persistent_ref      TYPE REF TO zcl_d_persist_bom,

         obj_ref             TYPE REF TO zcl_d_bom,

         l_msg               TYPE bapiret2-message,

         l_warnings          TYPE capiflag-flwarning,

         l_stpo              TYPE TABLE OF stpo_api02,

         wa_stpo             LIKE LINE OF l_stpo,

         l_stko              TYPE TABLE OF stko_api02,

         lv_matnr            TYPE csap_mbom-matnr,

         timestamp           TYPE tzonref-tstamps,

         obj_bom             TYPE REF TO zcl_d_bom.

 

  TYPES : BEGIN OF ty_mast,

              matnr TYPE mast-matnr,

              werks TYPE mast-werks,

              stlan TYPE mast-stlan,

              stlal TYPE mast-stlal,

            END OF ty_mast.

 

  DATA : lit_mast  TYPE STANDARD TABLE OF ty_mast,

         wa_mast   TYPE ty_mast,

         lit_mast1 TYPE TABLE OF mast,

         lv_index  TYPE sy-tabix,

         lv_itmid  TYPE bapi1080_itm_c-item_id.

 

  DATA : bom_items         TYPE STANDARD TABLE OF zsbom_items,

         lit_bom_item_temp TYPE  STANDARD TABLE OF zsbom_items.

 

 

  DATA : lit_stas  TYPE TABLE OF stas,

         wa_stas   TYPE stas,

 

         lit_ausp  TYPE TABLE OF ausp,

         wa_ausp   TYPE ausp,

 

         wa_mast1  TYPE mast,

 

         lit_stpo1 TYPE TABLE OF stpo,

         wa_stpo1  TYPE stpo,

 

         lit_inob  TYPE TABLE OF inob,

         wa_inob   TYPE inob.

 

  DATA : lv_objek   TYPE inob-objek,

         lv_date    TYPE rn1datum-datex,

         lv_stlnr   TYPE mast-stlnr,

         lv_counter TYPE i.

 

  DATA : lit_bom_hrep      TYPE TABLE OF ztbom_head_rep,    "Historical Report declarations

         wa_bom_hrep        TYPE ztbom_head_rep,

         wa_bom_hrep1       TYPE ztbom_head_rep,

         lit_bom_hist_temp  TYPE TABLE OF ztbom_head_rep,

         wa_bom_hist_temp  TYPE ztbom_head_rep,

         wa_bom_hist_temp1 TYPE ztbom_head_rep,

         lit_ampl          TYPE TABLE OF ampl,

         wa_ampl           TYPE ampl,

         lit_bom_irep      TYPE TABLE OF zsbom_i_report,

         wa_bom_irep       TYPE zsbom_i_report,

         wa_bom_itemrep    TYPE ztbom_item_rep,

         lit_hist_msg      type ztd_hist_msgs,

         wa_hist_msg       type ztd_hist_msgs.

 

* internal table that have to be passed to the bapi

          DATA :  lit_bomgroup TYPE STANDARD TABLE OF bapi1080_bgr_c,

                  wa_bomgroup   TYPE bapi1080_bgr_c,

                  lv_bom_text   TYPE string,

                  lv_plant      TYPE ztbom_header-werks,

 

                   lit_variants TYPE STANDARD TABLE OF bapi1080_bom_c,

                   wa_variants  TYPE bapi1080_bom_c,

 

                   lit_items    TYPE STANDARD TABLE OF bapi1080_itm_c,

                   wa_items     TYPE bapi1080_itm_c,

 

                   lit_matrel   TYPE STANDARD TABLE OF bapi1080_mbm_c,

                   wa_matrel    TYPE bapi1080_mbm_c,

 

                   lit_itemas   TYPE STANDARD TABLE OF bapi1080_rel_itm_bom_c,

                   wa_itemas    TYPE bapi1080_rel_itm_bom_c.

 

 

*-->Check BOM Existency

 

          CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'

            EXPORTING

              input  = i_bom_header-matnr

            IMPORTING

              output = lv_matnr.

 

 

          SELECT SINGLE stlnr FROM mast INTO lv_stlnr WHERE matnr = lv_matnr

AND werks = i_bom_header-werks

AND stlal = i_bom_header-stlal AND stlan = '1'.

          IF lv_stlnr IS  INITIAL.

 

*  assign bom usage to 1.

            IF wa_bom_h-stlan IS INITIAL.

              wa_bom_h-stlan = zif_d_constant=>c_production_bom_usg.

            ENDIF.

 

* assign bom text bases on condition

            lv_plant = wa_bom_h-werks.

            IF lv_plant+0(2) = '10'.

              CONCATENATE 'BOM For' wa_bom_h-maktx INTO lv_bom_text SEPARATED BY space.

            ELSE.

              lv_bom_text = ' ' .

            ENDIF.

 

wa_bomgroup-bom_group_identification = 'BAPI_SMP_COL1'.

            wa_bomgroup-object_type = 'BGR'.

            wa_bomgroup-object_id = 'SIMPLE1'.

            wa_bomgroup-bom_usage = wa_bom_h-stlan.

            wa_bomgroup-created_in_plant = wa_bom_h-werks.

            wa_bomgroup-ltxt_lang = sy-langu.

            wa_bomgroup-technical_type = ' '.

            wa_bomgroup-bom_text = lv_bom_text.

            APPEND wa_bomgroup TO lit_bomgroup.

 

            IF wa_bom_h-datuv IS INITIAL.

              wa_bom_h-datuv = sy-datum.

            ENDIF.

 

*UOM Conversion :

 

            CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'

              EXPORTING

                input          = wa_bom_h-bmein

              IMPORTING

                output         = wa_bom_h-bmein

              EXCEPTIONS

                unit_not_found = 1

                OTHERS         = 2.

 

*Define Varaints

 

wa_variants-bom_group_identification = 'BAPI_SMP_COL1'.

            wa_variants-object_type              = 'BOM'.

            wa_variants-object_id                = 'SIMPLE1'.

            wa_variants-alternative_bom          = wa_bom_h-stlal.

            wa_variants-bom_status               = wa_bom_h-stlst.

            wa_variants-base_qty                 = wa_bom_h-bmeng.

            wa_variants-base_unit                = wa_bom_h-bmein. " base unit

            wa_variants-alt_text                 = wa_bom_h-alternate_text.   " alternative text

            wa_variants-valid_from_date          = wa_bom_h-datuv.

 

            wa_variants-function = 'NEW'.

            APPEND wa_variants TO lit_variants.

 

            CLEAR lv_itmid.

            LOOP AT bom_items INTO wa_bom_i.

              CLEAR wa_items.

 

              MOVE-CORRESPONDING wa_bom_i TO wa_bom_items.

 

              IF wa_bom_items-posnr IS INITIAL.

                wa_bom_items-posnr = '0010'.

              ENDIF.

 

              IF wa_bom_items-postp IS INITIAL.

                wa_bom_items-postp = 'L'.

              ENDIF.

 

              IF wa_bom_items-datuv IS INITIAL.

                wa_bom_items-datuv = sy-datum.

              ENDIF.

 

              CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'

                EXPORTING

                  input        = wa_bom_items-idnrk

                IMPORTING

                  output       = wa_bom_items-idnrk

                EXCEPTIONS

                  length_error = 1

                  OTHERS       = 2.

 

 

* Details of the items of the variants

 

*to convert the uom for bom item

 

              CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'

                EXPORTING

                  input          = wa_bom_items-meins

                  language       = sy-langu

                IMPORTING

                  output         = wa_bom_items-meins

                EXCEPTIONS

                  unit_not_found = 1

                  OTHERS         = 2.

 

              CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

                EXPORTING

                  input  = wa_bom_items-vendor_no

                IMPORTING

                  output = wa_bom_items-vendor_no.

 

              wa_items-bom_group_identification = 'BAPI_SMP_COL1'.

              wa_items-object_type              = 'ITM'.

              wa_items-object_id                = 'SIMPLE1'.

              wa_items-item_no                  = wa_bom_items-posnr.

              wa_items-item_cat                 = wa_bom_items-postp ."Item Category

              wa_items-comp_unit                = wa_bom_items-meins. " bom uom added

              wa_items-alt_item_prio            = wa_bom_items-alprf. " priority added

              wa_items-usage_prob               = wa_bom_items-ewahr. " usage probability added

 

*-->Sort String

              IF wa_bom_items-sortf IS NOT INITIAL.

                wa_items-sort_string              = wa_bom_items-sortf." sort string added

              ELSE.

                SPLIT wa_bom_items-zph_assign AT '-' INTO lv_phassign lv_ph_desc.

                CONDENSE lv_ph_desc.

                wa_items-sort_string              = lv_ph_desc .

 

              ENDIF.

*-->End of Sort String

 

              wa_items-component                = wa_bom_items-idnrk.

              wa_items-comp_qty                 = wa_bom_items-menge.

              wa_items-item_text1               = wa_bom_items-ktext. "Bom component description added

              wa_items-alt_item_group           = wa_bom_items-alpgr.  " Bom Alt Item Group

              wa_items-valid_from_date          = wa_bom_items-datuv.

              wa_items-iss_st_loc               = wa_bom_items-lgort."storage plant

 

 

*-->Alt Item Strategy

              IF wa_items-alt_item_group IS NOT INITIAL.

                wa_items-alt_item_strategy = '2'. "Alt Item Strategy

              ELSE.

                wa_items-alt_item_strategy = ' '.

              ENDIF.

 

              IF wa_bom_items-idnrk CP '35*'.

                wa_items-class_type        = '023'.

                wa_items-vendor_no         = wa_bom_items-vendor_no.

              ENDIF.

 

              APPEND wa_items TO lit_items.

              CLEAR  wa_items.

            ENDLOOP.

 

            CLEAR lv_itmid.

 

            CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'

              EXPORTING

                input        = wa_bom_h-matnr

              IMPORTING

                output       = wa_bom_h-matnr

              EXCEPTIONS

                length_error = 1

                OTHERS       = 2.

 

*creation of production BOM

 

            IF wa_bom_h-stlan IS INITIAL.

              wa_bom_h-stlan = 1.

            ENDIF.

 

*--From Lot size and to size------------*

 

            IF i_bom_header-werks CP '10*'.

 

              lv_bstmi = zif_d_constant=>c_bstmi.  "BASE QUANTITY

              lv_bstma = zif_d_constant=>c_bstma.

              CONDENSE lv_bstma.

              CONDENSE lv_bstmi.

            ELSE.

 

              lv_bstmi = zif_d_constant=>c_bstmi.

              lv_bstma = zif_d_constant=>c_bstma.

              CONDENSE lv_bstma.

              CONDENSE lv_bstmi.

            ENDIF.

 

* Details of the materials of the different variants

            wa_matrel-bom_group_identification = 'BAPI_SMP_COL1'.

            wa_matrel-material                 = wa_bom_h-matnr.

            wa_matrel-plant                    = wa_bom_h-werks.

            wa_matrel-bom_usage                = wa_bom_h-stlan.

            wa_matrel-alternative_bom          = wa_bom_h-stlal.

            wa_matrel-lot_size_from            = lv_bstmi.

            wa_matrel-lot_size_to              = lv_bstma.

            APPEND wa_matrel TO lit_matrel.

 

* Linking items to the corresponding variants

            wa_itemas-bom_group_identification = 'BAPI_SMP_COL1'.

            wa_itemas-sub_object_type          = 'ITM'.

            wa_itemas-sub_object_id            = 'SIMPLE1'.

            wa_itemas-super_object_type        = 'BOM'.

            wa_itemas-super_object_id          = 'SIMPLE1'.

            wa_itemas-valid_from_date          = wa_bom_items-datuv.

            wa_itemas-function                 = 'NEW'.

            APPEND wa_itemas TO lit_itemas.

 

* call function to create bill fo materail by using

* the previously declared local internal tables

 

            SORT lit_items BY object_id valid_from_date.

            CALL FUNCTION 'BAPI_MATERIAL_BOM_GROUP_CREATE'

              EXPORTING

                all_error         = 'X'

              TABLES

                bomgroup          = lit_bomgroup

                variants          = lit_variants

                items             = lit_items

                materialrelations = lit_matrel

                itemassignments   = lit_itemas

                return            = e_return.

 

            CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

 

*----END OF Production BOM CREATION-----------------------*

 

References:

 

http://braincybersolutions.com/sap-tutorials/pp/bom-in-sap-bill-of-material/

http://help.sap.com/saphelp_46c/helpdata/en/ea/e9af734c7211d189520000e829fbbd/frameset.htm


Viewing all articles
Browse latest Browse all 935

Trending Articles