EXEC SQL
Hi,
What does an EXEC SQL stmt do in ABAP?
What is the disadvantage of using it?
Regards,
Kalai
Hi
<b>EXEC SQL</b>
EXEC SQL [PERFORMING subr].
ENDEXEC.
These statements define an area in an ABAP program in which one or more Native SQL statements are to be carried out. The area between EXEC and ENDEXEC is not completely checked by the syntax check. The statements entered there are passed to the Native SQL interface and processed there as follows:
Almost all SQL statements that are valid for the addressed database system can be included between EXEC and ENDEXEC, in particular the DDL statements. These SQL statements are passed from the Native SQL interface to the database system largely unchanged. The syntax rules are specified by the database system, in particular the case sensitivity rules for database objects. If the syntax allows a separator character between individual statements, you can include several Native SQL statements between EXEC and ENDEXEC. Generally, the semicolon ( is used as the separator character.
You can also include SAP-specific Native SQL language elements between EXEC and ENDEXEC. These statements are not passed directly from the Native SQL interface to the database, but are converted appropriately. These SAP-specific language elements are::
<b>Host variables</b>
Statements for cursor processing
Database procedure calls
Statements for establishing database connections
All Native SQL statements bypass SAP buffering. Automatic client handling is not performed.
<b>System fields</b>
The statement ENDEXEC sets the system fields sy-subrc and sy-dbcnt.
sy-subrc Meaning
0 The statements between EXEC and ENDEXEC were executed successfully.
4 The statements between EXEC and ENDEXEC were not executed.
The ENDEXEC statement sets sy-dbcnt to the number of table rows processed in the last Native SQL statement.
Programs with Native SQL statements are generally dependent on the database system used, so that they cannot be executed in all SAP Systems. This is especially true for the examples in this section, which was written for Informix database systems.
<b>Example</b> Inserting two rows in the database table SCARR. If neither of these rows exists, sy-subrc is set to 0 by ENDEXEC and sy-dbcnt to 1. Otherwise, an exception is raised and handled.
DATA: exc_ref TYPE REF TO cx_sy_native_sql_error,
error_text TYPE string.
TRY.
EXEC SQL.
INSERT INTO scarr
(MANDT, CARRID, CARRNAME, CURRCODE, URL)
VALUES ('000', 'FF', 'Funny Flyers', 'EUR',
'http://www.ff.com');
INSERT INTO scarr
(MANDT, CARRID, CARRNAME, CURRCODE, URL)
VALUES ('000', 'EF', 'Easy Flyers', 'EUR',
'http://www.ef.com');
ENDEXEC.
CATCH cx_sy_native_sql_error INTO exc_ref.
error_text = exc_ref->get_text( ).
MESSAGE error_text TYPE 'I'.
ENDTRY.
<b>Reward if usefull</b>
Similar Messages
-
SQL error 3113 occurred when executing EXEC SQL.
Hi,
We are facing one typical problem, One background is failing regularly with
below dump. as we now got all notes giving information, if database restarted
taking backup, these type of failures occur, but our database is only down for backup once in a week, but it is failing with frequenly.
in this two servers are located in different place, in this job tries to connect
another server to get material statistics.
It is giving some error message in sm21 with
SQL error 3113 occurred when executing EXEC SQL.
work procees in reconnect mode.
all notes saying these types of dump occur when database restared, but this dump
even though database is up.
below is short dump, please can anyone help me from this problem.
ABAP runtime errors DBIF_DSQL2_SQL_ERROR
Occurred on 08.01.2007 at 00:30:28
>> Short dump has not been completely stored. It is too big.
SQL error 3113 occurred when executing EXEC SQL.
What happened?
The error occurred in the current database connection "AZ1".
What can you do?
Note the actions and input that caused the error.
Inform your SAP system administrator.
You can print out this message by choosing "Print". Transaction ST22
allows you to display and manage termination messages, including keeping
them beyond their normal deletion date.
Error analysis
How to correct the error
Database error text........: "ORA-03113: end-of-file on communication channel#"
Triggering SQL statement...: "select mara.groes, mara.brgew, mara.ntgew,
mara.gewei, mara.volum, mara.voleh, mara.mstae, mara.mstde, mara.prdha,
marc.matnr, marc.werks, marc.mmsta, marc.mmstd from sapr3.mara, sapr3.m
where sapr3.mara.mandt = sapr3.marc.mandt and sapr3.mara.matnr =
Internal call code.........: "[DBDS/NEW DSQL]"
Please check the entries in the system log (Transaction SM21).
If the error occurred in a non-modified SAP program, you may be
able to find a solution in the SAP note system.
If you have access to the note system yourself, use the following
search criteria:
"DBIF_DSQL2_SQL_ERROR"
"ZM2431216 " or "ZM2431216 "
"EXTRACT_GENERAL_DATA"
If you cannot solve the problem yourself, please send the
following documents to SAP:
1. A hard copy print describing the problem.
To obtain this, select the "Print" function on the current screen.
2. A suitable hardcopy prinout of the system log.
To obtain this, call the system log with Transaction SM21
and select the "Print" function to print out the relevant
part.
3. If the programs are your own programs or modified SAP programs,
supply the source code.
To do this, you can either use the "PRINT" command in th
print the programs using the report RSINCL00.
4. Details regarding the conditions under which the error o
or which actions and input led to the error.
System environment
SAP Release.............. "46C"
Application server....... "essceu3"
Network address.......... "172.19.119.198"
Operating system......... "AIX"
Release.................. "5.3"
Hardware type............ "00C7ADBD4C00"
Database server.......... "ukblx176"
Database type............ "ORACLE"
Database name............ "EU3"
Database owner........... "SAPR3"
Character set............ "es_ES.ISO8859-1"
SAP kernel............... "46D"
Created on............... "Jul 9 2006 20:26:33"
Created in............... "AIX 1 5 00447C4A4C00"
Database version......... "OCI_920__OCI_7_API "
Patch level.............. "2257"
Patch text............... " "
Supported environment....
Database................. "ORACLE 8.0.5.., ORACLE 8.0.6.., ORACLE
8.1.6.., ORACLE 8.1.7.., ORACLE 9.2.0.., ORACLE 10.2.0.."
SAP database version..... "46D"
Operating system......... "AIX 1 4, AIX 2 4, AIX 3 4, AIX 1 5, AIX 2 5, AIX 3
5, , System build information:, , LCHN :
841480"
User, transaction...
Client.............. 600
User................ "MPZMMES"
Language key........ "S"
Transaction......... " "
Program............. "ZM2431216 "
Screen.............. "SAPMSSY0 1000"
Screen line......... 6
Information on where termination occurred
The termination occurred in the ABAP/4 program "ZM2431216 " in
"EXTRACT_GENERAL_DATA".
The main program was "ZM2431216 ".
The termination occurred in line 980
of the source code of program "ZM2431216 " (when callin
The program "ZM2431216 " was started as a background jo
Source code extract
009500 mara.ntgew,
009510 mara.gewei,
009520 mara.volum,
009530 mara.voleh,
009540 mara.mstae,
009550 mara.mstde,
009560 mara.prdha,
009570 marc.matnr,
009580 marc.werks,
009590 marc.mmsta,
009600 marc.mmstd
009610 into :w_ops-groes,
009620 :w_ops-brgew,
009630 :w_ops-ntgew,
009640 :w_ops-gewei,
009650 :w_ops-volum,
009660 :w_ops-voleh,
009670 :w_ops-mstae,
009680 :w_ops-mstde,
009690 :w_ops-prdha,
009700 :w_ops-matnr,
009710 :w_ops-werks,
009720 :w_ops-mmsta,
009730 :w_ops-mmstd
009740 from sapr3.mara, sapr3.marc
009750 where sapr3.mara.mandt = sapr3.marc.mandt
009760 and sapr3.mara.matnr = sapr3.marc.matnr
009770 and sapr3.mara.mandt = :p_mandt
009780 and sapr3.mara.matnr = :w_ebs-matnr
009790 and sapr3.marc.werks = :p_owerks
> ENDEXEC.
009810 endform. " extract_general_data
009820 *&
009830 *& Form append_i_ops
009840 *&
009850 * Appends W_OPS to I_OPS
009860 *
009870 form append_i_ops.
009880 append w_ops to i_ops.
009890 endform. " append_i_ops
009900 *&
009910 *& Form extract_material_description
009920 *&
009930 * Extracts a Material Description from the remote database an
009940 * modifies the current record in I_OPS.
009950 *
009960 * >P_SPRAS Language Key
009970 *
009980 form extract_material_description using p_spras.
009990 EXEC sql performing set_langauge.
Contents of system fields
SY field contents..................... SY field contents............
SY-SUBRC 0 SY-INDEX 0
SY-TABIX 1 SY-DBCNT 1
SY-FDPOS 18 SY-LSIND 0
SY-PAGNO 0 SY-LINNO 1
SY-COLNO 1
Chosen variables
Name.......................... Contents.1........2........3....+..
W_EBS-PRAT4
2
0
W_OPS-GROES
22222222222222222222222222222222
00000000000000000000000000000000
W_OPS-BRGEW #######
0000000
000000C
W_OPS-NTGEW #######
0000000
000000C
regards,
krishnaiah.Hi,
This is usually a SERVER SIDE DATABASE PROBLEM or SQLNET LISTENER (server side) PROBLEM. The client side should initially be ignored and instead the server should be investigated. In rare cases, this can be caused by client
side memory or other resource problem, or a DLL version mismatch, but this is
unlikely.
Enlist the assistance of your DBA. Then reproduce the ORA-3113 error on your
client application. Ask your DBA to look at the database side Alert.log and
trace files and look for ANY activity. Any activity that coincides with your
ORA-3113 will be a clue.
REgards
Vinod -
Getting core dump when using EXEC SQL CLOSE
In my pro*c program , i have used a cursor to fetch the set of accounts.Once cursor is opened , code will perform set
of operation using fetched data and then cursor is closed. Between open and closing of cursor , i have used 23 EXEC
SQL CLOSE. For example i am copying the value of a to b using strlcpy between fetch and close cursor statement.If
returned value from strlcpy is greater than size of destination variable, then flow should not proceed , in that case I will
close the cursor using EXEC SQL CLOSE and return the flow to calling program. Similarly i have closed the cursor at
another 22 locations.
When i compile the code and run binary the core dump occurs. On analyzing the core it shows
t@null (l@8) terminated by signal SEGV (no mapping at the fault address)
0xffffffffffffffff: <bad address 0xffffffffffffffff>
dbx: core file read error: address 0xfc4ffe48 not in data space
Current function is dbMtBaseClass::Pswd_Change
7860 sqlcxt(&_dbMtCtx, &sqlctx, &sqlstm, &sqlfpn);
if I remove any of the three EXEC SQL CLOSE commands , core dump does not occurs.
It looks strange.Please help me to resolve the issue.In my pro*c program , i have used a cursor to fetch the set of accounts.Once cursor is opened , code will perform set
of operation using fetched data and then cursor is closed. Between open and closing of cursor , i have used 23 EXEC
SQL CLOSE. For example i am copying the value of a to b using strlcpy between fetch and close cursor statement.If
returned value from strlcpy is greater than size of destination variable, then flow should not proceed , in that case I will
close the cursor using EXEC SQL CLOSE and return the flow to calling program. Similarly i have closed the cursor at
another 22 locations.
When i compile the code and run binary the core dump occurs. On analyzing the core it shows
t@null (l@8) terminated by signal SEGV (no mapping at the fault address)
0xffffffffffffffff: <bad address 0xffffffffffffffff>
dbx: core file read error: address 0xfc4ffe48 not in data space
Current function is dbMtBaseClass::Pswd_Change
7860 sqlcxt(&_dbMtCtx, &sqlctx, &sqlstm, &sqlfpn);
if I remove any of the three EXEC SQL CLOSE commands , core dump does not occurs.
It looks strange.Please help me to resolve the issue. -
Use Of "#EC CI_EXECSQL in ABAP with EXEC SQL. Statement giving Syntax Error
Dear Gurus,
I have encountered an issue while trying to remove warning for using Native SQL statement using pseudo comment "#EC CI_EXECSQL
The thing is like this -- i have used follwing native sql command in abap.
EXEC SQL.
CONNECT TO 'SURROUND_DB'
ENDEXEC.
Now when i am checking this code in code inspector it is showing a warning with information below
CA CL_CI_TEST_CRITICAL_STATEMENTS0006
Code Inspector
Critical Statements
Use of Native SQL
Authorization checks cannot be appropriately run using EXEC SQL and should be carried out at program level.
The message can be hidden using the pseudo-comment "#EC CI_EXECSQL
Use of exceptin handling section for that warning showing me to use :
The message can be hidden using pseudo
comment "#EC CI_EXECSQL
Now when I am using "#EC CI_EXECSQL in the abap like below :
EXEC SQL. "#EC CI_EXECSQL
CONNECT TO 'SURROUND_DB'
ENDEXEC.
It is giving syntax error
The text literal ""#EC CI_EXECSQL " is longer than 255
characters.Check whether it ends correctly.
Please provide the guideline to resolve this issue.
Thanks & regards
Saifur Rahaman.Hi Saifur,
You can remove the warning using the following syntax:
EXEC "#EC CI_EXECSQL
SQL.
CONNECT TO 'SURROUND_DB'
ENDEXEC.
At least, it worked fine for me when using OPEN CURSOR, SELECT, FETCH and so on statements.
The way to use the pseudo comment is not very intuitive, but at least for my examples worked fine.
I hope this may help you.
Best regards,
Edgardo G. König -
Hi All,
I am using EXEC SQL join in my ABAP report,but it is giving dump.could you please correct my following code?
START-OF-SELECTION.
CONCATENATE '%' pa_match '%' INTO tp_match.
EXEC SQL.
OPEN dbcur FOR
SELECT kunnr,name1, banks
FROM kna1 as a inner join
knbk as b
on akunnr = bkunnr
WHERE a.kunnr = b.kunnr and
upper(a~name1) LIKE :tp_match
ENDEXEC.
DO.
EXEC SQL.
FETCH NEXT dbcur INTO :wa_name1
ENDEXEC.
IF sy-subrc <> 0.
EXIT.
ENDIF.
APPEND wa_name1 TO ta_name1.
COLLECT wa_name1 INTO ta_name1.
ENDDO.
EXEC SQL.
CLOSE dbcur
ENDEXEC.Remove the 'As' from the statement
EXEC SQL.
OPEN dbcur FOR
SELECT kunnr,name1, banks
FROM kna1 a inner join "Delete 'AS' here
knbk b
on a~kunnr = b~kunnr
WHERE a.kunnr = b.kunnr and
upper(a~name1) LIKE :tp_match
ENDEXEC. -
Where can i set up connection in "exec sql"?
i have code block like this:
EXEC SQL.
SET CONNECTION :'PA'
ENDEXEC.
IF SY-SUBRC <> 0.
Connection not yet opened.
EXEC SQL.
CONNECT TO :'PA'
ENDEXEC.
IF SY-SUBRC <> 0.
write: / sy-msgid ,sy-msgno,sy-msgty,sy-msgv1,sy-msgv2,sy-msgv3,sy-msgv4.
write: / 'connect error'.
RAISE EXCEPTION TYPE cx_sy_native_sql_error.
ENDIF.
ENDIF.
where can i set up the 'PA'?thanks very much!!!!You set up new databse connection for SAP to communincate with using 'DBCO' tcode.
-
What does an EXEC SQL stmt do in ABAP? What is the disadvantage of using it
hi,
What does an EXEC SQL stmt do in ABAP? What is the disadvantage of using it?
regards.sorry, question resolved.
-
How to use INSERT in EXEC SQL ...... ENDEXEC ?
Hi,
The following code;
DATA: BEGIN OF str_insert,
a(3) TYPE c,
b(3) TYPE c,
END OF str_insert.
EXEC SQL.
SET CONNECTION DEFAULT
ENDEXEC.
str_insert-a = 'a'.
str_insert-b = 'b'.
EXEC SQL.
INSERT INTO ZSAP VALUES :str_insert
ENDEXEC.
The Structure of the ZSAP table (There is no data in ZSAP);
A CHAR 3 (Primary Key)
B CHAR 3
I cannot instert a record to this table it throughs the following error;
Runtime Errors DBIF_DSQL2_SQL_ERROR
Exceptn CX_SY_NATIVE_SQL_ERROR
How could use a structure to insert values into ZSAP?
Thanks,
KishanHello..
loop at T_PC.
loop at T_PCD .
at new NUMREFERENCIA.
exec sql.
INSERT INTO tblPolizaContableR3
(LibroMayor, PeriodoContable, Prefijo, NumReferencia,
Fecha, FuenteDiario, ComentarioPoliza, Moneda,
TipoCambio, RefExternaID1, RefExternaID2, RefExterna1,
RefExterna2, DescRefExterna)
VALUES (:T_PC-LIBROMAYOR, :T_PC-PERIODOCONTABLE,
:T_PC-PREFIJO, :T_PC-NUMREFERENCIA, :T_PC-FECHA,
:T_PC-FUENTEDIARIO, :T_PC-COMENTARIOPLIZA, :T_PC-MONEDA,
:T_PC-TIPOCAMBIO, :T_PC-REFEXTARNAID1, :T_PC-REFEXTERNAID2,
:T_PC-REFEXTERNA1, :T_PC-REFEXTERNA2, :T_PC-DESCREFEXTERNA)
endexec.
endat.
exec sql.
INSERT INTO tblPolizaContableDetR3
(LibroMayor, PeriodoContable, Prefijo, NumReferencia,
Partida, Cuenta, CuentaIMSA, CCostoIMSA,
Cargo, Abono, ComentarioPartida)
VALUES (:T_PCD-LIBROMAYOR, :T_PCD-PERIODOCONTABLE,
:T_PCD-PREFIJO, :T_PCD-NUMREFERENCIA, :T_PCD-PARTIDA,
:T_PCD-CUENTA, :T_PCD-CUENTAIMSA, :T_PCD-CCOSTOIMSA,
:T_PCD-CARGO, :T_PCD-ABONO, :T_PCD-COMENPARTIDA)
endexec.
endloop.
Hope this help you.
Regards, Gustavo Estrada -
Hi,
My ProC code works fine when I have Exec sql in it but when I include plsql block in it using EXEC SQL EXECUTE, it throws the following error:
/tmp/cc88UGZa.o(.text+0x2c0): In function `main':
: undefined reference to `ECPGget_sqlca'
I have included all these below header files:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sqlca.h>
#include <sqlda.h>
#include <sqlcpr.h>
and the path have been mentioned in pcscfg.cfg as well.
what can be the reason and the solution to this please? Help is appreciated.
Thanks in advance!
AshYou have to use 'BEGIN procedure_name END' in the execute statement while calling PL/SQL Procedures
EXEC SQL EXECUTE
DECLARE
BEGIN
END;
END-EXEC; -
EXEC SQL Error: ORA-01401: Inserted value too large for column
Getting this SQL Error: ORA-01401: Inserted value too large for column..on an EXEC SQL Insert statement when writing to an
external Oracle DB from SAP.
On further analysis..it appears that this happens to the fields..when the string length matches the field length.
Example: Plant field is defined as char(4) on the SAP side and it is a Varchar2(4) on the Oracle side.
When a value like '1015' is passed thru a variable in the insert statement then this ORA-01401 error pops up.
No error:
- if the value '1015' is passed directly in the insert statement to the external table (or)
- when a value with 3 chars or less(like the first three chars..101) is passed thru a variable defined as 'Plant(4) type c'.
- when using EXEC sql within SAP
- when reading from the external db table
This was working ok until the Oracle Patch P9147110 was installed recently.
Any suggestions !Hello Dvas,
what's the characterset of your external database?
What's the column definition in your external database (byte or character based)?
If you use a characeterset like UTF8 it is possible, that one character needs more than one byte and then you will run into such kind of issues if the definition is too small.
Regards
Stefan -
Hi,
I have this abap/exec sql code to extract data from as400/db2.
I am getting data by a "select" statement and i am trying to append the records with append statements.
but, not works.
EXEC SQL.
CONNECT TO 'SATDBR'
ENDEXEC.
EXEC SQL.
--->(HERE THE PROBLEM) OPEN C1 FOR.
SELECT A,B,C,D
FROM SAPTEST.XX1
ENDEXEC.
EXEC SQL.
OPEN C1
FETCH NEXT C1 INTO
:ZTABLE.AA, :ZTABLE.BB, :ZTABLE.CC, :ZTABLE.DD
ENDEXEC.
IF sy-subrc <> 0.
EXIT.
ELSE.
APPEND ZTABLE.
ENDIF.
ENDDO.
EXEC SQL.
CLOSE C1
ENDEXEC.
EXEC SQL.
DISCONNECT 'SATDBR'
ENDEXEC.
I need to declare the cursor??? whats wrong in my code :S
the runtime error is "A SQL mistake has appeared by the execution of Native SQL."
i would appreciate your help.
thanks
vickyhi,
I recommend you, make the select and test it first in the DB2 console.
Only delcare your internal tables, your variable with abap code.
To extract the data with the select statement is enough, to fill the table with several records use this code:
EXEC SQL.
CONNECT TO 'DB2' " the name of the connection
ENDEXEC.
EXEC SQL.
OPEN C1 FOR
SELECT A,B,C,D
FROM SAPTEST.XX1
ENDEXEC.
DO
EXEC SQL.
OPEN C1
FETCH NEXT C1 INTO
:ZTABLE
ENDEXEC.
IF sy-subrc <> 0.
EXIT.
ELSE.
APPEND ZTABLE.
ENDIF.
ENDDO.
EXEC SQL.
CLOSE C1
ENDEXEC.
EXEC SQL.
DISCONNECT 'DB2'
ENDEXEC.
The ZTABLE must have the same order in which you put on the fields in the "select"
DATA: BEGIN OF ztable OCCURS 0,
A(1) TYPE c
B(8) TYPE c
C(17)TYPE N
D(19 TYPE c
DATA: END OF ZTABLE.
I HOPE THIS INFORMATION HELPS YOU!!
REGARDS
VICKY
Message was edited by: Victoria León -
Hello,
I'm trying to run an EXEC SQL statement with an IN clause. Here's my SQL code:
EXEC SQL.
OPEN C FOR
SELECT name
FROM sv_hoover_data
where dunsNum in :DUNS_NUMBERS
ENDEXEC.
My DUNS_NUMBERS variable is of type String and contains the following data:
('12334223','4353434','54674563')
When the statement is executed, I receive the following error message in SM21:
Line 1: Incorrect syntax near '@P1'.
Also, the underlying database is MS SQL Server. When I run the query via MS Query Ananlyzer, it runs fine.
Does any know if EXEC SQL can handle IN clauses, and if so, how they're written?
Thanks,
MattI haven't used it myself (yet), but this is what I found in the help:
EXEC SQL - EXECUTE
Syntax
EXEC SQL.
EXECUTE PROCEDURE proc ( IN p_in1 IN p_in2 ...,
OUT p_out1 OUT p_out2 ...,
INOUT p_inout1 INOUT p_inout2 ... )
ENDEXEC.
Effect
In database systems, you can define procedures as so-called "stored procedures". Since the syntax for calling such procedures and the pertinent parameter transfer for various database systems can vary widely, a uniform command exists in Native SQL.
The statement EXECUTE PROCEDURE calls a procedure proc stored in the database. For all formal parameters of the procedure, you must specify the actual parameters, separated by commas. You must specify IN, OUT or INOUT before every actual parameter, in order to indicate whether the parameter is an input, output, or input/output parameter. You can use literals or Host Variables labeled by a colon(:)for the actual parameters.
Example
This example defines a selfunc procedure using database specific SQL-Statements (Informix). It also calls the procedure using the SAP-specific Native-SQL-Statement EXECUTE PROCEDURE in a LOOP-loop by means of a Selection Table, and deletes the the procedure using an SQL-Statement. In the case shown here, the procedure is a function whose return value output in EXECUTE PROCEDURE is copied to the host variable name.
DATA scarr_carrid TYPE scarr-carrid.
SELECT-OPTIONS s_carrid FOR scarr_carrid NO INTERVALS.
DATA s_carrid_wa LIKE LINE OF s_carrid.
DATA name TYPE c LENGTH 20.
TRY.
EXEC SQL.
CREATE FUNCTION selfunc( input CHAR(3) )
RETURNING char(20);
DEFINE output char(20);
SELECT carrname
INTO output
FROM scarr
WHERE mandt = '000' AND
carrid = input;
RETURN output;
END FUNCTION;
ENDEXEC.
LOOP AT s_carrid INTO s_carrid_wa
WHERE sign = 'I' AND option = 'EQ'.
TRY.
EXEC SQL.
EXECUTE PROCEDURE selfunc( IN :s_carrid_wa-low,
OUT :name )
ENDEXEC.
WRITE: / s_carrid_wa-low, name.
CATCH cx_sy_native_sql_error.
MESSAGE `Error in procedure execution` TYPE 'I'.
ENDTRY.
ENDLOOP.
EXEC SQL.
DROP FUNCTION selfunc;
ENDEXEC.
CATCH cx_sy_native_sql_error.
MESSAGE `Error in procedure handling` TYPE 'I'.
ENDTRY. -
TRY ... CATCH doesn't work with EXEC SQL?
When I created a native SQL statement, I knew before, that it would take a few tries to get it working. I decided to use exception classes to avoid short dumps, but it didn't work.
Following code causes a short dump because of the dot after :xp_stras in the native SQL SELECT statement:
try.
EXEC SQL PERFORMING list.
SELECT LIFNR, NAME1, STRAS
INTO :xsl
FROM LFA1
WHERE UPPER( NAME1 ) LIKE :xp_name1
AND UPPER( STRAS ) LIKE :xp_stras.
ENDEXEC.
catch CX_SY_NATIVE_SQL_ERROR.
write: /1 'CX_SY_NATIVE_SQL_ERROR'.
catch CX_SY_SQL_ERROR.
write: /1 'CX_SY_SQL_ERROR'.
catch CX_DYNAMIC_CHECK.
write: /1 'CX_DYNAMIC_CHECK'.
catch CX_ROOT.
write: /1 'CX_SY_ROOT'.
endtry.
In ST22 you can see
Name of runtime error: DBIF_DSQL2_SQL_ERROR
Exception:
The name of the exception is empty, in other short dumps you can find there the name of the exception class. Maybe that's the reason for CATCH does'nt work, but I don't understand it.
Online help for EXEC SQL says:
Catchable Exceptions
CXSY_NATIVE_SQL_ERROR_
Cause: SQL-Error at the execution of a Native SQL-command.
Runtime Error: DBIF_DSQL2_SQL_ERROR
We have SAP ECC 6.0 with SAP_BASIS rel. 700 lvl. 0013.
If You have an idea why CATCH doesn't work, please tell me!
Regards,
KlausHi Rob,
I tried out Your original code as program ZTEST5 and got a short dump (sorry, some of the short dump symbols are formatting this post in a wrong way ...):
Short text
An SQL error occurred when executing Native SQL.
What happened?
The error 919 occurred in the current database connection "DEFAULT".
What can you do?
Note down which actions and inputs caused the error.
To process the problem further, contact you SAP system
administrator.
Using Transaction ST22 for ABAP Dump Analysis, you can look
at and manage termination messages, and you can also
keep them for a long time.
How to correct the error
Database error text........: "ORA-00919: invalid function"
Database error code........: 919
Triggering SQL statement...: "FETCH NEXT "
Internal call code.........: "[DBDS/NEW DSQL]"
Please check the entries in the system log (Transaction SM21).
If the error occures in a non-modified SAP program, you may be able to
find an interim solution in an SAP Note.
If you have access to SAP Notes, carry out a search with the following
keywords:
"DBIF_DSQL2_SQL_ERROR" " "
"ZTEST5" or "ZTEST5"
"START-OF-SELECTION"
If you cannot solve the problem yourself and want to send an error
notification to SAP, include the following information:
1. The description of the current problem (short dump)
To save the description, choose "System->List->Save->Local File
(Unconverted)".
2. Corresponding system log
Display the system log by calling transaction
Restrict the time interval to 10 minutes befor
after the short dump. Then choose "System->List->
(Unconverted)".
3. If the problem occurs in a problem of your own
program: The source code of the program
In the editor, choose "Utilities->More
Utilities->Upload/Download->Download".
4. Details about the conditions under which the e
actions and input led to the error.
System environment
SAP-Release 700
Application server... "lux01617"
Network address...... "195.217.80.104"
Operating system..... "Linux"
Release.............. "2.6.5-7.283-smp"
Hardware type........ "x86_64"
Character length.... 16 Bits
Pointer length....... 64 Bits
Work process number.. 5
Shortdump setting.... "full"
Database server... "lux09208"
Database type..... "ORACLE"
Database name..... "D10"
Database user ID.. "SAPDAT"
Char.set.... "C"
SAP kernel....... 700
created (date)... "Dec 2 2007 20:18:08"
create on........ "Linux GNU SLES-9 x86_64 cc3.3.3"
Database version. "OCI_102 (10.2.0.2.0) "
Patch level. 138
Patch text.. " "
Database............. "ORACLE 9.2.0.., ORACLE 10.1.0.., ORACLE 1
SAP database version. 700
Operating system..... "Linux 2.6"
Memory consumption
Roll.... 16192
EM...... 16759392
Heap.... 0
Page.... 98304
MM Used. 694160
MM Free. 3493088
User and Transaction
Client.............. 500
User................ "Z0000D2P"
Language key........ "E"
Transaction......... "SE38 "
Transactions ID..... "48FE92EB921F51C3E1000000C3D95068"
Program............. "ZTEST5"
Screen.............. "SAPMSSY0 1000"
Screen line......... 6
Information on where terminated
Termination occurred in the ABAP program "ZTEST5" - in "START-OF-SELECTION".
The main program was "ZTEST5 ".
In the source code you have the termination point in line 16
of the (Include) program "ZTEST5".
Source Code Extract
Line SourceCde
1 REPORT ztest LINE-SIZE 80 MESSAGE-ID 00.
2
3 TABLES: lfa1.
4
5 DATA: BEGIN OF xsl,
6 lifnr TYPE lfa1-lifnr,
7 name1 TYPE lfa1-name1,
8 stras TYPE lfa1-stras,
9 END OF xsl.
10
11 DATA: xp_name1 TYPE lfa1-name1,
12 xp_stras TYPE lfa1-stras.
13
14 TRY.
15 EXEC SQL PERFORMING list.
>>>>> SELECT LIFNR, NAME1, STRAS
17 INTO :xsl
18 FROM LFA1
19 WHERE UPPER( NAME1 ) LIKE :xp_name1
20 AND UPPER( STRAS ) LIKE :xp_stras.
21 ENDEXEC.
22
23 CATCH cx_sy_native_sql_error.
24 WRITE: /1 'CX_SY_NATIVE_SQL_ERROR'.
25 CATCH cx_sy_sql_error.
26 WRITE: /1 'CX_SY_SQL_ERROR'.
27 CATCH cx_dynamic_check.
28 WRITE: /1 'CX_DYNAMIC_CHECK'.
29 CATCH cx_root.
30 WRITE: /1 'CX_SY_ROOT'.
31 ENDTRY.
32
33 &----
34 *& Form LIST
35 &----
Edited by: Klaus Babl on Oct 22, 2008 6:42 AM -
SELECT on TIMESTAMP field from ABAP with EXEC SQL
Hello,
I'm trying to get a field of one table which is defined as TIMESTAMP. MaxDB parameter DATE_TIME_FORMAT is set to INTERNAL. When I do the SELECT in SQL Studio I get ISO format 'YYYY-MM-DD HH:MM:SS.MMMMMM' back. So I tried a SELECT with ISO in WHERE clause, but I'm always getting a shortdump with this error:
Database error text........: "POS(82) Invalid date input value"
Database error code........: "-3065"
Then I did a SELECT without a WHERE clause in ABAP and got value '06-FEB-09' back from this field. So I tried with this ABAP statement and got no shortdump, but I also need to add time and not only the date.
EXEC SQL.
SELECT recv_time INTO :l_time FROM ztest WHERE sent_recv_time = '06-FEB-09'
ENDEXEC.
I'm using Native SQL because the SELECT is on a table which is not located in SAP Schema User. "SELECT recv_time FROM ztest WHERE recv_time = '2009-02-24 10:02:55.888000'" works in SQL studio, but not from ABAP.
Does anyone know which format I need to specify in the WHERE clause?
Regards
Markus Karsch
Edited by: Markus Karsch on Feb 26, 2009 4:22 PM>
Thomas Theodor Koetter wrote:
> Hello Markus
>
> I don't know whether this will work from ABAP, but at least MaxDB can internally handle the ODBC literals for time, date and timestamp.
>
> Therefore literals like
>
> "{d'0001-02-03'}"
> "{t'01:02:03'}"
> "{ts'0001-02-03 04:05:06'}"
>
> might work. See [http://msdn.microsoft.com/de-de/library/ms190234(SQL.90).aspx]
>
>
> HTH & regards Thomas
Hi Thomas,
Thanks for your help. Unfortunately doesn't seem to work, I get following shortdumps (tried with 3 different notations):
Database error text........: " "
Database error code........: "-4005"
Triggering SQL statement...: "SELECT xxxxxx, status, sent_xxxx_time FROM
xxx_xxxxxxxxx WHERE sent_recv_time = "{ts'2009-02-06 04:05:06'}""
Database error text........: "POS(87) Invalid keyword or missing delimiter"
Database error code........: "-3008"
Triggering SQL statement...: "SELECT xxxxxx, status, sent_xxxx_time FROM
xxx_xxxxxxxxx WHERE sent_recv_time = '{ts' 2009-02-06 04:05:06 '}'"
Database error text........: "POS(81) Missing value specification"
Database error code........: "-5010"
Triggering SQL statement...: "SELECT xxxxxx, status, sent_xxxx_time FROM
xxx_xxxxxxxxx WHERE sent_recv_time = { ts '2009-02-06 04:05:06.000' }"
Regards
Markus -
EXEC SQL and DBIF_DSQL2_CONNECTERR error
Hello,
Currently our shipping system is communicating with SAP below are the parameters used:
<SAPProgramID>kewill_LXD</SAPProgramID>
<SAPGatewayHost>10.XX.40.XX</SAPGatewayHost>
<SAPGatewayService>sapgw00</SAPGatewayService>
<TransHandlerConnString>STMT=;OPTION=3;DSN=didb;UID=sn_usr;PASSWORD=sipndb;DESC=MySQL ODBC 3.51 Driver;DATABASE=didb;SERVER=localhost;PORT=3306</TransHandlerConnString
This is what I have in DBCON or tcode DBCO
Connection Name: Ship
DBMS: MSS
User Name: sn_usr
Password: sipndb
Conn. info: MSSQL_SERVER=localhost;MSSQL_DBNAME=didb
I get a dump with DBIF_DSQL2_CONNECTERR error when I try to use this in the EXEC SQL:
REPORT ZKEWILL_CONN .
Tables: DBCON.
DATA: BEGIN OF WA,
ship_date(10), S2Name1(50),
END OF WA.
DATA : bdate(10) value '2008-09-29',
edate(10) value '2008-10-05'.
EXEC SQL.
CONNECT TO 'KEWILL' AS 'K'
ENDEXEC.
EXEC SQL.
SET CONNECTION 'K'
ENDEXEC.
EXEC SQL.
SELECT ship_date, s2name1 INTO :WA FROM shipment_header
WHERE ship_date >= :bdate
AND ship_date <= :edate
ENDEXEC.
WRITE: / WA-ship_date, WA-s2name1.
We are in 4.6C. Please let me know if I need to make changes to the DBCO or to the program or both.... thanks!!
AJHi Jimmy,
The issue is more related to livecache.So can you please close this tread and create new thread under forum 'SAP MaxDB/livecache'.
Thanks & Regards,
Sunitha -
EXEC SQL - Convert NVARCHAR to char
Hi all,
I am tring to read data from Sql sever using native SQL,
My problem is that if I need to get data using WHERE on a field that is declared as NVARCHAR in SQL then the sekect is not working.
for example -
EXEC SQL.
select count(*)
from DocLine@MICRONET1_LINK
where "DocNum" = '1234'
into :lv_count
ENDEXEC.
DocNum is defined as NVARCHAR.
in SQL server there is a function name CONVERT but I cant use it threw Native Sql in abap.
Thanks,
NaamaLuc,
You can use the reftohex() function (http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/functions100a.htm).
Regards,
Geoff
Maybe you are looking for
-
How do I change the default POP account directory (~/Library/Mail)?
With Mail 1.0 in 10.3.9, I could change the default ~/Library/Mail storage location for a POP account. I did this by setting up an account and in the advanced tab choosing a path. With Mail 2.0 in 10.4.4, when going through the guided account setup,
-
My ipod touch is just showing the apple
im having trouble with my ipod touch 8gb
-
The PS in my CS6 wont open. I have uninstalled and reinstalled, same problem, I did change a preference for storage of photos to and external harddrive because of large files prior to any trouble is all I can think off ,but if that is the problem..ho
-
It is possible to disable SkyDrive, right?
Hi, Office 2013 prominently gives users the option to save to SkyDrive - if they have a Microsoft (Hotmail, Live, XBox etc) account they just need to enter a username and password and they are away, nice and easy. Unfortunately, and I'm sure I'm not
-
Slow Scrolling pdf file on MACPro using acrobat Pro
Hey Guys, I am having problem when I try to edit 300Pages PDF file on MACPRO quad core 3.2 2010 with 10GB memory running 10.8.4 with adobe acrobat pro 9.3 it's sluggish and very slow when open on 300% zoom. I tried the same file on my MBP i5 2.4 with