In List

From MidrangeWiki
Revision as of 21:15, 12 December 2018 by DaveLClarkI (talk | contribs) (Created page with "Category:Service Procedures == Summary == The following are the RPG/LE fully free-form definitions and instructions needed for using the {{AN}} service procedure. This se...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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;