View previous topic :: View next topic
|
Author |
Message |
jsnair
New User
Joined: 26 Sep 2006 Posts: 38 Location: India
|
|
|
|
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 |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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)
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 |
|
|
jsnair
New User
Joined: 26 Sep 2006 Posts: 38 Location: India
|
|
|
|
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 |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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.... |
|
Back to top |
|
|
jsnair
New User
Joined: 26 Sep 2006 Posts: 38 Location: India
|
|
|
|
Thanks Sambhaji, Dick, enrico and Bill for your valuable suggestions... |
|
Back to top |
|
|
|