cjiop.blogg.se

Sorting an array in cobol program
Sorting an array in cobol program















#SORTING AN ARRAY IN COBOL PROGRAM HOW TO#

I don't think I am even implementing this table correctly, so any help on how to improve this code would be great.

sorting an array in cobol program

you must “when” the thing that occurs or an item under it comparing it to something on input record (month of hire ) WHEN EACH-MONTH-number(MONTH-INDEX) = ER-MONTH-OF-HIRE Move ‘Y’ to found-switch at this point you have found it - got a match so here is where you do what you need to do on a match MOVE EACH-MONTH-NAME(month-index) TO DL-MONTH-OF-HIRE END-SEARCH.I am learning COBOL, and I am having difficulty trying to figure out how to sort this table. When doing a binary search, you don’t set the index to 1 before doing the search (but if you do, it ignores that and still works) you search “all” the thing that occurs, SEARCH ALL EACH-MONTH-INFO At end means not found AT END Move ’N’ to found-switch move ‘unknown’ to dl-month-of-hire the when is a condition, like an if. READ INPUT-FILE AT END MOVE ‘Y’ TO FILE-AT-END NOT AT END ADD 1 TO CTR-RECORDS-READ END-READ. PERFORM LOOKUP-MONTH MOVE INPUT-RECORD TO dl-reCORD-IMAGE WRITE REPORT-RECORD FROM DETAIL-PRINT-LINE PERFORM READ-PAR. OPEN INPUT INPUT-FILE OUTPUT REPORT-FILE WRITE REPORT-RECORD FROM TITLE-HEADING-LINE PERFORM READ-PAR * accept gets today’s date from the system ACCEPT REPORT-DATE FROM DATE. PERFORM INITIALIZATION PERFORM PROCESS-ALL UNTIL FILE-AT-END = ‘Y’ PERFORM TERMINATION GOBACK. Next item must occur as many times as there are fillers in the preceding 01 its picture or the pictures under it must add up to the same number as the picture in the fillers above (11 in this example) 05 EACH-MONTH-INFO OCCURS 12 TIMES You need the indexed by clause if you’re going to use the search verb this defines and creates the index - so no pictures for the index, please The ascending (or descending) key clause is required for a binary search of course, the data must actually be in order or this won’t work right ASCENDING KEY IS EACH-month-number INDEXED BY MONTH-INDEX. 0* Redefines means that this 01 level item occupies the same spot in memory as the one it redefines so actually the two 01 levels are the same thing with different names and different picture 01 MONTH-TABLE REDEFINES MONTH-TABLE-LITERALS. 05 FILLER PIC X(11) VALUE ‘09SEPTEMBER’ 05 FILLER PIC X(11) VALUE ‘10OCTOBER’. most explanations are meaningless, until you study this carefully to see what is happening these are fillers, because you won’t be referring to them directly, by name notice how the code (01) is written right beside the name (january) all the pictures must be the same the literals inside of quotes don’t have to be the same length, but many will code them that way 05 FILLER PIC X(11) VALUE ‘01JANUARY’. 05 DL-RECORD-IMAGE PIC X(80) VALUE SPACES. 05 FILLER PIC X(35) VALUE ‘EMPLOYEE RECORDS WITH MONTH OF HIRE’. 05 CTR-RECORDS-WRITTEN PIC 9(5) PACKED-DECIMAL VALUE 0. 05 CTR-RECORDS-READ PIC 9(5) PACKED-DECIMAL VALUE 0. 0 FD REPORT-FILE RECORDING MODE IS F RECORD CONTAINS 133 CHARACTERS. MONTH OF HIRE CAN BE DEFINED AS CHARACTER (ALPHANUMERIC) 05 ER-MONTH-OF-HIRE PIC X(02). INPUT RECORD DESCRIPTION 05 FILLER PIC X(08).

sorting an array in cobol program

FD INPUT-FILE RECORDING MODE IS F RECORD CONTAINS 80 CHARACTERS. REPORTFI: A REPORT FILE, PRINTS OUT INFORMATION ON EMPLOYEES WITH MONTH OF HIRE, SEND TO PRINTER SELECT REPORT-FILE ASSIGN REPORTFI. INPUT FILE EMP SELECT INPUT-FILE ASSIGN EMP. The binary search reads every input record after looking up the employee’s month of hire on a table, by a sequential search, it writes it out to an output file ENVIRONMENT DIVISION. Searching for a value in a Table: R: which(sapply(df, function(x) any(month = "January"))) Python: df COBOL: IDENTIFICATION DIVISION. MOVE '12ABCDEF34GHIJKL56MNOPQR' TO WS-TABLE. Working with tables of data: R: x Python: x.iloc COBOL: IDENTIFICATION DIVISION. PERFORM VARYING WS-I FROM 1 BY 1 UNTIL WS-I > 6 DISPLAY WS-TBL(WS-I) END-PERFORM. DISPLAY ‘>DESCENDING ORDER 6 IF WS-FLD(WS-J) > WS-FLD(WS-I) THEN MOVE WS-TBL(WS-I) TO WS-TAB-HLD MOVE WS-TBL(WS-J) TO WS-TBL(WS-I) MOVE WS-TAB-HLD TO WS-TBL(WS-J) END-IF END-PERFORM END-PERFORM. DISPLAY ‘>ASCENDING ORDER 6 IF WS-FLD(WS-J) 6 DISPLAY WS-TBL(WS-I) END-PERFORM.

sorting an array in cobol program

We put the hottest languages to the test! Sorting an Array R: sort(x) Python: numpy.sort(x) COBOL: IDENTIFICATION DIVISION.















Sorting an array in cobol program