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
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."
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)
: 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)
--
You can do your own homewlrk... please.
DD
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
webmaster wrote in message <3820885E...@eii.fr>...
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.
: 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).
--
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..
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
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
==============================================
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...
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
--
==============================================
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).
>> >
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...
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 ?
> >