Portal | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Want to check if trailer count is 0 and produce a new file

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> JCL & VSAM
View previous topic :: :: View next topic  
Author Message
rohanthengal

Active User


Joined: 19 Mar 2009
Posts: 192
Location: Globe, India

PostPosted: Fri Jun 26, 2020 10:47 am    Post subject: Want to check if trailer count is 0 and produce a new file
Reply with quote

I am working on one requirement where I need to check if trailer count is zero, if zero then i want to copy just header and trailer from the input record.
Code:


HEADER2020-06-20
COL1,COL2,COL3,COL4
TRAILER0000


Output should have below:
Code:
HEADER2020-06-20
TRAILER0000


I am just thinking to drop COL1,COL2,COL3,COL4 line from input file and retain HEADER, TRAILER record.
Back to top
View user's profile Send private message

Joerg.Findeisen

Active User


Joined: 15 Aug 2015
Posts: 311
Location: Bamberg, Germany

PostPosted: Fri Jun 26, 2020 11:44 am    Post subject:
Reply with quote

And the question is, what have you tried so far to achieve this?
Back to top
View user's profile Send private message
rohanthengal

Active User


Joined: 19 Mar 2009
Posts: 192
Location: Globe, India

PostPosted: Fri Jun 26, 2020 4:19 pm    Post subject:
Reply with quote

I am thinking about solution either of sortcard, rexx to do that.
Whichever is best, could do that.

I am not much familiar with SORT cards to do these so thought to check here.
Back to top
View user's profile Send private message
Willy Jensen

Active User


Joined: 01 Sep 2015
Posts: 386
Location: Denmark

PostPosted: Fri Jun 26, 2020 6:14 pm    Post subject:
Reply with quote

If you never have more than 3, or at least a small number of, records, then I would go with a REXX pgm. Otherwise I would start looking at SORT, though I cannot offhand say that it is possible with SORT.
REXX will be something like this:
Code:
"execio * diskr in (stem in.)"
if right(value('in.'in.0),4)=0 then do
  queue in.1
  queue value('in.'in.0)
  "execio 2 diskw out (finis)"
end
else "execio" in.0 "diskw out (stem in. finis)"
Back to top
View user's profile Send private message
Joerg.Findeisen

Active User


Joined: 15 Aug 2015
Posts: 311
Location: Bamberg, Germany

PostPosted: Fri Jun 26, 2020 8:01 pm    Post subject:
Reply with quote

Note DD:F1 and DD:F2 have to be exactly the same input.
Code:
//TRLCHECK EXEC PGM=ICEMAN                       
//SYSOUT   DD SYSOUT=*                           
//F1       DD *                                   
HEADER2020-06-20                                 
COL1,COL2,COL3,COL4                               
TRAILER0000                                       
/*                                               
//F2       DD *                                   
HEADER2020-06-20                                 
COL1,COL2,COL3,COL4                               
TRAILER0000                                       
/*                                               
//SORTOUT  DD SYSOUT=*                           
//SYSIN    DD *                                   
  OPTION COPY                                     
  JOINKEYS F1=F1,FIELDS=(41,1,A)                 
  JOINKEYS F2=F2,FIELDS=(41,1,A)                 
  REFORMAT FIELDS=(F1:1,40,F1:42,1,F2:43,4)       
  OUTFIL FNAMES=(SORTOUT),                       
    OMIT=(41,1,CH,EQ,C'D',AND,42,4,ZD,EQ,+0),     
    REMOVECC,                                     
    BUILD=(1,40)                                 
/*                                               
//JNF1CNTL DD *                                           
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(41:C'XD',4X)),         
    IFTHEN=(WHEN=(1,6,CH,EQ,C'HEADER'),OVERLAY=(42:C'H')),
    IFTHEN=(WHEN=(1,7,CH,EQ,C'TRAILER'),OVERLAY=(42:C'T'))
  END                                                     
/*                                                         
//JNF2CNTL DD *                                           
  INCLUDE COND=(1,7,CH,EQ,C'TRAILER')                     
  INREC BUILD=(41:C'X',X,8,4)                             
  END                                                     
/*

Output for TRAILER0000:
Code:
****** *****************
000001 HEADER2020-06-20
000002 TRAILER0000     
****** *****************

Output for TRAILER0008:
Code:
****** ********************
000001 HEADER2020-06-20   
000002 COL1,COL2,COL3,COL4
000003 TRAILER0008         
****** ********************
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2406
Location: Hampshire, UK

PostPosted: Sat Jun 27, 2020 1:40 am    Post subject: Reply to: Want to check if trailer count is 0 and produce a new file
Reply with quote

I assume that if the trailer count is not 0 then there will be many data records i..e. more than 0. I assume, maybe wrongly, that the second record (COPY....) is not a data record so will be in an 'empty' dataset. If that is correct then surely you read 4 records (STOPAFT=4) assigning sequence numbers and if the highest sequence number is 4 then this is not an empty dataset so you STOP. If the highest sequence number is 3 then there are no data records so only output records with sequence numbers 1 and 3.

For a Rexx solution you only meed to read 4 records again and if RC=400 (I think 400 is EOF) then there were only 3 records so output records 1 and 3.
Back to top
View user's profile Send private message
Joerg.Findeisen

Active User


Joined: 15 Aug 2015
Posts: 311
Location: Bamberg, Germany

PostPosted: Sat Jun 27, 2020 2:15 am    Post subject:
Reply with quote

@Nic: With STOPAFT=n you will not be able to print the existing trailer record if the number of data records exceeds n. TS request was to have HDR/TRL in any case.
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2406
Location: Hampshire, UK

PostPosted: Sat Jun 27, 2020 1:33 pm    Post subject: Reply to: Want to check if trailer count is 0 and produce a new file
Reply with quote

Well, he needs to clarify with data examples. To me it looks like the data is in csv format and the record with col1, col2 etc is a column headings record that is written before it is found that there are zero records to output. He says he wants header and trailer records written when the dataset is empty i.e. no data records. I do not think that he is wanting to check for the trailer having a zero count when there are data records. Clarification needed.
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2406
Location: Hampshire, UK

PostPosted: Wed Jul 01, 2020 2:54 pm    Post subject: Reply to: Want to check if trailer count is 0 and produce a new file
Reply with quote

Moot point as OP has not come back but
Quote:
if zero then i want to copy just header and trailer from the input record.

Note he wants output if trailer is 0 - not any other number.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2467
Location: NY,USA

PostPosted: Wed Jul 01, 2020 11:45 pm    Post subject:
Reply with quote

This is one another way, You can change the offsets as per your record offset and good to go. You can also do 3 pass to 2 and 2 to 1 if you want.

Code:
//STEP01   EXEC PGM=ICETOOL                           
//TOOLMSG  DD SYSOUT=*                               
//DFSMSG   DD SYSOUT=*                               
//IN       DD *                                       
HDR1234                                               
DTLAAAA                                               
TRL0000                                               
//TMP1     DD  DISP=(NEW,PASS),                       
//             UNIT=SYSDA,SPACE=(TRK,(10,10),RLSE),   
//             DSN=&&MASTER                           
//TMP2     DD  DISP=(NEW,PASS),                       
//             UNIT=SYSDA,SPACE=(TRK,(10,10),RLSE),   
//             DSN=&&MASTER                           
//OUT      DD  SYSOUT=*                               
//TOOLIN   DD *                                       
 RESIZE FROM(IN) TO(TMP1) TOLEN(80) USING(CTL1)       
 COPY FROM(TMP1) TO(TMP2) USING(CTL2)                 
 COPY FROM(TMP2) TO(OUT) USING(CTL3)                 
//CTL1CNTL DD *                                       
  INREC BUILD=(1,10)                                 
  OUTFIL BUILD=(1,80)                                                   
//CTL2CNTL DD *                                                         
  INREC IFTHEN=(WHEN=(21,7,CH,EQ,C'TRL0000'),                           
                         OVERLAY=(81:1,10,10X,21,10)),                 
        IFTHEN=(WHEN=(21,7,CH,NE,C'TRL0000'),                           
                         OVERLAY=(81:1,10,11,10,21,10))                 
  OUTFIL BUILD=(81,10,/,91,10,/,101,10)                                 
//CTL3CNTL DD *                                                         
  OMIT COND=(1,1,CH,EQ,C' ')   


Output-
Code:
********************************* TOP OF DATA **********************************
HDR1234                                                                         
TRL0000                                                                         
******************************** BOTTOM OF DATA ********************************   


When TRL0001 << other than 0000 then
Code:
********************************* TOP OF DATA **********************************
HDR1234                                                                         
DTLAAAA                                                                         
TRL0001                                                                         
******************************** BOTTOM OF DATA ********************************   
Back to top
View user's profile Send private message
Joerg.Findeisen

Active User


Joined: 15 Aug 2015
Posts: 311
Location: Bamberg, Germany

PostPosted: Thu Jul 02, 2020 5:14 am    Post subject:
Reply with quote

And one more:
Code:
//A        EXEC PGM=ICEMAN                                             
//SORTIN   DD *                                                       
HEADER2020-06-20                                                       
COL1,COL2,COL3,COL4                                                   
TRAILER0000                                                           
/*                                                                     
//SYSOUT   DD SYSOUT=*                                                 
//SORTOUT  DD DISP=(NEW,PASS),UNIT=SYSALLDA,                           
//            SPACE=(CYL,(2,1),RLSE),                                 
//            DSORG=PS,RECFM=FB,LRECL=80,BLKSIZE=0                     
//SYSIN    DD *                                                       
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(41:SEQNUM,8,ZD))                   
  SORT FIELDS=(41,8,ZD,D)                                             
  OUTREC IFTHEN=(WHEN=GROUP,BEGIN=(1,7,CH,EQ,C'TRAILER'),PUSH=(49:8,4))
  END                                                                 
/*                                                                     
//B        EXEC PGM=ICEMAN                                             
//SORTIN   DD DISP=(OLD,PASS),DSN=*.A.SORTOUT                         
//SYSOUT   DD SYSOUT=*                                                 
//SORTOUT  DD SYSOUT=*                                                 
//SYSIN    DD *                                                       
  INCLUDE COND=(1,6,CH,EQ,C'HEADER',OR,1,7,CH,EQ,C'TRAILER',OR,       
                49,4,ZD,NE,+0)                                         
  SORT FIELDS=(41,8,ZD,A)                                             
  OUTFIL BUILD=(1,40)                                                 
  END                                                                 
/*
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> JCL & VSAM All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Group selective VB records - Trailer ... Premnath_TJ DFSORT/ICETOOL 12 Sun Sep 13, 2020 3:38 am
No new posts TWS - ETT File triggering does not wo... me00266 IBM Tools 4 Mon Sep 07, 2020 11:58 pm
No new posts How to process dependent file based o... HithaSri JCL & VSAM 8 Sun Sep 06, 2020 12:42 pm
No new posts EIBRESP =16 & EIBRESP2 = 01 while... Farheen CICS 4 Mon Aug 24, 2020 2:05 pm
No new posts Dynamic file read via JCL abdulrafi JCL & VSAM 4 Fri Aug 14, 2020 11:51 am

Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us