MainframeSupports
tip week 21/2013:

Recently I needed to split a lot of records at a specific word instead of at a specific position. Of course the word did not occur at the same position in all records. I recalled the SPLIT funcion in ISPF EDIT. Fortunately the SPLIT function is available as an EDIT MACRO command and thus I invented the following REXX:

/* REXX */
ADDRESS ISREDIT
'MACRO (PARM) NOPROCESS'
'(USRSTATE) = USER_STATE'
'(LRECL) = LRECL'
CHANGES = 0
IF PARM <> ''
THEN DO
  DO WORDNO = 1 TO WORDS(PARM)
    THISWORD = WORD(PARM, WORDNO)
    'FIND "'THISWORD'" FIRST 2 'LRECL
    DO WHILE RC = 0
      'TSPLIT'
      CHANGES = CHANGES + 1
      'FIND "'THISWORD'" NEXT 2 'LRECL
    END
  END
END
'USER_STATE = (USRSTATE)'
IF CHANGES = 0
THEN
  SAY 'NONE OF THE WORDS 'PARM' FOUND'
ELSE
  SAY 'SPLIT ON 'PARM' SUCCESFUL IN 'CHANGES' LINES'
EXIT

If you name this program TXTSPLIT you can execute the command TXTSPLIT FROM WHERE and it will split all records in your EDIT or VIEW session on all occurences of the word FROM and afterwords on the word WHERE. I think this is extremely clever especially when you take into consideration how small the program is.

Take note of the usage of USER_STATE. This is a feature in the EDIT MACRO language that makes it possible to recreate the original data position along with other settings when the EDIT MACRO has done its job. In this macro it is highly recommended to use. If it is not used you will be positioned at the last splitted record which can be very confusing.

Previous tip in english        Forrige danske tip        Tip list