Home SELCOPY CBLVCAT SELCOPY/i Trial/Prices CBL SiteMap
 
Multiple Information Retrieval, Manipulation & Update for IBM Mainframe, iSeries, UNIX & PC Platforms

SELCOPY Examples Menu

The following job illustrates use of EXPAND and COMPRESS for CSV data.

Input CSV records are read into position 1 of the workarea and expanded so that all comma separated fields are copied to contiguous, fixed 30 byte fields beginning at position 201.

The expanded fields are printed (datawidth 30) before being re-compressed into a CSV format where hash (#) is used to delimit fields (instead of comma) and all non-numeric fields are enclosed in apostrophes (').

* Expand/Compress CSV example.
*
* Note: The LRECL value is automatically updated to be the length of the
*       expanded or compressed data following an EXPAND or COMPRESS operation.
*       Hence, PRINT FROM x, requires no length. (Prints LRECL bytes by default).
*

  opt worklen=2222   pagedepth=99999  datawidth=30

  read CARD   fill

  if incount > 1
    then print "------------------------------"
    then space 3

  print        "*** --------------------------"
  print  from   1                   * The original (compressed) CSV data.
  space 1

* Expand to fixed length 30 byte fields.
* Note that each comma separated source field must be <= 30 bytes.

  expand    Lrecl at   1    to    600 at 201    dlm=','   enc='"'       flen 30

  print  from 201                   * The expanded CSV data.
  space 1

* Re-Compress using "#" to delimit fields (instead of commas) and enclose all
* non-numeric fields in single quotes.

  compress  600   at 201    to    200 at 801    dlm='#'   enc="'"  str  flen 30

  print  from 801                   * The re-compressed CSV data.

end
10010001,Mrs,Gaye,Sample,0,Mrs Sample,"""Uppingdene House""",Barham,,,,CANTERBURY,Kent,CT4 6QD,United Kingdom,C
10010002,Mr,Edward,McSample,10,Mr Edward S McSample,23 Sycamore Drive,,,,,AYLESFORD,Kent,ME20 7LB,United Kingdom,C
10010003,Ms,Lisa,Sample,"""""",Ms Lisa Sample,14 St. Stephen's Road,,,,,CANTERBURY,Kent,CT2 7HT,United Kingdom,C
10010004,Mrs,Glynis,O'Sample,',Mrs O'Sample,"Railway Cottage, Sandilands",Chipstead,,,,SEVENOAKS,Kent,TN13 2SP,United Kingdom,C
10010005,Mrs,Patricia,Sample,,Mrs Sample,Barbican House,St. Stephen's Way,,,,FOLKESTONE,Kent,CT20 3RD,United Kingdom,C
10010006,Mrs,Jennifer,Sample,,Mrs Sample,2 Court Cottages,Flete Road,Manston,,,MARGATE,Kent,CT9 4LP,United Kingdom,C02
10010007,Mrs,Elizabeth,Sample,,Mrs Sample,5 Hever Place,,,,,CANTERBURY,Kent,,United Kingdom,C
10010008,Mr,Christopher,Sample,,Mr Christopher J Sample,12 Croft Way,,,,,SEVENOAKS,Kent,TN13 2JX,United Kingdom,C
10010009,Mrs,Adriana,Sample-Sample,,Mrs Sample-Sample,19 Westway,Pembury,,,,TUNBRIDGE WELLS,,TN2 7EX,United Kingdom,C
10010010,Mrs,Sally,Sample,xxx,Mrs Sample,Woodstock',Pelham Gardens,xxx,xxx,xxx,FOLKESTONE,xxx,CT20 2LF,United Kingdom,C
10010011,Mrs,Susan,Sample,,Mrs Sample,Colleton House,101 North Road,,,,,Kent,CT21 4AS,United Kingdom,C
Top © 2005 Compute (Bridgend) Limited
http://www.cbl.com/selcex17.html
2009/06/15 12:04:13