Re: Dynamically Determine Numeric PICTURE String
- From: "Rick Smith" <ricksmith@xxxxxxx>
- Date: Fri, 23 Mar 2007 14:55:01 -0500
"Rick Smith" <ricksmith@xxxxxxx> wrote in message
news:13085kf5ukmp595@xxxxxxxxxxxxxxxxxxxxx
I question whether there is any real need for this;
but I was thinking about some parts of COBOL
and ... well ... one thing led to another.
Well ... another thing led to another when I realized
I had not accounted for "P" in the PICTURE string.
This program works only when ANSI truncation
is in effect.
-----
$set ans85 flag"ans85" flagas"s"
identification division.
program-id. find-pic.
data division.
working-storage section.
01 item comp pic sp(3)9(3).
01 pic-work-area.
02 counts.
03 minus-sign pic 9(2) value 0.
03 9s-before pic 9(2) value 0.
03 0s-before pic 9(2) value 0.
03 0s-after pic 9(2) value 0.
03 9s-after pic 9(2) value 0.
02 pic-work.
03 int-part pic -(17)9.
03 frac-part pic .9(18)-.
02 pic-string pic x(12) value spaces.
02 string-pos pic s9(4) binary value 0.
procedure division.
begin.
initialize pic-work-area
add -999999999999999999 -.999999999999999999
giving item
move item to int-part frac-part
inspect pic-work tallying
minus-sign for all "-"
9s-before for all "9" before "."
0s-before for all "0" after "9" before "."
0s-after for all "0" after "." before "9"
9s-after for all "9" after "."
move 1 to string-pos
if 9s-after > 0
string
")" delimited by size
function reverse (9s-after (1:))
delimited by "0"
"(9" delimited by size
into pic-string
pointer string-pos
end-string
if 0s-after > 0
string
")" delimited by size
function reverse (0s-after (1:))
delimited by "0"
"(p" delimited by size
into pic-string
pointer string-pos
end-string
else
string
"v" delimited by size
into pic-string
pointer string-pos
end-string
end-if
end-if
if 0s-before > 0
string
")" delimited by size
function reverse (0s-before (1:))
delimited by "0"
"(p" delimited by size
into pic-string
pointer string-pos
end-string
end-if
if 9s-before > 0
string
")" delimited by size
function reverse (9s-before (1:))
delimited by "0"
"(9" delimited by size
into pic-string
pointer string-pos
end-string
end-if
if minus-sign > 0
string "s"
delimited by size
into pic-string
pointer string-pos
end-string
end-if
subtract 1 from string-pos
move function reverse (pic-string (1:string-pos))
to pic-string
display pic-string (1:string-pos)
stop run.
-----
.
- References:
- Dynamically Determine Numeric PICTURE String
- From: Rick Smith
- Dynamically Determine Numeric PICTURE String
- Prev by Date: Dynamically Determine Numeric PICTURE String
- Next by Date: Re: Dynamically Determine Numeric PICTURE String
- Previous by thread: Re: Dynamically Determine Numeric PICTURE String
- Next by thread: Re: Dynamically Determine Numeric PICTURE String
- Index(es):
Relevant Pages
|