HR模块-组织信息类型创建-PP01


前言

第一次上HR模块的项目,发现HR得表都很有意思,基本上靠一个模板创出来得表,刚刚接触到这个模块懂得还不是很多,还请多指教


一、组织模块相关表

组织模块得表以HRP开头,这里记录了组织相关信息得抬头,其具体得行项目信息以HRT开头为命名,在开发时创建相关的结构命名以P开头,这倒是跟正常的PA30的信息类型一致。

二、创建相关函数和使用

盲猜和HR_INFOTYPE_OPERATION一样底层使用的BDC录屏

1.RH_READ_INFTY

看函数名,就可以发现这个读取信息类型的函数,之所以先使用这个函数后面会说到

    CALL FUNCTION 'RH_READ_INFTY'
      EXPORTING
        PLVAR                = LV_PLVAR
        OTYPE                = LV_OTYPE
        OBJID                = LS_BZMB-ORGEH
        INFTY                = '9510'
        ISTAT                = LV_ISTAT
        BEGDA                = SY-DATUM
        ENDDA                = SY-DATUM
      TABLES
        INNNN                = LT_P9510
*       OBJECTS              =
      EXCEPTIONS
        ALL_INFTY_WITH_SUBTY = 1
        NOTHING_FOUND        = 2
        NO_OBJECTS           = 3
        WRONG_CONDITION      = 4
        WRONG_PARAMETERS     = 5
        OTHERS               = 6.

2.RH_INSERT_INFTY_EXP

把函数名中的’INSERT’换成*号搜索一下,估计能查到相关的函数,大家自己试一下

      CALL FUNCTION 'RH_INSERT_INFTY_EXP'
        EXPORTING
          FCODE                  = 'INSE'
          VTASK                  = 'S'
          ORDER_FLG              = ''
          COMMIT_FLG             = 'X'
        TABLES
          INNNN                  = LT_WPLOG_INS
          TNNNN                  = LT_PT9510
        EXCEPTIONS
          NO_AUTHORIZATION       = 1
          ERROR_DURING_INSERT    = 2
          CORR_EXIT              = 3
          BEGDA_GREATER_ENDDA    = 4
          NO_INNNN_TNNNN         = 5
          ADDITIONAL_INNNN_TNNNN = 6
          OTHERS                 = 7.

注意点

我们用P****结构时,通常会使用一个类的方法,转换成函数提供的结构

      CALL METHOD CL_HR_PNNNN_TYPE_CAST=>PNNNN_TO_WPLOG
        EXPORTING
          PNNNN = LS_P9510
        IMPORTING
          WPLOG = LS_WPLOG.

前面有个坑,在这里埋一下

之前说到为什么要先read信息类型呢,而不是直接创建,这里我是观察组织结构信息类型表得出的结论。当然像HRP1001这种标准的可能不会出现这种情况,根据自己实际情况使用。

首先

9开头的表,有标准表一样的关键字外,最后面还挂了一个TABNR字段,这是关联他的T表(明细表),列如HRP9510对应的T表就是HRT9510
在这里插入图片描述

其次

T表,我关注了两个字段,其中TABNR是与P表做关联的,
那TABSEQNR字段,是作为序列号,这个字段是关键
在这里插入图片描述
如果我们不对这个字段进行赋值,INSTER函数会将T表进行覆盖而达不到我们想要的结果。
下面是我写的一段参考PEFROM,多多指点

FORM FRM_INS_INFTY  TABLES   PT_BZBM STRUCTURE ZTHRBG020
                     USING PV_GUID
                     CHANGING PV_BZZQ
                              E_MESSAGE TYPE ZSHR_MESSAGE.
  DATA:LT_P9510 TYPE TABLE OF P9510,
       LS_P9510 TYPE P9510.
  DATA:LT_WPLOG_INS TYPE STANDARD TABLE OF WPLOG.
  DATA:LS_WPLOG     TYPE WPLOG.
  DATA:LT_PT9510 TYPE TABLE OF HRT9510,
       LS_PT9510 TYPE HRT9510.
  CONSTANTS:LV_PLVAR TYPE PLOG-PLVAR VALUE '01',
            LV_ISTAT TYPE PLOG-ISTAT VALUE '1',
            LV_ENDDA TYPE PLOG-ENDDA VALUE '99991231',
            LV_OTYPE TYPE PLOG-OTYPE VALUE 'O',
            LV_TABNR TYPE HRTABNR VALUE '1',
            LV_LANGU TYPE SY-LANGU VALUE '1',
            LV_INFTY TYPE P9510-INFTY VALUE '9510'.
  DATA: LV_BEGDA TYPE SY-DATUM.
  DATA: LT_MESG  TYPE TSMESG.
  DATA:LT_ZTHRBG020 TYPE TABLE OF ZTHRBG020,
       LS_ZTHRBG020 TYPE ZTHRBG020.
  DATA:IDENT  LIKE SY-UZEIT.

  LV_BEGDA = SY-DATUM.
  SORT PT_BZBM BY ZGS ORGEH ZHR_BZLX ZHR_GWCJ.
  LOOP AT PT_BZBM INTO DATA(LS_BZMB).
    CLEAR:LS_P9510.
    MOVE-CORRESPONDING LS_BZMB TO LS_ZTHRBG020.
    LS_ZTHRBG020-GUID = PV_GUID.

    CALL FUNCTION 'MESSAGES_INITIALIZE'    "消息初始化
      EXPORTING
        I_IDENTIFICATION = IDENT
      IMPORTING
        E_IDENTIFICATION = IDENT
      EXCEPTIONS
        OTHERS           = 0.

    CALL FUNCTION 'MESSAGES_ACTIVE'      "激活消息
      EXCEPTIONS
        OTHERS = 1.
    "查询
    CALL FUNCTION 'RH_READ_INFTY'
      EXPORTING
        PLVAR                = LV_PLVAR
        OTYPE                = LV_OTYPE
        OBJID                = LS_BZMB-ORGEH
        INFTY                = '9510'
        ISTAT                = LV_ISTAT
        BEGDA                = SY-DATUM
        ENDDA                = SY-DATUM
      TABLES
        INNNN                = LT_P9510
*       OBJECTS              =
      EXCEPTIONS
        ALL_INFTY_WITH_SUBTY = 1
        NOTHING_FOUND        = 2
        NO_OBJECTS           = 3
        WRONG_CONDITION      = 4
        WRONG_PARAMETERS     = 5
        OTHERS               = 6.
    IF SY-SUBRC <> 0.
* Implement suitable error handling here
    ENDIF.
    READ TABLE LT_P9510 INTO DATA(IS_P9510) INDEX 1.
    IF SY-SUBRC = 0.
      LS_P9510-PLVAR = IS_P9510-PLVAR.
      LS_P9510-OTYPE = IS_P9510-OTYPE.
      LS_P9510-OBJID = IS_P9510-OBJID.
      LS_P9510-ISTAT = IS_P9510-ISTAT.
      LS_P9510-BEGDA = IS_P9510-BEGDA.
      LS_P9510-ENDDA = IS_P9510-ENDDA.
      LS_P9510-INFTY = IS_P9510-INFTY.
      LS_P9510-ZHR_BZZQ = IS_P9510-ZHR_BZZQ .
      LS_P9510-TABNR = IS_P9510-TABNR.
      LS_P9510-AEDTM = SY-DATUM.
      LS_P9510-UNAME = SY-UNAME.
      CLEAR:LS_WPLOG,LT_WPLOG_INS.
      CALL METHOD CL_HR_PNNNN_TYPE_CAST=>PNNNN_TO_WPLOG
        EXPORTING
          PNNNN = LS_P9510
        IMPORTING
          WPLOG = LS_WPLOG.
      APPEND LS_WPLOG TO LT_WPLOG_INS.
      CLEAR:LS_PT9510,LT_PT9510.
      SELECT * FROM HRT9510 INTO CORRESPONDING FIELDS OF TABLE LT_PT9510 WHERE TABNR = LS_P9510-TABNR.
      "查看岗位层级的行号
      SORT LT_PT9510 DESCENDING BY TABNR.
      READ TABLE LT_PT9510 ASSIGNING FIELD-SYMBOL(<FS_PT9510>)  WITH KEY ZHR_GWCJ = LS_BZMB-ZHR_GWCJ.
      IF SY-SUBRC = 0.
        <FS_PT9510>-ZHR_GWCJ = LS_BZMB-ZHR_GWCJ.
        <FS_PT9510>-ZHR_BZZS = LS_BZMB-ZSQBZS.
        <FS_PT9510>-ZHR_ZBZS01 = LS_BZMB-ZBZS01.
        <FS_PT9510>-ZHR_ZBZS02 = LS_BZMB-ZBZS02.
        <FS_PT9510>-ZHR_ZBZS03 = LS_BZMB-ZBZS03.
        <FS_PT9510>-ZHR_ZBZS04 = LS_BZMB-ZBZS04.
        <FS_PT9510>-ZHR_ZBZS05 = LS_BZMB-ZBZS05.
        <FS_PT9510>-ZHR_ZBZS06 = LS_BZMB-ZBZS06.
        <FS_PT9510>-ZHR_ZBZS07 = LS_BZMB-ZBZS07.
        <FS_PT9510>-ZHR_ZBZS08 = LS_BZMB-ZBZS08.
        <FS_PT9510>-ZHR_ZBZS09 = LS_BZMB-ZBZS09.
        <FS_PT9510>-ZHR_ZBZS10 = LS_BZMB-ZBZS10.
        <FS_PT9510>-ZHR_ZBZS11 = LS_BZMB-ZBZS11.
        <FS_PT9510>-ZHR_ZBZS12 = LS_BZMB-ZBZS12.
      ELSE.
        READ TABLE LT_PT9510 INTO DATA(IS_PT9510) INDEX 1.
        IF SY-SUBRC = 0.
          LS_PT9510-TABNR = LS_P9510-TABNR.
          LS_PT9510-TABSEQNR = IS_PT9510-TABSEQNR + 1.
          LS_PT9510-ZHR_GWCJ = LS_BZMB-ZHR_GWCJ.
          LS_PT9510-ZHR_BZZS = LS_BZMB-ZSQBZS.
          LS_PT9510-ZHR_ZBZS01 = LS_BZMB-ZBZS01.
          LS_PT9510-ZHR_ZBZS02 = LS_BZMB-ZBZS02.
          LS_PT9510-ZHR_ZBZS03 = LS_BZMB-ZBZS03.
          LS_PT9510-ZHR_ZBZS04 = LS_BZMB-ZBZS04.
          LS_PT9510-ZHR_ZBZS05 = LS_BZMB-ZBZS05.
          LS_PT9510-ZHR_ZBZS06 = LS_BZMB-ZBZS06.
          LS_PT9510-ZHR_ZBZS07 = LS_BZMB-ZBZS07.
          LS_PT9510-ZHR_ZBZS08 = LS_BZMB-ZBZS08.
          LS_PT9510-ZHR_ZBZS09 = LS_BZMB-ZBZS09.
          LS_PT9510-ZHR_ZBZS10 = LS_BZMB-ZBZS10.
          LS_PT9510-ZHR_ZBZS11 = LS_BZMB-ZBZS11.
          LS_PT9510-ZHR_ZBZS12 = LS_BZMB-ZBZS12.
          APPEND LS_PT9510 TO LT_PT9510.
        ENDIF.
      ENDIF.

      CALL FUNCTION 'RH_INSERT_INFTY_EXP'
        EXPORTING
          FCODE                  = 'INSE'
          VTASK                  = 'S'
          ORDER_FLG              = ''
          COMMIT_FLG             = 'X'
        TABLES
          INNNN                  = LT_WPLOG_INS
          TNNNN                  = LT_PT9510
        EXCEPTIONS
          NO_AUTHORIZATION       = 1
          ERROR_DURING_INSERT    = 2
          CORR_EXIT              = 3
          BEGDA_GREATER_ENDDA    = 4
          NO_INNNN_TNNNN         = 5
          ADDITIONAL_INNNN_TNNNN = 6
          OTHERS                 = 7.
    ELSE.

      LS_P9510-PLVAR = LV_PLVAR.
      LS_P9510-OTYPE = LV_OTYPE.
      LS_P9510-OBJID = LS_BZMB-ORGEH.
      LS_P9510-ISTAT = LV_ISTAT.
      LS_P9510-BEGDA = LV_BEGDA.
      LS_P9510-ENDDA = LV_ENDDA.
      LS_P9510-INFTY = LV_INFTY.
      LS_P9510-ZHR_BZZQ = PV_BZZQ.
      LS_P9510-AEDTM = SY-DATUM.
      LS_P9510-UNAME = SY-UNAME.
      CLEAR:LS_WPLOG,LT_WPLOG_INS.
      CALL METHOD CL_HR_PNNNN_TYPE_CAST=>PNNNN_TO_WPLOG
        EXPORTING
          PNNNN = LS_P9510
        IMPORTING
          WPLOG = LS_WPLOG.



      LS_PT9510-TABSEQNR = LS_PT9510-TABSEQNR + 1.
      LS_PT9510-ZHR_GWCJ = LS_BZMB-ZHR_GWCJ.
      LS_PT9510-ZHR_BZZS = LS_BZMB-ZSQBZS.
      LS_PT9510-ZHR_ZBZS01 = LS_BZMB-ZBZS01.
      LS_PT9510-ZHR_ZBZS02 = LS_BZMB-ZBZS02.
      LS_PT9510-ZHR_ZBZS03 = LS_BZMB-ZBZS03.
      LS_PT9510-ZHR_ZBZS04 = LS_BZMB-ZBZS04.
      LS_PT9510-ZHR_ZBZS05 = LS_BZMB-ZBZS05.
      LS_PT9510-ZHR_ZBZS06 = LS_BZMB-ZBZS06.
      LS_PT9510-ZHR_ZBZS07 = LS_BZMB-ZBZS07.
      LS_PT9510-ZHR_ZBZS08 = LS_BZMB-ZBZS08.
      LS_PT9510-ZHR_ZBZS09 = LS_BZMB-ZBZS09.
      LS_PT9510-ZHR_ZBZS10 = LS_BZMB-ZBZS10.
      LS_PT9510-ZHR_ZBZS11 = LS_BZMB-ZBZS11.
      LS_PT9510-ZHR_ZBZS12 = LS_BZMB-ZBZS12.
      APPEND LS_PT9510 TO LT_PT9510.

      AT END OF ORGEH.

        APPEND LS_WPLOG TO LT_WPLOG_INS.
        CALL FUNCTION 'RH_INSERT_INFTY_EXP'
          EXPORTING
            FCODE                  = 'INSE'
            VTASK                  = 'S'
            ORDER_FLG              = ''
            COMMIT_FLG             = 'X'
          TABLES
            INNNN                  = LT_WPLOG_INS
            TNNNN                  = LT_PT9510
          EXCEPTIONS
            NO_AUTHORIZATION       = 1
            ERROR_DURING_INSERT    = 2
            CORR_EXIT              = 3
            BEGDA_GREATER_ENDDA    = 4
            NO_INNNN_TNNNN         = 5
            ADDITIONAL_INNNN_TNNNN = 6
            OTHERS                 = 7.
        CLEAR:LS_PT9510,LT_PT9510.
      ENDAT.




    ENDIF.

    IF SY-SUBRC = 0.
      COMMIT WORK AND WAIT.
      LS_ZTHRBG020-MSGTY = 'S'.
      LS_ZTHRBG020-MSGTX = '更新成功'.
      E_MESSAGE-MSGTY = 'S'.
      E_MESSAGE-MSGTX = '更新成功'.
    ELSE.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
      CALL FUNCTION 'MESSAGES_GIVE'     "获取消息
        TABLES
          T_MESG = LT_MESG.
      READ TABLE LT_MESG INTO DATA(LS_MESG) WITH KEY MSGTY = 'E'.
      IF SY-SUBRC = 0.
        LS_ZTHRBG020-MSGTY = LS_MESG-MSGTY.
        LS_ZTHRBG020-MSGTX = LS_MESG-TEXT.
        E_MESSAGE-MSGTY = LS_MESG-MSGTY.
        E_MESSAGE-MSGTX = LS_MESG-TEXT.
      ELSE.
        LS_ZTHRBG020-MSGTY = 'E'.
        LS_ZTHRBG020-MSGTX = '更新失败'.
        E_MESSAGE-MSGTY = 'E'.
        E_MESSAGE-MSGTX = '更新失败'.
      ENDIF.
    ENDIF.
    APPEND LS_ZTHRBG020 TO LT_ZTHRBG020.
    CLEAR:LS_BZMB,LS_ZTHRBG020.
  ENDLOOP.

  MODIFY  ZTHRBG020 FROM TABLE LT_ZTHRBG020.
  IF SY-SUBRC = 0.
    COMMIT WORK AND WAIT.
  ELSE.
    ROLLBACK WORK.
  ENDIF.

ENDFORM.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值