Application Development 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: 

How to get a list of tables from the system.

mahmood_hammood
Participant
0 Kudos
1,569

Hello everyone,

I have this code to display the SFLIGHTS table data. But I need to edit it to be able to find all tables which are in my system, not only SFLIGHTS. How can I make this please?




REPORT ZTEST_PROGRAM.


DATA: gv_table_name TYPE DDOBJNAME,
gv_num_records TYPE I.


PARAMETERS: p_tabnam TYPE dd02l-tabname OBLIGATORY,
p_num_re TYPE I DEFAULT 20.


AT SELECTION-SCREEN ON help-REQUEST FOR p_tabnam.




START-OF-SELECTION.
PERFORM display_table_data.
END-OF-selection.

FORM fetch_table_list.
DATA: lt_table_list TYPE STANDARD TABLE OF DFIES,
ls_table_list TYPE dd02l.
gv_table_name = p_tabnam.

CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = gv_table_name
TABLES
dfies_tab = lt_table_list.

* LOOP AT lt_table_list INTO ls_table_list.
* CONCATENATE ls_table_list-tabname ' -' ls_table_list-tabname INTO ls_table_list-tabname SEPARATED BY space.
* MOVE-CORRESPONDING ls_table_list TO lt_table_list.
* MODIFY lt_table_list TRANSPORTING tabname.
* ENDLOOP.


CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'P_TABLE_NAME'
value_org = 'S'
multiple = ' '
TABLES
value_tab = lt_table_list
EXCEPTIONS
OTHERS = 1.


IF sy-subrc <> 0.
MESSAGE 'Error in fetching table list' TYPE 'E'.
ENDIF.
ENDFORM.

FORM display_table_data.
DATA: lt_table_data TYPE TABLE OF sflights,
ls_table_data TYPE sflights.
gv_table_name = p_tabnam. "global variable
* SELECT * FROM (gv_table_name) INTO TABLE lt_table_data UP TO gv_num_records ROWS.
SELECT *
INTO TABLE lt_table_data
FROM (gv_table_name) UP TO p_num_re ROWS.

LOOP AT lt_table_data INTO ls_table_data.
WRITE: / ls_table_data-carrid,
ls_table_data-connid,
ls_table_data-fldate.
* ls_table_data-price.
ENDLOOP.




CALL FUNCTION 'SRTT_TABLE_DISPLAY'

EXPORTING

TABLE = 'sflights'

IV_TITLE = 'Flight List'

TABLES

table_content = lt_table_data. "display content from the internal table lt_table_data.

FIELD-SYMBOLS: <fs_field> TYPE ANY.

DESCRIBE TABLE lt_table_data LINES sy-tabix.
WRITE: / 'Number of Records Displayed:', sy-tabix.
ENDFORM:

12 REPLIES 12

raymond_giuseppi
Active Contributor
1,260

Try

      CALL FUNCTION 'RS_DD_F4_OBJECT'
        EXPORTING
          objname            = p_tabnam
          objtype            = 'T'
          suppress_selection = 'X'

0 Kudos
1,260

I tried your solution with the help of searching in google but allways some wrongs . Should I change something in my code? Can you explain more please? this is my first program in ABAP.

0 Kudos
1,260
  • First try to call the FM in test mode with SE37
  • Then call this FM in the Process On Value Request AT SELECTION-SCREEN ON VALUE-REQUEST

Eduardo-CE
Active Participant
0 Kudos
1,260

Hi,

You can also check table TADIR with PGMID = 'R3TR' OBJECT = 'TABL'.

Sandra_Rossi
Active Contributor
1,260

I advise anyone to check systematically the format of the question after posting one, because of the many forum bugs.

To fix them, use Actions > Edit.

Sandra_Rossi
Active Contributor
0 Kudos
1,260

You want "to find all tables in the system", I guess you know they are listed in the table DD02L because your program already refers to DD02L, but what exactly do you want to do after you get all the tables? Display an ALV with the list of all tables instead of flights? Table names and their titles? Or just permit F4 on the selection screen to show all tables and select one?

mahmood_hammood
Participant
0 Kudos
1,260

As you see in photo, I select a table, open it, display table data and be able to edit it. other question, when I create some table, will it locate automatically in the table DD02L ?

matt
Active Contributor
1,260

It looks like you're working from some old training material. It's probably a good idea to find something more modern. FORMs for example, are obsolete now and should only be used under specific circumstances.

Sandra_Rossi
Active Contributor
0 Kudos
1,260

You're new in ABAP and also in the forum, it seems, you can still fix the formatting of your code (Actions > Edit > button CODE formatting).

Sandra_Rossi
Active Contributor
0 Kudos
1,260

Sorry. I didn't understand your first question. And I didn't understand your second question.

Sandra_Rossi
Active Contributor
0 Kudos
1,260

Thanks for the nice formatting of ABAP code, it looks great now !

Sandra_Rossi
Active Contributor
0 Kudos
1,260

Oh I now understand your latest question "when I create some table, will it locate automatically in the table DD02L ?"

Yes.