HPlogo DATA TYPES CONVERSION Programmer's Guide: HP 3000 MPE/iX Computer Systems > Chapter 3 Converting Data Types

Converting from Packed Decimal

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

This section offers some suggestions converting packed decimal data types to character, integer, and real data types.

Compiler library routines can be used to manipulate decimals in NM. Because the sizes of the operands are passed as parameters, these routines are useful in applications where the field sizes are not known at compile-time, such as general-purpose database applications and report writers.

The compiler library packed-decimal procedures must be declared as intrinsics if you use them in high-level NM languages. If speed is a primary concern, consider doing packed-decimal operations within HP COBOL II/XL or HP RPG/XL.

If you are working within COBOL or RPG, you would use PIC clauses and the MOVE command to convert types. The following suggestions are for situations where you have other languages involved.

To Character

HPPACCVDA accepts a packed-decimal number and returns an ASCII representation of the number. An unsigned source produces an unsigned result; if the source a signed decimal, you specify whether the target will be signed. You specify the number of digits in the result.

To Integer

HPPACCVDB accepts a packed decimal and returns an integer. The integer is a signed binary number in twos complement form, and its size depends on the number of digits in the source.

To Real

If you are working outside COBOL or RPG, you would convert indirectly as follows:

  1. Convert the decimal value to an integer.

  2. Convert the resulting integer to a real number.

  3. Multiply or divide by the appropriate power of ten.

(See the previous sections about making these conversions.)

If you are working in COBOL, you can convert the decimal value to an ASCII integer. Pass this to the routine, and convert it to a real value there.

To Other Decimals

The MOVE command is used to change one decimal to another within COBOL or RPG.

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.

Feedback to webmaster