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

How to write only the last 30 records from an array to file


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

New User


Joined: 16 Mar 2007
Posts: 19
Location: Pune

PostPosted: Fri Jun 22, 2007 11:58 am
Reply with quote

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

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Fri Jun 22, 2007 12:29 pm
Reply with quote

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

New User


Joined: 16 Mar 2007
Posts: 19
Location: Pune

PostPosted: Fri Jun 22, 2007 1:02 pm
Reply with quote

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

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Fri Jun 22, 2007 2:14 pm
Reply with quote

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
View user's profile Send private message
Naresh Kumar Reddy P

New User


Joined: 24 May 2007
Posts: 8
Location: Bangalore

PostPosted: Fri Jun 22, 2007 4:31 pm
Reply with quote

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

Moderator Emeritus


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

PostPosted: Fri Jun 22, 2007 7:41 pm
Reply with quote

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

New User


Joined: 03 Nov 2005
Posts: 43
Location: St.Louis

PostPosted: Sat Jun 23, 2007 1:02 am
Reply with quote

Gd thought dick...should work fine..
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 Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top