|
View previous topic :: View next topic
|
| Author |
Message |
Mounika Nemani
New User
Joined: 25 May 2018 Posts: 5 Location: India
|
|
|
|
Hi,
I have a PS file with length 80. I have 10 byte character data from column 70. now I have to count the char data for any characters apart from spaces and put the length in my varchar field. how can I do it in sort.
please post any example sort card on how to achieve this.
Thanks in Advance |
|
| Back to top |
|
 |
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
| You cannot. |
|
| Back to top |
|
 |
Ilavenil
New User
Joined: 16 May 2018 Posts: 4 Location: India
|
|
|
|
Hello Mounika,
We cannot do that in single step, but with couple of steps it is possible, if I understood your problem statement in a right way! Assuming that the CHAR(10) starts from 71 to 80 and the length field from 69 to 70.
| Code: |
//STEP1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DSN=BPV081.TEST.SORT,DISP=SHR
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//OUT DD DSN=BPV081.TEST.SORT.OUT,DISP=(NEW,CATLG,DELETE),
// DCB=(RECFM=FB,LRECL=12),DATACLAS=MB020
//TOOLIN DD *
COPY FROM(IN) USING(CTL1)
COPY FROM(T1) TO(OUT) USING(CTL2)
/*
//CTL1CNTL DD *
OUTFIL FNAMES=T1,FTOV,VLTRIM=C' ',
BUILD=(71,10)
/*
//CTL2CNTL DD *
OUTFIL VTOF,BUILD=(1:1,2,BI,SUB,+4,TO=ZD,LENGTH=2,3:5,10)
/*
//STEP2 EXEC PGM=SORT
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTJNF1 DD DSN=BPV081.TEST.SORT.OUT,DISP=MOD
//SORTJNF2 DD DSN=BPV081.TEST.SORT,DISP=SHR
//OUTFILE DD DSN=BPV081.TEST.SORT.OUT1,DISP=(NEW,CATLG,DELETE),
// DCB=(RECFM=FB,LRECL=80),DATACLAS=MB020
//SYSIN DD *
JOINKEYS FILE=F1,FIELDS=(3,10,A)
JOINKEYS FILE=F2,FIELDS=(71,10,A)
JOIN UNPAIRED,F1,F2
REFORMAT FIELDS=(?,F2:1,68,F1:1,12)
OPTION COPY
OUTFIL FNAMES=OUTFILE,INCLUDE=(1,1,CH,EQ,C'B'),
BUILD=(2,80)
/*
|
Hope it helps! |
|
| Back to top |
|
 |
Mounika Nemani
New User
Joined: 25 May 2018 Posts: 5 Location: India
|
|
|
|
I'm sorry if I am unable to explain properly. I am trying to move a character field to a varchar field throught sortcard.
ex:
input file:
ABC
ABCDEFGI
AJDFAJ
In the above file my pic x(10) field has data less than 10 bytes as well. so, now im trying to move it to varchar(10) field through sort. I wrote the below sort card.
//SYSIN DD *
SORT FIELDS=COPY
OUTREC FIELDS=(1:X'000A',
3:71,10)
however im trying to see If I can count the number of chars in the filed and put it in the length part of varchar field.
ex:
first line of input has 3 characters. so, X'0003' should be moved to the length.
please help me if we can achieve that counting part in the sort card. |
|
| Back to top |
|
 |
Ilavenil
New User
Joined: 16 May 2018 Posts: 4 Location: India
|
|
|
|
Mounika,
The step 1 does that exactly. It moves the CHAR(10) to VB file by trimming trailing spaces. Again the VB data is converted into FB and from the RDW the length is calculated. The final output of step 1 has the VARCHAR equivalent of the CHAR(10) from the input file. Try running the job with your input, study the output files, you will get to know what it does. |
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
Mounika Nemani,
If you have only one field that you are trying to find the data length of, and it is just 10 bytes then probably you can do this in one step with a bunch of IFTHENs evaluating the trailing blanks and find the data length.
Something like this:
| Code: |
//STEP01 EXEC PGM=SORT
//SORTIN DD *
ABC
ABCDEFGI
AJDFAJ
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
OUTREC IFTHEN=(WHEN=INIT,BUILD=(X'000A',1,10)),
IFTHEN=(WHEN=(4,9,CH,EQ,C' '),
OVERLAY=(1,2,BI,SUB,+9,TO=BI,LENGTH=2)),
IFTHEN=(WHEN=(5,8,CH,EQ,C' '),
OVERLAY=(1,2,BI,SUB,+8,TO=BI,LENGTH=2)),
IFTHEN=(WHEN=(6,7,CH,EQ,C' '),
OVERLAY=(1,2,BI,SUB,+7,TO=BI,LENGTH=2)),
IFTHEN=(WHEN=(7,6,CH,EQ,C' '),
OVERLAY=(1,2,BI,SUB,+6,TO=BI,LENGTH=2)),
IFTHEN=(WHEN=(8,5,CH,EQ,C' '),
OVERLAY=(1,2,BI,SUB,+5,TO=BI,LENGTH=2)),
IFTHEN=(WHEN=(9,4,CH,EQ,C' '),
OVERLAY=(1,2,BI,SUB,+4,TO=BI,LENGTH=2)),
IFTHEN=(WHEN=(10,3,CH,EQ,C' '),
OVERLAY=(1,2,BI,SUB,+3,TO=BI,LENGTH=2)),
IFTHEN=(WHEN=(11,2,CH,EQ,C' '),
OVERLAY=(1,2,BI,SUB,+2,TO=BI,LENGTH=2)),
IFTHEN=(WHEN=(12,1,CH,EQ,C' '),
OVERLAY=(1,2,BI,SUB,+1,TO=BI,LENGTH=2)) |
EDIT: You might want to add another IFTHEN after the very first IFTHEN BUILD above, to look for all spaces and then subtract 10 if you are expecting all blanks in the input field. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|