Is Generic Match
From MidrangeWiki
Summary
The following are the RPG/LE fully free-form definitions and instructions needed for using the Is Generic Match service procedure. This service procedure simply allows the caller to determine if a character string is a generic or partial match for another character string—or not.
By Dave Clark
Service Prototype
Place the following in a separate copybook for inclusion in both the caller and the service program source members.
**free //============================================================================== // This procedure provides a Boolean result indicating whether or not the // first parameter is a generic (or partial) match of a second parameter. // Note that both kinds of matches are supported -- generic or partial -- // by comparing the first part of the second parameter based on the // length of the first parameter (after stripping any trailing asterisk). //============================================================================== dcl-pr GenUtl_isGenericMatch ind; pNeedle varchar(50) const options(*trim); pHayStack varchar(50) const options(*trim); end-pr;
Service Procedure
Place the following in a service program source member.
**free ctl-opt NoMain AlwNull(*UsrCtl) Debug Option(*SrcStmt:*NoDebugIo) DatFmt(*ISO) TimFmt(*ISO); //============================================================================== // This procedure provides a Boolean result indicating whether or not the // first parameter is a generic (or partial) match of a second parameter. // Note that both kinds of matches are supported -- generic or partial -- // by comparing the first part of the second parameter based on the // length of the first parameter (after stripping any trailing asterisk). //============================================================================== dcl-proc GenUtl_isGenericMatch export; dcl-pi *n ind; pNeedle varchar(50) const options(*trim); pHayStack varchar(50) const options(*trim); end-pi; dcl-s iNeedle like(pNeedle); if GenUtl_SuffixString(pNeedle:1) = '*'; // if generic indicator present iNeedle = %subst(pNeedle: 1: %len(pNeedle)-1); // strip it off else; // else iNeedle = pNeedle; // take the string as-is endif; if %len(iNeedle) > %len(pHayStack); // if needle bigger than haystack return *off; // then a compare is not possible endif; return (iNeedle = %subst(pHayStack:1:%len(iNeedle))); // return result end-proc;
References
- GenUtl_SuffixString service procedure