ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

varying keyword

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

  • varying keyword

    Hello All,

    I have a input/output parameter defined as 25000 byte length. I'm not alway going to be populating the field with this much bytes so I was wondering if I could use the VARYING keyword to only pass back the actual values #bytes back to the calling program (or web application).

    Never used the VARYING keyword before...is this the purpose of the VARYING keyword?

    Please advise.

    Thanks,

    Pagen

  • #2
    Re: varying keyword

    If you're only wanting to pass by value, just use the VALUE keyword.

    Comment


    • #3
      Re: varying keyword

      The field is defined with a EXTPGM prototype and doesn't allow the value keyword.

      Comment


      • #4
        Re: varying keyword

        Yeah!!! you can use variying keyword..

        you can use options(*varsize) with string it will work.

        be sure you can not pass longer string than defined.



        Pramendra Pandeya
        Young people knows how to run fast but old people knows the way..

        Comment


        • #5
          Re: varying keyword

          Thanks RPGnoobie and Pramendra for the help. I'll probably try the OPTIONS(*varsize) and the VARYING keywords and see what I get.

          Thanks again.

          Pagen

          Comment


          • #6
            Re: varying keyword

            just a friendly FYI. if you use options(varsize) and a non-varying field make sure you don't access more characters than you pass in. if you do you will corrupt (overwrite/retrieve) data that may or may not belong to your program/process and can cause some severely undesired results!!!
            I'm not anti-social, I just don't like people -Tommy Holden

            Comment


            • #7
              Re: varying keyword

              Tahnks Tom,

              The field is an output parameter, if I initialize with blank prior to inializing with the needed value, would this fix the issue you mentioned previously?

              Please advise.

              Thanks.

              Pagen

              Comment


              • #8
                Re: varying keyword

                Originally posted by pagenbeast View Post
                Hello All,

                I have a input/output parameter defined as 25000 byte length. I'm not alway going to be populating the field with this much bytes so I was wondering if I could use the VARYING keyword to only pass back the actual values #bytes back to the calling program (or web application).

                Never used the VARYING keyword before...is this the purpose of the VARYING keyword?

                Please advise.

                Thanks,

                Pagen

                Any field that is longer than 100 bytes or so should be varying. A 25K byte field should absolutely be varying. When you build the contents of this field, you are likely having to trim the field several times. Basically, this requires the program to start at byte 25,000 and work backwards until it finds the first non-blank character. So if there is little data in that field, the program will have to do a lot of work to trim it.

                Varying fields don't have to do this. By their design, they know exactly where the end of the field is at all times, so the overhead of trimming isn't required. Also, other bifs such as %scan are faster, because it doesn't have to scan all 25,000 bytes. It only has to scan until it reaches the end of the data in that field.


                The keyword options(*varsize) is a totally different animal and shouldn't be confused with varying length fields. *varsize tells the program that a parameter is allowed to be passed with a shorter length than that specified in the prototype/interface.

                In your case, I would simply change the field to varying, and then make sure that the prototypes and procedure interfaces that you are passing this field to are also changed to varying. As long as you are always passing a 25,000 varying field, you dont have to worry about options(*varsize).
                Michael Catalani
                IS Director, eCommerce & Web Development
                Acceptance Insurance Corporation
                www.AcceptanceInsurance.com
                www.ProvatoSys.com

                Comment


                • #9
                  Re: varying keyword

                  Difference between varying and option(*varsize)

                  Code:
                  D myname        s            100A   VARYING
                  C                   eval      myString = 'PRAMENDRA PANDEYA'
                  In this example, the variable is declared as varying. It's true, I still coded "100A", but now that number specifies the maximum length of the string. The actual length can vary. In this example, myname only gets assigned the 17 characters. No blanks are added to the end.

                  On the other way option(*varsize)

                  *VARSIZE is an option that may be specified in the OPTIONS D-spec keyword. It has nothing to do with the data type of the variable. All it does is disable the compiler's validity checking of the length.

                  there is example here hope it helps....
                  http://http://forums.systeminetwork....ad.php?t=49845

                  Pramendra Pandeya
                  Young people knows how to run fast but old people knows the way..

                  Comment


                  • #10
                    Re: varying keyword

                    for a better description of what i'm talking about check out slides 36-38 in this powerpoint tommyholden.com
                    I'm not anti-social, I just don't like people -Tommy Holden

                    Comment


                    • #11
                      Re: varying keyword

                      By reading all responses, it sounds like the VARYING keyword is the preferred method to use.

                      Thanks again to all that replied.

                      Pagen

                      Comment

                      Working...
                      X