MEMINDEX returns a size_t 1 value that indicates the starting position within a buffer of a specified substring.
With three arguments, the function's syntax is as follows:
>>-MEMINDEX--(--p--,--n--,--x--)-------------------------------><
With four arguments, the function's syntax is as follows:
>>-MEMINDEX--( -p--,--n--,--q--,--m--)-------------------------><
The buffer lengths must be nonnegative and must have a computational type. The buffer lengths are converted to type size_t.
With three arguments, the target string-expression must have type CHARACTER (including PICTURE), GRAPHIC, or WIDECHAR. The buffer length is interpreted as the number of units of that string type.
With four arguments, the buffer lengths specify a number of bytes and the search performed is a character search.
For a VARYING, VARYING4, or VARYINGZ string X and string Y, the function MEMINDEX(ADDRDATA(X), LENGTH(X), Y) will return the same value as INDEX(X, Y).
dcl cb(128*1024) char(1);
dcl wb(128*1024) widechar(1);
dcl pos fixed bin(31);
/* 128K bytes searched for the character string 'test' */
pos = memindex( addr(cb), stg(cb), 'test' );
/* 256K bytes searched for the string 'test' as widechar */
pos = memindex( addr(wb), stg(wb), wchar('<') );