Friday, September 4, 2009

Split Large Char Field Into Table

To Split a large char field into table , you can use the function below. You may say , there are lots of alternative keywords and functions for this approach. Here’s the difference of  this function ; It separates given character field considering the white spaces and fills the given tables 1st component which must be char type and has any given length. Table can have only one component.
This function is very usefull when you need to split a given free text into fixed lentgh parts (sap script texts ) .
——————————————————————————–
Text Field Type C
DATA : free_text(10000).

*** Table to fill Splitted lines

DATA : BEGIN OF lt_table OCCURS 1,
filed(10) ,
other_field TYPE i ,
n_filed TYPE n ,
p_field TYPE p ,
END OF lt_table .
*** Dummy Text
free_text = ’123 123 12345678 12345678567890Z 1234567 3243324′.
*** Function To Split large Char. Field Into Table
CALL FUNCTION ’OCS_SPLIT_TEXTLINE
EXPORTING
iv_textline         = free_text
*    iv_preserve_space   = ’X'   if you like to preserve spaces
TABLES
et_fragments        = lt_table[]
EXCEPTIONS
wrong_fragment_type = 1
OTHERS              = 2.
IF sy-subrc <> 0.
” Sth wrong
ENDIF.



No comments:

Post a Comment