View previous topic :: View next topic
|
Author |
Message |
Rahul_kumar Warnings : 2 New User
Joined: 24 Jun 2006 Posts: 50
|
|
|
|
Hi ,
I need to convert the COMP into usage.Can anyone please let me know how it can be done.
I have 2 fields :
WS-A PIC S9(9) USAGE COMP.
WS-B PIC S9(4) USAGE COMP.
I have to convert the COMP fields into Usage and store it in another output file.
shall I directly move it into a PIC 9(9) usage Display fields or will I have to move it to PIC S9(9) usage Display field or will it be PIC 9(4) usage Display as PIC 9(9) usage COMP occupies 4 bytes.
An urgent reply will be arppreciated.
Thanks,
Rahul |
|
Back to top |
|
|
UmeySan
Active Member
Joined: 22 Aug 2006 Posts: 771 Location: Germany
|
|
|
|
Rahul_kumar !
Why not code your own suggestions, try it out and look what happens ???
Plse tell us the results. |
|
Back to top |
|
|
hikaps14
Active User
Joined: 02 Sep 2005 Posts: 189 Location: Noida
|
|
|
|
You requirements not very clear
Quote: |
I need to convert the COMP into usage.Can anyone please let me know how it can be done. |
There are different type of usages.If you want to move it DISPLAY variable.
Then you just need to have a variable with same PIC clause as in COMP but the usage DISPLAY.
This should work because defaut usage is 'DISPLAY'.
Hope this helps.
Thanks,
-Kapil.
Cobol Queries |
|
Back to top |
|
|
Rahul_kumar Warnings : 2 New User
Joined: 24 Jun 2006 Posts: 50
|
|
|
|
Hi Kapil and Umey,
thanks for the suggestion.I will be moving the input field S9(9) Comp to the output field S9(9). I think it will occupy 9 bytes.
Thanks ,
Anshul |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
A word of caution. S9(09) COMP (a/k/a binary fullword) has a maximum value of 2147483647, which is 10-digits.
As a failsafe, perhaps you should make the receiving field S9(10) and eliminate the possibility of high-order truncation and make sure you use the TRUNC(BIN) compiler option, which will guarantee that high-order truncation will NOT occur.
If your compiler supports COMP-5 (native binary) then the TRUNC option will have no effect and high-order truncation will NOT occur.
Regards,
Bill |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
What's the TRUNC option on your COBOL compiler set to? Depending on the TRUNC option, both PIC S9(04) COMP and S9(09) COMP fields could overflow receiving fields of S9(04) USAGE DISPLAY and S9(09) USAGE DISPLAY. TRUNC(STD) means no overflow will occur, TRUNC(BIN) means overflow could definitely occur, and TRUNC(OPT) means overflow may or may not occur. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
If you define the receiving field as signed S9(9) or S(910), be prepared to see a sign in the receiving field (i.e. +123 would be 12C, -456 would be 45F). |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Robert is absolutely correct regarding the fact that the TRUNC option will be an issue. However, if your compiler supports COMP-5 (Native Binary) then the TRUNC option can remain as it has no effect on COMP-5.
But, if your compiler does not support COMP-5 and you want to use TRUNC(OPT), then you can move your PIC 9(09) COMP field to a PIC 9(18) COMP field, then move the PIC 9(18) COMP field to your 09/10 Byte Display-Numeric field.
Yes, there are some "extra" instructions generated, but they're not too draconian.
Somebody could write a Thesis on the COBOL TRUNC option as over the years, it has become bane with many a techie.
Regards,
Bill |
|
Back to top |
|
|
Rahul_kumar Warnings : 2 New User
Joined: 24 Jun 2006 Posts: 50
|
|
|
|
Hi all,
I have coded the program as below :
01 WS-A PIC S9(9) comp
01 WS-B.
05 WS-B1 PIC X(1).
05 WS-B2 PIC S9(9).
1) Check the sign by comparing
IF WS-A >= 0
move '+' to WS-B1
ELSE
MOVE '-' TO WS-B1
2)MOVE WS-A TO WS-B2.
I am not sure whether the sign checking is done correctly as shown in 1.
Please let me know in case of any suggestions.
Thanks,
Rahul |
|
Back to top |
|
|
muthuvel
Active User
Joined: 29 Nov 2005 Posts: 217 Location: Canada
|
|
|
|
Your WS-B2 PIC S9(9) will have the sign and i am not sure is there any requirement to specify + or - outside.
If you want sign also to be displayed irrespective of + or - ,you can try the declaration of 01 WS-B PIC +9(09). |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Check the sign by comparing |
Is there some reason to check the sign? The declaration of WS-B2 PIC S9(9) will carry the sign within the data - positive or negative. This field cold be used for comparison or computation.
If you want the sign to be not a part of the number, you could store it in the separate field but then the pic would be 9(9). The field would no longer be directly usale in a compare or a computation.
How you store the field depends on your requirement - which is still not clear |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
See the SIGN clause in 5.3.14 of the Language Reference Manual. |
|
Back to top |
|
|
Rahul_kumar Warnings : 2 New User
Joined: 24 Jun 2006 Posts: 50
|
|
|
|
Hi all,
I have declared WS-B2 PIC S9(9) as PIC 9(9) only.It was by mistake that I had written it as S9(9).I have tested the sign thing by moving -ve value to the COMP field and it getting stored correctly in the display field in output file.
But I still need to test as per "Bill O'Boyle" comments that S9(9) COMP will occupy a max value of 2147483647 and whether it will result in any data loss by moving it to 9(9) display field.
Thanks a lot for your help.
Regards,
Rahul |
|
Back to top |
|
|
|