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

Quick Question on Numeric formats

Status
Not open for further replies.

tuipeatau

Programmer
Oct 20, 2002
6
AU
Hi All,

I need to convert an -9(03).9(02) (of value say -001.45) to
a printed value of -1.45

Reason being so I can string these values into a comma delimited file. Leading zeroes are suppressed and no trailing or leading spaces.

If i were to define the field as -ZZ9.99 then the printed value will be - 1.45 with two blank positions between the sign and 1 which is my problem at the moment. Not that I need to define it in a way that I can ultimately use the STRING clause to string these values together.

Cheers
Tuipeatau
 
Try:
Code:
PIC -(4).99

The symbol - can be a floating insertion character. Tom Morrison
 
Thanks Tom

That helps.

However I am hoping to eliminate any leading spaces.

So when I string all these values together they will appear something like so:

12.12,123.45,-1.45,123

Without any spaces and no leading zeroes.

I know that I can use the inspect to count the number of leading spaces then work out the portion that I want to display but surely if there are 100 fields there has to be a better way in COBOL ???

Thnx
Tuipeatau
 
The PIC Tom gave you is a good start. I think the problem you may encounter is that now your value looks like bb-1.45 where b is a space. You have the two spaces in front of the minus sign. You have to find a way to know which byte contains the start of the value.

What you might try to do after you've moved the value into this field is to then left justify that value.

03 FIELD-A PIC -(4).99.


After you get a value in FIELD-A, you can left justify it by using:

PERFORM UNTIL FIELD-A(1:1) NOT = SPACE
MOVE FIELD-A(2:) TO FIELD-A(1:)
END-PERFORM.

As long as the first byte is a space, it will shift the remaining characters one byte to the left and pad trailing spaces.
 
Tom/Lunker

Appreciate your help.

Code seems to work as expected now.

Cheers
tuipeatau
 
Tuipeatau

Well, there are several ways to do this. One way would be to define all your fields in a group such as:
Code:
01  formatting-group.
    02  field-1    pic -(13).99.
    02             pic x.    
    02  field-2    pic -(10).99.
    02             pic x.    
    02  field-3    pic -(15).99.
    02             pic x.    
    02  field-4    pic -(9).99.
    02             pic x.
et cetera.

Then you can code your procedure division with a loop. Here is some metacode...
Code:
   move spaces to formatting-group.
   move a-number to field-1.
   move another-num to field-2.
   move yet-another to field-3.
   move b-number to field-4.
...
   move 0 to i.
   move 1 to j.
   inspect formatting-group tally i for initial spaces.
   perform until i not < length of formatting-group
      unstring formatting-group delimited by all spaces
         into save-num
         pointer i
         not on overflow
             string &quot;&quot;&quot;&quot; delimited by size
                    save-num delmited by space
                    &quot;&quot;&quot;,&quot;delimited by size
                 into output-buffer
                 pointer j
             end-string
      end-unstring
   end-perform.
Tom Morrison
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top