How to read records which is in sequential file in reverse
order ? Exp. 1 2 3 4 5 . i want 5 4 3 2 1?please clear my
doubt any one
Answers were Sorted based on User's Feedback
Answer / abhishek
i am giving you pseudo code of same
suppose we have 5 records
rec-no 1-->10
rec-no 2-->1
rec-no 3-->25
rec-no 4-->35
rec-no 5-->20
read sequential file to get record count of file
close file
define an array whose size is equal to record count of file
open file
read file in loop
move current record of sequential file to last subscript of
array define above ( this can be taken care using perform
varying)
read the array starting from subscript 1 to record count
this will be similar to reading sequntial file in reverse
order.....
thanks,
Abhishek
| Is This Answer Correct ? | 23 Yes | 0 No |
Answer / mustafa i
Abhishekh your logic is correct
just to add to it
we can even do it by reading the file only once.
1)Read File & Move into an array until EOF also increment a
counter after every read.
3)By decrementing the Counter and using it as subscript
we can now read the array and hence the file in
reverse order.
| Is This Answer Correct ? | 10 Yes | 4 No |
Answer / chp
ok.. but if my file consists of the records 10 1 25 35 20??
| Is This Answer Correct ? | 6 Yes | 3 No |
Answer / sreejith
sort the file firt in decending order
and then read sequentially
| Is This Answer Correct ? | 12 Yes | 10 No |
Answer / rakesh
we dont know how many records in the file so how can u
declare the array ?
| Is This Answer Correct ? | 3 Yes | 1 No |
Answer / abhishek
@Rakesh You can define table occurs clause based on the No
of records that input file have.
All, You can reverse the file it self using external sort
before reading it.
Thanks,
Abhishek
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / gautam
Read file till end of the file and move the record to array.
Increase the counter.
Read the record from array until counter = 0.
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / mustafa i
@Rakesh ... you can then set it to a maximum.
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / mastan ummadisetti
First read the file and add a sequence number to it.
Then use sort for descending the records based on sequence numbers.
| Is This Answer Correct ? | 0 Yes | 0 No |
what is the difference between implicit and explicit scope terminator with example?
IDENTIFICATION DIVISION. PROGRAM-ID. UPDT. AUTHOR.anbu. DATE-WRITTEN. AUG 13. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT CMSTR ASSIGN TO CINP1 ORGANIZATION IS INDEXED ACCESS IS SEQUENTIAL RECORD KEY CM2-KEY FILE STATUS IS WS-CMSTR-FST. SELECT CTAB ASSIGN TO CINP2 ORGANIZATION IS ACCESS IS SEQUENTIAL RECORD KEY VSAM-WHSE- KEY FILE STATUS IS WS-CTAB- FST. DATA DIVISION. FILE SECTION. FD CMSTR. COPY RXCYFC20. FD CTAB. COPY AITYWHSE. ************************************************************ ****** *** WORKING STORAGE VARIABLES *** ************************************************************ ****** WORKING-STORAGE SECTION. 01 WS- VARIABLES. 05 WS-EB PIC X(02) VALUE ZEROES. 05 WS-DIV PIC 9(03) VALUE ZEROES. 05 WS-CMF-RECS-REWRITTEN PIC 9(01) VALUE ZERO. *** FILE STATUS VARIABLES *** 05 WS- FILESTATUS. 10 WS-CMSTR-FST PIC 9(02) VALUE ZEROES. 10 WS-CTAB-FST PIC 9(02) VALUE ZEROES. *** END OF FILE VARIABLES *** 05 WS-CMSTR-EOF PIC X(01) VALUE 'N'. 88 WS-CMSTR-EOF-YES VALUE 'Y'. 88 WS-CMSTR-EOF-NO VALUE 'N'. 05 WS-CTAB-EOF PIC X(01) VALUE 'N'. 88 WS-CTAB-EOF-YES VALUE 'Y'. 88 WS-CTAB-EOF-NO VALUE 'N'. **** ERROR VARIABLES **** 05 WC-ABEND-900 PIC 9(03) VALUE 900. 05 WE-ERR-CODE PIC 9(02) VALUE ZEROES. 05 WE-ABEND-CODE PIC 9(03) VALUE ZEROES. ************************************************************ **** ********* PROCEDURE DIVISON ********** ************************************************************ **** PROCEDURE DIVISION. 0000- BEGIN. PERFORM 1000-INITIALISE THRU 1000- EXIT. PERFORM 2000-PROCESS THRU 2000- EXIT UNTIL WS-CMSTR-EOF- YES. DISPLAY 'WS-CMF-RECS-REWRITTEN :' WS-CMF-RECS- REWRITTEN. PERFORM 5000-CLOSE THRU 5000- EXIT. GOBACK. 0000- EXIT. EXIT. 1000- INITIALISE. OPEN I-O CMSTR. EVALUATE WS-CMSTR- FST WHEN 00 WHEN 97 CONTINUE WHEN OTHER DISPLAY 'ERROR IN READING INPUT FILE: ' DISPLAY WS-CMSTR-FST MOVE WS-CMSTR-FST TO WE-ERR-CODE PERFORM 9999-ABEND-PARA THRU 9999-EXIT END-EVALUATE. OPEN INPUT CTAB. EVALUATE WS-CTAB-FST WHEN 00 WHEN 97 CONTINUE WHEN OTHER DISPLAY 'ERROR IN READING INPUT FILE: ' DISPLAY WS-CTAB-FST MOVE WS-CTAB-FST TO WE-ERR-CODE PERFORM 9999-ABEND-PARA THRU 9999-EXIT END-EVALUATE. 1000-EXIT. EXIT. 2000-PROCESS. READ CMSTR. EVALUATE WS-CMSTR-FST WHEN 00 CONTINUE WHEN 10 SET WS-CMSTR-EOF-YES TO TRUE GO TO 2000-EXIT WHEN OTHER DISPLAY 'ERROR IN READING INPUT FILE: ' DISPLAY WS-CMSTR-FST MOVE WS-CMSTR-FST TO WE-ERR-CODE PERFORM 9999-ABEND-PARA THRU 9999-EXIT END-EVALUATE IF CM2-RECORD-TYPE-SOLD-TO MOVE CM2-ENTERING-BRANCH TO WS-EB PERFORM 3000-READ THRU 3000-EXIT UNTIL WS-CTAB-EOF-YES END-IF. 2000-EXIT. EXIT. 3000-READ. MOVE WS-EB TO VSAM-WHSE-CD. MOVE 'WHSE' TO VSAM-WHSE-ID. READ CTAB. EVALUATE WS-CTAB-FST WHEN 00 MOVE WHSE-DIV-CODE TO WS-DIV PERFORM 4000-REWRITE-CMF THRU 4000-EXIT WHEN 10 SET WS-CTAB-EOF-YES TO TRUE GO TO 3000-EXIT WHEN OTHER DISPLAY 'ERROR IN READING TABLE FILE: ' DISPLAY WS-CTAB-FST MOVE WS-CTAB-FST TO WE-ERR-CODE PERFORM 9999-ABEND-PARA THRU 9999-EXIT END- EVALUATE. 3000- EXIT. EXIT. 4000-REWRITE- CMF. IF WS-DIV = 250 OR 252 MOVE 'F' TO CM2-FREIGHT- TYPE MOVE 1 TO CM2-FREIGHT-THRESHOLD- AMT ADD +1 TO WS-CMF-RECS- REWRITTEN REWRITE CM2-SOLD-TO- RECORD DISPLAY 'RECORD UPDATED' END- IF. * EVALUATE WS-CMSTR- FST * WHEN 00 * CONTINUE * WHEN OTHER * DISPLAY 'FILE NOT UPDATED' * DISPLAY WS-CMSTR- FST * MOVE WS-CMSTR-FST TO WE-ERR-CODE * PERFORM 9999-ABEND-PARA THRU 9999-EXIT * GO TO 4000-EXIT * END-EVALUATE. 4000-EXIT. EXIT. 5000-CLOSE. CLOSE CMSTR CTAB. 5000-EXIT. EXIT. 9999-ABEND-PARA. COMPUTE WE-ABEND-CODE = WC-ABEND-900 + WE-ERR-CODE CALL 'ILBOABN0' USING WE-ABEND-CODE GO TO 5000-CLOSE. 9999-EXIT. EXIT. 5000-CLOSE. CLOSE CMSTR CTAB. 5000-EXIT. EXIT. 9999-ABEND-PARA. COMPUTE WE-ABEND-CODE = WC-ABEND-900 + WE-ERR-CODE CALL 'ILBOABN0' USING WE-ABEND-CODE GO TO 5000-CLOSE. 9999-EXIT. EXIT. //this program is giving maxcc=0, but not updating..
what are the working storage fields in BMS macro?
What are the steps you go through while creating a COBOL program executable?
Mention the guidelines to write a structured cobol program?
Identify the invalid dataname from the following: (A) savings-account (B) annual-allocation-for-overhead (C) samount250 (D) 12demand
how do you reference the printer file formats from cobol programs
wht do u mean by (*,intrdr) wht is * used for ?
What compiler option would you use for dynamic linking?
is this below syntax correct? CALL 'subprg' using A,B Please help
Describe the difference between subscripting and indexing ?
What the difference is between continue and next sentence?