Skip to Content

Hello All,

Im gonna explain how to get database records from Axapta( MS SQL Server) to an ABAP program.

Okay first thing is you have to define a connection from dbco transaction.

/wp-content/uploads/2012/12/1_165373.jpg

After that you can use that connection with exec_sql statments in abap which lets you query with native sql.

here is some sample code;

DATA dbtype TYPE dbcon_dbms. "dbtype chaine de caractere



DATA wl_con_name TYPE dbcon-con_name.



DATA wl_info_con(3).

DATA: BEGIN OF LT_SERVICE_TEMP,

      SERVICEID TYPE CHAR20,

  END OF LT_SERVICE_TEMP.



  DATA LV_TEMP TYPE CHAR20.



*

*  DATA wa_sytabix TYPE sy-tabix.

*

* DATA matnr_temp TYPE mara-matnr.

*

*

*

*

*  DATA refart TYPE mara-matnr.

*

*  DATA consi  TYPE zed_cons.







    wl_con_name = 'AX_BAYI'.







  SELECT SINGLE dbms FROM dbcon INTO dbtype WHERE con_name = wl_con_name.







  IF dbtype = 'MSS'.



    TRY.



*Connexion a la base de donnée



        EXEC SQL.



          CONNECT TO :wl_con_name



        ENDEXEC.



        IF sy-subrc <> 0.



          RAISE EXCEPTION TYPE cx_sy_native_sql_error.



        ELSE.



          MESSAGE s258(zm) WITH wl_info_con.



        ENDIF.







*Recupération des données



        EXEC SQL.



          OPEN AXDB FOR SELECT SERVICEID FROM SERVICETABLE



        ENDEXEC.



        IF sy-subrc <> 0.



          RAISE EXCEPTION TYPE cx_sy_native_sql_error.



        ENDIF.

WRITE: LT_SERVICE_TEMP-SERVICEID.





        DO.



          EXEC SQL.



            FETCH NEXT AXDB INTO :LV_TEMP



          ENDEXEC.



          IF sy-subrc <> 0.



            EXIT.



          ENDIF.

          ENDDO.

          WRITE LV_TEMP.

*

An that would be all check out the dumps from st22 to see native sql errors.

take care.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply