View previous topic :: View next topic
|
Author |
Message |
sangee27
New User
Joined: 16 Mar 2007 Posts: 19 Location: Pune
|
|
|
|
Hi,
I have a requirement like below:
I have an array defined as :
01 WS-ARRAY.
02 WS-TABLE OCCURS 50 TIMES
INDEXED BY WS-I.
05 WS-value1 PIC 9(02) VALUE ZEROES.
05 WS-value2 PIC 9(02) VALUE ZEROES.
05 WS-value 3 PIC X(20) VALUE SPACES.
Now i am having 40 records in the array which was loaded from a file.
And i want to write only last 30 records into output file.
Please let me know how to proceed with this.
Thanks in advance. |
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
sangee27,
If the number of records are always going to be 40, start writing the records from 11th occurence to 40th by putting in a loop.
Else follow this -
(1) Intialize the table while declaring it in working-storage section.
(2) Load the records into the table.
(3) Since you know the table size (50 here), start from 50 counting down by 1 till you get the first occurence of data.
(4) Deduct 30 from this above occurence and write the data into the file. |
|
Back to top |
|
|
sangee27
New User
Joined: 16 Mar 2007 Posts: 19 Location: Pune
|
|
|
|
Hi Murali,
Thanks for your inputs.
The number of records loaded into the array table differs each time. Sometimes it will be less than 30, in that case i have to write all the records into the output file, if it's more than 30 then i have to write last 30 records into the output file.
And i could not understand your third point clearly. Could you please explain that.
Thanks. |
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
Quote: |
And i could not understand your third point clearly. Could you please explain that. |
Quote: |
02 WS-TABLE OCCURS 50 TIMES
|
Code: |
PEFORM SOME-PARA VARYING WS-SUB FROM 50 BY -1 UNTIL
WS-SUB NOT EQUALS ZERO.
IF WS-SUB1 <= 30 (if records are less or equal to 30)
write records from start to WS-TABLE(WS-SUB1)
ELSE (if records are greater than 30)
COMPUTE WS-SUB1 = WS-SUB1 - 30
put loop to write 30 records from WS-TABLE(WS-SUB1)
END-IF.
.
.
SOME-PARA.
IF WS-TABLE(WS-SUB) NOT = intialised value
MOVE WS-SUB TO WS-SUB1
MOVE 0 TO WS-SUB
END-IF.
|
|
|
Back to top |
|
|
Naresh Kumar Reddy P
New User
Joined: 24 May 2007 Posts: 8 Location: Bangalore
|
|
|
|
sangee27,
Try the below logic:
Quote: |
Now i am having 40 records in the array which was loaded from a file. |
1. Have a counter say ws-count while loading the array
2. If count is lessthan or equal 30, write all the records from first occurance.
3. Else write the all the records from (wscount-29)th occurance.
Thanks
Reddy |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
You will want the same bit of write-the-output code to work for any number of entries in the array, so i'd suggest your code be written to start at entry "f" and end at entry "l" (first/last to be copied).
While you are loading the array, keep track of the highest entry loaded. When the array load is complete, use the highest entry and do the appropriate arithmetic to detemine the "f" and "l" values, then invoke the write-the-output routine. |
|
Back to top |
|
|
Suryanarayana.tadala
New User
Joined: 03 Nov 2005 Posts: 43 Location: St.Louis
|
|
|
|
Gd thought dick...should work fine.. |
|
Back to top |
|
|
|