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

DB02 transaction

Former Member
0 Likes
9,365

Hello Experts,

Developing program for DB02 transaction. I need to display data for "Tablespace_name", "Total size" and "Free Space".

Looked into DB02 transaction report and they are using tables "dba_data_files" and "dba_free_space".

But i dont find these tables. Please do let me know how to fetch data for the above mentioned fields from the table.

regards,

Gururaj.

7 REPLIES 7
Read only

GauthamV
Active Contributor
0 Likes
7,108

You will get all the list of tablespace names from TSDB6 table.

Regards,

Gautham.

Read only

FredericGirod
Active Contributor
0 Likes
7,108

Hi,

the code to get the size space of a table :

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME .
PARAMETERS : p_bytes TYPE k_bytes.

SELECT-OPTIONS : s_sn FOR zbc_stat_table-sn,
                 s_s_type  FOR zbc_stat_table-s_type,
                 s_owner   FOR zbc_stat_table-owner,
                 s_ts      FOR zbc_stat_table-ts.

SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME .
PARAMETERS : p_maj TYPE c.
SELECTION-SCREEN END OF BLOCK b2.

* Types

TYPES : BEGIN OF ts_segment.
        INCLUDE STRUCTURE segments_f.
TYPES : END OF ts_segment,
        tt_segment TYPE TABLE OF ts_segment.

* Data

DATA : it_segment TYPE tt_segment,
       is_segment TYPE ts_segment.

REFRESH it_segment.

EXEC SQL PERFORMING APP_SEGMENTS.
  SELECT
    OWNER,
    NVL(PARTITION_NAME, SEGMENT_NAME) NAME,
    SEGMENT_TYPE,
    TABLESPACE_NAME,
    HEADER_FILE,
    HEADER_BLOCK,
    BYTES/1024,
    BLOCKS,
    EXTENTS,
    INITIAL_EXTENT/1024,
    NEXT_EXTENT/1024,
    MIN_EXTENTS,
    MAX_EXTENTS,
    PCT_INCREASE,
    SEGMENT_NAME,
    ''
  FROM DBA_SEGMENTS
  INTO :is_sEGMENT
WHERE BYTES/1024 > :P_BYTES

ENDEXEC.

regards

Fred

Read only

0 Likes
7,108

Hi,

Developing report to display like the following output.. Columns are Tablename_space, Total space, Free space and %used.

PSAPSR3250,000.00173,731.3831
PSAPSR370170,350.008,727.5688
PSAPSR3USR290.0097.7566
PSAPTEMP2,220.002,220.000
PSAPUNDO10,000.006,366.5036
SYSAUX1,284.00798.9438
SYSTEM1,894.00967.8149
Sum

i have developed little bit of code, but able to display only one tablename_space(Report in progress).

Attached my code here : ( INTO :TAB_1 is not working as its not an internal table, but ow to declare it as an internal table?)

   TYPES : BEGIN OF ty_tab1,
         tablespace_name(50),
*        size_mb,
*         free_mb,
        END OF ty_tab1.

DATA : tab_1 TYPE ty_tab1.
*       wa_tab_1 TYPE  ty_tab1.


EXEC SQL.
  SELECT TABLESPACE_NAME, SUM(NVL(BYTES,0))/1024
   FROM DBA_DATA_FILES
   GROUP BY TABLESPACE_NAME  INTO :TAB_1
ENDEXEC.

*EXEC SQL.
*    SELECT TABLESPACE_NAME, round(SUM(NVL(BYTES,0))/1024/1024) size_mb
*      FROM DBA_DATA_FILES
*      GROUP BY TABLESPACE_NAME INTO :TAB_2
*  ENDEXEC.

*LOOP AT tab_1 INTO wa_tab1.
  WRITE : / tab_1.
*ENDLOOP.

Thanks in advance.

Gururaj.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
7,108

Those tables don't exist in SAP ddic, those are standard Oracle tables and you must use native sql statements to read their records.

Regards,

Raymond

Read only

Former Member
0 Likes
7,108

Hi Gururaj,

dba_data_files and dba_free_space are not tables in the ABAP dictionary, they are dictionary views in the underlying Oracle database.

DB02 gives information on allocation of data in the Oracle database.

Functions of DB02 in the Database are

  • Space analysis of the SAP database and transaction logs showing space allocated, free space and used space.
  • List of basic options and the recovery model that have been set for the database. By default, automatic creation and update of statistics is set for an SAP system.
  • List of all files of the SAP database and the free space available on disk.

Specifies the space allocated for individual files, the amount of space used and other data.

The following are the structures of dba_data_files and dba_free_space.

DBA_DATA_FILES

DBA_FREE_SPACE

Dba_data_files:

The dba_data_files means total size of the data file. The data file size is total number of the dba_free_space + dba_segments.
SQL> select tablespace_name,sum(bytes)/(1024*1024*1024) from dba_data_files group by tablespace_name order by 1;

This example display the total size of the data file:
SQL> select sum(bytes)/(1024*1024*1024) from dba_data_files;
SUM(BYTES)/(1024*1024*1024)


Dba_segments:

The dba_segments means used size of the data file.
SQL> select tablespace_name,sum(bytes)/(1024*1024*1024) from dba_segments group by tablespace_name order by 1;
This example display the total size of the segments:
SQL> select sum(bytes)/(1024*1024*1024) from dba_segments;
SUM(BYTES)/(1024*1024*1024)

Dba_free_space:

The dba_free_space means free size of the data file.
SQL> select tablespace_name,sum(bytes)/(1024*1024*1024)from dba_free_space group by tablespace_name order by 1;

This example display the total size of the free space:
SQL> select sum(bytes)/(1024*1024*1024) from dba_free_space;
SUM(BYTES)/(1024*1024*1024)

These tables are accessed using the native SQL statements .

Example IN DB02

dba_data_files

EXEC SQL PERFORMING APP_1.
     SELECT TABLESPACE_NAME, SUM(NVL(BYTES,0))/1024
      FROM DBA_DATA_FILES
      GROUP BY TABLESPACE_NAME INTO :TAB_1
  ENDEXEC.

dba_free_space

EXEC SQL PERFORMING APP_2.
    SELECT TABLESPACE_NAME, SUM(NVL(BYTES,0))/1024 FROM DBA_FREE_SPACE
      GROUP BY TABLESPACE_NAME INTO :TAB_2
  ENDEXEC.

dba_tablespaces

EXEC SQL PERFORMING DBA_SEG_ANALYZER2.

    SELECT * FROM DBA_TABLESPACES
       INTO :TAB_3
  ENDEXEC.

dba_segments

EXEC SQL PERFORMING DBA_SEG_ANALYZER2.

    SELECT OWNER, SEGMENT_NAME, TABLESPACE_NAME,
           EXTENTS, SEGMENT_TYPE, BYTES / 1024
          FROM DBA_SEGMENTS
          INTO :DBA_SEG_AN
  ENDEXEC.

Read only

0 Likes
7,108

Hi,

Developing report to display like the following output.. Columns are Tablename_space, Total space, Free space and %used.

PSAPSR3250,000.00173,731.3831
PSAPSR370170,350.008,727.5688
PSAPSR3USR290.0097.7566
PSAPTEMP2,220.002,220.000
PSAPUNDO10,000.006,366.5036
SYSAUX1,284.00798.9438
SYSTEM1,894.00967.8149
Sum

i have developed little bit of code, but able to display only one tablename_space(Report in progress).

Attached my code here : ( INTO :TAB_1 is not working as its not an internal table, but ow to declare it as an internal table?)

   TYPES : BEGIN OF ty_tab1,
         tablespace_name(50),
*        size_mb,
*         free_mb,
        END OF ty_tab1.

DATA : tab_1 TYPE ty_tab1.
*       wa_tab_1 TYPE  ty_tab1.


EXEC SQL.
  SELECT TABLESPACE_NAME, SUM(NVL(BYTES,0))/1024
   FROM DBA_DATA_FILES
   GROUP BY TABLESPACE_NAME  INTO :TAB_1
ENDEXEC.

*EXEC SQL.
*    SELECT TABLESPACE_NAME, round(SUM(NVL(BYTES,0))/1024/1024) size_mb
*      FROM DBA_DATA_FILES
*      GROUP BY TABLESPACE_NAME INTO :TAB_2
*  ENDEXEC.

*LOOP AT tab_1 INTO wa_tab1.
  WRITE : / tab_1.
*ENDLOOP.

Thanks in advance.

Gururaj.

Read only

0 Likes
7,108

To fill an internal table in native SQL, use OPEN cursor, FETCH NEXT cursor, CLOSE cursor statements, look a the sample at http://help.sap.com/abapdocu_731/en/abapexec_cursor.htm.

(Native SQL doesn't know anything of Abap internal table )

For better select statement, check Oracle forums for threads like query to check tablespace size and freespace in https://forums.oracle.com/, or wiki like http://www.orafaq.com/wiki/Tablespace.

Regards,

Raymond