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


  • Subject: Re: CL parameters over 32 length
  • From: Buck Calabro <kc2hiz@xxxxxxxxx>
  • Date: Thu, 5 Jul 2018 10:20:40 -0400
  • Autocrypt: addr=kc2hiz@xxxxxxxxx; keydata= xsDiBEcbaT4RBADqmM9OgXil65pjrxclJpxuAF6vraI3kkmJbEHb5ElL7EquHE3QDuFqFgIB 4NZLHDbVAh0AD5exAX+r+xg//UvtBc2k34HROnCpWTMnIOaSVhhVjpYEbZGLz6wfrRpu4Qyn 45iaKT4F0qcHo+0LrGQPef3xrFkUhxURgzY5zgo6+wCg/XjYJ155witPWB2CbNf6RAm9QT0D /jSp6YhvE3xPE12aBuRYM678JTbaQfuYv4HUfug1Wz/0zH5btfEihWVN4wbKaoQ/H/29v2TP /Lyh8XTVd3Z0rz4iaSD5fGicn81WPANBeIepLB8vpfEik6UhHpN1DJkz6Ryw2mgx8p53LhHV Ck4Jt0HP2TAl3f7QTXGFOiFzJwEqBACsHk/gFpKAHdv7n4vJoHqp0RNgOOyhnTThlulPilt6 tAaSe10FOrrugBuLMn7wXBANQ1ApmIb5yNjhYqPREj65OVv2MUbw8H2HnQs//Z6aodyR/kzU 2q2G9A/YFI1LL0m/gvaVbEj/wE0ybBgFkrcoEFeStkqS5HzLEFGUDFXhD80fQnVjayBDYWxh YnJvIDxrYzJoaXpAZ21haWwuY29tPsKFBBMRAgBFAhsDBgsJCAcDAgQVAggDBBYCAwECHgEC F4AFAkcbdMokGGh0dHA6Ly9rZXlzZXJ2ZXIudmVyaWRpcy5jb206MTEzNzEvAAoJEN7KcclH umuRfngAoNXU6AXqyTR8FRuoXKBGS4k7bPUEAJ912WKSkjpCt0axjrq6j22e5XgWzc7BTQRH G2k+EAgAnLXJ9hOqedgsIYM3LuomBBNN+7WTFSVaJ3Rqz8XVZtJvLL0bIRAvpVK9L9rYXlCR cPAm0YNK6H2DR7sQxWlxEH4mWB+jTCTALpcVq+Kpfbw5qDdn+9DVMS7tBOchtTlPSGgdKgn7 sTObra8cHtX/ddTB6OLzHeTXr4PZbUwVeQdIStdwMmozKBQvgjXWKi1GiuYbwYkCM/zJEUCs J36BIE4li9xohJ5O4iKC20YVckMJfZLbn1a2gVgn6Re8C5ezNewT0qM8ZDCUNENWAxsU/c9J UCFQ2QcMU+25b84D5yPxnEKna5U9Fz2JjRjWy5ZKZx2+WhZj0r2Tw6/kGb28AwADBgf/WBsn JSMHxyVfg+LKLHpdANwa9jdrKOt2WjJbWOiJ9l7SmqD0oi3c22FFxRXKsFfjCikLk9wbLZKH SqqnOePvMMHqNcqQTSv7+ARjxnBH4g6dhqg+zmebKpt8zV2awQzYSSm4YY6IqzkWmPNAN7BU zUtSAfL4UU2PljTnT9m443aVCTXMne5l90HQv/gdJ121owg5KuGE6LodTpoR4hn9nbdKWtfY pDNoykvR+GN5y335yF2Zp/j6QgdxWezjou5Y3/6PUZLEsJagWe9hAcKb1eiO2bmg+1bFYu0T g5Mvb27nqfFeHHFysC7a7sXtxp/pqNLNDcK6j/7Th6vF7/n98cJJBBgRAgAJBQJHG2k+AhsM AAoJEN7KcclHumuR9SgAnRuJWHon4GP58xbqCiFR/jSUfvRgAJ47KZ1UNoXgdftoePnbrZu6 W+poEw==
  • List-archive: <https://archive.midrange.com/midrange-l/>
  • List-help: <mailto:midrange-l-request@midrange.com?subject=help>
  • List-id: Midrange Systems Technical Discussion <midrange-l.midrange.com>
  • List-post: <mailto:midrange-l@midrange.com>
  • List-subscribe: <https://lists.midrange.com/mailman/listinfo/midrange-l>, <mailto:midrange-l-request@midrange.com?subject=subscribe>
  • List-unsubscribe: <https://lists.midrange.com/mailman/options/midrange-l>, <mailto:midrange-l-request@midrange.com?subject=unsubscribe>

On 7/5/2018 3:58 AM, Erwin Donker wrote:

So basically what I want to know is, why does using CL parameters over 32 characters sometimes work, and sometimes not?

tl;dr It always works.


Parameter passing is done by address - by a pointer.
The caller sets aside a variable in memory and passes a pointer to the
start of that memory to the callee.
In a programming language, we use some kind of declaration to explicitly
state the name, type and length of the variable like so:
DCL &CUSTNAME *CHAR 50
dcl-s cust_name char(50);

In this case, the caller is the command line - QCMD and friends.
There is no DCL.
There is no variable.
There is only a literal.

In order to pass a pointer to the address of the variable, QCMD needs
first to create a variable. Remember: QCMD is running, not the called
program. QCMD has no idea what the called program uses for parameter
definitions. No calling program on this system knows what the called
program's parameter definitions are like.

So QCMD needs to create a variable, but what type and size? It's a
simple program so it has simple rules:
1) IF the literal is numbers:
THEN create a variable PACKED(15 5)
2) IF the literal is not numbers
AND there are more than 32 characters in the literal
THEN create a variable CHAR(length(literal))
3) IF the literal is not numbers
AND there are 32 characters or less in the literal
THEN create a variable CHAR(32)

These simple rules have been in place from very, very early releases of
S/38 CPF. If our calling program insists on reading the first 512
characters of a 32 character variable, we get what we deserve.
Sometimes we catch a break and discover our error on the very first test
run. Sometimes, characters 32+1 through 512 contain blanks, and we
don't realise we wrote bad code for a long, long time.

Another question out of curiosity, this "problem" has been around at
least since 1998 and probably much longer (1998 was the oldest
information I found online). I see many people having issues with this,
so why has IBM never changed this?

This is how the system was designed.
These rules are what govern tens of millions of program calls.
It's not a problem, any more than gravity is a problem.
Follow the rules and it's completely reliable.


That said, in order to change this behaviour, here are several ideas you
might ask for in an RFE.

1) Alter the rules by which QCMD creates variables. Maybe always create
a 64k character variable. The resultant performance problems might be
fun to watch.

2) Alter the way programs are created. Have each program store the
parameter definitions. Expose those definitions via API. Alter QCMD et
al to inquire into what the caller expects, ignoring the actual literals
supplied, and create variables that always match between the command
line and every possible called program.

3) Alter the CALL command to allow for parameter definitions. So
instead of

CALL SOMEPGM ('parm1' 'parm2')

we might have

CALL SOMEPGM ('parm1' 'parm2') ARGDEF((*CHAR 50) (*CHAR 512))

While I myself haven't had an issue remembering the three rules, it is
2018. Maybe it's time to have IBM i deal handle parameters in a more
programmer-friendly way. Put in an RFE and see how the wind blows.

https://www.ibm.com/developerworks/rfe/?BRAND_ID=352


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.