0% found this document useful (0 votes)
229 views2 pages

Sorting A Cobol Table (Not File) Within The Cobol Program - XT

The document describes a COBOL program that sorts a table of elements entered by the user. The program accepts the number of elements from the user, accepts each element into an array, then performs a bubble sort on the array. It displays the sorted array after completing the sort. The program sorts the table of elements in-place within the COBOL program using a bubble sort algorithm.

Uploaded by

sati1987
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
229 views2 pages

Sorting A Cobol Table (Not File) Within The Cobol Program - XT

The document describes a COBOL program that sorts a table of elements entered by the user. The program accepts the number of elements from the user, accepts each element into an array, then performs a bubble sort on the array. It displays the sorted array after completing the sort. The program sorts the table of elements in-place within the COBOL program using a bubble sort algorithm.

Uploaded by

sati1987
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

TABLE SORT AIM: SORTING A COBOL TABLE (NOT FILE) WITHIN THE COBOL PROGRAM ****** ***************************** Top

of Data ******************************* ******* IDENTIFICATION DIVISION. PROGRAM-ID. SORTTAB. DATA DIVISION. WORKING-STORAGE SECTION. 01 A VALUE ZEROES. 05 AA PIC 99 OCCURS 1 TO 99 DEPENDING N. 01 N PIC 99. 01 I PIC 99 VALUE 1. 01 J PIC 99. 01 K PIC 99. 01 T PIC XX. PROCEDURE DIVISION. 001. DISPLAY "ENTER NO OF ELEMENTS IN TABLE:". ACCEPT N. DISPLAY "ENTER ELEMENTS:". PERFORM 0002 N TIMES. PERFORM 0001 VARYING I FROM 1 BY 1 UNTIL I > N. MOVE 1 TO I. DISPLAY "THE SORTED TABLE IS:". PERFORM 0003 N TIMES. STOP RUN. 0001. COMPUTE K = I + 1. PERFORM 00001 VARYING J FROM K BY 1 UNTIL J > N. 00001. IF AA ( I ) > AA ( J ) MOVE AA ( I ) TO T MOVE AA ( J ) TO AA ( I ) MOVE T TO AA ( J ). 0002. ACCEPT AA(I). ADD 1 TO I. 0003. DISPLAY AA(I). ADD 1 TO I. ****** **************************** Bottom of Data ***************************** ******* //Compatible with all compilers & version OUTPUT

ENTER NO OF ELEMENTS IN TABLE 10 ENTER ELEMENTS: 10

22 4 52 12 53 65 6 67 56 THE SORTED TABLE IS: 04 06 10 12 22 52 53 56 65 67

You might also like