‎2008 Jul 31 8:25 AM
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
‎2008 Jul 31 8:29 AM
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
‎2008 Jul 31 8:27 AM
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
‎2008 Jul 31 8:28 AM
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
‎2008 Jul 31 8:36 AM
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".
‎2008 Jul 31 8:39 AM
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.
‎2008 Jul 31 8:29 AM
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
‎2008 Jul 31 8:31 AM
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.
‎2008 Jul 31 8:31 AM
For those of you wittering on about sy-index - please READ THE QUESTION.
‎2008 Jul 31 8:32 AM
‎2008 Jul 31 8:42 AM
‎2008 Jul 31 9:00 AM