IBM COBOL for Linux on X86 1.1: Programming Guide Part 1
Total Page:16
File Type:pdf, Size:1020Kb
IBM COBOL for Linux on x86 1.1 Programming Guide IBM SC28-3118-00 Note Before using this information and the product it supports, be sure to read the general information under “Notices” on page 587. First edition This edition applies to Version 1.1 of IBM® COBOL for Linux® on x86 (program number 5737-L11) and to all subsequent releases and modifications until otherwise indicated in new editions. Make sure you are using the correct edition for the level of the product. You can view or download softcopy publications free of charge in the COBOL for Linux on x86 library. © Copyright International Business Machines Corporation 2021. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents Tables..................................................................................................................xv Preface...............................................................................................................xix About this information...............................................................................................................................xix How this information will help you...................................................................................................... xix Abbreviated terms................................................................................................................................xix How to read syntax diagrams............................................................................................................... xx How examples are shown....................................................................................................................xxi Related information............................................................................................................................. xxi How to send your comments.................................................................................................................... xxi Accessibility............................................................................................................................................... xxi Part 1. Coding your program.................................................................................. 1 Chapter 1. Structuring your program...........................................................................................................3 Identifying a program.............................................................................................................................3 Identifying a program as recursive...................................................................................................4 Marking a program as callable by containing programs.................................................................. 4 Setting a program to an initial state................................................................................................. 4 Changing the header of a source listing........................................................................................... 4 Describing the computing environment.................................................................................................5 Example: FILE-CONTROL paragraph................................................................................................5 Specifying the collating sequence....................................................................................................6 Defining symbolic characters........................................................................................................... 7 Defining a user-defined class........................................................................................................... 8 Identifying files to the operating system (ASSIGN)......................................................................... 8 Describing the data.................................................................................................................................9 Using data in input and output operations.......................................................................................9 Comparison of WORKING-STORAGE and LOCAL-STORAGE......................................................... 11 Using data from another program.................................................................................................. 12 Processing the data..............................................................................................................................13 How logic is divided in the PROCEDURE DIVISION.......................................................................14 Declaratives.................................................................................................................................... 17 Chapter 2. Using data................................................................................................................................ 19 Using variables, structures, literals, and constants............................................................................ 19 Using variables................................................................................................................................19 Using data items and group items..................................................................................................20 Using literals................................................................................................................................... 21 Using constants...............................................................................................................................22 Using figurative constants.............................................................................................................. 22 Assigning values to data items.............................................................................................................23 Examples: initializing data items....................................................................................................24 Initializing a structure (INITIALIZE).............................................................................................. 27 Assigning values to elementary data items (MOVE)...................................................................... 28 Assigning values to group data items (MOVE)............................................................................... 29 Assigning arithmetic results (MOVE or COMPUTE)........................................................................30 Assigning input from a screen or file (ACCEPT)............................................................................. 30 Displaying values on a screen or in a file (DISPLAY)........................................................................... 31 Using intrinsic functions (built-in functions)....................................................................................... 32 iii Using tables (arrays) and pointers.......................................................................................................33 Chapter 3. Working with numbers and arithmetic....................................................................................35 Defining numeric data.......................................................................................................................... 35 Displaying numeric data.......................................................................................................................37 Controlling how numeric data is stored...............................................................................................38 Formats for numeric data.....................................................................................................................39 Examples: numeric data and internal representation................................................................... 42 Data format conversions...................................................................................................................... 46 Conversions and precision..............................................................................................................47 Sign representation of zoned and packed-decimal data.................................................................... 47 Checking for incompatible data (numeric class test)..........................................................................48 Performing arithmetic.......................................................................................................................... 48 Using COMPUTE and other arithmetic statements........................................................................49 Using arithmetic expressions......................................................................................................... 50 Using numeric intrinsic functions...................................................................................................50 Examples: numeric intrinsic functions...........................................................................................51 Fixed-point contrasted with floating-point arithmetic........................................................................53 Examples: fixed-point and floating-point evaluations...................................................................55 Using currency signs...........................................................................................................................