After having connected to an SAP system (via RfcAccept) and after having installed the supported RFC functions, the RFC server program has to use the RFC call RfcInstallTransactionControl for working with the TIDs to check and execute the real RFC function it supports before entering in the loop with RfcDispatch.
This function installs the following four functions (e.g. C routines) to control transactional behavior:
will be activated if a tRFC is called from an SAP system. The current TID is
passed. The function has to store this TID in permanent storage and return
If the same function will be called again later with the same TID, it has to make sure that it will return a value <>0. If the same TID is already running by another process but is not completed, the function has to wait until the transaction finishes or to stop the RFC connection with RfcAbort.
This function will be called if all RFC functions belonging to this transaction are done and the local transaction can be completed. It should be used to locally commit the transaction if necessary (working with database).
This function is called instead of the function onCommit if there is an error occurring in the RFC library while processing the local transaction. This function can be used to roll back the local transaction (working with database).
This function will be called if the local transaction is completed. All information about this TID can be deleted.
· These four functions must be realized in any tRFC server program and are independent of the real RFC function offered in an RFC server program. A server program can offer more than one RFC function but only the four functions above and not four functions for each RFC function.
· If you do not install and work with these four functions it can only be guaranteed that an RFC call issued by ‘Call Function... In Background Task’ is executed by this RFC server program at least once. In this case, all RFC functions offered by such a server program can be called more than once by using the tRFC interface.
The following parameters can be configured with transaction SM59:
· try or do not try to connect to an RFC server program in cases of error
· number of times for trying
· time between two tries
The program location ‘User’ defined with this transaction (start RFC server program via currently using SAPGUI) is not available, because the tRFC component is not assigned to any SAPGUI while running.
Transaction SM58 displays the running state of a transaction if the transaction was not executed successfully already.
The tRFC component, the RFC library and the tRFC server communicate with each other in two phases:
· Phase 1/F1: Function transfer
· Phase 2/F2: Confirmation
After tRFC data is received, the RFC library will activate the tRFC server program (action: start). Using RfcDispatch in a loop, the library will call up the following functions within this function transfer phase:
· T1: onCheckTid
· T2: the required RFC function ‘abc_function’
· T3: onCommit
As described above, the function transfer phase will be repeated by the tRFC component in the SAP system if any CPI-C error (network errors, for example) occurs during this phase. The maximum number of tries and the time between two tries can be defined by using transaction SM59 and TRFC options.
After the RFC library informs the tRFC components in the SAP system about a successful T3, it will immediately receive confirmation of the current transaction. The RFC library will then call up the function
· T4: onConfirmTID
After this phase, the current transaction is successfully completed on both sides.
The C-program trfcserv.c, delivered in the form of executable and source code in the RFC SDK, is an example of a tRFC server program.
For testing, the ABAP program SRFCTEST, option Transactional RFC, can be used with this server program.
The data received from the SAP system will be written in ‘trnn... n.dat’ on the running platform. Each line in this file is one line in an internal table. Only one internal table with a line length of 72 bit is used.
To manage the TIDs, the trfcserv.c program uses the file I/O on the running platform.
For each TID there is an entry in the TID-management which contains the date and time, the TID itself, the state of this transaction (CREATED, CONFIRMED,...) and the name of the data file.
Since this program can run on different platforms, a corresponding flag (SAPonUNIX, SAPonNT,...) must be set if you want to compile and link this program in your environment.
For more details, see the source code delivered in the RFC SDK.