cancel
Showing results for 
Search instead for 
Did you mean: 

Raising Exceptions and Assistance classes

Former Member
0 Kudos

Hi everyone. I know that the WDA framwork will not let me declare a raising clause in the method signature. However, during checks in the component i usually declare some code like this which is not pretty:

The methods below were declared in the view controller.

*---this method is called from DOBEFOREACTION method

METHOD validate_view_fields .

DATA: l_returncode TYPE sysubrc.

CALL METHOD validate_required_fields(

IMPORTING

e_returncode = l_returncode ).

IF l_returncode <> 0.

e_returncode = l_returncode.

ENDIF.

-more code down here-

ENDMETHOD.

I would like the framework to call a method and if something goes wrong I do not want to proceed further down the code or navigate. If I could declare exceptions I could handle this pretty easily.

If assistance classes or model classes are the answer then would I be able to read the context from those classes? I've also read that passing references of the web dynpro controllers to the assistance class could produce some problems.

What's the best way to check the view fields and to prevent going further with the subsequent code if an exception condition is found?

Thanks! Generous points will be awarded!

Accepted Solutions (1)

Accepted Solutions (1)

former_member215843
Active Participant
0 Kudos

Hi Alexander,

The best way to check the input fields and prevent the framework from calling further methods is this:

Check the values in WDDOBEFOREACTION. In this method you can check the name of the action, if it is an action of the same view. Maybe you want to skip testing, if the user pressed the CANCEL button or something similar.

Report the message as an error message attached to an attribute. Then the next methods (e.g. event handler) will not be called, and therefore no navigation will take place.

If this does not work as described here, you should check your basis support package. It should be SP11 or higher.

Ciao, Regina

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi guys. Yup I know the message manager prevents the navigation of the view but it does not prevent the processing of subsequent statements after the call to the message manager. For example in ABAP Dynpro, when you trigger an error message the error message is displayed and the code does not continue on. Is there a similar technique in WDA?

If we could use exceptions in the WDA methods then I would not run into this problem as when an exception is raised in a try block, all subsequent statements are not executed because the runtime immediately proceeds to the catch block.

Hoping for your valuable inputs. Thanks again.

shwetars
Advisor
Advisor
0 Kudos

Hi Alexander,

anyways you are going to raise the exception within an if block i assume, at the end of the method call you can write a RETURN or EXIT statement to stop execution.

if this doesn't satify you then you will have to go ahead with the approach suggested by Nithya.

For raising exceptions or error messages, message manager is the only interface provided by the WDA framework and it is the suggested way too.

Regards,

Shweta

Former Member
0 Kudos

To stop further processing, go ahead and use a RETURN statement. I think thats the simplest approach.

Also, check out the method report_exception in if_wd_message_manager. I think it would simulate the exceptions that we have in normal ABAP code.

Regards

Nithya

Former Member
0 Kudos

Hi,

if you want to just do validation then it is good idea to use REPORT_ATTRIBUTE_....

kind of message as they will point to the attribute where the validation has failed.

There are also exception messages available..

May be you can check the link below for all type of messages available

http://help.sap.com/saphelp_nw04s/helpdata/en/77/3545415ea6f523e10000000a155106/frameset.htm

Former Member
0 Kudos

Hi Alexander.

You should be able to raise excetions in ur controller methods if they are of the type

CX_NO_CHECK. Then these exceptions do not have to be declared explicitly in the signature.

But for your example I would use Regina's solution.

Have a nice weekend,

Sascha

shwetars
Advisor
Advisor
0 Kudos

Hello Alexander,

reporting error messages using the methods of the interface if_wd_message_manager also prevents further processing.

you can check out the methods raise_exception, report_fatal_exception, report_error_message etc.

you can use code wizard to generate the code required to use these methods.

Regards,

Shweta

Former Member
0 Kudos

Hi Alexander,

You can have a class with static methods that raise exceptions. In your Web Dynpro method, just call these classes, in case of exceptions, raise error messages and execute the return statement. That will suffice to prevent further processing.

For eg, if you want have a simple login view and take the user to the details view after validating the login info, you can read the context, pass the username and password to your static method, if an exception is raised, just give an error message. This will help the user stay in the same view. If no exception is raised, fire an outbound plug.

You have to read the context, I dont think it can be read from the classes.

Regards,

Nithya