Skip to content

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 class

Scenario:

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 separation

Practice information ​

Recommended timeAbout 2.5–3 hours
EnvironmentSAP BTP ABAP Trial
Global classZCL_EXPENSE_PROCESSOR_###
Local helperlcl_claim_evaluator
Main focusLocal types + local class design

1. Create the global class ​

Create:

text
ZCL_EXPENSE_PROCESSOR_###

Description:

text
Expense Claim Processor

Implement:

text
IF_OO_ADT_CLASSRUN

The global class should be responsible for:

text
creating input
calling the evaluator
displaying results

2. Open Local Types ​

Open:

text
Local Types

Do not put the helper in:

text
Test Classes

Do 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
urgent

Suggested 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_bool

4. Create tt_claims ​

Define:

text
tt_claims

as a standard internal table of:

text
ty_claim

with:

text
EMPTY KEY

5. Create ty_evaluation ​

Define another local structured type containing:

text
claim_no
accepted
requires_manager
decision
message

Suggested types:

abap
claim_no         TYPE string
accepted         TYPE abap_bool
requires_manager TYPE abap_bool
decision         TYPE string
message          TYPE string

6. Create the local helper class ​

Create:

text
lcl_claim_evaluator

Its public method:

text
evaluate

must:

text
IMPORT ty_claim
RETURN ty_evaluation

The evaluation rules belong in this local class.

Do not put them in main.

7. Rule A — amount ​

If:

text
amount <= 0

then:

text
accepted = false
decision = REJECTED
message  = Amount must be greater than zero

Do not continue evaluating that claim.

8. Rule B — age ​

If:

text
days_old > 60

then:

text
accepted = false
decision = REJECTED
message  = Claim is older than 60 days

Do not continue evaluating that claim.

9. Rule C — receipt ​

If:

text
amount > 25

and:

text
receipt_attached = false

then:

text
accepted = false
decision = REJECTED
message  = Receipt is required for claims over 25

Do not continue evaluating that claim.

10. Rule D — manager approval ​

If the claim passed all rejection rules:

text
accepted = true

Manager approval is required when:

text
amount >= 500

or:

text
urgent = true

Then return:

text
requires_manager = true
decision = MANAGER APPROVAL

Otherwise:

text
requires_manager = false
decision = APPROVED

11. Currency assumption ​

Do not implement currency conversion.

Treat:

text
amount
currency

as input data.

Use:

text
EUR

for 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 missing

13. Suggested test cases ​

ClaimAmountReceiptDays oldUrgentExpected
CLM-00118No5NoApproved
CLM-002720Yes12NoManager approval
CLM-00390Yes3YesManager approval
CLM-0040Yes2NoRejected
CLM-005120Yes75NoRejected
CLM-00680No10NoRejected

14. Implement the global orchestration ​

In:

text
IF_OO_ADT_CLASSRUN~MAIN

the global class should:

  1. create the tt_claims table;
  2. create one lcl_claim_evaluator object;
  3. loop over the claims;
  4. call evaluate;
  5. output every result.

15. Output requirements ​

For every claim, output at least:

text
Claim Number
Decision
Message

Optional:

text
Employee ID
Amount
Currency
Requires Manager

16. Architecture check ​

Your solution should look like:

text
ZCL_EXPENSE_PROCESSOR_###
        ↓
     tt_claims
        ↓
       LOOP
        ↓
lcl_claim_evaluator
        ↓
   ty_evaluation
        ↓
      output

17. 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_evaluator

in:

text
Test Classes

Answer:

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 result

Explain two disadvantages.

Then explain what improves when evaluation moves into:

text
lcl_claim_evaluator

22. 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_claim

without copying its components.

24. Repair exercise — local vs public member type ​

Imagine moving:

text
ty_claim

into:

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_summary

Its responsibility is to summarize evaluation results.

Count:

text
approved
manager approval
rejected

Keep responsibilities separate:

text
lcl_claim_evaluator
→ evaluates one claim

lcl_claim_summary
→ summarizes many evaluations

26. Optional challenge — result table type ​

Create:

text
tt_evaluations

as a local table type of:

text
ty_evaluation

Collect results during processing and pass them to:

text
lcl_claim_summary

27. Optional investigation — Class-Relevant Local Types ​

The required solution uses:

text
Local Types

For an optional investigation:

  1. add a private reference attribute to the global class;
  2. type it with a local helper class;
  3. 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 Unit

The 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 →