Difference between revisions of "Add List Delimiter"

From MidrangeWiki
Jump to: navigation, search
Line 26: Line 26:
 
Place the following in a service program source member.
 
Place the following in a service program source member.
 
<pre>
 
<pre>
 +
**free
 +
 
//==============================================================================
 
//==============================================================================
 
// If the supplied variable-length string (or list) has a length greater than
 
// If the supplied variable-length string (or list) has a length greater than

Revision as of 15:59, 14 December 2018

Summary

The following are the RPG/LE fully free-form definitions and instructions needed for using the Add List Delimiter service procedure. This service procedure simply allows the caller to conditionally add a delimiter string to another (or "master") character string when the master character string has a length greater than zero (meaning: it already has content in it).

Service Prototype

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

**free

//==============================================================================
// If the supplied variable-length string (or list) has a length greater than
// zero, then this procedure adds the supplied delimiter to the end of that
// string on return.  Otherwise, the string is returned unchanged.
// This can also be used, for example, for dynamically building command (or SQL)
// character strings that have conditional content without having to know
// whether the built string already has content--or not. 
//==============================================================================
dcl-pr GenUtl_AddListDelimiter varchar(65530) rtnparm;
  pList                        varchar(65530) const;
  pDelimiter                   varchar(30)    const;
end-pr;

Service Procedure

Place the following in a service program source member.

**free

//==============================================================================
// If the supplied variable-length string (or list) has a length greater than
// zero, then this procedure adds the supplied delimiter to the end of that
// string on return.  Otherwise, the string is returned unchanged.
// This can also be used, for example, for dynamically building command (or SQL)
// character strings that have conditional content without having to know
// whether the built string already has content--or not. 
//==============================================================================
dcl-proc GenUtl_AddListDelimiter  export;
  dcl-pi *n             varchar(65530) rtnparm;
    pList               varchar(65530) const;
    pDelimiter          varchar(30)    const;
  end-pi;

  if %len(pList) <= *zero;      // if list is empty
    return pList;               // return unchanged list
  endif;

  return (pList + pDelimiter);         // return resulting list
end-proc;