Difference between revisions of "Get Scan Count"
From MidrangeWiki
DaveLClarkI (talk | contribs) |
DaveLClarkI (talk | contribs) (→Summary) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
== 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 retrieve a count of the number of times a needle is found in a haystack. | 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 retrieve a count of the number of times a needle is found in a haystack. | ||
+ | |||
+ | By [[User:DaveLClarkI|Dave Clark]] | ||
== Service Prototype == | == Service Prototype == | ||
Line 21: | Line 23: | ||
Place the following in a service program source member. | Place the following in a service program source member. | ||
<pre> | <pre> | ||
+ | **free | ||
+ | ctl-opt NoMain AlwNull(*UsrCtl) Debug Option(*SrcStmt:*NoDebugIo) | ||
+ | DatFmt(*ISO) TimFmt(*ISO); | ||
+ | |||
//****************************************************************************** | //****************************************************************************** | ||
// Get a count of the number of times needle was found in haystack. | // Get a count of the number of times needle was found in haystack. |
Latest revision as of 15:59, 17 December 2018
Summary
The following are the RPG/LE fully free-form definitions and instructions needed for using the Get Scan Count service procedure. This service procedure simply allows the caller to retrieve a count of the number of times a needle is found in a haystack.
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 //****************************************************************************** // Get a count of the number of times needle was found in haystack. //****************************************************************************** dcl-pr GenUtl_GetScanCount int(10); pNeedle varchar(256) value; pHaystack varchar(65535) value; 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); //****************************************************************************** // Get a count of the number of times needle was found in haystack. //****************************************************************************** dcl-proc GenUtl_GetScanCount export; dcl-pi *n int(10); pNeedle varchar(256) value; pHaystack varchar(65535) value; end-pi; dcl-s Posn packed(5:0); dcl-s haystackLength packed(5:0); dcl-s scanCount int(10); scanCount = *zero; // initialize counter haystackLength = %len(pHaystack); // one-time retrieval of length Posn = %scan(pNeedle: pHaystack); // find first occurrence dow Posn > *zero // loop on needles and Posn <= haystackLength; // within the haystack scanCount += 1; // count it if (Posn + %len(pNeedle)) <= haystackLength; // beyond end of haystack? Posn = %scan(pNeedle: pHaystack: Posn + %len(pNeedle)); // no, search again else; // else Posn = *zero; // needle can't fit in remaining haystack endif; enddo; // end of loop on needles return scanCount; // return scan count end-proc;