z/OS TSO/E REXX User's Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Exercise - Writing an Exec with Built-In Functions

z/OS TSO/E REXX User's Guide
SA32-0982-00

Write an exec that checks a data set member name for a length of 8 characters. If a member name is longer than 8 characters, the exec truncates it to 8 and sends the user a message indicating the shortened name. Use the LENGTH and the SUBSTR built-in functions as described in z/OS TSO/E REXX Reference.

ANSWER

Possible Solution

/**************************** REXX *********************************/
/* This exec tests the length of a name for a data set member. If  */
/* the name is longer than 8 characters, the exec truncates the    */
/* extra characters and sends the user a message indicating the    */
/* shortened member name.                                          */
/*******************************************************************/
SAY 'Please enter a member name.'
PULL membername

IF LENGTH(membername) > 8 THEN  /* Name is longer than 8 characters*/
  DO
    membername = SUBSTR(membername,1,8)   /* Shorten the name to   */
                                          /* the first 8 characters*/
    SAY 'The member name you entered was too long.'
    SAY  membername 'will be used.'
  END
ELSE NOP

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014