Skip to Content
-3

Internal table Sorting

May 04, 2017 at 10:03 AM

226

avatar image

Hi all,

I have Internal Table (iTab1) like below.

I am expecting output Internal table like below (Itab2).

1. If there is only one Line Item with single batch count should be 1.

2. mutliple batch items then ignore 00000 HIERARITME then count.

Please suggest me how to get the output.

Thanks for the help.

itab1.jpg (18.2 kB)
itab2.jpg (16.1 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Raghu Govindarajan May 04, 2017 at 11:44 AM
3

This can be solved with a little programming...

Share
10 |10000 characters needed characters left characters exceeded
Horst Keller
May 05, 2017 at 05:47 AM
2

The aim is to get and count the subnodes of a parent node of a tree like structure in an internal table.

There are many ways to do so.

A modern way of handling tree structures in internal tables are reflexive mesh path expressions. (In fact the only use case for which I have used meshes productively up to now).

Check the example.

Show 2 Share
10 |10000 characters needed characters left characters exceeded

<keels over with a glazed look>

0

As intended ;-)

A "real life" example:

DATA parent TYPE abapdocu_tree-node_key VALUE 'ABENABAP'.
cl_demo_input=>request( CHANGING field = parent ).

TYPES:
  BEGIN OF line,
    id        TYPE abapdocu_tree-node_key,
    parent_id TYPE abapdocu_tree-relatkey,
  END OF line,
  t_itab TYPE STANDARD TABLE OF line WITH NON-UNIQUE KEY id
         WITH NON-UNIQUE SORTED KEY by_parent COMPONENTS parent_id,
  BEGIN OF MESH t_mesh,
    node TYPE t_itab
       ASSOCIATION to_node TO node ON parent_id = id
         USING KEY by_parent,
  END OF MESH t_mesh.
DATA mesh TYPE t_mesh.

SELECT * FROM abapdocu_tree
         WHERE tab_index > 0
         INTO TABLE @DATA(abap_docu_tree).

TRY.
    mesh-node = VALUE #( FOR node IN abap_docu_tree
                        ( id = node-node_key parent_id = node-relatkey ) ).
    DATA(subtree) = VALUE t_itab(
      FOR <node> IN mesh-node\to_node[ mesh-node[ id = parent ] ] ( <node> )  ).

    cl_demo_output=>new(
      )->write( subtree
      )->write( lines( subtree ) )->display( ).
  CATCH cx_sy_itab_line_not_found.
    RETURN.
ENDTRY.

Using \to_node+ would also retrieve subnodes of the subnodes.

This might serve as a pattern for similar tasks.

0
Kali Charan May 04, 2017 at 12:14 PM
-1

Move (iTab1) to other table just like itab2
now sort itab2 posnr hireitem

now delete adjecent duplicated from itab2 comparing posnr hireitme.

data:No_of_times type i.

Now

loop at itab2
loop at itab1 where psonr = itab2-posnr and hireitem = itab2-hiritem.
No_of_times = No_of_times + 1.

endloop.

write:itab2-posnr itab2-hireitem No_of_times.
clear:no_of_times.

endloop.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi Charan,

Thanks for the reply, I did exactly same but that doesn't solved by issue.

I am expecting output like below.

0010 00000 1

0020 00000 1

0030 0030 2

0040 0000 1

Thanks,

tab3.jpg (37.5 kB)
0
Venkatramesh V May 05, 2017 at 05:42 AM
-1

Hi,

Try.

SORT itab POSNR HIERAITEM.

loop at itab into wa.

wa-count = '1'.

collect wa into itab1.

endloop.

delete the itab1 according to your requirement.

Hope it helpful,

Regards,

Venkat.

Share
10 |10000 characters needed characters left characters exceeded