Difference between revisions of "Parse Integer"

From MidrangeWiki
Jump to: navigation, search
(Created page with "Category:Sample Code Category:Service Procedures __FORCETOC__ == Summary == The following are the RPG/LE fully free-form definitions and instructions needed for using...")
 
(Summary)
 
Line 4: Line 4:
 
== 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 extract an integer value that is embedded in a character string with other (alpha) data.
 
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 extract an integer value that is embedded in a character string with other (alpha) data.
 +
 +
By [[User:DaveLClarkI|Dave Clark]]
  
 
== Service Prototype ==
 
== Service Prototype ==

Latest revision as of 16:10, 17 December 2018


Summary

The following are the RPG/LE fully free-form definitions and instructions needed for using the Parse Integer service procedure. This service procedure simply allows the caller to extract an integer value that is embedded in a character string with other (alpha) data.

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

//******************************************************************************
// This procedure parses the first blank-delimited "word" of a character string
// into an integer format as a return result.  If the first "word" cannot be
// parsed into an interger format then the caller must monitor for the exception
// which will occur as a result.
//******************************************************************************
dcl-pr GenUtl_parseInteger   int(20);
  pString                    varchar(40) value;
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);

//******************************************************************************
// This procedure parses the first blank-delimited "word" of a character string
// into an integer format as a return result.  If the first "word" cannot be
// parsed into an interger format then the caller must monitor for the exception
// which will occur as a result.
//******************************************************************************
 dcl-proc GenUtl_parseInteger export;
   dcl-pi *n                 int(20);
     pString                 varchar(40) value;
   end-pi;

   dcl-s pos                 packed(3:0);

   pString = %trim(pString) + ' ';     // trim off all but one blank
   pos = %scan(' ': pString);          // find first blank in string

   return %int(GenUtl_LeftString(pString:pos)); // return parsed value
 end-proc;

References