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

regarding subroutine

Former Member
0 Kudos
1,234

how to handle exceptions in subroutine, give me the loginc

can we use RAICE statement in subroutines.

if we can use RAICE statement in subroutine. tell me How can we use?

8 REPLIES 8
Read only

Former Member
0 Kudos
771

in subroutine you can only pass using < value addition> changing < value addition> and table option no exception option is there RAISE is on ly pass the value for exception. so in subroutine you cant do raise.

regards

shiba dutta

Read only

0 Kudos
771

give me logic we shoud maintain exception in subroutine

Read only

0 Kudos
771

what are you asking means you want to do some validation i.e. by raising exception we are just getting the value of sy-subrc in our program and using validation.

just pass the value to subroutine and check the value.

if sy-subrc ne 0.

message i001(zspd).

endif.

just you have to assign the sy-subrc value and show the message as per needed.

in subroutine you have to do at your own validation and sy-subrc checking and display thae message there.

regards

shiba dutta

Read only

Former Member
0 Kudos
771

Rajesh,

DATA FIELD(10).

MOVE 'ABCB' TO FIELD.

REPLACE 'B' WITH 'string' INTO field.

Pls. Maek for all useful answers

Read only

Former Member
0 Kudos
771

Hi Rajesh,

No exceptions are raised in a Subroutine as in a Function Module.

Subroutines are procedures that you can define in any ABAP program and also call from any program. Subroutines are normally called internally, that is, they contain sections of code or algorithms that are used frequently locally. If you want a function to be reusable throughout the system, use a function module.

A subroutine is a block of code introduced by FORM and concluded by ENDFORM.

FORM <subr> [USING ... [VALUE(]<pi>[)] [TYPE <t>|LIKE <f>]... ]

[CHANGING... [VALUE(]<pi>[)] [TYPE <t>|LIKE <f>]... ].

...

ENDFORM.

<subr> is the name of the subroutine. The optional additions USING and CHANGING define the parameter interface. Like any other processing block, subroutines cannot be nested. You should therefore place your subroutine definitions at the end of the program, especially for executable programs (type 1). In this way, you eliminate the risk of accidentally ending an event block in the wrong place by inserting a FORM...ENDFORM block.

You call subroutines using the statement

PERFORM... [USING ... <pi>... ]

[CHANGING... <pi>... ].

Subroutines can call other subroutines (nested calls) and may also call themselves (recursive calls). Once a subroutine has finished running, the calling program carries on processing after the PERFORM statement. You can use the USING and CHANGING additions to supply values to the parameter interface of the subroutine.

Regards,

Priyanka.

Read only

Former Member
0 Kudos
771

Rajesh ,

Sorry wrogly pasted ......

Read only

Former Member
0 Kudos
771

Hi Rajesh ,

You cannot raise execptions in subroutines , if you want to do it then you can either create a FM containing the same logic or create a class and create methods containg your logc and trigger an event when an error occus( instead of exceptions ).

Rehards

Arun

Read only

Former Member
0 Kudos
771

HI,

RAISE exception is not possible in subroutine.

U pass a FLAG variable in changing parameter of the subroutine.

After the subroutine, u can check the flag variable.

e.g.

DATA FLG_ERROR type flag.

PERFORM f100_check_validity changing FLG_ERROR.

if FLG_ERROR = 'X'.

logic

endif.

Rgds,

Prakash