已阅读5页,还剩45页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
使用copy,call和其他语句来提高编程效率.nancy stern .robert a. stern .james p. ley. 霍夫斯特拉大学 . 拿骚社区学院 . 威斯康星大学斯托特关键词:copy, call, string, unstring, overflow, pointer, fd, of, in, pic, identification division, program-id, data division, replacing, by, using, procedure division, linkage section, working-storage section, exit program, cobol, stop run, calling, display,content, delimited, value, accept, on, with, move, subtract, into, all, end-unstring. 参考文献:10th edition cobol for the 21st century .nancy sternhofstra university.robert a. sternnassau community college.james p. leyuniversity of wisconsin-stoutcopyright 2003by john wiley & sons, inc.improving program productivity using the copy, call, and other statementsobjectivesto familiarize you with1. the copy statement for copying parts of a program that are stored in a library.2. the call statement for executing called programs as subroutines.3. text manipulation with the string and unstring statements.contentscopy statementintroductionentries that can be copiedan examplethe full format for the copy statementcall statementwhy use a call statement?format of the call statementcalled program requirementscalling program requirementsexamplestext manipulation with string and unstring statementsthe string statementthe basic formatoverflow optionpointer optiongeneral rules for using the stringthe unstring statementthe basic formatgeneral rules for using the unstringend-of-chapter aidschapter summarykey termscopy statementintroductiona copy statement is used to bring into a program a series of prewritten cobol entries that have been stored in a library. copying entries from a library, rather than coding them, has the following benefits: (1) it could save a programmer a considerable amount of coding and debugging time; (2) it promotes program standardization since all programs that copy entries from a library will be using common data-names and/or procedures; (3) it reduces the time it takes to make modifications and reduces duplication of effort; if a change needs to be made to a data entry, it can be made just one in the library without the need to alter individual programs; and (4) library entries are extensively annotated so that they are meaningful to all users; this annotation results in better-documented programs and systems.most often, the copy statement is used to copy fd and 01 entries that define and describe files and records. in addition, standard modules to be used in the procedure division of several programs may also be stored in a library and copied as needed.organizations that have large databases or files that are shared make frequent use of libraries from which entries are copied. students may also find that file and record description entries for test data for programming assignments have been stored in a library, which may then be copied when needed.each computer has its own machine-dependent operating system commands for creating and accessing a library. you will need to check you computer center for the required entries.entries that can be copiedwith the copy statement, you may include prewritten environment, data, or procedure division entries in your source programs as follows:environment divisionoption 1 (within the configuration section):source-computer. copy text-namelibrary-name.object-computer. copy text-namelibrary-name.special-names. copy text-namelibrary-name.option 2 (within the input-output section):file-control. copy text-namelibrary-name.i-o-control. copy text-namelibrary-name.data divisionoption 1 (within the file section):fd file-name copy text-namelibrary-name.option 2 (within a file description entry):01 data-name copy text-namelibrary-name.procedure divisionparagraph-name. copy text-namelibrary-name.the library-name is an external-name. it should be 1 to 8 characters and include letters and digits only.an examplesuppose we have created a library entry called customer that contains the following:01 customer-rec.05cust-nopic x(5).05cust-namepic x(20).05cust-addresspic x(30).05cust-bal-duepic 9(4)v99.to copy the entries in customer into our source program, code the following at the point in the program where you want the entries to appear:copy customerthe source listing would appear as follows (we use lowercase letters for the copied library entries to distinguish them from the source program coding):the c following the source program line numbers indicates that these entries have been copied from a library. some systems use an l (for library) or another letter to distinguish copied entries from programmer-supplied ones.as noted, other prewritten program entries besides file and record descriptions can also be copied.the full format for the copy statementa copy statement can be used not only to copy prewritten entries but to make certain changes to them in the source program. the full format for the copy is:format: if the replacing clause is omitted from the copy statement, the library text is copied unchanged.the replacing option allows virtually any library entry to be changed when it is being copied into the users source program. this includes cobol entries as well as comments or other elements that would appear as “pseudo-text.” literals and identifiers can also be changed as well as “words” that refer to cobol reserved words.example:using the library entry called customer in the preceding example, suppose we code:copy customer replacing cust-no bycust-number, =x(5)= by =x(6)=.this results in the following changes to the library entry when it is called into the source program:14c01customer-rec.15c05cust-numberpic x(6). data-name and pic clause have been changed16c05cust-namepic x(20).17c05cust-addresspic x(30).18c05cust-bal-duepic 9(4)v99.the replacing clause does not alter the prewritten entries in the library. that is, the changes are made to the users source program only.typically, fds with long or complex record descriptions are copied into programs, as are screen sections and even modules or paragraphs that are common to more than one program.tables are also often copied. in chapter 12, we saw that some tables are coded directly in the working-storage section with value clauses. suppose that records in a student file contain a code (01-10) identifying each students major. if the school has only 10 majors and these majors are not likely to change, we can code them in a cobol program as:01 major-table value art his eco mat csc phi bio eng soc psy .05each-major occurs 10 timespic x(4).the table would consist of 10 four-position majors, where a major code of 1 would indicate art, a major code of 2 would indicate his (for history), and so on.it is likely that more than one file makes use of this table for processing student information. an alumni file, a department file, and a personnel file, for example, may all need these table entries. it is best, therefore, to store the data in a library and allow it to be copied into programs that need it. moreover, since the possibility exists that a change of major codes might occur on rare occasions, you should store the table data in a single location so that any change need only be made once.call statementwhy use call statement?you will recall that structured programs should consist of a series of independent modules that are executed from the main module.when programs are properly structured:1. each module may be written, compiled, and perhaps even tested independently.2. the modules may be written in different stages, in a top down manner. they may even be coded by different programmers.3. if a specific module needs to be modified, the entire logical flow should still function properly without the need for extensive revision to other parts of the program.modules within a program can be viewed as subroutines that are called or executed from the main module. but a program may also call or reference independent subprograms stored in a library that are entirely separate from the main program itself. the main program that references or calls a subprogram is referred to as the calling program. the subprogram that is linked and executed within the main program is referred to as the called program.main (or user or source) program: calling programsubprogram: called programthe called program would need to be compiled, debugged, and catalogued or stored in a library so that it may be called when needed. typical subprograms that may be used by numerous calling programs include edit routines, error control checks, standard calculations, and summary and total printing. some programming languages use the term “external subroutines” to refer to these; the term “subprogram” is used in cobol.the technique of enabling a main program to call a subprogram has the following advantages:advantages of calling subprograms1. avoids duplication of effort.when modules need to be included in more than one program, it is best to write them separately and call them into each program as needed.2. improves programmer productivity.programmers can “specialize” or code modules that make use of their specific talents or skills.3. provides greater flexibility.subprograms may be written in any programming language; they are typically written in a language best suited to the specific task required.4. changes to the called program can be made without the need to modify the calling program.5. results in greater standardization.since a subprogram is really an independent module that is external to the main program, it may be called in just as one would use a perform to execute an internal module.differences between call and copythe call statement is very different from the copy statement. the copy brings into a user program separate environment, data, or procedure division segments as is. the copied entries are compiled and executed together with the source program. the call causes an entire program, which is already in machine language, to be executed. the calling and called programs are separate, but data may be passed from the called program to the calling program or from the calling program to the called program. that is, a called program is stored in compiled form in a library.when the call is performed, data is passed from the calling to the called program (if the calling program has assigned values to fields used in the called program). the entire called program is executed, data is passed from the called program back to the calling program, and control returns to the calling program.typically, we copy environment and data division entries into a source program and we call programs from a library rather than copy them.format of the call statementfigure 16.1(this chapter is the 16 chapter) illustrates the relationships between a calling program and called programs.a subprogram is called into a main program with the call statement. the following is the basic format for the call statement:format: literal-1 is the name of the called program as specified its program-id statement; it is enclosed in quotes like a nonnumeric literal. typically, the program name conforms to the rules for forming external-names: 1 to 8 characters, letters and digits only. literal-1 must also be catalogued as the called or subprogram name. this is performed with operating system commands that are system-dependent.figure 16.1 the relationships between a calling program and called programs.the using clause of the call statement is required if the subprogram performs any operations in which data is to be passed from one program to another. the call using identifies fields in the main or calling program that will be either passed to the called program before it is executed, or passed back to the calling program after the called program has been executed. since the purpose of calling a subprogram is to perform operations or calculations on data, we almost always employ the using option.see figure 16.2.the passing of parameters in figure 16.2 can be performed in several ways:1. suppose the called program needs to operate on two values that have to be passed to it from the calling program. a and b in the calling program can be passed to the called program as x and y. then the called program can perform its operations, produce results, and/or pass results back to the calling program as new values for a and b.figure 16.2 passing parameters between a calling program and a called program.example:suppose the called program computes and prints state and federal taxes owed for each individual. the calling program passes a federal-taxable-income value and a state-taxable-income value to the called program, where calculations are performed and the actual taxes either printed out or used to replace the taxable income figures in the calling program.2.suppose the called program needs to operate on only one value that must be passed to it from the calling program. a from the calling program can be passed to x in the called program as in figure 16.2. the called program can then perform its calculations, producing a result in y, which is passed back to the calling program as b.example:a called program computes a salary increase for employees on level numbers 1 to x, where the value for x is specified in a field called a in the calling program. the salary increase generated as y in the called program is returned to the calling program as b.example:the called program accepts the date of the run and the time of the run and converts that date and time to a different format needed by the calling program. (the format needed is not one of those available as an intrinsic function.) the computed date and time are stored as x and y in the called program and passed to the calling program as a and b. there is no need to pass parameters from the calling program because the called program can accept the computer-generated date and time.let us consider the coding requirements of the called program first and then consider the corresponding coding requirements of the calling program.called program requirementsprogram-idthe literal used in the call statement of the main program to extract a subprogram or routine from a library and execute it must be identical to the called programs program-id. in the calling program, we code call literal-1 using in the called program, we code program-id. literal-1. note that the literal is enclosed in quotation marks when used in the call statement.linkage sectiona linkage section must be defined in the called program for identifying those items that (1) will be passed to the called program from the calling program and (2) passed back from the called program to the calling program. the linkage section of the called program, then, describes all items to be passed between the two programs.the linkage section, if used, is coded after the file and working-storage sections of the called program. this section is similar to working-storage except that value clauses for initializing fields are not permitted in the linkage section.procedure division usingthe identifiers specified in the using clause in the procedure division entry include all fields defined in the linkage section; these identifiers will be passed from one program to the other. they are passed to and from corresponding identifiers in the call using of the main program. see figure 16.2 again.exit programthe last executed statement in the called program must be the exit program. it signals the computer to return control back to the calling program. (some systems use end program progname instead of exit program.)with cobol 74 exit program must be the only statement in the last paragraph.note that the subprogram should not have a stop run since program termination should be controlled by the calling program. if the subprogram is ever used independently, as well as used as a called program, it should have a stop run immediately after the exit program statement.calling program requirementswe have seen that the called program will include the following procedure division entries:called programprogram-id. prog1.procedure division using identifier-1a, identifier-2a,identifier-1a, identifier-2a,must be defined in the linkage section of the called program.to execute a subprogram stored in library, the only statement required in the calling program is the call literal-1 using statement. the literal specified in the call statement of the main program should be the same as in the program-id of the called program, but it is enclosed in quotes in the call. the calling program, then, will have the following entry:call prog1 using identifier-1, identifier-2,identifier-1, identifier-2, must be defined in the calling program.when the called program is executed, the contents of identifier-1 of the calling program will be passed to identifier-1a of the called program; the contents of identifier-2 of the calling program will be passed to identifier-2a of the called program, and so on. in this way, initial values, if there are any, may be passed from the calling program to the called program for execution. then, after execution of the called program, indentifier-1a of the called program is passed back to indentifier-1 of the calling program, and so on. thus, resultant data, if there is any, is passed from the called program back to the calling program for subse
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 佛山羽毛球馆租赁合同
- 学生住校心理健康预警责任协议
- 2024年服装批发购销协议规定版B版
- 2024年度水电预埋安装合同纠纷解决协议3篇
- 2024年安装工程玻璃施工安全教育与培训合同范本2篇
- 2024年体育场馆建设项目三方代建施工合同范本3篇
- 2024全新事业单位实习生实习合同及实习期间权益保护协议2篇
- 2024年二零二四年度企业内部员工培训计划保密合同3篇
- 2024年度版权授权:2024年度软件授权使用合同3篇
- 2024商场儿童游乐区租赁服务协议3篇
- 《现代大学英语精读1》第二课
- Keilc51常用库函数汇总参考
- 小学数学无纸化评价:一年级数学游园活动总结
- SAP生产计划概念及实施流程
- IPC77117721电子组件的返工维修和修改教程课件
- 工厂安全用电培训PPT
- 普通胃镜早期胃癌的诊断PPT课件
- DG∕T 154-2022 热风炉
- 抽样检验培训教材(共47页).ppt
- 时光科技主轴S系列伺服控制器说明书
- 通用带式输送机TD75或DT型出厂检验要求及记录
评论
0/150
提交评论