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

How to avoid these records from writing ?


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
tamminenisidhartha
Currently Banned

New User


Joined: 31 Oct 2012
Posts: 43
Location: INDIA

PostPosted: Wed Nov 07, 2012 3:39 pm
Reply with quote

I have the input file like this.

Code:
emp dep  emp type   emp sal
         
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);           


I have coded this inside a do while loop.

I hope you understood my question.

Code'd
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: Wed Nov 07, 2012 3:53 pm
Reply with quote

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.

What's all the SUBSTR for?
Back to top
View user's profile Send private message
tamminenisidhartha
Currently Banned

New User


Joined: 31 Oct 2012
Posts: 43
Location: INDIA

PostPosted: Wed Nov 07, 2012 4:33 pm
Reply with quote

I have been comparing the values by passing them into the variables using substring function.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Wed Nov 07, 2012 5:03 pm
Reply with quote

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
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Thu Nov 08, 2012 12:38 am
Reply with quote

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?
Back to top
View user's profile Send private message
tamminenisidhartha
Currently Banned

New User


Joined: 31 Oct 2012
Posts: 43
Location: INDIA

PostPosted: Thu Nov 15, 2012 11:45 am
Reply with quote

The data is srted by EMPDEP already and the employee types are only of P, S, T types.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Thu Nov 15, 2012 8:49 pm
Reply with quote

Very well. Consider the following program:
Code:
 foo36:  proc options (main) reorder;

 %dcl (true,false,digits,space)     char;
 %true   = '''1''B';
 %false  = '''0''B';
 %digits = '''0123456789''';
 %space  = ''' ''';

 dcl tulin                          file record input
                                    env (fb recsize(80)),
     tulout                         file record output
                                    env (fb recsize(132));

 dcl eyecatch (11)                  unsigned fixed bin (32) static
         init ('E69989A3'XU, 'A3859540'XU, '82A840C1'XU,
               '9281A3A2'XU, 'A4928194'XU, '8960A281'XU,
               '948140C8'XU, '8589A285'XU, '8940F2F4'XU,
               '4BF1F14B'XU, 'F1F50000'XU);

 dcl (eof_tulin, set_aside)         bit init(false),
     emptyp                         char,
     (empdep, lastdep)              char (79),
     (recin, recaside)              char (80) init((80)' '),
     recout                         char (132),
     (p, q)                         fixed bin (31);

 dcl (index, substr, verify)        builtin;

 on endfile (tulin) eof_tulin = true;

 read file (tulin) into (recin);

 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;

       set_aside = false;
       lastdep   = empdep;
     end;

     select (emptyp);
       when ('S') do;
         recout = recin;
         write file (tulout) from (recout);
       end;
       when ('P', 'T') do;
         recaside  = recin;
         set_aside = ªset_aside;
       end;
       otherwise do;
         put skip edit ('Serious error!  Unknown EMPTYP = [', emptyp,
                        ']') (a,a,a);
         exit;
       end;
     end;
   end;

   read file (tulin) into (recin);
 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.
Back to top
View user's profile Send private message
tamminenisidhartha
Currently Banned

New User


Joined: 31 Oct 2012
Posts: 43
Location: INDIA

PostPosted: Fri Nov 16, 2012 2:34 pm
Reply with quote

@akatsukami.
Thank you.
I would execute the code and post the outcome here.
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 -> PL/I & Assembler

 


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 Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Two input files & writing counter... DFSORT/ICETOOL 12
Search our Forums:

Back to Top