Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

pic x(5) to pic 9(5)

343 views
Skip to first unread message

webmaster

unread,
Nov 3, 1999, 3:00:00 AM11/3/99
to
Hi

I have the following variables :

01 var-x pic x(5).
01 var-9 pic 9(5).

My problem is that var-x contains
numeric date align on the left and with
blank on the right (ie : 15 + 3 blanks
on the right in var-x)

What can I do to obtain 00015 in var-9 ?

thanks

Christophe


Judson McClendon

unread,
Nov 3, 1999, 3:00:00 AM11/3/99
to

If you have a COBOL compiler that supports intrinsic functions, use:

compute var-9 = function numval(var-x)

If not, download GETNUM.ZIP from my web page below. :-)
--
Judson McClendon judm...@bellsouth.net (remove numbers)
Sun Valley Systems http://personal.bhm.bellsouth.net/~judmc
"For God so loved the world that He gave His only begotten Son, that
whoever believes in Him should not perish but have everlasting life."


Howard Brazee

unread,
Nov 3, 1999, 3:00:00 AM11/3/99
to
webmaster wrote:
>
> Hi

>
> I have the following variables :
>
> 01 var-x pic x(5).
> 01 var-9 pic 9(5).
>
> My problem is that var-x contains
> numeric date align on the left and with
> blank on the right (ie : 15 + 3 blanks
> on the right in var-x)
>
> What can I do to obtain 00015 in var-9 ?
>
> thanks
>
> Christophe

several possibilities:
If you know your format, do a redefines to 3 characters.

If you have a new compiler use NUMVAL().

You can look at each character (redefines & occurs), from right to left
- the first numeric character gets placed in your receiving field, the
next gets multiplied by 10 and added to receiving field, etc.

You can inspect to see how many numeric characters you have, then only
move that many characters using reference modification. (I suspect this
is what you will want to do)

Richard Plinston

unread,
Nov 3, 1999, 3:00:00 AM11/3/99
to
webmaster <webm...@eii.fr> wrote:

: 01 var-x pic x(5).
: 01 var-9 pic 9(5).

: blank on the right (ie : 15 + 3 blanks


: on the right in var-x)

: What can I do to obtain 00015 in var-9 ?

COMPUTE Var-9 = FUNCTION NUMVAL(Var-X)

--

docd...@clark.net

unread,
Nov 3, 1999, 3:00:00 AM11/3/99
to
In article <3820885E...@eii.fr>, webmaster <webm...@eii.fr> wrote:
>Hi
>
>I have the following variables :
>
>01 var-x pic x(5).
>01 var-9 pic 9(5).
>
>My problem is that var-x contains
>numeric date align on the left and with
>blank on the right (ie : 15 + 3 blanks
>on the right in var-x)
>
>What can I do to obtain 00015 in var-9 ?

You can do your own homewlrk... please.

DD


Joey

unread,
Nov 3, 1999, 3:00:00 AM11/3/99
to
I won't give you an example, but look up 'reference modification'. That
is an easy solution to this one.

webmaster wrote:

> Hi
>
> I have the following variables :
>
> 01 var-x pic x(5).
> 01 var-9 pic 9(5).
>
> My problem is that var-x contains
> numeric date align on the left and with
> blank on the right (ie : 15 + 3 blanks
> on the right in var-x)
>
> What can I do to obtain 00015 in var-9 ?
>

> thanks
>
> Christophe


donald tees

unread,
Nov 3, 1999, 3:00:00 AM11/3/99
to
Use the NUMVAL function, or
UNSTRING var-x DELIMITED BY SPACE INTO var-9.

webmaster wrote in message <3820885E...@eii.fr>...

Gumbo

unread,
Nov 4, 1999, 3:00:00 AM11/4/99
to
Your problem seems to be that your originating field is JUSTIFIED LEFT and
the way you want it to look would be JUSTIFIED RIGHT.

Look up the JUSTIFIED RIGHT clause. If you define the PIC X field with a
JUSTIFIED RIGHT CLAUSE when the values are originally filled in to the PIC X
field will be filled in properly. Thus a MOVE from the PIC X to the PIC 9
field will properly convert the field if leading ZZZs are used. ex: PIC
ZZZZ9.

Richard Plinston

unread,
Nov 4, 1999, 3:00:00 AM11/4/99
to
Gumbo <a...@a.com> wrote:
: Your problem seems to be that your originating field is JUSTIFIED LEFT and

: the way you want it to look would be JUSTIFIED RIGHT.

: Look up the JUSTIFIED RIGHT clause. If you define the PIC X field with a
: JUSTIFIED RIGHT CLAUSE when the values are originally filled in to the PIC X
: field will be filled in properly.

I think that you misunderstand the JUSTIFIED clause. It will
not drop spaces in the right hand end of a field. This may
depend on how you think the field is 'originally filled', but
for the purpose you describe it probably won't work.

That is to say if the value ws 'originally filled' by
MOVE "15" TO Var-X

then JUST RIGHT will work, but so will " 15" and this is
unlikely to be realistic.

: Thus a MOVE from the PIC X to the PIC 9


: field will properly convert the field if leading ZZZs are used. ex: PIC
: ZZZZ9.

It is Var-X that needs to be PIC ZZZZ9 for this to work, not the
Var-9 fied which should still be PIC 9(5). ANSI-85 can do
'de-editing' as long as the digits are aligned correctly and
are valid for the picture.

MicroFocus can de-edit in a move from an edited numeric to a
numeric regardless of alignment (with compiler flag DE-EDIT"1")
so that:

01 Var-X.
03 Var-E PIC ZZZZ9.
01 Var-9 PIC 9(5).

MOVE "15" TO Var-X
MOVE Var-E TO Var-9

results in the correct value (15) being in the Var-9 field.
This should be available with the next standard (as I
understand it).


--

Alex Flinsch

unread,
Nov 4, 1999, 3:00:00 AM11/4/99
to

docd...@clark.net wrote:

> In article <3820885E...@eii.fr>, webmaster <webm...@eii.fr> wrote:

> >Hi
> >
> >I have the following variables :
> >
> >01 var-x pic x(5).
> >01 var-9 pic 9(5).
> >
> >My problem is that var-x contains
> >numeric date align on the left and with
> >blank on the right (ie : 15 + 3 blanks
> >on the right in var-x)
> >
> >What can I do to obtain 00015 in var-9 ?
>

> You can do your own homewlrk... please.
>
> DD

Normally I would agree with DD, but it is a slow day here. So here goes

WORKING-STORAGE SECTION.
01 CONFUSING-WAY-TO-DO-IT.
05 VAR-X PIC X(05) VALUE '15 '.
05 VAR-9 PIC 9(05) VALUE ZERO.
05 VAR-9X REDEFINES VAR-9 PIC X(05).
05 VAR-X-SWAP-IN.
10 VAR-X-SWP4 PIC X(04).
10 VAR-X-SWP1 PIC X(01).
05 VAR-X-SWAP-OUT.
10 VAR-X-SWP1 PIC X(01).
10 VAR-X-SWP4 PIC X(04).
PROCEDURE DIVISION.
0000-MAIN.
MOVE VAR-X TO VAR-X-SWAP-IN
PERFORM UNTIL VAR-X-SWP1 OF VAR-X-SWAP-IN NOT = SPACE
MOVE CORRESPONDING VAR-X-SWAP-IN TO VAR-X-SWAP-OUT
MOVE VAR-X-SWAP-OUT TO VAR-X-SWAP-IN
END-PERFORM
MOVE VAR-X-SWAP-IN TO VAR-X
INSPECT VAR-X REPLACING LEADING SPACES BY '0'
MOVE VAR-X TO VAR-9X
DISPLAY VAR-9
GOBACK..

Cheesle

unread,
Nov 4, 1999, 3:00:00 AM11/4/99
to
webmaster wrote in message <3820885E...@eii.fr>...
>Hi
>
>I have the following variables :
>
>01 var-x pic x(5).
>01 var-9 pic 9(5).
>
>My problem is that var-x contains
>numeric date align on the left and with
>blank on the right (ie : 15 + 3 blanks
>on the right in var-x)
>
>What can I do to obtain 00015 in var-9 ?

This is interesting, do you know for sure that you are getting 2 digit
numbers, or will the number always be left justified and may be of variable
size? If the latter is true, how do you distinguish 1 and 10?

10000
10000

Just asking.

Cheesle

Robert Heady

unread,
Nov 4, 1999, 3:00:00 AM11/4/99
to
webmaster wrote in message <3820885E...@eii.fr>...
>Hi
>
>I have the following variables :
>
>01 var-x pic x(5).
>01 var-9 pic 9(5).
>
>My problem is that var-x contains
>numeric date align on the left and with
>blank on the right (ie : 15 + 3 blanks
>on the right in var-x)
>
>What can I do to obtain 00015 in var-9 ?
>
>thanks
>
>Christophe
>

The easiest way I know is:

01 var-x pic x(5) value '15 '.
01 var-red redefines var-x pic z(5).
01 var-9 pic 9(5).
PROCEDURE DIVISION.
A.
Move var-red to var-9.
Stop run.
--

An alphanumeric data item can be translated to a numeric data item by
redefining the alphanumeric data item with a PIC Z(n) and moving the
redefined item to the desired numeric item. The MOVE statement, triggering
the translation, starts the scan at the rightmost character of the
alphanumeric item and looks for numeric characters, plus/minus signs, and a
decimal point. The translated data item aligns the numeric value around the
first decimal point found.

==============================================
Robert A. Heady r.h...@liant.com

Liant Software Corp.
8911 Capital of Texas Hwy.
Austin, TX 78759
Phone: (512) 343-1010
Fax: (800) 835-0301
Home Page: www.liant.com
==============================================


William M. Klein

unread,
Nov 4, 1999, 3:00:00 AM11/4/99
to
If you have a field defined as PIC Z(5) and that data item includes "15 "
(3 trailing spaces), then you have INCOMPATIBLE DATA - and all "bets are
off". The data would have to be " 15" (3 leading spaces) for it to be
defined.

As stated much earlier in this thread, the NUMVAL intrinsic function would do
what was requested - but certainly NOT just redefining it as PIC Z(5)

--
Bill Klein
wmklein <at> ix dot netcom dot com
Robert Heady <r.h...@liant.com> wrote in message
news:lFoU3.2$rC1.1791@client...

Michael Mattias

unread,
Nov 5, 1999, 3:00:00 AM11/5/99
to
I can't stand it anymore!

If you don't have/ aren't permitted to use FUNCTION NUMVAL,

I have the following variables :
>>
>>01 var-x pic x(5).
>>01 var-9 pic 9(5).

ADD: 10 VAR-X-9 REDEFINES VAR-X PIC 9(05).
>>

MOVE ZERO TO SPACE-COUNTER
INSPECT VAR-X TALLYING SPACE-COUNTER FOR ALL SPACE
INSPECT VAR-X REPLACING ALL SPACE BY '0'
PERFORM SPACE-COUNTER TIMES
DIVIDE 10 INTO VAR-X-9 END-DIVIDE
END-PERFORM
MOVE VAR-X-9 TO VAR-9.

(Obviously, assumes VAR-X is left justified) (So add you own edits for
'numeric')

MCM


Rob Heady

unread,
Nov 6, 1999, 3:00:00 AM11/6/99
to
The original post did not specify which COBOL vendor he was using. The
solution I provided works with RM/COBOL and Acucobol. It is true that MF
COBOL will return: Error 163 Illegal character in Numeric Field when the
contents of the PIC Z(5) have trailing spaces. The standard does not
specify the action to take when the data item value does not conform to the
PICTURE character-string. So neither RM/COBOL nor MF COBOL are wrong in
what they do, at least in regards what Standard COBOL specifies. I should
have qualified my response with: Depending on how strict the enforcement of
the PICTURE character-string of the COBOL you are using ....

--


==============================================
Robert A. Heady r.h...@liant.com


William M. Klein wrote in message <7vt69u$o25$1...@nntp2.atl.mindspring.net>...


>If you have a field defined as PIC Z(5) and that data item includes "15
"
>(3 trailing spaces), then you have INCOMPATIBLE DATA - and all "bets are
>off". The data would have to be " 15" (3 leading spaces) for it to be
>defined.
>
>As stated much earlier in this thread, the NUMVAL intrinsic function would
do
>what was requested - but certainly NOT just redefining it as PIC Z(5)
>
>--
>Bill Klein
> wmklein <at> ix dot netcom dot com
>Robert Heady <r.h...@liant.com> wrote in message
>news:lFoU3.2$rC1.1791@client...
>> webmaster wrote in message <3820885E...@eii.fr>...
>> >Hi
>> >

>> >I have the following variables :
>> >
>> >01 var-x pic x(5).
>> >01 var-9 pic 9(5).
>> >

William M. Klein

unread,
Nov 6, 1999, 3:00:00 AM11/6/99
to
The thing to remember about incompatible data is that what your compiler does
may vary from release to release - not just from compiler to compiler. (Ask
any IBM mainframe COBOL programmer about S0C7s in OS/VS COBOL vs VS COBOL
II). You are correct that the Standard does NOT say what needs to happen
with incompatible data l- but what any vendor does with it today is NOT
something you should rely on.

FYI,
The draft of the next Standard *does* explicitly provide for an "exception"
to be raised by this situation. What you (the programmer) do with it, is
still up to you, but I sure would not develop new code relying on specific
compiler behavior in this case.

--
Bill Klein
wmklein <at> ix dot netcom dot com

Rob Heady <r.heady...@flash.net> wrote in message
news:zAPU3.2044$OQ.2...@news.flash.net...

Carl Hardeman

unread,
Dec 20, 1999, 3:00:00 AM12/20/99
to
A simple COBOL UNSTRING verb from the x field to the 9 field delimited by space
might would have done it. I haven't done that in a long time but it's a powerful
tool that is generally unused.

Alex Flinsch wrote:
>
> docd...@clark.net wrote:
>
> > In article <3820885E...@eii.fr>, webmaster <webm...@eii.fr> wrote:

> > >Hi
> > >
> > >I have the following variables :
> > >
> > >01 var-x pic x(5).
> > >01 var-9 pic 9(5).
> > >
> > >My problem is that var-x contains
> > >numeric date align on the left and with
> > >blank on the right (ie : 15 + 3 blanks
> > >on the right in var-x)
> > >
> > >What can I do to obtain 00015 in var-9 ?
> >

cwhardeman.vcf

Carl Hardeman

unread,
Dec 20, 1999, 3:00:00 AM12/20/99
to
cwhardeman.vcf
0 new messages