0% found this document useful (0 votes)
82 views94 pages

ABAP Trainer's Document

This document can be used to train freshers on Classic ABAP.

Uploaded by

Felix Johnson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views94 pages

ABAP Trainer's Document

This document can be used to train freshers on Classic ABAP.

Uploaded by

Felix Johnson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 94

ABAP

CONCEPTS
The Successful Interview

This Document provides an overview of the core ABAP concepts to brush up in a quick time to
get through any Technical Interview for Profiles with 5 to 9 Years of experience.

9/7/2017
INDEX
1. Custom Reports and Transactions
1.1 Report Events……………………………………………………………………………………………………………...03
1.2 ALV (using Factory Methods)……………….……………………………………………………………………….03
2. Procedural Programming and Modularization
2.1 Function Module………………………………………………………………………………………………………….09
2.2 Subroutines………………………………………………………………………………………………………………….10
3. Object Oriented Programming
3.1 Class……………………………………………………………………………………………………………………………..11
3.2 Interface…………………………………………..………………………………………………………………………….11
3.3 Abstract Class……………………………………………………………………………………………………………….12
3.4 Inheritance…………………………………………………………………………………………………………………..12
4. Module Pool Programming
4.1 Basic Control Commands………………………………………………………………………………………………13
4.2 Events..…………………………………………………………………………………………………………………………13
4.3 Screen Navigation…………………….……………………................................................................13
4.4 Controls…………………………………….…...................................................................................13
5. Interface Techniques
5.1 IDOCS……………………………………………………………………………………………………………………………17
5.2 ABAP Proxies………………………………………………………………………………………………………………..37
6. Data Migration
6.1 BDC………………………………………………………………………………………………………………………………43
6.2 LSMW…………………………………………………………………………………………………………………………..45
6.3 BAPI……………………………………………………………………………………………………………………………..46
6.4 BW Extractor Function Modules........…………………………………………………………………………..56
7. Forms
7.1 SAP Scripts……………………………………………………………………………………………………………………70
7.2 SMARTFORMS……………………………………….……………………………………………………………………..72
8. Enhancements
8.1 User Exit……………………………………………………………………………………………………………………….78
8.2 BADI……………………………………………………………………………………………………………………………..78
8.3 BTE……………………………………………………………………………………………………………………………….80
8.4 Implicit and Explicit Enhancements……….……………………………………………………………………..82
8.5 VOFM Routines.……………………………………………………………………………………………………………82
9. Performance Tuning
9.1 Performance Analysis Tools……………..…………………………………………………………………………..83
9.2 Code Fine Tuning Techniques………..……….…………………………………………………………………….87
10. Upgrade
10.1 Sequence of Activities………………………………………………………………………………………………….89
10.2 ABAP Activities……………………………………………………………………………………………………………..89

1
10.3 Procedure to fix impacted objects in SPDD & SPAU………………………………………………………89
11. Debugging
11.1 Break Point…………………………………………………………………………………………………………………..91
11.2 Watch Point………………………………………………………………………………………………………………….92
11.3 Update Debugging……………………………………………………………………………………………………….92

2
1. CUSTOM REPORTS & TRANSACTIONS
1.1 Report Events:

INTIALIZATION: This event triggers before selection screen display.


AT-SELECTION-SCREEN: This event triggers after proccesing user input still selection screen is in active
mode.
START OF SELECTION: Start of selection screen triggers after proceesing selection screen.
END-OF-SELECTION: It is for Logical Database Reporting.
Interactive Reports
As the name suggests, the user can interact with the report. We can have a drill down into the report
data. For example, Column one of the report displays the material numbers, and the user feels that he
needs some more specific data about the vendor for that material, he can HIDE that data under those
material numbers.
And when the user clicks the material number, another report (actually sub report/secondary list) which
displays the vendor details will be displayed.
We can have a basic list (number starts from 0) and 20 secondary lists (1 to 21).
Events associated with Interactive Reports are:
AT LINE-SELECTION
AT USER-COMMAND
AT PF<key>
TOP-OF-PAGE DURING LINE-SELECTION
HIDE statement holds the data to be displayed in the secondary list.
SY-LISEL: contains data of the selected line.
SY-ISIND: contains the level of report (from 0 to 21)
Interactive Report Events:
AT LINE-SELECTION: This Event triggers when we double click a line on the list, when the event is
triggered a new sub list is going to be generated. Under this event whatever the statements that are been
return will be displayed on newly generated sub list.
AT PFn: For predefined function keys...
AT USER-COMMAND: It provides user functions keys.
TOP-OF-PAGE DURING LINE-SELECTION: top of page event for secondary list.

1.2 ALV using Factory Methods:

Total & Subtotal:


* Declaration of objects for ALV factory methods
DATA: go_table TYPE REF TO cl_salv_table,
go_functionss TYPE REF TO cl_salv_functions,
go_columns TYPE REF TO cl_salv_columns_table,

3
go_column TYPE REF TO cl_salv_column,
go_layout TYPE REF TO cl_salv_layout,
go_sorts TYPE REF TO cl_salv_sorts,
go_sort TYPE REF TO cl_salv_sort,
go_aggregations TYPE REF TO cl_salv_aggregations,
gw_layout_key TYPE salv_s_layout_key.
* Generate an instance of the ALV table object
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = go_table
CHANGING
t_table = gt_output.

* Setting Optimized Column width in output


go_columns = go_table->get_columns( ).
go_columns->set_optimize( abap_true ).
* Set Column Header Text
go_column = go_columns->get_column( 'VNAME1' ).
go_column->set_short_text( 'Vend. Nam' ).
go_column->set_medium_text( 'Vendor Name' ).
go_column->set_long_text( 'Vendor Name' ).

* Set all Standard ALV functions


go_functions = go_table->get_functions( ).
go_functions->set_all( abap_true ).

* Set ALV Layout


go_layout = go_table->get_layout( ).
gw_layout_key-report = sy-repid.
go_layout->set_key( gw_layout_key ).
go_layout->set_save_restriction( if_salv_c_layout=>restrict_none ).

* Subtotal of all Accrued, Paid and Remaining Amounts for each Vendor
go_sorts = go_table->get_sorts( ).
* Sort the ALV by Vendor Number
go_sort = go_sorts->add_sort( columnname = 'LIFNR' ).
* Inform the ALV that subtotal is required
go_sort->set_subtotal( value = abap_true ).
* Set Total for Accrued, Paid and Remaining Amounts
go_aggregations = go_table->get_aggregations( ).
go_aggregations->add_aggregation( columnname = 'ACCRUED' ).
go_aggregations->add_aggregation( columnname = 'PAID' ).
go_aggregations->add_aggregation( columnname = 'REMAIN' ).

* Display the ALV table.


go_table->display( ).

4
Button in ALV Tool Bar:
1. Copy standard PF-Status to custom PF-Status via SE41.
2. In the application tool bar, provisions will be there for new buttons. Name the provisions, assign
Function Code and Icon. Save the PF-Status.
3. Call the PF-Status in the program as below.
l_o_table->set_screen_status( pfstatus = 'ZPP_DOL_SALV_STATUS'
report = sy-repid
set_functions = l_o_table>c_functions_all ).

Determining Selected Rows in ALV Output:


The Method GET_SELECTED_ROWS of class CL_SALV_SELECTIONS will return the index of the rows
selected in the ALV output.

Events in ALV:
1. Create New include for creating ALV event handler classes.
INCLUDE z365n_pp_dol_seq_part_vldt_alv. "Include to handle ALV Events
2. Select from the list of events in class CL_SALV_EVENTS.

3. Define Event Handler Class with a Method referring to event in CL_SALV_EVENTS.


CLASS cl_handle_events DEFINITION.

PUBLIC SECTION.
METHODS: on_user_command FOR EVENT added_function OF cl_salv_events
IMPORTING e_salv_function.

ENDCLASS. "cl_handle_events DEFINITION


4. Implement the Method and write the functionality within the method.
Example: Displaying summary report on click of a button ‘SUMMARY’ and calling Smart Form on
click of another button ‘PRINT’.

5
CLASS cl_handle_events IMPLEMENTATION.

METHOD on_user_command.

CASE e_salv_function.
WHEN 'SUMMARY'.
* declaration of objects for alv factory methods
DATA: l_o_table TYPE REF TO cl_salv_table,
l_o_functions TYPE REF TO cl_salv_functions,
l_o_columns TYPE REF TO cl_salv_columns_table,
l_o_column TYPE REF TO cl_salv_column,
l_o_layout TYPE REF TO cl_salv_layout,
l_o_display TYPE REF TO cl_salv_display_settings,
l_o_events TYPE REF TO cl_salv_events_table,
l_o_events_handler TYPE REF TO cl_handle_events,
l_w_layout_key TYPE salv_s_layout_key,
l_f_salv_exception TYPE REF TO cx_salv_msg,
l_f_message TYPE string.

* Local Internal Tables


DATA: l_t_output TYPE STANDARD TABLE OF g_ty_output.

CONSTANTS: l_c_info TYPE char1 VALUE 'I',


l_c_error TYPE char1 VALUE 'E'.

REFRESH g_t_summary.
CLEAR l_f_mnglg_total.
l_t_output = g_t_output.
SORT l_t_output BY idnrk.

* Building output table for Summary Report


LOOP AT l_t_output INTO g_w_output.
l_f_mnglg_total = g_w_output-mnglg + l_f_mnglg_total. "Calculating total Qty for a Part
g_w_summary-matnr = g_w_output-idnrk.
g_w_summary-maktx = g_w_output-idnmtx.
g_w_summary-revlv = g_w_output-revlv.
g_w_summary-lgpla = g_w_output-lgpla.
g_w_summary-labst = g_w_output-labst.
AT END OF idnrk.
g_w_summary-mnglg = l_f_mnglg_total.
APPEND g_w_summary TO g_t_summary.
CLEAR: g_w_summary, l_f_mnglg_total.
ENDAT.
ENDLOOP.

* Generate an instance of the ALV table object


TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = l_o_table
CHANGING
t_table = g_t_summary.
CATCH cx_salv_msg INTO l_f_salv_exception.
l_f_message = l_f_salv_exception->get_text( ).

6
MESSAGE l_f_message TYPE l_c_info DISPLAY LIKE l_c_error.
ENDTRY.

* Setting Optimized Column width in output


l_o_columns = l_o_table->get_columns( ).
l_o_columns->set_optimize( abap_true ).

* Set Custom Column Names


l_o_column = l_o_columns->get_column('LGPLA').
l_o_column->set_short_text('LC Loctn').
l_o_column->set_medium_text('LC Location').
l_o_column->set_long_text('LC Location').
l_o_column = l_o_columns->get_column('REVLV').
l_o_column->set_short_text('ZGS Level').
l_o_column->set_medium_text('ZGS Level').
l_o_column->set_long_text('ZGS Level').
l_o_column = l_o_columns->get_column('MATNR').
l_o_column->set_short_text('Material').
l_o_column->set_medium_text('Material').
l_o_column->set_long_text('Material').

* Set all Standard ALV functions


l_o_functions = l_o_table->get_functions( ).
l_o_functions->set_all( abap_true ).

* Set ALV Layout


l_o_layout = l_o_table->get_layout( ).
l_w_layout_key-report = sy-repid.
l_o_layout->set_key( l_w_layout_key ).
l_o_layout->set_save_restriction( if_salv_c_layout=>restrict_none ).

l_o_display = l_o_table->get_display_settings( ). "General Display Settings


l_o_display->set_striped_pattern( cl_salv_display_settings=>true ). "zebra stripes

* Display the ALV table.


l_o_table->display( ).

WHEN 'PRINT'.
* Local Variables Declaration
DATA: l_o_selections TYPE REF TO cl_salv_selections,
Lt_rows TYPE salv_t_row,
L_w_rows LIKE LINE OF l_t_rows,
l_f_fname TYPE rs38l_fnam,
l_f_serno TYPE int4,
l_f_oldaf TYPE aufnr,
l_f_oldcm TYPE z365_commodity.
* Local Constants Declaration
CONSTANTS: l_c_fname TYPE tdsfname VALUE 'Z365SF_PP_DOL_SEQ_PRT_VALIDATE'.

* Building Output Table of selected rows for Smart Form

l_o_selections = gr_table->get_selections( ).

7
L_t_rows = lr_selections->get_selected_rows( ).
REFRESH g_t_print.
LOOP AT l_t_rows INTO l_w_rows.
READ TABLE g_t_output INTO g_w_output INDEX l_w_rows.
g_w_print-serial_no = g_w_output-ser_no.
g_w_print-commodity = g_w_output-commodity.
g_w_print-aufnr = g_w_output-aufnr.
g_w_print-variant = g_w_output-plnbez.
g_w_print-variant_desc = g_w_output-plnmtx.
g_w_print-part_number = g_w_output-idnrk.
g_w_print-part_desc = g_w_output-idnmtx.
g_w_print-revlv = g_w_output-revlv.
g_w_print-labst = g_w_output-labst.
l_f_oldaf = g_w_output-aufnr.
l_f_oldcm = g_w_output-commodity.
APPEND g_w_print TO g_t_print.
CLEAR: g_w_print, g_w_output.
ENDLOOP.

* Sorting Form Output by Commodity to introduce page break in smart form based on commodity
SORT g_t_print BY commodity serial_no.

* Get Smart Form Function Module Name


CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = l_c_fname
IMPORTING
fm_name = l_f_fname
EXCEPTIONS
no_form =1
no_function_module = 2
OTHERS = 3.
IF sy-subrc <> 0.
ENDIF.

* Call Smart Form


CALL FUNCTION l_f_fname
TABLES
g_t_print = g_t_print
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error =3
user_canceled = 4
OTHERS = 5.
IF sy-subrc <> 0.
ENDIF.
ENDCASE.

ENDMETHOD. "on_user_command
ENDCLASS. "cl_handle_events IMPLEMENTATION

8
2. PROCEDURAL PROGRAMMING AND MODULARIZATION

2.1 FUNCTION MODULE

UPDATE TASK:

The update work processes are responsible for updating the database. When an ABAP program reaches a
COMMIT WORK statement, any function modules from CALL FUNCTION... IN UPDATE TASK statements
are released for processing in an update work process.

On execution of a Program that contains UPDATE TASK, it will get registered in VBLOG table on priority
basis. It will not get executed until COMMIT WORK statement is reached. Debugging can be done via
Update Debugging in settings.

BACKGROUND TASK:

Running a Function module in back-ground task means assigning the module to separate LUW. It can be
run in parallel and is an asynchronous process.

9
To debug our background task we need to switch on ‘Do not process’ in debugging mode as shown below.

On execution of Program containing FM with BACKGROUND TASK, FM will get execute in background task
and it will be assigned to a separate LUW. We can see this LUW registered in t-code SM58 and execute,
debug and delete manually. If the checkbox in above screen shot is checked, LUW will not get registered
in SM58 and we cannot debug.

If checkbox ‘In background task’ is checked, LUW gets registered in SM58. Now we can go to SM58, select
the record and Debug the LUW.

2.2 SUBROUTINES
PERFORM <Subroutine Name> USING <Parameters>
CHANGING <Parameters>
TABLES <Parameters>
Note: TABLES parameter is now obsolete and internal tables can be passed via USING / CHANGING itself.

10
3. OBJECT ORIENTED PROGRAMMING
3.1 CLASS

GLOBAL CLASS

Transaction – SE24
These Classes support reusability and can be used in any custom program created.

LOCAL CLASS

These Classes are defined and implemented within the program.


Example:
CLASS cl_handle_events DEFINITION.

PUBLIC SECTION.
METHODS: on_user_command FOR EVENT added_function OF cl_salv_events
IMPORTING e_salv_function.

ENDCLASS. "cl_handle_events DEFINITION

CLASS cl_handle_events IMPLEMENTATION.

METHOD on_user_command.

CASE e_salv_function.
WHEN 'SUMMARY'.
* declaration of objects for alv factory methods
DATA: l_o_table TYPE REF TO cl_salv_table,
l_o_functions TYPE REF TO cl_salv_functions,
l_o_columns TYPE REF TO cl_salv_columns_table,
l_o_column TYPE REF TO cl_salv_column,
l_o_layout TYPE REF TO cl_salv_layout,
l_o_display TYPE REF TO cl_salv_display_settings,
l_o_events TYPE REF TO cl_salv_events_table,
l_o_events_handler TYPE REF TO cl_handle_events,
l_w_layout_key TYPE salv_s_layout_key,
l_f_salv_exception TYPE REF TO cx_salv_msg,
l_f_message TYPE string.
ENDMETHOD. "on_user_command

ENDCLASS. "cl_handle_events IMPLEMENTATION

3.2 INTERFACE

Interfaces have only the definition for the functionalities supported via Methods. However, none of the
methods will hold implementation.
Transaction – SE24
Interfaces should begin with ZIF_ and Classes should begin with ZCL_. Based on the name provided at the
time of creation, SAP will automatically determine if it’s an interface or class.

11
3.3 ABSTRACT CLASS

Abstract Class is a class which contains at least one abstract method (method with no implementation).
The class which inherits the abstract class will contain implementation for the abstract method. If the
class inheriting the abstract class doesn’t contain implementation for the abstract method, then this will
also be termed as an abstract class. In addition to abstract methods, an abstract class can contain also
normal methods with implementation unlike interfaces.

3.4 INHERITANCE

To inherit from another class, click on the button highlighted and provide the super class name / Interface
/ Abstract Class.

12
4. MODULE POOL PROGRAMMING
4.1 BASIC CONTROL COMMANDS

CHAIN-ENDCHAIN
 Set of fields to be validated together.
 On Error, All fields within CHAIN-ENDCHAIN are input enabled and all other fields are disabled.
 MODULE inside CHAIN-ENDCHAIN is used to validate the field immediately after input. When the
MODULE throws Error or Warning, all fields inside CHAIN-ENDCHAIN are open for input.

AT-EXIT COMMAND
 Used to exit from the screen even if a field in the screen throws error.
 The Button used to exit should have Function Type ‘E’.

4.2 EVENTS
PROCESS BEFORE OUTPUT (PBO) - The event is triggered during Screen Load.

PROCESS AFTER INPUT (PAI) - The event is triggered on any user action on screen.

PROCESS ON VALUE REQUEST (POV) - The event is triggered on click of F4 help.

PROCESS ON HELP REQUEST (POV) - The event is triggered on click of F1 help.

4.3 SCREEN NAVIGATION


CALL SCREEN <XXXX> - Calls the screen ‘XXXX’ without stopping the current screen processing. It is used
to call sub-screen and on processing of sub-screen is complete, returns back to main screen to continue
current processing.

SET SCREEN <XXXX> - Used to set the next screen number overriding the one given in the screen
properties as shown in the screen properties below.

LEAVE SCREEN – Leaves to the screen indicated in SET SCREEN or under Next Screen in Screen Attributes.
It ends the processing in current screen.

LEAVE TO SCREEN <XXXX> - It is equal to combining SET SCREEN and LEAVE SCREEN.

4.4 CONTROLS
TABLE CONTROL

Create Table Control in Layout and add the necessary fields.

13
Populating Table Control – For e.g. G_T_TABL is the final internal table.

* Populate Table Control.


LOOP AT g_t_tabl WITH CONTROL tabl_ctrl
CURSOR tabl_ctrl-current_line.
ENDLOOP.

TAB STRIP CONTROL

Create a screen 100 (screen on which Tab Strip is going to be placed) and Sub-Screens 110 & 130(which
are going to be placed in the screen areas of the tabs in Tab Strip control).

Go to Layout of main screen and create a Tab Strip control (for e.g. name it as tabstrip) with tabs.
Assign Sub-screens to respective Tabs and Function Codes (to identify which tab the user selects) to tabs.
Go to the Sub-screens and create necessary fields.

Code in the PBO &PAI of respective Screens:


************************************************************************
* DATA DECLARATIONS *
************************************************************************
DATA : NUMBER1 TYPE I,
NUMBER2 TYPE I,
RESULT TYPE I,
N1 TYPE I,
N2 TYPE I,

14
OK_CODE LIKE SY-UCOMM.
CONTROLS TABSTRIP TYPE TABSTRIP.
CALL SCREEN 100.
CALL SCREEN 110.
CALL SCREEN 130.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'BACK'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
CASE OK_CODE.
WHEN 'TAB1'.
TABSTRIP-ACTIVETAB = 'TAB1'.
WHEN 'TAB2'.
TABSTRIP-ACTIVETAB = 'TAB2'.
RESULT = NUMBER1 + NUMBER2.
WHEN 'BACK'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0130 INPUT
*&---------------------------------------------------------------------*
text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0130 INPUT.
RESULT = NUMBER1 + NUMBER2.
ENDMODULE. " USER_COMMAND_0130 INPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0110 INPUT
*&---------------------------------------------------------------------*
text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0110 INPUT.
N1 = NUMBER1.
N2 = NUMBER2.
ENDMODULE. " USER_COMMAND_0110 INPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0110 OUTPUT
*&---------------------------------------------------------------------*
text
*----------------------------------------------------------------------*
MODULE STATUS_0110 OUTPUT.
SET PF-STATUS 'xxxxxxxx'.

15
SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0110 OUTPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0130 OUTPUT
*&---------------------------------------------------------------------*
text
*----------------------------------------------------------------------*
MODULE STATUS_0130 OUTPUT.
SET PF-STATUS 'xxxxxxxx'.
SET TITLEBAR 'xxx'.
RESULT = NUMBER1 + NUMBER2.
ENDMODULE. " STATUS_0130 OUTPUT

16
5. INTERFACE TECHNIQUES

5.1 IDOCS

EDI (Electronic Document interchange) - EDI is the electronic exchange of business documents between
the computer systems of business partners, using a standard format over a communication network.
EDI is also called paperless exchange.

Advantages:
Reduced Data entry errors
Reduced processing time
Availability of data in electronic form
Reduced paperwork
Reduced Cost
Reduced inventories and better planning
Standard means of communications
Better business process

EDI has two process:


1. Outbound process
2. Inbound process

Outbound Process:
Application document is created.
IDOC is generated
IDOC is transferred from SAP to Operating system layer
IDOC is converted into EDI standards
Edi document is transmitted to the business partner
The Edi Subsystem report status to SAP

Inbound Process:
1.EDI transmission received
2.EDI document is converted into an IDOC
3.IDOC is transferred to the SAP layer
4.The application document is created
5.The application document can be viewed.

IDOC: IDOC is a container that can be used to exchange data between any two processes.
Each IDOC is assigned a unique number for tracking and future reference.
IDOC consists of several segments, and segments contain several fields.

IDOC contains the following three types of records:


1. One Control Record.
2. One or many Data Records
3. One or many Status records

17
In IDOCs the following terms are to be known.
PORT:
Port is used in the outbound process to determine the name of the EDI subsystem program, the directory
path where the IDOC file will be created at the operating system level, the IDOC file names and the RFC
destinations.

RFC Destination:
Used to define the characteristics of communication links to a remote system on which a functions needs
to be executed.

Partner Profile:
Partner profile specified the various components used in an outbound process (Partner number, IDOC
type, message type, Port, Process code), the mode in which it communicates with the subsystem (batch or
immediate) and the person to be notified in case of errors.

Message Control:
Used in pricing, account determination, material determination, and output determination. The message
control component enables you to encapsulate business rules with out having to write ABAP programs.

TO Process IDOCS the following TCODES will be used:


On both sides:
Logical System Names SALE
Setup RFC destinations SM59
Port Destinations WE21
In Source system:
Segment Creation WE31
Basic IDOC Type Creation WE30
Message Type Creation WE81
Assign Message Type to Basic IDOC Type WE82
Distribution Model BD64
Writing Report Program SE38
Partner Profile WE20
Message control NACE
Check IDOCs WE02, WE05

In Destination System:
Creating FM SE37
Assign FM to Logical Message WE57
Define I/P method for Inbound FM BD51
Create Process Code WE42
Generate Partner Profile BD64

IDOC processing in the same instance of R/3 Clients:


For example two clients 900 and 800 in the same R/3 instance.
To transfer the data between two clients the table structures and their data types should be match.
In this example, Client 900 is Source system, and Client 800 is destination system.

18
In Client 900 I have created a customized table and inserted some records.
In Client 800 I have created only table.

Common Steps in Both Clients:


Creating the Logical System Names and Assigning to Clients:
Go to TCODE SALE.

Define Logical Systems. Specify the Logical System name and description.
Note: Logical System Naming convention is <SID>CLNT<NNN>

Assign Logical System to client.

19
Click on New Entries

Go to TCODE SM59 to create RFC Destination.

Creating RFC ports:


Go to TCODE WE21
Select the Transactional RFC in left side tree and click on Create button

In dialog box you can select either Generate port name or own port name. If you select Generate Port
name system will generate automatically. Here I selected Own port name. Click on continue.

20
Specify the description and RFC destination name and save.

Repeat the same above process in other client. By using opposite client instead of 900 specify 800.

In Client 900 steps: (Outbound IDOC)

Creating table structure:


 Go to TCODE SE11.
 Specify table name as ZSTUDENTS.
 In Delivery and Maintenance tab set attributes as “Display Maintenance Allowed”
 Create table fields.

21
Insert some records in table.

Creating IDOC Segments:


Go to TCODE WE31 and create Segments by specifying fields of table ZSTUDENTS just created.

Release the Segment.

22
Creating Basic IDOC Type:
Go to TCODE WE30
Specify a name to your IDOC and click on create button.

In next dialog box select create new option and specify the description of IDOC and click on continue.

Click on Create segment in the screen.

In dialog box specify the segment name which you created, check mandatory check box (If this segment is
mandatory to hold data) and save.

Minimum Number – Minimum number of times the segment will come in the IDOC.
Maximum Number – Maximum number of times the segment will repeat in the IDOC.
For e.g. If the segment is going to hold line items of a Sales Order, then it would repeat multiple times (we
do not know the number of line items) and hence we would set Maximum Number to 999.

23
Go to menu EDIT ->Click Set Release

Creating Message Type:


Go to TCODE WE81 and create a Message Type. Specify a message type name and Description and Save.

Assign Message Type to Basic IDOC Type:


Go to TCODE WE82. Click on New Entries, Specify the Message Type, Basic IDOC Type and Release
version. Save the same.

Creating Model View and Distributing and Generating Partner profile:


Go to TCODE BD64 and Click on Edit menu -> Model View -> Create

Specify description of model view and technical name in dialog box and press continue.

Select your model view and click on Edit menu -> Add Message type

Now your Model View looks like

24
Click on Environment Menu -> Generate Partner profile

It will show the following screen, click on execute.

It will show the partner profile log in next screen.

25
Come back to BD64 and Click on Edit Menu -> Model View -> Distribute.

In displayed dialog box select the partner system and click continue

Then it will show the Log of Model View Distribution.

26
To check partner profile Go to TCODE WE20. In displayed screen select the partner system in left
side tree under Partner Type LS.

Write a Report Program in SE38 to create IDOC control records and transfer it to destination
partner system.

The following is the program to generate the IDOC control records and process it.

*&---------------------------------------------------------------------*
*& Report ZSHAN_IDOC_STUD
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZSHAN_IDOC_STUD.
TABLES: ZSTUDENTS.
DATA : S_CTRL_REC LIKE EDIDC, "Idoc Control Record
S_ZSHSTUSEG LIKE ZSHSTUSEG. "CUSTOMER Header Data
DATA : T_ZSTUDENTS LIKE ZSTUDENTS OCCURS 0 WITH HEADER LINE.
DATA : T_EDIDD LIKE EDIDD OCCURS 0 WITH HEADER LINE. "Data Records
DATA : T_COMM_IDOC LIKE EDIDC OCCURS 0 WITH HEADER LINE. "Generated Communication IDOc
CONSTANTS :C_ZSHSTUSEG LIKE EDIDD-SEGNAM VALUE 'ZSHSTUSEG'.
CONSTANTS: C_IDOCTP LIKE EDIDC-IDOCTP VALUE 'ZSHSTUDIDOCS'.
*** Selection Screen
SELECT-OPTIONS : S_STUID FOR ZSTUDENTS-ZSTUID OBLIGATORY.
PARAMETERS : C_MESTYP LIKE EDIDC-MESTYP DEFAULT 'ZSHSTUDMT', "Message Type
C_RCVPRT LIKE EDIDC-RCVPRT DEFAULT 'LS', "Partner type of receiver
C_LOGSYS LIKE EDIDC-RCVPRN DEFAULT 'IT3CLNT800',
C_RCVPOR LIKE EDIDC-RCVPOR DEFAULT 'PORTSH800',
C_SNDPRN LIKE EDIDC-SNDPRN DEFAULT 'IT3CLNT900',
C_SNDPRT LIKE EDIDC-SNDPRT DEFAULT 'LS'. "Destination System
***START-OF-SELECTION
START-OF-SELECTION.
PERFORM GENERATE_DATA_RECORDS.

27
PERFORM GENERATE_CONTROL_RECORD.
PERFORM SEND_IDOC.
*&---------------------------------------------------------------------*
*& Form GENERATE_DATA_RECORDS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GENERATE_DATA_RECORDS .
SELECT * FROM ZSTUDENTS
INTO TABLE T_ZSTUDENTS
WHERE ZSTUID IN S_STUID.
IF SY-SUBRC NE 0.
MESSAGE E398(00) WITH 'No Students Found'.
ENDIF.
PERFORM ARRANGE_DATA_RECORDS.
ENDFORM. " GENERATE_DATA_RECORDS
*&---------------------------------------------------------------------*
*& Form GENERATE_CONTROL_RECORD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GENERATE_CONTROL_RECORD .
S_CTRL_REC-RCVPOR = C_RCVPOR. "Receiver Port
S_CTRL_REC-MESTYP = C_MESTYP. "Message type
S_CTRL_REC-IDOCTP = C_IDOCTP. "Basic IDOC type
S_CTRL_REC-RCVPRT = C_RCVPRT. "Partner type of receiver
S_CTRL_REC-RCVPRN = C_LOGSYS. "Partner number of receiver
S_CTRL_REC-SNDPRT = C_SNDPRT. "Sender Partner type
S_CTRL_REC-SNDPRN = C_SNDPRN. "Sender Partner Number
ENDFORM. " GENERATE_CONTROL_RECORD
*&---------------------------------------------------------------------*
*& Form SEND_IDOC
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SEND_IDOC .
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
EXPORTING
MASTER_IDOC_CONTROL = S_CTRL_REC
* OBJ_TYPE = ''
* CHNUM = ''
TABLES

28
COMMUNICATION_IDOC_CONTROL = T_COMM_IDOC
MASTER_IDOC_DATA = T_EDIDD
EXCEPTIONS
ERROR_IN_IDOC_CONTROL =1
ERROR_WRITING_IDOC_STATUS =2
ERROR_IN_IDOC_DATA =3
SENDING_LOGICAL_SYSTEM_UNKNOWN =4
OTHERS =5
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
COMMIT WORK.
LOOP AT T_COMM_IDOC.
WRITE:/ 'IDoc Generated - ', T_COMM_IDOC-DOCNUM.
ENDLOOP.
ENDIF.
ENDFORM. " SEND_IDOC
*&---------------------------------------------------------------------*
*& Form ARRANGE_DATA_RECORDS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM ARRANGE_DATA_RECORDS .
DATA: W_INDEX1 LIKE SY-TABIX,
W_INDEX2 LIKE SY-TABIX.
SORT T_ZSTUDENTS BY ZSTUID.
LOOP AT T_ZSTUDENTS.
S_ZSHSTUSEG-ZSTUID = T_ZSTUDENTS-ZSTUID.
S_ZSHSTUSEG-ZSNAME = T_ZSTUDENTS-ZSNAME.
T_EDIDD-SEGNAM = C_ZSHSTUSEG.
T_EDIDD-SDATA = S_ZSHSTUSEG.
APPEND T_EDIDD.
CLEAR T_EDIDD.
ENDLOOP.
ENDFORM. " ARRANGE_DATA_RECORDS

Now execute the program, and specify the range of records to transfer

29
Go to TCODE WE02 to check the generated IDOC control records.

In Client 800 Steps: (Inbound IDOC)

Create a Function Module. This function module will contain the program lines required to create
the necessary transactional data as per Business Requirements.

Specify the below Import parameters.

30
Specify the below Export parameters.

Specify the below Table parameters.

Specify the Exceptions.

Write program lines to pick data from the IDOC Data Records and update Database Table.
FUNCTION ZSHAN_IDOC_ZSHSTUDMT.
*"--------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(INPUT_METHOD) LIKE BDWFAP_PAR-INPUTMETHD
*" REFERENCE(MASS_PROCESSING) LIKE BDWFAP_PAR-MASS_PROC
*" EXPORTING
*" REFERENCE(WORKFLOW_RESULT) LIKE BDWF_PARAM-RESULT
*" REFERENCE(APPLICATION_VARIABLE) LIKE BDWF_PARAM-APPL_VAR
*" REFERENCE(IN_UPDATE_TASK) LIKE BDWFAP_PAR-UPDATETASK
*" REFERENCE(CALL_TRANSACTION_DONE) LIKE BDWFAP_PAR-CALLTRANS
*" TABLES
*" IDOC_CONTRL STRUCTURE EDIDC
*" IDOC_DATA STRUCTURE EDIDD
*" IDOC_STATUS STRUCTURE BDIDOCSTAT
*" RETURN_VARIABLES STRUCTURE BDWFRETVAR
*" SERIALIZATION_INFO STRUCTURE BDI_SER

31
*" EXCEPTIONS
*" WRONG_FUNCTION_CALLED
*"--------------------------------------------------------------------
* Include File containing ALE constants
INCLUDE MBDCONWF.
TABLES: ZSTUDENTS.
DATA: W_ZSHSTUSEG LIKE ZSHSTUSEG.
DATA: T_ZSTUDENTS LIKE ZSTUDENTS OCCURS 0 WITH HEADER LINE.
WORKFLOW_RESULT = C_WF_RESULT_OK.
LOOP AT IDOC_CONTRL.
IF IDOC_CONTRL-MESTYP NE 'ZSHSTUDMT'.
RAISE WRONG_FUNCTION_CALLED.
ENDIF.
* Before reading a new entry, clear application buffer
LOOP AT IDOC_DATA WHERE DOCNUM EQ IDOC_CONTRL-DOCNUM.
W_ZSHSTUSEG = IDOC_DATA-SDATA.
MOVE-CORRESPONDING W_ZSHSTUSEG TO T_ZSTUDENTS.
INSERT INTO ZSTUDENTS VALUES T_ZSTUDENTS.
ENDLOOP.
UPDATE ZSTUDENTS FROM T_ZSTUDENTS.
IF SY-SUBRC EQ 0.
IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.
IDOC_STATUS-STATUS = '53'.
IDOC_STATUS-MSGTY = 'I'.
IDOC_STATUS-MSGID = 'YM'.
IDOC_STATUS-MSGNO = '004'.
IDOC_STATUS-MSGV1 = T_ZSTUDENTS-ZSTUID.
APPEND IDOC_STATUS.
CLEAR IDOC_STATUS.
ELSE.
IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.
IDOC_STATUS-STATUS = '51'.
IDOC_STATUS-MSGTY = 'E'.
IDOC_STATUS-MSGID = 'YM'.
IDOC_STATUS-MSGNO = '005'.
IDOC_STATUS-MSGV1 = T_ZSTUDENTS-ZSTUID.
APPEND IDOC_STATUS.
CLEAR IDOC_STATUS.
WORKFLOW_RESULT = C_WF_RESULT_ERROR.
RETURN_VARIABLES-WF_PARAM = 'Error_Idocs'.
RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.
APPEND RETURN_VARIABLES.
CLEAR RETURN_VARIABLES.
ENDIF.
ENDLOOP.
ENDFUNCTION.

Assign FM to Logical Message:


Go to WE57 and Click on New Entries Button

32
Specify created FM name, Function Type, Basic Type (IDOC), Message Type, and Direction and click
on SAVE button.

Go to TCODE BD51, Click on Display / Change button and Add New Entry.

Specify FM name and Input Types as 2. And Click on Save and Back buttons.

Creating Process Code:


Go to TCODE WE42. Click on Display / Change Button and add new entry. Specify a process code
name, Description and select the options processing with ALE services, Processing by Function
Module.

In next screen select the FM name and click on SAVE button and Click on BACK button.

33
It will take to you previous screen. Double Click on Logical Message in left side tree.
Select Logical Message and Click on New Entries button

Specify the Message Type and Save.

34
Generating the Partner Profile:
Go to TCODE BD64.
Select the Model View which you distributed in client 900.

Click on Environment Menu -> Generate Partner Profile

It will show the next screen, in that click on Execute button

It will show the Partner Profile details

35
To check the partner profile details. Go to TCODE WE20. Select the partner system name.

Transferring the IDOC control records from Client 900 to 800:


In source system, go to TCODE SE38. (In client 900)
Execute the Report program which you created.

Check in Destination System: (Here client 800)


Go to TCODE WE02

36
Debugging:
Inbound IDOC – WE19Select Function Module and Execute.
Outbound IDOC – Break Point at FM MASTER_IDOC_DISTRIBUTE.

5.2 ABAP PROXIES:

PI system is prerequisite to use ABAP Proxies for interfacing.


SourceSAP PIDestination

Transport protocol – HTTP


RFC Destination (SM59) – Type ‘H’.

PI Settings
Create Data Type.

Create Message Type.

37
Create Service Interface.

ECC Settings

Proxies will generate 3 objects in Application System –


 ABAP Class
 Structure for Message Type
 Structure for Data Type

Inbound Proxy:

SAP Data SAP


ECC PI
(Ap (Int
T-Code – SPROXY
plic
Open the egr
node for your Service (Inbound / Outbound), right click and create proxy.

atio atio
n n 38
Syst Syst
em) em)
Give Package Name and Prefix: Click on Continue.

After completing the creation process, the below screen will be there.

39
Activate and double click on Provider Class.

Write necessary coding as per business requirements inside the method.

Outbound Proxy:

SAP Data SAP


ECC PI
(Ap (Int
T-Code – SPROXY
plic
Open the egr
node for your Service (Inbound / Outbound), right click and create proxy.

atio atio
n n
Syst Syst
em) em) 40
• For Outbound Proxy, an executable code in ABAP will be written to call that proxy.
• In this Example, we are writing that code in Executable program in SE38.
• First Pick data from Table.
• Fill Proxy Structure & send to Integration System (PI).

Data Declaration –

41
Filling Proxy structure and sending to integration system (PI).

Debugging:

Go to Transaction SXI_MONITOR and download the Inbound XML Payload as an XML file to
the Presentation Server.
Go to Transaction SPROXY, execute the Proxy and upload the XML file.
Place a break-point in the Proxy Class Method.
Now execute and the debugger will get triggered.

42
6. DATA MIGRATION
6.1 BDC:

MODE:
N - Background Mode.
A – Foreground Mode.
E – Display Screen on Error.
P – Branches into debugging once breakpoint is reached.

UPDATE:

A – Asynchronous Update
S – Synchronous Update
L – Local Updates

Automate BDC Session:

Step 1: Get BDC Queue ID

Session name is the name of session we pass to FM ‘BDC_OPEN_GROUP’.


CALL FUNCTION 'BDC_OBJECT_SELECT'
EXPORTING
name = session name
session_creator = sy-uname
datatype = 'BDC'
client = sy-mandt
qstate =''
date_from = sy-datum
date_to = sy-datum
TABLES
apqitab = itab_apqi
EXCEPTIONS
OTHERS = 1.

Queue ID (QID) = itab_apqi-qid

Step 2: Get Session Info


Get Session info for the queue ID from table APQI.
SELECT SINGLE * FROM apqi INTO session WHERE qid = QID (from Step 1).

Step3: Lock BDC Queue


CALL FUNCTION 'ENQUEUE_BDC_QID'
EXPORTING
datatyp = session-datatyp
groupid = session-groupid
qid = session-qid
EXCEPTIONS
foreign_lock = 1
system_failure = 99.

43
Step4: OPEN JOB
DATA: jobname LIKE tbtco-jobname,
jobnumb LIKE rsjobinfo-jobnumb,
Jobname = wa_session-groupid.
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobgroup = 'BATCH-INPUT'
jobname = jobname
sdlstrtdt = sy-datum
sdlstrttm = sy-uzeit
IMPORTING
jobcount = jobnumb
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 99.

Step5: Execute the Queue


Execute the QUEUE using Submit to Report RSBDCBTC.
SUBMIT rsbdcbtc
TO SAP-SPOOL
DESTINATION space
IMMEDIATELY space
KEEP IN SPOOL space
WITHOUT SPOOL DYNPRO
USER session-userid
VIA JOB jobname
NUMBER jobnumb
WITH queue_id EQ wa_session-qid
WITH mappe EQ jobname
WITH modus EQ 'N'
WITH logall EQ 'X' " Extended Log
AND RETURN.
If Sy-subrc = 0

Step6: Close Job

CALL FUNCTION 'JOB_CLOSE'


EXPORTING
jobcount = jobnumb
jobname = jobname
strtimmed = 'X'
targetsystem = '' " Target Host
EXCEPTIONS
cant_start_immediate =1
invalid_startdate =2
jobname_missing =3
job_close_failed =4
job_nosteps =5
job_notex =6
lock_failed =7
OTHERS = 99.
IF sy-subrc = 0

44
Step 7: Update Session info
UPDATE apqi SET qstate = 'S'
WHERE destsys = wa_session-destsys
AND destapp = wa_session-destapp
AND datatyp = wa_session-datatyp
AND groupid = wa_session-groupid
AND progid = wa_session-progid
AND formid = wa_session-formid
AND qattrib = wa_session-qattrib
AND qid = wa_session-qid.
COMMIT WORK.

Step 8: Delete Job


If Job Not closed (Sy-subrc <> 0 for step 5 or 6), delete Job.
CALL FUNCTION 'BP_JOB_DELETE'
EXPORTING
jobname = jobname
jobcount = jobnumb
forcedmode = 'X'
EXCEPTIONS
OTHERS = 99.

Step 9: Unlock BDC queue


CALL FUNCTION 'DEQUEUE_BDC_QID'
EXPORTING
datatyp = wa_session-datatyp
groupid = wa_session-groupid
qid = wa_session-qid.

To populate Currency field in BDC:

WRITE <gs_accdcp>-wrbtr TO lv_amt CURRENCY <gs_accdcp>-waers LEFT-


JUSTIFIED.

6.2 LSMW

45
Maintaining Field Mapping & Conversion Rules – Mapping the fields in BDC Recording with the Structure
fields created in Step 3. Field Level Code Logic can also be written here.

6.3 BAPI:
BAPI Extensions
It is used to update additional custom fields that are not supported by original BAPI.

Feasibility
Check import parameters if the BAPI has extension structure.

Example
Assume that there is extra information that we want to save to the database while creating a new
purchase order. I.e. Prepared By, Checked By, Approved By.

BAPI Extension Table


But this change might affect the further BAPI implementations. This is because BAPIs are designed to
implement SAP standard business processes through a predefined standard interface. I.e. its import and
export parameters for any BAPI are fixed. So addition of new customer fields has absolutely nothing to do
with this predefined BAPI interface. This is because these fields are added to SAP database. So executing
BAPI with the same import and export parameter is not sufficient. We have to pass extra information
about newly added fields. This information is passed to the BAPI using BAPI table extension. The naming
convention for BAPI table extensions is BAPI_TE_<table_name>.Here the customer first creates a data
structure that contains the customer-specific fields. In our example, it is CI_EKKODB. This structure is
included in both the database table and the BAPI table extension. This ensures that the enhancements to

46
the database table and the table extension are always identical.

47
Extension container
Also, an extension parameter (Extension In) in the BAPI interface is used to pass on the enhancements to
the BAPI in container format. This extension parameter is always based on data structure BAPIPAREX.
Using this parameter BAPI understands the format of the data to be passed.

Here, the STRUCTURE refers to the name of the BAPI table extension though which extra information is
to be sent whereas VALUEPART1 to VALUEPART4 are the values that will be inserted in the additional
table fields along with the table key field. Key field, here, purchase_order_no is the extra information
that needs to be passed to know the line in the database table where the data record needs to be written.

So extension container could look like

STRUCTURE VALUEPART1 VALUEPART2 …..


BAPI_TE_MEPOHEADER 3300000180 Nikhil Pravin Parvati
.

..

Here, ‘3300000180’ is the key field for EKKO table specifying which row to be updated. And “Nikhil Pravin
Parvati” is the extra fields of EKKO specified in BAPI_TE_MEPOHEADER.

48
Source Code

Once the BAPI Extension Table and Extension Container are filled, Execute the BAPI by passing Extension
Container as a table type argument.

Custom BAPI Creation

Create a RFC Function Module with necessary parameters. Make sure you have a table parameter of type
BAPIRET2 to capture the messages generated within the FM. Write necessary coding based on Business
Requirement inside the FM.

Go to T-code SWO1 and create a BAPI as below.

49
Now click on the methods to drop down and see what methods are provided by default. There would be
two methods, showing in red color which comes by default while creating the BAPI.

50
Click or select the method as shown above and go to the path “UtilitiesAPI methodsAdd methods”.
On the screen that follows, provide the function module name and click on the continue icon.

In the ultimate pop-up, click the next step icon. We observe that the information is predefined in the
fields.
This is the next screen where you would just click on the “next” icon.

51
Click on Yes. You can see an information message reading ZBAPIFMT001 inserted.

Now save after you add the method. Select & Double click on the API method.

52
Go to Tab: ABAP Check 'API Function'.

The above screen is displayed. Go to the ABAP tab as shown below.

53
Select the Radio button reading “API Function” as already said above.

Click on the continue icon to proceed further.

Now select the Object “ZBAPI_T001” as shown below.

Go to EditChange Release StatusObject type To Modeled.

54
The above shown screen will be displayed. Click on yes.
The message shows, the object type status set to modeled. (Or already modeled)
Go to EditChange Release StatusObject type  To Implemented.

Similarly, change Object Type Status to release.

55
Similarly, change the status for Object Type component also.
Go to EditChange Release StatusObject type componentTO Modeled.

Change Object Type Component Status to implemented and released.

Finally, Generate the BAPI.

Now, if you go to BAPI transaction you can find your Custom BAPI.

6.4 BW Extractor Function Modules:

The BW Extract program (Function module) is called twice. The first time the extractor program is called,
the extraction parameters are retrieved and then the function module is called once again when the
actual data extraction takes place.

This is handled by using a flag 'I_INITFLAG'. This Flag is a part of the FM input Interface and is set during
the first call and reset for all subsequent calls.

The Data extract should be done only when it is called the second time.

Function module Interface

IMPORT PARAMETERS
I_DSOURCE - Datasource Name
I_INITFLAG - Initialize flag is for Initialize call up: When the FM is called for the first time, this parameter
is set to 'X', afterwards it is set to ' ' (blank).
I_MAXSIZE - Package size: This parameter contains the no of rows expected for a read call up.
I_REQUNR - Request number

56
TABLES PARAMETERS
I_T_SELECT - Input Selection Criteria
I_T_FIELDS - Output Structure
E_T_DATA - Output Data

STEPS

STEP 1: Create an Extract Structure in SE11 according to your requirement; here we will create a structure
for Shipment Item details for a Delivery with necessary fields.

STEP 2: Go to t code SE80 & copy the function group RSAX & give the name as ZZRSAX for the new
function group & then copy only the function module RSAX_BIW_GET_DATA_SIMPLE as
ZZRSAX_BIW_GET_DATA_SIMPLE as shown below.

57
Now go to the Tables tab for the FM ZZRSAX_BIW_GET_DATA_SIMPLE & change the Associated Type for
the parameter E_T_DATA as ZZVTTPLIKP (Extract Structure that we have created using SE11 in step 1) as
shown below:

FUNCTION ZZRSAX_BIW_GET_DATA_SIMPLE.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_REQUNR) TYPE SRSC_S_IF_SIMPLE-REQUNR
*" VALUE(I_DSOURCE) TYPE SRSC_S_IF_SIMPLE-DSOURCE OPTIONAL
*" VALUE(I_MAXSIZE) TYPE SRSC_S_IF_SIMPLE-MAXSIZE OPTIONAL
*" VALUE(I_INITFLAG) TYPE SRSC_S_IF_SIMPLE-INITFLAG OPTIONAL
*" VALUE(I_READ_ONLY) TYPE SRSC_S_IF_SIMPLE-READONLY OPTIONAL
*" VALUE(I_REMOTE_CALL) TYPE SBIWA_FLAG DEFAULT SBIWA_C_FLAG_OFF
*" TABLES
*" I_T_SELECT TYPE SRSC_S_IF_SIMPLE-T_SELECT OPTIONAL
*" I_T_FIELDS TYPE SRSC_S_IF_SIMPLE-T_FIELDS OPTIONAL
*" E_T_DATA STRUCTURE ZZVTTPLIKP OPTIONAL
*" EXCEPTIONS

58
*" NO_MORE_DATA
*" ERROR_PASSED_TO_MESS_HANDLER
*"----------------------------------------------------------------------
* Example: DataSource for table SFLIGHT
* Change the structure from sflight to ZZVTTPLIKP********
TABLES: ZZVTTPLIKP.
* Auxiliary Selection criteria structure
DATA: L_S_SELECT TYPE SRSC_S_SELECT.
* Maximum number of lines for DB table
STATICS: S_S_IF TYPE SRSC_S_IF_SIMPLE,
* counter
S_COUNTER_DATAPAKID LIKE SY-TABIX,
* cursor
S_CURSOR TYPE CURSOR.
* Create a range for Delivery Number
RANGES: L_R_VBELN FOR LIKP-VBELN.
* Initialization mode (first call by SAPI) or data transfer mode
* (following calls) ?
IF I_INITFLAG = SBIWA_C_FLAG_ON.
************************************************************************
* Initialization: check input parameters
* buffer input parameters
* prepare data selection
************************************************************************
* Check DataSource validity
CASE I_DSOURCE.
* Give the datasource a name which we will create in RSO2
WHEN 'ZZ_SHIPMENT_DATA '.
WHEN OTHERS.
IF 1 = 2. MESSAGE E009(R3). ENDIF.
* this is a typical log call. Please write every error message like this
LOG_WRITE 'E' "message type
'R3' "message class
'009' "message number
I_DSOURCE "message variable 1
' '. "message variable 2
RAISE ERROR_PASSED_TO_MESS_HANDLER.
ENDCASE.
APPEND LINES OF I_T_SELECT TO S_S_IF-T_SELECT.
* Fill parameter buffer for data extraction calls
S_S_IF-REQUNR = I_REQUNR.
S_S_IF-DSOURCE = I_DSOURCE.
S_S_IF-MAXSIZE = I_MAXSIZE.
* Fill field list table for an optimized select statement
* (in case that there is no 1:1 relation between InfoSource fields
* and database table fields this may be far from beeing trivial)
APPEND LINES OF I_T_FIELDS TO S_S_IF-T_FIELDS.
ELSE. "Initialization mode or data extraction ?
********************************************************************
* Data transfer: First Call OPEN CURSOR + FETCH
* Following Calls FETCH only
********************************************************************
* First data package -> OPEN CURSOR

59
IF S_COUNTER_DATAPAKID = 0.
* fill range with VBELN & change the name of range table
LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'VBELN'.
MOVE-CORRESPONDING L_S_SELECT TO L_R_VBELN.
APPEND L_R_VBELN.
ENDLOOP.
* Determine number of database records to be read per FETCH statement
* from input parameter I_MAXSIZE. If there is a one to one relation
* between DataSource table lines and database entries, this is trivial.
* In other cases, it may be impossible and some estimated value has to
* be determined.
OPEN CURSOR WITH HOLD S_CURSOR FOR
* Write your Select Query to fetch the data:
Select LIKP~VBELN
LIKP~ERNAM
LIKP~ERDAT
LIKP~VKORG
LIKP~LFDAT
LIKP~KUNNR
LIKP~KUNAG
VTTP~TKNUM
VTTP~TPNUM
from LIKP INNER JOIN VTTP
on LIKP~VBELN = VTTP~VBELN
where LIKP~VBELN IN L_R_VBELN.
ENDIF. "First data package ?
* Fetch records into interface table.
* named E_T_'Name of extract structure'.
FETCH NEXT CURSOR S_CURSOR
APPENDING CORRESPONDING FIELDS
OF TABLE E_T_DATA
PACKAGE SIZE S_S_IF-MAXSIZE.
IF SY-SUBRC <> 0.
CLOSE CURSOR S_CURSOR.
RAISE NO_MORE_DATA.
ENDIF.
S_COUNTER_DATAPAKID = S_COUNTER_DATAPAKID + 1.
ENDIF. "Initialization mode or data extraction ?
ENDFUNCTION.

STEP 3: Go to t-code RSO2 & create a DataSource with the same name that we have used in our FM i.e.,
ZZ_SHIPMENT_DATA & as we are uploading transactional data so select the radiobutton for Transaction
data as shown below.

60
Select Application Component as SD & maintain the text for short, medium & long description & then click
on the tab Extraction by FM as shown below.

Now enter the name of the Extract Structure & FM that we have created in step 1 & 2 respectively & then
click on Save.

Give the selection condition & click on save.

61
STEP 4: Go to t code RSA3, enter the name of our DataSource & click on Start Extractor to check the data
in the datasource using Extractor.

STEP 5: Go to t code RSA1 in our BI system, here go to DataSources, right click on application component
Sales and Distribution & Replicate data as shown below.

62
Click on Continue & proceed as shown below.

Double click on the Data-Source & Activate it as shown.

63
STEP 6: In RSA1 click on InfoProvider in the right hand panel, create an InfoArea & then create a DataStore
Object in it as shown below.

Select the content for the DSO & Activate it:

64
STEP 7: In RSA1 click on DataSources in the right hand panel, go to our DataSource ZZ_SHIPMENT_DATA &
right click on it & click on Create Transformation as shown below.

In the Target of Transformation give Object Type as DataStore Object and name of DSO that we have
created in Step 6 as shown.

Create the Transformation & Activate it.

65
STEP 8: Go to DataSource ZZ_SHIPMENT_DATA right click on it & create InfoPackage as shown below.

Give a description for the InfoPackage & click on Save.

Now go to tab Schedule & click on Start as shown below.

66
Now go to the Monitor.

STEP 9: Right click on the DataStore Object ZDEMODSO & Create Data Transfer Process as shown below:

Click on Continue, Activate it & then click on Execute.

67
Click on Yes as shown below to continue.

STEP 10: Right click on the DataStore Object ZDEMODSO & click on Manage to check the result.

68
Go to the Content tab of InfoProvider Administrator screen & click on New Data as shown below.

Now click on Execute.

Final data in DataStore Object:

69
7. FORMS

7.1 SAP Script

Window Types

MAIN – This is the window in which continuous text is output. This is the window used by dialog users of a
print program and layout set. For example the body text of a letter would be entered in MAIN.
VAR – Window with variable contents. The text can vary on each page in which the window is positioned.
Variable windows are formatted for each page.
CONST – Window with constant contents which is only formatted once.

Elements of Layout Set

Header data - Data related to development (created by, development class, etc.) and layout set
information (which elements are used) are both stored in the header data. A start page must be entered
here.
Paragraph formats - Paragraph formats are required in layout sets - as in styles - in order to format texts.
However, they are also used for word processing in layout sets, for example, to format text elements.
Character formats - You can also use character formats to format texts or paragraphs. Unlike paragraph
formats, however, they are used to format text within a paragraph.
Windows - Windows are names and window types, which are not physically positioned until they are
allocated to pages and units of measurement are specified.
Pages - Pages are defined to provide the system with a start and end point in text formatting.
Page windows - Page windows are the combination of windows and pages, where the dimensions of a
window and its position on a page are specified.
Logo in Sap Script
The report RSTXLDMC allows a TIFF graphics file to be uploaded from the file system of the R/3 GUI to a
standard text in the R/3 word processor SAP script. Specify the TIFF file path and type as shown below,
enter the Name of the standard text to be generated and execute.

70
The details of the upload will be displayed as below.

Now include this in Script window as stated below


INCLUDE ZHEX-MACRO-LOGO OBJECT GRAPHICS ID BMON LANGUAGE EN.

Page Protection (A portion of Content to be displayed in single page i.e. should not get split up between
pages.)

/: PROTECT
Contents
/: ENDPROTECT

Page Break

/: NEW-PAGE
Insert SO10 Text in SAP Script
/: INCLUDE <zstandardtxt> OBJECT <txt> ID <st> LANGUAGE <lang>

Call Subroutine in SAP Script

Definition in the SAPscript form:


/: PERFORM GET_BARCODE IN PROGRAM QCJPERFO
/: USING &PAGE&
/: USING &NEXTPAGE&
/: CHANGING &BARCODE&
/: ENDPERFORM
Coding of the calling ABAP program:

71
REPORT QCJPERFO.
FORM GET_BARCODE TABLES IN_PAR STUCTURE ITCSY
OUT_PAR STRUCTURE ITCSY.
DATA: PAGNUM LIKE SY-TABIX, "page number
NEXTPAGE LIKE SY-TABIX. "number of next page
READ TABLE IN_PAR WITH KEY ‘PAGE’.
CHECK SY-SUBRC = 0.
PAGNUM = IN_PAR-VALUE.
READ TABLE IN_PAR WITH KEY ‘NEXTPAGE’.
CHECK SY-SUBRC = 0.
NEXTPAGE = IN_PAR-VALUE.
READ TABLE OUT_PAR WITH KEY ‘BARCODE’.
CHECK SY-SUBRC = 0.
IF PAGNUM = 1.
OUT_PAR-VALUE = ‘|’. "First page
ELSE.
OUT_PAR-VALUE = ‘||’. "Next page
ENDIF.
IF NEXTPAGE = 0.
OUT_PAR-VALUE+2 = ‘L’. "Flag: last page
ENDIF.
MODIFY OUT_PAR INDEX SY-TABIX.
ENDFORM.

7.2 SMARTFORMS

Logo
Go to transaction SE78 (Administration of Form Graphics).

Double-click on “GRAPHICS” node and click on “Import (F5)” to import the image.

72
Select the file name by using the F4 functionality available. Name your graphic and enter a short
description. If you have color image, select the radio button “Color Bitmap image”. Click on tick mark to
proceed.

The graphic is imported and is stored in “Business Document Server”.

You can test this by selecting print preview:

73
Now go to transaction SMARTFORM and create a new form and give a short description for the same.

To display an image, right click on Main Window  Create  Graphic

Page Break

Click on main area and create a loop, give internal table & workarea as shown

74
Right click on loop and create command, followed by table line Create table line for the loop. we will get
four columns now. Create text for every column

In cell 5 i.e first column, create a code by right clicking on that cell->create->flow logic->programming
lines.

In that code, write the following code and pass variables to output parameters.

Under Conditions in Command and mention the condition.

Under General Attributes in command, tick Go to New Page and mention the Page.

75
Total and Subtotal

Create LOOP in MAIN Area under the Table. Inside the loop under SORT CRITERIA give the name of the
field with which you want to sort and when it has to be displayed,(here EVENT SORT BEGIN).It works like
AT-NEW event in loop. Now write the field for which the subtotal to be calculated in the SORT CRITERIA
and select the event. Here EVENT ON END. This works like AT-NEW event in loop. Mention the field (Sort-
Field for subtotal) based on which Subtotal is required under the events SORT BEGIN and SORT END.

Now 2 events will be created.

Calculate Total for the required field (field for which Subtotal is required).

76
In the event CARRID EVENT ON SORT END which will be called at the end of current CARRID, create a table line
and text under that to display the Subtotal. Also create Code Program Lines to clear the SUM so that SUM is back
to zero for the next CARRID.

77
8. ENHANCEMENTS

8.1 User Exit

SMOD – Search Exit using Package Details, Debug & keep breakpoint at ‘CALL CUSTOMER-FUNCTION’.
CMOD – Create implementation.
SD Exits – MV45AFZZ, MV50AFZZ, RV60AFZZ.

8.2 BADI

Works on interface concept. Hence, multiple implementations of any method in the BADI is possible since
each implementation creates a new Class inheriting from the Interface.

BADI Filters

T-code - SE18

Tick Checkbox Filter-Dependant. Use F4 on Filter Type to search appropriate Data Element.

If a BADI implementation exists, system will try to adjust the implementation since the BADI defenition
has changed.

78
Now check the parameters of the method any implementation, you can find a new parameter FLT_VAL
which will act as filter to be used inside the method.

Adding Filter value to the BADI implementation.

Now, this implementation will be called only for the user ‘SAPUSER’.

79
8.3 BTE

Transaction – FIBF

Environment -> Infosystem (Processes)

Execute and you will find the list of events.

Double click on appropriate BTE and go to Sample Function Module.

Copy the Sample FM to Z FM.

80
Write addidional Logic in FM as per requirement.

Create a Product.

Link Function Module and Event using the Product.

81
8.4 Implicit and Explicit Enhancements

Implicit Enhancements
Found with sequence of “ (generally at end of Forms, Includes and FMS). We need to right click and create
implementation.

Explicit Enhancements
Enhancement Section – possibility to replace Standard code with Custom Code.
Enhancement Spot – Cannot replace but can add new implementations. Multiple implementations
possible.

8.5 VOFM Pricing Routines

Transaction – VOFM
Condition Base Value – KWERT
Condition Value – KBETR
Create new routine and activate. Code inside to change values.

Deactivate routine to stop the code from being executed.

82
9. PERFORMANCE TUNING

9.1 Performance Analysis Tools

ST05
It contains SQL Trace plus RFC, Enqueue and Buffer Trace. Mainly the SQL trace is used to measure the
performance of the select statements of the program.

SE30
It is used to measure performance of Programming Lines (LOOPS and READS).

SAT
It is the replacement of the pretty outdated SE30. It provides same functionality as SE30 plus some
additional features.

ST12
This transaction (part of ST-A/PI software component) is a combination of ST05 and SAT.

ST12 Demonstration
Enter User Name and Start Trace.

Execute the necessary transactions.

83
Now Click on End Traces and Collect.

You will get the below pop-up screen.

84
Select the necessary traces from the ALV and hit Enter. Then, select Full Screen to display list of traces.

85
Now, select the necessary trace and click on Analysis Button ( ).

Now click on Per ModUnit to Sort the Trace based on subroutines for easier analysis.

Now you will get records sorted on Subroutines, FMs and Methods.

To analyze any of these, for e.g. subroutine FINAL_DATA, expand the same. Now you can see the time
taken for LOOPs and READs.

86
After this analysis, code fine tuning can be done accordingly.

9.2 Code Fine Tuning Techniques

1. DATABASE
a. Use WHERE clause in your SELECT statement to restrict the volume of data retrieved. Very important!!
b. Design your Query to Use as much index fields as possible in your WHERE statement
c. Use INNER (or OUTER under some circumstances) JOINS in your SELECT statement to retrieve the
matching records at one shot instead of FOR ALL ENTRIES.
d. Avoid using nested SELECT statement and SELECT within LOOPs, better use JOINs or FOR ALL ENTRIES. Use
FOR ALL ENTRIES when the internal table is already there or the end of some processing. Try JOINs if the
SELECT are right behind each other
e. Avoid using INTO CORRESPONDING FIELDS OF TABLE during buffered access. Otherwise use the most
appropriate for the program.
f. Avoid using SELECT * and Select only the required fields from the table.
g. Avoid using ORDER BY in SELECT statements if it differs from used index (instead, sort the resulting
internal table), because this may add additional work to the database system which is unique, while there
may be many ABAP servers
h. INDEX: Creation of Index for improving performance should not be taken without thought. Index speeds
up the performance but at the same time adds two overheads namely; memory and insert/append
performance. When INDEX is created, memory is used up for storing the index and index sizes can be
quite big on large transaction tables! When inserting new entry in the table, all the indexes are updated.
More index more time. More the amount of data, bigger the indices, larger the time for updating all the
indices
i. Avoid Executing an identical Select (same SELECT, same parameter) multiple times in the program. Buffer
in your ABAP code.
j. Avoid using join statements if adequate standard views exist - no performance impact.

2. TABLE BUFFER
a. Defining a table as buffered (SE11) can help in improving the performance but this has to be used with
caution. Buffering of tables leads to data being read from the buffer rather than from table. Buffer sync
with table happens periodically, only if something changes which is happen rarely. If this table is a
transaction table, chances are that the data is changing for a particular selection criteria; therefore
application tables are usually not suited for table buffering. Using table buffering in such cases is not
recommended. Use Table Buffering for configuration data and sometimes for Master Data.

87
b. Avoid using complex Selects on buffered tables-, because SAP may not be able to interpret this request,
and may transmit the request to the database- The code inspector tells which commands bypass the
buffer.

3. Internal tables
a. Use HASHED tables where-ever possible. Otherwise SORTED tables. STANDARD tables should be the last
choice.
b. Use assign instead of into in LOOPs for table types with large work areas, if the data is being modified.
c. When in doubt call transaction SE30 and check your code.
d. If you must use a STANDARD table and you are using a READ, sort the table appropriately and use the
addition BINARY SEARCH to speed up the search.

4. Miscellaneous
a. PERFORM: When writing a subroutine, always provide type for all the parameters. This reduces the
overhead which is present when system determines on its own each type from the formal parameters
that are passed. It also makes for more robust programming.

88
10.UPGRADE

10.1 Sequence of Activities

 System Preparation and Stack Level patch Upgrade – BASIS


 SPDD Phase – ABAP team
 System Upgrade – BASIS team
 SPAU Phase – ABAP team
 Functional Testing – FUNCTIONAL team

10.2 ABAP Activities

SPDD
To fix the impact on Data Dictionary Objects due to upgrade.
Transaction – SPDD

SPAU
To fix the impact on program code due to upgrade.
Transaction – SPAU

10.3 Procedure to fix Impacted Objects in SPDD & SPAU

Any standard object that contains custom code due to enhancements or any other method and has been
modified by SAP as part of this new upgrade version will reflect in the transactions SPDD (Data Dictionary)
and SPAU (Program Lines).

Following actions are posible to fix the impacted objects in SPDD & SPAU –
 Reset to Original – Considers only SAP’s Standard changes and removes our custom changes.

 Adopt Modification – Considers our custom changes as well.

89
Following are possible scenarios w.r.t objects in SPDD & SPAU –
 Any custom changes / enhancements done has been standardized by SAP – This means that our
cutom changes have been adopted by SAP in this upgrade and hence we need to ‘Reset to
Original’.
 SAP has modified the object’s standard but has not standardized the custom changes – This
means that SAP has upgraded it’s standard alone and has not adopted our custom changes.
Hence, we need to ‘Adopt Modifications’ and include our custom changes as well.

90
11.DEBUGGING

11.1 Break Point

In the debugging session, we can set breakpoints at run time on a statement (using Keywords),
subroutine, Function Module, Message.. etc.

For example, we will set breakpoint on a message.

Here we need to specify the Message Details and the breakpoint will be set..

91
11.2 Watch Point

Watch-point is used to monitor change in value of any variable during run time. The debugger will stop at
the statement that changes the value of the variable specified in the Watch-point. In a watch-point, we
can also specify value conditions on that variable based on which the debugger must start.

For example, let us create a watch-point on the variable ‘l_w_final-quantity’.


Click on create Watch-point.

Specify Variable name and condition.

11.3 Update Debugging

In general, in any transaction, all the DB Update happens in background after the transaction is complete
in foreground and COMMIT WORK is triggered. Update Debugging can be used to debug the statements
that are executed after COMMIT WORK.

92
Go to Settings -> Change Debugger Profile/ Settings.

Tick Update Debugging.

Now, once the normal debugging session get’s complete, a new session will open for update debugging.
Here, we can use breakpoints and watchpoints to debug.

93

You might also like