2023 Mar 07 7:34 AM
Hi experts!,
can someone provide me a simple sample code for general table display ? just to search for a table and then display it.
Thank you.
2023 Mar 07 7:53 AM
Hi demaauliansyah ,
REPORT z_display_table.
DATA: lv_table_name TYPE tabname,
lt_table_data TYPE TABLE OF (lv_table_name).
PARAMETERS p_table TYPE tabname.
IF p_table IS INITIAL.
MESSAGE 'Please enter a table name' TYPE 'E'.
ENDIF.
IF NOT cl_abap_dictionary=>is_table_known( p_table ).
MESSAGE 'Table not found' TYPE 'E'.
ENDIF.
SELECT * FROM (p_table) INTO TABLE lt_table_data.
cl_salv_table=>factory(
IMPORTING
r_salv_table = DATA(salv_table)
CHANGING
t_table = lt_table_data
).
salv_table->display( ).
In this example, we first prompt the user to enter a table name using the PARAMETERS statement. We then check if the entered table exists using the cl_abap_dictionary=>is_table_known method. If the table exists, we use a dynamic SELECT statement to retrieve all data from the table and store it in the lt_table_data internal table. We then use the cl_salv_table=>factory method to create an instance of the cl_salv_table class, passing in the lt_table_data internal table as the data source. Finally, we call the display method on the salv_table object to display the table on the screen.2023 Mar 07 7:34 AM
Welcome to the SAP Community. Thank you for visiting us to get answers to your questions.
Since you're asking a question here for the first time, I'd like to offer some friendly advice on how to get the most out of your community membership and experience.
First, please see https://community.sap.com/resources/questions-and-answers, as this resource page provides tips for preparing questions that draw responses from our members. Second, feel free to take our Q&A tutorial at https://developers.sap.com/tutorials/community-qa.html, as that will help you when submitting questions to the community.
I also recommend that you include a profile picture. By personalizing your profile, you encourage readers to respond: https://developers.sap.com/tutorials/community-profile.html.
Now for some specific suggestions on how you might improve your question:
* Outline what steps you took to find answers (and why they weren't helpful) -- so members don't make suggestions that you've already tried.
* Make sure you've applied the appropriate tags -- because if you don't apply the correct tags, the right experts won't see your question to answer it.
Should you wish, you can revise your question by selecting Actions, then Edit.
The more details you provide (in questions tagged correctly), the more likely it is that members will be able to respond. As it stands, I don't know if there is enough information here for members to understand your issue. So please consider revising your question because I'd really like to see you get a solution to your problem!
I hope you find this advice useful, and we're happy to have you as part of SAP Community!
2023 Mar 07 7:53 AM
Hi demaauliansyah ,
REPORT z_display_table.
DATA: lv_table_name TYPE tabname,
lt_table_data TYPE TABLE OF (lv_table_name).
PARAMETERS p_table TYPE tabname.
IF p_table IS INITIAL.
MESSAGE 'Please enter a table name' TYPE 'E'.
ENDIF.
IF NOT cl_abap_dictionary=>is_table_known( p_table ).
MESSAGE 'Table not found' TYPE 'E'.
ENDIF.
SELECT * FROM (p_table) INTO TABLE lt_table_data.
cl_salv_table=>factory(
IMPORTING
r_salv_table = DATA(salv_table)
CHANGING
t_table = lt_table_data
).
salv_table->display( ).
In this example, we first prompt the user to enter a table name using the PARAMETERS statement. We then check if the entered table exists using the cl_abap_dictionary=>is_table_known method. If the table exists, we use a dynamic SELECT statement to retrieve all data from the table and store it in the lt_table_data internal table. We then use the cl_salv_table=>factory method to create an instance of the cl_salv_table class, passing in the lt_table_data internal table as the data source. Finally, we call the display method on the salv_table object to display the table on the screen.2023 Mar 07 8:36 AM
Please edit your answer, select your code and press the button [CODE], which makes the code appear colored/indented, it will be easier for people to look at it. Thank you!
2023 Mar 07 9:29 AM
Hello vinaychowdary,
sure that your source code works? Not in mine... 2 problems:
1.: With this
DATA: lv_table_name TYPE tabname,
lt_table_data TYPE TABLE OF (lv_table_name).
you intend to declare a table of a type that is not known at compile time. IMHO you have to use some RTTI mechanism to declare the table at runtime, when the table name is given.
2.: Class CL_ABAP_DICTIONARY does not exist (checked in some systems).
Kind regards
Jan
2023 Mar 07 1:58 PM
there's this error Type "(LV_TABLE_NAME)" is unknown
or i supposed to fill it with the table name
2023 Mar 07 4:23 PM
Another homework question?
Being spoonfed the answer won't help you in your new career.
2023 Mar 08 6:27 AM
yes i do know that, but if you provide me with some explanation, I learn at the same time that way.
Thank you for the reminder, appreciate it
2023 Mar 08 7:09 AM
search for SALV example in the SE38 transaction ( *salv*demo* + F4 )