Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

MOVE COMP-3 TO DISPLAY.
COBOL Crew,

This code is broken because the non-integer move to alphanumeric is
illegal.
--------------------
01 ACOMP3 PIC 9999v9 COMP-3.
01 ADISPLAY PIC X(6).

MOVE 1234.5 to ACOMP3.
MOVE ACOMP3 TO ADISPLAY.
DISPLAY ADISPLAY.
-------------------

What are some options for me to change this code such that the output
of the "DISPLAY ADISPLAY" statement is "1234.5" with the constraint
that ACOMP3 and ADISPLAY must remain defined as they are?

I could come  up with some brute force way to do this, but I figure
one of you guys has to have a graceful way to do this.

--
Michael Potter

Report this thread to moderator Post Follow-up to this message
Old Post
pottmi
03-05-08 11:56 PM


Re: MOVE COMP-3 TO DISPLAY.

"pottmi" <pottmi@gmail.com> wrote in message
news:3417ff0f-baad-4cb9-9b24-f23079af4c18@c33g2000hsd.googlegroups.com...
> COBOL Crew,
>
> This code is broken because the non-integer move to alphanumeric is
> illegal.

No it isn't. The code is not broken and the move is not illegal. You can
move non-integer to Alphanumeric with no problem.

Your understanding may be "broken" :-)

It currently shows 12345b   ...where "b" is a blank, right?

> --------------------
> 01 ACOMP3 PIC 9999v9 COMP-3.
> 01 ADISPLAY PIC X(6).
>
> MOVE 1234.5 to ACOMP3.
> MOVE ACOMP3 TO ADISPLAY.
> DISPLAY ADISPLAY.
> -------------------
>
> What are some options for me to change this code such that the output
> of the "DISPLAY ADISPLAY" statement is "1234.5" with the constraint
> that ACOMP3 and ADISPLAY must remain defined as they are?


That seems to be a very unlikely thing to actually want to do (You could
simply move "1234.5" to ADISPLAY and display it to achieve what you stated
above...), so I have assumed that what you really want is a single decimal
place, preceded by a point, capable of handling various values:

01 ACOMP3 PIC 9999v9 COMP-3.
01 ADISPLAY PIC X(6).

... add two lines...
01 ADISPLAY-EDITED PIC z(4).9.
01 ADSTRING REDEFINES ADISPLAY-EDITED PIC X(6).
...
MOVE 1234.5 to ACOMP3.
MOVE ACOMP3 TO ADISPLAY-EDITED.
MOVE ADSTRING TO ADISPLAY.
DISPLAY ADISPLAY.

This will do what you require, within the constraints you specified.

REDEFINES is one of the most powerful features in COBOL.

Pete.
--
"I used to write COBOL...now I can do anything."




Report this thread to moderator Post Follow-up to this message
Old Post
Pete Dashwood
03-05-08 11:56 PM


Re: MOVE COMP-3 TO DISPLAY.
In article <3417ff0f-baad-4cb9-9b24-f23079af4c18@c33g2000hsd.googlegroups.co
m>,
pottmi  <pottmi@gmail.com> wrote:
>COBOL Crew,
>
>This code is broken because the non-integer move to alphanumeric is
>illegal.

Please do your own homework.

DD

Report this thread to moderator Post Follow-up to this message
Old Post

03-06-08 02:55 AM


Re: MOVE COMP-3 TO DISPLAY.
Pete,

Your suggestion worked.  thanks.  I did not know about using a period
in the picture clause, that was the trick that makes the redefines
graceful.

For the benefit of others, here is a cut and paste ready scrap of
code:
01  CONSTANTS.
02 ACOMP3 PIC 9(4)v9 COMP-3.
02 ADISPLAY PIC X(6).
02 ANUMERIC PIC Z(4).9.
02 ASTRING REDEFINES ANUMERIC PIC X(6).
*
PROCEDURE DIVISION.
FIRST-PARA.
MOVE 1234.5 TO ACOMP3.
*     MOVE ACOMP3 TO ADISPLAY.
*     DISPLAY ADISPLAY.

MOVE ACOMP3 TO ANUMERIC.
DISPLAY "ASTRING = " ASTRING.

STOP RUN.

The commented out MOVE statement produces this error on the latest
version of microfocus compiler:

pottmi@mikesuse:~/cobtst/moverule> cob moverule.cbl
20     MOVE ACOMP3 TO ADISPLAY.
*1029-
E***************************
**
**    A non-integer is being moved to an alphanumeric data item

Given that, can you clarify your statement that the MOVE is legal?

--
Michael Potter


On Mar 5, 6:48 pm, "Pete Dashwood"
<dashw...@removethis.enternet.co.nz> wrote:
> "pottmi" <pot...@gmail.com> wrote in message
>
> news:3417ff0f-baad-4cb9-9b24-f23079af4c18@c33g2000hsd.googlegroups.com...
> 
> 
>
> No it isn't. The code is not broken and the move is not illegal. You can
> move non-integer to Alphanumeric with no problem.
>
> Your understanding may be "broken" :-)
>
> It currently shows 12345b   ...where "b" is a blank, right?
> 
> 
> 
>
> That seems to be a very unlikely thing to actually want to do (You could
> simply move "1234.5" to ADISPLAY and display it to achieve what you stated
> above...), so I have assumed that what you really want is a single decimal
> place, preceded by a point, capable of handling various values:
>
>  01 ACOMP3 PIC 9999v9 COMP-3.
>  01 ADISPLAY PIC X(6).
>
> ... add two lines...
>  01 ADISPLAY-EDITED PIC z(4).9.
>  01 ADSTRING REDEFINES ADISPLAY-EDITED PIC X(6).
> ...
>  MOVE 1234.5 to ACOMP3.
> MOVE ACOMP3 TO ADISPLAY-EDITED.
> MOVE ADSTRING TO ADISPLAY.
> DISPLAY ADISPLAY.
>
> This will do what you require, within the constraints you specified.
>
> REDEFINES is one of the most powerful features in COBOL.
>
> Pete.
> --
> "I used to write COBOL...now I can do anything."


Report this thread to moderator Post Follow-up to this message
Old Post
pottmi
03-06-08 02:55 AM


Re: MOVE COMP-3 TO DISPLAY.
In article <638tbgF26nicjU1@mid.individual.net>, "Pete Dashwood" <dashwood@r
emovethis.enternet.co.nz> wrote:

> 01 ACOMP3 PIC 9999v9 COMP-3.
> 01 ADISPLAY PIC X(6).
>
>.... add two lines...
> 01 ADISPLAY-EDITED PIC z(4).9.
> 01 ADSTRING REDEFINES ADISPLAY-EDITED PIC X(6).
>....
> MOVE 1234.5 to ACOMP3.
>MOVE ACOMP3 TO ADISPLAY-EDITED.
>MOVE ADSTRING TO ADISPLAY.
>DISPLAY ADISPLAY.

Even simpler:

01 ADISPLAY.
03 ADISPLAY-EDITED PIC Z(4).9.
..
MOVE 1234.5 TO ACOMP3.
MOVE ACOMP3 TO ADISPLAY-EDITED.
DISPLAY ADISPLAY.

To the OP: even though this may not look like it, it *does* satisfy your
constraint that the definition of ADISPLAY remain unchanged, as all group
items are PIC X(n) by default, where n is the aggregate length of the
elementary items comprising the group. Since there is only one elementary it
em
(ADISPLAY-EDITED), and it's six characters long, the default picture of the
group item ADISPLAY is PIC X(6).

--
Regards,
Doug Miller (alphag at milmac dot com)

It's time to throw all their damned tea in the harbor again.

Report this thread to moderator Post Follow-up to this message
Old Post
Doug Miller
03-06-08 02:55 AM


Re: MOVE COMP-3 TO DISPLAY.
pottmi wrote:
> (snip)
>
> The commented out MOVE statement produces this error on the latest
> version of microfocus compiler:
>
> pottmi@mikesuse:~/cobtst/moverule> cob moverule.cbl
>     20     MOVE ACOMP3 TO ADISPLAY.
> *1029-
> E***************************
> **
> **    A non-integer is being moved to an alphanumeric data item
>
> Given that, can you clarify your statement that the MOVE is legal?

I really cannot speak for Pete Dashwood, but I am sure there are COBOL
compilers that allow the MOVE statement as written.  I think the
Fujitsu COBOL compiler might be one.  The question is, if a particular
COBOL compiler allows this kind of MOVE, what does it actually do?

There are versions of the IBM mainframe COBOL compiler that will
attempt a conversion from packed decimal to zoned decimal with this
kind of statement.  I can't recall if that includes the current
Enterprise COBOL for z/OS, but I'm pretty sure VS COBOL II did that,
and I was surprised when I discovered it.

I don't think there is anything in the COBOL standard that would
prevent a COBOL compiler from treating this as a move of one string of
characters to another, with no conversion, but perhaps Bill Klein can
give a definitive answer.

In my opinion, it's always a bad idea to move packed-decimal data to a
PIC X field, and I would always prefer a more explicit data
conversion, such as Pete suggested.  So I don't think there's anything
wrong with MicroFocus disallowing that MOVE statement.

Cheers,


--
http://arnold.trembley.home.att.net/

Report this thread to moderator Post Follow-up to this message
Old Post
Arnold Trembley
03-06-08 08:55 AM


Re: MOVE COMP-3 TO DISPLAY.
On Wed, 5 Mar 2008 16:00:26 -0800 (PST), pottmi <pottmi@gmail.com>
wrote:

>COBOL Crew,
>
>This code is broken because the non-integer move to alphanumeric is
>illegal.
>--------------------
>01 ACOMP3 PIC 9999v9 COMP-3.
>01 ADISPLAY PIC X(6).
>
>MOVE 1234.5 to ACOMP3.
>MOVE ACOMP3 TO ADISPLAY.
>DISPLAY ADISPLAY.
>-------------------

Most compilers I've used allow simple displays of the packed data. I'm
trying to remember the syntax of the compiler that required a
conversion in the display.   Something like DISPLAY ACOMP3 WITH
CONVERSION.

I routinely add some fields such as:
D01  DISPLAY-FIELDS.
D    05  DISPLAY-NDX         PIC 9(05).
D    05  DISPLAY-SORT        PIC Z(05).
D    05  DISPLAY-AMT1        PIC ++,+++,+++.99.
D    05  DISPLAY-AMT2        PIC ++,+++,+++.99.

Before I display most numbers, I move it here to see it better.
D    MOVE AMOUNT-INDEX     TO DISPLAY-NDX
D    MOVE MY-AMOUNT (AMOUNT-INDEX)      TO DISPLAY-AMT1
D    DISPLAY 'DEBUG 01 - MY-AMOUNT (' DISPLAY-INDEX ')="'
D        DISPLAY-AMT1 '"'.

Report this thread to moderator Post Follow-up to this message
Old Post
Howard Brazee
03-06-08 11:55 PM


Re: MOVE COMP-3 TO DISPLAY.

"pottmi" <pottmi@gmail.com> wrote in message
news:2d29289d-7596-46fb-a216-766e7f695e23@c33g2000hsd.googlegroups.com...
> Pete,
>
> Your suggestion worked.  thanks.  I did not know about using a period
> in the picture clause, that was the trick that makes the redefines
> graceful.
>
No problem, glad to help.

This is called an "insertion" edit character. You can use a few other things
as well, depending on which compiler you are using.

> For the benefit of others, here is a cut and paste ready scrap of
> code:
>       01  CONSTANTS.
>           02 ACOMP3 PIC 9(4)v9 COMP-3.
>           02 ADISPLAY PIC X(6).
>           02 ANUMERIC PIC Z(4).9.
>           02 ASTRING REDEFINES ANUMERIC PIC X(6).
>      *
>       PROCEDURE DIVISION.
>       FIRST-PARA.
>           MOVE 1234.5 TO ACOMP3.
>      *     MOVE ACOMP3 TO ADISPLAY.
>      *     DISPLAY ADISPLAY.
>
>           MOVE ACOMP3 TO ANUMERIC.
>           DISPLAY "ASTRING = " ASTRING.
>
>           STOP RUN.
>
> The commented out MOVE statement produces this error on the latest
> version of microfocus compiler:
>
> pottmi@mikesuse:~/cobtst/moverule> cob moverule.cbl
>    20     MOVE ACOMP3 TO ADISPLAY.
> *1029-
> E***************************
> **
> **    A non-integer is being moved to an alphanumeric data item
>
> Given that, can you clarify your statement that the MOVE is legal?
>

It certainly looks like it ISN'T legal on MicroFocus. Sorry, I didn't know
that.  I use Fujitsu, and, although I haven't tried it, I would expect it to
work.  I would expect to be able to move ANYTHING to an AN receiving field
and find it left justifed in that field. (Maybe MY understanding is
broken... :-))

What the standard actually allows would be the domain of other posters here.
(I'm sure Bill Klein or Rick Smith can tell us what the current standard
allows and what the 2002 (yet to be implemented) standard proposes.)

I think Doug Miller's use of COBOL's implicit hierarchic structure is an
improvement over what I posted, and I think that what Arnold Trembley had to
say is worth noting.

You actually got pretty good value for your assistance request... :-)

Pete.
--
"I used to write COBOL...now I can do anything."



Report this thread to moderator Post Follow-up to this message
Old Post
Pete Dashwood
03-06-08 11:55 PM


Re: MOVE COMP-3 TO DISPLAY.
"Pete Dashwood" <dashwood@removethis.enternet.co.nz> wrote in message
news:63b5e8F274l7vU1@mid.individual.net...
>
>
> "pottmi" <pottmi@gmail.com> wrote in message
> news:2d29289d-7596-46fb-a216-766e7f695e23@c33g2000hsd.googlegroups.com... 
> No problem, glad to help.
>
> This is called an "insertion" edit character. You can use a few other
things
> as well, depending on which compiler you are using.
> 
>
> It certainly looks like it ISN'T legal on MicroFocus. Sorry, I didn't know
> that.  I use Fujitsu, and, although I haven't tried it, I would expect it
to
> work.  I would expect to be able to move ANYTHING to an AN receiving field
> and find it left justifed in that field. (Maybe MY understanding is
> broken... :-))
>
> What the standard actually allows would be the domain of other posters
here.
> (I'm sure Bill Klein or Rick Smith can tell us what the current standard
> allows and what the 2002 (yet to be implemented) standard proposes.)

1. The current standard is the 2002 standard. <g>
2. Behavior with COMP-3 is not defined in any COBOL standard.
3. Moving noninteger to alphanumeric is not a valid move in 2002
(MOVE statement SR8); nor was it valid, as nearly as I can tell,
in 85, 74, or 68.



Report this thread to moderator Post Follow-up to this message
Old Post
Rick Smith
03-06-08 11:55 PM


Re: MOVE COMP-3 TO DISPLAY.

"Rick Smith" <ricksmith@mfi.net> wrote in message
news:13t13ek62h28bad@corp.supernews.com...
>
> "Pete Dashwood" <dashwood@removethis.enternet.co.nz> wrote in message
> news:63b5e8F274l7vU1@mid.individual.net... 
> things 
> to 
> here. 
>
> 1. The current standard is the 2002 standard. <g>
> 2. Behavior with COMP-3 is not defined in any COBOL standard.
> 3. Moving noninteger to alphanumeric is not a valid move in 2002
>    (MOVE statement SR8); nor was it valid, as nearly as I can tell,
>    in 85, 74, or 68.
>

Thanks Rick. I stand corrected, and learned something... :-)

Pete.
--
"I used to write COBOL...now I can do anything."
>



Report this thread to moderator Post Follow-up to this message
Old Post
Pete Dashwood
03-07-08 08:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Cobol archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 08:13 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.