2014 Mar 06 7:59 PM
Hello Gurus,
I need to make string of having length 1000 into multiple parts from a particular position which has some text without any delimiter and i want to populate each part into an internal table which has one filed...
eg : string = 'sap abap sap abap sap abap sap abap sap abap sap abap sap abap sap sap sap abap sap abap'
suppose i want to start splitting from 40th position...assume that i have 3 parts
and these 3 parts i have put into an internal table..
lt_itab = [sap abap sap abap sap abap sap abap,
sap abap sap abap sap abap sap abap,
sap abap sap sap sap abap sap abap]
plese help!
any help would be Appreciated ...thank you
2014 Mar 07 4:28 AM
hi,
check below coding and use fm - SWA_STRING_SPLIT ,,
* Split each line of it_longstrings into lines with length 10
* The resuklting lines are palced in table it_string_components
LOOP AT it_longstrings.
CLEAR it_string_components. REFRESH it_string_components.
CALL FUNCTION 'SWA_STRING_SPLIT'
EXPORTING
input_string = it_longstrings-line
max_component_length = 10
* TERMINATING_SEPARATORS =
* OPENING_SEPARATORS =
TABLES
string_components = it_string_components
* EXCEPTIONS
* MAX_COMPONENT_LENGTH_INVALID = 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.
* Add the lines to table
LOOP AT it_string_components.
it_shortstrings-line = it_string_components-str.
APPEND it_shortstrings.
ENDLOOP.
ENDLOOP.
END-OF-SELECTION.
LOOP AT it_shortstrings.
WRITE: / it_shortstrings-line.
ENDLOOP.
Regards DJ
2014 Mar 06 8:31 PM
Hi Nagendra,
I'm just sharing code which need to changed accordling. Just an idea
DATA : w_str TYPE string VALUE 'abapaaaaaaaaaaaaaaaaaaaaaaaaa aabaaaaaaaaaaaaaaaaaaqqqqq',
part TYPE n VALUE 3,
w_lengh(4) TYPE n,
offset(3) TYPE n,
start(3) TYPE n,
wa_area(100) TYPE c .
* String lengh
w_lengh = strlen( w_str ).
offset = w_lengh DIV part .
start = 0.
DO part times.
wa_area = w_str+start(offset).
* APPEND wa_rea to t_table.
start = start + offset.
ENDDO.
Thanks & Regards,
Arun
2014 Mar 07 12:20 PM
2014 Mar 07 3:55 AM
Hi,
Try this code.
TYPES: BEGIN OF ty,
b TYPE string,
END OF ty,
tt TYPE STANDARD TABLE OF ty.
DATA: a TYPE string VALUE 'aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll',
tb TYPE tt,
wa TYPE ty,
off TYPE i,
len TYPE i,
count TYPE i,
count1 TYPE i,
temp TYPE i.
len = 8. "Position
off = 0.
count = strlen( a ).
count1 = count / 8.
temp = len - 1.
DO count1 times.
temp = off + len.
IF temp > count.
wa-b = a+off.
ELSE.
wa-b = a+off(len).
ENDIF.
off = off + len.
SHIFT wa-b LEFT DELETING LEADING space.
APPEND wa to tb.
ENDDO.
LOOP AT tb INTO wa.
write: / wa-b.
ENDLOOP.
2014 Mar 07 4:28 AM
hi,
check below coding and use fm - SWA_STRING_SPLIT ,,
* Split each line of it_longstrings into lines with length 10
* The resuklting lines are palced in table it_string_components
LOOP AT it_longstrings.
CLEAR it_string_components. REFRESH it_string_components.
CALL FUNCTION 'SWA_STRING_SPLIT'
EXPORTING
input_string = it_longstrings-line
max_component_length = 10
* TERMINATING_SEPARATORS =
* OPENING_SEPARATORS =
TABLES
string_components = it_string_components
* EXCEPTIONS
* MAX_COMPONENT_LENGTH_INVALID = 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.
* Add the lines to table
LOOP AT it_string_components.
it_shortstrings-line = it_string_components-str.
APPEND it_shortstrings.
ENDLOOP.
ENDLOOP.
END-OF-SELECTION.
LOOP AT it_shortstrings.
WRITE: / it_shortstrings-line.
ENDLOOP.
Regards DJ
2014 Mar 07 12:19 PM
2014 Mar 07 4:35 AM
Here's one more way to do it.
/.
2014 Mar 13 5:10 AM
I wonder why you have marked your 'Thank you' replies as Correct/Helpful Answers.
2014 Mar 13 5:45 AM
Hi,
Some time when I try to solve a problem I wake up the next day with the solution.
My theory is that I have "A SPLIT personality" and the other guy is much smarter then I am.....
Regards.
2014 Mar 13 5:45 AM
2014 Mar 13 5:49 AM
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |