‎2007 Jul 10 8:07 AM
Hi ABAP Guru's,
Can you please help me out? How can I split a string into two which has a space in between?
For example: lets suppose the string is 'LA CA USA'. How can I split this string? I have to dynamically determine the number of characters before the space therefore I cannot use number constant such as 2 or 3.
With best regards,
Ketan
‎2007 Jul 10 8:11 AM
SPLIT <ITAB/STRING> AT ' ' into table ITAB1.
Regards,
Amit
reward all helpful replies.
‎2007 Jul 10 8:11 AM
Hi Ketan,
use 'Replace' space with '$'
It will fill up all spaces with $
and then split at '$'
Reward if useful!
‎2007 Jul 10 8:11 AM
try this..
REPORT ychatest.
DATA : v_str TYPE string VALUE 'LA CSD KDGKL'.
DATA : BEGIN OF itab OCCURS 0,
fld(250),
END OF itab.
SPLIT v_str AT space INTO TABLE itab.
LOOP AT itab.
WRITE : / itab-fld.
ENDLOOP.
‎2007 Jul 10 8:13 AM
‎2007 Jul 10 8:14 AM
data: itab type table of string.
split your_string at space into itab.
reward points if helpful
‎2007 Jul 10 8:26 AM
hi,
To split a character string into two or more smaller strings, use the SPLIT statement as follows:
<b>SPLIT <c> AT <del> INTO <c1> ... <cn>.</b>
The system searches the field <c> for the separator <del>. The parts before and after the separator are placed in the target fields <c1> ... <cn>.
To place all fragments in different target fields, you must specify enough target fields. Otherwise, the last target field is filled with the rest of the field <c> and still contains delimiters.
If all target fields are long enough and no fragment has to be truncated, SY-SUBRC is set to 0. Otherwise it is set to 4.
<b>SPLIT LA CA USA AT ' ' INTO <c1></b>
regards,
Sudheer
‎2007 Jul 10 8:31 AM
Hi
Try like this
DATA : opbal TYPE p DECIMALS 2 VALUE 0.
SELECT * FROM zs_mkpf_mseg
into corresponding fields of table it_opbal
WHERE werks = itmat-werks
AND matnr = itmat-matnr
AND budat = s_budat-low.
* sort it_opbal by budat.
loop at it_opbal.
read table it_opbal.
IF it_opbal-shkzg = 'S'.
opbal = opbal + it_opbal-menge.
ELSEIF it_opbal-shkzg = 'H'.
opbal = opbal + it_opbal-menge * -1.
ENDIF.
endloop.
append opbal TO itab-opbal.
ENDFORM. " opbal_data
you can also use thi s
DATA: NAMES(30) TYPE C VALUE 'Charly, John , Peter',
NAMES2 TYPE STRING,
ONE(10) TYPE C,
TWO(10) TYPE C,
THREE TYPE STRING,
FOUR(4) TYPE C VALUE 'FOUR',
DELIMITER(2) VALUE ','.
SPLIT NAMES AT DELIMITER INTO ONE TWO.
* ONE contains 'Charly' and TWO contains 'John , Pet'.
* SY-SUBRC is 4, because TWO was not large enough to
* accommodate the whole of the remaining string
SPLIT NAMES AT ',' INTO ONE TWO THREE.
* ONE contains 'Charly', TWO contains ' John',
* THREE contains ' Peter'.
SPLIT NAMES AT ', ' INTO ONE THREE TWO.
* ONE contains 'Charly', THREE contains 'John',
* TWO contains 'Peter'.
CONCATENATE NAMES '' INTO NAMES2 SEPARATED BY SPACE.
SPLIT NAMES2 AT DELIMITER INTO ONE TWO THREE FOUR.
* ONE contains 'Charly', TWO contains 'John',
* THREE contains 'Peter ', FOUR is empty.
SPLIT NAMES2 AT DELIMITER INTO ONE FOUR THREE.
* ONE contains 'Charly', FOUR contains 'John',
* THREE contains 'Peter', SY-SUBRC is 4, since
* FOUR was not large enough (spaces are significant
* characters!)
Reward all helpfull answers
Regards
Pavan
‎2007 Jul 10 8:36 AM
Thanks a lot for your replies.
How can I use the search functionality here to determine the length of the first word before the space?
For example lets suppose the string is 'Uzbekistan Russia USA' how can I use the search or any other functionality to determine the length of Uzbekistan? I cannot use a constant number and I have to dynamically calculate for each string.
With best regards,
Ketan