Skip to main content

Posts

How to reverse a file content using JCL SORT?

Hello, Mainframers!! Have you ever been asked to write a logic for reversing the file content, or any requirement to read the file in reverse order? In this post, I will try to explain how we can achieve the same using the SORT utility. Let's assume we have a dataset as mentioned below. Name: MFUSER.SORT.INPUT RECFM=FB, LRECL=40 Type: PS Input Dataset: It contains the list of Month names along with Unique Month ID in ascending order. File Edit Edit_Settings Menu Utilities Compilers Test Help ------------------------------------------------------------------------------- VIEW MFUSER.SORT.INPUT Columns 00001 00040 Command ===> Scroll ===> CSR =COLS> ----+----1----+----2----+----3----+----4 ****** ***************************** Top of Data ****************************** 000001 01 JANUARY ...

How to Reverse a string with or without using REVERSE function?

Hello Readers! Have you ever wanted to REVERSE a string a Mainframe COBOL program, or have you ever been asked to reverse a string without using REVERSE function? If the answer is Yes, then you may find this post useful to you. In the below mentioned COBOL program, I used two different ways of reversing a string in COBOL program. Using FUNCTION REVERSE REVERSE function returns a character string of exactly same length as input, but in the reverse order. Using PERFORM VARYING UNTIL In this logic, we loop through each character of input string from end of input (i.e. Length) to beginning of input (i.e. Position=1) and store the characters in result variable using reference modification. Output: From the output, we can say that we are able to reverse the input, but have you noticed something? Reverse string output has leading spaces. It is because string variable is declared with 20 length, but the actual length length of string (i.e. z/OS Mainframer ) is 15. As input WS-STRING is Alpha...