A COBOL program is coded in four divisions. COBOL allows nested-IF constructs such as IF condition1 IF condition2 statement. Turning the bad and ugly into the good COBOL has been with us for a long time. Early versions of the language contained 'features' that forced programmers to write. For example, with Pro*COBOL you can embed SQL statements in. You must place the nested program directly before the END PROGRAM header of. Algorithms and code examples. For example we have two input files. You will use the sorted file as input to the rest of the program. Use of NESTED PROGRAMS, GLOBAL, EXTERNAL in cobol. One program may contain other program(s). The contained program(s) may themselves contain yet other program(s). PGMB is nested a program in the example below. Example: IDENTIFICATION DIVISION. ![]() If you want to access any working storage variable of PGMB in PGMA, declare them with the clause . Nested Programs are supported only in COBOL8. If there is a program PGMC inside PGMB, it cannot be called from PGMA unless it’s program id is qualified with keyword COMMON. ![]() ![]() 3 Writing a Pro*COBOL Program. This chapter provides the basic information you need to write a Pro*COBOL program, including: Programming Guidelines.Precompiler Concepts. This chapter explains how embedded SQL programs do their work. It presents definitions of important words, explanations of basic concepts, and key rules. Topics covered are: Key Concepts of Embedded SQL Programming. This section lays the conceptual foundation on which later chapters build. Steps in Developing an Embedded SQL Application. Precompiling results in a source file that can be compiled normally. Although precompiling adds a step to the traditional development process, that step is well worth taking because it lets you write very flexible applications. Figure 2- 1 walks you through the embedded SQL application development process: Figure 2- 1 Application Development Process. Text description of the illustration pco. Embedded SQL Statements. The term embedded SQL refers to SQL statements placed within an application program. Because the application program houses the SQL statements, it is called a host program, and the language in which it is written is called the host language. For example, with Pro*COBOL you can embed SQL statements in a COBOL host program. To manipulate and query Oracle data, you use the INSERT, UPDATE, DELETE, and SELECT statements. COBOL programming site with a full COBOL course as well as lectures, tutorials, programming exercises, and over 50 example COBOL programs. For example, a banking system. The Object COBOL class program contains the code and data for both the class. INSERT adds rows of data to database tables, UPDATE modifies rows, DELETE removes unwanted rows, and SELECT retrieves rows that meet your search criteria. Only SQL statements- -not SQL*Plus statements- -are valid in an application program. There are two types of embedded SQL statements: executable statements and directives. Executable SQL statements generate calls to the database. They include almost all queries, DML (Data Manipulation Language), DDL (Data Definition Language), and DCL (Data Control Language) statements. Directives, on the other hand, do not result in calls to SQLLIB and do not operate on Oracle data. You use directives to declare Oracle objects, communications areas, and SQL variables. They can be placed wherever COBOL declarations can be placed. Appendix F, . The only special requirement for building SQL statements into your host program is that you begin them with the words EXEC SQL and end them with the token END- EXEC. Pro*COBOL translates all executable EXEC SQL statements into calls to the runtime library SQLLIB. Most embedded SQL statements differ from their interactive counterparts only through the addition of a new clause or the use of program variables. Compare the following interactive and embedded ROLLBACK statements: ROLLBACK WORK; - - interactive. ROLLBACK WORK. END- EXEC. Either of the following is allowed: EXEC SQL .. END- EXEC. EXEC SQL .. In this case, you know the makeup of each SQL statement and transaction before run time. That is, you know which SQL commands will be issued, which database tables might be changed, which columns will be updated, and so on. In this case you might not know until run time all the SQL commands, database tables, and columns involved. Dynamic SQL is an advanced programming technique that lets your program accept or build SQL statements at run time and take explicit control over datatype conversion. To embed PL/SQL in your host program, you simply declare the variables to be shared with PL/SQL and bracket the PL/SQL block with the keywords EXEC SQL EXECUTE and END- EXEC. From embedded PL/SQL blocks, you can manipulate Oracle data flexibly and safely because PL/SQL supports all SQL data manipulation and transaction processing commands. For more information about PL/SQL, see Chapter 6, . Host variables are the key to communication between Oracle and your program. You use input host variables to pass data to the database. You use output host variables to pass data and status information from the database to your program. Host variables can be used anywhere an expression can be used. In SQL statements, host variables must be prefixed with a colon ': ' to set them apart from database schema names. You can associate any host variable with an optional indicator variable. An indicator variable is an integer variable that indicates the value or condition of its host variable. A NULL is a missing, an unknown, or an inapplicable value. You use indicator variables to assign NULLs to input host variables and to detect NULLs in output variables or truncated values in output character host variables. A host variable must not be: prefixed with a colon in COBOL statementsused in data definition (DDL) statements such as ALTER and CREATEIn SQL statements, an indicator variable must be prefixed with a colon and appended to its associated host variable (to improve readability, you can precede the indicator variable with the optional keyword INDICATOR). Every program variable used in a SQL statement must be declared according to the rules of the COBOL language. Normal rules of scope apply. COBOL variable names can be any length, but only the first 3. Pro*COBOL. Any valid COBOL identifier can be used as a host variable identifier, including those beginning with digits. The external datatype of a host variable and the internal datatype of its source or target database column need not be the same, but they must be compatible. Oracle inserts input data into database tables and selects output data into program host variables. To store a data item, Oracle must know its datatype, which specifies a storage format and valid range of values. Oracle recognizes two kinds of datatypes: internal and external. Internal datatypes specify how Oracle stores data in database columns. Oracle also uses internal datatypes to represent database pseudo- columns, which return specific data items but are not actual columns in a table. External datatypes specify how data is stored in host variables. When your host program inputs data to Oracle, it does any conversion between the external datatype of the input host variable and the internal datatype of the database column. When Oracle outputs data to your host program, if necessary, Oracle converts between the internal datatype of the database column and the external datatype of the output host variable. Note: You can override default datatype conversions by using dynamic SQL Method 4 or datatype equivalencing. For information about datatype equivalencing, see . Using the SELECT, FETCH, DELETE, INSERT, and UPDATE statements, you can query and manipulate large volumes of data with ease. For a complete discussion of host tables, see Chapter 7, . You need a way to handle these results. Pro*COBOL provides the following error handling mechanisms: SQLCODE status variable. SQLSTATE status variable. SQL Communications Area (SQLCA)WHENEVER statement. Oracle Communications Area (ORACA)SQLCODE/SQLSTATE Status Variables. After executing a SQL statement, the Oracle Server returns a status code to a variable named SQLCODE or SQLSTATE. The status code indicates whether the SQL statement executed successfully or caused an error or warning condition. SQLCA Status Variable. The SQLCA is a data structure that defines program variables used by Oracle to pass runtime status information to the program. With the SQLCA, you can take different actions based on feedback from Oracle about work just attempted. For example, you can check to see if a DELETE statement succeeded and, if so, how many rows were deleted. The SQLCA provides for diagnostic checking and event handling. At runtime, the SQLCA holds status information passed to your program by Oracle. After executing a SQL statement, Oracle. SQLCA variables to indicate the outcome, as illustrated in Figure 2- 2. Figure 2- 2 Updating the SQLCAText description of the illustration pco. You can check to see if an INSERT, UPDATE, or DELETE statement succeeded and if it did, how many rows were affected. Or, if the statement failed, you can get more information about what happened. When MODE=. These actions include continuing with the next statement, calling a subprogram, branching to a labeled statement, performing a paragraph, or stopping. ORACAWhen more information is needed about runtime errors than the SQLCA provides, you can use the ORACA. The ORACA is a data structure that handles Oracle communication. It contains cursor statistics, information about the current SQL statement, option settings, and system statistics. Precompiler Options and Error Handling. Oracle returns the success or failure of SQL statements in status variables, SQLSTATE and SQLCODE. With precompiler option MODE=ORACLE, you use SQLCODE, declared by including SQLCA. With MODE=ANSI, either SQLSTATE or SQLCODE must be declared, but SQLCA is not necessary. For more information, see Chapter 8, . Topics are arranged alphabetically for quick reference. Abbreviations. You can use the standard COBOL abbreviations, such as PIC for PICTURE IS and COMP for USAGE IS COMPUTATIONAL. Case- Insensitivity. Pro*COBOL precompiler options and values as well as all EXEC SQL statements, inline commands, and COBOL statements are case- insensitive. The precompiler accepts both upper- and lower- case tokens. COBOL Versions Supported. Pro*COBOL supports the standard implementation of COBOL for your operating system (usually COBOL- 8. COBOL- 7. 4). Some platforms may support both COBOL implementations. For more information, see your Oracle system- specific documentation. Coding Areas. The precompiler option FORMAT, specifies the format of your source code. If you specify FORMAT=ANSI (the default), you are conforming as much as possible to the ANSI standard. In this format, columns 1 through 6 can contain an optional sequence number, and column 7 (indicator area) can indicate comments or continuation lines. Division headers, section headers, paragraph names, FD and 0. A). Other statements, including EXEC SQL and EXEC ORACLE statements, must be placed in area B (columns 1. These guidelines for source code format can be overridden by your compiler's rules. If you specify FORMAT=TERMINAL, COBOL statements can begin in column 1 (the left- most column), or column 1 can be the indicator area. This format is also subject to the rules of your compiler.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
August 2017
Categories |