cancel
Showing results for 
Search instead for 
Did you mean: 

Clear WBS field in sales order using bapi_salesorder_createfromdat2.

Former Member
0 Kudos

Hi,

Situation is this, I have a sales order, where the WBS element in the line item is populated. I want to clear that field to blank and save the sales order.

When I try to do that using the bapi_salesorder_createfromdat2, it says that it is successful, but when I go back to the sales order and see that field is still populated and not cleared. But the same field if I clear it through VA02 it works fine.

Header level update flag is set as 'U'.

I have tried setting up 'D' 'U' and 'I' for the update flag for the line item. Still no luck.

Given below is the sample code, did anybody else also faced the same issue.

Data Section.


data : sal_t_in type standard table of BAPISDHD1,
       sal_s_in like line of sal_t_in.

*data : sal_t_in type standard table of BAPISDH1,
*       sal_s_in like line of sal_t_in.



data : ret_t type standard table of bapiret2,
       ret_s like line of ret_t.

data : partner_t type standard table of bapiparnr,
       partner_s like line of partner_t.

data : item_t type standard table of bapisditm,
       item_s like line of item_t.

data : item_t_inx type standard table of BAPISDITMX,
       item_s_inx like line of item_t_inx.

data : schdl_t type standard table of BAPISCHDL,
       schdl_s like line of schdl_t.

data : schdl_t_inx type standard table of BAPISCHDLX,
       schdl_s_inx like line of schdl_t_inx.

data : ord_view type order_view.

data : sal_t_key type standard table of sales_key,
       sal_s_key like line of sal_t_key.

data : ord_t_hdr type standard table of bapisdhd,
       ord_s_hdr like line of ord_t_hdr.

data : ord_t_itm type standard table of bapisdit,
       ord_s_itm like line of ord_t_itm.

 data : hdr_inx type BAPISDHD1X.
 data : hdr2_inx type BAPISDH1X.
data : qty type DZMENG.

data : logic_switch type BAPISDLS.

data : sd_doc_out type BAPIVBELN-VBELN.
data : sd_hdr_out type BAPISDHD.
data : sd_hdr_stat type BAPISDHDST.

Logic Section.


sal_s_in-doc_type = 'ZOR'.
hdr_inx-updateflag = 'U'.

ord_view-header = 'X'.
ord_view-item = 'X'.

sal_s_key-vbeln = '0000001067'.
append sal_s_key to sal_t_key.

call function 'BAPISDORDER_GETDETAILEDLIST'
  exporting
    i_bapi_view                   = ord_view
*   I_MEMORY_READ                 =
  tables
    sales_documents               = sal_t_key
   ORDER_HEADERS_OUT             = ord_t_hdr
   ORDER_ITEMS_OUT               = ord_t_itm
*   ORDER_SCHEDULES_OUT           =
*   ORDER_BUSINESS_OUT            =
*   ORDER_PARTNERS_OUT            =
*   ORDER_ADDRESS_OUT             =
*   ORDER_STATUSHEADERS_OUT       =
*   ORDER_STATUSITEMS_OUT         =
*   ORDER_CONDITIONS_OUT          =
*   ORDER_COND_HEAD               =
*   ORDER_COND_ITEM               =
*   ORDER_COND_QTY_SCALE          =
*   ORDER_COND_VAL_SCALE          =
*   ORDER_CONTRACTS_OUT           =
*   ORDER_TEXTHEADERS_OUT         =
*   ORDER_TEXTLINES_OUT           =
*   ORDER_FLOWS_OUT               =
*   ORDER_CFGS_CUREFS_OUT         =
*   ORDER_CFGS_CUCFGS_OUT         =
*   ORDER_CFGS_CUINS_OUT          =
*   ORDER_CFGS_CUPRTS_OUT         =
*   ORDER_CFGS_CUVALS_OUT         =
*   ORDER_CFGS_CUBLBS_OUT         =
*   ORDER_CFGS_CUVKS_OUT          =
*   ORDER_BILLINGPLANS_OUT        =
*   ORDER_BILLINGDATES_OUT        =
*   ORDER_CREDITCARDS_OUT         =
*   EXTENSIONOUT                  =
          .
loop at ord_t_itm into ord_s_itm.

move-corresponding ord_s_itm to item_s.

call function 'CONVERSION_EXIT_ABPSP_OUTPUT'
  exporting
    input         = item_s-WBS_ELEM
 IMPORTING
   OUTPUT        = item_s-WBS_ELEM
          .



*move space to item_s-WBS_ELEM.

append item_s to item_t.

endloop.


clear item_s_inx.
item_s_inx-updateflag = 'D'.
item_s_inx-wbs_elem = 'X'.
append item_s_inx to item_t_inx.


call function 'BAPI_SALESORDER_CREATEFROMDAT2'
  exporting
    SALESDOCUMENTIN               = '0000001067'
    order_header_in               = sal_s_in
    ORDER_HEADER_INX              = hdr_inx
*   SENDER                        =
*   BINARY_RELATIONSHIPTYPE       =
*   INT_NUMBER_ASSIGNMENT         =
*   BEHAVE_WHEN_ERROR             =
*   LOGIC_SWITCH                  =
*   TESTRUN                       =
*   CONVERT                       = ' '
* IMPORTING
*   SALESDOCUMENT                 =
  tables
    RETURN                        = ret_t
   ORDER_ITEMS_IN                = item_t
   ORDER_ITEMS_INX               = item_t_inx
    order_partners                = partner_t
*   ORDER_SCHEDULES_IN            =
*   ORDER_SCHEDULES_INX           =
*   ORDER_CONDITIONS_IN           =
*   ORDER_CONDITIONS_INX          =
*   ORDER_CFGS_REF                =
*   ORDER_CFGS_INST               =
*   ORDER_CFGS_PART_OF            =
*   ORDER_CFGS_VALUE              =
*   ORDER_CFGS_BLOB               =
*   ORDER_CFGS_VK                 =
*   ORDER_CFGS_REFINST            =
*   ORDER_CCARD                   =
*   ORDER_TEXT                    =
*   ORDER_KEYS                    =
*   EXTENSIONIN                   =
*   PARTNERADDRESSES              =
          .

*


call function 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
*   WAIT          =
* IMPORTING
*   RETURN        =
          .

Result I get when I execute is

S V4 233 SALES_HEADER_IN has been processed successfully VBAKKOM

S V4 233 SALES_ITEM_IN has been processed successfully VBAPKOM 000001

S V1 311 Standard order 1067 has been saved Standard order 1067

Which means it says it save successfully..but data is not changed.

Any Ideas??

Thanks and Regards,

Mahesh.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

The problem is fixed. The item inx table I was not passing the item number field, so the bapi was not knowing which line item to update.

It was a stupid overlook on my part.

Thanks and Regards,

Mahesh.