![]() ![]() a table in WORKING-STORAGE that is searched to obtain a value related to a particular search criteriaĪn array can contain any number of data items of identical type and size.a group of accumulators in WORKING-STORAGE for different categories of totals.a series of similarly formatted input or output record fields in the FILE SECTION.The primary uses of arrays are to define: ![]() Please note, we are taking only first two digits as key.Arrays are data structures that are used to simplify coding and improve processing efficiency. IF WS-FLD(WS-J) WS-FLD(WS-I) THEN Sort will turn as a " Sort in Descending order" Output. ![]() PERFORM VARYING WS-I FROM 1 BY 1 UNTIL WS-I > 6 (Image courtesy Wikipedia) COBOL program for BUBBLE SORT (COBOL program for sorting an array) Please see the below graphical illustration!. The array is sorted, and the algorithm can terminate. The algorithm needs one whole pass without any swap to know it is sorted. Now, the array is already sorted, but our algorithm does not know if it is completed. ( 1 4 2 5 8 ) > ( 1 4 2 5 8 ), Now, since these elements are already in order (8 > 5), algorithm does not swap them. ( 5 1 4 2 8 ) > ( 1 5 4 2 8 ), Here, algorithm compares the first two elements, and swaps them. The algorithm goes for n (length of array) n iterations across the array, and take one element in each phase The algorithm take elements from left most node to right most node and compare two adjacent elements and replace their positions if the right most element is greater than left most element of the pair. I thought I can implement a simple “bubble sort” to sort the table. The reason why I said the story is, before started with writing the code I searched a couple of times in internet to see some sample codes but internet disappointed me I couldn’t very much useful codes over there. Few days back one of my friend contacted me to get the code for sorting a table in Cobol, his requirement was very rare/unique so I had to write custom sort for his requirement, since he needs it in CICS-COBOL environment we could not use SORT verb. But trust me there can be situations in CICS-COBOL program. I can understand what you are thinking while reading the heading “Sorting table! its not required because we have sort utilities to do this”. Hi folks, I could see the folds on you forehead. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |