Difference between revisions of "In List"
From MidrangeWiki
DaveLClarkI (talk | contribs) (→Summary) |
DaveLClarkI (talk | contribs) |
||
Line 1: | Line 1: | ||
[[Category:Sample Code]] | [[Category:Sample Code]] | ||
[[Category:Service Procedures]] | [[Category:Service Procedures]] | ||
+ | __FORCETOC__ | ||
== Summary == | == Summary == | ||
The following are the RPG/LE fully free-form definitions and instructions needed for using the {{AN}} service procedure. This service procedure simply allows the caller to check if a character string is in a comma-separated list of possible matches—or not. See also [[Get List Entry]] and [[In String]]. | The following are the RPG/LE fully free-form definitions and instructions needed for using the {{AN}} service procedure. This service procedure simply allows the caller to check if a character string is in a comma-separated list of possible matches—or not. See also [[Get List Entry]] and [[In String]]. |
Revision as of 19:46, 13 December 2018
Contents
Summary
The following are the RPG/LE fully free-form definitions and instructions needed for using the In List service procedure. This service procedure simply allows the caller to check if a character string is in a comma-separated list of possible matches—or not. See also Get List Entry and In String.
Example
Rather than coding the following:
if pTblData.AUDRSN <> 'UND' and pTblData.AUDRSN <> 'DEF' and pTblData.AUDRSN <> 'RMV' and pTblData.AUDRSN <> 'PGN' and pTblData.AUDRSN <> 'LBN' and pTblData.AUDRSN <> 'FLN' and pTblData.AUDRSN <> 'FLQ' and pTblData.AUDRSN <> 'TGN' and pTblData.AUDRSN <> 'TGQ' and pTblData.AUDRSN <> 'TGO' and pTblData.AUDRSN <> 'MDE' and pTblData.AUDRSN <> 'EVT' and pTblData.AUDRSN <> 'EVC' and pTblData.AUDRSN <> 'EVO'; // indicate validation failure endif;
this service procedure allows the following simplified coding for the same result.
if not GenUtl_inList( pTblData.AUDRSN: 'UND,DEF,RMV,PGN,LBN,FLN,FLQ,' + 'TGN,TGQ,TGO,MDE,EVT,EVC,EVO' ); // indicate validation failure endif;
Service Procedure
**free //============================================================================== // This procedure determines if a needle is found in a haystack. The // haystack is expected to be a comma-separated list of possible matches. // Returns a Boolean true/false value as a result. //============================================================================== dcl-pr GenUtl_InList ind; pNeedle varchar(50) const; pHaystack varchar(3000) const; end-pr; //============================================================================== // This procedure determines if a needle is found in a haystack. The // haystack is expected to be a comma-separated list of possible matches. // Returns a Boolean true/false value as a result. //============================================================================== dcl-proc GenUtl_InList export; dcl-pi *n ind; pNeedle varchar(50) const; pHaystack varchar(3000) const; end-pi; dcl-c GenUtl_lower 'abcdefghijklmnopqrstuvwxyz'; dcl-c GenUtl_UPPER 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; dcl-s iHaystack varchar(3002); iHaystack = %trim(pHaystack); // make sure haystack is trimmed iHaystack = %xlate( GenUtl_lower: GenUtl_UPPER: pHaystack ); if %subst(iHaystack:1:1) <> ','; // if no starting separator iHaystack = ',' + iHaystack; // put one there endif; if %subst(iHaystack:%len(iHaystack):1) <> ','; // if no ending separator iHaystack += ','; // put one there endif; return (%scan( ','+%xlate(GenUtl_lower: GenUtl_UPPER: %trim(pNeedle))+',' : iHaystack ) > *zero ); // indicate if found end-proc;