Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

file manipulation using cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions
View previous topic :: :: View next topic  
Author Message
mighty

New User


Joined: 21 May 2008
Posts: 22
Location: chennai

PostPosted: Fri Aug 15, 2008 9:41 pm    Post subject: file manipulation using cobol
Reply with quote

I have an input file with n number of records.
I have to write the 3rd record from the last to my output file using cobol.

Can anyone explain me how to achieve this.
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


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

PostPosted: Fri Aug 15, 2008 10:03 pm    Post subject:
Reply with quote

since you have to write the 3rd record from the last:

3rd
2rd
1st
last
eof

I would read and save records in a 4 item table.

open input

perform varying index from 1 to 4
read
move record to item(index)
end-perform

read

perform until eof
move items 2/3/4 to 1/2/3 (i would make it a group move)
move record to item(4)
read
end-perform

close input

open output

write item(1)

close output

goback.

this logic obviously assums you have 4 or more records.

if it turns out that we are basing on 3 records, modify the logic accordingly
Back to top
View user's profile Send private message
mighty

New User


Joined: 21 May 2008
Posts: 22
Location: chennai

PostPosted: Fri Aug 15, 2008 10:19 pm    Post subject:
Reply with quote

can you explain me this in detail

"move items 2/3/4 to 1/2/3 (i would make it a group move) "

how to move records like this

for example my input file layout
empid name
1 a
2 b
3 c
4 d
5 e

Thanks for your quick response
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: Sat Aug 16, 2008 12:06 am    Post subject:
Reply with quote

Hello,

In your example data, which record do you consider "the 3rd record from the last"?
Back to top
View user's profile Send private message
Pedro

Senior Member


Joined: 01 Sep 2006
Posts: 2038
Location: Silicon Valley

PostPosted: Sat Aug 16, 2008 1:32 am    Post subject: Reply to: file manipulation using cobol
Reply with quote

You have an array, initialized to blanks. You have a loop which reads a record. Each time you read, you move the old ones up 1 and add the new record at the end.
Code:
init      pass 1    pass 2    pass 3    pass 4   ... pass 531   pass 532
1 empty   1 empty   1 empty   1 empty   1 rec 1      1 rec528   1 rec529
2 empty   2 empty   2 empty   2 rec 1   2 rec 2      2 rec529   2 rec530
3 empty   3 empty   3 rec 1   3 rec 2   3 rec 3      3 rec530   3 rec531
4 empty   4 rec 1   4 rec 2   4 rec 3   4 rec 4      4 rec531   4 rec532
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: Sat Aug 16, 2008 1:46 am    Post subject: Reply to: file manipulation using cobol
Reply with quote

Yup, the only question now is which does TS consider the "3rd from the last". . .

d
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Sat Aug 16, 2008 10:43 am    Post subject:
Reply with quote

What Dick meant by group move is like this:
Code:
01  last-three-recs.
    05  last-rec                     pic  x(80).
    05  second-from-last-rec         pic  x(80).
    05  third-from-last-rec          pic  x(80).
01  redefines last-three-recs.
    05  last-two-recs                pic  x(160).
    05                               pic  x(80).
01  redefines last-three-recs.
    05                               pic  x(80).
    05  shift-em-down-one            pic  x(160).


move last-two-recs to shift-em-down-one,
read your-file into last-rec,
repeat the above move and read until end of file at which time third-from-last-rec is the one you want. The above assumes a LRECL of 80.
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Sat Aug 16, 2008 11:00 am    Post subject:
Reply with quote

I've asked for edit authority on my own posts but haven't gotten it yet. I would have aligned the pic clauses. Also, Dick mentioned group move although mine are elementary moves but I believe it's the functionality that he was alluding to.
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: Sat Aug 16, 2008 8:48 pm    Post subject:
Reply with quote

Hi Terry,

Quote:
I've asked for edit authority on my own posts but haven't gotten it yet.
Even moderators cannot edit all of their own posts. . .

Quote:
I would have aligned the pic clauses.
Using "Preview" lets you see your post the way the forum will see it rather than the way it looks in the reply editor. While it doesn't help after the submit, it can help "up front".

fwiw.
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Sun Aug 17, 2008 8:26 am    Post subject:
Reply with quote

Thanks Dick. I didn't realize that editing wasn't allowed. Some bulletin boards allow editing after you've shown that you won't abuse the privilege! I should have thought of the Preview option before submitting.
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: Sun Aug 17, 2008 8:32 am    Post subject: Reply to: file manipulation using cobol
Reply with quote

You're welcome icon_smile.gif

d
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Mon Aug 18, 2008 11:17 am    Post subject:
Reply with quote

Hi,
Terry Heinze wrote:
I've asked for edit authority on my own posts but haven't gotten it yet.
Sometimes, when editing is quite necessary I request some Moderator via PM, they had been pretty helpful so far.. icon_smile.gif
Back to top
View user's profile Send private message
mighty

New User


Joined: 21 May 2008
Posts: 22
Location: chennai

PostPosted: Mon Aug 18, 2008 10:31 pm    Post subject:
Reply with quote

Thanks all for your help.The answer for my question got clarified from your posts
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 -> Mainframe Interview Questions All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Converting Variable block file to Fix... bhavana yalavarthi DFSORT/ICETOOL 10 Tue May 16, 2017 2:20 pm
This topic is locked: you cannot edit posts or make replies. Cobol GUI (like Editor) Kala Mainframe COBOL Programming 14 Wed May 10, 2017 12:30 pm
No new posts IMS T-Pipe queue counts in a COBOL Pr... Siva NKK Kothamasu IMS DB/DC 0 Tue May 09, 2017 6:31 pm
No new posts Getting error while opening a variabl... apandey1 COBOL Programming 5 Fri May 05, 2017 12:22 pm
No new posts Issue with NDM process to transmit ES... chetanambi All Other Mainframe Topics 6 Wed May 03, 2017 10:52 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us