%THIS
%THIS returns an Object value that contains a reference to the class instance on whose behalf the native method is being called. %THIS is valid only in non-static native methods. This built-in gives non-static native methods access to the class instance.
A non-static native method works on a specific instance of its class. This object is actually passed as a parameter to the native method by Java, but it does not appear in the prototype or procedure interface for the native method. In a Java method, the object instance is referred to by the Java reserved word this. In an RPG native method, the object instance is referred to by the %THIS built-in function.
* Method "vacationDays" is a method in the class 'Employee'
D vacationDays PR 10I 0 EXTPROC(*JAVA
D : 'Employee'
D : 'vacationDays')
* Method "getId" is another method in the class 'Employee'
D getId PR 10I 0 EXTPROC(*JAVA
D : 'Employee'
D : 'getId')
...
* "vacationDays" is an RPG native method. Since the STATIC keyword
* is not used, it is an instance method.
P vacationDays B EXPORT
D vacationDays PI 10I 0
D id_num S 10I 0
* Another Employee method must be called to get the Employee's
* id-number. This method requires an Object of class Employee.
* We use %THIS as the Object parameter, to get the id-number for
* the object that our native method "vacationDays" is working on.
C eval id_num = getId(%THIS)
C id_num chain EMPFILE
C if %found
C return VACDAYS
C else
C return -1
C endif
P vacationDays E