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
 

 

Getting records alternatively from a sequential file in cobo

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
sri541

New User


Joined: 13 Jul 2006
Posts: 4

PostPosted: Mon Sep 29, 2008 12:09 pm    Post subject: Getting records alternatively from a sequential file in cobo
Reply with quote

Hi

I have one i/p file like...
1
2
3
4
5
6
I require an o/p like
2
4
6
How to code this in cobol using sequetail files....... no jcl sorting.
Back to top
View user's profile Send private message

ramakrishnag

New User


Joined: 10 Sep 2008
Posts: 6
Location: india

PostPosted: Mon Sep 29, 2008 12:27 pm    Post subject: Reply to: Getting records alternatively from a sequential fi
Reply with quote

Hi

If your just looking for skip each record after written the record.

Then use the preform read-para until EOF.

In the para use the count variable and increament by one. check count variable reminder using the divide by 2 and giving X variable and check if the X reminder is zero then write the record into output file if not skip.

Issue the next read command.

Thanks,
Rama
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 Sep 29, 2008 12:31 pm    Post subject:
Reply with quote

One way can be -

- read input file,
- on every add 1 to some count varaiable
- if count variable is even, write to output.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2171
Location: @my desk

PostPosted: Mon Sep 29, 2008 12:37 pm    Post subject:
Reply with quote

Hello sri541,

Here's one more way. icon_lol.gif
Code:
Read input-file             
Move WS-FLAG = 'N'         
                           
Perform until e-o-f
         
   If WS-FLAG = 'N'         
      Move 'Y' TO WS-FLAG   
   else                     
      Write record to output
      Move 'N' TO WS-FLAG   
   End-if
                   
   Read input-file         

End-perform
Back to top
View user's profile Send private message
sri541

New User


Joined: 13 Jul 2006
Posts: 4

PostPosted: Mon Sep 29, 2008 12:50 pm    Post subject:
Reply with quote

Thanks all,

I know this procedure. Other than this we have any other procedure to find out.
Please help me.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Mon Sep 29, 2008 12:59 pm    Post subject: Reply to: Getting records alternatively from a sequential fi
Reply with quote

You got many advices and one working solution...
what else are You looking for icon_evil.gif
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 Sep 29, 2008 1:03 pm    Post subject:
Reply with quote

Hi Arun,

Being lil picky tonight..what's this line of code is
Code:
Move WS-FLAG = 'N'
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 Sep 29, 2008 1:10 pm    Post subject:
Reply with quote

sri541,

You rule out the possibility of JCL solution so I didn't post them otherwise you could try these. If there is osmething specific, you need - explain that.
Code:
//S1 EXEC PGM=ICEMAN
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=...  input file
//SORTOUT DD DSN=...  output file
//SYSIN DD *
   SORT FIELDS=(...)
   OUTFIL STARTREC=2,SAMPLE=2
/*

or
Code:
//S1    EXEC  PGM=ICEMAN                 
//SYSOUT    DD  SYSOUT=*                 
//SORTIN DD DSN=... input file                             
//ODD DD DSN=...  output file1 (odd records)                         
//EVEN DD DSN=...  output file2 (even records)                       
//SYSIN DD *                             
  SORT FIELDS=COPY                       
  OUTFIL FNAMES=(ODD,EVEN),SPLIT         
/*     
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2171
Location: @my desk

PostPosted: Mon Sep 29, 2008 1:31 pm    Post subject:
Reply with quote

Anuj D. wrote:
Hi Arun,

Being lil picky tonight..what's this line of code is
Code:
Move WS-FLAG = 'N'

Anuj,

I think that was a piece of pseudocode. icon_lol.gif
Back to top
View user's profile Send private message
ridgewalker58

New User


Joined: 26 Sep 2008
Posts: 51
Location: New York

PostPosted: Mon Sep 29, 2008 10:20 pm    Post subject:
Reply with quote

Read input-file.
Add 1 to ws-toggle-sw.
>>>> described 01 ws-toggle-sw pic 9 value zero.

If ws-toggle-sw = 2
write output-record from input-record
move zero to ws-toggle-sw.
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: Mon Sep 29, 2008 11:58 pm    Post subject:
Reply with quote

Hello,

Quote:
I know this procedure. Other than this we have any other procedure to find out.
Please help me.
Why do you need help? You have been given multiple answers already.

You have something in mind that you have not yet posted. If/when you post a better description of your requirement or explain why none of the posted answers are acceptable, someone may be able to respond.
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


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

PostPosted: Tue Sep 30, 2008 9:58 am    Post subject:
Reply with quote

arcvns wrote:
I think that was a piece of pseudocode. icon_lol.gif
Ok, forgiven.. icon_razz.gif
Back to top
View user's profile Send private message
anil.csk

New User


Joined: 22 Oct 2007
Posts: 16
Location: Noida

PostPosted: Tue Sep 30, 2008 2:19 pm    Post subject: Reply to: Getting records alternatively from a sequential fi
Reply with quote

for reading the records alternatively from sequential file move all the records to an One dimensional error then you can display your required records,
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2171
Location: @my desk

PostPosted: Tue Sep 30, 2008 2:39 pm    Post subject:
Reply with quote

Quote:
One dimensional error
Anil,

That was really a one dimensional error. icon_lol.gif If what you meant is a working-storage table, you really don't need that. Think of a case where your input file has 50 million records. Secondly why would you want to have an additional pass of data.
Back to top
View user's profile Send private message
aparicio esteves

New User


Joined: 17 Sep 2008
Posts: 4
Location: Lisbon

PostPosted: Thu Oct 02, 2008 12:55 pm    Post subject:
Reply with quote

You can try this structured mode

PERFORM READ-INPUT 2 TIMES
PERFORM
UNTIL BEYOND-END-OF-FILE
OR END-OF-FILE
PERFORM WRITE-OUTPUT
PERFORM READ-INPUT 2 TIMES
END-PERFORM

READ-INPUT.
READ FILE-INPUT
IF FILE-STATUS = '46'
SET BEYOND-END-OF-FILE TO TRUE
END-IF
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Oct 02, 2008 1:41 pm    Post subject:
Reply with quote

Jose,

why not assign a level 88 variable to FILE-STATUS for Beyond-end-of-file and then you can save the SET statement.
I would also have a level 88 FILE-OK value '00' or 00.
I assume END-OF-FILE is a level 88 of FILE-STATUS with value of '10' or 10.

I would also modify your READ-INPUT paragraph to the following:
Code:

READ-INPUT.

IF FILE-OK
THEN
    READ FILE-INPUT INTO WORK-AREA
    END-READ
END-IF


Would suggest using the workarea option on reads and writes.
Checking for FILE-OK before reading, allows you to avoid reading beyond EOF, as well as trying to read a file that opened with an error.
Back to top
View user's profile Send private message
aparicio esteves

New User


Joined: 17 Sep 2008
Posts: 4
Location: Lisbon

PostPosted: Fri Oct 03, 2008 12:51 pm    Post subject:
Reply with quote

Dick,

Thanks for the advise, and taking it into account, I rewritted the code.
Code:

    PERFORM TRY-TO-READ-INPUT-FILE-2-TIMES
    PERFORM WITH TEST AFTER
      UNTIL  END-OF-FILE
     PERFORM WRITE-OUTPUT
     PERFORM TRY-TO-READ-INPUT-FILE-2-TIMES
    END-PERFORM

TRY-TO-READ-INPUT-FILE-2-TIMES.
    READ FILE-INPUT
    IF FILE-OK
       READ FILE-INPUT
    END-IF.
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 Removing Duplicates based on certain ... chandracdac DFSORT/ICETOOL 5 Fri Dec 09, 2016 4:40 am
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm


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