首先简单介绍一下DOI,以下描述来自于网上:
OLE是SAP早期与微软Office集成的工具,而DOI是它的替代技术。在实际项目中使用到OLE&DOI的场合多是EXCEL表格的读入或是填制。有些需要自动画表格及填数据,有的只是要求在原有的模版上填制数据。根据不同的场合可以选用不同的技术。
DOI实现把excel嵌入到程序中,需要上传一个写入数据的excel模板,这个模板中个人认为是不能实现动态的合并单元格(自己没找到方法,如有方法,请私信我)。
DOI实现步骤:
1.上传excel模板
T-CODE:OAOR
准备好一个excel模板,这个模板是用来向里面填充数据的,上传效果如图:
2.代码实现
*&----------------------------------------------------------*
*& Form FRM_DO_DOI
*&----------------------------------------------------------*
* text DOI处理
*-----------------------------------------------------------*
FORM FRM_DO_DOI .
"得到填充数据
PERFORM FRM_GET_DATA_FOR_EXCEL USING WA_TAB1_DOI.
" 创建EXCEL输出的一些基本对象
PERFORM CREATE_BASIC_OBJECTS USING '' '' '' '' DOCUMENT_NAME.
"EXCEL输出
PERFORM OUTPUT_TO_EXCEL USING WA_TAB1_DOI IT_BBAT.
ENDFORM. " FRM_DO_DOI
*&----------------------------------------------------------*
*& Form FRM_GET_DATA_FOR_EXCEL
*&----------------------------------------------------------*
* text 得到填充excel的数据
*-----------------------------------------------------------*
FORM FRM_GET_DATA_FOR_EXCEL USING P_WA_BBAT LIKE WA_TAB1.
SELECT
ZROWID
ITMID
ITMTY
DMBTR
ZDATE
ZTEXT
INTO CORRESPONDING FIELDS OF TABLE IT_BBAT
FROM ZFIB002
WHERE SAKNR = P_WA_BBAT-SAKNR AND BUKRS = P_WA_BBAT-BUKRS
AND ZDELF <> 'X'. "没有删除标志
IF IT_BBAT IS INITIAL.
MESSAGE '指定关键字的数据没有找到!' TYPE 'S'.
LEAVE TO SCREEN 0.
ENDIF.
ENDFORM. " FRM_GET_DATA_FOR_EXCEL
*&----------------------------------------------------------*
*& Form CREATE_BASIC_OBJECTS
*&----------------------------------------------------------*
* text 创建DOI所需对象
*-----------------------------------------------------------*
FORM CREATE_BASIC_OBJECTS USING P_APP_NAME P_CLASSNAME
P_CLASSTYPE P_OBJ_KEY P_DOCNAME.
DATA: L_APP_NAME(200),
BDS_INSTANCE TYPE REF TO CL_BDS_DOCUMENT_SET,
DOC_SIGNATURE TYPE SBDST_SIGNATURE,
WA_DOC_SIGNATURE LIKE LINE OF DOC_SIGNATURE,
DOC_COMPONENTS TYPE SBDST_COMPONENTS,
DOC_URIS TYPE SBDST_URI,
WA_DOC_URIS LIKE LINE OF DOC_URIS.
"OAOR上传模板的参数(在上传参数的时候填写的类,类型,对象)
DATA: DOC_CLASSNAME TYPE SBDST_CLASSNAME VALUE 'ZDFAM_EXCEL',
DOC_CLASSTYPE TYPE SBDST_CLASSTYPE VALUE 'OT',
DOC_OBJECT_KEY TYPE SBDST_OBJECT_KEY VALUE 'ZFI_BANK_BBAT'.
DATA: HAS TYPE I.
CHECK INITIALIZED IS INITIAL.
IF P_APP_NAME IS INITIAL.
L_APP_NAME = 'R/3 Reporter'.
ELSE.
L_APP_NAME = P_APP_NAME.
ENDIF.
IF NOT ( P_CLASSNAME IS INITIAL OR P_CLASSTYPE IS INITIAL
OR P_OBJ_KEY IS INITIAL ).
DOC_CLASSNAME = P_CLASSNAME.
DOC_CLASSTYPE = P_CLASSTYPE.
DOC_OBJECT_KEY = P_OBJ_KEY.
ENDIF.
CALL METHOD C_OI_CONTAINER_CONTROL_CREATOR=>GET_CONTAINER_CONTROL
IMPORTING
CONTROL = DOI_CONTROL "CONTROL TYPE REF TO I_OI_CONTAINER_CONTROL,
ERROR = DOI_ERROR.
CALL METHOD DOI_ERROR->RAISE_MESSAGE
EXPORTING
TYPE = 'E'.
"创建一个屏幕和容器Z_FI_BANK_CON03
CREATE OBJECT DOI_CONTAINER
EXPORTING
CONTAINER_NAME = 'Z_FI_BANK_CON03'.
CALL METHOD DOI_CONTROL->INIT_CONTROL
EXPORTING
R3_APPLICATION_NAME = L_APP_NAME
INPLACE_ENABLED = INPLACE
INPLACE_SCROLL_DOCUMENTS = 'X'
PARENT = DOI_CONTAINER
REGISTER_ON_CLOSE_EVENT = 'X'
REGISTER_ON_CUSTOM_EVENT = 'X'
NO_FLUSH = 'X'
IMPORTING
ERROR = DOI_ERRORS.
APPEND DOI_ERRORS.
CLEAR ITEM_URL.
WA_DOC_SIGNATURE-PROP_NAME = 'DESCRIPTION'.
DOCUMENT_TYPE = EXCEL.
WA_DOC_SIGNATURE-PROP_VALUE = P_DOCNAME.
APPEND WA_DOC_SIGNATURE TO DOC_SIGNATURE.
CREATE OBJECT BDS_INSTANCE.
CALL METHOD BDS_INSTANCE->GET_INFO
EXPORTING
CLASSNAME = DOC_CLASSNAME
CLASSTYPE = DOC_CLASSTYPE
OBJECT_KEY = DOC_OBJECT_KEY
CHANGING
COMPONENTS = DOC_COMPONENTS
SIGNATURE = DOC_SIGNATURE.
CALL METHOD BDS_INSTANCE->GET_WITH_URL
EXPORTING
CLASSNAME = DOC_CLASSNAME
CLASSTYPE = DOC_CLASSTYPE
OBJECT_KEY = DOC_OBJECT_KEY
CHANGING
URIS = DOC_URIS
SIGNATURE = DOC_SIGNATURE.
FREE BDS_INSTANCE.
READ TABLE DOC_URIS INTO WA_DOC_URIS INDEX 1.
ITEM_URL = WA_DOC_URIS-URI.
CALL METHOD DOI_CONTROL->GET_DOCUMENT_PROXY
EXPORTING
DOCUMENT_TYPE = 'Excel.Sheet'
NO_FLUSH = 'X'
IMPORTING
DOCUMENT_PROXY = DOI_DOCUMENT
ERROR = DOI_ERRORS.
APPEND DOI_ERRORS.
* open a document saved in business document service
CALL METHOD DOI_DOCUMENT->OPEN_DOCUMENT
EXPORTING
OPEN_INPLACE = INPLACE
DOCUMENT_URL = ITEM_URL.
CALL METHOD DOI_DOCUMENT->HAS_SPREADSHEET_INTERFACE
EXPORTING
NO_FLUSH = ''
IMPORTING
IS_AVAILABLE = HAS
ERROR = DOI_ERRORS.
APPEND DOI_ERRORS.
CALL METHOD DOI_DOCUMENT->GET_SPREADSHEET_INTERFACE
EXPORTING
NO_FLUSH = ' '
IMPORTING
SHEET_INTERFACE = DOI_SPREADSHEET
ERROR = DOI_ERRORS.
APPEND DOI_ERRORS.
* Activate sheet
CALL METHOD DOI_SPREADSHEET->SELECT_SHEET
EXPORTING
NAME = ACTIVE_SHEET
NO_FLUSH = ''
IMPORTING
ERROR = DOI_ERRORS.
APPEND DOI_ERRORS.
LOOP AT DOI_ERRORS.
CALL METHOD DOI_ERRORS->RAISE_MESSAGE
EXPORTING
TYPE = 'S'.
ENDLOOP.
FREE DOI_ERRORS.
INITIALIZED = 'X'.
ENDFORM. " CREATE_BASIC_OBJECTS
*&----------------------------------------------------------*
*& Form OUTPUT_TO_EXCEL
*&----------------------------------------------------------*
* text 输出数据到EXCEL
*-----------------------------------------------------------*
FORM OUTPUT_TO_EXCEL USING P_WA_TAB1_DOI LIKE WA_TAB1
P_IT_BBAT LIKE IT_BBAT.
DATA: TMPDATE(10) TYPE C,
G_STR(20) TYPE C,
NUM_RESULT(50) TYPE C,
CHAR_RESULT(50) TYPE C,
LAST_DAY LIKE SY-DATUM,
SUB_NUM TYPE P DECIMALS 3 ,
ROW_A TYPE I VALUE 6 ,
ROW_B TYPE I VALUE 6 ,
ROW_C TYPE I,
ROW_D TYPE I,
ROW_N TYPE I,
SUM_A TYPE P DECIMALS 3,
SUM_B TYPE P DECIMALS 3,
SUM_C TYPE P DECIMALS 3,
SUM_D TYPE P DECIMALS 3.
G_STR = P_WA_TAB1_DOI-TXT20. "1银行
PERFORM GET_STR_BY_TYPE USING G_STR CHANGING NUM_RESULT CHAR_RESULT.
PERFORM FILL_CELL USING 2 2 CHAR_RESULT.
CLEAR : NUM_RESULT ,CHAR_RESULT.
G_STR = P_WA_TAB1_DOI-TXT50. "2账号
PERFORM GET_STR_BY_TYPE USING G_STR CHANGING NUM_RESULT CHAR_RESULT.
PERFORM FILL_CELL USING 3 2 NUM_RESULT.
CLEAR : NUM_RESULT ,CHAR_RESULT.
PERFORM FRM_GET_LAST_DAY USING P_RPMAX CHANGING LAST_DAY. "3日期
PERFORM FILL_CELL USING 2 6 LAST_DAY.
CLEAR : LAST_DAY.
*&---表格抬头-----------------------------------------------*
G_STR = P_WA_TAB1_DOI-WAERS. "4货币
PERFORM FILL_CELL USING 3 6 G_STR.
G_STR = P_WA_TAB1_DOI-DMBTR. "5银行余额
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT' "数字负号提前
CHANGING
VALUE = G_STR.
PERFORM FILL_CELL USING 4 2 G_STR.
IF P_WA_TAB1_DOI-WAERS = 'CNY'. "6账簿余额
G_STR = P_WA_TAB1_DOI-FLCHA.
ELSE.
G_STR = P_WA_TAB1_DOI-FFCHA.
ENDIF.
SUB_NUM = G_STR. "记录账簿余额
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT' "数字负号提前
CHANGING
VALUE = G_STR.
PERFORM FILL_CELL USING 4 6 G_STR.
G_STR = P_WA_TAB1_DOI-DMBTR - SUB_NUM. "差额
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT' "数字负号提前
CHANGING
VALUE = G_STR.
PERFORM FILL_CELL USING 2 8 G_STR.
*&---表格内容-----------------------------------------------*
SORT P_IT_BBAT BY ITMID.
CLEAR : SUM_A,SUM_B,SUM_C,SUM_D.
"对于A B项目类别进行填充
LOOP AT P_IT_BBAT INTO WA_BBAT.
CASE WA_BBAT-ITMID.
WHEN 'A'. "账簿已增银行未增
"项目类别
G_STR = WA_BBAT-ITMTY.
PERFORM FILL_CELL USING ROW_A 1 G_STR.
"9手工调节金额
G_STR = WA_BBAT-DMBTR.
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT' "数字负号提前
CHANGING
VALUE = G_STR.
PERFORM FILL_CELL USING ROW_A 2 G_STR.
"日期
G_STR = WA_BBAT-ZDATE.
PERFORM FILL_CELL USING ROW_A 3 G_STR.
"未达账项说明
G_STR = WA_BBAT-ZTEXT.
PERFORM FILL_CELL USING ROW_A 4 G_STR.
ROW_A = ROW_A + 1.
SUM_A = SUM_A + WA_BBAT-DMBTR.
WHEN 'B'. "银行已增账簿未增
"项目类别
G_STR = WA_BBAT-ITMTY.
PERFORM FILL_CELL USING ROW_B 5 G_STR.
"9手工调节金额
G_STR = WA_BBAT-DMBTR.
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT' "数字负号提前
CHANGING
VALUE = G_STR.
PERFORM FILL_CELL USING ROW_B 6 G_STR.
"日期
G_STR = WA_BBAT-ZDATE.
PERFORM FILL_CELL USING ROW_B 7 G_STR.
"未达账项说明
G_STR = WA_BBAT-ZTEXT.
PERFORM FILL_CELL USING ROW_B 8 G_STR.
ROW_B = ROW_B + 1.
SUM_B = SUM_B + WA_BBAT-DMBTR.
ENDCASE.
ENDLOOP.
"8账簿已增银行未增合计
G_STR = SUM_A.
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT' "数字负号提前
CHANGING
VALUE = G_STR.
PERFORM FILL_CELL USING 5 2 G_STR.
"10银行已增账簿未增合计
G_STR = SUM_B.
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT' "数字负号提前
CHANGING
VALUE = G_STR.
PERFORM FILL_CELL USING 5 6 G_STR.
"删除项目类别为A和B的数据
DELETE IT_BBAT WHERE ITMID = 'A' OR ITMID = 'B' .
IF ROW_A > ROW_B.
ROW_C = ROW_A + 1.
ROW_D = ROW_A + 1.
ROW_N = ROW_A. "用于填充新的行标题
ELSE.
ROW_C = ROW_B + 1.
ROW_D = ROW_B + 1.
ROW_N = ROW_B.
ENDIF.
"新的一个小表头
G_STR = DATE_STR. "日期
PERFORM FILL_CELL USING ROW_N 3 G_STR.
G_STR = TXT_STR. "未达款项说明
PERFORM FILL_CELL USING ROW_N 4 G_STR.
G_STR = DATE_STR. "日期
PERFORM FILL_CELL USING ROW_N 7 G_STR.
G_STR = TXT_STR. "未达款项说明
PERFORM FILL_CELL USING ROW_N 8 G_STR.
"对于C D项目类别进行填充
LOOP AT P_IT_BBAT INTO WA_BBAT.
CASE WA_BBAT-ITMID.
WHEN 'C'. "账簿已增银行未增
"项目类别
G_STR = WA_BBAT-ITMTY.
PERFORM FILL_CELL USING ROW_C 1 G_STR.
"9手工调节金额
G_STR = WA_BBAT-DMBTR.
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT' "数字负号提前
CHANGING
VALUE = G_STR.
PERFORM FILL_CELL USING ROW_C 2 G_STR.
"日期
G_STR = WA_BBAT-ZDATE.
PERFORM FILL_CELL USING ROW_C 3 G_STR.
"未达账项说明
G_STR = WA_BBAT-ZTEXT.
PERFORM FILL_CELL USING ROW_C 4 G_STR.
ROW_C = ROW_C + 1.
SUM_C = SUM_C + WA_BBAT-DMBTR.
WHEN 'D'. "银行已增账簿未增
"项目类别
G_STR = WA_BBAT-ITMTY.
PERFORM FILL_CELL USING ROW_D 5 G_STR.
"9手工调节金额
G_STR = WA_BBAT-DMBTR.
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT' "数字负号提前
CHANGING
VALUE = G_STR.
PERFORM FILL_CELL USING ROW_D 6 G_STR.
"日期
G_STR = WA_BBAT-ZDATE.
PERFORM FILL_CELL USING ROW_D 7 G_STR.
"未达账项说明
G_STR = WA_BBAT-ZTEXT.
PERFORM FILL_CELL USING ROW_D 8 G_STR.
ROW_D = ROW_D + 1.
SUM_D = SUM_D + WA_BBAT-DMBTR.
ENDCASE.
ENDLOOP.
"8账簿已增银行未增合计
G_STR = SUM_C.
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT' "数字负号提前
CHANGING
VALUE = G_STR.
PERFORM FILL_CELL USING ROW_N 2 G_STR.
"10银行已增账簿未增合计
G_STR = SUM_D.
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT' "数字负号提前
CHANGING
VALUE = G_STR.
PERFORM FILL_CELL USING ROW_N 6 G_STR.
"得到表未开始填充的行
IF ROW_C > ROW_D.
ROW_N = ROW_C. "用于填充新的行标题
ELSE.
ROW_N = ROW_D.
ENDIF.
"相对相符数
G_STR = OPT_NUM.
PERFORM FILL_CELL USING ROW_N 1 G_STR.
"16 = 5 + 8 - 12
G_STR = P_WA_TAB1_DOI-DMBTR + SUM_A - SUM_C.
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT' "数字负号提前
CHANGING
VALUE = G_STR.
PERFORM FILL_CELL USING ROW_N 2 G_STR.
"相对相符数
G_STR = OPT_NUM.
PERFORM FILL_CELL USING ROW_N 5 G_STR.
"17 = 6 + 11 - 14
G_STR = SUB_NUM + SUM_B - SUM_D.
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT' "数字负号提前
CHANGING
VALUE = G_STR.
PERFORM FILL_CELL USING ROW_N 6 G_STR.
ROW_N = ROW_N + 2 .
"编制
G_STR = OPE_MAN.
PERFORM FILL_CELL USING ROW_N 1 G_STR.
"18编制人
G_STR = P_WA_TAB1_DOI-PRMAN.
PERFORM FILL_CELL USING ROW_N 2 G_STR.
"复核,用于打印签字
G_STR = CHE_MAN.
PERFORM FILL_CELL USING ROW_N 7 G_STR.
ENDFORM. " OUTPUT_TO_EXCEL
*&----------------------------------------------------------*
*& Form FILL_CELL
*&----------------------------------------------------------*
* text 填充单元格
*-----------------------------------------------------------*
FORM FILL_CELL USING I J VAL.
DATA: COLUMNS_NUMBER TYPE I,
ROWS_NUMBER TYPE I.
COLUMNS_NUMBER = 1.
ROWS_NUMBER = 1.
CALL METHOD DOI_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'cell'
NO_FLUSH = 'X'
TOP = I
LEFT = J
ROWS = ROWS_NUMBER
COLUMNS = COLUMNS_NUMBER
IMPORTING
ERROR = DOI_ERRORS.
APPEND DOI_ERRORS.
REFRESH: RANGES, EXCEL_INPUT.
RANGEITEM-NAME = 'cell'.
RANGEITEM-COLUMNS = 1.
RANGEITEM-ROWS = 1.
APPEND RANGEITEM TO RANGES.
EXCEL_INPUT_WA-COLUMN = 1.
EXCEL_INPUT_WA-ROW = 1.
EXCEL_INPUT_WA-VALUE = VAL.
APPEND EXCEL_INPUT_WA TO EXCEL_INPUT.
CALL METHOD DOI_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = RANGES
CONTENTS = EXCEL_INPUT
NO_FLUSH = 'X'
IMPORTING
ERROR = DOI_ERRORS.
APPEND DOI_ERRORS.
CALL METHOD DOI_SPREADSHEET->FIT_WIDEST
EXPORTING
NAME = SPACE
NO_FLUSH = 'X'.
REFRESH: RANGES, EXCEL_INPUT.
ENDFORM. " FILL_CELL
*&----------------------------------------------------------*
*& Form DOWNLOAD_TO_COMPUTER
*&----------------------------------------------------------*
* text 下载excel到本地
*-----------------------------------------------------------*
FORM DOWNLOAD_TO_COMPUTER.
DATA: LV_FILENAME TYPE STRING, "文件名
LV_WINTITLE TYPE STRING, "文件标题
LV_FILEPATH TYPE STRING, "路径
LV_FULLPATH TYPE STRING, "全路径
LV_DEFAULT TYPE STRING. "默认文件名
DATA: TITLE TYPE STRING VALUE 'XXXX调节表'.
LV_WINTITLE = 'excel文档'.
CONCATENATE TITLE '_' P_RYEAR '_' P_RPMAX '.xls' INTO TITLE.
LV_DEFAULT = TITLE.
*&---打开保存对话框
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
EXPORTING
WINDOW_TITLE = LV_WINTITLE
DEFAULT_EXTENSION = 'xls'
DEFAULT_FILE_NAME = LV_DEFAULT
FILE_FILTER = 'xls'
* INITIAL_DIRECTORY =
CHANGING
FILENAME = LV_FILENAME
PATH = LV_FILEPATH
FULLPATH = LV_FULLPATH
* USER_ACTION =
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
OTHERS = 3.
IF SY-SUBRC = 0.
DATA: P_FILE TYPE RLGRAP-FILENAME.
P_FILE = LV_FULLPATH.
*&---保存文件
CALL METHOD DOI_DOCUMENT->SAVE_AS
EXPORTING
FILE_NAME = P_FILE
IMPORTING
ERROR = DOI_ERRORS.
IF SY-SUBRC = 0.
MESSAGE '文件已保存!' TYPE 'I'.
* LEAVE TO SCREEN 0.
ENDIF.
ELSE.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM.
*&----------------------------------------------------------*
*& Form HANDLE_USER_COMMAND_LEAVE_02
*&----------------------------------------------------------*
* text 退出命令处理
*-----------------------------------------------------------*
FORM HANDLE_USER_COMMAND_LEAVE_02 USING P_SY_UCOMM LIKE SY-UCOMM.
IF P_SY_UCOMM = 'BACK' OR P_SY_UCOMM = 'RETURN'.
IF NOT DOI_DOCUMENT IS INITIAL.
CALL METHOD DOI_DOCUMENT->CLOSE_DOCUMENT.
FREE DOI_DOCUMENT. "type I_OI_DOCUMENT_PROXY
ENDIF.
IF NOT DOI_CONTROL IS INITIAL.
CALL METHOD DOI_CONTROL->DESTROY_CONTROL.
FREE DOI_CONTROL. "type I_OI_CONTAINER_CONTROL
ENDIF.
"必须释放,否则会出现白板的情况
IF DOI_CONTAINER IS NOT INITIAL.
CALL METHOD DOI_CONTAINER->FREE.
ENDIF.
LEAVE TO SCREEN 0.
ELSE.
IF NOT DOI_DOCUMENT IS INITIAL.
CALL METHOD DOI_DOCUMENT->CLOSE_DOCUMENT.
FREE DOI_DOCUMENT. "type I_OI_DOCUMENT_PROXY
ENDIF.
IF NOT DOI_CONTROL IS INITIAL.
CALL METHOD DOI_CONTROL->DESTROY_CONTROL.
FREE DOI_CONTROL. "type I_OI_CONTAINER_CONTROL
ENDIF.
LEAVE PROGRAM.
ENDIF.
ENDFORM. " HANDLE_USER_COMMAND_LEAVE_02
*&----------------------------------------------------------*
*& Form GET_STR_BY_TYPE
*&----------------------------------------------------------*
* text 截取字符串中的数字或者非数字
*-----------------------------------------------------------*
FORM GET_STR_BY_TYPE USING P_E_STR CHANGING NUM_RESULT CHAR_RESULT.
DATA : LEN TYPE I,
POS TYPE I,
STR(60) ,
NUMS TYPE STRING VALUE '1234567890'.
STR = P_E_STR.
LEN = STRLEN( STR ).
POS = 0.
WHILE POS LT LEN.
IF STR+POS(1) CA NUMS.
CONCATENATE NUM_RESULT STR+POS(1) INTO NUM_RESULT.
CONDENSE NUM_RESULT NO-GAPS.
ELSE.
CONCATENATE CHAR_RESULT STR+POS(1) INTO CHAR_RESULT.
CONDENSE CHAR_RESULT NO-GAPS.
ENDIF.
POS = POS + 1.
ENDWHILE.
ENDFORM. " GET_STR_BY_TYPE
*&----------------------------------------------------------*
*& Form FRM_GET_LAST_DAY
*&----------------------------------------------------------*
* text 得到所给日期所在月份的最后一天
*-----------------------------------------------------------*
FORM FRM_GET_LAST_DAY USING P_P_RPMAX
CHANGING P_LAST_DAY LIKE SY-DATUM.
DATA : E_DATE(8) TYPE C,
E_YEAR(4) TYPE C,
E_MONTH(2) TYPE C,
E_DAY(2) TYPE C VALUE '01',
FIRST_DAY LIKE SY-DATUM.
E_YEAR = P_RYEAR.
E_MONTH = P_RPMAX+1(2).
CONCATENATE E_YEAR E_MONTH E_DAY INTO E_DATE.
FIRST_DAY = E_DATE.
CALL FUNCTION 'FIMA_DATE_CREATE'
EXPORTING
I_DATE = FIRST_DAY
I_SET_LAST_DAY_OF_MONTH = 'X'
IMPORTING
E_DATE = P_LAST_DAY .
ENDFORM. " FRM_GET_LAST_DAY