Tips and Techinques: The VARY Keyword

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Back in 1984, I wrote a user-written command, but this type was different. This one required that the CPP know the length of the value specified for the parameter. I did a little research and discovered the VARY keyword.

On the PARM statement of a Command Definition source member, you can specify VARY(*YES) for the parameter. This causes the command to insert a 2-byte binary prefix that contains the length of the value specified for the parameter. This 2-byte binary prefix is passed along with the parameter value to the CPP.

Today, it is structurally similar to a variable-length field in RPG IV. A 2-byte integer, as it is called today, is appended to the front of the value.

In RPG IV, there are two ways to receive this parameter value: as a varying field or as a data structure.

To receive it as varying field, you would code the following:




     D CompName        S             50A  VARYING

     C     *ENTRY        PLIST      
     C                   PARM                    CompName

To receive it as a data structure, you would code the following:

     D CompName        DS                
     D  nLen                          5I 0
     D  Data                         50A

     C     *ENTRY        PLIST      
     C                   PARM                    CompName

Either method works just fine.

To declare a command parameter, as mentioned, use the VARY keyword with *YES specified, as follows:

           PARM     KWD(COMPNAME) TYPE(*CHAR) LEN(50) +
                      VARY(*YES) PROMPT('Company name')

Today, the VARY keyword has two elements. Originally, it had only the *YES | *NO options, and VARY(*NO) was the default. Now, you can specify VARY(*YES) followed by the size of the integer used for the prefix. The size defaults to *INT2 (2-byte integer) or you can specify *INT4 (4-byte integer). In RPG IV, these values translate as follows:

  • *INT2=5I 0
  • *INT4=10I 0

Unless you're doing something unusual with the length because of the V5R3 CL enhancements, I can't ever see a need to use *INT4. So specifying VARY(*YES) is probably good enough for any work you do.

Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.

BOB COZZI

Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.


MC Press books written by Robert Cozzi available now on the MC Press Bookstore.

RPG TnT RPG TnT
Get this jam-packed resource of quick, easy-to-implement RPG tips!
List Price $65.00

Now On Sale

The Modern RPG IV Language The Modern RPG IV Language
Cozzi on everything RPG! What more could you want?
List Price $99.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: