COBOL INSPECT Function

In the real world scenario many a times you required to find the length of string value to do a concatenation or string parse but more commonly is used in the VARCHAR column data type of DB2 table.

Hence it becomes important for any application to be aware of the COBOL function available to calculate the length of the input string.

one of the very common methods used in COBOL for finding the length of the string is to use a INSPECT function. the INSPECT function majorly are of two times.

in this blog I will shows you the following 2 types of INSPECT TALLYING function which help to get the length of string, very much need in teal world scenarios.

Basic syntax:

Below is the example of the COBOL code which receives data from JCL using instream and PARM parameter

instream data received by the COBOL program by issuing a ACCEPT statement
whereas, the PARM parameter is received by the COBOL program by using LINKAGE SECTION and by mentioning PROCEDURE USING linkage section structure.

you can check these in the below code.

Note: you can only pass 100 bytes of Maximum value using PARM parameter.

source code URL: https://gist.github.com/sandeep-sparrow/33120681a51eef602f2b633e8260267f

below is the JCL:


Here I have passed 'WELCOME TO MAINFRAME' as the PARM string which is received in the linkage section of COBOL program as shown below.


//SYSIN DD *
WELCOME TO MAINFRAM
/*

SPOOL O/P


is the instream data which is received in the COBOL program by ACCEPT statement.
on submission of JCL, the program is executed and we can check the spool output where both the inspect function find the length of the same string but with different values.

Thank you, hope these help you learn something new today :)

Sandeep Prajapati
Technology Analyst, Infosys Limited.
                                 

 

       

Comments

Popular posts from this blog

Sort JCL in Descending Order and Format the output

Dynamic Allocation of PS Dataset Using a COBOL program.

Fixing DB2 data for A Given table using Batch Program.