Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Moving values upto 32767 to S9(04) COMP

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
rarvins

New User


Joined: 24 Jan 2007
Posts: 59
Location: Texas

PostPosted: Tue Apr 03, 2007 12:20 pm    Post subject: Moving values upto 32767 to S9(04) COMP
Reply with quote

Hi,

I would like to know how I can move a 5 digit value upto +32767 to an
S9(04) COMP variable in COBOL.This is because S9(04) COMP is the declaration given by DCLGEN for a SMALLINT column in DB2.A SMALLINT in DB2 can hold upto +32767.But when I move any 5 digit say 27797 to this S9(04) host variable in COBOL the left most digit gets truncated and only 7797 is present in the variable.But when I edit using fielaid I am able to enter 27797 into the variable.

Can somebody help me as to how I can move a 5 digit value upto +32767 to an S9(04) COMP variable in COBOL without any truncation

This is my previous post
http://ibmmainframes.com/about19542.html

Cheers,
Rarvins
Back to top
View user's profile Send private message

jasorn

Active User


Joined: 12 Jul 2006
Posts: 154
Location: USA

PostPosted: Tue Apr 03, 2007 12:26 pm    Post subject: The (04) means you only have 4 digits. You should use (09).
Reply with quote

If you want 5 decimal places you need to increase (04). Since the field is comp, you should go to (09).
Back to top
View user's profile Send private message
rarvins

New User


Joined: 24 Jan 2007
Posts: 59
Location: Texas

PostPosted: Tue Apr 03, 2007 12:41 pm    Post subject: Re: Moving values upto 32767 to S9(04) COMP
Reply with quote

I can change the datatype of the variable to S9(09) COMP , but the problem is that it becomes an integer.Since this is the DCLGEN given host variable for a DB2 column SMALLINT, I cannot modify it to an integer.My major doubt is that If I edit the file using fileaid and enter the same 5 digit number 27797, then it accepts.But when I issue a simple move statement in COBOL it doesnt...

So I want to know if there is a way out in COBOL itself.
Even if not directly in COBOL, is it possible by calling any other tool (like fileaid) from the COBOL program
Back to top
View user's profile Send private message
jasorn

Active User


Joined: 12 Jul 2006
Posts: 154
Location: USA

PostPosted: Tue Apr 03, 2007 1:51 pm    Post subject: Re: The (04) means you only have 4 digits. You should use (
Reply with quote

jasorn wrote:
If you want 5 decimal places you need to increase (04). Since the field is comp, you should go to (09).


Err, I'm a moron.

I answered this at 3 in the morning when I was awaken by an upset stomach. I Anyway, pic s9(4) comp is the proper cobol definition for smallint. The 4 doesn't represent the number of decimal places for comp fields.

Now that I'm awake my suspicion is that you're moving it to just pic s9(04) instead of pic s(94) comp. For instance, this program:
Code:

IDENTIFICATION DIVISION.                                         
PROGRAM-ID. TEST01.                                             
DATA DIVISION.                                                   
WORKING-STORAGE SECTION.                                         
01  FILLER.                                                     
    05 WS-PICS9-4-COMP      PIC S9(4) COMP.                     
    05 WS-PICS9-4           PIC 9(5).                           
PROCEDURE DIVISION.                                             
    COMPUTE WS-PICS9-4-COMP = +32767                             
    COMPUTE WS-PICS9-4      = WS-PICS9-4-COMP                   
    DISPLAY 'WS-PICS9-4: ' WS-PICS9-4                                           
    CONTINUE.                                                   
    GOBACK.                                                     

gives:
Code:

Command ===>                 
****** **********************
000001  WS-PICS9-4: 32767   
****** **********************
Back to top
View user's profile Send private message
rarvins

New User


Joined: 24 Jan 2007
Posts: 59
Location: Texas

PostPosted: Tue Apr 03, 2007 2:58 pm    Post subject:
Reply with quote

jasorn,
I am using S9(04) COMP and not S9(04) alone
I tried the same piece of code but this is the output that I got

02767
Back to top
View user's profile Send private message
jasorn

Active User


Joined: 12 Jul 2006
Posts: 154
Location: USA

PostPosted: Tue Apr 03, 2007 4:18 pm    Post subject:
Reply with quote

Hmmm. Don't know what the problem might be. This works as expected for me on the mainframe. However, if I run that same code on the pc with opencobol, I get different results:

Code:

WS-PICS9-4: 00000


What version of cobol are you using?
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 686
Location: Earth

PostPosted: Tue Apr 03, 2007 4:32 pm    Post subject:
Reply with quote

rarvins,
Could you please post part of actual code please? or is it same as jsorn posted? icon_confused.gif

I am getting correct o/p here.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 686
Location: Earth

PostPosted: Tue Apr 03, 2007 4:46 pm    Post subject:
Reply with quote

Got little something! icon_biggrin.gif
See your compiler options:
TRUNC(STD)
If you use STD then you will face truncation. As you are getting.
TRUNC(OPT)
Then you will not face truncation (as I am compiling with this option.)

Compile your program with TRUNC(OPT) option. ( may differ from compiler to compiler, see manual of the one which you are using. )
let us know your feedback. icon_smile.gif
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: Tue Apr 03, 2007 10:31 pm    Post subject:
Reply with quote

Hello,

Do keep in mind that all 5-digit values will not fit into the s9(4) comp field. . . If you check the value before moving it into the field, you should be ok.

If this program is compiled with other than your site's standard compiler options, please be sure to include that info in the remarks in the program. Someone who comes along later may have no idea that their "standard" re-compile caused the code to stop working properly. With luck, it will cause something to abend right away. If not, there will be corruption that may be quite difficult to trace back.
Back to top
View user's profile Send private message
Mickeydusaor

Active User


Joined: 24 May 2006
Posts: 258
Location: Salem, Oregon

PostPosted: Wed Apr 04, 2007 2:53 am    Post subject:
Reply with quote

What version of COBOL are you using.?? Try changing your
S9(04) COMP TO S9(04) COMP-5. This will retain the actual
field size without any truncation. The field will hold your 32K
data.
Back to top
View user's profile Send private message
RainbowUser

New User


Joined: 13 Apr 2007
Posts: 1
Location: Chennai

PostPosted: Tue Apr 17, 2007 5:56 pm    Post subject:
Reply with quote

Hey,
Recently I had the same problem. Coding was good but i was not getting the higher order bit value in the output file. Later I found that the problem was with compilation. Set the compiler option as TRUNC(BIN) and that will resolve the problem.

Thanks
Rainbow
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: Wed Apr 18, 2007 2:29 am    Post subject:
Reply with quote

Hello,

To repeat - if you must deviate from the site-standard compile(s):

Quote:
If this program is compiled with other than your site's standard compiler options, please be sure to include that info in the remarks in the program. Someone who comes along later may have no idea that their "standard" re-compile caused the code to stop working properly. With luck, it will cause something to abend right away. If not, there will be corruption that may be quite difficult to trace back.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Wed Apr 18, 2007 7:05 am    Post subject:
Reply with quote

Dick has a good point re. documentation. I usually do it this way:
Code:

       CBL TRUNC(BIN)
       IDENTIFICATION DIVISION.
       PROGRAM-ID.    FIXPKDDT.

This way you always get the right TRUNC and it becomes part of the code.
With this, PIC S9(4) COMP should allow you to store +/-32767.
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
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Extend the decimal values in DIVISION Balaryan DFSORT/ICETOOL 3 Thu Oct 05, 2017 4:05 pm
No new posts Moving UDB database to Db2 on z/OS Keith Hooley DB2 4 Wed Sep 27, 2017 12:38 am
No new posts Working with hex values in Filemanage... Emile Straker IBM Tools 0 Tue Sep 12, 2017 1:42 am
No new posts DB2 NULL Values display V S Amarendra Reddy DB2 3 Thu Sep 07, 2017 6:59 pm
No new posts Moving values to a variable of copybo... Vignesh Sid COBOL Programming 6 Wed Sep 06, 2017 1:04 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us