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: 

Modifying contents of internal Table.

Former Member
0 Kudos

Hi all,

I am tryint to modify the contents of an internal table. This is the code I have written . But it doesn't work. However hard I try to debug and see the code it goes wromng when I reach the modify statement. I tried in many ways but couldn't suceed. Can anyone please help me ?

I am attaching my code too.

FORM get_values_into_t_item.

LOOP AT t_header.

SELECT posnr

vgbel

vgpos

matnr

arktx

prctr

fkimg

vrkme

brgew

gewei

netwr INTO CORRESPONDING FIELDS OF TABLE t_item

FROM vbrp

WHERE vbeln EQ t_header-vbeln AND

vgbel IN s_vgbel AND

matnr IN s_matnr AND

arktx IN s_arktx AND

prctr IN s_prctr AND

fkimg IN s_fkimg AND

vrkme IN s_vrkme AND

brgew IN s_brgew AND

gewei IN s_gewei AND

netwr IN s_netwr.

ENDLOOP.

clear t_item.

LOOP AT t_item.

SELECT SINGLE vbeln

FROM lips INTO w_vbeln

WHERE vbeln EQ t_item-vgbel AND

posnr EQ t_item-vgpos .

IF sy-subrc EQ 0.

SELECT SINGLE tknum

FROM vttp INTO w_tknum

WHERE vbeln EQ w_vbeln.

IF sy-subrc EQ 0.

SELECT tknum

exti1

dtabf INTO CORRESPONDING FIELDS OF TABLE t_item

FROM vttk

WHERE tknum = w_tknum.

  • MODIFY t_item from t_item.

ENDIF.

ENDIF.

MODIFY t_item.

ENDLOOP.

ENDFORM. " get_values_into_t_item

Thanks and Regards,

Varun.

1 ACCEPTED SOLUTION

former_member181962
Active Contributor
0 Kudos

This would work definitely:

<b>The problem with your earlier code is that in the last select you have use the INTO CORRESPONDING FIELDS OF TABLE statement .

This would get the values into the table directly,whereas our aim is to get that values into the header first and then use modify statement.</b>

FORM get_values_into_t_item.

LOOP AT t_header.

SELECT posnr

vgbel

vgpos

matnr

arktx

prctr

fkimg

vrkme

brgew

gewei

netwr INTO CORRESPONDING FIELDS OF TABLE t_item

FROM vbrp

WHERE vbeln EQ t_header-vbeln AND

vgbel IN s_vgbel AND

matnr IN s_matnr AND

arktx IN s_arktx AND

prctr IN s_prctr AND

fkimg IN s_fkimg AND

vrkme IN s_vrkme AND

brgew IN s_brgew AND

gewei IN s_gewei AND

netwr IN s_netwr.

ENDLOOP.

clear t_item.

LOOP AT t_item.

SELECT SINGLE vbeln

FROM lips INTO w_vbeln

WHERE vbeln EQ t_item-vgbel AND

posnr EQ t_item-vgpos .

IF sy-subrc EQ 0.

SELECT SINGLE tknum

FROM vttp INTO w_tknum

WHERE vbeln EQ w_vbeln.

IF sy-subrc EQ 0.

SELECT single tknum

exti1

dtabf <b>INTO ( t_item-tknum , t_item-exti1 , t_item-dtabf )</b>

FROM vttk

WHERE tknum = w_tknum.

MODIFY t_item from t_item.

ENDIF.

ENDIF.

ENDLOOP.

ENDFORM. " get_values_into_t_item

9 REPLIES 9

former_member181962
Active Contributor
0 Kudos

Do like this:

FORM get_values_into_t_item.

LOOP AT t_header.

SELECT posnr

vgbel

vgpos

matnr

arktx

prctr

fkimg

vrkme

brgew

gewei

netwr INTO CORRESPONDING FIELDS OF TABLE t_item

FROM vbrp

WHERE vbeln EQ t_header-vbeln AND

vgbel IN s_vgbel AND

matnr IN s_matnr AND

arktx IN s_arktx AND

prctr IN s_prctr AND

fkimg IN s_fkimg AND

vrkme IN s_vrkme AND

brgew IN s_brgew AND

gewei IN s_gewei AND

netwr IN s_netwr.

ENDLOOP.

clear t_item.

LOOP AT t_item.

<b>lv_tabix = sy-tabix.</b>

SELECT SINGLE vbeln

FROM lips INTO w_vbeln

WHERE vbeln EQ t_item-vgbel AND

posnr EQ t_item-vgpos .

IF sy-subrc EQ 0.

SELECT SINGLE tknum

FROM vttp INTO w_tknum

WHERE vbeln EQ w_vbeln.

IF sy-subrc EQ 0.

SELECT tknum

exti1

dtabf INTO CORRESPONDING FIELDS OF TABLE t_item

FROM vttk

WHERE tknum = w_tknum.

<b> MODIFY t_item from t_item index lv_tabix.</b>

ENDIF.

ENDIF.

ENDLOOP.

ENDFORM. " get_values_into_t_item

0 Kudos

HI,

No luck Ravi I tried it already.

Regards,

Varun.

Former Member
0 Kudos

Hi,

1. In the first SELECT inside the loop opf the header, use appending. As this SELECT will fire multiple times, each time its going to overwrite the previous contents. You will end up with the values for the last header row.

You might try to use FOR ALL ENTRIES, so that you can avoid a SELECT inside the LOOP.

2. Try this

field-symbols : <fs_item> like line of t_item.

LOOP AT t_item assigning <fs_item>.

lv_tabix = sy-tabix.

SELECT SINGLE vbeln

FROM lips INTO w_vbeln

WHERE vbeln EQ <fs_item>-vgbel AND

posnr EQ <fs_item>-vgpos .

IF sy-subrc EQ 0.

SELECT SINGLE tknum

FROM vttp INTO w_tknum

WHERE vbeln EQ w_vbeln.

IF sy-subrc EQ 0.

SELECT tknum

exti1

dtabf INTO CORRESPONDING FIELDS OF TABLE <fs_item>

FROM vttk

WHERE tknum = w_tknum.

*******MODIFY t_item from t_item index lv_tabix.

ENDIF.

ENDIF.

ENDLOOP.

<b> I have used field symbols so that you don't have use the index at all, the updates are immediate and the performance improves. </b>

Regards,

Ravi

Note :Please mark the helpful answers

Message was edited by: Ravikumar Allampallam

0 Kudos

Hi,

The suggestion to use appending was wonderful !! Thanks a lot. I am not interested in using field symbols as I do not have any knowledge about them.

But still I couldn't why the modify is giiving false results.

<b>Note : My policy is to give and take.</b>

Varun.

0 Kudos

If you don't want to use field symbols, try declaring a separate work area wa_item and use that.

Then use this statement.

MODIFY <itab> FROM <wa> [INDEX <idx>] [TRANSPORTING <f1> <f 2> ... ].

Regards,

Ravi

former_member181962
Active Contributor
0 Kudos

This would work definitely:

<b>The problem with your earlier code is that in the last select you have use the INTO CORRESPONDING FIELDS OF TABLE statement .

This would get the values into the table directly,whereas our aim is to get that values into the header first and then use modify statement.</b>

FORM get_values_into_t_item.

LOOP AT t_header.

SELECT posnr

vgbel

vgpos

matnr

arktx

prctr

fkimg

vrkme

brgew

gewei

netwr INTO CORRESPONDING FIELDS OF TABLE t_item

FROM vbrp

WHERE vbeln EQ t_header-vbeln AND

vgbel IN s_vgbel AND

matnr IN s_matnr AND

arktx IN s_arktx AND

prctr IN s_prctr AND

fkimg IN s_fkimg AND

vrkme IN s_vrkme AND

brgew IN s_brgew AND

gewei IN s_gewei AND

netwr IN s_netwr.

ENDLOOP.

clear t_item.

LOOP AT t_item.

SELECT SINGLE vbeln

FROM lips INTO w_vbeln

WHERE vbeln EQ t_item-vgbel AND

posnr EQ t_item-vgpos .

IF sy-subrc EQ 0.

SELECT SINGLE tknum

FROM vttp INTO w_tknum

WHERE vbeln EQ w_vbeln.

IF sy-subrc EQ 0.

SELECT single tknum

exti1

dtabf <b>INTO ( t_item-tknum , t_item-exti1 , t_item-dtabf )</b>

FROM vttk

WHERE tknum = w_tknum.

MODIFY t_item from t_item.

ENDIF.

ENDIF.

ENDLOOP.

ENDFORM. " get_values_into_t_item

Former Member
0 Kudos

use

modify internaltable transporting f1 f2 f3.... .

f1, f2 , f3 = fieds u are modifying

0 Kudos

Hi,

Thank you all friends. My problem is solved and I have awarded points to all those who poested anwers and closing the post.

I lived upto my policy .

Thanks and Regards,

Varun.

Former Member
0 Kudos

You are looping at t_item and then in that loop selecting into the same table. I think you should do something like:


      SELECT tknum
      exti1
      dtabf appending CORRESPONDING FIELDS OF TABLE<b>wa_item</b>
      FROM vttk
      WHERE tknum = w_tknum.

******MODIFY t_item FROM t_item INDEX lv_tabix.

At the end of the loop, you need to do further processing to append lines of wa_item to t_item.

Rob