sort jcl to add two columns

Sort JCL: Easy Way to Add Two Columns

By Jessica Garcia
AD

Ever found yourself needing to add two columns of data together in a JCL (Job Control Language) program? If so, you're in the right place. In this guide, we'll walk you through the process of sorting JCL to perform column addition, step by step. Let's dive in.

Before we start, let's assume we have a simple JCL dataset in IDCAMS format, with two columns of numeric data that we want to add together. Our goal is to sort this data and then add the corresponding entries in each of the two columns.

Understanding the Sort Procedure

The first step in our process is understanding the SORT procedure in JCL. SORT is used to arrange data based on certain key fields. In our case, we'll use it to prepare our data for addition.

AD
How to Sort Two Columns to Match in Excel (2 Simple Methods) - ExcelDemy
How to Sort Two Columns to Match in Excel (2 Simple Methods) - ExcelDemy
How to Sort Column by Value in Excel (7 Easy Ways) - ExcelDemy
How to Sort Column by Value in Excel (7 Easy Ways) - ExcelDemy
How to Sort by Column in Excel and Keep Rows Together (4 Easy Ways) - ExcelDemy
How to Sort by Column in Excel and Keep Rows Together (4 Easy Ways) - ExcelDemy

SORT can be used to sort data in ascending or descending order. For our purpose, we'll focus on ascending order, as it's the most common. The SORT procedure can be complex, but for a basic understanding, we'll stick to the essentials.

Defining the SORT Input and Output

To define the input to the SORT, we use the 'INFILE' statement. This tells the SORT what dataset to read. We also need to specify the 'LRECL' (logical record length) to let the SORT know how long each record is. Here's an example:

How to Sort Multiple Columns in Excel (5 Quick Methods) - ExcelDemy
How to Sort Multiple Columns in Excel (5 Quick Methods) - ExcelDemy
Excel Formula to Compare Two Columns and Return a Value (5 examples) - ExcelDemy
Excel Formula to Compare Two Columns and Return a Value (5 examples) - ExcelDemy
an excel spreadsheet showing the number and type of columns in each column, including
an excel spreadsheet showing the number and type of columns in each column, including
```jcl INFILE A.Infile LRECL=80 BLKSIZE=3183 ```

The output from the SORT is defined using the 'OUTFILE' statement. This tells the SORT where to write the sorted data. Again, we specify the 'LRECL'.

```jcl OUTFILE A.Outfile LRECL=80 BLKSIZE=3183 ```

Defining the SORT Key

The 'SORTFIELDS' statement defines which fields to use as the key. This tells the SORT how to sort the records. In our case, we'll sort based on the first column.

AD
```jcl SORTFIELDS=(A.SortField,10,B.SortField,10) ```

Here, 'A.SortField' and 'B.SortField' are placeholders for the actual field names in your dataset.

How to Sort Rows by Column in Excel (4 Easy Methods) - ExcelDemy
How to Sort Rows by Column in Excel (4 Easy Methods) - ExcelDemy
How to Sort Multiple Columns in Excel
How to Sort Multiple Columns in Excel
How to Compare Two Columns or Lists in Excel (4 Suitable Ways) - ExcelDemy
How to Compare Two Columns or Lists in Excel (4 Suitable Ways) - ExcelDemy
VLOOKUP Formula to Compare Two Columns in Different Excel Sheets - ExcelDemy
VLOOKUP Formula to Compare Two Columns in Different Excel Sheets - ExcelDemy
How to Use Columns Formula in Excel
How to Use Columns Formula in Excel
an excel spreadsheet with the names and numbers listed in each column on it
an excel spreadsheet with the names and numbers listed in each column on it

Adding the Two Columns

Now that we have our data sorted, we can add the two columns. For this, we'll use a program where we read the sorted data, add the corresponding entries in each column, and write the result back to output.

This process involves more than just a simple JCL statement, and would typically require a program written in COBOL, PL/I, or another language supported by your z/OS system. However, the SORT procedure paves the way for this operation by ensuring that the data is in the correct order.

AD

Adding Inline with Basic JCL Procedures

While a full program would provide more advanced options, it's possible to perform basic additions inline with JCL. This is done using the 'ADD' statement. Here's a simple example:

How to Insert Columns into Google Docs
How to Insert Columns into Google Docs
How to Sort in Excel Rows or Columns Avoid Sort Problems
How to Sort in Excel Rows or Columns Avoid Sort Problems
How to Compare Two Columns in Excel (for matches & differences)
How to Compare Two Columns in Excel (for matches & differences)
How to Count Matches in Two Columns in Excel (3 Practical Methods) - ExcelDemy
How to Count Matches in Two Columns in Excel (3 Practical Methods) - ExcelDemy
Compare Two Excel Columns for Differences - wellsr.com
Compare Two Excel Columns for Differences - wellsr.com
How to Copy and Paste a Column in Excel
How to Copy and Paste a Column in Excel
Add Column In Excel
Add Column In Excel
How to Match Two Columns and Return a Third in Excel - ExcelDemy
How to Match Two Columns and Return a Third in Excel - ExcelDemy
Using Flash Fill in Excel
Using Flash Fill in Excel
Compare two columns in Excel for matches and differences - Excel Dashboard School
Compare two columns in Excel for matches and differences - Excel Dashboard School
Compare Two Columns in Excel (for Matches & Differences)
Compare Two Columns in Excel (for Matches & Differences)
What is a Column in Excel
What is a Column in Excel
How to merge and combine Excel spreadsheets into one
How to merge and combine Excel spreadsheets into one
Compare two Columns in Excel (for Matches & Differences)
Compare two Columns in Excel (for Matches & Differences)
```jcl ADD ((A.addField,10,B.addField,10),12),10, C.resultField,10 ```

In this example, 'A.addField' and 'B.addField' are the columns we want to add, and 'C.resultField' is where we'll store the result. The '10's specify the length of each field.

Understanding ENDFILE and Footer Processing

JCL also provides ways to handle special conditions, such as the end of a file (with 'ENDFILE') or the need to process a file footer (with 'FOOTER'). These can be useful in more complex addition operations, where you might need to handle data that doesn't match up exactly or process records in a specific order.

AD

With that, you've now learned how to sort JCL and add two columns. Remember, JCL can be complex, but with a solid understanding of its basics, you can tackle even the most daunting data tasks. So, start practicing, and you'll be performing column additions like a pro in no time!

AD