Hello Folks,
Today we learn about create Workorder for the PM/QM Notifications by using the BAPI –“BAPI_ALM_ORDER_MAINTAIN”.
This blog is to give clear picture on creating workorder for the notification with BAPI’s. and this blog is for who don’t know creating workorder for the notification by using BAPI.
Firstly we have to know few parameters in the above BAPI.
In the above screenshot there is a parameter called Methods you can find that Methods are are mandatory.
The methods table specifies which methods the BAPI executes. For this the following data is always required:
•REFNUMBER A reference number for a data table line
•OBJECTTYPE An object type that specifies which data table(s) is referenced
•METHOD A method that specifies what should be done to the object
•OBJECTKEY A key as a reference to the corresponding higher-level object
Value range
The following values are allowed:
OBJECTTYPE
HEADER | Order header |
PARTNER | Partner data |
USERSTATUS | User status |
OPERATION | Operation data |
RELATION | Relationships |
COMPONENT | Component |
TEXT | Long texts |
SRULE | Settlement rule |
OBJECTLIST | Object list |
OLISTRELATION | Object list link |
TASKLIST | General maintenance task list |
PRT | Production resources/tools |
SERVICEOUTLINE | Service package outline |
SERVICELINE | Service package service line |
SERVICELIMIT | Service package limit |
SERVICECONTRACTLIMIT | Service package contract limit |
ESTIMATEDCOST | Estimated costs per value category |
(empty) General BAPI functions (Save) |
METHOD
CREATE | Create objects |
CREATETONOTIF | Create with reference to a notification |
CHANGE | Change objects |
DELETE | Delete objects |
RELEASE | Release |
ATPCHECK | Availability check |
CALCULATE | Calculate |
SCHEDULE | Schedule |
DELETEDSEX | Delete the status for external scheduling at operation level |
ADD | Add (only possible for object TASKLIST) |
SAVE | Save all data |
DIALOG | Dialog call |
TRACE | Write trace file to the specified file on the front end |
DO_NOT_EXECUTE | Do not execute |
DO_NOT_EXEC_NOTIF_CLOSE | Do not execute and complete notifications |
Note: This also automatically completes any outstanding tasks in the notifications. | |
DO_NOT_EXEC_NOTIF_DEALLOC | Do not execute and remove assigned notifications from order |
Note: Notifications assigned to the order header are not removed, but rather automatically completed. | |
LOCK | Lock |
UNLOCK | Unlock |
TECHNICALCOMPLETE | Technically complete |
CANCEL_TECHNICAL_COMPLETION | Cancel technical completion |
TECO_WITH_NOTIF | Technically complete with notifications |
Note: If a reference date is transferred, the notification with the reference date is also completed. The tasks of the notification are not automatically completed. | |
CANCEL_TECO_WITH_NOTIF | Reset technical completion and put assigned notifications in process again |
COMPLETE_BUSINESS | Complete (business) |
CANCEL_BUSINESS_COMPLETION | Cancel business completion |
BUS_COMPL_WITH_NOTIF | Complete (business) with notifications |
SET_DEL_FLAG | Set Deletion Flag |
RESET_DEL_FLAG | Reset Deletion Flag |
SET_DLFL_WITH_NOTIF | Also set deletion flag for assigned notifications |
RESET_DLFL_WITH_NOTIF | Reset deletion flag and put assigned notifications in process again |
Note:
Executing the following methods requires saving (method SAVE) and updating the data. It is not possible to make further changes to the order data until the update is successful:
TECHNICALCOMPLETE |
TECO_WITH_NOTIF |
COMPLETE_BUSINESS |
BUS_COMPL_WITH_NOTIF |
SET_DEL_FLAG |
SET_DLFL_WITH_NOTIF |
OBJECTKEY
0-12 Order number
13-16 Operation number
17-20 Suboperation number
13-24 Notification number (only for method CREATETONOTIF)
The following methods are possible for the individual objects:
HEADER
CREATE, CHANGE, RELEASE, ATPCHECK, CALCUALTE, SCHEDULE, CREATETONOTIF, DO_NOT_EXECUTE, LOCK, UNLOCK, TECHNICALCOMPLETE, CANCEL_TECHNICAL_COMPLETION, COMPLETE_BUSINESS, CANCEL_BUSINESS_COMPLETION, SET_DEL_FLAG, RESET_DEL_FLAG
OPERATION
CREATE, CHANGE, DELETE, DELETEDSEX•PARTNER, RELATION, USERSTATUS, TEXT, SRULE, OBJECTLIST, PRT
CREATE, CHANGE, DELETE
OLISTRELATION
CREATE, DELETE•TASKLIST
ADD
COMPONENT
CREATE, CHANGE, REASSIGN, DELETE•ESTIMATEDCOST
CHANGE
(empty)
SAVE, DIALOG, TRACE
Common Lets Write the logic and achieve this, Follow below.
Selection Screen
Provide the Notification to create the notification
Execute will get the proper workorder number
result in Notification Screen
In case any error occurs it will show you the error message also.
So copy the below code and enjoy.
REPORT zcreate_work_order.
PARAMETERS: p_qmnum TYPE qmnum.
*Declarations
DATA:
it_methods TYPE STANDARD TABLE OF bapi_alm_order_method,
it_header TYPE STANDARD TABLE OF bapi_alm_order_headers_i,
it_header_up TYPE STANDARD TABLE OF bapi_alm_order_headers_up,
it_operation TYPE STANDARD TABLE OF bapi_alm_order_operation,
return TYPE TABLE OF bapiret2.
*Fetching Notification data
SELECT SINGLE qmart, aufnr FROM qmel INTO @DATA(ls_qmel) WHERE qmnum = @p_qmnum.
IF ls_qmel-aufnr IS NOT INITIAL.
* if Workorder is already created for the notification it will throw the errorr message
MESSAGE 'Work Order is already created for the given notification' TYPE 'I'.
ELSE.
* Creating Workorder
it_methods = VALUE #( ( refnumber = '000001' objecttype = 'HEADER'
method = 'CREATETONOTIF'
objectkey = |%00000000001{ p_qmnum } | )
( refnumber = '000001' objecttype = ''
method = 'SAVE'
objectkey = |%00000000001{ p_qmnum } | )
* operations
( refnumber = '000001'
objecttype = 'OPERATION'
method = 'CREATE'
objectkey = '%000000000010010' ) ).
it_header = VALUE #( ( orderid = '%00000000001'
order_type = 'ZM01' " Order type
planplant = '9001' " plant
mn_wk_ctr = 'MECH' " work center
start_date = sy-datum " Required Start Date
fINISH_DATE = sy-datum " Required End Date
short_text = 'Demo Create Workorder' " Short text value
funct_loc = '9001' " Functional location
pmacttype = '003'
notif_no = p_qmnum " Notification Number
notif_type = ls_qmel-qmart " Notification Type
) ).
it_header_up = VALUE #( ( notif_no = abap_true ) ).
it_operation = VALUE #( ( activity = '0010'
control_key = 'PM01'
description = 'Create Operaion Item' ) ).
CALL FUNCTION 'BAPI_ALM_ORDER_MAINTAIN'
TABLES
it_methods = it_methods
it_header = it_header
it_header_up = it_header_up
it_operation = it_operation
return = return.
IF line_exists( return[ type = 'E' ] ).
DATA(lv_message) = return[ type = 'E' ]-message.
MESSAGE lv_message TYPE 'E' DISPLAY LIKE 'I'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
CALL FUNCTION 'DEQUEUE_ALL'
EXPORTING
_synchron = 'X'.
DATA(lv_order) = return[ 1 ]-message_v2.
DATA(lv_success) = |Work Order created with order { lv_order } for the notification | && |{ p_qmnum ALPHA = OUT }|.
MESSAGE lv_success TYPE 'S' DISPLAY LIKE 'I'.
ENDIF.
ENDIF.
So folks i think you learned some thing new from this blog.
if you have any quires comment below and follow me for further content.
Thanks for reading.