<?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: SELECT... INTO CORRESPONDING FIELDS OF TABLE in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-corresponding-fields-of-table/m-p/4441896#M1053773</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Avraham,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead of using INTO CORRESPONDING FIELDS in the second select, use the statement APPENDING CORRESPONDING FIELDS to solve your issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Farzan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 19 Sep 2008 04:10:01 GMT</pubDate>
    <dc:creator>former_member137336</dc:creator>
    <dc:date>2008-09-19T04:10:01Z</dc:date>
    <item>
      <title>SELECT... INTO CORRESPONDING FIELDS OF TABLE</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-corresponding-fields-of-table/m-p/4441893#M1053770</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Let's say I did one SELECT using INTO CORRESPONDING FIELDS OF TABLE itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let's consider the table I selected from had the fields A, B, and C.&lt;/P&gt;&lt;P&gt;Now let's assume I do another select, now using FOR ALL ENTRIES, because I need the previous populated internal table - but now I'm selecting from a table that contains fields B, C and D.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Assuming my destination table itab is made of a structure of A, B, C and D, is it expected at the end that I whatever values I might have had for field A I lose them, because the 2nd select was made against a table that doesn't have it ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Because that's what is happening, and I would like to keep the values of A the 1st query brought me. But when I execute the 2nd query, it brings new rows - ok - but all the values I had for field A, which doesn't exist in this table in the FROM clause in the 2nd select, get erased.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Is there a way to prevent this from happening ?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In terms of code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES:  BEGIN OF ty_zcar,
          vbeln TYPE likp-vbeln,
          exidv TYPE vekp-exidv,
          venum TYPE vekp-venum,
        END OF ty_zcar,

        tt_zcar TYPE STANDARD TABLE OF ty_zcar.

DATA:   gt_zcar TYPE tt_zcar.

    SELECT * FROM likp
    INTO CORRESPONDING FIELDS OF TABLE lt_zcar
    WHERE likp~vbeln = p_vbeln.

  CHECK lt_zcar IS NOT INITIAL. "so the select below doesnt do a cross join with table lips

  SELECT * FROM lips
    INNER JOIN vepo
      ON  vepo~vbeln = lips~vbeln AND
          vepo~posnr = lips~posnr
    INTO CORRESPONDING FIELDS OF TABLE gt_zcar
    FOR ALL ENTRIES IN lt_zcar
    WHERE lips~vbeln = lt_zcar-vbeln.

  lt_zcar = gt_zcar.

  SELECT exidv FROM vekp
    INTO CORRESPONDING FIELDS OF TABLE gt_zcar
    FOR ALL ENTRIES IN lt_zcar
    WHERE vekp~venum = lt_zcar-venum.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What happens is that VEKP doesn't have the field VBELN, while all the others above the last select do, but I'm losing the values I got at so far at the end.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Avraham&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Sep 2008 15:01:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-corresponding-fields-of-table/m-p/4441893#M1053770</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-09-18T15:01:09Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT... INTO CORRESPONDING FIELDS OF TABLE</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-corresponding-fields-of-table/m-p/4441894#M1053771</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why don't you fill GT_ZCAR in one go using a JOIN select involving all four tables? They seem to have clear relationships, and you are selecting for one VBELN only. This might get rid of the problem.&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Sep 2008 15:13:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-corresponding-fields-of-table/m-p/4441894#M1053771</guid>
      <dc:creator>ThomasZloch</dc:creator>
      <dc:date>2008-09-18T15:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT... INTO CORRESPONDING FIELDS OF TABLE</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-corresponding-fields-of-table/m-p/4441895#M1053772</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Avraham,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your programming approach is not correct. &lt;/P&gt;&lt;P&gt;If you want to update only a single field in an internal table, you need to first populate that field and the linking field into a new internal table&lt;/P&gt;&lt;P&gt;and then  ( logic is as follows)&lt;/P&gt;&lt;P&gt;LOOP at first internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Read the second internal table using the linking field.&lt;/P&gt;&lt;P&gt;update firsdt internal table with field value from second internal table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="------------------------------------------------------------------------------" /&gt;&lt;P&gt;See the corrected code below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TYPES:  BEGIN OF ty_zcar,&lt;/P&gt;&lt;P&gt;          vbeln TYPE likp-vbeln,&lt;/P&gt;&lt;P&gt;          exidv TYPE vekp-exidv,&lt;/P&gt;&lt;P&gt;          venum TYPE vekp-venum,&lt;/P&gt;&lt;P&gt;        END OF ty_zcar,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;        tt_zcar TYPE STANDARD TABLE OF ty_zcar.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA:   gt_zcar TYPE tt_zcar WITH HEADER LINE,&lt;/P&gt;&lt;P&gt;        lt_zcar TYPE tt_zcar WITH HEADER LINE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;types : begin of ty_vekp,&lt;/P&gt;&lt;P&gt;         venum like vekp-venum,&lt;/P&gt;&lt;P&gt;         exidv like vekp-exidv,&lt;/P&gt;&lt;P&gt;       end of ty_vekp.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : i_vekp type ty_vekp OCCURS 0 WITH HEADER LINE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECTION-SCREEN begin of block b1.&lt;/P&gt;&lt;P&gt;  parameters : p_vbeln like vbak-vbeln.&lt;/P&gt;&lt;P&gt;SELECTION-SCREEN end of block b1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    SELECT * FROM likp&lt;/P&gt;&lt;P&gt;    INTO CORRESPONDING FIELDS OF TABLE lt_zcar&lt;/P&gt;&lt;P&gt;    WHERE likp~vbeln = p_vbeln.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  CHECK lt_zcar[] IS NOT INITIAL. "so the select below doesnt do a cross join with table lips&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  SELECT * FROM lips&lt;/P&gt;&lt;P&gt;    INNER JOIN vepo&lt;/P&gt;&lt;P&gt;      ON  vepo&lt;SUB&gt;vbeln = lips&lt;/SUB&gt;vbeln AND&lt;/P&gt;&lt;P&gt;          vepo&lt;SUB&gt;posnr = lips&lt;/SUB&gt;posnr&lt;/P&gt;&lt;P&gt;    INTO CORRESPONDING FIELDS OF TABLE gt_zcar&lt;/P&gt;&lt;P&gt;    FOR ALL ENTRIES IN lt_zcar&lt;/P&gt;&lt;P&gt;    WHERE lips~vbeln = lt_zcar-vbeln.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  lt_zcar[] = gt_zcar[].&lt;/P&gt;&lt;P&gt;*----&lt;/P&gt;&lt;HR originaltext="---------------------------------------------------------------------" /&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;CORRECTED CODE&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;*----&lt;/P&gt;&lt;HR originaltext="------------------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  SELECT exidv FROM vekp&lt;/P&gt;&lt;P&gt;    INTO CORRESPONDING FIELDS OF TABLE i_vekp&lt;/P&gt;&lt;P&gt;    FOR ALL ENTRIES IN lt_zcar&lt;/P&gt;&lt;P&gt;    WHERE vekp~venum = lt_zcar-venum.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;refresh lt_zcar.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at gt_zcar.&lt;/P&gt;&lt;P&gt;   read table i_vekp with key venum = gt_zcar-venum.&lt;/P&gt;&lt;P&gt;   if sy-subrc = 0.&lt;/P&gt;&lt;P&gt;     gt_zcar-exidv = i_vekp-exidv.&lt;/P&gt;&lt;P&gt;   endif.&lt;/P&gt;&lt;P&gt;   append gt_zcar to lt_zcar.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;refresh gt_zcar.&lt;/P&gt;&lt;P&gt;gt_zcar[] = lt_zcar[].&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Jyothi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Sep 2008 15:18:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-corresponding-fields-of-table/m-p/4441895#M1053772</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-09-18T15:18:04Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT... INTO CORRESPONDING FIELDS OF TABLE</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-corresponding-fields-of-table/m-p/4441896#M1053773</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Avraham,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead of using INTO CORRESPONDING FIELDS in the second select, use the statement APPENDING CORRESPONDING FIELDS to solve your issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Farzan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Sep 2008 04:10:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-into-corresponding-fields-of-table/m-p/4441896#M1053773</guid>
      <dc:creator>former_member137336</dc:creator>
      <dc:date>2008-09-19T04:10:01Z</dc:date>
    </item>
  </channel>
</rss>

