Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

collect

Former Member
0 Likes
1,486

can u guys explain contact,read,modify,append,editor call,insert with an example.

1 ACCEPTED SOLUTION
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
1,097

HI,

COLLECT:

is used to sum up all the numeric values of a workarea into an internal table record with same key as that of the workarea.

READ to read from an internal table based on index or using key (WITH KEY).

MODIFY is used to modify the records of an internal table either changing all the fields or only some fields using the option TRANSPORTING.

MODIFY can also be used for DB tables where it inserts the record if it does not exist else updates the record.

append is used to append records to internal tables of type STANDARD and SORTED.

EDITOR-CALL

This statement starts the ABAP editor for the source text of the program specified in prog. prog has to be a character-type data object, which contains the name of a program in capital letters that exists in the Repository. Otherwise you will get a corresponding status message.

After starting the ABAP editor, it provides the full functionality, as if called from the ABAP-Workbench. You can navigate forward to branch to other tools. After returning from the ABAP-editor, the current program continues after the statement EDITOR-CALL.

INSERT:

again can be used for internal tables of type to insert records into it. For database tables also can be used. check out the syntax for both of them.

Best Regards,

Sesh

5 REPLIES 5
Read only

Former Member
0 Likes
1,097

hii vijay

please read this

Syntax Diagram

COLLECT

Basic form

COLLECT [wa INTO] itab.

Extras:

1. ... ASSIGNING <fs>

2. ... REFERENCE INTO dref

3. ... SORTED BY f

The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See Cannot Use Short Forms in Line Operations.

Effect

COLLECT allows you to create unique or summarized datasets. The system first tries to find a table entry corresponding to the table key. (See also Defining Keys for Internal Tables). The key values are taken either from the header line of the internal table itab, or from the explicitly-specified work area wa. The line type of itab must be flat - that is, it cannot itself contain any internal tables. All the components that do not belong to the key must be numeric types ( ABAP Numeric Types).

If the system finds an entry, the numeric fields that are not part of the table key (see ABAPNumeric Types) are added to the sum total of the existing entries. If it does not find an entry, the system creates a new entry instead.

The way in which the system finds the entries depends on the kind of the internal table:

STANDARD TABLE:

The system creates a temporary hash administration for the table to find the entries. This means that the runtime required to find them does not depend on the number of table entries. The administration is temporary, since it is invalidated by operations (such as DELETE, INSERT, MODIFY, or SORT). A subsequent COLLECT is then no longer independent of the table size, because the system has to use a linear search to find entries. For this reason, you should only use COLLECT to fill standard tables.

SORTED TABLE:

The system uses a binary search to find the entries. There is a logarithmic relationship between the number of table entries and the search time.

HASHED TABLE:

The system uses the internal hash administration of the table to find records. Since (unlike standard tables), this remains intact even after table modification operations, the search time is always independent of the number of table entries.

For standard tables and SORTED TABLEs, the system field SY-TABIX contains the number of the existing or newly-added table entry after the COLLECT. With HASHED TABLEs, SY-TABIX is set to 0.

Notes

COLLECT allows you to create a unique or summarized dataset, and you should only use it when this is necessary. If neither of these characteristics are required, or where the nature of the table in the application means that it is impossible for duplicate entries to occur, you should use INSERT [wa INTO] TABLE itab instead of COLLECT. If you do need the table to be unique or summarized, COLLECT is the most efficient way to achieve it.

If you use COLLECT with a work area, the work area must be compatible with the line type of the internal table.

If you edit a standard table using COLLECT, you should only use the COLLECT or MODIFY ... TRANSPORTING f1 f2 ... statements (where none of f1, f2, ... may be in the key). Only then can you be sure that:

-The internal table actually is unique or summarized

-COLLECT runs efficiently. The check whether the dataset

already contains an entry with the same key has a constant

search time (hash procedure).

If you use any other table modification statements, the check for entries in the dataset with the same key can only run using a linear search (and will accordingly take longer). You can use the function module ABL_TABLE_HASH_STATE to test whether the COLLECT has a constant or linear search time for a given standard table.

Example

Summarized sales figures by company:

TYPES: BEGIN OF COMPANY,

NAME(20) TYPE C,

SALES TYPE I,

END OF COMPANY.

DATA: COMP TYPE COMPANY,

COMPTAB TYPE HASHED TABLE OF COMPANY

WITH UNIQUE KEY NAME.

COMP-NAME = 'Duck'. COMP-SALES = 10. COLLECT COMP INTO COMPTAB.

COMP-NAME = 'Tiger'. COMP-SALES = 20. COLLECT COMP INTO COMPTAB.

COMP-NAME = 'Duck'. COMP-SALES = 30. COLLECT COMP INTO COMPTAB.

Table COMPTAB now has the following contents:

NAME | SALES

-


Duck | 40

Tiger | 20

Addition 1

... ASSIGNING <fs>

Effect

If this statement is successfully executed, the field symbol <fs> is set to the changed or new entry. Otherwise the field symbol remains unchanged.

Addition 2

... REFERENCE INTO dref

Effect

If this statement is successfully executed the reference to the relevant line is placed in dref. Otherwise the data reference dref remains unchanged.

Addition 3

... SORTED BY f

Effect

COLLECT ... SORTED BY f is obsolete, and should no longer be used. It only applies to standard tables, and has the same function as APPEND ... SORTED BY f, which you should use instead. (See also Obsolete Language Elements).

Note

Performance:

If you are still using internal tables with headers but, as recommended, keep your data in work areas with a different name, you do not need to assign the data to the header first in order to pass it to the internal tables. Instead, you should use the work area directly as with tables without headers. For example, "APPEND wa TO itab." is roughly twice as fast as "itab = wa. APPEND itab.". The same applies to COLLECT and INSERT.

The runtime of a COLLECT increases with the width of the table key and the number of numeric fields whose contents are summated.

Exceptions

Catchable Exceptions

CX_SY_ARITHMETIC_OVERFLOW

Cause: Overflow in the integer field when forming totals

Runtime Error: COLLECT_OVERFLOW

Cause: overflow in type P field when forming totals

Runtime Error: COLLECT_OVERFLOW_TYPE_P

Non-Catchable Exceptions

Cause: COLLECT on non-numeric fileds

Runtime Error: TABLE_COLLECT_CHAR_IN_FUNCTION

reward if useful

vikaas

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
1,098

HI,

COLLECT:

is used to sum up all the numeric values of a workarea into an internal table record with same key as that of the workarea.

READ to read from an internal table based on index or using key (WITH KEY).

MODIFY is used to modify the records of an internal table either changing all the fields or only some fields using the option TRANSPORTING.

MODIFY can also be used for DB tables where it inserts the record if it does not exist else updates the record.

append is used to append records to internal tables of type STANDARD and SORTED.

EDITOR-CALL

This statement starts the ABAP editor for the source text of the program specified in prog. prog has to be a character-type data object, which contains the name of a program in capital letters that exists in the Repository. Otherwise you will get a corresponding status message.

After starting the ABAP editor, it provides the full functionality, as if called from the ABAP-Workbench. You can navigate forward to branch to other tools. After returning from the ABAP-editor, the current program continues after the statement EDITOR-CALL.

INSERT:

again can be used for internal tables of type to insert records into it. For database tables also can be used. check out the syntax for both of them.

Best Regards,

Sesh

Read only

Former Member
0 Likes
1,097

Inserts new lines or updates existing lines in a database table (s. relational database). If a line with the specified primary key already exists, an UPDATE is executed. Otherwise, an INSERT is performed. You can specify the name of the database table either in the program itself in the form MODIFY dbtab ... or at runtime as the contents of the variable dbtabname in the form MODIFY (dbtabname) .... In both cases, the database table must be defined in the ABAP Dictionary. If the program contains the name of the database table, it must also have a corresponding TABLES statement. Normally, records are inserted or updated only in the current client. Data can only be inserted or updated using a view, if the view refers to a single table and was created in the ABAP Dictionary with the maintenance status "No restriction".

example

DATA: wa TYPE scustom.

wa-id = '12400177'.

wa-name = 'Robinson'.

wa-postcode = '69542'.

wa-city = 'Heidelberg'.

wa-custtype = 'P'.

wa-discount = '003'.

wa-telephone = '06201/44889'.

MODIFY scustom FROM wa.

read:

Reads an entry from an internal table, using either its key or its index. The return code SY-SUBRC specifies whether an entry could be read. If you specify a non-unique key (the table must have a NON-UNIQUE key for this to be valid), the system returns the entry with the lowest index from the set of entries that meet the condition

READ TABLE itab FROM wa [ additions].

2. READ TABLE itab WITH TABLE KEY k1 = v1 ... kn = vn [additions].

3. READ TABLE itab WITH KEY k1 = v1 ... kn = vn [BINARY SEARCH] [additions].

4. READ TABLE itab INDEX i [additions].

append

Appends a new line to the end of the internal table itab. You can only use this variant with index tables (standard or sorted table).

APPEND [wa TO|INITIAL LINE TO] itab[ASSIGNING <fs> |REFERENCE INTO dref].

2. APPEND LINES OF itab1 [FROM idx1] [TO idx2] TO itab2.

3. APPEND [wa TO] itab SORTED BY f [ASSIGNING <fs>

|REFERENCE INTO dref].

Editor call

Displays the internal table itab in an editor similiar to the ABAP Editor. You can then use normal editor functions to make changes.

Changes to the table contents are only adopted if you save before leaving the editor.

DATA: BEGIN OF T OCCURS 200,

TEXT1(60),TEXT2(12),

END OF T.

T-TEXT1 = 'Text 1'. T-TEXT2 = 'A'. APPEND T.

T-TEXT1 = 'Text 2'. T-TEXT2 = 'B'. APPEND T.

T-TEXT1 = 'Text 3'. T-TEXT2 = 'C'. APPEND T.

T-TEXT1 = 'Text 4'. T-TEXT2 = 'D'. APPEND T.

EDITOR-CALL FOR T TITLE 'Editor for internal tables'.

LOOP AT T.

WRITE: / T-TEXT1, T-TEXT2.

ENDLOOP.

collect

COLLECT allows you to create unique or summarized datasets. The system first tries to find a table entry corresponding to the table key. (See also Defining Keys for Internal Tables). The key values are taken either from the header line of the internal table itab, or from the explicitly-specified work area wa. The line type of itab must be flat - that is, it cannot itself contain any internal tables. All the components that do not belong to the key must be numeric types ( ABAP Numeric Types).

TYPES: BEGIN OF COMPANY,

NAME(20) TYPE C,

SALES TYPE I,

END OF COMPANY.

DATA: COMP TYPE COMPANY,

COMPTAB TYPE HASHED TABLE OF COMPANY

WITH UNIQUE KEY NAME.

COMP-NAME = 'Duck'. COMP-SALES = 10. COLLECT COMP INTO COMPTAB.

COMP-NAME = 'Tiger'. COMP-SALES = 20. COLLECT COMP INTO COMPTAB.

COMP-NAME = 'Duck'. COMP-SALES = 30. COLLECT COMP INTO COMPTAB.

Table COMPTAB now has the following contents:

NAME | SALES

-


Duck | 40

Tiger | 20

Read only

Former Member
0 Likes
1,097

Hi Vijay

Let me come up with a simple answer!

<b>COLLECT:</b> This keyword is used to sum up all the records' numeric fields in an internal table. i.e, say there is an internal table with two fields: w_char and w_int of types CHAR and INT respectively. A collect operation will result in adding up of w_int for all the records which have same value for w_char.

<b>READ:</b> This statement reads any specified record of an internal table based on the index/key.

<b>MODIFY:</b> This modifies the mentioned record from the internal table. The modification can be controlled for only a few fields by using the extension <b>transporting</b>

<b>APPEND:</b> This appends a new record to an internal table.

<b>INSERT:</b> This adds a new record to the internal table...

I strongly suggest you to go through the SAP library help in detail for a deep understanding of internal tables, as these are the heart of ABAP programming.

Reward points if useful

Regards

Read only

Former Member
0 Likes
1,097