Difference between revisions of "In List"

From MidrangeWiki
Jump to: navigation, search
(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...")
 
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
[[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.
  
== Example ==
+
See also [[Get List Entry]] and [[In String]].
 +
 
 +
By [[User:DaveLClarkI|Dave Clark]]
 +
 
 +
== Usage ==
 
Rather than coding the following:
 
Rather than coding the following:
 
<pre>
 
<pre>
Line 32: Line 38:
 
</pre>
 
</pre>
  
== Service Procedure ==
+
== Service Prototype ==
 +
Place the following in a separate copybook for inclusion in both the caller and the service program source members.
 
<pre>
 
<pre>
 
**free
 
**free
Line 45: Line 52:
 
   pHaystack            varchar(3000) const;
 
   pHaystack            varchar(3000) const;
 
end-pr;
 
end-pr;
 +
</pre>
 +
 +
== Service Procedure ==
 +
Place the following in a service program source member.
 +
<pre>
 +
**free
 +
ctl-opt NoMain AlwNull(*UsrCtl) Debug Option(*SrcStmt:*NoDebugIo)
 +
        DatFmt(*ISO) TimFmt(*ISO);
  
 
//==============================================================================
 
//==============================================================================
Line 75: Line 90:
 
end-proc;
 
end-proc;
 
</pre>
 
</pre>
 +
 +
== Example ==
 +
See the [[Change Current Library]] service procedure.

Latest revision as of 18:52, 10 July 2019


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.