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

Convert COMP variable into usage.


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Rahul_kumar
Warnings : 2

New User


Joined: 24 Jun 2006
Posts: 50

PostPosted: Thu Dec 11, 2008 2:16 pm
Reply with quote

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
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Thu Dec 11, 2008 2:46 pm
Reply with quote

Rahul_kumar !

Why not code your own suggestions, try it out and look what happens ???
Plse tell us the results.
Back to top
View user's profile Send private message
hikaps14

Active User


Joined: 02 Sep 2005
Posts: 189
Location: Noida

PostPosted: Thu Dec 11, 2008 2:47 pm
Reply with quote

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'.

Code:
WS-A PIC S9(9).


Hope this helps.

Thanks,
-Kapil.
Cobol Queries
Back to top
View user's profile Send private message
Rahul_kumar
Warnings : 2

New User


Joined: 24 Jun 2006
Posts: 50

PostPosted: Thu Dec 11, 2008 4:51 pm
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Dec 11, 2008 5:29 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Dec 11, 2008 6:04 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Thu Dec 11, 2008 11:14 pm
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Dec 12, 2008 2:55 am
Reply with quote

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. icon_confused.gif

Regards,

Bill
Back to top
View user's profile Send private message
Rahul_kumar
Warnings : 2

New User


Joined: 24 Jun 2006
Posts: 50

PostPosted: Tue Dec 16, 2008 3:48 pm
Reply with quote

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
View user's profile Send private message
muthuvel

Active User


Joined: 29 Nov 2005
Posts: 217
Location: Canada

PostPosted: Tue Dec 16, 2008 4:43 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Tue Dec 16, 2008 10:33 pm
Reply with quote

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 icon_confused.gif
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Wed Dec 17, 2008 12:08 am
Reply with quote

See the SIGN clause in 5.3.14 of the Language Reference Manual.
Back to top
View user's profile Send private message
Rahul_kumar
Warnings : 2

New User


Joined: 24 Jun 2006
Posts: 50

PostPosted: Thu Dec 18, 2008 10:02 am
Reply with quote

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
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 Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Need to convert date format DFSORT/ICETOOL 20
No new posts Keep leading zero(s) after convert fl... SYNCSORT 7
No new posts Variable Output file name DFSORT/ICETOOL 8
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
Search our Forums:

Back to Top