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
 

 

How to convert a COMP-3 value?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
sabarikanth

New User


Joined: 07 Jun 2010
Posts: 59
Location: coimbatore

PostPosted: Thu Jul 01, 2010 5:40 pm    Post subject: How to convert a COMP-3 value?
Reply with quote

Hi,
Can anyone tell me how to convert a COMP-3 variable to 9() value.

i.e for example.
I'm getting the system date using
Code:
accept sysdate from date.

i have to compare the same date value with a variable
Code:
01 date1 pic x(7) comp-3.


and i need to do some arthimetric manipulations. so i need to convert that COMP-3 variable to a numeric clause.
How to achieve this..?
Back to top
View user's profile Send private message

Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Thu Jul 01, 2010 5:43 pm    Post subject:
Reply with quote

You can not have a pic x( ) and comp-3 together!
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Thu Jul 01, 2010 5:43 pm    Post subject:
Reply with quote

Have you considered a simple MOVE from the comp-3 field to a 9() field?
Back to top
View user's profile Send private message
sabarikanth

New User


Joined: 07 Jun 2010
Posts: 59
Location: coimbatore

PostPosted: Thu Jul 01, 2010 5:47 pm    Post subject: Reply to: How to convert a COMP-3 value?
Reply with quote

Sorry Craq Giegerich
The code is actually
Code:
01 date1 pic 9(7) comp-3.
Back to top
View user's profile Send private message
sabarikanth

New User


Joined: 07 Jun 2010
Posts: 59
Location: coimbatore

PostPosted: Thu Jul 01, 2010 5:49 pm    Post subject: Reply to: How to convert a COMP-3 value?
Reply with quote

CICS Guy-
Yeah i tried to using MOVE command. But its not working properly for arthimetric operations.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Thu Jul 01, 2010 5:55 pm    Post subject:
Reply with quote

I simple compare should to it, no conversion needed. RTFM!
Back to top
View user's profile Send private message
sabarikanth

New User


Joined: 07 Jun 2010
Posts: 59
Location: coimbatore

PostPosted: Thu Jul 01, 2010 5:55 pm    Post subject: Reply to: How to convert a COMP-3 value?
Reply with quote

Shall i move the Comp-3 value to a variable like below,

Code:
 01 DATE1                  PIC 9(7)   COMP-3.

 01 WS-DATE1.                           
    05 WS-YEAR                PIC 999. 
    05 WS-MONTH               PIC 99.   
    05 WS-DATE                PIC 99.   

will the below command work?

Code:
MOVE DATE1 TO WS-DATE1.

If its so wat will be the result?
Code:
DISPLAY 'YEAR' WS-YEAR
DISPLAY 'MONTH' WS-MONTH
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Jul 01, 2010 5:56 pm    Post subject:
Reply with quote

since only the date from ACCEPT is coming as 9(6)
(depending on your COBOL version - which you did not bother to define)

and everything else is COMP-3,

instead of converting all the COMP-3 to DISPLAY (9()) for calculations,
which is dumb

convert your ACCEPT'd date to COMP-3 - only one move and then you have it.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7905
Location: Bellevue, IA

PostPosted: Thu Jul 01, 2010 5:59 pm    Post subject:
Reply with quote

Quote:
Yeah i tried to using MOVE command. But its not working properly for arthimetric operations.
You have told us absolutely nothing significant here. Do you mean the MOVE worked but the results were not what you expected (if so -- what did you expect and what did you get)? or you got an abend on the MOVE statement (and if so, which abend)? or an error message was generated but no abend occurred?

For your information, the COBOL Language Reference manual (link at the top of the page) clearly states that moving a COMP-3 data value to any PIC 9 variable will work according to the rules COBOL uses for truncation and filling. So your statement
Quote:
Can anyone tell me how to convert a COMP-3 variable to 9() value.
is absolute nonsense -- a COMP-3 variable already is a 9() value by its very definition.
Back to top
View user's profile Send private message
sabarikanth

New User


Joined: 07 Jun 2010
Posts: 59
Location: coimbatore

PostPosted: Thu Jul 01, 2010 6:00 pm    Post subject: Reply to: How to convert a COMP-3 value?
Reply with quote

Thanks for your answer dbzTHEdinosauer.

but i need to compare a variable of lenght
Quote:
pic 9(7) comp-3
to a date value which has been accepted from system.
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 Jul 01, 2010 6:00 pm    Post subject: Reply to: How to convert a COMP-3 value?
Reply with quote

What is the format of DATEL? If it's Gregorian, it's too small for a CCYYMMDD format. It will only accommodate a format of CYYMMDD and truncate the high-order of the century.

What version of COBOL are you using? For the VS/COBOL II ACCEPT, the format is YYMMDD.

More information is needed....

Bill
Back to top
View user's profile Send private message
sabarikanth

New User


Joined: 07 Jun 2010
Posts: 59
Location: coimbatore

PostPosted: Thu Jul 01, 2010 6:08 pm    Post subject: Reply to: How to convert a COMP-3 value?
Reply with quote

Bill- Formate i obtain from system is YYMMDD.
but i have my value in the formate as YYYMMDD in Comp-3 variable. So now i need to compare these two values separtely (i.e YY, MM, DD) and need to perform some arthimetric operations.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Jul 01, 2010 6:13 pm    Post subject:
Reply with quote

??????????????????

what is the problem of
converting your date YYMMDD display to a YYYMMDD comp-3?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7905
Location: Bellevue, IA

PostPosted: Thu Jul 01, 2010 6:19 pm    Post subject:
Reply with quote

You don't know how to use COMPUTE statements? Time to read the manuals (link at the top of the page).

The mere fact a variable is COMP-3 or DISPLAY will not affect, in any way, its use as a number in a COBOL program. So far you've spent a lot of time telling us about, and we've spent a lot of time responding to, something that simply is not an issue in COBOL. If you want to continue this thread, go back to the beginning and describe -- in simple terms -- exactly what you are attempting to do and what specifically is not functioning as you expect with the code you have written. If you have not written any code yet, then go write some and find out how COBOL works before posting again.
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 645
Location: Pennsylvania

PostPosted: Thu Jul 01, 2010 6:25 pm    Post subject:
Reply with quote

If you really need seperate fields try this:
Code:

01 DATE1                  PIC 9(7)   COMP-3.

 01 WS-DATE1            PIC 9(6).
 01 FILLER REDEFINES WS-DATE1.                           
    05 WS-YEAR                PIC 99. 
    05 WS-MONTH               PIC 99.   
    05 WS-DATE                PIC 99.   


Then MOVE DATE1 TO WS-DATE1.

The elementary move will convert the format and truncate the leading (I assume zero).
Back to top
View user's profile Send private message
sabarikanth

New User


Joined: 07 Jun 2010
Posts: 59
Location: coimbatore

PostPosted: Thu Jul 01, 2010 6:31 pm    Post subject: Reply to: How to convert a COMP-3 value?
Reply with quote

i think you didnt get my question.icon_sad.gif
my code is like this.

Code:

 01 WS-DATE1.                           
    05 WS-YEAR                PIC 999 COMP-3. 
    05 WS-MONTH               PIC 99 COMP-3.   
    05 WS-DATE                PIC 99 COMP-3.


I get the date1 from my FD section as
Code:
01 DATE1                  PIC 9(7)   COMP-3.

then i'm moving this DATE1 to WS-DATE1.
here i cant get the exact ws-month value.
if suppose the DATE1 has 0100701. i'm getting
WS-YEAR = 010
WS-MONTH= 01 instead of 07.
Back to top
View user's profile Send private message
sabarikanth

New User


Joined: 07 Jun 2010
Posts: 59
Location: coimbatore

PostPosted: Thu Jul 01, 2010 6:49 pm    Post subject: Reply to: How to convert a COMP-3 value?
Reply with quote

Thanks daveporcelan. Your guess is right.
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 Jul 01, 2010 6:53 pm    Post subject: Reply to: How to convert a COMP-3 value?
Reply with quote

When you move DATE1 (COMP-3) to WS-DATE1 (GROUP), the compiler will generate a single internal MOVE instruction and will not perform a conversion. WS-DATE1 will contain X'0YYMMDDF4040'.

You need to read up on COBOL data movement and the expected results....

Bill
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 645
Location: Pennsylvania

PostPosted: Thu Jul 01, 2010 6:55 pm    Post subject:
Reply with quote

I did get your question.

I showed you something to try instead.

The ELEMENTARY move (to a field with a pic on it) is what i think you need.

Try it and see if it works.

What you have must not be working for you, so try what I proposed.
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