Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Friday, April 18, 2008

Difference between extract and collect statements SAP ABAP INTERVIEW Questions

What is the difference between 'extract' and 'collect' statements?

Once you have declared the possible record types as field groups and defined their structure, you can fill the extract dataset using the following statements:

EXTRACT .

When the first EXTRACT statement occurs in a program, the system creates the extract dataset and adds the first extract record to it. In each subsequent EXTRACT statement, the new extract record is added to the dataset.

Each extract record contains exactly those fields that are contained in the field group , plus the fields of the field group HEADER (if one exists). The fields from HEADER occur as a sort key at the beginning of the record. If you do not explicitly specify a field group , the EXTRACT statement is a shortened form of the statement extracts used in field groups (version 2.x - obsolete these days as noone uses field groups anymore), and collect is used to accumulate the contents of a field if X no. of keys are the same.

EXTRACT HEADER.

When you extract the data, the record is filled with the current values of the corresponding fields. As soon as the system has processed the first EXTRACT statement for a field group , the structure of the corresponding extract record in the extract dataset is fixed. You can no longer insert new fields into the field groups and HEADER. If you try to modify one of the field groups afterwards and use it in another EXTRACT statement, a runtime error occurs.

By processing EXTRACT statements several times using different field groups, you fill the extract dataset with records of different length and structure. Since you can modify field groups dynamically up to their first usage in an EXTRACT statement, extract datasets provide the advantage that you need not determine the structure at the beginning of the program.

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.

Create a table maintance program for a z table

In transaction SE11, in the attribute tab of your z table check table maintenance check box. Go to SM30 transaction, enter the ztable name and click on maintain button. Here you can enter new entries into the ztable .

Or

You can create a PARAMETER TRANSACTION for the transaction for SM30 .


Follow these steps :

1. go to transaction SE93 , give your own transaction code say ztran_tab, for maintaining your ztable.


2. Click on create button and check the radio button Transaction with parameters (PARAMETER TRANSACTION) and click on the tick button.


3. In the next screen enter default values:
transaction : SM30
check the check box skip initial screen


4. Scroll down you will find a table control for default values

--------------------------------------------------------------------------------

Name of the screen field | value

--------------------------------------------------------------------------------

VIEWNAME | your ztable name
SHOW | X


Save your work.


Now as you have created a custom transaction for maintaining your ztable this transaction can be called from any program with CALL transaction 'XXX'.

No comments:

Post a Comment

Content

Recent Topics