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

COBOL data formatting using PIC clause


IBM Mainframe Forums -> Mainframe Interview Questions
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
simimathew

New User


Joined: 26 Jan 2006
Posts: 23
Location: London

PostPosted: Wed May 10, 2006 6:24 pm
Reply with quote

Can somebody please tell me the difference between the following data declarations?

1. 03 ZB-COMMA-SI-LIMITS PIC -(3)9.99.
2. 03 ZB-COMMA-SI-LIMITS PIC Z(3)9.99.

What will happen if a decimal number, 0017.45, is moved to the field ZB-COMMA-SI-LIMITS in both cases? As per my understanding both will suppress the preceeding zeros (if the declaration had been 9(4).99, there would have been preceeding zeros) and replace them with spaces.

Please let me know the difference, if any.

Also is a declaration

03 ZB-COMMA-SI-LIMITS PIC Z,ZZZ,ZZZ,ZZZ,ZZ9.99.

valid????

Many Thanks,
Simi
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 May 10, 2006 10:20 pm
Reply with quote

Quote:

1. 03 ZB-COMMA-SI-LIMITS PIC -(3)9.99.
2. 03 ZB-COMMA-SI-LIMITS PIC Z(3)9.99.

What will happen if a decimal number, 0017.45, is moved to the field ZB-COMMA-SI-LIMITS in both cases? As per my understanding both will suppress the preceeding zeros (if the declaration had been 9(4).99, there would have been preceeding zeros) and replace them with spaces.

Please let me know the difference, if any.


The output from both these are identical.



Quote:
03 ZB-COMMA-SI-LIMITS PIC Z,ZZZ,ZZZ,ZZZ,ZZ9.99.

valid????


Yes, this is valid.

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

New User


Joined: 26 Jan 2006
Posts: 23
Location: London

PostPosted: Thu May 11, 2006 2:43 pm
Reply with quote

Thanks, Dave.

But I have one more clarification to make regarding the formatting.

If a field is declared as

03 DL6140-DAYS-OS PIC -(5)9.

What will be the output when u move a negative number -12345 to thsi field? Actually my question is, are we using this PIC clause to show the -ve sign as well. So in that case will PIC-(5)9 and PIC Z(5)9 be the same?

Please help me out.

Thanks in advance,
Simi
Back to top
View user's profile Send private message
DavidatK

Active Member


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

PostPosted: Thu May 11, 2006 7:41 pm
Reply with quote

Simi,

In this case you will get different results.

The PIC -(5)9 will result in "-12345"
and the PIC Z(5)9 will result in " 12345"

Both of these reserve 6 bytes, the -(5)9 is signed and will place a "-" as the leading byte if the value is negative. The Z(5)9 is unsigned and no sign, +/- will appear.

If you were to move a -123456 to both of these fields, the Z(5)9 will result in "123456" where the -(5)9 will truncate the Most Significant Byte and result in "-23456"

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

New User


Joined: 26 Jan 2006
Posts: 23
Location: London

PostPosted: Thu May 11, 2006 7:56 pm
Reply with quote

Thanks Dave.
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 -> Mainframe Interview Questions

 


Similar Topics
Topic Forum Replies
No new posts Store the data for fixed length COBOL Programming 1
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
Search our Forums:

Back to Top