‎2007 Nov 15 2:47 PM
Hi Gurus,
Is there any FM to split a string and place each values into the respected fields of a structure??
like for ex:
"adsav#kgdgsf#bdfjkajf" to be split into a structure of 3 fields.
or
Please tell me the best way to do it!
I have a structure with aroung 200 fields
Regards,
Sandy
‎2007 Nov 15 2:50 PM
Hi
Check this sytax..
SPLIT <string> AT <delimiter> INTO TABLE ITAB
‎2007 Nov 15 2:51 PM
‎2007 Nov 15 2:52 PM
- Define an internal table with just one character field with enough length (say 50)
- Define a field symbol TYPE ANY
- Use ABAP statement SPLIT and let the tags go into the internal table
Loop at the internal table
ASSIGN COMPONENT sy-tabix of structure to field symbol.
field symbol = internal table field value
Endloop
‎2007 Nov 15 2:52 PM
Hi Sandy,
Use below syntax
SPLIT dobj AT sep INTO TABLE result_tab IN CHARACTER} MODE.
Reward if it helps,
Satish
‎2007 Nov 15 2:57 PM
Oh, forgot to mention one thing. You asked for an FM and I don't think there is any.
You create a generic FM using the logic in my earlier post. It should take in a delimited string and a structure as inputs and change the structure before returning. Then post the code here so we can all use it.
‎2007 Nov 15 9:52 PM
Hello Sandy
You should always be suspicious if people say that something is <i>NOT </i>possible or does <i>NOT </i>exist. In most case such a statement is based either on a lack of knowledge or a lack of imagination.
To prove my point have a look at sample report<b> ZUS_SDN_SPLIT_DELIMITER_STRING</b>.
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_SPLIT_DELIMITER_STRING
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zus_sdn_split_delimiter_string.
TYPE-POOLS: truxs.
CONSTANTS:
gc_delimiter(1) TYPE c VALUE '#'.
" Normally your output itab should be based on a DDIC structure
TYPES: BEGIN OF ty_s_outtab.
types: text1 type ddtext.
types: text2 type ddtext.
types: text3 type ddtext.
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
WITH DEFAULT KEY.
DATA:
go_table TYPE REF TO cl_salv_table,
gt_outtab TYPE ty_t_outtab,
gt_raw_data TYPE truxs_t_text_data,
gs_raw LIKE LINE OF gt_raw_data.
PARAMETERS:
p_string TYPE char255 DEFAULT 'adsav#kgdgsf#bdfjkajf'.
START-OF-SELECTION.
gs_raw = p_string.
APPEND gs_raw TO gt_raw_data.
" NOTE: The length of the fieldtext must not exceed the length
" of the corresponding field in the output itab!!!
" NOTE: fm 'TEXT_CONVERT_TXT_TO_SAP' always assumes a tabulator
" as delimiter
CALL FUNCTION 'TEXT_CONVERT_TEX_TO_SAP'
EXPORTING
i_field_seperator = gc_delimiter
* I_LINE_HEADER =
i_tab_raw_data = gt_raw_data
* I_FILENAME =
TABLES
i_tab_converted_data = gt_outtab
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
TRY.
CALL METHOD cl_salv_table=>factory
* EXPORTING
* LIST_DISPLAY = IF_SALV_C_BOOL_SAP=>FALSE
* R_CONTAINER =
* CONTAINER_NAME =
IMPORTING
r_salv_table = go_table
CHANGING
t_table = gt_outtab.
CATCH cx_salv_msg .
ENDTRY.
go_table->display( ).
END-OF-SELECTION.Regards
Uwe
‎2007 Nov 16 12:44 AM
Hi
Check DEMO_DATA_STRING program in your system .
You wil get info of string operations .
Thanks,
Praveen
‎2009 Sep 10 4:35 PM
p_string TYPE char255 DEFAULT 'adsav#kgdgsf#bdfjkajf'
SPLIT p_string AT CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB INTO TABLE itab
‎2009 Sep 10 4:51 PM
Hi,
Try with new line indicator and split with that....
DATA: l_new_ln TYPE char1,
l_field TYPE filed type,
l_st2 TYPE char1.
data: l_var type string.
Let us Say, ur value is in this l_var.(abcd#fghjk#1234#1425)
l_new_ln = cl_abap_char_utilities=>cr_lf+0(1). " It gets # symbol
Now,
SPLIT l_wa_data-line
AT l_new_ln
INTO
wa_data-field1
wa_data-field2
wa_data-field3
wa_data-field3.
Append wa_data to i_data.It may help full to you.....
Thnaks
Babu