cancel
Showing results for 
Search instead for 
Did you mean: 

Error in creating Service Order using 'BAPI_ALM_ORDER_MAINTAIN'.

harshal_likhar
Explorer
0 Kudos

we are trying to create the service order with multiple operations and services but are not able to figure out the mapping. we have checked the BAPI documentation also, but still no luck.
The error I am getting is "Incorrect parameter mapping for operation &1 and service object &2".

Could anyone please help me with this regard, I have read all the blogs and answers available but no luck.

Please find the code I have written:

*******Header*******

lv_werks = '5000'.
ls_methods-refnumber = '1'.
ls_methods-objecttype = 'HEADER'.
ls_methods-method = 'CREATE'.
ls_methods-objectkey = '%00000000001'.
APPEND ls_methods TO lt_methods.

ls_header-order_type = p_auart.
ls_header-planplant = p_iwerk.
ls_header-plant = lv_werks.
ls_header-mn_wk_ctr = p_wk_ctr.
ls_header-start_date = sy-datum.
ls_header-start_date = sy-datum.
ls_header-funct_loc = '29'.
ls_header-equipment = p_equnr.
ls_header-funct_loc = p_tplnr.
ls_header-short_text = p_ktext.
ls_header-short_text = 'Angebot gemäß Abstimmung'.
INSERT ls_header INTO TABLE lt_header.

**********Operation*****************

p_act = '0010'. p_act2 = '0020'.

lv_objectkey = |%00000000001| & |{ p_act }|.
CLEAR ls_methods.
ls_methods-refnumber = '1'.
ls_methods-objecttype = 'OPERATION'.
ls_methods-method = 'CREATE'.
ls_methods-objectkey = lv_objectkey.
APPEND ls_methods TO lt_methods.

ls_operation-activity = p_act.
ls_operation-work_cntr = p_wk_ctr.
ls_operation-control_key = p_cntrl.
ls_operation-plant = p_werks.
ls_operation-description = p_desc.
ls_operation-acttype = p_actty.
ls_operation-matl_group = 'SANITÄR'.
ls_operation-mrp_relevant = '1'.
ls_operation-base_uom = 'LE'.
ls_operation-currency = 'EUR'.
ls_operation-calc_key = '1'.
ls_operation-execfactor = '1'.
APPEND ls_operation TO lt_operation.
* CLEAR :ls_operation,ls_methods.
* ENDDO.

IF p_vorg = abap_true.
lv_objectkey = |%00000000001| & |{ p_act2 }|.
CLEAR ls_methods.
ls_methods-refnumber = '2'.
ls_methods-objecttype = 'OPERATION'.
ls_methods-method = 'CREATE'.
ls_methods-objectkey = lv_objectkey.
APPEND ls_methods TO lt_methods.

CLEAR: ls_operation.
ls_operation-activity = p_act2.
ls_operation-work_cntr = p_wk_ctr.
ls_operation-control_key = p_cntrl2.
ls_operation-plant = p_werks.
ls_operation-description = p_desc2.
ls_operation-acttype = p_actty2 .
ls_operation-matl_group = 'SANITÄR'.
ls_operation-mrp_relevant = '1'.
ls_operation-base_uom = 'LE'.
ls_operation-currency = 'EUR'.
ls_operation-calc_key = '1'.
ls_operation-execfactor = '1'.
APPEND ls_operation TO lt_operation.

***********Service************

CLEAR ls_methods.
lv_objectkey = '%000000000010010'.
ls_methods-refnumber = 1.
ls_methods-objecttype = 'SERVICELINE'.
ls_methods-method = 'CREATE'.
ls_methods-objectkey = lv_objectkey.
APPEND ls_methods TO lt_methods.

CLEAR :lt_srv_detail.
SELECT esll~sub_packno FROM ekpo
INNER JOIN ekko ON ekko~ebeln = ekpo~ebeln
INNER JOIN esll ON esll~packno = ekpo~packno
INTO TABLE @DATA(lt_sub_packno) WHERE
ekko~ebeln = @p_lifr AND ekko~bsart = 'WK'.

SELECT srvpos
menge
meins
brtwr
ktext1
FROM esll INTO TABLE lt_srv_detail
FOR ALL ENTRIES IN lt_sub_packno
WHERE packno = lt_sub_packno-sub_packno AND uebtk = space.

READ TABLE lt_srv_detail INTO ls_srv_detail WITH KEY srvpos = p_srv.

APPEND INITIAL LINE TO lt_servicelines ASSIGNING <ls_serviceline>.
<ls_serviceline>-srv_line = '0000000010'.
<ls_serviceline>-outline = '0000000001'.
<ls_serviceline>-activity = '0010'.
* <ls_serviceline>-service = p_srv.
<ls_serviceline>-short_text = p_ktext. "'Angebot gemäß Abstimmung'.
<ls_serviceline>-quantity = ls_srv_detail-menge. "'1'.
<ls_serviceline>-uom = ls_srv_detail-meins."'LE'. 'LE'.
<ls_serviceline>-gross_price = ls_srv_detail-brtwr. "'1'.
<ls_serviceline>-currency = lv_waers.

CLEAR ls_methods.
ls_methods-refnumber = 1.
ls_methods-objecttype = 'SERVICEOUTLINE'.
ls_methods-method = 'CREATE'.
ls_methods-objectkey = lv_objectkey ."'%000000000010010'.
APPEND ls_methods TO lt_methods.

APPEND INITIAL LINE TO lt_serviceoutline ASSIGNING <ls_serviceoutline>.
<ls_serviceoutline>-activity = '0010'.
<ls_serviceoutline>-outline = <ls_serviceline>-outline." |000000000| & |{ sy-index }|.
<ls_serviceoutline>-parent_outline = '0000000000'.
<ls_serviceoutline>-from_line = '1'.
<ls_serviceoutline>-short_text = p_ktext.

CLEAR ls_methods.
lv_objectkey = '%000000000010020'.
ls_methods-refnumber = 1.
ls_methods-objecttype = 'SERVICELINE'.
ls_methods-method = 'CREATE'.
ls_methods-objectkey = lv_objectkey.
APPEND ls_methods TO lt_methods.

READ TABLE lt_srv_detail INTO ls_srv_detail WITH KEY srvpos = p_srv.

APPEND INITIAL LINE TO lt_servicelines ASSIGNING <ls_serviceline>.
<ls_serviceline>-srv_line = '0000000010'.
<ls_serviceline>-outline = '0000000001'.
<ls_serviceline>-activity = '0020'.
* <ls_serviceline>-service = p_srv.
<ls_serviceline>-short_text = p_ktext. "'Angebot gemäß Abstimmung'.
<ls_serviceline>-quantity = ls_srv_detail-menge. "'1'.
<ls_serviceline>-uom = ls_srv_detail-meins."'LE'. 'LE'.
<ls_serviceline>-gross_price = ls_srv_detail-brtwr. "'1'.
<ls_serviceline>-currency = lv_waers.

CLEAR ls_methods.
ls_methods-refnumber = 1.
ls_methods-objecttype = 'SERVICEOUTLINE'.
ls_methods-method = 'CREATE'.
ls_methods-objectkey = lv_objectkey ."'%000000000010010'.
APPEND ls_methods TO lt_methods.

APPEND INITIAL LINE TO lt_serviceoutline ASSIGNING <ls_serviceoutline>.
<ls_serviceoutline>-activity = '0020'.
<ls_serviceoutline>-outline = <ls_serviceline>-outline." |000000000| & |{ sy-index }|.
<ls_serviceoutline>-parent_outline = '0000000000'.
<ls_serviceoutline>-from_line = '1'.
<ls_serviceoutline>-short_text = p_ktext.

**********Save*************
CLEAR ls_methods.
ls_methods-refnumber = '1'.
ls_methods-method = 'SAVE'.
ls_methods-objectkey = '%00000000001'.
APPEND ls_methods TO lt_methods.

CALL FUNCTION 'BAPI_ALM_ORDER_MAINTAIN'
TABLES
it_methods = lt_methods
it_header = lt_header
it_operation = lt_operation
return = lt_return
et_numbers = lt_number
it_serviceoutline = lt_serviceoutline
it_servicelines = lt_servicelines.

IF line_exists( lt_return[ type = 'E' ] ).
RETURN.
ENDIF.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

VXLozano
Active Contributor

More useful info: there is a button in the editor reading "CODE"... it's very helpful to translate

gibberish yadda yadda yadda

to

gibberish yadda yadda yadda

Accepted Solutions (1)

Accepted Solutions (1)

peter_atkin
Active Contributor
0 Kudos

This works in my test system, so take this as a basis and extend it to add your services.

*&--------------------------------------------------------------------&*
*& Report ZPJA006
*& Author: Pete Atkin
*&--------------------------------------------------------------------&*
*& Test program to create order with multiple operations via function
*& module BAPI_ALM_ORDER_MAINTAIN
*&--------------------------------------------------------------------&*
report zpm0006.

data: lt_methods   type table of bapi_alm_order_method,
      ls_methods   type bapi_alm_order_method,
      lt_header    type table of bapi_alm_order_headers_i,
      ls_header    type bapi_alm_order_headers_i,
      lt_operation type table of bapi_alm_order_operation,
      ls_operation type bapi_alm_order_operation,
      lt_return    type table of bapiret2,
      lv_objkey    type objidext.

*&--------------------------------------------------------------------&*
*& Header Data
*&--------------------------------------------------------------------&*
ls_methods-refnumber  = 1.
ls_methods-objecttype = 'HEADER'.
ls_methods-method     = 'CREATE'.
ls_methods-objectkey  = '%00000000001'.
append ls_methods to lt_methods.

ls_header-order_type = 'PM01'.
ls_header-planplant  = '1000'.
ls_header-start_date = sy-datum.
ls_header-start_date = sy-datum.
ls_header-equipment  = '10000000'.
ls_header-short_text = 'Test Order via BAPI_ALM_ORDER_MAINTAIN'.
insert ls_header into table lt_header.

*&--------------------------------------------------------------------&*
*& Operation Data
*&--------------------------------------------------------------------&*
concatenate '%00000000001' '0010' into lv_objkey.
clear ls_methods.
ls_methods-refnumber  = 1.
ls_methods-objecttype = 'OPERATION'.
ls_methods-method     = 'CREATE'.
ls_methods-objectkey  = lv_objkey.
append ls_methods to lt_methods.

ls_operation-activity      = '0010'.
ls_operation-control_key   = 'PM01'.
ls_operation-description   = 'OP10'.
ls_operation-work_activity = 1.
append ls_operation to lt_operation.

concatenate '%00000000001' '0020' into lv_objkey.
clear ls_methods.
ls_methods-refnumber  = 2.
ls_methods-objecttype = 'OPERATION'.
ls_methods-method     = 'CREATE'.
ls_methods-objectkey  = lv_objkey.
append ls_methods to lt_methods.

ls_operation-activity      = '0020'.
ls_operation-control_key   = 'PM01'.
ls_operation-description   = 'OP20'.
ls_operation-work_activity = 2.
append ls_operation to lt_operation.

*&--------------------------------------------------------------------&*
*& Save Data
*&--------------------------------------------------------------------&*
clear ls_methods.
ls_methods-refnumber = '1'.
ls_methods-method    = 'SAVE'.
ls_methods-objectkey = '%00000000001'.
append ls_methods to lt_methods.

call function 'BAPI_ALM_ORDER_MAINTAIN'
  tables
    it_methods   = lt_methods
    it_header    = lt_header
    it_operation = lt_operation
    return       = lt_return.

if line_exists( lt_return[ type = 'E' ] ).
  return.
else.
  call function 'BAPI_TRANSACTION_COMMIT'.
endif.<br>

.

PeteA

harshal_likhar
Explorer
0 Kudos

Hello Peter,

Thanks for your reply,
the user has changed the requirement and we are creating one operation and one service for the order now.
your answer is correct but I was looking for multiple operations and multiple services to create for the order.

Regards,

Harshal

Answers (0)