MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Dynamic Sql error

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
naren_ab
Beginner


Joined: 07 Jan 2003
Posts: 32
Topics: 10

PostPosted: Thu Sep 18, 2003 8:50 am    Post subject: Dynamic Sql error Reply with quote

Need help in resloving this error.

****** SP START*****2003091809403858-0400
@ CHECK-PASSED-PARAMS.
STRING "SELECT C1"
",C2"
",C3"
",C4"
",C5"
",C6"
",C7"
",C8"
",C9"
",C10"
",C11"
",C12"
",C13"
",C14"
"FROM ADMIN.TBNAME
" WHERE C1 >= '" WS-C1(1:2) "' "
" ORDER BY C1 ASC "
DELIMITED BY SIZE
INTO WS-SQL-TXT
END-STRING.

EXEC SQL PREPARE
SEARCH_SQL FROM :WS-DYNAM-SQL
END-EXEC.
Evaluate SQLCODE
******** DATE/TIME: 09/18/2003-09:40:38.86
SQLERR: -104 PROGRAM: TEST PARAGRAPH:

ADDITIONAL PGMR INFO: UNEXPECTED ERROR PREPARING SELECT SQL

DSNT408I SQLCODE = -104, ERROR: ILLEGAL SYMBOL " ". SOME SYMBOLS THAT MIGHT BE LEGAL ARE: , FOR WITH FETCH QUERYNO OPTIMIZE
DSNT418I SQLSTATE = 42601 SQLSTATE RETURN CODE
DSNT415I SQLERRP = DSNHPARS SQL PROCEDURE DETECTING ERROR
DSNT416I SQLERRD = 0 0 0 -1 263 0 SQL DIAGNOSTIC INFORMATION
DSNT416I SQLERRD = X'00000000' X'00000000' X'00000000' X'FFFFFFFF' X'00000107' X'00000000' SQL DIAGNOSTIC INFORMATION
******** DATE/TIME: 09/18/2003-09:40:38.86 ******SP END
Back to top
View user's profile Send private message
Bithead
Advanced


Joined: 03 Jan 2003
Posts: 550
Topics: 23
Location: Michigan, USA

PostPosted: Thu Sep 18, 2003 10:08 am    Post subject: Reply with quote

You need to set the length of teh statement:

01 WS-DYNAM-SQL.
05 WS-SQL-LEN PIC S9(4) COMP.
05 WS-SQL-TXT PIC ...

01 SQL-POINTER PIC S9(4) COMP.


STRING ....
INTO WS-SQL-TXT
POINTER SQL-POINTER
END-STRING.

MOVE SQL-POINTER TO WS-SQL-LEN.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Thu Sep 18, 2003 10:12 am    Post subject: Reply with quote

Naren,

IS your ws-dynam-sql defined like this ?
Code:

01 WS-DYNAM-SQL.
  49 WS-SQL-LENGTH   PIC S9(4) COMP. 
  49 WS-SQL-TEXT     PIC X(NNNN).


If you indeed defined like that , are you populating the length field after the string?

You need to populate the length field before you prepare the the dynamic sql

Hope this helps...

cheers

kolusu

PS: Bithead beat me in posting the solution
Back to top
View user's profile Send private message Send e-mail Visit poster's website
naren_ab
Beginner


Joined: 07 Jan 2003
Posts: 32
Topics: 10

PostPosted: Tue Sep 23, 2003 8:50 am    Post subject: Reply with quote

Good morning Bithead and Kolusu,

Thanks for all the help, i found out with the ideas you gave me..
Bithead, I had the definition of ws-dynam-sql the way Kolusu mentioned and DELIMITED BY SIZE will equalize POINTER for my purpose.
Kolusu, i am populating the length field before the prepare.

When i do normal compute to get the length it was the length from the declaration of PIC clause. but not the real length of text. And more over i have defined the TEXT and LENGTH field, which gets moved into ws-dynam-sql wrongly. So it was always thinking that there should be some thing to end the statement.

But thanks for all the help. This was my first dynam SQL, though i know how it works all the internals, but newer tried it till now and the rest is same as static sql program.

You both have great day.


Last edited by naren_ab on Tue Sep 23, 2003 8:55 am; edited 1 time in total
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Tue Sep 23, 2003 8:55 am    Post subject: Reply with quote

Naren,
Glad I was able to help.

Quote:

When i do normal compute to get the length it was the length from the declaration of PIC clause. but not the real length of text.


Use this logic to get the actual length of the string instead of the defined length.

Code:

WORKING-STORAGE SECTION.                                   
                                                           
01  W-TEXT               PIC X(30) VALUE 'NAREN HAD PROBLEM'.   
01  W-TALLY              PIC S9(04) COMP VALUE ZERO.       
01  W-STR-LENGTH         PIC 9(3) VALUE ZERO.               

PROCEDURE DIVISION.                                         
                                                           
     INSPECT FUNCTION REVERSE(W-TEXT) TALLYING W-TALLY     
           FOR LEADING SPACES   
                           
     COMPUTE W-STR-LENGTH = LENGTH OF W-TEXT -  W-TALLY                   
                                                           
     DISPLAY 'THE STRING LENGTH IS:' W-STR-LENGTH           
     
                                                           


Hope this helps...

cheers

kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
naren_ab
Beginner


Joined: 07 Jan 2003
Posts: 32
Topics: 10

PostPosted: Tue Sep 23, 2003 8:58 am    Post subject: Reply with quote

Hi Morning,

Kolusu, i used SYSDUMMY1 to calculate the length. So squared that problem using existing variables.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group