Skip to Content

ABAP Mesh in 740: Connect your internal table as BO node association

ABAP Mesh is also a new feature in 740. Let’s use an example to demonstrate how it works:

I have defined two types for developers and managers. developer type has a field manager which points to his manager, while manager type does not have any reference to his managing employee.

types: begin of t_manager,
         name     type char10,
         salary   type int4,
       end of t_manager,
       tt_manager type sorted table of t_manager with unique key name.
types: begin of t_developer,
         name     type char10,
         salary   type int4,
         manager TYPE char10,
       end of t_developer,
       tt_developer type sorted table of t_developer with unique key name.​

I also use the new grammar – inline data declaration to fill developer and manager table. So far nothing special.

DATA: lt_developer TYPE tt_developer,
         lt_manager TYPE tt_manager.

   DATA(Jerry) = VALUE t_developer( name = 'Jerry' salary = 1000 manager = 'Jason' ).

   DATA(Tom) = VALUE t_developer( name = 'Tom' salary = 2000 manager = 'Jason' ).

   DATA(Bob) = VALUE t_developer( name = 'Bob' salary = 2100 manager = 'Jason' ).

   DATA(Jack) = VALUE t_developer( name = 'Jack' salary = 1000 manager = 'Thomas' ).

   DATA(David) = VALUE t_developer( name = 'David' salary = 2000 manager = 'Thomas' ).

   DATA(John) = VALUE t_developer( name = 'John' salary = 2100 manager = 'Thomas' ).

   DATA(Jason) = VALUE t_manager( name = 'Jason' salary = 3000 ).

   DATA(Thomas) = VALUE t_manager( name = 'Thomas' salary = 3200 ).

   INSERT Jerry INTO TABLE lt_developer.

   INSERT Tom INTO TABLE lt_developer.

   INSERT Bob INTO TABLE lt_developer.

   INSERT Jack INTO TABLE lt_developer.

   INSERT David INTO TABLE lt_developer.

   INSERT John INTO TABLE lt_developer.

   INSERT Jason INTO TABLE lt_manager.

   INSERT Thomas INTO TABLE lt_manager.

Now I define one ABAP mesh t_team with two component managers and developers. With association ‘my_employee’, I connect the internal table managers to developers, so that I could easily find all developers of a given manager. The association ‘my_manager’ just enables the connection in opposite direction: find out the manager of a given developer.

/wp-content/uploads/2013/12/clipboard1_338017.png

 

You can compare how I find Jerry’s manager and find all developers whose manager are Thomas using new ABAP mesh and the traditional way.

/wp-content/uploads/2013/12/clipboard2_338075.png

The result are exactly the same.

/wp-content/uploads/2013/12/clipboard3_338078.png

6 Comments
You must be Logged on to comment or reply to a post.
  • Why did you decide to throw an exception when you try to read invalid entries? I would expect an empty row instead of raising cx_sy_itab_line_not_found. Also why does the LOOP AT command implicitly catch this exception? This does not feel completely coherent.

    Consider this example with your sample data:

    WRITE / |Test not found |.

    LOOP AT ls_crm_teamdevelopers\my_manager[ VALUE #( manager = ‘Foo’ ) ] ASSIGNING FIELDSYMBOL(<line3>).
       WRITE / |Line found loop { <line3>name }|.
    ENDLOOP.

    TRY.
         DATA(line_not_exist) = ls_crm_teamdevelopers\my_manager[ VALUE #( manager = ‘Foo’ ) ].
         WRITE / |Line found direct { line_not_existname }|.
       CATCH cx_sy_itab_line_not_found.
         WRITE / |Line not found exception.|.
    ENDTRY.

    This gives the following result:

    Test not found

    Line not found exception.

    With kind regards,

    Tim

    • Hi Tim,

      on the first look, this might look confusing. But that behaviour is exactly the same as it is without using a mesh:

      1. Looping trough a table with no matching line leads to a sy-subrc=4
      2. Accessing a line in a table with a non-matching key leads to exception CX_SY_ITAB_LINE_NOT_FOUND

      Example:

      1. DATA ls_sflight TYPE sflight.
      2. DATA lt_sflight TYPE TABLE OF sflight.
      3. LOOP AT lt_sflight INTO ls_sflight WHERE connid = 'Foo'.
      4. ENDLOOP.
      5. WRITE / sy-subrc.
      6. TRY.
      7.     ls_sflight = lt_sflight[ connid = 'Foo' ].
      8.   CATCH cx_sy_itab_line_not_found.
      9.     WRITE / |Line not found exception.|.
      10. ENDTRY.

      With regards,

      Welf

  • Hi,

    i’m agree with Tim but in another context, if I use the FOR IN expression I should have the same result than the LOOP AT WHERE if I take your example:

    types:
      begin of mesh ty_rep_mesh2,
        agr_agrs type t_agr_agrs
    association parent_to_child to agr_1252
    on agr_name = child_agr ,
        agr_1252 type t_agr_1252,
      end   of mesh ty_rep_mesh2.
    
    data: lt_agr_agrs type t_agr_agrs,
          lt_agr_1252 type t_agr_1252.
    
    data t_mesh2 type ty_rep_mesh2.
    
    start-of-selection.
    
    select * from agr_agrs  into table lt_agr_agrs where agr_name = 'MYSPECIFICROLE'.
    
    select * from agr_1252  into table lt_agr_1252 for all entries in lt_agr_agrs where agr_name = lt_agr_agrs-child_agr.
    
    
    t_mesh2 = value #( agr_1252 = lt_agr_1252[]
                      agr_agrs = lt_agr_agrs[] ).
    
    
    data test type t_agr_1252.
    data test3 type t_agr_1252.
    data test2 type t_agr_agrs.
    
    "No dump 
    try.
    
        test = value #( for val in t_mesh2-agr_agrs (
                            cond #(
                                    when line_index( t_mesh2-agr_1252[ agr_name = val-child_agr ] ) > 0:
                                              then t_mesh2-agr_agrs\parent_to_child[ t_mesh2-agr_agrs[ child_agr = val-child_agr ] ]
                                          )
                                                    )
                      ).
    
    
      catch cx_sy_itab_line_not_found into data(ls_root).
    
    endtry.
    
    try.
    
        test = value #( for val in t_mesh2-agr_agrs ( t_mesh2-agr_agrs\parent_to_child[ t_mesh2-agr_agrs[ child_agr = val-child_agr ] ] ) ).
    
      catch cx_sy_itab_line_not_found into ls_root.
    
    
    endtry.
    
    try.
        test2 = value #( for val in t_mesh2-agr_agrs ( val ) ).
    
      catch cx_sy_itab_line_not_found into ls_root.
    
    endtry.
    
    loop at t_mesh2-agr_agrs into data(ls_info).
    
      try.
    
          data(ls_data) = t_mesh2-agr_agrs\parent_to_child[ t_mesh2-agr_agrs[ child_agr = ls_info-child_agr ] ].
    
        catch cx_sy_itab_line_not_found into ls_root.
    
      endtry.
    
    endloop.