Table type with reference type - how to sort?

I have an internal table lt_refs of the type ZXX_TT_REFS.
The table type ZXX_TT_REFS is a table of references ("ref. type") to the class ZCL_C.
The class C has an attribute attr1.
Now I would like to sort that table. Is there an easy (built-in) way to do this?
DATA lt_refs TYPE ZXX_TT_REFS.
DATA lr_ref  TYPE REF TO ZCL_C.
LOOP AT lt_refs INTO lr_ref.
  "Sort based on lr_ref->attr1. ?
ENDLOOP.
"or can I
SORT lt_refs BY attr1.
"directly?

Danial, please see the following.  In the case where you want to sort your reference by an attribute within the object, you can do something like this.
report zrich_0001.
*       CLASS lcl_tab DEFINITION
class lcl_app definition.
  public section.
    data: attri type i.
    methods: constructor importing im_attri type i.
endclass.
*       CLASS lcl_tab IMPLEMENTATION
class lcl_app implementation.
  method constructor.
    attri = im_attri.
  endmethod.
endclass.
data: a_app type ref to lcl_app.
data: a_app_list type table of ref to lcl_app.
start-of-selection.
  create object a_app exporting im_attri =  3 .
  append a_app to a_app_list.
  create object a_app exporting im_attri =  2 .
  append a_app to a_app_list.
  create object a_app exporting im_attri =  1 .
  append a_app to a_app_list.
  sort a_app_list by <b>table_line->attri</b> ascending .
  check sy-subrc = 0.
Here is the documentation.
<i>
<b>
Access to Attributes with References in Internal Tables</b>
If the line type of internal tables includes reference variables as components comp, the attributes attr of the object to which the reference in a line points can be used as key values for reading, sorting and changing table rows. This is possible in the following statements:
,,LOOP AT itab ... WHERE comp->attr ...
,,READ TABLE itab ... WITH [TABLE] KEY comp->attr = ...
<b>,,SORT itab BY comp->attr ...</b>
,,DELETE itab WHERE comp->attr ...
,,MODIFY itab ... TRANSPORTING ... WHERE comp->attr ...
<b>If a table contains unstructured lines with the type of a reference variable, the attributes of the object to which a line points can be addressed using TABLE_LINE->attr.</b>
</i>
Regards,
RIch Heilman

Similar Messages

  • How to create a record for table PLAF with order type 'NB'.

    How to create a record for table PLAF with order type 'NB'(standard purchase order).
    who can tell me the T-code or some usefull information?
    Thanks.

    Hi
    This will be updated automatically when generate planned orders thru MRP. (MD02)
    regards
    Srinivas

  • How to create table view with reference table

    Hi experts,
    How to create table view with reference table in SE11, plz gve me stp by stp procedure.
    pints grnded for hlp.

    Hi
    Go to Tcode se11 choose view and enter the name and create a popup opens up choose database view option
    enter the description
    On the left hand side choose the table name.
    Click on view fields tab and choose your table fields.Here you can choose which fields you want in your view.
    Save and then activate.
    Hope this helps.
    Regards,
    Harish

  • Data Type with reference and view maintenance

    Dear all,
    There are two questions that I want to ask.
    1.     Error when referencing a table with data type = u2018STRINGu2019.
    I have a Z table with some fields = u2018stringu2019, when I use this as a reference, an error prompted.
    "ZTBL_ABC" must be a flat structure. You cannot use internal
    tables, strings, references, or structures as components.-
    2.     Error in generating the View maintenance for field length > 255.
    Actually, I want to create fields with
    1.     data type = char(255),
    2.     data type = text
    3.     data type = char(3000)
    It is okay if I create the field with the selected size, however, when I generate the View maintenance (which can be access through SM30); it does not allow me to do so. It still not working if I change it into string. How can I create such table and use the table maintenance, as well as using that as the reference type of an internal table for another program?
    Regards,
    Mandy Au

    Hello,
    1st of all a table which has a field of type string can be converted in to table maintenance because TM does not support string type as it becomes a very big field to be displayed on screen ... so u need to change that.
    and then about the CHAR of length 3000 is too big ... to have a max limit of 255.
    If you change this both u will be able to generate TM.
    Incase after changing the field length it it gives error in activatin your table then go to SE14 put your table name EDIT and then Adjust n activate it....
    hope this was helpful
    --- Close the post once you get the solution

  • One particular Po document type with reference to one particular PR documen

    Dear all
           I want to create one PO for a particular document type only with reference to one PR, that to after release of PR, how can i do it.

    Hi
    Goto, OLME ---> PO ---> Define Document types -
    > Choose your PO Doc.Type...> there in Linking PR and PO Doc.Type....allow your PR doc.Type only.....
    Also in OLME -
    > PR -
    > Define Document types -
    > Choose your PR Doc.Type...>There also you maintain this PR Doc.type only as ref. to your PO doc. type....
    Then Configure Release Statergy in such that All your new PR Doc. type PRs should gone thro the Release Statergy.....(use field CEKKO-BSART)
    Reward if useful
    Regards
    S.Baskaran

  • Create a Sales order (type) with reference to another Sales order only

    Hi
    I have 2 Order Types (ZRA and ZRC). The ZRA should always be created only with reference to a ZRC. It should not be allowed to create ZRA directly.
    I believe I can remove the Item categories somewhere, but can't figure it out. Any help is appreciated
    Regards,
    Vikas

    Hi
    In sd doc tyoes in t code vov8 in the general control tab you can define mandatory referance and in that you can choose option C which means the referance doc should be only a sales doc not enquiry or quotation
    Pls reply whether my suggestion has helped you
    Raja

  • Manual Excise condition type with calculation type as FIXED AMOUNT

    Dear Gurus,
    I have used a manual excise condition (JMAN) in my pricing procedure the difference is that I've changed its calcultaion type to FIXED AMOUNT.
    And in the same pricing procedure I have also got a percentage based Excise condition (ZEXC).
    And in any transaction either of the one that is JMAN or ZEXC will be used.
    The Manual Excise condition is used basically when the raw material sale takes place. The requirement is as such that they should be able to enter the duty value in INR and not in percentage. Please go through the example below
    *(For Example I am procuring raw material of 100 kg worth 10000 at 8% of excise duty. Excise duty will be 800 for 10000rs. So it will be 8 rs per KG.
    And now suppose I am utilizing 80 kg for production and want to sell remaining 20 kg. the Excise duty charged should be 160 rs. considering the rate per unit is 8rs.)*
    In this case user wants to enter the value in INR and not in percentage.
    And normally for the finished goods the percentage based condition is used.
    Now what my issue is that how will I copy the value from JMAN to ZEXC at the raw material sale. otherwise my finished good sales is happening without any problem.
    For this should I use any routine to copy the values from ZMAN to ZEXC??
    Or rather is it possible that I could copy values from a condition type whose calculation type is FIXED AMOUNT to other condition whose calculation type is percentage.
    How should I go ahead with this??
    Please guide me.
    Any answers??
    Cant Do it this way??
    Thanks & Regards
    Anand.k
    Edited by: anand k on Jul 8, 2009 6:38 AM
    Edited by: anand k on Jul 8, 2009 1:04 PM

    Check the condtion value in condition type UTXJ . If the JMOD value is 10% of UTXJ then assessable value should have been maintained for the Material and Plant combination in J1ID. This is due to Routine 351 maintined in pricing procedure for the condition type UTXJ
    check and confirm
    Senthils

  • Compile error: Eclipse confuses Type with Window.Type

    Hi there,
    I'm using Eclipse Luna (Version: Luna Service Release 1a (4.4.1)) and JDK 1.8.0_31.
    Our projects are build with Maven. Maven build works without any problems and also our Netbeans users do not have any issues.
    But Eclipse shows compile errors and it seems, that it confuses the generic Java Type with java.awt.Window.Type which was introduced with Java 1.7.
    I created the following minimized example, which reproduces the compile problem.
    This class creates a instance of MyDialog which uses the generic Java Type:
    public class TypeTest {
    public static void main(String[] args) {
    String str = new String();
    MyDialog<String> dialog = new MyDialog<String>();
    String x = dialog.getValue(str);
    And this is the implementation of the dialog of type Type:
    import javax.swing.JDialog;
    public class MyDialog<Type> extends JDialog {
    public MyDialog() {
    super();
    public Type getValue(Type value) {
    return value;
    Eclipse persists that for getValue in MyDialog the Type is a Window.Type, which is wrong!
    This is the compile error message:
    The method getValue(Window.Type) in the type MyDialog<String> is not applicable for the arguments (String)
    Since it works without any issues for the maven build and the netbeans users, it seems to me that this is an Eclipse issue or bug? Or can someone give me a hint, how this can be solved?
    Thanks and kind regards,
    Daniel

    I just found that this question has never been answered, and from a cursory look I wasn't actually sure if this is a bug or not.
    Turns out I already wrote a little "essay" on what seems to be the same issue, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=396378#c6
    Bottom line: JLS doesn't seem to specify how to interpret / handle a conflict between an inherited member type and a same-named type parameter.
    This seems to impliy that both implementations, javac and ecj - although different - are both valid wrt JLS.

  • In RFC, no row types are allowed that contain table types or reference type

    Hi,
    I want to use an internal table in a Remote enabled function module (RFC). Is there any way to pass a table in a RFC?
    kind regards,
    Jonas

    Hello Jonas,
    Your subject line states correctly. You cannot pass tables as IMPORT/EXPORT params using a table type.
    You have to use the TABLES param, pass the internal table with type spec. LIKE against the dictionary structure you have created.(As suggested by Vikranth)
    BR,
    Suhas

  • CVD not capturing in GRN(101 mvt type) with reference to STO

    Hi Experts,
    This regarding the CVD not capturing at the time of 101 movement against STO.
    My scenerio is as follows.
    I am importing some materials. Import PO will be based on a pricing schema where no CVD or customs duties are maintained. Against that Import PO GRN (101mvt type) will takes place at Port plant(Maintained Port as a plant). Now STO will be done from the manufacturing plant setting port plant as the supplying plant.This STO also based on the pricing schema where the Customs duties as well as the CVD s are maintained. Miro for the BCD & CVD will be done based on this STO and then MB1B with 351 mvt type will be done .Then by analysing financial documents having the CVD and BCD entries will be generated at the time 351 mvt type. Then GRN (101)at the Manufacturing plant against STO will be done. But in the Excise duty field the CVD values are not capturing.
    Why CVD values are not capturing? Is it a std SAP functionality? If so please explain the logic.
    If not please guide me why it is not capturing.
    If Only at the time of 351 these excise invoice will be generated. How can I track the Invoice because during mb1b I am not supposed to put any vendor excise invoice number.
    Please analyse this scenerio and guide me with your experience in this Ocean.
    It will be helpful for me to tackle this issue raised by a client if you put some significant threads on this.
    Thanks & Regards
    Prabhul

    Dear
    It is not possible in standard SAP. use the MB_DOCUMENT_BADI.
    To get the order components use the COXT_BAPI_GET_DETAIL.
    Now while doing goods issue using transaction code MB1A and MIGO system has to do the check:
    If Quantity of issue in goods issue screen + Quantity withdrawn <= Requirement quantity then allow the transaction else throw an error u201CGoods Issue not possible for Requirement quantityu201D

  • Using TABLE() syntax with collection types

    Hi,
    I have created a function that returns a collection type as TABLE of VARCHAR2.
    Function works just fine like this:
    SELECT * FROM TABLE(some_fcn('VALUE1','VALUE2'));
    Where I am passing in static values.
    However, I need to join this with another table, passing in the values from that table as the parameters:
    SELECT f.some_table_key, t.* FROM some_table f, TABLE(some_fcn(f.col1,f.col2)) t;
    When I do this, I get the error "ORA-00904: "F"."COL1": invalid identifier"
    I am using 11gR1
    Could anyone please offer some guidance with this?
    Thanks!
    Edited by: odinsride on Aug 23, 2010 3:30 PM
    Edited by: odinsride on Aug 23, 2010 3:39 PM

    What are you doing differently?
    SQL> create or replace function some_fcn (col1 varchar2, col2 int)
       return sys.odcivarchar2list
    as
    begin
       return sys.odcivarchar2list (col2);
    end some_fcn;
    Function created.
    SQL> select ename, t.* from emp f, table(some_fcn(f.ename, f.empno)) t
    ENAME      COLUMN_VAL
    SMITH      7369     
    ALLEN      7499     
    WARD       7521     
    JONES      7566     
    MARTIN     7654     
    BLAKE      7698     
    CLARK      7782     
    SCOTT      7788     
    KING       7839     
    TURNER     7844     
    ADAMS      7876     
    JAMES      7900     
    FORD       7902     
    MILLER     7934     
    14 rows selected.can you give a description of your table some_table?

  • Table MSEG with movement type 541

    Dear All,
    In order to display the PO number, we maintain the customizing for
    movement type 541 in Transaction Code OMBW. Here we change the indicator
    From 'Suppress' inot 'Opt. entry', then the created material document
    will display the PO number in Table MSEG.
    Similarly if we want to display PO line item number,in which part we should do the Opt. entry????
    regards,
    indranil

    As of my knowledge, It is not Possible.
    Any way in the same trxn code OMBW Check the commitment Item Once for 541 Mov type.
    Regards,
    Ashok
    Edited by: Ashok Kumar Telikula on Aug 29, 2008 2:50 PM

  • How to use Reference type of Data Element

    Hi guys, is there anyone could give me a trace how to use reference type of data element.
    More details i'm going to reach is:
    I create 2 tables:
    eq.
    1. table ZFIRST has field X with data element ZFX (Data element i declared).
    2. table ZSECOND has field Y.
    Here at field Y (second table) I'm going to declare a new data element say it ZFY, but in ZFY I'm going to use the data element as i declared before (ZFX). Is it possible if I do it using reference type data element (SE11)?
    I already did this way, but I got error :
    Field Y: Reference ZFX to class w/o interface cannot be used in DB table ZSECOND
    What does it mean?. Did I miss something about using reference data element type?.
    This error occurs when I activate ZSECOND table. However in creating ZFY (reference) to data element ZFX, there is no error occur.
    The point is I need to RE-declared existing data element and ot put existing data element(ZFX) to my current table (ZSECOND).
    Any helpful will be highly appreciated.
    Thanks.
    Edited by: dinivian dondi on Nov 4, 2010 8:30 AM

    Field Y: Reference ZFX to class w/o interface cannot be used in DB table ZSECOND
    What does it mean?. Did I miss something about using reference data element type?.
    Apparently system doesn't allow you to type a transparent table field with deep type. This refers to references and tables types as components. The RDBMS (Relational DB Management System) cannot interpret this componenets correclty and mapp them to TABLEs in DB.
    So I am affraid you won't be able to type table component with reference to other data element.
    The point is I need to RE-declared existing data element and ot put existing data element(ZFX) to my current table (ZSECOND).
    Sorry but I don't get it, could you please explain this more clearly. Maybe then we can think of some workaround for you.
    Regards
    Marcin

  • Problem with Type Reference "TYPE' in JCO

    Hi All,
    I am facing a weard situation when i am creating a custom RFC function module. This FM is called by Java program with JCO. But, if i define the FM parameters with Reference type as 'TYPE', the Java application is not able to get the data. But the same time, if i declare the parameters with 'LIKE', it is working successfully.
    Can anybody advise me, why it is behaving differently? Is the problem with JCO which is not able to recognise the 'TYPE' reference or from SAP side?
    And, any solution to use 'TYPE' reference successfully?

    hi Sailesh,
    You are right. SAP doesn't recommend the usage of Like in PROGRAMS/REPORTS - mind it, only REPORTS.
    But when it comes to RFC enabled FMs, JCo Understands only LIKE. what you had observed is true. LIKE creates a WA and JCo looks into a workarea. TYPE can refer to a pool of variables but your JCo can't differentiate them. So, you use LIKE.
    Again, you use LIKE only Remote enabled FMs not in Reports/Programs. so, you may use TYPE as your company remommends in reports but in RFMs, use LIKE.
    Hope this cleared.
    Regards
    Ak.
    PS: If my post helped, don't forget the rewards!

  • Is there any table where there is wagetypes with Transaction types

    Hi
    Is there any table in SAP  where there is wage types with Transaction types setup or does it exist in FI side ? please help
    Regards
    Krishna

    if i am not wrong u are asking to view wage type models
    than go to transaction oh11 u will get wage type catalogue
    there u place f4 u can see all the the wage type models
    and one more thing we dont have any transaction for viewing each wage type
    thanks
    sikindar

Maybe you are looking for