View previous topic :: View next topic
|
Author |
Message |
nitin_d
New User
Joined: 27 Oct 2005 Posts: 15 Location: Pune
|
|
|
|
Hello All,
I have been trying to open a cursor with fetch first n rows only, where the value of n has to change dynamically.
The code snippets that i have used are as follows
EXEC SQL
INCLUDE SQLCA
END-EXEC.
01 DSTRING.
05 STRING-VAR-LEN PIC S9(4) COMP VALUE 92.
05 STRING-VAR-TXT PIC X(92).
( I build the query in a different group variable and move that into STRING-VAR-TXT)
EXEC SQL
DECLARE C1 CURSOR FOR STMT
END-EXEC.
EXEC SQL
PREPARE STMT FROM :DSTRING
END-EXEC.
I get DB2 pre-compiler error message as follows
UNDEFINED OR UNUSABLE HOST VARIABLE "DSTRING"
STRING VARIABLE "DSTRING" IS NOT "VARCHAR" TYPE
Can anybody please help me with this error.... |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
remove value clause 92 from the length field ...declare it as
05 STRING-VAR-LEN PIC S9(4) COMP.
varchar dynamically assigns the length whn u move the field to the txt field ... |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
one more thing use 49 level for ur varchar declaration
01 DSTRING.
49 STRING-VAR-LEN PIC S9(4) COMP.
49 STRING-VAR-TXT PIC X(92). |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
ashimer wrote: |
remove value clause 92 from the length field ...declare it as
05 STRING-VAR-LEN PIC S9(4) COMP.
varchar dynamically assigns the length whn u move the field to the txt field ... |
WRONG |
|
Back to top |
|
|
zero
New User
Joined: 01 Dec 2007 Posts: 21 Location: Hyderabad
|
|
|
|
Hi,
when a Query is executed dynamically, we should use the VARCHAR datatype. we can define a VARCHAR field in cobol, by using the approach that you are using. as ashimer said, the level numbers should be 0f 49.
So, use this :
Code: |
01 DSTRING.
49 STRING-VAR-LEN PIC S9(4) COMP.
49 STRING-VAR-TXT PIC X(92). |
Moving a string to -TXT field does not automatically finds its length. we have to find it ourselves.
After preparing the SQL stmt, find its length and move it to STRING-VAR-LEN field.
hope this helps, |
|
Back to top |
|
|
nitin_d
New User
Joined: 27 Oct 2005 Posts: 15 Location: Pune
|
|
|
|
Thanks all, I was declaring the VARCHAR elemnets at 05 level and not 49. That was what the actual root cause was. |
|
Back to top |
|
|
|