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: 

NEW INSERT WITH MODIFY

divsmart
Participant
0 Kudos

Hi i am new to SAP have a doubt , can anyone clarify it.. I have this program

Here need to change Pname(record from AC TO TC) i used modify but not working...

TYPES: BEGIN OF ty_product,

pid(10) TYPE c,

pname(20) TYPE c,

pamount TYPE i,

END OF ty_product.

DATA: it TYPE TABLE OF ty_product,

wa TYPE ty_product. DATA:

gv_tabix TYPE sy-tabix.

* Index1 wa-pid = 'IFB1'.

wa-pname = 'WASHING MACHINE'.

wa-pamount = 31000.

INSERT wa INTO TABLE it. *

Index2 wa-pid = 'IFB2'.

wa-pname = 'FRIDGE'.

wa-pamount = 32000.

INSERT wa INTO TABLE it.

*Index3 wa-pid = 'IFB3'.

wa-pname = 'AC'.

wa-pamount = 35000.

INSERT wa INTO TABLE it.

LOOP AT it INTO wa.

IF sy-subrc = 0.

gv_tabix = sy-tabix.

MODIFY it FROM wa INDEX gv_tabix TRANSPORTING pname .

wa-pname = 'TV'. * MODIFY it FROM wa INDEX 3 TRANSPORTING pname.

* READ TABLE it INTO wa INDEX gv_tabix.

* MODIFY it FROM wa INDEX 3 TRANSPORTING pname .

WRITE: / wa-pid , wa-pname , wa-pamount.

ELSE.

WRITE: 'No record found'.

ENDIF.

ENDLOOP.

1 ACCEPTED SOLUTION

mohit_dev
Contributor
0 Kudos

First of all, make sure your code is reviewed.

As far as your code is concerned, make the below change. (It's a basic change, which will get the desired output for you, but not advisable to full extent, in case we modify inside loop)

Inside your loop

IF sy-subrc = 0.
    gv_tabix = sy-tabix.
    IF wa-pname = 'AC'.
      wa-pname = 'TV'.
      MODIFY it FROM wa INDEX gv_tabix TRANSPORTING pname .
    ENDIF.
3 REPLIES 3

mohit_dev
Contributor
0 Kudos

First of all, make sure your code is reviewed.

As far as your code is concerned, make the below change. (It's a basic change, which will get the desired output for you, but not advisable to full extent, in case we modify inside loop)

Inside your loop

IF sy-subrc = 0.
    gv_tabix = sy-tabix.
    IF wa-pname = 'AC'.
      wa-pname = 'TV'.
      MODIFY it FROM wa INDEX gv_tabix TRANSPORTING pname .
    ENDIF.

former_member1716
Active Contributor
0 Kudos

Hello senthil gajendran,

Kindly use the CODE button to paste the code lines.

About the solution, The sequence in which you have written the code is wrong. Before you write MODIFY statement you should have assigned the value in Work area. What you have done is you are modifying the the table before the value is assigned.

By doing the below code change your code should work. To explain you are modifying the internal table from work area which is holding the value that needs to be changed.

By mentioning the TRANSPORTING Keyword you are explicitly mentioning which field needs to be changed. Hope you understood the concepts.

wa-pname = 'TV'. 
MODIFY it FROM wa INDEX gv_tabix TRANSPORTING pname .

Regards!

Sandra_Rossi
Active Contributor
0 Kudos

Please use the CODE button to format your code so that it's shown in a more user-friendly format (colorized).