Skip to content

Instantly share code, notes, and snippets.

@sandeep-sparrow
Last active March 3, 2021 11:36
Show Gist options
  • Save sandeep-sparrow/33120681a51eef602f2b633e8260267f to your computer and use it in GitHub Desktop.
Save sandeep-sparrow/33120681a51eef602f2b633e8260267f to your computer and use it in GitHub Desktop.
COBOL INSPECT Function
****** ***************************** Top of Data ******************************
000001 IDENTIFICATION DIVISION.
000002 PROGRAM-ID. CBLINSP.
000003 AUTHOR. SANDEEP R PRAJAPATI.
000004 *
000005 ENVIRONMENT DIVISION.
000006 INPUT-OUTPUT SECTION.
000007 *
000008 DATA DIVISION.
000009 WORKING-STORAGE SECTION.
000010 *
000011 01 WS-STRING1 PIC X(20) VALUE SPACES.
000012 01 WS-STRING2 PIC X(20) VALUE SPACES.
000013 01 WS-LEN1 PIC 9(02) VALUE 0.
000014 01 WS-LEN2 PIC 9(02) VALUE 0.
000015 *
000016 LINKAGE SECTION.
000017 * 000018 01 PARM-DATA.
000019 05 LS-PARM-LEN PIC S9(04) COMP.
000020 05 LS-STRING2 PIC X(20).
000021 *
000022 PROCEDURE DIVISION USING PARM-DATA.
000023 *
000024 DISPLAY '*** START OF PROGRAM CBLINSP ***'
000025 *
000026 ACCEPT WS-STRING1
000027 DISPLAY 'STRING VALUE FROM INSTREAM DATA : ' WS-STRING1
000028 MOVE LS-STRING2 TO WS-STRING2
000029 DISPLAY 'STRING VALUE FROM PARM PARAMETER: ' WS-STRING2
000030 *
000031 * INSPECT TYPE 1
000032 *
000033 INSPECT WS-STRING1 TALLYING WS-LEN1
000034 FOR CHARACTERS BEFORE INITIAL SPACE
000035 DISPLAY 'LENGTH FROM TYPE 1 INSPECT FUNCTION: ' WS-LEN1
000036 *
000037 * INSPECT TYPE 2
000038 *
000039 INSPECT FUNCTION REVERSE(WS-STRING2) TALLYING WS-LEN2
000040 FOR LEADING SPACES
000041 COMPUTE WS-LEN2 = LENGTH OF WS-STRING2 - WS-LEN2
000042 DISPLAY 'LENGTH FROM TYPE 2 INSPECT FUNCTION: ' WS-LEN2
000043 *
000044 DISPLAY '*** END OF PROGRAM CBLINSP ***'
000045 STOP RUN.
****** **************************** Bottom of Data ****************************
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment