Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Raise Exception.

raguraman_c
Active Contributor
0 Likes
862

Can anyone please tell me how to raise exception, i would like to know what is exception class and how we raise exception. I know the syntax. Can anyone please explain me.

--Ragu

6 REPLIES 6
Read only

Former Member
0 Likes
792

Hi Raghu,

Check this...

Example 
The function module STRING_SPLIT would appear as follows (compare the example in CALL FUNCTION): 



FUNCTION-POOL CSTR. 
FUNCTION STRING_SPLIT. 
  ... 
  IF STRING NA DELIMITER. 
    RAISE NOT_FOUND. 
  ENDIF. 
  ... 
ENDFUNCTION. 



The calling program could then include the following code: 



PROGRAM EXAMPLE. 
... 
CALL FUNCTION 'STRING_SPLIT' 
*    ... 
     EXCEPTIONS 
          NOT_FOUND = 7. 
IF SY-SUBRC = 7. 
  WRITE / 'There is a problem.'. 
ELSE. 
  ... 
ENDIF. 

Cheers

VJ

Read only

Former Member
0 Likes
792

Hi Raghu,

You can also check

report  DEMO_RAISE_EXCEPTIONS.

data OREF type ref to CX_ROOT.
data TEXT type STRING.

try.
  try.
    raise exception type CX_DEMO_CONSTRUCTOR
          exporting MY_TEXT = SY-REPID.
    catch CX_DEMO_CONSTRUCTOR into OREF.
      TEXT = OREF->GET_TEXT( ).
      write / TEXT.
      raise exception OREF.
  endtry.
  catch CX_DEMO_CONSTRUCTOR into OREF.
    TEXT = OREF->GET_TEXT( ).
    write / TEXT.
endtry.

Cheers

VJ

Read only

0 Likes
792

Hi Vijayendra,

Thanks for your reply.

I had already mentioned.I know the syntax.

can you explain

raise exception <b>type CX_DEMO_CONSTRUCTOR

exporting MY_TEXT = SY-REPID.</b>.

Can you explain me what this type and exporting means.

I get an error <b>"Old and new exceptions cannot be used the same time."</b>

--Ragu

Read only

0 Likes
792

Hi Raghu,

Check the explanation in the link below. Its explained very clearly.

http://help.sap.com/saphelp_nw2004s/helpdata/en/83/636d2012fc11d5991e00508b5d5211/content.htm

Cheer

VJ

Read only

Former Member
0 Likes
792
**  calculate UTC_END = UTC_START + h/m/s
    IF ( seconds IS INITIAL ) AND ( minutes IS INITIAL )
                              AND ( hours IS INITIAL ).
      RAISE invalid_param.
    ELSE.
      end_seconds = start_seconds + hours * 3600
                                  + minutes * 60
                                  + seconds.
      enddate = end_seconds DIV 86400.
      endtime = end_seconds MOD 86400.
      time_end(8) = enddate.  time_end+8(6) = endtime.
      utc_end = time_end.
    ENDIF.
Read only

Former Member
0 Likes
792

hi,

Exceptions are used to signal that a block cannot carry out it’s assigned task. This includes Siedersleben’s Emergencies as well as violated pre- or post-conditions (emergencies can be seen as a specific reason for post-condition violations). I do not consider using exceptions for generic co-routine -like control-flow manipulation (NOTIFY, and SIGNAL exceptions in Goodenough’s original proposal).

In general terms we can say, exception is a condition, often an error, that causes the program or microprocessor to branch to a different routine. The terms interrupt and exception are very close in meaning. Both can be used to refer to either hardware or software. The only real difference is that an exception usually indicates an error condition.

Exception handling is about what to do next. The goal is to succeed in carrying out the task (or to give up). There are two orthogonal aspects in this:

<b>Who handles the exception:</b>

-System:the program or supporting system

-User:the user

-System Administrator:a system administrator

-Programmer:the programmer

<b>What do they do, which strategy to use:</b>

-Retry:retry without changing anything

-Change Something:hange something and retry

-Change Input:change the input

-Fix Environment:change environmental condition

-Fix Program:change the program

-Reset:reset to a known state

-Change State:change the subsystem’s internal state

-Alternative :use alternative implementation or instance

-Give Up :give up (and propagate exception)

-Ignore:skip the action (ignore)

A very simple example can be a function module in which exceptions are defined.

CALL FUNCTION 'POPUP_TO_CONFIRM'
  EXPORTING
   TITLEBAR                    = 'ABC'
    TEXT_QUESTION              = 'Do you want to continue?'
   TEXT_BUTTON_1               = 'Ja'(001)
   TEXT_BUTTON_2               = 'Nein'(002)
 IMPORTING
   ANSWER                      =
 TABLES
   PARAMETER                   =
 EXCEPTIONS
   TEXT_NOT_FOUND              = 1
   OTHERS                      = 2
          .
IF SY-SUBRC <> 0.
 *Handle the exception here
ENDIF.

Here the system raises the exception when the FM is not able to get executed successfully. and it sy-subrc gets a value which states the reason for this exception.

We can also raise a exception when a certain condition arise. suppose in our case

if <some condition>.

raise exception" which you have defined.

else.

  • normal program flow

endif.

Hope this help you in understanding the exception concept.

Regards,

Richa