MainframeSupports
tip week 37/2011:

Many years ago I wrote a tip about how to use line commands in your own EDIT macros. Maybe you have been looking in vain for a tip on how to process the data in the line or lines marked by your line command. Well, here it comes.

The following EDIT macro compares data in two different columns (parameters FRSTCOL and LASTCOL) using the width specified in parameter COLW. If the two columns are equal the line is EXCLUDED. After execution of the EDIT macro the lines in the area marked by the line command * which has not been EXCLUDED will have different values in the two columns. If no line command has been specified the EDIT macro will scan through all lines in the data:

/* REXX */ ADDRESS ISREDIT
'MACRO (FRSTCOL LASTCOL COLW) NOPROCESS'
ADDRESS ISPEXEC "CONTROL ERRORS RETURN"
'PROCESS RANGE *'
IF RC = 0 ! RC = 4
THEN DO
  '(RGHTBND) = LRECL'
  IF ^DATATYPE(FRSTCOL, 'W')
  THEN
    FRSTCOL = 1
  IF ^DATATYPE(COLW, 'W')
  THEN
    COLW = 1
  ELSE
    IF COLW > RGHTBND
    THEN
      COLW = RGHTBND
  IF ^DATATYPE(LASTCOL, 'W')
  THEN
    LASTCOL = RGHTBND - COLW + 1
  ELSE
    IF LASTCOL > RGHTBND - COLW + 1
    THEN
      LASTCOL = RGHTBND - COLW + 1
  '(THISLINE) = LINENUM .ZFRANGE'
  '(LASTLINE) = LINENUM .ZLRANGE'
  FRSTLINE = THISLINE
  DO WHILE THISLINE <= LASTLINE
    '(NEWLINE) = LINE 'THISLINE
    IF SUBSTR(NEWLINE, FRSTCOL,COLW) == SUBSTR(NEWLINE, LASTCOL,COLW)
    THEN
      'XSTATUS 'THISLINE' = X'
    THISLINE = THISLINE + 1
  END
END
EXIT

If you give the EDIT macro the name COMPCOL then the command COMPCOL 1 5 2 executed when the above REXX is in the data area will exclude all lines having an indentation of six spaces. Please note that instead of reporting errors when parameters are missing or wrong the REXX uses default values instead.

The important processing of the data in the EDIT session is coded in the DO WHILE loop and starts with the first line in the marked area and ends with the last line in the marked area. The number of the starting line is fetched using LINENUM .ZFRANGE and the ending line number is fetched using LINENUM .ZLRANGE. If a line command is not specified then the default of .ZFRANGE is the first line number in data and .ZLRANGE contains the last line number. The actual contens of each line is fetched using (rexxVarName = LINE lineno. Now it is up to you, your needs and your fantasy to determine how the fetched data should be processed. As I have stated before this example compares two columns and marks the result for each line by excluding some and leave other untouched. Depending on what you want to acheive, you can use other means to display the result of your processing.

Previous tip in english        Forrige danske tip        Tip list