Adding Record Numbers to a Self-Describing File

By Hans Hendriks, Robelle Technical Support

Jim Walker, consultant, asked the following about Suprtool:

"I need the record number as part of my data file...I also need an SD file or a file that is identical to the dataset (i.e., in =) so I can do some more work with the file...however, I am lazy and do not want to re-define all the fields in the dataset when I read the file back in after using the NUM,DATA option.

When processing through the dataset, do I have access to the record number field? If so, how can I access it...extract it...and still use the ,LINK option on my output statement?"

click for more info on Hans

Here's is my response:

No, there's no way to reference the record number while reading a dataset. And of course adding the NUM option to output means that the output file is no longer identical to the input one. But I see your point, Suprtool should be able to add a field in the SD file description, and I'll log this as an enhancement request.

Meanwhile, here's a workaround:

- Pass 1 builds an SD file of the correct structure:

  > get dataset
  > define recnum,1,4,integer,
  > extract recnum,field1 / fieldlast
  > output foo,link
  > numrecs 1      {only read/write 1 record}
  > :comment  but leave the free space in the file
  > set squeeze off
  > x

-Pass 2 populates the file with records (including the record number):

  > get dataset
  > out foo,num,data,erase
  > x

This will give you an SD file that recognizes the record number and the data fields.....