Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7189318
  • 博文数量: 655
  • 博客积分: 10264
  • 博客等级: 上将
  • 技术积分: 8278
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-04 17:47
个人简介

ABAP顾问

文章分类

全部博文(655)

文章存档

2017年(2)

2014年(8)

2013年(3)

2012年(2)

2011年(18)

2010年(102)

2009年(137)

2008年(274)

2007年(134)

分类:

2009-03-27 21:51:11

网友: ABAP 菜鸟
白:
你好,看了博客好久了,能否帮忙做个能实现文本输入的例子?
像me23n里抬头文本的样式,并且能设置对象和ID需要保存的!
                                               谢谢了!

 

REPORT  z_barry_test_textedit NO STANDARD PAGE HEADING .

TABLES: sscrfields.
DATA: x_docking TYPE REF TO cl_gui_docking_container,
      x_editor  TYPE REF TO cl_gui_textedit,
      lines TYPE STANDARD TABLE OF tline ,
      header LIKE thead .

TYPES: BEGIN OF textline,
   line(255) TYPE c,
 END OF textline .
DATA texttable TYPE TABLE OF textline  .

PARAMETERS:p_name(70) DEFAULT '12345678'.
SELECTION-SCREEN FUNCTION KEY 1.
SELECTION-SCREEN FUNCTION KEY 2.

INITIALIZATION.
  sscrfields-functxt_01 = 'Save'.
  sscrfields-functxt_02 = 'Read'.

AT SELECTION-SCREEN OUTPUT.
  IF x_docking IS INITIAL .
    CREATE OBJECT x_docking
    EXPORTING
        repid                       = sy-repid
        dynnr                       = sy-dynnr
        side                        = 4
        extension                   = '255'
    EXCEPTIONS
        cntl_error                  = 1
        cntl_system_error           = 2
        create_error                = 3
        lifetime_error              = 4
        lifetime_dynpro_dynpro_link = 5.

    CREATE OBJECT x_editor
      EXPORTING
          parent                    = x_docking
          wordwrap_mode             = 2
          wordwrap_position         = 72
          max_number_chars          = 100000.
  ENDIF .

AT SELECTION-SCREEN.
  header-tdobject  = 'Z001'.
  header-tdname    = p_name.
  header-tdid      = '0001'.
  header-tdspras   = sy-langu.

  CASE sy-ucomm .
    WHEN 'FC01'.
      PERFORM savetext.
    WHEN 'FC02'.
      PERFORM readtext.
  ENDCASE.

*&---------------------------------------------------------------------*
*&      Form  savetext
*&---------------------------------------------------------------------*
FORM savetext.
  CALL METHOD x_editor->get_text_as_stream
    IMPORTING
      text                   = texttable
    EXCEPTIONS
      error_dp               = 1
      error_cntl_call_method = 2
      OTHERS                 = 3.

  CALL FUNCTION 'CONVERT_STREAM_TO_ITF_TEXT'
    EXPORTING
      language    = sy-langu
    TABLES
      text_stream = texttable
      itf_text    = lines.

  CALL FUNCTION 'SAVE_TEXT'
    EXPORTING
      header          = header
      savemode_direct = 'X'
    TABLES
      lines           = lines
    EXCEPTIONS
      id              = 1
      language        = 2
      name            = 3
      object          = 4
      OTHERS          = 5.
  IF sy-subrc = 0.
    MESSAGE s000(oo) WITH '保存成功'.
    COMMIT WORK.
  ELSE.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDFORM.                    "savetext

*&---------------------------------------------------------------------*
*&      Form  readtext
*&---------------------------------------------------------------------*
FORM readtext.
  CLEAR:texttable,texttable[].

  CALL FUNCTION 'READ_TEXT'
    EXPORTING
      id                      = header-tdid
      language                = sy-langu
      name                    = p_name
      object                  = header-tdobject
    TABLES
      lines                   = lines
    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.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  CALL FUNCTION 'CONVERT_ITF_TO_STREAM_TEXT'
    EXPORTING
      language    = sy-langu
    TABLES
      itf_text    = lines
      text_stream = texttable.

  CALL METHOD x_editor->set_text_as_stream
    EXPORTING
      text            = texttable
    EXCEPTIONS
      error_dp        = 1
      error_dp_create = 2
      OTHERS          = 3.
ENDFORM.                    "readtext

注:如果需要自己定义object,如本例的tdobject(Z001)和tdid(0001),则需要在表TTXOB和TTXID中维护(TCODE:SE75)

关于SAVE_TEXT的更多帮助:

 
关于cl_gui_textedit的一些用法示例程序:SAPTEXTEDIT_*
阅读(10066) | 评论(17) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-10-29 10:54:45

实现什么?没明白

chinaunix网友2009-10-19 12:46:15

用程序怎样实现呢?

qdbarry2009-10-19 11:07:32

SPRO: Materials Management -> Purchasing -> Purchase Order -> Texts for Purchase Orders -> Define Text Types for Header Texts 或者直接SM30维护VV_TTXID_MM_FK SD的长文本维护可以使用Tcode:VOTXN

chinaunix网友2009-10-19 00:00:16

白老师, 请问ME21里的抬头本文怎样做,右边为文本名称的选项(如:表头文本,表头注释,限期...),左边为可编辑的文本内容(textedit). 谢谢!

chinaunix网友2009-06-01 16:03:21

除了双击保存之外也可以使用自带的保存按钮,可是这样的话需要重新LOOP一次内表,对每一行的字段进行保存,如果输出内表条目多的话,严重影响速度