3 modularisation and bdc

39
Day 3 Modularisation Technique & BDCs

description

bdc & modulsation

Transcript of 3 modularisation and bdc

Page 1: 3 modularisation and bdc

Day 3

Modularisation Technique

&

BDCs

Page 2: 3 modularisation and bdc

Modularization techniques

• Macros

• Include program

• Subroutines

• Function Module

Page 3: 3 modularisation and bdc

Macros

• Callable modules of program code

Defining Macros - Syntax

DEFINE <macro>.

<statements>

ENDDEFINE.

Calling Macros - Syntax

<macro> [ <p1> <p2> ….<p9>].

Page 4: 3 modularisation and bdc

Macros…

Example

Defining MacrosDEFINE arithmetic.

result = &1 &2 &3.

Write: / ‘The result is ‘, result.

ENDDEFINE.

Calling Macros

arithmetic 4 + 5.

Output

The result is 9

Page 5: 3 modularisation and bdc

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

Page 6: 3 modularisation and bdc

Using Include programs

Syntax

INCLUDE <name_of_the_include>.

Example

REPORT zrssales10.

INCLUDE zrsdecla10.

….

Write: / ‘Date:’, sy-datum.

Page 7: 3 modularisation and bdc

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

Page 8: 3 modularisation and bdc

Defining and calling subroutine

Definition - SyntaxFORM <subr_name>.

<statement block>.ENDFORM.

Calling - syntaxInternal Subroutines

PERFORM <subr_name>.

External SubroutinesPERFORM <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.

Page 9: 3 modularisation and bdc

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

Page 10: 3 modularisation and bdc

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>].…

Page 11: 3 modularisation and bdc

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>]...

Page 12: 3 modularisation and bdc

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 byreference. This is the most common, and mostcost effective, method of parameter passing.

Page 13: 3 modularisation and bdc

Methods of passing parameters

2. Call by valueFORM..... USING...VALUE(<fii>)..

PERFORM... USING.......<aii>..

3. Call by value and resultFORM..... CHANGING...VALUE(<fii>)..

PERFORM... CHANGING.......<aii>..

Page 14: 3 modularisation and bdc

Terminating the Subroutines

• Terminating subroutines unconditionally by Using the command

EXIT

• Terminating Subroutines conditionally by Using the command

CHECK

Page 15: 3 modularisation and bdc

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

Page 16: 3 modularisation and bdc

Creating a Function Module – Step 1 of 7

Initial ParametersSE37

Page 17: 3 modularisation and bdc

Creating a Function Module – Step 2 of 7

General Attributes

Page 18: 3 modularisation and bdc

Creating a Function Module – Step 3 of 7

Import and Changing Interface Parameters

Page 19: 3 modularisation and bdc

Creating a Function Module – Step 4 of 7Export Interface Parameters

Page 20: 3 modularisation and bdc

Creating a Function Module – Step 5 of 7Tables Interface Parameters

Page 21: 3 modularisation and bdc

Creating a Function Module – Step 6 of 7 Exceptions

Page 22: 3 modularisation and bdc

Creating a Function Module – Step 7 of 7

Source Code and Activation

Page 23: 3 modularisation and bdc

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.

Page 24: 3 modularisation and bdc

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)

Page 25: 3 modularisation and bdc

Adding the function module to the program

Click PATTERN button in the edit program screen of the ABAP Editor

Page 26: 3 modularisation and bdc

Adding the function module to the program

Choose the Call Function Radio button and give thename of the function module and enter it

Page 27: 3 modularisation and bdc

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

Page 28: 3 modularisation and bdc

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

Page 29: 3 modularisation and bdc

File Handling – TRANSFER DATASET

• Syntax:- Writing to a dataset

TRANSFER <f> TO <dsn> [LENGTH <len>].

- Closing a datasetCLOSE DATASET <dsn>.

Page 30: 3 modularisation and bdc

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

Page 31: 3 modularisation and bdc

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

Page 32: 3 modularisation and bdc

BDC Methods

• Classical Method

• Call Transaction

• Call Dialog

Page 33: 3 modularisation and bdc

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

Page 34: 3 modularisation and bdc

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)

Page 35: 3 modularisation and bdc

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

Page 36: 3 modularisation and bdc

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

.

.

Page 37: 3 modularisation and bdc

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.

Page 38: 3 modularisation and bdc

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

Page 39: 3 modularisation and bdc

Job Scheduling

• Schedule a job – SM35– Create a job– Add program to be executed– Set timing and date to be executed