Application Development and Automation 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: 
Read only

ABOUT PERFORM

Former Member
0 Likes
1,003

HOW TO USE PERFORM....ENDPERFORM WITH AN EXAMPLE ?

HOW TO USE PERFORM....ENDPERFORM WITH AN EXAMPLE ?

7 REPLIES 7
Read only

Former Member
0 Likes
965

hi,

in the SAPScript,

/: PERFORM <form> IN PROGRAM <prog>

/: USING &INVAR1&

/: USING &INVAR2&

......

/: CHANGING &OUTVAR1&

/: CHANGING &OUTVAR2&

......

/: ENDPERFORM

INVAR1 and INVAR2 are variable symbols and may be of any of the four SAPscript symbol types.

OUTVAR1 and OUTVAR2 are local text symbols and must therefore be character strings.

In the ABAP program,

The ABAP subroutine called via the command line stated above must be defined in the ABAP report prog as follows:

FORM <form> TABLES IN_TAB STRUCTURE ITCSY

OUT_TAB STRUCTURE ITCSY.

...

ENDFORM.

Read only

anversha_s
Active Contributor
0 Likes
965

hi,

DATA : c1 TYPE i, c2 TYPE i, res TYPE i.

c1 = 1.

c2 = 2.

data: subroutinename(3) VALUE 'SUM'.

PERFORM (subroutinename) IN PROGRAM Y_JJTEST1USING c1 c2 CHANGING res.

*WRITE:/ res.

*&----


*

*& Form sum

*&----


*

  • text

*----


form sum using p_c1 p_c2 changing value(p_res).

p_res = p_c1 + p_c2.

endform. " sum

This link will clear all your Doubts reagrding Perform Statement.

Have a look:

http://help.sap.com/saphelp_erp2005/helpdata/en/9f/db977635c111d1829f0000e829fbfe/frameset.htm

rgds

anver

pls mark points if hlpful

Read only

Former Member
0 Likes
965

this is just a simple example..

hope you like it.

PERFORM f_progress_msg USING 'Hi, Joe!'.

FORM f_progress_msg USING fu_text.

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

EXPORTING

text = fu_text.

ENDFORM. " f_progress_msg

Read only

0 Likes
965

hai,

plz explain perform-endperform in sapscripts.

thank u.

Read only

Former Member
0 Likes
965

With the PERFORM statement, you can call subroutines which are coded in the same ABAP program (internal calls), or subroutines which are coded in other ABAP programs (external calls).

You can also specify the name of the subroutine dynamically at runtime, and call subroutines from a list.

Internal Subroutine Calls

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.

PROGRAM FORM_TEST.

DATA: NUM1 TYPE I,

NUM2 TYPE I,

SUM TYPE I.

NUM1 = 2. NUM2 = 4.

PERFORM ADDIT.

NUM1 = 7. NUM2 = 11.

PERFORM ADDIT.

FORM ADDIT.

SUM = NUM1 + NUM2.

PERFORM OUT.

ENDFORM.

FORM OUT.

WRITE: / 'Sum of', NUM1, 'and', NUM2, 'is', SUM.

ENDFORM.

The produces the following output:

Sum of 2 and 4 is 6

Sum of 7 and 11 is 18

In this example, two internal subroutines ADDIT and OUT are defined at the end of the program. ADDIT is called from the program and OUT is called from ADDIT. The subroutines have access to the global fields NUM1, NUM2, and SUM.

External subroutine calls

The principal function of subroutines is for modularizing and structuring local programs. However, subroutines can also be called externally from other ABAP programs. In an extreme case, you might have an ABAP program that contained nothing but subroutines. These programs cannot run on their own, but are used by other ABAP programs as pools of external subroutines.

However, if you want to make a function available throughout the system, you should use function modules instead of external subroutines. You create function modules in the ABAP Workbench using the Function Builder. They are stored in a central library, and have a defined release procedure.

You can encapsulate functions and data in the attributes and methods of classes in ABAP Objects. For any requirements that exceed pure functions, you can use global classes instead of external subroutines.

When you call a subroutine externally, you must know the name of the program in which it is defined:

PERFORM <subr>(<prog>) [USING ... <pi>... ]

[CHANGING... <pi>... ] [IF FOUND].

You specify the program name <prog> statically. You can use the IF FOUND option to prevent a runtime error from occurring if the program <prog> does not contain a subroutine <sub>. In this case, the system simply ignores the PERFORM statement.

When you call an external subroutine, the system loads the whole of the program containing the subroutine into the internal session of the calling program (if it has not already been loaded). For further information, refer to Memory Structure of an ABAP Program. In order to save memory space, you should keep the number of subroutines called in different programs to a minimum.

Suppose a program contains the following subroutine:

PROGRAM FORMPOOL.

FORM HEADER.

WRITE: / 'Program started by', SY-UNAME,

/ 'on host', SY-HOST,

'date:', SY-DATUM, 'time:', SY-UZEIT.

ULINE.

ENDFORM.

The subroutine can then be called from another program as follows:

PROGRAM FORM_TEST.

PERFORM HEADER(FORMPOOL) IF FOUND.

In this example, no data is passed between calling program and subroutine.

Specifying Subroutines Dynamically

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.

Suppose a program contains the following subroutines:

PROGRAM FORMPOOL.

FORM SUB1.

WRITE: / 'Subroutine 1'.

ENDFORM.

FORM SUB2.

WRITE: / 'Subroutine 2'.

ENDFORM.

Dynamic subroutine specification:

PROGRAM FORM_TEST.

DATA: PROGNAME(8) VALUE 'FORMPOOL',

SUBRNAME(8).

SUBRNAME = 'SUB1'.

PERFORM (SUBRNAME) IN PROGRAM (PROGNAME) IF FOUND.

SUBRNAME = 'SUB2'.

PERFORM (SUBRNAME) IN PROGRAM (PROGNAME) IF FOUND.

The produces the following output:

Subroutine 1

Subroutine 2

The character field PROGNAME contains the name of the program, in which the subroutines are contained. The names of the subroutines are assigned to the character field SUBRNAME.

Calling Subroutines from a List

You can call a subroutine from a list as follows:

PERFORM <idx> OF <subr1> <subr 2>.... <subr n>.

The system calls the subroutine specified in the subroutine list in position <idx>. You can only use this variant of the PERFORM statement for internal subroutine calls, and only for subroutines without a parameter interface. The field <idx> can be a variable or a literal.

PROGRAM FORM_TEST.

DO 2 TIMES.

PERFORM SY-INDEX OF SUB1 SUB2.

ENDDO.

FORM SUB1.

WRITE / 'Subroutine 1'.

ENDFORM.

FORM SUB2.

WRITE / 'Subroutine 2'.

ENDFORM.

The produces the following output:

Subroutine 1

Subroutine 2

In this example, the two internal subroutines, SUB1 and SUB2, are called consecutively from a list.

Passing Parameters to Subroutines

If a subroutine has a parameter interface, you must supply values to all of the formal parameters in its interface when you call it. You list the actual parameters after the USING or CHANGING addition in the PERFORM statement.

When you pass the values, the sequence of the actual parameters in the PERFORM statement is crucial. The value of the first actual parameter in the list is passed to the first formal parameter, the second to the second, and so on. The additions USING and CHANGING have exactly the same meaning. You only need to use one or the other. However, for documentary reasons, it is a good idea to divide the parameters in the same way in which they occur in the interface definition.

Actual parameters can be any data objects or field symbols of the calling program whose technical attributes are compatible with the type specified for the corresponding formal parameter. When you specify the actual parameters, note that any that you pass by reference to a formal parameter, and any that you pass by value to an output parameter, can be changed by the subroutine. You should therefore ensure that only data objects that you want to be changed appear in the corresponding position of the actual parameter list.

If a subroutine contains TABLES parameters in its interface, you must specify them in a TABLES addition of the PERFORM statement before the USING and CHANGING parameters. TABLES parameters are only supported to ensure compatibility with earlier releases, and should no longer be used.

You can specify actual parameters with variable offset and length specifications. Offset specifications for actual parameters function as offset specifications for field symbols. You can select memory areas that lie outside the boundaries of the specified actual parameter.

PROGRAM FORM_TEST.

DATA: A1 TYPE P DECIMALS 3,

A2 TYPE I,

A3 TYPE D,

A4 TYPE SPFLI-CARRID,

A5 TYPE C.

...

PERFORM SUBR USING A1 A2 A3 A4 A5.

...

PERFORM SUBR CHANGING A1 A2 A3 A4 A5.

...

PERFORM SUBR USING A1 A2 A3

CHANGING A4 A5.

...

FORM SUBR USING

VALUE(F1) TYPE P

VALUE(F2) TYPE I

F3 LIKE A3

CHANGING

VALUE(F4) TYPE SPFLI-CARRID

F5.

...

ENDFORM.

This example defines a subroutine SUBR with a parameter interface consisting of five formal parameter F1 to F5. The subroutine is called internally three times. The actual parameters are the data objects A1 to A5. The three subroutine calls are all equally valid. There are further PERFORM statements that are also equally valid, so long as the sequence of the actual parameters remains unchanged. In each call, A1 is passed to F1, A2 to F2, and so on. When the subroutine ends, A3, A4, and A5 receive the values of F3, F4, and F5 respectively. The third of the subroutine calls documents in the program what the parameter interface of the subroutine shows, namely that only A4 and A5 are changed. Whether A3 is changed depends on the way in which the subroutine is programmed.

Example of Passing Parameters by Reference

PROGRAM FORM_TEST.

DATA: NUM1 TYPE I,

NUM2 TYPE I,

SUM TYPE I.

NUM1 = 2. NUM2 = 4.

PERFORM ADDIT USING NUM1 NUM2 CHANGING SUM.

NUM1 = 7. NUM2 = 11.

PERFORM ADDIT USING NUM1 NUM2 CHANGING SUM.

FORM ADDIT

USING ADD_NUM1

ADD_NUM2

CHANGING ADD_SUM.

ADD_SUM = ADD_NUM1 + ADD_NUM2.

PERFORM OUT USING ADD_NUM1 ADD_NUM2 ADD_SUM.

ENDFORM.

FORM OUT

USING OUT_NUM1

OUT_NUM2

OUT_SUM.

WRITE: / 'Sum of', OUT_NUM1, 'and', OUT_NUM2, 'is', OUT_SUM.

ENDFORM.

The produces the following output:

Sum of 2 and 4 is 6

Sum of 7 and 11 is 18

In this example, the actual parameters NUM1, NUM2, and SUM are passed by reference to the formal parameters of the subroutine ADDIT. After changing ADD_SUM, the latter parameters are then passed to the formal parameters OUT_NUM1, OUT_NUM2, and OUT_SUM of the subroutine OUT.

Input parameters which are changed in the subroutine are also changed in the calling program. To prevent this, you must pass the parameter by value in a USING addition.

Have a look at below link.

http://help.sap.com/saphelp_40b/helpdata/en/d1/803279454211d189710000e8322d00/content.htm

Best Regards,

Vibha

*Please mark all the helpful answers

Read only

0 Likes
965

hai,

plz explain perform-endperform in sapscripts.

thank u.

Read only

Former Member
0 Likes
965

Hi Preethi,

Have a look at below code for FORM ENDFORM in scripts.

The Form :

/:PERFORM CDE_CENT IN PROGRAM ZKRPMM_PERFORM_Z1MEDRUCK

/:USING &EKKO-EBELN&

/:CHANGING &CDECENT&

/:ENDPERFORM

The report :

REPORT zkrpmm_perform_z1medruck .

DATA : BEGIN OF it_input_table OCCURS 10.

INCLUDE STRUCTURE itcsy.

DATA : END OF it_input_table.

  • déclaration de la table output_table contenant les

variables exportées

DATA : BEGIN OF it_output_table OCCURS 0.

INCLUDE STRUCTURE itcsy.

DATA : END OF it_output_table.

DATA : w_ebeln LIKE ekko-ebeln,

  • w_vbeln LIKE vbak-vbeln,

w_zcdffa LIKE vbak-zcdffa.

*----


  • FORM CDE_CENT

*----


FORM cde_cent TABLES input output.

it_input_table[] = input[].

it_output_table[] = output[].

READ TABLE it_input_table INDEX 1.

MOVE it_input_table-value TO w_ebeln.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = w_ebeln

IMPORTING

output = w_ebeln.

SELECT SINGLE zcdffa FROM ekko

INTO w_zcdffa

WHERE ebeln = w_ebeln.

it_output_table-name = 'CDECENT'.

MOVE w_zcdffa TO it_output_table-value.

MODIFY it_output_table INDEX 1.

output[] = it_output_table[].

ENDFORM.

Best Regards,

Vibha

*Please mark all the helpful answers