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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

floating trailing sign 1

Status
Not open for further replies.

dja1

Programmer
Apr 24, 2002
65
GB
I have a signed input field, PIC 9(12)V9(6).

I have no problem converting this to a leading and trailing zero suppressed field for example -
Input - 000000000123.450000 Output 123.45
However, I do have a problem when it's signed. For instance, if I define the output as PIC Z(11)9.9(6)-,
the result is 123.450000-, NOT the result I would like - 123.45-, (or input = -12.4567 output = 12.4567-).
Obviously, I can achieve the above by loads of code, but does anyone know if it's possible to get the desired result by simply using editting symbols ?
 
I'm not sure if it is possible to abbreviate Z(11) in
PIC Z(11)9.9(6)-
instead of using
ZZZZZZZZZZZ9.9(6)-

But I use similar display variable with trailing sign with the picture
PIC ZZZ.ZZZ.ZZZ.ZZZ.ZZ9,99-
and after moving in it e.g -1234,56 the output is correct, i.e. 1.234,56-
However I'm using DECIMAL-POINT IS COMMA
 
There is no standard way to achieve this result as zero-supressing from the right is not a standard function in COBOL. Excel would do this, but we are not talking Excel.

The way I would do it is with sub-string notation in a perform loop. I can't think of anything easier.
 
The following code snippet does roughly what you want. You'd have to change it some if you didn't want the sign immediately after the decimal point or if you wanted a minimum number of decimal positions.

Code:
        IDENTIFICATION DIVISION.
        PROGRAM-ID. TEST-PROG.
        DATA DIVISION.
        01  WS-FIELD                      PIC Z(9)9.9(6)-.
        01  WS-TALLY                      PIC S9(4) COMP-5.
        PROCEDURE DIVISION.
        0000-PARA.
            MOVE -123.4 TO WS-FIELD
            COMPUTE WS-TALLY = LENGTH OF WS-FIELD - 1
            PERFORM VARYING WS-TALLY FROM WS-TALLY BY -1 UNTIL
                WS-FIELD(WS-TALLY:1) NOT EQUAL "0"
                MOVE WS-FIELD(WS-TALLY + 1:1) TO WS-FIELD(WS-TALLY:2)
            END-PERFORM
            DISPLAY WS-FIELD
            GOBACK
            .

Regards,

Glenn
 
Thanks to everyone for taking the time to reply.

I have plumped for Glenn's solution, as this seems the closest to my requirements.

Thanks again

David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top