根据员工工号和身份证号,查询员工操作状态是入职和在入职的员工信息
查询字段:工号,姓名,操作类型(文本),组织单位(文本),职位(文本),职务(文本),身份证号
数据表:PA0000、PA0001、PA0185(身份证号)、PA0002(民族,省份,籍贯)
1、主报表
*&---------------------------------------------------------------------*
*& Report ZDEMO_ZLM
*&---------------------------------------------------------------------*
*&PA0000、PA0001、PA0185(身份证号)、PA0002(民族、省份、籍贯)
*&入职01、在入职09
*&工号、操作类型、操作类型文本、组织单位、职位、职务、转文本,身份证号
*&查询条件:工号、身份证、人事范围、员工子组、人事子范围、员工组
*&---------------------------------------------------------------------*
REPORT zdemo_zlm01.
INCLUDE zdemo_zlm01_top.
*INCLUDE zdemo_zlm_top."数据定义
INCLUDE zdemo_zlm01_scr.
*INCLUDE zdemo_zlm_scr."选择屏幕
INCLUDE zdemo_zlm01_frm.
*INCLUDE zdemo_zlm_frm."功能定义
START-OF-SELECTION.
*** 取数方式一
PERFORM frm_get_data. " 表连接取数
PERFORM frm_alv_display.
END-OF-SELECTION.
2、数据定义
*&---------------------------------------------------------------------*
*& 包含 ZDEMO_ZLM_TOP
*&工号、操作类型、操作类型文本、组织单位、职位、职务、身份证号、PA0002(民族、省份、籍贯)
*&---------------------------------------------------------------------*
TABLES:
pa0000,pa0001,pa0185,pa0002.
*** 报表结构定义
DATA:
BEGIN OF gs_item,
sel TYPE c,
pernr TYPE pa0000-pernr, "工号
sname TYPE pa0001-sname, "员工姓名
massn TYPE pa0000-massn, "操作类型
massntxt TYPE string, "操作类型文本
orgeh TYPE pa0001-orgeh, "组织单位
orgehtxt TYPE string, "组织单位文本
plans TYPE pa0001-plans, "职位
planstxt TYPE string, "职位文本
stell TYPE pa0001-stell, "职务
stelltxt TYPE string, "职务文本
icnum TYPE pa0185-icnum, "身份证号
zmzwb TYPE pa0002-zmzwb, "民族
zhrsfwb TYPE pa0002-zhrsfwb, "省份
zhrdjswb TYPE pa0002-zhrdjswb,"籍贯
END OF gs_item.
DATA:
gt_item LIKE TABLE OF gs_item.
**** alv *
DATA:
gs_layout TYPE lvc_s_layo,
gs_variant TYPE disvariant,
gt_fcat TYPE lvc_t_fcat,
gs_fcat LIKE LINE OF gt_fcat.
DEFINE m_range.
&1-sign = 'I'.
&1-option = &2.
&1-low = &3.
&1-high = &4.
APPEND &1.
END-OF-DEFINITION.
3、选择屏幕
* &---------------------------------------------------------------------*
* & 包含 ZDEMO_ZLM_SCR
* &查询条件:工号、身份证、人事范围、员工子组、人事子范围、员工组
* &---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1k0 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS:
s_pernr FOR pa0001-pernr NO INTERVALS, "员工号
s_werks FOR pa0001-werks NO INTERVALS, "人事范围
s_btrtl FOR pa0001-btrtl NO INTERVALS, "人事子范围
s_persg FOR pa0001-persg NO INTERVALS, "员工组
s_persk FOR pa0001-persk NO INTERVALS, "员工子组
s_icnum FOR pa0185-icnum NO INTERVALS. "身份证号
SELECTION-SCREEN END OF BLOCK b1k0.
4、功能定义(重点)
*&---------------------------------------------------------------------*
*& 包含 ZDEMO_ZLM_FRM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_ALV_DISPLAY
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_get_data .
SELECT
p0~pernr"员工号
p0~massn"操作类型
p1~icnum"身份证号
INTO CORRESPONDING FIELDS OF TABLE gt_item
FROM pa0000 AS p0
INNER JOIN pa0185 AS p1 ON p0~pernr = p1~pernr
WHERE p0~massn IN ('01' , '09')
AND p0~endda = '99991231'
AND p1~icnum IN s_icnum
AND p0~pernr IN s_pernr.
SORT gt_item BY pernr."排序
IF gt_item[] IS NOT INITIAL."检查gt_item的内部表或数组是否为空或未初始化
**** 组织单位、职位、职务(编码)、姓名 *
SELECT pernr,subty,objps,sprps,endda,begda,seqnr,orgeh,plans,stell,sname INTO TABLE @DATA(lt_pa0001)
FROM pa0001 FOR ALL ENTRIES IN @gt_item "将内部表的条目作为条件应用于数据检索
WHERE pernr = @gt_item-pernr
AND endda = '99991231'.
**** 查询组织单位名称
SELECT stext,objid
INTO TABLE @DATA(lt_orgeh)
FROM hrp1000
FOR ALL ENTRIES IN @lt_pa0001
WHERE otype = 'O'"对象类型
AND objid = @lt_pa0001-orgeh"对象标识
AND endda = '99991231'.
**** 查询职位名称
SELECT stext,objid
INTO TABLE @DATA(lt_plans)
FROM hrp1000
FOR ALL ENTRIES IN @lt_pa0001
WHERE otype = 'S'
AND objid = @lt_pa0001-plans
AND endda = '99991231'.
**** 查询职务名称
SELECT stext,objid
INTO TABLE @DATA(lt_stell)
FROM hrp1000
FOR ALL ENTRIES IN @lt_pa0001
WHERE otype = 'C'
AND objid = @lt_pa0001-stell
AND endda = '99991231'.
**** 民族、省份、籍贯 *
SELECT pernr,subty,objps,sprps,endda,begda,seqnr,zmzwb,zhrsfwb,zhrdjswb INTO TABLE @DATA(lt_pa0002)
FROM pa0002 FOR ALL ENTRIES IN @gt_item
WHERE pernr = @gt_item-pernr
AND endda = '99991231'.
*使用 BINARY SEARCH 之前,需要对数据进行排序
SORT lt_pa0001 BY pernr.
SORT lt_pa0002 BY pernr.
ENDIF.
LOOP AT gt_item ASSIGNING FIELD-SYMBOL(<gs_item>)."遍历gt_item中的元素并使用字段符号<gs_item>来访问每个元素的字段值
**** 操作类型描述赋值 *
IF <gs_item>-massn = '01'.
<gs_item>-massntxt = '入职'.
ELSEIF <gs_item>-massn = '02'.
<gs_item>-massntxt = '转正'.
ELSEIF <gs_item>-massn = '03'.
<gs_item>-massntxt = '调动'.
ELSEIF <gs_item>-massn = '04'.
<gs_item>-massntxt = '离职'.
ELSEIF <gs_item>-massn = '05'.
<gs_item>-massntxt = '退休'.
ELSEIF <gs_item>-massn = '06'.
<gs_item>-massntxt = '返聘'.
ELSEIF <gs_item>-massn = '07'.
<gs_item>-massntxt = '不在岗'.
ELSEIF <gs_item>-massn = '08'.
<gs_item>-massntxt = '返岗'.
ELSEIF <gs_item>-massn = '09'.
<gs_item>-massntxt = '在入职'.
ELSE.
<gs_item>-massntxt = '退休'.
ENDIF.
**** 部门编码、职位编码、职务编码、姓名赋值 *
*在内部表lt_pa0001中查找匹配pernr值的行,并将找到的行中的orgeh...等字段值赋给<gs_item>-orgeh等字段
READ TABLE lt_pa0001 INTO DATA(ls_pa0001) WITH KEY pernr = <gs_item>-pernr BINARY SEARCH.
IF sy-subrc = 0.
<gs_item>-orgeh = ls_pa0001-orgeh.
<gs_item>-plans = ls_pa0001-plans.
<gs_item>-stell = ls_pa0001-stell.
<gs_item>-sname = ls_pa0001-sname.
ENDIF.
**** 部门描述字段赋值 *
READ TABLE lt_orgeh INTO DATA(ls_orgeh) WITH KEY objid = <gs_item>-orgeh BINARY SEARCH.
IF sy-subrc = 0.
<gs_item>-orgehtxt = ls_orgeh-stext.
ENDIF.
**** 职位描述字段赋值 *
READ TABLE lt_plans INTO DATA(ls_plans) WITH KEY objid = <gs_item>-plans BINARY SEARCH.
IF sy-subrc = 0.
<gs_item>-planstxt = ls_plans-stext.
ENDIF.
**** 职务描述字段赋值 *
READ TABLE lt_stell INTO DATA(ls_stell) WITH KEY objid = <gs_item>-stell BINARY SEARCH.
IF sy-subrc = 0.
<gs_item>-stelltxt = ls_stell-stext.
ENDIF.
**** 民族、省份、籍贯赋值 *
READ TABLE lt_pa0002 INTO DATA(ls_pa0002) WITH KEY pernr = <gs_item>-pernr BINARY SEARCH.
IF sy-subrc = 0.
<gs_item>-zmzwb = ls_pa0002-zmzwb.
<gs_item>-zhrsfwb = ls_pa0002-zhrsfwb.
<gs_item>-zhrdjswb = ls_pa0002-zhrdjswb.
ENDIF.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_SET_SCR
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> P_
*& --> P_
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_ALV_DISPLAY
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
FORM frm_init_alv_fcat .
DEFINE m_fcat.
CLEAR gs_fcat.
gs_fcat-fieldname = &1. "内表的字段名
gs_fcat-coltext = &2. "字段描述.
gs_fcat-edit = &3.
gs_fcat-ref_table = &4.
gs_fcat-ref_field = &5.
APPEND gs_fcat TO gt_fcat.
END-OF-DEFINITION.
*** 定义表头字段*
CLEAR gt_fcat[].
m_fcat:
'PERNR' '员工工号' '' '' '',
'SNAME' '姓名' '' '' '',
'MASSNTXT' '操作类型' '' '' '',
'ORGEHTXT' '组织单位' '' '' '',
'PLANSTXT' '职位' '' '' '',
'STELLTXT' '职务' '' '' '',
'ZMZWB' '民族' '' '' '',
'ZHRSFWB' '省份' '' '' '',
'ZHRDJSWB' '籍贯' '' '' '',
'ICNUM' '身份证号' '' '' ''.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_ALV_DISPLAY
*&---------------------------------------------------------------------*
*& text 数据显示
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_alv_display .
DATA:i_grid_settings TYPE lvc_s_glay.
gs_layout-zebra = 'X'.
gs_layout-cwidth_opt = 'X'.
gs_layout-box_fname = 'SEL'."add
i_grid_settings-edt_cll_cb = 'X'."
PERFORM frm_init_alv_fcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'FRM_PF_STATUS_SET'
i_callback_user_command = 'FRM_USER_COMMAND'
is_layout_lvc = gs_layout
it_fieldcat_lvc = gt_fcat[]
i_default = 'X'
i_save = 'A'
TABLES
t_outtab = gt_item
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM.
FORM frm_pf_status_set USING t_ex_tcode TYPE slis_t_extab.
DATA:
lt_fcode TYPE TABLE OF sy-ucomm.
SET PF-STATUS 'PF9000' EXCLUDING lt_fcode.
ENDFORM. "SET_PF_STATUS
FORM html_top_of_page USING document TYPE REF TO cl_dd_document.
ENDFORM. "HTML_TOP_OF_PAGE
FORM frm_user_command USING p_ucomm TYPE sy-ucomm "响应功能代码
p_selfield TYPE slis_selfield.
DATA:
lv_ucomm LIKE sy-ucomm.
lv_ucomm = p_ucomm.
DATA: l_result LIKE LINE OF gt_item.
CLEAR p_ucomm.
CASE lv_ucomm.
WHEN '&QD'.
ENDCASE.
ENDFORM.