Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How to write only the last 30 records from an array to file

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How to write only the last 30 records from an array to file
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: 1439
Location: Bangalore,India

PostPosted: Fri Jun 22, 2007 12:29 pm    Post subject:
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    Post subject:
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: 1439
Location: Bangalore,India

PostPosted: Fri Jun 22, 2007 2:14 pm    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Fri Jun 22, 2007 7:41 pm    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Split 1 file into 10 output Files - S... Prasanth Kumar SYNCSORT 5 Sat Sep 16, 2017 12:02 am
No new posts BUILD OUTFIL based on condition other... balaji81_k DFSORT/ICETOOL 13 Fri Sep 08, 2017 11:06 pm
No new posts Skip file from delete pema_yozer All Other Mainframe Topics 3 Tue Aug 29, 2017 3:19 pm
No new posts Join records from 2 files with No Dup... Poha Eater DFSORT/ICETOOL 21 Sun Aug 27, 2017 10:35 pm
No new posts editting the file by inserting zeros ... pramodrsingh DFSORT/ICETOOL 9 Mon Aug 21, 2017 5:58 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us