T_DWNLRPT - Download a Report from CyberSource

**FREE
// Example Program: T_DWNLRPT
// Description:
//  This is a test program to demonstrate downloading a batch detail
//  report from CyberSource using the CTI_DownloadReport() API.
//
//  To achieve this, generate a unique ID with CTI_NextUniqueId(), and
//  then populate the required fields in the ReportDS data structure.
//  Call the API, passing in your unique ID and the other parameters
//  as shown.
//
//  CTI_DownloadReport() 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, the downloaded report can be found in the download
//  directory specified in your CTICFGENV record.

Ctl-Opt ActGrp(*Caller) BndDir('CTIBND') Option(*NoDebugIO);

/COPY QRPGLECPY,CTICB

// This is included for demo output purposes.
Dcl-Pr WriteToJobLog Int(10) Extproc('Qp0zLprintf');
  pString Pointer Value Options(*String);
End-Pr;
Dcl-C NewLine x'15';

// This stores the unique ID for this API call
Dcl-S UniqueId Like(CTI_UniqueId_t) Inz;

Dcl-Ds ReportDS LikeDS(CTI_DownloadReportDS_t) Inz(*LikeDS);
// This holds any error information returned by the API call
Dcl-Ds ErrorDS LikeDS(CTI_ErrorDS_t) Inz(*LikeDS);

// Modify this field to use your merchant ID
Dcl-S MerchantId Like(CTI_MerchantId_t) Inz('ikrengel');

reset ErrorDS;

// Each API call requires a unique ID
UniqueId = CTI_NextUniqueId();

ReportDS.MerchantId = MerchantId;
ReportDS.OrganizationId = MerchantId;
ReportDS.Environment = CTI_ENV_TEST;
// If this value is not specified, CTI will use a value of '*DEFAULT'
//ReportDS.KeyLabel = '';
ReportDS.ReportName = CTI_REPORT_BATCHDETAIL;
ReportDS.ReportDate = %Date('2019-03-16');
ReportDS.Filepath = %Char(UniqueId) + '_report.xml';

if not CTI_DownloadReport( UniqueId : ReportDS : ErrorDS );
  WriteToJobLog( 'Failure' + NewLine );
  WriteToJobLog( 'Source: ' + ErrorDS.Source + NewLine );
  WriteToJobLog( %Trim(ErrorDS.MessageId) + ': '
               + ErrorDS.Message + NewLine );
else;
  WriteToJobLog( 'Success' + NewLine );
  WriteToJobLog( 'Report File: ' + ReportDS.Filepath + NewLine );
endif;

// Write unique ID to job log for easy reference
WriteToJobLog( 'T_DWNLRPT Unique ID: ' + %Char(UniqueId) + NewLine );

*INLR = *On;
return;