ABAP programming tips

  • Q: How to convert CHAR type to RAW type?
    A:
  • Q: What does mean asterisk in front of the name?
    A: EKPO and *EKPO are usually defined in TABLES statement, and both use the DDIC structure of EKPO. Classical usage is to distinguish between old and new value of the record.
    SELECT SINGLE * FROM *bkpf is equal to SELECT SINGLE * FROM bkpf into *bkpf
    the same as SELECT SINGLE * FROM bkpf is equal to SELECT SINGLE * FROM bkpf into bkpf
  • While declaring variables, always follow the naming conventions through out your code. Your variable names talks a lot about its usage.
    Make sure your variables are of the form:

    {Prefix1}{Prefix2}_{Name} where:

    Prefix1:
    L – Local
    I – Import
    E – Export
    G – Global
    T – Table Type

    Prefix2:
    V – Single Value
    S – Structure
    T – Table
    R – Type ref to Data
    O – Type ref to Object
    E – Type ref to Exception objects

    Name – name of the variable.
    e.g.:
    lt_sel – local table
    lo_rvs – local object
    and so on.

    Before changing the parameters (type or name), make sure that you run “Where used”, make a note and change them as well.
    While working on ABAP Classes and Interfaces, Never change a super class of a framework. It could potentially bring all applications down. Double check to make sure that the code you change is in your class only.

    Ctrl + D Duplicate any line.
    Ctrl + . & Ctrl + , Comment and Un-Comment selected lines.
    Ctrl+Shift+X Deletes the whole line.
    Ctrl+Shift+V Gives All Paste options.
    To assist in locating codes, can be a bookmark, using a combination: CTRL + ALT + (0 to 9).
    To go to bookmark created, use combination CTRL + (0 to 9).

    _sap

    • Please ensure that IV_UNAME (SY-UNAME) and IV_LANGUAGE (SY_UNAME) are mandatory for all modules.
    • Q: How to debug IDOCs inbound processing (most first FMs on receiver system (under ALEREMOTE non dialog user)?
      A: Simple and stupid solution is to put eternal loop in form FA5_DOCUMENT_SYNTAX_CHECK (program LEDI1FA5):

      Then the process will be available for debugging in the transaction SM50.
    • Please create lock objects on the header tables and make sure that you obtain a lock before changes and release the lock after changes.
    • Make sure that you transactions are atomic. Either commit your work after all changes are successful or Rollback in case of error. If you rollback, make sure that you have released the locks.
    • Q: How to pass dynamic varable into SELECT … WHERE IN clause?
      A:
    • During save, please make sure that entries in all the text (_T_*) tables that relate to your modules are also saved. If no data exists, treat it as an error. (As across check, you can verify the same by executing the view and making sure that the data is returned correctly)
    • The Function should be RFC Enabled. Never raise an exception. Always return errors in the ET_RETURN (Type BAPIRET2) structure.
    • Never hardcode text strings. Make sure that you use a text element. But use it with text reference.
      E.g. If you have an error during validating the email, use it as “Email ID is required”(001) instead of using text-001. This will ensure that error messages are displayed regardless of user logon language.
    • At the end of the function, Always call “get details” and return the values as export/table values. This will serve the purpose of reflecting the data as-is in the DB back to the user and will save another round trip to retrieve it again.
    • Q: How to get variable value from another running program?
      A:
    • Update audit fields created by, created date, created time only during create.
    • Please ensure that IV_UNAME (SY-UNAME) and IV_LANGUAGE (SY_UNAME) are mandatory for all modules. Extract the data for the language specified.
    • Q: Where are the packing handling units data stored during execution of transaction VL01/VL02/VL32N”? CVEKP table is always empty.
      A: The variable is (SAPLV51G)IVEKP[]

    5 thoughts on “ABAP programming tips”

    1. – Руссские курсы BC400, BC410, пару английских.

      Следующие общеиспользуемые вещи:
      Отчет ALV, через FM REUSE_ALV_GRID
      Печатная форма PDF: заголовок, тч, подвал
      Печатная форма smartforms
      Выгрузка в Excel через ZWWW
      Загрузка из плоского файла
      Создание Z-таблицы в словаре, ракурс к ней в SM30, прямой апдейт
      Несложный FM
      Отчет на ALV с применением ООП
      Экраны (нарисовать), данные в них менять
      Средство поиска для Z-таблицы
      Программа со всеми этими компонентами

    2. Type Length Standard length Value Area Initial Value Description
      b 1 Byte   0 to 255 0 1 byte integer (internal)
      c 1 to 65,535 characters 1 character Any alphanumeric character ” ” for every position Text field
      d 8 characters   8 user-defined alphanumeric characters; Only values in the format YYYYMMDD that are
      permitted as date entries according to the calendar rules are valid: YYYY (year): 0001 to 9999, MM(month): 01 to 12, DD (day): 01 to 31
      “00000000” Date field
      f 8 bytes   Floating point numbers are displayed internally with 16 decimal places according to the IEEE-754
      standard (double precision). Valid values are -1,7976931348623157EE+308 to -2,2250738585072014EE-308
      for the negative area, the value zero, and +2,2250738585072014EE-308 to +1,7976931348623157EE+308 for
      the positive area. Both validity areas are extended in the direction of zero through denormalized numbers after IEEE-754.
      0 Floating point number
      i 4 bytes   -2.147.483.648 to +2.147.483.647 0 4 byte integer
      n 1 to 65,535 characters 1 character Any alphanumeric characters, however, valid values are only the digits 0 to 9 “0” for every position. Numeric text
      p 1 to 16 bytes 8 bytes The valid length for packed numbers is between 1 and 16 bytes; two decimal places are packed into one byte, whereby the last byte only contains one place and the plus/minus sign; after the decimal separator, up to 14 decimal places are permitted.
      Depending on the field length len and the number of decimal places dec, the following applies for the
      value area: (-10^(2len -1) +1) / (10^(+dec)) to (+10^(2len -1) -1) /(10^(+dec)) in steps of 10^(-dec). Values in between this range are rounded off.
      0 Packed number
      string variable   as for type c empty string of length 0 Text string
      s 2 bytes   -32.768 to +32.767 0 2 byte integer (internal)
      t 6 characters   6 user-defined alphanumeric characters; the only valid values are numbers that are
      interpreted as a time specification in the 24-hour clock format HHMMSS. SAP recommmends to exclusively use 00 to 23 hours for HH (hours) and 00 to 59 for MM (minutes) and 00 to 59 for SS (seconds).
      “000000” Time field
      x 1 to 65,535 bytes 1 byte hexadecimal characters 0-9, A-F hexadecimal 0 Byte field
      xstring variable   as for type x empty string of length 0. Byte string

      These types are predefined in every ABAP program.

      • All predefined ABAP types in this table are elementary.
      • Apart from the types b and s, the predefined ABAP types can also be used to define your own data types and data objects and for
        typing. The types
        b
        and s cannot be specified directly in ABAP
        statements. Self-defined data types and data objects in ABAP programs are of the data type
        b
        and s if they are defined with reference to data elements to the ABAP Dictionary which are of the external data types INT1 or INT2.
      • The program-globally predefined data type cursor is
        currently synonymous with the predefined ABAP type i. This is required for the declaration of a cursor variable for
        database cursor handling.
      • All predefined ABAP types for which a length interval is specified in second column in the table
        are generic, which means that the length is not part of the type description. For the type p, the
        fractional portion is indefinite as well as the length.
      • The entries in the standard length column specify the length that is used for the corresponding generic data type when declaring data objects, if no explicit length is specified in the relevant statement.
      • In Unicode systems, the length
        must either be specified in characters and bytes. In non-Unicode systems, the length of a character
        is one byte, but in Unicode systems the length of a character depends on which Unicode character representation is used.


      Notes

      • The system class CL_ABAP_EXCEPTIONAL_VALUES contains methods that return the minimum and maximum value for a data object (as of release 6.10).
      • As the decimal places of a floating point number of type f
        are represented internally as dual fractions, there is not an exact equivalent for every number that
        can be represented in the decimal system. This can lead to rounding errors in assignments and intermediate results of calculations. These errors can be avoided by using a two-step rounding procedure.
      • For data objects of data type p, the
        program attribute fixed point arithmetic
        must be set so that the decimal separator is taken into account. Otherwise, the content is handled as if there is no decimal separator, in all operations except for displaying a list.
      • Data objects of the data type t that contain numbers outside the value range 00 to 23 for hours and 00 to 59 for minutes and seconds can be
        converted to numeric values, but are invalid when using time stamps.
    3. Quickly send a e-mail:

    4. Shift leading/trailing symbols:

    Leave a Reply

    Your email address will not be published.