SAP Job Injector

You will find in this article two ABAP tools for injecting jobs in SAP from Excel files.

Simple injector

Download program ZTREXPI100

Input file : Tab delimited text

 Zone Length Description
 JOB  32  Job name
 USER  12  Execution User
 TYPE  1  P(Program) or S(Script)
 PROG  100  Program or Script
 PARAM  100  Variant or parameter

A set of controls is performed by the program before creating jobs in status “Scheduled“.

Program ZTREXPI100
injecteurs_jobs-1


Mass job creation and planification

ZTREXPI200

This program is more advanced than the first since it allows to inject and release the jobs according to scheduling criteria specified in a text file.

– File containing job definition :

 Zone Length Description
 JOB  32  Job name
 USER  12  Execution User
 TYPE  1  P(Programme) or S(Script)
 PROG  100  Program or Script name
 PARAM  100  Variant ou parameter

– File containing scheduling criteria :

 Zone Length Description
 JOB  32  Job name
 TARGETSYSTEM  40  Target server (cf SM51)
 TYPE  2  Planification type : DH (Date/Hour) ou EV (on event)
 SDLSTRTDT  8  Execution date (AAAAMMJJ)
 SDLSTRTTM  6  Execution time (HHMNSS)
 PRDMONTHS  2  Period in months
 PRDWEEKS  2  Period in weeks
 PRDDAYS  3  Period in days
 PRDHOURS  2  Period in hours
 PRDMINS  2  Period in minutes
 CALENDAR_ID  2  Factory calendar
 BTC_PROCESS_ALWAYS  1  Run sundays and during holidays (blank or X)
 BTC_DONT_PROCESS_ON_HOLIDAY  1  Do not run sundays and jours fériés (blanc ou X)
 BTC_PROCESS_BEFORE_HOLIDAY  1  Schedule to the previous working day(blank ou X)
 BTC_PROCESS_AFTER_HOLIDAY  1  Schedule to the next working day
 EVENT_ID  32  Event
 EVENT_PARAM  64  Event parameter
 EVENT_PERIODIC 1  Event periodic

Excel files for data formatting are available Here

Program ZTREXPI200
injecteurs_jobs-2

Optimizing the number of SAP work processes

This is a simple method to determine the optimal number of work processes DIA, BTC, UPD, …

– Execute transaction SM50
– Display CPU time via CTRL+SHIFT+F6 or menu List -> CPU

For each process type (DIA, BTC, …), you must have at least one process with a very small CPU time which mean that this work process was never used since SAP startup.
wp_sm50

BADIs : search method

 Before starting, please read BADIs Introduction.

There are different ways to search a business add-ins :

  • Search for the string ‘CL_EXITHANDLER’ in the relevant application program. If you call a business add-in from the program, you must also call the ‘GET_INSTANCE’ in this class.
  • Double-click the reference variable and note the name of the interface used.
  • Using class Builder (SE24), display the where used list of the interface to retrieve the business add-in definition class  (CL_EX_BADI).
  • The BADI definition contains documentation and a guide and implementation guide of the business add-in.
  • You can also use search tools.
  • However, you can also use application hierarchy to limit the search to certain components.
  • Start SE80, select  Repository Information System -> Enhancements -> Business Add-Ins to open the relevent search program.
  • You can also use the relevant entries in the implementation guide.

badis_rech-01

BADIS : Introduction

Before starting, please read this article about ABAP Objects : Advantages of BABIs

The business add-ins are a natural extension of conventional extension techniques. They reuse the management layer of customer exits, associated with various components of extension.

Implementing Object-Oriented provides new opportunities. It is for example possible to make an extension of the Object ‘Document’. It is also possible to provide a new instance of the extension for each individual document.

badis_intro-01

The main advantage of this concept is the reusability. Once implemented, a business add-in can have several new implementations.
In addition, an implementation may also provide its own add-ins.

Components
badis_intro-02

A business add-in contains all the components of an extension. Currently, each business Add-in can contain the following elements:

  • Extensions Program
  • Menu extensions

In future releases, other components included in customer exits will also be available as add-ins components.

When you define a business add-in, you can create several components:

  • Interface
  • Generated class (add-in adapter)

The generated class performs the following tasks:

  • Filtering: When you implement a filter dependent business add-in, adaptation class ensures that only relevant implementations are called
  • Control: the adaptation class calls active implementations.

Process
badis_intro-03

This graph illustrates the process followed by a program containing a call to a Business add-in. Not displayed here, you must declare a reference variable in the appropriate place.

In the first step, a existing service class (CL_EXITHANDLER), creates an object reference. The syntax used is discussed later. Once this step is completed, the extension program can be used.

When you define a business add-in, the system creates an adapter class that implements the interface. During call (2), the interface method of the adaptation class is called. This class research all implementations of business add-ins and call implemented methods .

badis_intro-04

This graph shows the syntax to call a business add-in. The circled numbers correspond to the calls of the previous graph.

You must first define a variable with reference to the interface of the business add-in. The variable name reference does not necessarily contain the name of the business add-in.

In the first step (1), an object reference is created. This creates an instance of the generated adaptation class, limited to the interface methods (narrow distribution).

You can use this object reference to invoke desired methods (2).

Definition of a business add-in

badis_intro-05

To create a BADI, use the BAdI Builder (Tools -> ABAP Workbench -> Utilities -> Business Add-Ins -> Definition) (Transaction SE18).

Attributes
badis_intro-06

You have to define two important attributes for business add-ins:

  • Multiple use
  • Limited filter use

If you want the business add-in supports multiple parallel implementations, select “Multiple Use”.

If you set the attribute “Limited filter use” for a business add-in, calls to the business add-in will depend to certain conditions. You must specify the type of filter as a data element. Table of domain values used by the data element contains valid values for implementation.

When the extension method is called, a filter value has to be transmitted to the interface.

Interface methods

badis_intro-07

The system proposes a name for the generated class and interface. You can change the name of the interface as you want. However, your business add-in will be easier to manage if you retain the proposed name.

The name of the generated class is constructed as follows:

Namespace prefix Z or Y
CL_ (to specify a class in general)
EX_ (for ‘exit’)
Name of business add-in

If you double-click on the interface name, the system switches to the Class Builder (SE24), in which you can define interface methods.
BADI interface can have multiple interface methods.

badis_intro-08

You can use all the standard functions of the Class Builder. You can for example:

  • define interface methods
  • define interface parameters for methods
  • declare the attributes of the interface

If the business add-in is filter dependent, you have to define an import  parameter (FLT_VAL) for each method. Otherwise, you define the interface parameters that you need for the extension.

Activating the interface

badis_intro-09

When you have finished working on your interface, you have to enable it. This generates adaptation class of business add-in. This class is automatically regenerated each time you change the interface.

You can also explicitly generate adaptation class at any time by selecting Tools -> Regenerate from the initial screen of the BADIs management transaction.

Calling program

badis_intro-10

To call a business add-in method from an application program, you have to include three statements in the program:

  1. Declare a reference variable to refer to business add-in interface (in our example, exit_ref).
  2. Call the static method GET_INSTANCE of class CL_EXITHANDLER. The system returns an instance of the required object. This implies a narrow implicit distribution, so that only the interface methods with the reference variable exit_ref are accessible.
  3. You can now call all the business add-in methods. Be sure to specify correctly the method parameters. If the business add-in is filter dependent, you must pass an appropriate value for the parameter FLT_VAL. If the business add-in has several active implementations, they will be called in alphabetical order.

Implementation of a business add-in

Naming convention

BADI ‘BADI’
Interface: IF_EX_’BADI ‘
Methods: Free choice
BADI generated class (not editable): CL_EX_’BADI ‘
Implementation name: Z’free ‘
Implementation class: ZCL_IM_’free’

Implementation: Initial Screen

badis_intro-11

To implement business add-ins, use transaction SE19 (Tools -> ABAP Workbench -> Utilities -> Business Add-Ins -> Implementation).

Enter the implementation name and select Create. A dialog box is displayed. Enter the name of the business add-in. The management screen will be displayed.

You can also use BADI definition transaction to access to implementation function. The menu contains an entry implementation that you can use to get an overview of existing implementations. You can also create new implementations at this level.

Methods

badis_intro-12

You can assign the name of your choice to the implementation class. However, it is recommended to follow the naming convention proposed. The proposed name is constructed by default as follows:

Namespace prefix, Y or Z
CL_ (for class)
Im_ (for implementation)
Implementation name

To implement the method, double-click on its name. The system then runs Class Builder.
When you have finished, you have to activate your objects.

Private methods

badis_intro-13

Implementation class allows you to create your own methods which can be called from the interface method.

Activation

badis_intro-14

Use the Activate icon to enable the implementation of a business add-in. Now, the implementation metods will be executed at the same time as the calling program.

If you disable the implementation, methods will not be called. However, the corresponding calls in the application program are still processed. The difference lies in the fact that adaptation class instance will not find active implementations. Unlike CALL CUSTOMER-FUNCTION,  CALL METHOD  CL_EXITHANDLER=>GET_INSTANCE is always executed even if there is no more implementations.

This principle is also valid for the instruction calling the adaptation class method.
You can only activate or deactivate an implementation in its original system. Any change other than in the original system is considered as a modification. The activation or deactivation must be transmitted to subsequent systems.

A business add-in can only have one definition, but many implementations may exist in the same system.

BADIS : Exercice

This exercise will allow you to have a comprehensive view on the use of BABIs.

Before starting, please read the following articles:
ABAP Objects
Badis: Introduction

The exercise covers two steps : definition and implementation of BADI knowing the definition phase is performed by SAP.

1-Defining a BADI
1.1-Initial Screen
To create a BAdI, use the BAdI Builder (Tools -> ABAP Workbench -> Utilities -> Business Add-Ins -> Definition) (Transaction SE18).

badis_exo-01


1.2-Properties

The adaptation class name “ZCL_EX_BADI” is automatically generated and can not be changed.

badis_exo-02

1.3-Interface
The name of the BADI’s interface “ZIF_EX_BADI” is proposed automatically. It can be changed but it is preferable to keep the naming logic proposed by SAP. The proposed name is constructed as follows:

Namespace prefix, Y or Z
IF_ (Interface)
EX_ (exit)
Name of business add-in

badis_exo-03

-> To define the interface, double-click on its name or use the Class Builder (SE24).
badis_exo-04

-> Create the interface method “USER_EXIT”
badis_exo-05

-> Assign method parameters
badis_exo-06

1.4-Activation
badis_exo-07


2-Implementing a BADI

2.1-Initial Screen
For the implementation of business add-ins, use transaction SE19 (Tools -> ABAP Workbench -> Utilities -> Business Add-Ins -> Implementation).

Enter the implementation name and select Create. A dialog box is displayed. Enter the name of the business add-in. The management screen is displayed.

You can also use BADI definition transaction to access to its implementations. The menu contains an entry ‘implementation’, which you can use to get an overview of existing implementations. You can also create new implementations at this level.

badis_exo-08


2.2-Implementation Class
You can assign the name of your choice to the implementation class. However, it is recommended to follow the naming convention proposed. The proposed name is constructed as follows:

Namespace prefix, Y or Z
CL_ (for class)
Im_ (for implementation)
Implementation name

In the case of the example, the proposed name of the implementation class is “ZCL_IM_BADI”

badis_exo-09


2.3-Interface method

-> To implement the method, double-click on its name. The system then runs  Class Builder (SE24). When you have finished the implementation, you must activate your objects.

badis_exo-10

-> Implementing interface method USER_EXIT ZIF_EX_BADI
badis_exo-11

-> Implementing source code of the method
badis_intro-12

2.4-Activation
-> Once interface is implemented, you have to activate it.

3-Second implementation of the same BADI
-> The main advantage of the Badis is their reusability. A business add-in can have multiple implementations in the same system. In the following example, we will create a second implementation for the same business add-in ZBADI.

-> Implementation (SE19)

badis_exo-13

-> Implementing method USER_EXIT for interface ZIF_EX_BADI

4-Calling program

To call a business add-in method from a program, you must include three statements in the program :

  1. Declare a reference variable to refer to the interface of business add-in (in our example, ‘ZIF’).
  2. Call the static method GET_INSTANCE of service class CL_EXITHANDLER. The system returns an instance of the required object. This implies a narrow implicit distribution, so that only the interface methods with the reference variable ‘ZIF’ are available.
  3. You can now call all the methods of business add-in. Be sure to specify correctly the method parameters. If the business add-in is filter dependent, you must pass an appropriate value for the parameter FLT_VAL. If the business add-in has several active implementations, they will be called in alphabetical order.

To test implementations, just run the above program and double-click on the displayed rows.

The first implementaion show the details of the selected flight and the second will show an information message.