• Aucun résultat trouvé

PROCESSING VARIABLE-LENGTH BLOCKED RECORDS

Dans le document A Programmer's Introduction to IBM System /360 (Page 110-113)

The following illustrative program applies techniques that are highly useful in certain commerical applications, and that the features of System/360 make particularly easy to accomplish. The task is the processing of blocked tape records (that is, many logical records in one physical block) with a variable number of records per block and with variable-length records. We shall take a record layout, furthermore, that places certain fIXed-length items after the variable-length portion of the record.

Each record in a block to be processed by the program of this example will contain four fields, with characteristics as follows:

variable, at most 60 characters 7 characters variable-length portion of the record. There is an unknown number of records. Immediately following the last record is another equal sign, which is the last character in the block.

We are required to process such a block, which we assume has already been read into core storage. We are to set up a line for printing that contains the account number, the quantity on hand, the sales, and the description, in that order. The numeric quantities are to be in zoned format.

After printing a line for each record in the block, we are to print the total dollar sales from all records on a separate line.

The program is shown in Figure 7-19. After the usual preliminaries we clear register 4 and store the resulting zero in TOTAL in order to be sure that the accumulator for total sales is zeroed. Register 7 is next loaded with the address of the first character of the block; register 7 will always contain the address of the first character of the next record as the loop is repeated. The MVI instruction inserts a one in the equal sign position of our translate table. This will occur during execution, of course.

In the body of the loop we fIrst blank out the space

The Translate and Test instruction references a table in which the only nonzero entry corresponds to an equal sign.

The effective address of the first operand in the Translate and T est is just the contents of rcgl:. ter 7 because the explicit displacement is zero. The length of 60 sets a limit on the search for an equal sign. If no equal sign is found within 60 bytes, the condition code will be zero; a Branch on Condition transfers to an error routine if this happens.

We now are ready to move the description from its place in the block to the space from which it will be printed. This can be done readily enough once we have available the length code of the description. Register I after the Translate and Test contains the address of the equal sign.

Subtracting from this address the address of the first byte of the description gives the length of the description in bytes;

one less than this number is the length code of the description. With this number in register 3, we can Execute a remote Move Characters instruction that moves the account number begins one byte beyond the address of the equal sign, which is contained in register 1. The effective address of the account number is therefore just register I as a base with a 1 for displacement. The address of the quantity on hand is just eight bytes beyond the address in register 1.

Here we must be careful of word boundaries. The quantity on hand was said to be a four-byte binary number, but, because of the variable length of the description, it may not be aligned on a word boundary in the block storage area.

LOC OBJECT CODE AOOR1 ADOR2 STMT SOURCE STATEMENT COMPUTE LENGTH CODE OF DESCRIPTION BRANCH IF EQ SIGN I S 1ST CHARACTER MOVE DESCRIPTION FOR PRINTING MOVE ACCOUNT NUMBER

MOVE QOH TO TEMPORARY STORAGE AREA QOH TO REGISTER FOR PROCESSING CONVERT TO DECIMAL

UNPACK AND MOVE FOR PRINTING SAME PROCESSING FOR DOLLARS

ADD DOLLARS TO TOTAL

-This completes the actions needed to make our first line of information ready for printing, and we would normally include a printer output routine at this point. There may still be another record in the block, so we branch back to AGAIN to see whether there is. During execution, the program will continue to go through the loop each time there is another record. After the fmal record, the equal sign delimiter that follows it will produce a result of -1 for the length-code computation, and this will cause the program to branch (on the Branch on Minus instruction) to our EOJ macro at OUT.

The sample block that appears at RECORD involves a little bit of trickery. One of the essential aspects of the assignment is that the binary fields appear in the block not aligned on word boundaries. In real life such a block would have been set up by a previous program. Here, in attemp-ting to set it up with DC entries, we run into the automatic boundary alignment that is normally performed on full-words. This action can be overridden~ however, by specifying a length modifier. A length of 4 is, of course, the same as the implied length of a fullword; the whole purpose is to prevent boundary alignment.

Dans le document A Programmer's Introduction to IBM System /360 (Page 110-113)