查询离职人员资产的报表
*&---------------------------------------------------------------------*
*& Report ZFIR0015D
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Responsibility
*&---------------------------------------------------------------------*
* NUM | Date | Programmer | Corr. # | Description
REPORT zfir0015d MESSAGE-ID zfi001.
*----------------------------------------------------------------------*
* INCLUDE 、 TYPES_POOLS 、 TABLES 引 用 区 *
*----------------------------------------------------------------------*
TABLES:anla,ankt,anlz,cskt,pa0000,pa0001,pa0032,t529t.
.
*----------------------------------------------------------------------*
* T Y P E S - 结 构 定 义 *
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* DATA 定义 *
*----------------------------------------------------------------------*
TYPES: BEGIN OF ty_report,
bukrs TYPE bukrs, ""公司代码
anln1 TYPE anln1, ""主资产号
anln2 TYPE anln2, ""资产子编号
anlkl TYPE anlkl, ""资产类
txk20 TYPE txt20_ankt, ""资产类描述
gdlgrp TYPE gdlgrp, ""资产状态
gdlgrp_txt TYPE gdlgrp_txt, ""资产状态描述
kostl TYPE kostl, ""成本中心
ltext TYPE kltxt, ""成本中心描述
pnalt TYPE pnalt, ""人员工号
pernr TYPE persno, ""SAP工号
sname TYPE smnam, ""员工姓名
massn TYPE massn, ""操作类型
mntxt TYPE mntxt, ""操作类型的名称
zdelete TYPE c, ""删除标识"
END OF ty_report.
DATA: gt_report1 TYPE TABLE OF ty_report,
gt_report2 TYPE TABLE OF ty_report,
gt_report3 TYPE TABLE OF ty_report,
gt_report4 TYPE TABLE OF ty_report,
gs_report1 TYPE ty_report,
gs_report2 TYPE ty_report.
FIELD-SYMBOLS <fs_com> TYPE ty_report.
*----------------------------------------------------------------------*
* ALV 定义
*----------------------------------------------------------------------*
DATA: lt_fieldcat TYPE lvc_t_fcat, "fieldcat 字段目录 参考结构 LVC_T_FCAT
ls_fieldcat LIKE LINE OF lt_fieldcat,
wa_layout TYPE lvc_s_layo, "layout 布局控制 参考结构 lvc_s_layo
lt_sort TYPE lvc_t_sort, "排序
ls_sort LIKE LINE OF lt_sort.
*----------------------------------------------------------------------*
* 选 择 屏 幕 定 义 块
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK text1.
SELECT-OPTIONS:
s_bukrs FOR anla-bukrs MODIF ID f1 OBLIGATORY , ""公司代码
s_anln1 FOR anla-anln1 MODIF ID f1 , ""主资产号
s_anln2 FOR anla-anln2 MODIF ID f1 , ""资产子编号
s_anlkl FOR anla-anlkl MODIF ID f1 , ""资产类
s_kostl FOR anlz-kostl MODIF ID f1 , ""成本中心
s_pnalt FOR pa0032-pnalt MODIF ID f1 , ""人员工号
s_pernr FOR pa0000-pernr MODIF ID f1 . ""SAP工号
PARAMETERS p_p1 TYPE char1 AS CHECKBOX MODIF ID f1. "异常 DEFAULT 'X'
SELECTION-SCREEN END OF BLOCK text1.
*----------------------------------------------------------------------*
* 初 始 化 块 *
*----------------------------------------------------------------------*
*该事件在屏幕未显示之前执行,对程式设置值及屏幕元素进行初始化赋值*
INITIALIZATION.
*----------------------------------------------------------------------*
* 选 择 屏 幕 字 段 处 理 块
*----------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
*----------------------------------------------------------------------*
* 逻 辑 处 理 块 *
*----------------------------------------------------------------------*
START-OF-SELECTION. "执行按钮后触发
PERFORM edit_main.
*&---------------------------------------------------------------------*
*& Form EDIT_MAIN
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM edit_main .
PERFORM frm_authority_check."权限检查
PERFORM frm_getdata. "取数
PERFORM frm_alv_layout. "布局
PERFORM frm_alv_fieldcat. "列
IF NOT p_p1 = 'X'.
PERFORM frm_alv_output TABLES gt_report3. "输出
ELSE.
PERFORM frm_alv_output TABLES gt_report4. "输出
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_AUTHORITY_CHECK
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_authority_check .
DATA:lt_bukrs TYPE TABLE OF t001-bukrs,
lw_bukrs TYPE t001-bukrs.
SELECT bukrs
INTO TABLE lt_bukrs
FROM t001
WHERE bukrs IN s_bukrs.
LOOP AT lt_bukrs INTO lw_bukrs.
AUTHORITY-CHECK OBJECT 'A_S_WERK'
ID 'BUKRS' FIELD lw_bukrs."检查字段
IF sy-subrc <> 0.
MESSAGE s021 WITH lw_bukrs DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GETDATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_getdata .
SELECT DISTINCT
pa0032~pnalt, ""人员工号
pa0000~pernr, ""SAP工号
pa0001~sname, ""员工姓名
pa0000~massn, ""操作类型
t529t~mntxt ""操作类型的名称 "
FROM pa0000
LEFT JOIN pa0032 ON pa0032~pernr = pa0000~pernr
AND pa0032~endda = '99991231'
LEFT JOIN pa0001 ON pa0001~pernr = pa0000~pernr
AND pa0001~endda = '99991231'
LEFT JOIN t529t ON t529t~massn = pa0000~massn
AND t529t~sprsl = @sy-langu ""语言代码
WHERE pa0032~pnalt IS NOT INITIAL
AND pa0000~massn = 'E1'
AND pa0000~endda = '99991231'
AND pa0032~pnalt IN @s_pnalt
AND pa0000~pernr IN @s_pernr
INTO CORRESPONDING FIELDS OF TABLE @gt_report1.
CHECK gt_report1[] IS NOT INITIAL.
"PA0032 中 工号对应了两个SAP工号,例如:C10410254。一个离职一个在职
"但有些人应该就是离职了,但是SAP工号却多创建了,会导致系统判断异常
WITH +data AS ( SELECT * FROM @gt_report1 AS a )
SELECT DISTINCT
pa0032~pnalt, ""人员工号
pa0000~massn, ""操作类型
t529t~mntxt ""操作类型的名称 "
FROM +data AS a
INNER JOIN pa0032 ON pa0032~pnalt = a~pnalt
AND pa0032~endda = '99991231'
INNER JOIN pa0000 ON pa0000~pernr = pa0032~pernr
AND pa0000~endda = '99991231'
INNER JOIN t529t ON t529t~massn = pa0000~massn
AND t529t~sprsl = @sy-langu ""语言代码
WHERE pa0000~massn <> 'E1'
INTO CORRESPONDING FIELDS OF TABLE @gt_report2.
IF gt_report2[] IS NOT INITIAL.
SORT gt_report2 BY pnalt. ""人员工号
LOOP AT gt_report1 INTO gs_report1.
READ TABLE gt_report2 INTO gs_report2 WITH KEY pnalt = gs_report1-pnalt ""人员工号
BINARY SEARCH."
IF sy-subrc = 0.
gs_report1-zdelete = 'X'.
MODIFY gt_report1 FROM gs_report1 TRANSPORTING zdelete.
ENDIF.
ENDLOOP.
CLEAR:gs_report1,gs_report2.
DELETE gt_report1 WHERE zdelete = 'X'.
ENDIF.
CHECK gt_report1[] IS NOT INITIAL.
WITH +data AS ( SELECT * FROM @gt_report1 AS a )
SELECT
anla~bukrs, ""公司代码
anla~anln1, ""主资产号
anla~anln2, ""资产子编号
anla~anlkl, ""资产类
ankt~txk20, ""资产类描述
anla~gdlgrp, ""资产状态
t087s~gdlgrp_txt, ""资产状态文本
anlz~kostl, ""成本中心
cskt~ltext, ""成本中心描述
a~pnalt, ""人员工号
a~pernr, ""SAP工号
a~sname, ""员工姓名
a~massn, ""操作类型
a~mntxt ""操作类型的名称 "
FROM +data AS a
INNER JOIN anla ON anla~fiamt = a~pnalt
INNER JOIN ankt ON ankt~anlkl = anla~anlkl ""资产类
AND ankt~spras = @sy-langu ""语言代码
INNER JOIN anlz ON anlz~bukrs = anla~bukrs ""公司代码
AND anlz~anln1 = anla~anln1 ""主资产号
AND anlz~anln2 = anla~anln2 ""资产子编号
AND anlz~bdatu = '99991231'
INNER JOIN cskt ON cskt~kostl = anlz~kostl ""成本中心
AND cskt~spras = @sy-langu ""语言代码
AND cskt~kokrs = '2688'
AND cskt~datbi = '99991231'
INNER JOIN t087s ON t087s~gdlgrp = anla~gdlgrp ""资产状态
AND t087s~spras = @sy-langu ""语言代码
WHERE anla~fiamt IS NOT INITIAL
AND anla~bukrs IN @s_bukrs
AND anla~anln1 IN @s_anln1
AND anla~anln2 IN @s_anln2
AND anla~anlkl IN @s_anlkl
AND anlz~kostl IN @s_kostl
INTO CORRESPONDING FIELDS OF TABLE @gt_report3.
DELETE gt_report3 WHERE gdlgrp = '4'."出售
DELETE gt_report3 WHERE gdlgrp = '6'."报废
SORT gt_report3 BY bukrs anln1 anln2.
"额外计算,计算出多个SAP工号人员的资产
CHECK gt_report2[] IS NOT INITIAL.
WITH +data AS ( SELECT * FROM @gt_report2 AS a )
SELECT
anla~bukrs, ""公司代码
anla~anln1, ""主资产号
anla~anln2, ""资产子编号
anla~anlkl, ""资产类
ankt~txk20, ""资产类描述
anla~gdlgrp, ""资产状态
t087s~gdlgrp_txt, ""资产状态文本
anlz~kostl, ""成本中心
cskt~ltext, ""成本中心描述
pa0032~pnalt, ""人员工号
pa0000~pernr, ""SAP工号
pa0001~sname, ""员工姓名
pa0000~massn, ""操作类型
t529t~mntxt ""操作类型的名称 "
FROM +data AS a
INNER JOIN anla ON anla~fiamt = a~pnalt
INNER JOIN ankt ON ankt~anlkl = anla~anlkl ""资产类
AND ankt~spras = @sy-langu ""语言代码
INNER JOIN anlz ON anlz~bukrs = anla~bukrs ""公司代码
AND anlz~anln1 = anla~anln1 ""主资产号
AND anlz~anln2 = anla~anln2 ""资产子编号
AND anlz~bdatu = '99991231'
INNER JOIN cskt ON cskt~kostl = anlz~kostl ""成本中心
AND cskt~spras = @sy-langu ""语言代码
AND cskt~kokrs = '2688'
AND cskt~datbi = '99991231'
INNER JOIN t087s ON t087s~gdlgrp = anla~gdlgrp ""资产状态
AND t087s~spras = @sy-langu ""语言代码
INNER JOIN pa0032 ON pa0032~pnalt = anla~fiamt
AND pa0032~endda = '99991231'
INNER JOIN pa0000 ON pa0000~pernr = pa0032~pernr
AND pa0000~endda = '99991231'
INNER JOIN pa0001 ON pa0001~pernr = pa0032~pernr
AND pa0001~endda = '99991231'
INNER JOIN t529t ON t529t~massn = pa0000~massn
AND t529t~sprsl = @sy-langu ""语言代码
WHERE anla~fiamt IS NOT INITIAL
AND anla~bukrs IN @s_bukrs
AND anla~anln1 IN @s_anln1
AND anla~anln2 IN @s_anln2
AND anla~anlkl IN @s_anlkl
AND anlz~kostl IN @s_kostl
INTO CORRESPONDING FIELDS OF TABLE @gt_report4.
DELETE gt_report4 WHERE gdlgrp = '4'."出售
DELETE gt_report4 WHERE gdlgrp = '6'."报废
SORT gt_report4 BY bukrs anln1 anln2.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_LAYOUT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_alv_layout.
wa_layout-cwidth_opt = 'X'. "最适列宽
wa_layout-zebra = 'X'. "隔行显示斑马纹 使ALV表格按斑马线间隔条码方式显示
wa_layout-sel_mode = 'D'. "选择模式 "'D' 单元格的选择,可以多选单元格 多行,多列,任何单元格多选 用户可以使用最左边的选择按钮来选择多行
wa_layout-stylefname = 'CELLBTN'. "设置单元
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_FIELDCAT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_alv_fieldcat .
*----------------------------------------------------------------------*
* 定义宏
*----------------------------------------------------------------------*
DEFINE macro_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = &1. "标题列对应的字段名
ls_fieldcat-coltext = &2. "列标题 列标题,如果字段参考了DDIC,可不设置
ls_fieldcat-fix_column = &3. "固定列 与KEY字段类似,固定列但颜色不变蓝,必须要在左边才起作用(如果设置固定列的左边包含非固定列,则该列不固定)
ls_fieldcat-no_zero = &4. "是否隐藏输出为零的字段 当字段为数值为0时,不显示【如0,0.00,则会显示为空】当字段包含前导0时,隐藏前导0,【如0100,则会显示为100】
ls_fieldcat-cfieldname = &5. "currency unit field name值为当前输出内表中的货币单位字段的字段名称
ls_fieldcat-edit = &6. "准备输入 X:可编辑,space:不可编辑 该控制是在整列的级别上,如果想控制仅仅某一行可编辑,则需要通过style来控制
IF ls_fieldcat-outputlen IS INITIAL. "当coltext不存在显示filedtext,如字段没域,只有手工描述的情况
ls_fieldcat-outputlen = 40. "方便条件筛选
ENDIF.
APPEND ls_fieldcat TO lt_fieldcat.
END-OF-DEFINITION.
macro_fieldcat:
'BUKRS' '公司代码'(t01) 'X' '' '' '',
'ANLN1' '主资产号'(t02) 'X' '' '' '',
'ANLN2' '资产子编号 '(t03) '' '' '' '',
'ANLKL' '资产类 '(t04) '' '' '' '',
'TXK20' '资产类描述 '(t05) '' '' '' '',
'GDLGRP' '资产状态 '(t06) '' '' '' '',
'GDLGRP_TXT' '资产状态描述'(t07) '' '' '' '',
'KOSTL' '成本中心'(t08) '' '' '' '',
'LTEXT' '成本中心描述'(t09) '' '' '' '',
'PNALT' '人员工号'(t10) '' '' '' '',
'PERNR' 'SAP工号 '(t11) '' '' '' '',
'SNAME' '员工姓名'(t12) '' '' '' '',
'MASSN' '操作类型'(t13) '' '' '' '',
'MNTXT' '操作类型的名称 '(t14) '' '' '' ''."
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_ALV_OUTPUT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> GT_REPORT
*&---------------------------------------------------------------------*
FORM frm_alv_output TABLES p_gt_report LIKE gt_report1[].
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
i_callback_program = sy-repid
* i_callback_pf_status_set = 'FM_SET_STATUS'
i_callback_user_command = 'FM_USER_COMMAND'
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
is_layout_lvc = wa_layout
it_fieldcat_lvc = lt_fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS_LVC =
* it_sort_lvc = lt_sort
* IT_FILTER_LVC =
* IT_HYPERLINK =
* IS_SEL_HIDE =
i_default = 'X'
i_save = 'A' " 'U'
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT_LVC =
* IS_REPREP_ID_LVC =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP =
* I_HTML_HEIGHT_END =
* IT_ALV_GRAPHICS =
* IT_EXCEPT_QINFO_LVC =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = p_gt_report
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
"LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM.
FORM fm_user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield.
rs_selfield-refresh = 'X'.
CASE r_ucomm.
WHEN '&IC1'. "
IF NOT p_p1 = 'X'.
IF gt_report3 IS NOT INITIAL.
READ TABLE gt_report3 ASSIGNING <fs_com> INDEX rs_selfield-tabindex."
PERFORM command_action USING rs_selfield-fieldname.
ENDIF.
ELSE.
IF gt_report4 IS NOT INITIAL.
READ TABLE gt_report4 ASSIGNING <fs_com> INDEX rs_selfield-tabindex."
PERFORM command_action USING rs_selfield-fieldname.
ENDIF.
ENDIF.
ENDCASE.
ENDFORM.
FORM command_action USING fieldname.
"双击栏位后跳转
TRANSLATE fieldname TO UPPER CASE. "将栏位名称转换为大写
CASE fieldname.
WHEN 'ANLN1'.
IF <fs_com>-bukrs IS NOT INITIAL
AND <fs_com>-anln1 IS NOT INITIAL
AND <fs_com>-anln2 IS NOT INITIAL.
SET PARAMETER ID: 'BUK' FIELD <fs_com>-bukrs.
SET PARAMETER ID: 'AN1' FIELD <fs_com>-anln1.
SET PARAMETER ID: 'AN2' FIELD <fs_com>-anln2.
IF sy-subrc = 0.
CALL TRANSACTION 'AS03' AND SKIP FIRST SCREEN. "跳过第一个屏幕到FB03屏幕
ENDIF.
ENDIF.
ENDCASE.
ENDFORM.
AS02修改保管人(税务局)
点击“技术信息”
双击主程序:SAPLAIST
查找包含:LAISTI59
转至行
输入行号