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: 

Calling ABAP Subroutines: PERFORM

dhineshkumar_j
Explorer
0 Kudos

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

1 ACCEPTED SOLUTION

vinoth_aruldass
Contributor
0 Kudos

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.

9 REPLIES 9

vinoth_aruldass
Contributor
0 Kudos

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.

kesavadas_thekkillath
Active Contributor

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

0 Kudos

Why? Classes can't have subroutines?

0 Kudos

@ Chinmay ,

It  is Simple Subroutines are Used with Cotext When you want to have Block Processing ( Procedural processing approach )  and OO has a Different

Approach.

0 Kudos

Well, it will work , no issues. But its not a good design of calling external subroutines when using OO programming.It is better to encapsulate the external functionality into the class itself.

Moreover, external subroutines are "local" in the calling program, do not exist separately in the central repository, whole program is loaded into session of calling program.

0 Kudos

Your logic is correct if it is a completely new development.

If I have a legacy program where the code is working perfectly well, why would I not use that. And even if I want to follow object methodology, I should create a separate class where all my re-usable methods are stored and I should call methods of that class. And I will have to change my legacy program for the same as well.

Of course your approach is valid, but it can not be a rule.

0 Kudos

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

Jelena
Active Contributor
0 Kudos

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.

rdiger_plantiko2
Active Contributor
0 Kudos

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