SAP has provided various ways to integrate with third party applications. Remote function call (RFCs) is one of them. The advantage of using RFCs over other alternate like IDOCs is that the former is real time and whereas IDOCs are received or transmitted to a destination in asynchronous manner. However, some BAPIs do not commit to database and although you may get a success message or a document number, you may be surprised to see that you are not able to view the document when you try to access with the respective transaction code.
Often, it leads to frustration and misconception that the BAPI has not worked in the first place. One way to overcome this is by writing a custom wrapper BAPI and do an explicit COMMIT. However, this may not be useful in all cases. Let’s look at how you can test such a BAPI without doing any custom ABAP coding.
Step by Step Manner to test BAPI and make it commit
To explain this , we are taking BAPI for sales order create as an example. The BAPI name is BAPI_SALESORDER_CREATEFROMDAT2 and it does not commit to database.
# 1 . Create a working test case in the test data directory
This will help you in testing the BAPI later. Ensure that you are having a success message or a document number when running the test case on a standalone basis.
# 2. Use Test Sequences
Launch SE37 and build up a test sequence. The test sequence can be built using Function Module ->Test-> Test Sequences as shown in the picture below.
Using the test sequence will ensure that the BAPIs which are listed here are executed in a single Logical Unit of Work (LUW). As you know, BAPI_TRANSACTION_COMMIT is the BAPI which helps in committing to the database. Hence the test sequence would look like the below screenshot.
# 3. Execute the Sequence
Execute the sequence normally using F8. Please note that on getting the output of the first BAPI, you would also get the screen for the second one. This is exactly where step 1 comes to your help. You can readily use the test case and execute the first BAPI. In the transaction commit call, you can call with WAIT parameter set to X.
# 4. Check the transaction
Go to the transaction and check the document. You will see that the document has been created and saved in the database too.
Why don’t all BAPI have COMMIT?
Every transaction in SAP is divided into multiple logical unit of works (LUWs). SAP ensures that if a transaction like order creation is being done, either it should be done completely in database or none. This is ensured by doing a commit at the end of the call. This ensures that data is consistent keeping in mind that the concurrency and other users who may be using the same object. Also, some BAPIs involve mere simulation and are not meant to create new records. It is a good idea to check the documentation of the BAPI to know whether it needs an explicit commit.
How to call RFCs from third party application
SAP has provided libraries for popular programming languages like Java and .NET. The JCO and NCO libraries have methods to help you in calling any standard or custom RFC. It must be noted that only function modules which have remote function call enabled can be called externally.
The process involves first call SAP with the credentials and then calling the RFC you desire to call.