Copying records with segmented data templates

Previous releases of File Manager that copied data with a segmented template, desegmented the output file. This behaviour has been changed so segmented data can be copied, and the record segment relationships, or physical record structures, are maintained. This means you can:

  • Selectively copy records from a segmented data set using an input template with selection criteria.
  • Use an input and output template to reformat segmented data. This includes the ability to scramble output. Note that the output segment lengths will be determined by the output template, and input segments will be padded or truncated during reformatting. To ensure you do not get unexpected results, make sure you do not have length errors when mapping input segments.
  • Use a procedure to drop or insert segments within a physical record. Procedure processing sees the input data one segment at a time. Coding a RETURN 'DROP' will remove that segment from the current output record. Coding a WRITE() statement inserts a segment on the current output record. Coding a RETURN 'STOP' will only write out the current physical record if the segment being processed is the last segment on that physical record, otherwise it behaves like a RETURN 'STOP IMMEDIATE' where the current physical record being processed is not written. See given examples:
Example 1.
Insert a new segment in the output record.

Consider the following input segmented record:

AsegBsegCsegDseg
is mapped by a segmented template with 5 layouts mapping segments A to E:
$$FILEM DSC ,
$$FILEM TCIN=MYSEG.TEMPLATE(SEGTP),,
$$FILEM PROC=*
IF FLD(1,1) = 'D' THEN DO              /* found a Dseg */
  WRITE()                              /* Write out current segment */
  OVLY_OUT('E',1)                      /* Create 'Eseg' in output area */
END                                    /* normal return writes Eseg  */
After running the above procedure, the output record would be
AsegBsegCsegDsegEseg.
Example 2.
Delete a segment in the output record.

Consider the following input segmented record:

AsegBsegCsegDseg
$$FILEM DSC ,
$$FILEM TCIN=MYSEG.TEMPLATE(SEGTP),,
$$FILEM PROC=*
IF FLD(1,1) = 'C' THEN                  /* found a Cseg */
  Return 'DROP'                         /* drop this segment */
After running the above procedure the output record would be
AsegBsegDseg 
Example 3.
Desegment a segmented file.
//DDIN     DD DISP=SHR,DSN=MYSEG.DATA
//DDOUT    DD DUMMY
//DDDESEG  DD DISP=SHR,DSN=MYDESEG.DATA
//SYSIN    DD *
$$FILEM DSC ,
$$FILEM TCIN=MYSEG.TEMPLATE(SEGTP),
$$FILEM PROC=*
WRITE(DDDESEG)   /* Write segment out as physical record */
RETURN 'DROP'    /* don't copy any data */
/*

Related topics