ABAP Programming Tips

August 16, 2017 | Author: sameer1562000 | Category: Database Transaction, Databases, Information Technology, Computer Programming, Technology
Share Embed Donate


Short Description

Download ABAP Programming Tips...

Description

ABAP Programming Tips General • •

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 o {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 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.

Here are some of the common data definitions:

Import Import Import Import Import Import Import Import

Type (Single Value Field) (Structure) (Range Structure) (Table Type) (Range Table Type) (Type Ref to Data) (Type Ref to Object) (Type Ref to Exceptions)

IV_{name} IS_{name} IS_{name}_RANGE IT_{name} IT_{name}_RANGE IR_{name} IO_{name} IE_{name}

Export Export Export Export Export Export Export Export

(Single Value Field) (Structure) (Range Structure) (Table Type) (Range Table Type) (Type Ref to Data) (Type Ref to Object) (Type Ref to Exceptions)

EV_{name} ES_{name} ES_{name}_RANGE ET_{name} ET_{name}_RANGE ER_{name} EO_{name} EE_{name}

Tables (Meant for Import) Tables (Meant for Export) Changing Exceptions Global Global Global Global Global Global Global Global Local Local Local Local Local Local Local Local

1

Field1 (Single Value) Field (Structure) Field (Range Structure) Field (Table Type) Field (Range Table Type) Field (Type Ref to Data) Field (Type Ref to Object) Field (Type Ref to Exceptions)

Field Field Field Field Field Field Field Field

(Single Value) (Structure) (Range Structure) (Table Type) (Range Table Type) (Type Ref to Data) (Type Ref to Object) (Type Ref to Exceptions)

Name

IT_{name} ET_{name} Avoid using it unless there is no option Do not declare exceptions in BAPI GV_{name} GS_{name} GS_{name}_RANGE GT_{name} GT_{name}_RANGE GR_{name} GO_{name} GE_{name} LV_{name} LS_{name} LS_{name}_RANGE TT_{name} LT_{name}_RANGE LR_{name} LO_{name} LE_{name}

Arguments in perform

P_{prefix}_{name} where prefix is LV, LS or LT

Structure Definition Table Type Definition

TS_{name} TT_{name}

Data elements declared in the TOP include.

Field Field Field Field Field Field Field Field

Symbol Symbol Symbol Symbol Symbol Symbol Symbol Symbol

Type Definition (Single Val, Local) Definition (Structure, Local) Definition (Range Structure) Definition (Table, Local) Definition (Single Val, Local) Definition (Structure, Local) Definition (Table, Local) Definition (Range Tab, Local)

Name

Function Modules Save Function Module (Insert/Update) • • • •





• •



• •

Please ensure that IV_UNAME (SY-UNAME) and IV_LANGUAGE (SY_UNAME) is mandatory for all modules. Create Number Ranges for the Header Tables (and some of the related tables as required). 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. Concurrent Updates needs to be handled via optimistic locking (soft) only. No Exclusive locking (pessimistic locking) should be done. One method is to check that the REVNUM field that is passed is the same as in the database. Along with that, make sure that the Changed Date and Change time is the same as in the database. Once verified change the REVNUM by incrementing by 1 and update the change date/time with current date/time. If you have other ways, feel free to share it with the team. 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 a cross 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. o 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. Always update audit fields changed by, changed date, changed time with IV_UNAME, current date/time. Update audit fields created by, created date, created time only during create.

Get Details Function Module • •

Please ensure that IV_UNAME (SY-UNAME) and IV_LANGUAGE (SY_UNAME) is mandatory for all modules. Extract the data for the language specified. Ensure that all corresponding text table data is also returned. Never return only Ids.

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF