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

Abap question

Former Member
0 Likes
870

1.what is the difference between CollectStatement and Appendstement?

2.How to create the table Generator?in the Datadictionary?

what is the use?

7 REPLIES 7
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
792

APPEND will add a line to the internal table, COLLECT will search for a key(all character fields to the left of a numeric) if it finds a hit it will add the numeric values to the existing row.

Regards,

Rich Heilman

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
792

You can create a table maintenance in SE11, under the utilites menu. ONce the table maintennace is generated, you can then maintain the table via SM30.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
792

hi ,

Append statement adds Work area(header) to TAble body.. collect statement adds the quatity fileds and stores in same field.

Read only

Former Member
0 Likes
792

Hi,

COLLECT allows you to create unique or summarized datasets. The system first tries to find a table entry corresponding to the table key

EG:

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

<b>Append</b>s a new line to the end of the internal table itab. You can only use this variant with index tables (standard or sorted table)

EG:

DATA: ITAB1 TYPE STANDARD TABLE OF I WITH NON-UNIQUE

DEFAULT KEY INITIAL SIZE 100, ITAB 2 TYPE STANDARD TABLE OF I WITH NON-UNIQUE

DEFAULT KEY INITIAL SIZE 100.

APPEND 2 TO ITAB1.

APPEND 3 TO ITAB1.

APPEND 5 TO ITAB1.

APPEND 7 TO ITAB1.

APPEND 3 TO ITAB2.

APPEND INITIAL LINE TO ITAB2.

APPEND LINES OF ITAB1 FROM 2 TO 20 TO ITAB2.

The table ITAB2 now contains five lines with the values 3, 0, 3, 5 and 7.

2. Goto SE11 -> Table name -> Utilities -> Table maintanance generator. ( Used to enter table data into the table )

Read only

Former Member
0 Likes
792

Hi

For table maintenance generator , refer the following threads

Append statement adds a new record to the internal table

Collect statement adds the quantity fields .

Read only

Former Member
0 Likes
792

Hi,

Appemd simply adds a new row toi the internal table . Collect statement summarizes the reords in the tabe based upon the numeric fields .:

Ex : begin of itab occurs o ,

a type c,

b type i ,

end of itab .

itab-a = 'A' .

itab-b = 15 .

append itab .

itab-a = 'A' .

itab-b = 15 .

append itab .

After this itab will have two rows .

where as :

itab-a = 'A' .

itab-b = 15 .

collect itab .

If there is no row with a =A it will create a new row .

itab-a = 'A' .

itab-b = 15 .

collect itab .

Secodn time when a = A is encountered the existing record ill be changed as a = A and b = 30 . Nonew row is created except it is collected .

To create table generator refer tcode SE54 .

Regards,

Varun .

Read only

Former Member
0 Likes
792

Hai

Check the following

1. specially function group.. what is its significance

When we generate table maintenance,

the system , based upon the table fields,

automatically,

generates

PROGRAM CODE, SCREEN FOR ENTERING DATA,

LOGIC FOR SAVING DATA, LOGIC FOR DISPLAYING DATA

ETC.

2. All this are BUNCHED under

a FUNCTION GROUP

(if you open that function group in se80, after

creatting table maintenacne,

u will see the program code, screens, gui status etc)

3. Hence, to BUNCH all these various objects,

SAP uses the concept of function group.

*----


4. And also why do we need to give two screens there

Its not necessary to have to screens.

5. ONE SCREEN MEANS:

only one screen with table control to enter data

TWO SCREEN means :

first screen : only primary key fields will appear

second screen : rest of the fields will appear to enter data

6. When the table consists of many fields,

its practically more convenient to have two screens,

so that all fields come vertically downwards.

(instead of scrolling horizontally in the table

control, in case of one screen concept)

The use of the FG is only this the Table Maintainance Generator part. Neednt be declared anywhere else.

yes u need to create a FG and the use it in Table maint. gen.

http://help.sap.com/saphelp_erp2005/helpdata/en/a7/513520407a11d1893b0000e8323c4f/frameset.htm - a link for basics on Table Maintenance.

Also, Check out this weblog on table maintenance:

/people/sudheer.cheedella/blog/2006/02/20/extracting-data-in-table-maintenance

Collect

COLLECT

Basic form

COLLECT [wa INTO] itab.

Addition

... SORTED BY f

Effect

COLLECT is used to create unique or compressed datsets. The key fields are the default key fields of the internal table itab .

If you use only COLLECT to fill an internal table, COLLECT makes sure that the internal table does not contain two entries with the same default key fields.

If, besides its default key fields, the internal table contains number fields (see also ABAP/4 number types ), the contents of these number fields are added together if the internal table already contains an entry with the same key fields.

If the default key of an internal table processed with COLLECT is blank, all the values are added up in the first table line.

If you specify wa INTO , the entry to be processed is taken from the explicitly specified work area wa . If not, it comes from the header line of the internal table itab .

After COLLECT , the system field SY-TABIX contains the index of the - existing or new - table entry with default key fields which match those of the entry to be processed.

Notes

COLLECT can create unique or compressed datasets and should be used precisely for this purpose. If uniqueness or compression are unimportant, or two values with identical default key field values could not possibly occur in your particular task, you should use APPEND instead. However, for a unique or compressed dataset which is also efficient, COLLECT is the statement to use.

If you process a table with COLLECT , you should also use COLLECT to fill it. Only by doing this can you guarantee that

the internal table will actually be unique or compressed, as described above and

COLLECT will run very efficiently.

If you use COLLECT with an explicitly specified work area, it must be compatible with the line type of the internal table.

Example

Compressed sales figures for each company

DATA: BEGIN OF COMPANIES OCCURS 10,

NAME(20),

SALES TYPE I,

END OF COMPANIES.

COMPANIES-NAME = 'Duck'. COMPANIES-SALES = 10.

COLLECT COMPANIES.

COMPANIES-NAME = 'Tiger'. COMPANIES-SALES = 20.

COLLECT COMPANIES.

COMPANIES-NAME = 'Duck'. COMPANIES-SALES = 30.

COLLECT COMPANIES.

The table COMPANIES now has the following appearance:

NAME SALES

Duck 40

Tiger 20

Addition

... SORTED BY f

Effect

COLLECT ... SORTED BY f is obsolete and should no longer be used. Use APPEND ... SORTED BY f which has the same meaning.

Note

Performance

The cost of a COLLECT in terms of performance increases with the width of the default key needed in the search for table entries and the number of numeric fields with values which have to be added up, if an entry is found in the internal table to match the default key fields.

If no such entry is found, the cost is reduced to that required to append a new entry to the end of the table.

A COLLECT statement used on a table which is 100 bytes wide and has a key which is 60 bytes wide and seven numeric fields is about approx. 50 msn (standardized microseconds).

Note

Runtime errors

COLLECT_OVERFLOW : Overflow in integer field when calculating totals.

COLLECT_OVERFLOW_TYPE_P : Overflow in type P field when calculating totals.

Append

APPEND

Variants

1. APPEND [wa TO|INITIAL LINE TO] itab.

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

3. APPEND [wa TO] itab SORTED BY f.

Variant 1

APPEND [wa TO|INITIAL LINE TO] itab.

Effect

Appends a new line to the end of the internal table itab .

If you specify wa TO , the new line is taken from the contents of the explicitly specified work area wa .

If you use INITIAL LINE TO , a line filled with the correct value for the type is added.

If the specification before itab is omitted, the new line is taken from the internal tbale itab .

After the APEND , the system field SY-TABIX contains the index of the newly added table entry.

Examples

Generate a list with customer numbers:

TABLES SCUSTOM.

DATA: CUSTOMER LIKE SCUSTOM-ID OCCURS 0.

APPEND SCUSTOM-ID TO CUSTOMER.

Append a blank line or a line with its initial value to the above list:

APPEND INITIAL LINE TO CUSTOMER

Generate a compressed list with plane data

PARAMETERS: SEATS_LO LIKE SAPLANE-SEATSMAX DEFAULT 30,

SEATS_HI LIKE SAPLANE-SEATSMAX DEFAULT 50.

DATA: PLANE LIKE SAPLANE OCCURS 0,

PLANE_NEEDED LIKE SAPLANE WITH HEADER LINE.

LOOP AT PLANE INTO PLANE_NEEDED

WHERE SEATSMAX BETWEEN SEATS_LO AND SEATS_HI.

APPEND PLANE_NEEDED.

ENDLOOP.

Notes

Performance

In contrast to COLLECT , APPEND does not check whether an entry with the same default key exists. Therefore, it is considerably faster than COLLECT . If the COLLECT logic is not needed or lines with an identical default key cannot occur in a particular situation, you should always use APPEND instead of COLLECT .

The runtime required for APPEND increases with the line width of the table and depends on the number of fields. Appending an entry to an internal table with a width of 111 bytes takes about 9 msn (standardized microseconds).

To append an internal table to another internal table, you should use the variant APPEND LINES OF ... which is 3 to 4 times faster than using a LOOP to process the source table and append the entries line-by-line to the target table.

Variant 2

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

Effect

Appends the internal table itab1 or an extract from itab1 to the end of the internal table itab2 .

By specifying FROM idx1 or TO idx2 you can restrict the line area taken from the source table itab1 . If there is no FROM specification, it begins with the first line of itab1 . If there is no TO specification, it ends with the last line of itab1 . This means that the complete table is appended if neither a FROM nor a TO is specified.

After the APPEND , the system field SY-TABIX contains the index of the last table entry appended, i.e. the total number of entries from both tables.

Note

By comparing the values of SY-TABIX before and after the APPEND statement, you can determine how many lines were appended to the table.

Example

Merge two tables with whole numbers:

DATA: ITAB1 TYPE I OCCURS 100,

ITAB2 TYPE I OCCURS 100.

APPEND 2 TO ITAB1.

APPEND 3 TO ITAB1.

APPEND 5 TO ITAB1.

APPEND 7 TO ITAB1.

APPEND 3 TO ITAB2.

APPEND INITIAL LINE TO ITAB2.

APPEND LINES OF ITAB1 FROM 2 TO 20 TO ITAB2.

The table ITAB2 now contains five lines with the values 3, 0, 3, 5 and 7.

Note

Performance

This variant is 3 to 4 times faster than using a LOOP to process the source table and append the entries line-by-line to the target table.

Variant 3

APPEND [wa TO] itab SORTED BY f.

Effect

Inserts the new entry into table and re-sorts the table by the sub-field f in descending order. This only makes sense if the table was sorted beforehand. When the number of table entries reaches the OCCURS parameter value, the last entry is deleted if the value f of a new entry is greater (particularly suitable for ranked lists). You can only sort by one sub-field.

If you specify wa TO , the new line is taken from the contents of the explicitly specified work area wa . Otherwise, it comes from the header line of the internal table itab .

Example

DATA: BEGIN OF COMPANIES OCCURS 3,

NAME(10), SALES TYPE I,

END OF COMPANIES.

COMPANIES-NAME = 'big'.

COMPANIES-SALES = 90.

APPEND COMPANIES.

COMPANIES-NAME = 'small'.

COMPANIES-SALES = 10.

APPEND COMPANIES.

COMPANIES-NAME = 'too small'.

COMPANIES-SALES = 5.

APPEND COMPANIES.

COMPANIES-NAME = 'middle'.

COMPANIES-SALES = 50.

APPEND COMPANIES SORTED BY SALES.

The table now has three (-> OCCURS 3 ) entries. The line with the contents 'too small' in the sub-field NAME is deleted from the table because the entry for 'middle' has a greater value in the sub-field SALES . This entry now appears in the second table line (after 'big' and before 'small' ).

Notes

Whenever an internal table is processed with APPEND SORTED BY , it should always be filled in this way.

If you specify APPEND with the parameter SORTED BY , the system always searches the entire table. Therefore, it is sometimes better to create the table with a simple APPEND and then use SORT to sort in descending ot ascending order afterwards.

You can also sort in ascending order by first determining the insert position with READ TABLE itab WITH KEY f = itab-f BINARY SEARCH and then by inserting the new entry into the table (perhaps read SY-SUBRC beforehand) with INSERT itab INDEX SY-TABIX .

However, you should be aware that, in such cases, the table may contain more entries than specified in the OCCURS parameter .

If several lines with an identical value f are added, lines added later are treated as smaller, i.e. they are inserted after existing lines with the same value f .

If you use APPEND ... SORTED BY f with an explicitly specified work area, this must be compatible with the line type of the internal table.

If the sort criterion f is not known until runtime, you can use SORTED BY (name) to specify it dynamically as the contents of the field name . If name is blank at runtime or contains an invalid component name, a runtime error occurs.

Regardless of whether you specify it statically or dynamically, you can restrict the sort criterion f further by defining an offset and/or length.

Related COLLECT itab , INSERT itab , SELECT / FETCH NEXT CURSOR ... INTO/APPENDING TABLE itab , MODIFY itab , WRITE f TO itab INDEX idx , SORT itab , READ TABLE itab , LOOP AT itab , DELETE itab

Regards

Sreeni