Saturday, November 22, 2008

Create transaction on a class method

By Joyjit Ghosh,
Kolkata
, India
.

In this demo I am going to show how to create transaction on a local class method.

Step1: First create a local class in a report from transaction SE38.

REPORT z_demo_oop_jg .

*---------------------------------------------------------------------*
* CLASS create_report DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*

CLASS create_report DEFINITION.

PUBLIC SECTION.

METHODS: main.

PRIVATE SECTION.

DATA: i_data TYPE STANDARD TABLE OF sbook INITIAL SIZE 0.

METHODS: fetch_data,

display_data.

ENDCLASS. "create_report DEFINITION

*---------------------------------------------------------------------*
* CLASS create_report IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*

CLASS create_report IMPLEMENTATION.

METHOD fetch_data.

* Select 100 records from SBOOK table

SELECT * FROM sbook

INTO TABLE i_data

UP TO 100 ROWS.

ENDMETHOD. "fetch_data

METHOD display_data.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_structure_name = 'SBOOK'

TABLES

t_outtab = i_data

EXCEPTIONS

program_error = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDMETHOD. "display_data

METHOD main.

fetch_data( ).

display_data( ).

ENDMETHOD. "main

ENDCLASS. "create_report IMPLEMENTATION

Step2. Now from transaction SE93 create a transaction for the method MAIN as shown in the screen shots given below:

Give a transaction name and press create button.


In the next screen give a description and choose the proper radio button

In the next screen provide report name (where the local class is defined), local class name and method name.


Now save the transaction and execute it.
In this case it will display the report.



This technique can be used to call a method (local class) from another program using statement: call transaction.

EX: call transaction 'Z_OOP'.

Note: In the same way you can create a transaction on method of a global class.

No comments: