业务背景:目前项目上 采购订单打印输出EXCEL的需求:允许客户进行长文本编辑、更改后保存到采购订单抬头,并且打印输出到EXCEL,且下次进入到相同的采购订单打印时,能取出相应的长文本进行excel输出。
一般来讲,这种类型于这种编辑后输出的需求直接在ALV上对应的列设置为可编辑即可,但是这次需求不太一样,它是一个长文本输出, 而ALV的列显示最大128位(这里的意思是:如果ALV的列里存了1000位长度的文本,但是它只会显示128位,但是如果输出成EXCEL时候是可以正常把1000位全都输出的)。为了解决alv不能显示长文本的问题,稍微研究了下长文本的形式。
长文本:在SAP内,我是用一个容器来实现的,或者应该不用容器也是可以的(比如docking),在屏幕上画一个容器,然后显示出来。
效果展示
其中保存按钮是当用户在点击后会把当前的文本更新回ALV,取消按钮则不做任何操作直接返回
主要代码
*&---------------------------------------------------------------------*
*& Module STATUS_9100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE STATUS_9100 OUTPUT.
SET PF-STATUS 'STATUS_9100'.
SET TITLEBAR 'TITLEBAR_9100'.
IF LCL_EDITOR IS INITIAL.
"实例化容器
CREATE OBJECT LCL_CONTAINER
EXPORTING
CONTAINER_NAME = 'ZCON'.
"实例化texteditor控制器
CREATE OBJECT LCL_EDITOR
EXPORTING
* MAX_NUMBER_CHARS =
STYLE = 0
* WORDWRAP_MODE = CL_GUI_TEXTEDIT=>WORDWRAP_AT_FIXED_POSITION "固定位置显示
WORDWRAP_POSITION = -1
WORDWRAP_TO_LINEBREAK_MODE = CL_GUI_TEXTEDIT=>TRUE "可以回车换行
* FILEDROP_MODE = DROPFILE_EVENT_OFF
PARENT = LCL_CONTAINER
* LIFETIME =
* NAME =
EXCEPTIONS
ERROR_CNTL_CREATE = 1
ERROR_CNTL_INIT = 2
ERROR_CNTL_LINK = 3
ERROR_DP_CREATE = 4
GUI_TYPE_NOT_SUPPORTED = 5
OTHERS = 6.
CALL METHOD LCL_EDITOR->SET_TEXT_AS_R3TABLE
EXPORTING
TABLE = GT_LINES
EXCEPTIONS
ERROR_DP = 1
ERROR_DP_CREATE = 2
.
"隐藏TOOLBAR
CALL METHOD LCL_EDITOR->SET_TOOLBAR_MODE
EXPORTING
TOOLBAR_MODE = 0
EXCEPTIONS
ERROR_CNTL_CALL_METHOD = 1
INVALID_PARAMETER = 2
OTHERS = 3
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_9100 INPUT.
CLEAR SAVE_CODE.
SAVE_CODE = OK_CODE.
CLEAR OK_CODE.
REFRESH GT_LINES.
CASE SAVE_CODE.
WHEN 'BACK' OR 'EXIT' OR 'ZCANCEL' OR 'CANCEL'.
IF LCL_EDITOR IS NOT INITIAL.
CLEAR:LCL_EDITOR.
* CALL METHOD LCL_EDITOR->FREE.
ENDIF.
IF LCL_CONTAINER IS NOT INITIAL.
CLEAR:LCL_CONTAINER.
* CALL METHOD LCL_CONTAINER->FREE.
ENDIF.
LEAVE TO SCREEN 0.
WHEN 'ZSAVE'.
"读取textedictor中的内容并输出
CLEAR:GT_LINES.
CALL METHOD LCL_EDITOR->GET_TEXT_AS_R3TABLE
* EXPORTING
* ONLY_WHEN_MODIFIED = FALSE
IMPORTING
TABLE = GT_LINES
* IS_MODIFIED =
EXCEPTIONS
ERROR_DP = 1
ERROR_CNTL_CALL_METHOD = 2
ERROR_DP_CREATE = 3
POTENTIAL_DATA_LOSS = 4
OTHERS = 5.
IF G_CG_TYPE EQ 'CGDD'.
CLEAR:GS_OUTPUT-ZTEXT_CGDD.
APPEND LINES OF GT_LINES TO GS_OUTPUT-ZTEXT_CGDD.
ELSEIF G_CG_TYPE EQ 'CGHT'.
CLEAR:GS_OUTPUT-ZTEXT_CGDD.
APPEND LINES OF GT_LINES TO GS_OUTPUT-ZTEXT_CGHT.
ENDIF.
IF LCL_EDITOR IS NOT INITIAL.
CLEAR:LCL_EDITOR.
* CALL METHOD LCL_EDITOR->FREE.
ENDIF.
IF LCL_CONTAINER IS NOT INITIAL.
CLEAR:LCL_CONTAINER.
* CALL METHOD LCL_CONTAINER->FREE.
ENDIF.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.