Format Zip Code

From MidrangeWiki
Revision as of 20:21, 12 December 2018 by DaveLClarkI (talk | contribs) (Created page with "Category:Service Procedures == Summary == The following are the RPG/LE fully free-form definitions and instructions needed for using the {{AN}} service procedure. This se...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Summary

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

Service Procedure

**free

//==============================================================================
// Format USA zip code or foreign postal code for output.
//==============================================================================
dcl-pr GenUtl_FormatZipCode       varchar(10);
  ZipValue              varchar(10)    const;
end-pr;

//==============================================================================
// Format USA zip code or foreign postal code for output.
//==============================================================================
dcl-proc GenUtl_FormatZipCode     export;
  dcl-pi *n             varchar(10);
    ZipValue            varchar(10)    const;
  end-pi;

  dcl-s ZipCode         like(ZipValue);

  ZipCode = GenUtl_StripFormatting(%trim(ZipValue): ' +-.');

  if %len(ZipCode) = *zero             // if blank
  or not GenUtl_isDigits(ZipCode);     // or not all digits
    return ZipCode;                    // return as-is (alpha postal code?)
  endif;

  if %len(ZipCode) <= 5;               // no zip+4 present?
    return %editc(%int(ZipCode):'X');  // return 5-digit zip code
  endif;

  return %trim(%editw(%int(ZipCode):'0     -    ')); // return formatted zip+4
end-proc;

References