UPS_Tracking()

This subprocedure calls the UPS Tracking API. It reads request data from UPSTKRQ, and writes response data to UPSTKRS, activity data to UPSTKRSAC, and package data to UPSTKRSPK.

Subprocedure Prototype

D UPS_tracking    PR              N

Returns *OFF if an error occurs during processing, *ON otherwise.

D  pUniqueID                    15P 0

The ID of the record in UPSTKRQ that will be used to build the request, and under which the response data will be saved in UPSTKRS and the other output tables.

D  pErrorDS                           LikeDS(UPS_Error)

The data structure in which error information will be returned.

Example Code


*------------------------------------------------------------------------ * @Author: Krengel Technology * @Description: * This is a test program to illustrate how to call the * UPS_tracking() subprocedure to determine shipping time for a * given shipping option. * * To achieve this, generate a unique ID with UPS_getUID(), and * then populate and write a record to UPSTKRQ. Then, call * UPS_tracking() passing in your unique ID as well as the other * parameters shown. * * UPS_tracking() will return *On if no error was encountered, * or *Off if an error occurred. If an error occurred, you should * look at the fields in ErrorDS to retrieve information about the * error. * * Otherwise, you can perform a CHAIN against the UPSTKRS physical * file, and retrieve the result fields, as well as UPSTKRSAC, * UPSTKRSPK, and UPSTKRSRF for child records. *------------------------------------------------------------------------ H DFTACTGRP(*NO) ACTGRP(*CALLER) BNDDIR('UPSBND') OPTION(*NODEBUGIO) FUPSTKRQ UF A E K DISK Qualified FUPSTKRS IF A E K DISK Qualified FUPSTKRSAC IF A E K DISK Qualified FUPSTKRSPK IF A E K DISK Qualified FUPSTKRSRF IF A E K DISK Qualified /COPY QRPGLECPY,UPS // This is included for demo output purposes. D WriteToJobLog PR 10I 0 Extproc('Qp0zLprintf') D pString * Value Options(*String) D NewLine C x'15' D TKRQ DS Likerec(UPSTKRQ.RUPSTKRQ:*Output) D TKRS DS Likerec(UPSTKRS.RUPSTKRS:*Input) D TKRSAC DS Likerec(UPSTKRSAC.RUPSTKRSAC:*Input) D TKRSPK DS Likerec(UPSTKRSPK.RUPSTKRSPK:*Input) D TKRSRF DS Likerec(UPSTKRSRF.RUPSTKRSRF:*Input) D ErrorDS DS LikeDS(UPS_ErrorDS_t) Inz(*LikeDS) D UniqueID S Like(UPS_UniqueID_t) /FREE reset ErrorDS; // Retrieve Unique ID used to identify this request UniqueID = UPS_getUID(); clear TKRQ; TKRQ.UID = UniqueID; // Populate this field with UPS user ID that is present in UPSACCT TKRQ.UserID = 'ataylorkt'; TKRQ.AcctNbr = '0704W7'; TKRQ.ReqOpt = '0'; // Retrieves "Last Activity" // TKRQ.ReqOpt = '1'; // Retrieves "All Activity" TKRQ.PkgNbr = '1Z12345E0291980793'; // These fields can be used to perform a search against a reference // number instead of a tracking number. //TKRQ.ShipNbr = ''; //TKRQ.RefNbr = ''; //TKRQ.BeginDt = ''; //TKRQ.EndDt = ''; //TKRQ.DPostCd = ''; //TKRQ.DCntry = 'US'; write UPSTKRQ.RUPSTKRQ TKRQ; // If UPS_tracking() returns *Off, an error occurred and // UPS_ErrorDS should be reviewed to determine the cause. if not UPS_tracking( UniqueID : ErrorDS ); WriteToJobLog( 'API Error: ' + NewLine ); WriteToJobLog( 'Error Code: ' + %Trim(ErrorDS.Code) + NewLine ); WriteToJobLog( 'Error Severity: ' + %Char(ErrorDS.Severity) + NewLine ); WriteToJobLog( 'Error Source: ' + %Trim(ErrorDS.Pgm) + NewLine ); WriteToJobLog( 'Error Text: ' + %Trim(ErrorDS.Text) + NewLine ); exsr cleanup; return; else; setll UniqueID UPSTKRS.RUPSTKRS; if not %Found(UPSTKRS); WriteToJobLog( 'ERROR: No results found in UPSTKRS' + NewLine ); exsr cleanup; return; endif; // Read the results from UPSTKRS. There are typically multiple // records. A selection of the available fields is output by // this example program but more are availble - review the file // to see what else is available. reade UniqueID UPSTKRS.RUPSTKRS TKRS; dow not %Eof(UPSTKRS); WriteToJobLog( 'Result Record: ' + NewLine ); WriteToJobLog( 'PID: ' + %Char(TKRS.PID) + NewLine ); WriteToJobLog( 'UID: ' + %Char(TKRS.UID) + NewLine ); WriteToJobLog( 'SHIPNBR: ' + %Trim(TKRS.SHIPNBR) + NewLine ); WriteToJobLog( 'SHACCT: ' + %Trim(TKRS.SHACCT) + NewLine ); WriteToJobLog( 'SHADDR1: ' + %Trim(TKRS.SHADDR1) + NewLine ); WriteToJobLog( 'SHADDR2: ' + %Trim(TKRS.SHADDR2) + NewLine ); WriteToJobLog( 'SHADDR3: ' + %Trim(TKRS.SHADDR3) + NewLine ); WriteToJobLog( 'SHCITY: ' + %Trim(TKRS.SHCITY) + NewLine ); WriteToJobLog( 'SHSTATE: ' + %Trim(TKRS.SHSTATE) + NewLine ); WriteToJobLog( 'SHPOSTCD: ' + %Trim(TKRS.SHPOSTCD) + NewLine ); WriteToJobLog( 'SHCNTRY: ' + %Trim(TKRS.SHCNTRY) + NewLine ); WriteToJobLog( 'STADDR1: ' + %Trim(TKRS.STADDR1) + NewLine ); WriteToJobLog( 'STADDR2: ' + %Trim(TKRS.STADDR2) + NewLine ); WriteToJobLog( 'STADDR3: ' + %Trim(TKRS.STADDR3) + NewLine ); WriteToJobLog( 'STCITY: ' + %Trim(TKRS.STCITY) + NewLine ); WriteToJobLog( 'STSTATE: ' + %Trim(TKRS.STSTATE) + NewLine ); WriteToJobLog( 'STPOSTCD: ' + %Trim(TKRS.STPOSTCD) + NewLine ); WriteToJobLog( 'STCNTRY: ' + %Trim(TKRS.STCNTRY) + NewLine ); WriteToJobLog( 'WGTCD: ' + %Trim(TKRS.WGTCD) + NewLine ); WriteToJobLog( 'SHIPWGT: ' + %Char(TKRS.SHIPWGT) + NewLine ); WriteToJobLog( 'SVCCD: ' + %Trim(TKRS.SVCCD) + NewLine ); WriteToJobLog( 'SVCDSC: ' + %Trim(TKRS.SVCDSC) + NewLine ); WriteToJobLog( 'REFNBR: ' + %Trim(TKRS.REFNBR) + NewLine ); WriteToJobLog( 'REFNBRCD: ' + %Trim(TKRS.REFNBRCD) + NewLine ); WriteToJobLog( 'PKUPDT: ' + %Char(TKRS.PKUPDT) + NewLine ); WriteToJobLog( 'SCHEDDT: ' + %Char(TKRS.SCHEDDT) + NewLine ); WriteToJobLog( 'SCHEDTIM: ' + %Char(TKRS.SCHEDTIM) + NewLine ); WriteToJobLog( '==========' + NewLine ); // UPSTKRSPK, UPSTKRSAC, and UPSTKRSRF may contain child records // that could be read here. reade UniqueID UPSTKRS.RUPSTKRS TKRS; enddo; endif; exsr cleanup; return; begsr cleanup; // Always call UPS_cleanup() any time your program will terminate UPS_cleanup(); *INLR = *ON; endsr; /END-FREE

Data Structures

D UPS_Error       DS                  Qualified Inz
 
D  Code                         10A

Error code raised by subprocedure

D  Severity                     10I 0

Severity of error - will be either UPS_SEVERE or UPS_INFO

D  Pgm                          30A   Varying

Name of subprocedure that raised the error

D  Text                      32000A   Varying

Error message text

Input Table Files

A          R RUPSTKRQ

Record

Tracking Request Record

A            UID           15P 0

Key

Record Unique ID

A            USERID        30A

UPS User ID

A            ACCTNBR       10A

UPS Account Number

A            REQOPT         4A

Tracking Request Option

A            PKGNBR        21A

Package Number

A            SHIPNBR       21A

Shipment Number

A            REFNBR        35A

Reference Number

A            BEGINDT         L

Period Begin Date

A            ENDDT           L

Period End Date

A            DPOSTCD       16A

Destination Postal Code

A            DCNTRY         2A

Destination Country

Output Table Files

A          R RUPSTKRS

Record

Tracking Response Record

A            PID           15P 0

Key

Parent Unique ID

A            UID           15P 0

Key

Child Unique ID

A            SHIPNBR       21A

Shipment ID Number

A            SHACCT        10A

Shipper Account Number

A            SHADDR1       35A

Shipper Address Line 1

A            SHADDR2       35A

Shipper Address Line 2

A            SHADDR3       35A

Shipper Address Line 3

A            SHCITY        40A

Shipper City

A            SHSTATE        5A

Shipper State

A            SHPOSTCD      16A

Shipper Postal Code/Zip

A            SHCNTRY        2A

Shipper Country

A            STADDR1       35A

Ship To Address Line 1

A            STADDR2       35A

Ship To Address Line 2

A            STADDR3       35A

Ship To Address Line 3

A            STCITY        40A

Ship To City

A            STSTATE        5A

Ship To State

A            STPOSTCD      16A

Ship To Postal Code/Zip

A            STCNTRY        2A

Ship To Country

A            WGTCD          3A

Shipment Weight Code

A            SHIPWGT       10P 2

Shipment Weight

A            SVCCD          4A

UPS Service Code

A            SVCDSC        40A

UPS Service Description

A            REFNBR        35A

Shipment Reference Number

A            REFNBRCD       2A

Shipment Reference Code

A            PKUPDT          L

Shipment Pickup Date

A            SCHEDDT         L

Sheduled Delivery Date

A            SCHEDTIM        T

Scheduled Delivery Time

A          R RUPSTKRSAC

Record

Tracking Package Activity Response Record

A            PID           15P 0

Key

Parent Unique ID

A            UID           15P 0

Key

Child Unique ID

A            ACADDR1       35A

Activity Address Line 1

A            ACADDR2       35A

Activity Address Line 2

A            ACADDR3       35A

Activity Address Line 3

A            ACCITY        40A

Activity City

A            ACSTATE       5A

Activity State

A            ACPOSTCD      16A

Activity Postal Code/Zip

A            ACCNTRY        2A

Activity Country

A            LOCCD          2A

Activity Location Code

A            LOCDESC       35A

Activity Location Description

A            SIGNEDBY      30A

Signed For By

A            STSTYPCD       1A

Status Type Code

A            STSTYP       300A

Status Type

A            STSCD          2A

Status Code

A            ACTIVDT         L

Activity Date

A            ACTIVTIM        T

Activity Time

A          R RUPSTKRSPK

Record

Tracking Response Package Information Record

A            PID           15P 0

Key

Parent Unique ID

A            UID           15P 0

Key

Child Unique ID

A            TRACKNBR      21A

Package Tracking Number

A            RSCHDDT         L

Rescheduled Delivery Date

A            RSCHDTIM        T

Rescheduled Delivery Time

A            RRADDR1       35A

Rerouted Address Line 1

A            RRADDR2       35A

Rerouted Address Line 2

A            RRADDR3       35A

Rerouted Address Line 3

A            RRCITY        40A

Rerouted City

A            RRSTATE        5A

Rerouted State

A            RRPOSTCD      16A

Rerouted Postal Code/Zip

A            RRCNTRY        2A

Rerouted Country

A            RTADDR1       35A

Return To Sender Address Line 1

A            RTADDR2       35A

Return To Sender Address Line 2

A            RTADDR3       35A

Return To Sender Address Line 3

A            RTCITY        40A

Return To Sender City

A            RTSTATE        5A

Return To Sender State

A            RTPOSTCD      16A

Return To Postal Code/Zip

A            RTCNTRY        2A

Return To Country

A            CODCURCD       3A

COD Currency Code

A            CODVALUE      11P 2

COD Value

A            CODCTRL       12A

COD Control Number

A            CODSTS        13A

COD Status

A            SIGREQCD       2A

Signature Required Code

A            MSGCD          2A

Message Code

A            MSGDESC       15A

Message Description

A            WGTCD          3A

Package Weight Code

A            PKGWGT         7P 2

Package Weight