Application Development 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: 

methods

Former Member
0 Kudos

what are functional methods?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

http://help.sap.com/saphelp_nw04s/helpdata/en/08/d27c03b81011d194f60000e8353423/frameset.htm

Functional Methods

Functional methods are methods with any number of IMPORTING parameters and one RETURNING parameter. In addition to CALL METHOD you can also use the following expressions at operand positions to call functional methods:

IMPORTING parameters

Expression

None

meth( )

One

meth( f ) oder meth( p = f )

n

meth( p1 = f1 ... pn = fn )

This notation is currently supported:

· for the source field of the MOVE statement

· in arithmetic expressions of the COMPUTE statement

· in logical expressions

· in the CASE statement of the CASE control structure

· in the WHEN statement of the CASE control structure

· in the WHERE condition of the statements LOOP AT, DELETE and MODIFYfor internal tables

The functional method is entered instead of an operand. When the statement is executed, the method is called and the RETURNING parameter passed back is used as the operand.

Thanks,

Aby

4 REPLIES 4

0 Kudos

hi,

Methods that have a RETURNING parameters are described as <b>Functional Methods.</b> These methods can not have EXPORTING(or) CHANGING parameters,but has IMPORTING parameters and EXCEPTIONS.

<b>if helpful reward some points.</b>

Former Member
0 Kudos

Hi,

http://help.sap.com/saphelp_nw04s/helpdata/en/08/d27c03b81011d194f60000e8353423/frameset.htm

Functional Methods

Functional methods are methods with any number of IMPORTING parameters and one RETURNING parameter. In addition to CALL METHOD you can also use the following expressions at operand positions to call functional methods:

IMPORTING parameters

Expression

None

meth( )

One

meth( f ) oder meth( p = f )

n

meth( p1 = f1 ... pn = fn )

This notation is currently supported:

· for the source field of the MOVE statement

· in arithmetic expressions of the COMPUTE statement

· in logical expressions

· in the CASE statement of the CASE control structure

· in the WHEN statement of the CASE control structure

· in the WHERE condition of the statements LOOP AT, DELETE and MODIFYfor internal tables

The functional method is entered instead of an operand. When the statement is executed, the method is called and the RETURNING parameter passed back is used as the operand.

Thanks,

Aby

Former Member
0 Kudos

Hi Srikanth,

As already said functional methods have returning parameter and no exporting and changing parameters. This returning parameter should be by value. By reference is not allowed.

See the below code for a functional constructor.


* & - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * 
 
 * &   R e p o r t     Z G S _ E X E R _ 1 
 
 * & 
 
 * & - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * 
 
 * & 
 
 * & 
 
 * & - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * 
 
 
 
 R E P O R T     z g s _ e x e r _ 1 . 
 
 
 
 
 
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * 
 
 *               C L A S S   l c l _ a i r p l a n e   D E F I N I T I O N 
 
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * 
 
 * 
 
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * 
 
 C L A S S   l c l _ a i r p l a n e   D E F I N I T I O N . 
 
     P U B L I C   S E C T I O N . 
 
         M E T H O D S   :   c o n s t r u c t o r   I M P O R T I N G   i m _ c a r r i d   T Y P E   s _ c a r r _ i d 
 
                                                                 i m _ c o n n i d   T Y P E   s _ c o n n _ i d 
 
                                                                 i m _ d i s t a n c e   T Y P E   s _ d i s t a n c e , 
 
                             c a l c _ f u e l   r e t u r n i n g   v a l u e ( r e _ f u e l )   t y p e   i   . 
 
 
 
         C L A S S - M E T H O D S :   c a l c _ t o t _ f l i . 
 
     P R I V A T E   S E C T I O N . 
 
         D A T A   :   c a r r i d   T Y P E   s _ c a r r _ i d , 
 
                       c o n n i d   T Y P E   s _ c o n n _ i d , 
 
                       d i s t a n c e   T Y P E   s _ d i s t a n c e , 
 
                       f u e l _ c   T Y P E   i . 
 
 
 
         C L A S S - D A T A   :   t o t _ f l i g h t s   T Y P E   i . 
 
 
 
         M E T H O D S   :   d i s p _ f l i . 
 
 
 
 
 
 E N D C L A S S .                                         " l c l _ a i r p l a n e   D E F I N I T I O N 
 
 
 
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * 
 
 *               C L A S S   l c l _ a i r p l a n e   I M P L E M E N T A T I O N 
 
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * 
 
 * 
 
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * 
 
 C L A S S   l c l _ a i r p l a n e   I M P L E M E N T A T I O N . 
 
     M E T H O D   c o n s t r u c t o r . 
 
         M O V E   i m _ c a r r i d   T O   c a r r i d . 
 
         M O V E   i m _ c o n n i d   T O   c o n n i d . 
 
         M O V E   i m _ d i s t a n c e   T O   d i s t a n c e . 
 
 
 
 *         C A L L   M E T H O D   c a l c _ f u e l . 
 
         C A L L   M E T H O D   m e - > d i s p _ f l i . 
 
         A D D   1   T O   t o t _ f l i g h t s . 
 
     E N D M E T H O D .                                         " s e t _ f l i 
 
 
 
     M E T H O D   d i s p _ f l i . 
 
         W R I T E   :   / 1 0   c a r r i d , 
 
                         / 1 0   c o n n i d , 
 
                         / 1 0   d i s t a n c e . 
 
 *                         / 1 0   f u e l _ c . 
 
     E N D M E T H O D .                                         " d i s p _ f l i 
 
 
 
     M E T H O D   c a l c _ f u e l . 
 
         r e _ f u e l   =   d i s t a n c e   /   1 0 . 
 
     E N D M E T H O D .                                         " c a l c _ f u e l 
 
 
 
     M E T H O D   c a l c _ t o t _ f l i . 
 
         W R I T E   : / 1 0   ' T o t a l   f l i g h t s   n o   o f   f l i g h s     : ' ,   t o t _ f l i g h t s . 
 
 *         w r i t e   : / 1 0   ' T o t a l   f u e l   c o n s u m p t i o n   i s       : ' ,   v _ t o t _ f u e l . 
 
     E N D M E T H O D .                                         " c a l c _ t o t _ f l i 
 
 E N D C L A S S .                                         " l c l _ a i r p l a n e   I M P L E M E N T A T I O N 
 
 
 
 S T A R T - O F - S E L E C T I O N . 
 
 
 
     D A T A   :   f l i g h t 1   T Y P E   R E F   T O   l c l _ a i r p l a n e , 
 
                   f l i g h t 2   T Y P E   R E F   T O   l c l _ a i r p l a n e . 
 
 
 
   d a t a   :   v _ c a r r i d   t y p e   s _ c a r r _ i d , 
 
                 v _ c o n n i d   t y p e   s _ c o n n _ i d , 
 
                 v _ d i s t a n c e   t y p e   s _ d i s t a n c e . 
 
 
 
 s e l e c t   s i n g l e   c a r r i d   c o n n i d   d i s t a n c e   f r o m   s p f l i 
 
   i n t o   ( v _ c a r r i d , v _ c o n n i d , v _ d i s t a n c e )                 . 
 
 
 
     C R E A T E   O B J E C T   f l i g h t 1   e x p o r t i n g   i m _ c a r r i d   =   v _ c a r r i d 
 
                                                                     i m _ c o n n i d   =   v _ c o n n i d 
 
                                                   i m _ d i s t a n c e   =   v _ d i s t a n c e   . 
 
 
 
     C R E A T E   O B J E C T   f l i g h t 2   e x p o r t i n g   i m _ c a r r i d   =   ' c d 2 ' 
 
                                                   i m _ c o n n i d   =   ' 0 0 0 2 ' 
 
                                                   i m _ d i s t a n c e   =   1 0 0   . 
 
 
 
 
 
 
 
 *     C A L L   M E T H O D   f l i g h t 1 - > s e t _ f l i (   i m _ c a r r i d   =   ' c d 1 ' 
 
 *                                                                 i m _ c o n n i d   =   ' 0 0 0 1 ' 
 
 *                                                                 i m _ d i s t a n c e   =   5 0 0   ) . 
 
 * 
 
 *     C A L L   M E T H O D   f l i g h t 2 - > s e t _ f l i (   i m _ c a r r i d   =   ' c d 2 ' 
 
 *                                                                 i m _ c o n n i d   =   ' 0 0 0 2 ' 
 
 *                                                                 i m _ d i s t a n c e   =   1 0 0   ) . 
 
 
 
         d a t a   :   v _ t o t _ f u e l   t y p e   i . 
 
         v _ t o t _ f u e l   =   f l i g h t 1 - > c a l c _ f u e l (   )   +   f l i g h t 2 - > c a l c _ f u e l (   ) . 
 
 
 
 
 
 * 
 
 l c l _ a i r p l a n e = > c a l c _ t o t _ f l i (   ) . 
 
 
 
 w r i t e   : / 1 0   ' T h e   t o t a l   f u e l   c o n s u m p t i o n   i s   :   ' , v _ t o t _ f u e l . 
 

Just copy paste this code and debug .

Functional methods can also be directly called in various expressions like if, case,loop etc.

Reward points if useful,

Aleem.

Former Member
0 Kudos

Hi

http://help.sap.com/saphelp_46c/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm

Method

An object's abilities. Lassie, being a Dog, has the ability to bark. So bark() is one of Lassie's methods. She may have other methods as well, for example sit() or eat(). Within the program, using a method should only affect one particular object; all Dogs can bark, but you need one particular dog to do the barking.