View previous topic :: View next topic
|
Author |
Message |
sumannaidu
New User
Joined: 21 May 2005 Posts: 13 Location: Bangalore
|
|
|
|
hi,
can anyone tell me how to move s9(4) comp to 9(2) .. when we do that in our program we getting junk data.. can anyone explain me doing that.
regards
suman |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
When you move a possible 4 digit number to a maximum of 2 digits what would you expect to get? What is the full definition of each field, what results are you getting? |
|
Back to top |
|
|
sumannaidu
New User
Joined: 21 May 2005 Posts: 13 Location: Bangalore
|
|
|
|
abc pic S9(4) comp.
ws-a pic 9(2).
move abc to ws-a
now abc consists say 25 ... after the move we are getting junk data in ws-a... i.e #### is coming |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
sumannaidu wrote: |
abc pic S9(4) comp.
ws-a pic 9(2).
move abc to ws-a
now abc consists say 25 ... after the move we are getting junk data in ws-a... i.e #### is coming |
What is '####' and why is it four characters long?
Try:
display '*' abc '*'
move abc to ws-a
display '*' ws-a '*'
And then set hex on in the sysout and paste back here the results..... |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Something is not as it is being explained. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
can anyone tell me how to move s9(4) comp to 9(2) |
Sorry, but you cannot do this (and expect anything but questionable results).
What is the data in "abc"? Why would you want to truncate it?
If you post your code and explain what you need to accomplish, we can offer suggestions. |
|
Back to top |
|
|
mytags
New User
Joined: 28 Apr 2008 Posts: 63 Location: US
|
|
|
|
Hi Suman,
From your question i understood that your intention is move first 2 digits of the data to another field? if so it is better to use reference modification and move the first two digits to the field you need to move.If this is not your intention can you please explain it in detail? |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
Moving a 9(4) to a 9(2) would not move the "first" 2 digits (ambiguous), but rather the rightmost two.
You cannot use reference mod on a COMP, which is binary. You must move it to a DISPLAY var, then use reference mod.
However, most COBOL's should let you must move any type of 9(4) to a 9(2) and chop off the left without an issue.
That's the question here - why is op's not doing so.
OP - are you there? - how's about posting your actual values in hex. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Quote: |
junk data in ws-a... i.e #### is coming |
That is what you see in Excel when the column width is to small to show the value. If so what does Excel have to do with mainframe COBOL? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
The same happens with some mainframe reporting tools when a field/accumulator has a value too large for the output definition. |
|
Back to top |
|
|
Meir Goldstein
New User
Joined: 12 May 2008 Posts: 7 Location: Jerusalem, israel
|
|
|
|
hello,
i think the compiler does not do the conversion because he looks on 9(2)
as a group item, try to move first to a signed packed field and then to 9(2).
good tidings |
|
Back to top |
|
|
sudhakar_lendave
New User
Joined: 21 Nov 2006 Posts: 48 Location: mumbai
|
|
|
|
Hi All,
with the same thread, i got stucked with following problem:
I have a WS-DATE PIC x(4) field which is having comp value of a date(yyyymmdd).
To get the date in Decimal format,
I moved this field into 9(08) comp field which again moved to 9(08) for displaying.
When I displayed this field it was not showing proper value.
What was the reason?
Sudhakar. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Please post the hex values for a few of these x(4) fields.
Also, please post what was shown when you displayed the 9(8) values for those same x(4) values. |
|
Back to top |
|
|
sudhakar_lendave
New User
Joined: 21 Nov 2006 Posts: 48 Location: mumbai
|
|
|
|
The x(4) contains 13267E1
after moving this to comp field and then to display field, it's showing 1279 |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Don't move x(4) to 9(8) comp just redefine the x(4) as 9(8) comp, and then move the comp to a display field. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
These PIC X(04) fields may contain the date as packed-unsigned (similar to the older COBOL ANSI standard known as COMP-6), with a format of X'CCYYMMDD', so the values need to be treated as packed-decimal then converted to display-numeric.
Try this -
Code: |
03 WS-HEX-DATE PIC X(04) VALUE X'20080531'.
03 WS-PACKED-DATE PIC 9(09) PACKED-DECIMAL.
03 WS-PACKED-DATE-V9 REDEFINES WS-PACKED-DATE
PIC 9(08)V9 PACKED-DECIMAL.
03 WS-PACKED-DATE-X REDEFINES WS-PACKED-DATE
PIC X(05).
03 WS-DISPLAY-DATE PIC 9(08).
03 WS-DISPLAY-DATE-X REDEFINES WS-DISPLAY-DATE
PIC X(08).
*
MOVE ZERO TO WS-PACKED-DATE.
MOVE WS-HEX-DATE TO WS-PACKED-DATE-X (1:4).
MOVE WS-PACKED-DATE-V9 TO WS-DISPLAY-DATE.
|
Field WS-DISPLAY-DATE-X (WS-DISPLAY-DATE) now contains the date as C'20080531'.
If these hex-values were treated as if they were binary-fullwords and they went through the conversion process, when all was said and done (using an original hex-value of X'20080531'), that value would be decimal 537396529.
AFAIK, COMP-6 was never defined to any release of IBM COBOL.
Other COBOL compilers, such as Burroughs and NCR did include this definition.
There's a possiblity these hex-dates were created in Assembler with the idea to save the 1-byte sign-byte (which would have caused these values to be formatted as PIC X(05)). Saw this technique used many times during Y2K conversion/compliance.
HTH....
Regards,
Bill |
|
Back to top |
|
|
sudhakar_lendave
New User
Joined: 21 Nov 2006 Posts: 48 Location: mumbai
|
|
|
|
Thanks Craq Giegerich.. it worked.
But i don't understand, why, even though the X(4) field which has comp value in it, is not moving correctly into the comp variable?
It would be a great help. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Code: |
03 WS-FWORD-X.
05 WS-FWORD PIC 9(08) COMP.
03 WS-DISPLAY-DATE PIC 9(08).
*
MOVE X'013267E1' TO WS-FWORD-X.
MOVE WS-FWORD TO WS-DISPLAY-DATE.
|
Here's what happens under the covers (Assembler expansion) -
Code: |
FWORD DS F
DWORD DS D
DATE DS CL8
*
MVC FWORD,=X'013267E1'
L R15,FWORD
CVD R15,DWORD
UNPK DATE,DWORD
OI DATE+L'DATE-1,X'F0'
|
01) Populate FWORD with the hex-value
02) LOAD the FWORD into Register 15
03) CONVERT to DECIMAL into DWORD
04) UNPACK DWORD into DATE
05) Ensure the last byte of DATE has a Zone-Nibble of 'F'
You're done! DATE = 20080609
You can verify this by converting hex to decimal on your calculator.
HTH....
Bill |
|
Back to top |
|
|
sudhakar_lendave
New User
Joined: 21 Nov 2006 Posts: 48 Location: mumbai
|
|
|
|
That's Great Bill.
Thanks again |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
sudhakar_lendave wrote: |
Thanks Craq Giegerich.. it worked.
But i don't understand, why, even though the X(4) field which has comp value in it, is not moving correctly into the comp variable?
It would be a great help. |
COBOL doesn't know that is a comp value in the x(4) field so it treats it an alphanumeric item. If you define a field incorrectly in COBOL it does what you tell it not what you want. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
The basic design flaw in all computers. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Each keyboard and programming language should have a DWIM key/function (Do What I Meant). . . .
d |
|
Back to top |
|
|
|