04-03-2008 8:25 AM
04-03-2008 8:26 AM
hi,
by the following stmt we call subroutine:-
PERFORM <subroutine>.
04-03-2008 8:27 AM
Hi,
if it is internal
perform <name>.
external
perform <name> (program) if found.
rgds,
bharat.
04-03-2008 8:28 AM
Internal subroutines in the sense ..subroutines which are defined and used in a same program external in the sense if you create a sub routine in one program and youre calling this subroutine in another program ..then this is external subroutine
or
The name itself implies the internal subroutines defined by form /perform.. can be called within the same prog in which they were declared
external subroutines can be called outside the program ....
SUBROUTINES:
-
FORM - ENDFORM statement is used to create subroutines.
PERFORM statement is used to invoke the subroutine created.
Subroutines are used to call a piece of code frequently within the program or externally from other program.
LOCAL SUBROUTINES:
-
The subroutine is called locally from the same program using PERFORM statement.
eg. code of local subroutine without any value:
-
PERFORM STALIN.
FORM STALIN.
DO 5 TIMES.
WRITE 😕 'WELCOME TO ABAP'.
ENDDO.
ENDFORM.
eg. code of external subroutine without any value:
-
create an executable program and write the following code:
REPORT ZSUBROUTINES2 .
PERFORM STALIN.
FORM STALIN.
DO 5 TIMES.
WRITE 😕 'WELCOME TO ABAP'.
ENDDO.
ENDFORM.
Save -> Activate.
Create another executable program and write the following code:
REPORT ZSUBROUTINES1.
PERFORM STALIN(ZSUBROUTINES2).
Save -> Activate -> Execute.
We have to specify name of the program where subroutine is created within the bracket whenever we try to invoke the subroutine externally.
PASS BY REFERENCE:
-
DATA : A(10) VALUE 'INDIA', B TYPE I VALUE '20'.
PERFORM STALIN USING A B.
FORM STALIN USING X Y.
WRITE 😕 X , Y.
ENDFORM.
PASS BY VALUE:
-
DATA : A(10) VALUE 'INDIA', B TYPE I VALUE '20'.
PERFORM STALIN USING A B.
FORM STALIN USING X Y.
X = 'AMERICA'.
Y = '100'.
WRITE 😕 X , Y.
ENDFORM.
PASSING INTERNAL TABLE AS AN ARGUMENT:
-
DATA ITAB LIKE KNA1 OCCURS 0 WITH HEADER LINE.
SELECT * FROM KNA1 INTO TABLE ITAB.
PERFORM DISPLAY TABLES ITAB .
FORM DISPLAY TABLES ITAB STRUCTURE KNA1.
LOOP AT ITAB.
WRITE 😕 ITAB-KUNNR, ITAB-NAME1, ITAB-LAND1, ITAB-ORT01.
ENDLOOP.
ENDFORM.
04-03-2008 8:33 AM
Hi,
To call a subroutine defined in the same program, you need only specify its name in the
PERFORM statement:
PERFORM <subr> [USING ... <pi>... ]
[CHANGING... <pi>... ].
The internal subroutine can access all of the global data of the calling program.
You can specify the name of a subroutine and, in the case of external calls, the name of the program in which it occurs, dynamically as follows:
PERFORM (<fsubr>)[IN PROGRAM (<fprog>)][USING ... <pi>... ]
[CHANGING... <pi>... ]
[IF FOUND].
The names of the subroutine and the external program are the contents of the fields <fsubr> and <fprog> respectively. By using the option IF FOUND, you can prevent a runtime error from being triggered if <fprog> does not contain a subroutine with the name <fsubr>. If you omit the parentheses, this variant of the PERFORM statement behaves like the static variant.
Regards,
Bhaskar
04-03-2008 8:58 AM
HI,
You can create a subroutine & call it as follows:
PERFORM f_validation.
&----
*& Form f_validation
&----
text
----
--> p1 text
<-- p2 text
----
FORM F_VALIDATION .
IF SY-UCOMM = 'ONLI' OR SY-UCOMM = 'SJOB'.
IF ZCOMP IS NOT INITIAL AND S_COMP IS NOT INITIAL.
MESSAGE E001(ZBHI) WITH TEXT-006.
ENDIF.
ENDFORM. " f_validation
First you can write the perform statement & when you double click on this statement, it will automatically create FORM.
Then you can put your code in this FORM statement.
Hope this helps.
Reward if helpful.
Regards,
Sipra