SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Show number of records in a table (by Client)



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP Dictionary
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Wed Aug 20, 2008 9:53 am    Post subject: Show number of records in a table (by Client) Reply with quote

Code:
* Source Name is  ZCUSTOM_TABLES
REPORT zcustom_tables LINE-SIZE 255 LINE-COUNT 65.

************************************************************************
*       Table Declarations                                             *
************************************************************************
TABLES: dd09l,      "DD: Technical settings of tables
        dd02t,      "R/3 DD: SAP table texts
        usr21,      "Assign user name address key
        adrp,       "Persons (central address administration)
        dd02l,      "SAP tables
        t000.       "Clients

************************************************************************
*        Internal Table Declarations                                   *
************************************************************************
DATA:  BEGIN OF zcustom OCCURS 0,
         tabname     LIKE dd02t-tabname,     "Table Name
         contflag    LIKE dd02l-contflag,    "Delivery Class
         ddtext      LIKE dd02t-ddtext,      "Table Text
         as4local    LIKE dd09l-as4local,    "Activation status
         tabkat      LIKE dd09l-tabkat,      "Size category
         tabart      LIKE dd09l-tabart,      "Data class
         as4user     LIKE dd09l-as4user,     "Last changed by
         as4date     LIKE dd09l-as4date,     "Last changed on
         as4time     LIKE dd09l-as4time,     "Last changed at
         persnumber  LIKE usr21-persnumber,  "Person number
         name_first  LIKE adrp-name_first,   "First name
         name_last   LIKE adrp-name_last,    "Last name
         tab_count   LIKE sy-dbcnt,          "DB Count
       END OF zcustom.

DATA: zcustom_fin LIKE zcustom OCCURS 0.

DATA: BEGIN OF nametab OCCURS 300.
        INCLUDE STRUCTURE dfies.
DATA: END OF nametab.

DATA: BEGIN OF tab OCCURS 500.
        INCLUDE STRUCTURE t000.
DATA: END OF tab.

************************************************************************
*        Constants                                                     *
************************************************************************
CONSTANTS: zappl0(40) VALUE ' Master data, transparent tables',
           zappl1(40) VALUE ' Transaction data, transparent tables',
           zappl2(40) VALUE ' Organization and customizing',
           zuser0(40) VALUE ' Customer data class',
           zuser1(40) VALUE ' Customer data class'.

CONSTANTS: zszcat0(40) VALUE ' 0 to 6,300',
           zszcat1(40) VALUE ' 6,300 to 25,000',
           zszcat2(40) VALUE ' 25,000 to 100,000',
           zszcat3(40) VALUE ' 100,000 to 400,000',
           zszcat4(40) VALUE ' 400,000 to 32,000,000'.

CONSTANTS:
  zdelcls_a(60) VALUE
    'Application table (master and transaction data)',
  zdelcls_c(60) VALUE
    'Customizing table, maintenance only by cust., not SAP import',
  zdelcls_e(60) VALUE
    'Control table, SAP and customer have separate key areas',
  zdelcls_g(60) VALUE
             'Application table (master and transaction data)',
  zdelcls_l(60) VALUE
    'Customizing table, protected against SAP Upd., only INS all',
  zdelcls_s(60) VALUE
    'System table, maint. only by SAP, change = modification',
  zdelcls_w(60) VALUE
    'System table, contents transportable via separate TR objects'.

************************************************************************
*        Data Declarations                                             *
************************************************************************
DATA: dat              TYPE d,
      ztable_sel       LIKE zcustom-tabname,
      zdata_class      LIKE zcustom-tabart,
      zsize_cat        LIKE zcustom-tabkat,
      zdel_class       LIKE zcustom-contflag,
      zformat(1)       VALUE 'T',
      leer(1)          VALUE 'X',
      has_mandt(1)     VALUE ' ',
      client_count     LIKE sy-dbcnt,
      total_count      LIKE client_count,
      data_stor(5000).

************************************************************************
*        Start of Selection                                            *
************************************************************************
START-OF-SELECTION.

  SELECT-OPTIONS: tabname FOR dd02t-tabname.

  SELECT tabname contflag
      INTO CORRESPONDING FIELDS OF zcustom
      FROM dd02l
      WHERE tabname IN tabname
        AND ( tabclass EQ 'TRANSP'     "Determine if
          OR tabclass EQ 'CLUSTER'     "Table Physically
          OR tabclass EQ 'POOL' ).       "Stores Data
*          OR tabclass EQ 'VIEW' ).

    SELECT ddtext
      INTO CORRESPONDING FIELDS OF zcustom
      FROM dd02t
      WHERE tabname    = zcustom-tabname
        and ddlanguage = sy-langu.

      SELECT SINGLE as4local tabkat tabart as4user as4date as4time
        INTO CORRESPONDING FIELDS OF zcustom
        FROM dd09l
        WHERE tabname = zcustom-tabname.

      SELECT SINGLE persnumber
        INTO CORRESPONDING FIELDS OF zcustom
        FROM usr21
        WHERE bname = zcustom-as4user.

      SELECT SINGLE name_first name_last
        INTO CORRESPONDING FIELDS OF zcustom
        FROM adrp
        WHERE persnumber = zcustom-persnumber.

      APPEND zcustom.
      exit.
    ENDSELECT.

  ENDSELECT.

  PERFORM write_and_hide_text.

END-OF-SELECTION.

AT LINE-SELECTION.

  ztable_sel  = sy-lisel(30).
  zdata_class = sy-lisel+60(5).
  zsize_cat   = sy-lisel+49(1).
  zdel_class  = sy-lisel+38(1).

  PERFORM write_and_show_text.

************************************************************************
*        Top of Page                                                   *
************************************************************************
TOP-OF-PAGE.
  FORMAT COLOR COL_HEADING ON INTENSIFIED ON.
  WRITE: (30) 'Table Name',
         (6)  'Status',
         (10) 'Del Status',
         (10) 'Size Cat',
         (10) 'Data Class',
         (12) 'Created By',
         (12) 'Date Created',
         (16) 'Time Created'.

  FORMAT COLOR COL_HEADING OFF INTENSIFIED OFF.

TOP-OF-PAGE DURING LINE-SELECTION.
  FORMAT COLOR COL_HEADING ON.
  WRITE: (30) 'Table Name',
         (10) 'Short Text',
          /.

*&---------------------------------------------------------------------*
*&      Form  write_and_hide_text
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM write_and_hide_text.

  SORT zcustom.
  LOOP AT zcustom.
    FORMAT HOTSPOT ON INTENSIFIED ON.
    WRITE:  / zcustom-tabname   UNDER 'Table Name'.
    FORMAT HOTSPOT OFF INTENSIFIED OFF.

    CASE zformat.
      WHEN 'T'.
        PERFORM column_intensified_on.
      WHEN 'F'.
        PERFORM column_intensifeid_off.
    ENDCASE.

    WRITE:  zcustom-as4local  UNDER 'Status',
            zcustom-contflag  UNDER 'Del Status',
            zcustom-tabkat    UNDER 'Size Cat',
            zcustom-tabart    UNDER 'Data Class',
            zcustom-as4user   UNDER 'Created By',
            zcustom-as4date   UNDER 'Date Create',
            zcustom-as4time   UNDER 'Time Created'.
  ENDLOOP.

ENDFORM.                    " write_and_hide_text
*&---------------------------------------------------------------------*
*&      Form  write_and_show_text
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM write_and_show_text.

  LOOP AT zcustom.
    IF ztable_sel = zcustom-tabname.
      FORMAT HOTSPOT OFF INTENSIFIED OFF.

      FORMAT COLOR COL_HEADING ON INVERSE ON.
      WRITE:  zcustom-tabname   UNDER 'Table Name',
              zcustom-ddtext    UNDER 'Short Text'.

      FORMAT COLOR COL_HEADING OFF INVERSE OFF.
    ENDIF.
  ENDLOOP.

*Determine Delivery Class
  PERFORM determ_delivery_class USING zdel_class.

*Determine Data Class
  PERFORM determ_data_class_ USING zdata_class.

*Determine Size Category
  PERFORM determ_size_cat_ USING zsize_cat.

*Select Distinct Table Record count and display info
  PERFORM table_count USING ztable_sel.

ENDFORM.                    " write_and_show_text
*&---------------------------------------------------------------------*
*&      Form  table_count
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_ZTABLE_SEL  text
*----------------------------------------------------------------------*
FORM table_count USING  p_ztable_sel.
  data: mandt-value(8).
  data: begin of where-value occurs 10,
        filler(35),
        end of where-value.
  CLEAR: data_stor.
  clear mandt-value.

  SELECT * FROM dd02l WHERE tabname EQ p_ztable_sel   "Determine if
                        AND ( tabclass EQ 'TRANSP'    "Table Physically
                          OR tabclass EQ 'CLUSTER'    "Stores Data
                          OR tabclass EQ 'POOL'
                          OR tabclass EQ 'VIEW' ).
    CLEAR dd02t.
    SELECT  SINGLE * FROM dd02t WHERE tabname EQ dd02l-tabname
                                  AND ddlanguage EQ 'E'
                                  AND as4local   EQ dd02l-as4local
                                  AND as4vers    EQ dd02l-as4vers.
  ENDSELECT.

  IF sy-subrc NE 0.
    MESSAGE e999(zz) WITH 'Table ' p_ztable_sel ' does not Store Data'.
  ENDIF.
  REFRESH nametab.
  CALL FUNCTION 'GET_FIELDTAB'           "Find Field Names of Table
       EXPORTING
            langu    = sy-langu
            tabname  = p_ztable_sel
            withtext = leer
       TABLES
            fieldtab = nametab
       EXCEPTIONS
            OTHERS   = 1.
  IF sy-subrc NE 0.
    MESSAGE e999(zzzfi001) WITH 'Table ' p_ztable_sel ' is not VALID'.
  ENDIF.
  MOVE 'N' TO has_mandt.

  LOOP AT nametab.
   if  nametab-domname eq 'MANDT'  "See IF Table is Client Dependent
          AND sy-tabix EQ 1.
      MOVE 'Y' TO has_mandt.
      move nametab-fieldname to MANDT-value.
      EXIT.
    ENDIF.
  ENDLOOP.

  IF has_mandt EQ 'Y'.
    SELECT * FROM t000.
      MOVE-CORRESPONDING t000 TO tab.
      APPEND tab.
    ENDSELECT.

    LOOP AT tab.
      CLEAR client_count.
      refresh where-value.
      concatenate   mandt-value '= ' tab-mandt into where-value
        separated by ' '.
      append where-value.

      SELECT COUNT(*)
        FROM (p_ztable_sel) CLIENT SPECIFIED
        INTO data_stor
          where  (where-value).
      MOVE sy-dbcnt   TO client_count.
      ADD client_count TO total_count.

************************************************************************
*        Format Record List                                            *
************************************************************************
      FORMAT COLOR COL_KEY ON INTENSIFIED ON.
      WRITE: / 'Client:'.
      FORMAT COLOR COL_KEY OFF.

      FORMAT COLOR COL_NORMAL ON.
      WRITE:    tab-mandt.
      FORMAT COLOR COL_NORMAL OFF.

      FORMAT COLOR COL_KEY ON INTENSIFIED ON.
      WRITE:  'Records:'.
      FORMAT COLOR COL_KEY OFF.

      FORMAT COLOR COL_NORMAL ON.
      WRITE:  client_count.
      FORMAT COLOR COL_NORMAL OFF.

      COMMIT WORK.
    ENDLOOP.
  ELSE.
    SELECT COUNT(*)
      FROM (p_ztable_sel)
      INTO data_stor.

    MOVE sy-dbcnt TO total_count.
  ENDIF.

  FORMAT COLOR COL_TOTAL ON INTENSIFIED ON.
  WRITE: / 'Total Records in all clients:'.

  FORMAT COLOR COL_TOTAL ON INTENSIFIED OFF.
  WRITE:    total_count,
            dd02t-ddtext.

************************************************************************
*        Clear Internal Table and Total Record Count                   *
************************************************************************
  CLEAR:     tab,
             total_count.

  REFRESH:   tab.

ENDFORM.                    " table_count
*&---------------------------------------------------------------------*
*&      Form  determ_data_class_
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_ZDATA_CLASS  text
*----------------------------------------------------------------------*
FORM determ_data_class_ USING    p_zdata_class.

  FORMAT COLOR COL_GROUP ON INTENSIFIED ON.
  WRITE: / 'Data Class:'.

  FORMAT COLOR COL_GROUP ON INTENSIFIED ON.
  CASE p_zdata_class.
    WHEN 'APPL0'.
      FORMAT INTENSIFIED OFF.
      WRITE: p_zdata_class.
      FORMAT INVERSE ON INTENSIFIED ON.
      WRITE: zappl0.
      FORMAT INVERSE OFF INTENSIFIED OFF.

    WHEN 'APPL1'.
      FORMAT COLOR COL_GROUP ON INTENSIFIED OFF.
      WRITE: p_zdata_class.
      FORMAT INVERSE ON INTENSIFIED ON.
      WRITE: zappl1.
      FORMAT INVERSE OFF INTENSIFIED OFF.


    WHEN 'APPL2'.
      FORMAT COLOR COL_GROUP ON INTENSIFIED OFF.
      WRITE: p_zdata_class.
      FORMAT INVERSE ON INTENSIFIED ON.
      WRITE: zappl2.
      FORMAT INVERSE OFF INTENSIFIED OFF.


    WHEN 'USER'.
      FORMAT COLOR COL_GROUP ON INTENSIFIED OFF.
      WRITE: p_zdata_class.
      FORMAT INVERSE ON INTENSIFIED ON.
      WRITE: zuser0.
      FORMAT INVERSE OFF INTENSIFIED OFF.

    WHEN 'USER1'.
      FORMAT COLOR COL_GROUP ON INTENSIFIED OFF.
      WRITE: p_zdata_class.
      FORMAT INVERSE ON INTENSIFIED ON.
      WRITE: zuser1.
      FORMAT INVERSE OFF INTENSIFIED OFF.
  ENDCASE.

ENDFORM.                    " determ_data_class_
*&---------------------------------------------------------------------*
*&      Form  determ_size_cat_
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_ZSIZE_CAT  text
*----------------------------------------------------------------------*
FORM determ_size_cat_ USING    p_zsize_cat.

  FORMAT COLOR COL_GROUP ON INTENSIFIED ON.
  WRITE: / 'Size Category:'.
  FORMAT COLOR COL_GROUP OFF INTENSIFIED OFF.

  FORMAT COLOR COL_GROUP ON INTENSIFIED ON.
  CASE p_zsize_cat.
    WHEN '0'.
      FORMAT INTENSIFIED OFF.
      WRITE: p_zsize_cat.
      FORMAT INVERSE ON INTENSIFIED ON.
      WRITE: zszcat0.
      FORMAT INVERSE OFF INTENSIFIED OFF.

    WHEN '1'.
      FORMAT INTENSIFIED OFF.
      WRITE: p_zsize_cat.
      FORMAT INVERSE ON INTENSIFIED ON.
      WRITE: zszcat1.
      FORMAT INVERSE OFF INTENSIFIED OFF.
    WHEN '2'.
      FORMAT INTENSIFIED OFF.
      WRITE: p_zsize_cat.
      FORMAT INVERSE ON INTENSIFIED ON.
      WRITE: zszcat2.
      FORMAT INVERSE OFF INTENSIFIED OFF.

    WHEN '3'.
      FORMAT INTENSIFIED OFF.
      WRITE: p_zsize_cat.
      FORMAT INVERSE ON INTENSIFIED ON.
      WRITE: zszcat3.
      FORMAT INVERSE OFF INTENSIFIED OFF.

    WHEN '4'.
      FORMAT INTENSIFIED OFF.
      WRITE: p_zsize_cat.
      FORMAT INVERSE ON INTENSIFIED ON.
      WRITE: zszcat4.
      FORMAT INVERSE OFF INTENSIFIED OFF.
  ENDCASE.

ENDFORM.                    " determ_size_cat_
*&---------------------------------------------------------------------*
*&      Form  determ_delivery_class
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_ZDEL_CLASS  text
*----------------------------------------------------------------------*
FORM determ_delivery_class USING    p_zdel_class.

  FORMAT COLOR COL_HEADING ON INTENSIFIED ON.
  WRITE:  / 'Deliver Class:'.
  FORMAT COLOR COL_HEADING OFF INTENSIFIED OFF.

  FORMAT COLOR COL_KEY ON INTENSIFIED OFF.
  CASE p_zdel_class.
    WHEN 'A'.
      FORMAT INTENSIFIED ON.
      WRITE: p_zdel_class.
      FORMAT INTENSIFIED OFF.
      WRITE: zdelcls_a,
             /.
    WHEN 'C'.
      FORMAT INTENSIFIED ON.
      WRITE: p_zdel_class.
      FORMAT INTENSIFIED OFF.
      WRITE: zdelcls_c,
             /.
    WHEN 'E'.
      FORMAT INTENSIFIED ON.
      WRITE: p_zdel_class.
      FORMAT INTENSIFIED OFF.
      WRITE: zdelcls_e,
             /.
    WHEN 'G'.
      FORMAT INTENSIFIED ON.
      WRITE: p_zdel_class.
      FORMAT INTENSIFIED OFF.
      WRITE: zdelcls_g,
             /.
    WHEN 'L'.
      FORMAT INTENSIFIED ON.
      WRITE: p_zdel_class.
      FORMAT INTENSIFIED OFF.
      WRITE: zdelcls_l,
             /.
    WHEN 'S'.
      FORMAT INTENSIFIED ON.
      WRITE: p_zdel_class.
      FORMAT INTENSIFIED OFF.
      WRITE: zdelcls_s,
             /.
    WHEN 'W'.
      FORMAT INTENSIFIED ON.
      WRITE: p_zdel_class.
      FORMAT INTENSIFIED OFF.
      WRITE: zdelcls_w,
             /.
  ENDCASE.

ENDFORM.                    " determ_delivery_class
*&---------------------------------------------------------------------*
*&      Form  column_intensified_on
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM column_intensified_on.

  FORMAT COLOR COL_NORMAL ON INTENSIFIED ON.
  zformat = 'F'.

  FORMAT HOTSPOT ON INTENSIFIED ON.
  WRITE:  zcustom-tabname   UNDER 'Table Name'.
  FORMAT HOTSPOT OFF. " INTENSIFIED OFF.


ENDFORM.                    " column_intensified_on
*&---------------------------------------------------------------------*
*&      Form  column_intensifeid_off
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM column_intensifeid_off.

  FORMAT COLOR COL_NORMAL ON INTENSIFIED OFF.
  zformat = 'T'.

  FORMAT HOTSPOT ON INTENSIFIED OFF.
  WRITE:  zcustom-tabname   UNDER 'Table Name'.
  FORMAT HOTSPOT OFF. " INTENSIFIED OFF.

ENDFORM.                    " column_intensifeid_off
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP Dictionary All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.