Difference between sy-tabix and sy-index?

tell me about sy-tabix and sy-index?what is the difference between sy-tabix and sy-index?
Moderator Message: Please search before posting. Read the [Forum Rules Of Engagement |https://wiki.sdn.sap.com/wiki/display/HOME/RulesofEngagement] for further details.
Edited by: Suhas Saha on Jun 18, 2011 5:33 PM

HI,
    Here is a brief description of difference between SY_TABIX and SY_INDEX and using them with several conditions.
SY-TABIX
Current line of an internal table. SY-TABIX is set by the statements below, but only for index tables. The field is either not set or is set to 0 for hashed tables.
APPEND sets SY-TABIX to the index of the last line of the table, that is, it contains the overall number of entries in the table.
COLLECT sets SY-TABIX to the index of the existing or inserted line in the table. If the table has the type HASHED TABLE, SY-TABIX is set to 0.
LOOP AT sets SY-TABIX to the index of the current line at the beginning of each loop lass. At the end of the loop, SY-TABIX is reset to the value that it had before entering the loop. It is set to 0 if the table has the type HASHED TABLE.
READ TABLE sets SY-TABIX to the index of the table line read. If you use a binary search, and the system does not find a line, SY-TABIX contains the total number of lines, or one more than the total number of lines. SY-INDEX is undefined if a linear search fails to return an entry.
SEARCH <itab> FOR sets SY-TABIX to the index of the table line in which the search string is found.
SY-INDEX
In a DO or WHILE loop, SY-INDEX contains the number of loop passes including the current pass.
Hope this helps.
Thank you,
Pavan.

Similar Messages

  • What is difference between sy-tabix and sy-index.

    SAP Seniors,
    Can you please let me know what is difference between sy-index and sy-tabix.
    I read the SAP help, it is confusing for me. it looks like both are same from help. please help me.
    Thank you
    Anitha.

    HI,
        Here is a brief description of difference between SY_TABIX and SY_INDEX and using them with several conditions.
    SY-TABIX
    Current line of an internal table. SY-TABIX is set by the statements below, but only for index tables. The field is either not set or is set to 0 for hashed tables.
    APPEND sets SY-TABIX to the index of the last line of the table, that is, it contains the overall number of entries in the table.
    COLLECT sets SY-TABIX to the index of the existing or inserted line in the table. If the table has the type HASHED TABLE, SY-TABIX is set to 0.
    LOOP AT sets SY-TABIX to the index of the current line at the beginning of each loop lass. At the end of the loop, SY-TABIX is reset to the value that it had before entering the loop. It is set to 0 if the table has the type HASHED TABLE.
    READ TABLE sets SY-TABIX to the index of the table line read. If you use a binary search, and the system does not find a line, SY-TABIX contains the total number of lines, or one more than the total number of lines. SY-INDEX is undefined if a linear search fails to return an entry.
    SEARCH <itab> FOR sets SY-TABIX to the index of the table line in which the search string is found.
    SY-INDEX
    In a DO or WHILE loop, SY-INDEX contains the number of loop passes including the current pass.
    Hope this helps.
    Thank you,
    Pavan.

  • Difference between primary key and primary index

    Dear All,
             Hi... .Could you pls tell me the difference between primary key and primary index.
    Thanks...

    Hi,
    Primary Key : It is one which makes an entry of the field unique.No two distinct rows in a table can have the same value (or combination of values) in those columns.
    Eg: first entry is 111, if you again enter value 111 , it doesnot allow 111 again. similarly for the strings or characters or numc etc. Remember that for char or numc or string 'NAME' is not equal to 'name'.
    Primary Index: this is related to the performance .A database index is a data structure that improves the speed of operations in a table. Indices can be created using one or more columns, providing the basis for both rapid random lookups and efficient ordering of access to records. The disk space required to store the index is typically less than the storage of the table (since indices usually contain only the key-fields according to which the table is to be arranged, and excludes all the other details in the table), yielding the possibility to store indices into memory from tables that would not fit into it. In a relational database an index is a copy of part of a table. Some databases extend the power of indexing by allowing indices to be created on functions or expressions. For example, an index could be created on upper(last_name), which would only store the uppercase versions of the last_name field in the index.
    In a database , we may have a large number of records. At the time of retrieving data from the database based on a condition , it is a burden to the db server. so whenever we create a primary key , a primary index is automatically created by the system.
    If you want to maintain indices on other fields which are frequently used in where condition then you can create secondary indices.
    Reward points if helpful.
    Thanks,
    Sirisha..

  • Difference between primary eindex and secondary index?

    hi experts
    pls answer me
    difference between primary eindex and secondary index?
    rewads apply.
    thanks.
    naresh.

    hi,
    check this link.
    http://help.sap.com/saphelp_47x200/helpdata/en/cf/21eb2d446011d189700000e8322d00/frameset.htm
    A difference is made between Primary & Secondary indexes to a table. the primary index consists of the key fields of the table and a pointer to the non-keys-fields of the table. The Primary index is generated automatically when a table is created and is created in the datebase as the same times as the table. It is also possible to define further indexes to a table in the ABAP/4 dictionary, which are then referred to as Secondary indexes.
    Always it is not mandatory that an index should have all the key fields of a table. To see the index of a table
    goto SE11->specify table name->click on the indexes... button on the application toolbar.
    Based on your requirement you can you any of those index fields in the where clause of your query. Always its a better practice to use the index fields in the order specified. While selecting the records from a table it is always better to select the fields in the same order as specified in the table.

  • Difference between unique constraint and unique index

    1. What is the difference between unique constraint and unique index when unique constraint is always indexed ? Which one is better in this case for better performance ?
    2. Is Composite index of 3 columns x,y,z better
    or having independent/ seperate indexes on 3 columns x,y,z is better for better performance ?
    3. It has been very confusing for me to decide which columns to index, I have indexed most foreignkey columns, is it a good idea ? We do lot of selects and DMLS on most of our tables. Is there any query that I can run and find out if indexes are really being used and if they are improving any performance. I have analyzed and computed my indexes using ANALYZE index index_name validate structure and COMPUTE STATISTICS;
    null

    1. Unique index is part of unique constraint. Of course you can create standalone unique index. But is is no point to skip the logical view of business if you spend same effort to achive.
    You create unique const. Oracle create the unique index for you. You may specify index characteristic in unique constraint.
    2. Depends. You can't utilize the composite index if the searching condition is not whole or front part of the indexing key. You can't utilize your index if you query the table for y=2. That is.
    3. As old words in database arena, Index may be good or bad for a table depending on the size of table, number of columns in the table... etc. It is very environmental dependent. In fact, It is part of database nomalization. Statistic is a way oracle use to determine the execution plan.
    Steve
    null

  • What is the difference between "Invisible" (11g) and "virtual" index?

    Hi
    What is the difference between the "Invisible" index and "virtual" index?
    Thanks
    Balaji

    Indexes can be visible or invisible. An invisible index is maintained by DML operations and cannot be used by the optimizer. Actually takes space, but is not to be used as part of a potential access path.
    AFAIK, a virtual index is created by the tools used in SQL statement access path tuning to provide an alternative for the optimizer to test. It does not take any real space as it is a pure in memory definition.

  • Difference between Unique key and Unique index

    Hi All,
    I've got confused in the difference between unique index & unique key in a table.
    While we create a unique index on a table, its created as a unique index.
    On the other hand, if we create a unique key/constraint on the table, Oracle also creates an index entry for that. So I can find the same name object in all_constraints as well as in all_indexes.
    My question here is that if during creation of unique key/constraint, an index is automatically created than why is the need to create unique key and then two objects , while we can create only one object i.e. unique index.
    Thanks
    Deepak

    This is only my understanding and is not according to any documentation, that is as follows.
    The unique key (constraint) needs an unique index for achieving constraint of itself.
    Developers and users can make any constraint (unique-key, primary-key, foreign-key, not-null ...) to enable,disable and be deferable. Unique key is able to be enabled, disabled, deferable.
    On the other hand, the index is used for performance-up originally, unique index itself doesn't have the concept like constraints. The index (including non-unique, unique) can be rebuilded,enabled,disabled etc. But I think that index cannot be set "deferable-builded" automatic.

  • Access path difference between Primary Key and Unique Index

    Hi All,
    Is there any specific way the oracle optimizer treats Primary key and Unique index differently?
    Oracle Version
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE    11.2.0.3.0      Production
    TNS for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    SQL> Sample test data for Normal Index
    SQL> create table t_test_tab(col1 number, col2 number, col3 varchar2(12));
    Table created.
    SQL> create sequence seq_t_test_tab start with 1 increment by 1 ;
    Sequence created.
    SQL>  insert into t_test_tab select seq_t_test_tab.nextval, round(dbms_random.value(1,999)) , 'B'||round(dbms_random.value(1,50))||'A' from dual connect by level < 100000;
    99999 rows created.
    SQL> commit;
    Commit complete.
    SQL> exec dbms_stats.gather_table_stats(USER_OWNER','T_TEST_TAB',cascade => true);
    PL/SQL procedure successfully completed.
    SQL> select col1 from t_test_tab;
    99999 rows selected.
    Execution Plan
    Plan hash value: 1565504962
    | Id  | Operation         | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |            | 99999 |   488K|    74   (3)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| T_TEST_TAB | 99999 |   488K|    74   (3)| 00:00:01 |
    Statistics
              1  recursive calls
              0  db block gets
           6915  consistent gets
            259  physical reads
              0  redo size
        1829388  bytes sent via SQL*Net to client
          73850  bytes received via SQL*Net from client
           6668  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          99999  rows processed
    SQL> create index idx_t_test_tab on t_test_tab(col1);
    Index created.
    SQL> exec dbms_stats.gather_table_stats('USER_OWNER','T_TEST_TAB',cascade => true);
    PL/SQL procedure successfully completed.
    SQL> select col1 from t_test_tab;
    99999 rows selected.
    Execution Plan
    Plan hash value: 1565504962
    | Id  | Operation         | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |            | 99999 |   488K|    74   (3)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| T_TEST_TAB | 99999 |   488K|    74   (3)| 00:00:01 |
    Statistics
              1  recursive calls
              0  db block gets
           6915  consistent gets
              0  physical reads
              0  redo size
        1829388  bytes sent via SQL*Net to client
          73850  bytes received via SQL*Net from client
           6668  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          99999  rows processed
    SQL> Sample test data when using Primary Key
    SQL> create table t_test_tab1(col1 number, col2 number, col3 varchar2(12));
    Table created.
    SQL> create sequence seq_t_test_tab1 start with 1 increment by 1 ;
    Sequence created.
    SQL> insert into t_test_tab1 select seq_t_test_tab1.nextval, round(dbms_random.value(1,999)) , 'B'||round(dbms_random.value(1,50))||'A' from dual connect by level < 100000;
    99999 rows created.
    SQL> commit;
    Commit complete.
    SQL> exec dbms_stats.gather_table_stats('USER_OWNER','T_TEST_TAB1',cascade => true);
    PL/SQL procedure successfully completed.
    SQL> select col1 from t_test_tab1;
    99999 rows selected.
    Execution Plan
    Plan hash value: 1727568366
    | Id  | Operation         | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |             | 99999 |   488K|    74   (3)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| T_TEST_TAB1 | 99999 |   488K|    74   (3)| 00:00:01 |
    Statistics
              1  recursive calls
              0  db block gets
           6915  consistent gets
              0  physical reads
              0  redo size
        1829388  bytes sent via SQL*Net to client
          73850  bytes received via SQL*Net from client
           6668  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          99999  rows processed
    SQL> alter table t_test_tab1 add constraint pk_t_test_tab1 primary key (col1);
    Table altered.
    SQL> exec dbms_stats.gather_table_stats('USER_OWNER','T_TEST_TAB1',cascade => true);
    PL/SQL procedure successfully completed.
    SQL> select col1 from t_test_tab1;
    99999 rows selected.
    Execution Plan
    Plan hash value: 2995826579
    | Id  | Operation            | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT     |                | 99999 |   488K|    59   (2)| 00:00:01 |
    |   1 |  INDEX FAST FULL SCAN| PK_T_TEST_TAB1 | 99999 |   488K|    59   (2)| 00:00:01 |
    Statistics
              1  recursive calls
              0  db block gets
           6867  consistent gets
              0  physical reads
              0  redo size
        1829388  bytes sent via SQL*Net to client
          73850  bytes received via SQL*Net from client
           6668  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          99999  rows processed
    SQL> If you see here the even though statistics were gathered,
         * In the 1st table T_TEST_TAB, the table is still using FULL table access after creation of index.
         * And in the 2nd table T_TEST_TAB1, table is using PRIMARY KEY as expected.
    Any comments ??
    Regards,
    BPat

    Thanks.
    Yes, ignored the NOT NULL part.Did a test and now it is working as expected
    SQL>  create table t_test_tab(col1 number not null, col2 number, col3 varchar2(12));
    Table created.
    SQL>
    create sequence seq_t_test_tab start with 1 increment by 1 ;SQL>
    Sequence created.
    SQL> insert into t_test_tab select seq_t_test_tab.nextval, round(dbms_random.value(1,999)) , 'B'||round(dbms_random.value(1,50))||'A' from dual connect by level < 100000;
    99999 rows created.
    SQL> commit;
    Commit complete.
    SQL>  exec dbms_stats.gather_table_stats('GREP_OWNER','T_TEST_TAB',cascade => true);
    PL/SQL procedure successfully completed.
    SQL>  set autotrace traceonly
    SQL>  select col1 from t_test_tab;
    99999 rows selected.
    Execution Plan
    Plan hash value: 1565504962
    | Id  | Operation         | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |            | 99999 |   488K|    74   (3)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| T_TEST_TAB | 99999 |   488K|    74   (3)| 00:00:01 |
    Statistics
              1  recursive calls
              0  db block gets
           6912  consistent gets
              0  physical reads
              0  redo size
        1829388  bytes sent via SQL*Net to client
          73850  bytes received via SQL*Net from client
           6668  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          99999  rows processed
    SQL>  create index idx_t_test_tab on t_test_tab(col1);
    Index created.
    SQL>  exec dbms_stats.gather_table_stats('GREP_OWNER','T_TEST_TAB',cascade => true);
    PL/SQL procedure successfully completed.
    SQL>  select col1 from t_test_tab;
    99999 rows selected.
    Execution Plan
    Plan hash value: 4115006285
    | Id  | Operation            | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT     |                | 99999 |   488K|    63   (2)| 00:00:01 |
    |   1 |  INDEX FAST FULL SCAN| IDX_T_TEST_TAB | 99999 |   488K|    63   (2)| 00:00:01 |
    Statistics
              1  recursive calls
              0  db block gets
           6881  consistent gets
              0  physical reads
              0  redo size
        1829388  bytes sent via SQL*Net to client
          73850  bytes received via SQL*Net from client
           6668  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          99999  rows processed
    SQL>

  • ABAP-- diff between sy-sy-tabix and sy-index

    Hi Guru's,
    Pleae can anybody expalins me what is the difference between sy-tabix and sy-index(Loop Index) ?
    Because in one case i am Modifyimg the internal table inside the do loop by giving sy-index ((Index of Internal Tables)(MODIFY scarr_tab INDEX sy-index FROM scarr_wa TRANSPORTING currcode. )  in the syntax and in other case inside loop statement i am modifyng same record by giving sy-tabix MODIFY scarr_tab INDEX  sy-tabix FROM scarr_wa TRANSPORTING currcode.) in the syntax.
    in both cases its working fine but i am not getting which one i have to use  where to modify the internal table?
    regards
    SATYA

    Hi Henry,
    SY-INDEX is the value of the current iteration. It is applicable for the following programming constructs in ABAP -
    DO...ENDDO.
    WHILE...ENDWHILE.
    SY-TABIX (TABle IndeX) is applicable to internal tables. If you scroll down in the link which Eddie has given, you will find a more detailed explanation for sy-tabix and which statements affect its value.
    Regards,
    Anand Mandalika.

  • What is the difference between Topic Keywords and Index File Keywords?

    What is the difference between Topic Keywords and Index File Keywords? Any advantages to using one over the other? Do they appear differently in the generated index?
    RH9.0.2.271
    I'm using Webhelp

    Hi there
    When you create a RoboHelp project you end up with many different ancillary files that are used to store different bits of information. Many of these files bear the name you assigned to the project at the time you created it. The index file has the project name and it ends with a .HHK file extension. (HHK meaning HTML Help Keywords)
    Generally, unless you change RoboHelp's settings, you add keywords to this file and associate topics to the keywords via the Index pod. At the time you compile a CHM or generate other types of output, the file is consulted and the index is built.
    As I said earlier, the default is to add keywords to the Index file until you configure RoboHelp to add the keywords to the topics themselves. Once you change this, any keyword added will become a META tag in the topic code. If your keyword is BOFFO, the META tag would look like this:
    <meta name="MS-HKWD" content="BOFFO" />
    When the help is compiled or generated, the Index (.HHK) file is consulted as normal, but any topics containing keywords added in this manner are also added to the Index you end up with. From the appearance perspective, the end user woudn't know the difference or be able to tell. Heck, if all you ever did was interact with the Index pod, you, as an author wouldn't know either. Well, other than the fact that the icons appear differently.
    Operationally, keywords added to the topics themselves may hold an advantage in that if you were to import these topics into other projects, the Index keywords would already be present.
    Hopefully this helps... Rick

  • Difference between open loop and closed loop mode when finding the index on a stepper motor axis.

    I have a test system which uses a PXI-7352 motion controller with a MID-7602 stepper motor drive to position a 200 step/revolution stepper motor with an attached 1000 line encoder.  The MID-7602 is configured for 64 microsteps per step, giving 12,800 microsteps and 4000 encoder counts per revolution.  The system is controlled using LabView 7.1 and NI-Motion 6.13.  To home the motor, I've defined a sequence in MAX which first finds the reverse limit switch and then moves forward to the encoder index pulse.
    When finding its reference in open loop mode, the system its reference at the same microstep each time.  When findings its reference in closed loop mode, the system finds its reference somewhere within about a 20 microstep wide range.
    I hope somebody out there with more experience with this controller can describe the difference between finding the encoder index in open loop mode and finding the encoder index in closed loop mode. 
    Thanks,
    Mark Moss

    Hello Mark,
    I suspect that the behavior you are experiencing has today
    with the resolution difference between your encoder and your
    microstepping.  Let me illustrate with an
    example:
    Example Setup
    Stepper
    Motor
    NI
    Motion Controller
    10
    steps per encoder pulse (Every 10 steps the controller gets an encoder
    pulse, therefore positions 0-9 all appear to be 0 to the controller)
    The
    system has a maximum of 3 pull in moves set
    Open Loop Scenario
    The
    system is commanded to go to position 9.
    The
    controller sends out 9 pulses.
    The
    motor moves to position 9.
    Closed Loop Scenario
    The
    system is commanded to go to position 9.
    The
    controller sends out 9 pulses.
    The
    motor moves to position 9.
    The
    controller checks its position and sees that it is still at position 0
    because it has not received an encoder pulse.
    Because
    the controller thinks it is still at position 0, it sends another 9 pulses
    as its first pull in move.
    The
    motor moves to position 18.
    The
    controller checks its position and sees that it is at position 10 because
    it has only received one encoder pulse.
    Because
    the controller thinks it is still at position 10, it sends1 reverse pulse
    as its second pull in move.
    The
    motor moves to position 17.
    The
    controller checks its position and sees that it is at position 10 because
    it has only received one encoder pulse.
    Because
    the controller thinks it is still at position 10, it sends and additional
    single reverse pulse as its third pull in move.
    The
    motor moves to its final position of 16.
    I believe something similar is happening with your
    application as it looks for the index pulse. 
    Because the controller does not compensate for what it perceives as
    position error in open loop mode, the motor always goes to the same commanded
    position.  In closed loop mode, the motor
    is bouncing around inside the single index encoder pulse trying to find a
    certain position.
    There are several recommendations I can make towards
    correcting this behavior.  These
    recommendations are in order of effectiveness:
    Setup
    your system so that there are more encoder counts per revolution than
    steps per revolution.
    Turn
    off pull-in moves by setting them to 0 in MAX.
    Use an
    open loop configuration.
    Play
    around with the pull in window in MAX.
    Regards,
    Luke H

  • Difference between abap object and function

    hi all,
    i read the book on abap object of the difference between abap object and classical abap.
    i know that there is only 1 instance of a specific function group but somehow i still not so clear why subsequent vehicle cannot use the same function. i also can use the do and loop to call the function? if cannot then why?
    hope can get the advice.
    thanks
    using function *********
    function-pool vehicle.
    data speed type i value 0.
    function accelerate.
    speed = speed + 1.
    endfunction.
    function show_speed.
    write speed.
    endfunction.
    report xx.
    start-of-selection.
    *vehicle 1
    call function 'accelerate'.
    call function 'accelerate'.
    call function 'show_speed'.
    *vehicle 2
    *vehicle 3
    *****abap object*******
    report xx.
    data: ov type ref to vehicle,
             ov_tab type table of ref to vehicle.
    start-of-selection.
    do 5 times.
    create object ov.
    append ov to ov_tab.
    enddo.
    loop at ov_tab into ov.
    do sy-tabix times.
    call method ov->accelerate.
    enddo.
    call method ov->show_speed.
    endloop.

    Hi
    Now try this:
    REPORT ZTEST_VEHICLEOO .
    PARAMETERS: P_CAR   TYPE I,
                P_READ  TYPE I.
    *       CLASS vehicle DEFINITION
    CLASS VEHICLE DEFINITION.
      PUBLIC SECTION.
        CLASS-DATA: MAX_SPEED   TYPE I,
                    MAX_VEHICLE TYPE I,
                    NR_VEHICLES TYPE I.
        CLASS-METHODS CLASS_CONSTRUCTOR.
        METHODS CONSTRUCTOR.
        METHODS ACCELERATE.
        METHODS SHOW_SPEED.
        METHODS GET_SPEED EXPORTING E_SPEED TYPE I.
      PRIVATE SECTION.
        DATA: SPEED      TYPE I,
              NR_VEHICLE TYPE I..
    ENDCLASS.
    *       CLASS vehicle IMPLEMENTATION
    CLASS VEHICLE IMPLEMENTATION.
      METHOD CLASS_CONSTRUCTOR.
        NR_VEHICLES = 0.
      ENDMETHOD.
      METHOD CONSTRUCTOR.
        NR_VEHICLES = NR_VEHICLES + 1.
        NR_VEHICLE  = NR_VEHICLES.
      ENDMETHOD.
      METHOD ACCELERATE.
        SPEED = SPEED + 1.
        IF MAX_SPEED < SPEED.
          MAX_SPEED   = SPEED.
          MAX_VEHICLE = NR_VEHICLE.
        ENDIF.
      ENDMETHOD.
      METHOD SHOW_SPEED.
        WRITE: / 'Speed of vehicle nr.', NR_VEHICLE, ':', SPEED.
      ENDMETHOD.
      METHOD GET_SPEED.
        E_SPEED = SPEED.
      ENDMETHOD.
    ENDCLASS.
    DATA: OV     TYPE REF TO VEHICLE,
          OV_TAB TYPE TABLE OF REF TO VEHICLE.
    DATA: V_TIMES TYPE I,
          FL_ACTION.
    DATA: V_SPEED TYPE I.
    START-OF-SELECTION.
      DO P_CAR TIMES.
        CREATE OBJECT OV.
        APPEND OV TO OV_TAB.
      ENDDO.
      LOOP AT OV_TAB INTO OV.
        IF FL_ACTION = SPACE.
          FL_ACTION = 'X'.
          V_TIMES = SY-TABIX * 2.
        ELSE.
          FL_ACTION = SPACE.
          V_TIMES = SY-TABIX - 2.
        ENDIF.
        DO V_TIMES TIMES.
          CALL METHOD OV->ACCELERATE.
        ENDDO.
        CALL METHOD OV->SHOW_SPEED.
      ENDLOOP.
      SKIP.
      WRITE: / 'Higher speed', VEHICLE=>MAX_SPEED, 'for vehicle nr.',
                VEHICLE=>MAX_VEHICLE.
      SKIP.
      READ TABLE OV_TAB INTO OV INDEX P_READ.
      IF SY-SUBRC <> 0.
        WRITE: 'No vehicle', P_READ.
      ELSE.
        CALL METHOD OV->GET_SPEED IMPORTING E_SPEED = V_SPEED.
        WRITE: 'Speed of vehicle', P_READ, V_SPEED.
      ENDIF.
    Try to repeat this using a function group and I think you'll undestand because it'll be very hard to do it.
    By only one function group how can u read the data of a certain vehicle?
    Yes you can create in the function group an internal table where u store the data of every car: in this way u use the internal table like it was an instance, but you should consider here the example is very simple. Here we have only the speed as characteristic, but really we can have many complex characteristics.
    Max

  • Difference between Session method and call transaction

    Hi,
    please give me the differences between session method and call transaction,
    briefly explaining synchronus , asynchronus, process, update.
    Thanks in advance

    Hi Vijay Kumar
    CLASSICAL BATCH INPUT (Session Method)
    CALL TRANSACTION
    BATCH INPUT METHOD:
    This method is also called as ‘CLASSICAL METHOD’.
    Features:
    Asynchronous processing.
    Synchronous Processing in database update.
    Transfer data for more than one transaction.
    Batch input processing log will be generated.
    During processing, no transaction is started until the previous transaction has been written to the database.
    CALL TRANSACTION METHOD :
    This is another method to transfer data from the legacy system.
    Features:
    Synchronous processing. The system performs a database commit immediately before and after the CALL TRANSACTION USING statement.
    Updating the database can be either synchronous or asynchronous. The program specifies the update type.
    Transfer data for a single transaction.
    Transfers data for a sequence of dialog screens.
    No batch input processing log is generated.
    http://www.sap-img.com/abap/difference-between-batch-input-and-call-transaction-in-bdc.htm
    Among the two methods call transaction is better compared to session bcoz data transfer is faster in it.
    Differences between call transaction and session.
    Session Method:
    1) Data is not updated in the database table until the session is processed.
    2) No sy-subrc is returned.
    3) Error log is created for error records.
    4) Updation is always synchronous.
    Call Transaction Method:
    1) Immediate updation in the database table.
    2) sy-subrc is returned.
    3)Error need to be handled explicitly.
    4) updation can be synchronous as well as asynchronous.
    2) ya u can use using the N mode no screen.
    3)u can't handle multiple transaction in call transaction.
    4) u can handle multiple transaction in session using the BDC_INSERT fm.
    5)When u go to SM35 u can able to see the error records.
    Which is best?
    That depends on your requirement. Both of them have there advantages.
    According to the situation u can choose any one of these.
    difference between batch input and call transaction in BDC Session method.
    1) synchronous processing.
    2) can tranfer large amount of data.
    3) processing is slower.
    4) error log is created
    5) data is not updated until session is processed.
    Call transaction.
    1) asynchronous processing
    2) can transfer small amount of data
    3) processing is faster.
    4) errors need to be handled explicitly
    5) data is updated automatically
    For session method,these are the function modules to b used.
    BDC_OPEN_GROUP
    BDC_INSERT
    BDC_CLOSE_GROUP
    For call transaction,this is the syntax.
    CALL TRANSACTION TCODE USING BDCDATA
    MODE A or E or N
    UPDATE A or S
    MESSAGES INTO MESSTAB.
    Take a scenario where we need to post documents in FB01 and the input file has say 2000 records (2000 documents, not line items in FB01 but 2000 records)
    In the BDC call transaction method
    We call the transaction FB01 2000 times (once for each record posting) and if the processing fails in record no 3 it can be captured and start with reocord 4.
    Eg: Loop at itab.
    call transaction FB01
    capture errors
    endloop.
    In the session method.
    We do not explicity call the transaction 2000 times, but all the records are appeneded into a session and this session is stored. The processinf of the session is done wwhenever the user wants it to be done. Hence the errors cannot be captured in the program itself
    Check these link:
    http://www.sap-img.com/abap/difference-between-batch-input-and-call-transaction-in-bdc.htm
    http://www.sap-img.com/abap/question-about-bdc-program.htm
    http://www.itcserver.com/blog/2006/06/30/batch-input-vs-call-transaction/
    http://www.planetsap.com/bdc_main_page.htm
    Batch Input Session method is asynchronous as told by others here. But the advantage of this is that you have all the error messages and the data for each transaction held persistantly. You don't have to code anything for processing them or writing the logs.
    But at the same time, the same feature can be disadvantageous if you need to react to an error or if there are too many errors to manually correct in a session. Since the session are created in the program and its execution is done seperately, you loose the trackability of such transactions.
    With a call transaction, what was a disadvantage above will become an advantage. Call transaction immediately gives you messages back and you can react to it in your program. But the disadvantage is that, if you have several hundreds of transactions to run, running them from within the program can be resource crunching affair. It will hamper the system performance and you cannot really distribute the load. Of course, you have some mechanisms with which you can overcome this, but you will have to code for it. Also, storing the messages and storing the errored transaction data etc will have to be handled by you in the program. Whereas, in batch input session, your program's job is to just create the session, after that everything is standard SAP system's responsibility.
    Ideally, you should do a call transaction if the resources are not a problem and if it fails, put the errored transaction into a session.
    You can decide based on the data volume that your BDC is processing. If data volume is high go for session else call transaction will do.The call transaction updates will be instantaneous where as session needs to be processed explictly after creation.
    Session Method
    1) Session method supports both small amount of data aswell as large amount of data
    2) data processing is asynchronus and data updation is synchronus.
    3) it process multiple apllication while perfomaning validations.
    4) in session method data will be updated in data base only after processing session only.
    5) system provide by default logfile for handling error records.
    6) it supports both foreground aswell as background process
    in bdc we use FM ...
    bdc_open_group " for creating Session
    bdc_insert " adding transaction and bdcdata table for updating database
    bdc_close_group " for closing Session
    Call Transaction
    1) Call transaction exclusively for small amout of data
    2) it supports only one apllication while perfoming validations
    3) there is no default logfile, We can explicitly provide logic for creating logfile for handling error records.
    we can create logfile by using structure....BDCMSGCOLL
    4) it doesn't support background processing.
    5) data processing is synchronous and Data updation is Synchronous( default), in
    this method also supports daya updation in asynchronus process also.
    syntax:
    Call transaction <transaction-name> using BDCDATA
    mode <A/N/E>
    update <L/A/S>
    messages into BDCMSGCOLL.
    BDC:
    Batch Data Communication (BDC) is the process of transferring data from one SAP System to another SAP system or from a non-SAP system to SAP System.
    Features :
    BDC is an automatic procedure.
    This method is used to transfer large amount of data that is available in electronic medium.
    BDC can be used primarily when installing the SAP system and when transferring data from a legacy system (external system).
    BDC uses normal transaction codes to transfer data.
    Types of BDC :
    CLASSICAL BATCH INPUT (Session Method)
    CALL TRANSACTION
    BATCH INPUT METHOD:
    This method is also called as ‘CLASSICAL METHOD’.
    Features:
    Asynchronous processing.
    Synchronous Processing in database update.
    Transfer data for more than one transaction.
    Batch input processing log will be generated.
    During processing, no transaction is started until the previous transaction has been written to the database.
    CALL TRANSACTION METHOD :
    This is another method to transfer data from the legacy system.
    Features:
    Synchronous processing. The system performs a database commit immediately before and after the CALL TRANSACTION USING statement.
    Updating the database can be either synchronous or asynchronous. The program specifies the update type.
    Transfer data for a single transaction.
    Transfers data for a sequence of dialog screens.
    No batch input processing log is generated.
    For BDC:
    http://myweb.dal.ca/hchinni/sap/bdc_home.htm
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/home/bdc&
    http://www.sap-img.com/abap/learning-bdc-programming.htm
    http://www.sapdevelopment.co.uk/bdc/bdchome.htm
    http://www.sap-img.com/abap/difference-between-batch-input-and-call-transaction-in-bdc.htm
    http://help.sap.com/saphelp_47x200/helpdata/en/69/c250684ba111d189750000e8322d00/frameset.htm
    http://www.sapbrain.com/TUTORIALS/TECHNICAL/BDC_tutorial.html
    Check these link:
    http://www.sap-img.com/abap/difference-between-batch-input-and-call-transaction-in-bdc.htm
    http://www.sap-img.com/abap/question-about-bdc-program.htm
    http://www.itcserver.com/blog/2006/06/30/batch-input-vs-call-transaction/
    http://www.planetsap.com/bdc_main_page.htm
    call Transaction or session method ?
    Check the following links:
    http://www.sap-img.com/bdc.htm
    See below example code :
    Call three FM : BDC_OPEN_GROUP,BDC_INSERT and BDC_CLOSE_GROUP.
    Once you execute the program and it creates the session at SM35 Transaction.
    Report : ZMPPC011
    Type : Data upload
    Author : Chetan Shah
    Date : 05/05/2005
    Transport : DV3K919557
    Transaction: ??
    Description: This ABAP/4 Program creates new Production Versions
    (C223). It accepts tab-delimited spreadsheet input and
    creates BDC sessions.
    Modification Log
    Date Programmer Request # Description
    06/10/2005 Chetan Shah DV3K919557 Initial coding
    report zmppc011 no standard page heading line-size 120 line-count 55
    message-id zz.
    pool of form routines
    include zmppn001.
    Define BDC Table Structure
    data: begin of itab_bdc_tab occurs 0.
    include structure bdcdata.
    data: end of itab_bdc_tab.
    Input record layout of Leagcy File
    data: begin of itab_xcel occurs 0,
    matnr(18) type c,
    werks(4) type c,
    alnag(2) type c,
    verid(4) type c,
    text1(40) type c,
    bstmi like mkal-bstmi,
    bstma like mkal-bstma,
    adatu(10) type c,
    bdatu(10) type c,
    stlal(2) type c,
    stlan(1) type c,
    serkz(1) type c,
    mdv01(8) type c,
    elpro(4) type c,
    alort(4) type c,
    end of itab_xcel.
    data: begin of lt_pp04_cache occurs 0,
    matnr like itab_xcel-matnr,
    werks like itab_xcel-werks,
    alnag like itab_xcel-alnag,
    plnnr like mapl-plnnr,
    arbpl like crhd-arbpl,
    ktext like crtx-ktext,
    end of lt_pp04_cache.
    data: v_ssnnr(4) type n,
    v_lines_in_xcel like sy-tabix,
    v_ssnname like apqi-groupid,
    v_trans_in_ssn type i,
    wa_xcel LIKE itab_xcel,
    l_tabix like sy-tabix,
    v_matnr like rc27m-matnr,
    v_plnnr like mapl-plnnr,
    v_plnal like mapl-plnal,
    v_tcode like sy-tcode value 'C223',
    v_plnty like plas-plnty value 'R',
    v_objty like crhd-objty value 'A',
    v_plpo_steus like plpo-steus value 'PP04',
    v_verwe like crhd-verwe value '0007'.
    Parameters
    selection-screen: skip 3.
    selection-screen: begin of block 1 with frame.
    parameters: p_name like rlgrap-filename
    default 'C:\My Documents\InputFile.txt'
    obligatory,
    bdc session name prefix
    p_bdcpfx(6) default 'ZPVCRT'
    obligatory,
    number for transction per BDC session
    p_trnssn type i
    default 2000 obligatory,
    retain the BDC session after successfull execution
    p_keep like apqi-qerase
    default 'X',
    user who will be executing BDC session
    p_uname like apqi-userid
    default sy-uname
    obligatory.
    selection-screen: end of block 1.
    possible entry list (F4 dropdown) for input file name
    at selection-screen on value-request for p_name.
    *-SELECT FILE FROM USERS LOCAL PC
    call function 'WS_FILENAME_GET'
    exporting
    DEF_FILENAME = ' '
    def_path = 'C:\Temp\'
    mask = ',.,..'
    mode = 'O'
    title = 'Select File '(007)
    importing
    filename = p_name
    RC =
    exceptions
    inv_winsys = 1
    no_batch = 2
    selection_cancel = 3
    selection_error = 4
    others = 5.
    if sy-subrc 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    endif.
    begin the show
    start-of-selection.
    read data from input file
    perform transfer_xcel_to_itab.
    loop at itab_xcel.
    hang on to xcel line num
    l_tabix = sy-tabix.
    each line in the xcel file marks begining of new prod.version defn
    if num-of-trnas-in-session = 0, create new BDC session
    if v_trans_in_ssn is initial.
    perform bdc_session_open.
    endif.
    begin new bdc script for rtg create trans
    fill in bdc-data for prod.version maintenance screens
    perform bdc_build_script.
    insert the bdc script as a BDC transaction
    perform bdc_submit_transaction.
    keep track of how many BDC transactions were inserted in the BDC
    session
    add 1 to v_trans_in_ssn.
    if the user-specified num of trans in BDC session is reached OR
    if end of input file is reached, close the BDC session
    if v_trans_in_ssn = p_trnssn or
    l_tabix = v_lines_in_xcel.
    perform bdc_session_close.
    clear v_trans_in_ssn.
    endif.
    endloop.
    top-of-page.
    call function 'Z_HEADER'
    EXPORTING
    FLEX_TEXT1 =
    FLEX_TEXT2 =
    FLEX_TEXT3 =
    FORM TRANSFER_XCEL_TO_ITAB *
    Transfer Xcel Spreadsheet to SAP Internal Table *
    form transfer_xcel_to_itab.
    Read the tab-delimited file into itab
    call function 'WS_UPLOAD'
    exporting
    filename = p_name
    filetype = 'DAT'
    IMPORTING
    filelength = flength
    tables
    data_tab = itab_xcel
    exceptions
    conversion_error = 1
    file_open_error = 2
    file_read_error = 3
    invalid_table_width = 4
    invalid_type = 5
    no_batch = 6
    unknown_error = 7
    others = 8.
    if sy-subrc = 0.
    sort the data
    sort itab_xcel by matnr werks.
    clear v_lines_in_xcel.
    if no data in the file - error out
    describe table itab_xcel lines v_lines_in_xcel.
    if v_lines_in_xcel is initial.
    write: / 'No data in input file'.
    stop.
    endif.
    else.
    if file upload failed - error out
    write: / 'Error reading input file'.
    stop.
    endif.
    endform.
    FORM BDC_SESSION_OPEN *
    Open BDC Session *
    form bdc_session_open.
    create bdc session name = prefix-from-selectn-screen + nnnn
    add 1 to v_ssnnr.
    concatenate p_bdcpfx v_ssnnr into v_ssnname.
    open new bdc session
    call function 'BDC_OPEN_GROUP'
    exporting
    client = sy-mandt
    group = v_ssnname
    keep = p_keep
    user = p_uname
    exceptions
    client_invalid = 1
    destination_invalid = 2
    group_invalid = 3
    group_is_locked = 4
    holddate_invalid = 5
    internal_error = 6
    queue_error = 7
    running = 8
    system_lock_error = 9
    user_invalid = 10
    others = 11.
    endform.
    FORM BDC_BUILD_SCRIPT *
    Build BDC *
    form bdc_build_script.
    data: l_arbpl like crhd-arbpl,
    l_text1 like mkal-text1,
    l_mdv01 like mkal-mdv01,
    l_mapl like mapl.
    clear bdc-data itab - begin of new bdc transaction
    clear itab_bdc_tab.
    refresh itab_bdc_tab.
    read material cross reference tables to determine sap part#
    clear : v_matnr, v_plnnr, v_plnal.
    perform read_matnr_cross_ref using itab_xcel-matnr
    itab_xcel-werks
    changing v_matnr.
    determine the version description to use
    if itab_xcel-text1 is initial.
    l_text1 = itab_xcel-verid.
    else.
    l_text1 = itab_xcel-text1.
    endif.
    determine the routing group# and group ctr# to use
    perform read_routing .
    determine the production line to use
    if itab_xcel-mdv01 is initial.
    if not provided in the file then:
    prod line = work ctr on the last PP04 op of the rtg determined above
    perform read_wc_on_last_pp04 using v_plnnr v_plnal
    changing l_mdv01.
    NOTE: when executing the above form\routine, if v_plnnr is initial
    or v_plnal is initial, THEN l_mdv01 will automatically be
    returned blank (ie initial)
    else.
    l_mdv01 = itab_xcel-mdv01.
    endif.
    build bdc script
    perform bdc_build_script_record
    fill in initial screen
    using: 'X' 'SAPLCMFV' '1000',
    ' ' 'BDC_OKCODE' '=ENTE',
    ' ' 'MKAL-WERKS' itab_xcel-werks,
    ' ' 'MKAL-MATNR' v_matnr,
    ' ' 'MKAL_ADMIN-DISPO' space,
    ' ' 'MKAL-PLNNR' space,
    ' ' 'MKAL_ADMIN-STTAG' space,
    ' ' 'MKAL-PLNNG' space,
    ' ' 'MKAL-MDV01' space,
    ' ' 'MKAL-PLNNM' space,
    click create button on initial screen and go to detail screen
    'X' 'SAPLCMFV' '1000',
    ' ' 'BDC_OKCODE' '=CREA',
    fill in the detail screen and go back to initial screen
    'X' 'SAPLCMFV' '2000',
    ' ' 'BDC_OKCODE' '=CLOS',
    ' ' 'MKAL_EXPAND-MATNR' v_matnr,
    ' ' 'MKAL_EXPAND-VERID' itab_xcel-verid,
    ' ' 'MKAL_EXPAND-TEXT1' l_text1,
    ' ' 'MKAL_EXPAND-BSTMI' itab_xcel-bstmi,
    ' ' 'MKAL_EXPAND-BSTMA' itab_xcel-bstma,
    ' ' 'MKAL_EXPAND-ADATU' itab_xcel-adatu,
    ' ' 'MKAL_EXPAND-BDATU' itab_xcel-bdatu,
    ' ' 'MKAL_EXPAND-PLTYG' v_plnty,
    ' ' 'MKAL_EXPAND-PLNNG' v_plnnr,
    ' ' 'MKAL_EXPAND-ALNAG' v_plnal,
    ' ' 'MKAL_EXPAND-STLAL' itab_xcel-stlal,
    ' ' 'MKAL_EXPAND-STLAN' itab_xcel-stlan,
    ' ' 'MKAL_EXPAND-SERKZ' itab_xcel-serkz,
    ' ' 'MKAL_EXPAND-MDV01' l_mdv01,
    ' ' 'MKAL_EXPAND-ELPRO' itab_xcel-elpro,
    ' ' 'MKAL_EXPAND-ALORT' itab_xcel-alort,
    save the production version from initial screen
    'X' 'SAPLCMFV' '1000',
    ' ' 'BDC_OKCODE' '=SAVE'.
    endform.
    FORM BDC_SUBMIT_TRANSACTION *
    Submit BDC Session *
    form bdc_submit_transaction.
    Load BDC script as a trqansction in BDC session
    call function 'BDC_INSERT'
    exporting
    tcode = v_tcode
    tables
    dynprotab = itab_bdc_tab
    exceptions
    internal_error = 01
    not_open = 02
    queue_error = 03
    tcode_invalid = 04.
    endform.
    FORM BDC_BUILD_SCRIPT_RECORD *
    form bdc_build_script_record using dynbegin name value.
    clear itab_bdc_tab.
    if dynbegin = 'X'.
    move: name to itab_bdc_tab-program,
    value to itab_bdc_tab-dynpro,
    'X' to itab_bdc_tab-dynbegin.
    else.
    move: name to itab_bdc_tab-fnam,
    value to itab_bdc_tab-fval.
    shift itab_bdc_tab-fval left deleting leading space.
    endif.
    append itab_bdc_tab.
    endform.
    FORM BDC_SESSION_CLOSE *
    Close BDC Session *
    form bdc_session_close.
    close the session
    call function 'BDC_CLOSE_GROUP'
    exceptions
    not_open = 1
    queue_error = 2
    others = 3.
    skip 2.
    if sy-subrc ne 0.
    write: / 'Error Closing BDC Session ' , 'RETURN CODE: ', sy-subrc.
    else.
    write : / 'Session created:', v_ssnname,
    50 '# of transactions:', v_trans_in_ssn.
    endif.
    endform.
    *& Form read_routing_cache
    *FORM read_routing_cache USING pi_matnr
    pi_werks
    pi_alnag
    pi_verid
    pi_mdv01.
    DATA: BEGIN OF lt_plpo OCCURS 0,
    vornr LIKE plpo-vornr,
    objty LIKE crhd-objty,
    objid LIKE crhd-objid,
    arbpl LIKE crhd-arbpl,
    END OF lt_plpo,
    l_mapl_plnnr LIKE mapl-plnnr.
    determine the routing group#
    CLEAR lt_pp04_cache.
    chk if its in the cache first, if not then get it from MAPL table
    and put it in the cache
    READ TABLE lt_pp04_cache WITH KEY matnr = pi_matnr
    werks = pi_werks
    alnag = pi_alnag.
    IF sy-subrc = 0.
    do nothing - lt_pp04_cache header line has rtg#
    ELSE.
    get the routing group # from MAPL
    SELECT plnnr INTO l_mapl_plnnr
    FROM mapl UP TO 1 ROWS
    WHERE matnr = pi_matnr AND
    werks = pi_werks AND
    plnty = 'R' AND
    plnal = pi_alnag AND
    loekz = space.
    ENDSELECT.
    put it in the cache internal table
    IF NOT l_mapl_plnnr IS INITIAL.
    lt_pp04_cache-matnr = pi_matnr.
    lt_pp04_cache-werks = pi_werks.
    lt_pp04_cache-alnag = pi_alnag.
    lt_pp04_cache-plnnr = l_mapl_plnnr.
    APPEND lt_pp04_cache.
    ENDIF.
    ENDIF.
    if the rtg# was determined AND
    -- the work center was not determined yet AND
    -- work center was really needed for this line in the input file
    then
    -- read the work center from last PP04 operation on the routing
    -- update the cache accordingly
    IF NOT lt_pp04_cache-plnnr IS INITIAL AND
    lt_pp04_cache-arbpl IS INITIAL AND
    ( pi_verid IS INITIAL OR
    pi_mdv01 IS INITIAL ).
    read the last PP04 operation
    CLEAR lt_plpo.
    REFRESH lt_plpo.
    SELECT vornr eobjty eobjid e~arbpl
    INTO CORRESPONDING FIELDS OF TABLE lt_plpo
    FROM plas AS b
    INNER JOIN plpo AS c
    ON bplnty = cplnty AND
    bplnnr = cplnnr AND
    bzaehl = czaehl
    INNER JOIN crhd AS e
    ON carbid = eobjid
    WHERE b~plnty = v_plnty AND
    b~plnnr = lt_pp04_cache-plnnr AND
    b~plnal = lt_pp04_cache-alnag AND
    c~loekz = space AND
    c~steus = v_plpo_steus AND
    e~objty = v_objty AND
    e~werks = lt_pp04_cache-werks AND
    e~verwe = v_verwe.
    SORT lt_plpo BY vornr DESCENDING.
    READ TABLE lt_plpo INDEX 1.
    IF NOT lt_plpo-arbpl IS INITIAL.
    lt_pp04_cache-arbpl = lt_plpo-arbpl.
    read work center description
    SELECT SINGLE ktext INTO lt_pp04_cache-ktext
    FROM crtx WHERE objty = lt_plpo-objty AND
    objid = lt_plpo-objid AND
    spras = sy-langu.
    the following read will get the index of the correct record to be
    updated in the cache
    READ TABLE lt_pp04_cache
    WITH KEY matnr = pi_matnr
    werks = pi_werks
    alnag = pi_alnag.
    MODIFY lt_pp04_cache
    INDEX sy-tabix
    TRANSPORTING arbpl ktext.
    ENDIF.
    ENDIF.
    *ENDFORM. " read_last_pp04_operation_cache
    *& Form read_routing
    form read_routing.
    data: begin of lt_mapl occurs 0,
    plnnr like mapl-plnnr,
    plnal like mapl-plnal,
    end of lt_mapl,
    l_arbpl like crhd-arbpl.
    get all the rtg# and grp ctr# from MAPL
    select plnnr plnal
    into corresponding fields of table lt_mapl
    from mapl
    where matnr = v_matnr and
    werks = itab_xcel-werks and
    plnty = v_plnty and "Rate Routing
    loekz = space. "with del flag = OFF
    sort lt_mapl by plnal.
    if not itab_xcel-verid is initial.
    if the verid=0001 then use the 1st good rtg-grp# and grp-ctr#
    if itab_xcel-verid = '0001'.
    read table lt_mapl index 1.
    v_plnnr = lt_mapl-plnnr.
    v_plnal = lt_mapl-plnal.
    else.
    if the verid0001 then use the rtg-grp# and grp-ctr# of the routing
    whose work center on the last PP04 operation matches the given verid
    loop at lt_mapl.
    clear l_arbpl.
    get the work center from the last PP04 operation
    perform read_wc_on_last_pp04 using lt_mapl-plnnr
    lt_mapl-plnal
    changing l_arbpl.
    if itab_xcel-verid = l_arbpl.
    v_plnnr = lt_mapl-plnnr.
    v_plnal = lt_mapl-plnal.
    exit.
    endif.
    endloop.
    endif.
    else.
    do nothing
    endif.
    For version IDs that are other then '0000' or 'ZWIP' :--
    if itab_xcel-verid NE '0000' and
    itab_xcel-verid NE 'ZWIP'.
    if routing group# or group counter was not determined, make the
    valid-to date 99/99/9999 so that the BDC, on execution, errors out.
    if v_plnnr is initial or
    v_plnal is initial.
    itab_xcel-bdatu = '99/99/9999'.
    endif.
    endif.
    determine the routing group#
    CLEAR lt_pp04_cache.
    chk if its in the cache first, if not then get it from MAPL table
    and put it in the cache
    READ TABLE lt_pp04_cache WITH KEY matnr = pi_matnr
    werks = pi_werks
    alnag = pi_alnag.
    IF sy-subrc = 0.
    do nothing - lt_pp04_cache header line has rtg#
    ELSE.
    get the routing group # from MAPL
    put it in the cache internal table
    IF NOT l_mapl_plnnr IS INITIAL.
    lt_pp04_cache-matnr = pi_matnr.
    lt_pp04_cache-werks = pi_werks.
    lt_pp04_cache-alnag = pi_alnag.
    lt_pp04_cache-plnnr = l_mapl_plnnr.
    APPEND lt_pp04_cache.
    ENDIF.
    ENDIF.
    if the rtg# was determined AND
    -- the work center was not determined yet AND
    -- work center was really needed for this line in the input file
    then
    -- read the work center from last PP04 operation on the routing
    -- update the cache accordingly
    IF NOT lt_pp04_cache-plnnr IS INITIAL AND
    lt_pp04_cache-arbpl IS INITIAL AND
    ( pi_verid IS INITIAL OR
    pi_mdv01 IS INITIAL ).
    read the last PP04 operation
    CLEAR lt_plpo.
    REFRESH lt_plpo.
    SELECT vornr eobjty eobjid e~arbpl
    INTO CORRESPONDING FIELDS OF TABLE lt_plpo
    FROM plas AS b
    INNER JOIN plpo AS c
    ON bplnty = cplnty AND
    bplnnr = cplnnr AND
    bzaehl = czaehl
    INNER JOIN crhd AS e
    ON carbid = eobjid
    WHERE b~plnty = v_plnty AND
    b~plnnr = lt_pp04_cache-plnnr AND
    b~plnal = lt_pp04_cache-alnag AND
    c~loekz = space AND
    c~steus = v_plpo_steus AND
    e~objty = v_objty AND
    e~werks = lt_pp04_cache-werks AND
    e~verwe = v_verwe.
    SORT lt_plpo BY vornr DESCENDING.
    READ TABLE lt_plpo INDEX 1.
    IF NOT lt_plpo-arbpl IS INITIAL.
    lt_pp04_cache-arbpl = lt_plpo-arbpl.
    read work center description
    SELECT SINGLE ktext INTO lt_pp04_cache-ktext
    FROM crtx WHERE objty = lt_plpo-objty AND
    objid = lt_plpo-objid AND
    spras = sy-langu.
    the following read will get the index of the correct record to be
    updated in the cache
    READ TABLE lt_pp04_cache
    WITH KEY matnr = pi_matnr
    werks = pi_werks
    alnag = pi_alnag.
    MODIFY lt_pp04_cache
    INDEX sy-tabix
    TRANSPORTING arbpl ktext.
    ENDIF.
    ENDIF.
    endform. " read_last_pp04_operation_cache
    *& Form read_wc_on_last_pp04
    form read_wc_on_last_pp04 using pi_plnnr
    pi_plnal
    changing pe_arbpl.
    data: begin of lt_plpo occurs 0,
    vornr like plpo-vornr,
    objty like crhd-objty,
    objid like crhd-objid,
    arbpl like crhd-arbpl,
    end of lt_plpo.
    get all the PP04 operations for the given rtg# & grp-ctr#
    select vornr eobjty eobjid e~arbpl
    into corresponding fields of table lt_plpo
    from plas as b
    inner join plpo as c
    on bplnty = cplnty and
    bplnnr = cplnnr and
    bzaehl = czaehl
    inner join crhd as e
    on carbid = eobjid
    where b~plnty = v_plnty and "Rate Routing
    b~plnnr = pi_plnnr and
    b~plnal = pi_plnal and
    c~loekz = space and "Oper Del Flag = OFF
    c~steus = v_plpo_steus and "PP04
    e~objty = v_objty. "WC Obj Type = 'A'
    read the last operation
    sort lt_plpo by vornr descending.
    read table lt_plpo index 1.
    pe_arbpl = lt_plpo-arbpl.
    endform. " read_wc_on_last_pp04
    Goto LSMW-> Select Direct Input method in 1st step. These are the standard programs for data transfer.
    Otherwise goto SPRO->SAP Reference IMG-> Under this you'll find standard data transfer programs module wise.
    Reward points,
    Shakir

  • Differences between Procedural ABAP and OOPs ABAP

    Hi Friends,
    Can any one explain the differences between Procedural ABAP and OOPs ABAP in brief ? pls explain the most important ( atleast 3 or 4 points ). pls don't give me any other links, i will appreciate for good responses... and will be awarded with full points...
    Thanks and Regards
    Vijaya

    Hi
    Core ABAP (procedural) works with Event driven, subroutine driven one
    OOPS ABAP works on the OOPS concepts like Inheritance, polymorphism,abstraction and encapsulation.
    see the doc
    ABAP is one of many application-specific fourth-generation languages (4GLs) first developed in the 1980s. It was originally the report language for SAP R/2, a platform that enabled large corporations to build mainframe business applications for materials management and financial and management accounting. ABAP used to be an abbreviation of Allgemeiner Berichtsaufbereitungsprozessor, the German meaning of "generic report preparation processor", but was later renamed to Advanced Business Application Programming. ABAP was one of the first languages to include the concept of Logical Databases (LDBs), which provides a high level of abstraction from the basic database level.
    The ABAP programming language was originally used by SAP developers to develop the SAP R/3 platform. It was also intended to be used by SAP customers to enhance SAP applications – customers can develop custom reports and interfaces with ABAP programming. The language is fairly easy to learn for programmers but it is not a tool for direct use by non-programmers. Good programming skills, including knowledge of relational database design and preferably also of object-oriented concepts, are required to create ABAP programs.
    ABAP remains the language for creating programs for the client-server R/3 system, which SAP first released in 1992. As computer hardware evolved through the 1990s, more and more of SAP's applications and systems were written in ABAP. By 2001, all but the most basic functions were written in ABAP. In 1999, SAP released an object-oriented extension to ABAP called ABAP Objects, along with R/3 release 4.6.
    SAP's most recent development platform, NetWeaver, supports both ABAP and Java.
    Implementation
    Where does the ABAP Program Run?
    All ABAP programs reside inside the SAP database. They are not stored in separate external files like Java or C++ programs. In the database all ABAP code exists in two forms: source code, which can be viewed and edited with the ABAP workbench, and "compiled" code ("generated" code is the more correct technical term), which is loaded and interpreted by the ABAP runtime system. Code generation happens implicitly when a unit of ABAP code is first invoked. If the source code is changed later or if one of the data objects accessed by the program has changed (e.g. fields were added to a database table), then the code is automatically regenerated.
    ABAP programs run in the SAP application server, under control of the runtime system, which is part of the SAP kernel. The runtime system is responsible for processing ABAP statements, controlling the flow logic of screens and responding to events (such as a user clicking on a screen button). A key component of the ABAP runtime system is the Database Interface, which turns database-independent ABAP statements ("Open SQL") into statements understood by the underlying DBMS ("Native SQL"). The database interface handles all the communication with the relational database on behalf of ABAP programs; it also contains extra features such as buffering of frequently accessed data in the local memory of the application server.
    Basis
    Basis sits between ABAP/4 and Operating system.Basis is like an operating system for R/3. It sits between the ABAP/4 code and the computer's operating system. SAP likes to call it middleware because it sits in the middle, between ABAP/4 and the operating system. Basis sits between ABAP/4 and the operating system. ABAP/4 cannot run directly on an operating system. It requires a set of programs (collectively called Basis) to load, interpret, and buffer its input and output. Basis, in some respects, is like the Windows environment. Windows starts up, and while running it provides an environment in which Windows programs can run. Without Windows, programs written for the Windows environment cannot run. Basis is to ABAP/4 programs as Windows is to Windows programs. Basis provides the runtime environment for ABAP/4 programs. Without Basis, ABAP/4 programs cannot run. When the operator starts up R/3, you can think of him as starting up Basis. Basis is a collection of R/3 system programs that present you with an interface. Using this interface the user can start ABAP/4 programs. To install Basis, an installer runs the program r3inst at the command-prompt level of the operating system. Like most installs, this creates a directory structure and copies a set of executables into it. These executables taken together as a unit form Basis.
    To start up the R/3 system, the operator enters the startsap command. The Basis executables start up and stay running, accepting requests from the user to run ABAP/4 programs.
    ABAP/4 programs run within the protective Basis environment; they are not executables that run on the operating system. Instead, Basis reads ABAP/4 code and interprets it into operating system instructions. ABAP/4 programs do not access operating system functions directly. Instead, they use Basis functions to perform file I/O and display data in windows. This level of isolation from the operating system enables ABAP/4 programs to be ported without modification to any system that supports R/3. This buffering is built right into the ABAP/4 language itself and is actually totally transparent to the programmer.
    Basis makes ABAP/4 programs portable. The platforms that R/3 can run on are shown in Table. For example, if you write an ABAP/4 program on Digital UNIX with an Informix database and an OSF/Motif interface, that same program should run without modification on a Windows NT machine with an Oracle database and a Windows 95 interface. Or, it could run on an AS/400 with a DB2 database using OS/2 as the front-end.
    SAP also provides a suite of tools for administering the Basis system. These tools perform tasks such as system performance monitoring, configuration, and system maintenance. To access the Basis administration tools from the main menu, choose the path Tools->Administration.
    Platforms and Databases Supported by R/3
    Operating Systems Supported Hardware Supported Front-Ends Supported Databases
    AIX SINIX IBM SNI SUN Win 3.1/95/NT DB2 for AIX
    SOLARIS HP-UX Digital HP OSF/Motif Informix-Online
    Digital-UNIX Bull OS/2 Oracle 7.1
    Windows NT AT&T Compaq Win 3.1/95/NT Oracle 7.1
    Bull/Zenith OSF/Motif SQL Server 6.0
    HP (Intel) SNI OS/2 ADABAS D
    OS/400 AS/400 Win95 OS/2 DB2/400
    SAP Systems and Landscapes
    All SAP data exists and all SAP software runs in the context of an SAP system. A system consists of a central relational database and one or more application servers ("instances") accessing the data and programs in this database. A SAP system contains at least one instance but may contain more, mostly for reasons of sizing and performance. In a system with multiple instances, load balancing mechanisms ensure that the load is spread evenly over the available application servers.
    Installations of the Web Application Server (landscapes) typically consist of three systems: one for development, one for testing and quality assurance, and one for production. The landscape may contain more systems, e.g. separate systems for unit testing and pre-production testing, or it may contain fewer, e.g. only development and production, without separate QA; nevertheless three is the most common configuration. ABAP programs are created and undergo first testing in the development system. Afterwards they are distributed to the other systems in the landscape. These actions take place under control of the Change and Transport System (CTS), which is responsible for concurrency control (e.g. preventing two developers from changing the same code at the same time), version management and deployment of programs on the QA and production systems.
    The Web Application Server consists of three layers: the database layer, the application layer and the presentation layer. These layers may run on the same or on different physical machines. The database layer contains the relational database and the database software. The application layer contains the instance or instances of the system. All application processes, including the business transactions and the ABAP development, run on the application layer. The presentation layer handles the interaction with users of the system. Online access to ABAP application servers can go via a proprietary graphical interface, the SAPGUI, or via a Web browser.
    Transactions
    We call an execution of an ABAP program using a transaction code a transaction. There are dialog, report, parameter, variant, and as of release 6.10, OO transactions. A transaction is started by entering the transaction code in the input field on the standard toolbar, or by means of the ABAP statements CALL TRANSACTION or LEAVE TO TRANSACTION. Transaction codes can also be linked to screen elements or menu entries. Selecting such an element will start the transaction.
    A transaction code is simply a twenty-character name connected with a Dynpro, another transaction code, or, as of release 6.10, a method of an ABAP program. Transaction codes linked with Dynpros are possible for executable programs, module pools, and function groups. Parameter transactions and variant transactions are linked with other transaction codes. Transaction codes that are linked with methods are allowed for all program types that can contain methods. Transaction codes are maintained in transaction SE93.
    So, a transaction is nothing more than the SAP way of program execution—but why is it called “transaction”? ABAP is a language for business applications and the most important features of business applications were and still are are transactions. Since in the early days of SAP, the execution of a program often meant the same thing as carrying out a business transaction, the terms transaction and transaction code were chosen for program execution. But never mix up the technical meaning of a transaction with business transactions. For business transactions, it is the term LUW (Logical Unit of Work) that counts. And during one transaction (program execution), there can be many different LUW’s.
    Let’s have a look at the different kind of transactions:
    Dialog Transaction
    These are the most common kind of transactions. The transaction code of a dialog transaction is linked to a Dynpro of an ABAP program. When the transaction is called, the respective program is loaded and the Dynpro is called. Therefore, a dialog transaction calls a Dynpro sequence rather than a program. Only during the execution of the Dynpro flow logic are the dialog modules of the ABAP program itself are called. The program flow can differ from execution to execution. You can even assign different dialog transaction codes to one program.
    Parameter Transaction
    In the definition of a parameter transaction code, a dialog transaction is linked with parameters. When you call a parameter transaction, the input fields of the initial Dynpro screen of the dialog transaction are filled with parameters. The display of the initial screen can be inhibited by specifying all mandatory input fields as parameters of the transaction.
    Variant Transaction
    In the definition of a variant transaction code, a dialog transaction is linked with a transaction variant. When a variant transaction is accessed, the dialog transaction is called and executed with the transaction variant. In transaction variants, you can assign default values to the input fields on several Dynpro screens in a transaction, change the attributes of screen elements, and hide entire screens. Transaction variants are maintained in transaction SHD0.
    Report Transaction
    A report transaction is the transaction code wrapping for starting the reporting process. The transaction code of a report transaction must be linked with the selection screen of an executable program. When you execute a report transaction, the runtime environment internally executes the ABAP statement SUBMIT—more to come on that.
    OO Transaction
    A new kind of transaction as of release 6.10. The transaction code of an OO transaction is linked with a method of a local or global class. When the transaction is called, the corresponding program is loaded, for instance methods an object of the class is generated and the method is executed.
    Types of ABAP programs
    In ABAP, there are two different types of programs:
    Report programs(Executable pools)
    A Sample ReportReport programs AKA Executable pools follow a relatively simple programming model whereby a user optionally enters a set of parameters (e.g. a selection over a subset of data) and the program then uses the input parameters to produce a report in the form of an interactive list. The output from the report program is interactive because it is not a passive display; instead it enables the user, through ABAP language constructs, to obtain a more detailed view on specific data records via drill-down functions, or to invoke further processing through menu commands, for instance to sort the data in a different way or to filter the data according to selection criteria. This method of presenting reports has great advantages for users who must deal with large quantities of information and must also have the ability to examine this information in highly flexible ways, without being constrained by the rigid formatting or unmanageable size of "listing-like" reports. The ease with which such interactive reports can be developed is one of the most striking features of the ABAP language.
    The term "report" is somewhat misleading in the sense that it is also possible to create report programs that modify the data in the underlying database instead of simply reading it.
    A customized screen created using Screen Painter,which is one of the tool available in ABAP workbench(T-code = SE51).
    Online programs
    Online programs (also called module pools) do not produce lists. These programs define more complex patterns of user interaction using a collection of screens. The term “screen” refers to the actual, physical image that the users sees. Each screen also has a “flow logic”; this refers to the ABAP code invoked by the screens, i.e. the logic that initializes screens, responds to a user’s requests and controls the sequence between the screens of a module pool. Each screen has its own Flow Logic, which is divided into a "PBO" (Process Before Output) and "PAI" (Process After Input) section. In SAP documentation the term “dynpro” (dynamic program) refers to the combination of the screen and its Flow Logic.
    Online programs are not invoked directly by their name, but are associated with a transaction code. Users can then invoke them through customizable, role-dependent, transaction menus.
    Apart from reports and online programs, it is also possible to develop sharable code units such as class libraries, function libraries and subroutine pools.
    Subroutine Pools
    Subroutine pools, as the name implies, were created to contain selections of subroutines that can be called externally from other programs. Before release 6.10, this was the only way subroutine pools could be used. But besides subroutines, subroutine pools can also contain local classes and interfaces. As of release 6.10, you can connect transaction codes to methods. Therefore, you can now also call subroutine pools via transaction codes. This is the closest to a Java program you can get in ABAP: a subroutine pool with a class containing a method – say – main connected to a transaction code!
    Type Pools
    Type pools are the precursors to general type definitions in the ABAP Dictionary. Before release 4.0, only elementary data types and flat structures could be defined in the ABAP Dictionary. All other types that should’ve been generally available had to be defined with TYPES in type pools. As of release 4.0, type pools were only necessary for constants. As of release 6.40, constants can be declared in the public sections of global classes and type pools can be replaced by global classes.
    Class Pools
    Class pools serve as containers for exactly one global class. Besides the global class, they can contain global types and local classes/interfaces to be used in the global class. A class pool is loaded into memory by using one of its components. For example, a public method can be called from any ABAP program or via a transaction code connected to the method. You maintain class pools in the class builder.
    Interface Pools
    Interface pools serve as containers for exactly one global interface—nothing more and nothing less. You use an interface pool by implementing its interface in classes and by creating reference variables with the type of its interface. You maintain interface pools in the class builder.
    ABAP Workbench
    The ABAP Workbench contains different tools for editing Repository objects. These tools provide you with a wide range of assistance that covers the entire software development cycle. The most important tools for creating and editing Repository objects are:
    ABAP Editor for writing and editing program code
    ABAP Dictionary for processing database table definitions and retrieving global types
    Menu Painter for designing the user interface (menu bar, standard toolbar, application toolbar, function key assignment)
    Screen Painter for designing screens (dynamic programs) for user dialogs
    Function Builder for displaying and processing function modules (routines with defined interfaces that are available throughout the system)
    Class Builder for displaying and processing ABAP Objects classes
    The ABAP Dictionary
    Enforces data integrity
    Manages data definitions without redundancy
    Is tightly integrated with the rest of the ABAP/4 Development Workbench.
    Enforcing data integrity is the process of ensuring that data entered into the system is logical, complete, and consistent. When data integrity rules are defined in the ABAP/4 Dictionary, the system automatically prevents the entry of invalid data. Defining the data integrity rules at the dictionary level means they only have to be defined once, rather than in each program that accesses that data.
    The following are examples of data lacking integrity:
    A date field with a month value of 13
    An order assigned to a customer number that doesn’t exist
    An order not assigned to a customer
    Managing data definitions without redundancy is the process of linking similar information to the same data definition. For example, a customer database is likely to contain a customer’s ID number in several places. The ABAP Dictionary provides the capability of defining the characteristics of a customer ID number in only one place. That central definition then can be used for each instance of a customer ID number.
    The ABAP Dictionary’s integration with the rest of the development environment enables ABAP programs to automatically recognize the names and characteristics of dictionary objects.
    Additionally, the system provides easy navigation between development objects and dictionary definitions. For example, as a programmer, you can double-click on the name of a dictionary object in your program code, and the system will take you directly to the definition of that object in the ABAP/4 Dictionary.
    When a dictionary object is changed, a program that references the changed object will automatically reference the new version the next time the program runs. Because ABAP is interpreted, it is not necessary to recompile programs that reference changed dictionary objects.
    ABAP Syntax
    The syntax of the ABAP programming language consists of the following elements:
    Statements
    An ABAP program consists of individual ABAP statements. Each statement begins with a keyword and ends with a period.
    "Hello World" PROGRAM
    WRITE 'Hello World'.
    This example contains two statements, one on each line. The keywords are PROGRAM and WRITE. The program displays a list on the screen. In this case, the list consists of the line "My First Program".
    The keyword determines the category of the statement. For an overview of the different categories, refer to ABAP Statements.
    Formatting ABAP Statements
    ABAP has no format restrictions. You can enter statements in any format, so a statement can be indented, you can write several statements on one line, or spread a single statement over several lines.
    You must separate words within a statement with at least one space. The system also interprets the end of line marker as a space.
    The program fragment
    PROGRAM TEST.
    WRITE 'This is a statement'.
    could also be written as follows:
    PROGRAM TEST. WRITE 'This is a statement'.
    or as follows:
    PROGRAM
    TEST.
    WRITE
    'This is a statement'.
    Use this free formatting to make your programs easier to understand.
    Special Case: Text Literals
    Text literals are sequences of alphanumeric characters in the program code that are enclosed in quotation marks. If a text literal in an ABAP statement extends across more than one line, the following difficulties can occur:
    All spaces between the quotation marks are interpreted as belonging to the text literal. Letters in text literals in a line that is not concluded with quotation marks are interpreted by the editor as uppercase. If you want to enter text literals that do not fit into a single line, you can use the ‘&’ character to combine a succession of text literals into a single one.
    The program fragment
    PROGRAM TEST.
    WRITE 'This
    is
    a statement'.
    inserts all spaces between the quotation marks into the literal, and converts the letters to uppercase.
    This program fragment
    PROGRAM TEST.
    WRITE 'This' &
    ' is ' &
    'a statement'.
    combines three text literals into one.
    Chained Statements
    The ABAP programming language allows you to concatenate consecutive statements with an identical first part into a chain statement.
    To concatenate a sequence of separate statements, write the identical part only once and place a colon ( after it. After the colon, write the remaining parts of the individual statements, separating them with commas. Ensure that you place a period (.) after the last part to inform the system where the chain ends.
    Statement sequence:
    WRITE SPFLI-CITYFROM.
    WRITE SPFLI-CITYTO.
    WRITE SPFLI-AIRPTO.
    Chain statement:
    WRITE: SPFLI-CITYFROM, SPFLI-CITYTO, SPFLI-AIRPTO.
    In the chain, a colon separates the beginning of the statement from the variable parts. After the colon or commas, you can insert any number of spaces.
    You could, for example, write the same statement like this:
    WRITE: SPFLI-CITYFROM,
    SPFLI-CITYTO,
    SPFLI-AIRPTO.
    In a chain statement, the first part (before the colon) is not limited to the keyword of the statements.
    Statement sequence:
    SUM = SUM + 1.
    SUM = SUM + 2.
    SUM = SUM + 3.
    SUM = SUM + 4.
    Chain statement:
    SUM = SUM + : 1, 2, 3, 4.
    Comments
    Comments are texts that you can write between the statements of your ABAP program to explain their purpose to a reader. Comments are distinguished by the preceding signs * (at the beginning of a line) and " (at any position in a line). If you want the entire line to be a comment, enter an asterisk (*) at the beginning of the line. The system then ignores the entire line when it generates the program. If you want part of a line to be a comment, enter a double quotation mark (") before the comment. The system interprets comments indicated by double quotation marks as spaces.
    PROGRAM SAPMTEST *
    WRITTEN BY KARL BYTE, 06/27/1995 *
    LAST CHANGED BY RITA DIGIT, 10/01/1995 *
    TASK: DEMONSTRATION *
    PROGRAM SAPMTEST.
    DECLARATIONS *
    DATA: FLAG " GLOBAL FLAG
    NUMBER TYPE I " COUNTER
    PROCESSING BLOCKS *
    Advantages of ABAP over Contemporary languages
    ABAP OBJECTS
    Object orientation in ABAP is an extension of the ABAP language that makes available the advantages of object-oriented programming, such as encapsulation, interfaces, and inheritance. This helps to simplify applications and make them more controllable.
    ABAP Objects is fully compatible with the existing language, so you can use existing statements and modularization units in programs that use ABAP Objects, and can also use ABAP Objects in existing ABAP programs.
    ABAP Statements – an Overview
    The first element of an ABAP statement is the ABAP keyword. This determines the category of the statement. The different statement categories are as follows:
    Declarative Statements
    These statements define data types or declare data objects which are used by the other statements in a program or routine. The collected declarative statements in a program or routine make up its declaration part.
    Examples of declarative keywords:
    TYPES, DATA, TABLES
    Modularization Statements
    These statements define the processing blocks in an ABAP program.
    The modularization keywords can be further divided into:
    · Defining keywords
    You use statements containing these keywords to define subroutines, function modules, dialog modules and methods. You conclude these processing blocks using the END statements.
    Examples of definitive keywords:
    METHOD ... ENDMETHOD, FUNCTION ... ENDFUNCTION, MODULE ... ENDMODULE.
    · Event keywords
    You use statements containing these keywords to define event blocks. There are no special statements to conclude processing blocks - they end when the next processing block is introduced.
    Examples of event key words:
    AT SELECTION SCREEN, START-OF-SELECTION, AT USER-COMMAND
    Control Statements
    You use these statements to control the flow of an ABAP program within a processing block according to certain conditions.
    Examples of control keywords:
    IF, WHILE, CASE
    Call Statements
    You use these statements to call processing blocks that you have already defined using modularization statements. The blocks you call can either be in the same ABAP program or in a different program.
    Examples of call keywords:
    CALL METHOD, CALL TRANSACTION, SUBMIT, LEAVE TO
    Operational Statements These keywords process the data that you have defined using declarative statements.
    Examples of operational keywords:
    MOVE, ADD
    Unique Concept of Internal Table in ABAP
    Internal tables provide a means of taking data from a fixed structure and storing it in working memory in ABAP. The data is stored line by line in memory, and each line has the same structure. In ABAP, internal tables fulfill the function of arrays. Since they are dynamic data objects, they save the programmer the task of dynamic memory management in his or her programs. You should use internal tables whenever you want to process a dataset with a fixed structure within a program. A particularly important use for internal tables is for storing and formatting data from a database table within a program. They are also a good way of including very complicated data structures in an ABAP program.
    Like all elements in the ABAP type concept, internal tables can exist both as data types and as data objects A data type is the abstract description of an internal table, either in a program or centrally in the ABAP Dictionary, that you use to create a concrete data object. The data type is also an attribute of an existing data object.
    Internal Tables as Data Types
    Internal tables and structures are the two structured data types in ABAP. The data type of an internal table is fully specified by its line type, key, and table type.
    Line type
    The line type of an internal table can be any data type. The data type of an internal table is normally a structure. Each component of the structure is a column in the internal table. However, the line type may also be elementary or another internal table.
    Key
    The key identifies table rows. There are two kinds of key for internal tables - the standard key and a user-defined key. You can specify whether the key should be UNIQUE or NON-UNIQUE. Internal tables with a unique key cannot contain duplicate entries. The uniqueness depends on the table access method.
    If a table has a structured line type, its default key consists of all of its non-numerical columns that are not references or themselves internal tables. If a table has an elementary line type, the default key is the entire line. The default key of an internal table whose line type is an internal table, the default key is empty.
    The user-defined key can contain any columns of the internal table that are not references or themselves internal tables. Internal tables with a user-defined key are called key tables. When you define the key, the sequence of the key fields is significant. You should remember this, for example, if you intend to sort the table according to the key.
    Table type
    The table type determines how ABAP will access individual table entries. Internal tables can be divided into three types:
    Standard tables have an internal linear index. From a particular size upwards, the indexes of internal tables are administered as trees. In this case, the index administration overhead increases in logarithmic and not linear relation to the number of lines. The system can access records either by using the table index or the key. The response time for key access is proportional to the number of entries in the table. The key of a standard table is always non-unique. You cannot specify a unique key. This means that standard tables can always be filled very quickly, since the system does not have to check whether there are already existing entries.
    Sorted tables are always saved sorted by the key. They also have an internal index. The system can access records either by using the table index or the key. The response time for key access is logarithmically proportional to the number of table entries, since the system uses a binary search. The key of a sorted table can be either unique or non-unique. When you define the table, you must specify whether the key is to be unique or not. Standard tables and sorted tables are known generically as index tables.
    Hashed tables have no linear index. You can only access a hashed table using its key. The response time is independent of the number of table entries, and is constant, since the system access the table entries using a hash algorithm. The key of a hashed table must be unique. When you define the table, you must specify the key as UNIQUE.
    Generic Internal Tables
    Unlike other local data types in programs, you do not have to specify the data type of an internal table fully. Instead, you can specify a generic construction, that is, the key or key and line type of an internal table data type may remain unspecified. You can use generic internal tables to specify the types of field symbols and the interface parameters of procedures . You cannot use them to declare data objects.
    Internal Tables as Dynamic Data Objects
    Data objects that are defined either with the data type of an internal table, or directly as an internal table, are always fully defined in respect of their line type, key and access method. However, the number of lines is not fixed. Thus internal tables are dynamic data objects, since they can contain any number of lines of a particular type. The only restriction on the number of lines an internal table may contain are the limits of your system installation. The maximum memory that can be occupied by an internal table (including its internal administration) is 2 gigabytes. A more realistic figure is up to 500 megabytes. An additional restriction for hashed tables is that they may not contain more than 2 million entries. The line types of internal tables can be any ABAP data types - elementary, structured, or internal tables. The individual lines of an internal table are called table lines or table entries. Each component of a structured line is called a column in the internal table.
    Choosing a Table Type
    The table type (and particularly the access method) that you will use depends on how the typical internal table operations will be most frequently executed.
    Standard tables
    This is the most appropriate type if you are going to address the individual table entries using the index. Index access is the quickest possible access. You should fill a standard table by appending lines (ABAP APPEND statement), and read, modify and delete entries by specifying the index (INDEX option with the relevant ABAP command). The access time for a standard table increases in a linear relationship with the number of table entries. If you need key access, standard tables are particularly useful if you can fill and process the table in separate steps. For example, you could fill the table by appending entries, and then sort it. If you use the binary search option with key access, the response time is logarithmically proportional to the number of table entries.
    Sorted tables
    This is the most appropriate type if you need a table which is sorted as you fill it. You fill sorted tables using the INSERT statement. Entries are inserted according to the sort sequence defined through the table key. Any illegal entries are recognized as soon as you try to add them to the table. The response time for key access is logarithmically proportional to the number of table entries, since the system always uses a binary search. Sorted tables are particularly useful for partially sequential processing in a LOOP if you specify the beginning of the table key in the WHERE condition.
    Hashed tables
    This is the most appropriate type for any table where the main operation is key access. You cannot access a hashed table using its index. The response time for key access remains constant, regardless of the number of table entries. Like database tables, hashed tables always have a unique key. Hashed tables are useful if you want to construct and use an internal table which resembles a database table or for processing large amounts of data.
    Advanced Topics
    Batch Input: Concepts
    Processing Sessions
    The above figure shows how a batch input session works.A batch input session is a set of one or more calls to transactions along with the data to be processed by the transactions. The system normally executes the transactions in a session non-interactively, allowing rapid entry of bulk data into an R/3 System.
    A session records transactions and data in a special format that can be interpreted by the R/3 System. When the System reads a session, it uses the data in the session to simulate on-line entry of transactions and data. The System can call transactions and enter data using most of the facilities that are available to interactive users.
    For example, the data that a session enters into transaction screens is subject to the same consistency checking as in normal interactive operation. Further, batch input sessions are subject to the user-based authorization checking that is performed by the system.
    Advantages of ABAP over Contemporary languages
    ABAP Objects offers a number of advantages, even if you want to continue using procedural programming. If you want to use new ABAP features, you have to use object-oriented interfaces anyway.
    Sharing Data: With ABAP shared objects, you can aggregate data once at a central location and the different users and programs can then access this data without the need for copying.
    Exception Handling: With the class-based exception concept of ABAP, you can define a special control flow for a specific error situation and provide the user with information about the error.
    Developing Persistency: For permanent storage of data in ABAP, you use relational database tables by means of database-independent Open SQL, which is integrated in ABAP. However, you can also store selected objects transparently or access the integrated database or other databases using proprietary SQL.
    Connectivity and Interoperability: The Exchange Infrastructure and Web services are the means by which developers can implement a service-oriented architecture. With Web services, you can provide and consume services independently of implementation or protocol. Furthermore, you can do so within NetWeaver and in the communication with other systems. With the features of the Exchange Infrastructure, you can enable, manage, and adapt integration scenarios between systems.
    Making Enhancements: With the Enhancement Framework, you can enhance programs, function modules, and global classes without modification as well as replace existing code. The Switch Framework enables you activate only specific development objects or enhancements in a system.
    Considerable Aspects
    It follows a list of aspects to be considered during development. The list of course is not complete.
    Dynpro persistence
    When implementing dynpros one has to care for himself to read out and persist the necessary fields. Recently it happened to me that I forgot to include a field into the UPDATE-clause which is an error not so easy to uncover if you have other problems to be solved in the same package. Here, tool-support or built-in mechanisms would help.
    The developer could help himself out by creating something like a document containing a cookbook or guide in which parts of a dynpro logic one has to care about persistence. With that at hand, it would be quite easy finding those bugs in short time. Maybe a report scanning for the definition of the dynpro fields to be persisted could scan the code automatically, too.
    Memory Cache
    It should be common-sense that avoiding select-statements onto the database helps reducing the server load. For that the programmer either can resort to function modules if available. This maybe is the case for important tables. Or the programmer needs to implement his own logic using internal tables. Here, the standard software package could provide the developer with a tool or a mechanism auto-generating memory cached tables resp. function modules implementing this.
    Sometimes buffering of database tables could be used, if applicable. But that would require an effort in customizing the system and could drain down system performance overall, especially if a table is involved that has a central role.
    Interfaces
    It should be noticed that some function modules available have an incomplete interface. That means, the interface does not include all parameters evaluated by the logic of the function module. For example, global variables from within the function group could be read out, which cannot be influenced by the general caller. Or memory parameters are used internally to feed the logic with further information.
    One workaround here would be copying the relevant parts of the logic to a newly created function module and then adapt it to the own context. This sometimes is possible, maybe if the copied code is not too lengthy and only a few or no calls to other logic is part of it.
    A modification of the SAP code could be considered, if the modification itself is unavoidable (or another solution would be not justifiable by estimated effort to spend on it) and if the location of the modification seems quite safe against future upgrades or hot fixes. The latter is something that could be evaluated by contacting the SAP hotline or working with OSS message (searching thru existing one, perhaps open a new one).
    Example
    'From SAP NetWeaver:'
    set an exclusive lock at level object-type & object-id
    IF NOT lf_bapi_error = true.
    IF ( NOT istourhd-doc_type IS INITIAL ) AND
    ( NOT istourhd-doc_id IS INITIAL )
    CALL FUNCTION 'ENQUEUE_/DSD/E_HH_RAREF'
    EXPORTING
    obj_typ = istourhd-doc_type
    obj_id = istourhd-doc_id
    EXCEPTIONS
    foreign_lock = 1
    system_failure = 2
    OTHERS = 3.
    IF sy-subrc <> 0.
    terminate processing...
    lf_bapi_error = true.—
    ...and add message to return table
    PERFORM set_msg_to_bapiret2
    USING sy-msgid gc_abort sy-msgno
    sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
    gc_istourhd gc_enqueue_refdoc space
    CHANGING lt_return.
    ENDIF.
    ENDIF.
    ENDIF. " bapi error
    Example Report(Type - ALV(Advanced List Viewer))
    REPORT Z_ALV_SIMPLE_EXAMPLE_WITH_ITAB .
    *Simple example to use ALV and to define the ALV data in an internal
    *table
    *data definition
    tables:
    marav. "Table MARA and table MAKT
    Data to be displayed in ALV
    Using the following syntax, REUSE_ALV_FIELDCATALOG_MERGE can auto-
    matically determine the fieldstructure from this source program
    Data:
    begin of imat occurs 100,
    matnr like marav-matnr, "Material number
    maktx like marav-maktx, "Material short text
    matkl like marav-matkl, "Material group (so you can test to make
    " intermediate sums)
    ntgew like marav-ntgew, "Net weight, numeric field (so you can test to
    "make sums)
    gewei like marav-gewei, "weight unit (just to be complete)
    end of imat.
    Other data needed
    field to store report name
    data i_repid like sy-repid.
    field to check table length
    data i_lines like sy-tabix.
    Data for ALV display
    TYPE-POOLS: SLIS.
    data int_fcat type SLIS_T_FIELDCAT_ALV.
    select-options:
    s_matnr for marav-matnr matchcode object MAT1.
    start-of-selection.
    read data into table imat
    select * from marav
    into corresponding fields of table imat
    where
    matnr in s_matnr.
    Check if material was found
    clear i_lines.
    describe table imat lines i_lines.
    if i_lines lt 1.
    Using hardcoded write here for easy upload
    write: /
    'No materials found.'.
    exit.
    endif.
    end-of-selection.
    To use ALV, we need a DDIC-structure or a thing called Fieldcatalogue.
    The fieldcatalouge can be generated by FUNCTION
    'REUSE_ALV_FIELDCATALOG_MERGE' from an internal table from any
    report source, including this report.
    Store report name
    i_repid = sy-repid.
    Create Fieldcatalogue from internal table
    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
    I_PROGRAM_NAME = i_repid
    I_INTERNAL_TABNAME = 'IMAT' "capital letters!
    I_INCLNAME = i_repid
    CHANGING
    CT_FIELDCAT = int_fcat
    EXCEPTIONS
    INCONSISTENT_INTERFACE = 1
    PROGRAM_ERROR = 2
    OTHERS = 3.
    *explanations:
    I_PROGRAM_NAME is the program which calls this function
    I_INTERNAL_TABNAME is the name of the internal table which you want
    to display in ALV
    I_INCLNAME is the ABAP-source where the internal table is defined
    (DATA....)
    CT_FIELDCAT contains the Fieldcatalouge that we need later for
    ALV display
    IF SY-SUBRC <> 0.
    write: /
    'Returncode',
    sy-subrc,
    'from FUNCTION REUSE_ALV_FIELDCATALOG_MERGE'.
    ENDIF.
    *This was the fieldcatlogue
    Call for ALV list display
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = i_repid
    IT_FIELDCAT = int_fcat
    TABLES
    T_OUTTAB = imat
    EXCEPTIONS
    PROGRAM_ERROR = 1
    OTHERS = 2.
    *explanations:
    I_CALLBACK_PROGRAM is the program which calls this function
    IT_FIELDCAT (just made by REUSE_ALV_FIELDCATALOG_MERGE) contains
    now the data definition needed for display
    I_SAVE allows the user to save his own layouts
    T_OUTTAB contains the data to be displayed in ALV
    IF SY-SUBRC <> 0.
    write: /
    'Returncode',
    sy-subrc,
    'from FUNCTION REUSE_ALV_LIST_DISPLAY'.
    ENDIF.
    OOPs ABAP uses Classes and Interfaces which uses Methods and events.
    If you have Java skills it is advantage for you.
    There are Local classes as well as Global Classes.
    Local classes we can work in SE38 straight away.
    But mostly it is better to use the Global classes.
    Global Classes or Interfaces are to be created in SE24.
    SAP already given some predefined classes and Interfaces.
    This OOPS concepts very useful for writing BADI's also.
    So first create a class in SE 24.
    Define attributes, Methods for that class.
    Define parameters for that Method.
    You can define event handlers also to handle the messages.
    After creation in each method write the code.
    Methods are similar to ABAP PERFORM -FORM statements.
    After the creation of CLass and methods come to SE38 and create the program.
    In the program create a object type ref to that class and with the help of that Object call the methods of that Class and display the data.
    Regards
    Anji

  • What is difference between report programming and dialog programming?

    hi,
    what is difference between report programming and dialog programming? plz provide some example code
    bye

    ABAP programming
    Basically reports are used to read database and represent the results in lists.
    Reports are collections of processing blocks that the system calls depending on events.
    We can use reports to evaluate data from database tables.
    Reports are stand alone programs and controlled by events.
    A report itself never creates events
    steps in report:
    Processing the selection screen
    Reading the database
    Evaluating the data and creating lists
    Outputting a list.
    1st u write simple logics, after that u can enhance the code as step by step.
    http://venus.imp.mx/hilario/Libros/TeachYrslfAbap4/index.htm
    http://help.sap.com/saphelp_47x200/helpdata/en/d1/802cfc454211d189710000e8322d00/frameset.htm
    http://www.sapdev.co.uk/reporting/reportinghome.htm
    Dialog Programming
    Structure of a Dialog Program
    A dialog program consists of the following basic components:
    Screens (dynpros)
    Each dialog in an SAP system is controlled by dynpros. A dynpro (DYnamic PROgram) consists of a screen and its flow logic and controls exactly one dialog step. The flow logic determines which processing takes place before displaying the screen (PBO-Process Before Output) and after receiving the entries the user made on the screen (PAI-Process After Input).
    The screen layout fixed in the Screen Painter determines the positions of input/output fields, text fields, and graphical elements such as radio buttons and checkboxes. In addition, the Menu Painter allows to store menus, icons, pushbuttons, and function keys in one or more GUI statuses. Dynpros and GUI statuses refer to the ABAP/4 program that control the sequence of the dynpros and GUI statuses at runtime.
    ABAP/4 module pool
    Each dynpro refers to exactly one ABAP/4 dialog program. Such a dialog program is also called a module pool, since it consists of interactive modules. The flow logic of a dynpro contains calls of modules from the corresponding module pool. Interactive modules called at the PBO event are used to prepare the screen template in accordance to the context, for example by setting field contents or by suppressing fields from the display that are not needed. Interactive modules called at the PAI event are used to check the user input and to trigger appropriate dialog steps, such as the update task.
    All dynpros to be called from within one transaction refer to a common module pool. The dynpros of a module pool are numbered. By default, the system stores for each dynpro the dynpro to be displayed next. This dynpro sequence or chain can be linear as well as cyclic. From within a dynpro chain, you can even call another dynpro chain and, after processing it, return to the original chain.
    Check this link for basics.
    http://sap.mis.cmich.edu/sap-abap/abap09/index.htm
    Check this link for Dialog Programming/Table Control
    http://www.planetsap.com/Tips_and_Tricks.htm#dialog
    Check this SAP Help for Dialog Program doc.
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9cdc35c111d1829f0000e829fbfe/content.htm
    Check this SAP Help link for Subscreens.
    http://help.sap.com/saphelp_nw70/helpdata/en/9f/dbabfe35c111d1829f0000e829fbfe/content.htm
    Check this link for subscreen demo program.
    http://abapcode.blogspot.com/2007/05/demo-program-to-create-subscreen-in.html
    Also check this link too.
    http://abapcode.blogspot.com/2007/06/dialog-programming-faq.html
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9cdc35c111d1829f0000e829fbfe/frameset.htm
    http://sap.mis.cmich.edu/sap-abap/abap09/sld004.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/52/670ba2439b11d1896f0000e8322d00/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/52/670c17439b11d1896f0000e8322d00/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/52/670c17439b11d1896f0000e8322d00/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9ccf35c111d1829f0000e829fbfe/frameset.htm
    http://abapprogramming.blogspot.com/

Maybe you are looking for