Application Development and Automation 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: 
Read only

Need help in processing internal table

Former Member
0 Likes
868

Hi all,

Im facing a problem in processing an internal table..especially with MODIFY.

The internal table is having following records.(t_vttp)

TKNUM       VBELN      KUNNR       NAME1                             LAND1
0000975179|0071004839|0000022946|HUNTSMAN APC LIMITED               |SA   |
0000975180|0071004845|0000022946|                                   |     |

In the above, there are two delviry documents with same customers.

The customer data is coming from different internal table.

LOOP AT t_vttp.

READ TABLE t_kna1_temp INTO wa_kna1_temp WITH KEY kunnr = t_vttp-kunnr.

IF sy-subrc = 0.

t_vttp-name1 = wa_kna1_temp-name1.

t_vttp-land1 = wa_kna1_temp-land1.

MODIFY t_vttp INDEX sy-tabix TRANSPORTING name1 land1.

ENDIF.

ENDLOOP.

Here for second record,,the customer name and country is nt getting populated to t_vttop.

Pls correct where it is going wrong.

Thanks,

Priya

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
828

Hi,

Store the value of sy-tabix of t_vttp before READ TABLE t_kna1_temp.

data : lv_tabix type sy-tabix.   "Added"
LOOP AT t_vttp.
move sy-tabix to lv_tabix.       "Added"
READ TABLE t_kna1_temp INTO wa_kna1_temp WITH KEY kunnr = t_vttp-kunnr.
IF sy-subrc = 0.
t_vttp-name1 = wa_kna1_temp-name1.
t_vttp-land1 = wa_kna1_temp-land1.

MODIFY t_vttp INDEX lv_tabix TRANSPORTING name1 land1. "Changed from sy-tabix to lv_tabix"
ENDIF.
ENDLOOP.

Regards

Vinod

5 REPLIES 5
Read only

former_member386202
Active Contributor
0 Likes
828

Hi,

Do like this

Data : l_index type sy-tabix.

LOOP AT t_vttp.

l_index = sy-tabix.

READ TABLE t_kna1_temp INTO wa_kna1_temp WITH KEY kunnr = t_vttp-kunnr.

IF sy-subrc = 0.

t_vttp-name1 = wa_kna1_temp-name1.

t_vttp-land1 = wa_kna1_temp-land1.

MODIFY t_vttp INDEX l_index TRANSPORTING name1 land1.

ENDIF.

ENDLOOP.

Regards,

Prashant

Read only

Former Member
0 Likes
829

Hi,

Store the value of sy-tabix of t_vttp before READ TABLE t_kna1_temp.

data : lv_tabix type sy-tabix.   "Added"
LOOP AT t_vttp.
move sy-tabix to lv_tabix.       "Added"
READ TABLE t_kna1_temp INTO wa_kna1_temp WITH KEY kunnr = t_vttp-kunnr.
IF sy-subrc = 0.
t_vttp-name1 = wa_kna1_temp-name1.
t_vttp-land1 = wa_kna1_temp-land1.

MODIFY t_vttp INDEX lv_tabix TRANSPORTING name1 land1. "Changed from sy-tabix to lv_tabix"
ENDIF.
ENDLOOP.

Regards

Vinod

Read only

0 Likes
828

data : lv_tabix type sy-tabix.

LOOP AT t_vttp.

*-- passing the sy-tabix to a variable

move sy-tabix to lv_tabix.

READ TABLE t_kna1_temp INTO wa_kna1_temp WITH KEY kunnr = t_vttp-kunnr.

IF sy-subrc = 0.

t_vttp-name1 = wa_kna1_temp-name1.

t_vttp-land1 = wa_kna1_temp-land1.

*-- modify the t_vttp table based on the lv_tabix.

MODIFY t_vttp INDEX lv_tabix TRANSPORTING name1 land1.

ENDIF.

ENDLOOP.

Regards

Manoj

Read only

Former Member
0 Likes
828

Hi Try the follwoing code with a little modification in your code.

LOOP AT t_vttp.

READ TABLE t_kna1_temp INTO wa_kna1_temp WITH KEY kunnr = t_vttp-kunnr.

IF sy-subrc = 0.

t_vttp-name1 = wa_kna1_temp-name1.

t_vttp-land1 = wa_kna1_temp-land1.

MODIFY t_vttp INDEX sy-tabix TRANSPORTING name1 land1.

append t_vttp.

ENDIF.

clear: wa_kna1_temp, t_vttp.

ENDLOOP

Also Please debugg your code and check if you are getting values.

also check the value of t_vttp-kunnr in debugging for the second run of your loop.

thanks

lalit

Read only

Former Member
0 Likes
828

It has worked out, by declaring sy-tabix separately.

Thanks all for your help.