when=group in sort jcl examples

Mastering Sort JCL: "GROUP" in "WHEN" Clause Examples

By James Moore
AD

When sorting data in a JCL (Job Control Language) program, the GROUP and WHEN conditions play a pivotal role in determining the sequence of records. They are utilized in conjunction with the SORT and SORTFIELDS statements. Let's delve into the intricacies of these concepts with practical examples.

The GROUP condition, denoted by 'GROUP', OF(...'), determines the grouping of similar records together based on specified sort fields. Meanwhile, the WHEN condition, denoted as 'WHEN', allows for customized actions or processes to be executed when a specific record matches the condition. Understanding these conditions can greatly enhance the effectiveness of your sorting operations.

Understanding GROUP in JCL SORT

The GROUP condition is particularly useful when working with sequential files that need to be sorted and aggregated in specific ways. It groups together records that match the specified criteria, creating output sets that can be processed efficiently.

AD
Julia's Reruns Bot (@b0rk_reruns@jvns.ca)
Julia's Reruns Bot (@b0rk_reruns@jvns.ca)
The Best Sorting Activities for Young Students & The Benefits of Using Them - Lessons for Little One
The Best Sorting Activities for Young Students & The Benefits of Using Them - Lessons for Little One
Sort By Grouping Worksheets | Reading Duck.com
Sort By Grouping Worksheets | Reading Duck.com

GROUP Example: Sorting by Employee ID

Let's consider an employee dataset, with fields like 'employee_id', 'name', and 'salary'. To group records based on 'employee_id', we can use the following JCL:

SORT FIELDS=(1,15,A) ONDG
    GROUP OF employee_id ONDG

a table with numbers on it that are written in the form of an x and y
a table with numbers on it that are written in the form of an x and y
2 Group Sort And Count Worksheet For Grade 1
2 Group Sort And Count Worksheet For Grade 1
sorting
sorting

This will sort the dataset in ascending order by 'employee_id'. The 'ONDG' option indicates that the buffer will be drained after the group key changes, ensuring that related records are output together.

GROUP Example: Sorting and Aggregating

To aggregate data like total salary for each employee, the GROUP condition can be combined with the OUTPUT clause. For instance:

AD

SORT FIELDS=(1,15,A) ONDG
    GROUP OF employee_id ONDG
    OUTPUT hardcopy
        AGGREGATE total_salary

GD Topics for Placement
GD Topics for Placement
3 Group Sorting Activity Worksheet For Grade 1
3 Group Sorting Activity Worksheet For Grade 1
Categorizing and Sorting with Kindergartners
Categorizing and Sorting with Kindergartners
Group Development: Stages of Group Work, Skills & Evaluation | Social Work Notes
Group Development: Stages of Group Work, Skills & Evaluation | Social Work Notes
Counting objects in groups worksheets
Counting objects in groups worksheets
Selection sort
Selection sort

This will output a hardcopy file containing the total salary for each employee, sorted by employee ID.

Using GROUP and WHEN in JCL SORT

The WHEN condition adds flexibility to your sorting operations, enabling you to perform specific actions based on record attributes. This is particularly useful when you want to filter, modify, or output records under certain conditions.

AD

WHEN Example: Filtering Records

Suppose you want to filter out employees with a salary below a certain threshold. You can use the 'WHEN' condition as follows:

Visibly Random Grouping Cards | Groups of Three
Visibly Random Grouping Cards | Groups of Three
i can sort by color and shape with pictures
i can sort by color and shape with pictures
SQL GROUP BY & HAVING Made Easy 📊 | Grouping & Filtering Data with Examples
SQL GROUP BY & HAVING Made Easy 📊 | Grouping & Filtering Data with Examples
the social groups diagram is shown in black and white
the social groups diagram is shown in black and white
Understanding the Algorithm behind Merge Sort for Linked Lists
Understanding the Algorithm behind Merge Sort for Linked Lists
Sorting and Classification Skills for Early Math
Sorting and Classification Skills for Early Math
the diagram shows how many different numbers can be found in an array, including one that is
the diagram shows how many different numbers can be found in an array, including one that is
Same and Different Sorting and Classification Activities for Kindergarten Noprep
Same and Different Sorting and Classification Activities for Kindergarten Noprep
Non-linear sorting
Non-linear sorting
two numbers are shown with the same number in each column, and one is missing
two numbers are shown with the same number in each column, and one is missing
Social Group Work Explained: UGC NET Social Work Complete Notes
Social Group Work Explained: UGC NET Social Work Complete Notes
Social Skills Group Activities for Sped Classrooms
Social Skills Group Activities for Sped Classrooms
a notebook with some writing on it and an image of two different types of computers
a notebook with some writing on it and an image of two different types of computers

SORT FIELDS=(1,15,A) ONDG
    WHEN employee_salary >= 50000
        OUTPUT hardcopy

This will output a hardcopy file containing only employees with a salary of 50,000 or more.

AD

WHEN Example: Modifying Records

The 'WHEN' condition can also be used to modify record fields. For example, to increase the salary of all employees by 10%:

SORT FIELDS=(1,15,A) ONDG
    WHEN employee_salary < 80000
        MODIFY employee_salary=(employee_salary * 1.1) F

This will increase the salary of all employees with a current salary below 80,000 by 10%.

Mastering the use of GROUP and WHEN in JCL sorting not only enhances the efficiency of your data processing but also unlocks a world of possibilities for data manipulation and analysis. The key lies in understanding your data and determining the most effective way to group and process it. Happy coding!

AD