cancel
Showing results for 
Search instead for 
Did you mean: 

exec sql help

Former Member
0 Kudos
116

Hi,

I have this abap/exec sql code to extract data from as400/db2.

I am getting data by a "select" statement and i am trying to append the records with append statements.

but, not works.

EXEC SQL.

CONNECT TO 'SATDBR'

ENDEXEC.

EXEC SQL.

--->(HERE THE PROBLEM) OPEN C1 FOR.

SELECT A,B,C,D

FROM SAPTEST.XX1

ENDEXEC.

EXEC SQL.

OPEN C1

FETCH NEXT C1 INTO

:ZTABLE.AA, :ZTABLE.BB, :ZTABLE.CC, :ZTABLE.DD

ENDEXEC.

IF sy-subrc <> 0.

EXIT.

ELSE.

APPEND ZTABLE.

ENDIF.

ENDDO.

EXEC SQL.

CLOSE C1

ENDEXEC.

EXEC SQL.

DISCONNECT 'SATDBR'

ENDEXEC.

I need to declare the cursor??? whats wrong in my code :S

the runtime error is "A SQL mistake has appeared by the execution of Native SQL."

i would appreciate your help.

thanks

vicky

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

i]

<b>--->(HERE THE PROBLEM) OPEN C1 FOR.</b> </i>

Do you have period " ." after FOR , you are better off if you remove the period..as it thinks it is end of statement and is not able to compile properly..

Regards

Manga

Former Member
0 Kudos

Hi vicky!!!

can you help me??, my problem is in the code, because i don`t know how declarate, how extract the data of the database, and the tables ....

Thanks

Former Member
0 Kudos

hi,

I recommend you, make the select and test it first in the DB2 console.

Only delcare your internal tables, your variable with abap code.

To extract the data with the select statement is enough, to fill the table with several records use this code:

EXEC SQL.

CONNECT TO 'DB2' " the name of the connection

ENDEXEC.

EXEC SQL.

OPEN C1 FOR

SELECT A,B,C,D

FROM SAPTEST.XX1

ENDEXEC.

DO

EXEC SQL.

OPEN C1

FETCH NEXT C1 INTO

:ZTABLE

ENDEXEC.

IF sy-subrc <> 0.

EXIT.

ELSE.

APPEND ZTABLE.

ENDIF.

ENDDO.

EXEC SQL.

CLOSE C1

ENDEXEC.

EXEC SQL.

DISCONNECT 'DB2'

ENDEXEC.

The ZTABLE must have the same order in which you put on the fields in the "select"

DATA: BEGIN OF ztable OCCURS 0,

A(1) TYPE c

B(8) TYPE c

C(17)TYPE N

D(19 TYPE c

DATA: END OF ZTABLE.

I HOPE THIS INFORMATION HELPS YOU!!

REGARDS

VICKY

Message was edited by: Victoria León

Answers (0)