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

COBOL query: move space to 9(2)


IBM Mainframe Forums -> COBOL Programming
Post new topic   This topic is locked: you cannot edit posts or make replies.
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
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
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Jan 17, 2008 5:02 pm
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

Senior Member


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

PostPosted: Thu Jan 17, 2008 6:17 pm
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
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
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: 218
Location: India

PostPosted: Thu Mar 13, 2008 5:41 pm
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
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

Moderator Emeritus


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

PostPosted: Thu Mar 13, 2008 9:55 pm
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Mar 13, 2008 10:06 pm
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

Moderator Emeritus


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

PostPosted: Thu Mar 13, 2008 10:17 pm
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: 218
Location: India

PostPosted: Fri Mar 14, 2008 6:26 pm
Reply with quote

Thanks Dick..
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 Mar 14, 2008 9:33 pm
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: 1287
Location: Chennai, India

PostPosted: Sat Mar 15, 2008 12:26 am
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
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

Moderator Emeritus


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

PostPosted: Sat Mar 15, 2008 4:13 am
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

Superior Member


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

PostPosted: Sat Mar 15, 2008 5:22 am
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: 1287
Location: Chennai, India

PostPosted: Sat Mar 15, 2008 7:16 am
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

Superior Member


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

PostPosted: Sat Mar 15, 2008 7:28 am
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
Craq Giegerich

Senior Member


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

PostPosted: Sat Mar 15, 2008 7:55 am
Reply with quote

Initialize uses the first definition of an item if the the item is redefined.
Back to top
View user's profile Send private message
Aaru

Senior Member


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

PostPosted: Sun Mar 16, 2008 3:54 am
Reply with quote

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

Superior Member


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

PostPosted: Sun Mar 16, 2008 4:46 am
Reply with quote

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

New User


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

PostPosted: Mon Mar 17, 2008 7:03 pm
Reply with quote

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

Active User


Joined: 31 Aug 2006
Posts: 218
Location: India

PostPosted: Tue Mar 18, 2008 6:11 pm
Reply with quote

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
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. View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top