In many cases it is necessary to change the data of an object once it has been saved.
Reasons for this may be:
- There is no corresponding userexit to manipulate data of the object before saving.
- The corresponding fields are available only after saving, with the help of which you want to manipulate the data of the object.
Scenario
When saving the production order, the sequence short text should be changed.
Although the central userexit EXIT_SAPLCOBT_001 as well as the BADI WORKORDER_UPDATE are executed in the production order, they can not change the production order itself.
Change data of an SAP object with qRFC
The problem is that you can not change the production order before it is saved and the lock is released.
The following options are available for resetting a production order after saving.
- In userexit EXIT_SAPLCOBT_001, a function module IN BACKGROUND TASK is inserted which is aexecuted after COMMIT WORK. In the function module, the WAIT command is inserted, in order to execute the coding there for e.g. 5 sec waiting time. Alternatively, at the beginning of the function module, you can ask the enqueue object for the production order in a DO loop in conjunction with the WAIT command. When the lock is released, the function module’s code is executed.
- In the userexit EXIT_SAPLCOBT_001, a report is inserted, which is started as a job after a e.g. 5 sec waiting time.
However, SAP offers, in addition to the above methods, the queued Remote Function Call (qRFC), an elegant option for subsequently changing the production order in a queue and making possible errors transparent.
In the following, the work steps are shown how to call a function module via qRFC in the userexit EXIT_SAPLCOBT_001.
Create a RFC-capable function module
First, an RFC-capable function module is created.
FUNCTION z_pp_change_avfc_qrfc.
*”———————————————————————-
*”*”Lokale Schnittstelle:
*” TABLES
*” HEADER_TABLE STRUCTURE CAUFVDB OPTIONAL
*” OPERATION_TABLE STRUCTURE AFVGB OPTIONAL
*”———————————————————————-
* Deklarationen —————————————————— *
DATA: ls_header TYPE caufvdb,
ls_operation TYPE afvgb,
lv_tabix TYPE i,
lt_opr_change TYPE cose_t_opr_change,
ls_opr_change TYPE cose_s_opr_change,
lv_order_number TYPE aufnr.
DATA: lt_return TYPE TABLE OF bapiret2.
DATA: ls_return TYPE bapiret2.
* Update the oparation table AFVC ———————————— *
LOOP AT header_table INTO ls_header.
lv_order_number = ls_header-aufnr.
LOOP AT operation_table INTO ls_operation
WHERE aufpl = ls_header-aufpl.
ls_operation-ltxa1 = ‘123456’.
MOVE-CORRESPONDING ls_operation TO ls_opr_change.
ls_opr_change-ltxa1_x = ‘X’.
APPEND ls_opr_change TO lt_opr_change.
* Fertigungsauftrag: Vorgänge ändern ——————————— *
CALL FUNCTION ‘CO_SE_PRODORD_OPR_CHANGE’
EXPORTING
iv_order_number = lv_order_number
it_opr_change = lt_opr_change
iv_refresh = ‘X’
iv_order_post = ‘X’
iv_commit = ‘X’
IMPORTING
es_return = ls_return.
IF ls_return-type = ‘E’.
MESSAGE ID ls_return-id
TYPE ls_return-type
NUMBER ls_return-number
WITH ls_return-message_v1
ls_return-message_v2
ls_return-message_v3.
ENDIF.
The function module is inserted in the userexit EXIT_SAPLCOBT_001 with the attribute IN BACKGROUND TASK. It should only be called once for the initial creation of the production order.
Triggering the function module as qRFC in the input queue
The function module is to be executed as qRFC in the input queue of transaction SMQ2. For this purpose, it is necessary to call function block TRFC_SET_QIN_PROPERTIES before the function block IN BACKGROUND TASK. The function module TRFC_SET_QIN_PROPERTIES must be assigned a unique queue name. The queue name should start with a “Z” and contain the production order number for unambiguous identification. A name might be e.g. “ZPP_FAUF_0000100373”.
DATA: lv_queue_name TYPE trfcqin-qname.
READ TABLE header_table_old INDEX 1.
IF sy-subrc NE 0.
CONCATENATE ‘ZPP_FAUF_’
header_table-aufnr
INTO lv_queue_name.
CALL FUNCTION ‘TRFC_SET_QIN_PROPERTIES’
EXPORTING
qin_name = lv_queue_name
EXCEPTIONS
invalid_queue_name = 1
OTHERS = 2.
CALL FUNCTION ‘Z_PP_CHANGE_AVFC_QRFC’
IN BACKGROUND TASK DESTINATION ‘NONE’
TABLES
header_table = header_table
operation_table = operation_table.
When the production order is saved, the function module Z_PP_CHANGE_AVFC_QRFC is processed in the queue ZPP_FAUF_ after COMMIT WORK. If the production order is still locked, the processing is canceled and an error message is placed in the queue. The queue scheduler now calls the queue periodically until the function block of the queue has been successfully processed, depending on the setting. Depending on the setting, the queue is processed n times.
Anzeigen der Queue in der Eingangsqueue-Verarbeitung SMQ2
Wenn man jetzt einen Fertigungsauftrag initial anleget und sichert, wird ein Queue-Eintrag zur aktuellen Fertigungsauftragsnummer in Transaktion SMQ2 erzeugt.
In Transaktion SMQs ist der Eintrag sichtbar.
Durch Doppelklick auf den Queue-Eintrag kommt man in die Sicht, um die Queue zu registrieren und anzustarten.
Die Queue erhält den Status RUNNING und der Funktionsbaustein Z_PP_CHANGE_AVFC_QRFC wird jetzt aufgerufen und verarbeitet.
Wenn alles ok ist, dann verschwindet der Queue-Eintrag. In einer Endlosschleife bleibt der Status auf RUNNING, im Fehlerfall wird eine Fehlermeldung ausgegeben.
Registrierung der Queue im QIN-Scheduler
Der soeben gezeigte Weg erfordert, dass die Queue immer manuell gegistriert und angestartet werden muss. Zur automatischen Queue-Verarbeitung registriert man die Queue im QIN-Scheduler. Der QIN-Scheduler plant dann die Verarbeitung der Queue nach dem Sichern eines Fertigungsauftrags automatisch ein.
Nun geht man in die Transaktion SMQ2 und registriert die Queue.
Im QIN-Scheduler wird jetzt der Präfix des Queue-Namens eingetragen.
Weitere Informationen
Spezialthemen zu SAP Formularen
SAP Formulare zum Festpreis
SAP Formularentwicklung