Skip to Content
0

How to sort a copied internal table?

Mar 30, 2017 at 06:17 AM

85

avatar image

I have copied one internal table to another as shown below:

It_aacout2 = It_aacout.

Both tables will have matching data, with the exception that it_aacout2 will show one less field than it_aacout. Currently, this is working fine.

The problem, however, is that my new table, is still sorted as if the removed data is still there, even though it is not. I have tried deleting adjacent duplicates and that does not work. Is there a better way to do this? Can I select the individual fields from the original table and bypass this issue? Is there a better way to sort my table?

I've tried copying the table and deleting the duplicates in both the beginning and the end thinking that this may make a difference. In the various performs that are mentioned, they are all referencing it_aacout, not the new table, it_aacout2.

Any help would be much appreciated.

data: l_done type c.                          "<<< Start of STC0013

      Perform prepare_colors.

      sort it_aacout2 by FG AAC ASCENDING.

      DATA wa_matnr like line of s_matnr.

      loop at s_matnr into wa_matnr.

        PERFORM check_converge.
        if l_convg = '2.0'.
          EXIT.
        ENDIF.
      ENDLOOP.

      Refresh it_fieldcat[].
      if l_done is initial
        and l_convg = '2.0'.
        PERFORM get_conv_struct.
        Perform prepare_columns3.
      ELSEIF
      l_done is initial
        and l_convg ne '2.0'.
        PERFORM prepare_columns4.
      ENDIF.

      it_aacout2 = it_aacout.
      delete ADJACENT DUPLICATES FROM it_aacout2
      COMPARING ALL FIELDS.


      Perform report_data2 tables it_aacout2      "<<< End of STC0013

                           USING TEXT-t01.
10 |10000 characters needed characters left characters exceeded

You don't provide enough information: please clean useless code (we can't concentrate on your only problem), and provide the data types (of internal tables). Moreover, DELETE ADJACENT DUPLICATES works only if the rows of the concerned internal table have been previously sorted in the same way, and I can't conclude by looking at your code if your internal table has bee previously sorted.

2
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Volker Binder Mar 30, 2017 at 06:40 AM
-2

may be this will help:

it_aacout2[] = it_aacout[] .

Show 2 Share
10 |10000 characters needed characters left characters exceeded
Why should that help?
1

It would probably help if the table had a header :)

0
Richard Harper Mar 30, 2017 at 07:07 AM
0

Well of course it will still be sorted as if the missing data is present. As Horst pointed out above, copying the table does not re-order the rows. However, you are making a really fundamental mistake and that is the over use of global variables.

I note that your performs do not have any arguments to them so I assume that your tables are all global. This style of programming leads to bugs likes this. Never ever use global variables unless SAP forces you to (such as when handling screens), Always parameterise your procedures and always type those parameters*.

So, assuming that your check_converge procedure takes a material,

loop at s_matnr into wa_matnr.

PERFORM check_converge Using wa_Matnr Changing l_Convg.

if l_convg ='2.0'.

EXIT.

ENDIF.

ENDLOOP.

And in fact, I would put the whole table as an argument and do the loop in the procedure hiding the actual nitty gritty of the functionality.

By using global variables you make each procedure reliant on knowing intimate details of the rest of the program. You cannot poke a program like that somewhere and not expect it to fail somewhere else because of the reliance on globals. By using good programming techniques you would not have come across this problem because you would pass it_accout2[] as a parameter instead of it_accout[].

Rich

@Horst.

Typing your procedure parameters prevents you passing rubbish at compile time to your procedures and is a good sanity check, but also other programming languages run faster when you parameterise your procedures because the compiler knows the data type expected and therefore you don't get an implicit type conversion during a call. Does Abap show this behaviour ?

Thanks!

Rich

Share
10 |10000 characters needed characters left characters exceeded
Kirill Gorin Mar 30, 2017 at 07:36 AM
0

First of all you don't want to copy data structures that have different lenghts (it's bad practice if anything). Second of all the most relevant thing to show would be your data and type defenitions.

Share
10 |10000 characters needed characters left characters exceeded