View previous topic :: View next topic
|
Author |
Message |
sri541
New User
Joined: 13 Jul 2006 Posts: 4
|
|
|
|
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 |
|
|
ramakrishnag
New User
Joined: 10 Sep 2008 Posts: 6 Location: india
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
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 |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Hello sri541,
Here's one more way.
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 |
|
|
sri541
New User
Joined: 13 Jul 2006 Posts: 4
|
|
|
|
Thanks all,
I know this procedure. Other than this we have any other procedure to find out.
Please help me. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
You got many advices and one working solution...
what else are You looking for |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Hi Arun,
Being lil picky tonight..what's this line of code is
|
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
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 |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Anuj D. wrote: |
Hi Arun,
Being lil picky tonight..what's this line of code is
|
Anuj,
I think that was a piece of pseudocode. |
|
Back to top |
|
|
ridgewalker58
New User
Joined: 26 Sep 2008 Posts: 51 Location: New York
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
arcvns wrote: |
I think that was a piece of pseudocode. |
Ok, forgiven.. |
|
Back to top |
|
|
anil.csk
New User
Joined: 22 Oct 2007 Posts: 16 Location: Noida
|
|
|
|
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 |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Quote: |
One dimensional error |
Anil,
That was really a one dimensional error. 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 |
|
|
aparicio esteves
New User
Joined: 17 Sep 2008 Posts: 4 Location: Lisbon
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
aparicio esteves
New User
Joined: 17 Sep 2008 Posts: 4 Location: Lisbon
|
|
|
|
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 |
|
|
|