Difference between revisions of "Suffix String"
From MidrangeWiki
DaveLClarkI (talk | contribs) (→References) |
DaveLClarkI (talk | contribs) |
||
(10 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 extract the right-most non-blank '''''n''''' characters from a supplied 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 extract the right-most non-blank '''''n''''' characters from a supplied string. | ||
− | == Service | + | By [[User:DaveLClarkI|Dave Clark]] |
+ | |||
+ | == 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 16: | Line 21: | ||
PadChar char(1) const options(*nopass); | PadChar char(1) const options(*nopass); | ||
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 57: | Line 70: | ||
end-proc; | end-proc; | ||
</pre> | </pre> | ||
+ | |||
+ | == Example == | ||
+ | See the [[Is Generic Match]] service procedure. | ||
== References == | == References == | ||
− | * [[ | + | * [[Right String|GenUtl_RightString]] service procedure |
Latest revision as of 17:42, 17 December 2018
Summary
The following are the RPG/LE fully free-form definitions and instructions needed for using the Suffix String service procedure. This service procedure simply allows the caller to extract the right-most non-blank n characters from a supplied string.
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 //============================================================================== // After removing blanks on the right, return requested number of bytes of // suffix characters -- optional padding on the left. //============================================================================== dcl-pr GenUtl_SuffixString varchar(256) rtnparm; OrigString varchar(65535) const; ByteCount packed(3:0) const; PadChar char(1) const options(*nopass); 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); //============================================================================== // After removing blanks on the right, return requested number of bytes of // suffix characters -- optional padding on the left. //============================================================================== dcl-proc GenUtl_SuffixString export; dcl-pi *n varchar(256) rtnparm; OrigString varchar(65535) const; ByteCount packed(3:0) const; PadChar char(1) const options(*nopass); end-pi; dcl-s StrLeng like(ByteCount); dcl-s NewString varchar(256) inz(''); dcl-s PadString char(256) inz(*blanks); NewString = GenUtl_RightString( %trimr(OrigString) // trim blanks to : %len(NewString:*max) ); // determine suffix StrLeng = ByteCount; // start with bytes requested if %parms < %parmnum(PadChar) // if no padding and or StrLeng > %len(NewString); // request greater than string supplied StrLeng = %len(NewString); // take supplied string length endif; if StrLeng > *zero; // if something to return if StrLeng > %len(PadString); // if more than what can return StrLeng = %len(PadString); // set to max return length endif; if %parms < %parmnum(PadChar); // if no padding NewString = %subst(NewString: %len(NewString) - StrLeng + 1); else; // else, with right padding NewString = %subst( %xlate(' ': PadChar: PadString) + NewString : %len(PadString) + %len(NewString) - StrLeng + 1 ); endif; else; // else return ''; // nothing to return endif; return NewString; // return the suffix string end-proc;
Example
See the Is Generic Match service procedure.
References
- GenUtl_RightString service procedure