The wrapper you just created is currently not released for consumption in tier 1. You can test this by creating a console application in tier 1 to call the (unreleased) wrapper. We suggest to create a dedicated package under the tier 1 ZLOCAL package in your SAP S/4HANA System for this test.
In ADT, open your SAP S/4HANA system project folder, navigate to the ZLOCAL structure package, right click on it and select New > ABAP Package and input the Name Z_PURCHASE_REQ_TEST_### and a Description:
Click on Next and then Next again. Select a suitable transport request (or create a new one if needed) and then click on Finish. Now you can create the class for the console application. Right click on the newly created package and select New > ABAP Class and input the Name ZCL_BAPI_WRAP_TEST_### and a Description:
Click on Next, select a suitable transport request (or create a new one if needed) and then click on Finish.
You can check that the newly created class is a tier 1 class by checking that the ABAP Language Version is ABAP Language for Cloud Development in the Properties > General tab:
Implement the newly created class as follows:
CLASS zcl_bapi_wrap_test_### DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun .
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_bapi_wrap_test_### IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA pr_returns TYPE bapirettab.
DATA number TYPE banfn .
"if the data element banfn is not released for the use in cloud develoment in your system
"you have to use the shadow type zif_wrap_bapi_pr_create_###=>banfn
"DATA number TYPE zif_wrap_bapi_pr_create_###=>banfn .
DATA prheader TYPE zif_wrap_bapi_pr_create_###=>bapimereqheader .
DATA prheaderx TYPE zif_wrap_bapi_pr_create_###=>bapimereqheaderx .
DATA pritem TYPE zif_wrap_bapi_pr_create_###=>_bapimereqitemimp .
DATA pritemx TYPE zif_wrap_bapi_pr_create_###=>_bapimereqitemx .
DATA prheaderexp TYPE zif_wrap_bapi_pr_create_###=>bapimereqheader .
DATA(myclass) = zcl_bapi_wrap_factory_###=>create_instance( ).
prheader = VALUE #( pr_type = 'NB' ).
prheaderx = VALUE #( pr_type = 'X' ).
pritem = VALUE #( (
preq_item = '00010'
plant = '1010'
acctasscat = 'U'
currency = 'EUR'
deliv_date = cl_abap_context_info=>get_system_date( ) + 14 "format: yyyy-mm-dd (at least 10 days)
material = 'ZPRINTER01'
matl_group = 'A001'
preq_price = '100.00'
quantity = '1'
unit = 'ST'
pur_group = '001'
purch_org = '1010'
short_text = 'ZPRINTER01'
) ).
pritemx = VALUE #( (
preq_item = '00010'
plant = 'X'
acctasscat = 'X'
currency = 'X'
deliv_date = 'X'
material = 'X'
matl_group = 'X'
preq_price = 'X'
quantity = 'X'
unit = 'X'
pur_group = 'X'
purch_org = 'X'
short_text = 'X'
) ).
TRY.
myclass->bapi_pr_create(
EXPORTING
prheader = prheader
prheaderx = prheaderx
testrun = abap_false
IMPORTING
number = number
prheaderexp = prheaderexp
CHANGING
pritem = pritem
pritemx = pritemx
return = pr_returns
)
.
CATCH cx_aco_application_exception cx_aco_communication_failure cx_aco_system_failure INTO DATA(call_wrapper_exception).
"handle exception
out->write( |Exception occured: { call_wrapper_exception->get_text( ) }| ).
ENDTRY.
out->write( |purchase requistion number: { number } | ).
LOOP AT pr_returns INTO DATA(bapiret2_line).
out->write( |bapi_return: { bapiret2_line-message } | ).
ENDLOOP.
ENDMETHOD.
ENDCLASS.
Save it.
The class calls the wrapper factory class and, given some input parameter values like the delivery date and the item price, creates a purchase requisition for that specific item and prints the information to the console. Since the wrapper is not released for consumption in tier 1, when you try to activate the class you will get an error message.
The class calls the method create_instance of the BAPI, which will create an instance of the Shopping Cart Business Object and the relative purchase requisition. In the context of this tutorial group, this is of course done for educational purposes, to show the creation of a purchase requisition and test the wrapper via console application. If for any reason you do not wish to create an instance of the Shopping Cart Business Object at this point, you can instead make use of the BAPI method check.