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: 

Sorting internal table and a tricky change

Former Member
0 Kudos

Ex : If internal table for PO looks like :

POSNR - Plant

00010 - 204

00020 - 202

00030 - 204

00040 - 202

00050 - 206

After sorting with respect to plant and then posnr,

the layout is :

00020 - 202

00040 - 202

Page-break

00010 - 204

00030 - 204

Page-break

00050 - 206

In this case, the 1st item displayed on the 1st page is item # 00020

Our key users do not like it, and wish to see the 1st item (# 00010) on the 1st page

The desired result is to change the sequence displaying the "plant block" containing the 1st item :

00010 - 204

00030 - 204

Page-break

00020 - 202

00040 - 202

Page-break

00050 - 206

The general rule is still to sort by plant (ascending) and then by item number (ascending also), but to move the block

of the plant containing the lowest item number on top of the sequence.

Please be careful not to generate regression in case there is only 1 item, or only 1 plant, or any other case.

Kindly provide a solution.

Thanks & Regards,

Tejas

3 REPLIES 3

Former Member
0 Kudos

Hi,

You have to sort with posnr first and then sort with the plant..

SORT ITAB BY POSNR PLANT

Thanks

Naren

Former Member
0 Kudos

Use this logic. Create a copy of the internal table.

itab_temp[] = itab[].

SORT ITAB BY POSNR.

LOOP AT ITAB.

LOOP AT ITAB_TEMP WHERE ITAB_TEMP-PLANT = ITAB-PLANT.

WRITE ITAB_TEMP-PLANT , ITAB_TEMP-POSNR.

ENDLOOP.

DELETE ITAB_TEMP WHERE PLANT = ITAB-PLANT.

ENDLOOP.

Former Member
0 Kudos

hi,

i suggest you create another intrnal table ( I_TAB2 ) and do it like this

sort I_TAB by posnr

move the first record of I_TAB to I_TAB2

delete the 1st record of I_TAB

transfer all remainingrecords of I_TAB into I_TAB2 where plant = I_TAB2-plant

delete from I_TAB all records with plant = I_TAB2 plant

sort I_TAB by plant posnr

transfer all records of I_TAB into I_TAB2

your I_TAB2 will be the result