SAP 物件更改记录查询报表

*&---------------------------------------------------------------------*
*& Report ZMMRTEST7
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZMMRTEST7.

TABLES:cdhdr,cdpos.
TYPES:BEGIN OF gs_data,
username LIKE cdhdr-username, "負責變更文件人員的使用者名稱
udate LIKE cdhdr-udate, "建立變更文件的日期
utime LIKE cdhdr-utime, "更改時間
tcode LIKE cdhdr-tcode, "已做更改的交易
objectclas LIKE cdpos-objectclas,"物件类别
objectid LIKE cdpos-objectid, "物件值
changenr LIKE cdpos-changenr, "文件的更改號碼
tabname LIKE cdpos-tabname, "表格名稱
fname LIKE cdpos-fname, "欄位名稱
chngind LIKE cdpos-chngind, "更改類型 (U, I, E, D)
unit_old LIKE cdpos-unit_old, "變更文件,參考的單位
cuky_old LIKE cdpos-cuky_old, "變更文件,參考貨幣
value_new LIKE cdpos-value_new, "更改的欄位之新內容
value_old LIKE cdpos-value_old, "更改的欄位之舊內容
unit_new LIKE cdpos-unit_new, "變更文件,參考的單位
cuky_new LIKE cdpos-cuky_new, "變更文件,參考貨幣
END OF gs_data.
DATA:BEGIN OF outdb OCCURS 0 ,
       scggdh TYPE char20,
       scssrq TYPE char20,
       xtwplj TYPE char20,
       xtwpks TYPE char20,
       xtwpys TYPE char20,
       xtxmdm TYPE char20,
       sckgks TYPE char20,
       sckgml TYPE char20,
       scwpsl TYPE char20,
       erp_dl TYPE char20,
       xtwpbm TYPE char20,
       scjgdj TYPE char20,
     END OF outdb.
DATA: gt_data TYPE TABLE OF gs_data.
DATA: gs_layout TYPE slis_layout_alv,
          gt_fieldcat TYPE slis_t_fieldcat_alv with header line,
          wa_fieldcat TYPE slis_fieldcat_alv.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
   SELECT-OPTIONS:
                              s_objtid FOR cdhdr-objectid,"物件值
                              s_chanr FOR cdhdr-changenr,"文件件号码
                              s_uname FOR cdhdr-username, "使用账号
                              s_udate FOR cdhdr-udate,"修改日期日期
                              s_utime FOR cdhdr-utime,"修改时间
                              s_chind FOR cdpos-chngind,"更改指示码
                              s_tname FOR cdpos-tabname,"表格名称
                              s_fname FOR cdpos-fname,"栏位名称
                              s_tocde FOR cdhdr-tcode." t_code
SELECTION-SCREEN END OF BLOCK B1.

INITIALIZATION.
 PERFORM default_value.
************************************************************************
* At Selection Screen
************************************************************************
AT SELECTION-SCREEN.

************************************************************************
* At Selection Screen Output
************************************************************************
AT SELECTION-SCREEN OUTPUT.

************************************************************************
* Report Format
************************************************************************
TOP-OF-PAGE.

END-OF-PAGE.

START-OF-SELECTION.
 PERFORM gt_data.
 PERFORM gt_col.
 PERFORM alv_show.
END-OF-SELECTION.

FORM gt_data.
DATA:l_changenr LIKE cdhdr-changenr.

  SELECT
        cdpos~objectclas
        cdpos~objectid "物件值
        cdpos~changenr "文件的更改號碼
        cdpos~tabname "表格名稱
        cdpos~fname "欄位名稱
        cdpos~chngind "更改類型 (U, I, E, D)
        cdpos~text_case "旗標:X= 內文變更
        cdpos~unit_old "變更文件,參考的單位
        cdpos~unit_new "變更文件,參考的單位
        cdpos~cuky_old "變更文件,參考貨幣
        cdpos~cuky_new "變更文件,參考貨幣
        cdpos~value_new "更改的欄位之新內容
        cdpos~value_old "更改的欄位之舊內容
        cdhdr~username "負責變更文件人員的使用者名稱
        cdhdr~udate "建立變更文件的日期
        cdhdr~utime "更改時間
        cdhdr~tcode "已做更改的交易
  INTO CORRESPONDING FIELDS OF TABLE gt_data
  FROM cdpos
  INNER JOIN cdhdr ON cdhdr~changenr EQ cdpos~changenr
                            AND cdhdr~objectid EQ cdpos~objectid
  WHERE cdhdr~objectid IN s_objtid
            AND cdhdr~changenr IN s_chanr "文件件号码
            AND cdhdr~username IN s_uname "使用账号
            AND cdhdr~udate IN s_udate "修改日期日期
            AND cdhdr~utime IN s_utime "修改时间
            AND cdpos~chngind IN s_chind "更改指示码
            AND cdpos~tabname IN s_tname "表格名称
            AND cdpos~fname IN s_fname "栏位名称
            AND cdhdr~tcode IN s_tocde." t_code

*CONSTANTS:cns_ygjk TYPE c LENGTH 20 VALUE 'SQL_SERVER1'.
*
*  EXEC SQL.
*    CONNECT TO :cns_ygjk
*  ENDEXEC.
*   IF sy-subrc = 0.
*
*   ENDIF.
*  EXEC SQL.
*    SET CONNECTION :cns_ygjk
*  ENDEXEC.
*
*DATA:l_data(40).
* EXEC SQL PERFORMING pf_get_rs.
*    SELECT a.CreateDate
*    INTO :l_data
*    FROM WF_Base AS a
*    where a.BaseCode='dyd-20191122-0204'
*  ENDEXEC.

ENDFORM.

FORM pf_get_rs.
  outdb-erp_dl = outdb-xtwpks+1(2).
  APPEND outdb.
  CLEAR outdb.
*  BREAK-POINT .
ENDFORM.

FORM gt_col.
  DEFINE FILEDCAT.
      GT_FIELDCAT-FIELDNAME = &1.   "对应内表的字段名
      GT_FIELDCAT-SELTEXT_L = &2.   "输出列文本
      GT_FIELDCAT-ddic_outputlen = &3.   "长度
      APPEND GT_FIELDCAT.
  END-OF-DEFINITION.
  FILEDCAT 'USERNAME'                '账号名称'        '12'.
  FILEDCAT 'UDATE'                '日期'        '10'.
  FILEDCAT 'UTIME'                '修改时间'        '8'.
  FILEDCAT 'TCODE'                'T_CODE'        '20'.
  FILEDCAT 'OBJECTCLAS'                '物件类别'        '20'.
  FILEDCAT 'OBJECTID'                '物件值'        '90'.
  FILEDCAT 'CHANGENR'                '文件号码'        '10'.
  FILEDCAT 'TABNAME'                '表格名称'        '30'.
  FILEDCAT 'FNAME'                '栏位名称'        '30'.
  FILEDCAT 'CHNGIND'                '更改类型'        '1'.
  FILEDCAT 'UNIT_OLD'                '參考的單位'        '3'.
  FILEDCAT 'CUKY_OLD'                '参考的货币'        '5'.
  FILEDCAT 'VALUE_NEW'                '更改的值'        '254'.
  FILEDCAT 'MATNR'                '旧值'        '254'.
  FILEDCAT 'UNIT_NEW'                '參考的單位'        '3'.
  FILEDCAT 'CUKY_NEW'                '参考的货币'        '5'.
ENDFORM.

FORM alv_show.

*DATA: w_repid TYPE sy-repid.
  gs_layout-zebra = 'X'. "使ALV界面呈现颜色交替
  gs_layout-colwidth_optimize = 'X'. "自动优化列宽

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
          i_grid_title              = '修改记录查询'
          i_callback_program = sy-repid
          is_layout                 = gs_layout
          it_fieldcat                = gt_fieldcat[]
           i_save                    = 'A'
         TABLES
           t_outtab                 = gt_data
          EXCEPTIONS
            PROGRAM_ERROR      = 1
          OTHERS                     = 2.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form DEFAULT_VALUE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM default_value .
 s_chind-sign = 'I'.
 s_chind-option = 'EQ'.
 s_chind-low = 'U'.
 APPEND s_chind.
 s_chind-sign = 'I'.
 s_chind-option = 'EQ'.
  s_chind-low = 'E'.
 APPEND s_chind.
  s_chind-sign = 'I'.
 s_chind-option = 'EQ'.
  s_chind-low = 'D'.
 APPEND s_chind.

CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
  EXPORTING
    date      = sy-datum    "输入日期
    days      = 5            "天数
    months    = 0             "月数
    signum    = '-'           "+号:表示 N天/月/年后的日期, -号:表示过去的日期
    years     = 0             "年数
  IMPORTING
    calc_date = s_udate-low.    "返回结果:10天后的日期

*s_udate FOR cdhdr-udate,"修改日期日期
*s_udate-low = calc_date.
s_udate-high = sy-datum.
APPEND s_udate.

ENDFORM.

 

上一篇:like %和-的区别与使用


下一篇:MySQL checkpoint和巡检指标说明