
| 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) |
| 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 |
| 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)



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.