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: 

Runtime Error when I insert a data in a internal table

Former Member
0 Kudos

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

7 REPLIES 7

Former Member
0 Kudos

What is the error?

Former Member
0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

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.

0 Kudos

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

Former Member
0 Kudos

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.

former_member186741
Active Contributor
0 Kudos

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.