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



thanks chris but data precision and scale must be dynamically coded

jay

On Fri, Feb 28, 2020 at 1:30 PM Hiebert, Chris <chris.hiebert@xxxxxxxxxxxxxx>
wrote:

Here is a function I wrote many years ago to translate a character string
containing a packed decimal into a string that can be passed into the %DEC
bif.

https://code.midrange.com/3f624ce206.html


Dcl-Pr Utl_FmtNumForDec Varchar(128) Opdesc;
String Varchar(128) Const;
Precision Int(5) Options( *NOPASS ) Const;
Decimalplaces Int(5) Options( *NOPASS ) Const;
Assumedecimal Ind Options( *NOPASS ) Const;
Ignorenegative Ind Options( *NOPASS ) Const;
Digitsonly Ind Options( *NOPASS ) Const;
Perrords Char(512) Options(*VARSIZE:*OMIT:*NOPASS);
Validstrict Ind Options( *NOPASS ) Const;
End-Pr;


usage:

DCL-S FLD2 VARCHAR(128);
DCL-S fld1 CHAR(7);
DCL-S FLD3 PACKED(7:2);
fld1 = '002632J';
FLD2 = UTL_FMTNUMFORDEC(fld1:7:2:*ON:*OFF);
FLD3 = %DEC( FLD2 : 7:2);



I use this in lots of places where I want to cleanup user input and then
convert it to a numeric field.
Originally I wrote it because I wanted something I could code in FREE that
would replace the MOVE opp code for packed decimal conversions.


I have this in a service program with other functions.
The snippet also includes another function that was needed to format an
error data-structure, which I included so people can compile.

Chris Hiebert
Senior Programmer/Analyst
Disclaimer: Any views or opinions presented are solely those of the author
and do not necessarily represent those of the company.


-----Original Message-----
From: MIDRANGE-L <midrange-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Jay
Vaughn
Sent: Friday, February 28, 2020 10:22 AM
To: Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxxxxxxxx>
Subject: Re: parse a negative number out of a before image string

I hate to beat a dead horse with this topic but never really found a
solution using only RPG... my solution was derived from using SQL, but now
I need an RPG solution only.

So running with Barbara's suggestion...

challenge - extract for a number of bytes, the length of a packed decimal
value (may contain decimals) objective - convert that clear text value

Jay
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/midrange-l.

Please contact support@xxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
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.