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

Perform array to add $ fields into a TEMP variable


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

New User


Joined: 13 Nov 2006
Posts: 24
Location: Bengalooru

PostPosted: Fri Feb 20, 2009 6:42 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Feb 20, 2009 8:15 am
Reply with quote

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 icon_confused.gif

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
View user's profile Send private message
srikanthkailasam

New User


Joined: 13 Nov 2006
Posts: 24
Location: Bengalooru

PostPosted: Fri Feb 20, 2009 9:37 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Feb 20, 2009 9:51 am
Reply with quote

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
View user's profile Send private message
srikanthkailasam

New User


Joined: 13 Nov 2006
Posts: 24
Location: Bengalooru

PostPosted: Fri Feb 20, 2009 10:21 am
Reply with quote

Yes. It is exactly the same process you have mentioned..
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Feb 21, 2009 7:57 am
Reply with quote

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
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Sun Feb 22, 2009 4:53 am
Reply with quote

Using your logic, you are going to have PERFORMs nested 35 levels deep. I'd consider an alternate approach.
Back to top
View user's profile Send private message
srikanthkailasam

New User


Joined: 13 Nov 2006
Posts: 24
Location: Bengalooru

PostPosted: Mon Feb 23, 2009 11:07 pm
Reply with quote

This is exactly what I want to avoid. Can someone suggest a better alternative approach?
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 Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Use of Perform Thru Exit COBOL Programming 6
No new posts XDC SDSF output to temp dataset CLIST & REXX 4
No new posts Variable Output file name DFSORT/ICETOOL 8
No new posts Moving Or setting POINTER to another ... COBOL Programming 2
Search our Forums:

Back to Top