说明: 通过动态参数获取字段数据,抓取有规则列的字段值
在程序开发中,可能会遇到一些规则的字段名,在数据传递中通常需要对这些字段逐个赋值,以下报表是通过动态参数从数据表(结构体)中获取数据。
在透明表 FAGLFLEXT中,用于总账总计,每个月的增加减少额都分别用TSL01,TSL02…… TSL16(16列)记录下来,这些字段是有规则的,可以通过动态字段方便的获取其数据。
例子:
FIELD-SYMBOLS:
DATA: FIELDNAME TYPE STRING. " 定义变量用于保存字段名
" 每月数据——专用
DATA: BEGIN OF it_month OCCURS 0,
RYEAR LIKE FAGLFLEXT-RYEAR, " 会计年度
RACCT LIKE FAGLFLEXT-RACCT, " 会计科目
RBUKRS LIKE FAGLFLEXT-RBUKRS, " 公司代码
RTCUR LIKE FAGLFLEXT-RTCUR, " 货币
DRCRK LIKE FAGLFLEXT-DRCRK, " 借贷标识
TSLVT TYPE TSLVT12, " 起初账面余额
TSL01 TYPE TSLXX12, " 每月(Month)减少额(JS)
TSL02 TYPE TSLXX12,
TSL03 TYPE TSLXX12,
TSL04 TYPE TSLXX12,
TSL05 TYPE TSLXX12,
TSL06 TYPE TSLXX12,
TSL07 TYPE TSLXX12,
TSL08 TYPE TSLXX12,
TSL09 TYPE TSLXX12,
TSL10 TYPE TSLXX12,
TSL11 TYPE TSLXX12,
TSL12 TYPE TSLXX12,
END OF it_month.
" 结果内表
" 累计增加、减少分开记录,不再保留借贷标识
data: BEGIN OF it_out OCCURS 0,
RYEAR LIKE FAGLFLEXT-RYEAR, " 会计年度
ZMON LIKE FAGLFLEXT-RPMAX, " 当前月份
RACCT LIKE FAGLFLEXT-RACCT, " 会计科目
TXT50 TYPE TEXT50, " 会计科目描述
RBUKRS LIKE FAGLFLEXT-RBUKRS, " 公司代码
RTCUR LIKE FAGLFLEXT-RTCUR, " 货币
TSL_ZJ TYPE TSLVT12, " 当月增加
TSL_JS TYPE TSLVT12, " 当月减少
TSL_ZJLJ TYPE TSLVT12, " 增加累计
TSL_JSLJ TYPE TSLVT12, " 减少累计
TSLVT TYPE TSLVT12, " 期初账面余额
TSLVT_QM TYPE TSLVT12, " 期末账面余额
SEL,
END OF it_out.
*…………………………
*…………………………
*…………………………
* 提取当月的增、减额;计算期末金额
CLEAR it_out.
LOOP AT it_out.
LOOP at it_month WHERE RYEAR = it_out-RYEAR
AND RACCT = it_out-RACCT
AND RBUKRS = it_out-RBUKRS
AND RTCUR = it_out-RTCUR .
" 提取当月增减额。
CONCATENATE 'TSL' p_month+1(02) INTO FIELDNAME.
ASSIGN COMPONENT FIELDNAME OF STRUCTURE it_month TO
if it_month-DRCRK = 'H'.
it_out-TSL_ZJ =
elseif it_month-DRCRK = 'S'.
it_out-TSL_JS =
endif.
" it_month的期初账面余额 是汇总后的,但是分了HS 。it_out的期初余额汇总所有的,不再区分HS。
it_out-TSLVT = it_out-TSLVT + it_month-TSLVT .
endloop.
it_out-TSLVT_QM = it_out-TSLVT + it_out-TSL_ZJLJ + it_out-TSL_JSLJ .
READ TABLE it_KM with key SAKNR = it_out-RACCT.
it_out-TXT50 = it_KM-TXT50.
modify it_out.
ENDLOOP.
SORT it_out by RYEAR RACCT RBUKRS RTCUR.
DELETE ADJACENT DUPLICATES FROM it_out.