How To
Summary
This document provides clarification of declaring and using a variable of type integer , aka *INT
Environment
IBM i V7R1 and higher
Steps
IBM has enhanced the ability to declare integer variables within a CL program. Back in V5R3, the CL DCL command added support for 2-byte and 4-byte signed and unsigned integer variables (removing the need in many cases to use the %bin CL built-in). The 4-byte signed integer values could range from -2147483648 to 2147483647, and unsigned integers from 0 to 4294967295. While these are large numbers, they are not large enough for some applications. One specific type of application, where larger numeric value support is needed, is in the area of systems management.
Many systems are tuned throughout the day using CL commands, and this results in quite a few of the systems management applications being written, at least in part, using CL. The problem is that many of the system APIs that return system-level information, information that a systems management application needs access to in order to effectively manage a system, have evolved to using 8-byte integer values in order to reflect the high workloads that IBM i is capable of supporting. Compared to 4-byte integer values, 8-byte signed integers can store a value ranging from -9223372036854775808 to 9223372036854775807, and 8-byte unsigned integers a range from 0 to 18446744073709551615. With V7R1, CL developers who need access to these expanded ranges can simply DCL the appropriate variables as TYPE(*INT) or TYPE(*UINT) with LEN(8).
There are two considerations related to 8-byte integer support, neither of which I consider to be very limiting. The first is that 8-byte integers can be declared only within an ILE CL program. So if you're still writing for the OPM environment, my only comment is that it's time to move into the 21st century! The second consideration is that while the DCL command supports 8-byte signed and unsigned integers, the Parameter definition (PARM) and Element definition (ELEM) commands used in creating user commands do not. I have never encountered a need to supply a numeric value, to a command, even approaching the size of a 4-byte integer, and I really don't know that I would even want a user trying to supply such a number, at a command prompt, in any case. So I do not see this as being a problem. And I'm sure IBM could remove this limitation if it were to become a problem, just as they did for DCL and the need for CL programs to access system API information efficiently.
For type *INT or *UINT, if you do not specify the LEN parameter, the default length is 4.
Sample CL using INT.
The source must be compiled with Create CL Module (CRTCLMOD) and then CRTPGM or
Create Bound CL Program (CRTBNDCL)
PGM
DCL VAR(&COUNT) TYPE(*INT)
DCL VAR(&LGL) TYPE(*LGL)
DCL VAR(&MYCHAR) TYPE(*CHAR) LEN(3)
DOUNTIL (&LGL)
CHGVAR &COUNT (&COUNT + 1)
IF (&COUNT *GE 10) (CHGVAR &LGL '1')
CHGVAR VAR(&MYCHAR) VALUE(%CHAR(&COUNT))
SNDPGMMSG MSG(&MYCHAR)
enddo
ENDPGM
This sample program was named KOUNTER.
Call the program from command line to see the results.
> call kounter
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
I want to acknowledge Bruce Vining for the content published in this article.
Document Location
Worldwide
[{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m0z0000000CHtAAM","label":"Programming ILE Languages"}],"ARM Case Number":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Version(s)","Line of Business":{"code":"LOB57","label":"Power"}}]
Was this topic helpful?
Document Information
Modified date:
27 July 2020
UID
ibm16252071