How To
Summary
This document pertains to IBM i CL Programming.
The binary built-in function (%BINARY or %BIN) interprets the contents of a specified CL character variable as a signed binary integer.
The starting position begins at the position specified and continues for a length of 2 or 4 characters.
CL Programming built-in function %BIN works with 2 or 4 bytes signed integers.
There are certain APIs that use a BINARY(8) field in the format of the data to return and it is not obvious how to convert the value to a character.
Objective
In this example, 8-byte integer is being used.
The CL program needs to be an ILE CL program compiled by using CRTBNDCL.
This sample uses Retrieve Partition Information (dlpar_get_info) API to return information about configuration and CPU usage of the logical partition where this API is called. IBM Knowledge Center IBM i api dlpar_get_info
This sample uses Retrieve Partition Information (dlpar_get_info) API to return information about configuration and CPU usage of the logical partition where this API is called. IBM Knowledge Center IBM i api dlpar_get_info
The sample is obtaining the value for Defined memory that is at offset 353 and is defined as binary(8).
The following notes help clarify the composition of the CL program.
- STG(*DEFINED) - Storage: the value for this variable is specified in the variable defined in the DEFVAR parameter.
- DEFVAR(&DATA ?) - Defined on variable: specifies the variable that contains this field, and its starting position.
- %CHAR converts logical, decimal, integer, or unsigned integer data to character format.
PGM DCL VAR(&Return) TYPE(*CHAR) LEN(4) DCL VAR(&Receiver) TYPE(*CHAR) LEN(368) DCL VAR(&Format) TYPE(*INT) LEN(4) DCL VAR(&Length) TYPE(*INT) LEN(4) DCL VAR(&Message) TYPE(*CHAR) LEN(38) VALUE('DEFMEM: - ') DCL VAR(&MsgDta) TYPE(*CHAR) LEN(30) STG(*DEFINED) DEFVAR(&Message 9) DCL VAR(&DefMem) TYPE(*INT) LEN(8) STG(*DEFINED) DEFVAR(&Receiver 353) CHGVAR VAR(&Format) VALUE(1) CHGVAR VAR(&Length) VALUE(368) CALLPRC PRC('dlpar_get_info') PARM((&Receiver) (&Format *BYVAL) (&Length + *BYVAL)) RTNVAL(&Return) DMPCLPGM CHGVAR VAR(&MsgDta) VALUE(%CHAR(&DefMem)) SNDPGMMSG MSGID(CPF9898) MSGF(QSYS/QCPFMSG) MSGDTA(&Message) ENDPGM
Compile the CL :- CRTBNDCL PGM(<libname>/<pgmname>) SRCFILE(<libname>/<srcfile>)
Run the program and view the result.
> call binapi2
DEFMEM: 30976.
DEFMEM: 30976.
Document Location
Worldwide
[{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG60","label":"IBM i"},"Component":"CL Programming","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB57","label":"Power"}}]
Was this topic helpful?
Document Information
Modified date:
19 December 2019
UID
ibm11137904