|
|
| Author |
Message |
Roshnii
New User
Joined: 30 Sep 2008 Posts: 39 Location: bangalore
|
|
|
|
I have two tables , table A and table B.
Table b is the child of table a. I need to unload the data
Of both the tables and put it in a file.
Say the data in the tables are like this
TABLE A
ID(PK) NAME SEMESTER
001 THOMAS THIRD
002 SMITH FOURTH
003 JOHN FIRST
TABLE B
ID(PK) SEQ(PK) SUBJECTS
001 1 MATHS
001 2 GEOGRAPHY
001 3 PSYCHOLOGY
002 1 HISTORY
003 1 ENGLISH
003 2 ELECTRONICS
OUTPUT FILE
A.ID A.NAME A.SEMESTER B.ID B.SEQ B.SUBJECTS
001 THOMAS THIRD 001 1 MATHS
001 THOMAS THIRD 001 2 GEOGRAPHY
001 THOMAS THIRD 001 3 PSYCHOLOGY
002 SMITH FOURTH 002 1 HISTORY
003 JOHN FIRST 003 1 ENGLISH
003 JOHN FIRST 003 2 ELECTRONICS
The output should be such that when there are multiple TABLE B entries then one record would be created for each TABLE B with the TABLE A repeating at the beginning or each record.
I do an unload of the data from these two tables and keep them in two files. Then while merging, is it possible to obtain the above results using sort? |
|
| Back to top |
|
 |
References
|
|
 |
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 7197 Location: Brussels once more ...
|
|
|
|
The usual questions ........................
For both input files - what is the RECFM and LRECL.
In which position and format are the key fields. |
|
| Back to top |
|
 |
Roshnii
New User
Joined: 30 Sep 2008 Posts: 39 Location: bangalore
|
|
|
|
Both the files are FB and the rec length for file A is 38.
and for file B is 35
and the key for table A is ID which is defined as DECIMAL(18,0) in the database
and the key for table B are ID and seq number which are defined as DECIMAL(18,0) and SMALLINT |
|
| Back to top |
|
 |
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 7197 Location: Brussels once more ...
|
|
|
|
| Where the key fields live on the database is of no consequence, it is where they are in the unloaded file that matters. |
|
| Back to top |
|
 |
sudhakarreddy.ibm Warnings : 1 New User
Joined: 20 Apr 2009 Posts: 15 Location: chennai
|
|
|
|
Hello,
I think, following query will help you to get your required output.
select A.ID, A.NAME, A.SEMESTER, B.ID, B.SEQ, B.SUBJECTS from A JOIN B ON A.ID=B.ID
WHERE GROUP BY A.ID,B.ID
Please correct me if i am wrong?
Sudha................ |
|
| Back to top |
|
 |
sudhakarreddy.ibm Warnings : 1 New User
Joined: 20 Apr 2009 Posts: 15 Location: chennai
|
|
|
|
| Inaccurate response removed - Expat |
|
| Back to top |
|
 |
Roshnii
New User
Joined: 30 Sep 2008 Posts: 39 Location: bangalore
|
|
|
|
I will be unloading the data from table A to file A which is of length 38 and from table B to a file B which is of 35
and the the first 18 characters of each file will be the key X(18). I hope my answer is clear. |
|
| Back to top |
|
 |
Skolusu
DFSORT Developer
Joined: 07 Dec 2007 Posts: 1163 Location: San Jose
|
|
|
|
| roshnii wrote: |
I will be unloading the data from table A to file A which is of length 38 and from table B to a file B which is of 35
and the the first 18 characters of each file will be the key X(18). I hope my answer is clear. |
roshnii,
In your earlier post you mentioned your key is defined as DECIMAL(18,0) which is equivalent to 10 PD field. If you are unloading it it would be just 10 byte PD field and not 18 byte character field.
The Following DFSORT/ICETOOL JCl will give you the desired results. This will give all the matching key records with the value from the parent table inserted in the first 38 bytes followed by child table data making 73 byte file (38+35 bytes)
| Code: |
//STEP0100 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//I1 DD DSN=your 38byte parent table file,DISP=SHR
//I2 DD DSN=your 35byte child table file,DISP=SHR
//T1 DD DSN=&&T1,DISP=(MOD,PASS),SPACE=(CYL,(X,Y),RLSE)
//OUT DD SYSOUT=*
//TOOLIN DD *
COPY FROM(I1) USING(CTL1)
COPY FROM(I2) USING(CTL2)
SORT FROM(T1) USING(CTL3)
//CTL1CNTL DD *
OUTFIL FNAMES=T1,OVERLAY=(39:C'$')
//CTL2CNTL DD *
OUTFIL FNAMES=T1,OVERLAY=(39:X)
//CTL3CNTL DD *
SORT FIELDS=(1,10,PD,A)
OUTREC IFTHEN=(WHEN=INIT,OVERLAY=(40:SEQNUM,8,ZD,RESTART=(1,10))),
IFTHEN=(WHEN=GROUP,BEGIN=(40,8,ZD,EQ,1),PUSH=(39:39,1,48:11,28))
OUTFIL FNAMES=OUT,BUILD=(1,10,48,28,1,35),
OMIT=(39,1,CH,EQ,C'$',AND,40,8,ZD,EQ,1)
/* |
|
|
| Back to top |
|
 |
|
|
|