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

Getting records alternatively from a sequential file in cobo


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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

Superior Member


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

PostPosted: Mon Sep 29, 2008 12:31 pm
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: 2481
Location: @my desk

PostPosted: Mon Sep 29, 2008 12:37 pm
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Sep 29, 2008 12:59 pm
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

Superior Member


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

PostPosted: Mon Sep 29, 2008 1:03 pm
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

Superior Member


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

PostPosted: Mon Sep 29, 2008 1:10 pm
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: 2481
Location: @my desk

PostPosted: Mon Sep 29, 2008 1:31 pm
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
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

Moderator Emeritus


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

PostPosted: Mon Sep 29, 2008 11:58 pm
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

Superior Member


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

PostPosted: Tue Sep 30, 2008 9:58 am
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
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: 2481
Location: @my desk

PostPosted: Tue Sep 30, 2008 2:39 pm
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 2
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
Search our Forums:

Back to Top