3 modularity in abap_ macro,include,subroutines,function modules & groups

Upload: raza887

Post on 03-Apr-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 3 Modularity in ABAP_ Macro,Include,Subroutines,Function Modules & Groups

    1/6

    3/18/13 Modularity in ABAP: Macro,Include,Subroutines,Function Modules & Groups

    www.saptraininghub.com/sap-macro-include-function-module-group-subroutine/

    Sap Training Hub

    Free SAP Training & Tutorials

    What is SAP?

    ABAP

    HR

    FICO

    SD

    Video

    Payroll

    Quiz

    Java

    Testing

    Answers

    Modularity in ABAP:

    Macro,Include,Subroutines,Function Modules &

    Groups

    When you modularize source code, you place a sequence of ABAP statements in a module. Then, instead of placing all

    of the statements in your main program, you just call the module.When the program is generated, the source code in the

    modularization unit is treated as though it were actually physically present in the main program.

    Need of Modularization

    Improve the structure of the program.

    Easy to read the code

    Choose Gmail NowMail.Google.com

    You Get Less Spam, More Storage &Free SMS! Start Enjoying Gmail now.

    Function Pointsdavidconsultinggroup.com/learnFP

    Learn IFPUG function points Contact usfor customized training.

    2TB Cloud Storage $12/mthwww.livedrive.com

    Appears on your computer like any disk

    drive. Access files anywhere.

    http://www.googleadservices.com/pagead/aclk?sa=L&ai=CQx2HWZpGUeWxJoesigbLr4CwA5qV4uoC4uft20bAjbcBEAMgm8zvIygDUIeL4bj______wFgywSgAf6o7PUDyAEBqQK2O9sLG1G5PqgDAcgD0wSqBKQBT9Ab7_LvGKLZn8hM2bLmjQWLvwVIplO3ialO7k3-AUJzReNZPFX7bs5ppq5-M5vTcw6BtBuAesSCRDtU-ZsN99WWdEQ7w7rhDVmJfmuQFnEF5wzMhZ1CRDypJQRcNJ596T34gUW2B-FpVyIwqoh6DXNfCVKvW6p_6cH-B99QW_FePKjPsvuWeZmy7KPHJPHps5uwwh41YVd9N7qn49q6f30gi4SIBgGAB-rWkwo&num=3&cid=5Gi95FR2Xsi17aHSPaSZkr-g&sig=AOD64_1BBf1FshMj7MndOThH2gVj0G3LXQ&client=ca-pub-6330153051175486&adurl=http://www.livedrive.com/in/sync_briefcase%3Ftid%3Dadwordsnewendisplaygenericcloudsync.briefcaselandingpage%23oprhttp://googleads.g.doubleclick.net/aclk?sa=L&ai=CHz9_WZpGUeWxJoesigbLr4CwA7L4y-MC0tzG_zXAjbcBEAIgm8zvIygDUIC2r-8GYMsEyAEBqAMByAPTBKoEngFP0DvL9e8ZotmfyEzZsuaNBYu_BUimU7eJqU7uTf4BQnNF41k8Vftuzmmmrn4zm9NzDoG0G4B6xIJEO1T5mw331ZZ0RDvDuuENWYl-a5AWcQXnDMyFnUJEPKklBFw0nn3pPfiBRbYH4WlXIjCqiHoNc18JUq9bqn_pwf4H31Bb8V48qM-y-7Z4HMtNrdok7AGwXrDCHDVhh2gyJD5T2YAHwNnNEg&num=2&sig=AOD64_1osTj2XhN7TVZuxTj5QqM1WU8bYg&client=ca-pub-6330153051175486&adurl=http://www.davidconsultinggroup.com/training/fpa.aspx%3F_kk%3Dfunction%2520point%26_kt%3D1405587c-2c5c-4e13-937d-ff861d68cf0ahttp://www.googleadservices.com/pagead/aclk?sa=L&ai=CZ5pCWZpGUeWxJoesigbLr4CwA-iPvNAD2L7drE7AjbcBEAEgm8zvIygDUJ6VusEFYMsEoAHY2d3eA8gBAagDAcgD0wSqBJsBT9B77PnvGqLZn8hM2bLmjQWLvwVIplO3ialO7k3-AUJzReNZPFX7bs5ppq5-M5vTcw6BtBuAesSCRDtU-ZsN99WWdEQ7w7rhDVmJfmuQFnEF5wzMhZ1CRDypJQRcNJ596T34gUW2B-FpVyIwqoh6DXNfCVKvW6p_6cH-B99QW_FePKins-W2eAbWTaovJy70s55FwQzVZxdjyZuIBgGAB5CmoiE&num=1&cid=5Gi95FR2Xsi17aHSPaSZkr-g&sig=AOD64_0ySB3KbcWHRo3iGymPnhhJTwhNKg&client=ca-pub-6330153051175486&adurl=http://ad.doubleclick.net/clk%3B268213466%3B94044324%3Bhhttp://www.googleadservices.com/pagead/aclk?sa=L&ai=CQx2HWZpGUeWxJoesigbLr4CwA5qV4uoC4uft20bAjbcBEAMgm8zvIygDUIeL4bj______wFgywSgAf6o7PUDyAEBqQK2O9sLG1G5PqgDAcgD0wSqBKQBT9Ab7_LvGKLZn8hM2bLmjQWLvwVIplO3ialO7k3-AUJzReNZPFX7bs5ppq5-M5vTcw6BtBuAesSCRDtU-ZsN99WWdEQ7w7rhDVmJfmuQFnEF5wzMhZ1CRDypJQRcNJ596T34gUW2B-FpVyIwqoh6DXNfCVKvW6p_6cH-B99QW_FePKjPsvuWeZmy7KPHJPHps5uwwh41YVd9N7qn49q6f30gi4SIBgGAB-rWkwo&num=3&cid=5Gi95FR2Xsi17aHSPaSZkr-g&sig=AOD64_1BBf1FshMj7MndOThH2gVj0G3LXQ&client=ca-pub-6330153051175486&adurl=http://www.livedrive.com/in/sync_briefcase%3Ftid%3Dadwordsnewendisplaygenericcloudsync.briefcaselandingpage%23oprhttp://www.google.com/url?ct=abg&q=https://www.google.com/adsense/support/bin/request.py%3Fcontact%3Dabg_afc%26url%3Dhttp://www.saptraininghub.com/sap-macro-include-function-module-group-subroutine/%26gl%3DPK%26hl%3Den%26client%3Dca-pub-6330153051175486%26ai0%3DCZ5pCWZpGUeWxJoesigbLr4CwA-iPvNAD2L7drE7AjbcBEAEgm8zvIygDUJ6VusEFYMsEoAHY2d3eA8gBAagDAcgD0wSqBJsBT9B77PnvGqLZn8hM2bLmjQWLvwVIplO3ialO7k3-AUJzReNZPFX7bs5ppq5-M5vTcw6BtBuAesSCRDtU-ZsN99WWdEQ7w7rhDVmJfmuQFnEF5wzMhZ1CRDypJQRcNJ596T34gUW2B-FpVyIwqoh6DXNfCVKvW6p_6cH-B99QW_FePKins-W2eAbWTaovJy70s55FwQzVZxdjyZuIBgGAB5CmoiE%26ai1%3DCHz9_WZpGUeWxJoesigbLr4CwA7L4y-MC0tzG_zXAjbcBEAIgm8zvIygDUIC2r-8GYMsEyAEBqAMByAPTBKoEngFP0DvL9e8ZotmfyEzZsuaNBYu_BUimU7eJqU7uTf4BQnNF41k8Vftuzmmmrn4zm9NzDoG0G4B6xIJEO1T5mw331ZZ0RDvDuuENWYl-a5AWcQXnDMyFnUJEPKklBFw0nn3pPfiBRbYH4WlXIjCqiHoNc18JUq9bqn_pwf4H31Bb8V48qM-y-7Z4HMtNrdok7AGwXrDCHDVhh2gyJD5T2YAHwNnNEg%26ai2%3DCQx2HWZpGUeWxJoesigbLr4CwA5qV4uoC4uft20bAjbcBEAMgm8zvIygDUIeL4bj______wFgywSgAf6o7PUDyAEBqQK2O9sLG1G5PqgDAcgD0wSqBKQBT9Ab7_LvGKLZn8hM2bLmjQWLvwVIplO3ialO7k3-AUJzReNZPFX7bs5ppq5-M5vTcw6BtBuAesSCRDtU-ZsN99WWdEQ7w7rhDVmJfmuQFnEF5wzMhZ1CRDypJQRcNJ596T34gUW2B-FpVyIwqoh6DXNfCVKvW6p_6cH-B99QW_FePKjPsvuWeZmy7KPHJPHps5uwwh41YVd9N7qn49q6f30gi4SIBgGAB-rWkwo&usg=AFQjCNHrLQ4c2LLgq6vmoUdY1Jbtc0B29ghttp://www.googleadservices.com/pagead/aclk?sa=L&ai=CQx2HWZpGUeWxJoesigbLr4CwA5qV4uoC4uft20bAjbcBEAMgm8zvIygDUIeL4bj______wFgywSgAf6o7PUDyAEBqQK2O9sLG1G5PqgDAcgD0wSqBKQBT9Ab7_LvGKLZn8hM2bLmjQWLvwVIplO3ialO7k3-AUJzReNZPFX7bs5ppq5-M5vTcw6BtBuAesSCRDtU-ZsN99WWdEQ7w7rhDVmJfmuQFnEF5wzMhZ1CRDypJQRcNJ596T34gUW2B-FpVyIwqoh6DXNfCVKvW6p_6cH-B99QW_FePKjPsvuWeZmy7KPHJPHps5uwwh41YVd9N7qn49q6f30gi4SIBgGAB-rWkwo&num=3&cid=5Gi95FR2Xsi17aHSPaSZkr-g&sig=AOD64_1BBf1FshMj7MndOThH2gVj0G3LXQ&client=ca-pub-6330153051175486&adurl=http://www.livedrive.com/in/sync_briefcase%3Ftid%3Dadwordsnewendisplaygenericcloudsync.briefcaselandingpage%23oprhttp://googleads.g.doubleclick.net/aclk?sa=L&ai=CHz9_WZpGUeWxJoesigbLr4CwA7L4y-MC0tzG_zXAjbcBEAIgm8zvIygDUIC2r-8GYMsEyAEBqAMByAPTBKoEngFP0DvL9e8ZotmfyEzZsuaNBYu_BUimU7eJqU7uTf4BQnNF41k8Vftuzmmmrn4zm9NzDoG0G4B6xIJEO1T5mw331ZZ0RDvDuuENWYl-a5AWcQXnDMyFnUJEPKklBFw0nn3pPfiBRbYH4WlXIjCqiHoNc18JUq9bqn_pwf4H31Bb8V48qM-y-7Z4HMtNrdok7AGwXrDCHDVhh2gyJD5T2YAHwNnNEg&num=2&sig=AOD64_1osTj2XhN7TVZuxTj5QqM1WU8bYg&client=ca-pub-6330153051175486&adurl=http://www.davidconsultinggroup.com/training/fpa.aspx%3F_kk%3Dfunction%2520point%26_kt%3D1405587c-2c5c-4e13-937d-ff861d68cf0ahttp://www.googleadservices.com/pagead/aclk?sa=L&ai=CZ5pCWZpGUeWxJoesigbLr4CwA-iPvNAD2L7drE7AjbcBEAEgm8zvIygDUJ6VusEFYMsEoAHY2d3eA8gBAagDAcgD0wSqBJsBT9B77PnvGqLZn8hM2bLmjQWLvwVIplO3ialO7k3-AUJzReNZPFX7bs5ppq5-M5vTcw6BtBuAesSCRDtU-ZsN99WWdEQ7w7rhDVmJfmuQFnEF5wzMhZ1CRDypJQRcNJ596T34gUW2B-FpVyIwqoh6DXNfCVKvW6p_6cH-B99QW_FePKins-W2eAbWTaovJy70s55FwQzVZxdjyZuIBgGAB5CmoiE&num=1&cid=5Gi95FR2Xsi17aHSPaSZkr-g&sig=AOD64_0ySB3KbcWHRo3iGymPnhhJTwhNKg&client=ca-pub-6330153051175486&adurl=http://ad.doubleclick.net/clk%3B268213466%3B94044324%3Bhhttp://www.83answers.com/http://www.guru99.com/http://www.javatutorialhub.com/http://www.saptraininghub.com/quiz/http://www.saptraininghub.com/sap-payroll/http://www.saptraininghub.com/sapvideos/http://www.saptraininghub.com/free-sap-sd-training-course/http://www.saptraininghub.com/sap-fico-training-tutorials/http://www.saptraininghub.com/sap-hcm/http://www.saptraininghub.com/abap-tutorial/http://www.saptraininghub.com/what-is-sap/http://feeds.feedburner.com/SapTrainingHubhttp://www.facebook.com/pages/Sap-Training-Hub/139632216092864http://twitter.com/SAPTHubhttp://www.saptraininghub.com/
  • 7/29/2019 3 Modularity in ABAP_ Macro,Include,Subroutines,Function Modules & Groups

    2/6

    3/18/13 Modularity in ABAP: Macro,Include,Subroutines,Function Modules & Groups

    www.saptraininghub.com/sap-macro-include-function-module-group-subroutine/

    Easy to maintain the code

    Avoid redundancy and promotes code reuse

    Various Modularization Techniques

    Use of Macros

    Use of include files

    Subroutines

    Function Modules

    Lets look into each of them in detail :

    SAP- ABAP Macro

    If you want to reuse the same set of statements more than once in a program, you can include them in a macro.

    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.

    Macros can be useful for long calculations or complex WRITE statements.

    Syntax

    DEFINE

    Macro Statements

    END-OF-DEFINITION

    Macros can use Parameters &Nwhere N = 1,2,3

    Example:-

    DATA: number1 TYPE I VALUE 1.

    DEFINE increment.

    ADD 1 to &1.

    WRITE &1.

    END-OF-DEFINITION.

    Increment number1.

    WRITE number1.

    Output: 2

    Include Programs

  • 7/29/2019 3 Modularity in ABAP_ Macro,Include,Subroutines,Function Modules & Groups

    3/6

    3/18/13 Modularity in ABAP: Macro,Include,Subroutines,Function Modules & Groups

    www.saptraininghub.com/sap-macro-include-function-module-group-subroutine/

    Include Programs are solely for modularizing source code, and have no parameter interface.

    Include programs allow you to use the same source code in different programs. They can be useful if you have lengthy

    data declarations that you want to use in different programs.

    Syntax

    Include

    Points to Note

    Include programs cannot call themselves.

    Include programs must contain complete statements.

    Example:

    INCLUDE ZILX0004.

    WRITE: / User, SY-UNAME,/ Date, SY-DATUM.

    ================================

    PROGRAM ZRPM0001.

    INCLUDE ZILX0004.

    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.

    Syntax-

    FORM [].

    .

    ENDFORM.

    = Name of the subroutine

    = Parameters being passed

    Types of Subroutines

    1. Internal

    Subroutine defined in same program being called.

    Can access all the data objects declared in the main ABAP/4 program.

    2. External

    Subroutine defined outside the program being called.

    Need to use the option or declare data objects in common parts of memory.

  • 7/29/2019 3 Modularity in ABAP_ Macro,Include,Subroutines,Function Modules & Groups

    4/6

    3/18/13 Modularity in ABAP: Macro,Include,Subroutines,Function Modules & Groups

    www.saptraininghub.com/sap-macro-include-function-module-group-subroutine/

    Calling a Subroutine

    Internal Subroutines

    PERFORM []

    = Name of the subroutine

    = Parameters being passed

    Data declared in main program is automatically available.

    External Subroutines

    PERFORM () [].

    PERFORM () [] [IF FOUND].

    PERFORM () IN PROGRAM () [] [IF FOUND].

    PERFORM OF [].

    Points to Note

    Nested calls are allowed in subroutines (i.e. PERFORM within a FORM ENDFORM ).

    Recursive calls are also possible.

    To define local data, use the DATA statement after FORM . Each time you enter the subroutine, the data is

    recreated (with an initial value) and released at the end (from the stack).

    To define global data used within a subroutine, use the LOCAL statement after FORM . The values are saved

    when you enter the subroutine and then released at the end (from the stack)

    Function Modules

    Function Modules are general purpose ABAP/4 routines that anyone can use. Infact , there are a large number of

    standard function Modules available.

    Function Modules are organized into Function Groups: Collections of logically related functions. A Function module

    always belongs to a Function Group.

    Syntax-

    FUNCTION

    ENDFUNCTION.

    Important information Associated with Function Module

    Administration

    Import/Changing/Export parameters.

    Table Parameters/Exceptions.

  • 7/29/2019 3 Modularity in ABAP_ Macro,Include,Subroutines,Function Modules & Groups

    5/6

    3/18/13 Modularity in ABAP: Macro,Include,Subroutines,Function Modules & Groups

    www.saptraininghub.com/sap-macro-include-function-module-group-subroutine/

    Documentation

    Source code LU01 . is the Function Group

    Global Data LTOP.Global data for the function group- Accessible across function modules in the

    function group.

    Main Program SAPL . Contains the list of all the include files for that function group

    Call a Function Module

    To call a function module, use the CALL FUNCTION statement:

    CALL FUNCTION

    [EXPORTING f1 = a 1.... f n = a n] [IMPORTING f1 = a 1.... f n = a n] [CHANGING f1 = a 1.... f n

    = a n] [TABLES f1 = a 1.... f n = a n] [EXCEPTIONS e1 = r 1.... e n = r n [ERROR_MESSAGE = r

    E] [OTHERS = ro]].

    Function Groups

    Function groups are containers for function modules. Infact, there are a large number of standard Function Groups.All of the function modules in a function group can access the global data of the group.

    Like executable programs (type 1) and module pools (type M), function groups can contain screens, selection screens,

    and lists.

    Points to Note

    Function Groups cannot be executed.

    The name of a function group can be up to 26 characters long.

    When you create a function group or function module, the main program and include programs are generated

    automatically.

    Function groups encapsulate data.

    How to create a Function Group

    1. Goto Transaction SE80.

    2. Select Program in the DropDown.

    3. Write the name of the Function Group That you want to create. Generally User made Function groups start with

    Z. e.g. . Hit Enter Key.

    4. Note that The TOP Include is create by default if the user checks the option of creating a TOP include.

    How to create a Function Module

    1. Create a function Group (say ZCAL).

    2. Create a function module, set the attributes like (Function group, Application, Short Text and Process Type) and

    Save.

    3. Include file LZCALU01 will have source code of first function module.

    4. Include file LZCALTOP will have global data.

    5. Main program SAPLZCAL contains

    Global data Include file LZCALTOP

    Function modules include file LZCALUXX

    User defined Include files LZCALF.., LZCALO.. and LZCALI..

  • 7/29/2019 3 Modularity in ABAP_ Macro,Include,Subroutines,Function Modules & Groups

    6/6

    3/18/13 Modularity in ABAP: Macro,Include,Subroutines,Function Modules & Groups

    www.saptraininghub.com/sap-macro-include-function-module-group-subroutine/

    6. Define interface parameters and Exceptions

    7. Write the source code

    8. Activate Function Module

    9. Testing the Function Module Single Test & Debugging

    10. Documenting and Releasing a Function Module

    Thats all to Modularity in ABAP.

    You might like:

    Recommended by

    Share6 Tweet0 Share0 +14 Share1007

    On January 28, 2011 / ABAP / Comments Off

    Comments are closed.

    Search

    FAQ

    How to Become SAP Consultant

    How to select the Best SAP Module

    How to create

    returns,free of

    charge delivery and

    sub sequent delivery

    Create Material

    Master for Sales

    View

    How to become SAP

    consultant

    Accounting Key How To Create

    Credit Memo

    http://www.saptraininghub.com/credit-memo-request/http://www.saptraininghub.com/accounting-key/http://www.saptraininghub.com/how-to-become-sap-consultant/http://www.saptraininghub.com/create-material-master-for-sales-view/http://www.saptraininghub.com/how-to-create-returnsfree-of-charge-delivery-and-sub-sequent-delivery/http://www.saptraininghub.com/credit-memo-request/http://www.saptraininghub.com/accounting-key/http://www.saptraininghub.com/how-to-become-sap-consultant/http://www.saptraininghub.com/create-material-master-for-sales-view/http://www.saptraininghub.com/how-to-create-returnsfree-of-charge-delivery-and-sub-sequent-delivery/http://www.saptraininghub.com/best-sap-module/http://www.saptraininghub.com/how-to-become-sap-consultant/http://www.saptraininghub.com/abap/