【SAP-HCM】报表跳转PA30/PA40实例

2021-12-30 09:51:51 浏览数 (1)

代码语言:javascript复制
REPORT zhrr_0016.
INFOTYPES:0019.
TABLES:pernr,objec.
TYPES: BEGIN OF ty_out,
         xh(8)    TYPE n,
         szd      LIKE t001p-btext,
         szgs     LIKE t500p-name1,
         gsdm     LIKE pa0001-werks,
         ejbm     LIKE p1000-stext,
         sjbm     LIKE p1000-stext,
         cjbm     LIKE p1000-stext,
         sapid    LIKE pernr-pernr,
         empid    LIKE p0002-zyggh,
         empna    LIKE p0001-ename,
         ygxz(40) TYPE c,
         txcd     LIKE p0019-tmart,
         txlx     LIKE t531s-tmtxt,
         txrq     LIKE p0019-mndat,
         dqrq     LIKE p0019-termn,
         rwzt(40) TYPE c,
         statu    TYPE char10,
       END OF ty_out.
DATA l_object TYPE REF TO zclce_hr_organization_kit.
DATA: gw_out TYPE ty_out,
      gt_out TYPE TABLE OF ty_out.
DATA: gw_p0001 LIKE pa0001,
      gt_p0001 LIKE TABLE OF pa0001,
      gw_p0002 LIKE pa0002,
      gt_p0002 LIKE TABLE OF pa0002,
      gw_p0019 LIKE pa0019,
      gt_p0019 LIKE TABLE OF pa0019,
      gw_t001p LIKE t001p,
      gt_t001p LIKE TABLE OF t001p,
      gw_t500p LIKE t500p,
      gt_t500p LIKE TABLE OF t500p,
      gw_t531s LIKE t531s,
      gt_t531s LIKE TABLE OF t531s.
DATA:gt_dm LIKE TABLE OF dd07v, "读取域文本
     gw_dm LIKE dd07v.
DATA:gt_dma LIKE TABLE OF dd07v,
     gw_dma LIKE dd07v.
DATA:gt_zt  LIKE TABLE OF dd07v,
     gt_zta LIKE TABLE OF dd07v,
     gw_zt  LIKE dd07v.
DATA: gw_layo TYPE slis_layout_alv,
      gw_fcat TYPE slis_fieldcat_alv,
      gt_fcat TYPE slis_t_fieldcat_alv.
*----------------------------------------------------------------------*
* 宏定义
*----------------------------------------------------------------------*
DEFINE macro_add_fieldcat.
  CLEAR: gw_fcat.
  gw_fcat-fieldname     = &1.
  gw_fcat-reptext_ddic  = &2.
  gw_fcat-seltext_l     = &2.
  gw_fcat-seltext_m     = &2.
  gw_fcat-seltext_s     = &2.
  APPEND gw_fcat TO gt_fcat.
END-OF-DEFINITION.
gw_fcat-ref_tabname = 'GT_OUT'.
gw_fcat-fieldname = 'SAPID'.
gw_fcat-hotspot = 'X'.

APPEND gw_fcat TO gt_fcat.
SELECTION-SCREEN: BEGIN OF BLOCK b0 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: s_tmart FOR p0019-tmart NO INTERVALS.
PARAMETERS s_check AS CHECKBOX."完成任务
SELECTION-SCREEN: END OF BLOCK b0.

INITIALIZATION.

AT SELECTION-SCREEN OUTPUT.

AT SELECTION-SCREEN.

START-OF-SELECTION.
  PERFORM frm_get_value.

GET pernr.
  PERFORM frm_get_outvalue.




  PERFORM frm_display_result.
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_VALUE
*&---------------------------------------------------------------------*
*       先获取值
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_get_value .

  IF l_object IS INITIAL.
    CREATE OBJECT l_object.
  ENDIF.
  IF s_check IS INITIAL.
    SELECT * INTO TABLE gt_p0019 FROM pa0019
      WHERE  tmart IN s_tmart
      AND     bvmrk = ''
      AND mndat <= pn-endda
    AND mndat >= pn-begda.
  ELSE.
    SELECT * INTO TABLE gt_p0019 FROM pa0019
  WHERE mndat <= pn-endda
AND mndat >= pn-begda.
  ENDIF.
  IF gt_p0019 IS NOT INITIAL.
    SELECT * INTO TABLE gt_p0001 FROM pa0001
   FOR ALL ENTRIES IN gt_p0019
      WHERE pernr = gt_p0019-pernr
            AND begda <= pn-endda
    AND endda >= pn-begda..
    SELECT * INTO TABLE gt_p0002 FROM pa0002
      FOR ALL ENTRIES IN gt_p0019
         WHERE pernr = gt_p0019-pernr
      AND begda <= pn-endda
    AND endda >= pn-begda.
    SORT gt_p0019 BY pernr tmart.
    SORT gt_p0001 BY pernr.
    SORT gt_p0002 BY pernr.
  ELSE.
*    MESSAGE e016(zhr01).
  ENDIF.
  SELECT * INTO TABLE gt_t001p FROM t001p
    WHERE molga = '28'.
  SELECT * INTO TABLE gt_t500p FROM t500p
    WHERE molga = '28'.
  SELECT * INTO TABLE gt_t531s FROM t531s
    WHERE sprsl = sy-langu.
  CALL FUNCTION 'DD_DOMA_GET'
    EXPORTING
      domain_name = 'ZDYGXZ'
    TABLES
      dd07v_tab_a = gt_dma
      dd07v_tab_n = gt_dm.
  CALL FUNCTION 'DD_DOMA_GET'
    EXPORTING
      domain_name = 'BVMRK'
    TABLES
      dd07v_tab_a = gt_zta
      dd07v_tab_n = gt_zt.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_OUTVALUE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_get_outvalue .
  DATA: lw_zzcj LIKE zshr_0008.
  CLEAR: gw_p0001,gw_p0002,gw_p0019,lw_zzcj.
  CLEAR: gw_t001p,gw_t500p,gw_t531s,gw_dm,gw_zt.
  READ TABLE gt_p0019 INTO gw_p0019 WITH KEY pernr = pernr-pernr BINARY SEARCH.
  IF gw_p0019 IS NOT INITIAL.
    READ TABLE gt_p0001 INTO gw_p0001 WITH KEY pernr = pernr-pernr BINARY SEARCH.
    READ TABLE gt_p0002 INTO gw_p0002 WITH KEY pernr = pernr-pernr BINARY SEARCH.
    READ TABLE gt_t001p INTO gw_t001p WITH KEY werks = gw_p0001-werks btrtl = gw_p0001-btrtl.
    READ TABLE gt_t500p INTO gw_t500p WITH KEY persa = gw_p0001-werks.
    READ TABLE gt_t531s INTO gw_t531s WITH KEY tmart = gw_p0019-tmart.
    READ TABLE gt_dm INTO gw_dm WITH KEY domvalue_l = gw_p0001-zygxz.
    READ TABLE gt_zt INTO gw_zt WITH KEY domvalue_l = gw_p0019-bvmrk.
    gw_out-szd = gw_t001p-btext.
    gw_out-szgs = gw_t500p-name1.
    gw_out-empid = gw_p0002-zyggh.
    gw_out-sapid = pernr-pernr.
    gw_out-empna = gw_p0001-ename.
    gw_out-txlx = gw_t531s-tmtxt.
    gw_out-txrq = gw_p0019-mndat.
    gw_out-dqrq = gw_p0019-termn.
    gw_out-gsdm = gw_p0001-werks.
    gw_out-txcd = gw_p0019-tmart.
    MOVE gw_dm-ddtext TO gw_out-ygxz.
    MOVE gw_zt-ddtext TO gw_out-rwzt.
    CALL METHOD l_object->get_organization_level
      EXPORTING
        iv_objid = gw_p0001-orgeh
        iv_date  = sy-datum
      IMPORTING
        ev_jgdj  = lw_zzcj.
    gw_out-ejbm = lw_zzcj-l2t.
    gw_out-sjbm = lw_zzcj-l3t.
    gw_out-cjbm = lw_zzcj-l4t.
    gw_out-statu = icon_led_red.
    APPEND gw_out TO gt_out.
    CLEAR gw_out.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_DISPLAY_RESULT
*&---------------------------------------------------------------------*
*       显示ALV结果
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_display_result .
  DATA:l_xh(8) TYPE n.
*  IF gt_out IS INITIAL.
*    MESSAGE e016(zhr01).
*  ENDIF.
  SORT gt_out BY txrq.
  LOOP AT gt_out INTO gw_out.
    l_xh = l_xh   1.
    gw_out-xh = l_xh.
    MODIFY gt_out FROM gw_out .
    CLEAR gw_out.
  ENDLOOP.
*FREE MEMORY ID 'MTXTAB'.
*EXPORT GT_OUT TO MEMORY ID 'MTXTAB'.

  PERFORM frm_build_layout.
  PERFORM frm_build_fieldcat.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program       = sy-repid
      i_callback_pf_status_set = 'FRM_STATUS_ALV'
      is_layout                = gw_layo
      i_structure_name         = 'SAPID'
      i_callback_user_command  = 'ALV_USER_COMMAND'   "定义执行事件
      it_fieldcat              = gt_fcat
      i_save                   = abap_true
    TABLES
      t_outtab                 = gt_out
    EXCEPTIONS
      program_error            = 1
      OTHERS                   = 2.
  IF sy-subrc NE 0.
    MESSAGE ID sy-msgid
    TYPE sy-msgty
    NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2
    sy-msgv3 sy-msgv4.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_BUILD_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_build_layout .
  gw_layo-colwidth_optimize = abap_true.
  gw_layo-zebra = abap_true.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_build_fieldcat .
  macro_add_fieldcat 'XH' '序号'.
  macro_add_fieldcat 'SZD' '所在地'.
  macro_add_fieldcat 'SZGS' '所在公司'.
  macro_add_fieldcat 'EJBM' '二级部门'.
  macro_add_fieldcat 'SJBM' '三级部门'.
  macro_add_fieldcat 'CJBM' '车间'.
  macro_add_fieldcat 'EMPID' '员工号'.
  macro_add_fieldcat 'SAPID' 'SAPID'.
  macro_add_fieldcat 'EMPNA' '姓名'.
  macro_add_fieldcat 'YGXZ' '用工性质'.
  macro_add_fieldcat 'TXLX' '提醒类型'.
  macro_add_fieldcat 'TXRQ' '提醒日期'.
  macro_add_fieldcat 'DQRQ' '到期日期'.
  macro_add_fieldcat 'RWZT' '任务状态'.
  macro_add_fieldcat 'STATU' '执行状态'.
ENDFORM.

FORM alv_user_command USING r_ucomm     LIKE sy-ucomm
                         rs_selfield TYPE slis_selfield.
  rs_selfield-refresh = 'X'.
  CASE r_ucomm.
    WHEN '&IC1'.
* 获取当前ALV所在行数据
      CLEAR gw_out.
      READ TABLE gt_out INTO gw_out INDEX rs_selfield-tabindex.
      SET PARAMETER ID: 'PER' FIELD gw_out-sapid.
      IF gw_out-txcd = '02'.
        CALL TRANSACTION 'PA30' AND SKIP FIRST SCREEN.
        gw_out-statu  = icon_led_green.
      ELSE.
        CALL TRANSACTION 'PA40' AND SKIP FIRST SCREEN.
        gw_out-statu  = icon_led_green.
      ENDIF.
  ENDCASE.
  MODIFY gt_out FROM gw_out  INDEX rs_selfield-tabindex.

ENDFORM.
sap

0 人点赞