sy-tabix value modification during deletion in looping | Techbirds

Posted on: December 23, 2013 /

Categories: ABAP, SAP / Author Name: Ankit Shukla

hi Abapers ,

Today  i am going to discuss

1 .how to use the sy-tabix value …?

2 .how sy-tabix value manipulate during looping .. ?

discuss these question by explaining a simple program or report .

REPORT  zloop_test.

DATA : lt_emp TYPE TABLE OF zemployee, ls_emp TYPE zemployee, counter TYPE i ,

flag TYPE i.

SELECT * FROM zemployee INTO TABLE lt_emp UP TO 5 ROWS .

LOOP AT lt_emp INTO ls_emp.

DELETE lt_emp INDEX sy-tabix  .

WRITE : / sy-tabix , 40 ls_emp-emp_no,

50 ls_emp-emp_name.

ENDLOOP.

1 . sy-tabix contain index value of  row in internal table during looping .

2 .Normally you will think the output of this report will nothing , because during looping delete statement

deleting  each row of internal table  , but  output will be there .

it will show first five record of employee table with sy-tabix value 1 each time . Now the question is how  .. ?

Explanation :

After select query internal table values will be :

SY-TABIX EMP_NO EMP_NAME
1 00001 ANKIT
2 00002 PRAKASH
3 00003 GOPAL
4 00004 DAS
5 00005 JOHN

On first deletion with sy-tabix value 1 .

Internal table (lt_emp)  contain four records (first was deleted ) . but it will print first record ,reason is workarea ( ls_emp has value ) .

internal table have values :

SY-TABIX EMP_NO EMP_NAME
1 00002 PRAKASH
2 00003 GOPAL
3 00004 DAS
4 00005 JOHN

first row was deleted and all bottom rows  sy-tabix value was decrement by 1 .

On second deletion again with sy-tabix value 1 .

Internal table (lt_emp)  contain three records (first was deleted ) . but it will print first record ,reason is workarea ( ls_emp has value ) .

internal table have values :

SY-TABIX EMP_NO EMP_NAME
1 00003 GOPAL
2 00004 DAS
3 00005 JOHN

first row was deleted and all bottom rows  sy-tabix value was decrement by 1 .

On third deletion again with sy-tabix value 1 .

Internal table (lt_emp)  contain two records (first was deleted ) . but it will print first record ,reason is workarea ( ls_emp has value ) .

internal table have values :

SY-TABIX EMP_NO EMP_NAME
1 00004 DAS
2 00005 JOHN

first row was deleted and all bottom rows  sy-tabix value was decrement by 1 .

On fourth deletion again with sy-tabix value 1 .

Internal table (lt_emp)  contain one records (first was deleted ) . but it will print first record ,reason is workarea ( ls_emp has value ) .

internal table have values :

SY-TABIX EMP_NO EMP_NAME
1 00005 JOHN

first row was deleted and all bottom rows  sy-tabix value was decrement by 1 .

On fifth deletion again with sy-tabix value 1 .

Internal table (lt_emp)  contain no records (first was deleted ) . but it will print single record ,reason is workarea ( ls_emp has value ) .

internal table have values :

So as you see , sy-tabix value was decremented by one  for all rows below the deleted index .

 Final output will have all five rows with same sy-tabix value as 1 .

SY-TABIX EMP_NO EMP_NAME
1 00001 ANKIT
1 00002 PRAKASH
1 00003 GOPAL
1 00004 DAS
1 00005 JOHN

ESSENTIAL  POINTS :

* At final lt_emp (internal table ) has zero rows  or empty .

* Each time in delete statement sy-tabix has value 1 .

1,377 total views, 2 views today