presentation on macros

Upload: niroop-raj

Post on 07-Aug-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/21/2019 Presentation on Macros

    1/21

  • 8/21/2019 Presentation on Macros

    2/21

    WHAT IS MEANT BY

    MODULARIZATION ?In General Modularization is the degree to which a system's components may be separated

    and recombined.

  • 8/21/2019 Presentation on Macros

    3/21

    THERE ARE DIFF.

    MODULARIZATION TECHNIQUES

    Macros

    Subroutine-Perform

    Function Module.

    Include

    Methods--- Oops

  • 8/21/2019 Presentation on Macros

    4/21

    D I F F E R E N C E B / WM A C R O S & S U B R O U T I N E S

    MACROS:

    Macros can only be used in the program the are defined in and only after the definition.

    Macros can take max 9 parameters.

    Macros are expanded at compilation / generation.

    SUBROUTINES:

    Subroutines (FORM) can be called from both the program the are defined in and other

    programs ('perform ' of 'perform in program ').

    Subroutines can take any amount of parameters.

    Subroutines are 'expanded' at runtime.

  • 8/21/2019 Presentation on Macros

    5/21

    D I F F E R E N C E B / WS U B R O U T I N ES & F U N C T I O N M O D U L E

    SUBROUTINES:

    The name of a SUBROUTINE must be unique within the program (two programs can have different SUBROUTINEs with

    the same name). A SUBROUTINE is intended to be called internal (from within the program, however by a 'trick' you can

    call them external).

    FUNCTION MODULE:

    The name of a FUNCTION has to be unique throughout the system. A FUNCTION is intended to be called external (and is

    thus shared by 'many' programs).

    The latter is more important for programmers and maintenance. Since a FUNCTION is called external, it is important to

    keep the interface (parameters) the same. The interface of a FORM (which is intended to be called internal) is check when

    debugging a program (but it is only checked within the program that is debugged). So if the interface of a FORM is changed,but the call to the FORM (perform ) is not, the debugger will notice this and issue an error message.

  • 8/21/2019 Presentation on Macros

    6/21

    D I F F E R E N C E B / WF U N C T I O N M O D U L E & I N C L U D E

    Function Module :Function Modules are stored in the central

    library and can be called from any program. Even the functionmodules(RFC enabled) can be called from non-SAP systems.

    Include:Include programs allow you to use the same source code

    in different programs.They are mainly used for modularizing

    source codeand have no parameter interface.

  • 8/21/2019 Presentation on Macros

    7/21

    DIFFERENCE B/W

    INCLUDE & METHODS

    INCLUDE: If I am defining the same variables in many programs,

    instead of defining in all programs we have define all the variables in oneprogram and that program is included or added to the programs

    whenever needed thats called include program. It cannot be executed

    independently it has to include in a program.

    METHODS:It describes the functions and behavior of classes and

    their instances in ABAP objects methods must be defined in classes.

  • 8/21/2019 Presentation on Macros

    8/21

    WHY WE ARE USING

    MACROS?

    If we want to reuse same set of statements more than once in

    program , we can include them in a macros.

    Ex: statements like write, clear, form calls, and DB statements such as

    SELECT and UPDATE.

  • 8/21/2019 Presentation on Macros

    9/21

    WHAT IS THE SYNTAX OF

    MACROS?

    DEFINE . ...

    END-OF-DEFINITION.

  • 8/21/2019 Presentation on Macros

    10/21

    DEMO PROGRAM-1

    Program Name: ZPW_MACRO1

    DEFINE print. write:/ 'Hello Macro'.

    END-OF-DEFINITION.

    WRITE:/ 'Before Using Macro'.

    print.

    OutPut :

  • 8/21/2019 Presentation on Macros

    11/21

    DEMO PROGRAM-2

    Program Name:

    DEFINE print. write:/ 'Hello', &1, &2.

    END-OF-DEFINITION.

    WRITE:/ 'Before Using Macro'.

    print 'ABAP' 'Macros'.

    Output:

  • 8/21/2019 Presentation on Macros

    12/21

    WHAT ARE THE

    LIMITATIONS OF MACROS?

    We can use macros with in the program in which it is

    defined.(Prog Name: zpw_macro1)

    Macros definition should occur before the macro is used in the

    program.(Prog.Name:zpw_macro2)

    We can pass up to 9 place holders to macros.

    Macros can be useful for long Calculations or complex writestatements:-(Prog. Name :zpw_macro3)

  • 8/21/2019 Presentation on Macros

    13/21

    Other than readability and meaning fulness macros also offer

    Performance Advantage.(Prog. Name:ZPW_MACRO4).

    We cant call this macro from another program,But you can call

    global macros from another program.

    http://saptechnical.com/Tips/ABAP/GlobalMacros/Define.htm

    http://saptechnical.com/Tips/ABAP/GlobalMacros/Define.htmhttp://saptechnical.com/Tips/ABAP/GlobalMacros/Define.htm
  • 8/21/2019 Presentation on Macros

    14/21

    DIFFERENT WAYS OF

    USING MACROS?

    Data Declaration

    Complex write statement

    Reading or changing variable values

    Formulas / calculations

    Nesting macros

    Program flexibility

    Working with heavy data.(Prog.Name:zpw_macro5)

  • 8/21/2019 Presentation on Macros

    15/21

    Most Popular Example of System Macros or Standard global

    macros is BREAK.Which is defined in table TRMAC

  • 8/21/2019 Presentation on Macros

    16/21

    PROS AND CONS OF

    MACROS

    Pros:

    Macro is faster than other modularization techniques ex. sub-routines (http://sap-

    abap-tricks.blogspot.in/2011/10/macro.html)

    Program Name:zpw_macro7,8,9,10

    Cons:

    Macros can't be debugged. Hence, complex code should not be written inside

    macros

    http://sap-abap-tricks.blogspot.in/2011/10/macro.htmlhttp://sap-abap-tricks.blogspot.in/2011/10/macro.htmlhttp://sap-abap-tricks.blogspot.in/2011/10/macro.htmlhttp://sap-abap-tricks.blogspot.in/2011/10/macro.htmlhttp://sap-abap-tricks.blogspot.in/2011/10/macro.htmlhttp://sap-abap-tricks.blogspot.in/2011/10/macro.htmlhttp://sap-abap-tricks.blogspot.in/2011/10/macro.html
  • 8/21/2019 Presentation on Macros

    17/21

    PROS AND CONS OF

    SUBROUTINE

    PROs

    Reducing duplicate code within a program

    Enabling reuse of code across multiple programs

    Dividing a large programming task among various programmers, or various stages of

    a project

    Hiding implementation details from users of the subroutine

    Improving traceability,

    CONS:

    Exceptions cannot be handled by subroutines. .(Prog.Name:ZPW_SUBROUTINE)

  • 8/21/2019 Presentation on Macros

    18/21

    PROS AND CONS OF

    FUNCTION MODULE

    PROS:

    it is one of the modularization techniques which helps code re-usability.

    We can handle exceptions using function modules.

    CONS:

    Using FM we can Communicate With in SAP Systems Only

  • 8/21/2019 Presentation on Macros

    19/21

    PROS AND CONS OF

    INCLUDE

    PROS:

    Good Readability.

    CONS:

    An include program cannot run independently, but must be built into other programs.

    Include programs can contain other includes.

    The only restrictions for writing the source code of include programs are:

    Include programs cannot call themselves.

    Include programs must contain complete statements.

    The INCLUDE statement has the same effect as copying the source code of the include program into the

    program. In the syntax check, the contents of the include program are also analyzed. Include programs are not

    loaded at runtime, but are expanded when the program is generated. Once the program has been generated, the

    load version contains static versions of all of its includes. If you subsequently change an include program, the

    programs that use it are automatically regenerated.(PROG. NAME:ZPW_INCULDE)

  • 8/21/2019 Presentation on Macros

    20/21

    PROS AND CONS OF

    METHODS

    PROS:

    CONS:

  • 8/21/2019 Presentation on Macros

    21/21