ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

How to pass a numeric parameter to query/400?

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

  • How to pass a numeric parameter to query/400?

    Hi,

    I am already familiar with how to pass character parameters to a query/400 and now I need to pass a numeric parameter. I also try sending alpha parameter (year â??05â??) and convert file field in query NEWYR (DIGITS (YR)) and compare the value with parameter field (NEWYR *EQ YEAR). I got an error about comparison operation.

    Please let me know if anyone has answer.

    Bharat

  • #2
    Re: How to pass a numeric parameter to query/400?

    Originally posted by BPandya
    Hi,

    I am already familiar with how to pass character parameters to a query/400 and now I need to pass a numeric parameter. I also try sending alpha parameter (year â??05â??) and convert file field in query NEWYR (DIGITS (YR)) and compare the value with parameter field (NEWYR *EQ YEAR). I got an error about comparison operation.

    Please let me know if anyone has answer.

    Bharat
    Hi Bharat,

    Sorry for counter question.
    Could you please explain how do we pass character parameter in query400?

    thks in advance.

    Comment


    • #3
      Re: How to pass a numeric parameter to query/400?

      The only way I've used this technique was to write my "parameters" into a Temp file and then have the Qry use the Temp file for processing. It made life much simpler that way.

      Comment


      • #4
        Re: How to pass a numeric parameter to query/400?

        Here's a tip I have used for a while that was posted on another site. It came from B.Hauser, who is a member of this board:

        PHP Code:
        FromBirgitta Hauser
        Subject
        ReCL Query Interface resolutions
        Date
        28 Oct 2003 00:12:56 -0800 

        Jonathan Spencer wrote
        Any ideas on full variables in Queries/CL

        Do 
        you want to pass variables for selection to a Query/400 and then run it? If so

        1. Change your selections in your Query using variables

           :
        VarName
           Before
        :
           AND/OR  
        Feld              Test   Wert (FeldNummer'Zeichen'
        oder...)
                   
        FIRNR             EQ     100
            
        AND    ADTPA             EQ     'E'

           
        After:
           AND/OR  
        Feld              Test   Wert (FeldNummer'Zeichen'
        oder...)
                   
        FIRNR             EQ     :PFINR
            
        AND    ADTPA             EQ     :PTPA

        2. Write a CL
        -Program to fill your variables and run your query using STRQMQRY instead of RUNQRY 

        Example


                        
        PGM        PARM(&P$FINR &P$TPA)             

                        
        DCL        VAR(&P$FINR)  TYPE(*DEC)  LEN(3
                        
        DCL        VAR(&QryFINRTYPE(*CHARLEN(3
                                                                 
                        
        DCL        VAR(&P$TPA)   TYPE(*CHARLEN(2
                        
        DCL        VAR(&QryTPA)  TYPE(*CHARLEN(4
                                                                 
                        
        ChgVar     Var(&QryFiNrValue(&P$FINR)     
                        
        ChgVar     Var(&QryTpa)                     
                                   
        Value('''' *cat &P$TPA *Cat '''')

                        
        StrQmQry   QmQry(MYQUERY)                  +
                                   
        Output(*PRINT)                  +
                                   
        QmForm(*QMQRY)                  +
                                   
        AlwQryDfn(*YES)                 +
                                   
        SetVar((PFINR &QryFiNr) (PTPA &QryTpa))
                                                                              
                                 
        ENDPGM

        Birgitta 
        You can also use the STRQMQRY command to run the query interactively and the prompts will pop up.

        Pete

        Comment


        • #5
          Re: How to pass a numeric parameter to query/400?

          Thanks Pete........and Birgitta
          All my answers were extracted from the "Big Dummy's Guide to the As400"
          and I take no responsibility for any of them.

          www.code400.com

          Comment


          • #6
            Re: How to pass a numeric parameter to query/400?

            Nice avatar........spend some quality time around Byron this weekend?

            Comment


            • #7
              Re: How to pass a numeric parameter to query/400?

              Excellent Pete,
              Thnks a lot!
              Today I have learnt a new technique.It's amazing!!
              Originally posted by Pete
              Here's a tip I have used for a while that was posted on another site. It came from B.Hauser, who is a member of this board:

              PHP Code:
              FromBirgitta Hauser
              Subject
              ReCL Query Interface resolutions
              Date
              28 Oct 2003 00:12:56 -0800 

              Jonathan Spencer wrote
              Any ideas on full variables in Queries/CL

              Do 
              you want to pass variables for selection to a Query/400 and then run it? If so

              1. Change your selections in your Query using variables

                 :
              VarName
                 Before
              :
                 AND/OR  
              Feld              Test   Wert (FeldNummer'Zeichen'
              oder...)
                         
              FIRNR             EQ     100
                  
              AND    ADTPA             EQ     'E'

                 
              After:
                 AND/OR  
              Feld              Test   Wert (FeldNummer'Zeichen'
              oder...)
                         
              FIRNR             EQ     :PFINR
                  
              AND    ADTPA             EQ     :PTPA

              2. Write a CL
              -Program to fill your variables and run your query using STRQMQRY instead of RUNQRY 

              Example


                              
              PGM        PARM(&P$FINR &P$TPA)             

                              
              DCL        VAR(&P$FINR)  TYPE(*DEC)  LEN(3
                              
              DCL        VAR(&QryFINRTYPE(*CHARLEN(3
                                                                       
                              
              DCL        VAR(&P$TPA)   TYPE(*CHARLEN(2
                              
              DCL        VAR(&QryTPA)  TYPE(*CHARLEN(4
                                                                       
                              
              ChgVar     Var(&QryFiNrValue(&P$FINR)     
                              
              ChgVar     Var(&QryTpa)                     
                                         
              Value('''' *cat &P$TPA *Cat '''')

                              
              StrQmQry   QmQry(MYQUERY)                  +
                                         
              Output(*PRINT)                  +
                                         
              QmForm(*QMQRY)                  +
                                         
              AlwQryDfn(*YES)                 +
                                         
              SetVar((PFINR &QryFiNr) (PTPA &QryTpa))
                                                                                    
                                       
              ENDPGM

              Birgitta 
              You can also use the STRQMQRY command to run the query interactively and the prompts will pop up.

              Pete

              Comment


              • #8
                Re: How to pass a numeric parameter to query/400?

                Just make sure you tell EVERYONE where you got this... we gotta make sure Birgitta gets all the credit he can.

                Great job B!!

                Comment


                • #9
                  Re: How to pass a numeric parameter to query/400?

                  FaStOnE,

                  Ah, er, hum, excuse me, but I think Birgetta is a she...

                  MdnghtPgmr
                  "Tis better to be thought a fool then to open one's mouth and remove all doubt." - Benjamin Franklin

                  Comment


                  • #10
                    Re: How to pass a numeric parameter to query/400?

                    Naa.. I'd have to say B is a Cartoon... just look at the Avitar!

                    Comment


                    • #11
                      Re: How to pass a numeric parameter to query/400?

                      Shanky,

                      I am sorry for not geting back to you.
                      I visited this site and particularly this event after long time.
                      Anyway you have got the answer.

                      Bpandya

                      Comment


                      • #12
                        Hi , I'm newbie in AS400 , may i ask how to pass the parameter from CL program ?

                        I tried to create a Query : PCK_INR with parameter and use CL program to pass in parameter but that is error.


                        Comment


                        • #13
                          You have to concatenate quotes around the value otherwise the query thinks the value is a field name.
                          Code:
                          PGM        PARM(&PCKNO)
                          
                                          DCL        VAR(&PCKNO) TYPE(*CHAR) LEN(10)
                                          DCL        VAR(&QRYPCKNO) TYPE(*CHAR) LEN(12)
                          
                                          CHGVAR     VAR(&QRYPCKNO) VALUE('''' *CAT &PCKNO *CAT '''')
                          
                                          STRQMQRY   QMQRY(YENNI9/PCK_INR) ALWQRYDFN(*YES) +
                                                       SETVAR((P1TRNO &QRYPCKNO))
                          ENDPGM

                          Comment


                          • #14
                            Hi , thanks for your reply.
                            But , i encountered another error :-
                            SAVE DATA command ended due to error .
                            The error is it come from my query ?

                            Comment


                            • #15
                              Were there other messages prior to that one? There's not enough information given to determine what the problem is. If you put the cursor on a message and press F1 it will show you more help text for that message. Hopefully, that will help you figure out what the problem is.

                              Comment

                              Working...
                              X