1 / 27

Chapter 14 - Sorting

Chapter 14 - Sorting. VOCABULARIO IMPORTANTE. Sort key – Campo dentro del record que determina como el archivo se va a organizar. Major key ( primary key ) – Campo de mayor importancia por el que deseamos organizar el archivo.

ilori
Download Presentation

Chapter 14 - Sorting

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 14 - Sorting

  2. VOCABULARIO IMPORTANTE • Sort key – Campo dentro del record que determina como el archivo se va a organizar. • Major key (primary key) – Campo de mayor importancia por el que deseamos organizar el archivo. • Minor key (secondary key) – Campo de menor importancia por el cual deseamos organizar si el primary key se repite. • Ascending - Organizar de menor a mayor (A  Z), (0  9) • Descending - Organizar de mayor a menor (Z  A), (9  0)

  3. Figure 14.1 Sorting Vocabulary NAME YEAR MAJOR Smith 1 Liberal artsJones 4 EngineeringAdams 3 BusinessHowe 2 Liberal artsFrank 1 EngineeringZev 4 BusinessBenjamin 4 BusinessGrauer 3 Liberal artsCrawford 2 EngineeringDeutsch 4 BusinessMakoske 1 Business (a) Unsorted Data

  4. Figure 14.1 (b) Sorted Data, One Key Primary Key: Name (Ascending) NAME YEAR MAJOR Adams 3 BusinessBenjamin 4 Business Crawford 2 EngineeringDeutsch 4 BusinessFrank 1 Engineering Grauer 3 Liberal arts Howe 2 Liberal artsJones 4 EngineeringMakoske 1 BusinessSmith 1 Liberal artsZev 4 Business

  5. Figure 14.1Sorted Data, Two Keys Primary key: Year (descending)Secondary key: Name (ascending) NAME YEAR MAJOR Benjamin 4 Business Deutsch 4 BusinessJones 4 EngineeringZev 4 Business Adams 3 BusinessGrauer 3 Liberal arts Crawford 2 EngineeringHowe 2 Liberal artsFrank 1 Engineering Makoske 1 BusinessSmith 1 Liberal arts

  6. Figure 14.1Sorted Data, Three Keys Primary Key: major (Ascending)Secondary Key: year (Descending)Tertiary Key: name (Ascending) NAME YEAR MAJOR Benjamin 4 Business Deutsch 4 BusinessZev 4 Business Adams 3 BusinessMakoske 1 Business Jones 4 Engineering Crawford 2 Engineering Frank 1 Engineering Grauer 3 Liberal arts Howe 2 Liberal artsSmith 1 Liberal arts

  7. Figure 14.2EBCDIC & ASCII Collating Sequences EBCDIC (space). (period, decimal point)< (less than)( (left parenthesis)+ (plus symbol)$ (currency symbol)* (asterisk)) (right parenthesis); (semicolon)- (hyphen, minus symbol)/ (slash), (comma)> (greater than)‘ (apostrophe)= (equal sign)“ (quotation mark) a through z (lower case) A through Z (upper case)0 through 9 ASCII (space)“ (quotation mark) $ (currency symbol)‘ (apostrophe) ( (left parenthesis) ) (right parenthesis) * (asterisk)+ (plus symbol) , (comma) - (hyphen, minus symbol) . (period, decimal point)/ (slash)0 through 9; (semicolon)< (less than)= (equal sign)> (greater than) A through Z (upper case) a through z (lower case)

  8. Figure 14.3 Embedded Signs (ASCII versus EBCDIC) Digit Character Digit Character+1 1 -1 Q +2 2 -2 R +3 3 -3 S +4 4 -4 T +5 5 -5 U +6 6 -6 V +7 7 -7 W +8 8 -8 X +9 9 -9 Y +0 0 -0 Z Digit Character Digit Character+1 A -1 J +2 B -2 K +3 C -3 L +4 D -4 M +5 E -5 N +6 F -6 O +7 G -7 P +8 H -8 Q +9 I -9 R +0 { -0 } ASCII EBCDIC

  9. Figure 14.4 Embedded Signs (ASCII versus EBCDIC) Name Account Balance John Doe $1,005Mary Smith $1,005CRFrank Coulter $2,000Erik Parket $2,000CR (a) Report Como se manejan campos con signos. (PIC S9) John Doe 1005Mary Smith 100UFrank Coulter 2000Erik Parket 200Z (b) Data (ASCII) John Doe 100EMary Smith 100NFrank Coulter 200{Erik Parket 200} (c) Data (EBCDIC)

  10. SORT syntax SORT file-name-1 ON {DESCENDING KEY { data-name-1} . . . }ASCENDING} WITH DUPLICATES IN ORDER COLLATING SEQUENCE IS alphabet-name INPUT PROCEDURE IS procedure-name-1USING {file-name-2} OUTPUT PROCEDURE IS procedure-name-2GIVING {fine-name-3}

  11. Ejemplo del SORT SORT STUDENT-FILE ASCENDING KEY STUDENT-MAJOR DESCENDING KEY YEAR-IN-SCHOOL ASCENDING KEY STUDENT-NAME… Este es el ejemplo de la tabla 14.1d página 406

  12. WITH DUPLICATES IN ORDER Se asegura que la secuencia de records que tengan el campo duplicado en el archivo original, se mantengan en ese mismo orden en el archivo a donde se van a guardar.

  13. COLLATING SEQUENCE Permite a una computadora ASCII organizar (sort) en formato EBCIDIC y de una computadora EBCIDIC organizar en formato ASCII .

  14. INPUT PROCEDURE / USINGOUTPUT PROCEDURE / GIVING INPUT / OUTPUT PROCEDURE le da al programador la opción de indicar como realizar el I/O mientras que el USING / GIVING lo hace automáticamente. Esto me permite hacer un sort por un campo calculado que no este creado en el record (usando PROCEDURE). Por ejemplo: si tenemos un archivo de empleados con el salario inicial y el salario actual, pero no tenemos el porciento de ingreso entre los salarios, utilizando los INPUT / OUTPUT PROCEDURES podemos crear y organizar el archivo por ese nuevo campo, mientras que el USING / GIVING solo puede utilizar los campos que están previamente creados. Esto se hace mucho en Base de Datos.

  15. SD Sort Description SD file-name-1 [ RECORD CONTAINS [ integer-1 TO ] integer-2 CHARACTERS ] RECORD IS DATA RECORDS ARE data-name-1 . . . Si vamos a organizar (sort) utilizando el comando SORT y no por algoritmo, necesitamos declarar un SD. Es similar al FD con la diferencia de que es un archivo temporero para organizar los datos. Se debe almacenar en área de directorio temporero.

  16. RELEASE & RETURN • El RELEASE es similar al WRITE. • El RETURN es similar al READ. • Se utilizan en el INPUT y OUTPUT PROCEDURE respectivamente. • Trabajan con el archivo tipo SD.

  17. FORMATOS RELEASE / RETURN RELEASE record-name [ FROM identifier ] RETURN file-name [ INTO identifier ] [ AT END imperative-statement-1 ] [ NOT AT END imperative-statement-2 ] [ END-RETURN ]

  18. Figure 14.6 Sorted Reports (continued) SALES ACTIVITY REPORT 04/21/03 PAGE 3 REGION LOCATION NAME ACCOUNT # SALES COMMISSION NORTHEAST TRENTON CLARK 576235 $ 100 $ 3 SOUTHEAST ST.PETERSBURG FEGEN 444444 $ 100 $ 2 SOUTHEAST ST.PETERSBURG FEGEN 476236 $ 376- $ 11- SOUTHEAST ST.PETERSBURG FEGEN 555555 $ 304 $ 15 SOUTHEAST ST.PETERSBURG JOHNSON 100000 $ 303- $ 18- SOUTHEAST ST.PETERSBURG JOHNSON 248545 $ 345 $ 48 SOUTHEAST ST.PETERSBURG JOHNSON 248545 $ 345 $ 57- SOUTHEAST ST.PETERSBURG JOHNSON 878787 $1,235 $ 148 $2,540 SALES ACTIVITY REPORT 04/21/03 PAGE 2 REGION LOCATION NAME ACCOUNT # SALES COMMISSION NORTHEAST BALTIMORE KARLSTROM 583645 $ 145 $ 6NORTHEAST BALTIMORE KARLSTROM 800396 $3,030 $ 273 NORTHEAST BALTIMORE MARCUS 700039 $ 932 $ 93 NORTHEAST BALTIMORE MARCUS 750020 $ 305 $ 15 NORTHEAST NEW YORK ADAMS 444333 $1,005- $ 10- NORTHEAST NEW YORK ADAMS 555666 $2,003 $ 401 NORTHEAST NEW YORK ADAMS 987654 $2,005 $ 201 NORTHEAST TRENTON CLARK 000101 $1,500 $ 150 NORTHEAST TRENTON CLARK 000104 $ 500 $ 15 NORTHEAST TRENTON CLARK 130101 $3,200 $ 640 SALES ACTIVITY REPORT 04/21/03 PAGE 1 REGION LOCATION NAME ACCOUNT # SALES COMMISSION MIDWEST CHICAGO BENWAY 000069 $ 231- $ 23-MIDWEST CHICAGO BENWAY 476530 $ 235- $ 12-MIDWEST CHICAGO BENWAY 988888 $ 450 $ 5MIDWEST CHICAGO BENWAY 999340 $ 334 $ 100MIDWEST CHICAGO HUMMER 000100 $ 107- $ 5-MIDWEST CHICAGO HUMMER 649355 $ 345 $ 17MIDWEST CHICAGO HUMMER 694446 $ 904 $ 90 MIDWEST ST. LOUIS HAAS 203000 $8,900 $ 445 MIDWEST ST. LOUIS HAAS 277333 $ 98- $ 8-MIDWEST ST. LOUIS HAAS 475365 $ 333 $ 17 (a) By Region, Location, and Name (All Records)

  19. Figure 14.6 Sorted Reports (continued) SALES ACTIVITY REPORT 04/21/03 PAGE 2 REGION LOCATION NAME ACCOUNT # SALES COMMISSION NORTHEAST TRENTON CLARK 130101 $3,200 $ 640MIDWEST ST. LOUIS HAAS 203000 $8,900 $ 445 NORTHEAST NEW YORK ADAMS 555666 $2,003 $ 401 NORTHEAST BALTIMORE KARLSTROM 800396 $3,030 $ 273 NORTHEAST NEW YORK ADAMS 987654 $2,005 $ 201 NORTHEAST TRENTON CLARK 000101 $1,500 $ 150SOUTHEAST ST.PETERSBURG JOHNSON 878787 $1,235 $ 148 *** COMPANY TOTAL = $ 21,873 $ 2,258 (b) By Decreasing Commission (Commission > $100)

  20. Figure 14.7 Hierarchy Chart (USING/GIVING)

  21. Sort sales fileOpen sorted sales file, print fileGet today’s dateDO WHILE sorted data remains READ sorted sales file AT END Indicate no more data NOT AT END Calculate commission IF line counter greater than lines-per-page Initialize line count to 1 Increment page count Write heading lines ENDIF Write detail line Increment company total END READENDDOWrite company totalsClose filesStop run Figure 14.8 Pseudocode (USING/GIVING)

  22. LISTADO DEL PRIMER PROGRAMA SORT1.CBL CBL SORT1.TXT TXT

  23. Figure 14.10 Hierarchy Chart (INPUT PROCEDURE/OUTPUT PROCEDURE)

  24. Input Procedure Open Input Sales FileDO WHILE data remains READ Sales File AT END Indicate no more data NOT AT END Calculate commission IF commission > 100 RELEASE sort record ENDIF END-READENDDO Figure 14.11 Pseudocode (INPUT PROCEDURE/OUTPUT PROCEDURE) Sort utility takes control

  25. Output Procedure Open Output Print FileGet today’s dateDO WHILE sorted data remains RETURN Sorted Sales File AT END Indicate no more data NOT AT END IF line count greater than lines per page Initialize line count to 1 Increment page count Write heading lines END-IF Write detail line Increment company total END RETURNENDDOWrite company totalClose filesStop run Figure 14.11 Pseudocode (INPUT PROCEDURE/OUTPUT PROCEDURE)

  26. LISTADO DEL PRIMER PROGRAMA SORT2.CBL CBL SORT2.TXT TXT

  27. MERGE syntax MERGE file-name-1 ON {DESCENDING KEY { data-name-1} . . . }ASCENDING} COLLATING SEQUENCE IS alphabet-name USING file-name-2 [ file-name-3 ] . . . THRU OUTPUT PROCEDURE IS procedure-name-1 THROUGH procedure-name-2 GIVING {fine-name-4}

More Related