04-12-2006 12:02 AM
Hi people!!
I need to insert a counter in the same table to organize the data. But the sistem display me a RUNTIME ERROR.
This is the code:
LOOP AT t_bsid .
sytabix = sy-tabix.
READ TABLE t_bsid WITH KEY blart = 'DZ' ordenador = ''.
IF sy-subrc = 0.
t_bsid-ordenador = v_contador + 1.
MODIFY t_bsid INDEX sytabix.
READ TABLE t_bsid WITH KEY belnr = t_bsid-rebzg.
t_bsid-ordenador = v_contador + 1.
v_contador = v_contador + 1.
MODIFY t_bsid INDEX sy-tabix.
ENDIF.
ENDLOOP.
Thanks
04-12-2006 12:20 AM
04-12-2006 2:25 AM
Hi Carlos,
Does it dump on the second modify statement? You are using directly sy-tabix to modify the record. The sy-tabix must have changed as you have a read command before that.
Btw why are you looping and reading the same table at the same time? A better approach would be have data in two different tables and then do a comparison. You can as well remove the first read and use a where clause in the loop to make it more quicker.
Anyways post the error description to understand the exact problem.
Cheers
VJ
04-12-2006 3:38 AM
It's dangerous, when looping at a table, to modify a line other than the one you have in the original header area. I'm not sure if this is causing the dump, bit I'd re-work the logic anyway. It's quite difficult to see exactly what's happening in the code.
Rob
04-12-2006 3:42 AM
Hi CARLOS,
I hope you should make the sy-subrc check in your second READ statement. If the second READ fails then sy-tabix would be 0.
Which would mean that you are trying to modify record with index 0.
Try with this code.
LOOP AT t_bsid .
sytabix = sy-tabix.
READ TABLE t_bsid WITH KEY blart = 'DZ' ordenador = ''.
IF sy-subrc = 0.
t_bsid-ordenador = v_contador + 1.
MODIFY t_bsid INDEX sytabix.
READ TABLE t_bsid WITH KEY belnr = t_bsid-rebzg.
<b>IF sy-subrc EQ 0.</b> "Make sy-subrc check here
t_bsid-ordenador = v_contador + 1.
v_contador = v_contador + 1.
MODIFY t_bsid INDEX sy-tabix.
<b>ENDIF.</b>
ENDIF.
ENDLOOP.
04-12-2006 3:51 AM
OK - it may be dumping because after:
READ TABLE t_bsid WITH KEY belnr = t_bsid-rebzg.
you aren't checking to see if sy-subrc = 0. If it's not 0, sy-tabix is set to 0 and it dumps when you try to modify the table index 0.
My other suggestion still stands, you should re-work the logic.
Rob
04-12-2006 3:54 AM
I will simply use another internal table which is of the same structure as t_bsid and use it appropriately. In the current code, there is too much scope for an error.
04-12-2006 3:59 AM
I think Wenceslaus has the answer....
.... but another possibility is that the table is sorted and one of the key fields is ordenador. You can't change key fields. If this is the problem you'd need to delete the original entry and insert a new one with the new ordenador value.