Exceptions can be raised by the ABAP runtime environment,or explicitly in coding. Exception situations have many causes(e.g. cardinality violation for a context node).The exceptions are treatable or untreatable;all the unhandled exceptions cause a runtime error,a so-called short dump.
We can find all the short dumps from the system with transaction ST22,ABAPrun time error.We can find the runtime error from today and yesterday by using the two buttons“Today” and “Yesterday”,or we can search for a specific runtime error by using our selected parameters.
ABAP runtime error
Web Dynpro ABAP offers support to work with the exception classes through the methods of the Message Manager.Each exception has an explanatory text assigned to it that describes the exception.It can be an Online Text Repository OTR or a text from a message class.
We can create our own exception classes as global classes by using Class Builder or the local classes in our programms. Class-based exception handling is based on the exception classes; we have a notation specification for an exception class: its name has to begin with cx,zcx or ycx.As basic exception classes,we have CX_STATIC_CHECK,CX_DYNAMIC_ CHECK and CX_NO_CHECK.This classes are derived from the superclass CX_ROOT.
Exception Class with OTR Text
We create a WD component with the structure presented.
WD component structure
By using the view V_VIEW,we implement a search mask.The user enters the concurrent ID and receives more information about him.All the data about candidates are stored inthe database table YPERSON we have created in the ABAP Dictionary.When we don’t find in the database a concurrent with the searched ID,we raise an exception and we show a proper message.The view layout is presented.
We have defined a node Search(Singleton,Cardinality 1...1)that holds the child node PERSON and the attribute ID_PERSON. The attribute ID_PERSON has the type yperson-id_person,Input help mode Automatic.For this table field,we have assigned in the ABAP Dictionary the search help YSH_ID_PERSON.We use this attribute to hold the concurrent ID entered by the user in the search mask.
The child node PERSON (Singleton,Cardinality 0...1)has the dictionary structure YPERSON,and as attributes we have quickly almost the entire table fields(without id_person).We use this context node to hold all the concurrent data with the searched ID.To show the result information,we have created a data binding between this node and the Table UI Element.
The user enters an ID and presses the button SEARCH.If the concurrent with this ID exists in the database table YPERSON,we show in the UI Element table the proper information,otherwise we raise an exception and the corresponding error message is shown.Before working with exception messages,we have to create an exception class.
Creating an exception class
As can be seen,we create an exception class without message class.In this case,the OTR is used as a central storage area for the exception texts.In the Text tab,we create an exception text The candidate with ID:&id_candidate& doesn’t exist,with the ID:YCX_NO_CANDIDATE.
Defining exception texts
Each exception text we create in the Texts tab consists of an ID and a corresponding text.The placeholder &id_candidate&is replaced at runtime by the content of the attribute with the same name defined in the Attributes tab.
When the user presses the SEARCH button,the Framework triggers the event handler method onactionsearch.
Coding of event handler method
After defining the data,we pass the value of the attribute id_person in the local variable lv_id_person.By using the TRY ENDTRY control structure,we handle a possible exception that can occur.We use open SQL to select all the data from the database table YPERSON into the internal table lt_candidate,where the field id_person is the same with our searched ID.
If we find this record in our database table,we populate the child node PERSON,because no exception occurs in the TRY block andthe system continues the processing after ENDTRY. Otherwise,a class-based exception occurs in the TRY block and the system searches for an exception handler.With RAISE EXCEPTION,we can raise an exception explicitly from our WD method.
RAISE EXCEPTION TYPE ycx_exception_otr_txt
EXPORTING textid = ycx_exception_otr_txt=>ycx_no_candidate id_candidate = lv_id_person.
This exception is caught in the CATCH block of the same TRY control structure:CATCH ycx_exception_otr_txt INTO obj.Because the additional INTO is specified,a reference to the exception object is stored in obj,where obj is the object reference variable.
After this,we use the method REPORT_EXCEPTION of the
IF_WD_MESSAGE_MANAGER interface to report a WD exception.
We present the execution result.The first picture represents the runtime where the exception occurs in the TRY-ENDTRY control structure,and the second picture represents the case when no exception occurs.In the second scenario,we can show,in the same time,the result of the Search help created in the ABAP Dictionary and attached to the id_person field of our database table YPERSON.
Exception Class with Text from a Message Class
We create the same WD component, but in this case we use an exception class with text from a message class. In this case,the interface IF_T100_MESSAGE is automatically included in the class definition. Figure shows the creation of an exception class by using Message Class.
Creating an exception class
In the “Properties”tab of the exception class,we have to enter the name of the message class we use.
Message class assignment
Each exception ID can be mapped to a message class and message ID.To do this,we have to use the Button Message Text.We assign the exception class attribute ID_CANDIDATE to the message class YCL_T100_MSG,message number 000.The placeholder and is replaced at runtime by the content of the ID_CANDIDATE attribute.
After activation,we can use this exception class in our WD component.Exception texts based on message classes are basically used in the same way as the exception texts thatuse OTR texts.When the user presses the SEARCH button,the Framework triggers the event handler method onactionsearch that has the same structureas the Listing.The only modification we have to do is to change the name of the exception class raised when an exception occurs.
Assigning attributes of an exception class to a message
Listing Exception handling
SAP ABAP Web Dynpro Related Tutorials
|SAP ABAP Tutorial|
SAP ABAP Web Dynpro Related Interview Questions
|SAP ABAP Interview Questions||SAP ABAP Web Dynpro Interview Questions|
|Sap Abap Hr Interview Questions||SAP ABAP Dictionary Interview Questions|
|SAP ABAP Enhancement Interview Questions||SAP ABAP Module Pool Interview Questions|
|SAP ABAP Report Developer Interview Questions||SAP ABAP Data Dictionary Interview Questions|
|SAP ABAP ALV Reports Interview Questions|
Sap Abap Web Dynpro Tutorial
Sap Easy Access
Designing A Web Dynpro Component
Context Nodes And Attributes At Design Time
Data Binding, Context Mapping And Interface Methods
View Controller Methods
Layout Ui Elements
User Interface Elements (ui Elements) Static And Dynamic Programming
Messages, Exceptions And Web Dynpro Abap
Writing Multilanguage Applications
Alv And Select Options
Integrating A Web Dynpro Application Into The Sap Netweaver Portal
Web Dynpro And Authorization
Web Dynpro Mind Map
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.