Table Processing

Accessing table elements containing multiple fields is best done using a DSECT and manipulating its base register, rather than using an index register.

Loop using an index register.  Index subfield required for RX instructions.  Extra register and instruction required to index the SS-format instructions.

         LA    R5,0                     INIT INDEX
         LA    R6,ITEMLEN               INCREMENT: ITEM LENGTH
         LA    R7,L'EMPLTAB-ITEMLEN     COMPARAND: OFFSET OF LAST ITEM
LOOP     DS    0H
         CLC   SSN(R5),=C'123456789'
         BNE   NEXT
         LA    R4,SALARY(R5)            EXTRA REG AND INSTRUCTION
         AP    0(L'SALARY,R4),=P'5000'  EXPLICIT FORMAT
NEXT     BXLE  R5,R6,LOOP
*
*                                  TABLE ITEM LAYOUT
SSN      DS    CL9                      SOCIAL SECURITY NUMBER
LNAME    DS    CL20                     LAST NAME
FNAME    DS    CL20                     FIRST NAME
SALARY   DS    PL5                      SALARY
*
ITEMLEN  EQU   *-SSN                    LENGTH OF TABLE ELEMENT
NUMITEMS EQU   50
         ORG   SSN
EMPLTAB  DS    CL(NUMITEMS*ITEMLEN)     INPUT AREA FOR TABLE ELEMENTS
         ORG

Loop manipulating the base register.  DSECT required, subfields not required.

         USING ITEM,R5
*
         LA    R5,EMPLTAB                    INIT BASE REG
         LA    R6,ITEMLEN                    INCREMENT: ITEM LEN
         LA    R7,EMPLTAB+L'EMPLTAB-ITEMLEN  COMPARAND: LAST ITEM ADDR
LOOP     CLC   SSN,=C'123456789'
         BNE   NEXT
         AP    SALARY,=P'5000'
NEXT     BXLE  R5,R6,LOOP
*
*
NUMITEMS EQU   50
EMPLTAB  DS    CL(NUMITEMS*ITEMLEN)       INPUT AREA FOR TABLE ELEMENTS
*                                           
ITEM     DSECT                       TABLE ITEM LAYOUT
SSN      DS    CL9                        SOCIAL SECURITY NUMBER
LNAME    DS    CL20                       LAST NAME
FNAME    DS    CL20                       FIRST NAME
SALARY   DS    PL5                        SALARY
ITEMLEN  EQU   SALARY-SSN+L'SALARY        LENGTH OF TABLE ELEMENT

Copyright © 2006 The Stevens Computing Services Company, Inc.  All rights reserved.