Source Member: QRPGLESRC,FDXAVTR
H COPYRIGHT('Copyright (C) 2008 Krengel Technology, Inc.')
H DATFMT(*ISO) TIMFMT(*ISO)
*
*?FedEx Address Verification
*
*?SYNOPSIS: This program is a front-end to the FDX_verifyAddress()
*? procedure. It allows a user to enter an address and see
*? a list of matching addresses.
*
*? If it is called with no parameters or with a blank
*? address, an initial screen is displayed allowing the
*? user to enter an address to validate. If an address is
*? passed as a parameter, the address is verified, the main
*? subfile screen is displayed and the user can select an
*? address to return to the calling program. In this way,
*? this program can be called directly from existing
*? applications.
*
*---------------------------------------------------------------------
FFDXAVTD CF E WORKSTN
F SFILE(SFLRCD:RRN)
*=====================================================================
D ThisProgram C 'FDXAVTR'
*
D/COPY RXS,RXSCP ?RPG-XML Suite
D/COPY RXS,FDXCP ?FedEx Address Verification
D DETAILFMT E DS EXTNAME(FDXAVTD:DETAIL)
D X S 10I 0
D Exit S N
D Valid S N
D cP_grn C x'20'
D cP_wht C x'22'
D cP_grn_ul C x'24'
D cP_red C x'28'
D cP_wht_pr C x'A2'
D AddressV S 256A Varying
D addr ds inz likeds(address_t)
D initaddr ds inz likeds(address_t)
D gInput ds inz likeds(FDXAV_Input)
D gOutput ds inz likeds(FDXAV_Output)
D gError ds inz likeds(RXS_Error)
*---------------------------------------------------------------------
D main PR Extpgm(ThisProgram)
D pAddress Likeds(address_t) Options(*Nopass)
D main PI
D pAddress Likeds(address_t) Options(*Nopass)
*=====================================================================
*?MAINLINE
*=====================================================================
/free
exsr initSR;
dou Exit = *on;
//?Display detail screen for input
Mode = cP_grn_ul; //?Display fields in input mode
dou Valid = *on;
exsr displayDetail;
if *in12;
exsr return;
endif;
exsr verifyAddress;
enddo;
//?Display the main subfile screen
initaddr = addr;
exsr formatAddress;
SELADR = AddressV;
exsr LoadSfl;
dou Exit = *on;
write CMDKEY;
exfmt SFLCTL;
select;
when *in03; //?F3=Exit
exsr return;
when *in05; //?F5=Refresh
clear addr;
leave;
when *in12; //?F12=Cancel
addr = initaddr;
leave;
other;
readc(e) SFLRCD;
dow not %error and not %eof;
select;
when SFLSEL = '1'; //?1=Select
Exit = *on;
if %parms > 0;
pAddress = addr;
endif;
leave;
when SFLSEL = '5'; //?5=Display
Mode = cP_wht_pr;
addr = RADDR;
if addr.SErrType <> *blanks;
ERRDATA = %trimr( addr.SErrType ) + ': ' +
addr.SErrMsg;
endif;
exsr displayDetail;
other;
endsl;
SFLSEL = *blanks;
update SFLRCD;
readc(e) SFLRCD;
enddo;
endsl;
enddo;
enddo;
exsr return;
//?displayDetail: Display the detail screen
begsr displayDetail;
dou *in05 = *off;
DETAILFMT = addr;
write CMDKEY;
exfmt DETAIL;
addr = DETAILFMT;
clear ERRDATA;
select;
when *in03;
exsr return;
when *in05;
clear addr;
when *in12;
leave;
other;
endsl;
enddo;
endsr;
//?verifyAddress: Verify the address using the FedEx web service
begsr verifyAddress;
Valid = *off;
//?Set up parameters to FDX_verifyAddress()
gInput.company = addr.company;
gInput.line1 = addr.line1;
gInput.line2 = addr.line2;
gInput.city = addr.city;
gInput.state = addr.state;
if %subst( addr.zipcode : 6 : 1 ) = '-';
gInput.zipcode = %subst( addr.zipcode : 1 : 5 ) +
%subst( addr.zipcode : 7 : 4 );
else;
gInput.zipcode = addr.zipcode;
endif;
gInput.urbname = addr.urbname;
clear gOutput;
clear gError;
//?Call FDX_verifyAddress()
FDX_verifyAddress( gInput : gOutput : gError );
//?Check for errors returned from FDX_verifyAddress()
select;
when gError.code <> *blanks; //?RXS-XML error
ERRDATA = 'ERROR: ' + gError.text;
when gOutput.HErrCode <> *blanks; //?FedEx error
ERRDATA = 'ERROR: ' + gOutput.HErrMsg;
other;
Valid = *on;
endsl;
endsr;
//?LoadSfl: Load the subfile from the array
begsr LoadSfl;
//?Clear subfile control
*in81 = *off;
*in82 = *off;
write SFLCTL;
RRN = 0;
*in81 = *on;
*in82 = *on;
//?Load subfile records from gOutput array entries
for x = 1 to gOutput.NbrEntRtn;
addr = gOutput.addressarray(x);
RADDR = addr;
//?Highlight in red if address has warnings
if addr.SErrType = 'WARNING' or
addr.SErrType = 'SHIPPING_WARNING' or
addr.SErrType = 'URSA_HARD' or
addr.SErrType = 'URSA_SOFT';
ATTR = x'28';
else;
ATTR = x'20';
endif;
SFLSEL = *blanks;
//?Format address for display
exsr formatAddress;
DTAVAL = AddressV;
rrn = rrn + 1;
write SFLRCD;
endfor;
//?If no matching entries, display error message
if rrn = 0;
SFLSEL = *blanks;
ATTR = x'22';
DTAVAL = '*** NO RECORDS MATCH YOUR QUERY ***';
rrn = rrn + 1;
write SFLRCD;
endif;
rrn = 1;
endsr;
//?InitSR: Initialization
begsr initSR;
if %parms > 0;
addr = pAddress;
else;
clear addr;
endif;
clear gInput;
gInput.AccountNbr = '000000000000'; //?Dummy account number
gInput.MeterNbr = '0000000000'; //?Dummy memter number
gInput.CarrierCode = 'FDXG'; //?Use Fedex Ground
gInput.MaxMatch = 10; //?Get up to 10 matches
endsr;
//?formatAddress: Format address for nice display
begsr formatAddress;
clear AddressV;
if addr.company <> *blanks;
AddressV = AddressV + %trimr( addr.company ) + ', ';
endif;
if addr.line1 <> *blanks;
AddressV = AddressV + %trimr( addr.line1 ) + ', ';
endif;
if addr.line2 <> *blanks;
AddressV = AddressV + %trimr( addr.line2 ) + ', ';
endif;
if addr.city <> *blanks;
AddressV = AddressV + %trimr( addr.city ) + ', ';
endif;
if addr.state <> *blanks;
AddressV = AddressV + %trimr( addr.state ) + ' ';
endif;
if addr.zipcode <> *blanks;
AddressV = AddressV + %trimr( addr.zipcode ) + ' ';
endif;
if addr.urbname <> *blanks;
AddressV = AddressV + %trimr( addr.urbname );
endif;
endsr;
//?Return: Return to caller
begsr return;
*inlr = *on;
return;
endsr;
//?*PSSR: Error-handling subroutine
begsr *pssr;
*inlr = *on;
return;
endsr;
/end-free