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

Read DB2 tables from ABAP program

Former Member
0 Likes
528

Hi All,

I have a requirement to read a DB2 table(in our landscape) from the ABAP program. I appreciate any pointers.

Thanks,

Kiran.

1 REPLY 1
Read only

Former Member
0 Likes
338

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 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……

FUNCTION-POOL z_houston. "MESSAGE-ID ..

DATA: BEGIN OF wa,

c_locid(3),

c_locname(50),

c_locstate(5),

END OF wa.

FUNCTION z_houston_connect.

*"----


""Local interface:

*"----


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.

ENDFUNCTION.

&----


*& 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