In List
From MidrangeWiki
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.
By Dave Clark
Usage
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 Prototype
Place the following in a separate copybook for inclusion in both the caller and the service program source members.
**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;
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 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;
Example
See the Change Current Library service procedure.