cancel
Showing results for 
Search instead for 
Did you mean: 

How to add new operation in work order using BAPI

lekhashree
Explorer
0 Kudos
834

Hi Team,

Can you please let me know How to add new operation in work order using BAPI ?

Thanks,

Lekha

Accepted Solutions (0)

Answers (1)

Answers (1)

peter_atkin
Active Contributor

Lekha,

For future reference; you will get a better response if you also tag your posts with: PLM Enterprise Asset Management (EAM)/Plant Maintenance (PM).

Below is some test code:

PeteA

*&--------------------------------------------------------------------&*
*& 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 = 'P-1000-N005'.
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' ] ).
break-point.
return.
else.
call function 'BAPI_TRANSACTION_COMMIT'.
endif.