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

need to copy using sort with outrec !


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

Active User


Joined: 19 Mar 2009
Posts: 206
Location: Globe, India

PostPosted: Thu Aug 18, 2011 10:59 pm
Reply with quote

i want to map few fields from input file layout to output file.
I am using SORT card as a copy and OUTREC to map the input fields of customer into output file.
But the problem is my input file layout has 3 types of record:
1. HEADER RECORD
2. actual Customer Details RECORD REDEFINES HEADER
3. TRAILER RECORD REDEFINES HEADER

and output also has similar 3 types
1. HEADER
2. REQUIRED FIELDS OF CUSTOMER REDEFINES HEADER
3. TRAILER REDFINES HEADER

Now the challenge ahead of me is to verify the record in input, If
1. it is HEADER then copy its required fields to output file's HEADER section
2. it is CUSTOMER RECORD then copy only its required fields to output file's CUSTOMER DETAILS
3. it is TRAILER RECORD then copy its required fields to TRAILER part of output file

I have done second task successfully, but without verifying input record.

kindly help me to resolve this issue.

any help is appreciable.
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 Aug 18, 2011 11:37 pm
Reply with quote

You haven't really given enough information for anyone to help you.

Please show an example of the records in your input file (relevant fields only) and what you expect for output. Explain the "rules" for getting from input to output. Give the starting position, length and format of each relevant field. Give the RECFM and LRECL of the input file.

Also, is there something in the header, detail and trailer records that identify them as such (what) e.g. H, D or T in position 1?
Back to top
View user's profile Send private message
rohanthengal

Active User


Joined: 19 Mar 2009
Posts: 206
Location: Globe, India

PostPosted: Fri Aug 19, 2011 10:43 am
Reply with quote

Great Thanks Frank.
In Header and Trailer, there are no tags to distinguish them from cust details record. One good thing is that they have first field as Date.
e.g.
in Input we have:
01 in-data.
03 HEADER.
05 DATE
05 HEADER COUNT
05 FILLER
03 CUST DETAILS REDEFINES HEADER.
05 CUST NAME
05 CUST ID
03 TRAILER REDEFINES HEADER.
05 DATE
05 TRAILER COUNT
05 FILLER

where as in output we have 2 files out of which one key file has below layout:
01 out-data.
03 OUT-HEADER.
05 DATE
05 HEADER COUNT
05 FILLER
03 KEY-CUST DETAILS REDEFINES OUT-HEADER.
05 KEY-CUST-ID
03 OUT-TRAILER REDEFINES OUT-HEADER.
05 DATE
05 TRAILER COUNT
05 FILLER

So i need to validate the input record, if it is header then populate its fields to corresponding output header fields
if it is customer details record then need to populate its only key to given output customer key layout
and in the same way for TRAILER also.

Currently i am able to write the DATACARD only for CUSTOMER DETAILS part as:
SORT=COPY
OUTFIL=SORTOF01 & OUTREC(OP1:IP1,LENGTH1,OP2:IP2,LENGTH2....)
......

but i need to do this after validating record for HEADER / CUSTOMER RECORD / TRAILER, and proceed accordingly.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Aug 19, 2011 10:49 am
Reply with quote

Hello,

What are the rules for validating? What should happen if some of the data does not pass validation.

You mention 2 output files, but only show one.

It would help if you post some sample input (containing both valid and invalid data) and the output(s) you want when the sample input is processed.
Back to top
View user's profile Send private message
rohanthengal

Active User


Joined: 19 Mar 2009
Posts: 206
Location: Globe, India

PostPosted: Fri Aug 19, 2011 11:09 am
Reply with quote

alright and thanks.
lets assume there is TAG field in HEADER as 'H' and in TRAILER as 'T', except this there are no validations rule. icon_sad.gif

Input file sample data:
Code:
18-08-2010     23112C     HDR
STEVE JACKSON   100000CUST
ANGUESS FRASER 100001CUST
18-08-2010     23112C     TLR

in output file number 1, I can expect something like this:
Code:
18-08-2010     23112C    HDR
100000CUST                   --------- > CUST NAME OMITTED in output
100001CUST                   ----------> CUST NAME OMITTED in output
18-08-2010     23112C     TLR
"Code'd"

all the input and output layout field lengths and data types are compatible.

Also we need not bother about the second output file as it is entire different flow.

Also we need not bother about second output file as it is different process.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Aug 19, 2011 11:56 am
Reply with quote

So, you copy the header, which can be identified (most of the time), unchanged.

You copy the trailer, which can be identified (most of the time), unchanged.

You copy the data, which has no indication that it is data, except you hope that your header/trailer indication can never occur at that position. When you copy the data, you drop the client name. Which in your example is variable length, but you have a cobol-like layout (with no PICTURES, USAGE, useful stuff) so probably fixed.

Is that about it?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Aug 19, 2011 12:39 pm
Reply with quote

Hello,

When posting data, jcl code, etc you should always use the Code tag. Your data has been coded for alignment and readability.

It appears that the name field might be fixed. It will make a difference in a solution . . .

Suggest you look for the dashes in the date as well as HDR or TLR to determine if the record is a header, trailer or the unidentifiable data.

I see no validation rules as was requested.
Back to top
View user's profile Send private message
rohanthengal

Active User


Joined: 19 Mar 2009
Posts: 206
Location: Globe, India

PostPosted: Fri Aug 19, 2011 1:42 pm
Reply with quote

Thanks Bill and Dick for your inputs, will take care onwards.
both of you have understood right.

input file is FB i.e. Fixed length record file with all fields of fixed cobol length.

I ahve come across now 1 solution of using:

SORT FIELDS=COPY
OUTFIL FNAMES=SORTOF01, OUTREC IFTHEN=WHEN(CONDITION)
BUILD=(OP:IP,length)

Is it the right way ?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Aug 19, 2011 1:49 pm
Reply with quote

Is "CUST" the indicator for a detail record?

When you are doing the input-to-output, don't do it at field level, do it in chunks. For instance, the entire header/trailer unchanged. If you have "CUST" for the detail records, then you end up with NE, it is header/trailer, otherwise it is detail, pick up everything after the name and stick it in from position 1 of the output.
Back to top
View user's profile Send private message
rohanthengal

Active User


Joined: 19 Mar 2009
Posts: 206
Location: Globe, India

PostPosted: Fri Aug 19, 2011 7:51 pm
Reply with quote

Bill, CUST is not an identifier.
let me give you now exact SAMPLE structure:
Input file layout
Code:
01 INREC.
  03 INHEADER.
     05  INHEADER-FLAG     PIC X(03). VALUE 'HDR'.
     05  INHEADER-DATE     PIC X(10).
  03 INCUSTOMER-DETAILS REDEFINES INHEADER.
     05  INCUST-NAME             PIC X(10).
     05  INCUST-ID                 PIC X(4).
  03 INTRAILER REDEFINES INHEADER.
     05  INTRAILER-FLAG         PIC X(03) VALUE 'TLR'
     05   INTRAILER-COUNT     PIC X(02).


output file layout
Code:
01 OUTREC.
   03 OUTHEADER.
     05  OUTHEADER-DATE      PIC X(10).
   03 OUTCUSTOMER-DETAILS REDFEINES OUTHEADER.
     05  OUTCUST-ID              PIC X(4).
   03 OUTTRAILER REDEFINES OUTHEADER.
     05  OUTTRAILER-COUNT   PIC X(2).


i want to read the input file, after validating them as HEADER / TRAILER / CUSTOMER DETAILS type of record , copy only required fields from these record into the respective section of the output layout like:

IF INPUT RECORD IS HEADER, THEN EXTRACT THE REQUIRED FIELD INTO THE OUTPUT HEADER LAYOUT.

IF RECORD IS TRAILER, THEN EXTRACT THE REQUIRED FIELD INTO THE OUTPUT TRAILER RECORD.

IF RECORD IS NEITHER OF ABOVE TYPE, I.E. CUSTOMER DETAILS, THEN EXTRACT ITS REQUIRED DETAILS INTO THE RESPECTIVE OUTPUT RECORD.
Back to top
View user's profile Send private message
sqlcode1

Active Member


Joined: 08 Apr 2010
Posts: 577
Location: USA

PostPosted: Fri Aug 19, 2011 8:00 pm
Reply with quote

rohanthengal,

See if below helps...
Code:
//STEP0001 EXEC PGM=SORT                                           
//SYSOUT   DD SYSOUT=*                                             
//SORTIN   DD  *                                                   
HDR2011-08-19                                                     
SQLCODE1  1111                                                     
SQLCODE2  2222                                                     
SQLCODE3  3333                                                     
TRL03                                                             
//SORTOUT  DD SYSOUT=*                                             
//SYSIN    DD *                                                   
 OPTION COPY                                                       
 INREC IFOUTLEN=14,IFTHEN=(WHEN=(1,3,CH,EQ,C'HDR'),BUILD=(04,10)),
                   IFTHEN=(WHEN=(1,3,CH,EQ,C'TRL'),BUILD=(04,02)),
                   IFTHEN=(WHEN=NONE,BUILD=(11,4))                 
/*                 

OUTPUT (14/FB)
Code:
2011-08-19
1111       
2222       
3333       
03         


I am sure this typo but still FYI... 05 INHEADER-FLAG PIC X(03). VALUE 'HDR'. is not valid. You will get compile error since it has 2 periods.
Thanks,
Back to top
View user's profile Send private message
rohanthengal

Active User


Joined: 19 Mar 2009
Posts: 206
Location: Globe, India

PostPosted: Fri Aug 19, 2011 8:13 pm
Reply with quote

I have got the solution

STEP 1:
----------
1. used SORT utility as COPY
2. copy only HDR record into first TEMP dataset using INCLUDE condition and formatting using OUTREC
3. copy all the records from input file, except HDR and TLR, into second TEMP dataset using OMIT condition and formatting using OUTREC
4. copy only TLR record into third TEMP dataset and formatting using formatting

STEP 2:
----------
1. once again use SORT utility as COPY
2. CONCATENATE all three TEMP datasets in the same order in which they were created in STEP 1, and use them in SORTIN
3. and FINAL OUPUT file in SORTOUT

I am not convinced with the above solution as it is expensive as per my requirement. Please open other ways.

Above solution increases the size of my PROC as the same input file will produce 2 different output files. If i carry the above solution for the second output file also then there will be again 3 more temporary datasets and different sort card which is not allowed in my shop.

icon_sad.gif
Back to top
View user's profile Send private message
sqlcode1

Active Member


Joined: 08 Apr 2010
Posts: 577
Location: USA

PostPosted: Fri Aug 19, 2011 8:18 pm
Reply with quote

rohanthengal wrote:
I am not convinced with the above solution as it is expensive as per my requirement. Please open other ways.

Above solution increases the size of my PROC as the same input file will produce 2 different output files. If i carry the above solution for the second output file also then there will be again 3 more temporary datasets and different sort card which is not allowed in my shop.

icon_sad.gif


Did you try the sort card, I provided above?

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

Active User


Joined: 19 Mar 2009
Posts: 206
Location: Globe, India

PostPosted: Fri Aug 19, 2011 8:19 pm
Reply with quote

sqlcode 1, thanks dear.. ya it was typo error..!!
I think your solution will help me.

this forum helped me a lot from begining time, thanks a lot to all moderators and kings of mainframes !!

kudos..salute..!
Back to top
View user's profile Send private message
rohanthengal

Active User


Joined: 19 Mar 2009
Posts: 206
Location: Globe, India

PostPosted: Fri Aug 19, 2011 8:22 pm
Reply with quote

will try tomorrow and get back to you friend for sure !
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Aug 19, 2011 8:25 pm
Reply with quote

Hello,

Quote:
ya it was typo error..!!
If you copy/paste rather than re-keying, the chance of a typo goes away. . .

Validate typically means the data needs to be checked for some kind of error(s).
Back to top
View user's profile Send private message
sqlcode1

Active Member


Joined: 08 Apr 2010
Posts: 577
Location: USA

PostPosted: Fri Aug 19, 2011 8:28 pm
Reply with quote

rohanthengal wrote:
sqlcode 1, thanks dear.. ya it was typo error..!!
I think your solution will help me.

this forum helped me a lot from begining time, thanks a lot to all moderators and kings of mainframes !!

kudos..salute..!

Same here icon_smile.gif

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

Active User


Joined: 19 Mar 2009
Posts: 206
Location: Globe, India

PostPosted: Fri Aug 19, 2011 9:02 pm
Reply with quote

thanks sqlcode1.
in continuation with the above script if i need few more enhancements like extracting more than one field for a particular record and setting output trailer FILLER field to SPACES then
can i continue in the same way of above suggested solution ?

FEW FIELDS HAVE BEEN ADDED IN THE SCRIPT AS BELOW:

Input file layout
Code:
01 INREC.
  03 INHEADER.
     05  INHEADER-FLAG         PIC X(03) VALUE 'HDR'.
     05  INHEADER-DATE        PIC X(10).
     05  INHEADER-COUNT      PIC X(2).
  03 INCUSTOMER-DETAILS REDEFINES INHEADER.
     05  INCUST-NAME             PIC X(10).
     05  INCUST-ID                 PIC X(4).
     05  INCUST-BALANCE       PIC 9(5). 
  03 INTRAILER REDEFINES INHEADER.
     05  INTRAILER-FLAG         PIC X(03) VALUE 'TLR'
     05   INTRAILER-COUNT     PIC X(02).


output file layout
Code:
01 OUTREC.
   03 OUTHEADER.
     05  OUTHEADER-DATE      PIC X(10).
     05  OUTHEADER-COUNT    PIC X(2). 
   03 OUTCUSTOMER-DETAILS REDFEINES OUTHEADER.
     05  OUTCUST-ID              PIC X(4).
     05  OUTCUST-BALANCE    PIC 9(5).
  03 OUTTRAILER REDEFINES OUTHEADER.
     05  OUTTRAILER-COUNT   PIC X(2).
     05  OUTTRAILER-FILLER    PIC X(8).
Back to top
View user's profile Send private message
sqlcode1

Active Member


Joined: 08 Apr 2010
Posts: 577
Location: USA

PostPosted: Fri Aug 19, 2011 9:24 pm
Reply with quote

rohanthengal,
Quote:
in continuation with the above script if i need few more enhancements like extracting more than one field for a particular record...

Yes, you can use the same method used in SORTCARD to extract more fields if needed, you just need to select respective fields in build and adjust IFOUTLEN=n where n is LRECL for the output file. In my original card, I used IFOUTLEN=14, so that if needed, you could add INCUST-NAME later.
Quote:
... and setting output trailer FILLER field to SPACES then
IFOUTLEN takes care of initializing remaining bytes with spaces,so no need for extra code.

For the field that you have added use something like below (untested)...
Code:
//SYSIN    DD *                                                   
 OPTION COPY                                                       
 INREC IFOUTLEN=12,IFTHEN=(WHEN=(1,3,CH,EQ,C'HDR'),BUILD=(04,12)), --> (04,12 is to select INHEADER-DATE & INHEADER-COUNT from header)
                   IFTHEN=(WHEN=(1,3,CH,EQ,C'TRL'),BUILD=(04,02)), --> select INTRAILER-COUNT and no need to select filler for spaces.
                   IFTHEN=(WHEN=NONE,BUILD=(11,9))                 --> 11,9 to select INCUST-ID & INCUST-BALANCE.
/*

Read about INREC here
Thanks,
Back to top
View user's profile Send private message
rohanthengal

Active User


Joined: 19 Mar 2009
Posts: 206
Location: Globe, India

PostPosted: Fri Aug 19, 2011 9:41 pm
Reply with quote

Excellent and really appreciable help sqlcode 1. Many Many Thanks !

Now came across last junction, what in case if i want to map the fields in input record which are discontinuos in nature ?

In above example, all the fields in input record are continuos in nature !

e.g.
out of CUST-NAME, CUST-ID, CUST-BAL,i need only last two consecutive fields, so no problem. BUT
What would have been, if i want to copy only first and third field i.e. CUST-NAME and CUST-BAL in the output layout ?

can i use BUILD=(S1,L1),(S2,L2) ?
where S1 and S2 are the starting positions of two fields respectively
and L1,L2 are their respective lengths
Back to top
View user's profile Send private message
sqlcode1

Active Member


Joined: 08 Apr 2010
Posts: 577
Location: USA

PostPosted: Fri Aug 19, 2011 9:47 pm
Reply with quote

rohanthengal wrote:
can i use BUILD=(S1,L1),(S2,L2) ?
where S1 and S2 are the starting positions of two fields respectively
and L1,L2 are their respective lengths
Yes, but you don't need separate bracket for each field, according to your understanding, something like this BUILD=(S1,L1,S2,L2)

Did you went through the link to manual at the end of my previous post?

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

Active User


Joined: 19 Mar 2009
Posts: 206
Location: Globe, India

PostPosted: Fri Aug 19, 2011 10:07 pm
Reply with quote

yessssss..... thanks buddy

the manual link provided by you has a very important guidance, have saved the link to be used in future before i post the doubt !

again thanks to our ibmmainframes and team !
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 JCL sort card - get first day and las... JCL & VSAM 9
No new posts VB to VB copy - Full length reached SYNCSORT 8
No new posts Sort First/last record of a subset th... DFSORT/ICETOOL 7
No new posts how to calculate SUM value for VB fil... DFSORT/ICETOOL 1
Search our Forums:

Back to Top