Appearance
Mini Lesson Practice — Local Classes and Local Types
Learning path
Complete the guided mini lesson — Local Classes and Local Types before starting this practice. When you finish, continue to Lesson 5 — Object APIs, Validation & Collaboration.
Build a practical business-style program using:
text
one global class
local structured types
one local table type
one local helper classScenario:
A company receives employee expense claims. Each claim must be evaluated before it can be approved, rejected, or sent for manager approval.
The purpose is to practise:
text
class pool
Local Types
local TYPES
local classes
visibility
responsibility separationPractice information
| Recommended time | About 2.5–3 hours |
| Environment | SAP BTP ABAP Trial |
| Global class | ZCL_EXPENSE_PROCESSOR_### |
| Local helper | lcl_claim_evaluator |
| Main focus | Local types + local class design |
1. Create the global class
Create:
text
ZCL_EXPENSE_PROCESSOR_###Description:
text
Expense Claim ProcessorImplement:
text
IF_OO_ADT_CLASSRUNThe global class should be responsible for:
text
creating input
calling the evaluator
displaying results2. Open Local Types
Open:
text
Local TypesDo not put the helper in:
text
Test ClassesDo not create another global helper class.
3. Create ty_claim
Define a local structured type containing:
text
claim_no
employee_id
category
amount
currency
receipt_attached
days_old
urgentSuggested ABAP types:
abap
claim_no TYPE string
employee_id TYPE string
category TYPE string
amount TYPE decfloat34
currency TYPE string
receipt_attached TYPE abap_bool
days_old TYPE i
urgent TYPE abap_bool4. Create tt_claims
Define:
text
tt_claimsas a standard internal table of:
text
ty_claimwith:
text
EMPTY KEY5. Create ty_evaluation
Define another local structured type containing:
text
claim_no
accepted
requires_manager
decision
messageSuggested types:
abap
claim_no TYPE string
accepted TYPE abap_bool
requires_manager TYPE abap_bool
decision TYPE string
message TYPE string6. Create the local helper class
Create:
text
lcl_claim_evaluatorIts public method:
text
evaluatemust:
text
IMPORT ty_claim
RETURN ty_evaluationThe evaluation rules belong in this local class.
Do not put them in main.
7. Rule A — amount
If:
text
amount <= 0then:
text
accepted = false
decision = REJECTED
message = Amount must be greater than zeroDo not continue evaluating that claim.
8. Rule B — age
If:
text
days_old > 60then:
text
accepted = false
decision = REJECTED
message = Claim is older than 60 daysDo not continue evaluating that claim.
9. Rule C — receipt
If:
text
amount > 25and:
text
receipt_attached = falsethen:
text
accepted = false
decision = REJECTED
message = Receipt is required for claims over 25Do not continue evaluating that claim.
10. Rule D — manager approval
If the claim passed all rejection rules:
text
accepted = trueManager approval is required when:
text
amount >= 500or:
text
urgent = trueThen return:
text
requires_manager = true
decision = MANAGER APPROVALOtherwise:
text
requires_manager = false
decision = APPROVED11. Currency assumption
Do not implement currency conversion.
Treat:
text
amount
currencyas input data.
Use:
text
EURfor the required test cases.
12. Create at least six claims
Your test data must cover:
text
normal approval
manager approval because amount >= 500
manager approval because urgent = true
rejection because amount <= 0
rejection because claim is older than 60 days
rejection because receipt is missing13. Suggested test cases
| Claim | Amount | Receipt | Days old | Urgent | Expected |
|---|---|---|---|---|---|
CLM-001 | 18 | No | 5 | No | Approved |
CLM-002 | 720 | Yes | 12 | No | Manager approval |
CLM-003 | 90 | Yes | 3 | Yes | Manager approval |
CLM-004 | 0 | Yes | 2 | No | Rejected |
CLM-005 | 120 | Yes | 75 | No | Rejected |
CLM-006 | 80 | No | 10 | No | Rejected |
14. Implement the global orchestration
In:
text
IF_OO_ADT_CLASSRUN~MAINthe global class should:
- create the
tt_claimstable; - create one
lcl_claim_evaluatorobject; - loop over the claims;
- call
evaluate; - output every result.
15. Output requirements
For every claim, output at least:
text
Claim Number
Decision
MessageOptional:
text
Employee ID
Amount
Currency
Requires Manager16. Architecture check
Your solution should look like:
text
ZCL_EXPENSE_PROCESSOR_###
↓
tt_claims
↓
LOOP
↓
lcl_claim_evaluator
↓
ty_evaluation
↓
output17. Responsibility check
Complete:
text
The global class is responsible for:
_____________________________________
The local helper class is responsible for:
_____________________________________
The local data types are responsible for:
_____________________________________18. Visibility check
Answer:
Can an unrelated global class directly instantiate lcl_claim_evaluator?
Can another class address ty_claim as ZCL_EXPENSE_PROCESSOR_###=>TY_CLAIM?
Explain why.
19. Local or global?
Decide whether each should remain local or become global.
A. Claim evaluator used only by this class pool
B. Currency conversion service used by twenty applications
C. Evaluation result type used only by the processor and helper
D. Public API result type used by many consumers
Explain each decision.
20. Repair exercise — wrong tab
A student puts:
text
lcl_claim_evaluatorin:
text
Test ClassesAnswer:
Why is this the wrong location?
What belongs in Test Classes?
21. Repair exercise — everything in main
Imagine:
text
main
├─ checks amount
├─ checks age
├─ checks receipt
├─ checks approval
└─ outputs resultExplain two disadvantages.
Then explain what improves when evaluation moves into:
text
lcl_claim_evaluator22. Repair exercise — unnecessary global helper
Suppose a student creates:
text
ZCL_CLAIM_EVALUATOR_###even though nothing outside the expense processor uses it.
Answer:
Is it technically possible?
Why might a local class be the cleaner design?
23. Repair exercise — type vs variable
Explain:
abap
TYPES ty_claim ...versus:
abap
DATA claim TYPE ty_claim.Then declare one additional variable based on:
text
ty_claimwithout copying its components.
24. Repair exercise — local vs public member type
Imagine moving:
text
ty_claiminto:
abap
PUBLIC SECTION.of the global class.
Answer:
How would another class address it?
What would become part of the global class API?
Is that desirable for this exercise?
25. Optional challenge — second local helper
Create:
text
lcl_claim_summaryIts responsibility is to summarize evaluation results.
Count:
text
approved
manager approval
rejectedKeep responsibilities separate:
text
lcl_claim_evaluator
→ evaluates one claim
lcl_claim_summary
→ summarizes many evaluations26. Optional challenge — result table type
Create:
text
tt_evaluationsas a local table type of:
text
ty_evaluationCollect results during processing and pass them to:
text
lcl_claim_summary27. Optional investigation — Class-Relevant Local Types
The required solution uses:
text
Local TypesFor an optional investigation:
- add a private reference attribute to the global class;
- type it with a local helper class;
- observe why that local definition must be available as a Class-Relevant Local Type.
Remove the experiment afterward if it makes your final solution unnecessarily complex.
28. Knowledge check
1. What is a class pool?
2. How many global classes are in one class pool?
3. What other local definitions can a class pool contain?
4. Why is lcl_claim_evaluator called a local class?
5. Where is ty_claim visible?
6. Why is ty_claim not a public type of ZCL_EXPENSE_PROCESSOR_###?
7. What is the difference between Local Types and Class-Relevant Local Types?
8. What belongs in Test Classes?
9. When should an implementation helper stay local?
10. When should you create a reusable global class instead?
29. Submission checklist
30. End-of-practice mental model
text
Class Pool
│
├─ Global Class
│ └─ orchestrates the use case
│
├─ Local Types
│ ├─ ty_claim
│ ├─ tt_claims
│ ├─ ty_evaluation
│ └─ lcl_claim_evaluator
│
└─ Test Classes
└─ reserved for ABAP UnitThe key design question is:
Does this type or helper need to be part of a reusable external API, or is it an implementation detail of this class pool?
Continue to Lesson 5 — Object APIs, Validation & Collaboration →