Writing a Pro*COBOL Program. This chapter provides the basic information you need to write a Pro*COBOL program, including. Programming Guidelines. This section deals with embedded SQL syntax, coding conventions, and Pro*COBOL- specific features and restrictions. Topics are arranged alphabetically for quick reference. The precompiler accepts both upper- and lower- case tokens. Some platforms may support both COBOL implementations. For more information, see your Oracle. If you specify FORMAT=ANSI (default), columns 1 through 6 can contain an optional sequence number, and column 7 indicates comments or continuation lines. Division headers, section headers, paragraph names, FD and 0. A). Other statements begin in columns 1. B). The online sample programs use FORMAT=ANSI. For example, the following two statements are equivalent. ADD AMT1, AMT2, AMT3 TO TOTAL- AMT. COBOL Comment lines start with an asterisk (*) in column 7. You can also place ANSI SQL- style Comments (- - ..) within SQL statements at the end of a line (but not after the last line of the SQL statement), and you can place C- style Comments (/* .. Tutorial on reading COBOL layouts. For example, all 25 line items on an invoice. There can be nested occurs -- an occurs within an occurs. On the next line, code a hyphen (- ) in column 7, a quote in column 1. An example follows. WORKING STORAGE SECTION. If you specify LITDELIM=APOST, the Pro*COBOL uses apostrophes when generating COBOL code. If you specify LITDELIM=QUOTE (default), quotation marks are used, as in. 3 Writing a Pro*COBOL Program. This chapter provides the basic information you need to write a Pro*COBOL program, including: Programming Guidelines. For example, a banking system. The Object COBOL class program contains the code and data for both the class. ILE COBOL Programmer's Guide. For example, each of the following COBOL. Nested Programs COBOL allows one program to be nested inside another. For example, suppose that A and B are paragraphs and that A calls B.CALL . Embedded SQL syntax is described in the Oracle. Server SQL Reference. For example, the following is invalid. EXEC SQL DELETE FROM EMP WHERE COMM = ZERO END- EXEC. Some of the variables used internally limit the size of the generated file. There is no absolute limit to the number of lines allowed, but the following aspects of the source file are contributing factors to the file- size constraint. SQL statements (for example, the number of bind and define variables). AT clause). number of embedded SQL statements. To prevent problems related to this limitation, use multiple program units to sufficiently reduce the size of the source files. Variable names can be any length, but only the first 3. The maximum number of significant characters recognized by COBOL compilers is 3. For example, the following usage is invalid. MOVE . Pro*COBOL does not allow variables containing the VARYING clause, or SQL- CURSOR variables to be declared level 4. For Pro*COBOL, the default value is 2. The PIC N or PIC G clause declares variables that store fixed- length NCHAR strings. You can store variable- length, multi- byte NCHAR strings using COBOL group items consisting of a length field and a string field, or using the modifier VARYING. This restriction cannot be enforced when precompiling, so the use of these column types within embedded DDL statements results in an execution error rather than a precompile error. Use the NVL function to convert nulls to non- null values, use the IS . GOTO statement, as the next example shows: PROCEDURE DIVISION. REDEFINES Clause. You can use the COBOL REDEFINES clause to redefine group or elementary items. For example, the following declarations are valid: EXEC SQL BEGIN DECLARE SECTION END- EXEC. Furthermore, COBOL allows the use of words instead of symbols, whereas SQL does not. In conditional sentences, only the last statement must end with a period, as the following example shows. IF EMP- NUMBER = ZERO. MOVE FALSE TO VALID- DATA. PERFORM GET- EMP- NUM UNTIL VALID- DATA = TRUE. EXEC SQL DELETE FROM EMP. WHERE EMPNO = : EMP- NUMBER. END- EXEC. ADD 1 TO DELETE- TOTAL. STOP to handle errors for a SQL statement, the SQL statement must be terminated by a period or followed by an ELSE. The word FILLER is used to specify an elementary item of a group that cannot be referred to explicitly. The following declaration is valid. STOCK. This section shows you how to meet these requirements. This is a change from Pro*COBOL prior to release 8. Declarations of host variables and indicator variables can be made either inside or outside a Declare Section. This option is. DECLARE. When MODE=ORACLE and DECLARE. When MODE=ANSI then DECLARE. See the discussion of macro and micro options in . Furthermore, a host program can contain several independently precompiled units. When you precompile your Pro*COBOL program, each EXEC SQL INCLUDE statement is replaced by a copy of the file named in the statement. The default extension is system- dependent. For more information, see your Oracle system- specific documentation. You need not specify a path for standard files such as the SQLCA and ORACA. However, a path is required for nonstandard files unless they are stored in the current directory. INCLUDE=< path. INCLUDE=< path. The directory containing standard INCLUDE files is searched last. The path syntax is system specific. For more information, see your Oracle system- specific documentation. If the file you want to INCLUDE is in another directory, make sure no file with the same name is in the current directory or any other directory that precedes it in the search path. If your operating system is case sensitive, be sure to specify the same upper/lowercase filename under which the file is stored. With Oracle mode, you can declare SQLCODE by including the SQLCA. For more information, see Chapter 9, . Typically, a host program inputs data to Oracle. Oracle. 8 outputs data to the program. Oracle. 8 stores input data in database columns and stores output data in program host variables. COBOL datatypes must be compatible with the source/target database column. For variable- length strings, n is the maximum length. For more information, see . For floating- point numbers, however, PIC strings are not accepted. The NLS settings for your system might change the decimal point from a period (.) to a comma (,). When converted to a binary value, the length is 7 bytes. If the string value assigned to a character variable is longer than the declared length, the string is truncated. Therefore, the following variable declarations cannot be made for host variables. A host variable must be prefixed with a colon (: ) in SQL statements but must not be prefixed with a colon in COBOL statements, as this example shows. WORKING- STORAGE SECTION. Group items with elementary items (containing only one level) can be used as host variables. The host group items (also referred to as host structures) can be referenced in the INTO clause of a SELECT or a FETCH statement, and in the VALUES list of an INSERT statement. When a group item is used as a host variable, only the group name is used in the SQL statement. For example, given the following declaration. DEPARTURE. Using a group item as a host variable has the semantics of substituting the group item with elementary items. In the above example, it would mean substituting : DEPARTURE with : DEPARTURE. HOUR, : DEPARTURE. MINUTE. In the following example, the group item containing tables is used to INSERT three entries into the SCHEDULE table. DEPARTURE. If the nested group item declaration resembles a VARCHAR host variable, then the entire group item is treated like an elementary item of VARYING type. It is similar to the IN (or OF) clause in COBOL, examples of which follow. MOVE MINUTE IN DEPARTURE TO MINUTE- OUT. Qualify elementary names to avoid ambiguity. For example. EXEC SQL BEGIN DECLARE SECTION END- EXEC. The contained programs may reference some of the resources of the programs within which they are contained. The names within the higher- level program and the nested program can be the same, and describe different data items without conflict, because the names are known only within the programs. However, names described in the Configuration Section of the higher- level program can be referenced in the nested program. Likewise, nested programs can have programs nested within them. You must place the nested program directly before the END PROGRAM header of the program in which it is nested. If you want a nested program to be called by any program, even one on a different branch of the nested tree structure, you code the COMMON clause in the PROGRAM- ID paragraph of the nested program. You can code COMMON only for nested programs. PROGRAM- ID. This allows them to be referenced in all subprograms directly or indirectly contained within them. You code GLOBAL on the higher- level program. If the nested program defines the same name as one declared GLOBAL in a higher- level program, COBOL uses the declaration within the nested program. If the data item contains a REDEFINES clause, GLOBAL must follow it. All 0. 1 level items which are marked as global in a containing program and are valid host variables at the containing program level are usable as valid host variables in any programs directly or indirectly contained by the containing program. Consider the following example. IDENTIFICATION DIVISION. Since VAR1 is declared as a global variable and also as a local variable in the nested program, the second select statement will use the VAR1 declared as S9(4), overriding the global declaration. In the third select statement, the global VAR1 of REC1 declared as PIC X(1. If the above program is precompiled with DECLARE. The first and third select statements would function the same. The SQLCA can change each time a new SQL statement is executed. The SQLCA provided can always be modified to remove the global specification if you want to declare additional SQLCA areas in the nested programs. The same will apply to SQLDA and ORACA. Each time the host variable is used in a SQL statement, a result code is stored in its associated indicator variable. Thus, indicator variables let you monitor host variables. In the following example, you declare an indicator variable named COMM- IND (the name is arbitrary). WORKING- STORAGE SECTION. In COBOL statements, an indicator variable must not be prefixed with a colon or appended to its associated host variable. An example follows. EXEC SQL SELECT SAL, COMM. INTO : SALARY, : COMMISSION: COMM- IND FROM EMP. WHERE EMPNO = : EMP- NUMBER. END- EXEC. You must still prefix the indicator variable with a colon.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2016
Categories |