|
-----Original Message----- From: rpg400-l-admin@midrange.com [mailto:rpg400-l-admin@midrange.com]On Behalf Of Hans Boldt Sent: Thursday, November 21, 2002 10:10 AM To: rpg400-l@midrange.com Subject: Re: CL pgm and pointer variables >Steve Richter wrote: >> Of course I validate input, just as an appl programmer should! I am being >> minimal in my example for the purpose of clarity. To add validatation to >> example I describe a 3rd array could be added. The 1st array contains data >> pointers to the pgm variables to be populated, the 2nd array contains the >> field names of those variables as appears in the stdin stream received from >> the browser and the 3rd array contains error information retrieved when the >> stdin char data ( "fld1=22.5&fld2=abc+efg&...." ) could not be mapped into >> the data pointer addressed variable. >> >> I challenge you or others to show how this very important and common task of >> mapping data from the browser stdin stream into variables in a program could >> be done as directly and efficiently as can be done with data pointers. >First, if I recall correctly, data pointers are not terribly >efficient. (Which is just one reason why data pointers aren't put to >more use.) Data pointers must be more efficient than the equivalent "DecVar = CvtCharToDec( string )". The conversion from unstructured char string to numeric variable has to be done and will take multiple steps to do it. The data pointer is best because it pushes many details below the abstraction level the appl programmer operates at. d dpVar s * dataptr d OrderQty s 9p 2 d StdInString s 999a varying dpVar = %SetDataPtr( OrderQty ) ; ParseAndExtractFromEnvString( dpVar: 'OrderQty': StdInString ) ; >Second, the conversion of a character value to the appropriate data >type typically involves only a single assignment anyways, for example: > fld1 = %dec(envvar('fld1'):7:2); > fld2 = envvar('fld2'); >And so not a lot of code is saved by using some common mechanism. In >fact, if three arrays need to be set up to be able to use a common >routine, I suspect that would require even more coding! Your example above does not handle a char to numeric conversion error. But I agree, your method is similar to a conversion that uses a data pointer. The problem with the non data pointer method is the hard coding of the data defn of the target variable. My hypothetical: dpVar = %SetDataPtr( OrderQty ) ; is error and database change proof. Your example requires the pgmr to correctly type the "7:2" and also find and change all its instances when the field is expanded to "9:2" at a later date. btw, rpg programmers too often have to use this method of hard coding of variable attributes. Any chance that %DataType(variableName), %DataLength(variable), %DataPrecision(variable) built ins will be introduced to rpg? thank you, Steve Richter
As an Amazon Associate we earn from qualifying purchases.
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.