Overview
Packed decimal numbers are frequently used to represent amounts of money. We would like to be able to print dollars signs for our numbers. Normally a dollar sign is found immediately to the left of the leftmost printed digit. That is, we would like to have
$123.45 $23.45 $3.45
and not
$123.45 $ 23.45 $ 3.45
The first of these is a floating dollar sign and the second is a fixed dollar sign.
We can arrange for a dollar sign to float using the Edit and Mark instruction.
Format
The format for Edit and Mark is:
EDMK D1(L,B1),D2(B2)
D1(B1) is the address of a character field L bytes long. This is the destination where we want to have the printable value.
D2(B2) is the address of a packed decimal variable. Notice we do not have a length for it.
In other words, EDMK looks a great deal like ED.
How do we use it?
EDMK behaves very much like ED except that it may change the value of register 1. Specifically, it will set register 1 = the address of the last character X in the result such that:
if such a character exists. If there is no such character, the value of register 1 is unchanged.
Normally there is at most one such character, so we could say "first" instead of "last".
Another way of saying this is that register 1 will usually be set to the address of the leftmost digit.
Why is this useful? We will want to put our dollar sign immediately to the left of the character X.
The sequence of events is thereforeL
Example
Suppose we have:
COST DC PL3'3995' OUTCOST DS CL7
We now execute:
MVC OUTCOST(7),=XL7'402021204B2020' EDMK OUTCOST(7),COST
OUTCOST will now contain XL7'4040F3F94BF9F5' and register 1 will contain the address of the X'F3'.
We want to put a dollar sign in place, so we need:
BCTR 1,0 MVI 0(1),C'$'
and now OUTCOST contains XL7'405BF3F94BF9F5', where X'5B' is a dollar sign.
What can go wrong?
Notice that the above statement about EDMK's effects includes the phrase "if such a character exists". How can that happen? One possibility is that the pattern has a misplaced X'21'. (Try putting X'21' immediately before X'4B'.) In that case, register 1's value is unchanged and we might end up putting a dollar sign somewhere we don't want it.
To avoid this, we can set register 1 to a default address where we want a dollar sign. Normally this will be the byte immediately after the X'21'.
So we might have:
LA 1,OUTCOST+3 MVC OUTCOST(7),=XL7'402021204B2020' EDMK OUTCOST(7),COST> BCTR 1,0 MVI 0(1),C'$'
What else can we do with EDMK?
The same technique can be used to put a plus or minus sign to the left of a number. Like ED, EDMK sets the condition code.
We could have:
NUMBER DS PL4 OUTNUM DS CL10
and then we execute:
MVC OUTNUM(10),=XL10'40206B2020206B202120' EDMK OUTNUM(10),NUMBER BC B'0010',POS BC B'0100',NEG POS BCTR 1,0 MVI 0(1),C'+' B DONE NEG BCTR 1,0 MVI 0(1),C'-' DONE DS 0H
If NUMBER's value is 0, we will have a blank, not C'+' or C'-'.