Exercise - Writing a program with Built-In Functions

About this task

Write a program that checks a file name for a length of 8 characters. If the name is longer than 8 characters, the program truncates it to 8 and sends a message indicating the shortened name. Use the built-in functions LENGTH, see page LENGTH, and SUBSTR, see page SUBSTR (Substring).

ANSWER
Figure 1. Possible Solution
/***************************** REXX *********************************/
/*  This program tests the length of a file name.                   */
/*  If the name is longer than 8 characters, the program truncates  */
/*  extra characters and sends a message indicating the shortened   */
/*  name.                                                           */
/********************************************************************/
PULL name                     /* Gets name from input stream        */

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

Task Task

Feedback


Timestamp icon Last updated: Tuesday, 7 January 2014


http://pic.dhe.ibm.com/infocenter/cicsts/v5r1/topic/com.ibm.cics.rexx.doc//dfhrx/dfhrx00052.html