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 select

Former Member
0 Likes
728

hi to all,

        i am working in the dynamic select scenario. i want to select the fieldnames  from the tables dynamically using report editor as per the requirement as new to abap can some one please help me out and also kindly mention the table name for example DD03L.

Thanks,

Devi

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
696

Hi priya,

Hope this code help you..

type-pools : slis.

data : it_tab  type table of dd03l,

      ls_tab  like line of it_tab.

data: fieldcatalog type slis_t_fieldcat_alv with header line,

      gd_layout    type slis_layout_alv,

      gd_repid     like sy-repid,

      g_exit type c,

      ispfli type table of spfli.

parameters :

tabnm type dd03l-tabname,

            fieldnm type dd03l-fieldname,

            local   type dd03l-as4local,

            vers  type dd03l-as4vers,

            pos    type dd03l-position.

data l_where(100) occurs 0 with header line.

start-of-selection.

  perform data_retrivel.

  perform build_fieldcatalog.

  perform display_alv_report.

form build_fieldcatalog .

  fieldcatalog-fieldname   = 'TABNAME'.

  fieldcatalog-seltext_m   = 'Tabname'.

  fieldcatalog-col_pos     = 0.

  append fieldcatalog to fieldcatalog.

  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'FIELDNAME'.

  fieldcatalog-seltext_m   = 'Fieldname'.

  fieldcatalog-col_pos     = 1.

  append fieldcatalog to fieldcatalog.

  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'AS4LOCAL'.

  fieldcatalog-seltext_m   = 'aslocal'.

  fieldcatalog-col_pos     = 2.

  append fieldcatalog to fieldcatalog.

  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'AS4VERS'.

  fieldcatalog-seltext_m   = 'asvers'.

  fieldcatalog-col_pos     = 3.

  fieldcatalog-outputlen   = 20.

  append fieldcatalog to fieldcatalog.

  clear  fieldcatalog.

   fieldcatalog-fieldname   = 'POSITION'.

  fieldcatalog-seltext_m   = 'SIGN IN'.

  fieldcatalog-col_pos     = 4.

  fieldcatalog-outputlen   = 20.

  append fieldcatalog to fieldcatalog.

  clear  fieldcatalog.

endform.                    " BUILD_FIELDCATALOG

form display_alv_report .

  gd_repid = sy-repid.

  call function 'REUSE_ALV_GRID_DISPLAY'

    exporting

      i_callback_program      = gd_repid

      i_callback_top_of_page  = 'TOP-OF-PAGE'  "see FORM

      i_callback_user_command = 'USER_COMMAND'

      it_fieldcat             = fieldcatalog[]

      i_save                  = 'X'

*      IS_VARIANT              = G_VARIANT

    tables

      t_outtab                = it_tab

    exceptions

      program_error           = 1

      others                  = 2.

  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.                    "DISPLAY_ALV_REPORT

form data_retrivel .

  if tabnm is not initial.

append 'TABNAME =tabnm' to l_where.

endif.

if fieldnm is not initial.

  if l_where is initial.

    append ' and ' to l_where.

  endif.

  append 'FIELDNAME = fieldnm' to l_where.

endif.

if local is not initial.

  if l_where is initial.

    append ' and ' to l_where.

  endif.

  append 'AS4LOCAL = local' to l_where.

endif.

if vers is not initial.

  if l_where is initial.

    append ' and ' to l_where.

  endif.

  append 'AS4VERS = vers' to l_where.

endif.

if pos is not initial.

  if l_where is initial.

    append ' and ' to l_where.

  endif.

  append 'POSITION = pos' to l_where.

endif.

select * from dd03l into corresponding fields of table it_tab

where (l_where).

endform.                    " DATA_RETRIVEL

form top-of-page.

*ALV Header declarations

  data: t_header type slis_t_listheader,

        wa_header type slis_listheader,

        t_line like wa_header-info,

        ld_lines type i,

        ld_linesc(10) type c.

* Title

  wa_header-typ  = 'H'.

  wa_header-info = 'Z  report'.

  append wa_header to t_header.

  clear wa_header.

* Date

  wa_header-typ  = 'S'.

  wa_header-key = 'Date: '.

  concatenate  sy-datum+6(2) '.'

               sy-datum+4(2) '.'

               sy-datum(4) into wa_header-info.   "todays date

  append wa_header to t_header.

  clear: wa_header.

  call function 'REUSE_ALV_COMMENTARY_WRITE'

    exporting

      it_list_commentary = t_header.

endform.                    "top-of-page

Regards ,

Niraj

5 REPLIES 5
Read only

former_member202818
Active Contributor
0 Likes
696

Hi devi,

Try this,

data : it_fields type table of fieldname.

append required field names into it_fields.

Now use it_fields in select query.

Select (it_fields) from ...etc...

regards

Sreekanth

Read only

Former Member
0 Likes
696

Hi Devi,

     Use FM

Thanks & Regards,

tashi

Read only

Former Member
0 Likes
697

Hi priya,

Hope this code help you..

type-pools : slis.

data : it_tab  type table of dd03l,

      ls_tab  like line of it_tab.

data: fieldcatalog type slis_t_fieldcat_alv with header line,

      gd_layout    type slis_layout_alv,

      gd_repid     like sy-repid,

      g_exit type c,

      ispfli type table of spfli.

parameters :

tabnm type dd03l-tabname,

            fieldnm type dd03l-fieldname,

            local   type dd03l-as4local,

            vers  type dd03l-as4vers,

            pos    type dd03l-position.

data l_where(100) occurs 0 with header line.

start-of-selection.

  perform data_retrivel.

  perform build_fieldcatalog.

  perform display_alv_report.

form build_fieldcatalog .

  fieldcatalog-fieldname   = 'TABNAME'.

  fieldcatalog-seltext_m   = 'Tabname'.

  fieldcatalog-col_pos     = 0.

  append fieldcatalog to fieldcatalog.

  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'FIELDNAME'.

  fieldcatalog-seltext_m   = 'Fieldname'.

  fieldcatalog-col_pos     = 1.

  append fieldcatalog to fieldcatalog.

  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'AS4LOCAL'.

  fieldcatalog-seltext_m   = 'aslocal'.

  fieldcatalog-col_pos     = 2.

  append fieldcatalog to fieldcatalog.

  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'AS4VERS'.

  fieldcatalog-seltext_m   = 'asvers'.

  fieldcatalog-col_pos     = 3.

  fieldcatalog-outputlen   = 20.

  append fieldcatalog to fieldcatalog.

  clear  fieldcatalog.

   fieldcatalog-fieldname   = 'POSITION'.

  fieldcatalog-seltext_m   = 'SIGN IN'.

  fieldcatalog-col_pos     = 4.

  fieldcatalog-outputlen   = 20.

  append fieldcatalog to fieldcatalog.

  clear  fieldcatalog.

endform.                    " BUILD_FIELDCATALOG

form display_alv_report .

  gd_repid = sy-repid.

  call function 'REUSE_ALV_GRID_DISPLAY'

    exporting

      i_callback_program      = gd_repid

      i_callback_top_of_page  = 'TOP-OF-PAGE'  "see FORM

      i_callback_user_command = 'USER_COMMAND'

      it_fieldcat             = fieldcatalog[]

      i_save                  = 'X'

*      IS_VARIANT              = G_VARIANT

    tables

      t_outtab                = it_tab

    exceptions

      program_error           = 1

      others                  = 2.

  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.                    "DISPLAY_ALV_REPORT

form data_retrivel .

  if tabnm is not initial.

append 'TABNAME =tabnm' to l_where.

endif.

if fieldnm is not initial.

  if l_where is initial.

    append ' and ' to l_where.

  endif.

  append 'FIELDNAME = fieldnm' to l_where.

endif.

if local is not initial.

  if l_where is initial.

    append ' and ' to l_where.

  endif.

  append 'AS4LOCAL = local' to l_where.

endif.

if vers is not initial.

  if l_where is initial.

    append ' and ' to l_where.

  endif.

  append 'AS4VERS = vers' to l_where.

endif.

if pos is not initial.

  if l_where is initial.

    append ' and ' to l_where.

  endif.

  append 'POSITION = pos' to l_where.

endif.

select * from dd03l into corresponding fields of table it_tab

where (l_where).

endform.                    " DATA_RETRIVEL

form top-of-page.

*ALV Header declarations

  data: t_header type slis_t_listheader,

        wa_header type slis_listheader,

        t_line like wa_header-info,

        ld_lines type i,

        ld_linesc(10) type c.

* Title

  wa_header-typ  = 'H'.

  wa_header-info = 'Z  report'.

  append wa_header to t_header.

  clear wa_header.

* Date

  wa_header-typ  = 'S'.

  wa_header-key = 'Date: '.

  concatenate  sy-datum+6(2) '.'

               sy-datum+4(2) '.'

               sy-datum(4) into wa_header-info.   "todays date

  append wa_header to t_header.

  clear: wa_header.

  call function 'REUSE_ALV_COMMENTARY_WRITE'

    exporting

      it_list_commentary = t_header.

endform.                    "top-of-page

Regards ,

Niraj

Read only

0 Likes
696

hi niraj,

i undestand the logic that u are appending fields in ITAB. the problem is the coding is showing dump error in the select statement  the error analysis displaying error in RSQL statement.

Thanks,

Priya

Read only

0 Likes
696

Hi priya...

I am sure about its may help you....please mention if you solve your questions..

REPORT  ZNKS_TEST19.

*TABLES : SFLIGHT.

type-pools : slis.

data : it_tab  type table of SFLIGHT,

      wa_tab  like line of it_tab.

data: fieldcatalog type slis_t_fieldcat_alv with header line,

      gd_layout    type slis_layout_alv,

      gd_repid     like sy-repid,

      g_exit type c,

      ispfli type table of spfli.

parameters :

            carrid  type SFLIGHT-CARRID,

            connid  type SFLIGHT-CONNID,

            date  type SFLIGHT-FLDATE,

            price  type SFLIGHT-PRICE.

data l_where(100) occurs 0 with header line.

start-of-selection.

  perform data_retrivel.

  perform build_fieldcatalog.

  perform display_alv_report.

form build_fieldcatalog .

  fieldcatalog-fieldname   = 'CARRID'.

  fieldcatalog-seltext_m   = 'carrid'.

  fieldcatalog-col_pos     = 0.

  append fieldcatalog to fieldcatalog.

  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'CONNID'.

  fieldcatalog-seltext_m   = 'connid'.

  fieldcatalog-col_pos     = 1.

  append fieldcatalog to fieldcatalog.

  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'FLDATE'.

  fieldcatalog-seltext_m   = 'date'.

  fieldcatalog-col_pos     = 2.

  append fieldcatalog to fieldcatalog.

  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'PRICE'.

  fieldcatalog-seltext_m   = 'price'.

  fieldcatalog-col_pos     = 3.

  fieldcatalog-outputlen   = 20.

  append fieldcatalog to fieldcatalog.

  clear  fieldcatalog.

   fieldcatalog-fieldname   = 'CURRENCY'.

  fieldcatalog-seltext_m   = 'currency'.

  fieldcatalog-col_pos     = 4.

  fieldcatalog-outputlen   = 20.

  append fieldcatalog to fieldcatalog.

  clear  fieldcatalog.

   fieldcatalog-fieldname   = 'PLANETYPE'.

  fieldcatalog-seltext_m   = 'planetype'.

  fieldcatalog-col_pos     = 5.

  fieldcatalog-outputlen   = 20.

  append fieldcatalog to fieldcatalog.

  clear  fieldcatalog.

endform.                    " BUILD_FIELDCATALOG

form display_alv_report .

  gd_repid = sy-repid.

  call function 'REUSE_ALV_GRID_DISPLAY'

    exporting

      i_callback_program      = gd_repid

      i_callback_top_of_page  = 'TOP-OF-PAGE'  "see FORM

      i_callback_user_command = 'USER_COMMAND'

      it_fieldcat             = fieldcatalog[]

      i_save                  = 'X'

*      IS_VARIANT              = G_VARIANT

    tables

      t_outtab                = it_tab

    exceptions

      program_error           = 1

      others                  = 2.

  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.                    "DISPLAY_ALV_REPORT

form data_retrivel .

  if carrid is not initial.

append 'CARRID = carrid' to l_where.

endif.

if connid  is not initial.

  if l_where is initial.

    append ' and ' to l_where.

  endif.

  append 'CONNID = connid' to l_where.

endif.

if date  is not initial.

  if l_where is initial.

    append ' and ' to l_where.

  endif.

  append 'FLDATE = date' to l_where.

endif.

if price is not initial.

  if l_where is initial.

    append ' and ' to l_where.

  endif.

  append 'PRICE = price' to l_where.

endif.

select * from sflight into corresponding fields of table it_tab

where (l_where).

endform.                    " DATA_RETRIVEL

form top-of-page.

*ALV Header declarations

  data: t_header type slis_t_listheader,

        wa_header type slis_listheader,

        t_line like wa_header-info,

        ld_lines type i,

        ld_linesc(10) type c.

* Title

  wa_header-typ  = 'H'.

  wa_header-info = 'Z  report'.

  append wa_header to t_header.

  clear wa_header.

* Date

  wa_header-typ  = 'S'.

  wa_header-key = 'Date: '.

  concatenate  sy-datum+6(2) '.'

               sy-datum+4(2) '.'

               sy-datum(4) into wa_header-info.   "todays date

  append wa_header to t_header.

  clear: wa_header.

  call function 'REUSE_ALV_COMMENTARY_WRITE'

    exporting

      it_list_commentary = t_header.

endform.    

// Dynamic Selection

Thanks and Regards ,

Niraj Sinha