09-22-2008 8:20 AM
Can anybody let me know, how to fetch data from ext database (mysql) through an ABAP program?
Please tell me the detail steps..
09-22-2008 12:16 PM
You can access external databases with native code.
You neeed to open the database and make the SQL operations.
The SAP administrator have to create the connection in SM59
Example of open, read and close operations from an external database.
*&----
*
*& Form pasar_datos
*&----
*
FORM pasar_datos.
DATA: g_rc TYPE i.
EXEC SQL.
EXECUTE PROCEDURE dbo. SAP_Prueba
( OUT :gt_datos-pernr,
OUT :gt_datos-kostl,
OUT :gt_datos-begda,
OUT :gt_datos-endda,
OUT :gt_datos-modif,
OUT :G_RC,
)
ENDEXEC.
IF SY-SUBRC <> 0 OR g_rc <> 0.
WRITE / 'Wrong result for EXECUTE PROCEDURE'.
ENDIF.
APPEND gt_datos.
ENDFORM. " pasar_datos_de_signed
*----
*
Form conexion
*----
*
FORM conexion USING p_cadena_conexion.
Ejecutamos SQL nativo para establecer la conexión con la BD
EXEC SQL.
connect TO :p_cadena_conexion
ENDEXEC.
Comprobamos que no haya habido error en el acceso
IF SY-SUBRC <> 0.
MESSAGE E000 WITH 'ERROR EN LA CONEXION CON '.
ENDIF.
ENDFORM. " conexion
*----
*
Form desconexion
*----
*
*----
*
-->p_cadena_conexion text
*----
*
FORM desconexion USING p_cadena_conexion.
Ejecutamos una sentencia en SQL nativo para desconectarnos
EXEC SQL.
disconnect :p_cadena_conexion
ENDEXEC.
ENDFORM. " desconexion