UPS_ratingReq()

This subprocedure calls the UPS Rating API. It reads request data from UPSRTRQ, and package data from UPSRTRQPK. It writes response data to UPSRTRS, and package data to UPSRTRSPK.

Subprocedure Prototype

D UPS_ratingReq   PR              N

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

D  pUniqueID                    15P 0

The ID of the records in UPSRTRQ and UPSRTRQPK that will be used to build the request, and under which the response data will be saved in UPSRTRS and UPSRTRSPK.

D  pErrorDS                           LikeDS(UPS_Error)

The data structure in which error information will be returned.

Example Code


*------------------------------------------------------------------------ * @Author: Kato Integrations * @Description: * This is a test program to illustrate how to call the * UPS_ratingReq() subprocedure to determine shipping rates. * * To achieve this, generate a unique ID with UPS_getUID(), and * then populate and write a record to UPSRTRQ, and one or more child * records to UPSRTRQPK. Then, call UPS_ratingReq() passing in * your unique ID as well as the other parameters shown. * * UPS_ratingReq() 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 UPSRTRS physical * file, and retrieve the result fields, as well as child records * for each package from UPSRTRSPK. *------------------------------------------------------------------------ H DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('UPSBND') OPTION(*NODEBUGIO) FUPSRTRQ UF A E K DISK Qualified FUPSRTRQPK UF A E K DISK Qualified FUPSRTRS IF A E K DISK Qualified FUPSRTRSPK 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 RTRQ DS Likerec(UPSRTRQ.RUPSRTRQ:*Output) D RTRQPK DS Likerec(UPSRTRQPK.RUPSRTRQPK:*Output) D RTRS DS Likerec(UPSRTRS.RUPSRTRS:*Input) D RTRSPK DS Likerec(UPSRTRSPK.RUPSRTRSPK:*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 RTRQ; RTRQ.UID = UniqueID; // Populate this field with application name set up using WRKUPSAUTH RTRQ.UserID = 'KATO_TEST'; // Populate this field with a UPS account number configured in // file UPSCFGACCT RTRQ.AcctNbr = '523FE3'; RTRQ.ReqOpt = 'Rate'; // Rate and validate this shipment // Validate the shipment and return rates for all UPS products from the // ShipFrom to the ShipTo // RTRQ.ReqOpt = 'Shop'; RTRQ.PKUPCD = '06'; RTRQ.CSTCLSCD = '03'; RTRQ.StAddr1 = '1600 Pennsylvania Avenue NW'; RTRQ.StCity = 'Washington'; RTRQ.StState = 'DC'; RTRQ.StPostCd = '20500'; RTRQ.StCntry = 'US'; RTRQ.SfAddr1 = '4706 Chiquita Blvd S'; //RTRQ.SfAddr2 = 'STE 310'; RTRQ.SfCity = 'Cape Coral'; RTRQ.SfState = 'FL'; RTRQ.SfPostCd = '33914'; RTRQ.SfCntry = 'US'; RTRQ.SvcCd = '03'; // Other fields are available but not used in this example code write UPSRTRQ.RUPSRTRQ RTRQ; // Write individual package child record to UPSRTRQPK clear RTRQPK; RTRQPK.PID = UniqueID; RTRQPK.UID = 1; RTRQPK.PkgCd = '02'; RTRQPK.DimCd = 'IN'; RTRQPK.Length = 6.5; RTRQPK.Width = 10; RTRQPK.Height = 4; RTRQPK.WgtCd = 'LBS'; RTRQPK.PkgWgt = 5; write UPSRTRQPK.RUPSRTRQPK RTRQPK; // If UPS_ratingReq() returns *Off, an error occurred and // UPS_ErrorDS should be reviewed to determine the cause. if not UPS_ratingReq( 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 UPSRTRS.RUPSRTRS; if not %Found(UPSRTRS); WriteToJobLog( 'ERROR: No results found in UPSRTRS' + NewLine ); exsr cleanup; return; endif; // Read the results from UPSRTRS. 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 UPSRTRS.RUPSRTRS RTRS; dow not %Eof(UPSRTRS); WriteToJobLog( 'Result Record: ' + NewLine ); WriteToJobLog( 'PID: ' + %Char(RTRS.PID) + NewLine ); WriteToJobLog( 'UID: ' + %Char(RTRS.UID) + NewLine ); WriteToJobLog( 'SVCCD: ' + %Trim(RTRS.SVCCD) + NewLine ); WriteToJobLog( 'SVCDSC: ' + %Trim(RTRS.SVCDSC) + NewLine ); WriteToJobLog( 'WGTCD: ' + %Trim(RTRS.WGTCD) + NewLine ); WriteToJobLog( 'TOTWGT: ' + %Char(RTRS.TOTWGT) + NewLine ); WriteToJobLog( 'TRSCURCD: ' + %Trim(RTRS.TRSCURCD) + NewLine ); WriteToJobLog( 'TRSCHRG: ' + %Char(RTRS.TRSCHRG) + NewLine ); WriteToJobLog( 'SVCCURCD: ' + %Trim(RTRS.SVCCURCD) + NewLine ); WriteToJobLog( 'SVCCHRG: ' + %Char(RTRS.SVCCHRG) + NewLine ); WriteToJobLog( 'TOTCURCD: ' + %Trim(RTRS.TOTCURCD) + NewLine ); WriteToJobLog( 'TOTCHRG: ' + %Char(RTRS.TOTCHRG) + NewLine ); WriteToJobLog( 'GTDDAYS: ' + %Trim(RTRS.GTDDAYS) + NewLine ); WriteToJobLog( 'GTDTIM: ' + %Char(RTRS.GTDTIM) + NewLine ); WriteToJobLog( 'NEGCURCD: ' + %Trim(RTRS.NEGCURCD) + NewLine ); WriteToJobLog( 'NEGCHRG: ' + %Char(RTRS.NEGCHRG) + NewLine ); // Package level charges can be read from UPSRTRSPK if needed reade UniqueID UPSRTRS.RUPSRTRS RTRS; 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 RUPSRTRQ

Record

Rating Request

A            UID           15P 0

Key

Record Unique ID

A            USERID        30A

UPS User ID

A            ACCTNBR       10A

UPS Account Number

A            REQOPT         4A

Request Option

Valid Values:

  • RATE
  • SHOP

A            PKUPCD         2A

Pickup Type Code

A            CSTCLSCD       2A

Customer Classification

A            STCONAME      35A

Ship To Company Name

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 Provice/State

A            STPOSTCD      16A

Ship To Postal Code/Zip

A            STCNTRY        2A

Ship To Country

A            STRESDNT       1A

Ship To Residential Indicator

Valid Values:

  • T
  • Y

A            SFCONAME      35A

Ship From Company Name

A            SFADDR1       35A

Ship From Address Line 1

A            SFADDR2       35A

Ship From Address Line 2

A            SFADDR3       35A

Ship From Address Line 3

A            SFCITY        40A

Ship From City

A            SFSTATE        5A

Ship From State

A            SFPOSTCD      16A

Ship From Zip/Postal Code

A            SFCNTRY        2A

Ship From Country

A            SVCCD          4A

UPS Service Code

A            DOCONLY        1A

Documents Only Indicator

Valid Values:

  • T
  • Y

A            SATPKUP        1A

Request Saturday Pickup Indicator

Valid Values:

  • T
  • Y

A            SATDLVR        1A

Request Saturday Delivery Indicator

Valid Values:

  • T
  • Y

A            PKUPDAY        2A

Pickup Day Code

A            PKUPMTHD       2A

Method to Schedule Pickup

A            CNEUTRAL       1A

Carbon Neutral Indicator

Valid Values:

  • T
  • Y

A            DELCNFCD       1A

Delivery Confirmation Type Code

A            NEGRATE        1A

Negotiated Rate Indicator

Valid Values:

  • T
  • Y

A            INVCURCD       3A

Invoice Currency Code

A            INVVALUE      10P 2

Invoice Value

A          R RUPSRTRQPK

Record

Rating Request Package Information

A            PID           15P 0

Key

Parent Unique ID

A            UID           15P 0

Key

Child Unique ID

A            PKGCD          2A

Package Type Code

A            DIMCD          2A

Package Dimensions Code

A            LENGTH         6P 2

Package Length

A            WIDTH          6P 2

Package Width

A            HEIGHT         6P 2

Package Height

A            WGTCD          3A

Package Weight Code

A            PKGWGT         8P 2

Package Weight

A            LRGPKG         1A

Large Package Indicator

Valid Values:

  • T
  • Y

A            INSCURCD       3A

Insured Value Currency Code

A            INSVALUE      15P 2

Insured Value

A            CODFNDCD       1A

COD Funds Code

A            CODCURCD       3A

COD Currency Code

A            CODVALUE       8P 2

COD Value

A            DELCNFCD       1A

Delivery Confirmation Type Code

A            VRBCNFNM      35A

Verbal Confirmation Name

A            VRBPHONE      15A

Verbal Confirmation Phone Number

A            ADDLHNDL       1A

Additional Handling Req

Output Table Files

A          R RUPSRTRS

Record

Rating Request Response Record

A            PID           15P 0

Key

Parent Unique ID

A            UID           15P 0

Key

Child Unique ID

A            SVCCD          4A

UPS Service Code

A            SVCDSC        40A

UPS Service Description

A            WGTCD          3A

Shipment Weight Code

A            TOTWGT         8P 2

Shipment Weight

A            TRSCURCD       3A

Transportation Currency Code

A            TRSCHRG       15P 2

Transportation Charge

A            SVCCURCD       3A

Service Currency Code

A            SVCCHRG       15P 2

Service Charge

A            TOTCURCD       3A

Total Currency Code

A            TOTCHRG       15P 2

Total Charge

A            GTDDAYS        8A

Guaranteed Days to Delivery

A            GTDTIM          T

Guaranteed Delivery Time

A            NEGCURCD       3A

Negotiated Currency Code

A            NEGCHRG       15P 2

Negotiated Total Charges

A          R RUPSRTRSPK

Record

Rating Request Response Package Information

A            PID           15P 0

Key

Parent Unique ID

A            UID           15P 0

Key

Child Unique ID

A            TRSCURCD       3A

Transportation Currency Code

A            TRSCHRG       15P 2

Transportation Charge

A            SVCCURCD       3A

Service Currency Code

A            SVCCHRG       15P 2

Service Charge

A            PKGCURCD       3A

Package Currency Code

A            PKGCHRG       15P 2

Package Charge

A            WGTCD          3A

Package Weight Code

A            PKGWGT         8P 2

Package Weight

A            BILLWGT        8P 2

Package Billing Weight