Internal table can be
edited as per requirement. We can modify one particular record when it is
required. Two kinds of statements can be used to modify one single line.
MODIFY TABLE internal_tab FROM work_area.
MODIFY internal_tab FROM work_area INDEX sy-tabix TRANSPORTING field1 field2.
Note that by these
statements one single line can be modified. We can add more fields as per
requirement. We can modify any type of internal table by these statements. After
modification the old record is lost completely from the table. If we store it
to any outer structure before modification then the old record can be reused.
REPORT zabap_gui.
* Declaring the local structure of internal table
TYPES:
BEGIN OF ty_tab,
item TYPE char10,
quantity TYPE i,
price TYPE i,
END OF ty_tab.
* Declaring the Standard internal table with non unique key
DATA:
itab TYPE STANDARD TABLE OF ty_tab,
wtab TYPE ty_tab.
* Entering records to each field
wtab-item = 'Rice'. wtab-quantity = 2. wtab-price = 80.
* Now one single row has been fulfilled with data
* Next appending one single row data into the table
APPEND wtab TO itab.
wtab-item = 'Suger'. wtab-quantity = 1. wtab-price = 90.
APPEND wtab TO itab.
wtab-item = 'Tea'. wtab-quantity = 1. wtab-price = 100.
APPEND wtab TO itab.
wtab-item = 'Rice'. wtab-quantity = 3. wtab-price = 150.
APPEND wtab TO itab.
wtab-item = 'Horlicks'. wtab-quantity = 1. wtab-price = 200.
APPEND wtab TO itab.
wtab-item = 'Suger'. wtab-quantity = 2. wtab-price = 70.
APPEND wtab TO itab.
WRITE: /3 'Item',
13 'Quantity(KG)',
28 'Price(Rs)'.
WRITE / '=========================================='.
SKIP. " Skipping one single line
LOOP AT itab INTO wtab.
WRITE: /3 wtab-item,
12 wtab-quantity,
25 wtab-price.
ENDLOOP.
SKIP.
WRITE '=========================================='.
SKIP.
LOOP AT itab INTO wtab.
IF wtab-item = 'Horlicks'.
wtab-item = 'Complan'.
wtab-price = 220.
MODIFY TABLE itab FROM wtab.
ENDIF.
WRITE: /3 wtab-item,
12 wtab-quantity,
25 wtab-price.
ENDLOOP.
* Declaring the local structure of internal table
TYPES:
BEGIN OF ty_tab,
item TYPE char10,
quantity TYPE i,
price TYPE i,
END OF ty_tab.
* Declaring the Standard internal table with non unique key
DATA:
itab TYPE STANDARD TABLE OF ty_tab,
wtab TYPE ty_tab.
* Entering records to each field
wtab-item = 'Rice'. wtab-quantity = 2. wtab-price = 80.
* Now one single row has been fulfilled with data
* Next appending one single row data into the table
APPEND wtab TO itab.
wtab-item = 'Suger'. wtab-quantity = 1. wtab-price = 90.
APPEND wtab TO itab.
wtab-item = 'Tea'. wtab-quantity = 1. wtab-price = 100.
APPEND wtab TO itab.
wtab-item = 'Rice'. wtab-quantity = 3. wtab-price = 150.
APPEND wtab TO itab.
wtab-item = 'Horlicks'. wtab-quantity = 1. wtab-price = 200.
APPEND wtab TO itab.
wtab-item = 'Suger'. wtab-quantity = 2. wtab-price = 70.
APPEND wtab TO itab.
WRITE: /3 'Item',
13 'Quantity(KG)',
28 'Price(Rs)'.
WRITE / '=========================================='.
SKIP. " Skipping one single line
LOOP AT itab INTO wtab.
WRITE: /3 wtab-item,
12 wtab-quantity,
25 wtab-price.
ENDLOOP.
SKIP.
WRITE '=========================================='.
SKIP.
LOOP AT itab INTO wtab.
IF wtab-item = 'Horlicks'.
wtab-item = 'Complan'.
wtab-price = 220.
MODIFY TABLE itab FROM wtab.
ENDIF.
WRITE: /3 wtab-item,
12 wtab-quantity,
25 wtab-price.
ENDLOOP.
Here the item Horlicks has been modified to Complan.
7 comments:
Above MODIFY statement won't work as you are modifying the key itself. You are able to see the output just because you have written the content of work area.
SAP Success Factors Real Time Hands on Training in Chennai...
Don't always Depend on Training Institute Alone and so please aware of Best Trainers too..
http://thecreatingexperts.com/sap-successfactors-training-in-chennai/
If You need a Best Trainer over SAP Success Factors Means??? Please ready for an DEMO From the Trainer MR.Karthick
CONTACT:8122241286
Both Classroom/Online Training is Available!!!!!!
Informative Blog...For a long time I was craving for a career growth in programming and then I came to know that THE CREATING EXPERTS is the one who provide training with hands on training and real time scenarios
http://thecreatingexperts.com/sap-abap-training-in-chennai/
contact 8122241286
Thanks for your info...Here THE CREATING EXPERTS provide hands on training with real time scenarios
http://thecreatingexperts.com/sap-abap-training-in-chennai/
contact +91-08122241286
This site has lots of advantage awesome i really enjoyed reading thanks for sharing for grate info ..sap-hr abap online classes
I am not able to see the correct output. Actually it is not modifying using this program .
Post a Comment