ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Passing numeric parameters to Query

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Passing numeric parameters to Query

    Hi All , having a torrid time trying to get something I thought simple to work !

    I have the following code in a CL to pass a date to a Query and I get an error saying the date in not valid as it's not character - please help me !

    1900 - CVTDAT DATE('190413') TOVAR(&JULDAT) FROMFMT(*DMY) TOFMT(*JUL)
    TOSEP(*NONE)
    3000 - CVTDAT DATE('11109') TOVAR(&CYMD) FROMFMT(*JUL) TOFMT(*CYMD)
    TOSEP(*NONE)
    3201 - STRQMQRY QMQRY(AMPHQRY/IMHISTARCH) OUTPUT(*OUTFILE)
    QMFORM(*QMQRY) OUTFILE(SPLIB/IMHISTARCH) OUTMBR(*FIRST *ADD)
    ALWQRYDFN(*YES) SETVAR((CYMD) ('1110419'))
    1110419 is not a valid Query Management variable.
    Error found on STRQMQRY command.

    The error details are :-

    Message ID . . . . . . : QWM1937 Severity . . . . . . . : 40
    Message type . . . . . : Diagnostic
    Date sent . . . . . . : 19/04/13 Time sent . . . . . . : 12:38:09

    Message . . . . : 1110419 is not a valid Query Management variable.
    Cause . . . . . : The 1110419 variable entered on the SETVAR parameter
    contains a value which is not valid. The return code is 1.
    The following return codes are possible:

    1 - The first character is not alphabetic.
    2 - One of the remaining characters is not alphanumeric or an '_'.
    3 - The variable begins with 'DSQ'. A variable that begins with 'DSQ'
    cannot be used from the SETVAR parameter.

    How do I code this to get the parameter passed ?

    Many thanks,
    Simon

  • #2
    Re: Passing numeric parameters to Query

    Verify that the variable in the QM is CYMD.
    I seem to recall that you have to add quotes around the variable that you send in. I don't QM here so no sample to give.
    Hunting down the future ms. Ex DeadManWalks. *certain restrictions apply

    Comment


    • #3
      Re: Passing numeric parameters to Query

      If you paste the STRQMQRY into a command line and prompt on it, you'll see that the SETVAR looks like this

      Code:
      Set variables:                               
        Variable name  . . . . . . . . > CYMD      
        Variable value . . . . . . . .             
                                                   
        Variable name  . . . . . . . . > '1110419' 
        Variable value . . . . . . . .             
                     + for more values
      You want this:
      Code:
      Set variables:                               
        Variable name  . . . . . . . . > CYMD      
        Variable value . . . . . . . . > '1110419' 
                                                   
                     + for more values
      Code:
       SETVAR((CYMD '1110419'))
      There's a cool feature of the command prompter that you might not know about. If you have the command the way you want it in the prompter, you can hit F14 and see the command as it would go on the command line. Here's how it looks after I fixed the SETVAR parameter.
      Code:
      STRQMQRY QMQRY(AMPHQRY/IMHISTARCH) 
               OUTPUT(*OUTFILE)          
               QMFORM(*QMQRY)            
               OUTFILE(SPLIB/IMHISTARCH) 
               OUTMBR(*FIRST *ADD)       
               ALWQRYDFN(*YES)           
               SETVAR((CYMD '1110419'))

      Comment

      Working...
      X