Symptom
When you mass release production orders, for example in Manage Production Orders app or in Mass Processing Production Orders (COHV), the production orders are printed automatically. There are usaually several output objects for one production order, such as Order Data List, Order Component List and Pick List. You are expecting that the sequence of the output items is the same as the sequence of the production orders that are released. This means, for Order 1, Order 2, Order 3...... that are released, the output sequence should be:
- Order 1 Output Item 1, Order 1 Output Item 2
- Order 2 Output Item 1, Order 2 Output Item 2
- Order 3 Output Item 1, Order 3 Output Item 2
- ......
However, in real use case, the output sequence is sometimes unexpected. For example:
- Order 1 Item 1, Order 2 Item 1, Order 3 Output Item 1
- Order 1 Item 2, Order 2 Item 2, Order 3 Output Item 2
- ......
Or even:
- Order 2
- Order 3
- Order 1
- ......
Environment
SAP S/4HANA Public Cloud
Cause
Due to performance reasons, for each output item an own bgRFC queue is created. Those queues are processed independently and can take over each other. The sequence of the output items is decided by the speed it is processed and the speed depends on how long the data retrieval takes (number of operations, components, PRT, and so on) and on the extent of the form that must be rendered.
Resolution
As a workaround, we can make an implementation of BD_MFGORDER_CHECK_BEFORE_SAVE to make sure there is no open output item when a production order is changed. In this way, the latter production order will be printed only when the former one has been fully printed. Here is an example of the implementation:
" ********************** Serialized Printing **********************
" When changing an order this implementation waits until all other orders are
" printed. This ensures that the orders are printed in the same sequence as
" they were released
" The following coding must be at the top of the logic!
" All other implementations can be placed after this coding block.
" Only needed when existing orders are changed as new orders can't be
" part of a Mass Release run
IF create_mode = abap_false.
" Check release date
DATA lv_releasedate TYPE d.
SELECT SINGLE mfgorderactualreleasedate
FROM i_manufacturingorder
WHERE manufacturingorder = @manufacturingorder-manufacturingorder
INTO @lv_releasedate.
" Only relevant for orders that are not yet released as released orders were already printed
IF sy-subrc = 0 AND lv_releasedate IS INITIAL.
" Do not wait longer than 20 * 1 second
DO 20 TIMES.
" Check if any (unfinished) printing of an order was scheduled during the last minute
DATA lv_time TYPE timestampl.
DATA(lo_tstmp) = cl_abap_timestamp_util=>get_instance( ).
GET TIME STAMP FIELD lv_time.
lv_time = lo_tstmp->tstmpl_add_seconds( iv_timestamp = lv_time iv_seconds = -60 ).
" Get open print output item that was changed during the last minute
SELECT * FROM c_outputrequestitemdex WITH PRIVILEGED ACCESS
WHERE outputcontrolapplobjecttype = 'MANUFACTURING_ORDER'
AND outputchannel = 'PRINT'
AND ( outputrequestitemstatus = '2' OR outputrequestitemstatus = '3' )
AND ( lastchangedatetime > @lv_time OR
creationdatetime > @lv_time )
INTO TABLE @DATA(lt_tab) UP TO 1 ROWS.
IF sy-subrc <> 0.
" No unfinished output recently, so no need to wait
EXIT.
ENDIF.
"Wait 1 seconds to allow previous orders to finish printing
DATA lo_timer TYPE REF TO if_abap_runtime.
lo_timer ?= cl_abap_runtime=>create_lr_timer( ).
WHILE lo_timer->get_runtime( ) < 1000000. "delay in micro seconds
ENDWHILE.
ENDDO.
ENDIF.
ENDIF.
" ********************** End of Serialized Printing **********************
Please note that the above coding is only an example and you can adjust it according to your real business.
See Also
Keywords
production order, output items, sequence, in mass, Manage Production Orders, COHV, BD_MFGORDER_CHECK_BEFORE_SAVE, release, print , KBA , PP-SFC-EXE-PRINT-2CL , Order Printing (Public Cloud) , Problem