Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
jpsapabap21
Participant
I recently stumbled upon ABAP 7.5 documentation. I was interested to see what is new. But rather I got to know what is old. SAP now says that subroutines are obsolete.

Shocked? Well, I was. I have been using performs and have always preferred them over methods. A habit that I am trying to change but not very successful at it so far.

So when I saw the statement 'Performs are Obsolete'. I was bit worried - how would I cope with this?

As per the guidelines available at this link, whenever you are developing new code, do not create new Subroutines(Performs) or Function Modules, use objects/methods instead.

The rules say, and there are couple of them -

Rule 1 : Do not implement in function modules and subroutines

Use FMs and Performs only if they are a must. Use Methods instead.

Rule 2 : Use ABAP Objects

Use ABAP objects wherever possible for new and further developments. Classic processing blocks should only be created in exceptional cases.

And as per every rule, these rules also have exceptions. Not everything can be done in classes. Well, not yet. So the exception is long. But over the time SAP will reduce the exceptions. Some of the exceptions are as below –

  1. RFC function modules – RMI or Remote Method Invocation is not yet available

  2. Update function modules – These are still to be used

  3. CALL SCREEN and CALL SELECTION-SCREEN – Object-oriented handling of classic dynpros is still not available. This is a feature that I personally would love. 

  4. PERFORM ON COMMIT|ROLLBACK – We anyways do not use these generally, but if you have to – go ahead.

  5. GENERATE SUBROUTINE POOL – I had to use this only once in 13 years. So not really looking forward.


So, our new ABAP reports should still be created using a program, have selection screen and have events, but instead of performs we should have methods. Here is an example of how it should look.
*&--------------------------------------------------------*
*& Report YABAP_750_REPORT
*&--------------------------------------------------------*
*&
*&--------------------------------------------------------*
REPORT yabap_750_report.

CLASS lcl_alv DEFINITION FINAL.

PUBLIC SECTION.
CONSTANTS :
information TYPE sy-msgty VALUE 'I'.

TYPES :
tt_flights TYPE STANDARD TABLE OF sflight
WITH EMPTY KEY.
"... add more types here

METHODS :
constructor
IMPORTING
i_carrier TYPE sflight-carrid
i_connection TYPE sflight-connid,
start_report_process
RETURNING
VALUE(r_error) TYPE char1.

"... add more public methods here

PROTECTED SECTION.
"Add protected data/methods if needed

PRIVATE SECTION.
DATA :
carrier TYPE sflight-carrid,
conn_id TYPE sflight-connid,
flights TYPE tt_flights.
"... add more data declarations here

METHODS :
get_flights
RETURNING
VALUE(rt_flights) TYPE tt_flights,
display_flights
RETURNING
VALUE(r_error) TYPE char1.
"... add more private methods here

ENDCLASS.

CLASS lcl_alv IMPLEMENTATION.
METHOD constructor.
"Set variables based on called parameters
carrier = i_carrier.
conn_id = i_connection.
"Initialize attributes
CLEAR flights.
ENDMETHOD.

METHOD start_report_process.
CLEAR r_error.
flights = get_flights( ).
IF flights IS INITIAL.
MESSAGE e001(00) WITH 'No data found'(002)
INTO DATA(lv_error).
r_error = abap_true.
ELSE.
r_error = display_flights( ).
ENDIF.
ENDMETHOD.

METHOD get_flights.
CLEAR rt_flights.
SELECT * FROM sflight INTO TABLE @rt_flights
WHERE carrid = @carrier
AND connid = @conn_id.
ENDMETHOD.

METHOD display_flights.
CLEAR r_error.
TRY.
"Create ALV table object for the output data table
cl_salv_table=>factory( IMPORTING r_salv_table = DATA(lo_table)
CHANGING t_table = flights ).
lo_table->get_functions( )->set_all( ).
lo_table->get_columns( )->set_optimize( ).
lo_table->display( ).
CATCH cx_salv_msg. "ALV can not be displayed, issue error
MESSAGE e001(00) WITH 'Error in ALV creation'(003) INTO DATA(lv_error).
r_error = abap_true.
ENDTRY.
ENDMETHOD.

"... add more methods implementation here
ENDCLASS.

"... build selection screen here or in another include
SELECTION-SCREEN BEGIN OF BLOCK main_block WITH FRAME TITLE TEXT-001.
PARAMETERS : carrid TYPE sflight-carrid,
connid TYPE sflight-connid.
SELECTION-SCREEN END OF BLOCK main_block.

START-OF-SELECTION.
"Create object for the class
DATA(o_alv) = NEW lcl_alv( i_carrier = carrid
i_connection = connid ).

"Below code starts the main process and issues error
"It can be coded as per requirement
IF o_alv->start_report_process( ) IS NOT INITIAL.
MESSAGE ID sy-msgid TYPE lcl_alv=>information NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

 

Conclusion:



  • If you have not switched to using methods over performs, this is the time to do so.

  • Using this or a similar template, reports can be created very easily.

  • This style can also be applied to other programs, like file/proxy based interface program.


In short, the message is, even if we are used to a way of coding, which is also comfortable, we should change with the ABAP advancements.

And this, is my first step.

This is also my first blog, so your comments and suggestions are welcome. Please use the comment section below or you can also post your questions here.

 

- Jagdish Patil
31 Comments
Labels in this area