一:故事背景
SAP的核算其实比较麻烦的就是没地方可以导出核算成功的人员编号,即使能导出也是树形的结构,需要反复加工多次才能整理好员工,所以非常麻烦,今天就想能不能抓取模拟工资的rt表数据.
二:解决办法
是不是能开发一个程序,抓取模拟工资结果的数据,抓到的数据不就能和工资明细表做对比吗?还有很多客户是想看看模拟工资结果的alv数据,是不是这个方案也一并解决。下面就是一个模拟的例子,网上看到老外写的一个例子,但是是加拿大的,所以开始一直不生效,后来分析下需要修改几行代码,修改的代码已经标记红色,有兴趣的人可以去研究下。所以我这个是中国版的,应该也算是原创吧,哈哈!!!
REPORT ZTEST12.
TYPE-POOLS: hrpay.
TABLES: pcl1, "IMPORT/EXPORT
pcl2. "IMPORT/EXPORT
DATA: molga(2) TYPE c.
DATA: buffer TYPE hrpay_buffer.
DATA: rgdir_line LIKE pc261.
DATA: sim_pernr LIKE pay_sim_pernr OCCURS 0 WITH HEADER LINE.
INCLUDE rpc2cd09.
INCLUDE rpc2rx02.
INCLUDE rpppxd00.
INCLUDE rpppxd10.
INCLUDE rpppxm00.
"INCLUDE rpc2rkk0.
INCLUDE PC2RXCN0. “”因为每个国家的簇表标识不一样
INCLUDE rpc2rx29.
INCLUDE rpc2rx39.
"INCLUDE rpcxrkk0.
PARAMETERS: p_area TYPE t549a-abkrs,
p_period TYPE t549q-pabrp,
p_year TYPE t549q-pabrj,
p_pernr TYPE persno,
p_var TYPE vari-variant,
p_prog TYPE trdir-name DEFAULT 'HCNCALC0' NO-DISPLAY.
START-OF-SELECTION.
sim_pernr-pernr = p_pernr.
APPEND sim_pernr.
CALL FUNCTION 'HR_PAYROLL'
EXPORTING
payroll_area = p_area
payroll_period = p_period
payroll_year = p_year
selection_variant = p_var
program_name = p_prog
TST_ON = 'X'
TABLES
employee_numbers = sim_pernr
buffer = tbuff
buffer_directory = buffer_dir
delete_pclx = del_pclx_tab
EXCEPTIONS
program_not_exist = 1
variant_not_exist = 2
missing_parameter = 3
wrong_parameter = 4
wrong_country_group = 5
OTHERS = 6
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
buffer-tbuff[] = tbuff[].
buffer-buffer_dir[] = buffer_dir[].
buffer-del_pclx_tab[] = del_pclx_tab[].
CALL FUNCTION 'CU_READ_RGDIR'
EXPORTING
persnr = sim_pernr-pernr
buffer = buffer
IMPORTING
molga = molga
TABLES
in_rgdir = rgdir
EXCEPTIONS
no_record_found = 1
OTHERS = 2.
CALL FUNCTION 'CD_READ_LAST_RESULT_IN_RGDIR'
IMPORTING
ptx_rgdir_nv = rgdir_line
TABLES
pt_rgdir = rgdir.
rx-key-pernr = sim_pernr-pernr.
rx-key-seqno = rgdir_line-seqnr.
rp-imp-c2-CN.
IF rp-imp-CN-subrc = 0.
READ TABLE rgdir INDEX 1.
WRITE: / 'fpper:', rgdir-fpper, 'inper:', rgdir-inper, 'srtza:', rgdir-srtza.
WRITE: /.
LOOP AT rt.
WRITE: / rt-lgart, rt-betpe, rt-anzhl, rt-betrg.
ENDLOOP.
ENDIF.
BREAK-POINT.