View previous topic :: View next topic
|
Author |
Message |
Manish Dhole
New User
Joined: 13 Jul 2012 Posts: 1 Location: India
|
|
|
|
Hi,
I want know the reason that why can't we directly display the COMP-3 variable directly, and why it is always required to move to the Numeric variable and then only we can display.
If we display directly what error will occur. |
|
Back to top |
|
|
Peter cobolskolan
Active User
Joined: 06 Feb 2012 Posts: 104 Location: Sweden
|
|
|
|
Who told you such lies?
Is this an interview question? |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Manish Dhole wrote: |
I want know the reason that why can't we directly display the COMP-3 variable directly, and why it is always required to move to the Numeric variable and then only we can display.
If we display directly what error will occur. |
Such a deal of confusion in such a small post.
First, you can DISPLAY COMP-3, without any error -- why do you think there should be an error? Have you tried soemthing?
COBOL Comp-3 is a binary field type that "packs" two digits into each byte (using the BCD). This halves the storage requirements compared to a character, or COBOL "display" field. However, comp-3 is not commonly found in PC languages and so the understanding about it is beyond words!
For examples on how comp-3 data is stored, let's see this
Code: |
Value Comp-3, hex
+0 0C
+1 1C
+12 01 2C
+123 12 3C
+1234 01 23 4C |
The left column in the table decimal value being stored, and the right column is the hexadecimal value you will see in the file and the values in the file/SYSOUT make sense to you or not depends on if you understand COMP-3 notation or not. |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Anuj,
Nice post
Probably we need to have a sticky how a COMP,COMP2,COMP3 is stored ?? |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Once in a while my mood swings to a better side.... Possibly, we can have sticky but this is an "expert forum" ... |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Expert forum might help groom others to experts |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Well, this sticky might be of help with the question.
You get the same effect with COMP-3.
It can be convenient to move to a signed-edited field before DISPLAYing it, but the only "problem" is with interpreting the sign and the right-most digit correctly. Setting the display to HEX can also reveal the values. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
why can't we directly display the COMP-3 variable directly, and why it is always required to move to the Numeric variable |
1. COMP-3 variables are numeric, period. You can check this in the COBOL Language Reference manual (link at the top of this page) by reading 5.1.6.6 Classes and categories of data.
2. Who told you you could not use DISPLAY on a COMP-3 variable? You would be wise to stop listening to that person's comments about COBOL -- no matter who it is -- because their advice is completely and totally WRONG! There have been many examples posted on this forum where DISPLAY VAR is used and VAR is defined as COMP-3. |
|
Back to top |
|
|
|