<?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: SQL Join Fields of Different Length in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194479#M1375094</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Akagus,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In fact, previous solutions can not work since EKPO~EBELP is not known when you do the CONCATENATE! So these codes will not work...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The way you should do it, is a bit more complcated, since it requires to break the join and to convert your field in a temporary internal table. You ca do something like this :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT blnrb bposb
  INTO TABLE it_fret
  FROM fret
    WHERE blnrb = pono.

" it_fret has 3 fields : blnrb / bposb / ebelp which contains bposb on 6 characters
LOOP AT it_fret ASSIGNING &amp;lt;fs_fret&amp;gt;.
  &amp;lt;fs_fret&amp;gt;-ebelp = &amp;lt;fs_fret&amp;gt;-bposb.
ENDLOOP.

SELECT ebeln ebelp
  INTO TABLE it_ekpo
  FROM ekpo
  FOR ALL ENTRIES IN it_fret
    WHERE ebeln = it_fret-blnrb AND
          ebelp = it_fret-ebelp.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Samuel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 25 Sep 2009 08:21:32 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-09-25T08:21:32Z</dc:date>
    <item>
      <title>SQL Join Fields of Different Length</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194473#M1375088</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have encountered a problem trying to join fields  of different lencth in an SQL statement.  The "value" of the fields are the same (10), however, they are stored as CHAR and as such the leading zeros are resulting in mismatch.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The fields in question are:&lt;/P&gt;&lt;P&gt;FRET-BPOSB length = 6 (e.g. 000010)&lt;/P&gt;&lt;P&gt;EKPO-EBELP length = 5 (e.g. 00010)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is the most efficient approach to create a join using these fields (or rather the most basic approach considering I am a novice APAPer)? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is a simple program I have written to test the join:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT  Z_DOWNLOAD_XDOCK.

*Define internal table type (ty_xdock)
TYPES : BEGIN OF ty_xdock,
          PO      TYPE FRET-BLNRB,
          POITEM  TYPE FRET-BPOSB,
          STO      TYPE EKPO-EBELN,
          STOITEM  TYPE EKPO-EBELP,
        END OF ty_xdock.

*Create internal table (it_xdock)
DATA it_xdock TYPE STANDARD TABLE OF ty_xdock WITH HEADER LINE.

PARAMETERS PONO LIKE FRET-BLNRB OBLIGATORY.

*Select Data
SELECT FRET~BLNRB
       FRET~BPOSB
       EKPO~EBELN
       EKPO~EBELP
  INTO TABLE it_xdock
  FROM FRET
       INNER JOIN EKPO
       ON  FRET~BLNRB = EKPO~EBELN
       AND FRET~BPOSB = EKPO~EBELP
 WHERE FRET~BLNRB = PONO.

LOOP AT it_xdock.
 WRITE: / it_xdock-PO.
 WRITE:   it_xdock-POITEM.
 WRITE: / it_xdock-STO.
 WRITE:   it_xdock-STOITEM.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Sep 2009 06:38:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194473#M1375088</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-25T06:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Join Fields of Different Length</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194474#M1375089</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't think it would be possible to join to different data types having different value (to the system, atleast).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A solution would be to read FRET first and then modify the field in question with a converson exit to match EBELP and then go on selecting record from EKPO.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FOR ALL ENTRIES can also be used.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;Aabhas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Sep 2009 07:26:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194474#M1375089</guid>
      <dc:creator>aabhas_wilmar</dc:creator>
      <dc:date>2009-09-25T07:26:04Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Join Fields of Different Length</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194475#M1375090</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Aabhas,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suspected that this might need to be done in a couple of passes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, being an ABAP novice I have little idea how to code this.  Do you have any sample code or links to helpful references?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your advice.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;akaGus&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Sep 2009 07:31:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194475#M1375090</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-25T07:31:11Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Join Fields of Different Length</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194476#M1375091</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;You can do one thing is that:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;define a char of length "6" ( say l_bposb(6) type c. ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and now what you can do is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;concatenate '0'  EKPO~EBELP into l_bposb.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;now, use the select query as:&lt;/P&gt;&lt;P&gt;*Select Data&lt;/P&gt;&lt;P&gt;SELECT FRET~BLNRB&lt;/P&gt;&lt;P&gt;       FRET~BPOSB&lt;/P&gt;&lt;P&gt;       EKPO~EBELN&lt;/P&gt;&lt;P&gt;       EKPO~EBELP&lt;/P&gt;&lt;P&gt;  INTO TABLE it_xdock&lt;/P&gt;&lt;P&gt;  FROM FRET&lt;/P&gt;&lt;P&gt;       INNER JOIN EKPO&lt;/P&gt;&lt;P&gt;       ON  FRET&lt;SUB&gt;BLNRB = EKPO&lt;/SUB&gt;EBELN&lt;/P&gt;&lt;P&gt;       AND FRET~BPOSB = l_bposb&lt;/P&gt;&lt;P&gt; WHERE FRET~BLNRB = PONO.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;just try this solution and check if it is working fine or not.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Vishnu.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Sep 2009 07:32:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194476#M1375091</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-25T07:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Join Fields of Different Length</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194477#M1375092</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;You can do one thing is that:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;define a char of length "6" ( say l_bposb(6) type c. ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and now what you can do is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;concatenate '0'  EKPO~EBELP into l_bposb.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;now, use the select query as:&lt;/P&gt;&lt;P&gt;*Select Data&lt;/P&gt;&lt;P&gt;SELECT FRET~BLNRB&lt;/P&gt;&lt;P&gt;       FRET~BPOSB&lt;/P&gt;&lt;P&gt;       EKPO~EBELN&lt;/P&gt;&lt;P&gt;       EKPO~EBELP&lt;/P&gt;&lt;P&gt;  INTO TABLE it_xdock&lt;/P&gt;&lt;P&gt;  FROM FRET&lt;/P&gt;&lt;P&gt;       INNER JOIN EKPO&lt;/P&gt;&lt;P&gt;       ON  FRET&lt;SUB&gt;BLNRB = EKPO&lt;/SUB&gt;EBELN&lt;/P&gt;&lt;P&gt;       AND FRET~BPOSB = l_bposb&lt;/P&gt;&lt;P&gt; WHERE FRET~BLNRB = PONO.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;just try this solution and check if it is working fine or not.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Vishnu.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Sep 2009 07:33:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194477#M1375092</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-25T07:33:29Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Join Fields of Different Length</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194478#M1375093</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Vishnu,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried your suggestion, however, I have not yet obtained any EKPO records - therefore I cannot convert the EBELP field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below I have incorporated your code into mine.  The problem is the line "concatenate '0' EKPO~EBELP into l_bposb. " &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT  Z_DOWNLOAD_XDOCK.
 
*Define internal table type (ty_xdock)
TYPES : BEGIN OF ty_xdock,
          PO      TYPE FRET-BLNRB,
          POITEM  TYPE FRET-BPOSB,
          STO      TYPE EKPO-EBELN,
          STOITEM  TYPE EKPO-EBELP,
        END OF ty_xdock.
 
*Create internal table (it_xdock)
DATA: it_xdock TYPE STANDARD TABLE OF ty_xdock WITH HEADER LINE,
      l_bposb(6) type c.
 
PARAMETERS PONO LIKE FRET-BLNRB OBLIGATORY.
 
concatenate '0' EKPO~EBELP into l_bposb. 

SELECT FRET~BLNRB
       FRET~BPOSB
       EKPO~EBELN
       EKPO~EBELP
  INTO TABLE it_xdock
  FROM FRET
 INNER JOIN EKPO
    ON FRET~BLNRB = EKPO~EBELN
   AND FRET~BPOSB = l_bposb
 WHERE FRET~BLNRB = PONO. 

LOOP AT it_xdock.
 WRITE: / it_xdock-PO.
 WRITE:   it_xdock-POITEM.
 WRITE: / it_xdock-STO.
 WRITE:   it_xdock-STOITEM.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Sep 2009 07:45:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194478#M1375093</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-25T07:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Join Fields of Different Length</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194479#M1375094</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Akagus,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In fact, previous solutions can not work since EKPO~EBELP is not known when you do the CONCATENATE! So these codes will not work...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The way you should do it, is a bit more complcated, since it requires to break the join and to convert your field in a temporary internal table. You ca do something like this :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT blnrb bposb
  INTO TABLE it_fret
  FROM fret
    WHERE blnrb = pono.

" it_fret has 3 fields : blnrb / bposb / ebelp which contains bposb on 6 characters
LOOP AT it_fret ASSIGNING &amp;lt;fs_fret&amp;gt;.
  &amp;lt;fs_fret&amp;gt;-ebelp = &amp;lt;fs_fret&amp;gt;-bposb.
ENDLOOP.

SELECT ebeln ebelp
  INTO TABLE it_ekpo
  FROM ekpo
  FOR ALL ENTRIES IN it_fret
    WHERE ebeln = it_fret-blnrb AND
          ebelp = it_fret-ebelp.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Samuel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Sep 2009 08:21:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194479#M1375094</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-25T08:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Join Fields of Different Length</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194480#M1375095</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;Try like this with two seperate select queries&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT  Z_DOWNLOAD_XDOCK.
 
*Define internal table type (ty_xdock)
TYPES : BEGIN OF ty_fret,
          PO         TYPE FRET-BLNRB,
          POITEM  TYPE FRET-BPOSB,
          END OF ty_fret.

TYPES : BEGIN OF ty_xdock,
          PO      TYPE FRET-BLNRB,
          POITEM  TYPE FRET-BPOSB,
          STO      TYPE EKPO-EBELN,
          STOITEM  TYPE EKPO-EBELP,
        END OF ty_xdock.
 
*Create internal table (it_xdock)
DATA: it_xdock TYPE STANDARD TABLE OF ty_xdock WITH HEADER LINE,
           it_fret TYPE STANDARD TABLE OF ty_fret WITH HEADER LINE.
 
PARAMETERS PONO LIKE FRET-BLNRB OBLIGATORY.
 
SELECT BLNRB  BPOSB
into table it_fret 
from FRET
where blnrb = pono.

if sy-subrc = 0.
loop at it_fret.
shift it_fret-poitem left deleting leading '0'.
modify it_fret.
endloop.
endif.

select ebeln ebelp
from ekpo
into corresponding fields of table it_xdock
for all entries in it_fret
where ebeln = it_fret-po and 
    ebelp = it_fret-poitem.

if sy-subrc = 0.

loop at it_xdock.
read table it_fret with key po = it_xdock-sto poitem = stoitem.
if sy-subrc = 0.
move-corresponding it_fret to it_xdock.
modify it_xdock.
endif.
endloop.

 
LOOP AT it_xdock.
 WRITE: / it_xdock-PO.
 WRITE:   it_xdock-POITEM.
 WRITE: / it_xdock-STO.
 WRITE:   it_xdock-STOITEM.
ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Vikranth&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Sep 2009 08:28:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194480#M1375095</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-25T08:28:55Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Join Fields of Different Length</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194481#M1375096</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Using a combination of the advice I have received in this thread I have come up with the following solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's not as elegant as I'd like, but it is surprisingly efficient.  The code takes less than 5 to 10 seconds to select the required data from a few million records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is certainly room for improvement, however, it works.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thankyou everyone for your advice.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Code removed due to faulty SAP Forum formatting, will try to post again later&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: akagus on Sep 29, 2009 9:50 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Sep 2009 07:36:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194481#M1375096</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-29T07:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Join Fields of Different Length</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194482#M1375097</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Could you please post your solution? I am facing the same problem..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Sep 2009 20:53:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194482#M1375097</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-30T20:53:48Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Join Fields of Different Length</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194483#M1375098</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It appears that all formatting is removed from the code when the post exceeds 2500 characters, therefore, I will post the code in two replies.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Part A:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT  Z_DOWNLOAD_XDOCK.

*Define internal table type (ty_xdock)
TYPES : BEGIN OF ty_xdock,
          PO      TYPE FRET-BLNRB,
          POITEM  TYPE EKPO-EBELP,
          POQTY   TYPE FRET-PMENB,
          DC      TYPE FRET-WERKA,
          ARTNO   TYPE FRET-MATNR,
          EAN     TYPE MEAN-EAN11,
          ARTDES  TYPE MAKT-MAKTX,
          STORE   TYPE FRET-ABNNR,
          STOQTY  TYPE FRET-PMENA,
          STO     TYPE FRET-BLNRA,
          STOITEM TYPE EKPO-EBELP,
        END OF ty_xdock,

        BEGIN OF ty_FRET,
          PO      TYPE FRET-BLNRB,
          POITEM  TYPE EKPO-EBELP,
          STO     TYPE FRET-BLNRA,
          STOITEM TYPE EKPO-EBELP,
        END OF ty_FRET,

        BEGIN OF ty_PO,
          PO      TYPE FRET-BLNRB,
          POITEM  TYPE FRET-BPOSB,
          PODEL   TYPE EKPO-LOEKZ,
          POQTY   TYPE EKPO-MENGE,
          POSITE  TYPE EKPO-WERKS,
          ARTNO   TYPE EKPO-MATNR,
          EAN     TYPE MEAN-EAN11,
          ARTDES  TYPE MAKT-MAKTX,
        END OF ty_PO,

        BEGIN OF ty_STO,
          STO     TYPE FRET-BLNRA,
          STOITEM TYPE FRET-BPOSA,
          STODEL  TYPE EKPO-LOEKZ,
          STOFDI  TYPE EKPO-EGLKZ,
          STODCI  TYPE EKPO-ELIKZ,
          STOQTY  TYPE EKPO-MENGE,
          STOSITE TYPE EKPO-WERKS,
        END OF ty_STO.

*Create internal table (it_FRET)
DATA: it_FRET TYPE STANDARD TABLE OF ty_FRET WITH HEADER LINE,
      it_PO TYPE STANDARD TABLE OF ty_PO WITH HEADER LINE,
      it_STO TYPE STANDARD TABLE OF ty_STO WITH HEADER LINE,
      wa_OUTPUT TYPE STANDARD TABLE OF ty_xdock WITH HEADER LINE,
      it_OUTPUT TYPE STANDARD TABLE OF ty_xdock WITH HEADER LINE.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Sep 2009 23:01:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194483#M1375098</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-30T23:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Join Fields of Different Length</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194484#M1375099</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Part B:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECTION-SCREEN BEGIN of BLOCK layar2 WITH FRAME TITLE judul2.
PARAMETER PONO LIKE FRET-BLNRB OBLIGATORY.
SELECTION-SCREEN END OF BLOCK layar2.


*Select FRET Data
SELECT FRET~BLNRB
        FRET~BPOSB
        FRET~BLNRA
        FRET~BPOSA
  INTO TABLE it_FRET
  FROM FRET
  WHERE FRET~BLNRB = PONO.

*Select PO Data
SELECT EKPO~EBELN
       EKPO~EBELP
       EKPO~LOEKZ
       EKPO~MENGE
       EKPO~WERKS
       EKPO~MATNR
       MEAN~EAN11
       MAKT~MAKTX
  INTO TABLE it_PO
  FROM EKPO
  LEFT JOIN MAKT
       ON  EKPO~MATNR = MAKT~MATNR
       LEFT JOIN MEAN
       ON  EKPO~MATNR = MEAN~MATNR
       AND MEAN~HPEAN = 'X'
   FOR ALL ENTRIES IN it_FRET
 WHERE EKPO~EBELN = it_FRET-PO AND EKPO~EBELP = it_FRET-POITEM.

*Select STO Data
 SELECT EKPO~EBELN
       EKPO~EBELP
       EKPO~LOEKZ
       EKPO~EGLKZ
       EKPO~ELIKZ
       EKPO~MENGE
       EKPO~WERKS
 FROM EKPO
      INTO TABLE it_STO
  FOR ALL ENTRIES IN it_FRET
 WHERE EKPO~EBELN = it_FRET-STO AND EKPO~EBELP = it_FRET-STOITEM.

*Output FRET Data only if matching PO and STO lines are found which are not deleted, not FDI and not DCI.
Loop at it_FRET.

*Find matching PO lines
  READ TABLE it_PO
  WITH KEY
  PO = it_FRET-PO
  POITEM = it_FRET-POITEM
  PODEL = ' '.
  IF sy-subrc = 0.
*Find matching STO lines
    READ TABLE it_STO
    WITH KEY
    STO = it_FRET-STO
    STOITEM = it_FRET-STOITEM
    STODEL = ' '
    STOFDI = ' '
    STODCI = ' '.
    IF sy-subrc = 0.
      wa_OUTPUT-PO      = it_FRET-PO.
      wa_OUTPUT-POITEM  = it_FRET-POITEM.
      wa_OUTPUT-POQTY   = it_PO-POQTY.
      wa_OUTPUT-DC      = it_PO-POSITE.
      wa_OUTPUT-ARTNO   = it_PO-ARTNO.
      wa_OUTPUT-EAN     = it_PO-EAN.
      wa_OUTPUT-ARTDES  = it_PO-ARTDES.
      wa_OUTPUT-STORE   = it_STO-STOSITE.
      wa_OUTPUT-STOQTY  = it_STO-STOQTY.
      wa_OUTPUT-STO     = it_FRET-STO.
      wa_OUTPUT-STOITEM = it_FRET-STOITEM.
      APPEND wa_OUTPUT to it_OUTPUT.

    ENDIF.

  ENDIF.

ENDLOOP.

*Output to Excel

ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Sep 2009 23:03:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-join-fields-of-different-length/m-p/6194484#M1375099</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-30T23:03:07Z</dc:date>
    </item>
  </channel>
</rss>

