Tag Archive ABAP SQL

Get customer address

ABAP code to get address from KUNNR (customer number) :

    SELECT SINGLE tsad3t~title_medi AS title, but000~name_org1, but000~name_org2,
                  but000~name_org3, but000~name_org4, adrc~po_box, adrc~street,
                  adrc~post_code1, adrc~city1, adrc~tel_number
      FROM but000
      LEFT OUTER JOIN tsad3t ON tsad3t~title = but000~title " Get the title (and 
                            AND tsad3t~langu = @sy-langu    " not the code)
      INNER JOIN but020 ON but020~partner = but000~partner
      INNER JOIN adrc   ON adrc~addrnumber = but020~addrnumber
      INTO @DATA(ls_customer)
      WHERE but000~partner = @lv_kunnr. " <== Specify customer number

Use statement CLIENT SPECIFIED when mandant is specified in SELECT statement

If you want to add the mandant in your where clause (to force use of an index for instance), you have to add statement CLIENT SPECIFIED.

    SELECT * FROM table_name CLIENT SPECIFIED INTO TABLE gi_table_name
      FOR ALL ENTRIES IN li_table
      WHERE mandt     = sy-mandt                 " To force Index 001
        AND field1    = li_table-field1
        AND field1    = li_table-field2.