Description: Meshes are special structures composed of internal tables that can be connected through associations. These associations are accessed using mesh paths within specific expressions and statements.
- A Mesh separates the definition of relationships from their usage. For example, if an item record includes a “parent_key” field that references its corresponding header record, this relationship is defined only once within the Mesh.
- Without a Mesh, the same logic must be repeated in every LOOP that processes items by header, and in every READ statement that retrieves a header from an item. If the data model changes, ideally only the Mesh definition needs to be updated—eliminating the need to modify all affected LOOPs and READ statements.
- Mesh is defined like a structure.
Syntax:
TYPES BEGIN OF MESH
...
TYPES snode ... ASSOCIATION _assoc
TO tnode ON tcomp1 = scomp1 [AND ...].
...
TYPES END OF MESH
Example:
*&---------------------------------------------------------------------*
*& Report ZMESHRPT
*&---------------------------------------------------------------------*
*& Purpose: Learn how to use Meshes
*& Author : Sangeeta Singh
*&---------------------------------------------------------------------*
REPORT zmeshrpt.
"Declare Meshes type
TYPES: BEGIN OF ty_vbak,
vbeln TYPE vbeln,
erdat TYPE erdat,
auart TYPE auart,
END OF ty_vbak,
BEGIN OF ty_vbap,
vbeln TYPE vbeln,
posnr TYPE posnr,
matnr TYPE matnr,
arktx TYPE arktx,
END OF ty_vbap,
tt_vbak TYPE STANDARD TABLE OF ty_vbak WITH KEY vbeln,
tt_vbap TYPE STANDARD TABLE OF ty_vbap WITH KEY vbeln posnr,
BEGIN OF MESH ty_po,
vbak TYPE tt_vbak ASSOCIATION _to_item TO vbap
ON vbeln = vbeln ,
vbap TYPE tt_vbap,
END OF MESH ty_po.
DATA: ls_po TYPE ty_po.
"Fill data in the created mesh
SELECT vbeln erdat auart
FROM vbak INTO TABLE ls_po-vbak UP TO 20 ROWS.
IF sy-subrc = 0.
SELECT vbeln posnr matnr arktx
FROM vbap
INTO TABLE ls_po-vbap
FOR ALL ENTRIES IN ls_po-vbak
WHERE vbeln = ls_po-vbak-vbeln.
IF sy-subrc <> 0.
MESSAGE 'No Data Found' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
ENDIF.
"Loop on meshes
LOOP AT ls_po-vbak ASSIGNING FIELD-SYMBOL(<lfs_vbak>).
DATA(ls_item) = ls_po-vbak\_to_item[ ls_po-vbak[ vbeln = <lfs_vbak>-vbeln ] ].
"As you can see we don't need additonal loop here
" we can fetch data based on association
WRITE: / ls_item-vbeln, ls_item-posnr, ls_item-matnr,ls_item-arktx.
ENDLOOP.
Output:
As you can see Meshes is a deep structure which is holding VBAK and VBAP data.


Conclusion:
Meshes in ABAP on HANA simplify relationship handling between internal tables. They reduce code duplication, improve clarity, and make maintenance easier by centralizing relationship logic through associations and mesh paths.
Thanks for Visiting!

Leave a Reply