You are on page 1of 39

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 - Syntax


<macro> [ <p1> <p2> .<p9>].
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
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
Using Include programs

Syntax
INCLUDE <name_of_the_include>.

Example
REPORT zrssales10.
INCLUDE zrsdecla10.
.
Write: / Date:, sy-datum.
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
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.
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
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>].
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>]...
Call by reference
Actual Parameters

PERFORM calculate_tax USING fl1 fl2.


..
FORM calculate_tax USING f1 f2.
CLEAR itab.
MOVE f1 TO itab-fl1.
APPEND itab.
ENDFORM. Formal Parameters

In this example, parameters are passed by


reference. This is the most common, and most
cost effective, method of parameter passing.
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>..
Terminating the Subroutines

Terminating subroutines unconditionally by Using the


command
EXIT

Terminating Subroutines conditionally by Using the


command
CHECK
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


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 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.
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)
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 and enter it
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
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
File Handling TRANSFER DATASET

Syntax:
- Writing to a dataset
TRANSFER <f> TO <dsn> [LENGTH <len>].
- Closing a dataset
CLOSE DATASET <dsn>.
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
BDC - Methods
Batch Input Call transaction / call dialog
Sequential dataset Sequential dataset

bdc table bdc table

queue dataset call transaction /


call dialog
function batch input
Application function
Application function

SAP Database
SAP Database
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 playing back
3) Correcting sessions that contain errors
4) Detailed logging
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)
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
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
.
.
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.
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
Job Scheduling

Schedule a job SM35


Create a job
Add program to be executed
Set timing and date to be executed

You might also like