1 / 63

Multi-Dimensional Arrays

Multi-Dimensional Arrays. Time Table. Time table array arranged by row. 01 Time-table-array. 05 Time-entry occurs 12 times. 10 Mon-Course-Code PIC X(8). 10 Tues-Course-Code PIC X(8). 10 Wed-Course-Code PIC X(8). 10 Thurs-Course-Code PIC X(8). 10 Fri-Course-Code PIC X(8).

mervyn
Download Presentation

Multi-Dimensional Arrays

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. Multi-Dimensional Arrays

  2. Time Table

  3. Time table arrayarranged by row 01 Time-table-array. 05 Time-entry occurs 12 times. 10 Mon-Course-Code PIC X(8). 10 Tues-Course-Code PIC X(8). 10 Wed-Course-Code PIC X(8). 10 Thurs-Course-Code PIC X(8). 10 Fri-Course-Code PIC X(8).

  4. Time table arrayarranged by column 01 Time-table-array. 05 Time-entry occurs 5 times. 10 PRD1-Course-Code PIC X(8). 10 PRD2-Course-Code PIC X(8). 10 PRD3-Course-Code PIC X(8). ... 10 PRD12-Course-Code PIC X(8).

  5. 2 dimensional Time table array“all in one” 01 Time-table-array. 05 Day-in-week occurs 5 times. 10 Course-entry occurs 12 times. 15 Period-Number PIC 9(2). 15 Course-Code PIC X(8).

  6. Load a Multi-Dimensional Arrayusing the PROCEDURE DIVISION Move ‘IBC233B’ to Course-Code (2, 5) Move 5 to Period-Number (2, 5) Move ‘IBC233B’ to Course-Code (2, 6) Move 6 to Period-Number (2, 6) Move ‘Student Help’ to Course-Code (2, 7) Move 7 to Period-Number (2, 7)

  7. Processing a Multi-Dimensional Array”THE LONG WAY” Example counts the number of Student Help Time periods in a week. Perform 330-Count-Office Varying Day-Sub from 1 by 1 until Day-Sub > 5. 330-Count-Office. Perform 335-Count-Office-2 Varying Period-Sub from 1 by until Period-Sub > 12. 335-Count-Office-2. If Course-Code (Day-Sub, Period-Sub) = ‘Student Help’ Add 1 to office-count.

  8. Processing a Multi-Dimensional Array The “smart way” Example counts the number of Student Help Time Periods in a week. Perform 430-Count-Office Varying Day-Sub from 1 by 1 until Day-Sub > 5 After Period-Sub from 1 by 1 until Period-Sub > 12. 430-Count-Office. If Course-Code (Day-Sub, Period-Sub) = ‘Student Help’ Add 1 to office-count.

  9. Searching a Multi-Dimensional Array 01 Time-table-array. 05 Day-in-week occurs 5 times indexed by Day-Sub, 10 Course-entry occurs 12 times indexed by Period-Sub. 15 Period-Number PIC 9(2). 15 Course-Code PIC X(8). 77 Match-Found PIC X(3). 77 Day-Found PIC 9(1). 77 Period-Found PIC 9(2). Note: indexes defined by the system

  10. Searching a Multi-Dimensional Array Find the first occurrence of the course code IBC233AB. Move ‘No’ to Match-Found. Perform 500-Search-It Varying Day-Sub from 1 by 1 until Day-Sub > 5 or Match-Found = ‘Yes’. 500-Search-It. Set Period-Sub to 1. Search Course-Entry When Course-Code (Day-Sub, Period-Sub) = ‘IBC233AB’ Move Day-Sub to Day-Found Move Period-Sub to Period-Found Move ‘Yes’ to Match-Found END-Search.

  11. Structured Programming Series of Independent Modules executed from a main module.

  12. Structured Programming • Logical program design • Avoid duplication of code • Improves programmer productivity • Greater Flexibility • Modules/programs can be written in languages best suited for the task • End up with greater standardization

  13. Intercommunicating Programs • Copy Statement • Structured Programming (Call Statement)

  14. Copy (Source)anywhere in a program and optionally substituting variables COPY member-name/record-name OF/IN Library-file REPLACING {pseudo-text1/identifier-1/literal-1/word-1} BY {pseudo-text2/identifier-2/literal-2/word-2}

  15. Copy external file structures COPY DDS-format-name DDS-ALL-FORMATS DDS uses the externally declared field names COPY DD-format-name DD-ALL-FORMATS DD uses the alias names used in external declarations

  16. Calling programsandpassing parameters(values)

  17. OPM - DYNAMIC CRTCBLPGM *PGMoption 14 on a CBL source member ILE - STATIC CRTCBLMOD *MODULE option 15 on a CBLLE member CRTPGM *PGM command line CRTPGM F4 CRTBNDPGM *PGM option 14 on a CBLLE member

  18. Static vs Dynamic Calls OPM – Original Program Model Dynamic *PGM to *PGM calls Called program loaded into memory and executed at runtime • ILE – Integrated Language Environment • Static modules (*MODULE) ARE bound at compile time (crtcblmod). • *PGM object created by CRTPGM command • Called MODULES are loaded together at the same time before any execution by a CALL • (faster execution / promotes modular programming / mix and match language object execution)

  19. OPM Benefits • Benefits • Calls are resolved a runtime. Called programs do not have to exist at the time that the calling program is compiled • Calling programs do not have to be recompiled when a called program changes (as long as the parameters stay the same. • Good use of AS/400 Disk Space • Version control

  20. OPM Disadvantages • Many calls leads to performance problems • Compatibility problems between two languages.

  21. Integrated Language Environment • (we’ve been using OPM - Original Program Model)

  22. ILE • Uses Static Calls • Modules are copied in to the program object when the program is bound together. • Steps • Each program is compiled into a module • Modules are bound together using ‘Bind by copy’. • http://public.boulder.ibm.com/pubs/html/as400/online/v4r5eng.htm • ILE COBOL for AS/400 programmer guide SC09-2540-01. • ILE COBOL for AS/400 reference SC09-2539-01 • http://public.boulder.ibm.com/pubs/html/as400/online/v4r4eng.htm • ILE Concepts V4R4 SC41-5606-03

  23. Programming Changes for ILE • To call another program • CALL LINKAGE TYPE IS PROGRAM ‘program-name’ • To call another procedure (*MODULE) • CALL LINKAGE TYPE IS PROCEDURE ‘program-name’

  24. Program Creation Steps • Type in the source code into source members with the type CBLLE • Create procedures (*MODULES) from the source code using the CRTCBLMOD command • Create a program object from all of the *MODULES using the CRTPGM command

  25. Combining Modules Example MODA *MODULE calls MODB *MODULE To create a program call MODCALL: CRTPGM MODCALL MODULES(MODA MODB)

  26. ILE Benefits • Resolves language incompatibility issues • Less Call intensive • All program modules are opened at the same time

  27. ILE Disadvantages • Uses more disk space. • All of the modules must exist before the final product can be bound. • Version control. (none)

  28. Program Creation Steps - Short Cut (we have been using this so far) • If the program consists of one module, then compile the module and create the program using the CRTBNDCBL command. • (option 14 against a CBLLE source member) • It Combines the CRTCBLMOD and CRTPGM functions to produce the *PGM object but DOES NOT RETAIN the modules!

  29. Program Creation Steps • Use SEU to type in the source code into source members with the type CBLLE (QCBLLESRC) • Create procedures from the source code using the CRTCBLMOD command (type *MODULES CBLLE) • Create a program object from all of the *MODULES using the CRTPGM command (type *PGM CBLLE)

  30. Opt Object Type Attribute Text 5_ ASSIGN2 *PGM CBLLE Fall 00 Assignment 2 Display Program Information Display 3 of 7 Program . . . . . . . : ASSIGN2 Library . . . . . . . : CBL344LIB Owner . . . . . . . . : MOOGK Program attribute . . : CBLLE Detail . . . . . . . . : *MODULE Type options, press Enter. 5=Display description 6=Print description Creation Optimization Debug Opt Module Library Attribute Date Level Data __ VM200C MOOGK CBLLE 06/20/01 *NONE *YES __ PR200C MOOGK CBLLE 06/20/01 *NONE *YES

  31. Executable type *PGM created from several modules of type *MODULE MULTI MODULE MODULE PEP! *module *MODULE *MODULE *MODULE *module *module

  32. Calling ProgramsThe program being called • Linkage Section • Part of the Data Division, usually coded after the working-storage section. • Defines the parameters being sent to the called program. • Only needed if parameters being passed to the program

  33. Calling ProgramsThe program being called • Procedure Division Statement • Using clause • Only needed if parameters are passed to calling program. • Example: Linkage Section. 01 PARM-Customer PIC X(10). Procedure Division using PARM-Customer.

  34. Calling ProgramsProgram being called • Must end with EXIT PROGRAM instead of STOP RUN. • Because … STOP RUN terminates the entire process / application

  35. Calling ProgramsThe program doing the calls Syntax: CALL LINKAGE TYPE IS PROCEDURE/PROGRAM ‘programname’ USING parameter list END-CALL. PROCEDURE is used if the object being called is a *MODULE. PROGRAM is used if the object being called is a *PGM. USING is used only if parameters are passed.

  36. CALL Statement with Parameters Called Program Identification Division PROGRAM-ID. PGMB. Data Division. Linkage Section. 01 FLDX PIC X(2). 01 FLDY PIC 9(5). Procedure Division USING FLDX FLDY. Calling Program Data Division. 01 FLDA PIC X(2). 01 FLDB PIC 9(5). Procedure Division. CALL Linkage type is program PGMB USING FLDA FLDB.

  37. CALL Statement with Parameters (OPM) Called Program Identification Division PROGRAM-ID. PGMB. Data Division. Linkage Section. 01 FLDX PIC X(2). 01 FLDY PIC 9(5). Procedure Division USING FLDX FLDY. Calling Program Data Division. 01 05 FLDA PIC X(2). 05 FLDB PIC 9(5). Procedure Division. CALL PGMB USING FLDA FLDB.

  38. Note: Number of parameters passed is different but length of passed value is same

  39. CALL … BY CONTENT • Passes Parameters, but the values do not get returned to the calling program.

  40. CALL … BY CONTENT Calling Program Called Programs Procedure Division. MOVE 4 to FLDA. MOVE 5 to FLDB. CALL Linkage Type is procedure ‘SUBPGM1’ USING FLDA FLDB CALL Linkage Type is program ‘SUBPGM2’ USING BY CONTENT FLDA FLDB DISPLAY FLDA. DISPLAY FLDB. Identification Division. PROGRAM-ID. SUBPGM1. Procedure Division using FLDX FLDY. COMPUTE FLDX = FLDY * 5. PROGRAM EXIT. Identification Division. PROGRAM-ID. SUBPGM2. Procedure Division using FLDX FLDY. COMPUTE FLDY = FLDX * 2. PROGRAM EXIT.

  41. CALL … BY CONTENT (OPM) Calling Program Called Programs Procedure Division. MOVE 4 to FLDA. MOVE 5 to FLDB. CALL ‘SUBPGM1’ USING FLDA FLDB CALL ‘SUBPGM2’ USING BY CONTENT FLDA FLDB DISPLAY FLDA. DISPLAY FLDB. Identification Division. PROGRAM-ID. SUBPGM1. Procedure Division. …. COMPUTE FLDA = FLDB * 5. PROGRAM EXIT. Identification Division. PROGRAM-ID. SUBPGM2. Procedure Division. … COMPUTE FLDB = FLDA * 2. PROGRAM EXIT.

  42. CALL Statement (OPM) Calling Program Called Programs Identification Division. PROGRAM-ID. SUBPGM1. Procedure Division. PROGRAM EXIT. Identification Division. Procedure Division. CALL ‘SUBPGM1’ CALL ‘SUBPGM2’ STOP RUN. Identification Division. PROGRAM-ID. SUBPGM2. Procedure Division. PROGRAM EXIT.

  43. CALL Statement (OPM) Calling Program Called Programs Identification Division. PROGRAM-ID. SUBPGM1. Procedure Division. STOP RUN. Identification Division. Procedure Division. CALL ‘SUBPGM1’ CALL ‘SUBPGM2’ STOP RUN. Identification Division. PROGRAM-ID. SUBPGM2. Procedure Division. PROGRAM EXIT.

  44. Review of someBasics

  45. Indexed Filesbasics

  46. File Organizations • Cobol supports 4 type of File Organizations • Sequential: Records stored in the same sequence they arrived • Relative : Each record occupies a position in the file relative to the beginning of the file (1th, 2nd, 3rd,…) • Indexed : Records are stored in the file sorted by their record key • TRANSACTION: used in interactive programming

  47. The Indexed Organization • A record key is one of the record fields (e.g. Student ID) • The field is permanently defined as the key of the file at creation time • The value of a record key is the content of that field for the file record being read, written, rewritten, or deleted • In general, key values are unique (e.g. two students cannot have same ID’s)

  48. The Record Key is a Field ACCT NUMBER CUSTOMER NAME CUST BIRTHDATE 8811150552811 ROMEO LOPEZ 19,701,203 8811217643650 IAN J PHILLIPS 19,640,901 8811390394475 MARGARET TSUN 19,560,523 8811614491905 FERNE PHILLIPS 19,750,623 8811618790104 PENNY VITANZA 19,680,220 8811618909845 JAMES MALMSTROM 19,800,805 8812081630043 LESLIE R CHAN 19,600,725 8814280715195 ROBERT MILLER 19,501,101 8814288615652 ALLAN P MCLERIE 19,621,001 8815082500765 MARY E WILLIAMS 19,701,231 8816283476944 MICHELLE E ANDREOTI 19,720,206 8821292094514 ROBERT NOBLE 19,711,210 8830450892333 WILLIAM TELL 19,501,206 ACCT Number = Key Field

  49. The Record Key Keep can access a Filesequentially in sorted key ordereither ascending or descending ACCT NUMBER CUSTOMER NAME CUST BIRTHDATE 8811150552811 ROMEO LOPEZ 19,701,203 8811217643650 IAN J PHILLIPS 19,640,901 8811390394475 MARGARET TSUN 19,560,523 8811614491905 FERNE PHILLIPS 19,750,623 8811618790104 PENNY VITANZA 19,680,220 8811618909845 JAMES MALMSTROM 19,800,805 8812081630043 LESLIE R CHAN 19,600,725 8814280715195 ROBERT MILLER 19,501,101 8814288615652 ALLAN P MCLERIE 19,621,001 8815082500765 MARY E WILLIAMS 19,701,231 8816283476944 MICHELLE E ANDREOTI 19,720,206 8821292094514 ROBERT NOBLE 19,711,210 8830450892333 WILLIAM TELL 19,501,206 ACCT Number = Key Field

  50. The Record Key Allows for Random Accessto the records in an indexed file based on a key fields contents ACCT NUMBER CUSTOMER NAME CUST BIRTHDATE 8811150552811 ROMEO LOPEZ 19,701,203 8811217643650 IAN J PHILLIPS 19,640,901 8811390394475 MARGARET TSUN 19,560,523 8811614491905 FERNE PHILLIPS 19,750,623 8811618790104 PENNY VITANZA 19,680,220 8811618909845 JAMES MALMSTROM 19,800,805 8812081630043 LESLIE R CHAN 19,600,725 8814280715195 ROBERT MILLER 19,501,101 8814288615652 ALLAN P MCLERIE 19,621,001 8815082500765 MARY E WILLIAMS 19,701,231 8816283476944 MICHELLE E ANDREOTI 19,720,206 8821292094514 ROBERT NOBLE 19,711,210 8830450892333 WILLIAM TELL 19,501,206 Key Field = 8816283476944

More Related