The ATC run came back red on a Thursday afternoon. One finding, one line: my new RAP extension for purchase requisitions was calling BAPI_PR_CREATE, and in a software component set to ABAP for Cloud Development that is simply not allowed. The BAPI is not released. The compiler did not care that the business wanted the feature on Monday.
I had two bad options in front of me. Switch the whole package back to Standard ABAP and lose every clean core guarantee I had built, or rewrite requisition creation from scratch. The third option, the one SAP actually recommends for on-premise and private cloud, is a wrapper. This article is how I build them now, and how I make sure they do not quietly turn into permanent debt.
WHERE THE WRAPPER SITS
The idea is to keep two worlds strictly apart. Extension code lives in a software component with language version ABAP for Cloud Development and may only touch released objects. The wrapper lives in a separate software component with language version Standard ABAP, where calling an unreleased BAPI is still legal. Then I release the wrapper itself with the C1 contract (Use System-Internally), and suddenly the cloud side can see it.
The direction matters. Cloud code calls the wrapper, the wrapper calls SAP, never the other way round. And the wrapper is the only place in the system that knows the old API exists. When SAP releases a successor, one class changes and the extensions above it never notice.
FIRST, PROVE YOU NEED ONE
A wrapper is the fallback, not the first move. Before I create one I check three things:
1. Is it already released? The Released Objects tree in ADT and the API State tab on the object itself answer this in seconds.
2. Is there a released successor? SAP's Cloudification Repository lists released objects and successor information for many classic ones. If a successor exists, I use it, even when it costs more effort today.
3. Is there a released RAP BO or CDS view? For many business objects the modern way in is EML against a released RAP business object interface, not a BAPI at all.
Only when all three come back empty do I write a wrapper, and I write down why. Whoever reviews the clean core status next year will ask, and "it was faster" is not an answer.
THE INTERFACE IS THE CONTRACT
The most common mistake I see is a wrapper that mirrors the BAPI one to one: same header structure, same X-flag tables, same RETURN table. That just moves the mess one layer up. My extension only needs a document type and a few item fields, so that is all the interface exposes:
INTERFACE zif_wrap_purchase_req PUBLIC.
TYPES:
BEGIN OF ty_item,
material TYPE matnr,
plant TYPE werks_d,
quantity TYPE bstmg,
unit TYPE bstme,
deliv_date TYPE eindt,
END OF ty_item,
tt_items TYPE STANDARD TABLE OF ty_item WITH EMPTY KEY.
METHODS create
IMPORTING doc_type TYPE bsart
items TYPE tt_items
test_run TYPE abap_bool DEFAULT abap_false
RETURNING VALUE(result) TYPE banfn
RAISING zcx_wrap_purchase_req.
ENDINTERFACE.
Own types, one method, one exception class. The cloud code will depend on this for years, so I treat it like a public API, because from its point of view, it is one.
WHAT THE WRAPPER ACTUALLY DOES
Inside, the wrapper's job is translation. It fills the header and its X-structure, builds the item and X-flag tables, calls the BAPI, and turns the RETURN table into a real exception.
METHOD zif_wrap_purchase_req~create.
DATA: header TYPE bapimereqheader,
headerx TYPE bapimereqheaderx,
pritem TYPE STANDARD TABLE OF bapimereqitemimp,
pritemx TYPE STANDARD TABLE OF bapimereqitemx,
return TYPE STANDARD TABLE OF bapiret2.
header-pr_type = doc_type.
headerx-pr_type = abap_true.
LOOP AT items INTO DATA(item).
DATA(pos) = CONV bnfpo( sy-tabix * 10 ).
APPEND VALUE #( preq_item = pos material = item-material
plant = item-plant quantity = item-quantity
unit = item-unit deliv_date = item-deliv_date ) TO pritem.
APPEND VALUE #( preq_item = pos preq_itemx = abap_true
material = abap_true plant = abap_true
quantity = abap_true unit = abap_true
deliv_date = abap_true ) TO pritemx.
ENDLOOP.
CALL FUNCTION 'BAPI_PR_CREATE'
EXPORTING prheader = header
prheaderx = headerx
testrun = test_run
IMPORTING number = result
TABLES return = return
pritem = pritem
pritemx = pritemx.
IF line_exists( return[ type = 'E' ] ) OR line_exists( return[ type = 'A' ] ).
RAISE EXCEPTION NEW zcx_wrap_purchase_req( messages = return ).
ENDIF.
" no BAPI_TRANSACTION_COMMIT here, on purpose
ENDMETHOD.
Look at the last comment. There is no BAPI_TRANSACTION_COMMIT in the wrapper, and that is deliberate. When the caller is a RAP business object, the RAP framework owns the transaction. A commit inside the wrapper breaks the RAP LUW and gives you half-saved data on the first error. So the rule I put on the interface documentation is simple: the caller controls the commit, and from a RAP handler the wrapper is called in the save sequence, not during interaction.
A FACTORY, THEN THE RELEASE
The cloud side should never instantiate the implementation directly. The implementation class is CREATE PRIVATE with the factory as its friend, and the factory hands out the interface:
CLASS zcl_wrap_purchase_req_factory DEFINITION PUBLIC FINAL CREATE PRIVATE.
PUBLIC SECTION.
CLASS-METHODS create_instance
RETURNING VALUE(result) TYPE REF TO zif_wrap_purchase_req.
ENDCLASS.
CLASS zcl_wrap_purchase_req_factory IMPLEMENTATION.
METHOD create_instance.
result = NEW zcl_wrap_purchase_req( ).
ENDMETHOD.
ENDCLASS.
This also gives me a clean seam for unit tests: the extension can be tested with a test double, without creating real requisitions in the system.
Then the release. In ADT I open the API State of the interface, the factory and the exception class, and add contract C1 with Use in Cloud Development enabled. The implementation class stays unreleased. Nobody outside needs it, and keeping it private means I can change it freely later.
THE CLOUD SIDE
Back in my ABAP Cloud component, the call looks like any other released API:
TRY.
DATA(pr_number) = zcl_wrap_purchase_req_factory=>create_instance( )->create(
doc_type = 'NB'
items = VALUE #( ( material = 'TG11' plant = '1010'
quantity = 5 unit = 'ST'
deliv_date = cl_abap_context_info=>get_system_date( ) + 14 ) ) ).
CATCH zcx_wrap_purchase_req INTO DATA(error).
" map error->messages to REPORTED in the RAP handler
ENDTRY.
ATC is green, the compiler is happy, and the BAPI is invisible from here.
THE PARTS PEOPLE SKIP
Authorizations. A BAPI may or may not check authority the way your scenario needs. Make it explicit: an AUTHORITY-CHECK inside the wrapper, or a clear note that the caller is responsible.
One wrapper per business purpose. A generic "call any function module" wrapper is not a wrapper, it is a loophole. It hides unreleased usage instead of isolating it, and auditors treat it accordingly.
ATC on the wrapper component too. The wrapper may use unreleased objects, but only the ones it needs. Run the cloud readiness checks there as well, so the list of exceptions stays short and known.
A WRAPPER IS A LOAN
Every wrapper is a known clean core deviation. I treat it as borrowed time with an exit plan, not as finished work.
In practice that is three habits. I keep a register of every wrapper: what it wraps, why no released alternative was used, who owns it, when it was last reviewed. After every upgrade I go through that register against the Cloudification Repository looking for new successors. And when a successor appears, I swap it inside the wrapper first, so the extensions keep running, and retire the wrapper once the extensions can call the released API directly.
MY CHECKLIST BEFORE I RELEASE A WRAPPER
1. I checked released objects, successors and RAP BOs, and wrote down why none fit.
2. The wrapper lives in its own Standard ABAP software component.
3. The interface uses my own types and exposes only what the extension needs.
4. Errors come out as an exception, not a RETURN table.
5. There is no commit inside, and the interface says who owns the LUW.
6. Only the interface, factory and exception are released with C1.
7. The wrapper is in the register with an owner and a review date.
Seven lines, and the red ATC finding from that Thursday turned into a feature that shipped on Monday without giving up the clean core.
Next time I will look at the other side of the same problem: when there is no BAPI to wrap at all, and the only way in is a released RAP business object interface with EML. How are you handling wrappers in your landscape, one central team or each project on its own?