In OO COBOL, SELF refers to the currently executing object instance. Use it to INVOKE methods or pass this object to collaborators.
SELF is like saying “me” when you speak. “I will call my method” → INVOKE SELF "MY-METHOD".
12345METHOD-ID. DO-WORK. PROCEDURE DIVISION. INVOKE SELF "INTERNAL-STEP" EXIT METHOD. END METHOD DO-WORK.
1INVOKE LOGGER "REGISTER" USING SELF
1201 THIS-OBJ OBJECT REFERENCE MY-CLASS. MOVE SELF TO THIS-OBJ
Mistake | Problem | Fix |
---|---|---|
Using SELF in procedural code | Not available | Use only inside OO classes |
Leaking SELF too widely | Tight coupling | Use interfaces and limit scope |
Action | Syntax | Example |
---|---|---|
Invoke own method | INVOKE SELF "name" | INVOKE SELF "DO-WORK" |
Pass self | USING SELF | INVOKE LOGGER "REGISTER" USING SELF |
1. What does SELF refer to?
2. How do you call a method on the current object?
3. Can you pass SELF to other methods?
4. Is SELF available in procedural COBOL?
5. What keyword calls a parent method?