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

Records not getting inserted in DB

sachin_soni
Active Participant
0 Likes
2,056

Hi all,

senario is : I have a screen where my screen input fields are linked to dictionary fields ,i'm takin the data from screen to two itabs by following statements:

WHEN 'SAVE'.

move zmm_truck_txn to itab1.

move zmm_po_alloc to itab2.

and then inserting the records by following statements:

INSERT zmm_truck_txn

FROM TABLE itab1

ACCEPTING DUPLICATE KEYS.

if sy-subrc = 0.

commit work.

endif.

INSERT zmm_po_alloc

FROM TABLE itab2

ACCEPTING DUPLICATE KEYS.

if sy-subrc = 0.

commit work.

endif.

endcase.

AND MY RECORDS ARE NOT GETTING INSERTED.

ANY IDEA ANY ONE???

thanks and regards,

sachin soni

1 ACCEPTED SOLUTION
Read only

former_member186741
Active Contributor
0 Likes
1,894

your insert statement is expecting the source to be in TABLES but you have only moved the values to the table headers, not the tables themselves.

Either change your insert to be from the varaibles rather than tables,

eg,

INSERT zmm_truck_txn

FROM itab1

.

or change the population so that you are adding entries to the tables:

move zmm_truck_txn to itab1.

append itab1.

move zmm_po_alloc to itab2.

append itab2.

15 REPLIES 15
Read only

Sougata
Active Contributor
0 Likes
1,894

What's the structure and definition of itab1 and itab2?

What is the reason for using ACCEPTING DUPLICATE KEYS addition? Do you know the implication of this?

What's the return code (sy-subrc) after the INSERT statements?

Read only

sachin_soni
Active Participant
0 Likes
1,894

itab1 is like a ztable zmm_truck_txn

and itab2 is like zmm_po_alloc

the reason for using ACCEPTING DUPLICATE KEYS addition :

so that it accepts duplicate keys.

return code after insert = 0

regards,

sachin

Read only

Former Member
0 Likes
1,894

hi user,

you can use

MODIFY in place of INSERT.

i.e.

MODIFY ITAB FROM WA.

CLEAR WA.

Read only

sachin_soni
Active Participant
0 Likes
1,894

still no success,followed all of you

Read only

0 Likes
1,894

hI sACHIN,

PLS SHOW US THE CURRENT CODE AND THE DECLARATIONS OF THE VARIABLES YOU ARE USING.

Read only

Former Member
0 Likes
1,894

first check whether your itab contains any value or not?

then i check whether you are trying to insert duplicate key value or not ? if it is so then you can not do that ACCEPTING DUPLICATE KEYS is only to avoid the errors if you are trying to insert duplicate keys but it will not update the records in the database...

regards

shiba dutta

Read only

sachin_soni
Active Participant
0 Likes
1,894

hi ,

here is the declaration :

&----


*& Include ZSSTOP Module pool ZSS_SAMPLE1

*&

&----


PROGRAM ZSS_SAMPLE1 MESSAGE-ID ZSS_MSG.

TABLES: zmm_truck_txn,zmm_po_alloc.

*DATA Begin of itab occurs 0.

*DATA include structure zmm_truck_txn.

*DATA include structure zmm_po_alloc.

*DATA End of itab.

DATA itab1 like zmm_truck_txn.

DATA itab2 like zmm_po_alloc.

data : okcode like sy-ucomm.

WHEN 'SAVE'.

move zmm_truck_txn to itab1.

move zmm_po_alloc to itab2.

If itab1 is not initial.

INSERT zmm_truck_txn

FROM itab1.

endif.

If itab2 is not initial.

INSERT zmm_po_alloc

FROM itab2.

endif.

if sy-subrc = 0.

commit work.

message s002.

endif.

Read only

0 Likes
1,894

depending on what the key values are the INSERT will not work if an entry with the same key fields already exists.

Somebody else already suggested you change the INSERT to a MODIFY. This does an INSERT or an UPDATE depending on if the record already exists.

If itab1 is not initial.

MODIFY zmm_truck_txn

FROM itab1.

endif.

If itab2 is not initial.

MODIFY zmm_po_alloc

FROM itab2.

endif.

Read only

sachin_soni
Active Participant
0 Likes
1,894

the seen is now the records are gettin inserted in zmm_truck_txn but not in zmm_po_alloc.

regards

sachin soni

Read only

0 Likes
1,894

IN DEBUG CAN YOU SEE IF ITAB2 HAS ANY VALUES BEFORE IT INSERTS TO zmm_po_alloc?

If it does have values and gives 0 sy-subrc after the modify I can't think what the problem is.

Read only

Former Member
0 Likes
1,894

hi soni,

u can use like this

insert statement can insert record from workarea to internal table and in our query no destination is mentioned [target place for inserting the record]

INSERT zmm_truck_txn

FROM TABLE itab1

ACCEPTING DUPLICATE KEYS.

into [destination table]

if sy-subrc = 0.

commit work.

endif.

INSERT zmm_po_alloc

FROM TABLE itab2

ACCEPTING DUPLICATE KEYS

into [destination table].

if sy-subrc = 0.

commit work.

endif.

reward points if helpful.

with regards,

suresh babu aluri.

Read only

0 Likes
1,894

and suresh !,i think your query is not correct because target is in the begining.

thx

Read only

former_member673464
Active Contributor
0 Likes
1,894

hi Sachin ..

I have sample code which may solve your problem. Here it is.

In report code is like this.

<b>controls:

c_spfli type tableview using screen '1400',

c_sflight type tableview using screen '1400'.

data:

w_ucomm type sy-ucomm.

data:

begin of fs_spfli.

include structure spfli.

data end of fs_spfli.

data:

begin of fs_sflight.

include structure sflight.

data end of fs_sflight.

data:

t_spfli like

standard table

of fs_spfli.

data:

t_sflight like

standard table

of fs_sflight.

call screen 1400.

&----


*& Module STATUS_1400 OUTPUT

&----


  • text

----


module STATUS_1400 output.

SET PF-STATUS 'YH634_STATUS'.

  • SET TITLEBAR 'xxx'.

endmodule. " STATUS_1400 OUTPUT

&----


*& Module exit_1400 INPUT

&----


  • text

----


module exit_1400 input.

leave program.

endmodule. " exit_1400 INPUT

&----


*& Module USER_COMMAND_1400 INPUT

&----


  • text

----


module USER_COMMAND_1400 input.

case w_ucomm.

when 'SAVE'.

INSERT yh634_spfli

FROM TABLE t_spfli

ACCEPTING DUPLICATE KEYS.

INSERT yh634_sflight

FROM TABLE t_sflight

ACCEPTING DUPLICATE KEYS.

endcase.

endmodule. " USER_COMMAND_1400 INPUT

&----


*& Module sflight_1400 INPUT

&----


  • text

----


module sflight_1400 input.

append fs_sflight to t_sflight.

endmodule. " sflight_1400 INPUT

&----


*& Module spfli_1400 INPUT

&----


  • text

----


module spfli_1400 input.

append fs_spfli to t_spfli.

endmodule. " spfli_1400 INPUT</b>

And in dialog screen i have following code

<b>MODULE STATUS_1400.

loop at t_spfli into fs_spfli with control c_spfli.

endloop.

loop at t_sflight into fs_sflight with control c_sflight.

endloop.

*

PROCESS AFTER INPUT.

loop at t_spfli.

module spfli_1400.

endloop.

loop at t_sflight.

module sflight_1400.

endloop.

module exit_1400 at exit-command.

MODULE USER_COMMAND_1400.</b>

i have defined two table controls for the t_spfli and t_sflight.

It is working fine.

give a Push button for save and function code <b>'SAVE'</b>.

REGARDS,

VEERESH

Read only

Former Member
0 Likes
1,894

hi sachin,

just try this code,

first of all your ztable structure and itab structure should be same,

then u can fill your itabs accordingley,

then your code should be as follows,

IF <itab> IS NOT INITIAL.

INSERT <ztable> FROM TABLE <itab>.

ENDIF.

IF <itab1>IS NOT INITIAL.

INSERT <ztable1>FROM TABLE <itab1>.

ENDIF.

if sy-subrc eq 0.

MESSAGE s002(Records are inserted into <ztable>) WITH lv_po.

regards...

seshu.

Read only

former_member186741
Active Contributor
0 Likes
1,895

your insert statement is expecting the source to be in TABLES but you have only moved the values to the table headers, not the tables themselves.

Either change your insert to be from the varaibles rather than tables,

eg,

INSERT zmm_truck_txn

FROM itab1

.

or change the population so that you are adding entries to the tables:

move zmm_truck_txn to itab1.

append itab1.

move zmm_po_alloc to itab2.

append itab2.