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

SORT question

Former Member
0 Likes
974

Hi,

I have the following code:

*SORT GT_ITAB BY name1 ASCENDING.
BREAK-POINT.
LOOP AT gt_itab INTO wa.
*  READ TABLE gt_itab INDEX sy-index INTO lv_wa TRANSPORTING name1.
  lv_wa = wa-name1.
  IF lv_cust <> lv_wa.
    APPEND lv_cust TO lv_new_itab.
    lv_cust = lv_wa.
  ENDIF.
ENDLOOP.

SORT lv_new_itab BY name1 ASCENDING.

Why is it so that if I uncomment the 1st line the program check isn't successful - giving me the following message: "You may only read from table "GT_ITAB" . reading. reading. reading. reading. reading."

but if I leave it like this (commented) the check goes ok ? Since the last SORT is being accepted it seems that you can't touch on the data after a SORT ? The 2nd sort, nevertheless, doesn't seem to be working anyway.

What's happening ?

Thanks

Avraham

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
856

Hi,

SY-INDEX doesnt work for Internal table loops, but only for conditional loops. Try using SY-TABIX for the INDEX in your READ statement

10 REPLIES 10
Read only

Former Member
0 Likes
856

hi,

Try this.

Use sy-tabix instead of sy-index.

For syntax of READ, check

http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb35f8358411d1829f0000e829fbfe/content.htm

Regards,

Anirban

Read only

matt
Active Contributor
0 Likes
856

Because GT_ITAB is protected in some way - perhaps an importing parameter to a method, for example. The rest of the program makes no sense, lv_cust never has a value assigned, so I'm not surprised that the 2nd sort "doesn't seem to be working", though you don't specify what you mean by "doesn't seem to be working".

matt

Read only

Former Member
0 Likes
856

Matt, lv_cust does have a value assigned, it is defined under the Global definitions in the Form. It starts with ''. The debugging shows (and actually the form preview) the values are being assigned.

I have to delve into your hint about "protected in some way".

Read only

matt
Active Contributor
0 Likes
856

OK. Sometimes it's difficult to get the balance between posting too much code, and posting too little!

Note, that it may not just be the form. If the form is called from a function module that's called from a method that has the table as an importing parameter, you'll get the same problem.

Read only

Former Member
0 Likes
857

Hi,

SY-INDEX doesnt work for Internal table loops, but only for conditional loops. Try using SY-TABIX for the INDEX in your READ statement

Read only

0 Likes
856

The READ statement is commented, guys, sorry, I should have taken it off the excerpt.

Matthew, maybe you have a point - because indeed my table is an imported parameter - this piece of code is within a Form.

Read only

matt
Active Contributor
0 Likes
856

For those of you wittering on about sy-index - please READ THE QUESTION.

Read only

0 Likes
856

Read only

0 Likes
856

You need to check "Pass by Value" in Form Interface Parameter

Read only

0 Likes
856

Thanks Shafiq, good catch.

The check doesn't complain now.