12-17-2018 12:38 PM
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...
12-17-2018 2:31 PM
I guess you could create mref_excel as an attribute of your class instead of the local variable lref_excel (if the get_data & process_data are instance methods). If not, you have the option of using respectively an exporting- and an importing parameter.
12-17-2018 3:57 PM
I believe, Creating a global attribute in class is a better solution then using ref in export import parameters. Preferably create a Private attribute in class is more meaningful in his case.
12-17-2018 8:00 PM
12-18-2018 11:39 AM
s1252 why do you think so?
I'd prefer to pass the objet, maybe as return parameter.
12-18-2018 12:04 PM
Hello s1252
Thanks for your response...
I can create lref as an attribute.. but how to pass that exporting parameters to that attribute..
i can't get it...
can you provide some sample codes...
thanks in advance...
12-18-2018 2:25 PM
If those are static methods , then we better go for import export parameters as Patrick Van Nierop suggested and add them in method signature exporting/returning parameters .
12-18-2018 9:52 AM
Hi Kabilarasan,
If your methods are static, then you can directly call that method by class name.
Click on pattern, and
Regards,
Rupesh