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

Inserting record in standard table

Former Member
0 Likes
922

Dear Sapians

I want to insert a record in standard table PRPS for testing one scenario. we tried to insert through abap program but we are unable to insert data in the PSPNR field.

Best regards

Sukumaran.E

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
884

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.

regards

siva

Dear Sapians

I want to insert a record in standard table PRPS for testing one scenario. we tried to insert through abap program but we are unable to insert data in the PSPNR field.

Best regards

Sukumaran.E

6 REPLIES 6
Read only

Former Member
0 Likes
884

Hi Sukumaran ,

Did you check the value of SY-SUBRC after the update/insert statement.

Please check it one reason can the value already exists in the table.

Regardsa

A.R

Read only

Former Member
0 Likes
884

i think this is primary key field.

don't try to do this it may impect on other table .

there is relation b/w this table to another table using this key.

if u trying insert data directly it craete inconistancy in database.

always follow bdc,lsmw bapi to do taht.

Read only

Former Member
0 Likes
885

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.

regards

siva

Read only

0 Likes
884

Dear all,

Thanks for your reply. I just want to insert one record in the table PRPS and I dont want to create the entire project through standard BAPI.

I have checked sy-subrc is 4.(I have given the value which is not there in the PRPS-PSPNR field)

Even while giving the value for the field PSPNR the system is not accepting.

May I know is there any other way

Thanks and Regards

Sukumaran.E

Read only

0 Likes
884

hi,

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.

regards

siva

Read only

Former Member
0 Likes
884

Hi,

Never try to update a std table directly.

If u do so it will create inconsistency in the system.

The same might be the reason it is not updating. Do it through Tocdes only