Difference between revisions of "Is Digits"

From MidrangeWiki
Jump to: navigation, search
(Summary)
(Examples)
 
(13 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
[[Category:Sample Code]]
 
[[Category:Service Procedures]]
 
[[Category:Service Procedures]]
 
== 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 validate that a character string is all numeric digits—or not.
 
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 validate that a character string is all numeric digits—or not.
 
{| class="wikitable"
 
{| class="wikitable"
|+Rule of Thumb
+
|+ style="padding-left:6px;text-align:left;"|Rule of Thumb
 
|-
 
|-
 
|Sometimes, having a service procedure is simply a means of making code more self-documenting (i.e., easier for others to understand).
 
|Sometimes, having a service procedure is simply a means of making code more self-documenting (i.e., easier for others to understand).
 
|}
 
|}
  
== Service Procedure ==
+
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 19: Line 23:
 
   pString              varchar(50) const;
 
   pString              varchar(50) 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 38: Line 50:
 
end-proc;
 
end-proc;
 
</pre>
 
</pre>
 +
 +
== Examples ==
 +
See the [[Format Phone Number]] service procedure.
 +
 +
See the [[Format Zip Code]] service procedure.

Latest revision as of 17:38, 17 December 2018

Summary

The following are the RPG/LE fully free-form definitions and instructions needed for using the Is Digits service procedure. This service procedure simply allows the caller to validate that a character string is all numeric digits—or not.

Rule of Thumb
Sometimes, having a service procedure is simply a means of making code more self-documenting (i.e., easier for others to understand).

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

//==============================================================================
// Validates variable-length character string for digits only.
//   Returns a Boolean true/false value as a result.
//==============================================================================
dcl-pr GenUtl_isDigits  ind;
  pString               varchar(50) 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);

//==============================================================================
// Validates variable-length character string for digits only.
//   Returns a Boolean true/false value as a result.
//==============================================================================
dcl-proc GenUtl_isDigits export;
  dcl-pi *n             ind;
    pString             varchar(50) const;
  end-pi;

  dcl-c GenUtl_Digits   '0123456789';

  if %len(pString) = *zero;            // if no supplied value
    return *off;                       // indicate not numeric
  endif;

  return (%check(GenUtl_Digits: pString) = *zero); // return result of check
end-proc;

Examples

See the Format Phone Number service procedure.

See the Format Zip Code service procedure.