Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Behavior of Reverse Association (Meshes)

SuhaSaha
Advisor
Advisor
0 Kudos

Hello SDNers,

This week i have been exploring the feature "Meshes" and have found a behaviour which i cannot understand.

Below is the sample code i'm using (ABAP 740 SP12):


REPORT ydemo_mesh_inverse_assoc.

CLASS demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS:
      main,
      class_constructor.
  PRIVATE SECTION.
    TYPES:
      BEGIN OF line1,
        col1 TYPE i,
      END OF line1,
      t_itab1 TYPE SORTED TABLE OF line1
                   WITH UNIQUE KEY col1,
      BEGIN OF line2,
        col1 TYPE i,
        col2 TYPE i,
      END OF line2,
      t_itab2 TYPE SORTED TABLE OF line2
                   WITH UNIQUE KEY col1 col2,
      BEGIN OF line3,
        col1 TYPE i,
        col2 TYPE i,
        col3 TYPE i,
      END OF line3,
      t_itab3 TYPE SORTED TABLE OF line3
                   WITH UNIQUE KEY col1 col2 col3,
      BEGIN OF MESH t_mesh,
        node1 TYPE t_itab1
             ASSOCIATION to_node2 TO node2 ON col1 = col1,
        node2 TYPE t_itab2
             ASSOCIATION to_node3 TO node3 ON col1 = col1
                                          AND col2 = col2,
        node3 TYPE t_itab3,
      END OF MESH t_mesh.
    CLASS-DATA
      mesh TYPE t_mesh.
ENDCLASS.

CLASS demo IMPLEMENTATION.
  METHOD main.
    DATA(idx) = 1.
    cl_demo_input=>request( CHANGING field = idx ).

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

    IF line_exists( mesh-node3[ col1 = idx ] ).

      out->next_section( 'node3\^to_node3~node2'
        )->write( VALUE t_itab2(
           FOR <node2> IN
             mesh-node3\^to_node3~node2[ mesh-node3[ col1 = idx ] ]
             ( <node2> ) ) ).

      out->next_section( 'node3\^to_node3~node2\^to_node2~node1'
        )->write( VALUE t_itab1(
           FOR <node1> IN
             mesh-node3\^to_node3~node2[ mesh-node3[ col1 = idx ]
                                       ]\^to_node2~node1[ ]
             ( <node1> ) ) ).
    ELSE.
      out->write( `Enter a valid index for node3 ...` ).
    ENDIF.

    out->display( ).
  ENDMETHOD.
  METHOD class_constructor.
    mesh-node1 = VALUE t_itab1(
      ( col1 = 1 ) ( col1 = 2 ) ( col1 = 3 ) ).
    mesh-node2 = VALUE t_itab2(
      col1 = 1  ( col2 = 11 ) ( col2 = 12 )
      col1 = 2  ( col2 = 21 ) ( col2 = 22 )
      col1 = 3  ( col2 = 31 ) ( col2 = 32 ) ).
    mesh-node3 = VALUE t_itab3(
        col1 = 1  col2 = 11 ( col3 = 111 ) ( col3 = 112 )
        col1 = 1  col2 = 12 ( col3 = 121 ) ( col3 = 122 )
        col1 = 2  col2 = 21 ( col3 = 211 ) ( col3 = 212 )
        col1 = 2  col2 = 22 ( col3 = 221 ) ( col3 = 222 )
        col1 = 3  col2 = 31 ( col3 = 311 ) ( col3 = 312 )
        col1 = 3  col2 = 32 ( col3 = 321 ) ( col3 = 322 ) ).
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  demo=>main( ).

My question is specifically for the reverse association -


FOR <node2> IN

mesh-node3\^to_node3~node2[ mesh-node3[ col1 = idx ] ]

Why does the path result return only 1 row of node2?

I referred to the ABAP Documentation and found this -


If the last path node contains multiple rows that fit the description, the first row found is read.

Refer - ABAP Keyword Documentation. But i am not sure, if this is the correct explanation of this behaviour.

BR,

Suhas

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos

Hello Suhas,

I think this is because of mesh-node3[ col1 = idx ] which by definition ("A mesh path expression is a special type of table expression and can be used in the same way as a table expression"; so I think it's really like a table expression) returns only one line. If idx is 1, then it will match one of the four lines with col1 = 1 (depends on binary search SAP internal algorithm I guess). Consequently, it takes only one line from node2.

Regards,

Sandra

2 REPLIES 2

Sandra_Rossi
Active Contributor
0 Kudos

Hello Suhas,

I think this is because of mesh-node3[ col1 = idx ] which by definition ("A mesh path expression is a special type of table expression and can be used in the same way as a table expression"; so I think it's really like a table expression) returns only one line. If idx is 1, then it will match one of the four lines with col1 = 1 (depends on binary search SAP internal algorithm I guess). Consequently, it takes only one line from node2.

Regards,

Sandra

0 Kudos

Hi Sandra,

Nice to see you back


"A mesh path expression is a special type of table expression and can be used in the same way as a table expression"

Refer: ABAP Keyword Documentation.

This statement explains the behaviour. I wrote a forward association to test this out and it is aligns with what you have mentioned.


out->next_section( 'Forward assoc: node2\to_node3'

)->write( VALUE t_itab3(

   FOR <node3> IN

  mesh-node2\to_node3[ mesh-node2[ col1 = idx ] ]

  ( <node3> ) ) ).

mesh-node2[ col1 = idx ] returns a row of node2, which is then used to analyse the follow-on node3.

Thanks for clarifying.

BR,

Suhas