Monday, February 13, 2017

ABAP Editor Keyboard Shortcuts

IconShortcut KeyUse
Enter keyEnter/Continue
Ctrl SSave
F3Back
Shift F3Exit System Task
F12Cancel
Ctrl PPrint
Ctrl FFind
Alt F12(PC only)Customize local layout
Ctrl GContinue Search
F1Help
Ctrl Page UpScroll to top of document
Page upScroll up one page

Thursday, February 9, 2017

Variable Naming Convention in ABAP

Here are some rules that I used for my convenience in coding ABAP. You can also have your own style in naming the variables in ABAP. These naming convention might help you remember and differentiate variables that you used, but keep in mind that you might need to follow a different naming convention in every project.

Variable TypeUsage
Global Varibles gv_<variablename>
d_<variablename>
Local Variable lv_<variablename>
ld_<variablename>
Global Internal Table it_<internaltablename>
gt_<internaltablename>
Local Internal Table lt_<internaltablename>
Global Work Area gw_<workareaname>
Local Work Area lw_<workareaname>
wa_<workareaname>
Constant c_<constantname>
Parameter p_<parametername>
Select_option s_<selectoptionname>
Ranges r_<rangename>
Type Structure ty_<structurename>
Subroutines F_<subroutinename>
FORM_<subroutinename>

Source: 

Friday, February 3, 2017

SAP Basic Operators, Keywords, Functions

Arithmetic Operators

Operator Using Operator Using Keyword
Less than a < b a LT B
Greater than a > b a GT b
Less than or equal a <= b a LE b
Greater than or equal a >= b a GE b
Equal a = b a EQ b
Not equal a <> b a NE b

Comparison Operators

Operator
Using Operator
Using Keyword
Addition
 p = n + m.
ADD n TO m.
Subtraction
 P = m – n.
SUBTRACT n FROM m.
Multiplication
 P = m * n.
MULTIPLY m BY n.
Division
 P = m / n.
DIVIDE m BY n.
Integer division
 P = m DIV n.
---
Remainder of division
 P = m MOD n.
---
Powers
 P = m ** n.

Logical Expressions

Expression Usage
AND (a<b) and (a<c)
OR (a<b) or (a<c)
NOT a NOT b
BETWEEN a BETWEEN b AND c
IS a IS (NULL/ASSIGNED/BOUND/INITIAL)

Numeric Data Types Functions

DATA

DATA n TYPE p DECIMALS 2.
DATA m TYPE p DECIMALS 2 VALUE '-5.55'.

Function Usage Output
ABS n = abs( m ).  WRITE:  'ABS: ', n. ABS: 5.55
SIGN n = sign( m ). WRITE: / 'SIGN: ', n. SIGN:  1.00-
CEIL n = ceil( m ). WRITE: / 'CEIL: ', n. CEIL:  5.00-
FLOOR n = floor( m ). WRITE: / 'FLOOR:', n. FLOOR: 6.00-
TRUNC n = trunc( m ). WRITE: / 'TRUNC:', n. TRUNC: 5.00-
FRAC n = frac( m ). WRITE: / 'FRAC: ', n. FRAC:  0.55-

Floating-Point Functions

Function Meaning
acos, asin, atan; cos, sin, tan Trigonometric functions.
cosh, sinh, tanh Hyperbolic functions.
exp Exponential function with base e (e=2.7182818285).
log Natural logarithm with base e.
log10 Logarithm with base 10.
sqrt Square root.


String Logical Expression

CO str1 only contains characters from <str2>;
CN  str1 contains characters not only from str2 (corresponds to NOT str1 CO str2);
CA  str1 contains at least one character from str2;
NA  str1 does not contain any characters from str2;
CS  str1 contains the string str2;
NS  str1 does not contain the string str2;
CP  str1 contains the pattern str2;
NP  str1 does not contain the pattern str2;

String Functions

DATA: title(15) TYPE c VALUE 'Mr',
surname(40) TYPE c VALUE 'Smith',
Forename(40) TYPE c VALUE 'Joe',
sep,  "an empty character by default"
Destination(200) TYPE c,
spaced_name TYPE STRING VALUE 'Joe Smith',
len TYPE i.

Function Usage Output
CONCATENATE DATAtitle(15TYPE c VALUE 'Mr',
      surname(40TYPE c VALUE 'Smith',
      forename(40TYPE c VALUE 'Joe',
      sep,  "an empty character by default"
      destination(200TYPE c.
CONCATENATE title surname forename INTO destination SEPARATED BY sep. Mr Smith Joe 
CONDENSE DATA spaced_name TYPE string VALUE 'Joe         Smith'.
CONDENSE spaced_name. Joe Smith
CONDENSE NO GAPS CONDENSE spaced_name NO-GAPS. JoeSmith
STRLEN DATA len TYPE i.
len strlensurname ).
WRITE / len.
strlen( surname ). 5
REPLACE REPLACE ' ' WITH '-' INTO destination. Mr-Smith Joe
REPLACE ' ' WITH '-' INTO destination. Mr-Smith-Joe
REPLACE ALL OCCURRENCES REPLACE ALL OCCURRENCES OF '-' IN destination WITH '+'. Mr+Smith+Joe
SEARCH destination 'Mr. Smith Joe'.
SEARCH destination for 'Joe   '. sy-fdpos 10
SEARCH destination for  '*ith'. sy-fdpos 4
SEARCH destination for 'John'. sy-subrc 4
SHIFT DATA empl_num TYPE STRING VALUE '0000654321'.
SHIFT empl_num"become 000654321 000654321
SHIFT DELETE LEADING empl_num '0000654321'.
SHIFT empl_num left deleting leading '0'"become 654321 654321
SHIFT CURCULAR empl_num '0000654321'.
SHIFT empl_num CIRCULAR. 0006543210
SPLIT DATA mystring TYPE string VALUE '1234** ACBD **6789'.
DATAa(10TYPE c,
      b(10TYPE c,
      c(10TYPE C, 1234 
      sep2(2TYPE c VALUE '**'. ABCD
SPLIT mystring AT sep2 INTO a b c. 6789
SUBFIELDS DATAint_tel_num(17TYPE c VALUE '+62-812345678',
      country_code(3TYPE c,
      tel_num(14TYPE c.
country_code int_tel_num(3). 62
tel_num int_tel_num+4(13). 812345678


Formatting String Functions

Function Description
LEFT-JUSTIFIED Specifies that the output is left-justified.
CENTERED Denotes that the output is centered.
RIGHT-JUSTIFIED Specifies that the output is right-justified.
UNDER <g> The output starts directly under the field <g>.
NO-GAP Specifies that the blank after field <f> is rejected.
USING EDIT MASK <m> Denotes the specification of the format template <m>. Using No EDIT Mask: This specifies that the format template specified in the ABAP Dictionary is deactivated.
NO-ZERO If a field contains only zeroes, then they are replaced by blanks.

Formatting Numeric Functions

FunctionDescription
NO-SIGN Specifies that no leading sign is displayed on the screen.
EXPONENT <e> Specifies that in type F (the floating point fields), the exponent is defined in <e>.
ROUND <r> The type P fields (packed numeric data types) are first multiplied by 10**(-r) and then rounded off to an integer value.
CURRENCY <c> Denotes that the formatting is done according to the currency <c> value that is stored in the TCURX database table.
UNIT <u> Specifies that the number of decimal places is fixed according to the <u> unit as specified in the T006 database table for type P.
DECIMALS <d> Specifies that the number of digits <d> must be displayed after the decimal point.

Thursday, February 2, 2017

The Central Repository of SAP, DATA DICTIONARY


ABAP Dictionary is a major tool of ABAP workbench which acts as a central repository for data definitions in SAP System. Hence, any new of modified information will be automatically provided for all system components to ensure the integrity, consistency, and security of the data. Having said that, it is just an interface as there is a real database which stores the data like DB2, MS SQL, Oracle, and even HANA.


The Object types in ABAP Dictionary are:
Tables: This is a table just like the one in a typical Relational Database Management System

View: This is a logical view of more than one table like the a Relational Database View do


Data Types: These are basic global data types, but very important as they determine the types of the data used by lots of programs. The data types includes:



Data element: Data element describes an individual fields in a form of elementary types. It tells the semantic attributes of a field like the field length, the number of decimal places, and even screen information like field help/explanatory text). However, the technical characteristics of the field such as data type (INT2, CURR, QUAN, CHAR, STRING), output characteristics, and value range in a field are defined in a domain.

Structure: Structure is a sequence of any other data types that can be used in the making of a workarea or even an internal table.

Table types: Just like a structure, but it is only for an internal table.

Lock objects: Objects that synchronize access to the same data by more than one user/program. Hence, it avoid the inconsistency when data is being maintained in the database. Domain: This is the technical type of a field which is used by a group of data elements as discussed before.