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

Utility Program:Downlaoding all Custom Tables Data to Application Server

Former Member
0 Likes
1,054

Hi,

I have a requirement to download all critical custom table data into a directory in application server. My idea is just enter the table name in selection screen and execute the program to download the data. Actually this is going to be a batch job once in a week to make sure critical data is not lost. Can you please suggest me a solution for this requirement? I appreciate your help in advance. Please share with me if you have the code or logics to accomplish the task. Is there any SAP Standard program that can do this task?

Thanks,

Kannan

.

1 ACCEPTED SOLUTION
Read only

karol_seman
Active Participant
0 Likes
698

Hi,

to backup any ddic table I am using the following code. It is backuping to presentation server. Simple replace GUI_DOWNLOAD with DATASET will solve the thing.


*&---------------------------------------------------------------------*
*& Report  ZBACKUPANYTABLETOCSV
*&
*& SHORT DESCRIPTION
*&   the program is used to copy whole content of ANY DDIC table "TAB_NAME"
*&   into file "FILENAME".

PARAMETERS: TAB_NAME type SY-TNAME.                   " table name
PARAMETERS: FILENAME TYPE string.                     " output file name

FIELD-SYMBOLS <wa>    TYPE ANY.                       " work area for line of table TAB_NAME
FIELD-SYMBOLS <field> TYPE ANY.                       " field of work area

DATA: BEGIN OF BUFFER,
        ALIGNMENT TYPE F,                             " Alignment
        C(8000)   TYPE C,                             " Table content
      END OF BUFFER.

DATA: l_index TYPE i.                                 " Field index

DATA: gt_file TYPE TABLE OF rtxline WITH HEADER LINE. " output file content

DATA: h_field TYPE string.                            " help field for casting

ASSIGN BUFFER TO <WA> CASTING TYPE (TAB_NAME).        " get structure of table

SELECT * from (TAB_NAME) into <wa>.                   " get all table records
  l_index = 0.
  gt_file = ''.

  WHILE sy-subrc = 0.
    ADD 1 to l_index.
    ASSIGN COMPONENT l_index OF STRUCTURE <wa> to <field>.
    h_field = <field>.

    IF sy-subrc = 0.
      IF l_index = 1.
        gt_file = h_field.
      ELSE.
        CONCATENATE gt_file ';' h_field INTO gt_file.
      ENDIF.
    ENDIF.
  ENDWHILE.

  APPEND gt_file.
ENDSELECT.

CALL FUNCTION 'GUI_DOWNLOAD'                          " download output to file FILENAME
  EXPORTING
    FILENAME                        = FILENAME
  TABLES
    DATA_TAB                        = gt_file .

Check https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b02d3594-ae48-2a10-83a7-89d369b7...

There also exists great program to backup whole DDIC table with possibility to recreate it then. This really makes sence for backuping. For more information check http://sap4.com/wiki/index.php?title=Copiar_definici%C3%B3n_de_tablas

Regards,

Karol

3 REPLIES 3
Read only

former_member194669
Active Contributor
0 Likes
698

1. Use fm RFC_READ_TABLE and give table name and you will get table entries

2. Use OPEN DATASET and TRANFSER to application server.

( It will not good practice to copying the custom table into app server. My question is what will be end result for this? )

a®

Read only

karol_seman
Active Participant
0 Likes
699

Hi,

to backup any ddic table I am using the following code. It is backuping to presentation server. Simple replace GUI_DOWNLOAD with DATASET will solve the thing.


*&---------------------------------------------------------------------*
*& Report  ZBACKUPANYTABLETOCSV
*&
*& SHORT DESCRIPTION
*&   the program is used to copy whole content of ANY DDIC table "TAB_NAME"
*&   into file "FILENAME".

PARAMETERS: TAB_NAME type SY-TNAME.                   " table name
PARAMETERS: FILENAME TYPE string.                     " output file name

FIELD-SYMBOLS <wa>    TYPE ANY.                       " work area for line of table TAB_NAME
FIELD-SYMBOLS <field> TYPE ANY.                       " field of work area

DATA: BEGIN OF BUFFER,
        ALIGNMENT TYPE F,                             " Alignment
        C(8000)   TYPE C,                             " Table content
      END OF BUFFER.

DATA: l_index TYPE i.                                 " Field index

DATA: gt_file TYPE TABLE OF rtxline WITH HEADER LINE. " output file content

DATA: h_field TYPE string.                            " help field for casting

ASSIGN BUFFER TO <WA> CASTING TYPE (TAB_NAME).        " get structure of table

SELECT * from (TAB_NAME) into <wa>.                   " get all table records
  l_index = 0.
  gt_file = ''.

  WHILE sy-subrc = 0.
    ADD 1 to l_index.
    ASSIGN COMPONENT l_index OF STRUCTURE <wa> to <field>.
    h_field = <field>.

    IF sy-subrc = 0.
      IF l_index = 1.
        gt_file = h_field.
      ELSE.
        CONCATENATE gt_file ';' h_field INTO gt_file.
      ENDIF.
    ENDIF.
  ENDWHILE.

  APPEND gt_file.
ENDSELECT.

CALL FUNCTION 'GUI_DOWNLOAD'                          " download output to file FILENAME
  EXPORTING
    FILENAME                        = FILENAME
  TABLES
    DATA_TAB                        = gt_file .

Check https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b02d3594-ae48-2a10-83a7-89d369b7...

There also exists great program to backup whole DDIC table with possibility to recreate it then. This really makes sence for backuping. For more information check http://sap4.com/wiki/index.php?title=Copiar_definici%C3%B3n_de_tablas

Regards,

Karol

Read only

Former Member
0 Likes
698

Hi a®s,

Thanks for your reply. It is just to make sure we have the table dump just in case Transports moved to Production caused any Issues (deleting the data).

Thanks,

Kannan.