2007 May 01 10:54 AM
Hi All,
Pls give me Difference between INSERT , APPEND AND COLLECT and
Also what is SANDBOX in the system landscape,how it is differ from other landscapes (i.e, DEV,QA,PROD).
Pls provide the information ASAP,
thanks®ards.
Bharat.
2007 May 01 10:58 AM
Hi bharat,
1. Difference between INSERT , APPEND AND COLLECT
Append = Adds one more record at the LAST
INSERT = Adds one record, (last, middle, top --wherever we specify)
COLLECT = it is used to sum numeric values,
based upon the combination of alpha-numeric fields in the internal table.
2. . SANDBOX is nothing but
another name for DEVELOPMENT Server.
3. This is the originating server.
4. It means
5. All Customization , all developments,
all primary things,
are first done in this server - sand box.
(it is just like sand,
we can give any shape we like)
regards,
amit m.
2007 May 01 11:00 AM
Hi...
<b>Insert</b> inserts at the place mentioned by the primary key values of the workarea or
by the index mentioned by you.
<b>Append</b> it at the end of the table normally. Not sure if key is there ,then it should be according to key it should find place.. otherwise it is added to end of internal table.
<b>collect</b> would add all the numerical columns of the internal table .
For more details , refer to this:
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb36a1358411d1829f0000e829fbfe/content.htm
Sandbox is stand alone server where you can experiment freely like a child plays in a sandbox freely, whereas dev qlty prd are linked ..
2007 May 01 11:01 AM
Hi Bharat
Appending Summarized Lines
The following statement allows you to summate entries in an internal table:
COLLECT <wa> INTO <itab>.
<itab> must have a flat line type, and all of the fields that are not part of the table key must have a numeric type (F, I, or P). You specify the line that you want to add in a work area that is compatible with the line type.
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.
Lines are added to internal tables as follows:
Standard tables
If the COLLECT statement is the first statement to fill the standard table, the system creates a temporary hash administration that identifies existing entries in the table. The hash administration is retained until another statement changes the contents of key fields or changes the sequence of the lines in the internal table. After this, the system finds existing entries using a linear search. The runtime for this operation increases in linear relation to the number of existing table entries. The system field SY-TABIX contains the index of the line inserted or modified in the COLLECT statement.
Sorted tables
The system uses a binary search to locate existing lines. The runtime for the operation increases logarithmically with the number of existing lines. The system field SY-TABIX contains the index of the line inserted or modified in the COLLECT statement.
Hashed tables
The system finds existing lines using the hash algorithm of the internal table. After the COLLECT statement, the system field SY-TABIX has the value 0, since hashed tables have no linear index.
Example
DATA: BEGIN OF LINE,
COL1(3) TYPE C,
COL2(2) TYPE N,
COL3 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE
WITH NON-UNIQUE KEY COL1 COL2.
LINE-COL1 = 'abc'. LINE-COL2 = '12'. LINE-COL3 = 3.
COLLECT LINE INTO ITAB.
WRITE / SY-TABIX.
LINE-COL1 = 'def'. LINE-COL2 = '34'. LINE-COL3 = 5.
COLLECT LINE INTO ITAB.
WRITE / SY-TABIX.
LINE-COL1 = 'abc'. LINE-COL2 = '12'. LINE-COL3 = 7.
COLLECT LINE INTO ITAB.
WRITE / SY-TABIX.
LOOP AT ITAB INTO LINE.
WRITE: / LINE-COL1, LINE-COL2, LINE-COL3.
ENDLOOP.
The output is:
1
2
1
abc 12 10
def 34 5
Appending Table Lines
There are several ways of adding lines to index tables. The following statements have no equivalent that applies to all internal tables.
Appending a Single Line
To add a line to an index table, use the statement:
APPEND <line> TO <itab>.
<line> is either a work area that is convertible to the line type, or the expression INITIAL LINE. If you use <wa>, the system adds a new line to the internal table <itab> and fills it with the contents of the work area. INITIAL LINE appends a blank line containing the correct initial value for each field of the structure. After each APPEND statement, the system field SY-TABIX contains the index of the appended line.
Appending lines to standard tables and sorted tables with a non-unique key works regardless of whether lines with the same key already exist in the table. Duplicate entries may occur. A runtime error occurs if you attempt to add a duplicate entry to a sorted table with a unique key. Equally, a runtime error occurs if you violate the sort order of a sorted table by appending to it.
Appending Several Lines
You can also append internal tables to index tables using the following statement:
APPEND LINES OF <itab1> TO <itab2>.
This statement appends the whole of ITAB1 to ITAB2. ITAB1 can be any type of table, but its line type must be convertible into the line type of ITAB2.
When you append an index table to another index table, you can specify the lines to be appended as follows:
APPEND LINES OF <itab1> [FROM <n1>] [TO <n 2>] TO <itab2>.
<n 1 > and <n 2 > specify the indexes of the first and last lines of ITAB1 that you want to append to ITAB2.
This method of appending lines of one table to another is about 3 to 4 times faster than appending them line by line in a loop. After the APPEND statement, the system field SY-TABIX contains the index of the last line appended. When you append several lines to a sorted table, you must respect the unique key (if defined), and not violate the sort order. Otherwise, a runtime error will occur.
Inserting Lines into Tables
You can insert lines into internal tables either singly or in groups:
Inserting a Single Line
To add a line to an internal table, use the statement:
INSERT <line> INTO TABLE <itab>.
<line> is either a work area that is compatible with the line type, or the expression INITIAL LINE. The work are must be compatible because the fields in the table key must be filled from fields of the correct type. INITIAL LINE inserts a blank line containing the correct initial value for each field of the structure.
If the table has a unique key and you attempt to insert lines whose key already exists in the table, the system does not add the line to the table, and sets SY-SUBRC to 4. When the system successfully adds a line to the table, SY-SUBRC is set to 0.
Reagrds
Rk
2007 May 01 11:10 AM
hi
i think the explanation along with the following examples is self explanatory.
read that once n complie the code 2 understand it in a better way.
plz let me know if the following stuff helps u
APPEND
Syntax : APPEND line_spec TO itab [SORTED BY comp] [result].
This statement appends one or more rows line_spec to an internal index table itab. If itab is a standard table, you can use SORTED BY to sort the table in a specified way. Use result when appending a single row as of release 6.10 to set a reference to the appended row in the form of a field symbol or a data reference.
For the individual table types, appending is done as follows:
To standard tables, rows are appended directly and without checking the content of the internal table.
To sorted tables, rows are appended only if they correspond to the sort sequence and do not create duplicate entries with unique table key. Otherwise, an untreatable exception is triggered.
To hashed tables, no rows can be appended.
DATA:
BEGIN OF FS_AIRLINE,
CARRID(5) TYPE C, " Carrier id
FLICONNID(4) TYPE N, " Connection id
FLITDATE LIKE SY-DATUM, " Flight date
END OF FS_AIRLINE.
"----
Internal table to hold Flight details *
"----
DATA:
T_AIRLINE LIKE
STANDARD TABLE
OF FS_AIRLINE
WITH NON-UNIQUE KEY FLICONNID.
PERFORM POPULATE_TABLE.
PERFORM DISPLAY_TABLE.
&----
*& Form POPULATE_TABLE *
&----
This subroutine populates the internal table with flight details. *
----
There are no interface parameters to be passed to this subroutine. *
----
FORM POPULATE_TABLE.
CLEAR FS_AIRLINE.
FS_AIRLINE-CARRID = 'AA'.
FS_AIRLINE-FLICONNID = '0017'.
FS_AIRLINE-FLITDATE = '19991212'.
APPEND FS_AIRLINE TO T_AIRLINE.
CLEAR FS_AIRLINE.
FS_AIRLINE-CARRID = 'DL'.
FS_AIRLINE-FLICONNID = '1984'.
FS_AIRLINE-FLITDATE = '20000506'.
APPEND FS_AIRLINE TO T_AIRLINE.
CLEAR FS_AIRLINE.
FS_AIRLINE-CARRID = 'AA'.
FS_AIRLINE-FLICONNID = '0026'.
FS_AIRLINE-FLITDATE = '19990804'.
APPEND FS_AIRLINE TO T_AIRLINE.
CLEAR FS_AIRLINE.
FS_AIRLINE-CARRID = 'UA'.
FS_AIRLINE-FLICONNID = '0941'.
FS_AIRLINE-FLITDATE = '20001111'.
APPEND FS_AIRLINE TO T_AIRLINE.
CLEAR FS_AIRLINE.
FS_AIRLINE-CARRID = 'LH'.
FS_AIRLINE-FLICONNID = '1699'.
FS_AIRLINE-FLITDATE = '20000201'.
APPEND FS_AIRLINE TO T_AIRLINE.
CLEAR FS_AIRLINE.
FS_AIRLINE-CARRID = 'LH'.
FS_AIRLINE-FLICONNID = '0026'.
FS_AIRLINE-FLITDATE = '19770901'.
APPEND FS_AIRLINE TO T_AIRLINE.
ENDFORM. " POPULATE_TABLE
&----
*& Form DISPLAY_TABLE *
&----
This subroutine displays the contents of internal table. *
----
There are no interface parameters to be passed to this subroutine. *
----
FORM DISPLAY_TABLE.
LOOP AT T_AIRLINE INTO FS_AIRLINE.
WRITE:
/10 FS_AIRLINE-CARRID,
20 FS_AIRLINE-FLICONNID,
50 FS_AIRLINE-FLITDATE.
ENDLOOP. " LOOP AT T_AIRLINE...
INSERT - line_spec
Syntax
...
| {INITIAL LINE}
| {LINES OF jtab [FROM idx1] [TO idx2]} ... .
Effect
You can insert a work area wa, an initial line INITIAL LINE or multiple lines of an internal table jtab.
DATA: BEGIN OF connection,
cityfrom TYPE spfli-cityfrom,
cityto TYPE spfli-cityto,
distid TYPE spfli-distid,
distance TYPE spfli-distance,
END OF connection.
DATA connection_tab LIKE SORTED TABLE OF connection
WITH UNIQUE KEY cityfrom cityto
distid distance.
SELECT cityfrom cityto distid distance
FROM spfli
INTO connection.
INSERT connection INTO TABLE connection_tab.
ENDSELECT.
COLLECT - result
Syntax
... { ASSIGNING <fs> }
| { REFERENCE INTO dref }... .
Effect
With the ASSIGNING addition, the inserted or existing row is assigned to a field symbol <fs> and with the REFERENCE INTO addition, a reference to the inserted or existing row is set in a reference variable.
The syntax and meaning are the same as when specifying the output behavior in the READ TABLE statement and the same restrictions regarding the manipulation of key fields for sorted and hashed tables apply
regards,
kiran kumar k