SAP ABAP Texteditor使用实例

1、如果要使用自定义的文本对象和识别码,需要先用se75创建文本对象和识别码。
2、在屏幕中拖个自定义控件,拖放适当的大小,激活。
3、在代码中申明一个cl_gui_custom_container类型的变量和一个cl_gui_textedit类型的变量。
data:gv_container type REF TO cl_gui_custom_container,
     gv_editor    type ref to cl_gui_textedit.

4、创建上面两个变量的实例。

IF gv_container IS INITIAL.
  CREATE OBJECT gv_container
    EXPORTING
*     parent         =
      container_name = 'GV_CONTAINER_TXT'  "一定要是屏幕中自定义控件的名字
*     style          =
*     lifetime       = lifetime_default
*     repid          =
*     dynnr          =
*     no_autodef_progid_dynnr     =
*      EXCEPTIONS
*     cntl_error     = 1
*     cntl_system_error           = 2
*     create_error   = 3
*     lifetime_error = 4
*     lifetime_dynpro_dynpro_link = 5
*     others         = 6
    .
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
  IF gv_editor IS INITIAL.
    CREATE OBJECT gv_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                     = gv_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
      .

    IF sy-subrc <> 0.
*         MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
  ENDIF.
ENDIF.


<span style="font-family: 'microsoft yahei'; background-color: rgb(255, 255, 255);">运行下就可以看到文本编辑框了。怎么读写文本呢,先申明下面的变量.</span>

DATA:fid       LIKE thead-tdid,
     fname     LIKE thead-tdname,
     fobject   LIKE thead-tdobject,
     it_line   LIKE STANDARD TABLE OF line WITH HEADER LINE,
     it_tline  LIKE STANDARD TABLE OF tline WITH HEADER LINE,
     it_header LIKE thead.

从数据库中读文本和写文本使用read_text、create_text这两个FM,他们有个table参数是tline类型的。
从文本编辑框中读、写文本使用 SPAN {font-family: "Courier New";font-size: 10pt;color: #000000;background: #FFFFFF;}</STYLE.get_text_as_r3table 和 setSPAN {font-family: "Courier New";font-size: 10pt;color: #000000;background: #FFFFFF;}</STYLE._text_as_r3table 这两个method 他们有个table参数是line类型的。这两种类型使用下面的form进行转换
FORM convert_tlines_to_lines.
  CLEAR:it_line[],it_line.
  LOOP AT it_tline.
    it_line = it_tline-tdline.
    APPEND it_line.
  ENDLOOP.
  "clear:it_tline[],it_tline.
ENDFORM.
"
"
FORM convert_lines_to_tlines.
  CLEAR:it_tline[],it_tline.
  LOOP AT it_line.
    it_tline-tdline = it_line.
    APPEND it_tline.
  ENDLOOP.
  "clear:it_line[],it_line.
ENDFORM.

*把文本读到文本编辑框中的代码。


*&---------------------------------------------------------------------*
*&      Form  READ_TEXT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM read_text .
  CALL FUNCTION 'READ_TEXT'
    EXPORTING
*     CLIENT                  = SY-MANDT
      id                      = fid
      language                = sy-langu
      name                    = fname
      object                  = fobject
*     ARCHIVE_HANDLE          = 0
*     LOCAL_CAT               = ' '
*    IMPORTING
*     HEADER                  =
    TABLES
      lines                   = it_tline
    EXCEPTIONS
      id                      = 1
      language                = 2
      name                    = 3
      not_found               = 4
      object                  = 5
      reference_check         = 6
      wrong_access_to_archive = 7
      OTHERS                  = 8.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.
  PERFORM. convert_tlines_to_lines.
ENDFORM.                    " READ_TEXT



PROCESS BEFORE OUTPUT.
  MODULE load_text.

MODULE load_text OUTPUT.
  "perform. convert_tlines_to_lines.
  CALL METHOD gv_editor->set_text_as_r3table
    EXPORTING
      table           = it_line[]
    EXCEPTIONS
      error_dp        = 1
      error_dp_create = 2
      OTHERS          = 3.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
  "clear:it_tline[],it_tline,it_line[],it_line.
ENDMODULE.                 " LOAD_TEXT  OUTPUT

*文本从编辑框中保存到数据库的代码。

FORM save_text .
  CALL METHOD gv_editor->get_text_as_r3table
*      EXPORTING
*        only_when_modified     = FALSE
    IMPORTING
      table                  = it_line[]
*     is_modified            =
    EXCEPTIONS
      error_dp               = 1
      error_cntl_call_method = 2
      error_dp_create        = 3
      potential_data_loss    = 4
      OTHERS                 = 5.
  IF sy-subrc <> 0.
*     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
  IF it_line[] IS NOT INITIAL.

    PERFORM. convert_lines_to_tlines.

    CALL FUNCTION 'CREATE_TEXT'
      EXPORTING
        fid       = fid
        flanguage = sy-langu
        fname     = fname
        fobject   = fobject
*       SAVE_DIRECT       = 'X'
*       FFORMAT   = '*'
      TABLES
        flines    = it_tline[]
      EXCEPTIONS
        no_init   = 1
        no_save   = 2
        OTHERS    = 3.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.

    "clear:it_tline[],it_tline.
  ENDIF.
ENDFORM.                    " SAVE_TEXT


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值