我们不经常使用convert text,这里简单介绍一些它的用法

CONVERT TEXT text INTO SORTABLE CODE hex. 

将text转换为16进制数值保存在hex变量中。

它主要是用在table较大,并且要经常进行排序的情况下。

用的时候注意,text必须是c或者string类型,hex必须是x或者xstring类型,如果hex是x类型则长度至少是24*length(text)-24,当然这个最小长度可能根据操作系统的不同而有所不同

DATA: BEGIN OF text_line, 
sort_indx TYPE xstring,
text TYPE string,
END OF text_line,
text_tab LIKE HASHED TABLE OF text_line
WITH UNIQUE KEY sort_indx.

text_line-text = `Muller`.
PERFORM fill_text_tab.
text_line-text = `Möller`.
PERFORM fill_text_tab.
text_line-text = `Moller`.
PERFORM fill_text_tab.
text_line-text = `Miller`.
PERFORM fill_text_tab.

SORT text_tab BY text.
PERFORM write_text_tab.

SET LOCALE LANGUAGE 'D'.
SORT text_tab BY sort_indx.
PERFORM write_text_tab.

FORM fill_text_tab.
CONVERT TEXT text_line-text
INTO SORTABLE CODE text_line-sort_indx.
INSERT text_line INTO TABLE text_tab.
ENDFORM.

FORM write_text_tab.
FIELD-SYMBOLS <line> LIKE text_line.
LOOP AT text_tab ASSIGNING <line>.
WRITE / <line>-text.
ENDLOOP.
SKIP.
ENDFORM.