Você está na página 1de 11

Custom Program to Analyze the PSA & Delete the PSA Records Dynamically

Applies to:
SAP Business Intelligence 7.0. For more information, visit the EDW homepage.

Summary
This article describes about to analyze the all PSA table in the system and to delete the PSA records dynamically. Author: Sreenivas Nannuri Company: Accenture Private Ltd. Created on: 21 September 2011

Author Bio
Sreenivas Nannuri is working with Accenture Private Ltd. since 1.8 years. He is currently working on SAP BI 7.0 He also worked on different areas in BI like modeling, reporting, Information broadcasting, production support, ETL process.

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com 1

Custom Program to Analyze the PSA & Delete the PSA Records Dynamically

Table of Contents
1) 2) 3) 4) 5) 6) Introduction ............................................................................................................................................ 3 Benefits of managing PSA data deletion ............................................................................................... 3 ABAP Code: ........................................................................................................................................... 3 Input screen for the program: ................................................................................................................ 7 Output: ................................................................................................................................................... 8 Cross checking the PSA table: .............................................................................................................. 9

Related Content ................................................................................................................................................ 10 Disclaimer and Liability Notice .......................................................................................................................... 11

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com 2

Custom Program to Analyze the PSA & Delete the PSA Records Dynamically

1) Introduction
In most cases, data that is staged in PSA should be deleted periodically. It helps to delete data in an organized way that will be easy to manage and maintain. How often the data should be deleted and what methods can be employed for the deletion of data will be discussed in this article. An ABAP program is presented that will help in identifying the how many records in PSA tables and can delete the records from the psa table dynamically from the output.

2) Benefits of managing PSA data deletion


1. Recover database space 2. Schedule deletion in such a way as not to interfere with daily data loads and user activity 3. Be able to keep the data stored for a reasonable period of time 4. Easy to monitor, maintain and document

3) ABAP Code:
The following ABAP program comes in handy to determine which PSAs are not being managed.

REPORT

Z_PSA_TABLE_SIZE_DELETION no standard page heading.

TABLES: rstsods, ICON. TYPE-POOLS: slis. TYPES: BEGIN OF ty_display, tabname TYPE rstsods-odsname, count TYPE rscewcount, odsname(20) TYPE c, records TYPE nrows, REQUEST TYPE RSREQUNR, END OF ty_display, BEGIN OF ty_function, request TYPE RSTSODSREQUEST-REQUEST, END OF ty_function, BEGIN OF ty_rsreqicods, tabname TYPE rsreqicods-tabname, timestamp TYPE rsreqicods-timestamp, req_date TYPE sy-datum, END OF ty_rsreqicods, BEGIN OF ty_rstsods, odsname TYPE rstsods-odsname, odstech TYPE rstsods-odsname_tech, dateto TYPE rstsods-dateto, END OF ty_rstsods. DATA: odsname TYPE RSODSNAME. DATA: wa_display TYPE ty_display, tb_display TYPE TABLE OF ty_display, tb_function TYPE TABLE OF ty_function, wa_function TYPE ty_function, wa_rsreqicods TYPE ty_rsreqicods, wa_rstsods TYPE ty_rstsods, t_display TYPE STANDARD TABLE OF ty_display INITIAL SIZE 0,

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com 3

Custom Program to Analyze the PSA & Delete the PSA Records Dynamically

t_rsreqicods TYPE STANDARD TABLE OF ty_rsreqicods INITIAL SIZE 0, t_rstsods TYPE STANDARD TABLE OF ty_rstsods INITIAL SIZE 0, i_icon_del LIKE icon-id, text(20) TYPE c, va_check TYPE c. DATA: PSA_NAME1 TYPE tabname, psa_name type RSODSNAME, PICK TYPE SY-UCOMM.

SELECTION-SCREEN BEGIN OF BLOCK B1. SELECT-OPTIONS: s_tabnm FOR rstsods-odsname. PARAMETERS: p_date LIKE sy-datum OBLIGATORY DEFAULT sy-datum. PARAMETERS: p_cnt TYPE c AS CHECKBOX DEFAULT 'X' . SELECTION-SCREEN END OF BLOCK b1. START-OF-SELECTION. DATA: lc_timestamp(14) TYPE c, l_timestamp TYPE rsreqicods-timestamp. CONCATENATE p_date '000000' INTO lc_timestamp. l_timestamp = lc_timestamp. SELECT tabname timestamp INTO TABLE t_rsreqicods FROM rsreqicods WHERE timestamp < l_timestamp AND typ = 'O' AND tabname in s_tabnm. IF sy-subrc <> 0. WRITE: / 'No matching records found.'(001). EXIT. ENDIF. LOOP AT t_rsreqicods INTO wa_rsreqicods. lc_timestamp = wa_rsreqicods-timestamp. wa_rsreqicods-req_date = lc_timestamp(8). MODIFY t_rsreqicods FROM wa_rsreqicods TRANSPORTING req_date. ENDLOOP. SELECT odsname odsname_tech dateto INTO TABLE t_rstsods FROM rstsods WHERE odsname IN ( SELECT DISTINCT tabname FROM rsreqicods WHERE timestamp < l_timesta mp AND typ = 'O' AND tabname in s_tabnm ). SORT t_rstsods BY odsname dateto. LOOP AT t_rsreqicods INTO wa_rsreqicods. CLEAR wa_display. wa_display-tabname = wa_rsreqicods-tabname. wa_display-count = 1. READ TABLE t_rstsods WITH KEY odsname = wa_rsreqicods-tabname TRANSPORTING NO FIELDS BINARY SEARCH. IF sy-subrc = 0.

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com 4

Custom Program to Analyze the PSA & Delete the PSA Records Dynamically

LOOP AT t_rstsods INTO wa_rstsods FROM sy-tabix. IF wa_rstsods-odsname <> wa_rsreqicods-tabname. EXIT. ENDIF. IF wa_rstsods-dateto >= wa_rsreqicods-req_date. wa_display-odsname = wa_rstsods-odstech. EXIT. ENDIF. ENDLOOP. ENDIF. COLLECT wa_display INTO t_display. ENDLOOP. LOOP AT t_display INTO wa_display. IF wa_display-odsname <> ''. *& Does the table really exist in the DB? SELECT tabname INTO wa_display-odsname FROM dd02l UP TO 1 ROWS WHERE tabname = wa_display-odsname. ENDSELECT. IF sy-subrc = 0. IF p_cnt = 'X'. SELECT COUNT(*) INTO wa_display-records FROM (wa_display-odsname). ENDIF. ELSE. *& Table doesn't exist. Put paranthesis to indicate so. CLEAR wa_display-records. CONCATENATE '(' wa_display-odsname ')' INTO wa_display-odsname SEPARATED BY space. ENDIF. MODIFY t_display FROM wa_display. ENDIF. ENDLOOP. IF p_cnt = 'X'. SORT t_display BY records DESCENDING. ELSE. SORT t_display BY count DESCENDING. ENDIF. start-of-selection. SELECT SINGLE id INTO i_icon_del FROM icon WHERE name = 'ICON_DELETE'. WRITE: / 'ICON',15 'TABLE NAME', 50 'ODS COUNT' , 68 'ODS NAME',90 'NO OF RECO RDS'. WRITE: / SY-ULINE.

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com 5

Custom Program to Analyze the PSA & Delete the PSA Records Dynamically

LOOP AT t_display INTO wa_display. WRITE:/ i_icon_del HOTSPOT, ' ', wa_display-tabname, ' ', wa_display-COUNT, ' ', wa_display-ODSNAME, ' ', wa_display-RECORDS, sy-uline. ENDLOOP. AT LINE-SELECTION. CASE PICK. WHEN PICK. READ CURRENT LINE FIELD VALUE wa_display-tabname INTO PSA_NAME1. READ CURRENT LINE FIELD VALUE wa_display-odsname INTO PSA_NAME. * UNPACK l_logsys TO l_logsys. if psa_name1 is not initial. REFRESH tb_function. SELECT REQUEST FROM RSTSODSREQUEST INTO TABLE tb_function where ODSNAME EQ psa_name1. LOOP AT tb_function INTO wa_function. DO TB_FUNCTION TIMES. IF psa_name is not initial and wa_function-request is not initial. CALL FUNCTION 'RSDU_PSA_DELETE' EXPORTING I_TABLNM = PSA_NAME I_REQUEST = wa_function-request * EXCEPTIONS * PSA_DELETE_FAILED = 1 * OTHERS = 2 . IF SY-SUBRC EQ 0. va_check = 'X'. ENDIF. ENDIF. CLEAR wa_function. ENDLOOP. * ENDO. CLEAR wa_display. IF va_check EQ 'X'. WRITE: 'SELECTED ROW PSA RECORDS DELETED SUCESSFULLY'. ENDIF. else. exit. ENDIF. ENDCASE. ***************************************************************************************************************************

* *

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com 6

Custom Program to Analyze the PSA & Delete the PSA Records Dynamically

4) Input screen for the program:


1) Info/Data source name: If we not given any input the program will retrieve all the PSA tables in the SAP-BW/BI system. 2) Requested Date Up to: By default it will be current date of execution, you can choose as per your requirement date to retrieve the PSA tables. 3) PSA Record Count: If we check the check box, program retrieves the record count of the PSA table consist.

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com 7

Custom Program to Analyze the PSA & Delete the PSA Records Dynamically

5) Output:

Click on the Delete Icon

Selected row PSA record count is 160

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com 8

Custom Program to Analyze the PSA & Delete the PSA Records Dynamically

6) Cross checking the PSA table:


After deleting the records in PSA table you can see 0 Records

Go to se11, Give the PSA name and click on display pushbutton.

Then execute the table, you will get the following popup, Click on Number of entries pushbutton you will get the pop up with number of records table holding in the database.

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com 9

Custom Program to Analyze the PSA & Delete the PSA Records Dynamically

Related Content
You must include at least 3 references to SDN documents or web pages. https://help.sap.com https://sdn.sap.com 1) Step by Step Procedure to Create Broadcasters, to Schedule and to Enhance of SAP- BI Queries from Query Designer. 2) Trigger the Process Chain by ABAP Program and how to Schedule ABAP Program as Background Job

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com 10

Custom Program to Analyze the PSA & Delete the PSA Records Dynamically

Disclaimer and Liability Notice


This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade. SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document, and anyone using these methods does so at his/her own risk. SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document.

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com 11

Você também pode gostar