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

pic 9(6) to pic s9(9) comp


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

New User


Joined: 11 Mar 2006
Posts: 13

PostPosted: Tue Oct 03, 2006 9:51 pm
Reply with quote

Hi
I have a variable from an input file defined as pic 9(6).I need to write this into an output file as pic s9(9) comp variable (4 bytes) after performing some validations.
how do i achieve this conversion and wat is the value of the variable in the output file?
sample input say 200603

I tried the following method. I moved the 9(6) into a S9(9) variable and moved that into the comp variable.But when i opened the output file i could see only 2006.

TIA

ram
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Tue Oct 03, 2006 10:17 pm
Reply with quote

ram,

Can you please post the actual variable definitions with levels, and the actual code you use to move the variables.

My suspicion is that you moving a higher level group variable to the 'pic s9(9) comp' field, not the s9(9) variable.

Your should be able to move the 9(6) directly to the S9(9) comp variable.

Dave
Back to top
View user's profile Send private message
isys2006

New User


Joined: 11 Mar 2006
Posts: 13

PostPosted: Wed Oct 04, 2006 8:15 am
Reply with quote

Hi Dave
The 9(6) variable is a level 05 variable. The s9(9) and the comp variable has also been defined as a level 05 variable.
Let me try the 'move' again & I will let you know.


Thanks
ram
Back to top
View user's profile Send private message
isys2006

New User


Joined: 11 Mar 2006
Posts: 13

PostPosted: Wed Oct 04, 2006 8:47 am
Reply with quote

Hi Dave
I tried moving the 9(6) variable (value : 200603 & level 05 variable) to the S9(9) Comp variable (level 05 variable ). In the output file the value written was 2006
Obviously that value in the output file is incorrect.
Also could you let me know if there are any Compiler Options that can be used.


Thanks
Ram
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Wed Oct 04, 2006 10:23 pm
Reply with quote

Ram,

Please post the source code for the working storage and move statement. I don't see why the move wouldn't work.

I'll copy and compile and run it on my machine

Dave
Back to top
View user's profile Send private message
noorkh

New User


Joined: 06 Mar 2006
Posts: 76
Location: Chennai

PostPosted: Thu Oct 05, 2006 6:11 pm
Reply with quote

Yes, I agree with David. Direct move itself should work. Post the source code.

Noor
Back to top
View user's profile Send private message
isys2006

New User


Joined: 11 Mar 2006
Posts: 13

PostPosted: Fri Oct 06, 2006 8:19 am
Reply with quote

Hi Dave
Here's the code snippet.

01 WS-PERFORMANCE-RECORD.
05 FUNDNAME PIC X(30) VALUE SPACES.
05 LOAD-YEAR-MONTH PIC S9(9) COMP VALUE ZEROS.
05 YEAR-MONTH PIC S9(9) COMP VALUE ZEROS.
***********************************************************
01 FUNDNAME-O-1.
05 FUNDNAME-O PIC X(30)
OCCURS 40 TIMES.
01 LOAD-YEAR-MONTH-O-1.
05 LOAD-YEAR-MONTH-O OCCURS 40 TIMES.
10 LOAD-YEAR PIC 9(4).
10 LOAD-MONTH PIC 9(2).
01 YEAR-MONTH-O-1.
05 YEAR-MONTH-O OCCURS 40 TIMES.
10 YEAR-O PIC 9(4).
10 MONTH-O PIC 9(2).

******************************************************************
5000-WRITE-RECORD.
******************************************************************

MOVE ZEROS TO WS-COUNT2,WS-TEMPORARY
MOVE 1 TO WS-COUNT3
PERFORM UNTIL WS-COUNT3 > 40
IF KEYS(WS-COUNT3) = 0
MOVE FUNDNAME-O(WS-COUNT3) TO FUNDNAME
MOVE LOAD-YEAR-MONTH-O(WS-COUNT3) TO LOAD-YEAR-MONTH
MOVE YEAR-MONTH-O(WS-COUNT3) TO YEAR-MONTH


Thanks
Ram
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Fri Oct 06, 2006 7:51 pm
Reply with quote

Ram,

The problem you are having comes from the move of
YEAR-MONTH-O(WS-COUNT3) TO YEAR-MONTH.

Although YEAR-O and MONTH-O are defined as PIC 9(), YEAR-MONTH-O is defines by default as PIC X(). When you move the PIC X() field to the PIC 9() COMP field no conversion takes place and is moved byte by byte and is truncated after the 4th character. That?s why you see ?2006? in the COMP field.

There are a couple of ways to correct this.

05 YEAR-MONTH-O OCCURS 40 TIMES.
10 YEAR-MONTH-9 PIC 9(6).
10 FILLER REDEFINES YEAR-MONTH-O.
15 YEAR-O PIC 9(4).
15 MONTH-O PIC 9(2).

MOVE YEAR-MONTH-9(WS-COUNT-3) TO YEAR-MONTH.

Or

01 YEAR-MONTH-9 PIC 9(6).

MOVE YEAR-MONTH-O(WS-COUNT3) TO YEAR-MONTH-9.
MOVE YEAR-MONTH-9 TO YEAR-MONTH.

Dave
Back to top
View user's profile Send private message
isys2006

New User


Joined: 11 Mar 2006
Posts: 13

PostPosted: Fri Oct 06, 2006 9:16 pm
Reply with quote

Hi Dave
Gr8 explanation. Thanx a ton!!!! icon_biggrin.gif
I will check it over the weekend & let you know how it went.

Thanks
Ram
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 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 Cobol COMP-2 fields getting scrambled... Java & MQSeries 6
No new posts convert alphanumeric PIC X(02) to hex... COBOL Programming 3
Search our Forums:

Back to Top