Function Returns the object linked to an attribute
Example myobj =
s10link( "kunnr" ).
Format data:
  myattrname type string,
  myobj type /s10/any.

myobj =
  s10link( myattrname ).
Parameters
Name Type Description
attrname string
Attribute name
obj /s10/any
Linked object
Description With s10link() foreign key relationships of the database system can be used in a simple and performant way. The s10link() method returns a different object for an attribute depending on its content, which is assigned via a foreign key relationship stored in the class (see below). The same object is always assigned to the same attribute value within a class. If the attribute value is initial, no object is created and an empty object reference is returned.
s10link() is called automatically by the S10 framework if a compound name with dot notation is specified in HTML for name="...", e.g. name="adrnr.title", and the first attribute (here "adrnr") is not of the type object or table.
The first specified attribute is interpreted as a foreign key relationship into another table. In the example "adrnr.title" "adrnr" is an address number for which the values are stored in another SAP table "ADRC". The S10 framework then reads the column "title" there.
Prerequisite for this mechanism is:
(a) In the S10 class, a link, i.e. a foreign key relationship, is assigned to the attribute "adrnr". This can be done explicitly in the class or implicitly via the SAP Data Dictionary.
Explicitly, the link class is assigned by defining a constant named "dblink_xxxxx" where xxxxx is the name of the corresponding attribute. The value of the constant is the name of the assigned class. Example:

constants:
      
dblink_adrnr type string value 'db_adrc'.

This assigns the link class "db_adrc" to the attribute "adrnr", which creates the link to the database table ADRC. The class "db_adrc" can look like the following, for example:

class db_adrc definition inheriting from /s10/any.

  
public section.

    
data:
      
addrnumber       type adrc-addrnumberAddress number
      title  
          type adrc-title" Title
      name1            
type adrc-name1" Name
      name2            
type adrc-name2" Name 2
      name3            
type adrc-name3" Name 3
      name4            
type adrc-name4" Name 4
      
name_text        type adrc-name_textConverted Name
      
name_co          type adrc-name_co" c/o
      city1            
type adrc-city1" City
      city2            
type adrc-city2District
      
po_box_num       type adrc-po_box_num" PO Box w/o No.
      
time_zone        type adrc-time_zone. Time zone
    

    
constants:
       
dbtablename type string value 'adrc'for select

endclass.  

You can have such classes generated automatically from database tables via the S10 utilities.

If no explicit link is assigned, the value table of the respective attribute is read from the data dictionary, prefixed with "db_" and used as the class name of the link class.

(b) The automatic database access is done by the S10 framework with a call to s10databaseread(), where the first key field is set, in the example the address number. If the language key is a key field, the language key of the current session is used for this.
The S10 system remembers per session all objects created via a link in the calling class and manages them via a hash table, so that access is very fast for repeating attribute values.

In an application that changes data in the foreign key tables, e.g. implements a change of the customer address, you should not use the link mechanism for the changing data, otherwise the old values will still be displayed.
You can use the link mechanism also multi-level, e.g.: name="kunnr.adrnr.title". In this case first the link to "kunnr" is followed, i.e. table "KNA1" is read in class "db_kna1", and then the address number "adrnr" is evaluated there and the database table "ADRC" is read via the link class "db_adrc".


Example HTML

 <!-- Name 1 -->
 
<div class="infoblock">
   <label class='label output' name="kunnr.name1"></label><br />

  
<span class='output' type="text" name='kunnr.name1'></span>
 </div>


 
<!-- Time zone -->
 <div class="infoblock2">
   <label class='label output' name="kunnr.adrnr.time_zone"></label><br />
   <span class='output' type="text" name='kunnr.adrnr.time_zone'></span>

  
<span class='output' type="text" name='kunnr.adrnr.time_zone@text'></span>
 </div
>


Display:

 

You can use both a local class defined in your program and a global class (transaction SE24) as a link class. This is convenient if you want to make general functionality available to several S10 applications when displaying objects via the link mechanism.

As an example, in a customer list we display a small country flag and the country currency in addition to the country name:

 

For this purpose, we provide the attribute "land1" with a link to a global class, which we call "zz_link_t005"; the name is freely selectable. This class provides information about the country key, in particular the country currency "waers" as well as an HTML representation of the country flag "countryflag_html".

HTML

<div class='outputcelldiv'      style="width: 90px;"   name="kunnr"></div>
<div class='outputcelldiv'      style="width: 290px;"  name="name1"></div>           
<div class='outputcellhtmldiv'  style="width: 24px;"   name="land1.countryflag_html"></div>
<div class='outputcelldiv'      style="width: 200px;"  name="land1.landx50"></div>
<div class='outputcelldiv'      style="width: 80px;"   name="land1.waers"></div>

For the representation of the country flag, which is transferred as HTML string, we have specified the class "outputcellhtmldiv", because with "outputcelldiv" the HTML string would be output.

In our own class it is now sufficient to assign the link class "zz_link_t005" to the attribute "land1":

ABAP

* attribute links
    
constants:
      dblink_land1 
type string value 'zz_link_t005'.

In this way, any S10 application can access the information provided by the class "zz_link_t005" by assigning the link class and naming the desired attributes in HTML, i.e. "land1.countryflag_html", "land1.landx50", "land1.waers". The S10 framework ensures that in a list with repeating country keys, the information is read or built only once each.

The reusable class "zz_link_t005" is defined in SE24. Here is the source code based representation, which can be used as a local class definition as well:     


 class zz_link_t005 definition inheriting from /s10/any.
 
  
public section.

    
data land1 type t005-land1.          " Country Key
    data lnplz type t005-lnplz.          " Postal code length
    data intca3 type t005-intca3.        " ISO code 3 char
    data waers type t005-waers.          " Country currency
    data landx type t005t-landx.         " Country text 
    data landx50 type t005t-landx50.     " Country text 50 characters

    data countryflag_html type string.   " Country flag as HTML code (.gif image)
    
    
constants dbtablename type string value 't005'" for database access

    
methods:
     build_countryflag_html
      
importing
        land1 type t005-land1
      
exporting
        countryflag_html type string,
    
     build_texts
      
importing
        land1 type t005-land1
      
exporting
        landx  type t005t-landx
        landx50 
type t005t-landx50.

endclass.


class zz_link_t005 implementation.

  
method build_countryflag_html.
    countryflag_html 
        |<img src='../../../ISO flags/| && land1 && |.gif/>|.
  endmethod.

  
method build_texts.
    select single landx landx50 from t005t into (landx,landx50)
      where land1 land1 and spras sy-langu.
  endmethod.
  
endclass.
 

 

Components S10 Framework