Application Development 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: 

extract statement and insert statement

Former Member
0 Kudos

can anyone explain me the use of this insert statement and extract statement.

INSERT lfa1-name1 INTO fg01

extract fg01.

thanks

phyrose

2 REPLIES 2

Former Member
0 Kudos

Hi,

From f1 help....

EXTRACT

Basic form

EXTRACT fg.

Effect

Writes all fields of the field group fg (FIELD-GROUPS) as an entry in asequential dataset. If you have defined a field group HEADER,its fields precede each entry as a sort key. Afterwards, you canuse SORT and LOOP ... ENDLOOP to sort or process the datasetrespectively. No further EXTRACT statements are possible afterthis.

Notes

General:

As soon as you have extracted a dataset using EXTRACT, you canno longer extend the field group using INSERT. In particular, you cannot change the HEADERfield group at all after the first EXTRACT (regardless of thefield group to which it applied).

Large extract datasets are not stored in main memory. Instead, theyare kept in an external auxiliary file. You can set the directory inwhich this file is created using the SAP profile parameterDIR_EXTRACT. The default directory is the SAP data directory(SAP profile parameter DIR_DATA).

Notes

Runtime errors:

EXTRACT_AFTER_SORT/LOOP: EXTRACT after SORT, orLOOP. EXTRACT_BUFFER_NO_ROLL: Unable to create the required main

EXTRACT_FIELD_TOO_LARGE: Occupied length of a field is toolarge.

EXTRACT_HEADER_NOT_UNIQUE: Field group HEADER wasmodified after an EXTRACT statement.

EXTRACT_OPEN_EXTRACTFILE_OPEN:

Error opening the external extract dataset file.

EXTRACT_RESOURCEHANDLER_FAILED: Error deleting the externalextract dataset file.

EXTRACT_TOO_LARGE: Total length of the entry for extraction(including HEADER fields) is too large.

Additional help

Filling anExtract with Data

Extracts

Since internal tables have fixed line structures, they are not suited to handle data sets with varying structures. Instead, you can use extract datasets for this purpose.

An extract is a sequential dataset in the memory area of the program. You can only address the entries in the dataset within a special loop. The index or key access permitted with internal tables is not allowed. You may only create one extract in any ABAP program. The size of an extract dataset is, in principle, unlimited. Extracts larger than 500KB are stored in operating system files. The practical size of an extract is up to 2GB, as long as there is enough space in the filesystem.

An extract dataset consists of a sequence of records of a pre-defined structure. However, the structure need not be identical for all records. In one extract dataset, you can store records of different length and structure one after the other. You need not create an individual dataset for each different structure you want to store. This fact reduces the maintenance effort considerably.

In contrast to internal tables, the system partly compresses extract datasets when storing them. This reduces the storage space required. In addition, you need not specify the structure of an extract dataset at the beginning of the program, but you can determine it dynamically during the flow of the program.

You can use control level processing with extracts just as you can with internal tables. The internal administration for extract datasets is optimized so that it is quicker to use an extract for control level processing than an internal table.

Procedure for creating an extract:

Define the record types that you want to use in your extract by declaring them as field groups. The structure is defined by including fields in each field group.

Defining an Extract

Fill the extract line by line by extracting the required data.

Filling an Extract with Data

Once you have filled the extract, you can sort it and process it in a loop. At this stage, you can no longer change the contents of the extract.

Processing Extracts

INSERT Statement

The INSERT statement is used to insert values into a single database table.

<insert statement> ::= INSERT INTO <table name> <insert column list> <insert source>.

<insert source> ::= VALUES '(' <value> ( ',' <value> )* ')'

| <query specification>.

<value> ::= <value expression>

| <dynamic parameter specification>

| NULL.

<insert column list> ::= '(' <column name> ( ',' <column name> )* ')'.

In Open SQL the <insert column list> is not optional.

You cannot specify string literals as values for CLOB columns. Hex literals are not supported in Open SQL.

Examples

INSERT INTO employees (employee_id, employee_name)

VALUES (4711, 'John Smith')

Inserting Values. A new row is inserted into the table employees with the values 4711 and 'John Smith' for the columns employee_id and employee_name respectively.

INSERT INTO well_paid_employees (employee_id, salary)

SELECT employee_id, salary

FROM employees

WHERE salary > ?

Inserting the Result of a Query. The employee_idand the salaryof all employees from table employeeswith a salary exceeding a certain value are inserted into the table well_paid_employees.

Regards

Former Member
0 Kudos

<b>

Go thru below F1 help from SAP

INSERT - Insert into a field group

Basic form

INSERT f1 f2 ... INTO fg.

Effect

Inserts one or more fields into the field group fg (see FIELD-GROUPS).

Notes

This basic form of INSERT is not a declarative, but an operational statement, i.e. it must be executed at runtime.

A field group can only accept global data objects, not data objects which have been defined locally in a FORM or FUNCTION.

f1 ... fn can also be field symbols. You can then insert a data object into the field group dynamically at runtime by referencing it with a field symbol. Unassigned field symbols are ignored (no new field is inserted in the field group).

The actual data transport is performed by EXTRACT.

As soon as the first dataset for a field group has been extracted with EXTRACT, the field group can no longer be extended with INSERT. The field group HEADER cannot be extended at all after the first EXTRACT (regardless of the field group).

</b>