Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

hi regarding native SQL statements

Former Member
0 Likes
458

Hi Experts,

i am trying to fetch data from the non sap system by connecting the non sap data base, i want to fetch 5 fields from the ORD table which is non sap table by using native SQL. when i am trying to fetch it goes to dump

could u please suggest me how to fetch the data.

following is the sample code

DATA: go_manu TYPE REF TO zcl_manuscm.

CREATE OBJECT go_manu.

data: begin of it_ord occurs 0,

id(12) type c,

source_id(12) type c,

early_avl type sy-datum,

late_avl type sy-datum,

dest_id(12) type c,

end of it_ord.

data: wa_ord like it_ord.

data lv_fdate type sy-datum.

data lv_tdate type sy-datum.

select-options: s_fdate for sy-datum.

go_manu->connect( ).

lv_fdate = s_fdate-low .

lv_tdate = s_fdate-high .

EXEC SQL.

open ord_cursor for select id, source_id, late_avl, early_avl, dest_id

from ord where late_avl = :lv_fdate ;

endsql.

do.

exec sql.

fetch next ord_cursor into :wa_ord-id, :wa_ord-source_id, :wa_ord-late_avl, :wa_ord-early_avl, :wa_ord-dest_id

endsql.

if sy-subrc <> 0.

exit.

endif.

append wa_ord to it_ord.

enddo.

exec sql.

close ord_cursor.

endexec.

3 REPLIES 3
Read only

Former Member
0 Likes
427

Hello ,

Take a look here:

http://help.sap.com/saphelp_nw04/helpdata/en/2b/b7b339ff52ff3fe10000000a11402f/frameset.htm

loop at it_cus1.

EXEC SQL.

FETCH NEXT C into

:IT_CUS2-KUNNR, :IT_CUS2-DATLT

ENDEXEC.

APPEND it_cus2.

CLEAR it_cus2.

ENDloop.

EXEC SQL.

CLOSE C

ENDEXEC.

If useful reward.

Vasanth

Read only

Former Member
0 Likes
427

Hi Srinivsulu,

Just remove the statmenet endsql from your code everywhere & replace it by ENDEXEC.

Also please note that programs with Native SQL statements are generally dependent on the database system used, so that they cannot be executed in all SAP Systems. This is especially true for Informix database systems. So just check whether ur database supports SAP calls or not.

Regards,

Chetan.

PS:Reward points if this helps.

Read only

0 Likes
427

Hi chetan,

thanks for the quick response.

as u said i removed all endsql by replacing endexec.

from here which is going to dump

exec sql.

fetch next ord_cursor into :wa_ord-id, :wa_ord-source_id, :wa_ord-late_avl, :wa_ord-early_avl, :wa_ord-dest_id ;

endexec.

could u please help me on this.

thanks in advance