Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 100001 IDENTIFICATION DIVISION.
- 100002 PROGRAM-ID. LUHNTEST.
- 100003 ENVIRONMENT DIVISION.
- 100004 INPUT-OUTPUT SECTION.
- 100005 data division.
- 100006 WORKING-STORAGE SECTION.
- 100007 01 inp-card.
- 100008 03 inp-card-ch pic x(01) occurs 20 times.
- 100009 01 ws-result pic 9(01).
- 100010 88 pass-luhn-test value 0.
- 100011
- 100012 PROCEDURE DIVISION.
- 100013 move "49927398716" to inp-card
- 100014 perform test-card
- 100015 move "49927398717" to inp-card
- 100016 perform test-card
- 100017 move "1234567812345678" to inp-card
- 100018 perform test-card
- 100019 move "1234567812345670" to inp-card
- 100020 perform test-card
- 100021 stop run
- 100022 .
- 100023 test-card.
- 100024 call "LUHN" using inp-card, ws-result
- 100025 if pass-luhn-test
- 100026 display "input=" inp-card "pass"
- 100027 else
- 100028 display "input=" inp-card "fail"
- 100029 .
- 100030
- 100031 END PROGRAM LUHNTEST.
- 100032 IDENTIFICATION DIVISION.
- 100033 PROGRAM-ID. LUHN.
- 100034 ENVIRONMENT DIVISION.
- 100035 INPUT-OUTPUT SECTION.
- 100036 DATA DIVISION.
- 100037 WORKING-STORAGE SECTION.
- 100038 01 maxlen pic 9(02) comp value 16.
- 100039 01 inplen pic 9(02) comp value 0.
- 100040 01 i pic 9(02) comp value 0.
- 100041 01 j pic 9(02) comp value 0.
- 100042 01 l pic 9(02) comp value 0.
- 100043 01 dw pic 9(02) comp value 0.
- 100044 01 ws-total pic 9(03) comp value 0.
- 100045 01 ws-prod pic 99.
- 100046 01 filler redefines ws-prod.
- 100047 03 ws-prod-tens pic 9.
- 100048 03 ws-prod-units pic 9.
- 100049 01 ws-card.
- 100050 03 filler occurs 16 times depending on maxlen.
- 100051 05 ws-card-ch pic x(01).
- 100052 05 ws-card-digit redefines ws-card-ch pic 9(01).
- 100053 LINKAGE SECTION.
- 100054 01 inp-card.
- 100055 03 inp-card-ch pic x(01) occurs 20 times.
- 100056 01 ws-result pic 9(01).
- 100057 88 pass-luhn-test value 0.
- 100058
- 100059 PROCEDURE DIVISION using inp-card, ws-result.
- 100060 perform varying i from 1 by +1
- 100061 until i > maxlen
- 100062 or inp-card-ch (i) = space
- 100063 end-perform
- 100064 compute l = i - 1
- 100065 compute inplen = l
- 100066 perform varying j from 1 by +1
- 100067 until j > inplen
- 100068 if l < 1
- 100069 move "0" to ws-card-ch (j)
- 100070 else
- 100071 move inp-card-ch (l) to ws-card-ch (j)
- 100072 compute l = l - 1
- 100073 end-if
- 100074 end-perform
- 100075 move 0 to ws-total
- 100076 perform varying i from 1 by +1
- 100077 until i > inplen
- 100078 compute dw = 2 - (i - 2 * function integer (i / 2))
- 100079 compute ws-prod = ws-card-digit (i) * dw
- 100080 compute ws-total = ws-total
- 100081 + ws-prod-tens
- 100082 + ws-prod-units
- 100083 end-perform
- 100084 compute ws-result = ws-total - 10 * function integer (ws-total / 10)
- 100085 goback
- 100086 .
- 100087 END PROGRAM LUHN.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement