Variable length field from a file using SORT

In this Mainframe Forum - You can post your queries on DFSORT, ICETOOL , SyncSort & JCL Utilities

Moderators: Frank Yaeger, Moderator Group

subasu
Member
Posts: 12
Joined: Tue Mar 24, 2009 1:12 pm

Variable length field from a file using SORT

Post by subasu » Tue Mar 24, 2009 1:21 pm

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 the in screenshot, the value 29 could be 329 or 2329 or 899033. There is no limit to the number.

"Loaded 29 rows into the database"

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

Post by Natarajan » Tue Mar 24, 2009 2:25 pm

is it delimited file?. example shown below.

12,343435,343527664
Natarajan
Chennai

subasu
Member
Posts: 12
Joined: Tue Mar 24, 2009 1:12 pm

Post by subasu » Tue Mar 24, 2009 2:29 pm

It is a dataset... which has a number of records... one of its lines contains information on the number of rows loaded to a system.... I need this count... its a numeric field and has variable length.

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

Post by Natarajan » Tue Mar 24, 2009 2:32 pm

In that case.. There should be a standard string like 'NO OF RECORDS LOADED'
do you have this kind of string in that line along with your numeric field.
Natarajan
Chennai

subasu
Member
Posts: 12
Joined: Tue Mar 24, 2009 1:12 pm

Post by subasu » Tue Mar 24, 2009 2:34 pm

The specific line only has the below details:

"Loaded 47 rows into the database" ... this value 47 could be of variable length... it can be 7 or 47 or 847 or 9847 and so on....

User avatar
dbzTHEdinosauer
Moderator
Posts: 981
Joined: Mon Oct 02, 2006 8:31 pm

Post by dbzTHEdinosauer » Tue Mar 24, 2009 3:15 pm

if the word 'Loaded ' in position 1 of a record, only in 1 record of the file?

is it, perchance, always the first or last record?
how many records could there be in this file?
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.

subasu
Member
Posts: 12
Joined: Tue Mar 24, 2009 1:12 pm

Post by subasu » Tue Mar 24, 2009 3:21 pm

There is only 1 line in the dataset where the word "Loaded " is present begining from the 1st position... the one which I require. This is neither the first or last record. There will be only 1 such record in the file.

User avatar
dbzTHEdinosauer
Moderator
Posts: 981
Joined: Mon Oct 02, 2006 8:31 pm

Post by dbzTHEdinosauer » Tue Mar 24, 2009 3:37 pm

other than not knowing the dcb attributes of the file,
we only need to know
I need to pick up a numeric value from a variable length field from a file
what do you want to do with the numeric value?
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.

subasu
Member
Posts: 12
Joined: Tue Mar 24, 2009 1:12 pm

Post by subasu » Tue Mar 24, 2009 3:39 pm

I need this numeric value and replace this value in another file.

User avatar
dbzTHEdinosauer
Moderator
Posts: 981
Joined: Mon Oct 02, 2006 8:31 pm

Post by dbzTHEdinosauer » Tue Mar 24, 2009 4:01 pm

I need this numeric value and replace this value in another file.
as I am off today, I don't mind this silliness, too much.

'replace'?

where, what? what are the dcb attributes of this 'other file'? (actually both files!)
what position do you want overlayed with this extract numeric value?

why don't you have the originator of the file containing the 'LOADED' also do this replacement?
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

DFSPRT INCLUDE OUTREC FINDREP INOUT

Post by Natarajan » Tue Mar 24, 2009 4:31 pm

Please check this sort card... i did not tested this card..

Code: Select all

//SYSIN    DD * 
    SORT FIELDS=COPY 
     INCLUDE COND=(1,6,CH,EQ,C'Loaded')
     OUTREC FINDREP=(INOUT=(C'LOADED',C'',C'rows into the database',C''))
/* 

It will place required record into output file. by replacing the string
with spaces.

Input file
asdfdssfsfsdf
Loaded 47 rows into the database
asdfsfdssadf


Output file
47
Natarajan
Chennai

User avatar
Frank Yaeger
Moderator
Posts: 812
Joined: Sat Feb 18, 2006 5:45 am
Location: San Jose, CA
Contact:

Post by Frank Yaeger » Tue Mar 24, 2009 8:41 pm

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.

Code: Select all

//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 (which isn't clear).
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort

subasu
Member
Posts: 12
Joined: Tue Mar 24, 2009 1:12 pm

Post by subasu » Wed Mar 25, 2009 11:43 am

Thanks for your promt replies.... probably I should have stated my requirements more clearly for everyone's understnading...

One file of FB/133 has the line which details the record count.... this count has to be picked up and replaced in another file FB/80.

Input FIle: FB-133
.......
.........
Loaded 29 rows into the database
....
....

O/P file:
FILEID001 0000000

This 7 digit value of 0000000 has to be replaced from the count in the input file.

dbzTHEdinosauer - Sorry for not making the requirements clear. I hope now you have a clearer understanding.

Natarajan - The INREC record was giving an error

Frank - You are the champ... it worked!!!! I need to replace this value in another file, which contains only 1 record, in the first line from the position 11 to 17 in the output file.

User avatar
Frank Yaeger
Moderator
Posts: 812
Joined: Sat Feb 18, 2006 5:45 am
Location: San Jose, CA
Contact:

Post by Frank Yaeger » Wed Mar 25, 2009 9:28 pm

subasu,

Here's a DFSORT job that will do what you asked for:

Code: Select all

//S1    EXEC  PGM=SORT
//SYSOUT    DD  SYSOUT=*
//SORTIN DD DSN=...  input file1 (FB/133)
//SORTOUT DD DSN=&&S1,UNIT=SYSDA,SPACE=(TRK,(1,1)),DISP=(,PASS)
//SYSIN    DD    *
  OPTION COPY
  INCLUDE COND=(1,6,CH,EQ,C'Loaded')
  INREC PARSE=(%01=(ABSPOS=8,ENDBEFR=C' ',FIXLEN=7)),
    BUILD=(C'NEWCT,''',%01,UFF,M11,LENGTH=7,C'''',80:X)
/*
//S2    EXEC  PGM=SORT
//SYSOUT    DD  SYSOUT=*
//SYMNAMES DD DSN=&&S1,DISP=(OLD,PASS)
//SORTIN DD DSN=... input file2 (FB/80)
FILEID001 0000000
/*
//SORTOUT DD DSN=...  output file (FB/80)
//SYSIN    DD    *
  OPTION COPY
  INREC OVERLAY=(11:NEWCT)
/*
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort

subasu
Member
Posts: 12
Joined: Tue Mar 24, 2009 1:12 pm

Post by subasu » Thu Mar 26, 2009 11:54 am

Thanks Frank... it worked.

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others