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: 

trans data

Former Member
0 Kudos

how to tranasfer data from internal table to database table.

4 REPLIES 4

former_member200338
Active Contributor
0 Kudos

Hi,

use modify or insert statment

like this

modify ZZVBAK from table it_ZZVBAK.

ZZVBAK -> DATABASE table name

IT_ZZVBAK -> ur internal table

reward points if useful

Regards,

Niyaz

Former Member
0 Kudos

INSERT - itab_position

Syntax

... {TABLE itab}

| {itab [INDEX idx]} ... .

Alternatives:

1. ... TABLE itab

2. ... itab INDEX idx

Effect

These alternatives specify at which position of the internal table itab lines are to be inserted. If you use the option with the addition TABLE, the position at which the line is inserted, is specified using the table key. If you use the option with the addition INDEX, the table index is used for the specification. The latter option can only be used for index tables.

Alternative 1

... TABLE itab

Effect

The lines line_spec to be inserted must be compatible with the line type of the internal table. Depending on the table type, each line is inserted as follows:

For standard tables, each new line is appended as the last line in the internal table regardless of the table key.

For sorted tables, each new line is inserted into the sort order of the internal table according to its key values and the table index of the following lines is increased by one. If the internal table does not have a unique key, duplicate entries are inserted before the existing line.

For hashed tables, each new line is inserted into the internal table by the hash adminstration according to its key values.

If the internal table has a unique key, duplicate entries are not inserted. When inserting single lines, sy-subrc is set to 4. When inserting multiple lines, an exception that cannot be handled is triggered.

Example

Filling an internal table connection_tab with data of the database table spfli. Single lines are inserted using the table key and are filled with the content of the work area connection. Since the internal table has a unique key, duplicate entries are rejected. The better performing SELECT statement for which the internal table is specified directly after INTO TABLE could raise an exception due to the uniqueness of the table key.

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.

Alternative 2

... itab INDEX idx

Effect

This variant can only be used for standard tables and sorted tables. Each line line_spec to be inserted into the line before the table index idx and the table index of the following lines is increased by one. A data object of the type i is expected for idx.

If idx contains a value equal to the number of the existing table lines plus one, the new line is appended as the last line in the internal table. If idx contains a greater value, no line is inserted and sy-subrc is set to 4.

An exception that cannot be handled is raised when:

idx contains a value less than or equal to 0

A line to be inserted would cause a duplicate entry in tables with a unique table key

A line to be inserted would disrupt the sort order of sorted tables

Within a LOOP loop, you can omit the addition INDEX. Each line to be inserted is inserted before the current table line of the LOOP loop. However, if the current line is deleted in the same loop pass, the response is undefined.

INSERT - line_spec

Syntax

...

| {INITIAL LINE}

| {LINES OF jtab [FROM idx1] [TO idx2]} ... .

Alternatives:

1. ... wa

2. ... INITIAL LINE

3. ... 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.

Alternative 1

... wa

Effect

A new line is generated and filled with the content of the work area wa. wa must be compatible with the line type of the internal table when you insert the lines or work area using the table key. When you insert the lines or work area using the table index, wa can be incompatible with the line type of the internal table and may be converted to the line type according to the conversion rules, if necessary.

Note

Outside of classes, you can omit the specification of wa INTO if the internal table contains a header line itab with the same name. In this case, the statement implicitly uses the header line as the work area.

Alternative 2

... INITIAL LINE

Effect

A new line is inserted in which each component contains the type-specific initial value from the table of value ranges of built-in ABAP types.

Alternative 3

... LINES OF jtab [FROM idx1] [TO idx2]

Effect

The lines of an internal table jtab are inserted one after another according to the same rules as for the insertion of a work area. The line types of itab and jtab must be compatible. If jtab is an index table, you can specify FROM idx1 and TO idx2 to restrict the lines to be inserted. In this case, only the table lines from the table idx1 onward and/or up to the table index idx2 are inserted from jtab. Data objects of the type i are expected for idx1 and idx2. If idx1 or idx2 is less than or equal to 0, an exception that cannot be handled is raised. If idx1 is greater than idx2 or greater than the number of table lines, no lines are inserted. If idx2 is greater than the number of table lines, it is set to the number of table lines.

Note

If a conflict with an already existing unique table key occurs, an exception that cannot be handled is caused when inserting multiple lines from an internal table.

former_member189059
Active Contributor
0 Kudos
PARAMETERS: p_carrid TYPE sflight-carrid, 
            percent(1) TYPE p DECIMALS 0. 

DATA sflight_tab TYPE TABLE OF sflight. 
FIELD-SYMBOLS <sflight> TYPE sflight. 

SELECT * 
       FROM sflight 
       INTO TABLE sflight_tab 
       WHERE carrid = p_carrid AND 
             fldate = sy-datum. 

IF sy-subrc = 0. 
  LOOP AT sflight_tab ASSIGNING <sflight>. 
    <sflight>-price = 
      <sflight>-price * ( 1 - percent / 100 ). 
  ENDLOOP. 
ENDIF. 

UPDATE sflight FROM TABLE sflight_tab. 

naimesh_patel
Active Contributor
0 Kudos

WIth MODIFY

MODIFY ZTABLE FROM TABLE  ITAB.

Here ITAB should be like same with the ZTABLE.

WIth the INSERT command.

Loop at itab.
  move correspoding itab to ZTABLE.
  INSERT ZTABLE.
ENDLOOP.

Don't forget to do <b>COMMIT WORK.</b>

Regards,

Naimesh Patel