abap 屏幕上长文本

TEXT长文本的编写

大家在编程过程中,一定经常用到READ_TEXT这个函数来读取长文本,下面我介绍的是如果自己定义一个长文本object和ID,自己储存长文本。

在项目中,做了很多功能性开发,用户要写一些备注或者是审批意见和建议,自定义表里面储存字段的长度是有限的,这个时候能自定义长文本就很实用了。

第一步:建长文本的OBJECT,TCODE SE75,选择‘文本对象和识别码’,点击change,这个时候就会看到SAP系统中存在的所有长文本OBJECT,点‘新建’,输入文本对象,描述,选择保存状态是更新,选择编辑器应用格式是TA,行宽选一下,回车,搞定

第二步:建长文本的ID,双击刚刚创建的OBJECT,点新建,就可以创建ID了

第三步:先READ_TEXT,如果sy-subrc = 0,说明可以读到,如果不等于0,就说明还没有写长文本,那就可以用INIT_TEXT函数先初始化一下,再EDIT_TEXT编辑一下,最后SAVE_TEXT保存一下就OK了.

 

长文本的编辑能做到:第二次编辑的时候,第一次编辑的内容都是灰色的,这样就可以用来写审批意见。也可以做到,第二次编辑的时候,第一次的编辑也可以修改,这由几个参数决定。

SAP的标准例子:SDTEXTE,可以参考

--------------------------------------------------------------------------------------

在屏幕上加一个custom control name ZCBOX

 

PBO事件 显示长文本编辑框

 

module mod_custom_control output.
  data: lv_dmode type xfeld. "Display mode.

** Get display mode.
  if t340-trtyp = 'H'.
    lv_dmode = space.
  elseif t340-trtyp = 'V'.
    lv_dmode = space.
  elseif t340-trtyp = 'A'.
    lv_dmode = 'X'.
  endif.
** Get what input in the textedit.
  perform frm_read_text.

** Text editor set.
  call function 'RH_EDITOR_SET'
    exporting
      repid          = sy-repid
      dynnr          = sy-dynnr
      controlname    = 'ZCBOX'
      max_cols       = 79
      show_tool      = 'X'
      show_status    = 'X'
      display_mode   = lv_dmode
    tables
      lines          = gt_lines
    exceptions
      create_error   = 1
      internal_error = 2
      others         = 3.

endmodule.                 " MOD_CUSTOM_CONTROL  OUTPUT

 

form frm_read_text .
  data: lv_name like thead-tdname. "Name.

** Object name.
  clear: lv_name.
  lv_name = mgef-stoff.

** Read text.
  if gv_enter_flg eq 'X'.
    clear gt_lines.
    call function 'RH_EDITOR_GET'
      exporting
        controlname    = 'ZCBOX'
      tables
        lines          = gt_lines
      exceptions
        internal_error = 1
        others         = 2.
    clear gv_enter_flg.
  else.
    call function 'READ_TEXT'
      exporting
        id                      = 'ZHAZ'
        language                = 'E'
        name                    = lv_name
        object                  = 'ZHAZARDMAT'
      tables
        lines                   = gt_text
      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 eq 0.
** Transfer text.
      loop at gt_text into gs_text.
        gs_lines = gs_text-tdline.
        append gs_lines to gt_lines.
        clear: gs_text, gs_lines.
      endloop.
    endif.
  endif.
endform.                    " FRM_READ_TEXT

 PAI事件 输入后进行保存

  

module mod_save_text input.
  perform frm_save_text using gv_action_mode.
endmodule.                 " MOD_SAVE_TEXT  INPUT
 "gv_action_mode 是状态 V H A tcode的类型  代表新建 修改 或者 显示
form frm_save_text using iv_mode type c.
 clear gt_lines.

  call function 'RH_EDITOR_GET'
    exporting
      controlname    = 'ZCBOX'
    tables
      lines          = gt_lines
    exceptions
      internal_error = 1
      others         = 2.
  data: lv_name like thead-tdname. "Name.

data: gs_header like thead. "SAPscript: Text Header.
** Transfer data to header.
  clear: gs_header, lv_name.

  lv_name = viqmel-qmnum.
  gs_header-tdobject = 'ZT2O'.
  gs_header-tdname   = lv_name.
  gs_header-tdid     = 'ZTOO'.
  gs_header-tdspras  = 'E'.
  if iv_mode = 'H'.  "Create.
    gs_header-tdfuser  = sy-uname.
    gs_header-tdfdate  = sy-datum.
    gs_header-tdftime  = sy-uzeit.
    gs_header-tdospras = 'E'.
  else.
    gs_header-tdluser = sy-uname.
    gs_header-tdldate = sy-datum.
    gs_header-tdltime = sy-uzeit.
  endif.

** Transfer data.
  clear: gt_text.
  loop at gt_lines into gs_lines.
    gs_text-tdformat = '/'.
    gs_text-tdline = gs_lines.
    append gs_text to gt_text.
    clear: gs_text, gs_lines.
  endloop.

** Save text.
  call function 'SAVE_TEXT'
    exporting
      client          = sy-mandt
      header          = gs_header
      insert          = ' '
      savemode_direct = ' '
      owner_specified = ' '
      local_cat       = ' '
    tables
      lines           = gt_text
    exceptions
      id              = 1
      language        = 2
      name            = 3
      object          = 4
      others          = 5.
** Check save status.
  if sy-subrc ne 0.
    call function 'SAPSCRIPT_MESSAGE'
      exporting
        typ    = 'W'                                        "#EC NOTEXT
      exceptions
        others = 1.
  else.
    call function 'COMMIT_TEXT'.
  endif.
endform.

 

  

你可能感兴趣的:(abap)