×
The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.
I recently posted a not so clear request regarding dynamic sql.
For those that have replied offering help, thank you. I'm just still not
getting it.
I'd like a second chance to clarify my request and even post a small sample
pgm that should help illustrate my dilemma.
attached is a small standalone pgm that anyone could run to help me out
with this. ( you would need the file object however for actual execution).
but will compile and allow you to see what I'm attempting.
I'm trying my best to build a cursor over a pre-constructed sql statement
(file/columns) unknown... but for sake of sample pgm, i have hardcoded a
statement in the host variable.
I then want to fetch the cursor for that sql statement and process the
fetched row (does this come from sqlda/sqlvar's?) and populate a host
variable ds. if so, how do they get processed? i've read and attempted
various methods, none with successful results, so hoping for some code
specific for my processing.
And one other piece of confusion regarding my current code in attachment,
when the fetch occurs, on my system, the record does indeed exist...
sqlcode is set to 0, BUT if I look a the joblog, it says 0 records fetched.
I'm confused... can someone please help me with this piece of a much bigger
application?
Thank you
Jay Vaughn
h dftActGrp(*No)
h option(*SrcStmt:*NoDebugIO)
//------------------
// Templates
//------------------
* sql descriptor area
d t_sqlda ds template qualified
d sqldaid 8
d sqldabc 10i 0
d sqln 5i 0
d sqld 5i 0
//------------------
// Global Variables
//------------------
d g_sqlStmt...
d s 5000 inz
//---------------------------------
// SQL Descriptor Redefinition
//---------------------------------
d sqlda ds likeds(t_sqlda) based(sqlda#)
d sqlInpDa ds likeds(t_sqlda) based(sqlInpDa#)
//--------------------------------------------------
// Main
//--------------------------------------------------
g_sqlStmt = 'select * from ldataj08.SRVACHI ' +
'where ACI010 = ''03'' and ACI015 = ''1'' and ' +
'ACI085 = ''003'' order by ACI010, ACI015, ACI085';
executeSQLSelectStmt();
return;
//--------------------------------------------------
// Procedure
//--------------------------------------------------
p executeSQLSelectStmt...
p b
d pi
*-----------------------------------------
* Local Variables
*-----------------------------------------
sqlda# = %alloc(%size(t_sqlda)); // not sure if really needed?
sqlDa.sqln = 16; // will come from host variable
exec sql
prepare s1_select from :g_sqlstmt;
if sqlcode <> 0;
return;
endif;
exec sql
declare c1 cursor for s1_select;
if sqlcode <> 0;
return;
endif;
exec sql open c1;
if sqlcode <> 0;
return;
endif;
exec sql fetch next from c1;
if sqlcode = 0;
// process sql fetched cursor and put values in a host ds
endif;
return;
p executeSQLSelectStmt...
p e
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact
[javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.