SAP NetWeaver AS ABAP Release 750, ©Copyright 2016 SAP AG. All rights reserved.
ABAP - Keyword Documentation → ABAP - Reference → Processing External Data → ABAP Database Accesses → Native SQL → AMDP - ABAP Managed Database Procedures → AMDP - Examples →AMDP, Filling a Mesh with SQLScript
This example demonstrates how a mesh is filled with a database procedure.
Source Code
REPORT demo_amdp_mesh.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
PRIVATE SECTION.
TYPES:
BEGIN OF output_line,
position TYPE string,
product TYPE string,
END OF output_line,
output TYPE STANDARD TABLE OF output_line WITH EMPTY KEY.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
DATA order_ids TYPE RANGE OF snwd_so-so_id.
DATA(rows) = 1.
cl_demo_input=>request( EXPORTING text = `Orders`
CHANGING field = rows ).
SELECT 'I' AS sign, 'EQ' AS option, so_id AS low
FROM snwd_so
ORDER BY low
INTO CORRESPONDING FIELDS OF TABLE @order_ids
UP TO @rows ROWS. "#EC CI_NOWHERE
DATA(out) = cl_demo_output=>new( ).
TRY.
DATA(order) = NEW cl_demo_amdp_mesh( )->select( order_ids ).
CATCH cx_amdp_error INTO DATA(amdp_error).
out->display( amdp_error->get_text( ) ).
RETURN.
ENDTRY.
LOOP AT order-orders ASSIGNING FIELD-SYMBOL(<order>).
out->begin_section( |Order #{ <order>-so_id }| ).
ASSIGN order-orders\_buyers[ <order> ]
TO FIELD-SYMBOL(<buyer>).
out->begin_section(
|Buyer: { <buyer>-company_name } | &&
|in { order-bupas\_addresses[ <buyer> ]-city } | ).
out->write(
name = 'Sales Order Items'
data = VALUE output(
FOR <item> IN order-orders\_items[ <order> ]
( position = <item>-so_item_pos
product = order-items\_products[ <item> ]-product_id
) ) ).
out->end_section( )->end_section( ).
ENDLOOP.
out->display( ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
Description
The AMDP class CL_DEMO_AMDP_MESH has a private AMDP method SELECT_HDB called by the public method SELECT if the current central database is the SAP HANA database. For all other databases, the private method SELECT_OPEN_SQL is called. Both methods return the same results, verified by a unit test in the class.
The methods fill the nodes of a mesh for sales orders whose type is declared in the AMDP class. The number of sales orders is restricted using a ranges table. In the method SELECT_OPEN_SQL, the Open SQL addition FOR ALL ENTRIES is used, but in SELECT_OPEN_SQL the intermediate results can be evaluated in subqueries.
SQLScript implementation of the AMDP method
ABAP implementation of the regular method
Note
This is a syntax example. The same function can be provided with the same efficiency in Open SQL. AMDP is not needed in simple cases like this.