In this section we will discuss all the SAP MM Tcodes. These transactional codes are sub divided into groups for your better understanding. Feel free to ask the Tcodes which we have missed in the comment section.
Material Master Tcodes
Create material master : MM01
Change material master : MM02
Display material master : MM03
Material master list : MM60
Display Material document : MB03
Vendor Master Tcodes
Create vendor master : XK01
Change vendor master : XK02
Display vendor master : XK03
Source list Tcodes
Maintain source list : ME01
Display source list : ME03
Change source list : ME04
Purchase Requisition Tcodes
Create Purchase Requisition : ME51N
Change Purchase Requisition : ME52N
Display Purchase Requisition : ME53N
Release Purchase Requisition : ME54
Collective release of Purchase Requisition : ME55
Assign source of supply to requisitions : ME56
Request for Quotation Tcodes
Create Request for quotation : ME41
Change Request for quotation : ME42
Display Request for quotation : ME43
Purchase Order Tcodes
Create Purchase Order : ME21N
Change Purchase Order : ME22N
Display Purchase Order : ME23N
Release Purchase Order : ME29N
Reservation Tcodes
Create Reservation : MB21
Change Reservation : MB22
Display Reservation : MB23
Reservation by Material : MB24
Reservation by Account Assignment : MB25
Goods Receipt Tcodes
Create Goods Receipt : MIGO
Cancellation/display Goods Receipt : MIGO
Physical Inventory Document Tcodes
Create Physical Inventory Document : MI01
Change Physical Inventory Document : MI02
Display Physical Inventory Document : MI03
Enter Inventory Count : MI04
Change Inventory Count : MI05
Display Inventory Count : MI06
Post Inventory Difference : MI07
List of Inventory Difference : MI20
Invoice Verification Tcodes
Display Of Invoice Document : MIR5
List Of GR/IR Balance : MB5S
MM configuration Tcodes
Create Company : OX15
Create Company Code : OX02
Create Plant : OX10
Create Storage Location : OX09
Create Purchasing Organization : OX08
Create Purchasing Group : OME4
Assign Plant to Company Code : OX18
Assign Purchasing Organization to Company Code : OX01
In the SAP ERP, SAP MM Organizational Structure is used to represent the legal and organizational structure of the company. The organizational structures form a framework according to which the whole business runs.
The organizational structure in Material management consists of the following levels:
Client
Company Code
Plant
Storage location
Purchasing Organization
Purchasing Group
The following diagram represents the organizational structure of SAP MM:
SAP MM Organizational Structure
Let’s discuss them briefly.
Client
A client is a group or combination of legal, organizational, business and/or administrative units with a common purpose. It is the highest hierarchy of the organizational structure in SAP.
Company code
A company code represents an independent unit within a client. This organizational unit is created in finance and the same is linked with the Materials Management module. Each company code maintains its own balance sheet and its own profit and loss statement.
Plant
A plant is an operational unit in a company code. In SAP, the plant is a broad term depending on the functionality. As in Material management, it is referred to as a facility where materials are stored, and inventory is maintained. Whereas in the Production planning module, it is referred to as a facility where materials are produced.
Storage location
A storage location is an organizational unit where stocks are kept physically, and inventory is maintained. A plant can consist of multiple storage location which differentiates between different materials are stocked in a plant.
Purchasing Organization
A purchasing organization is an organizational unit responsible for procuring materials/services for one or more plants. It is responsible for negotiating general conditions of purchase with vendors and holds legal responsibility for all external purchase transactions.
Purchasing organizations can be centralized or decentralized. In centralized, a single purchasing organization is assigned to one or more plant whereas in decentralized, different purchasing organization is assigned to a different plant.
Purchasing group
A purchasing group is an organizational unit responsible for day-to-day procurement activities in an organization. It may be an individual or group of individuals responsible for carrying out procurement activities.
Preface – This post is part of the ABAP Beginner series.
Introduction
As discussed in the earlier article i.e. Search Help in SAP ABAP, a search Help in SAP ABAP are reusable objects that are used to assign input helps (F4 helps) to screen fields. If the data for the search help is bought from combination of many elementary search help, then it will be termed as Collective Search Help.
Definition
As the name suggest a collective search help is a collection of multiple elementary search helps. It can even be a combination of elementary search help and another collective search help.
Below is the example of how it works (data exchange works):
It has an import and export parameter, the data is exchanged between the input screen template and the parameters of the assigned elementary search helps using this interface.
Steps to Create a Collective Search
Go to SE11
Search help name -> Create -> Choose a type (here, collective)
Maintenance screen of collective search help will open -> Give a short description to find your collective search help
In the definition tab -> Enter a search help parameter (can be elementary help or collective help) -> if it is an import parameter then check it and if it is an export parameter then check it.
Describe the data element to denote the types of elementary search help.
Now go to included Search help tab -> select an elementary search help
Parameter assignment-> Now system automatically maps elementary search help reference parameter to collective search help parameter -> now click on copy -> Activate.
The search help is ready to use.
Search Help Exit
When you want to use search help beyond normal hits, then we need something called Search Help Exit.
For example: For current run time data, I want to know the availability of flight seats with the prices enlisted in it. This might not be possible with the normal flow as the data would be fetched in tables containing either no of seats or costs separately.
In this case we will use Search Help Exit.
It is a well-designed function module with interface same as F4IF_SHLP_EXIT_EXAMPLE. It is called several times by the help processor.
Preface – This post is part of the ABAP Beginner series.
Introduction
As discussed in the last article i.e. Search Help in SAP ABAP, a search Help in SAP ABAP are reusable objects that are used to assign input helps (F4 helps) to screen fields. If the data for the search help is bought from a single table, structure or view and is displayed based on a condition, then it will be termed as Elementary Search Help.
Definition
As the name suggest an elementary search help reads records from a single element and that can be a table, structure or a view and based on a condition it returns records which are displayed by a dialog box.
Steps to Create an Elementary Search Help:
Go to SE11-> Choose Search Help-> Give a Name-> Click Create-> Choose types of search help-> Elementary-> (u will be directed to the maintenance screen of search help).
Elementary Search Help in SAP ABAP
Under the definition, tab give a description (It will help to get your Search Help identified).
Selection Method
One can choose a SE11 Table,
A View (Database, Projection or Help View)
If you enter a table that has a text table (language specific tables) it will automatically mention its name.
Dialog behavior
Display values immediately -> hit list displayed immediately, best suited for small entries.
Dialog with value restriction -> if the list of possible entries is large, user can limit the data to be processed to prevent system load.
Dialog depends on set of values -> If the hit list contains less than 100 entries, if the hit list contains more than 100 entries the system displays the dialog box for restricted values.
Dialog behavior
Selection parameters
Choose and select the fields through drop- down list from the selection method (tables, views) that is to be displayed in the selection screen.
IMP (Importing Parameters)
The input value/field is passed to the search help.
EXP (Exporting Parameters)
Export values back to the input help when the user selects an option or a row.
LPOS (List position)
Position on the output list (hit list) the user selects from.
SPOS (Screen position)
Position of parameters for value selection in the dialog box.
Default
To display default values (date, system-fields (values of structure SYST)).
Save -> Activate -> Test.
Use of an Elementary Search Help
Defines the standard flow of an input help.
Following components can be defined in search help.
Selection Method
Through this you can choose the data in the hit list where it can come from.
Dialog behavior
Choose the information displayed in the hit list and in the dialog box.
Selection parameters
Fields you can choose for hit lists and values to be displayed in the hit list that can be returned in screen fields.
Procurement starts with requirement gathering and ends with procuring goods/services from vendors. This involves an internal document that contains a list of requirements, be it goods or services, which need to be procured from the vendors, known as Purchase requisition. It is a request made to the purchasing department to procure a certain list of materials. It contains information about the materials such as the date of delivery, and quantity.
A purchase requisition is defined for the following procurement types:
Standard: Requisition created for getting finished material from the vendor.
Subcontracting: Requisition created for providing raw material to the vendor and getting finished material.
Consignment: Requisition created for procuring material that is kept in the company’s premises and paying to the vendor for that.
Stock transfer: Requisition created for transferring stocks from one plant to another.
External service: Requisition created for procuring services like maintenance from third-party vendor.
Creation of Purchase requisition
A purchase requisition can be created manually (with or without master data) or automatically. Let’s explore them one by one.
Manual creation of Purchase requisition
A purchase requisition can be created manually means when the purchasing document is created by the requesting department manually.
A purchase requisition can be created manually in multiple ways:
Purchase requisition with master data:
Step 1: Enter T-code ME51N in common field. A “Create purchase Requisition” screen will appear.
Step 2: It will ask to enter the following information:
The material number of item or service (e.g. B-R123)
Quantity to be procured (e.g. 20)
Delivery date of the material (e.g. today’s date + 3)
Plant location (e.g. 1203)
Step 3: On hitting enter, the data of the material is fetched from the material master data and the requisition process will fill up the default information in some of the blank fields.
After clicking on “Save”, a new purchase requisition will be created.
Purchase requisition without master data:
Step 1: In order to do that, enter T-code ME51N in common field. A “Create purchase Requisition” screen will appear.
Step 2: As there is no material master record for the material the following information will have to be entered:
Account assignment category (e.g. U)
Short text for description (e.g. Laptop Dell with an i5 processor)
Quantity to be Supplied (e.g., 4)
Unit of measure (e.g. PC)
Delivery date of the material (e.g. today’s date + 4)
Material group (e.g. Testing)
Plant location (e.g. SAP SE)
Purchasing group (e.g. 011)
In this scenario, the account assignment category is required to direct the cost to a specific account. Use ‘U’ to direct the purchase requisition to an unknown account. Other options available are:
A for Asset and sub number
F for production order number
K for cost center and general ledger account number
C for sales order and general ledger account number
P for project number and general ledger account number
Step 3: Press Enter, an error message will appear in the form of a red mark on the item line (in the column Status). Provide Valuation Price and hit enter again. The error message will disappear now.
After clicking on “Save”, a new purchase requisition will be created.
Automatic creation of Purchase requisition:
A purchase requisition can be created automatically means when the purchasing document is created by other SAP processes that include:
Production Order: A production order defines what materials need to be produced, the quantity of goods to be required, where it needs to be produced and at what time.
On creation of Purchase order in PP, BoM (Bill of Materials) is determined and a purchase requisition is created for materials required through MM.
Plan Maintenance Order: A maintenance order consists of a list of operations that specifies what needs to be done and the material needed for each step. There may be a need for non-stock material. So, a purchase requisition is created automatically.
Project System: In the Project system of Sap, a network is an object that creates a purchase requisition for non-stock materials.
Material Planning: The consumption-based planning module can create a purchase requisition for materials based on calculation.
Under Inventory Management in SAP MM, Procurement starts with requirement gathering and ends with procuring goods/services from vendors.
Once the goods/services are procured from the vendor, it is required to place them at the company’s premises. Inventory management deals with the management of the stock and goods movement, either on value or quantity basis. It includes planning and keeping records of all the goods movement.
There are several transactions and functions in inventory management. The most important of them are:
Movement Types
Goods Receipt
Reservation
Goods Issue
Let’s explore them one by one.
Movement Types
When goods movement is entered into the system, a movement type is defined to differentiate between the various goods movement. It is a 3-digit identification number for goods movement.
When a goods movement is entered into the system, following chain of events starts in the system:
A material document is generated, that updates all the stock quantity and value in the inventory.
Accounting documents are generated if the movement is relevant to Financial accounting.
The stock quantities are updated.
The stock values in the master record are updated.
All the updates are based on the information contained in the material document and the financial account document.
The important movement types are:
101: Goods receipt(GR) for purchase order(PO) into warehouse/stores
102: Goods receipt(GR) for purchase order(PO) into warehouse – reversal
201: Consumption for cost center from warehouse
To know more movement types, enter T-code MIGO in common field. A new screen will appear.
Select “Goods receipt” from the drop-down. On pressing F4 on the goods receipt input box, a list of movement types will appear. Depending upon the requirement, select the appropriate movement types for different goods movement.
Movement Types: Inventory Management in SAP
Goods Receipt
After receiving the material from the vendor, the purchasing department prepares a goods receipt that can be used later for any discrepancy. A goods receipt is a goods movement that is used to post goods received from the external vendors or from in-plant production which results in an increase in stock in the warehouse.
Goods receipt has 2 scenarios:
Creation Goods receipt
Cancellation of Goods receipt
To create a Goods receipt
Step 1: Enter T-code MIGO in common field. A new screen will appear.
A Goods receipt can be posted against various documents. Select the required document from the drop-down list. Select the movement type as per the requirement.
MIGO Goods Receipt: Inventory Management in SAP
Step 2: Enter reference document. Based on the reference document, it will fetch all the details such as material, quantity, storage location, plant, etc.
Enter Details Goods Receipt: Inventory Management in SAP
Step 3: Select the check tab and click on Save.
After click on “Save”, goods receipt is posted against the selected document and a material document number is generated.
To cancel a Goods receipt
Step 1: Enter T-code MIGO in common field. A new screen will appear.
Select “Cancellation” against the material document from the drop-down list. Enter the material document number.
MIGO Cancel a Goods receipt: Inventory Management in SAP
Step 2: The system will fetch all the details from the material document number.
Cancel a Goods Receipt: Inventory Management in SAP
Step 3: Select the check tab and click on “Save”.
After clicking on “Save”, the goods receipt is cancelled, and a material document number is generated.
Reservation
Reservations are made to block the materials in advance so that that they can be available at some particular time. It ensures the availability of the stock at a particular point of time.
T-code to view the reserved quantity is MMBE.
To make a reservation
Step 1: Enter T-code MB21 in common field. A “Create Reservation” screen will appear.
Enter the date, the movement type and the plant for which the reservation has to be made. Click on the “New Items” button.
MB21 Make A Reservation: Inventory Management in SAP
Step 2: Enter the order number against the reservation has to be made. Provide details of the materials and the quantity that has to be reserved.
Create Reservation: Inventory Management in SAP
After clicking on “Save”, a reservation has been made for the order.
Goods Issue
To post Goods Issue
Step 1: Enter T-code MIGO in common field. A new screen will appear.
Select Goods Issue from the drop-down list. A Goods Issue can be posted against various documents. Select the required document from the drop-down list. Select the movement type as per the requirement.
MIGO Goods Issue: Inventory Management in SAP
Step 2: Enter reference document. Based on the reference document, it will fetch all the details such as material, quantity, storage location, plant, etc.
Enter Reference Document Goods Issue: Inventory Management in SAP
Step 3: Select the check tab and click on Save.
After click on “Save”, Goods Issue is posted against the selected document and a material document number is generated.
Before we discuss about Master Data in SAP MM, let us discuss about type of Data in SAP.
SAP R/3 works on real-time data i.e. it makes sure that there is no time lag between data availability and data storage.
Data stored in SAP R/3 is categorized as:
Master data: Data that is created centrally and is the core used as base data for any transaction is called Master Data in SAP. For example, Material and Vendor are types of master data.
Transactional data: Data that is related to business transactional processes.
Types of Master Data
Material Master data
Vendor Master data
Material Master Data
Materials in SAP are a logistic representation of certain goods/services that is an object of production, sales, inventory management, etc. Material master data is the central source of information of the material that an enterprise can procure, produce or sell.
Characteristics of material master data are:
Material types: Materials having some basic common attributes are grouped together and are assigned a material type. Most common material types are:
M Type
Material type description
FERT
Finished Product
HALB
Semi-finished Product
ROH
Raw material
Material group: A material group is a wider term for a material type. Materials with some common attributes are grouped together and are assigned a material group. Let’s take an example of a finished product (material type), TV. Then the material group can be used to categorize them as Plasma TV, color TV etc.
Number Range: When a material master record is created, a unique number is assigned to the material, known as material number.
The following are the two ways to assign material number.
External number assignment: When material number is assigned manually while creating a material.
Internal number assignment: The system automatically assigns the material number while creating a material.
Internal number assignment is known as Number range.
Steps to create Material Master Data
Step 1: Enter T-code MM01 in common field. A “Create Material” screen will appear.
Enter all the information such as Material number, Material type, Industry sector, etc.
MM01: Master Data in SAP
Step 2: Select the views to maintain the material.
Maintain the Material: MM01: Master Data in SAP
Step 3: Enter plant name and storage location for the material.
Enter Plant Name: Master Data in SAP
Step 4: Provide the necessary details such as moving price, standard price, unit of measure, etc.
Click on “Save” and new material is created.
New Material Creation: Master Data in SAP
To change or display material master data, use T-code MM02 and MM03 respectively.
Vendor Master Data
A vendor is the one who provides goods/ services to a company. Vendor master data is the central source of information of the vendors from an enterprise can procure. It contains information such as name, address, the currency for the transaction, payment terms, Tax details, etc.
Data in a vendor master record is categorized into:
General Data − It is maintained at the client level and is valid at all organizational levels.
Accounting Data − It is maintained at the company level and is valid for all plants belonging to that company.
Purchasing Data − It is maintained at the purchasing organization level.
Characteristics of vendor master data are:
Account group: Vendors having some common attributes are grouped together and are assigned an account group.
Number range: When a vendor master record is created, a unique number is assigned to the vendor, known as vendor number. A vendor number is assigned to a vendor as in the case of the material number i.e. external number assignment and internal number assignment.
Steps to create Vendor Master Data
Step 1: Enter T-code XK01 in common field. A “Create Vendor” screen will appear.
Enter all the information such as Vendor number, Company Code, Purchase Organization, Account Group, etc.
XK01: Master Data in SAP
Step 2: Provide address details of the vendor.
Create Vendor: Master Data in SAP
Step 3: provide bank details, accounting information, terms of payment between the company and the vendor. Click on “Save” and a new vendor is created.
New Vendor Creation: Master Data in SAP
To change or display vendor master data, use T-code XK02 and XK03 respectively.
Preface – This post is part of the ABAP Beginner series.
Introduction
Before we start with Transport Request in SAP, let us discuss basic concepts of coding environements/landscapes in SAP. In SAP ERP, we have three landscapes: Development, Quality and Production.
Development landscape is where a developer develops his/her codes/programs.
Quality landscape is where a developer/tester tests his/her codes/programs.
The production is where users actually use the programs made by developer.
These landscapes give us flexibility to develop, test and run our under-development code before actually giving to the end user. In this way we can find and fix bugs that can actually cause crashes and dumps.
Now, to make a connection between these landscapes and to transfer our code, SAP provides us something known as Transport Request.
What is a Transport Request in SAP?
A transport request is a package where a user can register changes done. It is used in order to transfer data from one installation to the other.
Whenever we do a small or major change that can be an update an SAP user has to create TR.
TR holds change tasks that can be understood by a folder that holds files.
Syntax
<SID>K<NUMBER>
SID: System ID
K: After releasing TR creates a data file and co-file where data file holds database details and co file contains controlling data.
NUMBER : Starting with 900001(randomly generated).
Category of Transport Request
A TR can hold n number of sub request tasks categorized as:
Modifiable
A task is not released yet.
One can add more tasks and complete them before TR is finally released.
Released
Tasks are completed and then it is released by the owner.
One cannot do changes and send it to the target system.
Types of Transport Request
TR is preferably created in two types, but we will discuss others too.
Workbench
TR created as workbench request is cross-client i.e. changes done for one client reflects in the other client.
It is synonymously said that this type of request is created by technical
Customizing
TR created as Customizing request is client specific i.e. changes done for one client won’t reflect the other client.
A client copy has to be created using T-CODE SCC1.
Client number can be seen next to this type of request
It is said that this type of request is created by a functional person
Preface – This post is part of the ABAP Beginner series.
Introduction
Whenever a SAP coder writes a program. At the time of execution, if it gives a dump or runtime error then SAP debugger is a tool to check your lines of codes and examine error during runtime. Debugging in SAP ABAP helps a programmer to check his program flow at runtime.
We use ABAP debugger by default after the release of SAP 7.0.
Definition
In short, we can define as:
A tool to analyze ABAP programs.
A tool to examine errors in codes during runtime.
A tool to display data objects.
A tool to understand the flow logic of codes in a program while executing.
Stepping through a program with the debugger helps you to detect and correct errors in the source code of an ABAP program.
What is a Breakpoint?
A signal which tells the runtime processor to interrupt processing and start debugging.
It gets activated when the program reaches that point.
How can we debug
By setting a breakpoint
Start the debugger by setting and managing the breakpoints and executing the code.
By running the program debugging mode
We can enter the debugging mode by using \h from any screen.
This can be done when we want to check the program from the beginning and are not familiar with the program.
Types of Breakpoints
There are two types of breakpoints:
A. Static Breakpoint
This breakpoint is not specific to a user.
To use a static breakpoint use ABAP Keyword BREAK-POINT.
Place it in the line where you want to use the breakpoint.
EXAMPLE:
PROGRAMM Z_USERDATA.
…..if sy-subrc<>0 .
BREAK-POINT.
endif.
….
If you want to set a static break-point specific to a user.
BREAK-POINT username.
NOTE:
Kindly delete the static breakpoints manually in development system itself, else it might affect the program in the production system.
B. DYNAMIC BREAKPOINT
These are breakpoints that are triggered when the program that you are running reaches a particular ABAP statement or exception class.
When debugging session is finished it gets deleted automatically.
U can set a dynamic breakpoint, either in an ABAP editor or directly in the debugger.
c.1. For setting dynamic breakpoints in ABAP editor.
c.1.1 Position the cursor on the line of source code where you want to set the break-point.
c.1.2. Go to utilities->breakpoint->Set/Stop. The system confirms that breakpoint is set.
c.2. For setting a dynamic break point in debugging mode:
c.2.1- Position the cursor on the line where you want to set the breakpoint.
c.2.2- Select the line by double -clicking it or by choosing Breakpoint-> set/delete.
NOTE: A user can set 30 dynamic breakpoints without changing the program code.
Session breakpoint Specific to a particular ABAP user session. If the user session is ended (log off sap system) all session breakpoints get deleted.
External breakpoint They are applied to the current user session as well as future user sessions.
e.1. Works in sessions initiated with RFC or HTTP requests or any other external interface.
e.2. An external breakpoint can apply to:
e.2.1.A user in the current SAP system
e.2.2. A user in the current application server of the current SAP system
e.2.3. User sessions started by a request that has a specific terminal ID.
NOTE: Session, External breakpoints can be created at runtime and can be activated/deactivated.
Special KEYS in Debugging
Debugging in SAP ABAP – Image Illustration
F5- Executes a program line by line.
F6- Executes a function module or a subroutine without entering into it.
F7- Executes a module or a program in a single step.
F8 – Executes a program directly. If there is more than one break-point, then can move to one break-point to the other.
To understand an exception class, we need to understand what is an exception and when it is raised.
When we execute any program, some discrepancies can occur due to which a normal flow of execution gets interrupted and the behavior will not be the same as it was expected. That discrepancy is like an event which is occurring due to some reason, which is known as an ‘Exception’.
It is required to handle such discrepancies in order to prevent the execution flow of any program. In order to achieve that, SAP ABAP has a special class known as an ‘Exception Class’.
Exception Classes can be defined in a global class as well as in a local class. There are three exception classes exists, which are the subclasses of one root class ‘CX_ROOT’. Those three exception classes are:
CX_STATIC_CHECK – which is being checked by both compiler and runtime system.
CX_DYNAMIC_CHECK – Checked only at runtime system. All System exceptions will come under this exception.
CX_NO_CHECK – This type will be chosen if exceptions are frequent.
Definition
An Exception class is used to handle the discrepancies(exception) occurs during the execution a of program.
Whenever an exception occurs, an object is created (known as an exception object). The attributes of this object would contain information about the error. This exception can be caught by using TRY….CATCH…..ENDTRY block.
TRY….ENDTRY block contains a protected area, where an exception can be caught using the CATCH statement. One TRY….ENDTRY block can catch more than one exception, but it should get caught in a sequence in which it occurs.
There are two types of exception handling cases:
One where the exception was raised, deleted before or after handling it.
The other, where an exception which was raised is retained and the program is resumed after the statement that raised an exception.
Program
Let’s take an example of a simple arithmetic operation of two numbers. An exception should be raised if one of the two operands is missing.
NOTE: A local class is used in below sample program.
REPORT ztest_exception.
CLASS lcx_missing_operand DEFINITION
INHERITING FROM CX_STATIC_CHECK.
ENDCLASS. “lcx_missing_operand DEFINITION
CLASS lcl_test_exception DEFINITION.
PUBLIC SECTION.
METHODS: add_numbers IMPORTING iv_num1 TYPE i OPTIONAL
iv_num2 TYPE i OPTIONAL
RETURNING VALUE(rv_calc) TYPE i
RAISING lcx_missing_operand
PRIVATE SECTION.
METHODS: do_check RAISING lcx_missing_operand.
DATA: lv_num1 TYPE i,
lv_num2 TYPE i,
lv_result TYPE i.
ENDCLASS. “lcl_test_exception DEFINITION
CLASS lcl_test_exception IMPLEMENTATION.
METHOD add_numbers.
v_num1 = iv_num1.
v_num2 = iv_num2.
me->do_check( ).
rv_calc = v_result.
ENDMETHOD.
METHOD do_check.
IF v_num1 IS INITIAL.
RAISE EXCEPTION TYPE lcx_missing_operand.
ENDIF.
ENDMETHOD.
ENDCLASS. “lcl_test_exception IMPLEMENTATION
START-OF-SELECTION.
DATA: lo_obj TYPE REF TO lcl_test_exception.
DATA: lo_exc_root TYPE REF TO CX_ROOT.
DATA: lv_msg TYPE STRING.
CREATE OBJECT lo_obj.
TRY .
lo_obj->add_numbers( iv_num1 = 10 ).
CATCH lcx_missing_operand.
WRITE: / ‘Operand is missing’.
CATCH CX_ROOT INTO lo_exc_root.
lv_msg = lo_exc_root->get_text( ).
WRITE: / lv_msg.
ENDTRY.
Advantages
With exception classes, you can track the sequence of called methods. Since in exception class, we have try-end-try block, so we can put the called methods in it, to know if one of them get failed.
An exception class has an advantage that non-OO programmers won’t understand your code, increasing your job security a little.