As described in the index definition, it is possible to call jBC subroutines from an index definition. The SUBROUTINE should have five parameters as follows :
|1||Result||You store in here the result of the calculation|
|2||FileVar||This is a file variable for the file that has the update being processed|
|3||Record||This is the entire record being updated|
|4||Key||This is the record key of the record being updated|
|5||Field||This is the field, or attribute, already extracted as part of the index definition|
As an example, consider the following index creation
jsh-> CREATE-INDEX FILENAME INDEXNAME BY 1 : CALL(2,"INDEX-DEF") (M)
When an update occurs the index key is calculated by taking attribute 1 and concatenating it with the output from a CALL to a SUBROUTINE called INDEX-DEF-2. The source code for this may look something like this:
001 SUBROUTINE INDEX-DEF(Result, FileVar, Record, Key, Field )
002 IF NUM(Field) THEN Result = "*1" ELSE Result = "*0"
003 result := record<3>
In the above example the result is created in the first parameter, the "result" variable. This is calculated by taking the string "*1" or "*0" and concatenating it with attribute 3 from the record being updated. The choice of "*1" or "*0" depends upon whether the extracted attribute, passed in the fifth parameter as variable "field" , is numeric or not. The index definition was ‘ CALL(2,"INDEX-DEF")’ so this extracted attribute will be attribute 2.
Any normal jBC code will execute in these subroutines but you should be aware of the following pitfalls.
CATALOG BP INDEX-DEF
http://807199.827977/r5/knowledgebase/manuals/3.0/SecondaryIndexes/html/call-subs.htm last modified on 06/19/09 05:29 AM