Reset or Bypass SQL Buffer ABAP Program

Hi,
How to bypass or reset the use of the buffer table in an ABAP program with the purpose of evaluating their performance access. I can not change the program because it is in production.
Thanx.
Diovani

Hi ,
I am giving you the SAP standrad help  comments here  as prescriblely :
FROM clause
Specifies the database tables from which the data in the selection in the SELECT clause is to be read.
Syntax
... FROM [<tab> [INNER]|LEFT [OUTER] JOIN] <dbtab> [AS <alias>]
                               [ON <cond>]
         [CLIENT SPECIFIED]
         [BYPASSING BUFFER]
         [UP TO <n> ROWS]
You can read a single table <dbtab> or more than one table, using inner and outer joins to link tables with conditions <cond>, where <tab> is a single table or itself a join condition. You can specify individual database tables either statically or dynamically, and you can replace their names with an alternative <alias>. You can bypass automatic client handling with the CLIENT SPECIFIED addition, and SAP buffering with BYPASSING BUFFER. You can also restrict the number of lines read from the table using the UP TO <n> ROWS addition.
For More Information please see this link  : using keyword  in find "BYPASSING BUFFER"
Link: [http://help.sap.com/saphelp_46c/helpdata/en/87/56d00722c011d2954a0000e8353423/frameset.htm]
Regards,

Similar Messages

  • Reading BLOB in Native SQL from ABAP program

    Hello,
    I'm trying to read content of a BLOB field from a table with Native SQL in ABAP like this:
    DATA: l_bytes type xstring.
    EXEC SQL.
      SELECT bytes INTO :l_bytes FROM tablename
    ENDEXEC.
    But when I'm using xstring it returns only 32768 bytes. When using type x length 65000 for l_bytes it returns 65000 bytes, but x is limited to 65535 bytes only. So why it returns only 32768 bytes in direct sql? For DB2 I found note 610342 where you need to add \lob to the statement, I tried with Oracle but doesn't work.
    DATA: CLOB_VAR TYPE STRING.
    DATA: BLOB_VAR TYPE XSTRING.
    EXEC SQL.     
      SELECT FCLOB, FBLOB FROM ZZTAB        INTO :CLOB_VAR\lob, :BLOB_VAR\lob
    ENDEXEC.
    Regards
    Markus

    Hi Markus,
    you have to read it in chunks (remember a blob could be up to 4 Gbyte!).
    I assume you store the byte stream in the field (no bfile pointer to a file ).
    Give you a pseudocode that you get the picture.
    Would recommend that you read the Oracle manual (db Version?)
    9i
    http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96612/d_lob2.htm#1008611
    10g
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_lob.htm#ARPLS600
    chunksize = 32768 .  " or use 65000 . This is the amount of the blob part you want to read
    offset = 1.
    *get the row of interest and retrieve blob's length
    Exec sql.
    select  dbms_lob.getlength(your_blob)  :blob_length from blob_table where my_primary_key = 1
    end exec.
    *calculate times to read from blob  until the end (well, leave the adjustment to you
    * in case of an uneven  fraction)
    ntimes = blob_length / chunksize .
    Do ntimes
    *loop and get the chunks into your variable:
    * start reading from offset chunksize of bytes
    exec sql.
    select dbms_lob.substr(your_blob, :chunksize,:offset) into  :xblobvar  from blob_table
    where my_primary_key = 1
    endexec.
    *don't know what you want to do with the blob chunk...
    *process  :xblobvar
    offset = chunksize * ntimes .
    enddo.
    bye
    yk

  • Accessinng Table using Native SQL in ABAP Program

    Hi Experts,
    I need to access a table that is created in Oracle.
    But while writing a select query as below:
      EXEC sql.
       SELECT MAX(ID_EVENTO)
         INTO :LV_ID_EVENTO
         FROM ZTAB.
      ENDEXEC.
    I am getting a dump saying "ZTAB doesnot exist" or IF I use ZTAB@ifsap then it dumps saying "Database name is missing a component".
    Do I need to add some suffix to the table name like @ifsap to ZTAB?
    Also, can I use SY-SUBRC to check to the success and failure for SELECTION OR INSERTION Operation?
    Thanks
    Depesh

    Hello,
    Try using SAP<SID>.ZTAB in your query.
    For example SAPC05.ZTAB
    Regards,
    Yoganand.V

  • Are there any risks to use native sql in ABAP to access external DB

    here is a requirement to use native sql in abap program to access external DB to load some data into sap. Are there any risks and effects which SAP not recommend ?
    Can anybody show some official document to me because I want to know some risks and dangerous to report to my manager..thanks very much.

    hi Anversha s 
    thank you for your reply
    I means what's the risk when to use native sql to access external DB..
    can you show me some examples about open sql which is used to access external DB...
    Now I am investigating the technique about the connection
    between SAP (by abap program) and external DB...the supporter suggestion is to use native sql to access external DBs.but my manager is afraid of the risks when to use native sql,So I have to report the effective document (example: SAP official document) to explain  to my manager.
    thanks very much

  • How to execute an SQL query present in a string inside an ABAP program?

    hello,
    How to execute an SQL query present in a string inside an ABAP program

    Raut,
    You can execute Native SQl statements.
    Ex: To use a Native SQL statement, you must precede it with the EXEC SQL statement, and follow it with the ENDEXEC statement as follows:
    EXEC SQL [PERFORMING <form>].
      <Native SQL statement>
    ENDEXEC.
    There is no period after Native SQL statements. Furthermore, using inverted commas (") or an asterisk (*) at the beginning of a line in a native SQL statement does not introduce a comment as it would in normal ABAP syntax. You need to know whether table and field names are case-sensitive in your chosen database.
    In Native SQL statements, the data is transported between the database table and the ABAP program using host variables. These are declared in the ABAP program, and preceded in the Native SQL statement by a colon (:). You can use elementary structures as host variables. Exceptionally, structures in an INTO clause are treated as though all of their fields were listed individually.
    If the selection in a Native SQL SELECT statement is a table, you can pass it to ABAP line by line using the PERFORMING addition. The program calls a subroutine <form> for each line read. You can process the data further within the subroutine.
    As in Open SQL, after the ENDEXEC statement, SY-DBCNT contains the number of lines processed. In nearly all cases, SY-SUBRC contains the value 0 after the ENDEXEC statement. Cursor operations form an exception: After FETCH, SY-SUBRC is 4 if no more records could be read. This also applies when you read a result set using EXEC SQL PERFORMING.
    EXEC SQL PERFORMING loop_output.
      SELECT connid, cityfrom, cityto
      INTO   :wa
      FROM   spfli
      WHERE  carrid = :c1
    ENDEXEC.
    Pls. Mark If useful

  • Is it possible to reset password for any user using abap program

    Hi friends,
    Is it possible to reset password for any user using abap program by specifying client number and user id. in selection screen.
    if any code for that to reset password please mail me.
    Thanks & Regards,
    Yogesh

    Hello Yogesh,
    Yes you can reset the password for any body using ABAP Code. But for that you really don't need any client number.
    If this process is on regular basis, then recommended is to use BAPI for changing the user details Otherwise BDC also works fine.
    => Function Module - BAPI_USER_CHANGE
    Call this in the program for resetting the password.
    => CALL TRANSACTION 'SU01' USING InternalTable
    This will be executed in the BDC of SU01 transaction recording. Use the Password Change button in the application toolbar of transaction while recording.
    Hope this helps.
    PS If the answer solves your query, plz close the thread by marking it solved and rewarding each reply.
    Regards

  • How to execute this SQL Query in ABAP Program.

    Hi,
    I have a string which is the SQL Query.
    How to execute this sql Query (SQL_STR) in ABAP Program.
    Code:-
    DATA: SQL_STR type string.
    SQL_STR = 'select * from spfli.'.
    Thanks in Advance,
    Vinay

    Hi Vinay
    Here is a sample to dynamically generate a subroutine-pool having your SQL and calling it.
    REPORT dynamic_sql_example .
    DATA: BEGIN OF gt_itab OCCURS 1 ,
    line(80) TYPE c ,
    END OF gt_itab .
    DATA gt_restab TYPE .... .
    DATA gv_name(30) TYPE c .
    DATA gv_err(120) TYPE c .
    START-OF-SELECTION .
    gt_itab-line = 'REPORT generated_sql .' .
    APPEND gt_itab .
    gt_itab-line = 'FORM exec_sql CHANGING et_table . ' .
    APPEND gt_itab .
    gt_itab-line = SQL_STR .
    APPEND gt_itab .
    gt_itab-line = 'ENDFORM.' .
    APPEND gt_itab .
    GENERATE SUBROUTINE POOL gt_itab NAME gv_name MESSAGE gv_err .
    PERFORM exec_sql IN PROGRAM (gv_name) CHANGING gt_restab
    IF FOUND .
    WRITE:/ gv_err .
    LOOP AT gt_result .
    WRITE:/ .... .
    ENDLOOP .
    *--Serdar

  • Passing data from abap-program to mssql database table thro native sql

    Hi,
    To pass the data from abap-program to mssql server,i have created database connection through dbco t.code.
    now i am trying to get connection thro native sql but am not able to get it .Am working in ECC 5.0.
    Could anyone help me on this.Did i miss anything?
    i have tried Native-sql like this.
    DATA: CON_NAME LIKE DBCON-CON_NAME VALUE 'BIW'.
    EXEC SQL.
      CONNECT TO :con_name AS 'C1'
    ENDEXEC.
    Thanks in advance.

    Hi,
    Trying to do the same here, only using Oracle DB.
    DATA:     dbc TYPE DBCON_NAME VALUE 'BI'
    TRY.
      EXEC SQL.
        CONNECT TO :dbc
      ENDEXEC.
      IF sy-subrc NE 0.
        RAISE EXCEPTION TYPE cx_sy_native_sql_error.
      ENDIF.
    CATCH cx_sy_native_sql_error INTO oref_native_sql_error.
      sql_emsg = oref_native_sql_error->get_text( ).
      MESSAGE sql_emsg TYPE 'I'.
    ENDTRY.
    I keep getting the message 'Native SQL exception has occured' (because of the RAISE statement, I wonder how we can get a meaningfull error description).
    Of course this can be a result of a number of network issues, so I'm trying to resolve this together with my BC admin.
    I suggest the same to you..
    In the meantime, if anyone can help out, it will be appreciated.
    Regards,
    SD

  • Performance of ABAP program

    How do you take care of performance issues in your abap programs?

    HI
    and you can see this also
    Ways of Performance Tuning
    1.     Selection Criteria
    2.     Select Statements
    •     Select Queries
    •     SQL Interface
    •     Aggregate Functions
    •     For all Entries
    Select Over more than one Internal table
    Selection Criteria
    1.     Restrict the data to the selection criteria itself, rather than filtering it out using the ABAP code using CHECK statement. 
    2.     Select with selection list.
    Points # 1/2
    SELECT * FROM SBOOK INTO SBOOK_WA.
      CHECK: SBOOK_WA-CARRID = 'LH' AND
             SBOOK_WA-CONNID = '0400'.
    ENDSELECT.
    The above code can be much more optimized by the code written below which avoids CHECK, selects with selection list
    SELECT  CARRID CONNID FLDATE BOOKID FROM SBOOK INTO TABLE T_SBOOK
      WHERE SBOOK_WA-CARRID = 'LH' AND
                  SBOOK_WA-CONNID = '0400'.
    Select Statements   Select Queries
    1.     Avoid nested selects
    2.     Select all the records in a single shot using into table clause of select statement rather than to use Append statements.
    3.     When a base table has multiple indices, the where clause should be in the order of the index, either a primary or a secondary index.
    4.     For testing existence , use Select.. Up to 1 rows statement instead of a Select-Endselect-loop with an Exit. 
    5.     Use Select Single if all primary key fields are supplied in the Where condition .
    Point # 1
    SELECT * FROM EKKO INTO EKKO_WA.
      SELECT * FROM EKAN INTO EKAN_WA
          WHERE EBELN = EKKO_WA-EBELN.
      ENDSELECT.
    ENDSELECT.
    The above code can be much more optimized by the code written below.
    SELECT PF1 PF2 FF3 FF4 INTO TABLE ITAB
        FROM EKKO AS P INNER JOIN EKAN AS F
          ON PEBELN = FEBELN.
    Note: A simple SELECT loop is a single database access whose result is passed to the ABAP program line by line. Nested SELECT loops mean that the number of accesses in the inner loop is multiplied by the number of accesses in the outer loop. One should therefore use nested SELECT loops  only if the selection in the outer loop contains very few lines or the outer loop is a SELECT SINGLE statement.
    Point # 2
    SELECT * FROM SBOOK INTO SBOOK_WA.
      CHECK: SBOOK_WA-CARRID = 'LH' AND
             SBOOK_WA-CONNID = '0400'.
    ENDSELECT.
    The above code can be much more optimized by the code written below which avoids CHECK, selects with selection list and puts the data in one shot using into table
    SELECT  CARRID CONNID FLDATE BOOKID FROM SBOOK INTO TABLE T_SBOOK
      WHERE SBOOK_WA-CARRID = 'LH' AND
                  SBOOK_WA-CONNID = '0400'.
    Point # 3
    To choose an index, the optimizer checks the field names specified in the where clause and then uses an index that has the same order of the fields . In certain scenarios, it is advisable to check whether a new index can speed up the performance of a program. This will come handy in programs that access data from the finance tables.
    Point # 4
    SELECT * FROM SBOOK INTO SBOOK_WA
      UP TO 1 ROWS
      WHERE CARRID = 'LH'.
    ENDSELECT.
    The above code is more optimized as compared to the code mentioned below for testing existence of a record.
    SELECT * FROM SBOOK INTO SBOOK_WA
        WHERE CARRID = 'LH'.
      EXIT.
    ENDSELECT.
    Point # 5
    If all primary key fields are supplied in the Where condition you can even use Select Single.
    Select Single requires one communication with the database system, whereas Select-Endselect needs two.
    Select Statements           contd..  SQL Interface
    1.     Use column updates instead of single-row updates
    to update your database tables.
    2.     For all frequently used Select statements, try to use an index.
    3.     Using buffered tables improves the performance considerably.
    Point # 1
    SELECT * FROM SFLIGHT INTO SFLIGHT_WA.
      SFLIGHT_WA-SEATSOCC =
        SFLIGHT_WA-SEATSOCC - 1.
      UPDATE SFLIGHT FROM SFLIGHT_WA.
    ENDSELECT.
    The above mentioned code can be more optimized by using the following code
    UPDATE SFLIGHT
           SET SEATSOCC = SEATSOCC - 1.
    Point # 2
    SELECT * FROM SBOOK CLIENT SPECIFIED INTO SBOOK_WA
      WHERE CARRID = 'LH'
        AND CONNID = '0400'.
    ENDSELECT.
    The above mentioned code can be more optimized by using the following code
    SELECT * FROM SBOOK CLIENT SPECIFIED INTO SBOOK_WA
      WHERE MANDT IN ( SELECT MANDT FROM T000 )
        AND CARRID = 'LH'
        AND CONNID = '0400'.
    ENDSELECT.
    Point # 3
    Bypassing the buffer increases the network considerably
    SELECT SINGLE * FROM T100 INTO T100_WA
      BYPASSING BUFFER
      WHERE     SPRSL = 'D'
            AND ARBGB = '00'
            AND MSGNR = '999'.
    The above mentioned code can be more optimized by using the following code
    SELECT SINGLE * FROM T100  INTO T100_WA
      WHERE     SPRSL = 'D'
            AND ARBGB = '00'
            AND MSGNR = '999'.
    Select Statements       contd…           Aggregate Functions
    •     If you want to find the maximum, minimum, sum and average value or the count of a database column, use a select list with aggregate functions instead of computing the aggregates yourself.
    Some of the Aggregate functions allowed in SAP are  MAX, MIN, AVG, SUM, COUNT, COUNT( * )
    Consider the following extract.
                Maxno = 0.
                Select * from zflight where airln = ‘LF’ and cntry = ‘IN’.
                 Check zflight-fligh > maxno.
                 Maxno = zflight-fligh.
                Endselect.
    The  above mentioned code can be much more optimized by using the following code.
    Select max( fligh ) from zflight into maxno where airln = ‘LF’ and cntry = ‘IN’.
    Select Statements    contd…For All Entries
    •     The for all entries creates a where clause, where all the entries in the driver table are combined with OR. If the number of entries in the driver table is larger than rsdb/max_blocking_factor, several similar SQL statements are executed to limit the length of the WHERE clause.
         The plus
    •     Large amount of data
    •     Mixing processing and reading of data
    •     Fast internal reprocessing of data
    •     Fast
         The Minus
    •     Difficult to program/understand
    •     Memory could be critical (use FREE or PACKAGE size)
    Points to be must considered FOR ALL ENTRIES
    •     Check that data is present in the driver table
    •     Sorting the driver table
    •     Removing duplicates from the driver table
    Consider the following piece of extract
    Loop at int_cntry.
           Select single * from zfligh into int_fligh
    where cntry = int_cntry-cntry.
    Append int_fligh.
    Endloop.
    The above mentioned can be more optimized by using the following code.
    Sort int_cntry by cntry.
    Delete adjacent duplicates from int_cntry.
    If NOT int_cntry[] is INITIAL.
                Select * from zfligh appending table int_fligh
                For all entries in int_cntry
                Where cntry = int_cntry-cntry.
    Endif.
    Select Statements    contd…  Select Over more than one Internal table
    1.     Its better to use a views instead of nested Select statements.
    2.     To read data from several logically connected tables use a join instead of nested Select statements. Joins are preferred only if all the primary key are available in WHERE clause for the tables that are joined. If the primary keys are not provided in join the Joining of tables itself takes time.
    3.     Instead of using nested Select loops it is often better to use subqueries.
    Point # 1
    SELECT * FROM DD01L INTO DD01L_WA
      WHERE DOMNAME LIKE 'CHAR%'
            AND AS4LOCAL = 'A'.
      SELECT SINGLE * FROM DD01T INTO DD01T_WA
        WHERE   DOMNAME    = DD01L_WA-DOMNAME
            AND AS4LOCAL   = 'A'
            AND AS4VERS    = DD01L_WA-AS4VERS
            AND DDLANGUAGE = SY-LANGU.
    ENDSELECT.
    The above code can be more optimized by extracting all the data from view DD01V_WA
    SELECT * FROM DD01V INTO  DD01V_WA
      WHERE DOMNAME LIKE 'CHAR%'
            AND DDLANGUAGE = SY-LANGU.
    ENDSELECT
    Point # 2
    SELECT * FROM EKKO INTO EKKO_WA.
      SELECT * FROM EKAN INTO EKAN_WA
          WHERE EBELN = EKKO_WA-EBELN.
      ENDSELECT.
    ENDSELECT.
    The above code can be much more optimized by the code written below.
    SELECT PF1 PF2 FF3 FF4 INTO TABLE ITAB
        FROM EKKO AS P INNER JOIN EKAN AS F
          ON PEBELN = FEBELN.
    Point # 3
    SELECT * FROM SPFLI
      INTO TABLE T_SPFLI
      WHERE CITYFROM = 'FRANKFURT'
        AND CITYTO = 'NEW YORK'.
    SELECT * FROM SFLIGHT AS F
        INTO SFLIGHT_WA
        FOR ALL ENTRIES IN T_SPFLI
        WHERE SEATSOCC < F~SEATSMAX
          AND CARRID = T_SPFLI-CARRID
          AND CONNID = T_SPFLI-CONNID
          AND FLDATE BETWEEN '19990101' AND '19990331'.
    ENDSELECT.
    The above mentioned code can be even more optimized by using subqueries instead of for all entries.
    SELECT * FROM SFLIGHT AS F INTO SFLIGHT_WA
        WHERE SEATSOCC < F~SEATSMAX
          AND EXISTS ( SELECT * FROM SPFLI
                         WHERE CARRID = F~CARRID
                           AND CONNID = F~CONNID
                           AND CITYFROM = 'FRANKFURT'
                           AND CITYTO = 'NEW YORK' )
          AND FLDATE BETWEEN '19990101' AND '19990331'.
    ENDSELECT.
    1.     Table operations should be done using explicit work areas rather than via header lines.
    2.     Always try to use binary search instead of linear search. But don’t forget to sort your internal table before that.
    3.     A dynamic key access is slower than a static one, since the key specification must be evaluated at runtime.
    4.     A binary search using secondary index takes considerably less time.
    5.     LOOP ... WHERE is faster than LOOP/CHECK because LOOP ... WHERE evaluates the specified condition internally.
    6.     Modifying selected components using “ MODIFY itab …TRANSPORTING f1 f2.. “ accelerates the task of updating  a line of an internal table.
    Point # 2
    READ TABLE ITAB INTO WA WITH KEY K = 'X‘ BINARY SEARCH.
    IS MUCH FASTER THAN USING
    READ TABLE ITAB INTO WA WITH KEY K = 'X'.
    If TAB has n entries, linear search runs in O( n ) time, whereas binary search takes only O( log2( n ) ).
    Point # 3
    READ TABLE ITAB INTO WA WITH KEY K = 'X'. IS FASTER THAN USING
    READ TABLE ITAB INTO WA WITH KEY (NAME) = 'X'.
    Point # 5
    LOOP AT ITAB INTO WA WHERE K = 'X'.
    ENDLOOP.
    The above code is much faster than using
    LOOP AT ITAB INTO WA.
      CHECK WA-K = 'X'.
    ENDLOOP.
    Point # 6
    WA-DATE = SY-DATUM.
    MODIFY ITAB FROM WA INDEX 1 TRANSPORTING DATE.
    The above code is more optimized as compared to
    WA-DATE = SY-DATUM.
    MODIFY ITAB FROM WA INDEX 1.
    7.     Accessing the table entries directly in a "LOOP ... ASSIGNING ..." accelerates the task of updating a set of lines of an internal table considerably
    8.    If collect semantics is required, it is always better to use to COLLECT rather than READ BINARY and then ADD.
    9.    "APPEND LINES OF itab1 TO itab2" accelerates the task of appending a table to another table considerably as compared to “ LOOP-APPEND-ENDLOOP.”
    10.   “DELETE ADJACENT DUPLICATES“ accelerates the task of deleting duplicate entries considerably as compared to “ READ-LOOP-DELETE-ENDLOOP”.
    11.   "DELETE itab FROM ... TO ..." accelerates the task of deleting a sequence of lines considerably as compared to “  DO -DELETE-ENDDO”.
    Point # 7
    Modifying selected components only makes the program faster as compared to Modifying all lines completely.
    e.g,
    LOOP AT ITAB ASSIGNING <WA>.
      I = SY-TABIX MOD 2.
      IF I = 0.
        <WA>-FLAG = 'X'.
      ENDIF.
    ENDLOOP.
    The above code works faster as compared to
    LOOP AT ITAB INTO WA.
      I = SY-TABIX MOD 2.
      IF I = 0.
        WA-FLAG = 'X'.
        MODIFY ITAB FROM WA.
      ENDIF.
    ENDLOOP.
    Point # 8
    LOOP AT ITAB1 INTO WA1.
      READ TABLE ITAB2 INTO WA2 WITH KEY K = WA1-K BINARY SEARCH.
      IF SY-SUBRC = 0.
        ADD: WA1-VAL1 TO WA2-VAL1,
             WA1-VAL2 TO WA2-VAL2.
        MODIFY ITAB2 FROM WA2 INDEX SY-TABIX TRANSPORTING VAL1 VAL2.
      ELSE.
        INSERT WA1 INTO ITAB2 INDEX SY-TABIX.
      ENDIF.
    ENDLOOP.
    The above code uses BINARY SEARCH for collect semantics. READ BINARY runs in O( log2(n) ) time. The above piece of code can be more optimized by
    LOOP AT ITAB1 INTO WA.
      COLLECT WA INTO ITAB2.
    ENDLOOP.
    SORT ITAB2 BY K.
    COLLECT, however, uses a hash algorithm and is therefore independent
    of the number of entries (i.e. O(1)) .
    Point # 9
    APPEND LINES OF ITAB1 TO ITAB2.
    This is more optimized as compared to
    LOOP AT ITAB1 INTO WA.
      APPEND WA TO ITAB2.
    ENDLOOP.
    Point # 10
    DELETE ADJACENT DUPLICATES FROM ITAB COMPARING K.
    This is much more optimized as compared to
    READ TABLE ITAB INDEX 1 INTO PREV_LINE.
    LOOP AT ITAB FROM 2 INTO WA.
      IF WA = PREV_LINE.
        DELETE ITAB.
      ELSE.
        PREV_LINE = WA.
      ENDIF.
    ENDLOOP.
    Point # 11
    DELETE ITAB FROM 450 TO 550.
    This is much more optimized as compared to
    DO 101 TIMES.
      DELETE ITAB INDEX 450.
    ENDDO.
    12.   Copying internal tables by using “ITAB2[ ] = ITAB1[ ]” as compared to “LOOP-APPEND-ENDLOOP”.
    13.   Specify the sort key as restrictively as possible to run the program faster.
    Point # 12
    ITAB2[] = ITAB1[].
    This is much more optimized as compared to
    REFRESH ITAB2.
    LOOP AT ITAB1 INTO WA.
      APPEND WA TO ITAB2.
    ENDLOOP.
    Point # 13
    “SORT ITAB BY K.” makes the program runs faster as compared to “SORT ITAB.”
    Internal Tables         contd…
    Hashed and Sorted tables
    1.     For single read access hashed tables are more optimized as compared to sorted tables.
    2.      For partial sequential access sorted tables are more optimized as compared to hashed tables
    Hashed And Sorted Tables
    Point # 1
    Consider the following example where HTAB is a hashed table and STAB is a sorted table
    DO 250 TIMES.
      N = 4 * SY-INDEX.
      READ TABLE HTAB INTO WA WITH TABLE KEY K = N.
      IF SY-SUBRC = 0.
      ENDIF.
    ENDDO.
    This runs faster for single read access as compared to the following same code for sorted table
    DO 250 TIMES.
      N = 4 * SY-INDEX.
      READ TABLE STAB INTO WA WITH TABLE KEY K = N.
      IF SY-SUBRC = 0.
      ENDIF.
    ENDDO.
    Point # 2
    Similarly for Partial Sequential access the STAB runs faster as compared to HTAB
    LOOP AT STAB INTO WA WHERE K = SUBKEY.
    ENDLOOP.
    This runs faster as compared to
    LOOP AT HTAB INTO WA WHERE K = SUBKEY.
    ENDLOOP.

  • Oracle Query From ABAP Program

    Hello everybody,
    I have a doubt about if I can do a Query to a External Oracle Database to get some records and then process them in my ABAP Program, is this possible?, if this is the case can anyone help me with some documentation, thanks in advance for your answers.
    Regards,
    Julio

    Hi Julio,
    you can use the open SQL connect statement
    EXEC SQL.
      CONNECT TO dbs [AS con]
    ENDEXEC.
    or even you can define the DB in the FROM with the option CONNECTION
    ... FROM { {dbtab [AS tabalias]}
             | join
             | {(dbtab_syntax) [AS tabalias]} }
             [UP TO n ROWS]
             [CLIENT SPECIFIED]
             [BYPASSING BUFFER]
             [CONNECTION {con|(con_syntax)}] ... .
    Hope it helps,
    Edgar

  • Abap program standards

    hi all,
         i need to design flow chart for checking for a program whether it satifies the abap coding standards or not. who to do it. if possible send me graphical representations [flow charts]  or links to find programming standards.
    some of my requirements in that folw chart are
      1. how to recognize a blank space in a given program,
      2. how to recognize a comment,
      3. how to check wheteher a keyword is used or not,
      4. how to identify the ' :' symbol
    thanks & regards,
    suresh babu aluri.

    plz go through this documementaion,
    i think its helpful.
    ABAP Programming StandardsContents
    1.     Objective     5
    2.     Naming Conventions     5
    2.1     Codes for naming conventions     5
    2.1.1     Module Codes     5
    2.1.2     Free text     6
    2.2     Naming Convention of Development Objects     6
    2.2.1     Package     6
    2.2.2     Executable Program     6
    2.2.3     BSP Application     7
    2.2.4     Logical Database     8
    2.2.5     SAP Scripts /Smartforms     9
    2.2.6     Idocs     9
    2.2.7     Transaction Code     10
    2.2.8     Function Groups     10
    2.2.9     Dictionary Objects     11
    2.2.10     Message Class     11
    2.2.11     Enhancement Projects (User Exits)     11
    2.2.12     LSMW Objects     12
    2.2.13     Classes     12
    2.2.14     BOR Object Types     13
    2.2.15     Screen / Transaction Variants     13
    2.2.16     Area Menu     13
    2.3     Naming of Sub-Objects     13
    2.3.1     Program Sub-Objects     13
    2.3.2     SAP Script /Smartform sub-objects     14
    3.     General Programming Guidelines     14
    3.1     Modification Logs     14
    3.2     Program Organization     15
    3.2.1     Executable Programs     15
    3.2.2     Dialog Programs     15
    3.3     Package     15
    3.3.1     Adding Components to existing objects     15
    3.3.2     Creation of New Objects     15
    3.4     Program Messages     15
    3.4.1     Adding Messages to existing landscapes     15
    3.4.2     Creation of New Objects     16
    3.5     Dictionary Objects     16
    4.     Structure of ABAP Programs     16
    4.1     Type     16
    4.2     Status     18
    4.3     Authority Check     18
    4.4     Program Structure     19
    4.4.1     Declaration data for global data, classes and selection screens     19
    4.4.2     Container for Processing Blocks     19
    4.4.3     Calling Processing Blocks     20
    4.5     Screen Flow Logic (Dialog Programs)     20
    4.5.1     Place the AT EXIT COMMAND at the beginning of the flow logic.     20
    4.5.2     Use FIELD and CHAIN statements to keep fields in error open for correction.     20
    4.6     Main Program     20
    4.6.1     Events     20
    5.     General Coding Standards     21
    5.1     One command per line     21
    5.2     Indented Source Code     21
    5.3     Extended Syntax Check     21
    5.4     Reusability and Modularity     21
    5.5     Text Handling     21
    5.6     Usage of System Variables     22
    5.7     Chaining Statements     22
    5.8     Common Routines     22
    5.9     Dialog Messages     22
    5.10     Function Keys     23
    5.11     Enqueuing and Dequeuing Data Objects     23
    5.12     Error Handling (SY-SUBRC)     23
    5.13     General Conventions and Hints     24
    5.14     Parameters in Sub-Routines     24
    6.     Performance Standards     25
    6.1     General Tips on Performance Tuning     25
    6.1.1     Avoid Redundant code     25
    6.1.2     Subroutine Usage     25
    6.1.3     Case vs. Nested IF     25
    6.1.4     Using the MOVE Statement     25
    6.1.5     SELECT Queries     25
    6.1.6     Using the READ statement     27
    6.1.7     Hashed table     27
    6.1.8     Transporting     28
    6.1.9     Using LDB     28
    6.1.10     Append Lines of     28
    6.1.11     Use WHILE     28
    6.1.12     DELETE <itab> WHERE     28
    6.1.13     Using WHERE clause in LOOP…….ENDLOOP     28
    1.     Objective
    The objective of this document is to describe general programming guidelines, methodologies, Naming conventions and performance guidelines for all the programs developed for SAP Project.
    2.     Naming Conventions
    This chapter describes the naming conventions to be followed for naming the programming objects for SAP project.
    2.1      Codes for naming conventions
    The variable portion of naming convention is given with Code ID given in angle brackets(<>). Use the following tables for replacing code IDs with codes in the object naming.
    2.1.1     Module Codes
    Code ID:  mm
    Code     Description
    FI     Finance
    CO     Controlling Module
    MM     Materials Management
    PP      Production Planning
    SD     Sales & Distribution
    QM      Quality Management
    PM     Plant Maintenance
    IM     Inventory Management
    WM     Warehouse Management
    BC     Basis Module
    BW     Business Warehouse
    WF     Workflows (Master Data Management)
    HR     Human Resources
    EBP     EBP
    PS     Project Systems
    PCP     Synpro: Product Costing
    PAP     Synpro: COPA
    DP     APO :  Demand Planning
    SP     APO :  Supply Network Planning
    DS      APO : Production Planning & Detailed Scheduling
    AT     APO : Global ATP
    TP     APO : Transportation Planning/Vehicle Scheduling
    CI     Core Interface
    LC     Live Cache
    2.1.2     Free text
    Code ID: ffff
    Developer should replace ‘ffff’ with meaningful text. The text can be multiple words separated by underscore.
    2.2     Naming Convention of Development Objects
    2.2.1     Package
    Naming Convention: Z<mm>_<ffff>.
    Notes:
    1.     Replace <mm> with Module codes given in section 2.1.1 above.
    2.     Replace <ffff> with the sub-landscape of the Module that this Message Class caters to as illustrated in examples below.
    3.     The maximum permissible length for development class is 30 characters
    Examples:
    Dev. Class     Description
    ZFI_AR     FI: Account Receivables
    ZCO_CCA     CO: Cost Center Accounting
    2.2.2     Executable Program
    Naming Convention: Z<mm>_<ffff>.
    Notes:
    1.     Replace <mm> with module codes given in section 2.1.1 above.
    2.     Replace <ffff> with meaningful text as illustrated in examples below.
    3.     The maximum permissible length for program name is 30 characters. However, the name should be restricted to 25 characters to accommodate appropriate Include naming as described in 2.2.2.
    Examples:
    Program Name     Description
    ZFI_VAT_RET     FI:  Report for VAT Return
    ZMM_AUTO_GR     MM: Automated Goods Receipt
    ZSD_XX_STCK_SHORTAGE     SD: Stock shortage report for stock allocation
    2.2.2.1     Includes for executable programs
    Naming Convention: Z<mm>_<ffff>_<Inn>.
    Notes:
    1.     All includes of executable program will be prefixed by Z, followed by the same program name as described in 2.2.2 above.
    2.     Replace <Inn> with include type and sequence number. Use the following table for includes.
    Include Type ID     Description
    TOP     Top Include.
    Fnn     Subroutine pool (Forms)
    Inn     PAI Modules
    Onn     PBO Modules
    Xnn     Other Includes
    The maximum permissible length for Include name is 30 characters.
    Examples:
    Include Name     Main Program Name     Description
    ZFI_VAT_RET_TOP     ZFI_VAT_RET     FI:  Report for VAT Return – Top Include
    ZFI_VAT_RET_F01     ZFI_VAT_RET     FI:  Report for VAT Return – Forms
    ZMM_AUTO_GR_TOP     ZMM_FR_AUTO_GR     MM: – Automated Goods Receipt – Top include
    ZMM_AUTO_GR_F01     ZMM_FR_AUTO_GR     MM:– Automated Goods Receipt – Forms
    2.2.3     BSP Application
    2.2.3.1     Main Application
    Naming Convention: BSP Applications shall follow the same Naming Convention as Executable Programs i.e. Z<mm>_<ffff>.
    Notes:
    1.     Replace <mm> with module codes given in section 2.1.1 above.
    2.     Replace <ffff> with meaningful text as illustrated in examples below.
    2.2.3.2     Pages & Controllers
    Naming Convention: <ffff>
    Notes:
    1.     Replace <ffff> with meaningful text, that adequately describes the function of the page/controller
    2.2.3.3     Theme
    Naming Convention: Z_<ffff>.
    Notes:
    1.     Replace <ffff> with meaningful text
    2.2.3.4     Mime Objects:
    Naming Convention: <ffff>
    1.     A MIME Object can be logo for the company.
    2.     Replace <ffff> with meaningful text, that adequately describes the function of the MIME objects
    2.2.3.5     Controller and Handler Classes:
    See section Classes (Section 2.2.133)
    2.2.3.6     BSP Extension
    Naming Convention: Z_<ffff>
    Notes:
    1.     Replace <ffff> with meaningful text
    2.2.3.7     BSP Layout elements id
    Label:     lb_fffff
    Input field:     if_fffff
    Button:     b_fffff
    Text Edit:     te_fffff
    Text View:     tv_fffff
    Radio button Group:     rbg_fffff
    Radio button:     rb_fffff
    Check Box Group:     cbg_fffff
    Check Box     cb_fffff
    Tray     tr_fffff
    Tabstrip     ts_fffff
    Tableview      tab_fffff
    1.  Replace <fffff> with meaningful text
    2.2.4     Logical Database
    Naming Convention: Z<mm>_<ffff>.
    Notes:
    1.     Replace <mm> with module codes given in section 2.1.1 above.
    2.     Replace <ffff> with meaningful text
    3.     The maximum permissible length for LDB name is 20 characters. However, the name should be restricted to 15 characters to accommodate appropriate Include naming
    4.     LDB Program and LDB Program Includes shall follow the naming convention Auto-Generated by SAP
    2.2.5     SAP Scripts /Smartforms
    Naming Convention: ZF<mm>_<ffff>.
    Notes:
    1.     Replace <mm> with module codes given in section 2.1.1 above.
    2.     Replace <ffff> with meaningful text as illustrated in examples below.
    Examples:
    Form Name     Description
    ZFFI_EMP_CONF     Employee Confirmation Letter
    ZFFI_ANN_TO     Annual Turnover Letter To Customers and Vendors
    2.2.6     Idocs
    2.2.6.1     Idoc Types
    Basic Type :
    Naming Convention : ZB<FFFF>NN
    Notes:
    1.Replace <NN> with sequence number.
    3.     Replace <ffff> with meaningful text.
    Extension Type : ZX<Basic type name>_NN
    Notes:
    1.     Replace <NN> with sequence number .
    2.2.6.2     Message Types
    Naming Convention :  ZM<mm><ffff>.
    Notes :
    1.   Replace <mm> with module codes given in section 2.1.1 above.
    2.  Replace <ffff> with meaningful text .
    2.2.6.3      Process Code
    Naming Convention :  Z<ffff>.
    Notes :
    1.     Replace <ffff> with meaningful text ..
    2.2.6.4     IDOC Segments
    Naming Convention :  Z1<ffff>.
    Notes :
    1.Replace <ffff> with meaningful text as illustrated in examples below.
    2.2.7     Transaction Code
    Notes:
    1.     The tcode name is provided by SAP TIN The Developer must write a mail to SAP Tin asking for the T-Code name with a filled form.
    The form can be found at :
    2.2.8     Function Groups
    Naming Convention: Z<mm><ffff>
    Notes:
    1.     Replace <mm> with relevant module code as given above
    2.     Replace <ffff> with meaningful text.
    2.2.8.1     Function Group Include Programs
    Naming Convention: LZ<Function Group><Inn>.
    Notes:
    1.     All includes of Function Group program will be prefixed by LZ, followed by the Function Group name
    2.     Replace <Inn> with include type and sequence number. Use the values from the table given in 2.2.2.1
    Examples:
    Include Name     Function Group Name     Description
    SAPLZMMPURCHASING     ZMMPURCHASING     F.Group-Purchasing: Main Program
    LZMMPURCHASINGO01     ZMMPURCHASING     F.Group-Purchasing: PBO
    LZMMPURCHASINGI01     ZMMPURCHASING     F.Group-Purchasing: PAI
    LZMMPURCHASINGF01     ZMMPURCHASING     F.Group-Purchasing: Forms
    LZMMPURCHASINGTOP     ZMMPURCHASING     F.Group-Purchasing: Data Declarations
    2.2.8.2     Function Modules
    2.2.8.2.1     Normal Function Modules
    Convention: Z_<mm>_<ffff>.
    Notes:
    1.     Replace <mm> with relevant module code as given above.
    2.     Replace <ffff> with meaningful text.
    2.2.8.2.2     IDOC Function Modules
    Convention: Z_IDOC_<mode>_<msg type>.
    Notes:
    1.     Replace <mode> with INPUT or OUTPUT depending on whether the function processes incoming or outgoing IDOC.
    2.     Replace <msg type> with the IDOC message type.
    2.2.9     Dictionary Objects
    Tables:      Z<mm><ffff>
    Structures:      ZS<mm><ffff>
    Views:      ZV<mm><ffff>
    Data Element:      ZDE<mm><ffff>
    Domain:      ZDO<mm><ffff>
    Table Type:      ZTT<mm><ffff>
    Type Group:      Z<ffff>
    Search Help:      ZSH<mm><ffff>
    Lock Object:      EZ<mm><ffff>
    Notes:
    1.     Replace <mm> with module code given above.
    2.     Replace <ffff> with meaningful text.
    2.2.10     Message Class
    Naming Convention: Z<mm>_<ffff>.
    Notes:
    1.     Replace <mm> with Module codes given in section 2.1.1 above.
    2.     Replace <ffff> with the sub-landscape of the Module that this Message Class caters to as illustrated in examples below.
    3.     The maximum permissible length for development class is 30 characters
    Examples:
    Msg. Class     Description
    ZFI_AR     FI: Account Receivables
    ZCO_CCA     CO: Cost Center Accounting
    2.2.11     Enhancement Projects (User Exits)
    Convention: Z<XX><nn>.
    Notes:
    1.     XX is the application area code e.g. for sales it is SD etc.
    2.     'nn'  is one up number for one application area. It starts with 001.
    3.     Maximum length of the Project name is 8.
    Example:  The name of the SD enhancement project can be ZSD001.
    2.2.12     LSMW Objects
    2.2.12.1     Project
    Naming Convention: ZM_<ffff>.
    Notes:
    1.     1.     Replace <ffff> with meaningful text
    2.     The maximum permissible length for Project name is 16 characters. But please limit it to 12.
    Example : ZM_VENDOR
    2.2.12.2     SubProject
    Naming Convention: ZM_<ffff>_<n>.
    Notes:
         Suffix Project name with a running sequence no.
    Example : ZM_VENDOR_1
    2.2.12.3     Object
    Naming Convention: ZM_<ffff>_<n><n>.
    Notes:
         Suffix Subproject name with a running sequence no.
    Example : ZM_VENDOR_11
    2.2.13     Classes
    Naming Convention: ZCL_[IM/DF/BSPCO/BSPHN/BADI]_<ffff>.
    1.     IM: Implementation Class;
    DF: Definition Class
    BSPCO: BSP Controller class
    BSPHN: BSP Handler class
    BADI : BADI implementation
    2.     Replace <ffff> with meaningful text: In case of Implementation classes, it should preferably be the same as that of the Definition Class
    3.     Example:
    IMPLEMENTATION Class: ZCL_IM_REBATE_SETTL
    DEFINITION: ZCL_DF_REBATE_SETTL
    2.2.14     BOR Object Types
    Object     Convention     Example
    Supertype     Z<ffff>     ZLVAPPL
    SubType     Z<SuperType><nn>     ZZLVAPPL01
    Program     <Subtype>     ZZLVAPPL01
    1.     Replace <nn> with a running 2 digit serial Number
    2.     Replace <ffff> with meaningful text
    2.2.15     Screen / Transaction Variants
    Naming Convention: <tcode>_<ffff>
    Where:
    1.     Replace <tcode> with the t-code that will be assigned to this Variant
    2.     Replace ffff with a meaningful text
    E.g.:
    For an SE16 variant for table KONA that will be used by T-Code Z_CH_SD_001:
    Z_CH_SD_001_KONA
    2.2.16     Area Menu
    Naming Convention: Z<mm>_<Main Menu>_<Sub Menu>…<ffff>
    Where:
    1.     Replace <mm> with the Module code
    2.     Followed by the hierarchical position of the immediate parent of this Area Menu
    3.     Followed by a Meaningful text for this Menu
    E.g.:
    ZSD
    ZSD_TAB
    ZSD_TAB_VIEW
    ZSD_TAB_UPDT
    Notes:
    1.     Clusters of Transactions should be introduced as Sub-Menus rather than as Folders
    2.     As a gradual process, the current Clusters that exist as Folders should also be replaced with Sub-Menus
    2.3     Naming of Sub-Objects
    2.3.1     Program Sub-Objects
    Naming of all the internal components of a program will be consistent across the project.
    Naming Convention: <Prefix>ffff.
    Notes:
    1.     Replace <Prefix> with the component prefix values given in the table below.
    Program Component     Prefixed by
    Program Constants     C_
    Global Variables     W_
    Types Definition     T_
    Global Structures     WA_
    Global Internal Tables     I_
    Select-Options     SO_
    Parameters     PO_
    Table Type     TT_
    Field Symbols     FS_
    Ranges     R_
    Local Constants     LC_
    Local Variables     L_
    Local Static Variables     LS_
    Local Internal Tables     LI_
    Local Work Area     LWA_
    Local Range     LR_
    Field Groups     FG_
    Container      CO_
    Macro     MA_
    Important: The Same sequence as above must be followed in the Data declaration part of all the ABAP/4 programs.
    2.3.2     SAP Script /Smartform sub-objects
    Naming of all the internal components of a SAPScript/SmartForm shall follow the same convention as for Programs (2.2.2), with the addition of the Field Label on the FRS. E.g. if the FRS has labeled a field for Sales Order Number as Field 27 on the Layout, the variable name should be W_27_VBELN.
    3.     General Programming Guidelines
    3.1     Modification Logs
    At the top of every ABAP Object Modified by a Developer, there should be a Modification Log Every Line Created/Changed by the developer should be Identifiable by the TR Number.
    ABAP Patterns: Following Patterns should be used for Uniform ModLogs:
    Nature of Change     Pattern to Use
    New Development     ZZNEWPROG
    In-Line Logs     ZZLINE
    Modification Logs at the Top of Object     ZZMODLOG
    3.2     Program Organization
    All the programs will be organized as described below.
    3.2.1     Executable Programs
    TOP Include: For global data declarations
    Form Include: For definition of all the FORMs.
    3.2.2     Dialog Programs
    TOP Include: For global data declarations
    Form Include: For definition of all the FORMs.
    PBO Include: Include for PBO Modules
    PAI Include: Include for PAI Modules
    3.3     Package
    All the related objects within a sub-module of SAP will be developed under a single Package.
    3.3.1     Adding Components to existing objects
    When adding new workbench components to existing Objects, the same Package will be used as has been used for the existing Components
    3.3.2     Creation of New Objects
    When creating new Objects or new Sub-lanscapes, Packages used should have the Naming convention as in Section 2 Above
    3.4     Program Messages
    All the messages within a sub-module of SAP will be grouped under a single Message Class.
    3.4.1     Adding Messages to existing landscapes
    When adding new messages for existing Objects, the same Message Class will be used as has been used for the existing Objects
    3.4.2     Creation of New Objects
    When creating new Objects or new Sub-landscapes, Message classes used should have the Naming convention as in Section 2 Above
    3.5     Dictionary Objects
    Whenever you create a Z table in  system always include MANDT field as the first field, except when the table contains client independent data. Also create the table with attribute Data Class as USER.
    4.     Structure of ABAP Programs
    4.1     Type
    •     When an ABAP program is run, its processing blocks are called. ABAP programs are controlled from outside the program itself by the processors in the current work process. For the purposes of program flow, we can summarize the screen processor and ABAP processor into the ABAP runtime environment. The runtime environment controls screens and ABAP processing blocks. It contains a range of special control patterns that call screens and processing blocks in certain orders. These sections are also called processors. When a ABAP program is run, the control passes between various processors.
    •     In the R/3 System, there are various types of ABAP program. The program type determines the basic technical attributes of the program, and must be set when created. The main difference between the different program types is the way in which the runtime environment calls its processing blocks.
    •     When an application program is run, it must at least call the first processing block from outside the program, that is, from the runtime environment. This processing block can then either call further processing blocks or return control to the runtime environment. When an ABAP program is started, the runtime environment starts a processor (dependent on the program type), which calls the first ABAP processing block.
    •     The following program types are relevant to application programming:
    Type 1
    •     Type 1 programs have the important characteristic that they do not have to be controlled using user-defined screens. Instead, they are controlled by the runtime environment, which calls a series of processing blocks (and selection screens and lists where necessary) in a fixed sequence. User actions on screens can then trigger further processing blocks.
    Type M
    •     The most important technical attribute of a type M program is that it can only be controlled using screen flow logic and run via a transaction code which is linked to the program and one of its screens (initial screen).
    •     ABAP programs with type M contain the dialog modules belonging to the various screens. They are therefore known as module pools.
    Type F
    •     Type F programs are containers for function modules, and cannot be started using a transaction code or by entering their name directly.
    •     Type F programs are known as function groups. Function modules may only be programmed in function groups. The Function Builder is a tool in the ABAP Workbench that is used to create function groups and function modules. Apart from function modules, function groups can contain global data declarations and subroutines. These are visible to all function modules in the group. They can also contain event blocks for screens in function modules.
    Type K
    •     Type K programs are containers for global classes in ABAP Objects. Type K programs are known as class definitions. The Class Builder is a tool in the ABAP Workbench that can be used to create class definitions.     
    Type J
    •     Type J programs are containers for global interface in ABAP Objects. Type J programs are known as interface definitions and are created in the Class Builder.
    Type I
    •     Type I programs - called includes - are a means of dividing up program code into smaller, more manageable units. The coding of an include program can be inserted at any point in another ABAP program using the INCLUDE statement. There is no technical relationship between include programs and processing blocks. Includes are more suitable for logical programming units, such as data declarations, or sets of similar processing blocks. The ABAP Workbench has a mechanism for automatically dividing up module pools and function groups into include programs.
    4.2     Status
    P = SAP standard production program
    K = Customer production program
    S = System program
    T = Test program
    Application
    •     Categorize the program according to the purpose it fulfills.
    4.3     Authority Check
    Authority checks will be carried out as given in the respective FRS’s.
    4.4     Program Structure
    ABAP programs are responsible for data processing within the individual dialog steps (ie. events) of an application program. This means that the program cannot be constructed as a single sequential unit, but must be divided into sections that can be assigned to the individual dialog steps. To meet this requirement, ABAP programs should have a modular structure. Each module is called a processing block. A processing block consists of a set of ABAP statements. When a program is run, effectively a series of processing blocks is called. Therefore, they should not be nested but modularized.
    •     Each ABAP program consists of the following two parts:
    4.4.1     Declaration data for global data, classes and selection screens
    •     The first part of an ABAP program is the declaration part for global data, classes, and selection screens. This consists of:
    •     All declaration statements for global data. Global data is visible in all internal  processing   blocks and should be defined using declarative statements that appear before the first processing block, in dialog modules, or in event blocks. Local data should not be declared in dialog modules or event blocks.
    •     All selection screen definitions.
    •     All local class definitions (CLASS DEFINITION statement). Local classes are part of ABAP Objects, the object-oriented extension of ABAP.
    •     Declaration statements which occur in procedures (methods, subroutines, function modules) form the declaration part for local data in those processing blocks. This data is only visible within the procedure in which it is declared.
    4.4.2     Container for Processing Blocks
    •     The second part of an ABAP program contains all of the processing blocks for the program. The following types of processing blocks are allowed:
    1.     Dialog modules (no local data area)
    2.     Event blocks (no local data area)
    3.     Procedures (methods, subroutines and function modules with their own local data area).
    •     Whereas dialog modules and procedures are enclosed in the ABAP keywords which define them, event blocks are introduced with event keywords and concluded implicitly by the beginning of the next processing block.
    •     All ABAP statements (except declarative statements in the declaration part of the program) are part of a processing block. Non-declarative ABAP statements, which occur between the declaration of global data and a processing block are automatically assigned to the START-OF-SELECTION processing block.
    4.4.3     Calling Processing Blocks
    •     Processing blocks can be called from either the ABAP program or using ABAP commands which are themselves part of a processing block. Dialog modules and event blocks are called from outside the ABAP program. Procedures are called using ABAP statements in ABAP programs.
    •     Calling event blocks is different from calling other processing blocks for the following reasons:
    •     An event block call is triggered by an event. User actions on selection screens and lists, and the runtime environment trigger events that can be processed in ABAP programs. Define event blocks for the events that the program needs to react to (whereas a subroutine call, for example, must have a corresponding subroutine). This ensures that while an ABAP program may react to a particular event, it is not forced to do so.
    4.5     Screen Flow Logic (Dialog Programs)
    4.5.1     Place the AT EXIT COMMAND at the beginning of the flow logic.
    Example:
    PROCESS AFTER INPUT
       MODULE EXIT_1170 AT EXIT-COMMAND.
       MODULE PAINT_1170.
    4.5.2     Use FIELD and CHAIN statements to keep fields in error open for correction.
    Example:
       PROCESS AFTER INPUT.
       MODULE EXIT_1170 AT EXIT-COMMAND.
       CHAIN.
          FIELD BTCH1170-JOBNAME.
          FIELD BTCH1170-USERNAME.
          FIELD BTCH1170-FROM_DATE.
          FIELD BTCH1170-FROM_TIME.
          MODULE PAINT_1170.
       ENDCHAIN.
    4.6     Main Program
    4.6.1     Events
    The Program MUST NOT be coded without the use of Proper Coding blocks
    •     Initializations
    •     Top-of-page during line-selection
    •     At Selection-Screen
    •     At Line-Selection
    •     At User-Command
    •     At Pfn
    •     Start-Of-Selection
    •     Top-Of-Page
    •     Get
    •     End-Of-Page
    •     End-Of-Selection
    NOTE: The coding for each event should be logically split into forms (subroutines). That is to say, each event will comprise mostly of ‘PERFORM’ statements.
    5.     General Coding Standards
    5.1     One command per line
    Each ABAP/4 command consists of a sentence ending with a period. Multiple commands can be on one line; however, as a standard start each new command on a new line. This will allow for easier deleting, commenting, and debugging.
    5.2     Indented Source Code
    The ABAP/4 editor has a "Pretty Printer" command to indent by 2 positions specific lines of code and add subroutine comments. Event keywords are typically not indented.
    5.3     Extended Syntax Check
    Extended Program Check (EPC) to be done on each object to make sure the code is Syntactically correct. There should be no Error/warning messages in the code.
    5.4     Reusability and Modularity
    If a block of code is executed more than once, it should be placed in a subroutine at the bottom of the code. This makes the code more readable, requires less indentation, and is easier to debug since the debugger can jump through an entire subroutine via a PF key. Also, when possible parameters should be passed to and from subroutines to make the purpose easier to understand and reduce the need for global variables. Always document the purpose of each parameter.
    5.5     Text Handling
    Text elements must be used to display any text messages.
    5.6     Usage of System Variables
    The system variables should be used wherever possible. The SY-SUBRC is to be checked after any function call, selection operation, etc.
    5.7     Chaining Statements
    •     Consecutive sentences with an identical beginning shall be combined into a chained statement.
    Example:
    Instead of the statements
    MOVE SY-MANDT TO D00001-MANDT.
    MOVE SY-LANGU TO D00001-SPRAS.
    A chained statement shall be used
    MOVE:
                 SY-MANDT TO D00001-MANDT,
                 SY-LANGU TO D00001-SPRAS,
                 SY-UNAME TO D00001-BNAME.
    5.8     Common Routines
    •     Standard sub-routines should be implemented as FUNCTION's rather than a FORM (ie. SUBROUTINE). A FUNCTION is easier to maintain and can be easily tested without a calling program. Standard SAP function modules are also available and the function library should be used to check if function modules already exist for a function that needs to be performed i.e.POPUP_TO_CONFIRM_LOSS_OF_DATA etc.
    •     Includes can also be created for re-usable or common code e.g. common data declaration statements.
    5.9     Dialog Messages
    Dialogue messages are stored in table T100. Programmers shall check to see if an appropriate message exists before adding a new message. Programs shall use the message-id which corresponds to the SAP module that the program most relates to.
    5.10     Function Keys
    PF-keys should be programmed to execute functions where required. SAP Standard function keys should be used where appropriate. The most commonly used buttons should be displayed as pushbuttons in the application toolbar.
    5.11     Enqueuing and Dequeuing Data Objects
    •     All database objects being processed by a program, for purposes other than for display, shall be enqueued before such processing is executed. If the enqueue is unsuccessful, then a message shall be returned stating why the enqueue was unsuccessful.
    •     Enqueue and Dequeue objects should be created via the data dictionary.
    5.12     Error Handling (SY-SUBRC)
    •     Return codes shall always be checked immediately after an event which returns a code.  
    Eg. Function calls, Select statements, Updates etc.
    •     The value of SY-SUBRC is 0 when successful and generally produces a value of 4 when unsuccessful (there are a few exceptions).
    Therefore, rather check SY-SUBRC with:
               IF SY-SUBRC <> 0
    than with
             IF SY-SUBRC = 4  (which is redundant and makes the system do a double check)
    •     Error messages displayed to the user must be clear and descriptive.
    •     Remember to group related / dependant steps together and to Rollback all changes for steps in that group should any one of them fail, thus maintaining the integrity of the system.
    •     Check whether an Error Log, (file), must be produced by your program and if so check on the format of the file.
    •     If any Error Logging is done to a custom table in the database then make sure this table is maintained and monitored correctly. (Dev. Note)
    •     Transaction SE91 provides the facility to create and utilize messages in their appropriate message class. Elaborate on the message if necessary, using the long text documentation for that message number.
    5.13     General Conventions and Hints
    •     There should be NO hard coding of values in programs – easy maintainability
    •     For amounts, use the CURRENCY command in write statements to automatically convert fields into their correct decimal format. The currency specified in the write statement is treated as a key for the table TCURX. If no entry exists for the currency specified, the system assumes two decimal places.
    •     For quantities, use the UNIT command in write statements to automatically convert fields into their correct decimal format. The contents of the unit specified are used on table T006. If no entry exists for the unit specified, the formatting has no effect.
    •     Use the ‘LIKE’ statement as often as possible to declare ‘DATA’ variables instead of an explicit ‘TYPE’ declarations.
    •     Try to use the ‘INCLUDE’ statement with standard SAP structures and tables for your structures and internal tables where possible.  If you use the include statement to include other program components in your code then document what those components are, what they do and how to use them.
    •     Try to make use of standard SAP Function Modules wherever possible rather than building your own. Use the pull down functionality in transaction SE37 to find suitable standard function modules.
    •     Make use of the SAP PATTERN tool to automatically insert the standard code for:
    •     CALL FUNCTION
    •     MESSAGE ID
    •     SELECT*FROM
    •     PERFORM
    •     AUTHORITY-CHECK
    •     WRITE
    •     CASE
    •     CALL DIALOG
    •     The standard date format to use is ‘DD/MM/YYYY’. (Dev. Note)
    The standard time format to use is ‘HH:MM:SS’.
    5.14     Parameters in Sub-Routines
    Naming convention for Parameters in subroutine is P_
    6.     Performance Standards
    6.1     General Tips on Performance Tuning
    6.1.1     Avoid Redundant code
    Avoid leaving "dead" code in the program. Comment out variables that are not referenced and code that is not executed. To analyze the program, use the Program Analysis function in SE38 -> Utilities -> Program Analysis.
    6.1.2     Subroutine Usage
    For good modularization, the decision of whether or not to execute a subroutine should be made before the subroutine is called.
    Example:
    IF f1 NE 0.
      PERFORM sub1.
    ENDIF.
    FORM sub1.
    ENDFORM.
    6.1.3     Case vs. Nested IF
    When testing fields "equal to" something, one can use either the nested IF or the CASE statement. The CASE is better for two reasons. It is easier to read and after about five nested IFs the performance of the CASE is more efficient.
    6.1.4     Using the MOVE Statement
    When records a and b have the exact same structure, it is more efficient to MOVE a TO b than to MOVE-CORRESPONDING a TO b.
    6.1.5     SELECT Queries
    The performance of  any ABAP program mainly depends on the ABAP Queries used in it. More optimum the queries , better the performance. Take care of the points mentioned nin the following sections while writing any ABAP queries.
    6.1.5.1     Using all the keys in SELECT statement
    When using the SELECT statement, study the key and always provide as much of the left-most part of the key as possible. The SELECT * command is to be avoided everywhere.
    6.1.5.2     Fetching Single Record
    If the entire key can be qualified, code a SELECT SINGLE not just a SELECT. If all the keys are not available, we should use SELECT UPTO 1 ROWS if we are interested only in the first record.
    6.1.5.3     Avoid SELECT-ENDSELECT
    Selecting data into an internal table using an array fetch versus a SELECT-ENDELECT loop will give at least a 2x performance improvement.  After the data has been put into the internal data, then row-level processing can be done.  
    Example:
    select ... from table <..>
               into <itab>
               where ...
    loop at <itab>
      <do the row-level processing here>
    endloop.
    6.1.5.4     Using Indexs
    Use indexes wherever possible. Tune the Query so that optimum Indexing will happen.
    6.1.5.5     Provide all the keys
    Give as many keys as possible in the WHERE clause to optimize the database fetching. Use the Index fields in the first position to optimize performance.
    6.1.5.6     Avoid “INTO CORRESPONDING”
    Avoid using INTO CORESPONDING FIELDS of Table. Instead, explicitly mention the fields. Else, The Table Fields should be in the same sequence as the selection
    6.1.5.7     SELECT statement inside LOOP
    Do not write SELECT statements inside the loop. Instead, use the FOR ALL ENTRIES Command
    Before using FOR ALL ENTRIES command, check that the
    1.     Corresponding Internal table is not empty. If the Internal table is empty, the statement will select ALL the entries in the Database
    2.     The Internal table is sorted by the Filed used in the Where Clause: This makes selection faster
    6.1.5.8     Nested SELECT statement
    Avoid Using nested SELECT statements. Instead, make use of different internal tables to fetch the data, and Use Nested LOOPS to read them.
    6.1.5.9     Select Distinct
    Whenever its possible avoid SELECT DISTINCT, instead select data into internal table, sort and use DELETE ADJACENT DUPLICATES
    6.1.5.10     Use of OR in Where Clause
    Do not use OR when selecting data from DB table using an index because The optimizer generally stops if the WHERE condition contains an OR expression.
    e.g.
    Instead of
         SELECT * FROM spfli WHERE carrid = ‘LH’
                                   AND (cityfrom = ‘FRANKFURT’ OR
                 city from = ‘NEWYORK’)
    Use
         SELECT * FROM spfli WHERE (carrid = ‘LH’ AND cityfrom = ‘FRANKFURT’)
                                      OR (carrid = ‘LH’ AND cityfrom = ‘NEWYORK’).
    6.1.5.11     Order By
    ORDER BY will Bypass buffer. So, performance will decrease. If you want to sort data, it is efficient to SORT them in INTERNAL TABLE rather than using ORDER BY. Only use an ORDER BY in your SELECT if the order matches the index, which should be used.
    6.1.6     Using the READ statement
    When reading a single record in an internal table, the READ TABLE WITH KEY is not a direct READ. The table needs to be sorted by the Key fields and the command READ TABLE WITH KEY BINARY SEARCH is to be used.
    6.1.7     Hashed table
    If the number of entries in the Internal Table is high then use Hashed Table with Keys to access the table.
    6.1.8     Transporting
    With READ or MODIFY Statements use TRANSPORTING
    6.1.9     Using LDB
    In order to improve performance in case of an LDB, individual tables can be excluded from selection. Under the section ‘Table Selection’ in the Documentation of LDB the fields with proper description has been given those fields can be set in the application report at the time of INITIALIZATION or at the START OF SELECTION. This can enhance the performance.
    6.1.10     Append Lines of
    Whenever it is possible use APPEND LINES OF to append the internal Tables instead of using loop and then APPEND Statement.
    6.1.11     Use WHILE
    Use WHILE instead of a DO+EXIT-construction, as WHILE is easier to understand and faster to execute
    6.1.12     DELETE <itab> WHERE
    Use DELETE <itab> WHERE…for deleting records from an internal table.
    e.g.
    Instead of
    LOOP AT <itab> WHERE <field> = ‘0001’
         DELETE <itab>.
    ENDLOOP.
    Use
    DELETE <itab>  WHERE <field> = ‘0001’.
    6.1.13     Using WHERE clause in LOOP…….ENDLOOP
    Use:
    Sort ITAB by NAME.
    Loop at itab where name EQ SY-UNAME
    Endloop.
    Instead Of:
    Read itab with key name = SY-UNAME.
    L_tabix = sy-tabix.
    Loop at itab from l_tabix.
    If name eq ‘bijoy’
    Endif.
    Endloop.

  • Performance issue in abap program

    hi,
    how can we improve the performance of  abap program

    hi,
    read the follwing links
    ABAP provides few tools to analyse the perfomance of the objects, which was developed by us.
    Run time analysis transaction SE30
    This transaction gives all the analysis of an ABAP program with respect to the database and the non-database processing.
    SQL Trace transaction ST05
    by using this tool we can analyse the perfomance issues related to DATABASE calls.
    Perfomance Techniques for improve the perfomance of the object.
    1) ABAP/4 programs can take a very long time to execute, and can make other processes have to wait before executing. Here are some tips to speed up your programs and reduce the load your programs put on the system:
    2) Use the GET RUN TIME command to help evaluate performance. It's hard to know whether that optimization technique REALLY helps unless you test it out.
    3) Using this tool can help you know what is effective, under what kinds of conditions. The GET RUN TIME has problems under multiple CPUs, so you should use it to test small pieces of your program, rather than the whole program.
    4) Generally, try to reduce I/O first, then memory, then CPU activity. I/O operations that read/write to hard disk are always the most expensive operations. Memory, if not controlled, may have to be written to swap space on the hard disk, which therefore increases your I/O read/writes to disk. CPU activity can be reduced by careful program design, and by using commands such as SUM (SQL) and COLLECT (ABAP/4).
    5) Avoid 'SELECT *', especially in tables that have a lot of fields. Use SELECT A B C INTO instead, so that fields are only read if they are used. This can make a very big difference.
    6) Field-groups can be useful for multi-level sorting and displaying. However, they write their data to the system's paging space, rather than to memory (internal tables use memory). For this reason, field-groups are only appropriate for processing large lists (e.g. over 50,000 records). If you have large lists, you should work with the systems administrator to decide the maximum amount of RAM your program should use, and from that, calculate how much space your lists will use. Then you can decide whether to write the data to memory or swap space.
    Use as many table keys as possible in the WHERE part of your select statements.
    7)Whenever possible, design the program to access a relatively constant number of records (for instance, if you only access the transactions for one month, then there probably will be a reasonable range, like 1200-1800, for the number of transactions inputted within that month). Then use a SELECT A B C INTO TABLE ITAB statement.
    8) Get a good idea of how many records you will be accessing. Log into your productive system, and use SE80 -> Dictionary Objects (press Edit), enter the table name you want to see, and press Display. Go To Utilities -> Table Contents to query the table contents and see the number of records. This is extremely useful in optimizing a program's memory allocation.
    9) Try to make the user interface such that the program gradually unfolds more information to the user, rather than giving a huge list of information all at once to the user.
    10) Declare your internal tables using OCCURS NUM_RECS, where NUM_RECS is the number of records you expect to be accessing. If the number of records exceeds NUM_RECS, the data will be kept in swap space (not memory).
    11) Use SELECT A B C INTO TABLE ITAB whenever possible. This will read all of the records into the itab in one operation, rather than repeated operations that result from a SELECT A B C INTO ITAB... ENDSELECT statement. Make sure that ITAB is declared with OCCURS NUM_RECS, where NUM_RECS is the number of records you expect to access.
    12) If the number of records you are reading is constantly growing, you may be able to break it into chunks of relatively constant size. For instance, if you have to read all records from 1991 to present, you can break it into quarters, and read all records one quarter at a time. This will reduce I/O operations. Test extensively with GET RUN TIME when using this method.
    13) Know how to use the 'collect' command. It can be very efficient.
    14) Use the SELECT SINGLE command whenever possible.
    15) Many tables contain totals fields (such as monthly expense totals). Use these avoid wasting resources by calculating a total that has already been calculated and stored.
    Some tips:
    1) Use joins where possible as redundant data is not fetched.
    2) Use select single where ever possible.
    3) Calling methods of a global class is faster than calling function modules.
    4) Use constants instead of literals
    5) Use WHILE instead of a DO-EXIT-ENDDO.
    6) Unnecessary MOVEs should be avoided by using the explicit work area operations
    see the follwing links for a brief insifght into performance tuning,
    http://www.thespot4sap.com/Articles/SAPABAPPerformanceTuning_Introduction.asp
    http://help.sap.com/saphelp_nw2004s/helpdata/en/d1/801f7c454211d189710000e8322d00/frameset.htm
    regards
    Rohan

  • New ABAP Program to check Direct UPDATE in Database Table

    Hi all,
    As per customer requirement , I have to develop ONE  Program which find out that  in which ABAP Program , Programmer has used Open Sql command like  UPDATE , DELETE , INSERT , MODIFY to direct update in Database Table.
    Have a look on all Z-ABAPs, find out if there are statements with "update", "delete", "insert" or "modify" in the coding, then find out if updates to sap-Tables are done
    How can I achived that ?
    Please , If anybody is having idea , than please let me know..
    Thanks You ,

    Hi
    Kindly refer to the below link. This has step by step how you can achieve the checks.
    [http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/12659a90-0201-0010-c18b-9d014f9bed0d]
    But if you want to check if any program they have used 'UPDATE' then you can do like below.
    Go to SE38
    Utilities---> Find in Source Code-
    Find --- UPDATE
    In program - Z* or ZX* if you want to search only in Exits
    Regards,
    Vijay V .

  • OS specific changes in ABAP program

    Hi guys,
    I know due to OS migration ABAP program changes are not mostly required.
    possibly Except few things.
    1-External commands check
    2-File path or logical path settings check.
    3-Native sql check.
    Apart from this is there any possible that OS specific settings would be used in ABAP programs. I want to find out those things in advance.
    Could somebody shed light on this..
    In my case Os is unix to solaris 11. so just want to know if any specific things has to be checked or taken care after OS migration.
    Advice please.
    Thanks.
    Baasha.

    Hi,
    Did exactly the same, everything was fine. Your check scope is perfectly fine.
    Just to add, that external progs. could be used in jobs as well, and can be called directly from ABAP.

  • Abap program to MSSQL connection

    Hello !!
    Do anybody knows how to retrive data directly from  MSSQL server to abap program ,normaly it should by done by defining DBCO connection and using Native SQL statments but  our SAP system is running on UNIX and what I have found for know in sap notes is that connection to MSSQL can only be defined in DBCO transaction if SAP is working on Windows platform. Are there any other solutins to set that conection in situation like mine ??
    BR
    Jacek

    Hi again,
    1. since your system is aix,
       i don't think .DLL files (windows files)
        will work on it.
    2. probably , for MSSQL,
       there must be some other file,
       (for other operating systems like  AIX, UNIX etc).
    3. If that file is installed,
       then something may move further.
    4. Moreover, your basis
      team will have to make a CONNECTION STRING
      (ie. connection from application server
       to MSSQL server)
    5. Once that is made, only then
      we can use in abap.
    regards,
    amit m.

Maybe you are looking for

  • HP Photosmart Printer 5525

    When trying to print from Adobe Reader, custom sizes are not available under paper selection in printer dialog box, yet this option is available when I print from Word.  Any idea why?

  • Transfer Orders on Handheld

    Hi All,   We have a requirement where in based on the delivery priority, we will have to control the process of TO confirmation on Handheld. I understand we can do this by RF Queue Management in SAP. Does any one help me if you have any document whic

  • Built in isight camera and skype: crashing systmatically (iMac G5)

    Hi, I have problesm using skype video with the built-in camera on my iMac G5. Everytime i start the video or open the video preferences to select the video source, skype crashes. Has anyone epxerienced the same. If you have some tips, i'm in! thanks

  • SH VER and Dir Bootflash - Show differant mem sizes!!!!

    A sh ver shows 32 meg, while a Dir bootflash shows 16 meg. Shouln't these values be the same?. Device is a 6509. I need know if this is OK as I wish to upgrade the IOS. From SH VER: DRAM FLASH Total Used 32768K 23633K Uptime is 450 days, 1 hour, 31 m

  • Is there any proof that Airport Express really extends a network?

    I've been using various Airport Express devices since their inception, always on extended Extreme networks. Yet I've never been able to demonstrate with any certainty that the network is genuinely extended. I seem to get the same range with or withou