To use SubRoutines and function modules and include
Hellow Friends ,
Can any body suggest me at waht situations we have to use SubRoutines and function modules and include in an abap report and also i need the standards in an abap program.
Hi Rajesh,
You use create subroutines within your programs for those block of codes which are used often within the scope of the development. Function modules are like global subroutines , hence any number programs which might want to use the functionality within the function module can do so.
Creating includes is a good programming prctise, e.g. one for data declerations , one for subroutines, so that it makes the code more reader friendly and also helps in modularizing the program. Also once you put a subroutine in an include, you can use the same subroutine in other programs by referring to the include with the INCLUDE statement in your other programs.
Hence basically they are used for :
1. Reusability
2. Modularization of code (make it more readable)
Hope this is of some help.
Regards,
Aditya
Similar Messages
-
Using subroutines in Function Module
Hi , experts ,
I want to know how to use performs in function module,
If created subroutine must be used in all FM in Func.Group ?
if you have articles about this or any information , I will be glad .
Please help.
Regards,
Tatiana.If i am not mistaken you want to use forms in function module.
To enable forms in function module you have to follow these steps:
Create a Z include in your function module.
INCLUDE ZTEST_INCLUDE.
Inside this include you need to write your form routine which will be accessable from your function module.
Now you can use perform statement in your funtion module.
Thnaks & Regards,
Lalit Mohan Gupta -
Subroutine in function module exit include program
Hi Friend,
I want to modularise the code inside the include program defined in funtion module exit. but it is giving out errors.
Can any one help on this.
Regards
GauthamHello Gautam,
Use the PERFORM (FORM ................. ENDFORM.) for modularizing the code inside the function module exit. You can not use the include inside the function module directly but once u create a PERFORM (FORM ................. ENDFORM.). Inside this FORM ................. ENDFORM .. u can create any number of include's.
I hope it will resolve your problem.
Thanks.
Anurag -
Examples for using function modules and BApis.
My Dear FRNDS,
I am very new to ABAP. And I have read the documentation for function modules but i am not that clear to practice them.So I would be very happy if u people share a little bit of ur experience with me.
Please provide me some examples of all the use cases in function modules and specially exception handling.
Frnds, i am going to work with bapis so i feel practicing function module will give me a edge.
and please tell me after calling a BAPI FM why we have to perform 'BAPI_TRANSACTION_COMMIT' and 'BAPI_TRANSACTION_ROLLBACK'.
.Ur efforts will be greatly rewarded.
thx,
reshaliHi,
Please check this sample codes.
DATA: BAPI_Z05DOGI_DELIVERY LIKE BAPIOBDLVHDRCON-DELIV_NUMB ,
BAPI_Z05DOGI_HEADER_DATA LIKE BAPIOBDLVHDRCON OCCURS 0 WITH HEADER LINE ,
BAPI_Z05DOGI_HEADER_CONTROL LIKE BAPIOBDLVHDRCTRLCON OCCURS 0 WITH HEADER LINE,
BAPI_Z05DOGI_ITEM_DATA LIKE BAPIOBDLVITEMCON OCCURS 0 WITH HEADER LINE,
BAPI_Z05DOGI_ITEM_CONTROL LIKE BAPIOBDLVITEMCTRLCON OCCURS 0 WITH HEADER LINE ,
BAPI_Z05DOGI_RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE .
CLEAR: BAPI_Z05DOGI_DELIVERY , BAPI_Z05DOGI_HEADER_DATA , BAPI_Z05DOGI_HEADER_CONTROL , BAPI_Z05DOGI_ITEM_DATA ,BAPI_Z05DOGI_ITEM_CONTROL , BAPI_Z05DOGI_RETURN .
REFRESH: BAPI_Z05DOGI_HEADER_DATA , BAPI_Z05DOGI_HEADER_CONTROL , BAPI_Z05DOGI_ITEM_DATA , BAPI_Z05DOGI_ITEM_CONTROL , BAPI_Z05DOGI_RETURN .
BAPI_Z05DOGI_DELIVERY = ZMM_WB1-ISSUE .
BAPI_Z05DOGI_HEADER_DATA-DELIV_NUMB = ZMM_WB1-ISSUE.
APPEND BAPI_Z05DOGI_HEADER_DATA.
BAPI_Z05DOGI_HEADER_CONTROL-DELIV_NUMB = ZMM_WB1-ISSUE.
BAPI_Z05DOGI_HEADER_CONTROL-POST_GI_FLG = 'X'.
APPEND BAPI_Z05DOGI_HEADER_CONTROL.
BAPI_Z05DOGI_ITEM_DATA-DELIV_NUMB = ZMM_WB1-ISSUE.
BAPI_Z05DOGI_ITEM_DATA-DELIV_ITEM = 10.
BAPI_Z05DOGI_ITEM_DATA-DLV_QTY = LFIMGGIA.
BAPI_Z05DOGI_ITEM_DATA-SALES_UNIT = XTAB-MEINS.
BAPI_Z05DOGI_ITEM_DATA-DLV_QTY_IMUNIT = LFIMGGIA.
BAPI_Z05DOGI_ITEM_DATA-FACT_UNIT_NOM = UMVKZLIPS.
BAPI_Z05DOGI_ITEM_DATA-FACT_UNIT_DENOM = UMVKNLIPS.
APPEND BAPI_Z05DOGI_ITEM_DATA.
BAPI_Z05DOGI_ITEM_CONTROL-DELIV_NUMB = ZMM_WB1-ISSUE.
BAPI_Z05DOGI_ITEM_CONTROL-DELIV_ITEM = 10.
BAPI_Z05DOGI_ITEM_CONTROL-CHG_DELQTY = 'X'.
APPEND BAPI_Z05DOGI_ITEM_CONTROL.
CALL FUNCTION 'BAPI_OUTB_DELIVERY_CONFIRM_DEC'
EXPORTING
DELIVERY = BAPI_Z05DOGI_DELIVERY
HEADER_DATA = BAPI_Z05DOGI_HEADER_DATA
HEADER_CONTROL = BAPI_Z05DOGI_HEADER_CONTROL
TABLES
ITEM_DATA = BAPI_Z05DOGI_ITEM_DATA
ITEM_CONTROL = BAPI_Z05DOGI_ITEM_CONTROL
RETURN = BAPI_Z05DOGI_RETURN.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
IMPORTING
RETURN = BAPI_Z05DOGI_RETURN.
Go thru this link
http://www.planetsap.com/LIST_ALL_BAPIs.htm
BAPI_TRANSACTION_COMMIT
Execute external Commit when using BAPIs
This method executes a COMMIT WORK command. It is required for
transactions developed externally to the R/3 System that change data in
the R/3 System via BAPI calls.
When you call BAPIs in your program that change data in the R/3 System,
afterwards you must call this method to write the changes to the
database.
COMMIT WORK
The statement COMMIT WORK completes the current SAP LUW and opens a new one, storing all change requests for the currenta SAP LUW in the process
there are some FM that we use for creating trasaction . for example FM : that use for creating production order . if you execut the FM , the system will not create any data in the system so you need to excute the FM : BAPI_TRANSACTION_COMMIT to commit that creating the production order .
in case of commit work, that is a syntax in abap program . if you use this syntax after you insert ,update or delete table in the sap ,system will do it immediately otherwise the system will do it after execution is complete.
ROLLBACK WORK.
for confirming or undoing database updates. COMMIT WORK always concludes a database LUW and starts a new one. ROLLBACK WORK always undoes all changes back to the start of the database LUW.
Regards,
Raj. -
Macros, Function modules and subroutines
Hi Experts,
In performance wise which one is best macro or subroutine or Function module?
Thanks.Hi Nandini,
Each and every one has its importance in certain situations..
Macros
If you want to reuse the same set of statements more than once in a program, you can include them in a macro. For example, this can be useful for long calculations or complex WRITE statements. You can only use a macro within the program in which it is defined, and it can only be called in lines of the program following its definition.
Subroutines can call other subroutines (nested calls) and may also call themselves (recursive calls). Once a subroutine has finished running, the calling program carries on processing after the PERFORM statement. You can use the USING and CHANGING additions to supply values to the parameter interface of the subroutine.
Function modules allow you to encapsulate and reuse global functions in the SAP System. They are managed in a central function library. The SAP System contains several predefined functions modules that can be called from any ABAP program. Function modules also play an important role during updating and in interaction between different SAP systems, or between SAP systems and remote systems through remote communications.
Unlike subroutines, you do not define function modules in the source code of your program. Instead, you use the Function Builder. The actual ABAP interface definition remains hidden from the programmer. You can define the input parameters of a function module as optional. You can also assign default values to them. Function modules also support exception handling. This allows you to catch certain errors while the function module is running. You can test function modules without having to include them in a program using the Function Builder.
Best regards,
raam -
What is the difference between subroutine and function module?
What is the difference between subroutine and function module?
Hi,
they can both return values.
FMs are mainly used when a routine is to be performed by many programs.
Subroutines (forms) are generally only executed within one program.
You can perform routines from other programs, but it's not often done.
both forms and FMs are reusable modularization units.
To distinguish we generally say that forms are used for internal modularization and
FMs are used for external modularization.
To decide on which to implement, consider whether you need the content to be used just for a limited program
or wheteher it can be called from many independent programs.
For the first purpose it is better to implement a form whereas for the second we implement an FM.
However, ABAP does not isolate the usage context.
That is; you can call a form from another program within whose code the form is not actually implemented.
However, this requires attention since the form may utilize global variables.
The same issue holds for FMs.
FMs are encapsulated in function groups and function groups may have global variables that can be globally
used by all FMs inside it.
Thanks,
Reward If Helpful. -
Tracing Form and Function modules using SE30
Hi,
I want to trace only the Forms and function modules that are executed by a program using SE30. I have tried setting the variants in different ways but it still gives lot of junk information which i dont need. How can I set up the variant so that it only traces Forms and function modules executed by a program?
Will give points to right answer. Thanks for readingHi Srikrishna,
First of all create a vraian tin SE30. While creating the variant, in th Tab 'Duratn/Type' select the radio buton 'NONE'. Now execute yur program and then analyse.Select 'GROUP HIT LIST' Icon which gives Function Modules,Subroutines etc.
Regards,
Srinivas. -
Custome BAPI - declare ITAB and define the Function Module and Subroutine
Hello Experts
I want to create a Custom BAPI and it has the following scenario:
1) a Function Module which collects some records into it internal table, say ITAB
2) a Subroutine which moved the records from ITAB to BAPI table
Now, I want to declare ITAB and define the Function Module and Subroutine.
Where and How can I do this?
Plz suggest.
Regards
BDHi,
1) Got to SE37 and create an RFC .
2) Declare the ITAB directly in the TABLES tab of the FM.
3) Inside the FM source Code tab, collect all the data using SELECT query and directly or by using logic, put the data into the
ITAB.
4) Since the data collected is directly put into the itab you dont need a subroutine to be written.
5) If subroutine is a necessity, then just write PERFORM SUB ROUTINE NAME.
AND DEFINE THE FORM ENDFORM OF THE SUBROUTINE AFTER THE ENDFUNCTION OF THE FM
Let me know if any issues....
Regards,
Vimal. -
Difference between Function module and a subroutine
hi
In the case of subroutine i can access the global workarea values.
I want to know whether in the case of function module
whether
i can follow the same procedure to access the workarea values
or
i have to pass this workarea values as an import or tables parameter to the function module and then use it
(in first case whether that workarea to make global whether i have to place it in function pool please check this but which is better one)
Thx in advance for any replies.Yes
You would have to pass the values as import parameters to access the global variables of the program otherwise you will not be able to get the values of the global variable from inside the program.
Another solution would be to export to SAP memory but the entire concept of modularization of using the FM would be lost. -
Diff between Function Module and subroutine
sir,
explain the difference between Function Module and Subroutine.Hi Sandeep,
Subroutines:
Subroutines are procedures that you can define in any ABAP program and also call from any program. Subroutines are normally called internally, that is, they contain sections of code or algorithms that are used frequently locally. If you want a function to be reusable throughout the system, use a function module.
Function Modules:
Function modules are procedures that are defined in function groups (special ABAP programs with type F) and can be called from any ABAP program. Function groups act as containers for function modules that logically belong together. You create function groups and function modules in the ABAP Workbench using the Function Builder.
Function modules allow you to encapsulate and reuse global functions in the R/3 System. They are stored in a central library.
Unlike subroutines, you do not define function modules in the source code of your program. Instead, you use the Function Builder.
Regards,
Sunil -
Difference between function module and subroutines
hey all...
can u pls explai me the exact difference between subroutines and function modules...
also, when is a sub routine used and also when is a function module used..???
regards..
vishalHi Vishal,
Basically they do the same thing and purpose is almost same but tecnically the are way apart:
Function modules must belong to a pool called a function group.
They possess a fixed interface for data exchange. This makes it easier for you to pass input and output parameters to and from the function module.
For example, you can assign default values to the input parameters. The interface also supports exception handling. This allows you to catch errors and pass them back to the calling program for handling.
They use their own memory area. The calling program and the function module cannot exchange data using a shared memory area - they must use the function module interface. This avoids unpleasant side effects such as accidentally overwriting data.
You call a function module by its name (which must be unique) in a CALL FUNCTION statement.
and also
Unlike subroutines, you do not define function modules in the source code of your program. Instead, you use the Structure link Function Builder.
Check this link too
Re: Regarding difference between Subroutines and Function modules
Hope this helps you,
Regards
Amit
Message was edited by: Amit Kumar -
Using select option and function module in single view
Hi All,
I Have a requirment ,using service call i get a function module and bind to specified UI elements with low and high attributes to input fileds which i designed in my view . And i have to keep range for input values using select options for those input values and clicking on submit i have to display data in VC but it's going to dump
the bug is
Adapter error in INPUT_FIELD "SALEDOC_TXT" of view "ZSD_ORDERSTATUS.MAIN": Context binding of property VALUE cannot be resolved: Node COMPONENTCONTROLLER.1.ZSD_ORDER_STATUS.1.CHANGING.1.S_VBELN does not contain any elements
can any one get me out of this.
Thank U,
MadhanHi,
Call FM using CALL FUNCTION, if you want to pass selectoptions type values to FM..
Try like this...
DATA : delivery TYPE TABLE OF RVBELN,
wa_delivery TYPE RVBELN,
wa_delivery-sign = 'E'.
wa_delivery-option = 'BT'.
wa_delivery-low = lv_FROM_DELIVERYNO.
wa_delivery-high = lv_TO_DELIVERYNO.
APPEND wa_delivery to delivery.
CLEAR wa_delivery.
Pass Delivery to FM.
Cheers,
Kris. -
Generic extraction using function module and view
hi every one ,
iam new to bw and can anyone plz tell me how to extract the data from R/3 to bw using generic extractor by creating function module and a view
thank u,
kishoreHi Kishore,
Check this blog:
/people/siegfried.szameitat/blog/2005/09/29/generic-extraction-via-function-module
Also Check this doc:
http://help.sap.com/saphelp_nw04/helpdata/en/3f/548c9ec754ee4d90188a4f108e0121/frameset.htm
Generic Extractors
Generic data sources
Generic DS
Bye
Dinesh -
Comparing ALV using Function modules and OO ALV
Hi All,
Please provide me what are the advantages of developing ALV using Objects compared to creation using function modules. What are the disadvantages of creating using the conventional FM way.
I have not worked much on ALV using Function modules, have been developing using standard abap classes. I wanted to have an detailed understanding and differences between the two.
Please provide your views on the same.
I have searched SDN forum, but didnt find much information, so it will be of great help if you provide some inputs.
Thanks & Regards,
Navneeth K.Hello,
Check this link
ALV FUNCTION MODULE AND OBJECT ORIENTED ?
Example programs
http://saplab.blogspot.com/2007/10/sample-abap-program-of-alv-grid-control.html
http://www.abapcode.info/2007/06/object-oriented-alv-using-two.html -
I need to know thelist of bapi's and function modules used for transaction
I need to know thelist of bapi's and function modules used for transaction in order to use these FM or BAPI in reading some fields of equipment master and functional loocation.Can any one suggest me some methods...or do i need to write a report for the same.
Steps to find the BAPI/function modules used in a transaction
1) Find the package of the transaction thro' SE93.
For example the package for the transaction VA03 is VA
2) Go to Se80, key-in the package (say VA)
3) You can see the function modules under the folder finction group and
you can see the BAPI's under the folder Business Engineering-> Business Objects-> double click on the released methods of the Business Objects
Maybe you are looking for
-
Why I can't restore my iphone4
when it is restoring, it always show (1004) error.how come?
-
Hi, I have a question and I just can't find the answer in the forum. I work on a mac book pro, with an external monitor La Cie which is calibrated (hardware calibration). The color of the pictures are nice when in lightroom or photoshop but not outsi
-
Error message after installing latest FlashPlayerPlugin
After installing FlashPlayerPlugin_11_9_900_117.exe with the downloaded install file install_flashplayer11x32_mssd_aih.exe when I open Firefox and go to another tab I get this error message: The exception unknown software exception (0xc0000710) occur
-
How use c:forEach to loop over a String[][]
Hello, Is there anyone that can tell me how to use the c:forEach tag to loop over a double String[][]? I can find examples for resultsets etc....but whatever I try with my String[][], I never can get the results on the screen. Thanx, debeumers
-
Problem w/ Case Statement and Video Capture
Hey! I've got a question about a topic which seems pretty trivial, but has been giving me quite the trouble for some time now. I was hoping that someone on this forum would be able to help me catch and fix my mistake. Basically what I'm trying to do