<?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 Re: Problem in inserting the records in a database table in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-inserting-the-records-in-a-database-table/m-p/6470333#M1417158</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do You need to typecast your table? Why not to do it like that:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;PERFORM insert_table_to_db USING 'TAB1' gt_tab1.

FORM insert_table_to_db USING uv_table_name TYPE string
                              ut_table TYPE ANY TABLE.

   INSERT (uv_table_name) FROM TABLE ut_table.

ENDFORM.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can also catch exception like SAPSQL_WA_TOO_SMALL and others which can occur.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Adrian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 20 Jan 2010 07:21:02 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2010-01-20T07:21:02Z</dc:date>
    <item>
      <title>Problem in inserting the records in a database table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-inserting-the-records-in-a-database-table/m-p/6470331#M1417156</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am facing problem to insert the entry in a table. &lt;/P&gt;&lt;P&gt;I am getting the database table name as import parameter of function module and the records to be inserted are in a table structure of type ANY as import parameter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to insert these enteries in the table entered as import parameter.&lt;/P&gt;&lt;P&gt;Can you suggest how should I typecast records enterd in table sructure (type ANY) to the type database table in import parameter to insert the records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Pravesh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jan 2010 11:23:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-inserting-the-records-in-a-database-table/m-p/6470331#M1417156</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-07T11:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in inserting the records in a database table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-inserting-the-records-in-a-database-table/m-p/6470332#M1417157</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi pravesh,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;..................&lt;/P&gt;&lt;P&gt;(The post is not appearing properly......)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This code is not exact, but similar.&lt;/P&gt;&lt;P&gt;On selection screen it will show a field for table name.&lt;/P&gt;&lt;P&gt; It will dynamically select from this table, and will also show the fields.&lt;/P&gt;&lt;P&gt; At the time of showing, I have also written one line to include your requirement,&lt;/P&gt;&lt;P&gt;   where it inserts / updates the table record by record.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;May be this can help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(Please make sure you use this with care, and do not use any standard table in the screen, other wise it might change it).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT abc.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;*------------- COMPULSORY
FIELD-SYMBOLS: &amp;lt;dyntable&amp;gt; TYPE ANY TABLE.
FIELD-SYMBOLS: &amp;lt;dynline&amp;gt; TYPE ANY.
DATA: lt TYPE lvc_t_fcat.
DATA: ls TYPE lvc_s_fcat.
FIELD-SYMBOLS: &amp;lt;fld&amp;gt; TYPE ANY.
DATA : fldname(50) TYPE c.


*--------------------
parameters : tabname LIKE dd02l-tabname DEFAULT 'T001' OBLIGATORY.

*-----------------------------------------------
START-OF-SELECTION.

*-------------- PERFORM
  PERFORM mydyntable USING lt.
  PERFORM GET_DATA.
  PERFORM SHOW_DATA.

  BREAK-POINT.


*---------------------------------------------------------------
* FORM
*---------------------------------------------------------------
FORM GET_DATA.

  SELECT * FROM (TABNAME)
  INTO TABLE &amp;lt;DYNTABLE&amp;gt;.

ENDFORM.                    "GET_DATA




*---------------------------------------------------------------
* FORM
*---------------------------------------------------------------
FORM SHOW_DATA.

  loop at &amp;lt;dyntable&amp;gt; ASSIGNING &amp;lt;dynline&amp;gt;.
    sy-subrc = 0.
    write :/ .
    WHILE SY-SUBRC = 0.
      ASSIGN COMPONENT SY-INDEX OF STRUCTURE &amp;lt;DYNLINE&amp;gt; TO &amp;lt;FLD&amp;gt;.
      WRITE : &amp;lt;FLD&amp;gt;.
    ENDWHILE.
  endloop.

ENDFORM.                    "SHOW_DATA



*---------------------------------------------------------------
* INDEPENDENT FORM
*---------------------------------------------------------------

FORM mydyntable USING ptabname.




*-------------- Create Dyn Table From FC

  FIELD-SYMBOLS: &amp;lt;fs_data&amp;gt; TYPE REF TO data.
  FIELD-SYMBOLS: &amp;lt;fs_1&amp;gt;.
  FIELD-SYMBOLS: &amp;lt;fs_2&amp;gt; TYPE ANY TABLE.
  DATA: lt_data TYPE REF TO data.
  data : lt TYPE lvc_t_fcat .

  DATA : ddfields LIKE ddfield OCCURS 0 WITH HEADER LINE.

*-------------------------------------------
  CALL FUNCTION 'DD_NAMETAB_TO_DDFIELDS'
    EXPORTING
      tabname  = tabname
    TABLES
      ddfields = ddfields.
  .

*------------- CONSTRUCT FIELD LIST

  LOOP AT ddfields.
    ls-fieldname = ddfields-fieldname.
    APPEND ls TO lt.
  ENDLOOP.


  ASSIGN lt_data TO &amp;lt;fs_data&amp;gt;.

  CALL METHOD cl_alv_table_create=&amp;gt;create_dynamic_table
    EXPORTING
      it_fieldcatalog           = lt
    IMPORTING
      ep_table                  = &amp;lt;fs_data&amp;gt;
    EXCEPTIONS
      generate_subpool_dir_full = 1
      OTHERS                    = 2.
  IF sy-subrc &amp;lt;&amp;gt; 0.
  ENDIF.



*------------- Assign Dyn Table To Field Sumbol

  ASSIGN &amp;lt;fs_data&amp;gt;-&amp;gt;* TO &amp;lt;fs_1&amp;gt;.
  ASSIGN &amp;lt;fs_1&amp;gt; TO &amp;lt;fs_2&amp;gt;.
  ASSIGN &amp;lt;fs_1&amp;gt; TO &amp;lt;dyntable&amp;gt;.


ENDFORM. "MYDYNTABLE&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;amit m.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Amit Mittal on Jan 7, 2010 5:05 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jan 2010 11:32:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-inserting-the-records-in-a-database-table/m-p/6470332#M1417157</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-07T11:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in inserting the records in a database table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-inserting-the-records-in-a-database-table/m-p/6470333#M1417158</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do You need to typecast your table? Why not to do it like that:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;PERFORM insert_table_to_db USING 'TAB1' gt_tab1.

FORM insert_table_to_db USING uv_table_name TYPE string
                              ut_table TYPE ANY TABLE.

   INSERT (uv_table_name) FROM TABLE ut_table.

ENDFORM.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can also catch exception like SAPSQL_WA_TOO_SMALL and others which can occur.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Adrian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Jan 2010 07:21:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-inserting-the-records-in-a-database-table/m-p/6470333#M1417158</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-20T07:21:02Z</dc:date>
    </item>
  </channel>
</rss>

