0% found this document useful (0 votes)
5 views

SAPTechnical.COM - Retrieve data from Separate Oracle System

The document provides a tutorial on how to retrieve data from a separate Oracle system into an SAP system using a DB connection. It explains the process of creating a DB connection with transaction code DBCO, and includes sample ABAP code for connecting to the Oracle database, executing SQL queries, and handling data retrieval. Additionally, it highlights important considerations such as data type compatibility and cursor usage in ABAP programs.

Uploaded by

ANDRE DWI CAHYA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

SAPTechnical.COM - Retrieve data from Separate Oracle System

The document provides a tutorial on how to retrieve data from a separate Oracle system into an SAP system using a DB connection. It explains the process of creating a DB connection with transaction code DBCO, and includes sample ABAP code for connecting to the Oracle database, executing SQL queries, and handling data retrieval. Additionally, it highlights important considerations such as data type compatibility and cursor usage in ABAP programs.

Uploaded by

ANDRE DWI CAHYA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

SAPTechnical.COM - Retrieve data from Separate Oracle System http://saptechnical.com/Tutorials/Basis/Oracle/RetrieveData.

htm

Search

Home • Trainings • Quiz • Tips • Tutorials • Functional • Cert Q's • Interview Q's • Jobs • Testimonials • Advertise • Contact Us

SAP Virtual/Onsite
Trainings

Document Categories:

ABAPTM
Adobe Forms
ABAP-HR
ALE & IDocs
ALV
BAPI
BASIS
BSP
Business Objects
Business Workflow
CRM NEW
LSMW
SAP Script/Smart Forms
Retrieve data from Separate Oracle System
BI/BW
eXchange Infrastructure (XI) By Ribhu Ahuja, TCS
Enterprise Portals (EP)
eCATT
Suppose we have a separate Oracle system in which there is a database table -
Object Oriented Programming
PVACCOUNTBALANCE2 and we want to bring the data of that table into SAP system. The first
SAP Query
thing to be done for that is making a DB connection. TCode DBCO is used to create a DBCON
Userexits/BADIs connection.
WebDynpro for Java/ABAPTM
Open TCode DBCO and click on the change button.
Others

What's New?

ABAP Test Cockpit HOT


SAP ABAP Pragmas
Understanding SE32 (ABAP
Text Element Maintenance)
Creating an IDoc File on SAP
Application Server
Understanding “Advance with
dialog” option of SAP Workflow
SAP Workflow Scenario:
Maintenance Notification
Approval
Enhancements to a standard
class
Working with Floating Field in
Adobe Forms
Inserting data from Internal
Table into the step “Send Mail”
Display GL Account long text
using enhancement framework
Differences between
polymorphism in JAVA and
ABAP
Passing multiline parameters
from an ABAP Class event to a
Workflow container
Concept of Re-evaluate agents
for active work items in SAP
Workflow
Dynamic creation of component
usage in ABAP WebDynpro
Adobe Forms: Display symbols
like copyright and others
Deactivate Hold functionality in
Purchase order (ME21N)
Quiz on OOABAP
Add fields in FBL5N using Now click on the ‘new entries’ button.
BADIs
Tutorial on Wide casting
Defining a Range in Module
Pool Program
Copy fields from one
structure/table into another
structure/table
Side Panel Usage in NWBC

Contribute?

1 of 4 16/06/2021, 11:30
SAPTechnical.COM - Retrieve data from Separate Oracle System http://saptechnical.com/Tutorials/Basis/Oracle/RetrieveData.htm

Sample Specs

What's Hot?

Web Dynpro for ABAP Tutorials

Join the Mailing List

Enter name and email address below:


Name:

Email:

Subscribe Unsubscribe
GO

We see the following screen in which we make all the required entries:

In the box, DB Connection, give any name of the connection. It is to be noted that we would be
using this connection name in our SAP programs to connect to the oracle system.

In DBMS, choose the option ORA for oracle system. In the user name box, give the name of the
oracle system user. We see two boxes for DB password – one is the password box and the other
one is the confirm password box. Give the password in both the boxes. In Conn. Info box, give
the name of the Oracle server – we may ask the name of the same from the Oracle system
Administrator. Check the check box Permanent to make the connection permanent and give the
connection limit as 5. Once we save the entry and come back, we see the following screen:

Now, open SE38 and write a program to retrieve the data from PVACCOUNTBALANCE2 table of
the Oracle system. This table has 3 fields:

ACCOUNT_NUM – type char length 20

UNBILLED_USAGE type Int4 length 10

ACCOUNT_BALANC type Int4 length 10

In order to retrieve the data, we need to use similar data type fields but when I used int, it gave
me a short dump. So I used char 10 instead of int4 10 and it worked.

First of all we make a program to retrieve a single field from the Oracle database. Mentioned
below is the code:
REPORT ZDATAFRMORA_RIBZ.
data: DBN(20).

2 of 4 16/06/2021, 11:30
SAPTechnical.COM - Retrieve data from Separate Oracle System http://saptechnical.com/Tutorials/Basis/Oracle/RetrieveData.htm

* opening the connection


EXEC SQL.
CONNECT TO 'MYCONNECTION'
ENDEXEC.
*executing the select command
EXEC SQL.
SELECT ACCOUNT_NUM into :dbn from PVACCOUNTBALANCE2
ENDEXEC.
*closing the connection
EXEC SQL.
DISCONNECT :'MYCONNECTION'
ENDEXEC.
WRITE: / dbn.

This program connects to the oracle server using dbcon ‘myconnection’ and retrieves the value of
a single ACCOUNT_NUM into variable DBN. Below is the output:

Note the format of the program – there is no period (.) in the statements between EXEC SQL. and
ENDEXEC. Also note how the select statement is used. Now, let us see how we can use the
where condition in the same program:
REPORT ZDATAFRMORA_RIBZ.
data: DBN(20).
EXEC SQL.
CONNECT TO 'MYCONNECTION'
ENDEXEC.
EXEC SQL.
SELECT ACCOUNT_NUM into :dbn from PVACCOUNTBALANCE2
where ACCOUNT_NUM <> 'ACC0000005160'.
ENDEXEC.
EXEC SQL.
DISCONNECT :'MYCONNECTION'
ENDEXEC.
WRITE: / dbn.

The output comes as below. Note that for ‘not equal to’ in oracle ‘<>’ is used, NE won’t work there
and if we use NE, it gives short dump.

Now, let us make a program to read the entire table. It is possible to do so with help of declaring a
‘cursor type’ data and using fetch statement. The code is shown below:
REPORT ZDATAFRMORA_RIBZ.
DATA: c TYPE cursor.
data: DBN(20).
data: begin of ithead occurs 0,
ACCOUNT_NUM(20),
UNBILLED_USAGE(20),
ACCOUNT_BALANCE(20),
end of ithead.
EXEC SQL.
CONNECT TO 'MYCONNECTION'
ENDEXEC.
EXEC SQL.
open c for
SELECT * from PVACCOUNTBALANCE2
ENDEXEC.
DO.
EXEC SQL.

3 of 4 16/06/2021, 11:30
SAPTechnical.COM - Retrieve data from Separate Oracle System http://saptechnical.com/Tutorials/Basis/Oracle/RetrieveData.htm

FETCH NEXT c INTO :ithead


ENDEXEC.
append ithead.
IF sy-subrc ne 0.
EXIT.
ENDIF.
ENDDO.
EXEC SQL.
CLOSE c
ENDEXEC.
EXEC SQL.
DISCONNECT :'MYCONNECTION'
ENDEXEC.
loop at ithead.
WRITE: / ithead-ACCOUNT_NUM, ithead-UNBILLED_USAGE,
ithead-ACCOUNT_BALANCE.
endloop.

The output of the program is shown above. One very important thing to be noted here is the
declaration of cursor c. Since we declared it as:

DATA: c TYPE cursor.

It is to be made sure that wherever we use this cursor ‘c’, we use it in small and not in caps ( ‘C’)
otherwise it would give a short dump – the cursor declaration and use are case sensitive.

In the end, some small tips on some database tables in SAP – table TSTC shows the list of all the
transaction codes in SAP. Table TADIR shows all the unreleased objects in the system and if we
want to get a list of local objects in the system, we can specify $TMP in the devclass field and it
will show all the local objects created by all users. Table E701 can be used to find the requests of
workflows – if you know your workflow number, you can search it in this table and it will give you
your workflow’s request.

App Sewa
Apartemen Terbaik
Unit pilihan terbaik kita siap disewa oleh
kamu. Dan dapatkan promo menarik
lainnya

Travelio

Buka

Please send us your feedback/suggestions at [email protected]

Home • Contribute • About Us • Privacy • Terms Of Use • Disclaimer • Safe • Companies: Advertise on SAPTechnical.COM | Post Job • Contact Us

©2006-2007 SAPTechnical.COM. All rights reserved.


All product names are trademarks of their respective companies. SAPTechnical.COM is in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver, and and any other SAP trademarks are registered trademarks of SAP AG in Germany and in several other countries.
Every effort is made to ensure content integrity. Use information on this site at your own risk.

Graphic Design by Round the Bend Wizards

4 of 4 16/06/2021, 11:30

You might also like