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.

Problem with system refresh

By Joyjit Ghosh,
Kolkata, India.

Problem :

In few cases I have seen that after system refresh custom codes developed in the original system are not editable. This problem mainly happens in a landscape which contains two parallel paths one dedicated to development and another one for maintaining the old code. After a certain point in development cycle it is important to make the 2 paths in sync with each other and that’s why we have to refresh one system by the other. And after this refresh this problem may arise.

Solution:

From the above message you can get a hint and based on it you can check the original system name of this program from the menu path (Goto à Object directory) shown below





In this case original system name is different than the current system (BSP) name. This is happened because of system refresh. As code is refreshed from BT1 to BSP; due to this original system name is also changed to BT1 from BSP. And now SAP is considering BT1 as the original system that’s why it is showing this above message and not permitting to edit the program directly.

So to avoid this problem we need to manually change the original system from BT1 to BSP.

Go to transaction SE03. Set the first check box and give the program name to its corresponding text box and press execute button.



In the next screen select program entry and press the change object directory button.



In the next popup screen change the original system and press save button.


You will get the following message:



Now you can edit the program without any problem