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

move s9(4) comp to 9(2)


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sumannaidu

New User


Joined: 21 May 2005
Posts: 13
Location: Bangalore

PostPosted: Thu May 15, 2008 8:42 pm
Reply with quote

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
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Thu May 15, 2008 8:46 pm
Reply with quote

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
View user's profile Send private message
sumannaidu

New User


Joined: 21 May 2005
Posts: 13
Location: Bangalore

PostPosted: Thu May 15, 2008 8:55 pm
Reply with quote

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
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Thu May 15, 2008 9:00 pm
Reply with quote

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
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Thu May 15, 2008 9:15 pm
Reply with quote

Something is not as it is being explained.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu May 15, 2008 9:36 pm
Reply with quote

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
View user's profile Send private message
mytags

New User


Joined: 28 Apr 2008
Posts: 63
Location: US

PostPosted: Fri May 16, 2008 9:27 am
Reply with quote

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
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Fri May 16, 2008 6:08 pm
Reply with quote

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
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri May 16, 2008 6:15 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri May 16, 2008 8:02 pm
Reply with quote

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
View user's profile Send private message
Meir Goldstein

New User


Joined: 12 May 2008
Posts: 7
Location: Jerusalem, israel

PostPosted: Sat May 17, 2008 10:24 pm
Reply with quote

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). icon_lol.gif
good tidings
Back to top
View user's profile Send private message
sudhakar_lendave

New User


Joined: 21 Nov 2006
Posts: 48
Location: mumbai

PostPosted: Sat May 31, 2008 11:58 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat May 31, 2008 3:21 pm
Reply with quote

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
View user's profile Send private message
sudhakar_lendave

New User


Joined: 21 Nov 2006
Posts: 48
Location: mumbai

PostPosted: Sat May 31, 2008 4:09 pm
Reply with quote

The x(4) contains 13267E1
after moving this to comp field and then to display field, it's showing 1279
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Sat May 31, 2008 4:17 pm
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Sat May 31, 2008 4:44 pm
Reply with quote

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
View user's profile Send private message
sudhakar_lendave

New User


Joined: 21 Nov 2006
Posts: 48
Location: mumbai

PostPosted: Sat May 31, 2008 5:28 pm
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Sat May 31, 2008 6:13 pm
Reply with quote

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
View user's profile Send private message
sudhakar_lendave

New User


Joined: 21 Nov 2006
Posts: 48
Location: mumbai

PostPosted: Sat May 31, 2008 6:24 pm
Reply with quote

That's Great Bill.
Thanks again icon_smile.gif
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Sat May 31, 2008 7:12 pm
Reply with quote

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
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat May 31, 2008 9:57 pm
Reply with quote

The basic design flaw in all computers.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat May 31, 2008 11:11 pm
Reply with quote

Each keyboard and programming language should have a DWIM key/function (Do What I Meant). . . .

d
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 COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
No new posts Converting ASCII values to COMP-3 (ZD... JCL & VSAM 2
No new posts Interviewers are surprised with my an... Mainframe Interview Questions 6
No new posts How to move DB2 Installation HLQ DB2 4
Search our Forums:

Back to Top