Mainframes 360
The one stop destination for System Z professionals

Thursday, August 20, 2009

MOVE Verb, Alpha-numeric MOVE, Numeric MOVE, Editing Symbols


Contents

  1. How the MOVE Verb works 
    1. Rules to be applied while MOVEing 
  2. MOVEing to an Alphanumeric Data-Item 
    1. Simple Program that shows an alpha-numeric MOVE 
  3. MOVEing to a Numeric Data-item
    1. Simple Program to show a Numeric MOVE 
  4. Editing Symbols 
    1. Rules of how EDITING symbols work
    2. Simple Program to show working of varous EDITING Symbols

Q. How does the MOVE Verb in COBOL work?

Suppose we have two WORKING STORAGE Data-items A and B. Assume that A is a numeric data-item containing the value 2. B is also a numeric data-item containing the value 3. What happens when we write the instruction :

MOVE A TO B.

This instruction copies the value of A into B. Note that the variable B can only hold 1 value at a time. So, the old data value 3 stores in B, is now over-written by a new data-value 2.

A is called the sending field, B is called the receiving field. We can also move literals/figurative constants into a variable. For example,

MOVE 123 TO A.

However, we cannot just move any value into a destination variable. There are some rules which apply.
1.
MOVE can copy elementary or group data-items.
2. In MOVE Operation, if the source data-item is too small to fit into the destination data-item fully, the remaining area is blanked(B) out (if alphanumeric move) or zeroed out(if numeric move).
3. When moving to a numeric data-item, the contents are always right-justified, for digits before the decimal point(to the left), and left-justified for digits after the decimal point.
4. When moving to an alpha-numeric data-item, the contents are always left-justified.
5. You can also move one group data-item or record to another group data-item. These are always treated as alpha-numeric moves.

Q. What is an Alpha-numeric MOVE?

When the receiving field/destination item is alpha-numeric, i.e. it has a PICTURE Clause XXX, then the move is called an Alphanumeric MOVE.

Let’s take a simple program that’ll help us to understand the above rules. Suppose we have a EMP-NAME Independent data-item which is alphanumeric of size 8. It initially stores the value JAYAPRADA.

Now, we move the literal ‘QUASAR’ to EMP-NAME. Firstly, we need to understand, that when we move data to a field, this old contents of the receiving field will be completely replaced. So, ‘QUASAR’ has a length=6. Thus, EMP-NAME is large enough to hold the literal ‘QUASAR’. What happens to the remaining 2 places in EMP-NAME? They will contain blanks. So, in the output, EMP-NAME is displayed as

QUASARBB

I’ve explicitly written BB to indicated two blanks. Blanks are simply displayed as whitespace in Output.

Now, when we move the literal ‘CHUNAWALLA’ to EMP-NAME, ‘CHUNAWALLA’ has length 10, so its too large to fit into EMP-NAME. Hence, a small part of ‘CHUNAWALLA’ will be stripped off, or cut off. Since, EMP-NAME is alpha-numeric, the contents will be left-justified. Hence, EMP-NAME will contain CHUNAWAL, and the last two characters LA are cut-off.


Upon running the above COBOL Program, we get the following Output in the SYSOUT Dataset.


Q. What is a Numeric MOVE?

When the destination is a numeric data-item, we consider it to be a numeric move. In Numeric moves, the data is aligned along the decimal point. For the integer part of the number, the movement is from right to left. For the decimal portion of the number, the movement is from left to right.

Let me show you a simple example that will be an aid to understand the above concept with great ease.




The Output of the above COBOL Program, as seen in SYSOUT Dataset, is as follows :

 
In the first MOVE, we store the value 1234.56 in SALARY Field which 9(4)V9(2). Thus, it fits exactly into SALARY. In the second MOVE, we store 12345.6 in SALARY. First, the SALARY Field is zeroed out so it contains 0000|00. Next, 12345 in SALARY, from right-to-left. 1 is truncated, or stripped off. The 6 is stored in the decimal part from left-to-right. So, SALARY field contains 2345|60. In the third move, we store 123.456 in SALARY Field. In this case, the integer part contains 0123 and the decimal part stores 45, with 6 being cut-off.

Q. What are the various EDITING Symbols?

A COBOL Program takes input data in the form of records, performs processing or operations on the Input Data records, to produce resultant Output Records. Very often, we need to customize or re-format the way, certain fields are displayed in the Output report.

For example, we may have to add leading blank spaces, suppress leading zeroes, or trailing zeros to the rhs of the decimal point, insert $, CR and DB symbols, show sign(+ or -) of the number, display decimal point etc. These are called as
Editing symbols.

Given below is simple COBOL Program, which demonstrates how to use various Edit symbols.




 
Upon compiling and executing the above COBOL Program, we get the following output in the SYSOUT Dataset -

To many people who are thrown to work at a mainframe computer on their first job, they feel lost. Mainframe people seem to speak a completely different language and that doesn't make life easy. What's more, the books and manuals are incredibly hard to comprehend.

"What on earth is a Mainframe?" is an absolute beginner's guide to mainframe computers. We'll introduce you to the hardware and peripherals. We'll talk about the operating system, the software installed on a mainframe. We'll also talk about the different people who work on a mainframe. In a nutshell, we'll de-mystify the mainframe.

Readers based in India, can buy the e-book for Rs. 50 only or the print book. International readers based in the US and other countries can click here to purchase the e-book.