Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
bbharathiraj
Warnings : 1

New User

Joined: 26 Oct 2006
Posts: 50
Location: Chennai

 Posted: Wed Jun 04, 2008 9:10 pm    Post subject: ISBN-13 check digit 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.

Manuneedhi K

Active User

Joined: 07 May 2008
Posts: 115
Location: Chennai

Posted: Wed Jun 04, 2008 9:42 pm    Post subject:

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                                                                  .
CICS Guy

Senior Member

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

Posted: Wed Jun 04, 2008 10:34 pm    Post subject:

 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.
Antonio Barata
Warnings : 1

New User

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

 Posted: Wed Jun 04, 2008 11:12 pm    Post subject: CICS Guy I think there is something wrong with your code. Did you compile it?
CICS Guy

Senior Member

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

Posted: Wed Jun 04, 2008 11:17 pm    Post subject:

 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?
Antonio Barata
Warnings : 1

New User

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

 Posted: Wed Jun 04, 2008 11:24 pm    Post subject: [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.
CICS Guy

Senior Member

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

 Posted: Wed Jun 04, 2008 11:46 pm    Post subject: 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.
Antonio Barata
Warnings : 1

New User

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

 Posted: Thu Jun 05, 2008 12:00 am    Post subject: Reply to: ISBN-13 check digit 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.
bbharathiraj
Warnings : 1

New User

Joined: 26 Oct 2006
Posts: 50
Location: Chennai

 Posted: Thu Jun 05, 2008 7:14 pm    Post subject: Reply to: ISBN-13 check digit Thanks to every one. All your codes are working fine.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics GDG gen check using REXX raghuraman123 CLIST & REXX 6 Wed Apr 18, 2018 9:18 pm How syntax check at Bind time is diff... Poha Eater DB2 5 Wed Mar 21, 2018 9:16 pm ALPHABETIC check in COBOL vidyaa COBOL Programming 8 Thu Aug 17, 2017 7:13 pm Check if any Detail records and extra... V S Amarendra Reddy SYNCSORT 19 Mon May 08, 2017 8:54 pm Check Binary Values for symbols gandikk CA Products 3 Tue Mar 21, 2017 5:11 am

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us