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: 

How to sort a copied internal table?

Former Member
0 Kudos

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.
6 REPLIES 6

former_member226519
Active Contributor
0 Kudos

may be this will help:

it_aacout2[] = it_aacout[] .

Why should that help?

0 Kudos

It would probably help if the table had a header 🙂

Sandra_Rossi
Active Contributor

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.

former_member182550
Active Contributor
0 Kudos

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

k_gorin
Participant
0 Kudos

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.