IBM Support

Inputting Hex Data into a File using RPGLE

Troubleshooting


Problem

This document provides sample code that shows how to input Hex data into a file using an RPGLE program.

Resolving The Problem

The following is a sample program that shows how Hex data can be added to a Physical File (PF) with fields that are defined using the HEX data type.
Specify an H (hexadecimal) in position 35 to indicate a field whose contents are not interpreted by the system. In most cases, hexadecimal fields are treated as character fields, except that the contents of a hexadecimal field are not translated to any character set or code page.

The following code uses a hard coded value of 1234 in field1. It is more common for the data to be coming in from a display file.

The PF File HEXFIELD with HEX field defined:
     A          R FMT1
     A            HEXFLD         2H    

Example ILE RPG IV source HEXDTA2:
**FREE
Dcl-F hexfield   Usage(*Output);
Dcl-Ds *n;
  pck1            Packed(5:0);
  chr1            Char(2)         overlay(pck1);
End-Ds;
//
Dcl-S field1          Char(4)         inz('1234');
Dcl-S field2          Char(5);
field2 = field1;
pck1 = %Dec(%XLate(' ':'0':
      field2):5:0);
hexfld = chr1;
Write fmt1;
*INLR = '1'; 
Compile the program using CRTBNDRPG
Call from command: CALL HEXDTA2
The result can be examined using SQL
image-20241118113351-1

 

[{"Type":"MASTER","Line of Business":{"code":"LOB68","label":"Power HW"},"Business Unit":{"code":"BU070","label":"IBM Infrastructure"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m0z0000000CHtAAM","label":"Programming ILE Languages"}],"ARM Case Number":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions"}]

Historical Number

421499779

Document Information

More support for:
IBM i

Component:
Programming ILE Languages

Software version:
All Versions

Operating system(s):
IBM i

Document number:
637401

Modified date:
18 November 2024

UID

nas8N1014864

Manage My Notification Subscriptions