× 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.



On 2/25/11 5:36 AM, Rick.Chevalier@xxxxxxxxxxxxxxx wrote:
Thanks Barbara. I hate to admit it but I hadn't considered
negative numbers yet. I'll take a look at LBCPYNV.
The decimal positions shouldn't be an issue.

On 2/24/11 4:01 PM, Barbara Morris wrote:

Rick doesn't have a packed variable that he can use with %EDITC.
He has a string with a packed value in it, where the length (and
decimals) are not known at compile time.

Rick, if you know that you will never get a value with more than 31
digits, you could define a packed(63,31) variable in your program,
and use LBCPYNV to assign the packed value in your string to that
packed variable. Then you could use %CHAR on the packed variable.
That would handle negatives correctly. You'd probably want to trim
off trailing zeros if the input value has decimals.

http://archive.midrange.com/rpg400-l/200605/msg00738.html

Having started with the MI CVTHC, and the above archive message link showing the MI CPYNV [LBCPYNV], seems MI instructions are acceptable. Perhaps also consider using the MI EDIT [LBEDIT or EDITPD] instruction as an effective %EDITC or %EDITW. Admittedly that requires using an edit mask, which could mean using a stored mask or having to generate the mask.

Even if generating a mask is required, performing numeric editing directly could be better than moving the data into a fixed-size BCD [Binary Coded Decimal] scalar variable using CPYNV. With EDIT the support is there for the maximum digits, precision and scale; i.e. not limited to the fixed-size(s) chosen. If using the decimal scalar, further editing might be required to produce the desired effect, beyond the simple casting of a fixed-size decimal scalar to character; e.g. truncating trailing zeroes and possibly the decimal separator. Also the original message had some "Format" and "Separator" information about the data for which an Edit Code or Edit Word might be appropriate; though those appear possibly to deal with date\time data versus numeric.

The scenario was clarified in the message thread as:

On 2/24/11 12:30 PM, Rick.Chevalier@xxxxxxxxxxxxxxx wrote:
Sorry, I wasn't clear. It is a character representation of a
packed field. The source value is a character field that looks
like x'12345F'. The length could vary as well as the decimal
places. I am 'unpacking' it into a character field that will
have '12345'.

The EDIT can be used against numeric BCD data inline to character data by address, rather than requiring a [Packed decimal] scalar variable, just as with the use of CPYNV in the archived message; similarly by setting the attributes of the data at the given address. The results of my quick web search yielded an example of LBEDIT, but not an example of EDITPD; I verified a successful invocation of the former, but [could compile but] could not generate a valid instruction stream for the latter presumably due to a poor prototype.

FWiW I believe the MI SETDP instruction optionally can be used to assign the data type, length and decimal places [precision and scale], and the address to the data, if a data pointer were to be used. There seems no need for a DtaPtr, for use of the bound-program-access EDIT procedures _LBEDIT and _EDITPD.?

Regards, Chuck

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.