Just 4 Versions of the same program to understand OOPs ABAP

Today, we’ll alter an ABAP program four times to turn it into an OOPs ABAP program at version four.I assure you that if you stick around until the very end, you will understand how to program in ABAP utilizing the object-oriented approach.

Even though I’ve been programming in ABAP for over ten years, I haven’t really created an end-to-end ABAP application using OOPs.Although I have used static and instance methods, classes (local and global), attributes, and other concepts, I cannot claim to be an OOPs ABAP developer. I’m still the same developer that has worked with procedural languages for so long. I have worked with Web Dynpro ABAP extensively, and I have adhered strictly to the MVC core architecture. But I have generated my code in Web Dynpro 90% of the time using the wizard. Professionals advise us to write that code ourselves. However, lazy ABAPers never stop using the wizard; after all, why is the wizard’s magical wand included in the

Although I have been programming with ABAP for more than a decade, I haven’t truly used OOPs to construct an end-to-end ABAP application.Despite having used classes (both local and global), methods (both static and instance), attributes, etc., I cannot claim to be an OOPs ABAP developer. I’m still the same old coder that is used to working with procedural language. I’ve worked extensively with Web Dynpro ABAP, which has MVC as its main architecture, and I’ve followed its core values. Still, I use the wizard 90% of the time to produce my Web Dynpro code. Experts say that we should write the code ourselves. Lazy ABAPers frequently use the wizard because, well, why is the wizard, or magical wand.

We frequently use the justification that since the current application does not use OOPs, we do not want to implement OOPs while still supporting the current object. Another well-known justification is that the deadline is really tight. So let me stick to what I know better and avoid dabbling in OOPs. I was never able to learn OOPs with this mindset.I’m attempting to change, though. Even though it might not be perfect, I am attempting to write about the latest advancements in OOPs.Learning is never too late. When I go back and review all of the codes I wrote in my early days utilizing procedural approaches, I can see several problems with those so-called simple approaches. Thus, as of today,

So today, if there is a problem with my OOPs approach, it would just be a learning curve. Tomorrow if I look back to these OOPs programming and I can point out the mistakes, then I should consider I have learned some OOPs then. For some reason, if I am not able to find fault in my OOPs then probably, I never ever programmed in OOPs.

Permit me to present an actual item from one of my projects.In order to plan the authorization for various users, the Security Team and Business Team may review a report that showed all the roles associated to any transaction code.Examine the software that shows traditional report output and internal tables with header lines that were created using the same methodology.

Program Version 1.0

*----------------------------------------------------------------------*
* Author: www.sapyard.com
* Title: Security report - Roles assigned to
* Transaction Codes or vice versa.
*----------------------------------------------------------------------*
* Desc : Generates a report of relationships between Transaction
* Codes and Security Roles. It has options of switching the
* dimensions of the report - i.e. TCODE to ROLE or ROLE to
* TCODE
*----------------------------------------------------------------------*
* Old ABAPer's way of programming
*----------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK repopt WITH FRAME TITLE text-001.
PARAMETERS: p_tcode TYPE tcode.
SELECTION-SCREEN END OF BLOCK repopt.

* Internal table with Header line
DATA: BEGIN OF t_tcode OCCURS 0,
tcode LIKE agr_1251-low,
ttext LIKE tstct-ttext,
role LIKE agr_1251-agr_name,
rtext LIKE agr_texts-text,
END OF t_tcode.

TOP-OF-PAGE.
FORMAT COLOR COL_HEADING.

WRITE: / 'Old ABAPer', 60 'Transaction Code to Role Matrix',
136 'Date:', sy-datum.
WRITE: /136 'Page:', (10) sy-pagno NO-SIGN.
ULINE.
WRITE: /(20) 'Txn Code', (36) 'Txn Desc',
60(30)'Role Name', (61) 'Role Desc'.
ULINE.

FORMAT COLOR OFF.
START-OF-SELECTION.

PERFORM report_by_tcode.

*&---------------------------------------------------------------------*
*& Form report_by_tcode
*&---------------------------------------------------------------------*
* Generate report of Roles assigned to TCODEs
*----------------------------------------------------------------------*
FORM report_by_tcode.
SELECT a~low b~ttext a~agr_name c~text INTO TABLE t_tcode
FROM agr_1251 AS a
INNER JOIN tstct AS b ON a~low = b~tcode
INNER JOIN agr_texts AS c ON a~agr_name = c~agr_name
WHERE a~low = p_tcode
AND a~object = 'S_TCODE'
AND b~sprsl = sy-langu
AND c~spras = sy-langu
AND c~line = '00000'
ORDER BY a~low a~agr_name.

LOOP AT t_tcode.
* Table name and Header line name is same
WRITE: /(20) t_tcode-tcode, t_tcode-ttext, 60 t_tcode-role, (61) t_tcode-rtext.
ENDLOOP.
ENDFORM. " report_by_tcode

Highlights of the above program which is no more used.

ABAP Technical

Let us test this program.

ABAP Objects

Classical Output Report

OOPs ABAP

Please take a moment to read this lovely (if a little lengthy) and enlightening essay on SCN.

Let us now examine the identical software, which was created by a programmer who does not define the internal table with a header line but is familiar with REUSE_ALV_GRID_DISPLAY.

Version 2.0 of the program

*----------------------------------------------------------------------*
* Relatively New ABAPer's way of programming
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* TYPE Declaration
*----------------------------------------------------------------------*
TYPES: BEGIN OF ty_tcode,
tcode TYPE agval, " Transaction
ttext TYPE ttext_stct, " Transaction Text
role TYPE agr_name, " Role Name
rtext TYPE agr_title, " Short Description
END OF ty_tcode.
*----------------------------------------------------------------------*
* DATA Declaration
*----------------------------------------------------------------------*
DATA:
gt_tcode TYPE STANDARD TABLE OF ty_tcode,
gs_layout TYPE slis_layout_alv, " Declaration of field
gt_fcat TYPE slis_t_fieldcat_alv, " Declaration of Field
gs_fcat TYPE slis_fieldcat_alv. " Declaration of field
*----------------------------------------------------------------------*
* SELECTION SCREEN
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK repopt WITH FRAME TITLE text-001.
PARAMETERS: p_tcode TYPE tcode.
SELECTION-SCREEN END OF BLOCK repopt.

*----------------------------------------------------------------------*
* AT SELECTION-SCREEN.
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
PERFORM validate_input.

*----------------------------------------------------------------------*
* START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.

PERFORM report_by_tcode.

*----------------------------------------------------------------------*
* END-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.

PERFORM display_report.

*----------------------------------------------------------------------*
* SUB ROUTINES
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form VALIDATE_INPUT
*&---------------------------------------------------------------------*
* Validate Selection Input
*----------------------------------------------------------------------*
FORM validate_input.
SELECT COUNT(*) UP TO 1 ROWS
FROM tstc
WHERE tcode = p_tcode.
IF sy-subrc NE 0.
MESSAGE 'Please enter a Valid T-Code' TYPE 'I'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form report_by_tcode
*&---------------------------------------------------------------------*
* Generate report of Roles assigned to TCODEs
*----------------------------------------------------------------------*
FORM report_by_tcode.
SELECT a~low b~ttext a~agr_name c~text INTO TABLE gt_tcode
FROM agr_1251 AS a
INNER JOIN tstct AS b ON a~low = b~tcode
INNER JOIN agr_texts AS c ON a~agr_name = c~agr_name
WHERE a~low = p_tcode
AND a~object = 'S_TCODE'
AND b~sprsl = sy-langu
AND c~spras = sy-langu
AND c~line = '00000'
ORDER BY a~low a~agr_name.

ENDFORM. " report_by_tcode

*&---------------------------------------------------------------------*
*& Form DISPLAY_REPORT
*&---------------------------------------------------------------------*
* Display Report
*----------------------------------------------------------------------*
FORM display_report .
* Filling field catalog.
PERFORM prepare_fields_description.
* Setting the ALV layout
PERFORM build_layout.
* Display ALV Report
PERFORM display_alv_report.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form PREPARE_FIELDS_DESCRIPTION
*&---------------------------------------------------------------------*
FORM prepare_fields_description .
CLEAR gs_fcat.
gs_fcat-fieldname = 'TCODE'.
gs_fcat-seltext_m = 'Txn Code'.
gs_fcat-col_pos = 1.
APPEND gs_fcat TO gt_fcat.

CLEAR gs_fcat.
gs_fcat-fieldname = 'TTEXT'.
gs_fcat-seltext_m = 'Txn Desc'.
gs_fcat-col_pos = 2.
APPEND gs_fcat TO gt_fcat.

CLEAR gs_fcat.
gs_fcat-fieldname = 'ROLE'.
gs_fcat-seltext_m = 'Role Name'.
gs_fcat-col_pos = 3.
APPEND gs_fcat TO gt_fcat.

CLEAR gs_fcat.
gs_fcat-fieldname = 'RTEXT'.
gs_fcat-seltext_m = 'Role Desc'.
gs_fcat-col_pos = 4.
APPEND gs_fcat TO gt_fcat.

ENDFORM. " PREPARE_FIELDS_DESCRIPTION

*&---------------------------------------------------------------------*
*& Form build_layout
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM build_layout .
gs_layout-no_input = 'X'.
gs_layout-colwidth_optimize = 'X'.
gs_layout-zebra = 'X'.
ENDFORM. " BUILD_LAYOUT

*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* Display report using ALV grid
*----------------------------------------------------------------------*
FORM display_alv_report.

IF gt_tcode[] IS NOT INITIAL.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_buffer_active = space
i_callback_program = sy-repid
is_layout = gs_layout
it_fieldcat = gt_fcat[]
TABLES
t_outtab = gt_tcode
EXCEPTIONS
program_error = 1
OTHERS = 2.

ENDIF.

ENDFORM. " DISPLAY_ALV_REPORT

Check the output has changed from classical to ALV.

Object Oriented Programming in SAP ABAP

Now, let us check how most of the old-schooled ABAPers try their OOPs programming when they are forced to adopt OOPs. I know some projects where OOPs is the only standard of programming. In such projects, the not so OOPs enthusiast replace PERFORMs by METHODs without really taking the advantage of Object Oriented Architecture. Check how we can really kill the beauty of OOPs below. And I am one of them. 

Program Version 3.0

*----------------------------------------------------------------------*
* ABAPer who is trying to write his/her first OOPs development
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* CLASS-DEFINITIONs and IMPLEMENTATIONs
*----------------------------------------------------------------------*
CLASS lcl_validate_input DEFINITION.
PUBLIC SECTION.
CLASS-METHODS: validate_input.
ENDCLASS.

CLASS lcl_validate_input IMPLEMENTATION.
METHOD validate_input.
PERFORM validate_input.
ENDMETHOD.
ENDCLASS.

CLASS lcl_fetch_data DEFINITION.
PUBLIC SECTION.
CLASS-METHODS: fetch_data.
ENDCLASS.

CLASS lcl_fetch_data IMPLEMENTATION.
METHOD fetch_data.
PERFORM report_by_tcode.
ENDMETHOD.

ENDCLASS.

CLASS lcl_display_report DEFINITION.
PUBLIC SECTION.
CLASS-METHODS: display_data.
ENDCLASS.

CLASS lcl_display_report IMPLEMENTATION.
METHOD display_data.
PERFORM display_report.
ENDMETHOD.

ENDCLASS.

*----------------------------------------------------------------------*
* TYPE Declaration
*----------------------------------------------------------------------*
TYPES: BEGIN OF ty_tcode,
tcode TYPE agval, " Transaction
ttext TYPE ttext_stct, " Transaction Text
role TYPE agr_name, " Role Name
rtext TYPE agr_title, " Short Description
END OF ty_tcode.
*----------------------------------------------------------------------*
* DATA Declaration
*----------------------------------------------------------------------*
DATA:
gt_tcode TYPE STANDARD TABLE OF ty_tcode,
gs_layout TYPE slis_layout_alv, " Declaration of field
gt_fcat TYPE slis_t_fieldcat_alv, " Declaration of Field
gs_fcat TYPE slis_fieldcat_alv. " Declaration of field

* Define the Object Data
DATA:
o_validate TYPE REF TO lcl_validate_input,
o_fetch TYPE REF TO lcl_fetch_data,
o_display TYPE REF TO lcl_display_report.
*----------------------------------------------------------------------*
* SELECTION SCREEN
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK repopt WITH FRAME TITLE text-001.
PARAMETERS: p_tcode TYPE tcode.
SELECTION-SCREEN END OF BLOCK repopt.

*---------------------------------------------------------------------*
* INITIALIZATION *
*---------------------------------------------------------------------*
INITIALIZATION.
CREATE OBJECT: o_validate, o_fetch, o_display.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN.
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
o_validate->validate_input( ).

*----------------------------------------------------------------------*
* START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
o_fetch->fetch_data( ).

*----------------------------------------------------------------------*
* END-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
o_display->display_data( ).

*----------------------------------------------------------------------*
* SUB ROUTINES
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form VALIDATE_INPUT
*&---------------------------------------------------------------------*
* Validate Selection Input
*----------------------------------------------------------------------*
FORM validate_input.
SELECT COUNT(*) UP TO 1 ROWS
FROM tstc
WHERE tcode = p_tcode.
IF sy-subrc NE 0.
MESSAGE 'Please enter a Valid T-Code' TYPE 'I'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form report_by_tcode
*&---------------------------------------------------------------------*
* Generate report of Roles assigned to TCODEs
*----------------------------------------------------------------------*
FORM report_by_tcode.
SELECT a~low b~ttext a~agr_name c~text INTO TABLE gt_tcode
FROM agr_1251 AS a
INNER JOIN tstct AS b ON a~low = b~tcode
INNER JOIN agr_texts AS c ON a~agr_name = c~agr_name
WHERE a~low = p_tcode
AND a~object = 'S_TCODE'
AND b~sprsl = sy-langu
AND c~spras = sy-langu
AND c~line = '00000'
ORDER BY a~low a~agr_name.

ENDFORM. " report_by_tcode

*&---------------------------------------------------------------------*
*& Form DISPLAY_REPORT
*&---------------------------------------------------------------------*
* Display Report
*----------------------------------------------------------------------*
FORM display_report .
* Filling field catalog.
PERFORM prepare_fields_description.
* Setting the ALV layout
PERFORM build_layout.
* Display ALV Report
PERFORM display_alv_report.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form PREPARE_FIELDS_DESCRIPTION
*&---------------------------------------------------------------------*
FORM prepare_fields_description .
CLEAR gs_fcat.
gs_fcat-fieldname = 'TCODE'.
gs_fcat-seltext_m = 'Txn Code'.
gs_fcat-col_pos = 1.
APPEND gs_fcat TO gt_fcat.

CLEAR gs_fcat.
gs_fcat-fieldname = 'TTEXT'.
gs_fcat-seltext_m = 'Txn Desc'.
gs_fcat-col_pos = 2.
APPEND gs_fcat TO gt_fcat.

CLEAR gs_fcat.
gs_fcat-fieldname = 'ROLE'.
gs_fcat-seltext_m = 'Role Name'.
gs_fcat-col_pos = 3.
APPEND gs_fcat TO gt_fcat.

CLEAR gs_fcat.
gs_fcat-fieldname = 'RTEXT'.
gs_fcat-seltext_m = 'Role Desc'.
gs_fcat-col_pos = 4.
APPEND gs_fcat TO gt_fcat.

ENDFORM. " PREPARE_FIELDS_DESCRIPTION

*&---------------------------------------------------------------------*
*& Form build_layout
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM build_layout .
gs_layout-no_input = 'X'.
gs_layout-colwidth_optimize = 'X'.
gs_layout-zebra = 'X'.
ENDFORM. " BUILD_LAYOUT

*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* Display report using ALV grid
*----------------------------------------------------------------------*
FORM display_alv_report.

IF gt_tcode[] IS NOT INITIAL.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_buffer_active = space
i_callback_program = sy-repid
is_layout = gs_layout
it_fieldcat = gt_fcat[]
TABLES
t_outtab = gt_tcode
EXCEPTIONS
program_error = 1
OTHERS = 2.

ENDIF.

ENDFORM. " DISPLAY_ALV_REPORT

Now let us look at the obvious flaws.

Object Oriented Programming in ABAP

Even if you start with the aforementioned programming style and find that, when you develop your second program, you committed mistakes, you are still on the right track with OOPs. Recognizing our own mistakes is the cornerstone of education. Our leaders and mentors should be our more seasoned mentors and our junior members who are familiar with OOPs. Never should we feel bad about seeking more information about a concept we’re unsure of. Furthermore, no question is too small—not even with your ten years of experience. Everyone is constantly learning, therefore it’s never too late to start.

Let’s look at how to use OOPs to write the same program more efficiently.Since there can be issues with this code as well, I humbly beg the experts to correct me and show the right procedure.

Examine this OOPs software. Isn’t it neat looking?

Program Version 4.0

*----------------------------------------------------------------------*
* ABAPer who just wrote his first OOPs development nearly correct
*----------------------------------------------------------------------*

* Define the Object Data
DATA:
o_selection TYPE REF TO ycl_report_selection,
o_fetch TYPE REF TO ycl_report_fetch,
o_display TYPE REF TO ycl_report_display.

*----------------------------------------------------------------------*
* SELECTION SCREEN
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK repopt WITH FRAME TITLE text-001.
PARAMETERS: p_tcode TYPE tcode.
SELECTION-SCREEN END OF BLOCK repopt.

*---------------------------------------------------------------------*
* INITIALIZATION *
*---------------------------------------------------------------------*
INITIALIZATION.
CREATE OBJECT o_selection.
CREATE OBJECT o_fetch EXPORTING io_rep_sel = o_selection.
CREATE OBJECT o_display EXPORTING io_rep_fetch = o_fetch.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN.
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
* Validation at Selection Screen
o_selection->validate_input( p_tcode ).

*----------------------------------------------------------------------*
* START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
o_fetch->fetch_data( ).

*----------------------------------------------------------------------*
* END-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
o_display->display_alv( ).

Details of the classes used above in the program.

ABAP Object Concept

1. Class: YCL_REPORT_SELECTION

class YCL_REPORT_SELECTION definition
public
final
create public .

public section.

data G_TCODE type TCODE .
data G_LANGU type SPRAS .
data G_OBJECT type AGOBJECT .
data G_LINE type MENU_NUM_5 .

methods VALIDATE_INPUT
importing
!IP_TCODE type TCODE .
protected section.
private section.

types:
*----------------------------------------------------------------------*
* TYPE Declaration
*----------------------------------------------------------------------*
BEGIN OF ty_tcode,
tcode TYPE agval, " Transaction
ttext TYPE ttext_stct, " Transaction Text
role TYPE agr_name, " Role Name
rtext TYPE agr_title, " Short Description
END OF ty_tcode .
types:
tt_tcode TYPE STANDARD TABLE OF ty_tcode .
ENDCLASS.

CLASS YCL_REPORT_SELECTION IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method YCL_REPORT_SELECTION->VALIDATE_INPUT
* +-------------------------------------------------------------------------------------------------+
* | [--->] IP_TCODE TYPE TCODE
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD validate_input.
SELECT COUNT(*) UP TO 1 ROWS
FROM tstc
WHERE tcode = ip_tcode.
IF sy-subrc NE 0.
MESSAGE 'Please enter a Valid T-Code' TYPE 'E'.
ELSE.
* Populate the global variable
g_tcode = ip_tcode.
g_langu = sy-langu.
g_object = 'S_TCODE'.
g_line = '00000'.
ENDIF.
ENDMETHOD.
ENDCLASS.

2. Class YCL_REPORT_FETCH

OOPs programming in ABAP
class YCL_REPORT_FETCH definition
public
final
create public .

public section.

types:
*----------------------------------------------------------------------*
* TYPE Declaration
*----------------------------------------------------------------------*
BEGIN OF ty_tcode,
tcode TYPE agval, " Transaction
ttext TYPE ttext_stct, " Transaction Text
role TYPE agr_name, " Role Name
rtext TYPE agr_title, " Short Description
END OF ty_tcode .
types:
tt_tcode TYPE STANDARD TABLE OF ty_tcode .

data O_REP_SEL type ref to YCL_REPORT_SELECTION .
data T_TCODE type TT_TCODE .

methods FETCH_DATA .
methods CONSTRUCTOR
importing
!IO_REP_SEL type ref to YCL_REPORT_SELECTION .
protected section.
private section.
ENDCLASS.

CLASS YCL_REPORT_FETCH IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method YCL_REPORT_FETCH->CONSTRUCTOR
* +-------------------------------------------------------------------------------------------------+
* | [--->] IO_REP_SEL TYPE REF TO YCL_REPORT_SELECTION
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD constructor.
me->o_rep_sel = io_rep_sel.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method YCL_REPORT_FETCH->FETCH_DATA
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD fetch_data.
SELECT a~low b~ttext a~agr_name c~text INTO TABLE t_tcode
FROM agr_1251 AS a
INNER JOIN tstct AS b ON a~low = b~tcode
INNER JOIN agr_texts AS c ON a~agr_name = c~agr_name
WHERE a~low = me->o_rep_sel->g_tcode
AND a~object = me->o_rep_sel->g_object
AND b~sprsl = me->o_rep_sel->g_langu
AND c~spras = me->o_rep_sel->g_langu
AND c~line = me->o_rep_sel->g_line
ORDER BY a~low a~agr_name.

ENDMETHOD.
ENDCLASS.

3. Class YCL_REPORT_DISPLAY

Introduction to OOPs ABAP
class YCL_REPORT_DISPLAY definition
public
final
create public .

public section.

data O_REP_FET type ref to YCL_REPORT_FETCH .

methods DISPLAY_ALV .
methods CONSTRUCTOR
importing
!IO_REP_FETCH type ref to YCL_REPORT_FETCH .
protected section.
private section.
ENDCLASS.

CLASS YCL_REPORT_DISPLAY IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method YCL_REPORT_DISPLAY->CONSTRUCTOR
* +-------------------------------------------------------------------------------------------------+
* | [--->] IO_REP_FETCH TYPE REF TO YCL_REPORT_FETCH
* +--------------------------------------------------------------------------------------</SIGNATURE>
method CONSTRUCTOR.
me->o_rep_fet = io_rep_fetch.

endmethod.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method YCL_REPORT_DISPLAY->DISPLAY_ALV
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD display_alv.
cl_demo_output=>display_data( EXPORTING
value = me->o_rep_fet->t_tcode
name = 'My First Real OOPs ABAP Development' ).
ENDMETHOD.
ENDCLASS.

Result

Constructor in OOPs

Checked out our most popular post?

Practice:

Place breakpoints at the INITIALIZATION of the report and on the CONSTRUCTOR procedures of the classes YCL_REPORT_FETCH and YCL_REPORT_DISPLAY. Run the analysis.

What observes do you?

The classes’ CONSTRUCTOR function would, as anticipated, be invoked during the report’s INITIALIZATION event. Examine how the object data in this report is transferred across classes and applied to other methods (FETCH_DATA and DISPLAY_ALV).

In a few years, if I begin learning OOPs now, I might be able to understand the true meaning and recognize its true potential. Till then, allow me to grow from my errors.

I hope that this post will serve as a springboard for all ABAPers who were searching for a place to start when they embarked on their OOPs adventure.My advice, if you are still unsure about how to begin writing in OOPs ABAP, is to just select an existing report from your system and attempt to convert it to OOPs.Consult a team member, SAP mentors, or the SCN with any questions you may have. Professionals would undoubtedly help you or, at the at least, direct you to the appropriate resource so you may learn more.

If you have any examples of vanilla ABAP program and the new OOPs program for the same, please do share it with us. We would be happy to append it to this post so that it might act as a reference to all those ABAPers who might visit this page by mistake or knowingly. 

begin to make an effort to adapt and make ourselves fall in love with the new flavor of Object Oriented Programming in ABAP.

Please SUBSCRIBE if you would want to receive such helpful articles straight to your email. We take seriously our responsibility to protect your privacy.

What more would you like to add to this article? Have there been any problems using OOPs? Would you like to share any actual project specifications or solutions?Do not hesitate to speak up.Kindly share your opinions in the space provided for comments.

I sincerely appreciate your time!

  • Related Posts

    SAP Netweaver Gateway and OData SAP. Section I: A Brief History

    SAP Netweaver Gateway and OData SAP . Section I: A Brief History :- One area we need to stay up to date with is SAP HANA as the database, S/4…

    SAP Netweaver Gateway and OData. Section Two. Make your initial ODataService.

    SAP Netweaver Gateway, OData, and HTTPs in the Part I post, Introduction to SAP Netweaver Gateway and OData. We now have a decent understanding of the RESTful and STATEless concepts.…

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    You Missed

    Just 4 Versions of the same program to understand OOPs ABAP

    • By Varad
    • September 16, 2024
    • 5 views

    SAP Netweaver Gateway and OData SAP. Section I: A Brief History

    • By Varad
    • September 16, 2024
    • 2 views
    SAP Netweaver Gateway and OData SAP. Section I: A Brief History

    SAP Netweaver Gateway and OData. Section Two. Make your initial ODataService.

    • By Varad
    • September 14, 2024
    • 2 views

    SAP Netweaver Gateway and SAP OData. Section 3. Options for Queries in OData Service URL

    • By Varad
    • September 13, 2024
    • 3 views

    SAP Netweaver Gateway and SAP OData. Section IV. OData Service Association and Navigation

    • By Varad
    • September 12, 2024
    • 4 views

    SAP Netweaver Gateway and OData. Section V. OData Services CRUD Operations

    • By Varad
    • September 11, 2024
    • 2 views