IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

ISBN-13 check digit


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
bbharathiraj
Warnings : 1

New User


Joined: 26 Oct 2006
Posts: 50
Location: Chennai

PostPosted: Wed Jun 04, 2008 9:10 pm
Reply with quote

Could some one help me to provide the COBOL code for the below logic?

The calculation of an ISBN-13 check digit begins with the first 12 digits of the thirteen-digit ISBN (thus excluding the check digit itself). Each digit, from left to right, is alternately multiplied by 1 or 3, then those products are summed modulo 10 to give a value ranging from 0 to 9. Subtracted from 10, that leaves a result from 1 to 10. A zero (0) replaces a ten (10), so, in all cases, a single check digit results.

For example, the ISBN-13 check digit of 978-0-306-40615-? is calculated as follows:

s = 9×1 + 7×3 + 8×1 + 0×3 + 3×1 + 0×3 + 6×1 + 4×3 + 0×1 + 6×3 + 1×1 + 5×3
= 9 + 21 + 8 + 0 + 3 + 0 + 6 + 12 + 0 + 18 + 1 + 15
= 93
93 / 10 = 9 remainder 3
10 – 3
= 7

Thus, the check digit is 7, and the complete sequence is ISBN 978-0-306-40615-7.
Back to top
View user's profile Send private message
Manuneedhi K

Active User


Joined: 07 May 2008
Posts: 115
Location: Chennai

PostPosted: Wed Jun 04, 2008 9:42 pm
Reply with quote

Try this.

Code:

   IDENTIFICATION DIVISION.                     
   PROGRAM-ID. TESTPGMP.                         
   AUTHOR.     XXXXXXXXXXXXXX.                   
 *                                               
   ENVIRONMENT DIVISION.                         
   DATA DIVISION.                               
   WORKING-STORAGE SECTION.                     
   01 WK-SUM            PIC 9(5).               
   01 WK-REM            PIC 9(5).               
   01 WK-ISBN.                                   
      05 WK-NUM1        PIC 9(01) .             
      05 WK-NUM2        PIC 9(01) .             
      05 WK-NUM3        PIC 9(01) .             
      05 FILLER         PIC X(1)  .             
      05 WK-NUM4        PIC 9(01) .             
      05 FILLER         PIC X(1)  .             
      05 WK-NUM5        PIC 9(01) .             
      05 WK-NUM6        PIC 9(01) .             
      05 WK-NUM7        PIC 9(01) .             
      05 WK-NUM7        PIC 9(01) .                                   
      05 FILLER         PIC X(1)  .                                   
      05 WK-NUM8        PIC 9(01) .                                   
      05 WK-NUM9        PIC 9(01) .                                   
      05 WK-NUM10       PIC 9(01) .                                   
      05 WK-NUM11       PIC 9(01) .                                   
      05 WK-NUM12       PIC 9(01) .                                   
      05 FILLER         PIC X(1)  .                                   
      05 WK-NUM13       PIC 9(01) .                                   
   PROCEDURE DIVISION.                                               
   0000-MAIN-PARA.                                                   
        MOVE '978-0-306-40615-'   TO WK-ISBN                         
        COMPUTE WK-SUM = WK-NUM1  * 1 + WK-NUM2  * 3 +               
                         WK-NUM3  * 1 + WK-NUM4  * 3 +                 
                         WK-NUM5  * 1 + WK-NUM6  * 3 +                 
                         WK-NUM7  * 1 + WK-NUM8  * 3 +                 
                         WK-NUM9  * 1 + WK-NUM10 * 3 +                 
                         WK-NUM11 * 1 + WK-NUM12 * 3       
         COMPUTE WK-REM = FUNCTION MOD(WK-SUM,10)                       
         COMPUTE WK-NUM13 = 10 - WK-REM                                 
         DISPLAY WK-ISBN.                                               
        STOP RUN                                                         
        .       
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Wed Jun 04, 2008 10:34 pm
Reply with quote

How about?
Code:
   WORKING-STORAGE SECTION.                     
   01 CD                PIC 9(5).               
   01 WK-ISBN           PIC X(17).                                   
   01 N                 REDEFINES
      WK-ISBN           PIC 9(17).                                   
   PROCEDURE DIVISION.                                               
   0000-MAIN-PARA.                                                   
        MOVE '978-0-306-40615-'   TO WK-ISBN                         
        COMPUTE CD =  N(01:1)
                   +  N(02:1) * 3
                   +  N(03:1)
                   +  N(05:1) * 3
                   +  N(07:1)
                   +  N(08:1) * 3
                   +  N(09:1)
                   +  N(11:1) * 3
                   +  N(12:1)
                   +  N(13:1) * 3
                   +  N(14:1)
                   +  N(15:1) * 3
        COMPUTE N(17:1) = 10 - FUNCTION MOD(WK-SUM,10)
        DISPLAY WK-ISBN.                                               
Back to top
View user's profile Send private message
Antonio Barata
Warnings : 1

New User


Joined: 04 Apr 2007
Posts: 37
Location: Lisbon, Portugal

PostPosted: Wed Jun 04, 2008 11:12 pm
Reply with quote

CICS Guy

I think there is something wrong with your code.
Did you compile it?
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Wed Jun 04, 2008 11:17 pm
Reply with quote

Antonio Barata wrote:
CICS Guy

I think there is something wrong with your code.
Did you compile it?
Could be, no compiler, what do you see as an error?
Back to top
View user's profile Send private message
Antonio Barata
Warnings : 1

New User


Joined: 04 Apr 2007
Posts: 37
Location: Lisbon, Portugal

PostPosted: Wed Jun 04, 2008 11:24 pm
Reply with quote

[quote=Could be, no compiler, what do you see as an error?[/quote]
The message is the following:

IGYPA3074-S "N (ALPHANUMERIC REFERENCE MODIFIED ITEM)" was not numeric, but was sender in an arithmetic expression. The statement was discarded.

It refers to the COMPUTE statement where you pick up each digit an multiply it.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Wed Jun 04, 2008 11:46 pm
Reply with quote

Ah yes, getting too cocky for my own good...Thought it would keep the usage it came from, but no.....
data-name-1(leftmost-character-position:length)
If data-name-1 is described as numeric, numeric-edited, alphabetic, or alphanumeric-edited, it is operated upon for purposes of reference modification as if it were redefined as an alphanumeric data item of the same size as the data item referenced by data-name-1.
Back to top
View user's profile Send private message
Antonio Barata
Warnings : 1

New User


Joined: 04 Apr 2007
Posts: 37
Location: Lisbon, Portugal

PostPosted: Thu Jun 05, 2008 12:00 am
Reply with quote

I think this code will do the job, providing that you put all the numbers in the numeric field "ws-array":

WORKING-STORAGE SECTION.
01 ws-ind PIC S9(4) COMP VALUE 0.
01 ws-multiplier-factor PIC S9(3) COMP-3 VALUE 0.
01 ws-sum PIC S9(5) COMP-3 VALUE 0.
01 ws-ckd PIC 9(02) VALUE 0.

01 ws-array PIC 9(13) VALUE 1234567890321.
01 FILLER REDEFINES ws-array.
02 ws-number OCCURS 13 PIC 9.


PROCEDURE DIVISION.
0000-MAIN.
PERFORM VARYING ws-ind FROM 1 BY 1
UNTIL ws-ind > LENGTH OF ws-array
IF FUNCTION REM(ws-ind 2) = 1
MOVE 1 TO ws-multiplier-factor
ELSE
MOVE 3 TO ws-multiplier-factor
END-IF
COMPUTE ws-sum = ws-sum
+ ( ws-number(ws-ind)
* ws-multiplier-factor )
END-PERFORM.
COMPUTE ws-ckd = 10 - FUNCTION MOD(ws-sum 10)
DISPLAY ws-ckd.

I compiled it Ok. Didn't test it. Please do.
Back to top
View user's profile Send private message
bbharathiraj
Warnings : 1

New User


Joined: 26 Oct 2006
Posts: 50
Location: Chennai

PostPosted: Thu Jun 05, 2008 7:14 pm
Reply with quote

Thanks to every one. All your codes are working fine.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts SCOPE PENDING option -check data DB2 2
No new posts Check data with Exception Table DB2 0
No new posts How to check whether who renamed the ... JCL & VSAM 3
No new posts No ++JCLIN, APPLY CHECK job JCL & VSAM 1
No new posts EMPTY file check scenario JCL & VSAM 6
Search our Forums:

Back to Top