| Q. What does one understand by the phrase – Formatting of Output Records? Why do we need to format them? |
When we generate an Output using DFSORT sometimes, the records are not in a presentable format. For example, in the output records, there might not be a space between two fields. Or you might want to insert a $ sign for the currency field. You might want to re-order the fields, or display only selected fields/columns in the Output. This type of formatting of records can be done using DFSORT. You can format the records to be sorted in a particular way, prior to the sorting. This is also possible. So, for better presentation/easier understanding of the report, we re-format the records produced in Output. For re-formatting of records, there are mainly 3 tools at your disposal - BUILD - Reformat each record by specifying all of its items one by one. Here, you can add,delete or re-arrange fields. OVERLAY - It allows you to change (edit) the values in specific columns. IFTHEN - Reformats different records in different ways. The above re-formatting tools can be used with INREC, OUTREC and OUTFIL. INREC - Used to reformat the records before applying sort. OUTREC - Used to reformat the records after applying sort.
|
| Q. How to generate a Report, which displays only specific(desired) columns in the Output? |
| Suppose you are given the following Input Dataset. | ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-- AG10001 RAMESH CHANDRA GUHA INDIA MAHARASHT MUMBAI 01000 AG10002 QUASAR SHABBIR CHUN INDIA MAHARASHT PUNE 02000 AG10003 VEERAMANI DARYAGANJ INDIA MAHARASHT NAGPUR 03000 AG10004 DELPHAN FERANDAZ INDIA TAMIL NAD CHENNAI 04000 AG10005 PADMAVATHI SUNDARAM INDIA TAMIL NAD SALEM 05000 AG10006 NEELESHWARI IYER INDIA TAMIL NAD ERNAKULAM 06000 AG10007 AJAY NANUBHAI PARSA INDIA WEST BENG KOLKATA 07000 AG10008 MEHUL POPATLAL SUTA INDIA WEST BENG KHARAGPUR 08000 AG10009 KRITHIKA RAMANUJAM INDIA WEST BENG SUNDARBAN 09000 AG10010 ANKUR CHOUDHARY INDIA PUNJAB AMRITSAR 10000 AG10011 HIREN NITIN SHETH INDIA PUNJAB JALANDHAR 11000 AG10012 DARSHAN SHAH INDIA HARYANA CHANDIGAR 12000 | In the output report, you are asked to display only the name of the Insurance Agent and the Sales Figure. Since, we want reformat records after applying SORT, we will OUTREC FIELDS Control statement. We want to have two columns/fields in the ouput - NAME Start-Position 10 Length 20 SALES Start-Position 60 Length 05 Thus, we can write the Batch JOB/JCL for the above requirement as follows : | ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-- //CAA0176J JOB A123,QUASAR,NOTIFY=&SYSUID //STEP01 EXEC PGM=SORT,REGION=1024K //SORTIN DD DSN=CAA0176.DEMO.SORTIN,DISP=SHR //SYSPRINT DD SYSOUT=* //SYSOUT DD SYSOUT=* //SORTOUT DD DSN=CAA0176.DEMO.SORTOUT,DISP=(OLD,KEEP,KEEP) //SYSIN DD * SORT FIELDS=COPY - OUTREC FIELDS=(10,20,60,5) // | Note that, we have written SORT FIELDS=COPY, which simply copies the Input Records to the Output, and displays NAME and SALES Columns. Upon submitting the above Batch JOB/JCL, we get the following Output : | ----+----1----+----2----+ RAMESH CHANDRA GUHA 01000 QUASAR SHABBIR CHUN 02000 VEERAMANI DARYAGANJ 03000 DELPHAN FERANDAZ 04000 PADMAVATHI SUNDARAM 05000 NEELESHWARI IYER 06000 AJAY NANUBHAI PARSA 07000 MEHUL POPATLAL SUTA 08000 KRITHIKA RAMANUJAM 09000 ANKUR CHOUDHARY 10000 HIREN NITIN SHETH 11000 DARSHAN SHAH 12000 | A lot more formatting is possible on the above report. Read on to know more...
|
| Q. What if I wanted the SALES field/column to be displayed before(first) and then the NAME Field/Column? How do you re-order columns in the Output Report? |
If we would like to display the SALES Column first, and then the agent-names, we can simply change the order in OUTREC FIELDS statement. SORT FIELDS=COPY - OUTREC FIELDS=(60,5,10,20) Upon submitting a Batch JOB/JCL with the above control statements, we get the following output :
| ----+----1----+----2----+ 01000RAMESH CHANDRA GUHA 02000QUASAR SHABBIR CHUN 03000VEERAMANI DARYAGANJ 04000DELPHAN FERANDAZ 05000PADMAVATHI SUNDARAM 06000NEELESHWARI IYER 07000AJAY NANUBHAI PARSA 08000MEHUL POPATLAL SUTA 09000KRITHIKA RAMANUJAM 10000ANKUR CHOUDHARY 11000HIREN NITIN SHETH 12000DARSHAN SHAH | |
| Q. I’ve understood, how to re-order the columns, but the above output report looks like greek(Cyrilic) – there should be some space between the fields SALES and NAME. How do you insert a SPACE/SPACES? |
| Since the above output looks very clumsy, to make this report more readable we would like to insert 2 blank spaces between SALES and AGENT-NAME. To insert a blank space, we use X. To insert 2 blank spaces, we write 2X. SORT FIELDS=COPY - OUTREC FIELDS=(60,5,2X,10,20) Thus, upon submitting a Batch JOB/JCL with the above Control Statements, we get the following Output Report.
| ----+----1----+----2----+- 01000 RAMESH CHANDRA GUHA 02000 QUASAR SHABBIR CHUN 03000 VEERAMANI DARYAGANJ 04000 DELPHAN FERANDAZ 05000 PADMAVATHI SUNDARAM 06000 NEELESHWARI IYER 07000 AJAY NANUBHAI PARSA 08000 MEHUL POPATLAL SUTA 09000 KRITHIKA RAMANUJAM 10000 ANKUR CHOUDHARY 11000 HIREN NITIN SHETH 12000 DARSHAN SHAH | If you want to fill in blanks in the last field, you use the syntax c:X, where c is the column till where the padding takes place. For example, OUTREC FIELDS=(60,5,2X,10,20,140:X)
|
| Q. What if I wanted to insert a Character string like ‘IS SALES FOR’ between the two fields? What if I wanted to insert a Date and Timestamp? |
| You can insert characters at any position by tying C'<Characters>'. Suppose all records have length 65 bytes. Suppose, you would like to insert at the end of each record the current date and timestamp. Then, we would insert DATE1 and TIME2 fields respectively. This is the Batch JOB/JCL for doing it.
| ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-- //CAA0176L JOB A123,QUASAR,NOTIFY=&SYSUID //STEP01 EXEC PGM=SORT,REGION=1024K //SORTIN DD DSN=CAA0176.DEMO.SORTIN,DISP=SHR //SYSPRINT DD SYSOUT=* //SYSOUT DD SYSOUT=* //SORTOUT DD DSN=CAA0176.DEMO.SORTOUT,DISP=(OLD,KEEP,KEEP) //SYSIN DD * SORT FIELDS=COPY - OUTREC FIELDS=(60,5,2X,10,20,X,DATE1(/),X,TIME2(:)) // | Upon submitting the above Batch JOB/JCL, we get the following Output Report, with the Date and Time printed : | ----+----1----+----2----+----3----+----4----+ 01000 RAMESH CHANDRA GUHA 2009/07/29 03:32 02000 QUASAR SHABBIR CHUN 2009/07/29 03:32 03000 VEERAMANI DARYAGANJ 2009/07/29 03:32 04000 DELPHAN FERANDAZ 2009/07/29 03:32 05000 PADMAVATHI SUNDARAM 2009/07/29 03:32 06000 NEELESHWARI IYER 2009/07/29 03:32 07000 AJAY NANUBHAI PARSA 2009/07/29 03:32 08000 MEHUL POPATLAL SUTA 2009/07/29 03:32 09000 KRITHIKA RAMANUJAM 2009/07/29 03:32 10000 ANKUR CHOUDHARY 2009/07/29 03:32 11000 HIREN NITIN SHETH 2009/07/29 03:32 12000 DARSHAN SHAH 2009/07/29 03:32 | In the next tutorial, find out how to replace certain characters/fields, eliminate junk characters like LF, changing lower case to upper case and vice versa and much more.. Hope you’ve enjoyed! |