IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Inserting a new record using DFSORT


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Majid Hussain

New User


Joined: 18 Aug 2007
Posts: 20
Location: Bangalore

PostPosted: Thu Sep 23, 2010 4:24 pm
Reply with quote

Hi

I have the following data available in a file.

ABCD 0001
BCDE 0002
CDEF 0002

I am checking the column 1-4, if it matches with a certain value, the field from column 6-9 should increase by 1. I am able to do that but if the value doesnt matches, a new record should be inserted.
Suppose the string to be matched is VWXY, then the output should be something like this.

ABCD 0001
BCDE 0002
CDEF 0002
VWXY 0001

Can this be done using DFSORT?
Back to top
View user's profile Send private message
sqlcode1

Active Member


Joined: 08 Apr 2010
Posts: 577
Location: USA

PostPosted: Thu Sep 23, 2010 7:34 pm
Reply with quote

Majid Hussain wrote:
Hi

I have the following data available in a file.

ABCD 0001
BCDE 0002
CDEF 0002

I am checking the column 1-4, if it matches with a certain value, the field from column 6-9 should increase by 1. I am able to do that but if the value doesnt matches, a new record should be inserted.
Suppose the string to be matched is VWXY, then the output should be something like this.

ABCD 0001
BCDE 0002
CDEF 0002
VWXY 0001

Can this be done using DFSORT?

How are you getting certain value? Are they coming from different file?

Thanks,
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Thu Sep 23, 2010 10:07 pm
Reply with quote

Majid,

Will you only be checking for one value each time you run the job? Can the value be hardcoded? Or does it come from another file or a parameter or what?

If the value is found in a record, you want to increment the amount in the record in which the value is found. Is that correct? Can the value be present in more than one record?

If the value is not found in any record, you want to add a new record with that value and a count of 1. Is that correct? Where do you want to add it - at the end? in sorted order? Or what?

What is the RECFM and LRECL of the input file?
Back to top
View user's profile Send private message
Majid Hussain

New User


Joined: 18 Aug 2007
Posts: 20
Location: Bangalore

PostPosted: Fri Sep 24, 2010 4:26 pm
Reply with quote

Thanks guys for your responses.

The 'certain value' is actually the job name which I am getting from the JOBNAME parameter. So the first 4 column can be considered as the Job Names and will be unique i.e. one value would not be present in more than one record.

The idea is to be able to use the step in different jobs and maintain a record of sequence IDs for the reports generated in those jobs. Sequence ID is to be increased by 1 everytime the job runs.

Frank, your understanding is correct. The record can be added anywhere, row number does not matter for the new record.

The input file is RECFM=FB, LRECL=80.
Back to top
View user's profile Send private message
sqlcode1

Active Member


Joined: 08 Apr 2010
Posts: 577
Location: USA

PostPosted: Sat Sep 25, 2010 2:38 am
Reply with quote

Majid Hussain,
Quote:
The 'certain value' is actually the job name which I am getting from the JOBNAME parameter.
This may be a dumb question to ask but what is JOBNAME parameter? Are you talking about JCL or DFSort Parm?

See if below job works for you... Here I am providing JOB name through SYMNAME but you may/can replace with JOBNAME parameter if that works for you. I ran this job with 2 inputs for match and unmatch conditions. Both the outputs are provided.
Code:
//STEP01   EXEC PGM=SORT                                               
//SYSOUT   DD SYSOUT=*                                                 
//SORTIN   DD *                                                       
ABCD 0001                                                             
BCDE 0001                                                             
CDEF 0001                                                             
/*                                                                     
//SORTOUT  DD SYSOUT=*                                                 
//SYMNAMES DD *                                                       
JOBNAME,'ABCD'     --> YOUR JOB NAME GOES HERE...                     
//SYSIN    DD *                                                       
 INREC IFTHEN=(WHEN=INIT,OVERLAY=(11:SEQNUM,4,ZD)),                   
       IFTHEN=(WHEN=(1,4,CH,EQ,JOBNAME),OVERLAY=(15:C'Y'))             
 SORT FIELDS=(15,1,CH,D,11,4,ZD,A)                                     
 OUTREC IFTHEN=(WHEN=(15,1,CH,EQ,C'Y'),                               
                OVERLAY=(6:6,4,ZD,ADD,+1,TO=ZD,LENGTH=4)),             
        IFTHEN=(WHEN=(15,1,CH,EQ,C' ',AND,11,4,ZD,EQ,1),               
                OVERLAY=(16:C'Y'))                                     
 OUTFIL IFTHEN=(WHEN=(16,1,CH,EQ,C'Y'),BUILD=(1,9,/,                   
                                              JOBNAME,1X,SEQNUM,4,ZD)),
        IFTHEN=(WHEN=NONE,BUILD=(1,9))                                 
//*                                                                   

OUTPUT
Code:
ABCD 0002
BCDE 0001
CDEF 0001


When Symname changed to JOBNAME,'WXYZ', will produced below output...
Code:
ABCD 0001
WXYZ 0001
BCDE 0001
CDEF 0001


Thanks,
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Sat Sep 25, 2010 3:14 am
Reply with quote

Majid,

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

Code:

//S1 EXEC PGM=SORT                                           
//SYSOUT DD SYSOUT=*                                         
//JOBNAME DD *                                               
BCDE                                                         
//DATA DD *                                                 
ABCD 0001                                                   
BCDE 0002                                                   
CDEF 0002                                                   
//SORTOUT DD SYSOUT=*                                       
//SYSIN DD *                                                 
  JOINKEYS F1=JOBNAME,FIELDS=(1,4,A),SORTED                 
  JOINKEYS F2=DATA,FIELDS=(1,4,A)                           
  JOIN UNPAIRED,F1,F2                                       
  REFORMAT FIELDS=(F2:1,9,F1:1,4,?)                         
  OPTION COPY                                               
  INREC IFTHEN=(WHEN=(14,1,CH,EQ,C'B'),                     
    OVERLAY=(6:6,4,ZD,ADD,+1,EDIT=(TTTT))),                 
   IFTHEN=(WHEN=(14,1,CH,EQ,C'1'),                           
    BUILD=(1:10,4,X,C'0001'))                               
  OUTREC BUILD=(1,9,80:X)                                   
/*
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 3
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
Search our Forums:

Back to Top