Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

VA01 versus BAPI_SALESORDER_CREATEFROMDAT2

Former Member
0 Likes
2,781

(1) Create order using Va01 for BOM item, header + 3 items get created

(2) Try to create order using BAPI_SALESORDER_CREATEFROMDAT2 for same material, order does not create

In ORDER_ITEMS_IN I pass (BOM + components)

In ORDER_SCHEDULES_IN I pass quantity of (BOM+components)

I need to create sales order using BAPI_SALESORDER_CREATEFROMDAT2 for BOM material, please help.

11 REPLIES 11
Read only

Former Member
0 Likes
1,774

Hi,

Is the BOM you are referring to explodes automatically, check Item Category group of BOM Material in Material Master.

Also, make sure you are using the ITM_NUMBER when populating the items and respective schedule lines.

Regards

Eswar

Read only

0 Likes
1,774

Item category group is maintained in T184.

However in ORDER_ITEMS_IN there is only item category, not item category group.

I am filling in the item category in ORDER_ITEMS_IN for BOM header + components, not item category group

Read only

0 Likes
1,774

You missed my point...

BOM you are referring to explodes automatically

This is to check how the material is handled in Sales Order. I know we do not pass Item Category Group for BAPI.

Item Category Group in material master defines the characteristic, like NORM to act as Normal Material and LUMF for Structured Materials(standard way of defining automatic explosion).

Incase the BOM explodes automatically, you need not pass the BOM Items in Item Table for BAPI, just the Schedule lines will do the task.

Also, you can use FM: BAPI_SALESORDER_SIMULATE to detemine the item numbers and map accordingly while creating with other BAPI's.

We use the simulation BAPI for Items, Schedule lines and Conditions. Note that simulation is like a test before creating the actual order. Try to explore more on the BAPI and use it accordingly.

Regards

Eswar

Read only

Former Member
0 Likes
1,774

HI Eswar,

We are having a similar kind of scenario in my project.

We are implementing SO creation process thru EP.

There is BOM concept here and during SO creation using BAPI it is a headache .

We do not pass the BOM components via the RFC, only the BOM header material.

The thing is user can delete BOM component and then the SO shud be created minus this particular component.

So what we do is create SO via BAPI with all the BOM components and then run the CHANGE_BAPI to delete this particular item.

This is doubling the execution time.

Is there a way to stop the BOM from exploding ?

If yes, then we can map the items one-on-one and works done :).

Any idea if we can do this ?

Thanks,

Gary

Read only

0 Likes
1,774

Hi Gary

I havent tried for deletion of BOM components via creation BAPI, but i believe we can acheive this. Just that we have to be specific with the item data.

Try doing as below:

1. Use BAPI_SALESORDER_SIMULATE before actual creation of order.

2. We get the simulated data in return( even with BOM after explosion ).

3. Use data from Simulation for Creation BAPI.

Key thing to populate from Simulation:

For Item/Component that you intend to delete, use the ITM_NUMBER while populating items, you get the reference item number from Simulation BAPI and set the Deletion Indicator for flags.

Please try and let me know if it works, in the meanwhile i will try myself as well.

Regards

Eswar

Read only

0 Likes
1,774

Hello

Currently on Sales Order, i am able to delete a BOM component. I do not know how to stop this. How can i ensure that

the user is not able to delete a BOM component.

Regards

Read only

Former Member
0 Likes
1,774

see the following example


* Parameters
* Sales document type
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text FOR FIELD p_auart.
PARAMETERS: p_auart TYPE auart OBLIGATORY.
SELECTION-SCREEN END OF LINE.

* Sales organization
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text1 FOR FIELD p_vkorg.
PARAMETERS: p_vkorg TYPE vkorg OBLIGATORY.
SELECTION-SCREEN END OF LINE.

* Distribution channel
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text2 FOR FIELD p_vtweg.
PARAMETERS: p_vtweg TYPE vtweg OBLIGATORY.
SELECTION-SCREEN END OF LINE.

* Division.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text3 FOR FIELD p_spart.
PARAMETERS: p_spart TYPE spart OBLIGATORY.
SELECTION-SCREEN END OF LINE.

SKIP 1.

* Sold-to
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text4 FOR FIELD p_sold.
PARAMETERS: p_sold  TYPE kunnr OBLIGATORY.
SELECTION-SCREEN END OF LINE.

* Ship-to
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text5 FOR FIELD p_ship.
PARAMETERS: p_ship  TYPE kunnr OBLIGATORY.
SELECTION-SCREEN END OF LINE.

SKIP 1.

* Material
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text6 FOR FIELD p_matnr.
PARAMETERS: p_matnr TYPE matnr   OBLIGATORY.
SELECTION-SCREEN END OF LINE.

* Quantity.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text7 FOR FIELD p_menge.
PARAMETERS: p_menge TYPE kwmeng  OBLIGATORY.
SELECTION-SCREEN END OF LINE.

* Plant
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text9 FOR FIELD p_plant.
PARAMETERS: p_plant TYPE werks_d .
SELECTION-SCREEN END OF LINE.

* Complete Deliver
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text10 FOR FIELD p_autlf.
PARAMETERS: p_autlf TYPE autlf DEFAULT 'X'.
SELECTION-SCREEN END OF LINE.

continue.....

Edited by: Krupaji on Feb 18, 2010 1:46 PM

Edited by: Krupaji on Feb 18, 2010 1:46 PM

Read only

Former Member
0 Likes
1,774

* Data declarations.
DATA: v_vbeln            LIKE vbak-vbeln.
DATA: header             LIKE bapisdhead1.
DATA: headerx            LIKE bapisdhead1x.
DATA: item               LIKE bapisditem  OCCURS 0 WITH HEADER LINE.
DATA: itemx              LIKE bapisditemx OCCURS 0 WITH HEADER LINE.
DATA: partner            LIKE bapipartnr  OCCURS 0 WITH HEADER LINE.
DATA: return             LIKE bapiret2    OCCURS 0 WITH HEADER LINE.
DATA: lt_schedules_inx   TYPE STANDARD TABLE OF bapischdlx
                         WITH HEADER LINE.
DATA: lt_schedules_in    TYPE STANDARD TABLE OF bapischdl
                         WITH HEADER LINE.
 DATA: lt_schedules_ink    TYPE STANDARD TABLE OF bapisdhead1
                         WITH HEADER LINE.

START-OF-SELECTION.

* Header data

* Sales document type
  header-doc_type = p_auart.
  headerx-doc_type = 'X'.

* Sales organization
  header-sales_org = p_vkorg.
  headerx-sales_org = 'X'.

* Distribution channel
  header-distr_chan  = p_vtweg.
  headerx-distr_chan = 'X'.

* Division
  header-division = p_spart.
  headerx-division = 'X'.

  headerx-updateflag = 'I'.
*Complete delivery
    header-COMPL_DLV = p_autlf.
    header-COMPL_DLV = 'X'.

Continue....

Read only

Former Member
0 Likes
1,774

* Partner data
* Sold to
  partner-partn_role = 'AG'.
  partner-partn_numb = p_sold.
  APPEND partner.

* Ship to
  partner-partn_role = 'WE'.
  partner-partn_numb = p_ship.
  APPEND partner.

* ITEM DATA
  itemx-updateflag = 'I'.

* Line item number.
  item-itm_number = '000010'.
  itemx-itm_number = 'X'.

* Material
  item-material = p_matnr.
  itemx-material = 'X'.

* Plant
  item-plant    = p_plant.
  itemx-plant   = 'X'.

* Quantity
  item-target_qty = p_menge.
  itemx-target_qty = 'X'.

* item category
  itemx-ITEM_CATEG = 'X'.
  APPEND item.
  APPEND itemx.


*   ITEM DATA
  itemx-updateflag = 'I'.

* Line item number.
  item-itm_number = '000020'.
  itemx-itm_number = 'X'.

* Material
  item-material = p_matnr.
  itemx-material = 'X'.

* Plant
  item-plant    = p_plant.
  itemx-plant   = 'X'.

* Quantity
  item-target_qty = p_menge.
  itemx-target_qty = 'X'.



  APPEND item.
  APPEND itemx.


*   Fill schedule lines
  lt_schedules_in-itm_number = '000010'.
  lt_schedules_in-sched_line = '0001'.
  lt_schedules_in-req_qty    = p_menge.
  APPEND lt_schedules_in.

*   Fill schedule line flags
  lt_schedules_inx-itm_number  = '000010'.
  lt_schedules_inx-sched_line  = '0001'.
  lt_schedules_inx-updateflag  = 'X'.
  lt_schedules_inx-req_qty     = 'X'.
  APPEND lt_schedules_inx.


*   Fill schedule lines
  lt_schedules_in-itm_number = '000020'.
  lt_schedules_in-sched_line = '0001'.
  lt_schedules_in-req_qty    = p_menge.
  APPEND lt_schedules_in.

*   Fill schedule line flags
  lt_schedules_inx-itm_number  = '000020'.
  lt_schedules_inx-sched_line  = '0001'.
  lt_schedules_inx-updateflag  = 'X'.
  lt_schedules_inx-req_qty     = 'X'.
  APPEND lt_schedules_inx.

Read only

Former Member
0 Likes
1,774

* Call the BAPI to create the sales order.
  CALL FUNCTION 'BAPI_SALESDOCU_CREATEFROMDATA1'
       EXPORTING
            sales_header_in     = header
            sales_header_inx    = headerx
       IMPORTING
            salesdocument_ex    = v_vbeln
       TABLES
            return              = return
            sales_items_in      = item
            sales_items_inx     = itemx
            sales_schedules_in  = lt_schedules_in
            sales_schedules_inx = lt_schedules_inx
            sales_partners      = partner.

* Check the return table.
  LOOP AT return WHERE type = 'E' OR type = 'A'.
    EXIT.
  ENDLOOP.

  IF sy-subrc = 0.

    WRITE: / 'Error in creating document'.

  ELSE.

* Commit the work.
    COMMIT WORK AND WAIT.

    WRITE: / 'Document ', v_vbeln, ' created'.

  ENDIF.
Read only

Former Member
0 Likes
1,774

Hi,

Check this report...this will make your job easy

REPORT Z_ASSIGN_CHARAC_VA01.

&----


*& This report can be used to change the characteristic value *

*& assignment of the configuration in existing sales documents easily. *

&----


*Data Declaration

DATA: ls_val(180) TYPE C,

ls_vbeln TYPE sales_key,

lt_vbeln TYPE TABLE OF sales_key,

ls_bapi_view TYPE order_view,

ls_logic TYPE bapisdls,

lt_header TYPE TABLE OF bapisdhd,

lt_header_x TYPE bapisdh1x,

ls_item TYPE bapisdit,

ls_items TYPE bapisditm,

lt_item TYPE TABLE OF bapisdit,

lt_items TYPE TABLE OF bapisditm,

lt_item_x TYPE TABLE OF bapisditmx,

ls_item_x TYPE bapisditmx,

lt_schedules TYPE TABLE OF bapisdhedu,

lt_partners TYPE TABLE OF bapisdpart,

lt_conditions TYPE TABLE OF bapisdcond,

ls_curefs TYPE bapicurefm,

lt_curefs TYPE TABLE OF bapicurefm,

ls_cucfgs TYPE bapicucfgm,

lt_cucfgs TYPE TABLE OF bapicucfgm,

ls_cuins TYPE bapicuinsm,

lt_cuins TYPE TABLE OF bapicuinsm,

ls_cuprts TYPE bapicuprtm,

lt_cuprts TYPE TABLE OF bapicuprtm,

ls_cuvals TYPE bapicuvalm,

lt_cuvals TYPE TABLE OF bapicuvalm,

lt_cuval_ch TYPE TABLE OF bapicuvalm WITH HEADER LINE,

ls_blob TYPE bapicublbm,

lt_blob TYPE TABLE OF bapicublbm,

ls_cuvks TYPE bapicuvkm,

lt_cuvks TYPE TABLE OF bapicuvkm,

ls_return TYPE bapiret2,

lt_return TYPE TABLE OF bapiret2,

ls_cfgs_ref TYPE bapicucfg,

lt_cfgs_ref TYPE TABLE OF bapicucfg,

ls_inst TYPE bapicuins,

lt_inst TYPE TABLE OF bapicuins,

ls_parts TYPE bapicuprt,

lt_parts TYPE TABLE OF bapicuprt,

ls_values TYPE bapicuval,

lt_values TYPE TABLE OF bapicuval,

ls_cublob TYPE bapicublb,

lt_cublob TYPE TABLE OF bapicublb,

ls_cuvk TYPE bapicuvk,

lt_cuvk TYPE TABLE OF bapicuvk,

ls_curef TYPE bapicuref,

lt_curef TYPE TABLE OF bapicuref.

  • Selection Screen

SELECTION-SCREEN BEGIN OF BLOCK text-001

WITH FRAME TITLE text-001.

PARAMETERS: p_vbeln TYPE vbak-vbeln OBLIGATORY.

SELECTION-SCREEN END OF BLOCK text-001.

SELECTION-SCREEN BEGIN OF BLOCK text-002

WITH FRAME TITLE text-002.

PARAMETERS: p_show AS CHECKBOX.

SELECTION-SCREEN END OF BLOCK text-002.

SELECTION-SCREEN BEGIN OF BLOCK text-005

WITH FRAME TITLE text-005.

SELECT-OPTIONS: s_val FOR ls_val NO INTERVALS.

SELECTION-SCREEN END OF BLOCK text-005.

SELECTION-SCREEN BEGIN OF BLOCK text-003

WITH FRAME TITLE text-003.

PARAMETERS: p_method AS CHECKBOX,

p_test AS CHECKBOX,

p_ls_nos LIKE bapisdls-nostructure,

p_ls_pr LIKE bapisdls-pricing,

p_ls_atp LIKE bapisdls-atp_wrkmod,

p_ls_sch LIKE bapisdls-scheduling.

SELECTION-SCREEN END OF BLOCK text-003.

----


START-OF-SELECTION.

ls_vbeln-vbeln = p_vbeln.

APPEND ls_vbeln TO lt_vbeln.

  • Select the output tables

ls_bapi_view-header = 'X'.

ls_bapi_view-item = 'X'.

ls_bapi_view-sdschedule = 'X'.

ls_bapi_view-partner = 'X'.

ls_bapi_view-sdcond = 'X'.

ls_bapi_view-configure = 'X'.

  • Get the salesorder data

CALL FUNCTION 'BAPISDORDER_GETDETAILEDLIST'

EXPORTING

i_bapi_view = ls_bapi_view

TABLES

sales_documents = lt_vbeln

order_headers_out = lt_header

order_items_out = lt_item

order_schedules_out = lt_schedules

order_partners_out = lt_partners

order_conditions_out = lt_conditions

order_cfgs_curefs_out = lt_curefs

order_cfgs_cucfgs_out = lt_cucfgs

order_cfgs_cuins_out = lt_cuins

order_cfgs_cuprts_out = lt_cuprts

order_cfgs_cuvals_out = lt_cuvals

order_cfgs_cublbs_out = lt_blob

order_cfgs_cuvks_out = lt_cuvks.

  • Only Display characteristic assignment

IF NOT p_show IS INITIAL.

IF NOT lt_cuvals[] IS INITIAL.

WRITE: / text-004,

AT /(15) 'CONFIG_ID' COLOR COL_HEADING,

AT (15) 'INST_ID' COLOR COL_HEADING,

AT (25) 'CHARC' COLOR COL_HEADING,

AT (25) 'VALUE' COLOR COL_HEADING.

LOOP AT lt_cuvals INTO ls_cuvals.

WRITE: AT /(15) ls_cuvals-config_id COLOR COL_NORMAL,

AT (15) ls_cuvals-inst_id COLOR COL_NORMAL,

AT (25) ls_cuvals-charc COLOR COL_NORMAL,

AT (25) ls_cuvals-value COLOR COL_NORMAL.

ENDLOOP.

ELSE.

MESSAGE i001(cuib1).

ENDIF.

ELSE.

  • Change values for characteristics

IF NOT s_val IS INITIAL.

LOOP AT s_val INTO ls_val.

SPLIT ls_val+3 AT '/' INTO ls_cuvals-config_id

ls_cuvals-inst_id

ls_cuvals-charc

ls_cuvals-value.

APPEND ls_cuvals TO lt_cuval_ch.

ENDLOOP.

LOOP AT lt_cuval_ch.

READ TABLE lt_cuvals INTO ls_cuvals WITH KEY

config_id = lt_cuval_ch-config_id

inst_id = lt_cuval_ch-inst_id

charc = lt_cuval_ch-charc.

IF sy-subrc = 0.

  • AND

  • ls_cuvals-author is initial.

ls_cuvals-value = lt_cuval_ch-value.

MODIFY lt_cuvals FROM ls_cuvals INDEX sy-tabix.

ELSE.

MESSAGE e111(cu) WITH lt_cuval_ch-charc

lt_cuval_ch-value

text-006.

ENDIF.

ENDLOOP.

ENDIF.

  • Delete SCE Flag in order to call R/3 configurator

IF NOT p_method IS INITIAL.

LOOP AT lt_cucfgs INTO ls_cucfgs WHERE NOT sce IS initial.

CLEAR ls_cucfgs-sce.

MODIFY lt_cucfgs FROM ls_cucfgs.

ENDLOOP.

ENDIF.

  • Update flags for BAPI

lt_header_x-updateflag = 'U'.

LOOP AT lt_item INTO ls_item.

ls_item_x-itm_number = ls_item-itm_number.

ls_item_x-updateflag = 'U'.

ls_item_x-config_id = 'X'.

ls_item_x-po_itm_no = 'X'.

APPEND ls_item_x TO lt_item_x.

ENDLOOP.

  • Convert configuration data

PERFORM convert_cfg_data.

  • Call change bapi

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

EXPORTING

salesdocument = p_vbeln

order_header_inx = lt_header_x

logic_switch = ls_logic

TABLES

return = lt_return

order_item_in = lt_items

order_item_inx = lt_item_x

order_cfgs_ref = lt_cfgs_ref

order_cfgs_inst = lt_inst

order_cfgs_part_of = lt_parts

order_cfgs_value = lt_values

order_cfgs_blob = lt_cublob

order_cfgs_vk = lt_cuvk

order_cfgs_refinst = lt_curef.

  • Database update

IF NOT p_test IS INITIAL.

COMMIT WORK.

ENDIF.

  • Return Table

WRITE: / text-007,

AT /(5) 'TYPE' COLOR COL_HEADING,

AT (15) 'ID' COLOR COL_HEADING,

AT (7) 'NUMBER' COLOR COL_HEADING,

AT (80) 'MESSAGE' COLOR COL_HEADING.

LOOP AT lt_return INTO ls_return.

WRITE: AT /(5) ls_return-type COLOR COL_NORMAL,

AT (15) ls_return-id COLOR COL_NORMAL,

AT (7) ls_return-number COLOR COL_NORMAL,

AT (80) ls_return-message COLOR COL_NORMAL.

ENDLOOP.

ENDIF.

----


  • Data conversion:

  • BAPISDORDER_GETDETAILEDLIST => BAPI_SALESORDER_CHANGE

----


FORM convert_cfg_data.

DATA:

ls_profile TYPE cuco.

LOOP AT lt_item INTO ls_item.

ls_items-itm_number = ls_item-itm_number.

ls_items-hg_lv_item = ls_item-hg_lv_item.

ls_items-po_itm_no = ls_item-itm_number.

ls_items-material = ls_item-material.

APPEND ls_items TO lt_items.

CALL FUNCTION 'CUCB_GET_PROFILE_OF_INSTANCE'

EXPORTING

instance = ls_item-config

IMPORTING

profile_wa = ls_profile

EXCEPTIONS

invalid_instance = 1

instance_is_a_classification = 2

profile_not_found = 3

invalid_input = 4

OTHERS = 5.

CHECK sy-subrc IS INITIAL.

LOOP AT lt_cucfgs

INTO ls_cucfgs

WHERE posex EQ ls_item-itm_number.

ls_cfgs_ref-posex = ls_cucfgs-posex.

ls_cfgs_ref-config_id = ls_cucfgs-config_id.

ls_cfgs_ref-root_id = ls_cucfgs-root_id.

ls_cfgs_ref-sce = ls_cucfgs-sce.

ls_cfgs_ref-kbname = ls_cucfgs-kbname.

ls_cfgs_ref-kbversion = ls_cucfgs-kbversion.

APPEND ls_cfgs_ref TO lt_cfgs_ref.

ENDLOOP.

CHECK sy-subrc IS INITIAL.

LOOP AT lt_blob

INTO ls_blob

WHERE config_id EQ ls_cucfgs-config_id.

ls_cublob-config_id = ls_blob-config_id.

ls_cublob-context = ls_blob-context.

APPEND ls_cublob TO lt_cublob.

ENDLOOP.

LOOP AT lt_cuvks

INTO ls_cuvks

WHERE config_id EQ ls_cucfgs-config_id.

ls_cuvk-config_id = ls_cuvks-config_id.

ls_cuvk-inst_id = ls_cuvks-inst_id.

ls_cuvk-vkey = ls_cuvks-vkey.

ls_cuvk-factor = ls_cuvks-factor.

APPEND ls_cuvk TO lt_cuvk.

ENDLOOP.

LOOP AT lt_cuins

INTO ls_cuins

WHERE config_id EQ ls_cucfgs-config_id.

ls_inst-config_id = ls_cuins-config_id.

ls_inst-inst_id = ls_cuins-inst_id.

ls_inst-obj_type = ls_cuins-obj_type.

ls_inst-class_type = ls_cuins-class_type.

ls_inst-obj_key = ls_cuins-obj_key.

APPEND ls_inst TO lt_inst.

LOOP AT lt_cuvals

INTO ls_cuvals

WHERE config_id EQ ls_cuins-config_id AND

inst_id EQ ls_cuins-inst_id.

ls_values-config_id = ls_cuvals-config_id.

ls_values-inst_id = ls_cuvals-inst_id.

ls_values-charc = ls_cuvals-charc.

ls_values-value = ls_cuvals-value.

ls_values-author = ls_cuvals-author.

APPEND ls_values TO lt_values.

ENDLOOP.

IF NOT ls_profile-stlkd IS INITIAL.

  • do not add components of order BoM

EXIT.

ENDIF.

LOOP AT lt_cuprts

INTO ls_cuprts

WHERE config_id EQ ls_cuins-config_id

AND parent_id EQ ls_cuins-inst_id.

ls_parts-config_id = ls_cuprts-config_id.

ls_parts-parent_id = ls_cuprts-parent_id.

ls_parts-inst_id = ls_cuprts-inst_id.

ls_parts-part_of_no = ls_cuprts-part_of_no.

ls_parts-obj_type = ls_cuprts-obj_type.

ls_parts-class_type = ls_cuprts-class_type.

ls_parts-obj_key = ls_cuprts-obj_key.

APPEND ls_parts TO lt_parts.

ENDLOOP.

ENDLOOP.

ENDLOOP.

ENDFORM.

Thanks

Ankit Attrish

Edited by: Ankitatt on Feb 19, 2010 9:26 PM