Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Generic pattern to store name value pairs into table from a long string

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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.

5 REPLIES 5

Former Member
0 Kudos

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.

Former Member
0 Kudos

use it for ur requirement

split <string-name> at 'AND' into table <table- name>

Former Member
0 Kudos

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.

Former Member
0 Kudos

I think i am late )

Former Member
0 Kudos

Hi,

Thanks a lot. The problem is Solved now.

Thanks,

Siva.