Showing posts with label BASIC. Show all posts
Showing posts with label BASIC. Show all posts

Monday, March 13, 2017

Order of ABAP Events


Although there are subroutine that makes our code easier to maintain by modularize the program into modular units or logical blocks. There are some default blocks that help in controlling the flow of the program. These blocks are known as there are some ABAP events and they run in sequence.



LOAD-OF-PROGRAM
The first triggered event is load-of-program that runs before any other ABAP code. The purpose is to load the program into system memory so that the program can be executed. However, this event only available for program with the type of 1, M, F, or S.

INITIALIZATION.
Initialization will be the next event after Load-Of-Program. But, it will be the first triggered event if the program does not have load-of-program event. This event allow us to initialize values of variables or input fields of the selection screen.

AT SELECTION-SCREEN.
Before the selection screen is displayed, this event is usually called to validate done on selection screen. Moreover, it can be used to manipulate the actual screen in order to make a dynamic selection screen that can hide/disable some parameter by the use of loop at screen funcion.

START-OF-SELECTION.
This event is the first event that is triggered right after the user executes the program by pressing execute button (F8). It is before any GET events or any other event processing blocks. This will be started automatically when there is no other event keywords coded.

END-OF-SELECTION.
This event is triggered after all logical database records have been read or once the START-OF-SELECTION is finished. The purpose of this is generally only for the summary/results of reports.

TOP-OF-PAGE.
This event is used on basic list only in order to create a header.

END-OF-PAGE.
On the contrary, this event is used to create a footer.

AT LINE-SELECTION.
After the screen list has been displayed, the user can select on a list line by double click it or F2 to display a secondary list.

AT PFn (n is number between 01-24)
This is the event which is triggered by function key to perform interactive action.

AT USER-COMMAND.
This event triggered when toolbar button is pushed.



Source:
http://saptechsrs.blogspot.co.id/2011/10/abap-events-in-report-programming.html
http://loveabap.blogspot.co.id/2012/04/abap-flow-of-events-1.html
http://www.sapdev.co.uk/abap/abap-events.htm

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 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.
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 = strlen( surname ).
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'.
DATA: a(10) TYPE c,
      b(10) TYPE c,
      c(10) TYPE C, a 1234 
      sep2(2) TYPE c VALUE '**'. b  ABCD
SPLIT mystring AT sep2 INTO a b c. c 6789
SUBFIELDS DATA: int_tel_num(17) TYPE c VALUE '+62-812345678',
      country_code(3) TYPE c,
      tel_num(14) TYPE 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.

Tuesday, January 31, 2017

Hello World!

Hello World! This is the first post i just published on the day i made this blog on 31th January 2017. I believe most of the readers here have been familiar with my "Hello World!" phrase which is used in your very first program with a particular new language and here I will share my knowledge in ABAP language in this blog for everyone to learn.

If you haven't heard of ABAP, it is stands for Advanced Business Application Programming, originally Allgemeiner Berichts-Aufbereitungs-Prozessor in German, a high-level programming language created by the German software company, SAP SE. Hence, it can only be used in its ERP Software's environment, SAP for customisations of feature implementation in it.

By the way, my name is Evan Christiawan, I am a graduate student from Murdoch University majoring in Computer Science and Cyber Forensics. Currently, I work as ABAP technical consultant at Soltius Indonesia, a subsidiary of Metrodata Group that focuses its business in dealing with SAP Solution to help companies run better.

I think that's all for the introduction and won't introduce more about me unless you want to know me more :). Hopefully i can keep updating posts/notes in this blog and help lots of people who are curious in learning ABAP, a language of SAP.