Hey guys. I'm using some embedded sql in an sqlrpgle CGIDEV2 program. I've used it exactly like this before, but for some reason this time, it's giving me sqlcod = 501. Can anyone tell what's going on? Thanks.
Code:
D quote C CONST('"')
D snglQuote C CONST('''')
D term S LIKE(CINAME)
D city S LIKE(CINAME)
D state S LIKE(CIST)
D limit S 5 0
D counter S 5 0 INZ(0)
D UP C 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
D low C 'abcdefghijklmnopqrstuvwxyz'
D SqlString S 450 Varying Inz
D JSONstring S 32767 Varying
D SavedQryStr S 32767 Varying
//=============================================================
/Free
EXEC SQL
SET OPTION CLOSQLCSR = *ENDMOD,
DLYPRP = *YES,
SRTSEQ = *LANGIDSHR;
//Initialize JSON string
JSONstring = 'Content-type: text/html'+x'25'+x'25'+'[';
//Retrieve the value of City search string from the JSON string
If ZhbGetInput(SavedQryStr: QUSEC) > 0;
term = %xlate(low:UP : ZhbGetVar('term'));
limit = 10;
EndIf;
SqlString = 'SELECT CINAME, CIST FROM CITIESL8 WHERE CINAME LIKE UCASE('+
snglQuote+%TRIM(term)+'%'+snglQuote+')';
EXEC SQL
PREPARE SQL FROM :SqlString;
EXEC SQL
DECLARE @C1 CURSOR FOR SQL;
EXEC SQL //when debugging, sql code = 204
OPEN @C1;
EXEC SQL //when debugging, sql code = 501
FETCH NEXT FROM @C1 INTO
:city, :state;
If SQLCOD = 100;
JSONstring += quote+'No Results...'+quote;
Else;
DoW sqlcod = 0;
If counter > limit;
Leave;
ENDIF;
If counter > 0;
JSONstring += ',';
ENDIF;
JSONstring += '{'+quote+'label'+quote+':'+quote+city+'\, '+state+',';
JSONstring += quote+'value'+quote+':'+quote+city+quote+'}';
counter += 1;
EXEC SQL
Fetch NEXT From @C1 Into
:city, :state;
ENDDO;
ENDIF;
EXEC SQL
CLOSE @C1;
JSONstring += ']';
wrtnosection(%addr(JSONstring)+2:%len(JSONstring));
wrtsection('*fini');
*InLR = *On;
/End-Free





Comment