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

Can we move Character field to numeric field


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

New User


Joined: 22 Feb 2011
Posts: 19
Location: india

PostPosted: Mon Aug 22, 2011 3:27 pm
Reply with quote

Hi,

I have two variables :

03 WS-APPID S9(4) COMP.
03 WS-JZ-APPID X(4).


Can i move WS-JZ-APPID to WS-APPID ??

If yes, Can I use WS-APPID further in my program.
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Mon Aug 22, 2011 3:32 pm
Reply with quote

Answer to both questions is YES...

look at this thread

ibmmainframes.com/viewtopic.php?t=27830&highlight=numval
Back to top
View user's profile Send private message
Khushboo.goel

New User


Joined: 22 Feb 2011
Posts: 19
Location: india

PostPosted: Mon Aug 22, 2011 4:27 pm
Reply with quote

Hi Escapa,

Thanks for your reply..
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: Mon Aug 22, 2011 5:16 pm
Reply with quote

Khushboo.goel, be aware that you are moving a 4-byte alphanumeric variable to a 2-byte numeric variable. The MOVE will happen, but the results might not be what you think they are, and using WS-APPID in your program certainly will not be using anything like WS-JZ-APPID. For example, if WS-JZ-APPID is 'ABCD', then WS-APPID will be 49602 (or 9602 depending upon your compiler options).
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


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

PostPosted: Mon Aug 22, 2011 5:42 pm
Reply with quote

A bit lazy and incurious, eh?

Couldn't you just try and see what you get? You would need to view the results in hex of course.

Your way, if anyone asks you the same question, you'll say YES, and when they ask why it works, you can only answer: someone I don't know said so. That'll look good on your annual review.
Back to top
View user's profile Send private message
Khushboo.goel

New User


Joined: 22 Feb 2011
Posts: 19
Location: india

PostPosted: Mon Aug 22, 2011 6:20 pm
Reply with quote

Hi Robert,

Thanks for your reply.

The scenario is i have to move a 2 byte data (example 11) to WS-JZ-APPID where first two bytes will be 00..
i.e. the data in WS-JZ-APPID will be like 0012 (its x(4) )

I have to then move it WS-APPID S9(4) COMP

I have to use WS-APPID further in my program for computation.
How should I be doing this? should i use NUMVAL?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Aug 22, 2011 6:30 pm
Reply with quote

first you want to see
IF WS-JZ-APPID IS NUMERIC
and if true,
then
COMPUTE WS-APPID = FUNCTION NUMVAL(WS-JZ-APPID) END-COMPUTE.

Here are the Rules for using NUMVAL

RTFM.

and if you are working with COBOL II,
here is the COBOL II Reference
and this is the Application Programmers' Guide
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: Mon Aug 22, 2011 6:34 pm
Reply with quote

As long as WS-IZ-APPID contains numeric digits, the MOVE will be okay. However, you had better verify that it contains nothing but numeric digits before you do the move, or you may get a S0C7 abend in your code. The NUMVAL function isn't really required, although it might not hurt to make clearer to whoever maintains this code in later years what is going on.
Back to top
View user's profile Send private message
Khushboo.goel

New User


Joined: 22 Feb 2011
Posts: 19
Location: india

PostPosted: Mon Aug 22, 2011 6:35 pm
Reply with quote

can i also do like this??


WS-TEMP PIC S9(4)

MOVE WS-JZ-APPID to WS-TEMP
MOVE WS-TEMP to WS-APPID

will this work?
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Mon Aug 22, 2011 6:38 pm
Reply with quote

Khushboo.goel wrote:
can i also do like this??


WS-TEMP PIC S9(4)

MOVE WS-JZ-APPID to WS-TEMP
MOVE WS-TEMP to WS-APPID

will this work?


WHY CAN'T YOU TRY... icon_evil.gif icon_question.gif icon_evil.gif icon_evil.gif
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: Mon Aug 22, 2011 6:39 pm
Reply with quote

Doing your own testing will provide you much better insight than me writing the test.
Back to top
View user's profile Send private message
Khushboo.goel

New User


Joined: 22 Feb 2011
Posts: 19
Location: india

PostPosted: Mon Aug 22, 2011 6:42 pm
Reply with quote

Sorry to nag.. but currently, i cant run the code and just have to complete the code :'(
So, i was asking for your opinion..

It would be great if anyone can help me out...
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: Mon Aug 22, 2011 7:10 pm
Reply with quote

Quote:
i cant run the code and just have to complete the code :'(
This makes absolutely no sense -- either you can compile and test the code, or you cannot. If you cannot compile and test the code why are you attempting to write it?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Aug 22, 2011 7:20 pm
Reply with quote

Quote:
If you cannot compile and test the code why are you attempting to write it?


New maangement process Robert:
someone who can't code
instead does the pseudo code for the coder.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Mon Aug 22, 2011 7:41 pm
Reply with quote

dbzTHEdinosauer wrote:
Quote:
If you cannot compile and test the code why are you attempting to write it?


New maangement process Robert:
someone who can't code
instead does the pseudo code for the coder.

Everything old is new again; remember the programmer/coder distinction from the 1960s?
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: Mon Aug 22, 2011 7:55 pm
Reply with quote

Quote:
Everything old is new again; remember the programmer/coder distinction from the 1960s?
And turning keypunch sheets over to the keypunch operator -- hoping your writing was clear enough!
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Aug 22, 2011 8:01 pm
Reply with quote

Quote:
And turning keypunch sheets over to the keypunch operator -


ah, those were the days.

quick 'card shuffle' of some asshole's just punched card-deck
was always refreshing.

I started in an NCR shop, the cobol did not have a SORT,
so you either manually resorted your card deck
or hoped no one was using the card-sorter.

which during the day was intentially busy to really 'teach' the assholes a lessen.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Aug 22, 2011 9:29 pm
Reply with quote

yeah, yeah, yeah, i failed to mention that I often found my decks 'shuffled'
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Aug 23, 2011 1:16 am
Reply with quote

Khushboo.goel wrote:
can i also do like this??


WS-TEMP PIC S9(4)

MOVE WS-JZ-APPID to WS-TEMP
MOVE WS-TEMP to WS-APPID

will this work?


Late to the party on this.

Is WS-JZ-APPID supposed to be always numeric?

If yes, test that it is NUMERIC, do something reasonable (find out what from the spec writer) if it isn't then you can proceed as you coded above.

Any problem, as an alternative, with making WS-JC-APPID PIC 9(4)? Then you can ditch the WS-TEMP.

Now, where are the crackers? A little something for a parched throat? Ah, yes, I see...
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Aug 25, 2011 12:35 am
Reply with quote

Robert Sample wrote:
And turning keypunch sheets over to the keypunch operator -- hoping your writing was clear enough!


We finished our Cobol/JCL (DOS) training. We didn't know how to use a terminal (and they were shared, as well). So our "end of course" program was to be written on coding sheets, and off to "data-entry". My "program" came back with every 2 a Z and every Z a 2.
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 Aug 25, 2011 9:30 am
Reply with quote

Hello,

Quote:
I often found my decks 'shuffled'
Which was the reason for the diagonal stripe on the top of the card deck. . . At my first place, this was also know as floor-sorting ('cause sometimes an entire tray or 2 of cards got tipped over) icon_confused.gif

Quote:
We didn't know how to use a terminal (and they were shared, as well).
Terminal - we didn' have no steenkin terminal.

Quote:
My "program" came back with every 2 a Z and every Z a 2.
Remember the black/red automatic pencils (black on one end, red on the other)? Not only did things get mis-keyed, but it took much longer to write carefully than if one keyed their own . . .

Those were the days. . . Maybe not icon_wink.gif
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

 


Similar Topics
Topic Forum Replies
No new posts Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Join 2 files according to one key field. JCL & VSAM 3
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
Search our Forums:

Back to Top