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
 

 

Can we move Character field to numeric field
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Can we move Character field to numeric field
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    Post subject:
Reply with quote

Answer to both questions is YES...

look at this thread

http://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    Post subject:
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: 7913
Location: Bellevue, IA

PostPosted: Mon Aug 22, 2011 5:16 pm    Post subject:
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

Active Member


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

PostPosted: Mon Aug 22, 2011 5:42 pm    Post subject:
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    Post subject:
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    Post subject:
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: 7913
Location: Bellevue, IA

PostPosted: Mon Aug 22, 2011 6:34 pm    Post subject:
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    Post subject:
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    Post subject:
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: 7913
Location: Bellevue, IA

PostPosted: Mon Aug 22, 2011 6:39 pm    Post subject:
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    Post subject:
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: 7913
Location: Bellevue, IA

PostPosted: Mon Aug 22, 2011 7:10 pm    Post subject:
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    Post subject:
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: 1738
Location: Bloomington, IL

PostPosted: Mon Aug 22, 2011 7:41 pm    Post subject:
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: 7913
Location: Bellevue, IA

PostPosted: Mon Aug 22, 2011 7:55 pm    Post subject:
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    Post subject:
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    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Tue Aug 23, 2011 1:16 am    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Thu Aug 25, 2011 12:35 am    Post subject:
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
View previous topic :: :: View next topic  
Post new topic   Reply to topic    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
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 24 Tue Dec 06, 2016 8:04 pm
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
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm


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