This page has the aim to explain how to create a Purchase Requisition using a Business Application Programming Interface, the BAPI_PR_CREATE Function module.
There is a possibility to use a Business Application Programming Interface (a.k.a BAPI) to create purchase requisitions from an external system.
BAPI_PR_CREATE (formerly BAPI_REQUISITION_CREATE) is a standard SAP function module available within R/3 SAP systems depending on your version and release level.
You can use this BAPI_PR_CREATE FM to create purchase requisitions. Business Application Programming Interface (shortly a BAPI) can be used to simulate, test and execute a Business functionality, in our case to create or change a Purchase Requisition. More details about BAPI's can be found in any SAP-system in the transaction BAPI - the BAPI Explorer. Within that transaction go to Materials Management > Purchasing > PurchaseRequisition > select the method: CreateFromData1. A comprehensive documentation of the function will be shown under the Documentation tab.
How to run the BAPI by creating Test data
You might Test the running of the BAPI by creating test data records. You could manually fill in the Test data according to the BAPI documentation and/or your requirements. When done, go to the Menu path 'Edit > Save data record' (Ctrl+S) to save your data into the Test directory. Use the button 'Test data directory' in order to call all existing data records :
Alternatively, you can use the automatic generation of Test data. Such process can be initiated by an external system, like SRM. Or you can use the report FBGENDAT according to the Solution part of the SAP Note 539978 - "Automatic generation of BAPI test data directory", that is :
- For the user, under whose name the call is to be executed, enter parameter FBGENDAT = X. Use Transaction SU01 to do this. If the call comes from an external system, the caller can be an RFC user.
- Execute report FBGENDAT to activate the generation of test data records for certain function modules.
Enter the corresponding function module in the first line. Choose the mode in which you want to generate the report and execute it. The displayed list shows all function modules for which the test data generator is active and in which mode.
The following modes are available for selection:
a) A test data record is created after the call of the function module and the calling program ends with a termination message (dump).
b) A test data record is created after the call of the function module and the function module is processed normally.
c) NO test data record is generated. The program runs into an endless loop at the start of the function module. You can use Transaction SM50 to debug the process. You can stop the endless loop by setting the lv_exit_gd field to 'X' and you can then continue the process in individual steps.
d) A test data record is prepared after the call of the function module, but it is not stored.
- Start the BAPI call and check whether a test data record was generated in the Function Builder.
- Deactivate the generation of test data records by deleting the entries in report FBGENDAT and resetting the user parameter.
How to fill the BAPI - example
A detailed guide of how to fill the BAPI can be found with examples under the transaction BAPI. Depending on your scenario (PR with or without Material master, Sources of Supply, Account Assignment, etc.), relatively small number of fields are required to create a new Requisition. We provide here below a basic example :
PR_TYPE = NB
PR_TYPE = X
PREQ_ITEM = 00010
MATERIAL = YOUR_MATERIAL_ID
PLANT = YOUR_PLANT
QUANTITY = 1.000
PREQ_ITEM = 00010
PREQ_ITEMX = X
MATERIAL = X
PLANT = X
QUANTITY = X
Upon launching a new BAPI-run, internal BAPI structure (bapimereqitem) should be mapped to the Requisition structure (mereq_item). This is done in the include L2105I03, MAP2I_ITEM (LCL_BAPI_ITEM). The processing of PR-data starts from the include L2105I01, PROCESS (LCL_BAPI_REQUISITION). Item fields are filled in the include LMEREQF05, CLASS_CONSTRUCTOR (LCL_REQ_ITEM). The actual processing of the Requisition happens in the L2105I02, PROCESS_REQ (LCL_BAPI_HEADER). Finally commit may happen in LMEREQF06, POST (LCL_INSTANCE_FACTORY) include.
End of Support for the BAPI_REQUISITION_CREATE
Starting with release SAP R/3 4.6C, the "old" transactions and BAPIs related to business objects Purchase Order and Purchase Requisition were replaced by new single-screen - so called Enjoy - transactions.
ME51 has been replaced by ME51N. The old BAPI_REQUISITION_CREATE, BAPI_REQUISITION_CHANGE have been replaced by BAPI_PR_CREATE, BAPI_PR_CHANGE.
SAP strongly recommends to use these new transactions, IDocs and BAPIs to process Purchase Order and Purchase Requisition documents. Future enhancements that are related to Purchase Order or Purchase Requisition will only be done for the "new" transactions, IDocs and BAPIs. Please see the SAP Note 1803189 - "FAQ: End of Support of ME21, ME51, BAPI_PO_CREATE and Archiving Reports etc." (no code inside) for more information.
SAP Help Programming with BAPIs
Related SAP Notes/KBAs
SAP Note: 539978 Automatic generation of BAPI test data directory
SAP Note: 1803189 FAQ: End of Support of ME21, ME51, BAPI_PO_CREATE and Archiving Reports etc.