Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Packed number conversion 2

Status
Not open for further replies.

lbzh

Programmer
Aug 7, 2004
25
0
0
US
I have a v99999 packed number which i wish to convert to an alpha 8.

The following is the schema. A is the input, B I am using to unpack A, and C I am attempting to convert the unpacked number to the alpha, I wish to preserve the decimal point and sign (if there is any):

05 A PIC V99999 COMP-3.
05 B PIC V99999.
05 C PIC X(08).

MOVE A TO B.
MOVE B TO C.

This error message results:

"B" (NUMERIC NON-INTEGER)" and "C" (ALPHANUMERIC) did not follow the "MOVE"
statement compatibility rules. The statement was discarded
 
Try B as PIC .99999

V means virtial decimal point.
 
Hi lbzh,
I would like first like to bring in the point that 'V' in PIC V99999 represents a decimal point.I suggest what you do is split C in 2 sub levels as follows in addition to what TERMINATE has suggested :-
01 C.
05 C-decimal PIC X(01) VALUE '.'.
05 C-data pic X(07).
Now what you do is move the data from B (PIC 99999) to C-data.For example if B has 12345 .Then you do
MOVE B to C-data.
The result will as follows :-
.12345$$
where $ represents a space.
Hope it helps !
Bye
Tushar Johri
 
You will not get the sign unless you provide it in the PIC for A (e.g. SV99999 COMP-3. Then define B as PIC -.99999 and move A to B.

To test it, DISPLAY 'value of B is >' B '<'. A positive 123 should display as > .123<. If you want to display the + sign use PIC +.99999 (or do I have it reversed? :) Try it both ways.




Regards, Jack.

"A problem well stated is a problem half solved" -- Charles F. Kettering
 
What do you actually WANT to happen with your code

Code:
05  B   PIC V99999.
05  C   PIC X(08).
   ...
MOVE     B   TO C.

The rules of (Standard) COBOL only allow an INTEGER numeric field to be moved to an alphanumeric receiving item.

If you don't really WANT any "indication" of a decimal point in your alphanumeric field, then you could code:

Code:
05  B                  PIC V99999.
05  B-Red Redefines B  Pic  99999.
05  C                  PIC X(08).
   ...
MOVE     B-Red   TO C.

Bill Klein
 
At no point does lbzh indicate what he(?) wants the data to look like in C. If he value of A is .12345, does he want C to contain 12345bbb, .12345bb, bbb12345, bb.12345, or something else? Given an answer to this, almost anyone on this panel could give the right PICtures to produce the desired result.
 
I wanted the output to contain a decimal and a sign.

For instance

+.33333b
or
-.33333b

etc.

sorry for the vagueness.
 
Then it is quite simple. First A should have a sign in its picture: SV99999. Then C would have the picture of +.99999B. The conversion is done in one step: MOVE A TO C.

On IBM mainframes, this would be done in four machine instructions:
MVC - to put the edit pattern in the target.
EDMK - to convert packed decimal data to display data and mark the sign location.
BC - to bypass the + sign if the field is negative.
MVI - to move in the + sign.

Many of the IBM mainframe instructions are intended for COBOL:
MVCL - implements the COBOL Alphameric MOVE statement exactly.
CLCL - implements the COBOL Alphameric compare.
SRP - Adjusts the radix of a packed decimal number by [&plusmn;]31 digits with rounding if the adjustment is to the right. The "rounding" digit can be 0 - 9. In COBOL, the rounding digit would be 0 for no rounding, or 5 for rounding.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top