Chinaunix首页 | 论坛 | 博客
  • 博客访问: 202931
  • 博文数量: 49
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 520
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-24 09:35
文章分类

全部博文(49)

文章存档

2008年(49)

我的朋友

分类:

2008-04-09 16:00:54

Function module: HR_HK_STRING_INTO_2_LINES 可以完成将最大长度200的字符串截成2个,并且会考虑单词(单词以空格分割,一个单词不能分开放到两个串里).
 
该程序加强了这个Function module的功能,字符串长度不限,也考虑单词的问题. 可以将长的字符串分割到内表里.
 
REPORT  z_temp_demo3.
DATA: str TYPE string,
      line_len TYPE i.
DATA: BEGIN OF str_tab OCCURS 0,
        str(70),
      END OF str_tab.
DATA wa_tab LIKE LINE OF str_tab.

START-OF-SELECTION.
  str = 'n Applicants are classified according to certain criteria in the initial entry of data stage: Internal / external applicants' &
        'Unsolicited applicants / Applicants who have applied to an advertisement' &
 'Applicant groups' &
 'Applicant range .'.
  CONCATENATE str str INTO str SEPARATED BY SPACE.
 
  PERFORM split_str_to_table USING str
                                 'STR'
                                  wa_tab
                                  str_tab[].

  LOOP AT str_tab.
    WRITE: / str_tab-str.
  ENDLOOP.
 
*&---------------------------------------------------------------------*
*&      Form  split_str_to_table
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->VALUE(SOURCE_STR)     text
*      -->VALUE(LINE_LEN)       text
*      -->VALUE(WA_FIELD_NAME)  text
*      -->TAB_STRU              text
*      -->STR_TAB               text
*----------------------------------------------------------------------*
FORM split_str_to_table USING value(source_str) TYPE string
                              value(wa_field_name)  "table工作区的字符串字段名
                              tab_stru    "table的工作区
                              str_tab TYPE STANDARD TABLE.
  DATA: start_pos TYPE i,
        end_pos TYPE i,
        str_len TYPE i,
        full_field_name(20),
        temp_value TYPE i,
        temp_char,
        have_space,
        line_len TYPE i.
  FIELD-SYMBOLS .
  CLEAR: tab_stru, str_tab.
  start_pos = 0.
  end_pos = 0.
  CONCATENATE 'TAB_STRU-' wa_field_name INTO full_field_name.
  CONDENSE source_str.  "除去多余的空格
  str_len = STRLEN( source_str ).
  ASSIGN (full_field_name) TO .
  DESCRIBE FIELD LENGTH line_len IN CHARACTER MODE.
  IF sy-subrc <> 0.
    MESSAGE a000(o0) WITH 'Error'.
  ENDIF.
  DO.
    CLEAR have_space.
    temp_value = start_pos + line_len.
    IF temp_value < str_len.  "end_pos还可以继续按line_len长度向后移动
      end_pos = temp_value.   "end_pos向后移动
      DO.
        IF start_pos = end_pos. "start_pos与end_pos重合,直接把line_len长度的字符串放入
          EXIT.
        ENDIF.
        temp_char = source_str+end_pos(1). "看是否是空格
        IF temp_char = space.              "如果是,则把空格之前的截断放入内表
          have_space = 'X'.
          EXIT.
        ENDIF.
        end_pos = end_pos - 1. "没有遇到空格,end_pos继续向左移动
      ENDDO.
      IF have_space <> 'X'.
        end_pos = start_pos + line_len.
      ENDIF.
      temp_value = end_pos - start_pos.
      = source_str+start_pos(temp_value).
      APPEND tab_stru TO str_tab.
      start_pos = end_pos.
    ELSE.
      end_pos = str_len.
      temp_value = end_pos - start_pos.
      = source_str+start_pos(temp_value).
      APPEND tab_stru TO str_tab.
      EXIT.
    ENDIF.
  ENDDO.

ENDFORM.                    "split_str_to_table
阅读(2230) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~