Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

move s9(4) comp to 9(2)
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: move s9(4) comp to 9(2)
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    Post subject:
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    Post subject:
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: 2150
Location: At my coffee table

PostPosted: Thu May 15, 2008 9:00 pm    Post subject:
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    Post subject:
Reply with quote

Something is not as it is being explained.
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 15, 2008 9:36 pm    Post subject:
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    Post subject:
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

Active Member


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

PostPosted: Fri May 16, 2008 6:08 pm    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Fri May 16, 2008 8:02 pm    Post subject:
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    Post subject: move s9(4) comp to 9(2)
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    Post subject:
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

Site Director


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

PostPosted: Sat May 31, 2008 3:21 pm    Post subject:
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    Post subject:
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    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Sat May 31, 2008 4:44 pm    Post subject: Re: move s9(4) comp to 9(2)
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    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Sat May 31, 2008 6:13 pm    Post subject:
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    Post subject:
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    Post subject:
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
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. How to move a long alphanumeric data ... lind sh COBOL Programming 8 Mon Dec 05, 2016 7:51 pm
No new posts Protection Exception while move 0 to ... Kevin Vaz CICS 10 Tue Oct 18, 2016 4:19 pm
No new posts How can we create a flat file in JAVA... rakesh.v18 Java & MQSeries 7 Fri Sep 23, 2016 10:46 pm
This topic is locked: you cannot edit posts or make replies. Alphanumeric to Numeric move on UNIX mistah kurtz COBOL Programming 16 Wed Jul 27, 2016 8:47 pm
No new posts Need information on COBOL MOVE CORRES... subratarec COBOL Programming 10 Tue Jun 28, 2016 10:38 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us