‎2009 Jul 25 11:25 AM
My requirement is
CLASS lcl_alv_new IMPLEMENTATION.
METHOD set_columns.
DATA: ref_column TYPE REF TO cl_salv_column.
DATA: ls_color TYPE lvc_s_colo.
PERFORM build_fcat USING
c_neu_tissue_desc_f text-019.
ENDMETHOD. "on_user_command
ENDCLASS. "lcl_alv_new IMPLEMENTATION
FORM build_fcat USING p_fname TYPE lvc_fname
p_ftext TYPE scrtext_l.
TRY.
ref_column = me->lref_columns->get_column( c_neu_tissue_desc_f ).
CATCH cx_salv_not_found INTO ref_error.
w_msg = ref_error->get_text( ).
MESSAGE w_msg TYPE 'I'.
ENDTRY.
ref_column->set_long_text( text-019 ).
ENDFORM. " BUILD_FCAT
I am getting following errors:
1)Field "ME" is unknown. It is neither in one of the specified tables nor defined by a "DATA" statement. .
2)Field "REF_COLUMN" is unknown. It is neither in one of the specified tables nor defined by a "DATA" statement.
3)Field "REF_COLUMN" is unknown. It is neither in one of the specified tables nor defined by a "DATA" statement. .
Can any one tell how to write this perform " PERFORM build_fcat USING
c_neu_tissue_desc_f text-019." in Method and End Method. Thanks Ravi
‎2009 Jul 25 11:37 AM
Hi,
You cannot use PERFORM of FORM..ENDFORM statements in the class methods.... either you can call methods or Function Modules.
‎2009 Jul 25 11:38 AM
Hi,
Sure you can, althought it would be recommended to implement it in a method.
You get this errors because outside method/class (in your form) reference to ALV is no longer accessible. The same applies to REF_COLUMN. This is beacuse within class data are encapulated , which means are not visible outside unless it is explicitly defined as such (public section).
You can use two approaches:
1) pass reference me and column reference to form
FORM build_fcat USING p_fname TYPE lvc_fname
p_ftext TYPE scrtext_l
me type ref to "here goes name of your class where method is implemented
ref_column type ref to cl_salv_column.
TRY.
ref_column = me->lref_columns->get_column( c_neu_tissue_desc_f ). "now you can access it
CATCH cx_salv_not_found INTO ref_error.
w_msg = ref_error->get_text( ).
MESSAGE w_msg TYPE 'I'.
ENDTRY.
ref_column->set_long_text( text-019 ). "now you can access it
ENDFORM. " BUILD_FCAT
"Now you can call it like
perform build_fcat using .... me ref_column.
2) implement it in class - this is highly recommened as data stay encapsulated within class bounds
"class definition
data: ref_column TYPE REF TO cl_salv_column. "ref column must be declared as ATTRIBUTE of class in order each method of that class can access it without passing it as parameter
method build_fcat USING p_fname TYPE lvc_fname
p_ftext TYPE scrtext_l. "you now longer have to pass ME neither REF_COLUMN as it is automatically visible in method
"implementation
method buid_fcat.
TRY.
ref_column = me->lref_columns->get_column( c_neu_tissue_desc_f ). "here you are addressing attribute of a class
CATCH cx_salv_not_found INTO ref_error.
w_msg = ref_error->get_text( ).
MESSAGE w_msg TYPE 'I'.
ENDTRY.
ref_column->set_long_text( text-019 ). "same here
enmethod.
Regards
Marcin
Please note!
Form cannot be defined within class, it must be outside it, that's why you violate encapsulation rules. Method, on the other hand, is defined within CLASS .... ENDCLASS
Edited by: Marcin Pciak on Jul 25, 2009 12:39 PM
‎2009 Jul 25 12:50 PM
Hi,
Instead use Macro, define and use them.
Example
*---------------------------------------------------------------*
* Data declaration
*---------------------------------------------------------------*
DATA: lt_bdcdata TYPE TABLE OF bdcdata, " Internal table for BDCDATA
ls_bdcdata TYPE bdcdata. " Work area for BDCDATA
*---------------------------------------------------------------*
* Macro declaration for BDCDATA
*---------------------------------------------------------------*
DEFINE bdc_.
clear ls_bdcdata.
if &3 is initial.
ls_bdcdata-fnam = &1.
ls_bdcdata-fval = &2.
else.
ls_bdcdata-program = &1.
ls_bdcdata-dynpro = &2.
ls_bdcdata-dynbegin = &3.
endif.
append ls_bdcdata to lt_bdcdata.
END-OF-DEFINITION.
* Screen '0300'
bdc_ 'SAPMM06E' '0300' 'X'.
bdc_ 'BDC_CURSOR' 'EKKO-ANGDT' ' '.
bdc_ 'BDC_OKCODE' '=KOPF' ' '.
bdc_ 'RM06E-ASART' ls_impcluster-rfq_type ' '.
bdc_ 'EKKO-SPRAS' 'EN' ' '.
bdc_ 'RM06E-ANFDT' l_date ' '.
.
.
.Regards
Bala Krishna