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: 

Problem in Sy-tabix value

Former Member
0 Kudos

Hi Experts,

I have a scenario like this

Itab1

A | B | C

1050 | 10 | 88

1051 | 20 | 99

itab2

A | D

1050 | 1

1050 | 2

1050 | 3

1051 | 4

1051 | 5

now I want to combine these values in itab3

my result should be

A | B | C | D

1050 10 88 1

1050 10 88 2

1050 10 88 3

1051 20 99 4

1051 20 99 5

i did code like this

LOOP AT i_tab1 INTO w_tab1.

CLEAR w_tab3.

w_tab3-A = itab1-A.

w_tab3-B = itab1-B.

w_tab3-C = itab1-C.

APPEND w_tab3 TO i_tab3.

loop at i_tab2 INTO w_tab2 where A = w_tab2-A.

IF sy-tabix EQ 1.

w_tab3-D = w_tab2-D.

MODIFY i_tab3 INDEX sy-tabix FROM w_tab3 TRANSPORTING D.

else.

w_tab3-A = itab1-A.

w_tab3-B = itab1-B.

w_tab3-C = itab1-C.

w_tab3-D = itab2-D.

APPEND w_tab3 TO i_tab3

ENDIF.

CLEAR w_vttp.

CLEAR w_vttk_tknum.

endloop.

ENDLOOP.

ENDIF.

Probelm:

When I am pocessing 2 record of itab1, the value of sy-tabix for in internal table i_tab2 is not resetting, it's picking the old value.

Can you please tell me how i can reset the sy-tabix of inner loop for the second pass of outer loop.

Thnaks

Krishan

Edited by: Krishan Kumar on Aug 2, 2008 2:40 PM

1 ACCEPTED SOLUTION

Former Member
0 Kudos

You can try it like this:

data:
  count type i value 1,
  w_line type i.

describe table i_tab1 lines w_line.

do w_line time.

read  i_tab1 into  w_tab1 index count.

  loop at tab2 into w_tab2 where A = itab1-A.
   w_tab3-A = itab1-A.
   w_tab3-B = itab1-B.
   w_tab3-C = itab1-C.
   w_tab3-D = itab2-D.
  APPEND w_tab3 TO i_tab3
  endloop.
count = count + 1.
enddo.

With luck,

Pritam.

3 REPLIES 3

Former Member
0 Kudos

You can try it like this:

data:
  count type i value 1,
  w_line type i.

describe table i_tab1 lines w_line.

do w_line time.

read  i_tab1 into  w_tab1 index count.

  loop at tab2 into w_tab2 where A = itab1-A.
   w_tab3-A = itab1-A.
   w_tab3-B = itab1-B.
   w_tab3-C = itab1-C.
   w_tab3-D = itab2-D.
  APPEND w_tab3 TO i_tab3
  endloop.
count = count + 1.
enddo.

With luck,

Pritam.

0 Kudos

Hi Pritam,

Thanks a lot.

U gave a very-very precise logic.

It's running.

Again thanks.

former_member188685
Active Contributor
0 Kudos

Modified version of your code..

LOOP AT i_tab1 INTO w_tab1.
CLEAR w_tab3.
w_tab3-A = itab1-A.
w_tab3-B = itab1-B.
w_tab3-C = itab1-C.

loop at i_tab2 INTO w_tab2 where A = w_tab1-A.
w_tab3-D = w_tab2-D.
append w_tab3 to i_tab3.
clear w_tab2.
endloop.
if sy-subrc ne 0.
APPEND w_tab3 TO i_tab3.
ENDIF.
clear w_tab1.
ENDLOOP.

No need to use SY-TABIX here...