ITPub博客

首页 > Linux操作系统 > Linux操作系统 > abap中textedit的使用

abap中textedit的使用

原创 Linux操作系统 作者:100113 时间:2012-06-30 17:45:04 0 删除 编辑
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.
 
运行下就可以看到文本编辑框了。怎么读写文本呢,先申明下面的变量
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; } get_text_as_r3table 和 set SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } _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
 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23353800/viewspace-734216/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2011-11-24

  • 博文量
    19
  • 访问量
    53373