‎2007 Dec 30 6:28 AM
Hello,
What is the difference between COLLECT and INSERT statements in ABAP? Seems like both inserts a new record.
Thanks
‎2007 Dec 30 6:32 AM
‎2007 Dec 30 6:35 AM
Hi,
collesct statement eliminates the duplicate records, and also it sum up of the same type of records in workareal level and store at the internal table. those which r different records append at the sum of records.
insert statement is used to insert a new record in the database are internal table level..
no collect will sum up the records,
insert will insert the new records.
please reward points, if it is helpful to u.
regards,
satish.
‎2007 Dec 30 6:46 AM
Hi,
when collect is executed, the system forms a key from the default key fields in the work area. the default key fields are characterr fields
the system then searches the body of the internal table for a row that has the same key as the key in the work area.
if it doesn't find one, the record is appended as a last record.
if it does find one, the numeric fields in the work area are added to the corresponding fields in the found row.
modify is used to modify records
collect is used to avoid duplicate records.
‎2007 Dec 31 4:36 AM
Hi Sachin
pls go thru the below material.
Pls reward pts.
regards
Deepanker.
Collect:
When the line is inserted, the system checks whether there is already a table entry that matches the key. If there is no corresponding entry already in the table, the COLLECT statement has the same effect as inserting the new line. If an entry with the same key already exists, the COLLECT statement does not append a new line, but adds the contents of the numeric fields in the work area to the contents of the numeric fields in the existing entry.
You should only use the COLLECT statement if you want to create summarized tables. If you use other statements to insert table entries, you may end up with duplicate entries.
INSERT - Insert in a database table
Variants
1. INSERT INTO dbtab VALUES wa. or
INSERT INTO (dbtabname) VALUES wa.
2. INSERT dbtab. or
INSERT *dbtab. or
INSERT (dbtabname) ...
3. INSERT dbtab FROM TABLE itab. or
INSERT (dbtabname) FROM TABLE itab.
Effect
Inserts new lines in a database table .
You can specify the name of the database table either in the program itself in the form dbtab or at runtime as the contents of the field dbtabname . In both cases, the database table must be defined in the ABAP/4 Dictionary . If the program contains the name of the database table, it must also include a corresponding TABLES statement. Normally, lines are inserted only in the current client. Data can only be inserted using a view if the view refers to a single table and was defined in the ABAP/4 Dictionary with the maintenance status "No restriction".
INSERT belongs to the Open SQL command set.
Notes
You cannot insert a line if a line with the same primary key already exists or if a UNIQUE index already has a line with identical key field values.
When inserting lines using a view , all fields of the database table that are not in the view are set to their initial value (see TABLES ) - if they were defined with NOT NULL in the ABAP/4 Dictionary . Otherwise they are set to NULL .
Since the INSERT statement does not perform authorization checks , you must program these yourself.
Lines specified in the INSERT command are not actually added to the database table until after the next ROLLBACK WORK . Lines added within a transaction remain locked until the transaction has finished. The end of a transaction is either a COMMIT WORK , where all database changes performed within the transaction are made irrevocable, or a ROLLBACK WORK , which cancels all database changes performed within the transaction.