Skip to Content
author's profile photo
Former Member

Connecting to database

Hi,

Is it possible to connect to another database from SAP.

Thanks.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Best Answer
    Oct 03, 2005 at 06:35 PM

    Yes, it can be done by setting the enteries in DBCON table

    and following is the example

    FORM connect_hris_database.

    IF p_werks = 'ZDCF'.

    SELECT SINGLE * FROM dbcon WHERE con_name = 'SQL_CFMAX2_HRIS_CF'.

    IF sy-subrc NE 0.

    WRITE:/ 'Create Database connect String in DBCON'.

    WRITE: 'SQL_CFMAX2_HRIS_CR'.

    EXIT.

    ENDIF.

    EXEC SQL.

    CONNECT TO 'SQL_CFMAX2_HRIS_CF'

    ENDEXEC.

    ELSEIF p_werks = 'ZDCR'.

    SELECT SINGLE * FROM dbcon WHERE con_name = 'SQL_CFMAX2_HRIS_CR'.

    IF sy-subrc NE 0.

    WRITE:/ 'Create Database connect String in DBCON'.

    WRITE: 'SQL_CFMAX2_HRIS_CR'.

    EXIT.

    ENDIF.

    EXEC SQL.

    CONNECT TO 'SQL_CFMAX2_HRIS_CR'

    ENDEXEC.

    ELSEIF p_werks = 'ZDCC'.

    SELECT SINGLE * FROM dbcon WHERE con_name = 'SQL_CFMAX2_HRIS_CC'.

    IF sy-subrc NE 0.

    WRITE:/ 'Create Database connect String in DBCON'.

    WRITE: 'SQL_CFMAX2_HRIS_CC'.

    EXIT.

    ENDIF.

    EXEC SQL.

    CONNECT TO 'SQL_CFMAX2_HRIS_CC'

    ENDEXEC.

    ENDIF.

    IF sy-subrc <> 0.

    WRITE:/ 'CAN NOT OPEN DATABASE'.

    EXIT.

    ENDIF.

    ENDFORM. " connect_hris_database

    I hope this helps

    Jagraj

    Add comment
    10|10000 characters needed characters exceeded