× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I've got a standalone field defined as packed(3,0).
Is there an easy way to define a DS subfiled as char(3)?

That would be CHAR(2), actually. Packed fields are always digits+1/2 bytes long. In this case, 2 bytes.


In other words, given any specific numeric field, how can a define a
corresponding character field large enough to hold the numeric data
without having to hardcode the subfield size?

     D char            ds
     D   packed                       3P 0

or

     D                 ds
     D   char
     D   packed                       3P 0 overlay(char)

In either case, the character field is automatically created as 2 bytes long, and you don't have to hard code the size.

The DS is used to send out an email message.

It would NOT make sense to do this in an E-mail message. E-mail messages are text-only, so you'd want to convert the number to human-readable form.

For example, if you had the packed value -123, this would be stored in memory in a packed field as x'123D'. That means that your 2 character field would be made up of 2 unprintable control characters. You wouldn't want to put that in an e-mail message!

So I'm thinking to myself, "maybe he meant zoned decimal instead of packed?". OKay, in that case you'd define it this way:

     D                 ds
     D   char
     D   zoned                        3S 0 overlay(char)

That'd be closer. For example, if the zoned field had a value of 19, it'd be stored in memory as x'F0F1F9'. If you tried to view it as text, it'd be 019 which at least would be printable! However, it does have that annoying leading zero. Now consider what happens if you make it a negative number, such as -123. the bytes are set to x'F1F2D3', which would appear on the screen as 12L, since x'D3' is the EBCDIC letter L.

Truly, you do NOT want to use a data structure for this. A data structure just overlays two fields so that they have the same hex byte values. In reality, you want to convert from the numeric field to a human-readable, nicely formatted, character field. Not just copy the bytes from one to the other!

If there isn't an easy way to do what I want, I'll just get rid of the DS altogether and use eval + some bifs to build the message.

That's a MUCH MUCH MUCH better idea. EVAL and BIFs will make this much easier to write, and using %char() or %editc() you can format the number any way you want.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.