Home > Software > Mainframe > Cobol
Interview Questions   Tutorials   Discussions   Programs   

Cobol - What is internal sort and external sort ? which is preferable ?

asked mar August 22, 2014 12:55 PM  

What is internal sort and external sort ? which is preferable ?


1 Answers

answered By Mswami   0  
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 .


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.


  • If we need to change the sort sequence , the COBOL program has to be recompiled.
  • The programmer will not remember that Internal Sort is done in the program if he just looks at the JCL
  • 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.
  • 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.


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. 
   add comment

Your answer

Join with account you already have



 Write A Tutorials
Online-Classroom Classes

  1 person following this question

  3 people following this tag

  Question tags

cobol × 1

Asked 2 years and 3 months ago ago
Number of Views -451
Number of Answers -1
Last updated
3 years and 3 months ago ago

Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!