Application Development and Automation 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: 
Read only

string extraction

Former Member
0 Likes
742

Hi i have a internal table like this

data: begin of jtab occurs 0,

text(65000) type c,

end of jtab.

and it has data like this:

<field name="Industry Type" isUserMetaData="true">

- <![CDATA[ Banks

]]>

</field>

</metaData>

- <content>

- <field name="longDescription">

- <![CDATA[

<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

Duis sodales mollis nunc. Duis elementum. Pellentesque

habitant morbi tristique senectus et netus et malesuada

fames ac turpis egestas. Mauris dui neque, hendrerit semper,

eleifend sed, rhoncus quis, nisl. In in odio at tellus bibendum malesuada.

Mauris adipiscing porta mi. Curabitur tortor. Morbi semper.

Ut aliquet dolor sit amet odio vestibulum suscipit. Vivamus

at enim ut ipsum luctus bibendum. Mauris risus ligula, s

agittis egestas, consequat quis, elementum id, orci. Quisque

laoreet metus ut libero. Aenean erat neque, malesuada pellentesque,

blandit eu, varius id, purus. Quisque iaculis. Aliquam accumsan.

Duis at dolor ac dolor bibendum sodales. Morbi augue. Fusce aliquam

tempus magna. Aenean quam lorem, sagittis a, mattis in, rutrum quis,

nisl. </p>

<p>Ut quis est. In nibh quam, dictum vel, placerat sed, placerat ut

, justo. Mauris ipsum. Quisque et ipsum vitae tortor faucibus adipiscing.

In lacinia elit quis augue. Curabitur aliquam ornare risus. Nam a turpis

et velit bibendum dapibus. Integer pharetra, lorem ac blandit gravida,

nulla nisi pulvinar metus, ut gravida tellus lorem at arcu. Maecenas semper.

Maecenas auctor. Sed congue lacus eu tellus. Ut convallis dictum augue.

Morbi egestas pretium ante. Mauris sollicitudin. Maecenas mauris.</p>

<p><a class="" title="" href="#" target="_self">View More Details</a>&nbsp;</p>

]]>

</field>

- <field name="threadDisplay">

- <![CDATA[ Deposit

]]>

</field>

- <field name="searchDescription">

- <![CDATA[ Banks Industries for&nbsp;Deposit

]]>

</field>

So i want toextract the data after "longDescription"

ie from <p>Lorem ipsum...to.. View More Details</a>&nbsp;</p>. into a string..

ie complete data for field longDescription..i want to extract..

How can we do this?

Thanks in Advance

5 REPLIES 5
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
710

Does it always start and end with

<field name="longDescription">

</field>

If so, you can loop at the internal table and check for <field name="longDescription">, not the row of the internal table, then keep searching for </field>, when you get there not the end.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
710

Loop at jtab.

if jtab-text CS 'longDescription'.

lflag = 'Y'.

continue.

endif.

if jtab-text = '</field>'.

clear lflag.

endif.

check lflag = 'Y'.

check jtab-text NS 'CDATA'.

concatenate lstr jtab-text into lstr.

endloop.

Regards

Anurag

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
710

Please see the sample below. It is checking for the field tags and adjusting accordingly. Also for testing purposes, I was uploading your exact text from the frontend.



report zrich_0001.

data: begin of jtab occurs 0,
      text(65000) type c,
      end of jtab.

data: start type i,
      end type i.

      data: str type string.

start-of-selection.


* Upload test data from frontend.
  call function 'GUI_UPLOAD'
       exporting
            filename = 'C:test.txt'
       tables
            data_tab = jtab.


  <b>loop at jtab.

    if jtab cs  '<field name="longDescription">'.
      start = sy-tabix.
    endif.
    if not start is initial.
      if jtab cs '</field>'.
        end = sy-tabix.
        exit.
      endif.
    endif.

  endloop.</b>

<b>* Adjust for the tags.
  start = start + 2.
  end = end - 2.

  loop at jtab from start to end.
   concatenate str jtab into str separated by space.
  endloop.</b>
  write:/ str.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
710

Hi Ravi, it seems your trying to parse an XML document.

Please refer to this documentation:

http://help.sap.com/saphelp_erp2004/helpdata/en/47/b5413acdb62f70e10000000a114084/frameset.htm

Hope it helps.

Regards,

Gilberto Li

Read only

Former Member
0 Likes
710

Hi ravi,

If all this is in one single line, then

search jtab-text for 'longDescription'.

lv_start = sy-fdpos + 1.

search jtab-text for 'View More Details</a>&nbsp;</p>'.

lv_end = sy-fdpos + 1.

lv_len = lv_end - lv_start.

v_string_part = jtab-text+lv_start(lv_len).

If this text is in internal table,

then

search jtab for 'longDescription'.

lv_start = sy-tabix.

search jtab for 'View More Details</a>&nbsp;</p>'.

lv_end = sy-tabix.

loop at jtab from lv_start to lv_end.

write:/ jtab-text.

endloop.

Regards,

Ravi