‎2007 Jul 12 5:50 AM
Hi,
I want to create a method and pass a select-option to it. How to declare the parameter for this method.
regards,
Navneeth K.
‎2007 Jul 12 7:14 AM
Hello Navneeth
If you have just a single select-option you can define an IMPORTING parameter (e.g. IT_SELOPT) of table type <b>RSELOPTION</b>. This table type has RSDSSELOPT (<i>Structure of generic SELECT-OPTION for (dynamic selections)</i>) as line type.
However, if you have multiple select-options (and parameters as well) then the easiest (and probably most elegant) way is to use function module <b>RS_REFRESH_FROM_SELECTOPTIONS</b>.
In the CONSTRUCTOR method of your class you add an EXPORTING parameter IM_CALLING_PROGRAM.
Within the CONSTRUCTOR method you call the function module with the value of the calling program (which is your selection report). The function module returns you all current selection criteria of the report.
Have a look at class <b>CL_DBSEL_CATS</b> for a SAP standard example.
Regards
Uwe
‎2007 Jul 12 5:55 AM
Define a table type for the structure SELOPT and declare the parameter as a type of this table type.
Manoj
‎2007 Jul 12 7:14 AM
Hello Navneeth
If you have just a single select-option you can define an IMPORTING parameter (e.g. IT_SELOPT) of table type <b>RSELOPTION</b>. This table type has RSDSSELOPT (<i>Structure of generic SELECT-OPTION for (dynamic selections)</i>) as line type.
However, if you have multiple select-options (and parameters as well) then the easiest (and probably most elegant) way is to use function module <b>RS_REFRESH_FROM_SELECTOPTIONS</b>.
In the CONSTRUCTOR method of your class you add an EXPORTING parameter IM_CALLING_PROGRAM.
Within the CONSTRUCTOR method you call the function module with the value of the calling program (which is your selection report). The function module returns you all current selection criteria of the report.
Have a look at class <b>CL_DBSEL_CATS</b> for a SAP standard example.
Regards
Uwe
‎2007 Jul 12 7:34 AM
Hi Uwe can you provide some standard examples using the standard classes and methods. Also if possible provide me some demo report programs which makes use of the standard classes. (For example the link u had provided me earlier for creating ALV using standard class and objects ). Same way some examples of how to efficiently use the standard available ABAP Classes.
thanks,
Navneeth K.
‎2007 Jul 12 3:34 PM
Hello Navneeth
Sorry for the delay (I could not reply in the morning).
However, here is a sample report showing how class <b>CL_DBSEL_CATS</b> can be used to select CATSDB data. The select-options are transferred via <b>sy-repid</b> to the class.
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_ALV_CATSDB_SELECT
*&
*&---------------------------------------------------------------------*
*&
*& Screen '0100' contains no elements. ok_code -> assigned to GD_OKCODE
*&
*& Flow logic of screen '0100':
*&
*& PROCESS BEFORE OUTPUT.
*& MODULE STATUS_0100.
*&*
*& PROCESS AFTER INPUT.
*& MODULE USER_COMMAND_0100.
*&---------------------------------------------------------------------*
*& Description: Transfer select-options from selection screen into
*& method via sy-repid
*&
*&---------------------------------------------------------------------*
REPORT zus_sdn_alv_catsdb_select.
TABLES: catsdb.
CONSTANTS:
gc_tabname TYPE tabname VALUE 'CATSDB_EXT'.
DATA:
gd_okcode TYPE ui_func,
gd_repid TYPE syrepid,
gd_rejected TYPE catsxt_reject_count,
gd_rejected_n(6) TYPE n,
*
gt_fcat TYPE lvc_t_fcat,
gs_layout TYPE lvc_s_layo,
gs_variant TYPE disvariant,
*
go_docking TYPE REF TO cl_gui_docking_container,
go_grid TYPE REF TO cl_gui_alv_grid.
DATA:
go_cats TYPE REF TO cl_dbsel_cats.
DATA:
gt_outtab TYPE catsdb_ext_itab.
" NOTE: select-options MUST have the same names as defined in
" instance attribute SELCRIT (of class CL_DBSEL_CATS)
SELECT-OPTIONS:
ldbpernr FOR catsdb-pernr,
ldblgart FOR catsdb-lgart,
ldblstar FOR catsdb-lstar DEFAULT '1410' TO '1412'
SIGN i OPTION bt.
*---------------------------------------------------------------------*
* CLASS lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING
e_row
e_column
es_row_no
sender. " grid instance that raised the event
PRIVATE SECTION.
CLASS-DATA:
ms_outtab LIKE LINE OF gt_outtab.
ENDCLASS. "lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_eventhandler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_double_click.
* define local data
DATA:
ls_col_id TYPE lvc_s_col.
READ TABLE gt_outtab INTO ms_outtab INDEX e_row-index.
CHECK ( syst-subrc = 0 ).
CASE e_column-fieldname.
WHEN 'PERNR'.
** SET PARAMETER ID 'KUN' FIELD ms_outtab-pernr.
** SET PARAMETER ID 'BUK' FIELD ms_outtab-bukrs.
** CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.
WHEN OTHERS.
* do nothing
ENDCASE.
ENDMETHOD. "handle_double_click
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
gd_repid = syst-repid.
" Create instance for selecting CATSDB data
CREATE OBJECT go_cats
EXPORTING
im_calling_program = gd_repid " <= 'import' of select-options !!!
* IM_AUTHORITY_CHECK_TYPE = 'R'
* IM_FIELD_SELECTION =
* IM_SELECTION_CRITERIA =
* IM_FREE_SELECTIONS =
* IM_BADI =
.
" Select records from CATSDB -> uses select-options from current report
CALL METHOD go_cats->get_time_sheet_data
* EXPORTING
* IM_PERSONNEL_NUMBER_TAB =
IMPORTING
ex_cats_data = gt_outtab
* EX_CATSXT_DATA =
* EX_DOCFLOW =
.
gd_rejected = go_cats->get_reject_count( ).
IF ( gd_rejected > 0 ).
WRITE gd_rejected TO gd_rejected_n NO-ZERO.
CONDENSE gd_rejected_n NO-GAPS.
MESSAGE i398(00) WITH 'Rejected records =' gd_rejected_n ' ' ' '.
ENDIF.
DESCRIBE TABLE gt_outtab.
WRITE syst-tfill TO gd_rejected_n NO-ZERO.
CONDENSE gd_rejected_n NO-GAPS.
MESSAGE s398(00) WITH 'Selected records =' gd_rejected_n ' ' ' '.
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
OTHERS = 6.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Create ALV grid
CREATE OBJECT go_grid
EXPORTING
i_parent = go_docking
EXCEPTIONS
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Set event handler
SET HANDLER:
lcl_eventhandler=>handle_double_click FOR go_grid.
* Build fieldcatalog
PERFORM build_fieldcatalog.
PERFORM set_layout_and_variant.
* Display data
CALL METHOD go_grid->set_table_for_first_display
EXPORTING
is_layout = gs_layout
is_variant = gs_variant
i_save = 'A'
CHANGING
it_outtab = gt_outtab
it_fieldcatalog = gt_fcat
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Link the docking container to the target dynpro
CALL METHOD go_docking->link
EXPORTING
repid = syst-repid
dynnr = '0100'
* CONTAINER =
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* ok-code field = GD_OKCODE
CALL SCREEN '0100'.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE gd_okcode.
WHEN 'BACK' OR
'EXIT' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG_KNB1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_fieldcatalog.
* define local data
DATA:
ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = gc_tabname
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form SET_LAYOUT_AND_VARIANT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM set_layout_and_variant .
CLEAR: gs_layout,
gs_variant.
gs_layout-zebra = abap_true.
gs_layout-cwidth_opt = abap_true.
gs_variant-report = syst-repid.
gs_variant-handle = 'GRID'.
ENDFORM. " SET_LAYOUT_AND_VARIANTRegards
Uwe
‎2007 Aug 08 6:36 PM
Hi..
i know that your question has been answered already but I have another approach. I think this one is bit cleaner and much more explicit. use TYPE RANGE OF. This way your internal table is an EXPLICITLY TYPED range. Hope this helps.
CLASS test DEFINITION.
PUBLIC SECTION.
TYPES:
t_it_matnr TYPE RANGE OF matnr.
METHODS:
Constructor IMPORTING p_it_matnr TYPE t_it_matnr.
ENDCLASS.
CLASS test IMPLEMENTATION.
METHOD Constructor.
ENDMETHOD.
ENDCLASS.
DATA: screen_matnr TYPE matnr,
g_test TYPE REF TO test.
SELECT-OPTIONS: s_matnr FOR screen_matnr.
START-OF-SELECTION.
CREATE OBJECT g_test EXPORTING p_it_matnr = s_matnr[].