cancel
Showing results for 
Search instead for 
Did you mean: 

Modify internal table

Former Member
0 Kudos

Hi,

Below is a test code snippet, wherein I am trying to modify the internal table in one go. But giving me the dump.

If I use a loop and then modify it works.

But How can I do it in one go ?

Regards,

Nitin

REPORT ztest.

DATA :

BEGIN OF it_test OCCURS 0,

matnr LIKE mara-matnr,

counter(3) TYPE c,

END OF it_test.

it_test-counter = '0'.

it_test-matnr = '1'.

APPEND it_test.

it_test-counter = '0'.

it_test-matnr = '2'.

APPEND it_test.

it_test-counter = '0'.

it_test-matnr = '3'.

APPEND it_test.

it_test-counter = 1.

MODIFY it_test TRANSPORTING counter..

LOOP AT it_test.

WRITE 😕 it_test-matnr.

ENDLOOP.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Nitin,

Since you want to update the entire internal table unconditionally, just give some dummy condition which will always be true. Consider the following code. The part is bold is my addition to your code.

REPORT ztest.

DATA : BEGIN OF it_test OCCURS 0,
         matnr LIKE mara-matnr,
         counter(3) TYPE c,
       END OF it_test.

it_test-counter = '0'.
it_test-matnr = '1'.
APPEND it_test.

it_test-counter = '0'.
it_test-matnr = '2'.
APPEND it_test.

it_test-counter = '0'.
it_test-matnr = '3'.
APPEND it_test.

it_test-counter = 1.
MODIFY it_test TRANSPORTING counter <b>where counter ne 'X'</b>.

LOOP AT it_test.
  WRITE 😕 it_test-matnr.
ENDLOOP.

Reward points appropriately if that helps.

Regards,

Anand Mandalika.

Answers (4)

Answers (4)

matt
Active Contributor

Just to add a modern solution:

MODIFY TABLE <internal table> FROM VALUE #( field_to_change = new_value ) 
       TRANSPORTING field_to_change
       WHERE <cond>.
Former Member
0 Kudos

Hi,

U can also reward for the other helpful answers, others also suggested the same way.

Former Member
0 Kudos

Hey,

Create a work area of same internal table type.

assign the value for that work area-field and then use,

MODIFY <internal table> from <work area>

Regs,

Venkat

Former Member
0 Kudos

MODIFY it_test TRANSPORTING counter where

matnr = ...

DO a F1 and check the syntax.

Then it will work.

Thi s will update all the rows where the keyfield value is = 1 as per ur case.

Message was edited by: Judith Jessie Selvi

Former Member
0 Kudos

I want to update all the rows. Not specific with matnr

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

These are the syntax for Modify.

MODIFY itab [FROM wa] [INDEX idx].

[TRANSPORTING f1 ... fn [WHERE cond]].

- MODIFY TABLE itab [FROM wa]

[TRANSPORTING f1 ... fn].

- MODIFY itab [FROM wa]

TRANSPORTING f1 ... fn WHERE cond.

You can modify based on the workarea.

If you want to modify all the records,then you have to use a loop.

Hope this helps.

Message was edited by: Jayanthi Jayaraman

Former Member
0 Kudos

Hi,

See this sample code i got from ABAP Documentation

REPORT demo_int_tables_modify_ind_ind .

DATA name(4) TYPE c VALUE 'COL2'.

DATA: BEGIN OF line,
         col1 TYPE i,
         col2 TYPE i,
      END OF line.

DATA itab LIKE SORTED TABLE OF line WITH UNIQUE KEY col1.

DO 4 TIMES.
  line-col1 = sy-index.
  line-col2 = sy-index ** 2.
  APPEND line TO itab.
ENDDO.

line-col2 = 222.
<b>MODIFY itab FROM line INDEX 2 TRANSPORTING (name).</b>
line-col1 = 3.
line-col2 = 333.
MODIFY itab FROM line INDEX 3.

LOOP AT itab INTO line.
  WRITE: / sy-tabix, line-col1, line-col2.
ENDLOOP.

Hope u got it.

athavanraja
Active Contributor
0 Kudos

you could change your modify stt. to

MODIFY it_test TRANSPORTING counter where matnr is not initial.

Regards

Raja