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: 

Extract a word from a sentence

Former Member
0 Kudos

Hi all...

i gt this sql statement.

select firstname from student where admino = '123'.

i want to extract a word after the word from which is <b>student</b>.

how can i do it?

thks

9 REPLIES 9

Former Member
0 Kudos

select firstname

from student

where admino = '123'

and firstname = 'Student'.

Minal Nampalliwar

Former Member
0 Kudos

think gt me wrong....

let me rephrase my sentence.

exmaple.

i have a good friend name ken.

i want to extract a word after 'good'.

The extract word i want is <b>friend</b>.

how can i do it?

gopi_narendra
Active Contributor
0 Kudos

> select firstname from student where admino = '123'.

do it like this

select <fields> from STUDENT into table IT_STUD where ADMINO = '123'.

loop at IT_STUD.

move IT_STUD-FIRSTNAME+7(13) to IT_FINAL-FIRSTNAME.

move fields to IT_FINAL-fields. " respectvie fields

append IT_FINAL.

endloop.

supposing that the firstname length is 20

<b>OK, from your latest post which you just happened to post. I under stand like this and see the reply.</b>

loop at IT_STUD.
split IT_STUD-FIRSTNAME at SPACE into t1 t2 t3 t4. "I AM GOPI NARENDRA
 " now t1 contains I
 " t2 contains AM
 " t3 contains GOPI
 " t4 contains NARENDRA
move fields to IT_FINAL-fields. " respectvie fields
append IT_FINAL.
endloop.

Regards

Gopi

Message was edited by:

Gopi Narendra

0 Kudos

think u misunderstand from the previous entry pls look at the latest entry.

Anyway thks for helping.

i want to extract a word out from a sentence. The word i want to extract out is after this word 'good'. I expecting <b>friend</b> to be the extracted value. How can i do it?

the sentence is: i have a good friend name ken.

0 Kudos
DATA: names(30)    TYPE c VALUE 'i have a good friend name gary',
      one(10)      TYPE c,
      two(10)      TYPE c,
      three(10)    TYPE c,
      four(10)     TYPE c,
      five(10)     TYPE c,
      six(10)      TYPE c,
      seven(10)    TYPE c.

SPLIT names AT space INTO one two three four five six seven.

WRITE : / one.
WRITE : / two.
WRITE : / three.
WRITE : / four.
WRITE : / five.
WRITE : / six.
WRITE : / seven.

Here FIVE give the value 'FRIEND'.

Hope this is what you want.

Regards

Gopi

0 Kudos

yes! you have answer my question partially.

i just like to retrieve the value out after the word <b>good.</b>

example 1: i have a <b>good</b> friend name gary

friend is the value i want to retrieve.

example 2: i have a <b>good</b> habit that is hardworking.

habit is the value i want to retrieve.

any idea

0 Kudos

Its the same SPLIT command which can do this.

Use the SPLIT command for the same sentence "i have a good habit that is hardworking" now use the SPLIT command at space into 1 2 3 4 5 6 7 8 9 .... and so on

5 will contain the HABIT.

Regards

Gopi

Former Member
0 Kudos

try this

data : text(70) value 'i have a good friend name gary' .

data : text1(20),text2(20),text3(40).

clear : text1,text2,text3.

split text at 'good' into text1 text3.

clear : text1,text2.

condense text3.

split text3 at space into text2 text1.

write : / text2.

regards

shiba dutta

0 Kudos

thank you u solve my problem.