Application Development and Automation 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: 
Read only

internal table operation question

Former Member
0 Likes
689

Hello,

I am printing bill of lading with materials, I have some materials marked as hazardous , in that case I need to print all the hazardous materials first and the remaining materials should be printed after the hazardous materials are printed.

I know a method as get the main internal table contents into a temp table, and delete the non hazardous material from  temp table , and move  those hazardous materials into a third table  which are at the temp table , and after that loop the actual table containing both the hazardous and non hazardous material and if the material is present in the temp table dont append else append into the third table .

Please suggest if there is other best method as this requires two additional tables.

Thanks,

\RG

4 REPLIES 4
Read only

amol_samte
Contributor
0 Likes
650

Hi,

Always logic is dependent on individual developers....

There are several ways to achieve it...

1. Fire two queries with appending lines( first for hazardous, second for rest)...It will hit two times to DB

If you are on ABAP 7.4 SP 08/7.5 Stack,

You can go with FILTER ABAP Keyword Documentation

-Amol S

Read only

Former Member
0 Likes
650

Sounds like the good old grouping issue.

If you have NW 7.4 >= SP08 you can use a LOOP AT ... GROUP BY ... There you can also define a sorting order. In your case, I think you need DESCENGING ordering by the "hazardous" flag, so TRUE ('X') entries will come first.

Read only

0 Likes
650

Hi,

In my case how can I use group BY. I think in that case also I have two use two internal tables

Thanks,

RG

Read only

0 Likes
650

For example you have a table with the fields KEY, FLAG and DATA. Inside the internal table you have some data with set FLAG ('X') and unset FLAG (' '). KEY is simply an ID and DATA some text.

LOOP AT lt_table ASSIGNING FIELD-SYMBOL(<ls_entry>)

          GROUP BY flag DESCENDING INTO DATA(lv_flag).

     WRITE: / |Flag is '{ lv_flag }'|. " output = Flag is 'X'  or Flag is ' '

     LOOP AT GROUP lv_flag ASSIGNING FIELD-SYMBOL(<ls_member>).

          WRITE: / |{ <ls_member>-key } = { <ls_member>-data }|.

     ENDLOOP.

ENDLOOP.

Explanation:

With the GROUP BY you create groups for the field FLAG. In your case only two. One group with set FLAG and one with unset FLAG. With the addition DESCENDING the entries with FLAG = 'X' are handled first. With the LOOP AT GROUP you walk through all member of a group, i.e. first through all entries with FLAG = 'X' and second through all entries with FLAG = ' '.