‎2009 Jun 03 7:06 AM
Dear All,
Can anyone pls. give me the syntax of modify statement of internal table using where clause.
Thanks and Regards,
Sohail
‎2009 Jun 03 8:25 AM
Hi,
Try using code like the following
modify itab where condition
or use update
update table set field = fieldname
where condition
Regards,
Ibrar
‎2009 Jun 03 7:10 AM
hi
here is an example of modify statement...
data: idx type sy-tabix.
loop at it_final INTO wa_final.
idx = sy-tabix.
CLEAR wa_afru.
IF sy-subrc is INITIAL.
READ TABLE it_afru INTO wa_afru with key aufnr = wa_final-aufnr.
SORT it_afru DESCENDING.
wa_final-budat = wa_afru-budat.
*modify it_final from wa_final index idx TRANSPORTING budat.*
ENDIF.
clear: wa_final, idx.
ENDLOOP.
‎2015 Oct 14 4:50 AM
‎2009 Jun 03 7:10 AM
Hello
From SAP Help:
DATA: BEGIN OF TAB OCCURS 500,
FLAG TYPE C,
COMP(20) TYPE C,
END OF TAB.
CLEAR TAB-FLAG.
MODIFY TAB TRANSPORTING FLAG WHERE FLAG = 'X'.
‎2009 Jun 03 7:15 AM
Hi
Refer to the following index.
MODIFY <itab> FROM <wa> WHERE<condition>.
Hope it helps.
Regards
Rajesh Kumar
‎2009 Jun 03 7:16 AM
Hi Sohail,
Do not delete the records of internal table inside the Loop u2013 End loop.
Do not use: LOOP AT ITAB WHERE EQUNR = u201800001011u2019.
DELETE ITAB.
ENDLOOP.
Use: DELETE ITAB WHERE EQUNR = u201800001011u2019.
Use the MODIFY ITAB ... TRANSPORTING f1 f2 ... for single line, and MODIFY ITAB ... TRANSPORTING f1 f2 ... WHERE condition for a set of line, to accelerate the updating of internal table
If possible, Update/Insert statement is used instead of Modify.
Check these code :
LOOP AT TAB.
IF TAB-FLAG IS INITIAL.
TAB-FLAG = 'X'.
ENDIF.
MODIFY TAB.
ENDLOOP.
TAB-FLAG = 'X'.
MODIFY TAB TRANSPORTING FLAG
WHERE FLAG IS INITIAL.
Reg,
Siva
‎2009 Jun 03 7:16 AM
hi, plz search sap help
Taken from sap library.....
MODIFY itab [FROM wa] TRANSPORTING f1 ... fn WHERE cond.
Effect
Changes several entries in the internal table itab. You can use this variant for any table.
You can use " FROM wa" and "TRANSPORTING f1 ... fn" as in variant 1. If the table has the type SORTED TABLE or HASHED TABLE, the TRANSPORTING list may not contain key fields.
In comparisons within the logical expression cond, the first operand must always be a subfield of the line structure of itab.
The Return Code is set as follows:
SY-SUBRC = 0:
At least one entry was changed.
SY-SUBRC = 4:
None of the entries was changed.
Notes
When you use the WHERE condition with a STANDARD or HASHED table, a full table scan is always required.
If you are working with a SORTED TABLE, the partial sequential processing can be optimized so that only the entries that actually satisfy the WHERE condition are processed. This optimization requires that each sub-condition is linked with AND; that no parentheses are used; that at least one sub-condition is in the form k = v; and that the conditions in the form k1 = v1 ... kn = vn cover at least the first part of the table key.
The starting point for the loop is specified using a binary search with the sub-conditions that cover the table key (partially or completely). This optimization is similar to the optimization in the READ statement. The loop is only processed from the starting point to the point where these sub-conditions are still met. (See also Optimized Key Operations in Internal Tables).
You can replace any operand in the WHERE condition with a functional method - unless it is a subfield in a line structure of the relevant internal table. Functional methods are methods in ABAP Objects that can have any number of IMPORTING parameters, but have only one RETURNING parameter.
If the line type of the internal table is - or contains - object reference variables, the attributes of the object (to which the reference of the line points) can be used as comparison values in the WHERE condition. (See Object Attributes as Keys in Internal Tables).
Example
Reset a status flag universally
DATA: BEGIN OF TAB OCCURS 500,
FLAG TYPE C,
COMP(20) TYPE C,
END OF TAB.
CLEAR TAB-FLAG.
MODIFY TAB TRANSPORTING FLAG WHERE FLAG = 'X'.
Regards,
Sakthi Sri.
‎2009 Jun 03 7:26 AM
‎2009 Jun 03 7:31 AM
Sohail,
Ues this..
Loop at itab into wa.
modify itab from wa transporting f1.
Regards,
Vijay
‎2009 Jun 03 8:25 AM
Hi,
Try using code like the following
modify itab where condition
or use update
update table set field = fieldname
where condition
Regards,
Ibrar
‎2009 Jun 03 8:30 AM
Well.. to inform you
Modify and is a statement which acts like
INSERT and
UPDATE
i.e:-
--- If no record exists with the given key, than it will insert a new ROW.
---and if a record already exits with the given key, that it will EDIT it or update it.
‎2009 Jun 03 8:40 AM
The question is for internal tables. MODIFY works with internal tables and database tables, but INSERT and UPDATE are only for database tables.
‎2009 Jun 03 9:56 AM
how do you say INSERT cannot be used in an internal table?
wa_final-matnr = 'MATNR'
wa_final-menge4 = '10'.
wa_final-budat = sy-datum
wa_final-check = c_x.
INSERT wa_final INTO it_final INDEX lv_index.
Cant you use INSERT this way in an internal table
‎2009 Jun 03 10:44 AM
You are right, INSERT works also for internal tables. I checked documentation for UPDATE only. So my remark is only for UPDATE.
When I learned ABAP in 1994 (release 2.1), we learned only APPEND and COLLECT commands for inserting in internal tables.
Thank you for your remark. I will now study the differences between APPEND and INSERT.
‎2009 Jun 03 8:36 AM
hi,
go to tcode-se38 i.e abap editor give ur pgm name save it n when u get the editor screen type the key word 'MODIFY' then place d cursor on modify n press F1 u wl get all the syntax for modify statement of internal table using where clause
but for ur convenience i m giving u an example
syntax:-
MODIFY <itab> FROM <wa> TRANSPORTING <f1> <f2> ... WHERE <cond>.
example
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.
INSERT LINE INTO TABLE ITAB.
ENDDO.
LINE-COL2 = 100.
MODIFY ITAB FROM LINE TRANSPORTING COL2
WHERE ( COL2 > 1 ) AND ( COL1 < 4 ).
LOOP AT ITAB INTO LINE.
WRITE: / LINE-COL1, LINE-COL2.
ENDLOOP.
hope it helps u
rgds
shivraj
‎2009 Jun 03 8:37 AM
Hi Sohail,
Before modifying the records in the internal table, just set the value for that field first.
Example:
DATA: BEGIN OF itab OCCURS 0,
year(4) TYPE n,
count TYPE i,
END OF itab.
DATA: wa LIKE itab.
itab-year = '2003'.
itab-count = 20.
APPEND itab.
itab-year = '2004'.
itab-count = 30.
APPEND itab.
itab-year = '2007'.
itab-count = 50.
APPEND itab.
itab-year = '2008'.
itab-count = 60.
APPEND itab.
wa-year = '2009'.
MODIFY itab FROM wa TRANSPORTING year WHERE year LT '2005'.
LOOP AT itab.
WRITE:/5 itab-year, 25 itab-count.
ENDLOOP.
Regards,
Kumar Bandanadham
‎2009 Jun 03 10:54 AM
Hi
MODIFY <jtab> FROM <wa> WHERE<condition>.
just follow above syntax it will work.
regards,
munibabu.K
‎2014 Sep 18 12:27 PM
In below statement WD_THIS->MT_PTRV_SREC is internal table attribute in webdynpro, LW_PTRV_SREC is work area and these are field ZZTAX_REG ZZBILLNO ZZCHEQUE_NO. you should use TRANSPORTING and WHERE addition if you are not writing MODIFYstatement in loop.
MODIFY WD_THIS->MT_PTRV_SREC FROM LW_PTRV_SREC
TRANSPORTING ZZTAX_REG ZZBILLNO ZZCHEQUE_NO
WHERE MANDT = LW_PTRV_SREC-MANDT
AND PERNR = LW_PTRV_SREC-PERNR
AND REINR = LW_PTRV_SREC-REINR
AND PERIO = LW_PTRV_SREC-PERIO.