Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error when using Index

Status
Not open for further replies.

Ju5

Programmer
May 25, 2007
85
PH
I am using a variable to store my query select statement for a OPNQRYF operation defined as QSEL *char len(500).

To add a statement I use
CHGVAR %SST(&QSEL &INDEX 10) VALUE(&month
CHGVAR &INDEX VALUE(&INDEX + 11)
inside a DOUNTIL statement to multiple dates.
I.e
(&month='03') *or (&month='04')*or ...

The operation does fine when the difference between months is 1 but when the difference is more than 1 I receive a "Range of Subscript value or Character String Error" message. The difference between months can be > 1 because the user will be the one to enter the date.

&INDEX *DEC LEN(3 0) VALUE(001)

 
I can't tell the exact problem without more of the CL. But the error message indicates the value of &INDEX is incorrect.
 
Do you initialize QSEL to a 500-byte string of *BLANK?

Is it possible that while you're building the string, INDEX manages to exceed 500? (Is INDEX being incremented only when more text is added to the string?)

It sounds like the program's trying to access an undefined/uninitialized area.
 
GhostWolf said:
Do you initialize QSEL to a 500-byte string of *BLANK?

CAUTION: If you do this:

Code:
CHGVAR VAR(&QSEL) VALUE(*BLANK)

&QSEL will have the value '*BLANK '.

There are no figurative constants in CL, as there are in RPG. CL will take *BLANK as a literal string. Instead, do this:

Code:
CHGVAR VAR(&QSEL) VALUE(' ')

Tibi gratias agimus quod nihil fumas.

 
I only use the term *BLANK 'cause everyone here knows what it is.

Your initialization is succinct, but it always worries me: is the program really gonna give me the 500 bytes of ' ' that I want, or will I end up with just one byte and an index problem.

Personally, I prefer concatenation.
 
When you build the QSEL are you using QSEL *TCAT next.. or just *CAT. The *CAT will fail.
 
GhostWolf said:
I only use the term *BLANK 'cause everyone here knows what it is.

Well, not necessarily everyone...

I only brought it up because I got burned by that one myself, once (another programmer had made the assumption that *BLANK = ' ' in a CL. It caused me no end of grief debugging it until I finally put a DMPCLPGM in there to see what the heck was going on). Having been burned once, I always make sure the fire is out [wink].

Tibi gratias agimus quod nihil fumas.

 
LOL Yeah, I think that bug bit me a time or twice too. I should have known better.
 
GW - No problem.

Ju5:

It can be frustrating building a QRYSLT string. You can also use two vertical bars (||) in place of *TCAT. And you have to move all numeric values to character fields for concatenation into the query select string.

*BCAT inserts one space between the values being concatenated. *TCAT or || leaves nothing. I hardly ever use *CAT in a query select string.

For example:
Code:
            DCL        VAR(&FROM_YMD@) TYPE(*CHAR) LEN(8)
            DCL        VAR(&FROM_YMD) TYPE(*DEC) LEN(8 0)
            DCL        VAR(&TO_YMD@) TYPE(*CHAR) LEN(8)  
            DCL        VAR(&TO_YMD) TYPE(*DEC) LEN(8 0)  

            CHGVAR     VAR(&FROM_YMD@) VALUE(&FROM_YMD)
            CHGVAR     VAR(&TO_YMD@) VALUE(&TO_YMD)    

            CHGVAR     VAR(&QRYSLT) VALUE('FTUCDT = %RANGE(' || +      
                         &FROM_YMD@ *BCAT &TO_YMD@ || ')')             
                                                                       
            OVRDBF     FILE(MY_FILE) OVRSCOPE(*JOB) SHARE(*YES)        
            OPNQRYF    FILE((MY_FILE)) QRYSLT(&QRYSLT) +               
                         KEYFLD(*FILE) OPNSCOPE(*JOB)                  
                                                                       
            CALL       PGM(MY_PGM)
            CLOF       OPNID(MY_FILE)                                  
            DLTOVR     FILE(MY_FILE QSYSPRT) LVL(*JOB)

Tibi gratias agimus quod nihil fumas.

 
I use || to build QSEL. I don't initialize QSEL but it seems to be okay now. The length of QSEL was shorter than the statement I was putting together and couldn't fit in. I was using a loop to add the month/day selection to the statements making it longer.
 
The QRYSLT parameter for OPNQRYF can be up to 5000 bytes long, if you use a variable as the parameter (which you are doing). So, if you declare &QSEL as *CHAR 5000, you'll be fine.

If you put the selection in OPNQRYF without using a variable, you are limited to 512 bytes.

Tibi gratias agimus quod nihil fumas.

 
I only brought it up because I got burned by that one myself, once (another programmer had made the assumption that *BLANK = ' ' in a CL.
I've gotten burnt many times by CL -- and by RPG.

Around 10 years ago, I was trying to debug an RPG program where I was sure that there was a compiler problem, because the logic looked sound...

Even in debug, it took me awhile to figure out my syntax error...

It was something like this:

*IN90 ifeq '*ON'
instead of
*IN90 ifeq *ON

:)
 
bwtc said:
*IN90 ifeq '*ON'
instead of
*IN90 ifeq *ON
Yep, that's a sneaky one. I find myself not even doing the *OFF or *ON in free format:

if *in90; // *in90 is on

--or--

if not *in90; // *in90 is off

Tibi gratias agimus quod nihil fumas.

 
FYI: You don't need the compare in fixed-format either
If *IN90
works just fine, as do named indicators
 
Yep, Arrow, I have used indicators like

Code:
          If Its_Miller_Time;
            Return;
          Endif;

And I have used them in fixed-format (but that's so V4!

Tibi gratias agimus quod nihil fumas.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top