Wednesday, March 20, 2013

Method can be called from the same Method

A method can call itself by Call Method statement inside the implementation of the method. Inside there method will have to be declared directly as CALL METHOD METH. That means object will not be mentioned here. Important point is that the method must have an EXIT point to get outside of the method. Otherwise the method will fall in an infinite calling/looping.

Below is a program where we create a numeric table. Here we are getting the number by input parameter and multiplying it with the count. This count is initially 0 and it is gradually increased by 1. And the multiplied value is stored in a public variable and then it is written. Hence we are having the numeric table of input value. Inside the method we have called an Exit point. If the count is greater than 20 then it will get outside from the method otherwise it will continue for calling the method.

REPORT  zsr_test NO STANDARD PAGE HEADING.

PARAMETERS p_num TYPE i.

*----------------------------------------------------------------------*
*       CLASS cls DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls DEFINITION.
  PUBLIC SECTION.
    DATA: count TYPE i,
          value TYPE i.
    METHODS m_tab.
ENDCLASS.                    "cls DEFINITION

*----------------------------------------------------------------------*
*       CLASS cls IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls IMPLEMENTATION.
  METHOD m_tab.
    count = count + 1.
    IF count GT 20.
      EXIT.
    ELSE.
      value = count * p_num.
      WRITE: / p_num, '*', count, '=', value.
      CALL METHOD m_tab.
    ENDIF.
  ENDMETHOD.                    "m_tab
ENDCLASS.                    "cls IMPLEMENTATION

START-OF-SELECTION.

  DATA obj TYPE REF TO cls.
  CREATE OBJECT obj.

  WRITE: /10 'Table of ', p_num, ':',
         /10 '-----------------------'.
  SKIP.
  CALL METHOD obj->m_tab.

The program generates the following output.


12 comments:

yektek training said...

nice post thanks for sharing from Swathi

siva sankar Sankar said...

excellent post thanks for sharing from Sankar

Bhavya Kumar said...

Best blog.Got to learn new things.Thanks for this Blog SAP Success Factors Training in Chennai

virat said...

Very nice example

sanayamohit said...

SAP Success Factors Real Time Hands on Training in Chennai...

Don't always Depend on Training Institute Alone and so please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer over SAP Success Factors Means??? Please ready for an DEMO From the Trainer MR.Karthick
CONTACT:8122241286

Both Classroom/Online Training is Available!!!!!!

Shruti Ramalingam said...

From My search…Creating Experts provides Best SAP Training with real time projects assistance.

Most of the modules are equipped with advance level topics which the student can learn from the basics to the advance level stage.

They also provide placement assistance in leading MNC companies across the globe according to the current requirements.

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

And these are the Best SAP training institute which provides Real Time Hands on Training…

codedion Technologies-9003085882

creating Experts-8122241286

http://thecreatingexperts.com/sap-mm-training-in-chennai/

Unknown said...



Best SAP Success Factors Training Institute in Chennai
http://thecreatingexperts.com/sap-successfactors-training-in-chennai/
Best SAP MM Training in Chennai
http://thecreatingexperts.com/sap-mm-training-in-chennai/
Best SAP SD Training in Chennai
http://thecreatingexperts.com/sap-sd-training-in-chennai/
http://thecreatingexperts.com/sap-hr-training-in-chennai/
Best SAP FICO Training in Chennai
http://thecreatingexperts.com/sap-fico-training-in-chennai/
Best SAP ABAP Training in Chennai
http://thecreatingexperts.com/sap-abap-training-in-chennai/
Best SAP BASIS Training in Chennai
http://thecreatingexperts.com/sap-basis-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

Both Classroom/Online Training is Available!!!!!!

Camelliacanan said...

Very nice post here thanks for it I always like and search such topics and everything connected to them. Keep update more information..

SAP HR Training in Chennai

SAP SD Training in Chennai

SAP Basis Training in Chennai

gilledashivani said...


Great information. the information provided is of great use as i got to learn new things. If you are looking for real time training in SAP ABAP, kindly contact sieve software. Sieve software offers real time training by industry experts with live projects and placement support.
SAP ABAP TRAINING IN HYDERABAD

calfre services said...

thank you for sharing nice information really very nicesap hr online classes

sourav rai said...

sir , why paramater is not imported inside the method, you have used it directly is it a good approach , and can we do in all cases when fetching data based on the paramater from multiple tables

SieveSoftware said...

Great Post. The information provided is of great use as I got to learn new things. Keep Blogging.
SAP ABAP TRAINING IN HYDERABAD