08-02-2008 5:24 AM
Hai! Experts!
i want to get a data from table based on the users choice (for this i have a created a parameter on selection screen) and i want to display the table contents on the list....how to do it?
08-02-2008 5:41 AM
hi,
Select the data from the Db table inot an internal table and Assign the Internal table to ALV list Function Module.
Use Query.
Select * from <DBtable>
into table <itab>
where <field > EQ <p_val>.
This Query will store Data in the Internal table.
Regards
Sumit Agarwal
08-02-2008 5:41 AM
hi,
Select the data from the Db table inot an internal table and Assign the Internal table to ALV list Function Module.
Use Query.
Select * from <DBtable>
into table <itab>
where <field > EQ <p_val>.
This Query will store Data in the Internal table.
Regards
Sumit Agarwal
08-02-2008 5:54 AM
Hi,
For fetching data from Dynamic database table and disply it into list you can use field -symbol concept.
Refer the link for the ceoncept-
http://www.sap-img.com/ab030.htm
Regards,
Sujit
08-02-2008 6:14 AM
refer to the link for sample code on dynamic table selection:
http://www.sap-img.com/abap/how-can-we-give-dynamic-table-name-in-select-statement.htm
With luck,
Pritam.
08-02-2008 6:25 AM
1.First Get the components from the table(fields)
2.Create the fieldcatalog
3.Create the Dynamic Table using the CL_ALV_TABLE_CREATE
4. Now use the select
5. Display the data
Check the sample code.
REPORT ytest_dynamic.
TYPE-POOLS : abap.
DATA : table_des TYPE REF TO cl_abap_structdescr.
DATA : ifields TYPE abap_compdescr_tab,
wa_field LIKE LINE OF ifields.
DATA: it_fieldcat TYPE lvc_t_fcat,
wa_fieldcat TYPE lvc_s_fcat.
DATA: i_tab TYPE REF TO data.
FIELD-SYMBOLS: <fs> TYPE STANDARD TABLE.
PARAMETERS: p_table(30) TYPE c DEFAULT 'SFLIGHT'.
"Table definiton using the table name
table_des ?= cl_abap_typedescr=>describe_by_name( p_table ).
"Now Read all the fields to a table.
ifields = table_des->components.
LOOP AT ifields INTO wa_field.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = wa_field-name .
wa_fieldcat-datatype = wa_field-type_kind.
wa_fieldcat-inttype = wa_field-type_kind.
wa_fieldcat-intlen = wa_field-length.
wa_fieldcat-decimals = wa_field-decimals.
wa_fieldcat-coltext = wa_field-name.
wa_fieldcat-outputlen = wa_field-length.
APPEND wa_fieldcat TO it_fieldcat.
ENDLOOP.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcat
IMPORTING
ep_table = i_tab
* e_style_fname =
EXCEPTIONS
generate_subpool_dir_full = 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.
ASSIGN i_tab->* TO <fs>.
*-fill the data
APPEND INITIAL LINE TO <fs>.
SELECT *
INTO TABLE <fs>
FROM (p_table)
UP TO 20 ROWS.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
it_fieldcat_lvc = it_fieldcat
TABLES
t_outtab = <fs>
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.