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
 

 

Packed decimal field ina file to alphanumeric in File layout

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Jithucse

New User


Joined: 18 Apr 2008
Posts: 11
Location: Coimbatore

PostPosted: Thu Jul 10, 2008 8:22 pm    Post subject: Packed decimal field ina file to alphanumeric in File layout
Reply with quote

Hi,

Is it possible to receive a packed decimal field in a file to alphanumeric
layout in cobol?

Suppose my file contains a field like Account which is

Fieldname type length

Account PD 12


FD XXXX

01 INPUT-REC.
05 ACCOUNT-TAB PIC X (12).

Is it possible in COBOL to receive this data by a file section above?
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 Jul 10, 2008 9:01 pm    Post subject:
Reply with quote

Yes but cobol won't do any conversion, if you tell cobol that it is an X field that is the way cobol will treat it. Your record layout must match the actual data in the file or you will have problems.
Back to top
View user's profile Send private message
Suresh Ponnusamy

Active User


Joined: 22 Feb 2008
Posts: 107
Location: New York

PostPosted: Thu Jul 10, 2008 9:08 pm    Post subject:
Reply with quote

No. Direct move won't work.

When you code a MOVE statement of Packed Decimal to an Alphanumeric in COBOL, the code compilation itself will fail (compilation error).

One way I can think of moving Packed Decimal field to a numeric variable and you can redefine that numeric into Alphanumeric.

But we should be very careful in doing this. Sometimes incorrect declaration leads to data exception (S0C7) error.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Thu Jul 10, 2008 9:34 pm    Post subject:
Reply with quote

Suresh: direct move isn't involved. The file will be read and the record moved into the COBOL FD buffer. A packed decimal field can be treated as alphanumeric; as long as Jithucse doesn't expect to use the packed decimal field as a number there's no problem.
Back to top
View user's profile Send private message
Suresh Ponnusamy

Active User


Joined: 22 Feb 2008
Posts: 107
Location: New York

PostPosted: Thu Jul 10, 2008 9:43 pm    Post subject:
Reply with quote

That is correct Robert. Group MOVE in COBOL will always be considered as Alphanumeric. Getting the value directly in to the Group variable will not cause any error. But it might leads to the loss of data. That data cannot be read inside the program.

Please correct me If I am wrong.
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 Jul 10, 2008 9:47 pm    Post subject:
Reply with quote

Hello,

Quote:
But it might leads to the loss of data. That data cannot be read inside the program.
Please clarify your thought on this. . .

If the code is written correctly, there should be no loss of data. When reading "external" data (data not yet validated), it is common to define it as PIC x(..) and ensure it is correct before moving it to some numeric field.
Back to top
View user's profile Send private message
Suresh Ponnusamy

Active User


Joined: 22 Feb 2008
Posts: 107
Location: New York

PostPosted: Thu Jul 10, 2008 10:05 pm    Post subject:
Reply with quote

Hi Dick,

What I meant here is, normally if we open a file which has Comp-3 variable values, it will not be in a readable format.

So if we want to use the value in the program, it should be moved to a Packed Decimal variable to perform any operation. But we cannot move an alphanumeric variable to a Packed Decimal. Cobol compiler won't allow that.

And also, the above (directly to a FD buffer) will be moved by reference (Address) and not by values. So the Packed Decimal property will be lost. After MOVE the value in the variable will not be consider as an numeric and it is alphanumeric. If we compare the HEX value of the both, it will be different (packed and alphanumeric).

Suggestions are most welcome.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Thu Jul 10, 2008 11:12 pm    Post subject:
Reply with quote

The language is COBOL. You can open files with COMP-3, COMP, DISPLAY or other fields, read them, move them, and use them as desired.
Quote:
normally if we open a file which has Comp-3 variable values, it will not be in a readable format.
would only apply if you mean human-readable (and I can read it perfectly fine by turning hex mode on while browsing the file).

Quote:
And also, the above (directly to a FD buffer) will be moved by reference (Address) and not by values. So the Packed Decimal property will be lost. After MOVE the value in the variable will not be consider as an numeric and it is alphanumeric. If we compare the HEX value of the both, it will be different (packed and alphanumeric).
This makes absolutely no sense. Packed decimal is a type of data, not a property. It cannot be gained or lost by moves. If Jithucse adds a REDEFINES clause to the FD, the packed decimal data can be used as a number by the redefined variable.
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 Jul 10, 2008 11:30 pm    Post subject:
Reply with quote

Reading a file in cobol does no conversion to the data, if the record layout you read into match the actual data in the file then there is no problem, if it doesn't then you may have problems because cobol will try to use the data format you told it to use.
Back to top
View user's profile Send private message
Suresh Ponnusamy

Active User


Joined: 22 Feb 2008
Posts: 107
Location: New York

PostPosted: Thu Jul 10, 2008 11:42 pm    Post subject:
Reply with quote

Hi Robert,

Yes the readability here I mentioned is manual read only. Sorry for not mentioning the same. I agree with your point of reading Hex values.

Here the property I mentioned is, internal conversion of the data from a Packed decimal to alphanumeric. As Craiq mentioned, if the layout is same then there is no problem. Otherwise DB2 will try to use the given format.

As you said, using Redefine Clause, we can get the actual data.

please let me know your comments on this.
Back to top
View user's profile Send private message
keyarika

New User


Joined: 24 May 2008
Posts: 10
Location: bangalore

PostPosted: Sat Jul 12, 2008 12:35 pm    Post subject:
Reply with quote

HI, what sholud be the length of aplhanumeric field for moving a Packed decimal of length 12. Can it be same, i mean X (12) for PD 12.
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 Jul 12, 2008 2:23 pm    Post subject:
Reply with quote

Hello,

Quote:
what sholud be the length of aplhanumeric field for moving a Packed decimal of length 12
Please clarify your question.

It appears that you are confused as to how data is both stored and manipulated.

If you show a few examples of the data you need to work with we should be able to help.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Sat Jul 12, 2008 6:15 pm    Post subject:
Reply with quote

If your field is defined as PIC S9(12) COMP-3, this is an X(7) field.

If your field is defined as PIC X(12), this is equivalent to PIC S9(23) COMP-3 but will only be allowed by the compiler if ARITH(EXTEND) option is specified; PIC S9(18) is the maximum allowed otherwise.
Back to top
View user's profile Send private message
snehal

New User


Joined: 12 Dec 2006
Posts: 14
Location: pune

PostPosted: Fri Mar 12, 2010 4:02 pm    Post subject: Reply to: Packed decimal field ina file to alphanumeric in F
Reply with quote

Hello Robert,

Sorry, I am replying a topic almost two years old. But I could not understand how to get the pic clause X(7) for a variable declared as
PIC S9(12).
Can you please explain bit more. It will be very much helpful.

Thanks in Advance.

Regards,
Snehal
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Fri Mar 12, 2010 4:14 pm    Post subject:
Reply with quote

There is a manuals link at the top of the page. Click on it, find the COBOL manuals, and read up on internal formats for data.

A COMP-3 field stores 2 digits in each byte, plus half a byte for the sign. 12 digits of COMP-3 data can be stored in 6 bytes, but the sign requires another half-byte. Since the system won't work with half-bytes, one full byte is therefore required for the sign. 6 bytes for numbers plus 1 byte for sign is 7 bytes.
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 Mar 12, 2010 8:33 pm    Post subject:
Reply with quote

Hello,

Quote:
But I could not understand how to get the pic clause X(7) for a variable declared as PIC S9(12).

The x(7) does not "go with" a variable of s9(12). The pic x(7) is the same size as s9(12) comp-3.
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
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 24 Tue Dec 06, 2016 8:04 pm
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 Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm


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