Open Sql Insert
Hi Friends!
Using insert can we use direct to insert record in database table its possibe whats the syntax.
Hi Rahul,
1. INSERT INTO dbtab VALUES wa. oder
INSERT INTO (dbtabname) VALUES wa. oder
INSERT dbtab FROM wa. oder
INSERT (dbtabname) FROM wa.
2. INSERT dbtab FROM TABLE itab. oder
INSERT (dbtabname) FROM TABLE itab.
3. INSERT dbtab. oder
INSERT *dbtab.
Effect
Inserts new lines in a database table (see relational database). You can specify the name of the database table either in the program itself in the form dbtab or at runtime as the contents of the variable dbtabname. In both cases, the database table must be defined in the ABAP Dictionary. By default, data is only inserted in the current client. Data can only be inserted using a view if the view refers to a single table and was defined in the ABAP Dictionary with the maintenance status "No restriction".
INSERT belongs to the Open SQL command set.
In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs.See Open SQL and Unicode.
Notes
You cannot insert a line if a line with the same primary key already exists or if a UNIQUE index already has a line with identical key field values (with regard to this UNIQUE index).
When inserting lines using a view, all fields of the
database table that are not in the view are set to their initial value
(see TABLES) - if they were defined with NOT NULL in the ABAP Dictionary. Otherwise they are set to NULL.
Authorization checks (see The SAP Authorization Concept) are not supported by the INSERT statement. You must include these in the program yourself.
Lines specified with the INSERT command are not finally added to the database table until after a database commit (see Logical Unit of Work (LUW)). Prior to this, you can cancel any changes to the database with a database rollback (see Programming Transactions).
In the dialog system, you cannot rely on the locking mechanism used by the database system (see Database Locking) to synchronize simultaneous access to the same database by several users. Therefore, it is often necessary to use SAP's locking mechanism (see SAP Locking).
PS: please reward if useful..
Similar Messages
-
Hello SdNers,
I was trying to insert records into table CSKA Cost Elements (Data Dependent on Chart of Accounts).
I have an excel file with 45 records.
I am able to upload to records from the file and display it on the list processing screens.
It is not getting inserted to DB table...CSKA.
data : begin of t_ks06 occurs 0,
KOKRS type KOKRS, " Controlling area
KSTAR type KSTAR, " Cost element
DATAB type DATAB, " Valid from date
DATBI type DATBI, " Valid to date
KTEXT type KTEXT, " Name
LTEXT type LTEXT, " Description
KATYP type KATYP, " Cost element cat
KOSTL type KOSTL, " Cost center
end of t_ks06.
data : wa like line of t_ks06.
data : it_excel type alsmex_tabline occurs 0 with header line.
selection-screen begin of block b1 with frame title text-001.
parameter: f_name type rlgrap-filename default 'C:\Documents and Settings\Administrator\Desktop\Project_data\Cost_element_KS06.xls'.
parameter : p_begcol type i default 1 no-display,
p_begrow type i default 2 no-display,
p_endcol type i default 8 no-display,
p_endrow type i default 46 no-display.
selection-screen end of block b1.
at selection-screen on value-request for f_name.
perform f_get_file using f_name.
start-of-selection.
perform f_xls_itab using f_name changing it_excel.
perform f_move_data.
perform f_insert_db.
perform f_display_data.
form f_get_file using p_file_nam.
call function 'KD_GET_FILENAME_ON_F4'
exporting
program_name = syst-repid
dynpro_number = syst-dynnr
* FIELD_NAME = ' '
* STATIC = ' '
* MASK = ' '
changing
file_name = f_name
exceptions
mask_too_long = 1
others = 2.
endform. " f_get_file
form f_xls_itab using p_file_nam changing p_it_excel.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = f_name
i_begin_col = p_begcol
i_begin_row = p_begrow
i_end_col = p_endcol
i_end_row = p_endrow
tables
intern = it_excel
exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3.
endform. " f_xls_itab
form f_move_data.
data : lv_index type i.
field-symbols <fs>.
* Sorting the internal table
sort it_excel by row col.
clear it_excel.
loop at it_excel.
move it_excel-col to lv_index.
* Assigning each record to the internal table row.
assign component lv_index of structure wa to <fs>.
* Assigning the field value to a field symbol
move it_excel-value to <fs>.
at end of row.
append wa to t_ks06.
* flg_mv = 1.
clear wa.
endat.
endloop.
endform. " f_move_data
form f_display_data.
write:/1 sy-uline(140).
write:/1 sy-vline, 'Cont area', " Controlling area
16 sy-vline, 'Cost ele', " Cost element
31 sy-vline, 'Valid from', " Valid from date
46 sy-vline, 'Valid to ' , " Valid to date
61 sy-vline, 'Name', "Cost element cat
76 sy-vline, 'Description', " Cost center
101 sy-vline, 'Cost ele cat', " Cost element cat
126 sy-vline, 'Cost center', " Cost center
140 sy-vline.
write:/1 sy-uline(140).
skip 1.
clear wa.
loop at t_ks06 into wa.
write:/2 sy-uline(139).
write:/2 sy-vline, wa-KOKRS, " Controlling area
16 sy-vline, wa-KSTAR, " Cost element
31 sy-vline, wa-DATAB, " Valid from date
46 sy-vline, wa-DATBI, " Valid to date
61 sy-vline, wa-KTEXT, " Name
76 sy-vline, wa-LTEXT, " Description
101 sy-vline, wa-KATYP, " Cost element cat
120 sy-vline, wa-KOSTL, " Cost center
140 sy-vline.
endloop.
endform. " f_display_data
form f_insert_db .
if t_ks06[] is initial.
write:/ 'No records fetched from file' color 3.
else.
clear wa.
loop at t_ks06 into wa.
insert into CSKA values wa.
endloop.
* if sy-dbcnt ge 1.
* perform f_display_data.
* endif.
endif.
endform. " f_insert_db
Help highly appreciated and would be rewarded.
Regards,
Ranjith NHello Ranjinth,
To insert the record into data base table. you need to create a work area type of data base table.
because for insert purpose we need the all the field in header or in work area for inserting the new record into data base table. it doesn't mean that you need to use old the field that is avaible in data base table.
you can use only those field that you need in your program with primary key.Because primary key is mandatory to enter for inserting new record.
you can try this..
wa_wrk1 type CSKA.
to insert record.
INSERT CSKA FROM wa_work1.
hope it will help you.
Thanks.
Arun Kayal. -
The ABAP/4 Open SQL array insert results in duplicate database records
Hi,
Iam getting following error :
The ABAP/4 Open SQL array insert results in duplicate database records.
Error in ABAP application program.
The current ABAP program "SAPLV60U" had to be terminated because one of the
statements could not be executed.
This is probably due to an error in the ABAP program.
" Information on where terminated
The termination occurred in the ABAP program "SAPLV60U" in "VBUK_BEARBEITEN".
The main program was "SAPMSSY4 ".
The termination occurred in line 503 of the source code of the (Include)
program "LV60UF0V"
of the source code of program "LV60UF0V" (when calling the editor 5030).
Processing was terminated because the exception "CX_SY_OPEN_SQL_DB" occurred in
the
procedure "VBUK_BEARBEITEN" "(FORM)" but was not handled locally, not declared
in the
RAISING clause of the procedure.
The procedure is in the program "SAPLV60U ". Its source code starts in line 469
of the (Include) program "LV60UF0V "."
Please assist how to proceed further ..
Many thanks
Mujeeb.Sorry, THe correct note is 402221.
Description from the note
<< Please do not post SAP notes - they are copyrighed material >>
Edited by: Rob Burbank on Feb 22, 2009 3:46 PM -
ABAP/4 Open SQL array insert results in duplicate databaserecordsfor pk13
Hi Experts, when I am working with pk13n tranaction iam getting an error message stating that update was terminated by user. when i am checking with st22 it gives the following message. please give the solution , iam sending the code as well.
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_SY_OPEN_SQL_DB', was not caught
in
procedure "SAVE_DATA" "(FORM)", nor was it propagated by a RAISING clause.
Since the caller of the procedure could not have anticipated that the
exception would occur, the current program is terminated.
The reason for the exception is:
If you use an ABAP/4 Open SQL array insert to insert a record in
the database and that record already exists with the same key,
this results in a termination.
(With an ABAP/4 Open SQL single record insert in the same error
situation, processing does not terminate, but SY-SUBRC is set to 4.) please find the below code please give the solution for this error message.
1 *eject
2 *----
3 * Verbuchen der Daten *
4 *----
5 FORM SAVE_DATA.
6
7 DATA: lf_menge LIKE ekpo-menge VALUE 0, "717464
8 lf_netwr LIKE ekpo-netwr VALUE 0.
9
10 * Einteilungen löschen --> Array Delete aus Tabelle DEKET
11 DESCRIBE TABLE DEKET LINES SY-TFILL.
12 IF SY-TFILL GT 0.
13 DELETE EKET FROM TABLE DEKET.
14 IF SY-SUBRC NE 0.
15 MESSAGE A865.
16 ENDIF.
17 EKET_DELETE = EKET_DELETE + SY-DBCNT.
18 REFRESH: DEKET.
19 CLEAR : DEKET.
20 ENDIF.
21
22 * Einteilungen hinzufügen --> Array Insert aus Tabelle IEKET
23 DESCRIBE TABLE IEKET LINES SY-TFILL.
24 IF SY-TFILL GT 0.
>> INSERT EKET FROM TABLE IEKET.
26 IF SY-SUBRC NE 0.
27 MESSAGE A864.
28 ENDIF.
29 EKET_INSERT = EKET_INSERT + SY-DBCNT.
30 REFRESH: IEKET.
31 CLEAR : IEKET.
32 ENDIF.
33
34 * Check whether the qty in EKPO-MENGE is correct: note 717464
35 SELECT SUM( menge ) FROM eket INTO lf_menge
36 WHERE ebeln = ekpo-ebeln
37 AND ebelp = ekpo-ebelp.
38 IF sy-subrc = 0 AND ekpo-menge <> lf_menge.
39 IF ekpo-ktmng <> 0.
40 refe1 = ekpo-zwert * lf_menge / ekpo-ktmng.
41 ELSE.
42 refe1 = ekpo-zwert * lf_menge / 1000.
43 ENDIF.
44 IF refe1 > maxwert.Hi,
Well I don't know why you have duplicates, this is a functionnal issue. But you get the dump due the the message number 864 that triggers the abend... Changing the message type to 'E', 'S' or 'I' will prevent the dump but I guess this message has a good reason to be
Kr,
Manu. -
The ABAP/4 Open SQL array insert results in duplicate Record in database
Hi All,
I am trying to transfer 4 plants from R/3 to APO. The IM contains only these 4 plants. However a queue gets generated in APO saying 'The ABAP/4 Open SQL array insert results in duplicate record in database'. I checked for table /SAPAPO/LOC, /SAPAPO/LOCMAP & /SAPAPO/LOCT for duplicate entry but the entry is not found.
Can anybody guide me how to resolve this issue?
Thanks in advance
Sandeep PatilHi Sandeep,
Now try to delete ur location before activating the IM again.
Use the program /SAPAPO/DELETE_LOCATIONS to delete locations.
Note :
1. Set the deletion flag (in /SAPAPO/LOC : Location -> Deletion Flag)
2. Remove all the dependencies (like transportation lane, Model ........ )
Check now and let me know.
Regards,
Siva.
null -
The ABAP/4 Open SQL array insert results in duplic
Hi All,
During monitoring of our SAP SRM system in SM58 transaction we have received the below error. Please advise on this.
The ABAP/4 Open SQL array insert results in duplic
SM58 for Wf-BATCH user
SRM/MM: FM SPPF_PROCESS
thanks and regards
mohammedWhat action did you performed?
-
He ABAP/4 Open SQL array insert results in duplicate database records
Dear Gurus,
II am getting a dump when I run MD02/ MD03. (t- code to run MRP)
Below is the message system is showing:
Please help
Thanks in Advance
Best Regards
Adhish
Short text
The ABAP/4 Open SQL array insert results in duplicate database records.
What happened?
Error in the ABAP Application Program
The current ABAP program "SAPLM61U" had to be terminated because it has
come across a statement that unfortunately cannot be executed.
Error analysis
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_SY_OPEN_SQL_DB', was not caught
in
procedure "INSERT_MDSBI_IN_MDSB" "(FORM)", nor was it propagated by a RAISING
clause.
Since the caller of the procedure could not have anticipated that the
exception would occur, the current program is terminated.
The reason for the exception is:
If you use an ABAP/4 Open SQL array insert to insert a record in
the database and that record already exists with the same key,
this results in a termination.
(With an ABAP/4 Open SQL single record insert in the same error
situation, processing does not terminate, but SY-SUBRC is set to 4.)
1 *----
2 * ARRAY-INSERT auf MDSB
3 *----
4 FORM INSERT_MDSBI_IN_MDSB.
INSERT MDSB6 FROM TABLE MDSBI.
7 ADD SY-DBCNT TO STATS-RESBI. "statistics
8 ENDFORM.Hi,
There must be inconsistency in the number range. This happens when the current number in the number range for dependent requirements is lower than the highest number in the database table of the dependent requirements RESB.
Please check the current number in transaction OMI2. Here in the interval you can see the current number. Then please check the highest number in table RESB. If the current number in OMI2 is lower than the highest number in table RESB then this should be the reason for the dump.
Check and revert. If that's not the case we'll look into other possibilities.
In mean time check for SAP Note 138108. -
ABAP/4 Open SQL array insert results in duplicate database records in SM58
Hi Everyone,
I am testing a file to idoc scenario in my Quality system. When I passed the input file, the mapping executed successfully and there are no entries in SMQ2 but still the idoc wasn't created in the ECC system. When I have checked in TRFC, I am getting the error ABAP/4 Open SQL array insert results in duplicate database records for IDOC_INBOUND_AYNCHRONOUS function module. I thought this is a data issue and I have tested with a fresh data which was never used for testing in Quality but even then I am getting the same error.Kindly advise.
Thanks,
Laawanyause FM idoc_status_write_to_database to change the IDoc status from 03 to 30 and then run WE14 or RSEOUT00 to change the status back to 03
resending idoc from status 03 ...is a data duplicatino issue on receiving side...why do u need to do that ?
Use WE19 tcode to debug
In we19
1)U can choose your Idoc number in existing Idoc textbox
2)Press execute
3)u will display ur Idoc struct
4)Dbl click on any field then u can modify its content
5)PressStd Outbound Processing Btn to process modified Idoc
Thats it -
Error: The ABAP/4 Open SQL array insert results in duplic in EWM
Hi Friends,
During outbound process in EWM, my completed EWM delivery gets stuck in SMQ1 with error "The ABAP/4 Open SQL array insert results in duplic". I performed following checks and found all the ok. Please help me with your insights.
- Checked the Master data Products, Business Partners,are CIFed properly. Yes they are done properly.
- Checked if inbound is stuck in same way. But its not.
- Checked if there is any enhancement stopping in ECC. There is some enhancement in Document_save in ECC outbound delivery which I got it commented. Still the problem is same.
Please suggest what could be the root cause.
Thanks
TrivediHi Rushikesh,
I checked all Number ranges (O/D in EWM and ECC, HU and Batches). All are ok. I tried taking help of ABAPer to see if any Run time errors occuring but no use.
Regards,
Trivedi -
Hi friends,
I'm going to read and process data in an interface coded in ABAP and OPEN SQL. To improve efficiency and reliability I'm processing the data in packets of a fixed size of rows - reading rows up to a predetermined numer into an internal table which then is processed and then finaly written back to database followed by "commit work". Then the process will continue with reading the next fixed number of rows, process them, and so on ...
The general question is, which is the most efficient way to implement this scenario?
I think of two basic approaches:
1.1) Loop over results from a cursor using FETCH NEXT CURSOR inside a LOOP appending the lines to the internal table.
2.1) Execute SELECT ... INTO TABLE <itab> FROM <table> UP TO <data packet size> ROWS.
My assumtion is that approach 2 would be the more effecient, is that correct?
The processed data will be written back to the database in one single statement:
2.2) INSERT <table> FROM TABLE <itab>
Which I assume is more efficient than doing the same using multiple inserts within a loop?
Regards,
ChristianIn native SQL you can also use the packet options.
SELECT <Fields name> appending corresponding fields of table <Internal table>
<b>package size 20000</b>
FROM <Database table name>
WHERE <Condition>.
ENDSELECT.
By using this the system will fetch the records from database table in packets [20000 records per package]
Regards
Aman -
Second DB Connection to the Standard R/3 Database in Open SQL?
Is there any explicit way in Open SQL to open a second DB connection to standard R/3 database? I want to save some data to the database, but do not want to interrupt the connection and its transaction context. So I need to open a second DB connection to store these data.
I learn from some notes that Native SQL can be used to open second connection either to the standard R/3 DB or to another database(same manufacturer or not), which we would not use. Our need is just to connect to the standard R/3 DB.
Anyone can help, I would very appreciate.Hi Stanley!
You are talking about an user-exit / BADI? They are never
inside select ... endselect loop. You can just insert your own data in any Z-Table. Don't rise any commit work - then your data fits in SAP's 'logical unit of work'-concept.
Or do you plan to do something different?
Regards,
Christian -
ABAP/4 open SQL array results in dupl
Hi All,
The contract in SRM is not transferred to ECC. When checked the outbound queue through smq1, it says 'ABAP/4 open SQL array results in dupl ' for the program name given as SAPMSSY1. I learnt that this occurs when trying to insert a record in
the database and that record already exists with the same key. Debug didn't help and also searching for the relevant notes. Please suggest.
Thanks.
Regards,
AnuradhaHi Anuradha,
please implement the note 1092012 into the backend system, and retest.
Eventually if you have a BAdI (e.g. the BBP_CTR) deactviate it also temporary to check the infulence.
Regards,
Peter -
Generate SQL Insert Statements
Hello,
I am testing generating insert statements for which I have a function which will return a sql statement.
This sql statement when I execute would results as sql insert statements.
What I am trying to acheive through a procedure is when I execute function, the result I would like to execute automatically and then the second sql I would like to store to a control file or sql file.
How can I acheive this?
Any help is very helpful
Regards
Edited by: user20090209 on Aug 20, 2009 11:34 AMHere is the function to generate sql
CREATE OR REPLACE function insert_sql(v_table_name varchar2)
return varchar2 as
b_found boolean := false;
v varchar2(32000);
v1 varchar2(32000);
v2 varchar2(32000);
begin
for s in (
select *
from all_tables
where table_name=upper(v_table_name)
--and owner=upper(v_owner)
) loop
b_found := true;
for ss in (
select *
from all_tab_columns
where table_name = s.table_name
order by column_id
) loop
if ss.data_type='NUMBER' then
v1:=v1||','||ss.column_name;
v2:=v2||',''''''||to_char('||ss.column_name||')||''''''';
end if;
if ss.data_type in ('VARCHAR2','CHAR') then
v1:=v1||','||ss.column_name;
v2:=v2||',''''''||replace(replace('||ss.column_name||','''''''',''''''''''''),''&'','''')||''''''';
end if;
if ss.data_type='DATE' then
v1:=v1||','||ss.column_name;
v2:=v2||',to_date(''''''||to_char('||ss.column_name||',''dd.mm.yyyy hh:mi:ss'')||'''''',''''dd.mm.yyyy hh:mi:ss'''')';
end if;
end loop;
v:='select ''insert into '||s.table_name||' (';
v:=v||substr(v1,2,9999)||') '||chr(10)||' values ('||substr(v2,2,9999)||'); '' txt from '||s.table_name;
end loop;
if not b_found then
v:='- Table ' || v_table_name || ' not found';
else
v:=v;
end if;
return v;
end;
/And I am calling like
CREATE OR REPLACE PROCEDURE test_gen_script_exec IS
type v_ref_cur is REF CURSOR;
v_ref_cur_var v_ref_cur;
v_temp_sql VARCHAR2(4000);
v_sql varchar2(4000);
begin
v_sql := insert_sql('table_name');--change here
open v_ref_cur_var for v_sql;
loop
fetch v_ref_cur_var into v_temp_sql;
exit when v_ref_cur_var%notfound;
execute immediate v_temp_sql;
end loop;
close v_ref_cur_var;
end;
/Edited by: user20090209 on Aug 20, 2009 1:24 PM -
Hello,
Could anyone please tell me how I can insert a null date into an oracle table dynamically? Here are my codes:
DATA: LV_KEY(10),
LV_DATE TYPE D.
TRY.
EXEC SQL.
INSERT INTO Z_ORACLE_TABLE
( KEY_FIELD, OPTION_DATE )
VALUES
( :LV_KEY, TO_DATE( :LV_DATE, 'YYYYMMDD' ) )
ENDEXEC.
ENDTRY.
Somehow, Oracle gives an error if LV_DATE is initial ('00000000'), saying the date is not between -49xx to ....
I could have done the following but it is kind of dumb:
TRY.
IF :LV_DATE IS INITIAL.
EXEC SQL.
INSERT INTO Z_ORACLE_TABLE
( KEY_FIELD, OPTION_DATE )
VALUES
( :LV_KEY, NULL )
ENDEXEC.
ELSE.
EXEC SQL.
INSERT INTO Z_ORACLE_TABLE
( KEY_FIELD, OPTION_DATE )
VALUES
( :LV_KEY, TO_DATE( :LV_DATE, 'YYYYMMDD' ) )
ENDEXEC.
ENDTRY.
Thanks in advance for any suggestions.Hi Sau Tong Calvin,
don't you mess up INITIAL ans NULL values.
In ABAP, every data type has an initial value. As opposed to other programming languages, all variables are set to their initial value before use, numeric fields get 0, TYPE N which is numeric character will take 0 in all places, strings are empty and character fields are space. ABAP date fields are type N technically, so will be '00000000'.
You can store as this using open SQL.
NULL value means there is nothing stored for this field - this may save disk space if only few records have values stored for the field. But it will make problems in a WHERE clause of selection because SPACE matches initial values but not NULL values and opposite.
I don't know too much about native EXEC SQL because I never needed in the last decade. Hopefully you can solve the task using ABAP open SQL.
Regards,
Clemens -
"Open sql" report no data sourced defined in windows
when I want to import data from sql database, the Open sql window report error
"There are no data sourced defined. Please create one to continue",
but I have defined the odbc data source using windows 's odbc administrator, why the error?
chuliangA couple of possibilities.
First are you licensed for Sql interface? If not, you might get that message.
Second, where did you create the ODBC connection on your computer or the server. It has to be on the server.
Third, did you create the odbc as a system driver? it needs to be so
Fourth, what operating system? If it's unix or AIX there is a hole bunch more you need to do to get odbc connections working. If it's windows, it's pretty easy.
Fifth, did you test the connection before trying it in Essbase?
Maybe you are looking for
-
Help, Adobe reader is preventing my computer from shuting down!
Every time I am trying to shut down my computer, there is a message that Adobe Reader is stil running and preventing it from shutting down, even though i have not opened Adobe! any suggestions?? Thanx
-
File Name and Target Directory name issue in FTP CC
Hi All , I am using following code to assing file name and directory name in UDF. I don;t want these parameters to be part of my target structure. Since i have created these files names in UDF, what are the values do i need to mention in FTP CC's "Fi
-
Adding Custom Fields to FAGLFLEXP Table
Hello, We have a requirement to update WBS Element for Planning related Data. So have added custom field(WBS Element) in structure CI_FAGLFLEX04. The field is visible when I open FAGLFLEXP table, but when I post data The custom field (WBS Element) i
-
Using SharedObjects to load and save data
Hello, i am having troubles with using shared objects to save and load data for my highscore feature of my game i am developing in actionscript 3. This is my main code. I am trying to update a dynamic text field that acts as an high score function [a
-
Post Author: mohamedsaleh70 CA Forum: Formula Greetings, I hope some expert would help me in this problem. I created a report in VB 2005 Pro. Then, I tried to create a formula. I went to the Field Explorer and right clicked the Formula Fields. I name