You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: COBOL Programming Course #1 - Getting Started/COBOL Programming Course #1 - Getting Started.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1840,7 +1840,7 @@ A structured level number hierarchic relationship is available to all DATA DIVIS
1840
1840
1841
1841
### Levels of data
1842
1842
1843
-
After a record is defined, it can be subdivided to provide more detailed data references as seen in Figure 1. A level number is a one-digit or two-digit integer between 01 and 49, or one of three special level numbers: 66, 77, or 88 where the variable names are assigned attributes different from the 01-49-level numbers. The relationship between level numbers within a group item defines the hierarchy of data within that group. A group item includes all group and elementary items that follow it until a level number less than or equal to the level number of that group is encountered.
1843
+
After a record is defined, it can be subdivided to provide more detailed data references as seen in Figure 1. A level number is a one-digit or two-digit integer between 01 and 49, or one of three special level numbers: 66, 77, or 88 where the variable names are assigned attributes different from the 01-49-level numbers. The relationship between level numbers within a group item defines the hierarchy of data within that group. A group item includes all group and elementary items that follow it until a level number less than or equal to the level number of that group is encountered. An elementary item is an item which cannot be further subdivided. These items have a PIC clause because they reserve storage for the item.
Copy file name to clipboardExpand all lines: COBOL Programming Course #2 - Advanced Topics/COBOL Programming Course #2 - Advanced Topics.md
+151Lines changed: 151 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,46 @@ header-includes:
18
18
- \hypersetup{colorlinks=true,
19
19
linkcolor=blue}
20
20
---
21
+
\newpage
22
+
## Additional information
23
+
24
+
This section provides useful resources in the form of manuals and videos to assist in learning more about the basics of COBOL.
25
+
26
+
### Professional manuals
27
+
28
+
As Enterprise COBOL experience advances, the need for the professional documentation is greater. An internet search for Enterprise COBOL manuals includes: “Enterprise COBOL for z/OS documentation library - IBM”, link provided below. The site content has tabs for each COBOL release level. As of April 2020, the current release of Enterprise COBOL is V6.3. Highlight V6.3 tab, then select product documentation.
Three ‘Enterprise COBOL for z/OS” manuals are referenced throughout the chapters as sources of additional information, for reference and to advance the level of knowledge. They are:
34
+
35
+
1. Language Reference - Describes the COBOL language such as program structure, reserved words, etc.
@@ -225,6 +265,117 @@ COMP-2 supersedes COMP-1 for more precise scientific data storage as well as com
225
265
226
266
**Note** : [This](https://www.ibm.com/support/pages/how-display-hexadecimal-using-cobol) COBOL program can display the hexadecimal contents (and hence the exact internal representation) of a field. You can declare binary, packed decimal or zoned variable (or anything else, for that matter), do arithmetic with them and use the program to see how they are internally stored.
227
267
268
+
\newpage
269
+
# Dynamic-Length Item
270
+
So far during this course, we have only explored data items that have a fixed length. In other words, you need to define the length you need for each data type. But in this section, we will explore a fairly new concept in Enterprise COBOL - dynamic-length items.
271
+
272
+
Enterprise COBOL v6.3 supports dynamic-length items, which are items whose logical length might change at runtime.
273
+
274
+
## Dynamic-Length Elementary Items
275
+
276
+
Let us consider a dynamic-length elementary item. To recall, an elementary item is an item that cannot be further subdivided. These items have a PIC clause since storage is reserved for it. If we used dynamic-length elementary item to send data, it will be treated as a fixed-length item with a length equals to the current length of the dynamic-length item. On the other hand, if we used dynamic-length elementary item to receive data and it's not reference-modified, the content will simply be moved to the receiving's content buffer.
277
+
278
+
If the content received is longer than the current length, a new larger buffer will be allocated for it. Additionally, if the length of the sender is zero, the receiver's length will be set to zero as well.
279
+
280
+
Now, if the dynamic-length elementary item is used to receive data and we reference-modified it, the item will be treated as a fixed-length item with with a length equals to the current length of the dynamic-length item. In such cases, the compiler will not allocate or reallocated the buffer.
281
+
282
+
Note that not all statement supports dynamic-length elementary items. Common statement like REDEFINE or RENAME will not work. Additionally, we cannot take their address using the ADDRESS-OF special register. The full list of the statements supported is available on the [Language Reference](https://www.ibm.com/docs/en/cobol-zos/6.3?topic=relationships-dynamic-length-items).
283
+
284
+
When we compare a dynamic-length item with a fixed-length item, the comparison will follow the normal comparison rules (the shorter item will be extended to the right with enough spaces to make both items equal in length and then each character will be compared). Meanwhile, if you compare two dynamic-length elementary items, the lengths will be compared first and if they matched, the characters will then be examined.
285
+
286
+
We can also set the length of dynamic-length elementary item using the SET LENGTH OF syntax and pass dynamic-length elementary items as fixed-length items to a subroutine using the AS FIXED LENGTH phrase.
287
+
288
+
Note that doing the intrinsic function MIN and MAX are not supported for dynamic-length items.
289
+
290
+
## Dynamic-Length Group Items
291
+
292
+
A dynamic-length group item is a group item that contains at least one subordinate dynamic-length elementary item and whose logical length might change at runtime.
293
+
294
+
Any other group item is considered to be a fixed-length group item. These fixed-length group items can contain variable-length tables through the OCCURS DEPENDING ON clause.
295
+
296
+
Additionally, we cannot compare or move dynamic-length group items to any other group items. On the other hand, fixed-length group items are always compatible and comparable with other fixed-length group items.
297
+
298
+
## DYNAMIC LENGTH Clause
299
+
300
+
To define a dynamic length item, we can include the DYNAMIC LENGTH clause on the data description entry. Here are a couple of examples of how to indicate the clause:
301
+
302
+
```
303
+
01 MY-DYN PIC X DYNAMIC.
304
+
01 NAME PIC X DYNAMIC LENGTH.
305
+
01 DYN-PRICE PIC X DYNAMIC LIMIT 500.
306
+
```
307
+
308
+
Let us observe a few things from the examples above. Firstly, we note that the LENGTH keyword is optional. Next, we also have a LIMIT phrase that specifies the maximum length of the data item. If a sender's length is longer than the receiver's LIMIT value, the data will be truncated on the right. This LIMIT value defaults to 999999999 if not specified. Lastly, note that we use PIC X. To use dynamic-length clause, you can only use PIC X or PIC U (which is for UTF-8 data item).
309
+
310
+
\newpage
311
+
# UTF-8 Data Type
312
+
313
+
With Enterprise COBOL v6.3, we also have a new USAGE, which is UTF-8. This is indicated by the picture symbol 'U'. Unlike NATIONAL or DBCS characters, the byte length of each UTF-8 character varies between 1 and 4 bytes. Enterprise COBOL treats a single UTF-8 character as equivalent to a single Unicode code point.
314
+
315
+
## UTF-8 Data Items
316
+
317
+
There are three ways that Enterprise COBOL uses to define UTF-8 data items.
318
+
319
+
### Fixed Character-Length UTF-8 Data Items
320
+
321
+
This type of UTF-8 data item is defined when the PICTURE clause contains one or more 'U' characters, or a single 'U' followed by a repetition factor. Take for example the piece of code below:
322
+
323
+
```
324
+
01 NEW-UTF-CHAR PIC U(10).
325
+
```
326
+
327
+
In this case, we define a fixed character-length UTF-8 data item that holds 10 UTF-8 characters that occupy between 10 (n) and 40 (4 * n) bytes. Since UTF-8 character's byte length varies, 4 * n bytes are always reserved for UTF-8 item. If there are unused bytes, those will be padded with the UTF-8 blank statement (x'20'). When truncation is performed, it is done on a character boundary.
328
+
329
+
### Fixed Byte-Length UTF-8 Data Items
330
+
331
+
Like fixed character-length, we define this by the inclusion of the 'U' character in the PICTURE clause. But now, we will add a phrase called BYTE-LENGTH. Observe the code below:
332
+
333
+
```
334
+
01 NEW-UTF-BYTE PIC U BYTE-LENGTH 10.
335
+
```
336
+
337
+
In this case, we define a fixed byte-length UTF-8 data item that holds 10 bytes of UTF-8 data, this translates to up to 10 characters. When these are used to receive characters with byte length smaller than indicated, the unused bytes are padded by the UTF-8 blank statement (x'20').
338
+
339
+
### Dynamic-Length UTF-8 Data Items
340
+
341
+
Lastly, we have the dynamic-length UTF-8 data items. This is defined when we have a PICTURE clause with the 'U' character and the DYNAMIC LENGTH clause. Observe the code below:
342
+
343
+
```
344
+
01 NEW-UTF-DYN PIC U DYNAMIC LIMIT 10.
345
+
```
346
+
347
+
With dynamic-length UTF-8 data item, there is no restriction on the number of bytes besides the one indicated on the LIMIT phrase of the DYNAMIC LENGTH clause. Unlike the other two definitions, no padding is involved with the dynamic-length UTF-8 data item. Truncation will only occur on the character boundaries if it exceeds the specified limit.
348
+
349
+
Note that UTF-8 edited, numeric-edited, decimal and external float are not supported.
350
+
351
+
## UTF-8 Literals
352
+
353
+
There are two types of UTF-8 literals which are supported on Enterprise COBOL.
354
+
355
+
### Basic UTF-8 Literals
356
+
357
+
```
358
+
U'character-data'
359
+
```
360
+
361
+
When we define basic UTF-8 literals, the character-data is converted from EBCDIC to UTF-8. If we have double-byte EBCDIC characters, those must be delimited by shift-out and shift-in characters. The amount of Unicode code points which we can represent here varies depending on the size of the UTF-8 characters, but a maximum of 160 bytes (after conversion) is allowed before truncation.
362
+
363
+
### Hexadecimal UTF-8 Literals
364
+
365
+
```
366
+
UX'hexadecimal-digits'
367
+
```
368
+
369
+
In this case, the hexadecimal-digits are converted to bytes sequences which are used verbatim as the UTF-8 literal values. There is a minimum of 2 hexadecimal digits and a maximum of 320.
370
+
371
+
## UTF-8 Move Rules and Conversion
372
+
373
+
Generally speaking, a UTF-8 data item can be moved only to those of category National or UTF-8. While they can receive items from Alphabetic, Alphanumeric, National or UTF-8. If there are any padding or truncation, those are always done at the UTF-8 character.
374
+
375
+
Additionally, we can use the intrinsic function DISPLAY-OF to convert national to UTF-8 and UTF-8 to alphanumeric or the intrinsic function NATIONAL-OF to convert UTF-8 to national.
376
+
377
+
**Note** : For more information, please refer to the [Programming Guide](https://www.ibm.com/docs/en/cobol-zos/6.3?topic=cobol-converting-from-utf-8-unicode-representation).
378
+
228
379
\newpage
229
380
# COBOL Application Programming Interface (API)
230
381
API is the acronym for Application Programming Interface. An API allows two applications to communicate. We use API's everyday from our phones, personal computers, using a credit card to make a payment at a point of sale, etc.
0 commit comments