View previous topic :: View next topic
|
Author |
Message |
pecram24
New User
Joined: 12 Oct 2009 Posts: 35 Location: Chennai
|
|
|
|
Hi could anyone please help me on this..
What 'll happen while
Moving SPACES to a
COMP variable,
Signed Numeric S9(3),
Initializing
COMP variable,
Signed Numeric S9(3)
Thanks in advance |
|
Back to top |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
Hello pecram24,
Why dont you just tried both the case & get the result by urself? |
|
Back to top |
|
|
pecram24
New User
Joined: 12 Oct 2009 Posts: 35 Location: Chennai
|
|
|
|
I tried both the cases..
but i just wanted to know about in detail. That's the reason i am asking here... |
|
Back to top |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
What was the result? |
|
Back to top |
|
|
pecram24
New User
Joined: 12 Oct 2009 Posts: 35 Location: Chennai
|
|
|
|
While moving SPACES into a COMP variable the value of that variable becomes ZERO.
Even while initializing also the value of the COMP variable is ZERO.
But in case of S9(3)....
After moving SPACES& INITIALIZING, i am getting an error message saying that INVALID DECIMAL. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Which compiler are you using? My results are a compile error (as expected):
Code: |
01 WS-DATA.
05 WS-VAR1 PIC S9(03) COMP.
*
PROCEDURE DIVISION.
S1000-INITIALIZE.
MOVE SPACES TO WS-VAR1.
IGYPA3005-S "SPACES" and "WS-VAR1 (BINARY INTEGER)" did not follow the "MOVE"
statement compatibility rules. The statement was discarded.
DISPLAY 'SPACES ' WS-VAR1.
MOVE ZERO TO WS-VAR1.
DISPLAY 'ZERO ' WS-VAR1.
INITIALIZE WS-VAR1.
DISPLAY 'INITIALIZE ' WS-VAR1.
GOBACK. |
|
|
Back to top |
|
|
pecram24
New User
Joined: 12 Oct 2009 Posts: 35 Location: Chennai
|
|
|
|
@ Robert Sample ..
My question is something different....
You are using S9(3) COMP.. but my question is about S9(3) and
S9(9) COMP....
Could you please try for this ... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Regardless of what the compiler might permit, code should not move spaces to numeric fields. . . There is no good reason to do this.
Organizations with programmiing standards will not allow such code to be promoted. |
|
Back to top |
|
|
pecram24
New User
Joined: 12 Oct 2009 Posts: 35 Location: Chennai
|
|
|
|
I have one doubt here..
What the INITIALIZE verb 'll do..
my assumption is... it 'll move SPACES to the alphanumeric fields...and ZEROS to the numeric fields.....
but in my case it's not happening.. why like that |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hellol,
Quote: |
but in my case it's not happening.. why like that |
You need to post the variables that are being initialized, the initialize code and show the unwanted values that result.
At the top of the page is a link to "IBM Manualls". The first set is for COBOL. Look in the Language Reference for your level of cobol and read all of the specifics about INITIALIZE.
If you find something that is not clear,post what you found and your doubt about it. Someone will be able to clarify. |
|
Back to top |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
Robert Sample wrote: |
Which compiler are you using? My results are a compile error (as expected):
Code: |
01 WS-DATA.
05 WS-VAR1 PIC S9(03) COMP.
*
PROCEDURE DIVISION.
S1000-INITIALIZE.
MOVE SPACES TO WS-VAR1.
IGYPA3005-S "SPACES" and "WS-VAR1 (BINARY INTEGER)" did not follow the "MOVE"
statement compatibility rules. The statement was discarded.
DISPLAY 'SPACES ' WS-VAR1.
MOVE ZERO TO WS-VAR1.
DISPLAY 'ZERO ' WS-VAR1.
INITIALIZE WS-VAR1.
DISPLAY 'INITIALIZE ' WS-VAR1.
GOBACK. |
|
The compiler output tells you... The move SPACES instruction were discarded. You are displaying the initial storage contents in your working storage for the first display of WS-VAR1, and that is low values which is zero in a comp field.
If you manage to get 3 space characters into a S9(3) COMP mask you would get x'404040' which yields a value of 4.210.752. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
What 'll happen while
Moving SPACES to a
COMP variable,
Signed Numeric S9(3), |
If you MEANT two variables in your statement, why didn't you specify that they were different variables? If you cannot tell us precisely what your question is, how do you expect us to answer it correctly? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Robert,
you are being too harsh! As Marso so eloquently explained in this thread,
despite the fact that this is an english forum about an english documented machine,
we should read between the lines and determine what the user has meant, not what the user has said.
treating language literally is only for compilers, apparently. |
|
Back to top |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
Kjeld wrote: |
If you manage to get 3 space characters into a S9(3) COMP mask you would get x'404040' which yields a value of 4.210.752. |
...provided you are working on a EBCDIC system. On a ASCII system you will get x'202020', with the decimal equivalent 2.105.376 |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
On a ASCII system you will get x'202020', with the decimal equivalent 2.105.376 |
And which IBM mainframe are YOU working on that uses ASCII? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
we should read between the lines and determine what the user has meant, not what the user has said. |
Dick, I had a job one time where it was documented in my annual review that one of my tasks was to read programmer's minds. I never did get rated well on that aspect of the job. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
And, by the way, here's the code:
Code: |
05 WS-VAR1 PIC S9(03) COMP.
05 WS-VAR2 PIC S9(03) .
*
PROCEDURE DIVISION.
S1000-INITIALIZE.
MOVE SPACES TO WS-VAR1.
DISPLAY 'SPACES ' WS-VAR1.
MOVE ZERO TO WS-VAR1.
DISPLAY 'ZERO ' WS-VAR1.
INITIALIZE WS-VAR1.
DISPLAY 'INITIALIZE ' WS-VAR1.
MOVE SPACES TO WS-VAR2.
DISPLAY 'SPACES ' WS-VAR2.
MOVE ZERO TO WS-VAR2.
DISPLAY 'ZERO ' WS-VAR2.
INITIALIZE WS-VAR2.
DISPLAY 'INITIALIZE ' WS-VAR2. |
and here's the compiler output:
Code: |
S1000-INITIALIZE.
MOVE SPACES TO WS-VAR1.
IGYPA3005-S "SPACES" and "WS-VAR1 (BINARY INTEGER)" did not follow the "MOVE"
statement compatibility rules. The statement was discarded.
DISPLAY 'SPACES ' WS-VAR1.
MOVE ZERO TO WS-VAR1.
DISPLAY 'ZERO ' WS-VAR1.
INITIALIZE WS-VAR1.
DISPLAY 'INITIALIZE ' WS-VAR1.
MOVE SPACES TO WS-VAR2.
IGYPA3005-S "SPACES" and "WS-VAR2 (NUMERIC INTEGER)" did not follow the "MOVE"
statement compatibility rules. The statement was discarded.
DISPLAY 'SPACES ' WS-VAR2.
MOVE ZERO TO WS-VAR2.
DISPLAY 'ZERO ' WS-VAR2.
INITIALIZE WS-VAR2.
DISPLAY 'INITIALIZE ' WS-VAR2. |
Using COMP or not does not matter to the compiler -- moving SPACES to a numeric field is not allowed. |
|
Back to top |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
It was only because I read in another discussion that it would be a possibility if you were compiling for and executing the cobol code in a ASCII (UNIX?) system.
I have not seen an IBM mainframe that uses ASCII codepages, though. |
|
Back to top |
|
|
pecram24
New User
Joined: 12 Oct 2009 Posts: 35 Location: Chennai
|
|
|
|
Robert
Can u do me a favor..
Let's have both the variables under a group variable.. and try to move spaces to that group variable... and let me know what u are getting... because i didn't get error while doing compilation.... |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
pecram24 wrote: |
Robert
Can u do me a favor..
Let's have both the variables under a group variable.. and try to move spaces to that group variable... and let me know what u are getting... because i didn't get error while doing compilation.... |
Group moves are always alphanumeric! |
|
Back to top |
|
|
pecram24
New User
Joined: 12 Oct 2009 Posts: 35 Location: Chennai
|
|
|
|
what it means.. could you please elaborate your answer... |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Moving spaces to a group will always work because groups are always alphanumeric. And where in your original post did you state you were using a grouip?
Quote: |
Moving SPACES to a
COMP variable,
Signed Numeric S9(3), |
In fact, you specifically stated you were moving spaces to a COMP variable.
Perhaps if you fully and completely specified your question in the first place, you would have gotten an answer much faster. |
|
Back to top |
|
|
pecram24
New User
Joined: 12 Oct 2009 Posts: 35 Location: Chennai
|
|
|
|
okay...Thanks Robert for your help...
I didn't know about this.. (Group moves are always alphanumeric)....
anyway thanks a lot |
|
Back to top |
|
|
Ronald Burr
Active User
Joined: 22 Oct 2009 Posts: 293 Location: U.S.A.
|
|
|
|
You WOULD have known about that ( Group moves are always alphanumeric ) IF you had read the COBOL Language Reference Manual, where it explicitly says:
"A group move is treated as though it were an alphanumeric-to-alphanumeric elementary move, except that there is no conversion of data from one form of internal representation to another. In a group move, the receiving area is filled without consideration for the individual elementary items contained within either the sending area or the receiving area, except as noted in the OCCURS clause." |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
I didn't know about this.. (Group moves are always alphanumeric).... |
And now that you do know, do not move spaces to a group that contains numeric fields. . . |
|
Back to top |
|
|
|