Program to calculate modified mod 10 check digit

This program is stand-alone and can be incorporated in any program when you need to calculate modified mod 10 check digit as per UPS label requirements.
REPORT Z_mod_check_digit.

*This program will calculate the modified mod 10 check digit as per
*UPS label requirements.
PARAMETERS: S_NUMBER(17)  TYPE C DEFAULT '1Z123X56031234820'.

  DATA: WUPS_STR(15) TYPE C,
        SUM_ODD      TYPE I,
        SUM_EVEN     TYPE I,
        SUM_TOTAL    TYPE I,
        STEP         TYPE I,
        W_CHAR(1)    TYPE C,
        W_VAL(1)     TYPE C,
        W_TEMP(1)    TYPE C,
        MODX(2)      TYPE C,
        MOD10(1)     TYPE C.
  CLEAR: SUM_ODD, SUM_EVEN, SUM_TOTAL.
  WUPS_STR = S_NUMBER+2(15).
  STEP = 0.
  WHILE STEP < 15.
    W_CHAR = WUPS_STR+STEP(1).
    PERFORM GET_VALUE USING W_CHAR W_VAL.
    W_TEMP = STEP MOD 2.
    IF ( W_TEMP = 0 ).
      SUM_ODD = SUM_ODD + W_VAL.
    ELSE.
      SUM_EVEN = SUM_EVEN + W_VAL.
    ENDIF.
    STEP = STEP + 1 .
  ENDWHILE.
  SUM_TOTAL = SUM_ODD + 2 * SUM_EVEN.
  MODX = 10 - ( SUM_TOTAL MOD 10 ).
  IF MODX = 10.
    MOD10 = MODX+1(1).
  ELSE.
    MOD10 = MODX+0(1).
  ENDIF.
  SKIP 2.
  WRITE:/20 'The check digit is:  ', MOD10.
  SKIP 1.
*---------------------------------------------------------------------*
*       FORM GET_VALUE                                                *
*---------------------------------------------------------------------*
*      Convert alpha numeric to numeric as per

    Requires Free Membership to View

UPS Barcode specs * *---------------------------------------------------------------------* FORM GET_VALUE USING W_CHAR W_VAL. CASE W_CHAR. WHEN '0' OR 'I' OR 'S'. W_VAL = 0. WHEN '1' OR 'J' OR 'T'. W_VAL = 1. WHEN '2' OR 'A' OR 'K' OR 'U'. W_VAL = 2. WHEN '3' OR 'B' OR 'L' OR 'V'. W_VAL = 3. WHEN '4' OR 'C' OR 'M' OR 'W'. W_VAL = 4. WHEN '5' OR 'D' OR 'N' OR 'X'. W_VAL = 5. WHEN '6' OR 'E' OR 'O' OR 'Y'. W_VAL = 6. WHEN '7' OR 'F' OR 'P' OR 'Z'. W_VAL = 7. WHEN '8' OR 'G' OR 'Q'. W_VAL = 8. WHEN '9' OR 'H' OR 'R'. W_VAL = 9. WHEN OTHERS. ENDCASE. ENDFORM. " get_value

This was first published in March 2002

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.

    Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.