[COBOL] removing leading zeros in output
didiche
-
didiche -
didiche -
Hello,
I have a problem editing a field without leading zeros.
Here it is,
A PIC X(25) field to be placed in a 9(7)V99 field. (for example 0000002.50)
So far, so good.
Then to edit this 9(7)V99 field into Z(6)9V99, it doesn’t work anymore because I get:
2<0.5 (or something like that, I can't remember).
How should I proceed?
Thanks.
JG
Configuration: Windows XP / Firefox 5.0
I have a problem editing a field without leading zeros.
Here it is,
A PIC X(25) field to be placed in a 9(7)V99 field. (for example 0000002.50)
So far, so good.
Then to edit this 9(7)V99 field into Z(6)9V99, it doesn’t work anymore because I get:
2<0.5 (or something like that, I can't remember).
How should I proceed?
Thanks.
JG
Configuration: Windows XP / Firefox 5.0
5 answers
-
Hello,
The EDITION PICTURE (Z(6)9V99) should probably be defined with a comma Z(6)9,99 (or a point according to the DECIMAL POINT clause of the SPECIAL-NAMES paragraph) rather than with a virtual decimal point (V)
Best regards.
Christian.-
Hello,
I indeed set Special-Names. The decimal point is a comma.
My editing picture is correctly Z(6)9,99 (instead of V), but it doesn't work; it shows what I mentioned.
So I don't understand. I must be programming incorrectly at some point; I don’t know.
Can you provide me with a programming template?
Thank you
Best regards
-
-
A zone pic X(25) to be placed in a zone 9(7)V99. (for example 0000002.50)
So far, so good.
I believe the issue is related to moving from PIC X... to PIC 9V... and moreover from X(25) (let me remind you that COBOL only accepts 18 digits in fixed decimal for a numeric area. I presume there is left truncation of the receiving zone of the X(25) value. It is indeed surprising that the compiler did not react.
If you can redefine your emitting zone from X(25) and IF you are sure that it is filled at least in its last 9 positions with digits (0 to 9), try this:
01 ZONE-EMET PIC X(25).
01 RED-ZONE-EMET REDEFINES ZONE-EMET.
05 FILLER PIC X(16).
05 ZONE-NUM PIC 9(07)V99.
You then move ZONE-NUM to the receiving area PIC 9(7)V99.
MOVE ZONE-NUM TO ZONE-RECEPT.
Sincerely,
Cchristian. -
-
Hello,
Well, darn it, it doesn't work, I don't understand.
I tried the example you gave me, and it's as if (which it is), the numeric area goes into the PIC x(16)???
So my output area is zero!
When you say "Then you move ZONE-NUM into the receiving area PIC 9(7)V99" you mean into the area ZZZZZZ9,99 (ZONE-RECEPT)? Is that right?
There you go
Thank you
-
-
Good evening,
Here is a tested solution to the problem that works for me:
IDENTIFICATION DIVISION.
PROGRAM-ID. TESTCOB.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES. DECIMAL-POINT IS COMMA.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
01 ZONE-EMET PIC X(25) VALUE '0123456789012345678901234'.
01 RED-ZONE-EMET REDEFINES ZONE-EMET.
05 FILLER1 PIC X(16).
05 ZONE-NUM PIC 9(07)V99.
01 ZONE-RECEPT PIC ZZZZZZ9,99.
PROCEDURE DIVISION.
BEGIN.
MOVE ZONE-NUM TO ZONE-RECEPT
DISPLAY ' ZONE-RECEPT : ', ZONE-RECEPT UPON CONSOLE.
* The result is: 6789012,34
MOVE " (15 spaces)0000012346" TO ZONE-EMET.
MOVE ZONE-NUM TO ZONE-RECEPT
DISPLAY ' ZONE-RECEPT : ', ZONE-RECEPT UPON CONSOLE.
* The result is: 123,46.
STOP RUN.
END-PGM.
--
Sincerely.
Cchristian. -