I would like to use DFSORT to find the last occurrence of a particular delimiter ("\") within a record, throw everything away prior to that point in the record, and PARSE only the remainder of the record. The remainder needs to be parsed based on a different delimiter ("-"). The number of occurrences of the first delimiter are unpredictable. For example:
These would be VB records, max LRECL 255. I do not know how many backslashes will appear prior to the last one; it may vary from record to record. If necessary, we could assume a maximum number of backslashes; say, 10. The number of hyphens is fixed at 4 in each record, and I would parse each subfield into its own fixed-length parsed variable.
I think I know how to do PARSE once I get past the last backslash; what I can't figure out is how to get that far (i.e. how to ignore everything up to the last backslash when I don't know how many backslashes there will be). Is this doable in DFSORT?
I do have an issue remaining, however. In my original example data, the fields to the right of the backslash are all numeric. In reality, the data will be alphanumeric; I'm sorry that my examples led you to assume otherwise.
When I subsitute alpha characters in place of the numbers, the first extracted field is incorrect using your solution (unless the number of characters is exactly four). Can your code be generalized to handle any alphanumeric characters (other than the delimiter characters, of course)?
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
David Eisenberg wrote:
Skolusu,
Thank you very much for this solution!
I do have an issue remaining, however. In my original example data, the fields to the right of the backslash are all numeric. In reality, the data will be alphanumeric; I'm sorry that my examples led you to assume otherwise.
When I subsitute alpha characters in place of the numbers, the first extracted field is incorrect using your solution (unless the number of characters is exactly four). Can your code be generalized to handle any alphanumeric characters (other than the delimiter characters, of course)?
Thank you,
David
Use the following DFSORT control cards. You just need to change the second IFTHEN to have another parse.