You are here: Home > Knowledge Refreshers

KR editions 93 to 96


KR-93 (cutting tips)

We'll take a short break from our management series and go into some techie stuff. 
Did you know that we have clipboards in mainframes! Did you ever wonder about the DEFAULT in the message "5 lines cut to DEFAULT"? 

KR contributed by Latha:
The CUT and PASTE commands

  • The CUT primary command saves lines to one of eleven named clipboards for later retrieval by the PASTE command. The lines can be appended to the lines already saved by a previous CUT command or can replace existing lines in a clipboard.
    The syntax of the CUT command is:

    CUT {line pointer range} {DEFAULT or Clipboard name} {REPLACE or APPEND} 
    CUT DISPLAY
  • Line pointer range is two line pointers that specify the range of lines in the current member that are to be added to or replace data in the clipboard. A line pointer can be a label or relative line number. You must specify both a starting and ending line pointer. If you do not specify a range of lines, all lines in the edit session are copied to the clipboard. 
    E.g.: CUT .a .b
  • Clipboard name is the name of the clipboard to use. If you omit this parameter, the ISPF default clipboard (named DEFAULT) is used. You can define up to ten additional clipboards. The size of the clipboards and number of clipboards might be limited by installation defaults. 
    E.g.: 
    CUT CLIP1
    PASTE CLIP1
    CUT .a .b CLIP2
    PASTE CLIP2 
  • REPLACE or APPEND: Specify REPLACE to replace existing data in the clipboard. Specify APPEND to add the data to the clipboard. You can select REPLACE or APPEND as the default by entering the EDITSET command on the editor command line. The default action depends on the setting specified in EDITSET. 
  • CUT DISPLAY: use this command to show a list of existing clipboards. From this list you can browse, edit, clear, or rename the clipboards. The clipboard manager will pop up and will give the options to view, edit …

That's all for this edition and this week....suggestions and contributions welcome;
Have a great weekend.


KR-94 (COBOL pics)

The way cobol stores numbers tends to get confusing. We'll establish some basics about storage of numbers and then tackle the questions. A few questions:
If I move -8 to a PIC S9(1) variable and display this in my spool it shows: Q.
If I move 8 to a PIC S9(1) variable then it shows H.
If I move 8 to a PIC 9(1) variable then it shows 8. Why?


KR idea triggered by Elan and Divya:

  • What does an S9(1) mean? Is it a COMP variable?
    Unless we explicitly specify that usage is COMP the variable will not be considered a COMP. 
  • So, an S9(2) is not a COMP and when we don't specify anything the default type is 'display'. All variables of type display occupy one byte for each character.
  • Thus a simple PIC 9(2) will occupy 2 bytes. And a PIC S9(2) will also occupy 2 bytes. 
  • The question arises: how is the sign stored? before that we'll take a look at something simpler.

How is a PIC 9(1) stored?

  • To store one digit (0-9) we actually require a maximum of only 4 bits. For example: if we want to represent the digit 9, in binary it would be 1001 (digit 8 is 1000). 
  • But in type display, as in PIC 9(1), each digit will occupy 8 bits (i.e. one byte). Which means that to represent one digit we need to add 4 extra bits (let's call them dummy bits).
  • So to represent the digit 8, we would need to prefix 4 extra bits; the binary form for 8 would be 0000 1000 (using 0s for the dummy bits; or if we use 1s for the dummy bits it would be: 1111 1000). The latter is what is used in the COBOL standards (using 1s to fill up the extra space).
  • The number 28 if stored in a PIC 9(2) will be stored as: 1111 0010 1111 1000 (idea is simple: 2 = 0010 and 8 = 1000 and we just add 1s to fill up the rest of the space).

Try it out: just open an empty flat file and type a digit. Then on the command line type HEX ON and you'll know how a display digit is stored (note: 1111 = F in hexadecimal format). So if you typed 6 in the flat file and entered 'hex on' you'd see F6 on the screen - which equals 1111 0110.
What about an S9(2)? 

This edition is getting long so we'll continue tomorrow.....


KR-95 (COBOL pics II)

Continuing where we left off in our discussion on S9(2) and 9(2).....

  • As seen earlier, a numeric digit in display format actually needs only 4 bits for representation while the remaining 4 bits are only dummy bits and not used for anything. 
  • So even though a PIC 9(2) and a PIC S9(2) occupy 2 bytes, there is enough space to accomodate the sign (in 9(2) it's not needed but in S9(2) we have to accomodate the sign). 
  • The sign in a PIC S9(2) is stored in the rightmost digit's dummy bits (C for +ve and D for -ve; i.e. instead of 1111 in the dummy bits we'll have 1100 for a positive sign and 1101 for negative sign).
    Ex: 28 in a PIC 9(2) will be 1111 0010 1111 1000
    -28 in a PIC S9(2) will be 1111 0010 1101 1000
    28 in a PIC S9(2) will be 1111 0010 1100 1000

That covers the storage aspect of 9(2) and S9(2). Now we'll take a look at what happens when we display these values on screen.

  • Everything in a PC is stored in binary format; every character should also be stored in binary format. But how do we store alphabets or special characters as numbers? 
  • To convert between characters and numbers the PC uses some form of coding. In PCs it is ASCII and in mainframes (IBM systems) it is EBCDIC.
  • So, if you typed the letter H in a flat file, this H would be converted to a number using EBCDIC (the number in hex is C8 or 1100 1000 or in decimal it's 204). So a H is stored in memory as C8. When we read the flat file, the PC reads C8, and tries to convert it into a displayable character (it decodes C8 using EBCDIC and gets H). 

That should help answer yesterday's questions:

1.) A +8 stored in an S9(1) is stored as 1100 1000 (this corresponds to H). Thus when we display this in the spool we would see the character H and not +8 or 8.
2.) Similarly, a -8 in an S9(1) is stored as 1101 1000 (or D8 in hexa) and through EBCDIC decoding we'll arrive at the character Q.
3.) But an 8 stored in a PIC 9(1) is stored as 1111 1000 of F8 which in EBCDIC represents the character '8' itself.

That's all for this edition.....


KR-96 (COBOL numerics)

A short KR to round up the week.

To sum up our discussion, the different ways of representing numerics in COBOL are:
1.) DISPLAY - numerics in display type are also called zoned decimal (remember we talked about 4 dummy bits in every byte of a numeric; these 4 dummy bits are called the "zone bits" while the last 4 bits are the digit bits). There are 2 numeric types in display format: signed and unsigned; i.e. 9(2) or S9(2).
2.) PACKED DECIMAL or COMP-3
3.) Binary or COMP or COMP-4
4.) COMP-1
5.) COMP-4

  • COMP-1 and COMP-4 are used to store large floating point numbers (using exponents) and generally not used in programs because precision is lost. 
  • Did you know that EBCDIC stands for Extended Binary Coded Decimal Interchange Code? 
  • Ever wondered why character '1' is greater than 'A' in COBOL? This is because in EBCDIC, character '1' has a hex value of F1 while 'A' has a hex value of C1 (F1 > C1 so 1 > A). 
  • The alphabets A to Z in EBCDIC have the hex codes C1 to E9 (and 0 to 9 have hex code F0 to F9).

Well, that's all for this edition and this week; have a great weekend (suggestions and contributions welcome);


Go back to the main contents page