Directory UMM :wiley:Public:college:cobol:

��#ࡱ#�################>###��
#############################�#######����############���������������������������
��������������������������������������������������������������������������������
��������������������������������������������������������������������������������
��������������������������������������������������������������������������������
��������������������������������������������������������������������������������
��������������������������������������������������������������������������������
�����###���####################
###
#######

##############################################################################
###!###"#######$###%###&###'###(###)###*###+###,######.###/###0###1###2###3###4###5###6###7###8###9###:###;######?
###@###A###B###C###D###E###F###G###H###I###J###K###L###M###N###O###P###Q###R###S
###T###U###V###W###X###Y###Z###[###\###]###^###_###`###a###b###c###d###e###f###g
###h###i###j###k###l###m###n###o###p###q###r###s###t###u###v###w###x###y###z###{
###|###}###~###ࡱ###�###R#o#o#t#
#E#n#t#r#y#################################################��������#############
###################��P#1�#�###�#######P#P#4#0###################################
######################
###����####����########################################

?
########S#u#m#m#a#r#y#I#n#f#o#r#m#a#t#i#o#n###########################(###������
������####################################�###�#######C#u#r#r#e#n#t#
#I#D#################################################������������###############
#################################�###�###�###�###�###�###�###�###�###�###�###�##
#�###�###�###�###�###�###�###�###�###�###�###�###�###�###�###�###�###�###�###�##
#�###�###�����###�###�###�###�###�###�###�###�###�###�###�###�###�###�###�###�##
#�������������������������������������������������������������������������������
��������������������������������������������������������������������������������
��������������������������������������������������������������������������������
������������������������������������������������������������������ޭ#####E###�#1#
?
##f#�#(###(###y###[###########�#########################�##�###��#�###�#�#��##��
�#���###�##�###��#�###�#�#��##���#``````````````````````````````````````````````
```````````````################################################################0
h#`````````````````````````````````````````````````````````````#44##############
##############################################

```�````````````````````````````````````````````````````````l


###f#####################################################"####t#```��f�f�f�f�f�f
�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�```h#8####hffffffffffffffffffffffffffff
fffffffffffffffffffffffff
####�#```�f�o����������f�f�f�f���o�f�f�f�f�f�f�f�f�f�f�f�f�f�f```n#8####jffo��oo
�����fffffffff�offfffffffffffffffffffffffffff
####8#```��f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�```g#�####hffffff
fffffffffffffffffffffffffffffffffffffffffffffff
####8#```�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f```h#8####jffffff
fffffffffffffffffffffffffffffffffffffffffffffff"####�#```��f�f��o�������f�f�f�f�
f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�```h#8####hfffffffffffffffffffffffffffffffffffffff
ffffffffffffff ##
#z#```�f�f�f������������o����������������o�o����f�f�f�f````#C####jffffffffffffff
fffffffffffffffffffffffffffffffffffffff ##
#6#```��f�f�������������������������������o�f�f�f�f�````#�####hfffffffffffffffff
ffffffffffffffffffffffffffffffffffff ##
#�#```�f�f�f��������������o����������������o���f�o��f�f�f```l

###jfffffffffffffffffffffffffffffffffffffffffffffffffffff"##

b`b��f�f���o�������������������������������f�f�f�```d344###hffffffffffffffffffff

fffffffffffffffffffffffffffffffff ##

```�f�f�f���������o�����o�o��������������o�������f�f�f�f```l

###jfffffffffffffffffffffffffffffffffffffffffffffffffffff ##

b`b��f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�```l

###hfffffffffffffffff�fffffffffffffffffffffffffffffffffff ##

```�f�f�f�f���o�����o�f�o�f��o���o�o�o��o�����f�f�f�f```l

###jfffffffooo�o��oo�f��o����oo����of��o������ffffffff"##

f`f��f�f�f�o�f�f�f�f�f�f�o���f�o�f�f��f�f���f�f�f�f�f�f�```l

###hfffffffffffffffffffff�fffffffffffffffffffffffffffffff ##

`b`�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f```l


###jfffffffffffffffffo��oo����o��oo��offffffffffffffffff ##

f`f��f�f�f�f�f�f�f�f�o��o�����������f�f�f�f�f�f�f�f�f�```l

###hfffffffffffffffffo��fofff�o�f�offffffffffffffffffffff ##

bf`�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f```l

###jfffffffffffffffffffffffffffffffffffffffffffffffffffff"##

fbf��f�f�f�f�f�f�f�f�f�f�f�o�f�f�f���f�f�f�f�f�f�f�f�f�f�```d344###hffffffffffff
ffffffff���oo����offfffffffffffffffffff ##

`fb�f�f�f�f�f�f�f�f�f�f����������f�f�f�f�f�f�f�f�f�f�f```l

###jffffffffffffffffffff��fffffff��ffffffffffffffffffffff ##

fff��f�f�f�f�f�f�f�f�f�f�f�f�f�f���f�f�f�f�f�f�f�f�f�f�f�```l

###hfffffffffffffffffffffffffffffffffffffffffffffffffffff ##


ffb�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f```l

###jfffffffffffffffffffffffffffffff�ffffffo�fffffffffffff"##

fff��f�f�f�f�f�o�����o�o�������o�����o�f�f�f�f�f�f�```l

##&hfffffffffffoo�of�ofo��������f�o���o��ffffffffffff ##

bff�f�f�f�f�f�f���f�f�f��f�f�f�f��f�f���f�f�f�f�f�f�f�f```c444###jffffffffffffff
ffffffffffffffffffffff�ffffffffffffffff ##

fff��f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�```l

f#&hffffffffffffffffff���ooof��o������ffffffffffffffffff ##

fff�f�f�f�f�f�f�f�f�f�������o���f����f�f�f�f�f�f�f�f�f```l

#&#jffffffffffffffffff��f�ffofo�o��ffffffffffffffffffffff"##


fff��f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�```l

&#fhfffffffffffffffffffffffffffffffffffffffffffffffffffff ##

fff�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f```l

#&#jffffffffffffffffffffffffffffffffffoffffffffffffffffff ##

fff��f�f�f�f�f�f�f�f�f������o�������f�f�f�f�f�f�f�f�```d344f&fhffffffffffffffffo
���oo�of��������fffffffffffffffff ##

fff�f�f�f�f�f�f�f�f�o��f�f�f��f�f�f��f�f�f�f�f�f�f�f�f```l

#f#jffffffffffffffffffff�ffffffffffffffffffffffffffffffff"##

fff��f�f�f�f�f�f�f�f�f�f�f�f�o�f�f�f�f�f�f�f�f�f�f�f�f�f�```l

f&fhffffffffffffffffffff�o��f�o��oooffffffffffffffffffff ##

fff�f�f�f�f�f�f�f�f�f�f��o���������f�f�f�f�f�f�f�f�f�f```l


&f&jffffffffffffffffffffoofffffo��fffffffffffffffffffffff ##

�ff��f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�```l

fffhfffffffffffffffffffffffffffffffffffffffffffffffffffff ##

fff�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f```c444&f&jffffffffffff
ffffffffo�fffffffffffffffffffffffffffffff"##

ff���f�f�f�f�f�f�f�f�f��f�����o��o�f�f�f�f�f�f�f�f�f�```l

fffhffffffffffffffffffoo�������o���fffffffffffffffffff ##

fff�f�f�f�f�f�f�f�f�f�o�f���f��f�f�f�f�f�f�f�f�f�f�f�f```l

fffjffffffffffffffffffffffffffff�ffffffffffffffffffffffff ##

�f���f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�```l


fffhfffffffffffffffffffffffffffffffffffffffffffffffffffff ##

f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f���f�f�f�f�f���f�f```l

fffjffffo���o��o���o��f���o�o�o�foof����o��������o�ffff"##

�f���f�f�o��o�o�o�o���o�o���o�o�f�o�������o��o�f�f�```d344fffhffffo��o�o�o���ofo
f�o��ooffo�o�o����o���o�ffff ##

fff�f�f�o�f�f�f�f�f�f����o�o�o�f��f�f�f�f�f�f�f�f�f�f```l

fffjfffffffffffffffffffffffffffffffffffffffffffffffffffff ##

�f���f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�f�```l

fffnffffffffffffffffffffffffffffffffffffffffffffffffffffn ##

f�f����������������������������```l

fff�������������������������������������������������������##


�f�f�f�f�f�f�f�ffffffffffffffffffbfff`f`f`b`b```````````````l

fffffffffffffffff&f&f&f#&#f###&#############################

fff�fff�fff�ffffffffffffffffbfff`fbf`b`b````````````````````c444ffffffffffffff&f
&&#f#&#&#&##################################

�f�f�f�f�f�f�fff�ffffffffffffffbfffbf`f`f`b`b```````````````l

####��&##�##��&#####�e'#####�e'##:##�e'##&##��-##"##��-#####��-## ##��#####�#.#####�#.##�##�#.##&##��.##"##��.#####�#/##@##�)/#####�i/#####�i/##�##�i/
##&##�#2##"##�I2#####�k2##@##��2#####��2#####��2#####��2##&##��5##"##��5#####�!
6##`##�96#####��6#####��6##�##��6##&##�}:##"##��:#####��:##@##��:#####�#;#####�#
;##�##�#;##&##��>##"##�#?#####�E?##@##�]?#####��?#####��?##f##��?
##&##�#D##"##�)D#####�KD##@##�cD#####��D#####��D##�##��D##&##�?
I##@##�eI#####��I#####��I##`##��I##&##�#J##"##�+J#####�MJ##@##�eJ#####��J#####��
J#####��J##&##��M##"##��M#####�#N##@##�#N#####�[N#####�[N#####�[N##&##�sQ##"##��
Q#####��Q##@##��Q#####�#R#####�#R##�##�#R##&##��T##"##�#U#####�=U##@##�UU#####��
U#####��U##\##��U##&##��W##"##�#X#####�9X##@##�QX#####��X#####��X##�##��X##&##�W
[##"##�}

[#####��[##@##��[#####��[#####��[##�##��[##&##��_##"##��_#####�#`##@##�#`#####�Y
`#####�Y`#####�Y`##&##�Yb##"##�ࡱb#####��b##@##��b#####��b#####��b##�##��b##&##��
f##"##��f#####��f##@##�#g#####�Eg#####�Eg##2##�Eg##&##�wj##"##��j#####��j##@##��
j#####�#k#####�#k##^##�#k##&##�un##"##��n#####��n##@##��n#####�#o#####�#o##b##�#
o##&##�wq##"##��q#####��q##�##��q#####�Wr#####�Wr##�##�Wr##&##�Ct##"##�it#####��
t##�##��t#####�#u#####�#u##�##�#u##&##�#x##"##�9x#####�[x##�##�sx#####��x#####��
x##�##��x##&##��z##"##� {#####�+
{##@##�C{#####��{#####��{##�##��{##&##�k�##"##���#####���##�##�ˀ#####�K�#####�K�
##�##�K�##&##�#�##"##�?�#####�a�##@##�y�#####���#####���## ##���##&##�
�##@##�!�#####���##"##‫ي‬
9�#####�y�#####�y�##�##�y�##&##�#�##"##�5�#####�W�##@##�o�#####���#####���##t##�
��##&##�#�##"##�I�#####�k�##@##���#####�Ò#####�Ò##>##�Ò##&##�#�##"##�'�#####�I�#
#@##�a�#####���#####���##�##���##&##�{�##"##���#####�Ù##@##�ۙ#####�#�#####�#�##^
##�#�##&##�y�##"##���#####�\##@##�ٜ#####�#�#####�#�##t##�#�##&##���##"##���#####
�՟##@##��#####�-�#####�-�##d##��##&##���##"##���#####�٤##@##��#####�1�#####�1�##�##�1�##&##�#�##"##�E�#####�g�#
#@##�ࡱ�#####�� #####���##�##���##&##�Q�##"##�w�#####���##`##���#####�#�#####�#�#
#�##�#�##&##�#�##"##�1�#####�S�##`##�k�#####�˲#####�˲##�##�˲##&##�w�##"##���####
#���##@##�ࡱ#####�#�#####�#�##�##�#�##&##���##"##�˸#####��##�##�#�#####���#####��
�##~##���##&##�#�##"##�)�#####�K�##�##�c�#####��#####��##�##��##&##���##"##�վ###
##��##�##�#�#####���#####���##�##���##&##�7�##"##�]�#####�ࡱ�##�##�� #####�#�####

#�#�##�##�#�##&##���##"##�#�#####��##@##�E�#####���#####���##$##���##&##���##"##���#####���##@##�
�#####�I�#####�I�##b##�I�##&##���##"##���#####���##@##�#�#####�K�#####�K�##z##�K
�##&##���##"##���#####��##@##�
%�#####�e�#####�e�##�##�e�##&##�E�##"##�k�#####���##@##���#####���#####���##j##�
��##&##�O�##"##�u�#####���##@##���#####���#####���#####���##&##���##"##�#�#####�
;�##@##�S�#####���#####���##X##���##&##���##"##�#�#####�3�##@##�K�#####���#####�
��##�##���##&##���##"##���#####���##@##���#####�)�#####�)�##�##�)�##&##�#�##"##�
7�#####�Y�##@##�q�#####���#####���##�##���##&##�q�##"##���#####���##@##���#####�
#�#####�#�##�##�#�##&##���##"##���#####���##@##�#�#####�E�#####�E�##�##�E�##&##�
#�##"##�E�#####�g�##@##�ࡱ�#####�� #####���##�##���##&##�W�##"##�}�#####���##`##�
��#####�#�#####�#�##�##�#�##&##��##"##��#####�#�##@##�#�#####�c�#####�c�##,##�c�
##&##��###"##��######��###@##��######�/######�/###�##�/###&##��###"##��######�#
##@##�5
#####�u
#####�u
##�##�u
##&##�U##"##�{#####��
##@##��#####��#####��##�##��
##&##��###"##��######��###@##�#######�W######�W###N##�W###&##��###"##��######��#
##@##�#######�E######�E###,##�E###&##�q###"##��######��###@##��######�#######�##
##�##�####&##��###"##��######�# ##@##�3 #####�s #####�s ##�##�s
##&##��###"##�#$#####�=$##@##�U$#####��$#####��$#####��$##&##��&##"##��&#####��&
#####��*#####�#+##�##�#+#####��,##�##��,##~##��##&##�#1##@##�I1#####��1#####��1##P##��1##&##��2##"##��2#####�!
3#####�93#####�93#####�93#####�93##&##�G3##"##�m3#####��3#####��3#####��3#####��
3#####��3##&##��3##"##��3#####��3#####�#4#####�#4#####�94#####�S4##�##�q4##N##��
4##v##�?
5##v##��5##$##�+6#####�O6##"##�a:##�##��:##�##�c##�##�s>##########����#
###

#########AG����� ��############�##�#?># A����#p�############�##$#_=##`#
�P#`#p#############�##d

�(##a#���###:#############�##t#?>####�###########3##�##*��#�###��
###��#####��#��d#########d#2#######x###�Copyright
1997 John Wiley & Sons,
Inc..... All rights reserved. Reproduction or translation of this work beyond
that permitted in Section 117 of the 1976 United States Copyright Act without
the express written permission of the copyright owner is unlawful. Request for
further information should be addressed to the Permissions Department, John
Wiley & Sons, Inc... The purchaser may make back-up copies for his/her own use
only and not for distribution or resale. The Publisher assumes no responsibility
for errors, omissions, or damages, caused by the use of these programs or from
the use of the information contained herein.�

#x#########x#####
###########x#########x##### #��d#########d#2#######r##�##
���
���$###��#####��#��d######3##d#############Structured COBOL Programming

#################$##########################��#��d######3##d#########2##�##���F#
S���####��####T�l#��K######0##d#########Z###
Eighth edition
Nancy Stern
Hofstra University
Robert A. Stern
Nassau Community College
Prepared by
Herbert Rebhun
University of Houston Downtown

#Z#########################################>###############################A####
###########b###############1############### #################Z#############T
l###K######0##d#######R###Tl###K######0##d#######Z###T
l###K######0##d#######�###T
l###K######0##d#############################################�#�2################
####5#################����####

#########AGg��
S�############�##t#?>################r##�##���M
6���$###��#####��#��d#########d#############CHAPTER 14#SORTING AND MERGING

#################$##########################��#��d#########d####################
###��############ ###
###\#�2####

###############6#################����####

#########AGg�#�
��############�##�
?># A�g��� ##############�##�#_=####�###########r##�##��@�M
���$###��#####��#��d#########d#########
###OBJECTIVES

#
#########
#####$###########
#########
####��#��d#########d#########2##�##���M
�#��####��####T�l#��K#########d#########5###To Familiarize you with:1. How
files may be sorted within a COBOL program.2. How to process a file during a
SORT procedure before it is actually sorted. 3. How to process a file during a
SORT procedure after it is sorted but before it is created as output. 4. How to
use the MERGE verb for merging files.

#5#########5#################5#############Tl###K#########d#######3###T
l###K#########d#######P###Tl###K#########d#######j###T
l###K#########d#######/###T
l###K#########d#############################################�#�2################
######################����####

#########AGg���
��############�##�#_=# A�p�`� @#############�##�
?>####�###########r##�##��#�M
���$###��#####��#��d#########d#############CONTENTS

#################$##########################��#��d#########d#########2##�##��}�V
##��####��####U�l#��K#########d#########$###THE SOFT FEATURE: AN OVERVIEW
Format of the SORT StatementASCENDING or DESCENDING KEYCoding a Simple SORT
Procedure with the USING and GIVING OptionsPROCESSING DATA BEFORE AND/OR AFTER
SORTINGINPUT PROCEDUREOUTPUT PROCEDUREWhen to Use INPUT and/or OUTPUT Procedures
THE MERGE STATEMENT

#$#########$#################$##### #######U
l###K#########d#############�###d#########d#############�###d#########d#######A#
####�###d#########d#######,###U
l###K#########d#############�###d#########d#############�###d#########d#######+#
####�###d#########d###########U
l###K#########d#############################################l#�2################
######################����####

#########AGg�#�

��############�##

#�2# A�g�#� 0#############�######�###########r##�##��@�M
���$###��#####��#��d#########d#############ASCENDING / DESCENDING Key

#################$##########################��#��d#########d#########2##�##��=�M
##��####��#####��#��d#########d#########V###Sequencing Records with More
Than One SORT KeyThe SORT verb may be used to sequence records with more than
one key field. Suppose that we wish to sort fields in ascending alphabetic
sequence by name, within each office. That is:Office number is the major sort
fieldLevel number is the intermediate sort fieldName is the minor sort field

#V#########/###############'#################V#########/###U
l###K#########d#######M###Ul###K#########d#######l###U
l###K#########d#######&#####�###d#########d#######,#####�###d#########d#########
####�###d#########d#######A###>#######################L
?###@#####�2=###B################################����####

#########AGg�#�
��############�####�2# A�g�p�
�#############�##�#�2####�###########r##�##��0�M
���$###��#####��#��d#########d#############ASCENDING / DESCENDING Key

#################$##########################��#��d#########d#########2##�##���M
s#��####��#####��#��d#########d#########�###If all key fields are to be
sorted in ascending sequence we can code using the phrase ON ASCENDING KEY only
once.SORT SORT-FILE
ON ASCENDING KEY MAJOR-KEY
INTERMEDIATE -KEY
MINOR-KEY&

#�#########�#################�#########s###Ul###K#########d###########U
l###K#########d#############�###d#########d#############�###d#########d#########
####�###d#########d#######V###S################### ###x#T###U###$
�2R###W###############j#################����####

#########AGg��
s�############�##�#�2# A�g�`� �#############�##t
�2####�###########r##�##����M
V��####��#####��#��d#########d#########A###Coding a Simple SORT Procedure
with the USING and GIVING Options##

#A#########@#####$###########################A#########A####��#��d#########d####
#####2##�##��}�M c#��####��####T�l#��K#########d#########�###There are three
major files used in a sort:
FILES USED IN A SORT1. Input file:
File of unsorted input records.2. Work or sort file: File used to store records
temporarily during the sorting process.3. Output file: File of sorted output
records.

#�#########�#################�#########,###Ul###K#########d###########T
l###K#########d#####'#/###Tl###K#########d#######Y###T
l###K#########d#######.###Tl###K#########d#######]###Z#######################L
[###\###�
�2Y###^###############?#################����####

#########AGg�C�
#�############�##�#_=# A�g��� �#############�##�
?>####�###########r##�##��`�M ���$###��#####��#��d#########d#########@###Coding
a Simple SORT Procedure with the USING and GIVING Options

#@#########@#####$###########@#########@####��#��d#########d#########2##�##����M
�#��####��####U�l#��K#########d#########�###A sort file is usually
assigned to a special work device, indicated as SYSWORK in the following:SELECT
UNSORTED-MASTERN-FILE ASSIGN TO DISK1.SELECT SORT-FILE ASSIGN TO SYSWORK.SELECT
SORTED-MASTERN-FILE ASSIGN TO DISK2.The SORT-FILE is actually assigned to a
temporary work area that is used during processing but not saved. Only the
unsorted disk file and the sorted output disk file are assigned standard filenames so that they can be permanently stored.

#�#########�#################�#########a###Ul###K#########d#######.###T
l###K#########d#######$###Tl###K#########d#######,###T
l###K#########d###########Tl###K#########d#######k###U
l###K#########d#######�###U
l###K#########d#######d###a#########################b###c###�
�2`###e###############O#################����####

#########AGg���

��############�##�#_=# A�g�p� �#############�##\

?>####�###@#######r##�##��#�M ���$###��#####��#��d#########d#########