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

Split a record into two records


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

Active User


Joined: 01 Feb 2007
Posts: 123
Location: Hyderabad

PostPosted: Sat May 17, 2008 1:15 pm
Reply with quote

Hi,

I want to split a single record into two records. I will explain you clearly with an example.

Input file is FB and LRECL is 80

My input will be as follows which is sorted on SEQ_ID and TRAN_ID:
Code:

SEQ_ID AMOUNT TRAN_ID PRI_CUS SEC_CUS   
SEQ11  10000  T10001  2000011 3000221   
SEQ32  3000   T30021  2011000 1800111   
SEQ45  23400  T43000  2001000           


For the first record the prim cust number is less than sec cust. So the prim cust record should come first and then sec cust.

For the second record the prim cust number is greater than sec customer. So the sec cust record should come first and then prim cust.

For the third record as no sec cust number is there only the prim cust should be written.

Always the prim cust will have value.

My output file will be as follows which is FB and LRECL is 60:
Code:

SEQ_ID AMOUNT TRAN_ID CUST_ID
SEQ11  10000  T10001  2000011
SEQ11  10000  T10001  3000221
SEQ32  3000   T30021  1800111
SEQ32  3000   T30021  2011000
SEQ45  23400  T43000  2001000


How this can be done.
Back to top
View user's profile Send private message
Ajay Baghel

Active User


Joined: 25 Apr 2007
Posts: 206
Location: Bangalore

PostPosted: Sat May 17, 2008 8:26 pm
Reply with quote

Assuming each of your fields to be of length 5 and no spaces in between these 5 FIELDS (SEQ_ID, AMOUNT, TRAN_ID, PRI_CUS and SEC_CUS )
You can customize below jcl to include spaces between these fields.

Code:
//STEP1 EXEC PGM=SORT
//SORTIN    DD  DSN=INPUTFIILE,(LENGTH=25,FB)
//OUT1       DD   DSN=&&T1,LRECL=20,DISP=(NEW,PASS)...
//OUT2       DD   DSN=&&T2,LRECL=20,DISP=(NEW,PASS)...
//SORTOUT DD  DUMMY
//SYSIN      DD  *
   OPTION COPY
   OUTFIL  FNAMES=OUT1,OUTREC=(1,20)
   OUTFIL  FNAMES=OUT2,OMIT=(21,5,EQ,C' '),OUTREC=(1,15,21,5) 
/*
//STEP2   EXEC PGM=ICETOOL
//IN1         DD   DSN=&&T1,LRECL=20,DISP=(OLD,DELETE)...
//IN2         DD   DSN=&&T2,LRECL=20,DISP=(OLD,DELETE)...
//TEMP      DD    DSN=&&TEMP,LRECL=20,DISP=(MOD,PASS)...
//OUTPUT    DD  DSN=HLQ.YOUR.OUTPUT,DISP=(NEW,CATLG),
//SORTOUT DD  DUMMY
//SYSIN      DD  *
   COPY FROM(IN1) TO(TEMP)
   COPY FROM(IN2) TO(TEMP)
   COPY FROM(TEMP) TO(OUTPUT) USING(CTL1)
/*
//CTL1CNTL DD  *
  SORT FIELDS=(1,20,CH,A)
/*

In first step, first 4 fields SEQ_ID, AMOUNT, TRAN_ID and PRI_CUS from all the records are written to &&T1 temporary dataset. Also all the records in the input file which do not have spaces in fifth field (col21-25 i.e secondary customer), first three fields SEQ_ID, AMOUNT , TRAN_ID (these together occupy col1-15) and fifth field SEC_CUS (col 21-25) are extracted from these records and &&T2 file is created.

In the second step, &&t1 and &&t2 are merged and sorted to give data in OUTPUT file HLQ.YOUR.OUTPUT.

Hope this helps.


-Ajay
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 May 17, 2008 9:02 pm
Reply with quote

Bhaskar,

Ajay's "solution" is ridiculously inefficient. You don't need four passes over the data to do what you want - you can do it in one pass with the following DFSORT job:

Code:

//S1    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SORTIN DD *
SEQ11  10000  T10001  2000011 3000221
SEQ32  3000   T30021  2011000 1800111
SEQ45  23400  T43000  2001000
/*
//SORTOUT DD SYSOUT=*
//SYSIN    DD    *
  OPTION COPY
  OUTFIL IFOUTLEN=60,
    IFTHEN=(WHEN=(31,1,CH,EQ,C' '),
      BUILD=(1,29)),
    IFTHEN=(WHEN=(23,7,ZD,LE,31,7,ZD),
      BUILD=(1,29,/,1,22,31,7)),
    IFTHEN=(WHEN=(23,7,ZD,GT,31,7,ZD),
      BUILD=(1,22,31,7,/,1,29))
/*
Back to top
View user's profile Send private message
Ajay Baghel

Active User


Joined: 25 Apr 2007
Posts: 206
Location: Bangalore

PostPosted: Sat May 17, 2008 9:26 pm
Reply with quote

Hi Frank,

I never used the '/' operator and it did not cross my mind.

Please let me know if i am right,

Quote:
BUILD=(1,29,/,1,22,31,7)


causes two o/p records to be written from one input record:
1) col1 to 29 to be written to first output record.
2) col1-22 followed by col 31-37 to second o/p record.

Yes, my solution is less efficient as compared since it requires more no of passes. But it does the job.


Thanks,
Ajay
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: Sat May 17, 2008 11:54 pm
Reply with quote

Hello,

Quote:
Yes, my solution is less efficient as compared since it requires more no of passes. But it does the job.
Most organizations would not find this an acceptable answer for a Production solution.

For a one-time situation, maybe, but not as a philosophy.

/rant on
This is one of the major issues facing management today. There are far too many "developers" who have no idea how to do their job properly, so anything that happens to run to end-of-job is promoted and used. It is creating a performance and maintenance nightmare.
/rant off
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: Sun May 18, 2008 9:06 pm
Reply with quote

Ajay,

Yes, that's what the BUILD statement does and IFOUTLEN=60 ensures that the output records are padded on the right with blanks to 60 bytes.

Quote:
Yes, my solution is less efficient as compared since it requires more no of passes. But it does the job.


Actually, your "solution" doesn't even do the job! It has many problems. STEP1 is missing the required //SYSOUT DD statement. STEP2 is missing the required //TOOLMSG, //DFSMSG and //TOOLIN statements. The OMIT operand has a syntax error (missing format in OMIT). So as shown your job wouldn't even complete successfully.

If it did complete, it would give an output LRECL of 20 when the OP asked for 60.

I don't even see what you're trying to do - it doesn't seem to make any sense given that there was supposed to be a comparison between the two ZD fields and you don't have any such comparison.
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: Mon May 19, 2008 2:09 am
Reply with quote

Ahhh - the best of both worlds. . . icon_confused.gif

Not only can this type of "solution" cause the purchase of more/faster expensive hardware, it also provides the wrong answer icon_rolleyes.gif

And the population is growing. . .

d
Back to top
View user's profile Send private message
bhaskar_kanteti

Active User


Joined: 01 Feb 2007
Posts: 123
Location: Hyderabad

PostPosted: Mon May 19, 2008 8:21 pm
Reply with quote

Hi Frank,

Thanks for providing a simple solution.
Thank you so much.
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 Compare 2 files and retrive records f... DFSORT/ICETOOL 2
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
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 FINDREP - Only first record from give... DFSORT/ICETOOL 3
Search our Forums:

Back to Top