如何将旧的 HR INCLUDE 添加到本地 class?

How to add old HR INCLUDE into local class?

所以我需要使用 INCLUDES rpcblo00 and rpcbdt00 来获取信息类型更改的类型(创建、更新、删除)。事先我使用了一个子程序,它对包含没有问题,但我无法将它们放入 class 中。

如果我尝试按照 here (it's even about the same HR include) 所述将 include 放入方法中,我会收到以下错误(因为 lo-key 中的减号):

Syntax error: Names may only consist of the characters "A-Z", "0-9" and "_". In addition, they may not begin with a number.

最小可重现示例:

CLASS lcl_infotypaenderungen DEFINITION.

  PUBLIC SECTION.

    TYPES: tty_aenderungs_operationen TYPE STANDARD TABLE OF pc403.

    METHODS:

      constructor 
          IMPORTING is_aenderungs_kopf TYPE pldoc_key,

      get_aenderungs_operationen 
          RETURNING value(rt_aenderungs_operationen) TYPE tty_aenderungs_operationen.

  PRIVATE SECTION.

    DATA: s_aenderungs_kopf        TYPE pldoc_key,
          t_aenderungs_operationen TYPE tty_aenderungs_operationen.

    METHODS:

      select_aenderungs_operationen.

ENDCLASS.                    "lcl_infotypaenderungen DEFINITION

*----------------------------------------------------------------------*

TYPE-POOLS: abap.

DATA: lo_infotypaenderungen     TYPE REF TO lcl_infotypaenderungen,
      lv_fehler                 TYPE sy-subrc,
      lt_log_kopf               TYPE pldoc_key_tab WITH HEADER LINE,
      lt_log_felder             TYPE TABLE OF hrinftylog_fields,
      lt_infotyp_vorher         TYPE prelp_tab,
      lt_infotyp_nachher        TYPE prelp_tab,
      lt_aenderungs_operationen TYPE STANDARD TABLE OF pc403.

FIELD-SYMBOLS: <log_kopfzeile>  TYPE pldoc_key.

*----------------------------------------------------------------------*

CALL FUNCTION 'HR_INFOTYPE_LOG_GET_LIST'
  EXPORTING
    tclas              = 'A'
    begda              = '20190315'
    endda              = '20190315'
  IMPORTING
    subrc              = lv_fehler
  TABLES
    infty_logg_key_tab = lt_log_kopf.

  CLEAR lv_fehler.
  SORT lt_log_kopf DESCENDING BY infty bdate btime pernr.

  LOOP AT lt_log_kopf ASSIGNING <log_kopfzeile>.

    CALL FUNCTION 'HR_INFOTYPE_LOG_GET_DETAIL'
      EXPORTING
        logged_infotype  = <log_kopfzeile>
      IMPORTING
        subrc            = lv_fehler
      TABLES
        infty_tab_before = lt_infotyp_vorher
        infty_tab_after  = lt_infotyp_nachher
        fields           = lt_log_felder.

      CREATE OBJECT lo_infotypaenderungen
        EXPORTING
            is_aenderungs_kopf = <log_kopfzeile>.

      REFRESH lt_aenderungs_operationen.
      lt_aenderungs_operationen = lo_infotypaenderungen->get_aenderungs_operationen( ).

  ENDLOOP.

*----------------------------------------------------------------------*

CLASS lcl_infotypaenderungen IMPLEMENTATION.

  METHOD constructor.

    me->s_aenderungs_kopf = is_aenderungs_kopf.
    me->select_aenderungs_operationen( ).

  ENDMETHOD.                    "constructor

  METHOD select_aenderungs_operationen.

    INCLUDE rpcblo00.      """  <--- 
    INCLUDE rpcbdt00.      """  <---

    lo-key-tclas = me->s_aenderungs_kopf-tclas.
    lo-key-pernr = me->s_aenderungs_kopf-pernr.
    lo-key-infty = me->s_aenderungs_kopf-infty.
    lo-key-bdate = me->s_aenderungs_kopf-bdate.
    lo-key-btime = me->s_aenderungs_kopf-btime.
    lo-key-seqnr = me->s_aenderungs_kopf-seqnr.
    IMPORT header TO me->t_aenderungs_operationen FROM DATABASE pcl4(la) ID lo-key.

  ENDMETHOD.                    "select_aenderungs_operationen

  METHOD get_aenderungs_operationen.

    rt_aenderungs_operationen = me->t_aenderungs_operationen.

  ENDMETHOD.                    "get_aenderungs_operationen

ENDCLASS.                    "lcl_infotypaenderungen IMPLEMENTATION

谁知道好的解决办法?提前致谢

编辑: 包含有一些声明和从数据集群读取的宏。当然,我可以直接将它们放入方法中,但我想避免这种情况(现在我这样做了)。

或者,有人知道另一种获取每个信息类型行的更改操作的方法吗?

如果您将 class 用作本地程序,那么使用这些包含的唯一方法是将它们放在程序的最开头。缺点当然是那里的变量变成了全局变量,但不幸的是没有其他方法可以做到这一点,而且如果你想使用全局 class 肯定不会(不确定你的最小工作示例是否只是简化了是否使用本地 class 而不是全局)。

REPORT ZZZ.

INCLUDE rpcblo00.      """  <---
INCLUDE rpcbdt00.      """  <---

CLASS lcl_infotypaenderungen DEFINITION.

" ...

感谢 Jagger,我可以让它与本地 class 一起工作,但是万一以后有人想知道您需要如何更改包含代码才能在全局方法中使用它,您基本上只需需要摆脱 INCLUDE STRUCTURE 声明并用 header 行交换表。

所以

DATA BEGIN OF LO-KEY.
       INCLUDE STRUCTURE PC400.
DATA END OF LO-KEY.

变成

DATA: lo_key TYPE pc400.

DATA BEGIN OF BELEGE_00 OCCURS 100.
  DATA:
  SPLKZ(01) TYPE X,              
  FIELD(10) TYPE C,               
  FTYPE(04) TYPE C,             
  FLENG(03) TYPE N,        
  DECIM(02) TYPE N,          
  OLDDT(50) TYPE C,             
  NEWDT(50) TYPE C.            
DATA END OF BELEGE_00.

变成

TYPES: BEGIN OF ty_belege,
      splkz(01) TYPE x, 
      field(10) TYPE c,   
      ftype(04) TYPE c,  
      fleng(03) TYPE n,  
      decim(02) TYPE n,  
      olddt(50) TYPE c,   
      newdt(50) TYPE c,   
    END OF ty_belege.

DATA: belege_00 TYPE STANDARD TABLE OF ty_belege.

宏可以保持不变(或者我猜你可以重写它)。