Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Convert COMP variable into usage.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Convert COMP variable into usage.
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: 743
Location: Germany

PostPosted: Thu Dec 11, 2008 2:46 pm    Post subject:
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    Post subject: Reply to: Convert COMP variable into usage.
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    Post subject: Reply to: Convert COMP variable into usage.
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu Dec 11, 2008 5:29 pm    Post subject: Re: Convert COMP variable into usage.
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: 7931
Location: Bellevue, IA

PostPosted: Thu Dec 11, 2008 6:04 pm    Post subject:
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

Site Director


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

PostPosted: Thu Dec 11, 2008 11:14 pm    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Fri Dec 12, 2008 2:55 am    Post subject: Re: Convert COMP variable into usage.
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    Post subject: Reply to: Convert COMP variable into usage.
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: Chennai

PostPosted: Tue Dec 16, 2008 4:43 pm    Post subject:
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

Site Director


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

PostPosted: Tue Dec 16, 2008 10:33 pm    Post subject:
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: 1239
Location: Richfield, MN, USA

PostPosted: Wed Dec 17, 2008 12:08 am    Post subject:
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    Post subject: Reply to: Convert COMP variable into usage.
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    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 How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts Convert +9999999999999.99 to S9(12)V9(3) vnktrrd DFSORT/ICETOOL 8 Thu Nov 17, 2016 8:15 pm
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm
No new posts convert PD to ZD ram_vizag DFSORT/ICETOOL 5 Sat Nov 05, 2016 3:06 am
No new posts Protection Exception while move 0 to ... Kevin Vaz CICS 10 Tue Oct 18, 2016 4:19 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us