Skip to Content
avatar image
Former Member

Calling ABAP Subroutines: PERFORM

Hi,

   I have one basic question in ABAP PERFORM statement. I am calling a PERFORM which is part of another report from my class method and i am calling this class method in my report. I am using PERFORM <form> IN PROGRAM <prog> statement to call the FORM. The issue is the FORM what i am calling from my class, Has some WRITE Statement inside. So when ever i execute my report it is displaying two screen one screen from my report and another screen from the FORM statement what i am calling from other report. Can you please tell me how to remove the Second screen which is cuming from the other report.

Thank and Regards,

Dhinesh Kumar.J

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Nov 21, 2012 at 07:10 AM

    Hi Dhinesh,

    in FORM in the program at where you are calling before the screen display you should put if sy-cprog is not equal to the first program the screen has to appear.

    REPORT ZSOURCE2307.
    * List of the current program
    WRITE / 'I am program ZSOURCE2307'.
    * External perform
    PERFORM EXTFORM IN PROGRAM ZSOURCE2308.

    Program 2

    REPORT ZSOURCE2308.
    * Form definition
    FORM EXTFORM.

    if sy-cprog <> 'ZSOURCE2307'.
      WRITE / 'I am extform in program ZSOURCE2308.'.

    endif.
    ENDFORM.

    so the write in the program 2 will not appear now.

    hope this helps,

    Vinoth Aruldass. S.

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 21, 2012 at 08:44 AM

    PERFORM <form> IN PROGRAM <prog> from a CLASS - Very bad practice !!!

    Add comment
    10|10000 characters needed characters exceeded

    • Hi 😊

      In your terms, the subroutine of the legacy program is local to itself, it can be changed to a new logic anytime to which the caller was not aware of ( class/method as per this thread ). A local class with a static method will be neat in OP's case.

      I never said it was a rule , its the approach 😉

      happy week end..

      Kesav

  • Nov 26, 2012 at 10:19 PM

    I see that you have marked the first suggestion (using sy-cprog) as helpfull, but if you have an ability to modify the program where the routine is located, it kind of changes the question itself. If you can modify that program, then there could actually be much better options than using hardcoding, which kind of defeats the OOP purpose. E.g. sometimes WRITE is used just to display messages and can easily be replaced with MESSAGE. Or maybe it's not needed at all.

    Even though other replies may not seem as helpfull, they actually make more sense and provide better advice in the long run.

    Also you might want to educate yourself on the list processing at least a bit. It's not a fancy technology but usually it's nice to understand what we're dealing with.

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 26, 2012 at 10:48 PM

    Dinesh,

    the problem has nothing to do with subroutines in itself.

    Therefore, the discussions about "political correctness" of form routines are useless (and I find them boring, anyway: Programming decisions are not about do's and don'ts, but about advantages and disadvantages. Of course we all know about advantages of OO. But if someone is using forms, he may have his reasons for it and is obviously willing to accept the price.).

    Your problem would appear in precisely the same way if you would call a method, not a subroutine.

    The problem is about surpressing the output of the WRITE statement in a certain part of the code. For a time, you want your WRITE statement be collected into the ABAP list. But when that subroutine is processed, the WRITE output should be surpressed. Later on, the WRITE should again go into the ABAP list.

    But what I don't understand, why you are getting two lists. First, your own list, and then a second list from within the perform. Why does the output of the subroutine go into a separate list? An external perform wouldn't create a new list level on the stack, but simply continue to write into the existing list. Is there a SUBMIT AND RETURN involved? Somewhere inside of that subroutine?

    Regards,

    Rüdiger

    Add comment
    10|10000 characters needed characters exceeded