MainframeMaster

COBOL Tutorial

SELF - Current Object Reference

Progress0 of 0 lessons

Overview

In OO COBOL, SELF refers to the currently executing object instance. Use it to INVOKE methods or pass this object to collaborators.

🪞 Analogy

SELF is like saying “me” when you speak. “I will call my method” → INVOKE SELF "MY-METHOD".

Usage Patterns

Invoke Own Method

cobol
1
2
3
4
5
METHOD-ID. DO-WORK. PROCEDURE DIVISION. INVOKE SELF "INTERNAL-STEP" EXIT METHOD. END METHOD DO-WORK.

Pass SELF to Collaborator

cobol
1
INVOKE LOGGER "REGISTER" USING SELF

Store SELF

cobol
1
2
01 THIS-OBJ OBJECT REFERENCE MY-CLASS. MOVE SELF TO THIS-OBJ

Best Practices and Mistakes

Best Practices

  • Use SELF for clarity instead of implicit calls
  • Limit passing SELF to avoid tight coupling
  • Prefer interfaces when sharing SELF

Common Mistakes

MistakeProblemFix
Using SELF in procedural codeNot availableUse only inside OO classes
Leaking SELF too widelyTight couplingUse interfaces and limit scope

Quick Reference

ActionSyntaxExample
Invoke own methodINVOKE SELF "name"INVOKE SELF "DO-WORK"
Pass selfUSING SELFINVOKE LOGGER "REGISTER" USING SELF

Test Your Knowledge

1. What does SELF refer to?

  • Parent class
  • Current object instance
  • Global state
  • Factory

2. How do you call a method on the current object?

  • CALL SELF
  • INVOKE SELF "METHOD"
  • DISPLAY SELF
  • MOVE SELF

3. Can you pass SELF to other methods?

  • Yes
  • No

4. Is SELF available in procedural COBOL?

  • Yes
  • No

5. What keyword calls a parent method?

  • THIS
  • SUPER
  • BASE
  • PARENT

Frequently Asked Questions