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!

String numeric value into pipe delimited without leading zeros? 1

Status
Not open for further replies.

nixie21

Programmer
Jul 19, 2005
16
0
0
US
How can I do this? I have a value defined pic 999.99 (or even zz9.99). If the value is 60.00 I need to string the value as

|60.00|

How do I do that in my string command? I always get |060.00| or | 60.00|

Thanks so much!
 
First you should compute what you need.
That gives you a result
then you move that result to PIC z that you made
so it looks like this:

WORKING-STORAGE SECTION.

01 first PIC 9(6).
01 second PIC 9(6).
01 result PIC 9(6).
01 displayResult PIC Z(6).

PROCEDURE DIVISION.
ADD first second GIVING result.
MOVE result to displayResult.
DISPLAY displayResult.

and i think that is it !
you always have to have one VARIABLE for DISPLAYING!





 
Maybe I am missing something?

01 ws-hold-fine2 pic zz9.99.


Say the value is 10.00
The below code will look like

AAAAA|SDSSSS| 10.00|

The spaces is killing me!!! THANKS

move zeros to ws-hold-fine2.
move ws-hold-fine to ws-hold-fine2.

string 'AS' delimited by size
'|' delimited by size
cit-mag-no delimited by size
'|' delimited by size
new-cit-no delimited by size
'|' delimited by size
'Fine' delimited by size
'|' delimited by size
ws-hold-fine2 delimited by size
into courtrec.
 
Pic zzz99.99 is still treated as character and you will get the blank fill if you use it in a string statements. Here's what I usually do to eliminate blanks:

Create several numeric working storage ranging from 1 to n number of digits depending on the maximum length of your variables. i.e.,

NUM1 PIC 9.99.
NUM2 PIC 99.99.
NUM3 PIC 999.99. and so on.

In your program logic you will have to test the result with something like below:

IF (RESULT < 10)
MOVE RESULT TO NUM1
DO STRING-ROUTINE
ELSE
IF (RESULT < 100)
MOVE RESULT TO NUM2
DO STRING-ROUTINE
ELSE
IF (RESULT < 1000)
MOVE RESULT TO NUM3
DO STRING-ROUTINE
ELSE
more testing here up to the maximum digits

END-IF.

 
OK, I got it...

I did this

01 ws-hold-fine2 pic 999.99.
01 ws-hold-fine3 pic x(6).


Then I did

move ws-hold-fine to ws-hold-fine2.
if ws-hold-fine2 (1:1) = '0'
move ws-hold-fine2 (2:5) to ws-hold-fine3
else
move ws-hold-fine2 to ws-hold-fine3.

Worked great...thanks for the help!
 
A better method is to search for the occurrence of blanks in a numeric variable. This way you only need one working storage.
This also eliminates leading zeroes.

01 RESULT PIC 9(10)V99 VALUE ZEROES.

..RESULT above has 12 digits so in your logic do this

MOVE ZEROES TO I1.
MOVE ZEROES TO I2.

PERFORM VARYING I1 FROM 1 BY 1
UNTIL (I1 >= 12)
OR (I2 = 999)
IF (RESULT(I1) >= 1) AND (RESULT(I1) <= 9)
MOVE 999 TO I2
END-IF
END-PERFORM.

COMPUTE I2 = 12 - I6 + 1.

STRING SO AND SO DELIMITED BY SOMETHING
RESULT(I1:I2) DELIMITED BY SIZE
ETC.....





 
Sorry my finger is fast..

RESULT PIC 9(10).99 << 13 Char

MOVE ZEROES TO I1.
MOVE ZEROES TO I2.

PERFORM VARYING I1 FROM 1 BY 1
UNTIL (I1 >= 13)
OR (I2 = 999)
IF (RESULT(I1:1) >= 1) AND (RESULT(I1:1) <= 9)
OR (RESULT(I1:1) = ".")
MOVE 999 TO I2
END-IF
END-PERFORM.

COMPUTE I2 = 13 - I6 + 1.

STRING SO AND SO DELIMITED BY SOMETHING
RESULT(I1:I2) DELIMITED BY SIZE
ETC.....
 
Why does someone believe |060.00| is a problem?

This is incredibly simple to generate (one move versus an entire routine) and is completely workable on any target system that can handle |060.00| . . .
 
Code:
01 varx.
   05  filler pic x(01) value spaces.
   05  mynum pic z(3)9. <---- this one change according to your needs.
01 my-sourcenum pic 9(4).

01 dummy pic x(30).

01  my-outputvar pic x(30)
...
move my-sourcenum to mynum
unstring varx delimited by all spaces into dummy my-outputvar

something similar to the above will give you what you want

Regards

Frederico Fonseca
SysSoft Integrated Ltd

FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top