Sort Data in File

In COBOL, How to sort data in a file without using the sort command?

Questions by ravtej556

Showing Answers 1 - 6 of 6 Answers

Move all the records to array table.
then compare with each other,then swap that two records.
like IF ARRAY(I) > ARRAY(J)
MOVE I TO WS-DATA
MOVE J TO I
MOVE WS-DATA TO J
ELSE
COMPUT I = I + 1
PERFOEM SAME PARA UPTO FS = 10

  Was this answer useful?  Yes

mannurusrinivasulareddy

  • Oct 5th, 2011
 

Ws-rec is an occurs clause variable name.

Code
  1. perform sort-para varying I from 1 by 1 until I > (no of records)

  2.                           after J from I by 1 until J > (no of records)

  3.  

  4. sort-para,

  5.          if ws-rec(I) > ws-rec(j)

  6.                 Move ws-rec(I) to ws-temp

  7.                 move ws-rec(J) to ws-rec(I)

  8.                 move temp      to ws-rec(J).

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions