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

Moving values upto 32767 to S9(04) COMP


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
ibmmainframes.com/about19542.html

Cheers,
Rarvins
Back to top
View user's profile Send private message
jasorn
Warnings : 1

Active User


Joined: 12 Jul 2006
Posts: 191
Location: USA

PostPosted: Tue Apr 03, 2007 12:26 pm
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
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
Warnings : 1

Active User


Joined: 12 Jul 2006
Posts: 191
Location: USA

PostPosted: Tue Apr 03, 2007 1:51 pm
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
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
Warnings : 1

Active User


Joined: 12 Jul 2006
Posts: 191
Location: USA

PostPosted: Tue Apr 03, 2007 4:18 pm
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: 691
Location: Earth

PostPosted: Tue Apr 03, 2007 4:32 pm
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: 691
Location: Earth

PostPosted: Tue Apr 03, 2007 4:46 pm
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

Moderator Emeritus


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

PostPosted: Tue Apr 03, 2007 10:31 pm
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
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
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

Moderator Emeritus


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

PostPosted: Wed Apr 18, 2007 2:29 am
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Null values are considered in Total c... DFSORT/ICETOOL 6
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Moving Or setting POINTER to another ... COBOL Programming 2
Search our Forums:

Back to Top