<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Dynamically convert string to internal table in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamically-convert-string-to-internal-table/m-p/4801098#M1124182</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to convert a string to an internal table. There are 2 questions I would like to ask:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. I have created a FM to fulfill my requirement. The codes are as below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
FUNCTION ZCONVERT_STRING_TO_TABLE.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(INPUT_STRING) TYPE  STRING
*"     REFERENCE(DELIMITER) TYPE  CHAR1 DEFAULT ','
*"     REFERENCE(WITH_HEADER) TYPE  CHAR1 DEFAULT 'X'
*"  TABLES
*"      OUTPUT_TABLE
*"----------------------------------------------------------------------

  TYPES:
    BEGIN OF GTY_OUTPUT,
      BUKRS TYPE BUKRS,
      TXT50 TYPE TXA50_ANLT,
    END OF GTY_OUTPUT.

  DATA:
    GW_INPUT TYPE STRING,
    GS_RESULT TYPE MATCH_RESULT,
    GW_BEGIN_POS TYPE I,
    GT_DATA TYPE STANDARD TABLE OF STRING,
    GS_DATA TYPE STRING,
    GW_BUKRS TYPE BUKRS,
    GW_TXT50 TYPE TXA50_ANLT,
    GS_OUTPUT TYPE GTY_OUTPUT.

* Data initialization
  GW_INPUT = INPUT_STRING.

* Remove prefix if exists
  FIND FIRST OCCURRENCE OF '&amp;gt;' IN GW_INPUT RESULTS GS_RESULT.
  GW_BEGIN_POS = GS_RESULT-OFFSET + 1.
  SHIFT GW_INPUT BY GW_BEGIN_POS PLACES.

* Remove header line
  IF WITH_HEADER = 'X'.
    FIND FIRST OCCURRENCE OF CL_ABAP_CHAR_UTILITIES=&amp;gt;NEWLINE IN GW_INPUT RESULTS GS_RESULT.
    GW_BEGIN_POS = GS_RESULT-OFFSET + 1.
    SHIFT GW_INPUT BY GW_BEGIN_POS PLACES.

  ENDIF.

* Import line items into table
  SPLIT GW_INPUT AT CL_ABAP_CHAR_UTILITIES=&amp;gt;NEWLINE INTO TABLE GT_DATA.

* Parse line items and import to output table
  LOOP AT GT_DATA INTO GS_DATA.
    SPLIT GS_DATA AT DELIMITER INTO GW_BUKRS GW_TXT50.
    GS_OUTPUT-BUKRS = GW_BUKRS.
    GS_OUTPUT-TXT50 = GW_TXT50.
    APPEND GS_OUTPUT TO OUTPUT_TABLE.

  ENDLOOP.

ENDFUNCTION.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However my FM can only convert a string to an internal table that has fixed type, that is the string's content also matches with table type.&lt;/P&gt;&lt;P&gt;Could you help me making the FM to be able to apply for every string (the table type dynamically matches with the string's content)?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. In an easier way, could you tell me what existing FM can do this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;Nguyen&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 21 Nov 2008 06:16:54 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-11-21T06:16:54Z</dc:date>
    <item>
      <title>Dynamically convert string to internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamically-convert-string-to-internal-table/m-p/4801098#M1124182</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to convert a string to an internal table. There are 2 questions I would like to ask:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. I have created a FM to fulfill my requirement. The codes are as below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
FUNCTION ZCONVERT_STRING_TO_TABLE.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(INPUT_STRING) TYPE  STRING
*"     REFERENCE(DELIMITER) TYPE  CHAR1 DEFAULT ','
*"     REFERENCE(WITH_HEADER) TYPE  CHAR1 DEFAULT 'X'
*"  TABLES
*"      OUTPUT_TABLE
*"----------------------------------------------------------------------

  TYPES:
    BEGIN OF GTY_OUTPUT,
      BUKRS TYPE BUKRS,
      TXT50 TYPE TXA50_ANLT,
    END OF GTY_OUTPUT.

  DATA:
    GW_INPUT TYPE STRING,
    GS_RESULT TYPE MATCH_RESULT,
    GW_BEGIN_POS TYPE I,
    GT_DATA TYPE STANDARD TABLE OF STRING,
    GS_DATA TYPE STRING,
    GW_BUKRS TYPE BUKRS,
    GW_TXT50 TYPE TXA50_ANLT,
    GS_OUTPUT TYPE GTY_OUTPUT.

* Data initialization
  GW_INPUT = INPUT_STRING.

* Remove prefix if exists
  FIND FIRST OCCURRENCE OF '&amp;gt;' IN GW_INPUT RESULTS GS_RESULT.
  GW_BEGIN_POS = GS_RESULT-OFFSET + 1.
  SHIFT GW_INPUT BY GW_BEGIN_POS PLACES.

* Remove header line
  IF WITH_HEADER = 'X'.
    FIND FIRST OCCURRENCE OF CL_ABAP_CHAR_UTILITIES=&amp;gt;NEWLINE IN GW_INPUT RESULTS GS_RESULT.
    GW_BEGIN_POS = GS_RESULT-OFFSET + 1.
    SHIFT GW_INPUT BY GW_BEGIN_POS PLACES.

  ENDIF.

* Import line items into table
  SPLIT GW_INPUT AT CL_ABAP_CHAR_UTILITIES=&amp;gt;NEWLINE INTO TABLE GT_DATA.

* Parse line items and import to output table
  LOOP AT GT_DATA INTO GS_DATA.
    SPLIT GS_DATA AT DELIMITER INTO GW_BUKRS GW_TXT50.
    GS_OUTPUT-BUKRS = GW_BUKRS.
    GS_OUTPUT-TXT50 = GW_TXT50.
    APPEND GS_OUTPUT TO OUTPUT_TABLE.

  ENDLOOP.

ENDFUNCTION.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However my FM can only convert a string to an internal table that has fixed type, that is the string's content also matches with table type.&lt;/P&gt;&lt;P&gt;Could you help me making the FM to be able to apply for every string (the table type dynamically matches with the string's content)?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. In an easier way, could you tell me what existing FM can do this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;Nguyen&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Nov 2008 06:16:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamically-convert-string-to-internal-table/m-p/4801098#M1124182</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-11-21T06:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically convert string to internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamically-convert-string-to-internal-table/m-p/4801099#M1124183</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;THere is a way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Call method CREATE_DYNAMIC_TABLE of class CL_ALV_TABLE_CREATE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All you need to do is build a field catalog as you build to a ALV display and you will get a reference of the interntal table as an export parameter from this method and then you can use that to populate data.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Nov 2008 10:20:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamically-convert-string-to-internal-table/m-p/4801099#M1124183</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-11-21T10:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically convert string to internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamically-convert-string-to-internal-table/m-p/4801100#M1124184</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sharath,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry for my lateness.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My problem has been solved using Anirban Bhattacharjee's solution as the following link:&lt;/P&gt;&lt;P&gt;Link: [https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/dynamic&lt;EM&gt;Creation&lt;/EM&gt;of&lt;EM&gt;internal&lt;/EM&gt;table&lt;EM&gt;by&lt;/EM&gt;RTTC]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your answer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Nguyen&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Nov 2008 01:22:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamically-convert-string-to-internal-table/m-p/4801100#M1124184</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-11-25T01:22:30Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically convert string to internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamically-convert-string-to-internal-table/m-p/4801101#M1124185</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Seeing your FM code you can do it in a more simpler way as below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA: text TYPE string VALUE 'SAP COMMUNITY NETWORK',
      itab TYPE TABLE OF string WITH HEADER LINE.

SPLIT text AT space INTO TABLE itab.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;~Eswar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Nov 2008 03:50:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamically-convert-string-to-internal-table/m-p/4801101#M1124185</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-11-25T03:50:27Z</dc:date>
    </item>
  </channel>
</rss>

