Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

COBOL query: move space to 9(2)
Goto page 1, 2  Next
 
Post new topic   This topic is locked: you cannot edit posts or make replies.    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
halo_shankha

New User


Joined: 07 Nov 2007
Posts: 1
Location: KOLKATA

PostPosted: Thu Jan 17, 2008 3:45 pm    Post subject: COBOL query: move space to 9(2)
Reply with quote

Hi, can anyone tell what should be the supposed result if you move spaces into a numeric field.

I tried that and got zeroes in the numeric field.
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Jan 17, 2008 4:12 pm    Post subject:
Reply with quote

what does your datalayout look like? let us see your code.
Back to top
View user's profile Send private message
abhishekmdwivedi

New User


Joined: 22 Aug 2006
Posts: 95
Location: india

PostPosted: Thu Jan 17, 2008 4:17 pm    Post subject: Reply to: COBOL query: move space to 9(2)
Reply with quote

Quote:
I tried that and got zeroes in the numeric field.


Are you expecting anything else. Obviously the value will be zero.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu Jan 17, 2008 5:02 pm    Post subject: COBOL query: move space to 9(2)
Reply with quote

Use reference modification. The compiler will then treat your display-numeric field as alphanumeric. The field length is not necessary.

Code:

03  WS-NUMERIC PIC  9(02).

MOVE SPACES TO WS-NUMERIC (1:).


Regards,

Bill
Back to top
View user's profile Send private message
Phrzby Phil

Active Member


Joined: 31 Oct 2006
Posts: 961
Location: Richmond, Virginia

PostPosted: Thu Jan 17, 2008 6:17 pm    Post subject:
Reply with quote

There is always that obscure and rarely used feature REDEFINE.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Thu Jan 17, 2008 7:26 pm    Post subject:
Reply with quote

Just don't put your name to it. They may send a search and destroy team after you. icon_biggrin.gif
Back to top
View user's profile Send private message
Woe

New User


Joined: 03 Sep 2007
Posts: 2
Location: UK

PostPosted: Wed Mar 12, 2008 3:19 pm    Post subject:
Reply with quote

You will indeed get zeros.

As far as I understand it, on an IBM mainframe, using EBCDIC characters - the cobol compiler only moves the last 4 bits of a character when moving to a numeric field.

Imagine you wanted to move "1985" to a PIC 9(4) field.

"1985" is x"F1F9F8F5" - so COBOL ignores the first half of the byte ("F") and moves the second half.

What you are seeing is a result of <space> being x"40" (so drop the "4" and keep the "0").

Try it with "JZHE" (hex "D1E9C8C5")... you should still see 1985 in the numeric field (not tried this in about 15 years, so COBOL *may* trap it with a S0C7 now).
Back to top
View user's profile Send private message
sri_mf

Active User


Joined: 31 Aug 2006
Posts: 216
Location: India

PostPosted: Thu Mar 13, 2008 5:41 pm    Post subject: Re: COBOL query: move space to 9(2)
Reply with quote

Bill O'Boyle wrote:
Use reference modification. The compiler will then treat your display-numeric field as alphanumeric. The field length is not necessary.

Code:

03  WS-NUMERIC PIC  9(02).

MOVE SPACES TO WS-NUMERIC (1:).


Regards,

Bill

Bill,

Code:


01 WS-VAR1      PIC 9(02) VALUE 99.
MOVE 'BB'    TO WS-VAR1(1:).


For this code BB is moved to var1.Really amazing concept.
I did not heard abt this yet.
Can u expalin how this is considered and processed internally.
Back to top
View user's profile Send private message
dr_te_z

New User


Joined: 08 Jun 2007
Posts: 71
Location: Zoetermeer, the Netherlands

PostPosted: Thu Mar 13, 2008 7:40 pm    Post subject:
Reply with quote

mmwife wrote:
Just don't put your name to it. They may send a search and destroy team after you. icon_biggrin.gif
That's right! I volunteer for that posse!
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Thu Mar 13, 2008 9:55 pm    Post subject:
Reply with quote

Hello,

Quote:
Can u expalin how this is considered and processed internally
It is treated as a character move. And do not do this just because the compiler will allow it.

Quote:
That's right! I volunteer for that posse!
Me too. . . That posse should be allowed (or even encouraged) to inflict bodily harm on the perpetrator(s) icon_smile.gif

Yet another "thing" that can be done, but should not be permitted. And is not permitted most places and will be rejected during code review.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu Mar 13, 2008 10:06 pm    Post subject:
Reply with quote

Dick said
Quote:
Yet another "thing" that can be done, but should not be permitted. And is not permitted most places and will be rejected during code review.

Wow Dick, you actually work for a place that does code review? I've been pushing this where I'm at, but I get continually shot down. Too many "hissy" fits to deal with. icon_rolleyes.gif But, I'm over it.

Yes and as far as another thing that "can" be done, I would compare that with an "excercise" which "can" be done by male dogs. Why does he do that one would say? That's easy Watson, because he can! icon_wink.gif

Regards,

Bill
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Thu Mar 13, 2008 10:17 pm    Post subject:
Reply with quote

Hello,

Quote:
I would compare that with an "excercise" which "can" be done by male dogs.
Sexist. . . . icon_smile.gif

Quote:
Wow Dick, you actually work for a place that does code review?
I've been a migrant data worker (freelance sysadmin/database admin contractor) for a long, long time and many of "my sites" do code review - some also do not - especially with the rise in cross-platform processes. . .
Back to top
View user's profile Send private message
sri_mf

Active User


Joined: 31 Aug 2006
Posts: 216
Location: India

PostPosted: Fri Mar 14, 2008 6:26 pm    Post subject: Reply to: COBOL query: move space to 9(2)
Reply with quote

Thanks Dick..
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Fri Mar 14, 2008 9:33 pm    Post subject: Reply to: COBOL query: move space to 9(2)
Reply with quote

You're welcome icon_smile.gif

d
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1288
Location: Chennai, India

PostPosted: Sat Mar 15, 2008 12:26 am    Post subject: Reply to: COBOL query: move space to 9(2)
Reply with quote

Hi,

Quote:
Hi, can anyone tell what should be the supposed result if you move spaces into a numeric field.

I tried that and got zeroes in the numeric field.


Techies,

I have a doubt here. As per all your explanations we would have zeroes if we move SPACES to numeric field. But consider this scenario,

01 Group Variable
05 Elementary item 1 PIC 9(1)
05 Elementary item 2 PIC 9(1)
05 Elementary item 3 PIC 9(1)

As far as i know, group variables are always alphanumeric and hence if you initialize this Group variable we would have spaces in the 3 elementary items and not zeroes.

So is there any way to move zeroes to these elementary items other than moving zeroes to this gp variable?
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


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

PostPosted: Sat Mar 15, 2008 12:48 am    Post subject:
Reply with quote

INITIALIZE does it at the elementary item level! Please read the COBOL Language Reference.
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Sat Mar 15, 2008 4:13 am    Post subject:
Reply with quote

Hello,

Quote:
So is there any way to move zeroes to these elementary items other than moving zeroes to this gp variable
I believe INITIALIZE Group Variable will do what you want. I'm not connected so i've not tested this.
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Sat Mar 15, 2008 5:22 am    Post subject:
Reply with quote

Hi,

Yes, INITIALIZE 'Group Variable' will 'MOVE' zeros to all the elementry levels.
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1288
Location: Chennai, India

PostPosted: Sat Mar 15, 2008 7:16 am    Post subject: Reply to: COBOL query: move space to 9(2)
Reply with quote

Craq,

Quote:
INITIALIZE does it at the elementary item level! Please read the COBOL Language Reference


Even i had the similar beleif that INITIALIZE does it at the elementary item level. But today i tested a piece of code which behaved differently.

The Scenario is we had a group variable in a copybook with 40 elementary items PIC 9(1). We had initalized the copybook and i was under an assumption that all the elementary items would be initialized to zeroes. But to my surprise that didn't happen !

Those elementary items had spaces instead of zeroes. That made me post this question in this forum.
For time being we have fixed the issue by moving zeroes to the group variable.
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Sat Mar 15, 2008 7:28 am    Post subject:
Reply with quote

Hi,
Quote:
we had a group variable in a copybook with 40 elementary items PIC 9(1).
Does that copybook has same 'definition' of varaibles as shown by You in Your previous post or it differes? Show some contents of copybooks, might help better.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies.    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. How to move a long alphanumeric data ... lind sh COBOL Programming 8 Mon Dec 05, 2016 7:51 pm
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm
No new posts Two Selects in a single select query Rohit Umarjikar DB2 1 Fri Nov 04, 2016 8:46 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us