Internal sort is when an application program calls sort.Internal sort is done using COBOL programming language using SORT verb
In a COBOL program the input routine is the
reserved word 'INPUT PROCEDURE' followed by a SECTION name that performs the
procedure.
The output routine is the reserved word 'OUTPUT
PROCEDURE' followed by a SECTION which prints the report .
Eg:-
SORT filename ON ASCENDING KEY dataname
USING filename1
INPUT PROCEDURE IS
paragraph1
GIVING filename2
OUTPUT PROCEDURE IS
paragraph2
( Filename is the name given in the SD entry, Filename1
is the input file, and Filename2 is the output file)
Advantage of Internal Sort is that we have to pass the file only once.
Well,the diadvantages are more,Some of them are following:-
1. If we need to change the sort sequence , the COBOL program has to be recompiled.
2. The programmer will not remember that Internal Sort is done in the program if he just looks at the JCL
3. If a program has to open about 30 files for processing and need tp perform a sort on one of the file. Then, when one file is getting sorted, all the 30 files are 'locked' and other jobs will not able to use them.i.e Resources are held when Sorting is going on.
4. Cobol Code is easier without Internal Sorts.
In External Sort we explicitly code EXEC PGM=SORT
in our JCL, and the SORT utility usually DFSORT or SYNCSORT gets invoked. DFSORT is a sort utility. It can be called directly
or from a program.
When DFSORT is invoked directly, control statements
can be specified using the data set defined by SYSIN.
Eg:-
//SYSIN DD *
OMIT
COND=(30,5,CH,EQ,C'COBOL')
SORT
FIELDS=(1,9,CH,D)
SUM
FIELDS=NONE
/*
The system calls DFSORT directly.
DFSORT reads the input data set and deletes each
record with a zero OMIT field as requested by the OMIT statement. DFSORT sorts the remaining records as requested
by the SORT control statement. DFSORT writes one record with each key to the
output data set as requested by the SUM statement. External Sorting is better than Internal Sorting.
To summarize The primary difference between an
Internal and an External Sort is that in Internal Sort, Program uses the
SORT statement and in External Sort, Sort is directly invoked via
JCL.