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

How to convert a COMP-3 value?


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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: 2146
Location: At my coffee table

PostPosted: Thu Jul 01, 2010 5:43 pm
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
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
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
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
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Jul 01, 2010 5:59 pm
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Jul 01, 2010 6:00 pm
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
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Jul 01, 2010 6:19 pm
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: 792
Location: Pennsylvania

PostPosted: Thu Jul 01, 2010 6:25 pm
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
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Jul 01, 2010 6:53 pm
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: 792
Location: Pennsylvania

PostPosted: Thu Jul 01, 2010 6:55 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
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 COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Convert single row multi cols to sing... DFSORT/ICETOOL 6
No new posts convert file from VB to FB and use tr... DFSORT/ICETOOL 8
Search our Forums:

Back to Top