Querying an SQL Database from ABAP

Is is possible from within ABAP in R/3 (or NetWeaver) to query a non-SAP database? For example, can I write ABAP code which will go after data in say a non SAP DB2 database at some remote location?
Kevin

Hi
Connecting to an External database from SAP
Step 1: Create an entry for the External database in DBCON table using Trxn: DBCA.
Table: DBCON (Description of Database Connections)
Field Name Description Value (For: E.g.:)
CON_NAME Logical name for a database connection RAJ
DBMS Database system MSS
USER_NAME Database user <username>
PASSWORD Password for setting up the connection to the database <pwd>/<pwd>
CON_ENV Database-specific information for a database connection MSSQL_SERVER=depotserver MSSQL_DBNAME=HOF_INDORE
DB_RECO Availability type for an open database connect  
Step 2: Now you can write code to connect to the external database…
Your Sample code can be something like this……
DATA: BEGIN OF wa,
c_locid(3),
c_locname(50),
c_locstate(5),
END OF wa.
EXEC SQL.
CONNECT TO 'RAJ' AS 'V'
ENDEXEC.
EXEC SQL.
SET CONNECTION 'V'
ENDEXEC.
*- Get the data from MS-SQL Server
EXEC SQL.
open C1 for
select
loc_id,
loc_name,
loc_state
from ho_loc_mast
ENDEXEC.
DO.
EXEC SQL.
FETCH NEXT C1 into :wa-c_locid, :wa-c_locname, :wa-c_locstate
ENDEXEC.
IF sy-subrc = 0.
PERFORM loop_output.
ELSE.
EXIT.
ENDIF.
ENDDO.
EXEC SQL.
CLOSE C1
ENDEXEC.
*& Form LOOP_OUTPUT
Output
FORM loop_output .
WRITE: /5 wa-c_locid, 10 wa-c_locname, 65 wa-c_locstate.
CLEAR wa.
ENDFORM. " LOOP_OUTPUT
Regards
Raj

Similar Messages

  • How to connect and query the sql database in mobile application

    Hello,
    Can any one say how to connect the sql database from the j2me application.
    I have got some info that only through servlet or jsp only we can connect the database and from their we should get the info or query in mobile application.
    Is it true? and can i have any sample codes or white paper or guildlines.
    It would be more useful form my project.
    Thanks in advance.
    regards,
    sara

    Hi David,
    According to your description, when you add Windows Azure Mobile Services to a Window Phone 8 app, then store app data in the new mobile service. I recommend you post the related question on the Windows Azure Mobile Services Forums at
    http://social.msdn.microsoft.com/Forums/en-US/home?forum=azuremobile .It is appropriate and more experts will assist you.
    In addition, there are the details about creating a Windows Phone app connected to your mobile service.
    http://www.windowsazure.com/en-us/develop/mobile/tutorials/get-started-wp8/
    http://www.windowsazure.com/en-us/develop/mobile/tutorials/get-started-with-data-wp8/
    Thanks,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • How to move SQL database from one location to another location i.e. from C' drive to D' drive

    Hi, How to move SQL database from one location to another location i.e. from C' drive to D' drive ? please share some link.
    Thanks and Regards, Rangnath Mali

    Hi Rangnath,
    According to your description, my understanding is that you want to move databased from C drive to D drive.
    You can detach Database so that the files become independent, cut and paste the files from source to destination and attach again.
    There are two similar posts for your reference:
    http://mssqltalks.wordpress.com/2013/02/28/how-to-move-database-files-from-one-drive-to-another-or-from-one-location-to-another-in-sql-server/
    http://stackoverflow.com/questions/6584938/move-sql-server-2008-database-files-to-a-new-folder-location
    Best Regards,
    Wendy
    Wendy Li
    TechNet Community Support

  • Can I connect Azure SQL Database from Project Siena ?

    Can I connect Azure SQL Database from Project Siena ?
    I want to connect Azure SQL Database of Office 365 SharePoint's Access App from Project Siena.
    Access App's Database is Azure SQL Database.
    and can connect to Excel/PowerBI/etc.
    Access App's Database can connect from specific location / any locations.
    Access App's Database can allow read-only connection / read-write connection.
    I want to create Windows App connected to Access App's Database.
    Regards,
    Yoshihiro Kawabata.

    Hi Yoshihiro,
    Could you share more with us about the high level scenario for what you are trying to accomplish offline? We can discuss further at
    [email protected]
    Once we are done, we will definitely share our findings with the community.
    Thanks!

  • Transferring 3 SQL databases from both SQL Express 2005 and Standard to a new physical server

    I am trying to figure out the best method for transferring SQL 2005 databases from 2 different physical servers to a new server running windows server 2008 64bit.
    I own a fully registered copy of Microsoft SQL 2005 32bit Standard Edition. However all of my SQL databases together are only 4GB in size thereby making 2008 SQL Express an option.
    Here is the breakdown of the servers:
    1) (Old Server1) Windows 2003 Server 32bit - SQL Express 2005 32bit
    2) (Old Server2) Windows 2003 Server 32bit - SQL Server 2005 32bit Standard
    3) (New Server) Windows 2008 Server 64bit - (Not sure which version to install)
    **The objective is to migrate 2 SQL databases from Old Server1 and 1 SQL database from Old Server 2 to the New Server. What version should I install on the new server??? Do I go with 2008 express or install the 2005 Standard Edition?
    Pending your response to which version to install, what are the correct steps to migrate (which I have never done before) the databases from both of these servers to the new server?
    I have researched this online and I think this particular situation is unique in that I am transferring from both SQL Express and Standard from 2 different physical servers to a 2008 server that is 64bit. I cannot find anything online that I feel confident
    in trying. Please help me, as I have this migration deadline of this weekend. Any help is appreciated. Thanks.

    Hello,
    You may choose between using backup/restore or using detach/attach methods to migrate the databases.
    https://msdn.microsoft.com/en-us/library/ms187858(v=sql.90).aspx
    You can transfer logins using the following article.
    http://support.microsoft.com/en-us/kb/918992
    To decide if you migrate to Express Edition or to another edition, please review the features supported by each edition. For instance, Express Edition does not support jobs (SQL Server Agent is not available).
    https://msdn.microsoft.com/en-us/library/cc645993(v=sql.100).aspx
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • Accessing MsSQL Database from ABAP

    Hi Guys,
         I want to connect to an external MsSQL Database running in a window environment from an ABAP Report program where the SAP instance running in a Linux OS with DB2 as a Database. I tried all options suggested in all public forums like maintaining DBCON table entry & placing compatible dll files. I need answers from individuals who have done it in the recent past with this environment not beating bushes.
    Thanks in advance.
    Regards
    Vijaya

    hi,
    see on oss note  Question 4
    Note 555223 - FAQ: Microsoft SQL Server
    Q4: My SAP System runs under Oracle (DB2, SAPDB, ...) and I want to
    exchange data with a non-SAP Microsoft SQL Server directly from ABAP.
    Q4: My SAP System runs under Oracle (DB2, SAPDB, ...) and I want to exchange data with a non-SAP Microsoft SQL Server directly from ABAP. A4: The establishing and use of connections from an R/3 system to another non-SAP database (from the same vendor or not) is called multi-connect and is described in note 178949.
    But you must have a specific application server running on Windows if you want to connect SAP to your Microsoft SQL server with DBCON.
    Rgds
    Edited by: stéphane mouraux on Feb 27, 2010 11:21 PM

  • Help me on CVP class to query a SQL database

    Dear friends,
    I try to create a class extends to Action element. But when I do deploy, it return no result.
    I want this class receive Calling Number and do the query to database (SQL as I test, later if it works I will do for another database). After query I will get Name, Address, Email of this Customer based on Calling Number (ANI).
    Please help to take a look on my program and help me to fix it.
    Thank you very much.
    import com.audium.server.AudiumException;
    import com.audium.server.voiceElement.ActionElementBase;
    import com.audium.server.session.ActionElementData;
    import java.sql.*;
    * This class is called when a standard action has been configured to use a
    * Java class. Since this is a standard action element, it applies to a
    * specific application and does not have a configuration. As a result, the
    * only method needed in this class is the doAction method.
    public class DBLookupStandardAction extends ActionElementBase
    class WhatIGot
    String ANI = null;
    String Name = null;
    String Address = null;
    String Email = null;
    public void doAction(String name, ActionElementData data) throws AudiumException
    Connection conn = null;
    String Name = null;
    String Address = null;
    conn = connectToDatabase();
    String ani = data.getAni();
    WhatIGot whatigot = new WhatIGot();
    whatigot = QueryDatabase(conn, ani);
    Name = whatigot.Name;
    Address = whatigot.Address;
    data.setSessionData("Name",Name);
    data.setSessionData("Address",Address);
    // PUT YOUR CODE HERE.
    private Connection connectToDatabase()
    Connection conn = null;
    try
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    conn = DriverManager.getConnection("jdbc:sqlserver://172.16.3.5:1433;DatabaseName=hcmpt","sa","");
    catch (ClassNotFoundException e)
    e.printStackTrace();
    System.exit(1);
    catch (SQLException e)
    e.printStackTrace();
    System.exit(2);
    return conn;
    /*Query*/
    private WhatIGot QueryDatabase(Connection conn, String ANI)
    WhatIGot WhatIGot = new WhatIGot();
    try
    Statement st = conn.createStatement();
    ResultSet rs = st.executeQuery("SELECT prefixnos, Name, Address, Email FROM customer_info where prefixnos = ANI");
    WhatIGot.ANI = rs.getString ("prefixnos");
    WhatIGot.Name = rs.getString ("Name");
    WhatIGot.Address = rs.getString ("Address");
    WhatIGot.Email = rs.getString ("Email");
    rs.close();
    st.close();
    catch (SQLException se) {
    System.err.println("Threw a SQLException creating the list of blogs.");
    System.err.println(se.getMessage());
    return WhatIGot;

    Thank you Geoff,
    I have made some changes and now it's working fine with SQL database.
    I go forward to Oracle database. But can you show me how can I copy a new library (ojdbc14.jar) to the CVP server:
    - which folder?
    - and how apply it for all other application can use the same lib here?
    waiting for you answer...
    Thank you,
    This code I have tested, it can connect and query and I try to put to screen. It is working. But when I apply to CVP xml server, it not work. And the CVP VXML server got "stop" (maybe on the fail state)
    package com.dts.db;
    * @author Doan Khanh Tan Thanh
    // These classes are used by standard action elements.
    import com.audium.server.AudiumException;
    import com.audium.server.voiceElement.ActionElementBase;
    import com.audium.server.session.ActionElementData;
    import java.sql.*;
    * This class is called when a standard action has been configured to use a
    * Java class. Since this is a standard action element, it applies to a
    * specific application and does not have a configuration. As a result, the
    * only method needed in this class is the doAction method.
    public class OracleDBLookupAction extends ActionElementBase
    class WhatIGot
    String Name = null;
    String Address = null;
    String Email = null;
    public void doAction(String name, ActionElementData data) throws AudiumException
    String NameWhatIGot = null;
    Connection conn = null;
    String AddressWhatIGot = null;
    //String EmailWhatIGot = null;
    String ani = null;
    conn = connectToDatabase();
    ani = (String)data.getSessionData("ANI");
    WhatIGot whatigot = new WhatIGot();
    whatigot = QueryDatabase(conn, ani);
    NameWhatIGot = whatigot.Name;
    AddressWhatIGot = whatigot.Address;
    //EmailWhatIGot = whatigot.Email;
    data.setSessionData("Name",NameWhatIGot);
    data.setSessionData("Address",AddressWhatIGot);
    // PUT YOUR CODE HERE.
    private Connection connectToDatabase()
    Connection conn = null;
    try
    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn = DriverManager.getConnection("jdbc:oracle:thin:@172.16.5.134:1521:dbkttt","CUOC1080","123456");
    catch (ClassNotFoundException e)
    e.printStackTrace();
    System.exit(1);
    catch (SQLException e)
    e.printStackTrace();
    System.exit(2);
    return conn;
    /*Query*/
    private WhatIGot QueryDatabase(Connection conn, String ANI)
    WhatIGot WhatIGot = new WhatIGot();
    try
    Statement st = conn.createStatement();
    ResultSet rs = st.executeQuery("SELECT * FROM CUSTOMER_INFO where ANI = '838232822'");
    while ( rs.next() )
    WhatIGot.Name = rs.getString ("NAME");
    WhatIGot.Address = rs.getString ("ADDRESS");
    WhatIGot.Email = rs.getString ("EMAIL");
    rs.close();
    st.close();
    catch (SQLException se) {
    System.err.println("Threw a SQLException creating the list of blogs.");
    System.err.println(se.getMessage());
    return WhatIGot;

  • Connecting to an Azure SQL Database from a Windows C# Form

    Hi,
    Is it possible to connect to an SQL database in Azure from Visual Studio C# 2010 or 2012? If so how is this done. Is it the same as if you were connecting to SQL Express database with the use of a connection string? Any directions or tutorials would be of
    great help!
    Thanks!

    Hi,
    >>Thanks for the reply Paul, That is disappointing. I am trying to get my students to create a C# application that will connect with a database in Azure. Is there another approach besides SQL that I could use?
    Using SQL Azure will work fine (see below), if the students are familiar with SQL Server and SQL Databases it will be great for them to see how it works in the cloud. As an alternative you could explore Azure Storage, using Table Storage, Blob Storage or
    the new Document Database features.
    >>Azure enforces a firewall that prevents direct external access to the database server. You can add a firewall rule allowing external access, but the rules only support connecting from a fixed IP address because you have to specify the numeric IP
    from which connection will be allowed.
    You can specify ranges here, so you could cover a range of IP addresses. You can even specify 0.0.0.0 to 255.255.255.255 and allow all IP addresses, this could be an option if you don't know where the students will be connecting from, and you are using a
    database for the exercise where you don't care too much about the security.
    When I have run classes I typically use an IP address range, for example XXX.YYY.ZZZ.0 to XXX.YYY.ZZZ.255 if the students are accessing from the same classroom, and the external IP address may vary. You may find that they all have the same external IP address
    if they are on the same internal network.
    Also, with many students accessing the same database, you may get throttling if they place a lot of load on it. This is cool, as you can also teach them about transient fault handling and resource throttling :-).
    Regards,
    Alan
    Free e-book: Windows Azure Service Bus Developer Guide.

  • Remove decommissioned SQL database from SCOM

    Hi,
    In SCOM 2007 R2, we have few SQL databases which have been decommissioned & removed but, they are still in Healthy state in SCOM.
    How can I remove these entries from SCOM? I want to remove only the databases.
    TIA.

    Try this  -
    1) Log in to those SQL servers
    2) Stop System center management(SCOM health) service.
    3) Rename Health Service State folder located at "c:\programfiles\system center operations manager\agent\Health Service State:.
    4) Restart System center management(SCOM health) service.
    5) Wait for few minutes so that discoveries can run again and then check in the SCOM console. Those Databases should go away now.
    Please let me know if this did not help or if this is not what you are looking for.
    Thanks, S K Agrawal

  • Protect SQL database from untrusted domain

    Hello,
    I have some problems protecting a SQL 2008 SP3 database from untrusted domain with DPM 2012 R2 RU3. 
    When I try to protect the databases, it does not appear in the tree to select them, also when I try to recover a database into untrusted domain it doesnt appear in the tree.
    The NT Authority\System has sysadmin permissions, I have all TCP ports open and  the following UDP ports: 389,88,netbios-dgm,netbios-ns.
    Any idea ?

    Hi
    Is this sql Server part of Sql Server Cluster or a standalone Sql Server?
    Regards, Trinadh [MSFT] This posting is provided &amp;quot;AS IS&amp;quot; with no warranties, and confers no rights. If you found the reply helpful, please &amp;quot;MARK IT AS ANSWER&amp;quot;. Looking for source of information for DPM?
    http://blogs.technet.com/b/dpm/ http://technet.microsoft.com/en-in/library/hh758173.aspx

  • How to Create SQL "Databases" from LV?

    Is there a way to create SQL Databases (not just tables) from inside LabVIEW???  This sould be fairly easy...

    All I know is what is in the SQL Server help file. There is the SQL command "CREATE DATABASE". An example is:
    USE master
    GO
    CREATE DATABASE Sales
    ON
    ( NAME = Sales_dat,
    FILENAME = 'c:\program files\microsoft sql server\mssql\data\saledat.mdf',
    SIZE = 10,
    MAXSIZE = 50,
    FILEGROWTH = 5 )
    LOG ON
    ( NAME = 'Sales_log',
    FILENAME = 'c:\program files\microsoft sql server\mssql\data\salelog.ldf',
    SIZE = 5MB,
    MAXSIZE = 25MB,
    FILEGROWTH = 5MB )
    GO
    You have to have the correct permissions in order to do this and the server itself has to exist. I'm assuming that you already have the Database Connectivity Toolkit, LabSQL (http://www.jeffreytravis.com/lost/labsql.html), or are using your own ADO routines.

  • Troubles Exporting SQL databases from Azure

    1. If I connect via SQL Server Management Studio and choose Export Data Tier Application to local disk, it never ends
    2. If I export via Azure web portal, it takes few hours
    3. The only way that works is using  SQL Server Management Studio and exporting to Azure container and then downloading it and importing via SQL Server Management Studio, seems like a lot of hassle
    I need Azure SQL database to be transferred daily to my local machine, preferably automatically. How can I do it?

    Hi Alex,
    Since the issue regards Windows Azure SQL Database, I will help you move the question to the related forums, It is appropriate and more experts will assist you.
    As Olaf’s post, if you want to migrate databases between the SQL Server Database Engine and Windows Azure SQL Database, you can use the Windows Azure SQL Database Import and Export operations to copy databases between two different SQL Database servers.
     In addition, you can also use the Windows Azure SQL Database copy database feature to make a consistent copy of a database, and perform the export from the copy. For more information, see
    Copying Databases in Windows Azure SQL Database. And you also can migrate a database by using the generate scripts wizard. For more information, see:
    How to: Migrate a Database by Using the Generate Scripts Wizard (Windows Azure SQL Database)
    According to your description, you want to migrate database daily and automatically, you can configure automated exports to schedule export operations for a SQL database, and to specify the frequency of export operations, and to set the retention period
    to store export files. Also you can set data sync between SQL Server and Windows Azure SQL database, configure bi-directional for database. For more information, see:
    Windows Azure SQL Data Sync.
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • Readin IDM database from ABAP

    Hello,
    I would like to know where could I find an API description how to communicate from ABAP to the IDM database. IDM is said to be opened, so other system can read from it. That should mean ABAP too. Can anybody point me to such information source, provide a link to an example code, something to start from?
    Thanks Otto

    I have the similar requirement. Please help me.
    The IdM (7.2) has been directly connected to ECC clients via Jco RFC (No VDS). But for the other business suit clients (CRM, SRM, ..), it is connected via VDS.
    Here is my requirement. Due to the security reasons, we have decided to maintain some translation data in the IdM instead of SAP tables. Translation data is very simple. It will have two columns with ZID and EID.
    Forward Translation is from ZID to EID
    Reverse Translation is from EID to ZID
    We would like to use these translations in the interfaces and conversions. During the execution of interface/conversion, if the program encounters ZID, it should be translated to EID using some methods. Since the data is not in SAP tables, we have to get it from IdM.
    Since there is no VDS, do I need to read the IdM database directly? What are the steps involved in this process from ABAP developer point of view and also from IdM team? It would be great, it you suggest some examples.
    Thanks for reading and your help will be greatly appreciated.

  • Consistently getting "The wait operation timed out" when connecting to Azure SQL Database from a virtual instance...

    I have a web app that is backed by a an Azure SQL Database. The problem is that I had multiple issues when connecting to the database mainly when trying to establish a connection, or timeouts. This is the log I just encountered when trying to use the web
    app.
    [Win32Exception (0x80004005): The wait operation timed out]
    [SqlException (0x80131904): Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=21970; handshake=1; ]
    System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +671
    System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +116
    System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1012
    System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +6712291
    System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +152
    System.Data.SqlClient.SqlConnection.Open() +229
    System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +102

    Hi Affar2k,
    According to your description, we need to verify if there is no network issue and the Sqlclient version is older than .NET 4.5.  You can try to connect to the Windows Azure SQL database via SSMS and check if it can run well. When you
    connect to the SQL Azure database via ADO.NET, you need to verify that the server name and passwords are right in the connection string.
    For more information, you can review the following article about how to connect to Windows Azure SQL Database using ADO.NET.
    http://msdn.microsoft.com/en-us/library/windowsazure/ee336243.aspx
    Thanks,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • Sql statement from abap query

    is there any chance to get the sql statement (not program) from any abap query created via SQ01?
    I can get the code of program that generated by system, but I cannot get pure sql statement.
    any answer will be appreciated

    I see no parameters, and in the abstract that SQL ought to work.
    However, I halfway suspect that either User, Users, Password, or pass is a reserved word and somebody is getting confused. Try renaming your columns and table...

Maybe you are looking for