********************************************************************
      * Program Name - CHKDIG03                                          *
      *                                                                  *
      * Function     - This program was designed to calculate and        *
      *                display a check digit for an 11-digit UPC code.   *
      *                The logic of this program is in accordance to     *
      *                the algorithm defined as 'Standard' by the UCC    *
      *                for GTIN-12 (UPC) codes.                          *
      *                                                                  * 
      *                                                                  *
      *                NOTE: This does not correspond to a standard      *
      *                      Mod 10 (Luhn algorithm).                    *
      *                                                                  *
      * Programmer   - Steve Croy        03/13/08                        *
      ********************************************************************
      ********************************************************************
      *               PROGRAM INTERFACE SECTION                          *
      *                                                                  *
      *  CALLED BY PROGRAMS:                                             *
      *  CALLS PROGRAMS....:                                             *
      *                                                                  *
      ********************************************************************
      ********************************************************************
      *                   Modification log                               *
      *                                                                  *
      *   Date    Programmer      Description                            *
      *                                                                  *
      ********************************************************************
     FCHKDIGDF3 CF   E             WORKSTN
      *
     D                 DS
     D  CHK#                   1      1  0
      *  number data structure
     D  numn           DS            11
     D  UPC                    1     11  0
     D                                     DIM(11)
     D  even           s              3  0
     D  odd            s              3  0
     D  total          s              3  0
     D  z              s              3  0
     D  chkn           s              1  0
      *
      /free
         CLEAR chkdig;
         CLEAR number;
         // Main logic section
         DOU *IN99 = *ON;
            EXFMT CHKDIG01;
            IF *IN99 = *OFF;
               number = %xlate(' ':'0':number);
               numn = number;
               // Add the odd digits  and multiply by 3
               odd = upc(1) + upc(3) + upc(5) + upc(7) + upc(9) + upc(11);
               odd = odd * 3;
               // Add even digits
               even = upc(2) + upc(4) + upc(6) + upc(8) + upc(10);
               // Total of odd and even
                  total = even + odd;
               // Calculate the check digit
               z = 10;
               DOW Total > z;
                  z = z + 10;
               ENDDO;
               CHKN = Z - TOTAL;
               CHKDIG = %EDITC(CHKN:'X');
               CHK# = CHKN;
               *IN15 = *ON;
            ENDIF;
         ENDDO;
         *INLR = *ON;
         RETURN;