Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How is the date populated in COMP-3 variable?

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

New User


Joined: 24 Apr 2007
Posts: 23
Location: India

PostPosted: Thu May 03, 2007 4:56 pm    Post subject: How is the date populated in COMP-3 variable?
Reply with quote

Hi,

I have declared a variable as follows:

01 ws-var1 pic 9(8)
01 ws-var2 redefines ws-var1
02 ws-var3 pic s9(8) comp-3.

move 20070503 to ws-var1

what should be the value in ws-var3?

when i displayed the field, in hex it shows me
F F F F F F F F
2 F 0 F 0 F 7 F

variable 1 in hex is
F F F F F F F F
2 0 0 7 0 5 0 3

can you please explain me how is the value in variable 3 populated?
Back to top
View user's profile Send private message

acevedo

Active User


Joined: 11 May 2005
Posts: 344
Location: Spain

PostPosted: Thu May 03, 2007 5:14 pm    Post subject:
Reply with quote

Quote:
1.3.4.5 Packed-decimal (COMP-3) items

PACKED-DECIMAL and COMP-3 are synonyms on all platforms.

Packed-decimal items occupy 1 byte of storage for every two decimal digits you code in the PICTURE description, except that the rightmost byte contains only one digit and the sign. This format is most efficient when you code an odd number of digits in the PICTURE description, so that the leftmost byte is fully used. Packed-decimal items are handled as fixed-point numbers for arithmetic purposes.
Back to top
View user's profile Send private message
Vedam

New User


Joined: 24 Apr 2007
Posts: 23
Location: India

PostPosted: Thu May 03, 2007 5:27 pm    Post subject: Re: How is the date populated in COMP-3 variable?
Reply with quote

Yeah, i understand that. but my query is, how is the value

F F F F F F F F
2 F 0 F 0 F 7 F

populated? According to me, the value should be

0 0 7 5 3
2 0 0 0 F
Back to top
View user's profile Send private message
acevedo

Active User


Joined: 11 May 2005
Posts: 344
Location: Spain

PostPosted: Thu May 03, 2007 5:48 pm    Post subject:
Reply with quote

Code:

F F F F F F F F
2 F 0 F 0 F 7 F


That's not what I see, instead

Code:

--------
20070503
FFFFFFFF
20070503


anyway, I'd never use that redefines. Explain what you're trying to get.

by the way, '20070503', in it would be saved as
Code:

00753
2000C


remember you shouldn't declare COMP-3 with even number.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 686
Location: Earth

PostPosted: Thu May 03, 2007 6:09 pm    Post subject:
Reply with quote

Vedam,
May I know why you are using redefines?

If you want to know the exact storage for a COMP-3 variable (date in this case) use following-
Code:

01 comp-date 9(08) comp-3.
01 alpha-var   x(05).

move your date to date variable and display alpha variable.
do a hex on.. then you will see what you wanted to see. Let us know your results.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 686
Location: Earth

PostPosted: Thu May 03, 2007 6:10 pm    Post subject:
Reply with quote

Correction-
Quote:
01 comp-date 9(08) comp-3.
01 alpha-var redefines comp-date x(05).
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 May 03, 2007 9:01 pm    Post subject:
Reply with quote

Hello,

The situation as posted should never be coded. It is another of the things that the compiler might let you do, but will serve no good purpose and should be avoided.
Code:
01 ws-var1 pic 9(8)
01 ws-var2 redefines ws-var1
02 ws-var3 pic s9(8) comp-3.


This is an unacceptable set of code - it has multiple problems. Rather than discuss what all might happen (which will get many conflicting opinions), focus might be better spent on what the code needs to actually do.

Please post what you are trying to accomplich and we can offer suggestions.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 686
Location: Earth

PostPosted: Thu May 03, 2007 10:16 pm    Post subject:
Reply with quote

Dick,
I think Vedam wants to see how date is stored in COMP-3, my guess is he got confused by assuming ( 01 comp-date 9(08) comp-3 )will take 8 bytes. So he used redefinition and tried to print the contents.
That's why I suggested him to do-
01 comp-date 9(08) comp-3.
01 alpha-var redefines comp-date x(05).
Let's see if he clarifies more on his question.
Back to top
View user's profile Send private message
Vedam

New User


Joined: 24 Apr 2007
Posts: 23
Location: India

PostPosted: Thu May 03, 2007 10:27 pm    Post subject: Re: How is the date populated in COMP-3 variable?
Reply with quote

hi,

I have a date with pic 9(8). i have to write the date to a file. I thought I could use 9(8) comp-3 which will be more efficient. Instead of moving from var-1 to var-3, i used redefines clause which was my mistake.

thanks all for the clarification.
How will 'move' of a non comp variable to a comp variable work fine? as for an 8 byte, comp-3 will store the value in a 5 byte. when this value is being moved to another variable of 8 bytes, it should throw error right??
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 May 03, 2007 10:45 pm    Post subject:
Reply with quote

Hello,

If your "non comp" field has valid numeric data you will have no problem.

Due to the way comp-3 is stored it is a good idea to use an odd number of digits when defining comp-3 field(s). 9(8) comp-3 is the same size as 9(9) comp-3 (5 bytes).

This
Quote:
as for an 8 byte, comp-3 will store the value in a 5 byte. when this value is being moved to another variable of 8 bytes, it should throw error right
might be worded differently. I'm not sure why the comp-3 field would be moved to an 8-byte variable. I may be misunderstanding something. . .

You can move decimal numbers to packed-decimal (comp-3). You can move comp-3 data to binary, zoned, or edited fields with no problems. You should not move comp-3 fields to fields that are not defned as some kind of numeric. The compiler will often let you compile code that will cause problems.
Back to top
View user's profile Send private message
Vedam

New User


Joined: 24 Apr 2007
Posts: 23
Location: India

PostPosted: Thu May 03, 2007 10:56 pm    Post subject: Re: How is the date populated in COMP-3 variable?
Reply with quote

the reason why would i move comp-3 variable to an 8 byte variable is as follows:

I have a database record which has a date field in it defined as 9(8) COMP-3. I have to process the field in such a way that I require year, month and day separately.

So, I will move the 9(8) comp-3 variable to a 9(8) variable. I'll redefine this 9(8) variable.
I was wondering how a packed field when moved to a non comp field will fetch values correctly.
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 May 03, 2007 11:34 pm    Post subject:
Reply with quote

Hello,

First - i believe i misunderstood what 8-byte meant - i thought it meant x(8).

If you move 9(8) comp-3 to 9(8) you should have no problem. And then you can redefine the 9(8) as whatever you need.

Let us know if there is anything that needs clarification.
Back to top
View user's profile Send private message
Vedam

New User


Joined: 24 Apr 2007
Posts: 23
Location: India

PostPosted: Fri May 04, 2007 3:13 pm    Post subject: Re: How is the date populated in COMP-3 variable?
Reply with quote

Normally an 8 byte COMP-3 variable occupies 5 bytes. When its value is "move"d to a non-comp variable of 8 bytes, does it get unpacked? i.e., the 5 bytes get unpacked to 8 bytes and fit in the non-comp variable?

here "move" means the statement "move var-1 to var-2"
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 686
Location: Earth

PostPosted: Fri May 04, 2007 3:40 pm    Post subject:
Reply with quote

Quote:
Normally(always) an 8 byte (wrong, you mean digit)COMP-3 variable occupies 5 bytes. When its value is "move"d to a non-comp variable of 8 bytes, does it get unpacked? i.e., the 5 bytes get unpacked to 8 bytes and fit in the non-comp variable(You mean ZD then) ? YES
icon_wink.gif
Back to top
View user's profile Send private message
Vedam

New User


Joined: 24 Apr 2007
Posts: 23
Location: India

PostPosted: Fri May 04, 2007 3:43 pm    Post subject: Re: How is the date populated in COMP-3 variable?
Reply with quote

yeah..it is not byte..it is digit..by non-comp, i mean a variable having PIC 9(8).
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: Fri May 04, 2007 7:51 pm    Post subject:
Reply with quote

Hello,

If you move the 9(8) comp-3 field to a 9(8) field, you will get the result you want.
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 Validate the Date girishb2 DFSORT/ICETOOL 9 Tue Sep 19, 2017 1:12 am
No new posts Moving values to a variable of copybo... Vignesh Sid COBOL Programming 6 Wed Sep 06, 2017 1:04 pm
No new posts Julian Date to CICS ABSTTIME blayek CICS 3 Wed Aug 30, 2017 11:15 pm
No new posts Updating the Trailer count in variabl... satheshbabur DFSORT/ICETOOL 6 Wed Aug 30, 2017 9:49 pm
No new posts Move from Comp3 variable to Edited Va... sreekusr COBOL Programming 8 Thu Aug 10, 2017 4:20 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us