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

Implement the below logic with a single PERFORM statement


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

New User


Joined: 26 Sep 2006
Posts: 38
Location: India

PostPosted: Mon Apr 20, 2009 4:36 pm
Reply with quote

Hi All,

I have one single dimensional array with 200 elements. The existing logic is to take first 99 elements and load in to second array which can hold upto 100 elements. Now I need to map values from 160 and 166th position from the first array To 23rd and 24th position of the second array as well. Because the values present in 160, 166 positions are required and 23,24 positions in second array are free. So we can use these.

Can anybody suggest me whether I can implement the above logic with a single PERFORM statement.

Below please find the current logic.


Code:
PERFORM VARYING CNT1 FROM 1 BY 1 UNTIL CNT1 > TOT-COUNT
                                    OR CNT1 > 99           
 MOVE .....
 MOVE ......   
 
END-PERFORM.

Here TOT-COUNT --> Total element count in first array.
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Mon Apr 20, 2009 5:02 pm
Reply with quote

Certainly it is possible but need some clarification first...

Quote:
The existing logic is to take first 99 elements and load in to second array which can hold upto 100 elements


Quote:
23,24 positions in second array are free


These two statements are conflicting...

by first statement 23,24th pos of of second array will be already holding value from 23,24 pos of first array...
so how you are saying 23,24 pos in second array are free??

please clarify..
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Mon Apr 20, 2009 5:04 pm
Reply with quote

Your pseudo-code should work properly, when used together with several PERFORM's.

To incorporate all that you need to do into a single PERFORM, may cause your colleagues some heartache (as well as dirty looks) icon_wink.gif

There's really no reason to make this complicated or clever (with a single PERFORM) and your colleagues will appreciate the easiest method possible (for future maintenance consideration).

Just my .02 cents....

Regards,
Back to top
View user's profile Send private message
jsnair

New User


Joined: 26 Sep 2006
Posts: 38
Location: India

PostPosted: Mon Apr 20, 2009 5:39 pm
Reply with quote

Hi Sambhaji,

What I mean the values present in positions 23 and 24 are currently not using. So we can map with the new values.
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Mon Apr 20, 2009 6:08 pm
Reply with quote

Ok..
If I understand correctly you can use below..
Code:

PERFORM VARYING CNT1 FROM 1 BY 1 UNTIL CNT1 > TOT-COUNT
                                    OR CNT1 > 99           

IF CNT1 NOT = 23 AND CNT1 NOT = 24
     MOVE FARRAY(CNT1) TO SARRAY(CNT1)
ELSE IF CNT1=23
      MOVE FARRAY(160) TO SARRAY(CNT1)
     ELSE
      MOVE FARRAY(166) TO SARRAY(CNT1)
     END-IF
END-IF 

END-PERFORM.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Apr 20, 2009 8:55 pm
Reply with quote

the if statement is correct,
but following-up with what Bill said about changing requirements,
an EVALUATE statement would be
  • easier to modify
  • easier to read and understand:

Code:

PERFORM VARYING  CNT1
           FROM  1
             BY  1
          UNTIL  CNT1 > TOT-COUNT
             OR  CNT1 > 99           
   EVALUATE  TRUE
       WHEN  CNT1=23
             MOVE FARRAY(160)  TO SARRAY(CNT1)
       WHEN  CNT1=24
             MOVE FARRAY(166)  TO SARRAY(CNT1)
       WHEN  OTHER
             MOVE FARRAY(CNT1) TO SARRAY(CNT1)
   END-EVALUATE

END-PERFORM
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Apr 20, 2009 9:54 pm
Reply with quote

Quote:
Can anybody suggest me whether I can implement the above logic with a single PERFORM statement.

do You have a doctor' s prescription to do it inside a single perform ??

why not use a perform to fill 99 entries
at the end move the two spurious lines where they belong
simpler more clear

something like ...
Code:
PERFORM VARYING  CNT1  FROM  1  BY  1
             UNTIL  CNT1 > TOT-COUNT OR  CNT1 > 99           
   MOVE FARRAY(CNT1) TO SARRAY(CNT1)
END-PERFORM
MOVE FARRAY(160)  TO SARRAY(23)
MOVE FARRAY(166)  TO SARRAY(24)


also it will save all the evaluate stuff from being repeated
when You know that the result will be true only in the 2% of the iterations
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Tue Apr 21, 2009 5:49 am
Reply with quote

As a sidenote, make sure CNT1 and TOT-COUNT are both larger enough to hold a value greater than 99.

If you define them as 9(08) COMP, COMP-4, BINARY or COMP-5, you'll never have to worry.... icon_wink.gif
Back to top
View user's profile Send private message
jsnair

New User


Joined: 26 Sep 2006
Posts: 38
Location: India

PostPosted: Wed Apr 29, 2009 2:17 pm
Reply with quote

Thanks Sambhaji, Dick, enrico and Bill for your valuable suggestions...
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 How to append a PS file into multiple... JCL & VSAM 3
No new posts Use of Perform Thru Exit COBOL Programming 6
No new posts Submit multiple jobs from a library t... JCL & VSAM 14
No new posts Convert single row multi cols to sing... DFSORT/ICETOOL 6
No new posts JOIN STATEMENT PERFORMANCE. DFSORT/ICETOOL 12
Search our Forums:

Back to Top