ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Using BINARY(4) in CL Program

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

  • Using BINARY(4) in CL Program

    Hello, all.

    I'm still relatively new to using CL programs in general on the IBM i. I'm looking into using the QDCRDEVD API to retrieve information on *PRT printer device descriptions specifically so I can output the results to a database file:



    I'm familiar with dealing with character-based types, like 'CHAR(10)' and I do understand the decimal offset information. E.g. DEVD1100 Format: Offset - Dec - 152, CHAR(10), 'device class.'

    However, let's say I'd like to retrieve the values or data for 'Switch setting' that uses 'BINARY(4)' type with Offset - Dec - 144. You can't exactly use 'TYPE(*BIN)' of course in a CL pgm, so how best would you deal with this type of data? Would you need to do a conversion? I just can't seem to grasp this concept yet. If there's documentation on this I'd greatly appreciate it. Thank you.

  • #2
    I really hate that IBM calls them "BINARY" since everything in a computer is stored in binary, its really ambiguous. Most languages (including modern CL) refer to these BINARY(4) variables as "integer".

    Code:
    DCL VAR(&SWITCHES) TYPE(*INT) LEN(4)

    Comment


    • #3
      Originally posted by Scott Klement View Post
      I really hate that IBM calls them "BINARY" since everything in a computer is stored in binary, its really ambiguous. Most languages (including modern CL) refer to these BINARY(4) variables as "integer".

      Code:
      DCL VAR(&SWITCHES) TYPE(*INT) LEN(4)
      That makes things a little easier to work with then. Thanks for the response! How would you recommend I go about converting the integer value to character type? I see that %CHAR might accomplish this:
      %CHAR converts logical, decimal, integer, or unsigned integer data to character format. The converted value can be assigned to a CL variable, passed as a character constant to another program or procedure, or specified as a value for a command parameter of a CL command run from compiled CL.

      Comment


      • #4
        Originally posted by LiQuiD_FuSioN View Post
        How would you recommend I go about converting the integer value to character type? I see that %CHAR might accomplish this

        Depends. What do you plan to do with the CHAR value?

        Comment


        • #5
          Originally posted by Scott Klement View Post


          Depends. What do you plan to do with the CHAR value?
          In the end I'd like to output the information to a database file. Making sure I'm formatting the data correctly.



          Using 'Inactivity timer' instead:
          136 88 BINARY(4) Inactivity timer

          This is part of what we have so far in CL. I can post the whole CL if needed:

          DCL VAR(&INACTTA) TYPE(*CHAR) LEN(4)
          DCL VAR(&INACTT) TYPE(*DEC) LEN(5 0)
          DCL VAR(&INACTTN) TYPE(*CHAR) LEN(4)


          CHGVAR &INACTTA %SST(&DEVINFO 137 4)
          CHGVAR &INACTT %BIN(&INACTTA)
          CHGVAR &INACTTN &INACTT


          CHGVAR VAR(&SQL_STMT) VALUE('INSERT INTO +
          TESTLIB.PRTQRY VALUES (' *CAT &QTE +
          *CAT &DEVD *CAT &QTE *CAT ',' *CAT &QTE +
          *CAT &DEVTYPE *CAT &QTE *CAT ',' *CAT &QTE +
          *CAT &CTLDESC *CAT &QTE *CAT ',' *CAT &QTE +
          *CAT &LASTACT *CAT &QTE *CAT ',' *CAT &QTE +
          *CAT &IPADDRS *CAT &QTE *CAT ',' *CAT &QTE +
          *CAT &SYSDRV *CAT &QTE *CAT ',' *CAT &QTE +
          *CAT &INACTTN *CAT &QTE *CAT ',' *CAT &QTE +
          *CAT &DEVATTR *CAT &QTE *CAT ')')

          Comment


          • #6
            For that, I think %CHAR should work nicely.

            Comment

            Working...
            X