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



Sorry, forgive my stupidity. Why would someone ever want to left-fill a character field with zeros? I mean -- from a character field point of view, the zeros don't mean anything. And you're not populating a numeric field (or, if you are, there are MUCH better ways).

So... what's up? Is this some weird file format required by a customer?

But if you really want to concatenate a string of zeros to the front, and you don't want to hardcode the value (like 15 zeros) you could do something like this:

D zeros s like(coldta) inz(*zeros)

/free
coldta = %subst(zeros:1:cwdth(#col)-%len(coldta)) + coldta;

That way, no matter what the size of the coldta field is, you know you always have enough zeros to fill it.

But... why do this?


Terrence Enger wrote:
On Wed, 2009-03-25 at 14:27 -0500, Kurt Anderson wrote:
Using that example, you could, if you wanted, use *zeros instead of a line of 0's:
coldta = %subst( *zeros: 1: cwdth( #col ) - %len( coldta ) ) + coldta;

Um, not at V5R2, where the attempt tells me RNF0361 "The first parameter
*ZEROS for %SUBST is not valid; built-in function is ignored."

I typed 15 zeros because I rarely see numeric fields larger than that.
(Well, my preference for *CMD definitions largely protects me from even
those, but that is a fetish for me to flog some other day <grin />.)
Still, I am not entirely comfortable stopping there. How can the
compiler, not even knowing that coldta represents a number, do any
better?

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.