Difference between revisions of "Get Scan Count"
From MidrangeWiki
DaveLClarkI (talk | contribs) (→Service Procedure) |
DaveLClarkI (talk | contribs) (→Service Procedure) |
||
Line 23: | Line 23: | ||
**free | **free | ||
ctl-opt NoMain AlwNull(*UsrCtl) Debug Option(*SrcStmt:*NoDebugIo) | ctl-opt NoMain AlwNull(*UsrCtl) Debug Option(*SrcStmt:*NoDebugIo) | ||
− | DatFmt(*ISO) TimFmt(*ISO | + | DatFmt(*ISO) TimFmt(*ISO); |
//****************************************************************************** | //****************************************************************************** |
Revision as of 16:51, 14 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.
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;