ABAP长文本控件的两个例程

ABAP长文本控件的两个例程,一个是数据显示在文本控件上的,一个是从控件上读取内容的

constants:c_line_length type i value 4000.
*&---------------------------------------------------------------------*
*&      Form  FRM_SET_LONGTEXT
*&---------------------------------------------------------------------*
*       显示长文本空间
*----------------------------------------------------------------------*
form frm_set_longtext
                    using    pr_con  type ref to cl_gui_custom_container
                             pr_ltxt type ref to cl_gui_textedit
                             pv_cnam type c 
		             pv_edit type c  "‘X’-可编辑,‘’不可编辑
                             pv_value type c.
  data:lv_length type i,
       lv_pos    type i,
       lv_mode   type i.

  data:begin of ls_table,
         line(c_line_length) type c,
       end of ls_table,
       lt_table like table of ls_table.

  describe field pv_value length lv_length in character mode.

  if pr_con is initial.
*   创建容器
    create object pr_con
      exporting
        container_name              = pv_cnam
      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 'I' number sy-msgno
                 with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    endif.
*   创建文本框 ==
    create object pr_ltxt
      exporting
        max_number_chars           = lv_length      "可输入文本长度
        wordwrap_mode              =
                                     cl_gui_textedit=>wordwrap_at_fixed_position
        wordwrap_position          = '150' "行长度
        wordwrap_to_linebreak_mode = cl_gui_textedit=>true
        parent                     = pr_con
      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 'I' number sy-msgno
                 with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    endif.
  endif.


  check pr_ltxt is not initial.

  if pv_edit eq 'X'.
    lv_mode   = 0.
  else.
    lv_mode   = 1.
  endif.
  pr_ltxt->set_readonly_mode(
    exporting
      readonly_mode          = lv_mode
    exceptions
      error_cntl_call_method = 1
      invalid_parameter      = 2
         ).
  if sy-subrc <> 0.
*   Implement suitable error handling here
  endif.


*设置显示文本
  clear:lt_table[],lv_pos.
  do.
    clear:ls_table.
    if lv_pos >= lv_length.
      exit.
    elseif ( lv_pos + c_line_length ) > lv_length.
      ls_table-line = pv_value+lv_pos.
    else.
      ls_table-line = pv_value+lv_pos(c_line_length).
    endif.
    append ls_table to lt_table.
    add c_line_length to lv_pos.
  enddo.

  pr_ltxt->set_text_as_r3table(
    exporting
      table           = lt_table
    exceptions
      error_dp        = 1
      error_dp_create = 2
         ).
  if sy-subrc <> 0.
*   Implement suitable error handling here
  endif.
endform.
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_LONGTEXT
*&---------------------------------------------------------------------*
*       读取长文本
*----------------------------------------------------------------------*
form frm_get_longtext  using
                             pr_ltxt type ref to cl_gui_textedit
                             pv_value type c.
  data:begin of ls_table,
         line(c_line_length) type c,
       end of ls_table,
       lt_table like table of ls_table.
  pr_ltxt->get_text_as_r3table(
   importing
     table           = lt_table
   exceptions
     error_dp        = 1
     error_dp_create = 2
        ).
  if sy-subrc <> 0.
*   Implement suitable error handling here
  else.
    clear:pv_value.
    loop at lt_table into ls_table.
      concatenate pv_value ls_table-line into pv_value.
    endloop.
  endif.
endform.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值