H DFTACTGRP(*NO) BNDDIR('HTTPAPI':'QC2LE')
     ‚********************************************************************
     ‚* FILE SPECS
     ‚********************************************************************
     FDTEODRELM IT   F   20        DISK
     FDTEODR    IF   E             DISK    UsrOpn
     FDTWSINB   O    E             DISK
     ‚********************************************************************
     ‚* EXTENSION SPECS
     ‚********************************************************************
      /copy libhttp/qrpglesrc,httpapi_h
     ‚********************************************************************
     D StartOfElement  PR
     D   UserData                      *   value
     D   depth                       10I 0 value
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)

     D EndOfElement    PR
     D   UserData                      *   value
     D   depth                       10I 0 value
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   value                    65535A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)

     D Add_SOAPACTION  PR
     D   Header                    1024A   varying
     D   UserData                      *   value

     D SNDDTAQ         PR                  ExtPgm('QSNDDTAQ')
     D  Dtaqnme                      10a
     D  Dtaqlib                      10a
     D  DtaqLen                       5  0
     D  Dtaqdta                    4500a

     D  SendMesg       PR                  ExtPgm('SNDMSG')
     D   ErrUser                     10    const
     D   ErrMesg                    174    const

     D GETEODROLL      PR
     D  PmStrDte                     10A
     D  PmEndDte                     10A

     D GETEODROLL      PI
     D  PmStrDte                     10A
     D  PmEndDte                     10A
     ‚********************************************************************
     D SOAP            s          32767A   varying
     D rc              s             10I 0
     D act             s             10I 0
     D count           s              4s 0
     D @first          s              1a   Inz('Y')
     D @len            s              2s 0 Inz
     D @pos            s              2s 0 Inz(10)
     D @WkFld          s             10a   Inz
     D @elm            s              3s 0 Inz
     D @idx            s              5s 0 Inz
     D DteIso          s               d   datfmt(*iso)
     D cnt1            s             10I 0
     D cnt2            s             10I 0
     D @RxTime         s                   Like(RxTim1) Inz(*All'0')
     D AttrNme         s             15a   Dim(200)
     D AttrVal         s             20a   Dim(200)

     D RxAry           ds
     D  DtaqAry                      10a   Dim(200) Inz(*All'0')

     D ArrTag          s             15a   Dim(200) FromFile(DTEODRELM)
     D ArrIdx          s              5s 0 Dim(200) Alt(ArrTag)
     ‚*---------------------------------------------------------------------
     ‚* Web Service Credentials for each individual account from control fil
     ‚*---------------------------------------------------------------------
     D WScompany       s             15a   Inz
     D WScustnum       s             15a   Inz
     D WSusername      s             15a   Inz
     D WSpassword      s             15a   Inz
     D WSdtastore      s             10a   Inz
     D WSstrdate       s             10a   Inz
     D WSenddate       s             10a   Inz
     D WStimeout       c                   Const(1800)
     ‚*---------------------------------------------------------------------
     D WkTime          ds
     D  WkCy                   1      4
     D  WkMo                   6      7
     D  WkDy                   9     10
     D  WkHr                  12     13
     D  WkMn                  15     16
     D  WkSs                  18     19
     D
     D WkTime1         ds
     D  WkCy1                  1      4
     D  WkMo1                  5      6
     D  WkDy1                  7      8
     D  WkHr1                  9     10
     D  WkMn1                 11     12
     D  WkSs1                 13     14

     ‚********************************************************************
     ‚* Main Driver - Calls Webservice & retrieves Messages.
     ‚********************************************************************

      /free
       If PmStrDte = *Blanks and PmEndDte = *Blanks;
         DteIso    = %date;
         DteIso   -= %days(1);
         WSstrdate = %char(DteIso);
         WSenddate = %char(DteIso);
       Else;
         WSstrdate = PmStrDte;
         WSenddate = PmEndDte;
       EndIf;

       //‚Retrieve values from DTCTL
       Open DtEodr;                                                       
       Read rEodr;                                                        
       WScompany  = EcCstCd;                                              
       WScustnum  = EcCstNb;                                              
       WSusername = EcUsrNm;                                              
       WSpassword = EcUsrPw;                                              
       WSdtastore = EcDtaSt;                                              
       Close DtEodr;                                                      

       //‚Note:  http_debug(*ON/*OFF) can be used to turn debugging
       //‚       on and off.  When debugging is turned on, diagnostic
       //‚       info is written to an IFS file named
       //‚       /tmp/httpapi_debug.txt     Use "WRKLNK /tmp" cmd

       http_debug(*ON);

       HTTP_setCCSIDs(1208: 0);  // CCSID 1208 = UTF-8

         SOAP = *Blanks;
         SOAP =
         '<?xml version="1.0" encoding="utf-8"?>' +
         ' <soapenv:Envelope' +
         ' xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"' +
         ' xmlns:ns="http://fwapi.DriverTech.com/CommonTypes/2009/04"' +
         ' xmlns:rep="http://fwapi.DriverTech.com/ReportsService_v2">' +
         ' <soapenv:Header>' +
         ' <ns:RequestHeader>' +
         ' <ns:CompanyCode>' +%trim(WScompany) + '</ns:CompanyCode>' +
         ' <ns:UserName>' + %trim(WSusername) + '</ns:UserName>' +
         ' <ns:Password>' + %trim(WSpassword) + '</ns:Password>' +
         ' <ns:DataStoreName>' + %trim(WSdtastore) + '</ns:DataStoreName>' +
         ' <ns:DriverTechAPIVersion></ns:DriverTechAPIVersion>' +
         ' <ns:RequestId></ns:RequestId>' +
         ' </ns:RequestHeader>' +
         ' </soapenv:Header>' +
         ' <soapenv:Body>' +
         ' <rep:VehiclePerformance_GetByDate>' +
         ' <rep:StartDate>' + %trim(WSstrdate) + '</rep:StartDate>' +
         ' <rep:EndDate>'   + %trim(WSenddate) + '</rep:EndDate>' +
         ' <rep:QueryByRecordDate>false</rep:QueryByRecordDate>' +
         ' </rep:VehiclePerformance_GetByDate>' +
         ' </soapenv:Body>' +
         ' </soapenv:Envelope>';

       //  This tells HTTPAPI to call our subprocedure (in this example,
       //  the subprocedure is name ADD_SOAPACTION) when assembling the
       //  HTTP headers to send to the remote server.

       http_xproc( HTTP_POINT_ADDL_HEADER
                 : %paddr(Add_SOAPACTION) );

       rc = http_url_post_xml(
            'https://www.truck-pc.net/WebServices/FleetWatcher/+
            Reports/V1_9/ReportsService.asmx'
            : %addr(SOAP) + 2
            : %len(SOAP)
            : %paddr(StartOfElement)
            : %paddr(EndOfElement)
            : *NULL
            : WStimeout
            : HTTP_USERAGENT
            : 'text/xml; charset=utf-8' );

       if (rc <> 1);
          SendMesg('QSYSOPR':
              'Web Service GETEODROLL failed. ' +
              '  Start Date: ' + %Trim(PmStrDte) +
              '  End Date: ' + %Trim(PmEndDte) +
              '  See /tmp/httpapi_debug.txt');
              http_crash();
              *inlr = *on;
       endif;

       *inlr = *on;

      /end-free

     ‚********************************************************************
     ‚* Procedure - Add longer SOAPAction
     ‚********************************************************************
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * HTTPAPI will call this (because we set it with http_xproc)
      * just before sending the HTTP headers to the remote server.
      * This procedure lets us add any header we like to the
      * HTTP request.
      *
      * In this example, I'll use it to supply the SoapAction:
      * header.  This way, I can supply a SOAPAction that's up to
      * 1024 characters long.
      *
      * NOTE: Make sure you leave off the SOAPAction header on the
      *       HTTP_url_post_xml, above, otherwise you'll send two
      *       of them!
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P Add_SOAPACTION  B
     D Add_SOAPACTION  PI
     D   Header                    1024A   varying
     D   UserData                      *   value
      /free
         Header = 'SOAPAction: '
                + '"http://fwapi.DriverTech.com/'
                + 'ReportsService_v2/VehiclePerformance_GetByDate"';
      /end-free
     P                 E

     ‚********************************************************************
     ‚* Procedure - Start of XML element
     ‚********************************************************************
     P StartOfElement  B
     D StartOfElement  PI
     D   UserData                      *   value
     D   depth                       10I 0 value
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)
      /free

        if path = '/soap:Envelope/soap:Body';
           act += 1;
        endif;

      /end-free

     P                 E

     ‚********************************************************************
     ‚* Procedure - End of XML element
     ‚********************************************************************
     P EndOfElement    B
     D EndOfElement    PI
     D   UserData                      *   value
     D   depth                       10I 0 value
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   value                    65535A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)
      /free

         select;
           when name = 'Entry';
             clear RxRecf;
             clear AttrNme;
             clear AttrVal;
             Reset DtaqAry;
             cnt1 = 1;
             cnt2 = 1;
             dow attrs(cnt1) <> *NULL;
               AttrNme(cnt2) = %str(attrs(cnt1));
               cnt1 += 1;
               AttrVal(cnt2) = %str(attrs(cnt1));
               cnt1 += 1;
               cnt2 += 1;
             enddo;

             For cnt1 = 1 to cnt2;
               Select;
                 When AttrNme(cnt1) = 'DSRI' or        //‚Ignore DSRI and DSRD        
                      AttrNme(cnt1) = 'DSRD';
                 When AttrNme(cnt1) = 'Id';
                   RxSeq# = %dec(AttrVal(cnt1): 9: 0);
                 When AttrNme(cnt1) = 'Version';                                
                   RxFld2 = AttrVal(cnt1);                                      
                 When AttrNme(cnt1) = 'TruckName';
                   RxTrk# = AttrVal(cnt1);
                 When AttrNme(cnt1) = 'DriverLogon';
                   RxFld1 = AttrVal(cnt1);
                 When AttrNme(cnt1) = 'Date';
                   WkTime = AttrVal(cnt1);
                   WkCy1  = WkCy;
                   WkMo1  = WkMo;
                   WkDy1  = WkDy;
                   WkHr1  = WkHr;
                   WkMn1  = WkMn;
                   WkSs1  = WkSs;
                   RxTim1 = WkTime1;
                 When AttrNme(cnt1) = 'ReceivedOn';
                   WkTime = AttrVal(cnt1);
                   WkCy1  = WkCy;
                   WkMo1  = WkMo;
                   WkDy1  = WkDy;
                   WkHr1  = WkHr;
                   WkMn1  = WkMn;
                   WkSs1  = WkSs;
                   RxTim2 = WkTime1;
                 Other;
                   If %subst(AttrVal(cnt1): 1: 1) <> *Blank;
                     ReSet @pos;
                     @len = %CheckR(' ': AttrVal(cnt1));
                     @pos = (@pos - @len) + 1;
                     @elm = %Lookup(AttrNme(cnt1): ArrTag);
                     If @elm <> 0;
                       @idx = ArrIdx(@elm);
                       Monitor;
                         EvalR %SubSt(DtaqAry(@idx): @pos) =
                               %SubSt(AttrVal(cnt1):1: @len);
                       On-Error;
                       EndMon;
                     EndIf;
                   EndIf;
               EndSl;
             EndFor;
             If RxTim1 = *Blanks;
               RxTim1 = @RxTime;
             EndIf;
             If RxTim2 = *Blanks;
               RxTim2 = @RxTime;
             EndIf;
             %Subst(RxRecd: 41) = RxAry;
             Write RxRecf;
         EndSl;

      /end-free

     P                 E