Example of string manipulation
This procedure takes a string (address)
and converts it. This could be used to
compare free format address lines across
multiple files.
for example this: 1722 CANdleWick Dr NW.
converts to : 1722 Candlewick Drive North West
(remember its just an example)
The copybook (used to make it easier to add procedure to programs)
to compile :
The procedure FMTADR
The program used to test....
fmtadrtest
compile: (fix the libraries)
the code
This procedure takes a string (address)
and converts it. This could be used to
compare free format address lines across
multiple files.
for example this: 1722 CANdleWick Dr NW.
converts to : 1722 Candlewick Drive North West
(remember its just an example)
The copybook (used to make it easier to add procedure to programs)
PHP Code:
* FMTADR Format address string as title
d fmtadr pr 256
d Instring 256 value
to compile :
PHP Code:
CRTRPGMOD MODULE(JAMIELIB/FMTADR) SRCFILE(JAMIELIB/SOURCE)
PHP Code:
H NOMAIN EXPROPTS(*RESDECPOS)
* PROGRAM - fmtadr
* PURPOSE - Subprocedure to format text string as a address
* WRITTEN -
* AUTHOR -
* Parameters
* Instring Char 256 both
* Indicator Usage
* None
* The FMTADR_CP copy member should be used by programs that call this subprocedure
* to obtain the procedure prototype fields.
/copy source,fmtadr_cp
d AfterString s 256
d BeforeString s 256
d Count s 4 0
d CurrentOne s 1
d LastCharacter s 1
*
d Up c CONST('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
d Lo c CONST('abcdefghijklmnopqrstuvwxyz')
*
* Begin Procedure
P fmtadr B export
* Procedure Interface
d fmtadr pi 256
d instring 256 value
/free
//
// Upper case the entire string to start process
//
clear AfterString;
beforestring = %Xlate(lo:up:Instring);
exsr $FormatAddress;
//
// Now lower case and only UPPER case the first letter in each group of
// letters seperated by spaces
//
beforestring = %Xlate(up:lo:beforestring);
for count = 1 to %len(%trim(beforestring));
if lastcharacter = *blanks or count = 1;
%subst(beforestring:count:1) =
%xlate(lo:up: %subst(beforestring:count:1));
endif;
lastcharacter = %subst(beforestring:count:1);
endfor;
Afterstring = Beforestring;
return AfterString;
//--------------------------------------------------------
// $FormatAddress - format the address
//--------------------------------------------------------
begsr $FormatAddress;
// fix the address replace stuff with other stuff
if %scan (' S.W. ':beforestring ) > *zeros;
beforestring =
%replace (' SOUTH WEST ' :
beforestring :
%scan (' S.W. ': beforestring ) :
6
);
endif;
if %scan ('S.W. ': beforestring ) > *zeros;
beforestring =
%replace (' SOUTH WEST ' :
beforestring :
%scan ('S.W. ': beforestring ) :
5
);
endif;
if %scan (' SW ': beforestring ) > *zeros;
beforestring =
%replace (' SOUTH WEST ' :
beforestring :
%scan (' SW ': beforestring ) :
4
);
endif;
if %scan (' SW. ': beforestring ) > *zeros;
beforestring =
%replace (' SOUTH WEST ' :
beforestring :
%scan (' SW. ': beforestring ) :
5
);
endif;
if %scan (' S.E. ': beforestring ) > *zeros;
beforestring =
%replace (' SOUTH EAST ' :
beforestring :
%scan (' S.E. ': beforestring ):
6
);
endif;
if %scan ('S.E. ': beforestring ) > *zeros;
beforestring =
%replace (' SOUTH EAST ' :
beforestring :
%scan ('S.E. ': beforestring ) :
5
);
endif;
if %scan (' SE ': beforestring ) > *zeros;
beforestring =
%replace (' SOUTH EAST ' :
beforestring :
%scan (' SE ': beforestring ) :
4
);
endif;
if %scan (' SE. ': beforestring ) > *zeros;
beforestring =
%replace (' SOUTH EAST ' :
beforestring :
%scan (' SE. ': beforestring ) :
5
);
endif;
if %scan (' N.W. ': beforestring ) > *zeros;
beforestring =
%replace (' NORTH WEST ' :
beforestring :
%scan (' N.W. ': beforestring ) :
6
);
endif;
if %scan ('N.W. ': beforestring ) > *zeros;
beforestring =
%replace (' NORTH WEST ' :
beforestring :
%scan ('N.W. ': beforestring ) :
5
);
endif;
if %scan (' NW ': beforestring ) > *zeros;
beforestring =
%replace (' NORTH WEST ' :
beforestring :
%scan (' NW ': beforestring ) :
4
);
endif;
if %scan (' NW. ': beforestring ) > *zeros;
beforestring =
%replace (' NORTH WEST ' :
beforestring :
%scan (' NW. ': beforestring ) :
5
);
endif;
if %scan (' N.E. ': beforestring ) > *zeros;
beforestring =
%replace (' NORTH EAST ' :
beforestring :
%scan (' N.E. ': beforestring ) :
6
);
endif;
if %scan ('N.E. ': beforestring ) > *zeros;
beforestring =
%replace (' NORTH EAST ' :
beforestring :
%scan ('N.E. ': beforestring ) :
5
);
endif;
if %scan (' NE ': beforestring ) > *zeros;
beforestring =
%replace (' NORTH EAST ' :
beforestring :
%scan (' NE ': beforestring ) :
4
);
endif;
if %scan (' NE. ': beforestring ) > *zeros;
beforestring =
%replace (' NORTH EAST ' :
beforestring :
%scan (' NE. ': beforestring ) :
5
);
endif;
//AVE = Avenue
if %scan (' AVE ': beforestring ) > *zeros;
beforestring =
%replace (' AVENUE ' :
beforestring :
%scan (' AVE ': beforestring ) :
5
);
endif;
if %scan (' AVE. ': beforestring ) > *zeros;
beforestring =
%replace (' AVENUE ' :
beforestring :
%scan (' AVE. ': beforestring ) :
6
);
endif;
if %scan (' AV. ': beforestring ) > *zeros;
beforestring =
%replace (' AVENUE ' :
beforestring :
%scan (' AV. ': beforestring ) :
5
);
endif;
if %scan (' AV ': beforestring ) > *zeros;
beforestring =
%replace (' AVENUE ' :
beforestring :
%scan (' AV ': beforestring ) :
4
);
endif;
//BLVD = Boulevard
if %scan (' BLVD. ': beforestring ) > *zeros;
beforestring =
%replace (' BOULEVARD ' :
beforestring :
%scan (' BLVD. ':beforestring ) :
7
);
endif;
if %scan (' BLVD ': beforestring ) > *zeros;
beforestring =
%replace (' BOULEVARD ' :
beforestring :
%scan (' BLVD ' : beforestring ):
6
);
endif;
if %scan (' BLD ': beforestring ) > *zeros;
beforestring =
%replace (' BOULEVARD ' :
beforestring :
%scan (' BLD ' : beforestring ) :
5
);
endif;
if %scan (' BOULV. ': beforestring ) > *zeros;
beforestring =
%replace (' BOULEVARD ' :
beforestring :
%scan (' BOULV. ':beforestring ):
8
);
endif;
//CT = Court
if %scan (' CT ': beforestring ) > *zeros;
beforestring =
%replace (' DRIVE ' :
beforestring :
%scan (' CT ' : beforestring ) :
4
);
endif;
if %scan (' CT. ': beforestring ) > *zeros;
beforestring =
%replace (' COURT ' :
beforestring :
%scan (' CT. ' : beforestring ) :
5
);
endif;
//DR = drive
if %scan (' DR ': beforestring ) > *zeros;
beforestring =
%replace (' DRIVE ' :
beforestring :
%scan (' DR ': beforestring ) :
4
);
endif;
if %scan (' DR. ': beforestring ) > *zeros;
beforestring =
%replace (' DRIVE ' :
beforestring :
%scan (' DR. ': beforestring ) :
5
);
endif;
if %scan (' DRI ': beforestring ) > *zeros;
beforestring =
%replace (' DRIVE ' :
beforestring :
%scan (' DRI ' : beforestring ) :
5
);
endif;
//HWY = Highway
if %scan (' HWY ': beforestring ) > *zeros;
beforestring =
%replace (' HIGHWAY ' :
beforestring :
%scan (' HWY ' : beforestring ) :
5
);
endif;
if %scan (' HWY. ': beforestring ) > *zeros;
beforestring =
%replace (' HIGHWAY ' :
beforestring :
%scan (' HWY. ' : beforestring ):
6
);
endif;
//LN = lane
if %scan (' LN. ': beforestring ) > *zeros;
beforestring =
%replace (' LANE ' :
beforestring :
%scan (' LN. ': beforestring ) :
5
);
endif;
if %scan (' LN ': beforestring ) > *zeros;
beforestring =
%replace (' LANE ' :
beforestring :
%scan (' LN ': beforestring ) :
4
);
endif;
//PKY = Parkway
if %scan (' PKY ': beforestring ) > *zeros;
beforestring =
%replace (' PARKWAY ' :
beforestring :
%scan (' PKY ': beforestring ) :
5
);
endif;
if %scan (' PKWAY ': beforestring ) > *zeros;
beforestring =
%replace (' PARKWAY ' :
beforestring :
%scan (' PKWAY ': beforestring ):
7
);
endif;
//PL = Place
if %scan (' PL ': beforestring ) > *zeros;
beforestring =
%replace (' PLACE ' :
beforestring :
%scan (' PL ': beforestring ) :
4
);
endif;
//RD = road
if %scan (' RD. ': beforestring ) > *zeros;
beforestring =
%replace (' ROAD ' :
beforestring :
%scan (' RD. ': beforestring ) :
5
);
endif;
if %scan (' RD ': beforestring ) > *zeros;
beforestring =
%replace (' ROAD ' :
beforestring :
%scan (' RD ': beforestring ) :
4
);
endif;
//ST = street
if %scan (' ST ': beforestring ) > *zeros;
beforestring =
%replace (' STREET ' :
beforestring :
%scan (' ST ': beforestring ) :
5
);
endif;
if %scan (' ST. ': beforestring ) > *zeros;
beforestring =
%replace (' STREET ' :
beforestring :
%scan (' ST. ': beforestring ) :
6
);
endif;
if %scan (' ST, ': beforestring ) > *zeros;
beforestring =
%replace (' STREET ' :
beforestring :
%scan (' ST, ': beforestring ) :
5
);
endif;
if %scan (' STR. ': beforestring ) > *zeros;
beforestring =
%replace (' STREET ' :
beforestring :
%scan (' STR. ': beforestring ) :
6
);
endif;
//PO
if %scan ('PO. ': beforestring ) > *zeros;
beforestring =
%replace ('PO ' :
beforestring :
%scan ('PO. ': beforestring ) :
4
);
endif;
if %scan ('P.O. ': beforestring ) > *zeros;
beforestring =
%replace ('PO ' :
beforestring :
%scan ('P.O. ': beforestring ) :
5
);
endif;
if %scan ('P. O. ': beforestring ) > *zeros;
beforestring =
%replace ('PO ' :
beforestring :
%scan ('P. O. ': beforestring ) :
6
);
endif;
if %scan ('P.O.BOX ': beforestring ) > *zeros;
beforestring =
%replace ('PO BOX ' :
beforestring :
%scan('P.O.BOX ':beforestring ) :
8
);
endif;
//company
if %scan (' CO. ': beforestring ) > *zeros;
beforestring =
%replace (' COMPANY ' :
beforestring :
%scan (' CO. ': beforestring ) :
5
);
endif;
//Department
if %scan (' DEPT ': beforestring ) > *zeros;
beforestring =
%replace (' DEPARTMENT ' :
beforestring :
%scan (' DEPT ': beforestring ) :
6
);
endif;
//Division
if %scan (' DIV ': beforestring ) > *zeros;
beforestring =
%replace (' DIVISION ' :
beforestring :
%scan (' DIV ': beforestring ) :
5
);
endif;
if %scan ('DIV.': beforestring ) > *zeros;
beforestring =
%replace (' DIVISION ' :
beforestring :
%scan ('DIV.': beforestring ) : 4);
endif;
//Building
if %scan (' BLDG ': beforestring ) > *zeros;
beforestring =
%replace (' BUILDING ' :
beforestring :
%scan (' BLDG ': beforestring ) :
6
);
endif;
if %scan (' E ': beforestring ) > *zeros;
beforestring =
%replace (' EAST ' :
beforestring :
%scan (' E ': beforestring ) :
3
);
endif;
if %scan (' E. ': beforestring ) > *zeros;
beforestring =
%replace (' EAST ' :
beforestring :
%scan (' E. ': beforestring ) :
4
);
endif;
if %scan (' E.': beforestring ) > *zeros;
beforestring =
%replace (' EAST ' :
beforestring :
%scan (' E.': beforestring ) :
3
);
endif;
if %scan (' W ': beforestring ) > *zeros;
beforestring =
%replace (' WEST ' :
beforestring :
%scan (' W ': beforestring ) :
3
);
endif;
if %scan (' W. ': beforestring ) > *zeros;
beforestring =
%replace (' WEST ' :
beforestring :
%scan (' W. ': beforestring ) :
4
);
endif;
if %scan (' W.': beforestring ) > *zeros;
beforestring =
%replace (' WEST ' :
beforestring :
%scan (' W.': beforestring ) :
3
);
endif;
if %scan (' S ': beforestring ) > *zeros;
beforestring =
%replace (' SOUTH ' :
beforestring :
%scan (' S ': beforestring ) :
3
);
endif;
if %scan (' S. ': beforestring ) > *zeros;
beforestring =
%replace (' SOUTH ' :
beforestring :
%scan (' S. ': beforestring ) :
4
);
endif;
if %scan (' S.': beforestring ) > *zeros;
beforestring =
%replace (' SOUTH ' :
beforestring :
%scan (' S.': beforestring ) :
3
);
endif;
if %scan (' N ': beforestring ) > *zeros;
beforestring =
%replace (' NORTH ' :
beforestring :
%scan (' N ': beforestring ) :
3
);
endif;
if %scan (' N. ': beforestring ) > *zeros;
beforestring =
%replace (' NORTH ' :
beforestring :
%scan (' N. ': beforestring ) :
4
);
endif;
if %scan (' N.': beforestring ) > *zeros;
beforestring =
%replace (' NORTH ' :
beforestring :
%scan (' N.': beforestring ) :
3
);
endif;
if %scan (' NO. ': beforestring ) > *zeros;
beforestring =
%replace (' NORTH ' :
beforestring :
%scan (' NO. ': beforestring ) :
5
);
endif;
// Remove the "-"
if %scan (' - ' : beforestring ) > *zeros;
beforestring =
%replace (' ' :
beforestring :
%scan (' - ' : beforestring ) :
3
);
endif;
if %scan (' -' : beforestring ) > *zeros;
beforestring =
%replace (' ' :
beforestring :
%scan (' -' : beforestring ) :
2
);
endif;
if %scan ('- ' : beforestring ) > *zeros;
beforestring =
%replace (' ' :
beforestring :
%scan ('- ' : beforestring ) :
2
);
endif;
if %scan ('-' : beforestring ) > *zeros;
beforestring =
%replace (' ' :
beforestring :
%scan ('-' : beforestring ) :
1
);
endif;
// Remove the ","
if %scan (' , ' : beforestring ) > *zeros;
beforestring =
%replace (' ' :
beforestring :
%scan (' , ' : beforestring ) :
3
);
endif;
if %scan (' ,' : beforestring ) > *zeros;
beforestring =
%replace (' ' :
beforestring :
%scan (' ,' : beforestring ) :
2
);
endif;
if %scan (', ' : beforestring ) > *zeros;
beforestring =
%replace (' ' :
beforestring :
%scan (', ' : beforestring ) :
2
);
endif;
if %scan (',' : beforestring ) > *zeros;
beforestring =
%replace (' ' :
beforestring :
%scan (',' : beforestring ) :
1
);
endif;
endsr;
//--------------------------------------------------------
/end-free
p fmtadr E
fmtadrtest
compile: (fix the libraries)
PHP Code:
CRTRPGMOD MODULE(JAMIELIB/FMTADRTEST) SRCFILE(JAMIELIB/SOURCE)
(then)
crtpgm jamielib/fmtadrtest module(fmtadrtest fmtadr)
PHP Code:
d myfield s 256
/copy source,FMTADR_CP
* ================================================
* M A I N L I N E
* ================================================
*
c eval myfield = '1722 CANdleWick Dr NW.'
c eval myfield = FMTADR(Myfield)
*
c eval *INLR = *On
Comment