CA Easytrieve - How to total up hexadecimal values which are actually alpha-numeric values.
search cancel

CA Easytrieve - How to total up hexadecimal values which are actually alpha-numeric values.

book

Article ID: 33656

calendar_today

Updated On:

Products

PanAudit Plus Easytrieve Report Generator PAN/SQL

Issue/Introduction

Introduction:

 

Have you ever had the requirement to sum hexadecimal values in a file, which are actually alpha-numeric values (e.g. displayed as 'C6AEA155' )?

This document describes how to translate 8 digits hex values to decimal numeric values and summarize them.

 

 

Instructions: 

 

Compile and execute the following CA Easytrieve source:

...

//SYSIN DD *                                        

FILE FILEA                                          

  XIN             1  8  A                           

  XIN-BYTE   XIN     1  A  OCCURS 8 INDEX(IDX)      

*                                                   

FILE HEXTRAN TABLE INSTREAM                         

  ARG  1  1 A                                       

  DESC 4 12 N                                        

A  000000000010                                     

B  000000000011                                     

C  000000000012                                     

D  000000000013                                     

E  000000000014                                      

F  000000000015                                     

0  000000000000                                     

1  000000000001                                     

2  000000000002                                     

3  000000000003                                      

4  000000000004                                     

5  000000000005                                     

6  000000000006                                     

7  000000000007                                     

8  000000000008                                     

9  000000000009                                     

ENDTABLE                                            

*                                                   

NUM12   S 12 N   VALUE 0                             

SUMNUM  S 12 N   VALUE 0                            

*                                                   

JOB INPUT FILEA                                     

 IDX = 0                                            

 DO WHILE IDX < 8                                    

    IDX = IDX + 1                                   

    SEARCH HEXTRAN WITH XIN-BYTE(IDX), GIVING NUM12 

    CASE IDX                                        

       WHEN 7                                       

          NUM12 = NUM12 * 16                        

       WHEN 6                                       

          NUM12 = NUM12 * 256                       

       WHEN 5                                       

          NUM12 = NUM12 * 4096                      

       WHEN 4                         

          NUM12 = NUM12 * 65536       

       WHEN 3                         

          NUM12 = NUM12 * 1048576     

       WHEN 2                         

          NUM12 = NUM12 * 16777216    

       WHEN 1                          

          NUM12 = NUM12 * 268435456   

    END-CASE                          

    SUMNUM = SUMNUM + NUM12           

 END-DO                               

 DISPLAY 'SUMNUM: ' SUMNUM            

/*                                     

...

 

Short explanation of the source above:

-          <!--[endif]-->The JOB activity is reading the records from FILEA - one by one.

-          <!--[endif]-->Using the OCCURS with INDEX makes it possible to read Byte by Byte from the XIN field. This is being done in the "DO WHILE IDX < 8" loop.

-          <!--[endif]-->The "SEARCH HEXTRAN WITH XIN-BYTE(IDX), GIVING NUM12" instruction is searching for the XIN-BYTE in the HEXTRAN translation table, column 1, and writes the matching decimal value to NUM12.

-          <!--[endif]-->Then the CASE - END-CASE statement group is calculating the appropriate power of 16.

 

This is FILEA input DD used in the example:

...

//FILEA    DD  *

C6AEA155        

0043D11C        

...

 

And this is the expected result when using these two input records:

SUMNUM: 003333333333

SUMNUM: 003337777777

because

X'C6AEA155' = 3333333333

and

X'0043D11C' =    4444444

 

Environment

Release: EDBMSU00200-11.6-Easytrieve-Report Generator-Option for DB2-MSU
Component: