Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Meshes →  Meshes - Using Mesh Paths →  SET ASSOCIATION mesh_path 

Setting Mesh Associations for Mesh Paths

This example demonstrates how mesh associations are set for mesh paths.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA(out) = cl_demo_output=>new(
      )->begin_section( 'node1'
      )->write( mesh-node1
      )->next_section( 'node2'
      )->write( mesh-node2
      )->next_section( 'node3'
      )->write( mesh-node3 ).

    out->next_section( 'Initial Association' ).
    out->begin_section( 'Insert initial line into node1\_node2' ).
    INSERT INITIAL LINE INTO TABLE
      mesh-node1\_node2[ VALUE line1( col1 = 11 col2 = 12 ) ]
      ASSIGNING FIELD-SYMBOL(<line2>).
    out->write( mesh-node2 ).

    out->next_section( 'Set association node2\_node3' ).
    SET ASSOCIATION mesh-node2\_node3[ <line2> ] = mesh-node3[ 1 ].
    out->write( mesh-node2 ).

    out->next_section( 'Get association node2\_node3' ).
    DATA(line3) = mesh-node2\_node3[ <line2> ].
    out->write( line3 )->end_section( ).

    out->next_section( 'Chained Association' ).
    out->begin_section( 'Set association node1\_node2\_node3' ).
    DATA(root) = VALUE line1( col1 = 21 col2 = 22 ).
    SET ASSOCIATION
      mesh-node1\_node2[ root ]\_node3[ ] = mesh-node3[ 2 ].
    out->write( mesh-node2 ).

    out->next_section( 'Get association node1\node2\_node3' ).
    DATA(node3) = VALUE t_itab3( FOR wa IN
      mesh-node1\_node2[ root ]\_node3[ ] ( wa ) ).
    out->write( node3 ).

    out->display( ).

Description

This example shows how, in a mesh node mesh-node2 (which is the target node of the mesh association _node2 of a mesh node mesh-node1 and the initial node of a mesh association _node3 with the mesh node mesh-node3), values can be set that match the existing values in mesh-node3. The statement SET ASSOCIATION is used in two variants here:

  • In the first case, a mesh path with just one initial mesh association is used:
SET ASSOCIATION mesh-node2\_node3[ <line2> ] = mesh-node3[ 1 ]
The statement SET ASSOCIATION sets the column col3 in the structure specified in the square brackets. Here, a field symbol is used that points to a row inserted previously in mesh-node2. The values to be set are taken from the follow-on node mesh-node3 using a table expression. The subsequent read performed on the same mesh path demonstrates that this path now describes the required data in mesh-node3.
  • In the second case, a mesh path with a path extension is used:
SET ASSOCIATION mesh-node1\_node2[ root ]\_node3[ ] = mesh-node3[ 2 ].
The result of the mesh path up to the node mesh-node2 describes two existing rows. In these rows, the column col3 is again set to values from the follow-on node mesh-node3. Again, the subsequent read performed on the same mesh path demonstrates that this path describes the appropriate data in mesh-node3, with the duplicate row only being respected once.