ABAP 740 has a new special type of structure – MESH. Lets deep dive to know more about these Meshes.
Introduction
SAP Help defines the mesh as
These are special structures. Their components (referred to as nodes) are either structured internal tables or reference variables that point to structured internal tables.
How to define
To define the mesh, you need to add the keyword MESH when you define the complex structure. With like:
TYPES: BEGIN OF MESH ty_rep_mesh, order_info TYPE tt_orders ASSOCIATION order_to_customer TO customer_info ON customer = customer, customer_info TYPE tt_customers ASSOCIATION customer_to_route TO route_info ON route = route, route_info TYPE tt_routes, END OF MESH ty_rep_mesh.
Included Table Types – Nodes
The included table types must be fully defined structured type. i.e. the Key specification has to be included. If the key is not specified, You can’t include them in the mesh. These table types are known as nodes.
This type TT_CUSTOMERS will give a syntax error “The type does not meet the requirement of the mesh node type” since it not fully defined.
TYPES: BEGIN OF ty_customer, customer TYPE char10, name TYPE char30, city TYPE char30, route TYPE char10, END OF ty_customer. TYPES: tt_customers TYPE STANDARD TABLE OF ty_customer.
Whereas either of these types will meet all the requirements of the mesh node and will work.
TYPES: tt_customers TYPE SORTED TABLE OF ty_customer WITH UNIQUE KEY customer. "or TYPES: tt_customers TYPE STANDARD TABLE OF ty_customer. WITH NON-UNIQUE key customer.
Association between the Nodes
By using the addition ASSOCIATION, you can define the relationship between two nodes. These relationship would be almost same as the foreign key relationship in the DB tables. Here you define the
- ASSOCIATION name: this would be used to identify the node and can be able to access the target node from the source node
- TO node: here you define the node to which this association is referred to
- ON fields: here you define the fields which would be used for the association
Something like this:
BEGIN OF MESH ty_rep_mesh, order_info TYPE tt_orders ASSOCIATION order_to_customer TO customer_info ON customer = customer, customer_info TYPE tt_customers ASSOCIATION customer_to_route TO route_info ON route = route, route_info TYPE tt_routes, END OF MESH ty_rep_mesh.
How to Use Mesh
At a high level these are steps, you need to take to use the Mesh type:
- Declare a variable with type of mesh structure
- Assign the values to the nodes of the mesh
- Use the mesh paths to obtain the results
- Use the component selector – or object selector -> to select the component of the mesh type
Mesh Path
Nodes of the mesh can be accessed by using the association. The associations can also be chained together to obtain the result. The first association need to have the condition to find the node in the mesh. All the rest would follow the path. (You will see it in the next article).
Syntax is like:
mesh-node\association[ condition ]\assocation1[ ]\association2[ ]\..
Like:
Single association
DATA(ls_cust) = t_mesh-order_info\order_to_customer[ t_mesh-order_info[ order = ls_order-order ] ].
Simple Example – Single Association
Check out this simple example where there is only single association.
REPORT ztest_np_mesh. TYPES: BEGIN OF ty_customer, customer TYPE char10, name TYPE char30, city TYPE char30, route type char30, END OF ty_customer. TYPES: tt_customers TYPE SORTED TABLE OF ty_customer WITH UNIQUE KEY customer. TYPES: BEGIN OF ty_orders, order TYPE char10, customer TYPE char10, END OF ty_orders. TYPES: tt_orders TYPE SORTED TABLE OF ty_orders WITH UNIQUE KEY order. TYPES: BEGIN OF MESH ty_rep_mesh, order_info TYPE tt_orders ASSOCIATION order_to_customer TO customer_info ON customer = customer, customer_info TYPE tt_customers, END OF MESH ty_rep_mesh. DATA(t_customres) = VALUE tt_customers( ( customer = 'C0001' name = 'Test Customer 1' city = 'NY' route = 'R0001' ) ( customer = 'C0002' name = 'Customer 2' city = 'LA' route = 'R0003' ) ( customer = 'C0003' name = 'Good Customer 3' city = 'DFW' route = 'R0001' ) ( customer = 'C0004' name = 'Best Customer 4' city = 'CH' route = 'R0003' ) ). DATA(t_orders) = VALUE tt_orders( ( order = '90001' customer = 'C0001' ) ( order = '90002' customer = 'C0002' ) ( order = '90003' customer = 'C0001' ) ( order = '90004' customer = 'C0001' ) ( order = '90005' customer = 'C0004' ) ( order = '90006' customer = 'C0004' ) ( order = '90007' customer = 'C0003' ) ). data t_mesh type ty_rep_mesh. t_mesh-order_info = t_orders. t_mesh-customer_info = t_customres. loop at t_mesh-order_info into data(ls_order). write: / ls_order-order. data(ls_cust) = t_mesh-order_info\order_to_customer[ t_mesh-order_info[ order = ls_order-order ] ]. WRITE: ` `, ls_cust-customer, ls_cust-name. ENDLOOP.
Output
The report generates this output:
Explanation
I have two nodes in the mesh ORDER_INFO and CUSTOMER_INFO. I created one Association between orders to customers. The name is orders_to_customer. The mesh type is used to declare the T_MESH.
The LOOP AT is using the table ORDER_INFO from the mesh structure T_MESH. Within the LOOP, the association is used with mesh path to get the details of the customer. The workarea to hold the result from the mesh path is declared using Inline declaration.
In debug mode, you can see the mesh structure is nothing but a complex structure.
Next
In next part of MESH exploring, we’ll see
- Forward Association
- Inverse Association
Table of Content – ABAP 740 Concepts
- ABAP 740 – NEW Operator to instantiate the objects
- ABAP 740 – NEW Operator to create ITAB entries
- ABAP 740 – VALUE Operator to create ITAB entries
- ABAP 740 – Table Expressions to Read & Modify ITAB line
- ABAP 740 – LINE_EXISTS to check record in ITAB
- ABAP 740 – Meshes – A new complex type of Structures
- ABAP 740 – Mesh Path – Forward and Inverse Association
- ABAP 740 – FOR Iteration Expression
- ABAP 740 SWITCH – Conditional Operator
- ABAP 740 – LOOP AT with GROUP BY
- ABAP 740 – Is CONSTANT not a Static Attribute anymore?
- SALV IDA (Integrated Data Access) – Introduction
- SALV IDA – Selection Conditions
- SALV IDA – New Calculated Fields
- SALV IDA – Column Settings
- SALV IDA – Add and Handle Hotspot (Hyperlink)
Hi Naimesh!
That’s a very interesting command, could we call it a “inner join” equivalent for the internal tables?
Best Regards,
Fawcs
Hello Fawcs,
Exactly, These are kind of inner joins for internal tables and moreoever, which are combined together in a bigger structure, where you can traverse from one join to next 🙂
Thanks.
Really great explanation. Thanks for the articles, because at least to me, help me a lot and makes me want to learn more and more.
Thanks for this article. This looks like quite a nifty addition to ABAP for which we will no doubt find many use-cases as we go along. It is features like these that make ABAP a great language for processing business data.
Hi Naimesh.
First, I’ll like to thank you for blog, i love it!
I’ve just got in my hands a new 740 system, and I’m starting to test its new features.
I’ll just like to add that I think we can simplify the condition when navigating throw mesh paths:
I’ve just tested this code and seems to behave the same way:
Best regards!
Hey Marc,
Thanks for the simplified version of the code to access the data. I would try to include this in the post.
Regards,
Naimesh Patel
Hi
Thanks for the blog.
Can we use a MESH instead of using joins on tables tables? If yes, does it improve performance?
Once again thank you
Hello Tim,
Great question. I think we can use instead of the Joins on the tables but not sure it would improve the performance or not. I would need to try it out.
Regards,
Naimesh Patel