× 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 Thu, 14 Aug 2003, Fisher, Don wrote:
>
> Wow, they haven't fixed this even in V5R2?

They haven't "fixed" this because they haven't figured out how to
incorporate mind-reading into the operating system yet.

If you type CALL PGM(BAR) PARM('foo')  how does it know how long 'foo'
needs to be?   Is it 3?  Is it 10?  is it 250?  See the problem?

So, IBM came up with a set of rules which they expect programmers to
follow.  All numeric variables are passed as *DEC 15,5, and all
alphanumeric variables are passed as *CHAR 32.  If the string that the
user has placed in an alphanumeric variable exceeds the 32 characters,
then the memory is allocated large enough for the entire value.

For short variables this doesn't cause a problem.   32 chars are
allocated, but the program only examines the first 10, or 16 or whatever
you're using.  No harm is done.

But, if you do a PARM('foo') when the program is expecting 50 bytes, then
the program receives 'foo' followed by 29 blanks.  Yet, the program is
trying to another 18 bytes past those 32 -- which hasn't been allocated to
it, and therefore can be anything... just whatever happens to be in RAM at
that position...

> When submitting a CL program to batch with character parameters, any blank
> characters beyond the 32nd have the potential to be populated with random
> characters from memory.

No.  They're not "populated" at all.   You're accessing memory that wasn't
assigned to you, and you get whatever happens to be there.

> There are probably some ways to deal with this in the archives as I think
> this topic came up not more than a few months ago.

Its in the FAQ, as well.

> The way I deal with it is to pass a numeric parameter with the number of
> characters placed in the field, which would be 0 in your case.  I then
> have the program extract the characters using substring functions.  You
> can also make the parameter two parameters.

That would work.

Another common solution is to create a *CMD object to call your program
with.   The *CMD will define the lengths of all of the parameters, so when
you execute it, the system knows how much to allocate to each parameter.



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.