Structured Programming Macros: SELECT – You Gotta Try It!

The structured programming macros in HLASM are just too sweet to ignore.  Make your programming life easier by adopting them.  The SELECT statement works like Java’s SWITCH except the default behavior is to exit each case automatically (no pesky BREAKs) – just as God intended.  The code below examines a two-byte character field that contains a 01 for January, 02 for February, …, 12 for December.  The code substitutes a character version of the month in the output.  Notice how clean the code looks compared to what we would write in native assembler.

SELECT CLC,MONTHIN,EQ                   
   WHEN =C'01'                          
      MVC  MNTHOUT,=CL9'JANUARY'        
   WHEN =C'02'                          
      MVC  MNTHOUT,=CL9'FEBRUARY'       
   WHEN =C'03'                          
      MVC  MNTHOUT,=CL9'MARCH'          
   WHEN =C'04'                          
      MVC  MNTHOUT,=CL9'APRIL'          
   WHEN =C'05'                          
      MVC  MNTHOUT,=CL9'MAY'            
   WHEN =C'06'                          
      MVC  MNTHOUT,=CL9'JUNE'           
   WHEN =C'07'                          
      MVC  MNTHOUT,=CL9'JULY'           
   WHEN =C'08'                          
      MVC  MNTHOUT,=CL9'AUGUST'         
   WHEN =C'09'                          
      MVC  MNTHOUT,=CL9'SEPTEMBER'      
   WHEN =C'10'                          
       MVC  MNTHOUT,=CL9'OCTOBER'      
    WHEN =C'11'                        
       MVC  MNTHOUT,=CL9'NOVEMBER'     
    WHEN =C'12'                        
       MVC  MNTHOUT,=CL9'DECEMBER'     
    OTHRWISE                           
       MVC  MNTHOUT,=CL9'UNKNOWN'      
 ENDSEL                                

Just so you can see the difference, here is part of the generated code, which would be similar to the code we would write without the macro:

 SELECT CLC,MONTHIN,EQ
WHEN =C'01'
+       CLC MONTHIN,=C'01'
+       BC 7,#@LB2
        MVC MNTHOUT,=CL9'JANUARY'
WHEN =C'02'
+       BC 15,#@LB1 SKIP TO END
+#@LB2  DC 0H
+       CLC MONTHIN,=C'02'
+       BC 7,#@LB4
        MVC MNTHOUT,=CL9'FEBRUARY'
WHEN =C'03'
+       BC 15,#@LB1 SKIP TO END
+#@LB4  DC 0H
+       CLC MONTHIN,=C'03'
+       BC 7,#@LB6
        MVC MNTHOUT,=CL9'MARCH'
WHEN =C'04'
+       BC 15,#@LB1 SKIP TO END

Which is easier to debug and understand?

Leave a comment

Filed under IBM Mainframe Assembler

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s