Home - Cloud ERP Extensibility
ZDMO_GEN_RAP630_SINGLE
as described in the Getting started section that generates the packages and repository objects needed for this hands-on session.
In Exercise 1.1 you will build a custom UI on top of the released API I_BankTP. This application will allow you to create a bank.
As an additional (optional) Exercise 1.2 you can try out to consume this released API in a class via EML.
We will start by showing you how you can search for a released RAP business object. For this we will use the Released Objects part of the Project Explorer in ADT.
Reminder:
Don't forget to replace all occurences of the placeholder###
with your group ID in the exercise steps below.
You can use the ADT function Replace All (Ctrl+F) for the purpose.
When you don't know your group number anymore you can check the transport that has been created when you repository objects have been generated. Here you can check for example the name of the generated package.
In Exercise 1.1 you will build a custom UI on top of the released API I_BankTP.
Click to expand!
-
In the Project Explorer select the Released Objects tree and then the node USE_IN_CLOUD_DEVELOPMENT. Here you have to open the folder Core Data Services and then the folder Behavior Definitions where you find the C1-released Business Object Interface
I_BankTP
. -
Right-click on the interface
I_BankTP
and select Generate ABAP Repository Objects -
Select OData UI Service and then Next
-
Select the package
ZRAP630_###_EXT
where###
is the unique ID chosen by the generator class by pressing the Browse button and press Next. -
The generator finishes with the Configure Generator screen.
When you want to change the names of the repository objects that will be generated you can do so by selecting the entries Service Projection Entities, Service Projection Behavior, Service Definition and Service Binding. Since the generator will suggest unique names we will leave those default values unchanged.
Press Next to continue.
-
The wizard shows an overview of the repository objects that are going to be generated. Press Next.
-
Select the transport that has been created for the package
ZRAP630_###_EXT
or create a new transport and press Finish to start the generation of the repository objects.
-
When the generation process is finished a new tab with the generated Service Binding will be opened in ADT. Click Publish to publish the service binding locally. In the project explorer you can see all objects that have been generated.
-
Select the entity set
Bank
and click Preview or double-click on the entity setBank
. This will start the SAP Fiori Elements preview. -
In the preview of your app press the button Create to create a new bank.
-
Enter values in the fields Bank Country / Region e.g.
CZ
and Bank Key e.g.1234
and press Continue. -
The object page opens and you have to provide data for the remaining mandatory fields such as the Bank Name.
Click to expand!
-
When your development user does not have the authorization to create new banks you will receive the following error message: You are not authorized to create bank data for country/region CZ.
-
In order to identify the missing authorizations you can check the Knowledge Transfer Document of
I_BANKTP
. Either open it using the shortcut Ctrl+Shift+A or navigate to it in the Project Explorer as shown as shown below. -
As you can see the business object
I_BankTP
checks for the authorization objectsF_BNKA_MAO
andF_BNKA_INT
.
⚠️
The issue can only be resolved by creating an appropriate IAM app, assigning the same to a business catalog which in the end has to be assigned to a new or existing role that has to be assigned to your user.
In the next (optional) exercise where the BO is called as an API we show a workaround how the API can be called in a so called priveliged mode.
A second typical use case where released API's in an SAP S/4HANA system are used for, is using such an API in your own code that might for example be consumed as part of an application job.
This is an optional exercise.
Create a class
in the extension package
ZRAP630_###_EXT
to test the effects of using the language version ABAP for Cloud Development.
Click to expand!
-
Right-click on your ABAP package
ZRAP630_###_EXT
and select New > ABAP Class from the context menu. -
Maintain the required information (
###
is your group ID).- Name:
zcl_test_abap_cloud_###
- Description:
Test ABAP Cloud Governance
Click on Add and select the interface
if_oo_adt_classrun
and press OK.and click Next >
- Name:
-
Select or create a transport request, and click Finish to create the class.
-
Replace the code in the method
if_oo_adt_classrun~main( )
with the following code snippet.Tip You have to replace the value for '####' with a string that only contains numbers.
Coding explained:
The coding leverages theresponse
parameter of EML statements that is used to specify response parameters for ABAP EML statements to get information on the following:- Failures, i. e. operations that could not get processed (FAILED failed_resp)
- Key mapping information (MAPPED mapped_resp)
- Returned error messages (REPORTED reported_resp)
METHOD if_oo_adt_classrun~main. DATA create_bank TYPE STRUCTURE FOR CREATE i_banktp. DATA bank_id_number TYPE i_banktp-BankInternalID VALUE '8###'. create_bank = VALUE #( bankcountry = 'CZ' bankinternalid = bank_id_number longbankname = 'Bank name' longbankbranch = 'Bank branch' banknumber = bank_id_number bankcategory = '' banknetworkgrouping = '' swiftcode = 'SABMGB2LACP' ismarkedfordeletion = '' ). MODIFY ENTITIES OF i_banktp ENTITY bank CREATE FIELDS ( bankcountry bankinternalid longbankname longbankbranch banknumber bankcategory banknetworkgrouping swiftcode IsMarkedForDeletion ) WITH VALUE #( ( %cid = 'cid1' bankcountry = create_bank-bankcountry bankinternalid = create_bank-bankinternalid longbankname = create_bank-longbankname longbankbranch = create_bank-longbankbranch banknumber = create_bank-banknumber bankcategory = create_bank-bankcategory banknetworkgrouping = create_bank-banknetworkgrouping SWIFTCode = create_bank-SWIFTCode IsMarkedForDeletion = create_bank-IsMarkedForDeletion ) ) MAPPED DATA(mapped) REPORTED DATA(reported) FAILED DATA(failed). LOOP AT reported-bank INTO DATA(reported_error_1). DATA(exc_create_bank) = cl_message_helper=>get_longtext_for_message( EXPORTING text = reported_error_1-%msg ). out->write( |error { exc_create_bank } | ). ENDLOOP. COMMIT ENTITIES RESPONSE OF i_banktp FAILED DATA(failed_commit) REPORTED DATA(reported_commit). LOOP AT reported_commit-bank INTO DATA(reported_error_2). DATA(exc_create_bank2) = cl_message_helper=>get_longtext_for_message( EXPORTING text = reported_error_2-%msg ). out->write( |error { exc_create_bank2 } | ). ENDLOOP. IF reported_commit-bank IS INITIAL. COMMIT WORK. SELECT SINGLE * FROM I_Bank_2 WHERE BankInternalID = @bank_id_number INTO @DATA(my_bank). out->write( |my new bank { my_bank-BankName } { my_bank-BankInternalID }| ). ENDIF. ENDMETHOD.
-
Activate your changes by pressing Ctrl+F3
-
Run the test class by pressing F9.
You will notice that an error message is thrown. Namely
error You are not authorized to create bank data for country/region CZ.
Consequently also no new data is found. -
Adding PRIVILEGED to the EML call
When we add the key word
PRIVILEGED
to our EML call the authorization checks for the authorization objectsF_BNKA_MAO
andF_BNKA_INT
will basically be skipped.MODIFY ENTITIES OF i_banktp PRIVILEGED ENTITY bank CREATE FIELDS ( bankcountry bankinternalid longbankname ...
When you now run the class again using F9 you will find that the creation of a new bank seem to have worked.
However the select statement is not able to retrieve the newly created data.
Click to learn more about the PRIVILEGED EML access
We will now check the behavior definition of the Bank RAP business object. To do so use Ctrl+Shift+A to open the behavior definition
R_BankTP
.In the source code (see below) we see that the BDEF
R_BankTP
defines two so called authorization contexts:Own authorization context : Lists all authorization objects used by the RAP BO implementation.
NoCheckWhenPrivileged : Lists authorization objects that can be skipped by a RAP BO consumer with privileged access.managed with unmanaged save implementation in class bp_r_banktp unique; strict ( 2 ); with draft; extensible { with additional save; with determinations on modify; with determinations on save; with validations on save; } with privileged mode disabling NoCheckWhenPrivileged; //NoCheckWhenPrivileged define authorization context NoCheckWhenPrivileged { 'F_BNKA_MAO'; 'F_BNKA_INT'; }
-
Adding WITH PRIVILEGED ACCESS to the ABAP SQL statement
Similar to enforce skipping the authorization checks when creating a new bank it is also possible to enforce skipping of the authorization check that is imposed by the underlying DCL which performs a check on the authorization object
F_BNKA_MAO
and the fieldBBANKS
for displaying data.Open the DCL and check its source code.
To do so press Ctrl+Shift+A and enter I_Bank_2 to search for the DCL objects.
When we now change the ABAP SQL statement in class
zcl_test_abap_cloud_###
such that we add the key wordsWITH PRIVILEGED ACCESS
to it:METHOD if_oo_adt_classrun~main. .... SELECT SINGLE * FROM I_Bank_2 WITH PRIVILEGED ACCESS WHERE BankInternalID = @bank_id_number INTO @DATA(my_bank). .... ENDMETHOD.
we see that the data is now successfully been created and can also be read.
-
Other potential problems
The I_BankTP RAP BO checks whether the provided switft code fits to the ISO code of the region.
- error ISO code GB in the SWIFT code SABMGB2LACP is not correct for country/region US. Diagnosis Positions 5 and 6 of the SWIFT code do not correspond to the ISO code of country/region US. Procedure Check your entries. If necessary, check whether the ISO code of country/region US has been defined correctly.
When a bank with the ID that is provided already exists you will receive an error message as well.
- error Bank CZ 8888 already exists.
Now that you've have learned about how to leverage the released API I_BankTP in ABAP Cloud you can continue with the next exercise where you will learn how to extend an extensible RAP business object- Exercise 2.
Click to expand!
While developing an ABAP Application for S/4HANA on premise or S/4HANA private cloud edition , you do get the following error message: "Use of is not permitted".
But the error message does not provide a hint which API or object to use instead. The reason is that the successor information in on premise system does not contain the latest updates such as in SAP S/4HANA Cloud, ABAP Environment system or SAP BTP, ABAP Environment.
An example would be the table BNK2
.
You as a developer nevertheless want to find out which objects to use intstead and to check their documentation.
-
Check out the GitHub repository.
The repository contains the list of released APIs of S/4HANA Cloud. In addition also the objects that are not released are contained with the specification of successor objects. All objects are contained in one JSON file. This file is used as content for the ABAP Test Cockpit Check "Usage of Released APIs (Cloudification Repository)". This check can be used by customers and partners to analyse existing custom code concerning the usage of released and not released APIs on all ECC and S/4HANA releases. The check is available in SAP BTP, ABAP environment.
S/4 HANA Cloud - Released objects for ATC Check (Cloudification Repository).
When we check the csv file that is public available we can retrieve a list of successors for the table BNKA.
While csv files are nice for human beings, computers prefer json files.
You can continue with the next exercise - Exercise 2.1.