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 a TABLE within an RFC

Former Member
0 Kudos

I'm running up against a strange problem. I'm trying to return data from an RFC in a table data structure.

What I'm finding is that no matter how I sort the data in the function module, SAP resorts the data alphanumerically before it leaves the RFC.

Does anyone know how I can get my data to -stay- in the sort order I specified using the SORT command?

14 REPLIES 14

Former Member
0 Kudos

There is really no one who knows how function modules sort tables by default?

0 Kudos

ColtsFan,

How is the internal table declared?

Signed,

A Steelers Fan...

0 Kudos

I have just tested it, it is keeping the sort sequence in my example. Can you post some of your code?

Regards,

Rich Heilman

0 Kudos

Hi. It's in the "tables" section of the function module defined LIKE a data dictionary structure with the following fields:

CHAR 4

CHAR 20

CHAR 20

CHAR 20

CHAR 20

CHAR 18

CHAR 20

CHAR 1

INT4 10

CURR 15

CUKY 5

CURR 15

CUKY 5

DEC 5

CHAR 8

CURR 15

CUKY 5

CURR 15

CUKY 5

INT4 10

INT4 10

CHAR 1

CURR 15

CUKY 5

CHAR 30

CHAR 10

When I sort the table in the function module, it looks good! But as soon as the RFC completes the data in the table seems to be re-sorted alphanumberically based on the first CHAR fields in the table.

0 Kudos

Please post the entire internal table declaration and the code around your "forced" SORT command.

0 Kudos

Hi!

Do you change anything in this table except the order? Because there is a delta managing mechanism to minimize network load during parameter and result passing. In case of internal tables, the RFC server receives the table entries, it creates a local copy of the internal table. Then only delta information is returned to the RFC client. This information is not returned to the RFC client every time a table operation occurs, however; instead, all collected delta information is passed on at once when the function returns to the client.

Maybe sorting is not defined as 'change'.

Rich, did you fill the table inside or outside of the RFC-FM?

Regards,

Christian

0 Kudos

I filled the table inside the Function Module.

Regards,

Rich Heilman

0 Kudos

Looks like we have tracked down to the source of this riddle. In case of field changes, it's not a problem, otherwise using import / export parameter will be a workaround.

0 Kudos

So if I export and then import the table before the function module ends, it will force the new sorting to take effect within the outgoing table?

Let me give that a shot...

Former Member
0 Kudos

Hi,

In Function Module use

Export itab to memory Id 'TEST'.

Import itab from memory Id 'TEST'.

Regards

Amole

0 Kudos

Hi Amole,

What will importing and exporting the itab to memory do for me?

Former Member
0 Kudos

Export will write the data to temporary ABAP memory

import will get the data from ABAP memory

itab structure should be same in calling and called program

Regards

Amole

0 Kudos

Hi!

I was referring the FM interface definition. Send your table as import parameter (from FM point of view) and give back the result as export parameter - then you trick out the workload optimization of SAP.

You shouldn't need to export into memory / import from memory. This can't work anyway, because you have a <i>remote</i> function call.

Regards,

Christian

0 Kudos

Just for reference........but I think Christian is right. Haven't tested it.



report zrich_0003 .


data: itab type table of t001 with header line.
call function 'Z_TEST'.
import itab = itab from memory id 'ZRICHTEST'.




function z_Test.

data: itab type table of t001 with header line.

* Get data and sort it.

export itab = itab to memory id 'ZRICHTEST'.

ENdfunction.

Regards,

Rich Heilman