Difference between revisions of "Make Quoted String"

From MidrangeWiki
Jump to: navigation, search
(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...")
 
(Summary)
Line 2: Line 2:
 
== 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 create a single-quoted string out of another character string that may or may not have embedded single quotes in it.
 
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 create a single-quoted string out of another character string that may or may not have embedded single quotes in it.
 +
{| class="wikitable"
 +
|+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).
 +
|}
  
 
== Service Procedure ==
 
== Service Procedure ==

Revision as of 17:46, 13 December 2018

Summary

The following are the RPG/LE fully free-form definitions and instructions needed for using the Make Quoted String service procedure. This service procedure simply allows the caller to create a single-quoted string out of another character string that may or may not have embedded single quotes in it.

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).

Service Procedure

**free

//==============================================================================
// This procedure returns the supplied string as a single-quoted string
// with any embedded single-quotes appropriately doubled.
//==============================================================================
dcl-pr GenUtl_MakeQuotedString    varchar(4096) rtnparm;
  pString                         varchar(3000) const;
end-pr;

//==============================================================================
// This procedure returns the supplied string as a single-quoted string
// with any embedded single-quotes appropriately doubled.
//==============================================================================
dcl-proc GenUtl_MakeQuotedString  export;
  dcl-pi *n                       varchar(4096) rtnparm;
    pString                       varchar(3000) const;
  end-pi;

  return ( ''''
         + GenUtl_ScanAndReplace('''': %trimr(pString): '''''')
         + '''' );                     // return resulting entry
end-proc;

References