Ansicht
Dokumentation

ABENEML_CALCULATOR_ABEXA - EML CALCULATOR ABEXA

ABENEML_CALCULATOR_ABEXA - EML CALCULATOR ABEXA

Fill RESBD Structure from EBP Component Structure   PERFORM Short Reference  
This documentation is copyright by SAP AG.
SAP E-Book

- RAP Calculator (Unmanaged)

This example demonstrates a calculator that is implemented in a RAP context using a simple unmanaged RAP BO. Here, a create operation with an MODIFY ENTITY statement takes up user input - numbers and an operand - on whose basis a calculation is done.

Data model

The CDS data model only consists of the root entity DEMO_UNMANAGED_CALC.



Behavior definition

The CDS behavior definition DEMO_UNMANAGED_CALC is defined in CDS BDL as follows:

Behavior implementation

For the above CDS behavior definition, one ABP is created. The global class of the behavior pool is BP_DEMO_UNMANAGED_CALC. The actual behavior implementation takes place in local classes that are defined and implemented in the BP_DEMO_UNMANAGED_CALC========CCIMP of the behavior pool.

The class lcl_var contains the specification of the transactional buffer. The transactional buffer in this example is an internal table buffer_tab that is typed with a BDEF derived type. Furthermore, the structure request is defined for the GET PERMISSIONS statement that is used in the create method.

The following methods are relevant for this example:

  • create
As an initial step, the transactional buffer (i. e. the internal table buffer_tab) is filled with the entries provided via the input screen. A GET PERMISSIONS statement follows as a next step that retrieves information whether the calculation is allowed or not. As a prerequisite, %field elements are marked in the request structure to specify that the particular elements should be considered for the permission retrieval. During the execution of the GET PERMISSIONS statement, the get_instance_features method is called. After this method call, the calculation is executed or not depending on the result of the GET PERMISSIONS statement. If the calculation is allowed, the field calc_result receives the result of the calculation according to the numbers and operand provided. Possible short dumps are caught. If the calculation is not allowed and error messages exist (the error messages are created in the course of the get_instance_features method call), the reported parameter receives those messages.
  • read
The read method reads the entries that are input. It is used in the get_instance_features method.
  • get_instance_features
First, the entries that are input are read. As a next step, the permissions for the calculation are retrieved and stored in result. The calculation is allowed if none of the following conditions are met: the value provided in the number1 field must be filled and contain only numbers, the same is true for the value provided in the number2; additionally, the number2 field must not contain 0 if the operand is / (division by zero); the operand must only be +, -, *, / or P. After filling result, error messages are added to the reported if there are errors.
  • save
The save method saves the entries in the transactional buffer to the database table.

Source Code

Execute

Description

Access with ABAP using EML

The above source code uses EML to access the RAP business object from an ABAP program.

The whole scenario is implemented in a way that the database table only contains one line comprised of the user input (numbers and operand), the equal sign and the calculation result. The focus is on implementing RAP methods and their interaction in a simplified unmanaged RAP context.

The program uses the class CL_DEMO_INPUT for user input. This user input is taken up to create an instance with a MODIFY ENTITY statement.

The CREATE keyword as part of the MODIFY ENTITY statement triggers calling the create method in the behavior pool. As outlined in section Behavior implementation, the create method is responsible for the calculation if the calculation is allowed (see the get_instance_features method that is triggered by the GET PERMISSIONS statement contained in the create method). If the calculation is not allowed, for example, if characters are provided as input or a division by zero is carried out, error messages are inserted in the reported parameter. If there are error messages and the calculation fails, the error messages are displayed in the output screen.

The COMMIT ENTITIES statement triggers the saving of the entries to the database table. If the calculation can be executed successfully, the result of the calculation is displayed including the user input and the equal sign in the output screen.






CPI1466 during Backup   Addresses (Business Address Services)  
This documentation is copyright by SAP AG.

Length: 6122 Date: 20240419 Time: 121549     sap01-206 ( 105 ms )