View previous topic :: View next topic
|
Author |
Message |
halo_shankha
New User
Joined: 07 Nov 2007 Posts: 1 Location: KOLKATA
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
what does your datalayout look like? let us see your code. |
|
Back to top |
|
|
abhishekmdwivedi
New User
Joined: 22 Aug 2006 Posts: 95 Location: india
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
There is always that obscure and rarely used feature REDEFINE. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Just don't put your name to it. They may send a search and destroy team after you. |
|
Back to top |
|
|
Woe
New User
Joined: 03 Sep 2007 Posts: 2 Location: UK
|
|
|
|
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 |
|
|
sri_mf
Active User
Joined: 31 Aug 2006 Posts: 218 Location: India
|
|
|
|
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 |
|
|
dr_te_z
New User
Joined: 08 Jun 2007 Posts: 71 Location: Zoetermeer, the Netherlands
|
|
|
|
mmwife wrote: |
Just don't put your name to it. They may send a search and destroy team after you. |
That's right! I volunteer for that posse! |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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)
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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. 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!
Regards,
Bill |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
I would compare that with an "excercise" which "can" be done by male dogs. |
Sexist. . . .
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 |
|
|
sri_mf
Active User
Joined: 31 Aug 2006 Posts: 218 Location: India
|
|
|
|
Thanks Dick.. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
You're welcome
d |
|
Back to top |
|
|
Aaru
Senior Member
Joined: 03 Jul 2007 Posts: 1287 Location: Chennai, India
|
|
|
|
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 |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
INITIALIZE does it at the elementary item level! Please read the COBOL Language Reference. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Hi,
Yes, INITIALIZE 'Group Variable' will 'MOVE' zeros to all the elementry levels. |
|
Back to top |
|
|
Aaru
Senior Member
Joined: 03 Jul 2007 Posts: 1287 Location: Chennai, India
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
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 |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Initialize uses the first definition of an item if the the item is redefined. |
|
Back to top |
|
|
Aaru
Senior Member
Joined: 03 Jul 2007 Posts: 1287 Location: Chennai, India
|
|
|
|
Craq,
Interesting, Will have to check whether my group variable is redefined and whether the first defnition is alphanumeric.
Anuj,
The definition in my first post is just an example and not actually how my copybook looks. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Hi,
Yes
Quote: |
Initialize uses the first definition of an item if the the item is redefined. |
once a memory is "masked" with some definition, we can 'resue' it with that definition only. You re-define the variables not the memory. |
|
Back to top |
|
|
dr_te_z
New User
Joined: 08 Jun 2007 Posts: 71 Location: Zoetermeer, the Netherlands
|
|
|
|
INITIALIZE ignores FILLER's. So to be sure I code both:
Code: |
MOVE SPACE TO FOO-GR
INITIALIZE FOO-GR REPLACING NUMERIC DATA BY ZERO
|
|
|
Back to top |
|
|
sri_mf
Active User
Joined: 31 Aug 2006 Posts: 218 Location: India
|
|
|
|
Aaru wrote: |
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? |
Code: |
Aaru i tried this and i think it may help u.
01 WS-VARIABLE.
05 WS-ITEM1 PIC 9(1).
05 WS-ITEM2 PIC 9(1).
05 WS-ITEM3 PIC 9(1).
INITIALIZE WS-VARIABLE.
DISPLAY 'WS-VARIABLE :' WS-VARIABLE.
DISPLAY 'WS-ITEM1 :' WS-ITEM1.
DISPLAY 'WS-ITEM2 :' WS-ITEM2.
DISPLAY 'WS-ITEM3 :' WS-ITEM3.
Here is the SYSOUT i got.
WS-VARIABLE :000
WS-ITEM1 :0
WS-ITEM2 :0
WS-ITEM3 :0
|
|
|
Back to top |
|
|
|