Easytrieve Substr Function Macro

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

Easytrive

INDEX function Macro

Introduction
This Tool is developed in EASYTRIEVE language and can be used only in the MAINFRAME
environment.

Description

This EASYTRIEVE has macro which has the following function.

INDEX – Macro name.

Functionality:
There are no functions to extract sub-string in easytrieve. This macro is written in such
way that in given string we can extract any specific string. This macro works like INDEX function in REXX
language for easytrieve.
In program self-explanatory example is given. Please refer it.

How to Use?

1) JCLINDEX – Store it in a library and submit the JCL.

//USERIDKA JOB (NGAI),'INDEX',


// MSGCLASS=U,CLASS=0,NOTIFY=&SYSUID,REGION=0M
//*
//PS000100 EXEC PGM=EZTPA00
//*
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSLIST DD SYSOUT=*
//SYSLIN DD SYSOUT=*
//SYSSNAP DD SYSOUT=*
//SYSUDUMP DD SYSOUT=I
//*
//SYSIN DD *
MSTART INDEX
MACRO 3 SRC-FLD TAR-FLD POS LEN(0)
*START OF MACRO
*
* THIS MACRO WILL WORK AS SUBSTR FUNCTION
*
* INPUT : SRC-FLD
* : POS
* OUTPUT : RES-FLD
* LEN - DEFAULT VALUE
*
DEFINE FLD-HOLD S 100 A
DEFINE FLD-CHAR FLD-HOLD 001 A INDEX FLD-NDX
*
DEFINE RES-FLD S 100 A
DEFINE RES-FLD-CHAR RES-FLD 001 A INDEX RES-FLD-IDX
*
DEFINE TMP-POS S 3N
DEFINE TFR-LEN S 3N
DEFINE RES-FLD-LEN S 3N
DEFINE MAX-FLD-LEN S 3 N VALUE 100
*
*MACRO ROUTINE STARTS
*
FLD-HOLD = &SRC-FLD
*
RES-FLD-LEN = &LEN
RES-FLD = ' '
RES-FLD-IDX = 0
*
TMP-POS = &POS
TFR-LEN = 0
FLD-NDX = 0
*
IF RES-FLD-LEN = 0
RES-FLD-LEN = MAX-FLD-LEN
END-IF
*
FLD-NDX = &POS - 1
*
DO WHILE TFR-LEN LT RES-FLD-LEN AND FLD-NDX LT MAX-FLD-LEN
RES-FLD-CHAR = FLD-CHAR
RES-FLD-IDX = RES-FLD-IDX + 1
TFR-LEN = TFR-LEN + 1
FLD-NDX = FLD-NDX + 1
END-DO
*
&TAR-FLD = RES-FLD
*
*END OF MACRO
MEND
*MAIN PROGRAM STARTS
PARM DEBUG (NODMAP FLDCHK FLOW STATE XREF LONG) +
ABEXIT (NOSNAP) VFM(4000)
*
DEFINE WS-INPUT-STR W 100 A
DEFINE WS-POS W 02 N
DEFINE WS-LEN W 02 N
DEFINE WS-NO-OF-CHAR W 02 N
DEFINE WS-OUTPUT-STR W 100 A
DEFINE WS-CHAR W 1A
*
* PROGRAMS START HERE LOGICALLY
* STARTING
JOB INPUT (NULL)
*
* EXAMPLE - 1, FOURTH PARAMETER IS OPTIONAL
WS-INPUT-STR = 'THIS IS AN EXAMPLE'
WS-POS = 6
%INDEX WS-INPUT-STR WS-OUTPUT-STR WS-POS
DISPLAY ' '
DISPLAY 'EXAMPLE - 1 '
DISPLAY 'INPUT ' WS-INPUT-STR
DISPLAY 'OUTPUT ' WS-OUTPUT-STR
*
*
* EXAMPLE - 2, PASSING VALUE FOR FOURTH PARAMETER
WS-INPUT-STR = 'THIS IS AN EXAMPLE'
WS-POS = 6
WS-LEN = 0
%INDEX WS-INPUT-STR WS-OUTPUT-STR WS-POS LEN(WS-LEN)
DISPLAY ' '
DISPLAY 'EXAMPLE - 2 '
DISPLAY 'INPUT ' WS-INPUT-STR
DISPLAY 'OUTPUT ' WS-OUTPUT-STR
*
*
* EXAMPLE - 3, PASSING VALUE FOR FOURTH PARAMETER
WS-INPUT-STR = 'THIS IS AN EXAMPLE'
WS-POS = 6
WS-LEN = 5
%INDEX WS-INPUT-STR WS-OUTPUT-STR WS-POS LEN(WS-LEN)
DISPLAY ' '
DISPLAY 'EXAMPLE - 3 '
DISPLAY 'INPUT ' WS-INPUT-STR
DISPLAY 'OUTPUT ' WS-OUTPUT-STR
*
*
* EXAMPLE - 4, PASSING VALUE FOR FOURTH PARAMETER
WS-INPUT-STR = 'THIS IS AN EXAMPLE'
WS-POS = 1
WS-LEN = 1
DISPLAY ' '
DISPLAY 'EXAMPLE - 4 '
DISPLAY 'EXTRACTED ALL CHARS ONE BY ONE'
DISPLAY 'INPUT ' WS-INPUT-STR
DO WHILE WS-POS LE 18
%INDEX WS-INPUT-STR WS-CHAR WS-POS LEN(WS-LEN)
DISPLAY WS-CHAR
WS-POS = WS-POS + 1
END-DO
*
*
STOP
*
/*
//*

You might also like