Get Example source ABAP code based on a different SAP table
Using TYPE TABLE>/TYPE STRUCTURE FOR HIERARCHY> This example demonstrates actions> whose deep> input parameters> and deep> output parameters> use the BDEF derived types> TYPE TABLE FOR HIERARCHY>> and TYPE STRUCTURE FOR HIERARCHY>> with a managed> RAP BO >. Data model> The CDS data model consists of the root entity> DEMO_MANAGED_HIERARCHY >: DDLS DEMO_MANAGED_HIERARCHY Furthermore, the example uses the following abstract entities:
DEMO_ABSTRACT_ROOT >> (root abstract entity)
DEMO_HIER_ABS_ITEM1>>
DEMO_HIER_ABS_ITEM2>>
DEMO_HIER_ABS_SCALAR>> ( ABAP Alternative 2@2@>scalar type >)
DEMO_ABSTRACT_ROOT_2>> (root abstract entity) Behavior definition> The RAP behavior definition> DEMO_MANAGED_HIERARCHY>> is defined in RAP BDL> as follows: BDEF DEMO_MANAGED_HIERARCHY ABAP_NOTE Using the notation numbering : managed> for the key field, the value of the key field gets automatically created for each RAP BO instance. Further BDEFs for root abstract entities that are relevant for the example:
DEMO_ABSTRACT_ROOT>>
DEMO_ABSTRACT_ROOT_2>> Behavior implementation> For the above RAP behavior definition, one ABAP behavior pool (ABP)> is created. The global class of the behavior pool is BP_DEMO_MANAGED_HIERARCHY>>. The actual behavior implementation takes place in local classes that are defined and implemented in the BP_DEMO_MANAGED_HIERARCHY=====CCIMP>> of the behavior pool. The following methods are relevant for the example:
action_flat_param> The method loops at the flat input parameter. In the loop, the components of a structure are filled with values from the input parameter. These values are also changed within the loop. This change includes adding characters to the character fields and a calculation for the numeric fields. The output parameter result> returns the changed instances. Furthermore, the instances are added to an internal table that is typed with the BDEF derived type TYPE TABLE FOR CREATE>>. This internal table with RAP BO instances is used as input for a RAP create operation>.
action_deep_param> The method loops at the deep input parameter which includes a structure of type TYPE STRUCTURE FOR HIERARCHY>. In the loop, the components of a structure are filled with selected values from the abstract entities. Similar to the previous method, these values are changed. The structure is added to the output parameter result> and to an internal table on whose bases a RAP create operation is carried out.
action_deep_table_param> The method loops at the deep input parameter which includes a table of type TYPE TABLE FOR HIERARCHY>. In the loop, the components of a structure are filled with selected values from the abstract entities. Similar to the previous methods, these values are changed. The structure is added to the output parameter result> and to an internal table on whose bases a RAP create operation is carried out.
returnhdata> The method returns hierarchy data. The focus of this method is the use of variables that are typed with either TYPE TABLE FOR HIERARCHY> or TYPE STRUCTURE FOR HIERARCHY>. It visualizes how the BDEF derived type component %param >>, which is contained in the output parameter result>, might be set up, i. e. the component itself can contain subcomponents of type TYPE TABLE FOR HIERARCHY> and TYPE STRUCTURE FOR HIERARCHY>. The variables, i. e. the structures and internal tables, are filled with demo data. This data is added to the output parameter result>.
storehdata> The method loops at the deep input parameter which includes a structure of type TYPE STRUCTURE FOR HIERARCHY>. In the loop, an internal table, which is typed with TYPE TABLE FOR CREATE>, is filled with selected values from the abstract entities. A RAP create operation is carried out creating those instances that have been added to the internal table. Furthermore, the instances are added to the output parameter result>.
ABAP_DESCRIPTION Access with ABAP using EML> The class includes multiple ABAP_EML MODIFY>> requests executing actions. Before the actions are carried out, the input parameters for those actions is prepared. In this case, multiple internal tables and structures that are typed with the BDEF derived types TYPE TABLE FOR HIERARCHY > or TYPE STRUCTURE FOR HIERARCHY> respectively are created. The structures and internal tables are filled with demo values to provide input parameters for the actions that have deep parameters. In case of the action action_deep_param>, the input parameter is a structure. In case of the action action_deep_table_param>, the input parameter is an internal table. The value assignment just visualizes the hierarchy data and possible components of the BDEF derived types, i. e. multiple types with FOR HIERARCHY> can occur in those BDEF derived types. The following ABAP_EML MODIFY> requests executing actions are covered in the example: Executing action action_flat_param> A content ID %cid>> and a flat parameter %param> are provided as input parameter. A COMMIT ENTITIES>> statement saves the RAP BO instances to the database. The result of the action is output based on the method implementation mentioned above. The database table entries are retrieved using a SELECT >> statement and displayed as well. Executing action action_deep_param> A content ID %cid>> and a deep parameter %param> are provided as input parameter. Here, %param> is a structure. A COMMIT ENTITIES>> statement saves the RAP BO instances to the database. The result of the action is output based on the method implementation mentioned above. The database table entries are retrieved using a SELECT >> statement and output as well. Executing action action_deep_table_param> A content ID %cid>> and a deep parameter %param> are provided as input parameter. Here, %param> is an internal table. A COMMIT ENTITIES>> statement saves the RAP BO instances to the database. The result of the action is output based on the method implementation mentioned above. The database table entries are displayed, too. Executing actions returnhdata> and storehdata> A content ID %cid>> is provided as input parameter for the returnhdata> method. The method returns data based on the method implementation mentioned above. This data is used as input parameter for the storehdata> method which includes a RAP create operations that create RAP BO instances. A COMMIT ENTITIES>> statement saves the RAP BO instances to the database. The result of both actions is displayed as well as the database table entries.