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: 

Regarding sy-index

Former Member
0 Kudos

Hi all,

I am trying to get loop count by using sy-index.

But I am not able get exact expected out put.

I am gettig all zeros instead of loop number.

I am sending my code here.

DATA: lv_diff(10) TYPE c,

lv_erdat1 LIKE sy-datum,

lv_erdat2 LIKE sy-datum,

i(15) TYPE c VALUE '1'.

SORT t_ordno BY aufnr.

LOOP AT t_ordno INTO st_ordno.

READ TABLE t_ordno INTO st_ordno INDEX i.

lv_erdat1 = st_ordno-erdat.

i = i + 1.

READ TABLE t_ordno INTO st_ordno INDEX i.

lv_erdat2 = st_ordno-erdat.

i = i + 1.

CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'

EXPORTING

i_datum_bis = lv_erdat2

i_datum_von = lv_erdat1

IMPORTING

e_tage = lv_diff.

WRITE:/ lv_diff,

50 <u><b>sy-index.</b></u>

CLEAR: lv_erdat1,lv_erdat2,lv_diff.

3 REPLIES 3

0 Kudos

Hi,

BEtween LOOP and ENDLOOP you should use SY-TABIX.

Only when yo use DO and WHILE loops you need to use SY-INDEX

Regards,

Sesh

Former Member
0 Kudos

HI,

u can use like this.

DATA: lv_diff(10) TYPE c,

lv_erdat1 LIKE sy-datum,

lv_erdat2 LIKE sy-datum.

lv_diff = lv_erdat2 - lv_erdat1.

rgds,

bharat.

Pawan_Kesari
Active Contributor
0 Kudos

use this code


DATA: lv_diff(10) TYPE c      ,
      lv_erdat1 LIKE sy-datum ,
      lv_erdat2 LIKE sy-datum ,
      i(15) TYPE c VALUE '1'  ,
      l_tabix type syst-tabix .
      
SORT t_ordno BY aufnr.

LOOP AT t_ordno INTO st_ordno.
  
  l_tabix = sy-tabix .

  READ TABLE t_ordno INTO st_ordno INDEX i.
  lv_erdat1 = st_ordno-erdat.
  i = i + 1.
  READ TABLE t_ordno INTO st_ordno INDEX i.
  lv_erdat2 = st_ordno-erdat.
  i = i + 1.


  CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'
       EXPORTING
            i_datum_bis = lv_erdat2
            i_datum_von = lv_erdat1
       IMPORTING
            e_tage      = lv_diff.

  WRITE:/ lv_diff,
       50 l_tabix.
  CLEAR: lv_erdat1,lv_erdat2,lv_diff.