Creating A Program: Tcode: Se38

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

Creating a Program:

TCode: se38
After clicking the save button a popup screen will appear, from that select the „Local object‟
option to assign the program to the temporary development class. Once this is achieved, the
coding screen is reached.

Write Statements
Output Individual Fields

Chaining Statements Together

Declaring Variables
There are some rules to be followed when dealing with variables:
They must begin with a letter.
Can be a maximum size of 30 characters,
Cannot include + , : or ( ) in the name,
Cannot use a reserved word.
Constants
A constant is a variable whose associated value cannot be altered by the program during its
execution, hence the name
Arithmetic – Addition

Arithmetic – Subtraction

Arithmetic – Division

Arithmetic – Multiplication
Additionally to these methods, the statements ADD, SUBTRACT, DIVIDE and MULTIPLY can
be used. The syntax for these is slightly different. Beneath the first calculation (where integer01
and packed_decimal01 where added), write a new line of code “ADD 8 to result.” (Ignore the
comment line in the image):

While this is a legitimate method for calculations, it must be added that this is very rarely used,
as the initial method is much simpler.

Remainder from division


Character Strings
two elementary data types used for character strings. These are data type C, and data type N.

Data type C variables are used for holding alphanumeric characters, with a minimum of 1
character and a maximum of 65,535 characters. By default, these are aligned to the left.

The other common generic character string data type is N. data type NUMC, with a length
of 8.

This data type, then, is ideal when the field is only to be used for numbers with no intention of
carrying out cal-culations.

String Manipulation

Concatenating String Fields


Condensing Character Strings
Finding the Length of a String
Searching for Specific Characters
The SHIFT statement
Splitting Character Strings
SubFields

Concatenate
Condense

NO-GAPS

Find the Length of a String

Replace

Search

Shift
Split

Date and Time Fields


Program Flow Control and Logical Expressions
Control Structures
If Statement
Nested If Statements

Case Statement

Select Loops
Do Loops

Nested Do Loops

While Loops

Nested While Loops


Loop Termination – CONTINUE

Loop Termination – EXIT


ABAP Program Events In SAP
INITIALIZATION
Called after the abap selection screen code has been processed (i.e. parameters, select-options etc) but before
these are displayed to the user. So you can use it to initialize input fields of the selection screen or change the
default values of these before the user gets to enter data into them.

AT SELECTION SCREEN OUTPUT


This is called just before the selection screen is displayed and can be used to manipulate the actual selection
screen attributes using teh loop at screen functionality. This allows you to do things like hide fields, grey them
out so they are output only or make them intensified etc.

LOOP AT SCREEN.
IF SCREEN-name = 'P_FIELd1'.
SCREEN-INTENSIFIED = '1'.
MODIFY SCREEN.
CONTINUE.
ENDIF.
ENDLOOP.

AT SELECTION-SCREEN.
This event is triggered when the user presses enter on the report selection screen and is mainly used to add
processing related to screen validation. Within the AT SELECTION SCREEN event you have not left the
selection screen, which allows you to manipulate the values contained within sel screen parameters or stop the
program and return the user to the selection screen by displaying an error message.

AT SELECTION-SCREEN ON
This allows you to add processing to a selection screen field for when it is chnaged, user presses F1 or F4 etc
using the following parameters

<parameter1>
AT SELECTION-SCREEN ON Block <block1>
AT SELECTION-SCREEN ON HELP-REQUEST for <parameter1> (i.e. When press F1)
AT SELECTION-SCREEN ON VALUE-REQUEST for <parameter1> (i.e. When press F4)
AT SELECTION-SCREEN ON RADIOBUTTON for <parameter1> (i.e. When press F4)

AT SELECTION-SCREEN ON P_FIELD1.
AT SELECTION-SCREEN ON help-request for P_FIELD1.

START-OF-SELECTION
This event is called when . If the user executes the program either by pressing the execute button or F8 this is
the first event triggered after all screen selection processing has been completed (AT Selection...). So pressing
execute triggers both AT SELECTION and then START-OF-SELECTION

If no other events are declared then there is no need to manually code this event as all processing statements
will be automatically assigned to an implicit START-OF-SELECTION block. It is a good ideal to put it in though
as it separates the code and makes it easier to read. Generally you would put all you data selection ABAP code
within this event.

END-OF-SELECTION
If your report is linked to a logical database this event is called after the logical database has completely
finished its work. Otherwise this event is trigged after the START-OF-SELECTION event so you would
generally use it to processes the data retrieved in that event.

You might also like