在自定义程序的开发中,涉及到对IP41的编程,使用BDC进行编程,需要进行几个相关问题的处理
1.计划开始日期限定为时间类型
2.周期必须为天的整数倍
3.如果在计划开始日期的当天就能运行处第一个工单,那么需要将该日期提前一个周期(计划开始日期在开发的程序界面填写)
对于1,2,见如下代码
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_TIME
*&---------------------------------------------------------------------*
* 校验填写的时间是否为天的整数倍
*----------------------------------------------------------------------*
* -->P_GS_HEAD_200_ZYKL1 text
* -->P_GS_HEAD_200_ZEIEH text
*----------------------------------------------------------------------*
form frm_check_time using up_zykl1 like zzpmttzsxm-zykl1
up_zeieh like zzpmttzsxm-zeieh.
data: lv_sec_zykl1 like mmpt-zykl1. "以秒为单位的周期
data: rest_tag like mmpt-zykl1.
data: lv_zykl1 like zzpmttzsxm-zykl1.
lv_zykl1 = up_zykl1.
perform char_fltp_conversion_pak_f40
using lv_zykl1 "周期
lv_sec_zykl1 "返回以秒计算的周期数
up_zeieh. "周期单位
perform fltp_char_conversion_pak_f40
using lv_zykl1
lv_sec_zykl1
up_zeieh.
if not ( lv_sec_zykl1 is initial ).
clear rest_tag.
rest_tag = lv_sec_zykl1 mod 86400. "判断是否能被一天的秒数整除
if rest_tag <> 0.
message e000(zdev) with '必须为天的整数倍'.
endif.
endif.
endform. " FRM_CHECK_TIME
*&---------------------------------------------------------------------*
*& Form CHAR_FLTP_CONVERSION_PAK_F40
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->CHAR_WERT text
* -->FLTP_WERT text
* -->EINHEIT text
*----------------------------------------------------------------------*
form char_fltp_conversion_pak_f40 using char_wert
fltp_wert
einheit.
data: dec_max like t006-decan value '15'.
data: dec_char like t006-decan.
call function 'CHAR_FLTP_CONVERSION_TO_SI'
exporting
char_unit = einheit
char_value = char_wert
decimals_max = dec_max
field_name = ' '
masc_symbol = ' '
importing
fltp_value_si = fltp_wert
decimals = dec_char
exceptions
no_unit_given = 1.
* CASE sy-subrc.
* WHEN '1'.
* SET CURSOR FIELD 'RMIPM-ZEIEH'.
* MESSAGE e044(ir). "nicht mit Masseinheit
* ENDCASE.
if dec_char ne 0.
message e000 with '不能有小数位'.
endif.
endform. "CHAR_FLTP_CONVERSION_PAK_F40
*&---------------------------------------------------------------------*
*& Form fltp_char_conversion_pak_f40
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->CHAR_WERT text
* -->FLTP_WERT text
* -->EINHEIT text
*----------------------------------------------------------------------*
form fltp_char_conversion_pak_f40 using char_wert
fltp_wert
einheit.
clear char_wert.
check not einheit is initial.
call function 'FLTP_CHAR_CONVERSION_FROM_SI'
exporting
char_unit = einheit
decimals = 0
exponent = 0
fltp_value_si = fltp_wert
indicator_value = 'X'
masc_symbol = ' '
importing
char_value = char_wert.
endform. "fltp_char_conversion_pak_f40
对于第三点,需要将日期提前一个周期,相关计算逻辑及IP41的BDC程序如下:
form frm_bdc_ip41 changing cs_template like gs_template
cp_error type c.
data:
l_zykl1_out like t006a-mseh3,
l_ndate like sy-datum,
l_warpl like zzpmttemplate-warpl,
lt_bdcmsg like standard table of bdcmsgcoll with header line.
data:lv_sec_zykl1 like mmpt-zykl1,
lv_days type i,
lv_days_f(2) type n. "函数参数
clear cp_error.
"将内表数据转换为输出格式
write cs_template-zeieh to l_zykl1_out.
"计算开始日期 = 下次开始日期 - 周期
"首先将周期转换为以秒为单位的周期
perform char_fltp_conversion_pak_f40
using cs_template-zykl1
lv_sec_zykl1
cs_template-zeieh.
lv_days = lv_sec_zykl1 / cns_sec_tag. "前面校验过整数倍
"由于函数的天数只有2位,所以最大值为99天,因此对于大于99天
"的周期,需要多次减,才能得到正确的日期(不能直接以30天转化为月)
l_ndate = cs_template-ndate.
do.
if lv_days >= 99.
lv_days_f = 99.
else.
lv_days_f = lv_days.
endif.
call function 'RP_CALC_DATE_IN_INTERVAL'
exporting
date = l_ndate
days = lv_days_f
months = 00
signum = '-'
years = 00
importing
calc_date = l_ndate.
lv_days = lv_days - 99.
if lv_days <= 0.
exit.
endif.
enddo.
write l_ndate to l_ndate. "转换格式,BDC用
call function 'CONVERSION_EXIT_CUNIT_OUTPUT'
exporting
input = cs_template-zeieh
language = '1'
importing
* LONG_TEXT =
output = l_zykl1_out
* SHORT_TEXT =
exceptions
unit_not_found = 1
others = 2
.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
* 1.0 BDC IP41
refresh:gt_bdcdata[],lt_bdcmsg[].
perform frm_fill_bdc using: 'X' 'SAPLIWP3' '0100',
' ' 'BDC_OKCODE' '/00',
' ' 'RMIPM-MPTYP' 'PM',
'X' 'SAPLIWP3' '0201',
'' 'BDC_OKCODE' '/00',
'' 'RMIPM-WPTXT' cs_template-name1,
'' 'RMIPM-PSTXT' cs_template-name1,
'' 'RIWO1-TPLNR' cs_template-tplnr,
'' 'RMIPM-IWERK' cs_template-werks,
'' 'RMIPM-WPGRP' cs_template-jxbm ,
'' 'RMIPM-AUART' cs_template-jxlx,
'' 'RMIPM-GEWERK' cs_template-jxxz,
'' 'RMIPM-WERGW' cs_template-werks,
'' 'RMIPM-ZYKL1' cs_template-zykl1,
"单位转换
'' 'RMIPM-ZEIEH' l_zykl1_out,
"us_template-zeieh,
'X' 'SAPLIWP3' '0201',
'' 'BDC_OKCODE' '=T\02',
'' 'RMIPM-PRIOK' cs_template-priok, "优先级
'X' 'SAPLIWP3' '0201',
'' 'BDC_OKCODE' '=TX',
* '' 'BDC_OKCODE' '=BU',
'' 'RMIPM-ABRHO' cns_ip41_days,
'' 'RMIPM-HUNIT' cns_ip41_days_unit,
'' 'RMIPM-HORIZ' '100', "100%
'' 'RMIPM-STADT' l_ndate, "long text
* "给一个默认值,先激活文本,否则后面Save Text函数不能保存
'X' 'SAPLSTXX' '1100',
'' 'RSTXT-TXLINE(02)' '.',
'' 'BDC_OKCODE' '=TXBA', "back
'X' 'SAPLIWP3' '0201',
'' 'BDC_OKCODE' '=BU' . "save
"us_template-ndate.
call transaction 'IP41' using gt_bdcdata
mode g_mode
update 'S'
messages into lt_bdcmsg.
" 保存消息,待显示
append lines of lt_bdcmsg to gt_bdcmsg.
"判断是否成功
clear cp_error.
loop at lt_bdcmsg where msgtyp = 'E' or msgtyp = 'A'.
cp_error = 'X'.
exit.
endloop.
if cp_error is initial.
commit work and wait.
else.
rollback work.
* MESSAGE e000(zdev) WITH '模板启用失败,'
* '调用TCODE:IP41生成维护计划失败'.
return.
endif.
"若成功,在消息内表中找到新生成的号码
read table lt_bdcmsg with key msgtyp = 'S'
msgid = 'IP'
msgnr = '200'.
if sy-subrc eq 0.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = lt_bdcmsg-msgv1
importing
output = l_warpl. "维护计划
endif.
* 1.1 todo Save_text写入长文本
perform frm_save_ip41_text using cs_template.
endform. " FRM_BDC_IP41