An exception is a problem that arises during the execution of a program. When an exception occurs the normal flow of the program is disrupted and the program application terminates abnormally, which is not recommended, therefore these exceptions are to be handled.
Exceptions provide a way to transfer control from one part of a program to another. ABAP exception handling is built upon three keywords â RAISE, TRY, CATCH and CLEANUP. Assuming a block will raise an exception, a method catches an exception using a combination of the TRY and CATCH keywords. A TRY - CATCH block is placed around the code that might generate an exception. Following is the syntax for using TRY â CATCH â
RAISE â Exceptions are raised to indicate that some exceptional situation has occurred. Usually, an exception handler tries to repair the error or find an alternative solution.
TRY â The TRY block contains the application coding whose exceptions are to be handled. This statement block is processed sequentially. It can contain further control structures and calls of procedures or other ABAP programs. It is followed by one or more catch blocks.
CATCH â A program catches an exception with an exception handler at the place in a program where you want to handle the problem. The CATCH keyword indicates the catching of an exception.
CLEANUP â The statements of the CLEANUP block are executed whenever an exception occurs in a TRY block that is not caught by the handler of the same TRY - ENDTRY construct. Within the CLEANUP clause, the system can restore an object to a consistent state or release external resources. That is, cleanup work can be executed for the context of the TRY block.
Raising Exceptions
Exceptions can be raised at any point in a method, a function module, a subroutine, and so on. There are two ways an exception can be raised â
Catching Exceptions
Handlers are used to catch exceptions.
Letâs take a look at a code snippet â
In the above code snippet, we are trying to divide Num1 by Num2 to get the result in a float type variable.
Two types of exceptions could be generated.
Attributes of Exceptions
Here are the five attributes and methods of exceptions â
Example
In this example, if the number is greater than 150, the exception CX_DEMO_ABS_TOO_LARGE is raised. The above code produces the following output for the number 160.
As we already know SAP supports multiple types of drill down reports like ABAP Interactive reports, ALV Interactive etc., in this lesson we are going to develop a drill down report with TREE structure.
Requirement: Display list of materials for a give input(Material number ranges) with descriptions in different languages in the form of a tree.
To create a TREE LIST, we use
RS_TREE_CONSTRUCT and RS_TREE_LIST_DISPLAY Function Modules
RS_TREE_CONSTRUCT is used to construct a TREE node.
RS_TREE_LIST_DISPLAY is used to display/print constructed TREE.
Final output of the TREE like looks like below.
Steps to follow to create TREE LIST
Go to SE38, create a report with name ZSAPN_TREE_MATERIAL and follow below steps.
Data DeclarationsInternal tables and work area declarations for required tables, in our requirement, we are building tree for MARA(Material) and MAKT(Material descriptions multiple languages).Get Data from required tables MARA and MAKTGet data from tables MARA and MAKT under START-OF-SELECTION event using FOR ALL ENTRIES.Construct TREE node suing RS_TREE_CONSTRUCT
Function module RS_TREE_CONSTRUCT has a table parameter with name NODETAB, this parameter holds the TLEVEL (Level of a row ex:1, 2 etc), NAME,TEXT,TEXT1,TEXT2 - TEXT9(field name ex: MATNR), NLENGTH,TLENGTH,TLENGTH1 - TLENGTH9(Length of the field ex: 18), COLOR, TCOLOR, TCOLOR1 to TCOLOR9 etc.
Note: By using RS_TREE_LIST_DISPLAY and RS_TREE_CONSTRUCT function modules, we can display maximum of 10 columns in each level.
Create Root level
Loop through IT_MARA and IT_MAKT(inside IT_MARA loop) and build level 2 and level 3
Call Function module RS_TREE_CONSTRUCT
Display TREE
Finally Display TREE by calling Function module RS_TREE_LIST_DISPLAY
Testing the above report
Final and Full program source code
Note: By using RS_TREE_LIST_DISPLAY and RS_TREE_CONSTRUCT function modules, we can display maximum of 10 columns in each level.
Learner Questions
No Questions by learners, be first one to ask .!!
Was this lesson helpful to you? Yes No 21 People out of 21 think this lesson helpful
Abend Rs Exception Sap Error
I am using RFC function to receive data from sap abap side that sending from java. There is no error from java side . Problem is i cannot capture data from sap side. i need to save those data in a sap ztable.
This is my java code.
Abend Rs Exception Sap Portal
This is my ABAP code.
ZSLATENLOG is my z table.
D.MaduD.Madu
21211 gold badge44 silver badges1919 bronze badges
1 Answer
Well I think you have to provide some more informations to answer this question but I will try it anyway.
You are using the method
createRFCFunction . Why? I would suggest to use this way to get the complete signature of your ABAP Function Module: JCoFunction function = destination.getRepository().getFunction('ZZSL_ATEND_CRT_LOG_TBL'); and eventually function.execute(destination); This way you get the meta information of the function module to call from the connected SAP System
If this is not working could you please step through the list below and post a response
I hope this will help you.
lichtbringerlichtbringer
Got a question that you canât ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Not the answer you're looking for? Browse other questions tagged javasapabaprfc or ask your own question.
When a servlet throws an exception, the web container searches the configurations in web.xml that use the exception-type element for a match with the thrown exception type.
You would have to use the error-page element in web.xml to specify the invocation of servlets in response to certain exceptions or HTTP status codes.
web.xml Configuration
Consider, you have an ErrorHandler servlet which would be called whenever there is any defined exception or error. Following would be the entry created in web.xml.
If you want to have a generic Error Handler for all the exceptions then you should define following error-page instead of defining separate error-page elements for every exception â
Following are the points to be noted about above web.xml for Exception Handling â
Request Attributes â Errors/Exceptions
Following is the list of request attributes that an error-handling servlet can access to analyze the nature of error/exception. Counter strike source lan version.
Error Handler Servlet Example
This example would give you basic understanding of Exception Handling in Servlet, but you can write more sophisticated filter applications using the same concept â
This example would give you basic understanding of Exception Handling in Servlet, but you can write more sophisticated filter applications using the same concept:
Compile ErrorHandler.java in usual way and put your class file in /webapps/ROOT/WEB-INF/classes.
Let us add the following configuration in web.xml to handle exceptions â
Now try to use a servlet which raise any exception or type a wrong URL, this would trigger Web Container to call ErrorHandler servlet and display an appropriate message as programmed. For example, if you type a wrong URL then it would display the following result â
The above code may not work with some web browsers. So try with Mozilla and Safari and it should work.
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |