abap tricky points

Upload: sachin-adak

Post on 04-Apr-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 ABAP Tricky Points

    1/3

    Tricky Points:

    1.Difference Between SORT and SORT STABLE

    SORT keyword sorts the internal table by the field we mention in the statement, either it can be ascending or descending.

    But the sort sequence will not be preserved, i.e, if we have a field with similar values for more than once the sort sequence

    might differ everytime we sort the table on that particular field. To preserve the sequence we can use keyword SORT

    STABLE.

    SORT STABLE keyword sorts the internal table and preserves the sort sequence. When we try to re-sort the table on the

    same sort criteria the sequence will not changed.

    2.sy-tabix and sy-index.sy-tabix = Index of Internal Tables

    set by commands processing internal tables (e.g. READ, LOOP)

    It contains the nr/index of the last line accessed for standard or sorted tables. In case of hashed tables it is set to 0

    since hashed tables are no index tables, they use a hash administration.

    sy-index = Loop Index.

    set by DO and WHILE loops. contains the number of the loop passes including the current pass.

    3. Memory de-allocation for ITABs:

    REFRESHThis deletes the entire contents of the internal table. A part of the previouslyused memory remains available for future insertions.

    CLEARWith internal tables without a header line (all that have been previously definedin the course), the CLEAR statement has the same effect as REFRESH.For internal tables with a header line (see below) in contrast, it only initializesthe header line.

    FREEThis deletes the entire contents of the internal table and releases the previouslyused memory. You use the FREE statement for internal tables that have already

    http://wiki.sdn.sap.com/wiki/display/Snippets/Difference+Between+SORT+and+SORT+STABLEhttp://wiki.sdn.sap.com/wiki/display/Snippets/Difference+Between+SORT+and+SORT+STABLEhttp://wiki.sdn.sap.com/wiki/display/Snippets/Difference+Between+SORT+and+SORT+STABLEhttp://scn.sap.com/message/7947143#7947143http://scn.sap.com/message/7947143#7947143http://wiki.sdn.sap.com/wiki/display/Snippets/Difference+Between+SORT+and+SORT+STABLE
  • 7/31/2019 ABAP Tricky Points

    2/3

    been evaluated and are no longer required in the further course of the program.

    This has the effect that pre

    4. COLLECT :COLLECT wa INTO itab.

    itab must have a flat line type, and all of the fields that are not part of the table key must havea numeric type (f, i,p). You specify the linewathat you want to add as a work area that is compatible

    with the line type ofitab.

    When the line is inserted, the system checks whether there is already a table entry that matches the key.If there is no corresponding entry already in the table, the COLLECT statement has the same effect

    asinserting the new line. If an entry with the same key already exists, the COLLECT statement does not

    append a new line, but adds the contents of the numeric fields in the work area to the contents of thenumeric fields in the existing entry.

    5. Subroutine Types:

    Call by Value -

    A copy is made of the actual parameter. This copy is assigned to the formalparameter. If in the subroutine a value is assigned to the corresponding formalparameter, this value will actually be assigned to a copy of the formal parameterand not its original.You use this pass type, to make the value of a global variable available to thesubroutine (in the form of a variable copy) without making it possible to changethe respective global variable (protecting the original). Please note, however,that creating copies, especially for large internal tables, can be time-consuming.

    Call by value and result -With this transfer type, the same applies as for .call by value.. However, atthe regular end of the subroutine, the value that was changed to this point iswritten back to the original. If the program is prematurely terminated through aSTOP statement or a user message of type E, the writing back of the values is

    suppressed.You use this pass type to transfer the value of a global variable to the subroutineand to have the fully processed final value of the copy written back to theoriginal. But note that the creation of copies and the writing back of values canbe time-consuming, especially for large internal tables.

    Call by reference -The actual parameter is assigned directly to the formal parameter. This meansthat value assignments to the formal parameter are executed directly on theactual parameter.You use this pass type if you want to run the subroutine processing directly onthe specified actual parameter. It is popular for avoiding the time-consumingcreation of copies for large internal tables.

    http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb361f358411d1829f0000e829fbfe/content.htmhttp://help.sap.com/saphelp_nw70/helpdata/en/fc/eb361f358411d1829f0000e829fbfe/content.htmhttp://help.sap.com/saphelp_nw70/helpdata/en/fc/eb361f358411d1829f0000e829fbfe/content.htmhttp://help.sap.com/saphelp_nw70/helpdata/en/fc/eb361f358411d1829f0000e829fbfe/content.htm
  • 7/31/2019 ABAP Tricky Points

    3/3

    5. Import -Export stmts:

    A simple example of ABAP memory is using the EXPORT/IMPORT statements. Here in this program, I get the data,

    export it to memory, clear out the internal table in my progam, then reimport the data into it and write out the data.

    You probably wounldn't do this in a normal program, but this is how you can pass data from program a to program b

    when A Submits program B.

    report zrich_0002 .

    data: it001 type table of t001 with header line.

    select * into table it001 from t001.

    export it001 = it001 to memory id 'ZRICH_TEST'.

    clear it001. refresh it001.

    import it001 = it001 from memory id 'ZRICH_TEST'.

    loop at it001.

    write:/ it001-bukrs, it001-butxt.

    endloop.