Skip to Content
-3
Dec 17, 2018 at 12:38 PM

How to use class object from one method to another in class

1149 Views

Hello Experts,

I created a class with two methods using SE24.

Methods:

1. Get Data

2. Process Data

In a Get Data method i wrote a below code:

* References declarations
  DATA:
        lref_excel                                     TYPE REF TO zkab_cl_fdt_xl_spreadsheet,
        lref_excel_core                             TYPE REF TO cx_fdt_excel_core.

  DATA: lv_msg type string.

*  * * Internal tables declaration
  DATA:
        lt_worksheet                             TYPE STANDARD TABLE OF STRING,
        lw_worksheets like line of lt_worksheet.

  DATA: wa_worksheet type zkab_st_worksheet.

    TRY.

*     Create object of class to read .xlsx file contents

      CREATE OBJECT lref_excel
        EXPORTING
           document_name = file_name
           xdocument     = file_content.

    CATCH cx_fdt_excel_core INTO lref_excel_core.
      CLEAR lv_msg.

*     Call method to get error message text

      CALL METHOD lref_excel_core->if_message~get_text
        RECEIVING
          RESULT = lv_msg.
*<< Display error message returned in lv_msg >>
      RETURN.
  ENDTRY.

* Call method to get list of worksheets in the .xlsx file

  lref_excel->if_fdt_doc_spreadsheet~get_worksheet_names(
      IMPORTING
        worksheet_names = lt_worksheet ).

from the above code, i created a object called "lref_excel".

Now, i want to use the same object in a "Process data" method. is it possible....??

Because, in a "Process data" method also use the same logic what i wrote in a first method with some extended logics to processing the data.

Any suggestions please...

Thanks in advance...