abap 将hr节点转换成 子-父 节点的形式 DEMO

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

  DATA:LT_HRP1001 TYPE TABLE OF HRP1001,
       LS_HRP1001 LIKE LINE  OF LT_HRP1001,
       LT_HRP1001_TEMP TYPE TABLE OF HRP1001.

  DATA:GV_UP    TYPE STRUC-PUP.

  DATA: RESULT_TAB        TYPE TABLE OF SWHACTOR ,
        RESULT_WA         LIKE LINE OF RESULT_TAB,
        RESULT_OBJEC      TYPE TABLE OF OBJEC ,
        RESULT_OBJEC_WA   LIKE LINE OF RESULT_OBJEC,
        RESULT_STRUC      TYPE TABLE OF STRUC ,
        LT_RESULT_STRUC_TEMP TYPE TABLE OF STRUC,
        LS_RESULT_STRUC_TEMP LIKE LINE OF LT_RESULT_STRUC_TEMP.

  DATA:LV_OBJID TYPE HROBJID VALUE '00000000'.

  LS_HRP1001-OBJID = LV_OBJID.

  CALL FUNCTION 'RH_STRUC_GET'
    EXPORTING
      ACT_OTYPE              = 'O'
      ACT_OBJID              = LV_OBJID
      ACT_WEGID              = 'B002'
*     ACT_INT_FLAG           =
      ACT_PLVAR              = '01'
      ACT_BEGDA              = SY-DATUM
      ACT_ENDDA              = SY-DATUM
*     ACT_TDEPTH             = 0
      ACT_TFLAG              = 'X'
      ACT_VFLAG              = 'X'
      AUTHORITY_CHECK        = 'X'
*     TEXT_BUFFER_FILL       =
*     BUFFER_MODE            =
*   IMPORTING
*     ACT_PLVAR              =
   TABLES
      RESULT_TAB      = RESULT_TAB
      RESULT_OBJEC    = RESULT_OBJEC
      RESULT_STRUC    = RESULT_STRUC
   EXCEPTIONS
     NO_PLVAR_FOUND         = 1
     NO_ENTRY_FOUND         = 2
     OTHERS                 = 3
            .


  IF RESULT_STRUC IS NOT INITIAL.
    LOOP AT RESULT_OBJEC INTO RESULT_OBJEC_WA.
      LS_HRP1001-SOBID = RESULT_OBJEC_WA-OBJID.
      APPEND LS_HRP1001 TO LT_HRP1001_TEMP.
      CLEAR:LS_HRP1001,RESULT_OBJEC_WA.
    ENDLOOP.

    SORT LT_HRP1001_TEMP.
    DELETE ADJACENT DUPLICATES FROM LT_HRP1001_TEMP.

    IF LT_HRP1001_TEMP IS NOT INITIAL.

      SELECT *
        INTO CORRESPONDING FIELDS OF TABLE LT_HRP1001
        FROM HRP1001
        FOR ALL ENTRIES IN LT_HRP1001_TEMP
       WHERE SOBID EQ LT_HRP1001_TEMP-SOBID
         AND PLVAR EQ '01'
         AND RSIGN EQ 'B'
         AND RELAT EQ '002'
         AND SCLAS EQ 'O'
         AND BEGDA LE SY-DATUM
         AND ENDDA GE SY-DATUM
        .

       LOOP AT RESULT_OBJEC INTO RESULT_OBJEC_WA.
         LOOP AT LT_HRP1001 INTO LS_HRP1001 WHERE SOBID EQ RESULT_OBJEC_WA-OBJID.
           GS_HRP1001-OBJID = LS_HRP1001-SOBID."子节点
           GS_HRP1001-SOBID = LS_HRP1001-OBJID."父节点
           GS_HRP1001-STEXT = RESULT_OBJEC_WA-STEXT.
           GS_HRP1001-PRIOX = LS_HRP1001-PRIOX.

           APPEND GS_HRP1001 TO GT_HRP1001.
         ENDLOOP.

         IF SY-SUBRC NE 0.
           GS_HRP1001-OBJID = RESULT_OBJEC_WA-OBJID.
           GS_HRP1001-SOBID = SPACE.
           GS_HRP1001-STEXT = RESULT_OBJEC_WA-STEXT.
*          GS_HRP1001-PRIOX = LS_HRP1001-PRIOX.
           APPEND GS_HRP1001 TO GT_HRP1001.
         ENDIF.
       ENDLOOP.

    ENDIF.

  ENDIF.



ENDFORM.

 

?mid=&wid=51824&sid=&tid=8555&rid=LOADED&custom1=mp.csdn.net&custom2=%2Fpostedit%2F99830892&t=1566292217859?mid=&wid=51824&sid=&tid=8555&rid=FINISHED&custom1=mp.csdn.net&t=1566292217860

posted @ 2019-08-20 11:40  linhuang  阅读(3)  评论(0编辑  收藏  举报  来源