Licensing software means no resales, right?
Hewlett-Packard decays, not a 3000 killer

How to convert 3000 packed decimal data?

Independent consultant Dan Miller wrote us to hunt down the details on converting between data types on the HP 3000. He's written a utility to integrate VPlus, IMAGE/SQL and Query for updating and modifying records. We'll let Miller explain. He wants to expand his utility that he's written in SPL -- the root language of MPE -- to include packed decimal data.

Can you tell me how to transfer a packed decimal to ASCII for display, then convert ASCII characters to the corresponding packed decimal data item?

I wrote a utility that integrates VPlus, IMAGE/SQL and Query, one that I used in a Federal services contract for data entry and word processing. Basically, VIQ lets me design a VPlus screen with field names the same as IMAGE data items. From the formatted screen a function key drops you into Query. You select the records to be maintained, specify "LP" as output, and execute the "NUMBERS" command (a file equation for QSLIST is necessary before this). From there, you can scroll thru the records, modify any field, and update. I never marketed it commercially, but I have used it at consulting customer sites.

I recently had occasion to use it at a new customer's site and realized that I never programmed it to handle packed decimal format numbers; the customer has a few defined in their database. Typically, database designers use INTEGER or DOUBLE INTEGER formats for numeric data, which occupy even less space -- the goal of using packed decimal) employing ASCII/DASCII, or BINARY/DBINARY intrinsics.

I need to discover the proper intrinsics to transfer the packed decimal numbers to ASCII characters and back. I'm sure there's a way, as QUERY does it. In COBOL, I think the "MOVE" converts it automatically, but my utility is written in SPL.

HP's documentation on data types conversion includes some help on this challenge. But Miller hopes that the readers of the Newswire can offer some other suggestions, too. Email me with your suggestions and we'll share them with the readers.

In the Data Types Conversion Programmer's Guide (tip of the hat to HP MM Support), we read about techniques to convert to real data types when when working outside of the COBOL library and compiler. From HP's documentation:

To Packed Decimal  

The compiler procedure HPACCVBD converts a signed binary integer to a packed decimal.  The input number is considered to be in twos complement form, from 2 to 12 bytes long. 

Packed-decimal procedures must be declared as intrinsics to be called from within high-level NM languages. In languages other than COBOL and RPG, follow these steps to convert from an input real to a packed decimal:

   1.  Multiply or divide the real number by an appropriate power of 10. 

   2.  Convert the resulting value to an base-ten integer. 

   3.  Convert that integer to a decimal.

The MOVE command is used to change one decimal to another within COBOL or RPG. But outside of COBOL or RPG, use the compiler library functions HPPACSRD and HPPACSLD to perform right and left shifts on packed decimals. You specify the amount of offset (the number of digits to be shifted).

To convert a packed decimal to a BASIC decimal, you should convert first to a twos complement integer or type ASCII, and then convert to decimal within BASIC with an assignment.  For example, assign an integer value to a decimal with decval = intval * n0, where n00 is the appropriate power of 10.  To convert between ASCII and decimal, use the VAL or VAL$ internal functions.

Comments