Shared Top Border

Enterprise Resource
Planning Portal

 

Advertise | Founder BLOG

ERPGenie.COM ABAP Tips and Tricks Database

THE ultimate
ERP website

 

Forums | Vote for us |

Google    Other Search Options

Login

Login to view more content!!!





Lost Password?
No account yet? Register

Registered Access

Poll

What area of ABAP are you interested in?
 
Home arrow Tips and Tricks arrow General arrow ODBC in Abap by ravi Sharma
ODBC in Abap by ravi Sharma PDF Print E-mail
User Rating: / 1
PoorBest 
Written by Ravi Sharma   
Thursday, 26 April 2007
An ODBC connectivity from ABAP to different Databases.

report zra_ODBC no standard page heading.

*----------------------------------------------------------------------*
INCLUDE ole2incl.
*----------------------------------------------------------------------*
DATA: con TYPE ole2_object,
      rec TYPE ole2_object,
      SQL(1023).

DATA: BEGIN OF SPL OCCURS 0,
          VAL(1023),
      END OF SPL,
      sindx TYPE I.

parameters: pemcode(5).
tables: sscrfields.
*----------------------------------------------------------------------*
initialization.
    perform openconnection.
*----------------------------------------------------------------------*
at selection-screen.
*----------------------------------------------------------------------*
start-of-selection.
*    write: / 'Querry'.
    perform Get_Rec.
*----------------------------------------------------------------------*
end-of-selection.
*----------------------------------------------------------------------*
form openconnection.
      SQL = 'DSN=DSN_NAME;UID=USER_ID;PWD=PASSWORD'.
      IF con-header IS INITIAL OR con-handle = -1.
          CREATE OBJECT con 'ADODB.Connection'.
          IF NOT sy-subrc = 0.
              EXIT.
          ENDIF.

          CREATE OBJECT REC 'ADODB.Recordset'.
              IF NOT sy-subrc = 0.
              EXIT.
          ENDIF.
      ENDIF.

      CALL METHOD OF CON 'Open'
          EXPORTING #1 = SQL.
endform.
*----------------------------------------------------------------------*
form closeconnection.
    free rec.
    free con.
endform.
*----------------------------------------------------------------------*
form Get_Rec.

* Paymast is a table created in another Database with the below fields  

    concatenate 'select name,address from PAYMAST where empcode='
                '''' pemcode ''''  into  SQL.

*     Query run ...
    CALL METHOD OF REC 'OPEN'
              EXPORTING #1 = SQL
              #2 = CON
              #3 = '1'.
**   Query run ...
    do.
          CALL METHOD OF REC 'getstring' = SQL
              EXPORTING #1 = '2' "Do not modify!
              #2 = 1 "Do not modify!
              #3 = '|' "Do not modify!
              #4 = '|'. "Do not modify!
          if sy-subrc = 0.
              REFRESH SPL. CLEAR SPL.
              SPLIT SQL AT '|' INTO TABLE SPL.
              loop at SPL.
                write: / SPL-VAL.
              endloop.
          else.
            exit.
          endif.
    enddo.

 * Remember to close the connection

    perform close_connection.

endform.


Related Items:

Last Updated ( Thursday, 26 April 2007 )
 
< Prev   Next >

Google Search

Statistics

Contribution Activity
Utilities: 38
Tips and Tricks: 334
Sample Code: 166
Total Contributions: 553

Member Activity
Members: 6310 since 2/1/2007!
New: 1 since yesterday!
Visitors: 1184115
We have 1 guest online

Newest Members

Welcome our newest members:

Google Ads

Shared Bottom Border

Contact Us | Polls | Add URL | Contribute | Privacy | Terms | Feedback

Discussion Forum | BLOG | Consultants: Post your resume | Companies: Advertise on ERPGenie.COM | Post Job
Financials Consultant | Consultant Review | Gallia Consulting | Supply Chain Project | SAP Financials Forum
GenieHoldings.COM, Inc. | Genie Press | WorkflowGenie | ESAGenie | ERPTopSites | ABAP Tips and Tricks | SAP Solutions Database

EDIGenie | Searching Survivor