Page 1 of 1

Variable length field from a file using SORT

PostPosted: Tue Mar 24, 2009 3:21 pm
by subasu
I have a requirement where I need to pick up a numeric value from a variable length field from a file. Is this possible using DFSORT? Like in the screenshot, the value 29 could be 329 or 2329 or 899033. There is no limit to the number.

"Loaded 29 rows into the database". This is the only line in the dataset where the count is present.

Re: Variable length field from a file using SORT

PostPosted: Tue Mar 24, 2009 9:26 pm
by Frank Yaeger
subasu,

You can use a DFSORT job like the following to write a record with the extracted number as 10 digits with leading zeros. I assumed your largest number is 10 digits but you can change that if appropriate.

//S1    EXEC  PGM=SORT                                       
//SYSOUT    DD  SYSOUT=*                                     
//SORTIN DD *                                               
... record                                                   
... record                                                   
Loaded 29123 rows into the database                         
... record                                                   
... record                                                   
//SORTOUT DD DSN=...  output file (FB/80)                                       
//SYSIN    DD    *                                           
  OPTION COPY                                               
  INCLUDE COND=(1,6,CH,EQ,C'Loaded')                         
  INREC PARSE=(%01=(ABSPOS=8,ENDBEFR=C' ',FIXLEN=10)),       
    BUILD=(%01,UFF,M11,LENGTH=10,80:X)                       
/*


For the example give, SORTOUT would have:

0000029123

For an input record of:

Loaded 29 rows into the database

SORTOUT would have:

0000000029

and so on.

You can change this job appropriately for what you want to do.