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 into standard table?

Former Member
0 Likes
4,371

Hi All

Can i insert into standard table by ABAP code? How? Plz

Thank you!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,843

hi,

check this code it may help u,

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.

u can try using update command by giving condition.

check this code, this code is to update one record on where condition.

TABLES:BKPF,J_1IPART2.

PARAMETERS:P_FAWREF LIKE J_1IPART2-FAWREF,

P_FAWRE1 LIKE J_1IPART2-FAWREF.

DATA: P_FAWREF2 LIKE J_1IPART2-FAWREF,

P_FAWRE3 LIKE J_1IPART2-FAWREF.

MOVE P_FAWREF TO P_FAWREF2.

MOVE P_FAWRE1 TO P_FAWRE3.

UPDATE J_1IPART2 SET FAWREF = P_FAWRE3

WHERE FAWREF = P_FAWREF2.

IF SY-SUBRC = 0.

MESSAGE S000.

ELSE.

MESSAGE E001.

ENDIF.

6 REPLIES 6
Read only

Former Member
0 Likes
1,843

Hi

Make use of the following statement in a similar way as shown below,

INSERT <DATABASE TABLE NAME> FROM TABLE <INTERNAL TABLE>.

Note that the internal table has the same structure as the database table.

No need of looping at the internal table.

OR

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.

<b>

Reward if usefull</b>

Read only

Former Member
0 Likes
1,843

To add a line to an internal table, use the statement:

INSERT <line> INTO TABLE <itab>.

To add several lines to an internal table, use the statement:

INSERT LINES OF <itab1> [FROM <n1>] [TO <n 2>] INTO TABLE <itab2>.

DATA: BEGIN OF LINE,

LAND(3) TYPE C,

NAME(10) TYPE C,

AGE TYPE I,

WEIGHT TYPE P DECIMALS 2,

END OF LINE.

DATA ITAB LIKE SORTED TABLE OF LINE

WITH NON-UNIQUE KEY LAND NAME AGE WEIGHT.

LINE-LAND = 'G'. LINE-NAME = 'Hans'.

LINE-AGE = 20. LINE-WEIGHT = '80.00'.

INSERT LINE INTO TABLE ITAB.

LINE-LAND = 'USA'. LINE-NAME = 'Nancy'.

LINE-AGE = 35. LINE-WEIGHT = '45.00'.

INSERT LINE INTO TABLE ITAB.

LINE-LAND = 'USA'. LINE-NAME = 'Howard'.

LINE-AGE = 40. LINE-WEIGHT = '95.00'.

INSERT LINE INTO TABLE ITAB.

LINE-LAND = 'GB'. LINE-NAME = 'Jenny'.

LINE-AGE = 18. LINE-WEIGHT = '50.00'.

INSERT LINE INTO TABLE ITAB.

LINE-LAND = 'F'. LINE-NAME = 'Michele'.

LINE-AGE = 30. LINE-WEIGHT = '60.00'.

INSERT LINE INTO TABLE ITAB.

LINE-LAND = 'G'. LINE-NAME = 'Karl'.

LINE-AGE = 60. LINE-WEIGHT = '75.00'.

INSERT LINE INTO TABLE ITAB.

LOOP AT ITAB INTO LINE.

WRITE: / LINE-LAND, LINE-NAME, LINE-AGE, LINE-WEIGHT.

ENDLOOP.

The output is:

F Michele 30 60.00

G Hans 20 80.00

G Karl 60 75.00

GB Jenny 18 50.00

USA Howard 40 95.00

USA Nancy 35 45.00

<b>Hope this is helpful, Do reward.</b>

Message was edited by:

Runal Singh

Read only

Former Member
0 Likes
1,844

hi,

check this code it may help u,

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.

u can try using update command by giving condition.

check this code, this code is to update one record on where condition.

TABLES:BKPF,J_1IPART2.

PARAMETERS:P_FAWREF LIKE J_1IPART2-FAWREF,

P_FAWRE1 LIKE J_1IPART2-FAWREF.

DATA: P_FAWREF2 LIKE J_1IPART2-FAWREF,

P_FAWRE3 LIKE J_1IPART2-FAWREF.

MOVE P_FAWREF TO P_FAWREF2.

MOVE P_FAWRE1 TO P_FAWRE3.

UPDATE J_1IPART2 SET FAWREF = P_FAWRE3

WHERE FAWREF = P_FAWREF2.

IF SY-SUBRC = 0.

MESSAGE S000.

ELSE.

MESSAGE E001.

ENDIF.

Read only

Former Member
0 Likes
1,843

okey, thanks for your answers. But no change occurs.

for example, i want to insert value mandt='002' into <b>standard table</b> mkpf

data : i_mkpf like mkpf occurs 0 with header line." Internal table

data : wa_mkpf like line of i_mkpf. " Work area

start-of-selection.

move wa_mkpf to i_mkpf.

wa_mkpf-mandt = '002'.

append i_mkpf.

MODIFY mkpf FROM TABLE i_mkpf.

Those are true?

I think, we can't insert into a <b>standard table</b>, may be. Do you think?

Help me pls!

Thanks!

null

Read only

matt
Active Contributor
0 Likes
1,843

<b>If you directly enter data into a SAP standard table, you will are likely to end up with a corrupted database, and SAP will charge you/your employer/your client a great deal of money to clean it up.

Be very very careful you know what you are doing and have an excellent reason to do it. Otherwise, explain what you are trying to achieve, and perhaps we'll be able to tell you a safe way to do it.</b>

OK, warning over. Check out the ABAP documentation on the keywords CLIENT SPECIFIED. That will explain why your update of mandt doesn't work.

matt

Read only

0 Likes
1,843

Hi Matthew,

In fact, i have a problem but have not solved yet. Pls read "Post Goods Issue Update terminated" thread in SD flow.

rgds