View previous topic :: View next topic
|
Author |
Message |
rarvins
New User
Joined: 24 Jan 2007 Posts: 59 Location: Texas
|
|
|
|
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 |
|
|
jasorn Warnings : 1 Active User
Joined: 12 Jul 2006 Posts: 191 Location: USA
|
|
|
|
If you want 5 decimal places you need to increase (04). Since the field is comp, you should go to (09). |
|
Back to top |
|
|
rarvins
New User
Joined: 24 Jan 2007 Posts: 59 Location: Texas
|
|
|
|
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 |
|
|
jasorn Warnings : 1 Active User
Joined: 12 Jul 2006 Posts: 191 Location: USA
|
|
|
|
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 |
|
|
rarvins
New User
Joined: 24 Jan 2007 Posts: 59 Location: Texas
|
|
|
|
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 |
|
|
jasorn Warnings : 1 Active User
Joined: 12 Jul 2006 Posts: 191 Location: USA
|
|
|
|
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:
What version of cobol are you using? |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
rarvins,
Could you please post part of actual code please? or is it same as jsorn posted?
I am getting correct o/p here. |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Got little something!
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. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Mickeydusaor
Active User
Joined: 24 May 2006 Posts: 258 Location: Salem, Oregon
|
|
|
|
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 |
|
|
RainbowUser
New User
Joined: 13 Apr 2007 Posts: 1 Location: Chennai
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
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 |
|
|
|