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

INSERT DATA INTO DATABASE

Former Member
0 Likes
842

Hi expert,

How do i insert a new data into a database?

pls guide.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
808

hi,

use modify statement,

check this sample code

TABLES : AFKO,

AFPO.

DATA : BEGIN OF GI_AFKO OCCURS 1,

AUFNR LIKE AFKO-AUFNR,

END OF GI_AFKO.

data gi_AFPO like ZPRODUCT occurs 0 with header line.

*DATA : BEGIN OF GI_AFPO OCCURS 100,

  • MANDT LIKE

  • MATNR LIKE AFPO-MATNR,

  • DWERK LIKE AFPO-DWERK,

  • END OF GI_AFPO.

DATA: gv_date(11)," LIKE ekpo-aedat,

gv_date1(11),

year(4),

month(2),

day(2),

flag(1),

read_flag(1).

START-OF-SELECTION.

gv_date1 = sy-datum.

year = gv_date1+0(4).

month = gv_date1+4(2).

day = gv_date1+6(2).

year = year - 3.

CLEAR gv_date1.

CONCATENATE year month day INTO gv_date1.

select aufnr

from afko

into table gi_afko

where ( GLTRP <= sy-datum AND gltrp >= gv_date1 ) .

IF SY-SUBRC = 0.

select matnr

dwerk

from afpo

into CORRESPONDING FIELDS OF table gi_afpo

for all entries in gi_afko

where aufnr = gi_afko-aufnr.

ENDIF.

SORT GI_AFPO BY MATNR.

IF NOT GI_AFPO[] IS INITIAL.

MODIFY ZPRODUCT FROM TABLE GI_AFPO.

IF SY-SUBRC = 0.

MESSAGE I003 WITH 'VALUES UPDATED IN TO TABLE ZPRODUCT'.

ELSE.

MESSAGE I003 WITH 'VALUES NOT UPDATED IN TO TABLE ZPRODUCT'.

ENDIF.

regards

siva

6 REPLIES 6
Read only

Former Member
0 Likes
808

Hi,

try this,

INSERT INTO <dbtab> from <wa>

or

INSERT <dbtab>

Message was edited by:

Ari Kumar

Read only

mahaboob_pathan
Contributor
0 Likes
808

hi,

to insert data in database u can use INSERT command.

like.

INSERT ITAB INDEX 5.

Read only

Former Member
0 Likes
808

Hi

Check the below process:

First declare one internal table :

data : i_ztreglog like ztreglog occurs 0 with header line." Internal table

data : wa_ztreglog like line of i_ztreglog. " Work area

start-of-selection.

move wa_ztreglog to i_ztreglog.

append i_ztreglog.

MODIFY ztreglog FROM TABLE i_ztreglog.

Read only

Former Member
0 Likes
809

hi,

use modify statement,

check this sample code

TABLES : AFKO,

AFPO.

DATA : BEGIN OF GI_AFKO OCCURS 1,

AUFNR LIKE AFKO-AUFNR,

END OF GI_AFKO.

data gi_AFPO like ZPRODUCT occurs 0 with header line.

*DATA : BEGIN OF GI_AFPO OCCURS 100,

  • MANDT LIKE

  • MATNR LIKE AFPO-MATNR,

  • DWERK LIKE AFPO-DWERK,

  • END OF GI_AFPO.

DATA: gv_date(11)," LIKE ekpo-aedat,

gv_date1(11),

year(4),

month(2),

day(2),

flag(1),

read_flag(1).

START-OF-SELECTION.

gv_date1 = sy-datum.

year = gv_date1+0(4).

month = gv_date1+4(2).

day = gv_date1+6(2).

year = year - 3.

CLEAR gv_date1.

CONCATENATE year month day INTO gv_date1.

select aufnr

from afko

into table gi_afko

where ( GLTRP <= sy-datum AND gltrp >= gv_date1 ) .

IF SY-SUBRC = 0.

select matnr

dwerk

from afpo

into CORRESPONDING FIELDS OF table gi_afpo

for all entries in gi_afko

where aufnr = gi_afko-aufnr.

ENDIF.

SORT GI_AFPO BY MATNR.

IF NOT GI_AFPO[] IS INITIAL.

MODIFY ZPRODUCT FROM TABLE GI_AFPO.

IF SY-SUBRC = 0.

MESSAGE I003 WITH 'VALUES UPDATED IN TO TABLE ZPRODUCT'.

ELSE.

MESSAGE I003 WITH 'VALUES NOT UPDATED IN TO TABLE ZPRODUCT'.

ENDIF.

regards

siva

Read only

Former Member
0 Likes
808

You can use INSERT statement.

To insert a single line into a database table, use the following:

INSERT INTO dbtab VALUES wa or INSERT dbtab FROM wa.

To insert several lines into a database table, use the following:

INSERT dbtab FROM TABLE <itab>

If one or more lines cannot be inserted because the database already contains a line with the same primary key, a runtime error occurs. You can prevent the runtime error occurring by using the addition ACCEPTING DUPLICATE KEYS. In this case, the lines that would otherwise cause runtime errors are discarded, and SY-SUBRC is set to 4.

If the system is able to insert all of the lines from the internal table, SY-SUBRC is set to 0.