IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

MOVE and INITIALIZE


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
pecram24

New User


Joined: 12 Oct 2009
Posts: 35
Location: Chennai

PostPosted: Thu Jan 21, 2010 3:50 pm
Reply with quote

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 icon_smile.gif
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Thu Jan 21, 2010 3:52 pm
Reply with quote

Hello pecram24,

Why dont you just tried both the case & get the result by urself?
Back to top
View user's profile Send private message
pecram24

New User


Joined: 12 Oct 2009
Posts: 35
Location: Chennai

PostPosted: Thu Jan 21, 2010 4:10 pm
Reply with quote

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
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Thu Jan 21, 2010 4:11 pm
Reply with quote

What was the result?
Back to top
View user's profile Send private message
pecram24

New User


Joined: 12 Oct 2009
Posts: 35
Location: Chennai

PostPosted: Thu Jan 21, 2010 4:18 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Jan 21, 2010 6:19 pm
Reply with quote

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
View user's profile Send private message
pecram24

New User


Joined: 12 Oct 2009
Posts: 35
Location: Chennai

PostPosted: Fri Jan 22, 2010 10:40 am
Reply with quote

@ 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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Jan 22, 2010 10:44 am
Reply with quote

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
View user's profile Send private message
pecram24

New User


Joined: 12 Oct 2009
Posts: 35
Location: Chennai

PostPosted: Fri Jan 22, 2010 11:17 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Jan 22, 2010 11:40 am
Reply with quote

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
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Fri Jan 22, 2010 4:11 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Jan 22, 2010 4:12 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jan 22, 2010 5:31 pm
Reply with quote

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
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Fri Jan 22, 2010 5:55 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Jan 22, 2010 6:07 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Jan 22, 2010 6:08 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Jan 22, 2010 6:14 pm
Reply with quote

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
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Fri Jan 22, 2010 6:27 pm
Reply with quote

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
View user's profile Send private message
pecram24

New User


Joined: 12 Oct 2009
Posts: 35
Location: Chennai

PostPosted: Fri Jan 22, 2010 6:27 pm
Reply with quote

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
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri Jan 22, 2010 6:32 pm
Reply with quote

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
View user's profile Send private message
pecram24

New User


Joined: 12 Oct 2009
Posts: 35
Location: Chennai

PostPosted: Fri Jan 22, 2010 6:38 pm
Reply with quote

what it means.. could you please elaborate your answer...
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Jan 22, 2010 6:42 pm
Reply with quote

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
View user's profile Send private message
pecram24

New User


Joined: 12 Oct 2009
Posts: 35
Location: Chennai

PostPosted: Fri Jan 22, 2010 6:45 pm
Reply with quote

okay...Thanks Robert for your help...
I didn't know about this.. (Group moves are always alphanumeric)....
anyway thanks a lot icon_smile.gif
Back to top
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Fri Jan 22, 2010 7:24 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Jan 22, 2010 10:00 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming Goto page 1, 2  Next

 


Similar Topics
Topic Forum Replies
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
No new posts How to move DB2 Installation HLQ DB2 4
No new posts How to move values from single dimens... COBOL Programming 1
No new posts Reading the CSV data in COBOL and mov... COBOL Programming 4
Search our Forums:

Back to Top