|
View previous topic :: View next topic
|
| Author |
Message |
zh_lad
Active User
Joined: 06 Jun 2009 Posts: 115 Location: UK
|
|
|
|
Hi, Happy New Year to you all. I am back to the task.
| Code: |
//SORTIN DD *
518791041070069
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC IFTHEN=(WHEN=INIT,
BUILD=(1,1,UFF,MUL,+2,EDIT(TT),
2,1,UFF,MUL,+1,EDIT(TT),
3,1,UFF,MUL,+2,EDIT(TT),
4,1,UFF,MUL,+1,EDIT(TT),
5,1,UFF,MUL,+2,EDIT(TT),
6,1,UFF,MUL,+1,EDIT(TT),
7,1,UFF,MUL,+2,EDIT(TT),
8,1,UFF,MUL,+1,EDIT(TT),
9,1,UFF,MUL,+2,EDIT(TT),
10,1,UFF,MUL,+1,EDIT(TT),
11,1,UFF,MUL,+2,EDIT(TT),
12,1,UFF,MUL,+1,EDIT(TT),
13,1,UFF,MUL,+2,EDIT(TT),
14,1,UFF,MUL,+1,EDIT(TT),
15,1,UFF,MUL,+2,EDIT(TT)))
OUTREC BUILD=(1,1,ZD,ADD,
2,1,ZD,ADD,
3,1,ZD,ADD,
4,1,ZD,ADD,
5,1,ZD,ADD,
6,1,ZD,ADD,
7,1,ZD,ADD,
8,1,ZD,ADD,
9,1,ZD,ADD,
10,1,ZD,ADD,
11,1,ZD,ADD,
12,1,ZD,ADD,
13,1,ZD,ADD,
14,1,ZD,ADD,
15,1,ZD,ADD,
16,1,ZD,ADD,
17,1,ZD,ADD,
18,1,ZD,ADD,
19,1,ZD,ADD,
20,1,ZD,ADD,
21,1,ZD,ADD,
22,1,ZD,ADD,
23,1,ZD,ADD,
24,1,ZD,ADD,
25,1,ZD,ADD,
26,1,ZD,ADD,
27,1,ZD,ADD,
28,1,ZD,ADD,
29,1,ZD,ADD,
30,1,ZD,MUL,+9)
//SYSOUT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
|
output is 116, it should have been 468 (52 x 9). I have checked, calculation is right up to 52. Something has gone wrong when MULT with 9. Is the length of 52 causing MULT with work differently?
Thanks. |
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
| Try enclosing all your ADDs in a separate () parenthesis |
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2290 Location: USA
|
|
|
|
Definitely: MUL has priority over ADD.
With all ADDs enclosed in () the result is correct.
Edited to remove spurious content |
|
| Back to top |
|
 |
zh_lad
Active User
Joined: 06 Jun 2009 Posts: 115 Location: UK
|
|
|
|
| Thanks Arun. |
|
| Back to top |
|
 |
zh_lad
Active User
Joined: 06 Jun 2009 Posts: 115 Location: UK
|
|
|
|
Hi Arun,
Thanks for your help so far. One last query. Is there a way I can do this calculation in INREC using multiple BUILD as I want to use the OUTREC to present data differently.
Currennt output is 468.
I want to stick right most digit (8 in this case) to original input value. In this case, my final output should be:
5187910410700698
This algorithm will be used on an input file to calculate check digit (Luhn algorithm).
Thanks. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| Yes, there is no need for the OUTREC, you could put the second BUILD on another WHEN=INIT on INREC. |
|
| Back to top |
|
 |
zh_lad
Active User
Joined: 06 Jun 2009 Posts: 115 Location: UK
|
|
|
|
Thanks Bill. It worked with two BUILDs with WHEN=INIT.
Now I am working on OUTREC to stick right most digit to original input. Thanks for your help. Cheers! |
|
| Back to top |
|
 |
zh_lad
Active User
Joined: 06 Jun 2009 Posts: 115 Location: UK
|
|
|
|
I have managed to calculate check digit using:
| Code: |
//SORTIN DD *
518791041070069
518621031103021
518621031103022
518621031103023
494000111111111
456215111111112
420376111111113
457150111111114
446272111111115
431940111111116
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC IFTHEN=(WHEN=INIT,
BUILD=(1,15,1,1,UFF,MUL,+2,EDIT(TT),
2,1,UFF,MUL,+1,EDIT(TT),
3,1,UFF,MUL,+2,EDIT(TT),
4,1,UFF,MUL,+1,EDIT(TT),
5,1,UFF,MUL,+2,EDIT(TT),
6,1,UFF,MUL,+1,EDIT(TT),
7,1,UFF,MUL,+2,EDIT(TT),
8,1,UFF,MUL,+1,EDIT(TT),
9,1,UFF,MUL,+2,EDIT(TT),
10,1,UFF,MUL,+1,EDIT(TT),
11,1,UFF,MUL,+2,EDIT(TT),
12,1,UFF,MUL,+1,EDIT(TT),
13,1,UFF,MUL,+2,EDIT(TT),
14,1,UFF,MUL,+1,EDIT(TT),
15,1,UFF,MUL,+2,EDIT(TT))),
IFTHEN=(WHEN=INIT,
BUILD=(1,15,(16,1,ZD,ADD,
17,1,ZD,ADD,
18,1,ZD,ADD,
19,1,ZD,ADD,
20,1,ZD,ADD,
21,1,ZD,ADD,
22,1,ZD,ADD,
23,1,ZD,ADD,
24,1,ZD,ADD,
25,1,ZD,ADD,
26,1,ZD,ADD,
27,1,ZD,ADD,
28,1,ZD,ADD,
29,1,ZD,ADD,
30,1,ZD,ADD,
31,1,ZD,ADD,
32,1,ZD,ADD,
33,1,ZD,ADD,
34,1,ZD,ADD,
35,1,ZD,ADD,
36,1,ZD,ADD,
37,1,ZD,ADD,
38,1,ZD,ADD,
39,1,ZD,ADD,
40,1,ZD,ADD,
41,1,ZD,ADD,
42,1,ZD,ADD,
43,1,ZD,ADD,
44,1,ZD,ADD,
45,1,ZD,ADD,
46,1,ZD),MUL,+9))
OUTREC FIELDS=(1,15,30,1)
//SYSOUT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
|
| Code: |
Output:
5187910410700698
5186210311030217
5186210311030225
5186210311030233
4940001111111111
4562151111111129
4203761111111138
4571501111111140
4462721111111153
4319401111111165 |
Is there any better way to write above code? Thanks. |
|
| Back to top |
|
 |
zh_lad
Active User
Joined: 06 Jun 2009 Posts: 115 Location: UK
|
|
|
|
I am doing this when I am free. If I wanted to do then I too could have written a cobol program in an hour.
SORT gives me flexibility to re use code for different files and layout. |
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
Maybe you can remove the calculations that are not required and also directly overlay the final 'result digit', like this:
| Code: |
//SYSIN DD *
OPTION COPY
INREC IFOUTLEN=16,IFTHEN=(WHEN=INIT,
OVERLAY=(16:1,1,UFF,MUL,+2,EDIT(TT),
3,1,UFF,MUL,+2,EDIT(TT),
5,1,UFF,MUL,+2,EDIT(TT),
7,1,UFF,MUL,+2,EDIT(TT),
9,1,UFF,MUL,+2,EDIT(TT),
11,1,UFF,MUL,+2,EDIT(TT),
13,1,UFF,MUL,+2,EDIT(TT),
15,1,UFF,MUL,+2,EDIT(TT),
16:(16,1,ZD,ADD,
17,1,ZD,ADD,
18,1,ZD,ADD,
19,1,ZD,ADD,
20,1,ZD,ADD,
21,1,ZD,ADD,
22,1,ZD,ADD,
23,1,ZD,ADD,
24,1,ZD,ADD,
25,1,ZD,ADD,
26,1,ZD,ADD,
27,1,ZD,ADD,
28,1,ZD,ADD,
29,1,ZD,ADD,
30,1,ZD,ADD,
31,1,ZD,ADD,
02,1,ZD,ADD,
04,1,ZD,ADD,
06,1,ZD,ADD,
08,1,ZD,ADD,
10,1,ZD,ADD,
12,1,ZD,ADD,
14,1,ZD),MUL,+9,EDIT=(T))) |
|
|
| Back to top |
|
 |
zh_lad
Active User
Joined: 06 Jun 2009 Posts: 115 Location: UK
|
|
|
|
Thanks Arun. Looks brilliant.
I am getting slightly incorrect result with this code.
| Code: |
//SORTIN DD *
518791041070069
//SYSIN DD *
OPTION COPY
INREC IFOUTLEN=16,IFTHEN=(WHEN=INIT,
OVERLAY=(16:1,1,UFF,MUL,+2,EDIT(TT),
3,1,UFF,MUL,+2,EDIT(TT),
5,1,UFF,MUL,+2,EDIT(TT),
7,1,UFF,MUL,+2,EDIT(TT),
9,1,UFF,MUL,+2,EDIT(TT),
11,1,UFF,MUL,+2,EDIT(TT),
13,1,UFF,MUL,+2,EDIT(TT),
15,1,UFF,MUL,+2,EDIT(TT),
16:(16,1,ZD,ADD,
17,1,ZD,ADD,
18,1,ZD,ADD,
19,1,ZD,ADD,
20,1,ZD,ADD,
21,1,ZD,ADD,
22,1,ZD,ADD,
23,1,ZD,ADD,
24,1,ZD,ADD,
25,1,ZD,ADD,
27,1,ZD,ADD,
28,1,ZD,ADD,
29,1,ZD,ADD,
30,1,ZD,ADD,
31,1,ZD,ADD,
32,1,ZD,ADD,
02,1,ZD,ADD,
04,1,ZD,ADD,
06,1,ZD,ADD,
08,1,ZD,ADD,
10,1,ZD,ADD,
12,1,ZD,ADD,
14,1,ZD),MUL,+9,EDIT=(T))) |
output is:
Check digit should be '8'. Addition is resulting 51, should have been 52.
51 x 9 = 459 ==> resulting CH as '9'.
52 x 9 = 468 ==> results CH as '8'.
Thanks. |
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
| You missed the '26,1,ZD,ADD' and you have an extra line instead - '32,1,ZD,ADD' |
|
| Back to top |
|
 |
zh_lad
Active User
Joined: 06 Jun 2009 Posts: 115 Location: UK
|
|
|
|
| Sorted. Thanks. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|