000011 P 100
000011 T 200
000011 S 500
000023 P 300
000024 P 400
I would like to know this. I want to eliminate only emptype " P and T " records from writing if they have same emp dep value.
Code:
Note : In this example, The Emptype for first two records is " P and T ".
And they have the same empdep value.
Here the EMPTYPE " S" also has the same empdep value.
But it should be written into the output file.
So I would like to avoid only this pair of record from writing into
the output file.
Here's he logic on what I have been working on.
Code:
IF K = SUBSTR(INREC.EMPNO,1,6) THEN DO;
IF P ¬= SUBSTR(INREC.TYPE1,1,4) THEN DO;
WRITE FILE(OUTFILE) FROM (INREC);
END;
ELSE DO;
WRITE FILE(OUTFILE) FROM (HEADER);
WRITE FILE(OUTFILE) FROM (INREC);
END;
END;
END;
K = SUBSTR(INREC.EMPNO,1,6);
P = SUBSTR(INREC.TYPE1,1,4);
READ FILE(INFILE) INTO (INREC);
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
Your post has been Code'd to preserve formatting. Please do this yourself in future.
You will need to store the P/T records as you only know by the receipt of a T after the P (or P after the T) that the P (or T) is not needed for that key.
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
enrico-sorichetti wrote:
but why not use a proper DCL for the record layout
if the layout changes, You will not to have to chase around for the offsets
The data the TS shows suggests that the records are not necessarily of a fixed format (although heesh might have munged the example by putting explanatory column headers in the Code tags).
Tammi-kun, are more employee types possible than "P", "S", and "T"? May the data be assumed to be sorted by department?
do while (¬eof_tulin);
if (verify(substr(recin,1,1),digits)¬=0) then
do;
recout = recin;
write file (tulout) from (recout);
end;
else do;
p = index(recin,space);
q = verify(recin,space,p);
empdep = substr(recin,1,p-1);
emptyp = substr(recin,q,1);
if (empdep¬=lastdep) then
do;
if (set_aside) then
do;
recout = recaside;
write file (tulout) from (recout);
end;
if (set_aside) then
do;
recout = recaside;
write file (tulout) from (recout);
end;
end foo36;
I have assumed that the first character of EMPDEP is always a decimal digit; that criterion may be used to eliminate header records from consideration. I further assume that, although EMPDEP is always separated from EMPTYP by at least one space (and that it contains no embedded spaces), the record is not of fixed format; thus the use of the INDEX and VERIFY functions to find EMPTYP (if the record is of fixed format, you are better off declaring a structure as suggested by Dr. Sorichetti). An EMPTYP of "P" or "T" causes the record to be set aside and the switch SET_ASIDE to be toggled; when EMPDEP changes, the set-aside record is written if SET_ASIDE is true, which it will not be if a pair of records is encountered. Note that signficantly different data may require changes.