Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Inserting a new record using DFSORT

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
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    Post subject: Inserting a new record using DFSORT
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: 578
Location: USA

PostPosted: Thu Sep 23, 2010 7:34 pm    Post subject: Re: Inserting a new record using DFSORT
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 Moderator


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

PostPosted: Thu Sep 23, 2010 10:07 pm    Post subject:
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    Post subject:
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: 578
Location: USA

PostPosted: Sat Sep 25, 2010 2:38 am    Post subject:
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 Moderator


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

PostPosted: Sat Sep 25, 2010 3:14 am    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Record Not found in AlX but record re... mukun264 COBOL Programming 7 Fri Mar 24, 2017 9:28 am
No new posts Count the length of the record & ... sreekusr DFSORT/ICETOOL 4 Thu Mar 23, 2017 7:52 pm
No new posts IMS DB-How to update a record (a sing... Nic Clouston IMS DB/DC 9 Thu Mar 09, 2017 4:38 pm
No new posts DFSORT MUL FIELDS tspr52 DFSORT/ICETOOL 16 Fri Mar 03, 2017 11:53 pm
No new posts Inserting records based on conditions vickey_dw DFSORT/ICETOOL 9 Wed Feb 22, 2017 1:33 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us