View previous topic :: View next topic
|
Author |
Message |
sabarikanth
New User
Joined: 07 Jun 2010 Posts: 59 Location: coimbatore
|
|
|
|
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 |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
You can not have a pic x( ) and comp-3 together! |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Have you considered a simple MOVE from the comp-3 field to a 9() field? |
|
Back to top |
|
|
sabarikanth
New User
Joined: 07 Jun 2010 Posts: 59 Location: coimbatore
|
|
|
|
Sorry Craq Giegerich
The code is actually
Code: |
01 date1 pic 9(7) comp-3. |
|
|
Back to top |
|
|
sabarikanth
New User
Joined: 07 Jun 2010 Posts: 59 Location: coimbatore
|
|
|
|
CICS Guy-
Yeah i tried to using MOVE command. But its not working properly for arthimetric operations. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
I simple compare should to it, no conversion needed. RTFM! |
|
Back to top |
|
|
sabarikanth
New User
Joined: 07 Jun 2010 Posts: 59 Location: coimbatore
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
sabarikanth
New User
Joined: 07 Jun 2010 Posts: 59 Location: coimbatore
|
|
|
|
Thanks for your answer dbzTHEdinosauer.
but i need to compare a variable of lenght
to a date value which has been accepted from system. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
sabarikanth
New User
Joined: 07 Jun 2010 Posts: 59 Location: coimbatore
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
??????????????????
what is the problem of
converting your date YYMMDD display to a YYYMMDD comp-3? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
daveporcelan
Active Member
Joined: 01 Dec 2006 Posts: 792 Location: Pennsylvania
|
|
|
|
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 |
|
|
sabarikanth
New User
Joined: 07 Jun 2010 Posts: 59 Location: coimbatore
|
|
|
|
i think you didnt get my question.
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 |
|
|
sabarikanth
New User
Joined: 07 Jun 2010 Posts: 59 Location: coimbatore
|
|
|
|
Thanks daveporcelan. Your guess is right. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
daveporcelan
Active Member
Joined: 01 Dec 2006 Posts: 792 Location: Pennsylvania
|
|
|
|
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 |
|
|
|