<?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: dynamically table read / write with field symbols in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamically-table-read-write-with-field-symbols/m-p/5143681#M1192169</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; Answers below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) For this...you assigning an internal table to a work area...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;assign &amp;lt;table_to&amp;gt; to &amp;lt;wa_to&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This should solve the problem..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;* Create the target work area..
DATA: new_line  TYPE REF TO data. 
CREATE DATA new_line LIKE LINE OF &amp;lt;table_to&amp;gt;. 
ASSIGN new_line-&amp;gt;* TO &amp;lt;wa_to&amp;gt;.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now the target work area is created..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) For the second one...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
************New code
   FIELD-SYMBOLS: &amp;lt;FS&amp;gt;,&amp;lt;FS1&amp;gt;.
************New code End.

   loop at &amp;lt;table_from&amp;gt; assigning &amp;lt;wa_from&amp;gt;.
 
      assign component I_KOMP_TRANS-KOMP
        of structure &amp;lt;wa_from&amp;gt; to &amp;lt;l_komp&amp;gt;.
 
      CALL FUNCTION I_KOMP_TRANS-FUBA
           EXPORTING
                I_KOMP = I_KOMP_TRANS-KOMP
                I_ALT  = &amp;lt;l_komp&amp;gt;
           IMPORTING
                E_NEU  = &amp;lt;l_komp&amp;gt;.
 
      break-point.
      assign component 'SYSID' of structure &amp;lt;wa_to&amp;gt; to &amp;lt;l_sysid&amp;gt;.
      &amp;lt;l_sysid&amp;gt; = sy-sysid.
 
************New code
      LOOP AT itab .
         ASSIGN COMPONENT itab-fieldname of structure &amp;lt;WA_FROM&amp;gt; TO &amp;lt;FS&amp;gt;.
         CHECK SY-SUBRC = 0.

         ASSIGN COMPONENT itab-fieldname of structure &amp;lt;WA_TO&amp;gt; TO &amp;lt;FS1&amp;gt;.
         CHECK SY-SUBRC = 0.

* Move from source to target.
         &amp;lt;FS1&amp;gt; = &amp;lt;FS&amp;gt;.

      ENDLOOP.

************New code End

      append &amp;lt;wa_to&amp;gt; to &amp;lt;table_to&amp;gt;.
 
    endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Naren&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 02 Feb 2009 16:52:03 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-02-02T16:52:03Z</dc:date>
    <item>
      <title>dynamically table read / write with field symbols</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamically-table-read-write-with-field-symbols/m-p/5143680#M1192168</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;I like to read dynamically from a table via field symbols. The reading part is working.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But now I like to do some changes on the entry and then write it to another table with a similar structure.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I use SAP 4.6c&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There I have two problems:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. At the statement I get a dump:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&amp;lt;l_sysid&amp;gt; = sy-sysid.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;--&amp;gt; Field symbol has not yet been assigned.&lt;/P&gt;&lt;P&gt;I think that the problem is somewhere around&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;assign &amp;lt;table_to&amp;gt; to &amp;lt;wa_to&amp;gt;.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. the data change inside the loop. There I like to add the sysid to the target-wa and then copy the source-wa it to the new target-wa to append it to the target table.&lt;/P&gt;&lt;P&gt;But this does not work. What kind of code do I need? The "move-correspondig" is not correct.&lt;/P&gt;&lt;P&gt;--&amp;gt; see code around&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;loop at &amp;lt;table_from&amp;gt; assigning &amp;lt;wa_from&amp;gt;.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below you can find my code. The problem is within the last loop-statement.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
FUNCTION Z_MIG_COPY_TABLE.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     REFERENCE(I_TABNAME_FROM) TYPE  TABNAME
*"     REFERENCE(I_TABNAME_TO) TYPE  TABNAME
*"     REFERENCE(I_KOMP_TRANS) LIKE  ZS_KOMP_TRANS STRUCTURE
*"        ZS_KOMP_TRANS OPTIONAL
*"  TABLES
*"      I_SELCON STRUCTURE  ZS_SELCON
*"  EXCEPTIONS
*"      NOT_FOUND
*"      OTHERS
*"----------------------------------------------------------------------
*
* zeilenweiser Aufbau Tabelle I_SELCON z.B.:
* bukrs = 3011
* AND
* bstyp = 'F'
*
* I_KOMP_TRANS
* dient zur Uebersetzung von alt/neu, z.B. bei LIFNR
* der angegebene Funktionsbaustein wird genutzt,
* um den neuen Wert der übergebenen Komponente zu ermitteln
* Angabe z.B.:
* LIFNR

  DATA: dref       TYPE REF TO data,
        dref_to    TYPE REF TO data,
        i_alv_cat  TYPE TABLE OF lvc_s_fcat,
        ls_alv_cat LIKE LINE OF i_alv_cat,
        i_alv_cat_to  TYPE TABLE OF lvc_s_fcat,
        ls_alv_cat_to LIKE LINE OF i_alv_cat.


  DATA: BEGIN OF itab OCCURS 0.
*        INCLUDE STRUCTURE dntab.
          INCLUDE structure DFIES.
  DATA: END OF itab.

  DATA: BEGIN OF itab_to OCCURS 0.
*        INCLUDE STRUCTURE dntab.
          INCLUDE structure DFIES.
  DATA: END OF itab_to.

  FIELD-SYMBOLS: &amp;lt;table_from&amp;gt;   TYPE ANY TABLE.
  FIELD-SYMBOLS: &amp;lt;table_to&amp;gt;     TYPE Standard TABLE.
  FIELD-SYMBOLS: &amp;lt;wa_from&amp;gt;      TYPE ANY.
  FIELD-SYMBOLS: &amp;lt;wa_to&amp;gt;        TYPE ANY.
  FIELD-SYMBOLS: &amp;lt;l_komp&amp;gt;       TYPE ANY.
  FIELD-SYMBOLS: &amp;lt;l_sysid&amp;gt;      TYPE ANY.

  Data: l_alt type ELIFN.
  Data: l_neu type ELIFN.

  CALL FUNCTION 'DDIF_NAMETAB_GET'
       EXPORTING
            TABNAME   = i_tabname_from
       TABLES
            DFIES_TAB = itab
       EXCEPTIONS
            NOT_FOUND = 1
            OTHERS    = 2.
  IF SY-SUBRC = 1.
    raise not_found.
  elseif sy-subrc = 2.
    raise others.
  ENDIF.


  LOOP AT itab .
    ls_alv_cat-fieldname = itab-fieldname.
    ls_alv_cat-ref_table = i_tabname_from.
    ls_alv_cat-ref_field = itab-fieldname.
    APPEND ls_alv_cat TO i_alv_cat.
  ENDLOOP.

* build internal table
  CALL METHOD cl_alv_table_create=&amp;gt;create_dynamic_table
      EXPORTING
        it_fieldcatalog = i_alv_cat
      IMPORTING
        ep_table = dref.

  ASSIGN dref-&amp;gt;* TO &amp;lt;table_from&amp;gt;.


  CALL FUNCTION 'DDIF_NAMETAB_GET'
       EXPORTING
            TABNAME   = i_tabname_to
       TABLES
            DFIES_TAB = itab_to
       EXCEPTIONS
            NOT_FOUND = 1
            OTHERS    = 2.
  IF SY-SUBRC = 1.
    raise not_found.
  elseif sy-subrc = 2.
    raise others.
  ENDIF.

  LOOP AT itab_to.
    ls_alv_cat_to-fieldname = itab_to-fieldname.
    ls_alv_cat_to-ref_table = i_tabname_to.
    ls_alv_cat_to-ref_field = itab_to-fieldname.
    APPEND ls_alv_cat_to TO i_alv_cat_to.
  ENDLOOP.

*  break-point.
* build internal table
  CALL METHOD cl_alv_table_create=&amp;gt;create_dynamic_table
      EXPORTING
        it_fieldcatalog = i_alv_cat_to
      IMPORTING
        ep_table = dref_to.

  ASSIGN dref_to-&amp;gt;* TO &amp;lt;table_to&amp;gt;.


*Select Ursprungstabelle mit Selektionsbedingungen
  SELECT * FROM (i_tabname_from) up to 5 rows
    INTO CORRESPONDING FIELDS OF TABLE &amp;lt;table_from&amp;gt;
    where (i_selcon).

*  break-point.
*Aufbau interne Tabelle mit eventuell geänderten Feldern

  assign &amp;lt;table_to&amp;gt; to &amp;lt;wa_to&amp;gt;.

  if not I_KOMP_TRANS is initial.
    loop at &amp;lt;table_from&amp;gt; assigning &amp;lt;wa_from&amp;gt;.

      assign component I_KOMP_TRANS-KOMP
        of structure &amp;lt;wa_from&amp;gt; to &amp;lt;l_komp&amp;gt;.

      CALL FUNCTION I_KOMP_TRANS-FUBA
           EXPORTING
                I_KOMP = I_KOMP_TRANS-KOMP
                I_ALT  = &amp;lt;l_komp&amp;gt;
           IMPORTING
                E_NEU  = &amp;lt;l_komp&amp;gt;.

      break-point.
      assign component 'SYSID' of structure &amp;lt;wa_to&amp;gt; to &amp;lt;l_sysid&amp;gt;.
      &amp;lt;l_sysid&amp;gt; = sy-sysid.

*      move-corresponding &amp;lt;wa_from&amp;gt; to &amp;lt;wa_to&amp;gt;.


      append &amp;lt;wa_to&amp;gt; to &amp;lt;table_to&amp;gt;.

    endloop.
*    break-point.
*Speichern der ausgelesenen Daten in Zieltabelle
    MODIFY (i_tabname_to) FROM TABLE &amp;lt;table_to&amp;gt;.
    if sy-subrc &amp;lt;&amp;gt; 0.
      MESSAGE E001(ZMESSAGES) WITH i_tabname_to.
*   Fehler beim Modify von Tabelle '&amp;amp;'.
    endif.

  else.
*Speichern der ausgelesenen Daten in Zieltabelle
    MODIFY (i_tabname_to) FROM TABLE &amp;lt;table_from&amp;gt;.
    if sy-subrc &amp;lt;&amp;gt; 0.
      MESSAGE E001(ZMESSAGES) WITH i_tabname_to.
*   Fehler beim Modify von Tabelle '&amp;amp;'.
    endif.
  endif.

  commit work.
  if sy-subrc &amp;lt;&amp;gt; 0.
    MESSAGE E002(ZMESSAGES) WITH i_tabname_to.
*   Fehler beim Commit von Tabelle '&amp;amp;'.
  endif.

*  break-point.
ENDFUNCTION.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot for any hints.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Tom&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Feb 2009 16:18:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamically-table-read-write-with-field-symbols/m-p/5143680#M1192168</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-02-02T16:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: dynamically table read / write with field symbols</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamically-table-read-write-with-field-symbols/m-p/5143681#M1192169</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; Answers below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) For this...you assigning an internal table to a work area...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;assign &amp;lt;table_to&amp;gt; to &amp;lt;wa_to&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This should solve the problem..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;* Create the target work area..
DATA: new_line  TYPE REF TO data. 
CREATE DATA new_line LIKE LINE OF &amp;lt;table_to&amp;gt;. 
ASSIGN new_line-&amp;gt;* TO &amp;lt;wa_to&amp;gt;.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now the target work area is created..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) For the second one...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
************New code
   FIELD-SYMBOLS: &amp;lt;FS&amp;gt;,&amp;lt;FS1&amp;gt;.
************New code End.

   loop at &amp;lt;table_from&amp;gt; assigning &amp;lt;wa_from&amp;gt;.
 
      assign component I_KOMP_TRANS-KOMP
        of structure &amp;lt;wa_from&amp;gt; to &amp;lt;l_komp&amp;gt;.
 
      CALL FUNCTION I_KOMP_TRANS-FUBA
           EXPORTING
                I_KOMP = I_KOMP_TRANS-KOMP
                I_ALT  = &amp;lt;l_komp&amp;gt;
           IMPORTING
                E_NEU  = &amp;lt;l_komp&amp;gt;.
 
      break-point.
      assign component 'SYSID' of structure &amp;lt;wa_to&amp;gt; to &amp;lt;l_sysid&amp;gt;.
      &amp;lt;l_sysid&amp;gt; = sy-sysid.
 
************New code
      LOOP AT itab .
         ASSIGN COMPONENT itab-fieldname of structure &amp;lt;WA_FROM&amp;gt; TO &amp;lt;FS&amp;gt;.
         CHECK SY-SUBRC = 0.

         ASSIGN COMPONENT itab-fieldname of structure &amp;lt;WA_TO&amp;gt; TO &amp;lt;FS1&amp;gt;.
         CHECK SY-SUBRC = 0.

* Move from source to target.
         &amp;lt;FS1&amp;gt; = &amp;lt;FS&amp;gt;.

      ENDLOOP.

************New code End

      append &amp;lt;wa_to&amp;gt; to &amp;lt;table_to&amp;gt;.
 
    endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Naren&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Feb 2009 16:52:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamically-table-read-write-with-field-symbols/m-p/5143681#M1192169</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-02-02T16:52:03Z</dc:date>
    </item>
    <item>
      <title>Re: dynamically table read / write with field symbols</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamically-table-read-write-with-field-symbols/m-p/5143682#M1192170</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Naren&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks a lot for your help. It working correct now.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks and regards&lt;/P&gt;&lt;P&gt;Tom&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Feb 2009 17:45:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamically-table-read-write-with-field-symbols/m-p/5143682#M1192170</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-02-02T17:45:40Z</dc:date>
    </item>
  </channel>
</rss>

