ABAP顾问
分类:
2007-06-21 11:07:41
*&---------------------------------------------------------------------*
*& Report Z_BARRY_REPORT_VARIANT_CHANGE
*&
*&---------------------------------------------------------------------*
*& Codeing更改程序变式的值
*& 本例为点击"执行"后变式内的日期加一天
*& 而且包含如何把格式化的日期转换为内部日期的代码
*&---------------------------------------------------------------------*
REPORT z_barry_report_variant_change .
TABLES usr01 .
DATA: l_report LIKE rsvar-report,
l_varia LIKE rsvar-variant,
i_rc LIKE sy-subrc.
DATA: itab_variant_values LIKE rsparams OCCURS 0 WITH HEADER LINE,
wa_techn_data LIKE varid.
DATA: tmpdate LIKE sy-datum .
DATA: str(10).
PARAMETERS p_date LIKE sy-datum .
START-OF-SELECTION.
l_varia = 'TEST'.
l_report = sy-repid .
CALL FUNCTION 'RS_VARIANT_EXISTS'
EXPORTING
report = l_report
variant = l_varia
IMPORTING
r_c = i_rc
EXCEPTIONS
not_authorized = 1
no_report = 2
report_not_existent = 3
report_not_supplied = 4
OTHERS = 5.
CHECK i_rc = 0.
CALL FUNCTION 'RS_VARIANT_VALUES_TECH_DATA'
EXPORTING
report = l_report
variant = l_varia
IMPORTING
techn_data = wa_techn_data
TABLES
variant_values = itab_variant_values
EXCEPTIONS
variant_non_existent = 1
variant_obsolete = 2
OTHERS = 3.
READ TABLE itab_variant_values WITH KEY selname = 'P_DATE'.
IF sy-subrc = 0.
SELECT SINGLE * FROM usr01 WHERE bname = sy-uname.
CALL FUNCTION 'DATE_STRING_CONVERT' "格式化日期转为内部日期
EXPORTING
date_format = usr01-datfm
date_string = itab_variant_values-low
IMPORTING
result_date = tmpdate.
tmpdate = tmpdate + 1.
itab_variant_values-low = tmpdate.
MODIFY itab_variant_values INDEX sy-tabix.
ENDIF.
CALL FUNCTION 'RS_CHANGE_CREATED_VARIANT'
EXPORTING
curr_report = l_report
curr_variant = l_varia
vari_desc = wa_techn_data
TABLES
vari_contents = itab_variant_values
EXCEPTIONS
illegal_report_or_variant = 1
illegal_variantname = 2
not_authorized = 3
not_executed = 4
report_not_existent = 5
report_not_supplied = 6
variant_doesnt_exist = 7
variant_locked = 8
selections_no_match = 9
OTHERS = 10.