Parse Integer
From MidrangeWiki
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
- GenUtl_LeftString service procedure