Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

dynamic selection

Former Member
0 Likes
1,212

how to do dynamic selection without using logical database.

ex-run the transaction s_alr_87099970, beside the execute button you will found a green colour button that is dynamic selection button.

somebody help me please.

4 REPLIES 4
Read only

former_member194669
Active Contributor
0 Likes
759

Hi,

You can use dynamic selection without LDB.

Pl take a look at the Std Report RKAEP000

aRs

Read only

0 Likes
759

The program you have given is not complete.It is not showing the o/p

doyou have any other programs,if have please sent it.

Read only

Former Member
0 Likes
759

Check the documentation of these FM's

FREE_SELECTIONS_INIT Initialize dynamic selection: Declare permitted tables ..

FREE_SELECTIONS_DIALOG Dialog for entering dynamic selection conditions

Read only

Former Member
0 Likes
759

Hi

Try to execute this.

*----------------------------------------------------------------------*
* Program Details                                                      *
*----------------------------------------------------------------------*
report  z_vik_dynamic_ss line-size  80
                         line-count 64
                         message-id zz
                         no standard page heading.
*----------------------------------------------------------------------*
* Tables                                                               *
*----------------------------------------------------------------------*

tables : sscrfields,                "Fields on selection screens
         dd03l.                     "Table Fields
*----------------------------------------------------------------------*
* Type Pools                                                           *
*----------------------------------------------------------------------*

type-pools:rsds.

*----------------------------------------------------------------------*
* Selection Screen                                                     *
*----------------------------------------------------------------------*

selection-screen : begin of block b1 with frame title text-001,
                   skip,
                   begin of line,
                   comment 1(5) text-002.
parameters : p_tab like dd03l-tabname obligatory.            "Table name
selection-screen : pushbutton 45(8) p_btn user-command clk,
"Select-options
                   end of line,
                   end of block b1.

*----------------------------------------------------------------------*
* Types                                                                *
*----------------------------------------------------------------------*

types: begin of t_dd03l,
        tabname like dd03l-tabname,              "Table Name
        fieldname like dd03l-fieldname,          "Field Name
        keyflag   like dd03l-keyflag,            "Key Flag
        rollname  like dd03l-rollname,           "Roll Name
        position like dd03l-position,            "Position
        ddtext(30),                              "Description
       end of t_dd03l,

       begin of t_fields.
        include structure dd03l.
types: end of t_fields.

types : begin of t_tabs.
"To hold the table names
        include structure rsdstabs.
types : end   of t_tabs.

types : begin of t_flds.
"To hold the field names
        include structure rsdsfields.
types : end   of t_flds.

types : begin of t_fname,
"To hold the field names
          fld like dd03l-fieldname,
        end of t_fname.

*----------------------------------------------------------------------*
* Internal Tables                                                      *
*----------------------------------------------------------------------*

data : it_dd03l   type table of t_dd03l,   "To hold the field names
       it_tabs    type table of t_tabs,    "To hold the table names
       it_flds    type table of t_flds,    "To hold the field names
       it_temp    type table of t_flds,
       "Temp. table to hold field names
       it_fields  type table of t_fields,  "To hold the field names
       it_cat     type table of lvc_s_fcat,"To hold Field Catalog
       it_fname   type table of t_fname.

*----------------------------------------------------------------------*
* Work areas                                                           *
*----------------------------------------------------------------------*

data: d_ref     type ref to data ,         "Data reference
      wa_dd03l  like line of it_dd03l,     "Workarea for IT_DD03L
      wa_tabs   like line of it_tabs,      "Workarea for IT_TABS
      wa_flds   like line of it_flds,      "Workarea for IT_FLDS
      wa_temp   like line of it_temp,      "Workarea for IT_TEMP
      wa_fields like line of it_fields,    "Workarea for IT_FIELDS
      wa_cat    like line of it_cat ,      "Workarea for IT_CAT
      wa_fname  like line of it_fname.     "Workarea for IT_FNAME

*----------------------------------------------------------------------*
* Field Symbols                                                        *
*----------------------------------------------------------------------*

field-symbols : <f_fs> type table.
"FieldSymbol for holding fields

*----------------------------------------------------------------------*
* Variables                                                            *
*----------------------------------------------------------------------*

data: gx_texpr            type rsds_texpr,
"Variable to hold Expression
      gx_twhere           type rsds_twhere,
      "Variable to hold Where Clause
      gv_selid            like rsdynsel-selid,  "Variable to hold Selid
      gv_actnum           like sy-tfill,
      "Variable to hold no of fields
      gv_title            like sy-title,        "Variable to hold Title
      gv_where_cl(100)    type c,
      "Variable to hold Where clause
      gv_tbname           like dd03l-tabname,
      gv_temp.

select-options:
  s_fld   for dd03l-fieldname no-display,       "To hold fields selected
  s_selop for dd03l-fieldname no-display,
  "To hold fields for creating dyn. select-options
  s_where for gv_where_cl no-display.           "To hold where condition

parameters: gv_t_old like dd03l-tabname no-display.
"Earlier Table name



data : gt_grid type ref to cl_gui_alv_grid,
       gt_cust type ref to cl_gui_custom_container,    "Custom Container
       cust type scrfname value 'CC_OUTPUT'.
       "Custom controller

*----------------------------------------------------------------------*
* Constants                                                            *
*----------------------------------------------------------------------*

constants: gc_i      type c value 'I',
           gc_eq(2)  type c value 'EQ'.

*----------------------------------------------------------------------*
* Initialization                                                       *
*----------------------------------------------------------------------*

initialization.
**--Initialize values
  perform initialize.

*----------------------------------------------------------------------*
* At Selection Screen                                                  *
*----------------------------------------------------------------------*

at selection-screen.
**--Select the fields of the input table
  perform select_flds.
*----------------------------------------------------------------------*
* Start Of Selection                                                   *
*----------------------------------------------------------------------*

start-of-selection.
**--Fetch data to display output
  perform fetch_data.

*----------------------------------------------------------------------*
* End Of Selection                                                     *
*----------------------------------------------------------------------*
end-of-selection.

  call screen '0300'.

*----------------------------------------------------------------------*
* At User Command                                                      *
*----------------------------------------------------------------------*
at user-command.

  case sy-ucomm.
    when 'OK'.
      refresh it_temp.
      clear it_temp.
      move 'S' to wa_temp-type.
      move gv_tbname to wa_temp-tablename.
      do.
        read line sy-index field value gv_temp into gv_temp.
        if sy-subrc ne 0.
          exit.
        endif.
        if gv_temp eq 'X'.
          sy-index = sy-index - 1.
          read table it_dd03l into wa_dd03l index sy-index.
          if sy-subrc = 0.
            move wa_dd03l-fieldname to wa_temp-fieldname.
            append wa_temp to it_temp.
            clear gv_temp.
          endif.
        endif.
      enddo.
      describe table it_temp.
      if sy-tfill gt 70.
**--More than 70 fields can not be selected
        message i001 with 'Cannot select more than 70 Parameters'(006).
        refresh it_temp[]. clear it_temp.
      else.
        leave list-processing.
      endif.
    when 'CANCEL'.
      leave list-processing.
    when 'SELALL'.
**--Select all fields
      clear wa_dd03l-fieldname.
      do.
        read line sy-index.
        if sy-subrc eq 0 and
           wa_dd03l-fieldname ne space.
          gv_temp = 'X'.
          modify line sy-index index 0 field value gv_temp.
          hide gv_temp.
          clear wa_dd03l-fieldname.
        elseif sy-subrc ne 0.
          exit.
        endif.
      enddo.
    when 'DSELALL'.
**--Deselect all fields
      clear gv_temp.
      do.
        read line sy-index.
        if sy-subrc eq 0.
          clear gv_temp.
          modify line sy-index index 0 field value gv_temp from gv_temp.
          hide gv_temp.
        elseif sy-subrc ne 0.
          exit.
        endif.
      enddo.
  endcase.
  sy-lsind = 0.

*&---------------------------------------------------------------------*
*&      Form  INITIALIZE
*&---------------------------------------------------------------------*
*       Initialize values on selection-screen
*----------------------------------------------------------------------*
form initialize .

  p_btn = 'Options'(003).

endform.                    " INITIALIZE
*&---------------------------------------------------------------------*
*&      Form  SELECT_FLDS
*&---------------------------------------------------------------------*
*       Select fields from the table
*----------------------------------------------------------------------*
form select_flds .

  case sscrfields-ucomm.
    when 'CLK'.
**--Display Screen with the list of fields
      perform genr_scr.
  endcase.

endform.                    " SELECT_FLDS
*&---------------------------------------------------------------------*
*&      Form  genr_scr
*&---------------------------------------------------------------------*
*       Display a screen with list of fields
*----------------------------------------------------------------------*
form genr_scr.

**--If table in the parameter is not the same as the old table and
**--old table is not blank, then initialise all the variables associated
  if p_tab ne gv_t_old and gv_t_old is not initial.
    refresh: it_tabs, it_flds,
             gx_texpr, gx_twhere,
             s_where, s_selop.
    clear: gv_selid.
**--Pass current table parameter value to Old table parameter
    gv_t_old = p_tab.
  endif.

**--Pass the current table name to old table variable
  if gv_t_old eq space.
    gv_t_old = p_tab.
  endif.

**--Check if table name is given before clicking the button
  if p_tab is initial.
    message e001 with 'Enter the Table name'(004).
  endif.

**--Get the list of fields of a given table
  perform get_selections.
**--If none of the fields, provide the list of fields for selecting
  if it_flds[] is initial.
    clear gv_selid.
    perform select_fieldlist.
  endif.

**--Show message if none of the fields are selected
  if it_flds[] is initial.
    message s001 with 'No parameters selected'(005).
    exit.
  endif.

**--Generate dynamic select-options
  refresh it_tabs.
  clear : it_tabs, wa_tabs.
  wa_tabs-prim_tab = p_tab.
  append wa_tabs to it_tabs.
  perform set_values.

**--Generate Expression from Where clause
  call function 'FREE_SELECTIONS_WHERE_2_EX'
    exporting
      where_clauses        = gx_twhere
    importing
      expressions          = gx_texpr
    exceptions
      incorrect_expression = 1
      others               = 2.
  if sy-subrc ne 0.
    message i001 with 'Error in Dynamic screen generation'(009).
    exit.
  endif.

  if gx_texpr is not initial.
**--Populate values to select-options from expression
    perform set_values.
  endif.

**--Display screen with the fields listed
  if gv_selid is not initial.
    perform call_screen.
  endif.
endform.                    " genr_scr
*&---------------------------------------------------------------------*
*&      Form  GET_SELECTIONS
*&---------------------------------------------------------------------*
*       Fetch the fields in the table given
*----------------------------------------------------------------------*

form get_selections.

  data : wa_where like line of gx_twhere.

  refresh: it_flds, gx_twhere.
  clear : wa_flds.

  wa_flds-tablename = p_tab.
  wa_flds-type = 'S'.

  loop at s_selop.
**--Populate all the fields selected that are previously selected
    wa_flds-fieldname = s_selop-low.
    append wa_flds to it_flds.
  endloop.
  if s_where[] is not initial.
**--Populate values to where condition if any data is previously given
**--to the dynamic select-options
    wa_where-tablename = p_tab.
    loop at s_where.
      append s_where-low to wa_where-where_tab.
    endloop.
    append wa_where to gx_twhere.
  endif.
endform.                    " GET_SELECTIONS
*&---------------------------------------------------------------------*
*&      Form  SELECT_FIELDLIST
*&---------------------------------------------------------------------*
*       Display the list of fields
*----------------------------------------------------------------------*
form select_fieldlist.

  clear: it_dd03l[], it_dd03l,
         gv_tbname.

**--Get field names for given table
  select tabname
         fieldname
         keyflag
         rollname
         position
    from dd03l
    into table it_dd03l
   where tabname eq p_tab
     and fieldname ne 'MANDT'.
  if sy-subrc = 0.
    sort it_dd03l by position.
    delete it_dd03l where fieldname cp '.INCLU*'.
  endif.

**--Get the description of the fields
  loop at it_dd03l into wa_dd03l.
    if not wa_dd03l-rollname is initial.
      select single ddtext
        from dd04t
        into wa_dd03l-ddtext
       where rollname eq wa_dd03l-rollname
         and ddlanguage = sy-langu
         and as4local = 'A'.
      modify it_dd03l from wa_dd03l.
    else.
      select single ddtext
        from dd03t
        into wa_dd03l-ddtext
       where tabname eq wa_dd03l-tabname
         and ddlanguage = sy-langu
         and as4local = 'A'
         and fieldname = wa_dd03l-fieldname.
      modify it_dd03l from wa_dd03l.
    endif.

  endloop.

  gv_tbname = p_tab.
**--Display screen with the fields listed for the given table
  call screen 200 starting at 10 2
               ending at 70 22.

**--Clear all the fields selected
  clear : it_flds, it_flds[], gv_tbname.

**--Populate the newly selected fields
  it_flds[] = it_temp[].

**--Clear temporary table with the fields selected
  clear : it_temp, it_temp[].
endform.                    " SELECT_FIELDLIST
*&---------------------------------------------------------------------*
*&      Form  INITIALIZE_SCREEN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form initialize_screen.
  call function 'FREE_SELECTIONS_INIT'
    exporting
      kind                     = 'T'
      expressions              = gx_texpr
    importing
      selection_id             = gv_selid
      number_of_active_fields  = gv_actnum
    tables
      tables_tab               = it_tabs
      fields_tab               = it_flds
    exceptions
      fields_incomplete        = 01
      fields_no_join           = 02
      field_not_found          = 03
      no_tables                = 04
      table_not_found          = 05
      expression_not_supported = 06
      incorrect_expression     = 07
      illegal_kind             = 08
      area_not_found           = 09
      inconsistent_area        = 10
      kind_f_no_fields_left    = 11
      kind_f_no_fields         = 12
      too_many_fields          = 13.

endform.                    " INITIALIZE_SCREEN
*&---------------------------------------------------------------------*
*&      Form  SET_VALUES
*&---------------------------------------------------------------------*
*       Set the values to the select-options
*----------------------------------------------------------------------*
form set_values.

  call function 'FREE_SELECTIONS_INIT'
    exporting
      kind                     = 'T'
      expressions              = gx_texpr
    importing
      selection_id             = gv_selid
      number_of_active_fields  = gv_actnum
    tables
      tables_tab               = it_tabs
      fields_tab               = it_flds
    exceptions
      fields_incomplete        = 01
      fields_no_join           = 02
      field_not_found          = 03
      no_tables                = 04
      table_not_found          = 05
      expression_not_supported = 06
      incorrect_expression     = 07
      illegal_kind             = 08
      area_not_found           = 09
      inconsistent_area        = 10
      kind_f_no_fields_left    = 11
      kind_f_no_fields         = 12
      too_many_fields          = 13.
endform.                    " SET_VALUES
*&---------------------------------------------------------------------*
*&      Form  CALL_SCREEN
*&---------------------------------------------------------------------*
*       Call the screen to display the fields
*----------------------------------------------------------------------*
form call_screen.

  data : wa_where like line of gx_twhere,
         lv_txt type string.

  lv_txt = 'Dynamic Selections Parameters for'(007).
  concatenate lv_txt p_tab
         into gv_title separated by space.

  call function 'FREE_SELECTIONS_DIALOG'
    exporting
      selection_id            = gv_selid
      title                   = gv_title
      tree_visible            = ' '
    importing
      where_clauses           = gx_twhere
      expressions             = gx_texpr
      number_of_active_fields = gv_actnum
    tables
      fields_tab              = it_flds
    exceptions
      internal_error          = 01
      no_action               = 02
      no_fields_selected      = 03
      no_tables_selected      = 04
      selid_not_found         = 05.
  if sy-subrc eq 0.
    refresh: s_where, s_selop.
**--Populate the Where clause with selected values
    s_where-sign = gc_i.
    s_where-option = gc_eq.
    clear wa_where.
    read table gx_twhere index 1 into wa_where.
    loop at wa_where-where_tab into s_where-low.
      append s_where.
    endloop.
**--Populate all the fields
    s_selop-sign = gc_i.
    s_selop-option = gc_eq.
    clear : wa_flds.
    loop at it_flds into wa_flds.
      s_selop-low = wa_flds-fieldname.
      append s_selop.
    endloop.
  endif.

endform.                    " CALL_SCREEN
*&---------------------------------------------------------------------*
*&      Module  STATUS_0200  OUTPUT
*&---------------------------------------------------------------------*
*       Display screen with select-options
*----------------------------------------------------------------------*
module status_0200 output.

  data: lv_txt type string.

  lv_txt = 'Selection Paramters List'(008).
  set pf-status 'DIALOG'.

  leave to list-processing and return to screen 0.
  suppress dialog.
  move lv_txt to sy-title.
**--display list of fields that can be selected for creating dynamic
*select-options
  loop at it_dd03l into wa_dd03l.
    at first.
      write: (60) sy-uline.
    endat.
    read table it_flds into wa_flds with key fieldname =
    wa_dd03l-fieldname.
    if sy-subrc ne 0.
      clear gv_temp.
    else.
      gv_temp = 'X'.
    endif.
    write:/ '|' ,gv_temp as checkbox.
    write:  (20) wa_dd03l-fieldname,'|', wa_dd03l-ddtext, at 60 '|'.
    hide: gv_temp, wa_dd03l-fieldname, wa_dd03l-keyflag.
    at last.
      write: (60) sy-uline.
    endat.
  endloop.
endmodule.                 " STATUS_0200  OUTPUT
*&---------------------------------------------------------------------*
*&      Form  FETCH_DATA
*&---------------------------------------------------------------------*
*       Fetch data from table
*----------------------------------------------------------------------*
form fetch_data .

  data: lv_where type string,
        lv_cnt   type i.

**--Check for the existance of the table
  select *
    from dd03l
    into table it_fields
    where tabname = p_tab.

  sort it_fields by position.
**--Delete the fields starting with .INCLU
  delete it_fields where fieldname cp '.INCLU*'.

**--Display the first 150 fields of the table
  loop at it_fields into wa_fields to 150.
    lv_cnt = lv_cnt + 1.
    wa_cat-tabname = p_tab.
    wa_cat-fieldname = wa_fields-fieldname.
    wa_cat-col_pos = lv_cnt.
    wa_cat-inttype    = wa_fields-inttype.
    wa_cat-datatype = wa_fields-datatype.
    wa_cat-intlen = wa_fields-intlen.
    wa_cat-seltext = wa_fields-fieldname.
    wa_cat-decimals = wa_fields-decimals.
    wa_cat-ref_field = wa_fields-fieldname.
    wa_cat-ref_table = p_tab.
    append wa_cat to it_cat.
    clear wa_cat.

    wa_fname-fld = wa_fields-fieldname.
    append wa_fname to it_fname.
    clear wa_fname.
  endloop.

**--Create a dynamic internal table with the 150 fields
  call method cl_alv_table_create=>create_dynamic_table
    exporting
      it_fieldcatalog = it_cat
    importing
      ep_table        = d_ref.

  assign d_ref->* to <f_fs>.

**--Populate the Where clause as a string
  loop at s_where.
    concatenate lv_where s_where-low into lv_where separated by space.
  endloop.

**--Select the data from the table given as input and populate
**--it into the dynamic internal table created based on the where
*condition
  select (it_fname)
    from (p_tab)
    into corresponding fields of table <f_fs>
   where (lv_where).
**--If no entries are found that satisfies the selection criteria
  if sy-subrc <> 0.
    message i000(zz) with 'No data found'(010).
  endif.


endform.                    " FETCH_DATA
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_DATA
*&---------------------------------------------------------------------*
*       Display data in the grid control
*----------------------------------------------------------------------*
form display_data .

  if gt_cust is initial.
    create object gt_cust
      exporting
        container_name              = cust      .
    create object gt_grid
      exporting
        i_parent          = gt_cust.

**--Display the data in the grid control

    call method gt_grid->set_table_for_first_display
      exporting
        i_buffer_active               = 'X'
        i_bypassing_buffer            = ' '
*      I_CONSISTENCY_CHECK           =
*      I_STRUCTURE_NAME              =
*      IS_VARIANT                    =
*      I_SAVE                        =
*      I_DEFAULT                     = 'X'
*      IS_LAYOUT                     =
*      IS_PRINT                      =
*      IT_SPECIAL_GROUPS             =
*      IT_TOOLBAR_EXCLUDING          =
*      IT_HYPERLINK                  =
*      IT_ALV_GRAPHICS               =
*      IT_EXCEPT_QINFO               =
*      IR_SALV_ADAPTER               =
      changing
        it_outtab                     = <f_fs>
        it_fieldcatalog               = it_cat
*      IT_SORT                       =
*      IT_FILTER                     =
      exceptions
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 3
        others                        = 4
            .
    if sy-subrc <> 0.
    endif.
  endif.

endform.                    " DISPLAY_DATA
*&---------------------------------------------------------------------*
*&      Module  DISPLAY_DATA  OUTPUT
*&---------------------------------------------------------------------*
*       Dispaly data in the output
*----------------------------------------------------------------------*
module display_data output.
  perform display_data.
endmodule.                 " DISPLAY_DATA  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  STATUS_0300  OUTPUT
*&---------------------------------------------------------------------*
*       Pf-status for the screen
*----------------------------------------------------------------------*
module status_0300 output.
  set pf-status '13317'.
endmodule.                 " STATUS_0300  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0300  INPUT
*&---------------------------------------------------------------------*
*       Handling the button clicks
*----------------------------------------------------------------------*
module user_command_0300 input.

  case sy-ucomm.
**--Go to the previous screen
    when 'BACK'.
      leave to screen 0.
**--Come out of the program
    when 'EXIT'.
      leave program.
  endcase.
endmodule.                 " USER_COMMAND_0300  INPUT

Thanks

Vikranth KHimavath