View previous topic :: View next topic
|
Author |
Message |
srikanthkailasam
New User
Joined: 13 Nov 2006 Posts: 24 Location: Bengalooru
|
|
|
|
I have a variable say TEMP which is a $ field. I have 35 different $ fields say A1,A2...A35 which can add up to TEMP in any order. For example.
A1+A2 can be = Temp in one case.
A1+A4+A34 can be =Temp in another case.
A1+A2+A3+....+A35 can be =Temp in another case.
I came up with a Peform array where in I will store the A1....A35.
I have taken a case where I have A1, A2, A3 and A4.
Code: |
PERFORM VARYING A FROM 1 TILL 4
PERFORM VARYING B FROM A+1 TILL 4
PERFORM VARYING C FROM B+1 TILL 4
PERFORM VARYING D FROM C+1 TILL 4
CHECK TEMP = Z(A) + Z(B) + Z(C) + Z(D)
END-PERFORM
CHECK TEMP = Z(A) + Z(B) + Z(C)
END-PERFORM
CHECK TEMP = Z(A) + Z(B) + Z(C)
END-PERFORM
CHECK TEMP = Z(A) + Z(B)
END-PERFORM. |
The above will work even for 35 fields, but is there any better solution to check the same |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
When people start a topic nearly every one of them requires help - which make that a meaningless topic subject. . .
Help may be required, but there is no definition of what is needed
What should happen if multiple combinations match "temp"? What should happen if none do? Will/should all of the values that are non-zero add up to temp? |
|
Back to top |
|
|
srikanthkailasam
New User
Joined: 13 Nov 2006 Posts: 24 Location: Bengalooru
|
|
|
|
Whenever I hit a TEMP, i should exit out of the loop. There can be more than one combination for TEMP but we should consider only the first hit. If there is no combination available, just exit out of loop. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
I'm still confused. . . When a hit is found, the loop should exit. When no combination is found, the loop should exit.
Quote: |
There can be more than one combination for TEMP but we should consider only the first hit. |
What should be considered?
Is this by chance an accounts receivable process that is trying to apply a payment to outstanding invoices? |
|
Back to top |
|
|
srikanthkailasam
New User
Joined: 13 Nov 2006 Posts: 24 Location: Bengalooru
|
|
|
|
Yes. It is exactly the same process you have mentioned.. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
It has been a long time and so this is from memory. Your organizations "rules" may also be different from what we used.
Our first cut was to look for an invoice that was an exact match (if the customer did not specify which invoice(s) to pay). Our next cut was something like what you have coded. We looked at the combination of any 10 invoices that were less than the payment amount for an exact match. Large customers could have hundreds of outstanding invoices . . . If there was not an exact match, we paid the oldest invoices up to the amoung of the payment.
Customers were not so happy with this as they wanted to get their discount and wanted the payment applied to the newest invoices. . . |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Using your logic, you are going to have PERFORMs nested 35 levels deep. I'd consider an alternate approach. |
|
Back to top |
|
|
srikanthkailasam
New User
Joined: 13 Nov 2006 Posts: 24 Location: Bengalooru
|
|
|
|
This is exactly what I want to avoid. Can someone suggest a better alternative approach? |
|
Back to top |
|
|
|