08-31-2006 9:01 PM
Hi,
I have a String of variable lenght but with a separator '|'. I have to pick the values between the separator and put into different variables for further processing. Can any one please help me a good solutionfor this requirement? If there is no value between separator, it has to be considered as the "BLANK" value.
1|6 915912 |00S|||||KE| |HALB|M|00801A||EA| ||||PRMS|||||||||||||||||||0001||15||0||||||||0|0|0|||||||||||||||||||||||KE||P ||20060701||||||||||||||00|||||NORM||||||||||||||||||||
Thanks and Regards,
Kannan
Message was edited by: Kannan SA
Message was edited by: Kannan SA
08-31-2006 9:04 PM
08-31-2006 9:03 PM
Use SpLIT statement.
SPLIT lstr AT '|' into table itab.
--you can define you table or structure itab with the apprioriate field names.
Regards
Anurag
(Please check the syntax)
Message was edited by: Anurag Bankley
Message was edited by: Anurag Bankley
08-31-2006 10:11 PM
Hi Anurag,
Thanks for your reply. Please have a look at the code below. It throws syntax error. I need to put the values into an internal table after spliting the string as i am not sure of the length of the Original String.
types : begin of t_string,
record type string,
end of t_string.
data: lt_string type table of t_string with header line.
split lv_string at '|' into table lt_string.
Thanks and Regards,
Kannan.
08-31-2006 10:17 PM
The problem is the definition of lt_string.
Its structure should be the one as you require after the splitting of record.
example if you first field is company code followed by plant etc..than the structure of lt_string should
begin of lt_string occurs 0,
company(4),
plant(4),
end of lt_string.
--Dont forget to give points for useful answers --
Message was edited by: Anurag Bankley
Message was edited by: Anurag Bankley
08-31-2006 9:04 PM
08-31-2006 9:41 PM
Hi,
Check this sample code , check how split statement is used to process the strings with pipe symbols:
data : begin of i_tab1 occurs o,
fld(100) type c.
end of i_tab1.
DATA: BEGIN OF i_DATA occurs 0,
MATNR(18),
CHARG LIKE MCHA-CHARG,
werks like mcha-werks,
sdate(8) type c,
stats(1) type c,
lifnr like mcha-lifnr,
licha like mcha-licha,
lwedt like mcha-lwedt,
END OF i_DATA.
use Itab1 for read data statement to get the data from file.
then loop itab1 like below:
loop at i_tab1.
<b>split itab1-fld at '|' into T_DATA-MATNR
T_DATA-CHARG
T_DATA-werks
T_DATA-sdate
T_DATA-stats
T_DATA-lifnr
T_DATA-licha
T_DATA-lwedt .</b>
move T_DATA-MATNR to i_DATA-MATNR .
T_DATA-CHARG to i_DATA--CHARG .
....
append i_data.
endloop.
finally i_data will contains correct values
Regards
Laxman
*Reward the points for helpful answers
08-31-2006 10:17 PM
Hi,
Declare the internal table like this..
data: lt_string type table of string with header line.
Thanks,
Naren