Skip to Content
-1

NEW INSERT WITH MODIFY

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.

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    Posted on Oct 23, 2019 at 12:03 PM

    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.
    
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 23, 2019 at 12:11 PM

    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!

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.