Your SlideShare is downloading. ×
0
Day 3
Modularisation Technique
&
BDCs
Modularization techniques
• Macros
• Include program
• Subroutines
• Function Module
Macros
• Callable modules of program code
Defining Macros - Syntax
DEFINE <macro>.
<statements>
ENDDEFINE.
Calling Macros ...
Macros…
Example
Defining Macros
DEFINE arithmetic.
result = &1 &2 &3.
Write: / ‘The result is ‘, result.
ENDDEFINE.
Callin...
Include Programs
• If we want to use the same sequence of statements in
several programs, we can code them once in an incl...
Using Include programs
Syntax
INCLUDE <name_of_the_include>.
Example
REPORT zrssales10.
INCLUDE zrsdecla10.
….
Write: / ‘D...
Subroutines
• Program module that can be called by any program.
• You use subroutines to avoid having to write frequently
...
Defining and calling subroutine
Definition - Syntax
FORM <subr_name>.
<statement block>.
ENDFORM.
Calling - syntax
Interna...
Defining and calling subroutine…
Example
Defining the subroutine
PROGRAM formpool.
FORM show.
WRITE: / ‘Program started by...
Passing parameters
Defining
FORM <subr> [TABLES <formal table list>]
[USING <formal input list>]
[CHANGING <formal output ...
Methods of passing parameters
1. Calling by Reference
2. Calling by value
3. Calling by value and result
1. Call by refere...
Call by reference
PERFORM calculate_tax USING fl1 fl2.
……..
FORM calculate_tax USING f1 f2.
CLEAR itab.
MOVE f1 TO itab-fl...
Methods of passing parameters
2. Call by value
FORM..... USING...VALUE(<fii>)..
PERFORM... USING.......<aii>..
3. Call by ...
Terminating the Subroutines
• Terminating subroutines unconditionally by Using the
command
EXIT
• Terminating Subroutines ...
Function Builder
• An ABAP Workbench Tool
• ABAP routines that are stored in a central function library
• Non application-...
Creating a Function Module – Step 1 of 7
Initial Parameters
SE37
Creating a Function Module – Step 2 of 7
General Attributes
Creating a Function Module – Step 3 of 7
Import and Changing Interface Parameters
Creating a Function Module – Step 4 of 7
Export Interface Parameters
Creating a Function Module – Step 5 of 7
Tables Interface Parameters
Creating a Function Module – Step 6 of 7
Exceptions
Creating a Function Module – Step 7 of 7
Source Code and Activation
Function module - Interface parameters
Import
Contains a list of the formal parameters that are used to
pass data to a fun...
Function module - Interface parameters
Tables
Specifies the tables that are to be passed to a function
module. Table param...
Adding the function module to the program
Click PATTERN button
in the edit program
screen of the ABAP
Editor
Adding the function module to the program
Choose the Call Function
Radio button and give the
name of the function
module a...
File Handling – OPEN DATASET
• Opens a file for reading, writing or for appending
• Syntax:
OPEN DATASET <dsn> [FOR INPUT|...
File Handling – READ DATASET
• Reads a file
• Syntax:
READ DATASET <dsn> INTO <f> [LENGTH <len>].
• <dsn> can be a logical...
File Handling – TRANSFER DATASET
• Syntax:
- Writing to a dataset
TRANSFER <f> TO <dsn> [LENGTH <len>].
- Closing a datase...
BDC - Batch Data Communication
• To transfer data from non-SAP systems ( ie. already
available in electronic form )
• Suit...
BDC - Methods
Sequential dataset
bdc table
queue dataset
function “batch input”
Application function
SAP Database
Sequenti...
BDC Methods
• Classical Method
• Call Transaction
• Call Dialog
BDC Methods
• Creating a session on the batch input queue
Standard method.
1) Offers management of sessions
2) Support for...
BDC Methods
• Call transaction using
1) Offers faster processing than standard method
2) The playback, interactive correct...
Preparing a BDC Table
• The BDC table should have five fields viz.,
1) Program name
2) Screen number
3) Screen begin
4) Fi...
Preparing a BDC Table
Example
Prog Screen Scrn Field Field
name No begin name value
SAPMMO3M 0060 X RM03M- MATNR mat.no
RM...
Creating a session on the batch input queue
• The BDC program can be generated by recording the
transaction . Transaction ...
Call Transaction using
Uses the command
CALL TRANSACTION <tran code> USING <bdctab>
MODE <mode>.
Bdctab - BDC Table ( Inte...
Job Scheduling
• Schedule a job – SM35
– Create a job
– Add program to be executed
– Set timing and date to be executed
Upcoming SlideShare
Loading in...5
×

3 modularisation and bdc

260

Published on

bdc & modulsation

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
260
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
30
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Navigate to the Function Builder using one of the methods:
    From the main menu, go to Tools  ABAP Workbench  Development, or
    Type SE37 on the Command Field.
    Type a valid function module name (starting with Y or Z). Press the “Create” pushbutton.
    In the popup window that appears, enter the Function Group name (if you have not created it already, create it by navigating to Goto  Function Groups  Create group.
    Click on the “Save” Button.
  • To get a list of valid Function Groups and Applications, click on the Possible Entries pushbutton on the standard toolbar or press F4.
    An existing function module can be copied by entering its name in the Copy from input field.
    Process Type of a function module must be declared:
    Normal if the function module can only be called from this system, and is not tailored for asynchronous database table updates.
    Remote-enabled for function modules that can be called from other systems (R/3 or non R/3 supporting LU6.2 or TCP/IP)
    Update for function modules that will perform asynchronous database updates:
    Start Immediately will run in the V1 update task.
    Immediate start no restart, same as above, but cannot be restarted using SM13.
    Start delayed will run in the V2 update task, after V1 update has completed.
    Collective run, will sit in the update queue until a background job is scheduled to clear them up. This is mostly used for sending OLTP data to BW or other information systems.
    The Attributes tab displays General Data about the Function module such as the person in charged of the function module, the date the function module was last changed, the development class, the status, etc.
  • Define the Import and Changing parameters in the appropriate tabs.
    Import and Changing parameters are flat in structure. Changing parameters can be used to change values in the Function Module while Import parameters are mostly passed by value.
    For each parameter, specify the type either:
    Nothing. Calling a function module is like calling a subroutine, you do not have to use actual/formal parameters. This method is not recommended for performance reasons, since type assignment will be done by the system at run time.
    LIKE by a reference to a structure or field of the Dictionary.
    TYPE by reference to a SAP supplied pre-defined data type (Char, Integer, Numeric Character) or data element.
    TYPE REFERENCE to a user defined data type(TYPE REF must be defined in the top include for the function module).
    If parameters are typed, then calling program must use same types, otherwise a run time error will occur.
    An Import or Changing parameter can have a default value that is used when the calling program does not set this parameter explicitly. Enter the default value in the default value column.
    Import parameters (from the function point of view) and Changing parameters can be classified by the developer as optional parameters. In this case, the caller of the function need not pass a value to this parameter, and the runtime system chooses the initial value of the corresponding type.
    Parameters with a value in the default value column are always optional. If an input parameter is not classified as optional, it should be set by the caller; otherwise, a runtime error occurs.
  • Export Parameters would be passed back to the calling program by the function module.
    We could use the Changing parameters for passing back values to the program as well.
    Export parameters are generally passed by value.
  • Internal Tables are also included in the interface. For performance reasons, an internal table is always passed by reference parameter.
    Like Import and Changing parameters, Tables parameters can also be marked “Optional”.
    Internal tables must be typed if the structure of the table must be known to the function module.
  • Exceptions are used to handle abnormal conditions in the processing logic in the function module.
    The exceptions defined can be “raised” in the main function module for raising any user-defined errors.
    The “RAISE” ABAP command is used to raise an exception (RAISE RECORD_NOT_FOUND).
    On raising an exception, the processing terminates in the function module and control is handed over to the calling program.
    In the calling program, sy-subrc is set to positive number greater than zero corresponding to the position of the exception in the exception definition. For example, in the above screen, raising RECORD_NOT_FOUND would set sy-subrc to 1 while raising INVALID_DATE would set sy-subrc to 4.
  • The source code would contain ABAP code which would receive the input parameters, process the data and pass the output back to a calling program (or another function module).
    All the main processing logic should be contained within the FUNCTION – ENDFUNCTION boundaries.
    If there are any subroutines (FORMs) that need to be created for modularizing code in the function module, the FORM definitions should be after the ENDFUNCTION statement.
    Typically, one would create a separate INCLUDE (program of type “I”) to hold the subroutines.
    A TOP include could also be created to define global variables that can be accessed by any function module in the function group.
    All includes created need to be separately activated.
    Once, a syntax check is successfully completed, the function module can be Activated by pressing the “Activate” button on the Application Toolbar.
  • Opens a file &amp;lt;dsn&amp;gt; on the application server. The additions determine whether the file is for reading or writing, whether the contents are to be interpreted in binary or character form, the position in the file, the location to which an operating system can be written, and allow you to execute an operating system command.
    Filenames are platform-specific. You must therefore use file- and pathnames that conform to the rules of the operating system under which your R/3 System is running. However, you can also use logical filenames to ensure that your programs are not operating system-specific.
  • Reads the contents of the file &amp;lt;dsn&amp;gt; on the application server to the variable &amp;lt;f&amp;gt;. The number of bytes transferred can be written to &amp;lt;len&amp;gt;.
  • Before reading or writing to a dataset, the dataset should be OPENed using the OPEN DATASET and in appropriate mode.
    After completing the process, it is a good practice to close the dataset using the CLOSE DATASET statement.
  • Transcript of "3 modularisation and bdc"

    1. 1. Day 3 Modularisation Technique & BDCs
    2. 2. Modularization techniques • Macros • Include program • Subroutines • Function Module
    3. 3. Macros • Callable modules of program code Defining Macros - Syntax DEFINE <macro>. <statements> ENDDEFINE. Calling Macros - Syntax <macro> [ <p1> <p2> ….<p9>].
    4. 4. Macros… Example Defining Macros DEFINE arithmetic. result = &1 &2 &3. Write: / ‘The result is ‘, result. ENDDEFINE. Calling Macros arithmetic 4 + 5. Output The result is 9
    5. 5. Include Programs • If we want to use the same sequence of statements in several programs, we can code them once in an include program and call it in the other programs wherever it is required • Include programs cannot contain PROGRAM or REPORT Statements • Include programs cannot call themselves • Include programs must contain complete statements
    6. 6. Using Include programs Syntax INCLUDE <name_of_the_include>. Example REPORT zrssales10. INCLUDE zrsdecla10. …. Write: / ‘Date:’, sy-datum.
    7. 7. Subroutines • Program module that can be called by any program. • You use subroutines to avoid having to write frequently used program components more than once. Data can be passed explicitly from and to subroutines. • Types of subroutine – internal subroutines – external subroutines
    8. 8. Defining and calling subroutine Definition - Syntax FORM <subr_name>. <statement block>. ENDFORM. Calling - syntax Internal Subroutines PERFORM <subr_name>. External Subroutines PERFORM <subr_name> (<prog>) [IF FOUND]. <Prog> - Program name IF FOUND - If this is specified and there is no subroutine <sub> in the program <prog>, the system ignores the PERFORM statement.
    9. 9. Defining and calling subroutine… Example Defining the subroutine PROGRAM formpool. FORM show. WRITE: / ‘Program started by’, sy-uname. ENDFORM. Calling the subroutine from a program PROGRAM sapmztst. PERFORM show(formpool) IF FOUND
    10. 10. Passing parameters Defining FORM <subr> [TABLES <formal table list>] [USING <formal input list>] [CHANGING <formal output list>].… Calling PERFORM <subr>[(<prog>)] [TABLES <actual table list>] [USING <actual input list>] [CHANGING <actual output list>].…
    11. 11. Methods of passing parameters 1. Calling by Reference 2. Calling by value 3. Calling by value and result 1. Call by reference FORM..... [USING <fi1>... <fi n>] [CHANGING <fo 1>... <fo n>]... PERFORM... [USING <ai1>... <ai n>] [CHANGING <ao 1>... <ao n>]...
    12. 12. Call by reference PERFORM calculate_tax USING fl1 fl2. …….. FORM calculate_tax USING f1 f2. CLEAR itab. MOVE f1 TO itab-fl1. APPEND itab. ENDFORM. Actual Parameters Formal Parameters In this example, parameters are passed by reference. This is the most common, and most cost effective, method of parameter passing.
    13. 13. Methods of passing parameters 2. Call by value FORM..... USING...VALUE(<fii>).. PERFORM... USING.......<aii>.. 3. Call by value and result FORM..... CHANGING...VALUE(<fii>).. PERFORM... CHANGING.......<aii>..
    14. 14. Terminating the Subroutines • Terminating subroutines unconditionally by Using the command EXIT • Terminating Subroutines conditionally by Using the command CHECK
    15. 15. Function Builder • An ABAP Workbench Tool • ABAP routines that are stored in a central function library • Non application-specific, and available system wide • Must belong to a pool called a function group
    16. 16. Creating a Function Module – Step 1 of 7 Initial Parameters SE37
    17. 17. Creating a Function Module – Step 2 of 7 General Attributes
    18. 18. Creating a Function Module – Step 3 of 7 Import and Changing Interface Parameters
    19. 19. Creating a Function Module – Step 4 of 7 Export Interface Parameters
    20. 20. Creating a Function Module – Step 5 of 7 Tables Interface Parameters
    21. 21. Creating a Function Module – Step 6 of 7 Exceptions
    22. 22. Creating a Function Module – Step 7 of 7 Source Code and Activation
    23. 23. Function module - Interface parameters Import Contains a list of the formal parameters that are used to pass data to a function module. Export Contains a list of the formal parameters that are used to receive data from a function module. Changing Contains a list of the formal parameters that are used both to pass data to and receive data from a function module.
    24. 24. Function module - Interface parameters Tables Specifies the tables that are to be passed to a function module. Table parameters are always passed by reference. Exceptions Shows how the function module reacts to exceptions. The function definition is written in the editor (Source code)
    25. 25. Adding the function module to the program Click PATTERN button in the edit program screen of the ABAP Editor
    26. 26. Adding the function module to the program Choose the Call Function Radio button and give the name of the function module and enter it
    27. 27. File Handling – OPEN DATASET • Opens a file for reading, writing or for appending • Syntax: OPEN DATASET <dsn> [FOR INPUT|OUTPUT|APPENDING] [IN BINARY|TEXT MODE] [AT POSITION <pos>] [MESSAGE <mess>] [FILTER <filt>]. • <dsn> can be a logical or physical file names
    28. 28. File Handling – READ DATASET • Reads a file • Syntax: READ DATASET <dsn> INTO <f> [LENGTH <len>]. • <dsn> can be a logical or physical file names • Logical file names can be created in customizing
    29. 29. File Handling – TRANSFER DATASET • Syntax: - Writing to a dataset TRANSFER <f> TO <dsn> [LENGTH <len>]. - Closing a dataset CLOSE DATASET <dsn>.
    30. 30. BDC - Batch Data Communication • To transfer data from non-SAP systems ( ie. already available in electronic form ) • Suitable for entering large amounts of data as it executes the transactions automatically • Similar to entering the data in the transactions manually - All validations are done Advantages of Batch input • No manual intervention is needed • Ensures data integrity
    31. 31. BDC - Methods Sequential dataset bdc table queue dataset function “batch input” Application function SAP Database Sequential dataset bdc table call transaction / call dialog Application function SAP Database Batch Input Call transaction / call dialog
    32. 32. BDC Methods • Classical Method • Call Transaction • Call Dialog
    33. 33. BDC Methods • Creating a session on the batch input queue Standard method. 1) Offers management of sessions 2) Support for playing back 3) Correcting sessions that contain errors 4) Detailed logging
    34. 34. BDC Methods • Call transaction using 1) Offers faster processing than standard method 2) The playback, interactive correction, and logging facilities offered for batch input sessions are not available for CALL TRANSACTION USING. • Call dialog 1) Outdated and more complex (Not Recommended)
    35. 35. Preparing a BDC Table • The BDC table should have five fields viz., 1) Program name 2) Screen number 3) Screen begin 4) Field name 5) Field value
    36. 36. Preparing a BDC Table Example Prog Screen Scrn Field Field name No begin name value SAPMMO3M 0060 X RM03M- MATNR mat.no RM03M-MBRSH indu. sec . . SAPMM03M 0080 X RM03M-WERKS target pla . .
    37. 37. Creating a session on the batch input queue • The BDC program can be generated by recording the transaction . Transaction code - SHDB • To execute the session, go to transaction code SM35 and execute by selecting the session ( All session methods will automatically create as a job) • The BDC can be run in foreground, background or it can display only the error screens.
    38. 38. Call Transaction using Uses the command CALL TRANSACTION <tran code> USING <bdctab> MODE <mode>. Bdctab - BDC Table ( Internal table ) mode ‘A’ - All screens ‘N’ - No screens ‘E’ - Error screens only
    39. 39. Job Scheduling • Schedule a job – SM35 – Create a job – Add program to be executed – Set timing and date to be executed
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×