Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort something in Cobol. need help?!

Status
Not open for further replies.

Remo1978

Technical User
May 1, 2002
8
NL
Hello,

i have the following:

FD Persons
Label records standard
Data record Persons-record
Value of file-id is "Persons.seq".
01 Persons-record.
03 P-Persnr pic 9 (04)
03 P-Persname x (21)
03 P-PersFirstn x (11)
03 P-Persstreet x (22)
03 P-City x (20)
03 P-Abnr 9 (07)

The above must be sorted by P-Persnr. Can anyone tell me how i can do this? i thought something like this i have to need, i saw this in an example.

SD Perssort
01 Perssort-record.
03 P-Persnr pic 9 (04)
03 P-Persname x (21)
03 P-PersFirstn x (11)
03 P-Persstreet x (22)
03 P-City x (20)
03 P-Abnr 9 (07)

But what is de code for sorting something like the Perons-record?

Yours Sincerely,

Remo
 
This looks a mess (because of the width) but if you copy and paste it to a text file named LSEQSORT.BAT and then execute it from a DOS prompt it will prompt you for input and build a shell program for a sort routine.

Make sure that the name you choose for ProgID (ProgID.cbl) does not already exist in the directory or it will be overwritten.

@ECHO OFF
IF "%1"=="" GOTO ERROR
IF "%2"=="" GOTO ERROR
IF "%3"=="" GOTO ERROR
ECHO ****************************************************************** > %1.CBL
ECHO * >> %1.CBL
ECHO IDENTIFICATION DIVISION. >> %1.CBL
ECHO * >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO * >> %1.CBL
ECHO PROGRAM-ID. %1. >> %1.CBL
ECHO AUTHOR. CLIVE CUMMINS. >> %1.CBL
ECHO INSTALLATION. TUBULARITY. >> %1.CBL
ECHO DATE-WRITTEN. AUG 10,1996. >> %1.CBL
ECHO * >> %1.CBL
ECHO *-**************************************************************** >> %1.CBL
ECHO *- %1 >> %1.CBL
ECHO *- >> %1.CBL
ECHO *- >> %1.CBL
ECHO *-**************************************************************** >> %1.CBL
ECHO * >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO * MODIFICATION LOG >> %1.CBL
ECHO * CCYYMMDD MODIFICATION >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO * >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO * >> %1.CBL
ECHO ENVIRONMENT DIVISION. >> %1.CBL
ECHO * >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO * >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO INPUT-OUTPUT SECTION. >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO * >> %1.CBL
ECHO FILE-CONTROL. >> %1.CBL
ECHO SELECT LSEQINP-FILE ASSIGN TO LSEQINP-FILE-ID >> %1.CBL
ECHO FILE STATUS IS LSEQINP-STATUS >> %1.CBL
ECHO ACCESS MODE IS SEQUENTIAL >> %1.CBL
ECHO ORGANIZATION IS LINE SEQUENTIAL. >> %1.CBL
ECHO * >> %1.CBL
ECHO SELECT LSEQOUT-FILE ASSIGN TO LSEQOUT-FILE-ID >> %1.CBL
ECHO FILE STATUS IS LSEQOUT-STATUS >> %1.CBL
ECHO ACCESS MODE IS SEQUENTIAL >> %1.CBL
ECHO ORGANIZATION IS LINE SEQUENTIAL. >> %1.CBL
ECHO * >> %1.CBL
ECHO SELECT SORT-FILE ASSIGN TO DISK >> %1.CBL
ECHO FILE STATUS IS SORT-STATUS. >> %1.CBL
ECHO * >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO * >> %1.CBL
ECHO DATA DIVISION. >> %1.CBL
ECHO * >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO * >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO FILE SECTION. >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO * >> %1.CBL
ECHO ********************************** >> %1.CBL
ECHO FD LSEQINP-FILE. >> %1.CBL
ECHO ********************************** >> %1.CBL
ECHO * >> %1.CBL
ECHO 01 LSEQINP-RECORD. >> %1.CBL
ECHO 05 LSEQINP-KEY PIC X(%2). >> %1.CBL
ECHO 05 FILLER PIC X(%3). >> %1.CBL
ECHO * >> %1.CBL
ECHO ********************************** >> %1.CBL
ECHO FD LSEQOUT-FILE. >> %1.CBL
ECHO ********************************** >> %1.CBL
ECHO * >> %1.CBL
ECHO 01 LSEQOUT-RECORD. >> %1.CBL
ECHO 05 LSEQOUT-KEY PIC X(%2). >> %1.CBL
ECHO 05 FILLER PIC X(%3). >> %1.CBL
ECHO * >> %1.CBL
ECHO ********************************** >> %1.CBL
ECHO SD SORT-FILE. >> %1.CBL
ECHO ********************************** >> %1.CBL
ECHO * >> %1.CBL
ECHO 01 SORT-RECORD. >> %1.CBL
ECHO 05 SORT-KEY PIC X(%2). >> %1.CBL
ECHO 05 FILLER PIC X(%3). >> %1.CBL
ECHO * >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO WORKING-STORAGE SECTION. >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO * >> %1.CBL
ECHO 01 PROGRAM-DETAILS. >> %1.CBL
ECHO 05 PROGRAM-RELEASE. >> %1.CBL
ECHO 10 PROGRAM-NAME PIC X(08) VALUE '%1'. >> %1.CBL
ECHO 10 PROGRAM-REL PIC X(08) VALUE ' 1.0.00'. >> %1.CBL
ECHO 05 PROGRAM-COPYRIGHT. >> %1.CBL
ECHO 10 PROGRAM-COPY PIC X(16) VALUE 'COPYRIGHT: 1996'. >> %1.CBL
ECHO 10 PROGRAM-AUTH PIC X(16) VALUE ' Clive Cummins.'. >> %1.CBL
ECHO * >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO 01 WORK-AREAS. >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO * >> %1.CBL
ECHO 05 LSEQINP-FILE-ID PIC X(12) VALUE "XXXXXXXX.XXX". >> %1.CBL
ECHO 05 LSEQOUT-FILE-ID PIC X(12) VALUE "XXXXXXXX.XXX". >> %1.CBL
ECHO * >> %1.CBL
ECHO 05 LSEQINP-STATUS PIC X(02) VALUE '00'. >> %1.CBL
ECHO 88 LSEQINP-SUCCESSFUL VALUE '00'. >> %1.CBL
ECHO 88 LSEQINP-END-OF-FILE VALUE '10'. >> %1.CBL
ECHO * >> %1.CBL
ECHO 05 LSEQOUT-STATUS PIC X(02) VALUE '00'. >> %1.CBL
ECHO 88 LSEQOUT-SUCCESSFUL VALUE '00'. >> %1.CBL
ECHO * >> %1.CBL
ECHO 05 SORT-STATUS PIC X(02) VALUE '00'. >> %1.CBL
ECHO 88 SORT-SUCCESSFUL VALUE '00'. >> %1.CBL
ECHO 88 SORT-END-OF-FILE VALUE '10'. >> %1.CBL
ECHO * >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO * >> %1.CBL
ECHO PROCEDURE DIVISION. >> %1.CBL
ECHO * >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO * >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO 1000-CONTROL. >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO * >> %1.CBL
ECHO SORT SORT-FILE ON ASCENDING KEY SORT-KEY >> %1.CBL
ECHO INPUT PROCEDURE IS 2000-INP-PROCEDURE >> %1.CBL
ECHO OUTPUT PROCEDURE IS 3000-OUT-PROCEDURE. >> %1.CBL
ECHO * >> %1.CBL
ECHO GOBACK. >> %1.CBL
ECHO * >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO 2000-INP-PROCEDURE. >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO * >> %1.CBL
ECHO * >> %1.CBL
ECHO * >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO 2990-RELEASE-RECORD. >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO * >> %1.CBL
ECHO RELEASE SORT-RECORD. >> %1.CBL
ECHO * >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO 3000-OUT-PROCEDURE. >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO * >> %1.CBL
ECHO * >> %1.CBL
ECHO * >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO 3990-RETURN-RECORD. >> %1.CBL
ECHO ****************************************************************** >> %1.CBL
ECHO * >> %1.CBL
ECHO RETURN SORT-FILE RECORD. >> %1.CBL
ECHO * >> %1.CBL
TYPE %1.CBL
GOTO END
:ERROR
ECHO ****************************************
ECHO Builds a shell COBOL program to sort and
ECHO process a LSEQ file.
ECHO ****************************************
ECHO Parameter(s)...
ECHO 1 = ProgID
ECHO 2 = Sort Key length
ECHO 3 = Rest of Record length
:END
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top