SAP R/3’s Business Application Programming Interface (BAPI) is the powerful I/O engine that gets data in and out of the enormously complex superdatabases that SAP embodies. Its flexibility and convenience come from its writing and retrieval of data in ready-to-use configurations for business—part of SAP’s role to restructure the flow of information in a company.
At first glance, BAPIs are intimidating. A new SAP consultant may feel that something so powerful has to be complicated. The reality is that much of the work is done for you. Once you have a grasp of the role BAPIs play in the SAP data transport scheme, actually working with them isn’t that complicated.
Second in a series
This is the second installment in a series that looks at SAP’s Business Application Programming Interfaces and how consultants can use them. The previous article gave an overview of their role.
Creating BAPIs for new applications
The best news for the SAP newcomer is that you already have a library of BAPIs at your fingertips. The Business Object Repository (BOR) contains dozens of BAPIs for creating and retrieving master records and transactional records of all types, including orders and invoices, customer records, employee records, shipping records, quotes, security information, and plan data.
You can use these out of the can or create your own—whichever your application requires. The BOR is your starting point. You can access it in two ways: You can go directly there through the SAP transaction BAPI or through transaction SW01, the Business Object Builder. The path to the BOR is Tools | ABAP Workbench | Overview | Business Object Browser.
The BOR defines all the objects within the SAP database. In addition, it defines all the outside interfaces to the SAP system, such as EDI communications with other companies. All BAPIs that facilitate internal storage and retrieval to SAP are found there, and all access to applications that interact with SAP is also controlled by BAPIs found in the BOR.
Building BAPIs with BAPIs
BAPIs are actually created by and maintained with other BAPIs. The BAPI that creates BAPIs is in the BOR, and is called Create. (There’s also a variation, CreateFromData, that is sometimes useful.) Objects that have already been created, and need to be modified, may be manipulated with the BAPI Change, also found in the BOR.
Other BAPI utilities for object manipulation include Delete and UnDelete, Replicate and SaveReplicate, GetStatus, GetDetail, and ExistenceCheck, all of which are self-explanatory. These handy utilities exist alongside the workhorse BAPIs in the BOR. There is also a convenience in SAP called the subobject—objects attached to a greater object, such as line items on a purchase order. The BOR provides you with Add(subobject) and Remove(subobject) to facilitate these.
Typical of an object-oriented system, BAPIs must be treated as objects. Some are instance-dependent (a specific occurrence of an object); some are instance-independent (requiring class methods). When creating a BAPI, you must obviously be clear about which applies. As an example, if you’re working with a class-method BAPI (e.g., the SalesOrder class), GetDetail isn’t useful, because it returns data items from a specific sales order. Instead, you would use GetList, which would return a list of all instantiations of SalesOrder.
BAPI design considerations
You’ll need to have a clear picture of how your BAPI will interface with the corresponding business object in the BOR. This is a question of clearly defining the parameters that will be passed to and from your application by the BAPI. You must also distinguish between required and nonrequired parameters (say, item numbers in purchase orders, as opposed to the vendor’s alternate phone number). If your BAPI will be creating new objects, the keys for those objects must be defined.
An important consideration is that parameters passed to and from SAP by a BAPI aren’t passed in the same way as a normal system-internal function call, that is, by reference; a system-internal parameter can be blank in a data structure because the parameter will get the characteristics of the variable passed to it. But a BAPI is by definition a remote function call, not system-internal, so that information isn’t available. You must therefore define all the parameter characteristics of a BAPI.
Configuring a BAPI as an RFC
Because a BAPI is essentially a remote function call, the SAP system needs to see it that way. You must enable the BAPI as an RFC. You do this in the function module configuration. Click on the Admin tab and go to the Processing Type section. You’ll see the Remote Function Call Supported option. Click on this and your BAPI will be RFC-enabled.
Your BAPI must also be registered as an RFC in the RFC Destination table (RFCDES). Generally, this isn’t your problem; it’s something the system administrator does. You must inform the administrator of your BAPI’s name, clarifying that it’s an RFC, and the name of the system that will be calling it. (Note: You must also advise the system administrator to make such an entry in the RFCDES table even when using a canned BAPI with a new application, so that the relationship between the canned BAPI and the calling system will be defined.)
Linking your BAPI to the Object Repository
Finally, you must link your BAPI to the BOR before you can test your application with its BAPI in place. The new BAPI must not only be in the RFCDES table, but, obviously, it also must be in the BOR.
There’s a wizard for this, so it’s simple to do. Select the path Tools | Business Framework | BAPI Development | Business Object Builder. Choose the business object your BAPI will use. Then choose Utilities | API Methods | Add Method. The format for your BAPI’s name will be BAPI_(object name)_(method).
Next, you’re ready to test. Once you’ve successfully tested, you can enable your BAPI for live usage by “releasing” it. To do this, go to Function Builder. The path is Function Module | Release | Release. Next, go to Business Object Builder. Choose your BAPI, then go to Edit | Change Release Status | Object Type Component | In Released. Your BAPI will then be live.
These are the nuts and bolts of creating BAPIs, without which you can’t create SAP applications. You’ll find it a very smooth and convenient process once you’ve done it a couple of times. Effective interaction with SAP in creating new applications is largely a matter of making appropriate choices in the design of your application before you begin creating BAPIs.
Scott Robinson is a 20-year IT veteran with extensive experience in business intelligence and systems integration. An enterprise architect with a background in social psychology, he frequently consults and lectures on analytics, business intelligence and social informatics, primarily in the health care and HR industries.