12-29-2006 9:14 AM
hi guys,
Can any one send me in depth learning for PERFORM statements.
thanks
12-29-2006 9:16 AM
Please go through these links,
http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db976935c111d1829f0000e829fbfe/frameset.htm
http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db977635c111d1829f0000e829fbfe/frameset.htm
http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db978335c111d1829f0000e829fbfe/frameset.htm
A simple example
REPORT zkb_test4.
DATA: v_data1 TYPE string,
v_data2 TYPE string.
DATA: i_scarr TYPE TABLE OF scarr.
START-OF-SELECTION.
v_data1 = 'Welcome to ABAP'.
* Simple Perform
PERFORM display.
* Pass a value to perform
PERFORM display_1 USING v_data1.
* PAss value and return value
PERFORM display_2 USING v_data1 CHANGING v_data2.
WRITE:/ 'PERFORM display_2 :',v_data2.
* Pass a table to perform
SELECT * FROM scarr INTO TABLE i_scarr.
PERFORM display_3 TABLES i_scarr.
*&---------------------------------------------------------------------*
*& Form display
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM display .
WRITE:/ 'PERFORM display : Welcome to ABAP'.
ENDFORM. " display
*&---------------------------------------------------------------------*
*& Form display_1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM display_1 USING p_v_data1.
WRITE:/ 'PERFORM display_1 :',p_v_data1.
ENDFORM. " display_1
*&---------------------------------------------------------------------*
*& Form display_2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM display_2 USING p_v_data1
CHANGING p_v_data2.
p_v_data2 = p_v_data1.
ENDFORM. " display_2
*&---------------------------------------------------------------------*
*& Form display_3
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM display_3 TABLES p_i_scarr STRUCTURE scarr.
FIELD-SYMBOLS: <fs_scarr> TYPE scarr.
LOOP AT p_i_scarr ASSIGNING <fs_scarr> .
WRITE:/1 <fs_scarr>-carrid, 5 <fs_scarr>-carrname, 30 <fs_scarr>-url.
ENDLOOP.
ENDFORM. " display_3
Regards
Kathirvel
12-29-2006 9:24 AM
hi,
look at this program on BDC where u can see PERFORM statement ,
this is how we wil be using the perform statement
DATA : BEGIN OF IT_DUMMY OCCURS 0,
DUMMY(100) TYPE C,
END OF IT_DUMMY.
DATA : BEGIN OF IT_XK01 OCCURS 0,
LIFNR(10) TYPE C,
BUKRS(4) TYPE C,
EKORG(4) TYPE C,
KTOKK(4) TYPE C,
NAME1(30) TYPE C,
SORTL(10) TYPE C,
LAND1(3) TYPE C,
SPRAS(2) TYPE C,
AKONT(6) TYPE C,
FDGRV(2) TYPE C,
WAERS(3) TYPE C,
END OF IT_XK01,
BEGIN OF IT_BANK OCCURS 0,
BANKS(3) TYPE C,
BANKL(10) TYPE C,
BANKN(10) TYPE C,
KOINH(30) TYPE C,
LIFNR(10) TYPE C,
END OF IT_BANK.
DATA : IT_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE,
IT_BDCMSGCOLL LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = 'C:\VENDOR.TXT'
FILETYPE = 'ASC'
TABLES
DATA_TAB = IT_DUMMY.
LOOP AT IT_DUMMY.
IF IT_DUMMY-DUMMY+0(2) = '11'.
IT_XK01-LIFNR = IT_DUMMY-DUMMY+2(10).
IT_XK01-BUKRS = IT_DUMMY-DUMMY+12(4).
IT_XK01-EKORG = IT_DUMMY-DUMMY+16(4).
IT_XK01-KTOKK = IT_DUMMY-DUMMY+20(4).
IT_XK01-NAME1 = IT_DUMMY-DUMMY+24(30).
IT_XK01-SORTL = IT_DUMMY-DUMMY+54(10).
IT_XK01-LAND1 = IT_DUMMY-DUMMY+64(3).
IT_XK01-SPRAS = IT_DUMMY-DUMMY+67(2).
IT_XK01-AKONT = IT_DUMMY-DUMMY+69(6).
IT_XK01-FDGRV = IT_DUMMY-DUMMY+75(2).
IT_XK01-WAERS = IT_DUMMY-DUMMY+77(3).
APPEND IT_XK01.
ELSE.
IT_BANK-BANKS = IT_DUMMY-DUMMY+2(3).
IT_BANK-BANKL = IT_DUMMY-DUMMY+5(10).
IT_BANK-BANKN = IT_DUMMY-DUMMY+15(10).
IT_BANK-KOINH = IT_DUMMY-DUMMY+25(30).
IT_BANK-LIFNR = IT_DUMMY-DUMMY+55(10).
APPEND IT_BANK.
ENDIF.
ENDLOOP.
LOOP AT IT_XK01.
REFRESH IT_BDCDATA.
perform bdc_dynpro using 'SAPMF02K' '0100'<---perform
perform bdc_field using 'BDC_CURSOR'
'RF02K-REF_LIFNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-LIFNR'
IT_XK01-LIFNR.
perform bdc_field using 'RF02K-BUKRS'
IT_XK01-BUKRS.
perform bdc_field using 'RF02K-EKORG'
IT_XK01-EKORG.
perform bdc_field using 'RF02K-KTOKK'
IT_XK01-KTOKK.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-TELX1'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFA1-NAME1'
IT_XK01-NAME1.
perform bdc_field using 'LFA1-SORTL'
IT_XK01-SORTL.
perform bdc_field using 'LFA1-LAND1'
IT_XK01-LAND1.
perform bdc_field using 'LFA1-SPRAS'
IT_XK01-SPRAS.
perform bdc_dynpro using 'SAPMF02K' '0120'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-KUNNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_dynpro using 'SAPMF02K' '0130'.
perform bdc_field using 'BDC_CURSOR'
'LFBK-KOINH(02)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
DATA : FNAM(20) TYPE C,
IDX TYPE C.
MOVE 1 TO IDX.
LOOP AT IT_BANK WHERE LIFNR = IT_XK01-LIFNR.
CONCATENATE 'LFBK-BANKS(' IDX ')' INTO FNAM.
perform bdc_field using FNAM
IT_BANK-BANKS.
CONCATENATE 'LFBK-BANKL(' IDX ')' INTO FNAM.
perform bdc_field using FNAM
IT_BANK-BANKL.
CONCATENATE 'LFBK-BANKN(' IDX ')' INTO FNAM.
perform bdc_field using FNAM
IT_BANK-BANKN.
CONCATENATE 'LFBK-KOINH(' IDX ')' INTO FNAM.
perform bdc_field using FNAM
IT_BANK-KOINH.
IDX = IDX + 1.
ENDLOOP.
perform bdc_dynpro using 'SAPMF02K' '0130'.
perform bdc_field using 'BDC_CURSOR'
'LFBK-BANKS(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_dynpro using 'SAPMF02K' '0210'.
perform bdc_field using 'BDC_CURSOR'
'LFB1-FDGRV'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFB1-AKONT'
IT_XK01-AKONT.
perform bdc_field using 'LFB1-FDGRV'
IT_XK01-FDGRV.
perform bdc_dynpro using 'SAPMF02K' '0215'.
perform bdc_field using 'BDC_CURSOR'
'LFB1-ZTERM'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_dynpro using 'SAPMF02K' '0220'.
perform bdc_field using 'BDC_CURSOR'
'LFB5-MAHNA'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_dynpro using 'SAPMF02K' '0310'.
perform bdc_field using 'BDC_CURSOR'
'LFM1-WAERS'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFM1-WAERS'
IT_XK01-WAERS.
perform bdc_dynpro using 'SAPMF02K' '0320'.
perform bdc_field using 'BDC_CURSOR'
'WYT3-PARVW(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
CALL TRANSACTION 'XK01' USING IT_BDCDATA
MODE 'A'
UPDATE 'S'
MESSAGES INTO IT_BDCMSGCOLL.
ENDLOOP.
FORM BDC_DYNPRO USING PROG SCR.
CLEAR IT_BDCDATA.
IT_BDCDATA-PROGRAM = PROG.<---values u passed in perform
IT_BDCDATA-DYNPRO = SCR. <---values u passed in perform
IT_BDCDATA-DYNBEGIN = 'X'.<---values u passed in perform
APPEND IT_BDCDATA.
ENDFORM.
FORM BDC_FIELD USING FNAM FVAL.
CLEAR IT_BDCDATA.
IT_BDCDATA-FNAM = FNAM.
IT_BDCDATA-FVAL = FVAL.
APPEND IT_BDCDATA.
ENDFORM.
rewards points if this helps u
siva
Message was edited by:
Shan
12-29-2006 9:36 AM
Hi Ahmed ,
Perform statements are used to call subroutines defined in the program .
The format of using it is
PERFORM form_name.
so when ever this statement is executed , the control gets transfred to the subroutine form_name , which has been defined as follows
form form_name.
" Processing logic.
Endform.
you can have additions to perform statements like using and changing , based on whether you are just using the value or changing the passed value.
Regards
Aruun
12-29-2006 9:44 AM
Hi Ahmed,
<i><b>Perform Statement or Subroutine</b></i>
A subroutine is a program-internal modularization unit. You move parts of a
program to a subroutine to make the program easier to read and allow you to
use these code segments more than once.
You can pass data to the subroutine and back using its interface. This allows
you to call the same functions for different data objects. The above example
shows a subroutine that calculates a percentage. This subroutine is called
several times, even though different data objects are passed to the interface
in each case.
Using subroutines makes your program more function-oriented: It splits
the program’s task into subfunctions, so that each subroutine is responsible
for one subfunction.
This generally makes programs easier to maintain. In the Debugger, you can
run these programs in the background, so that you only see the result. This
usually makes it easier to find the source of the error.
Each subroutine starts with FORM and endswith ENDFORM.
The name of the program is followed by the interface definition.
This is followed in turn by the statements that the subroutine executes.
You specify how the data is passed from the main program (actual
parameters) to the subroutine (formal parameters) in the interface. There
are three ways of doing this:
<i><b>Call-by-value</b></i>
A local copy of the actual parameter is passed to the subroutine. This
means that value assignments to the formal parameter have absolutely
no effect on the actual parameter.
<i><b>Call-by-reference</b></i>
The dereferenced address of the actual parameter is passed to the
subroutine. This means that value assignments to the formal parameter
affect the actual parameter directly. The value of the actual parameter is
physically changed by the subroutine through the address.
<i><b>Call-by-value-and-result</b></i>
A local copy of the actual parameter is passed to the subroutine and
a value is passed back to the main program. This means that value
assignments to the formal parameter only affect the actual parameter
after leaving the subroutine. You should choose this option if you want
to be sure that the actual parameter will not be changed, should the
subroutine be terminated prematurely.
In the interface definition, you list the formal parameters of the different
kinds and assign a type to each one. The sequence is syntactically fixed:
First you name all the USING parameters, followed by all the CHANGING
parameters. Thus within the subroutine, you address the data that has been
passed using the formal parameters.The actual parameters are also grouped by USING and CHANGING when the subroutine is called.
The data objects passed to a subroutine (that is, the actual parameters) can be
of any type. If you use elementary types, you can decide whether or not you
want to specify the type of the formal parameters.
By specifying the type of the formal parameters, you ensure that only actual
parameters of that type can be passed to the subroutine. This makes your
program more stable, since the syntax check will find any type conflicts.
If you use the TYPE ANY addition, you leave the type unspecified. (For
compatibility reasons, you can also omit this addition.) In this case, the formal
parameter “inherits” the type from the actual parameter at runtime. Then, if
the statements in the subroutine are not suited to the inherited type, a runtime
error may occur. If you assign the types P, N, C, or X, the missing type attributes are similarly inherited at runtime. If you want to specify a type completely, you must use a user-defined type. If you use STRING or XSTRING, the type is not
fully specified until runtime. Conversely, the data types I, F, D, and T are fully typed.If you use structures or internal tables as formal parameters, you must type
them fully. This allows you to access these formal parameters as normal
within the subroutine.The components of structures are known in the subroutine, as a result of the assigned type, so that you can address these components with the usual syntax. If you use internal tables, the assigned type allows you to address the formal parameter as an internal table with the usual syntax.
<i><b>Note on runtime requirements:</b></i>
If you use internal tables as parameters, you should generally pass them using call-by-reference. Otherwise, the system can use considerable resources simply copying them to the subroutine.You can define local data within a subroutine. Both the formal parameters
and the local data objects are only active at the runtime of the subroutine. This
means that memory is only allocated when the subroutine is called and is
released as soon as the subroutine has been executed. Thus these parameters
and data objects can only be addressed from within the subroutine.
The global data objects fromthe main programcan also be addressed from
the subroutine. However, you should avoid doing this wherever possible.
Otherwise, you are bypassing the interface, which makes the program more
error-prone.
If a local data object or formal parameter has the same name as a global
data object, the ABAP runtime system addresses the local data object in the
subroutine and the global one outside it. They are then known as locally
obscured objects.
Address the global data objects in the main program and pass them to
the subroutine using the interface.
Address only the formal parameters and local data objects in the
subroutine.
*For clarity, avoid using identically-named variables. Instead, use a simple
prefix, such as f_... for formal parameters and l_... for local data
object or similar.
A subroutine is called using the <i><b>PERFORM</b></i> statement. When the subroutine is called, parameters are passed to it in strict sequence.
For this reason, you should define the subroutine first and then call it. The
Object Navigator supports you in this respect: You can generate the PERFORM
statement by dragging the subroutine from the navigation area to the editor
area. Alternatively, you can generate the call using the statement patterns in
the ABAP Editor. This prevents you from mixing up or forgetting any parameters. However, you must remember to replace the formal parameters with actual parameters.
In debugging mode, you can make a subroutine run without stopping. The
execution of the main program does not stop until after the subroutine has
been executed.
Alternatively, you can execute the subroutine statement-by-statement using
Single Step.
If the current statement is located in a subroutine, you can execute the rest of
the subroutine without it stopping by choosing Return. The execution of the
main program does not stop until after the subroutine has been executed.
Regards,
Balaji Reddy G
**Rewards if answers are helpful
12-29-2006 10:08 AM
HI,
You can wirte each funtionality of your program in perform statement, it will give more readability to your program.
Thanks,
Alex.