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



For numeric editing, a "data pointer" is what easily resolves the issue for variable precision & scale. Last I recall reading [on one of the lists here], they are still not available as part of the RPG, but they are available via the MI.

As for using the edit codes A & B, AFaIK the only difference is that the latter effects "blanks for a zero value" versus some amount of the character\digits zero & optionally a decimal separator effected by the former. Thus I would expect a variation of the following may be able to rid of all the extra edtcde(B) processing; perhaps by testing each precision value separately to achieve identical rounded results as currently coded:

<code>

If Amount=0;
rtnAmount = '';
Else;
Select;
When w_DecPos = 0;
Amt0Dec = Amount;
rtnAmount = %trim( %editc( Amt0Dec: 'A': *CURSYM ) );
When w_DecPos = 1;
Amt1Dec = Amount;
rtnAmount = %trim( %editc( Amt1Dec: 'A': *CURSYM ) );
When w_DecPos = 2;
Amt2Dec = Amount;
rtnAmount = %trim( %editc( Amt2Dec: 'A': *CURSYM ) );
EndSl;
EndIf;

</code>

The edit mask API can be used to generate the mask for those three variations of the numeric scale [optionally to use stored masks; i.e. retrieved masks versus created during runtime] and then the address of which mask to use can be assigned just before the call to the edit API. Although a reduction to one /edit invocation/ is achieved, that alone does not get the call into the assignment itself.

Regards, Chuck

Kurt Anderson wrote:
%kds - number of keys to use has to be a constant
%dec - length and decimal positions have to be constants
%editc - edit code has to be constant

I'm working with amounts that I'm writing to XML. They can have differing decimal precision based on the client processed. I thought, wonderful, I can create a procedure, pass in some parameters, and simply insert those parms into a statement to
format my return value. If only it were so easy. But why isn't
it? What is the purpose of making BIF parms requiring constant
values? Where is the flexibility in that? I suppose it may be
easier on the RPG developers, but is it better for the language?

Info about my example. Amounts are already rounded to the needed precision. Also, we go out to 6 decimals, I cut the example down
to only going out to two decimals.

So in my example, instead of being able to code:
rtnAmount = %trim( %editC( %dec( Amount: LEN_Amount: w_DecPos)
: EditCode: *CurSym);

I have to code:

<code>

Select;
When w_DecPos = 0;
Amt0Dec = Amount;
Select;
When EditCode = 'A';
rtnAmount = %trim( %editc( Amt0Dec: 'A': *CURSYM ) );
When EditCode = 'B';
rtnAmount = %trim( %editc( Amt0Dec: 'B': *CURSYM ) );
EndSl;
When w_DecPos = 1;
Amt1Dec = Amount;
Select;
When EditCode = 'A';
rtnAmount = %trim( %editc( Amt1Dec: 'A': *CURSYM ) );
When EditCode = 'B';
rtnAmount = %trim( %editc( Amt1Dec: 'B': *CURSYM ) );
EndSl;
When w_DecPos = 2;
Amt2Dec = Amount;
Select;
When EditCode = 'A';
rtnAmount = %trim( %editc( Amt2Dec: 'A': *CURSYM ) );
When EditCode = 'B';
rtnAmount = %trim( %editc( Amt2Dec: 'B': *CURSYM ) );
EndSl;
EndSl;

</code>

If I'm missing something and there's an easier way to do what I'm
doing, please let me know.


As an Amazon Associate we earn from qualifying purchases.

This thread ...


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.