03-26-2008 11:47 AM
Hi,
I am very new to ABAP. I have a requirement where I have a long string like this "FirstName=abcd AND SecondName=xyz AND LastName=123 AND......" and for sure the name value pairs will be a seperated by string "AND" but the
neither names nor their values are fixed. And the string can change at any time but the name value pairs are seperated by "AND" and name value pairs can be identified by an "=" operator in between.
Now i want to store this string in the form of a table with two attributes "NAME" and "VALUE" in an internal table and later use the name value pairs when needed.
Kindly tell me know how I can achieve this and a code snippet will be really helpful.
Thanks,
Siva.
PS : Points will be given.
03-26-2008 11:53 AM
data : begin of itab occurs 0,
data(50),
end of itab.
data : begin of itab1 occurs 0,
name(30),
value(30),
end of itab1.
v_string = "FirstName=abcd AND SecondName=xyz AND
LastName=123 AND......"
split v_string at 'AND' into table itab.
loop at itab.
split itab-data at '=' into itab1-name itab1-value.
append itab1.
clear itab1.
endloop.
03-26-2008 11:53 AM
data : begin of itab occurs 0,
data(50),
end of itab.
data : begin of itab1 occurs 0,
name(30),
value(30),
end of itab1.
v_string = "FirstName=abcd AND SecondName=xyz AND
LastName=123 AND......"
split v_string at 'AND' into table itab.
loop at itab.
split itab-data at '=' into itab1-name itab1-value.
append itab1.
clear itab1.
endloop.
03-26-2008 11:54 AM
use it for ur requirement
split <string-name> at 'AND' into table <table- name>
03-26-2008 12:04 PM
REPORT ychatest .
DATA : v_string TYPE string.
v_string = 'FirstName=abcd AND SecondName=xyz AND LastName=123'.
DATA : BEGIN OF itab OCCURS 0,
v_name(250),
END OF itab.
DATA : BEGIN OF itab1 OCCURS 0,
name(100),
value(100),
END OF itab1.
SPLIT v_string AT 'AND' INTO TABLE itab.
LOOP AT itab.
SPLIT itab-v_name AT '=' INTO itab1-name itab1-value.
APPEND itab1.
CLEAR itab1.
ENDLOOP.
LOOP AT itab1.
WRITE : / itab1-name , itab1-value.
ENDLOOP.
03-26-2008 12:05 PM
03-26-2008 12:12 PM