Difference between revisions of "Format Phone Number"

From MidrangeWiki
Jump to: navigation, search
Line 5: Line 5:
 
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 (re)format a USA phone number.
 
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 (re)format a USA phone number.
  
== 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 15: Line 16:
 
   PhoneValue            varchar(20)    const;
 
   PhoneValue            varchar(20)    const;
 
end-pr;
 
end-pr;
 +
</pre>
 +
 +
== Service Procedure ==
 +
Place the following in a service program source member.
 +
<pre>
 +
**free
  
 
//==============================================================================
 
//==============================================================================

Revision as of 16:09, 14 December 2018


Summary

The following are the RPG/LE fully free-form definitions and instructions needed for using the Format Phone Number service procedure. This service procedure simply allows the caller to (re)format a USA phone number.

Service Prototype

Place the following in a separate copybook for inclusion in both the caller and the service program source members.

**free

//==============================================================================
// Format phone number for output using a USA extended format.
//==============================================================================
dcl-pr GenUtl_FormatPhoneNo       varchar(20);
  PhoneValue            varchar(20)    const;
end-pr;

Service Procedure

Place the following in a service program source member.

**free

//==============================================================================
// Format phone number for output using a USA extended format.
//==============================================================================
dcl-proc GenUtl_FormatPhoneNo     export;
  dcl-pi *n             varchar(20);
    PhoneValue          varchar(20)    const;
  end-pi;

  dcl-s PhoneNo         like(PhoneValue);

  PhoneNo = GenUtl_StripFormatting(%trim(PhoneValue): ' ()+-.');

  if %len(PhoneNo) = *zero             // if blank
  or not GenUtl_isDigits(PhoneNo);     // or not all digits
    return PhoneNo;                    // return as-is (alpha phone number?)
  endif;

  if %len(PhoneNo) <= 7;               // no area code present?
    return %trim(%editw(%int(PhoneNo):'0      -    ')); // return 7-digit phone no
  endif;

  return %trim(%editw(%int(PhoneNo):'    0&(   )&   -    ')); // return formatted ph#
end-proc;

References