Skip to main content
  1. Documentation/

Instructions in ABAP

··20 mins· loading · loading · · ·
SAP ERP Back-End
Adrien D'acunto
Author
Adrien D’acunto
Table of Contents

Instructions in ABAP
#

Messages
#

Objectives
#

  • Understand the use of SAP MESSAGES in ABAP
  • Identify different types of MESSAGES: Informative, Warning, Error, Success
  • Know how to use DISPLAY LIKE option to change appearance
  • Create and reference TEXT ELEMENTS for MESSAGES
  • Create and use MESSAGES via transaction SE91

Definition
#

A MESSAGE is an ABAP instruction allowing you to display information to the user during program execution. MESSAGES can be informative, warning, error or success, each with different impact on the program.

A MESSAGE is like a lit sign: depending on its color and position, it attracts more or less attention and may or may not block user action.

Types of Messages
#

Informative Message (i)
#

WRITE:/ ’ - MESSAGE TYPE I…'.

MESSAGE 'This is an informative MESSAGE.' TYPE 'I'.
  • Displays simple popup window or MESSAGE at bottom left.

Like a post-it on board indicating non-urgent information.

Warning Message (w)
#

WRITE:/ ’ - MESSAGE TYPE W…'.

MESSAGE 'Warning: Risky operation!' TYPE 'W'.
  • Yellow or red MESSAGE, but not blocking.

Like blinking warning light to attract attention.

Error Message (e)
#

WRITE:/ ’ - MESSAGE TYPE E…'.

MESSAGE 'Error: Operation impossible.' TYPE 'E'.
  • Red blocking MESSAGE that halts program continuation.

Like red traffic light; user must correct before continuing.

Success Message (s)
#

WRITE:/ ’ - MESSAGE TYPE I…'.

MESSAGE 'Success.' TYPE 'S'.
  • Green MESSAGE indicating success.

Like green light or validation badge.

Using DISPLAY LIKE
#

Allows displaying a MESSAGE of different type from its actual type:

WRITE:/ ’ - MESSAGE DISPLAY LIKE…'.

MESSAGE 'This is an informative MESSAGE.' TYPE 'I' DISPLAY LIKE 'S'.

Like changing the color of lit sign without changing MESSAGE content/behavior.

Text Elements for Messages
#

  • Using TEXT ELEMENTS makes MESSAGES dynamic and modifiable without touching code.
  • Steps:
  1. Open Jump option → TEXT ELEMENTS in editable program.
  2. Go to Text Symbols tab.
  3. Fill in MESSAGE number (001) and content.
  4. Validate with Enter, save and activate.
  5. In program:

WRITE:/ ’ - MESSAGE FROM TEXT-ELEMENTS…'.

MESSAGE TEXT-001 TYPE 'I'.

TEXT ELEMENTS are like configurable signs: text can be easily changed without modifying main program.

It’s preferable to create MESSAGES in TEXT ELEMENTS as translations can be provided.

Creating Messages via SE91
#

  1. Open transaction SE91.
  2. Enter MESSAGE class name (ex: ZMSG_DEMO) and click Create if it doesn’t exist.
  3. Add MESSAGE number (ex: 001, 002, …) and define:
    • MESSAGE text
    • Type (I, W, E, S)
    • Optionally length and dynamic parameters
  4. Save and activate MESSAGE.
  5. In your ABAP program:

WRITE:/ ’ - MESSAGE FROM SE91 CLASS MSG…'.

MESSAGE e001(ZMSG_DEMO).

SE91 is like a workshop for creating lit signs: you create your sign with its text and color, and can reuse it in all your programs.

Ideal to create in MESSAGE class if program/class/function group presents multiple texts. Translations can also be provided here.

Best Practices
#

Best Practice Explanation
Always specify MESSAGE type Facilitates reading and user control
Use DISPLAY LIKE wisely Adapt attention without changing logic
Prefer TEXT ELEMENTS Makes MESSAGE dynamic and easily modifiable
Create reusable MESSAGES via SE91 Allows consistency and MESSAGE centralization
Avoid unnecessarily blocking MESSAGES Prevent unnecessary interruptions for user

Summary
#

  • MESSAGE = display SAP MESSAGE to user
  • Types: I, W, E, S
  • DISPLAY LIKE allows modifying appearance without changing type
  • TEXT ELEMENTS make MESSAGES dynamic and easy to maintain
  • SE91 allows creating reusable MESSAGES in multiple programs

Each color and type indicates a level of importance.


Calculation Instruction
#

Objectives
#

  • Understand arithmetic operations in ABAP
  • Use operators =, +, -, *, / for calculations
  • Know corresponding instructions MOVE, ADD, SUBTRACT, MULTIPLY, DIVIDE
  • Visualize and apply calculations in ABAP program

Definition
#

Like in any programming language, numeric variables (N, I, P, etc.) can be used in arithmetic operations.

Numeric variables are like boxes containing numbers, and operations are machines that manipulate these numbers: addition, subtraction, multiplication, division.

Arithmetic Operators
#

OPERATION SIGN ABAP INSTRUCTION
EQUAL = MOVE
ADDITION + ADD ... TO ...
SUBTRACTION - SUBTRACT ... FROM ...
MULTIPLICATION * MULTIPLY ... BY ...
DIVISION / DIVIDE ... BY ...

Mathematical expressions with =, +, -, *, / are more readable than MOVE, ADD instructions, etc.

= (equal) or MOVE … TO …
#

DATA: lv_a TYPE I,
     lv_b TYPE I,
     lv_c TYPE I,
     lv_d TYPE I.

lv_a = 3.
lv_b = lv_a.

MOVE 5    TO lv_c.
MOVE lv_c TO lv_d.

WRITE:/ 'Value of lv_a: ', lv_a,
      / 'Value of lv_b: ', lv_b,
      / 'Value of lv_c: ', lv_c,
      / 'Value of lv_d: ', lv_d.
  • = and MOVE assign a value to variable

= = put object directly in box MOVE = move object from one box to another

Multiple MOVE
#

MOVE: 5 TO lv_c,
      lv_c TO lv_d.
  • Assigns multiple values successively

+ (plus) or ADD … TO …
#

DATA: lv_a(2) TYPE I.

lv_a = 5 + 2.
ADD 7 TO lv_a.

- (minus) or SUBTRACT … FROM …
#

DATA: lv_a(2) TYPE I,
      lv_b(2) TYPE I.

lv_a = 5 + 2.
lv_b = lv_a - 3.
SUBTRACT 3 FROM lv_b.

* (multiplication) or MULTIPLY … BY …
#

DATA: lv_a(2) TYPE I,
      lv_b(2) TYPE I,
      lv_c(2) TYPE I.

lv_a = 5 + 2.
lv_b = lv_a - 3.
lv_c = lv_a * lv_b.
MULTIPLY lv_c BY 2.

/ (division) or DIVIDE … BY …
#

DATA: lv_a(2) TYPE I,
      lv_b(2) TYPE I,
      lv_c(2) TYPE I,
      lv_d(2) TYPE I.

lv_a = 5 + 2.
lv_b = lv_a - 3.
lv_c = lv_a * lv_b.
lv_d = lv_c / 2.
DIVIDE lv_d BY 7.
  • Visualize each variable as box containing number
  • Each operation = action on box: add, subtract, multiply or divide
  • Prefer expressions (+, -, *, /) for readability
  • MOVE, ADD, SUBTRACT, etc., remain useful for historical or explicit instructions

Best Practices
#

Best Practice Explanation
Prefer arithmetic operators More readable and concise
Always initialize variables Avoids undefined values
Check data types Avoid errors during division or multiplication
Use MOVE / ADD for clarity Useful in maintenance and readable code

Summary
#

  • Numeric variables (I, N, P, F, DECFLOAT) can undergo arithmetic operations
  • Operators: =, +, -, *, /
  • Historical instructions: MOVE, ADD, SUBTRACT, MULTIPLY, DIVIDE
  • Prefer expressions for readability
  • Always initialize variables and check type before calculations

Replace
#

Objectives
#

  • Understand use of REPLACE instruction in ABAP
  • Replace pattern string with another new in source string dobj
  • Use FIRST OCCURRENCE or ALL OCCURRENCES options
  • Master REPLACEMENT COUNT, REPLACEMENT OFFSET, REPLACEMENT LENGTH and RESULTS parameters

Definition
#

REPLACE finds word or pattern in string and replaces it with another.

Like correcting word in text by replacing it with correct word.

REPLACE can act on first occurrence only or all occurrences of pattern. You can also know how many replacements were done and where last replacement occurred.

Syntax
#

REPLACE [ {FIRST OCCURRENCE} | {ALL OCCURRENCES} OF ] pattern
        IN [ section_of ] dobj
        WITH new
        [ IN { BYTE | CHARACTER } MODE ]
        [ { RESPECTING | IGNORING } CASE ]
        [ REPLACEMENT COUNT rcnt ]
        { { [ REPLACEMENT OFFSET roff ] [ REPLACEMENT LENGTH rlen ] } | [ RESULTS result_tab|result_wa ] }.
  • FIRST OCCURRENCE: replace first occurrence only
  • ALL OCCURRENCES: replace all occurrences
  • IN section_of: replace in specific portion of string
  • IN BYTE|CHARACTER MODE: character reading mode
  • RESPECTING|IGNORING CASE: case-sensitive or not
  • REPLACEMENT COUNT rcnt: number of replacements made
  • REPLACEMENT OFFSET roff: position of last replacement
  • REPLACEMENT LENGTH rlen: length of replaced pattern
  • RESULTS result_tab|result_wa: stores result in table or structure

Visualize your string as text page where each word can be corrected or replaced. FIRST OCCURRENCE = change first found word, ALL OCCURRENCES = all identical words.

Basic Example
#

DATA: lv_text1 TYPE STRING,
      lv_text2 TYPE STRING.

lv_text1 = lv_text2 = 'ABADAFAX'.

REPLACE FIRST OCCURRENCE OF 'A' IN lv_text1 WITH 'I'.
REPLACE ALL OCCURRENCES OF 'A' IN lv_text2 WITH 'O'.

WRITE: / 'lv_text1 = ', lv_text1,
       / 'lv_text2 = ', lv_text2.

Like correcting typo in sentence: first REPLACE changes only first ‘A’, second corrects all ‘A’s.

Example - Replacement Count
#

DATA: lv_text TYPE STRING.

lv_text = 'ABADAFAX'.

REPLACE ALL OCCURRENCES OF 'A' IN lv_text WITH 'I'
    REPLACEMENT COUNT DATA(lv_count).

WRITE: / 'Number of replacements = ', lv_count.

REPLACEMENT COUNT lets you know how many modifications were made.

Example - Replacement Offset
#

DATA: lv_text1 TYPE STRING,
      lv_text2 TYPE STRING.

lv_text1 = lv_text2 = 'ABADAFAX'.

REPLACE FIRST OCCURRENCE OF 'A' IN lv_text1 WITH 'I'
    REPLACEMENT OFFSET DATA(lv_offset1).

REPLACE ALL OCCURRENCES OF 'A' IN lv_text2 WITH 'I'
    REPLACEMENT OFFSET DATA(lv_offset2).

WRITE: / 'Offset of first replacement = ', lv_offset1,
       / 'Offset of last replacement = ', lv_offset2.

Like noting exact position of correction in text to know where it is.

Example - Combination
#

DATA: lv_text TYPE STRING.

lv_text = 'ABADAFAX'.

REPLACE ALL OCCURRENCES OF 'A' IN lv_text WITH 'I'
    REPLACEMENT COUNT DATA(lv_count)
    REPLACEMENT OFFSET DATA(lv_offset1).

WRITE: / 'Text after replacement = ', lv_text,
       / 'Number of replacements = ', lv_count,
       / 'Position of last replacement = ', lv_offset1.

To modify string while tracking number of replacements and position of last change.

Summary
#

  • REPLACE = find and replace pattern in string
  • Can modify first occurrence or all occurrences
  • Useful parameters: REPLACEMENT COUNT, REPLACEMENT OFFSET, LENGTH, RESULTS

Like correcting text and tracking modifications made


Write
#

Objectives
#

  • Understand use of WRITE command in ABAP
  • Display text and variable values in output window
  • Combine fixed text, variables and system fields
  • Organize display on multiple lines
  • Use simple formatting options (length, justification)

Definition
#

WRITE command displays information in output window or SAP reports. You can display text, variable values or system fields.

WRITE acts like speaker or whiteboard: takes what you give it and shows it to user. Messages and variables are contents that speaker broadcasts.

Basic Example
#

DATA: lv_message1 TYPE string,
      lv_message2 TYPE string,
      lv_message3 TYPE string.

START-OF-SELECTION.

  " Define message
  lv_message1 = 'Welcome to my SAP report!'.
  lv_message2 = 'All is well!'.
  lv_message3 = 'Thank you for your attention'.

  " Display messages
  WRITE:/ lv_message1.
  WRITE:/ lv_message2,
        / lv_message3.
  • /: indicates new line
  • Multiple variables can be displayed on same line or multiple lines

Each / = line break on sheet of paper.

Display System Variables
#

WRITE:/ 'ABAP System Information',
      / 'Client:    ', sy-mandt,
      / 'User:      ', sy-uname,
      / 'Date:      ', sy-datum,
      / 'Time:      ', sy-uzeit.
  • sy-mandt: current client
  • sy-uname: connected user
  • sy-datum: system date (YYYYMMDD)
  • sy-uzeit: system time (HHMMSS)

Visualize these fields as header of official report. They are automatically generated by SAP.

Formatting Options
#

  • Justification: WRITE lv_var LEFT or WRITE lv_var RIGHT
  • Length: WRITE lv_var LENGTH 10
  • Combine text and variable: WRITE: / 'Name:', lv_name, 'Age:', lv_age.

Think of WRITE as whiteboard where you place text and values exactly where you want them to appear.

Best Practices
#

Best Practice Explanation
Use / to separate lines Facilitates report reading
Add explicit messages User better understands context
Combine text and variables clearly Avoid confusion in reports
Display system fields if useful Provides automatic context for report

Summary
#

  • WRITE = display text or values in SAP output
  • / = new line
  • Can display variables, fixed text and system fields
  • Options: justification, length, multiple combination

Like speaker or whiteboard, each WRITE directly shows information to user.


Concatenate
#

Objectives
#

  • Understand use of CONCATENATE in ABAP
  • Concatenate multiple character strings
  • Use SEPARATED BY and RESPECTING BLANKS options
  • Store result in variable

Definition
#

CONCATENATE merges multiple character strings or internal table lines and stores result in target variable.

Like gluing multiple text pieces on sheet to form complete sentence.

Syntax
#

CONCATENATE [ {dobj1 dobj2 ...} | {LINES OF itab} ]
    INTO result
    [IN {BYTE|CHARACTER} MODE]
    [SEPARATED BY sep]
    [RESPECTING BLANKS].
  • dobj1, dobj2…: strings or variables to concatenate
  • LINES OF itab: concatenates all internal table lines
  • INTO result: variable to store result
  • IN BYTE|CHARACTER MODE: character processing mode (rarely used)
  • SEPARATED BY sep: separation character between elements
  • RESPECTING BLANKS: preserves spaces in each string
  • IN BYTE MODE = work in “pure byte” mode, like manipulating letters in binary
  • SEPARATED BY = add small separator between each word, like dash or comma
  • RESPECTING BLANKS = preserve exactly intended space for each word, useful for flat files or bank formats

Example
#

CONSTANTS: lc_text1(20) TYPE C VALUE 'Hello',
           lc_text2(20) TYPE C VALUE 'World',
           lc_text3(20) TYPE C VALUE 'Welcome',
           lc_text4(20) TYPE C VALUE 'on',
           lc_text5(20) TYPE C VALUE 'SAP'.

DATA: lv_result1(50) TYPE C,
      lv_result2(50) TYPE C,
      lv_result3(100) TYPE C.

" Simple CONCATENATE
CONCATENATE lc_text1 lc_text2 lc_text3 lc_text4 lc_text5
  INTO lv_result1.

" CONCATENATE with separator
CONCATENATE lc_text1 lc_text2 lc_text3 lc_text4 lc_text5
  INTO lv_result2
  SEPARATED BY '-'.

" CONCATENATE respecting spaces
CONCATENATE lc_text1 lc_text2 lc_text3 lc_text4 lc_text5
  INTO lv_result3
  RESPECTING BLANKS.

WRITE:/ 'Without option:     ', lv_result1,
      / 'SEPARATED BY:       ', lv_result2,
      / 'RESPECTING BLANKS:  ', lv_result3.
  • First CONCATENATE: glue words together without extra space
  • Second: glue words with dash between each word
  • Third: glue words while preserving all defined spaces, like fixed boxes on sheet

Visualize each word as card to glue on sheet

  • SEPARATED BY = add visible space or separator
  • RESPECTING BLANKS = respect exactly word width
  • Internal tables can be merged automatically line by line with LINES OF itab

Summary
#

  • CONCATENATE = merge multiple strings into variable
  • Important options: SEPARATED BY, RESPECTING BLANKS

Like gluing cards or words on sheet to form complete text


Condense
#

Objectives
#

  • Understand use of CONDENSE instruction in ABAP
  • Remove superfluous spaces in character string
  • Use NO-GAPS option to remove all spaces

Definition
#

CONDENSE reduces unnecessary spaces in character string.

Like pushing all words together to avoid empty spaces, or folding sheet so all text fits without unnecessary space.

Syntax
#

CONDENSE text [NO-GAPS].
  • text: variable containing string to process
  • NO-GAPS: removes all spaces, including those between words
  • Without NO-GAPS = keep single space between each word
  • With NO-GAPS = glue all words together

Example
#

CONSTANTS: lc_text1(20) TYPE C VALUE 'Hello    ',
           lc_text2(20) TYPE C VALUE '    World    ',
           lc_text3(20) TYPE C VALUE '    Welcome    ',
           lc_text4(20) TYPE C VALUE '    on    ',
           lc_text5(20) TYPE C VALUE '    SAP    '.

DATA: lv_result(50) TYPE C.

" Initial concatenation
CONCATENATE lc_text1 lc_text2 lc_text3 lc_text4 lc_text5
  INTO lv_result.

WRITE:/ 'Without CONDENSE:         ', lv_result.

" CONDENSE to remove superfluous spaces
CONDENSE lv_result.
WRITE:/ 'With CONDENSE:            ', lv_result.

" CONDENSE NO-GAPS to remove all spaces
CONDENSE lv_result NO-GAPS.
WRITE:/ 'With CONDENSE NO GAPS:    ', lv_result.
  • First display: text with all added spaces
  • CONDENSE: remove superfluous spaces but keep single space between words
  • CONDENSE NO-GAPS: glue all words together without any space
  • Visualize string as line of words with too much space
  • CONDENSE = reorganize line to keep only minimal space
  • NO-GAPS = completely eliminate all spaces
  • Very useful after CONCATENATE to clean text before display or processing

Summary
#

  • CONDENSE = remove unnecessary spaces in variable
  • NO-GAPS = remove all spaces

Like folding text so it’s compact and readable


Split
#

Objectives
#

  • Understand use of SPLIT instruction in ABAP
  • Separate character string according to defined separator
  • Store result in VARIABLES or internal table

Definition
#

SPLIT cuts character string according to separator and stores each part in variable or internal table.

Like taking sentence and cutting each word to put in separate boxes.

Syntax
#

SPLIT dobj
  AT sep
  INTO { {result1 result2 ...} | {TABLE itab} }
  [IN {BYTE|CHARACTER} MODE].
  • dobj: character string to split
  • AT sep: separator character
  • INTO result1 result2 …: variables to receive pieces
  • INTO TABLE itab: internal table to receive all pieces
  • IN BYTE|CHARACTER MODE: character processing mode
  • IN BYTE MODE = work in pure binary mode (rarely used)
  • IN CHARACTER MODE = work on characters like letters

Basic Example
#

DATA: lv_text1(20) TYPE C,
      lv_text2(20) TYPE C,
      lv_text3(20) TYPE C,
      lv_text4(20) TYPE C,
      lv_text5(20) TYPE C.

CONSTANTS: lc_string(50) TYPE C VALUE 'Hello World Welcome on SAP'.

SPLIT lc_string
  AT space
  INTO lv_text1 lv_text2 lv_text3 lv_text4 lv_text5.

WRITE:/ 'lv_text1: ', lv_text1,
      / 'lv_text2: ', lv_text2,
      / 'lv_text3: ', lv_text3,
      / 'lv_text4: ', lv_text4,
      / 'lv_text5: ', lv_text5.

Each word in sentence is put in distinct box

Dynamic Declaration
#

  • Variables can be created directly in SPLIT instruction
CONSTANTS: lc_string(50) TYPE C VALUE 'Hello World Welcome on SAP'.

SPLIT lc_string AT space
  INTO DATA(lv_text1)
      DATA(lv_text2)
      DATA(lv_text3)
      DATA(lv_text4)
      DATA(lv_text5).
  • Variables lv_text1 to lv_text5 are automatically of type STRING

  • For internal table:

CONSTANTS: lc_string(50) TYPE C VALUE 'Hello World Welcome on SAP'.

SPLIT lc_string AT space INTO TABLE DATA(tab_result).

Each word becomes list element

  • Visualize string as sentence to cut into words
  • SPLIT is opposite of CONCATENATE: go from complete sentence to pieces
  • Very useful for analyzing or transforming text data

Summary
#

  • SPLIT = cut string according to separator
  • Result in individual variables or internal table

Like putting each word in separate box or list


Find
#

Objectives
#

  • Understand use of FIND instruction in ABAP
  • Search character string pattern in source string dobj
  • Identify first occurrence or all occurrences
  • Use MATCH COUNT, MATCH OFFSET, MATCH LENGTH, and RESULTS options

Definition
#

FIND locates words or patterns in sentence.

Like finding specific word in text to know where it is or how many times it appears.

Syntax
#

FIND [ {FIRST OCCURRENCE} | {ALL OCCURRENCES} OF ] pattern
    IN [SECTION OFFSET i1 LENGTH i2 OF] dobj
    [IN {BYTE|CHARACTER} MODE]
    [ {RESPECTING | IGNORING} CASE]
    [MATCH COUNT mcnt]
    { { [MATCH OFFSET moff] [MATCH LENGTH mlen] } | [RESULTS lt_tab|ls_structure] }.
  • FIRST OCCURRENCE: search first occurrence
  • ALL OCCURRENCES: search all occurrences
  • IN SECTION OFFSET i1 LENGTH i2 OF dobj: search in specific string portion
  • IN BYTE|CHARACTER MODE: character reading mode (rarely used)
  • RESPECTING|IGNORING CASE: case-sensitive or not
  • MATCH COUNT mcnt: number of times pattern found
  • MATCH OFFSET moff: pattern position in string
  • MATCH LENGTH mlen: length of found pattern
  • RESULTS lt_tab|ls_structure: stores result in table or structure

Frame search in precise text passage and note at what position searched word appears.

Example - Offset and Length
#

DATA lv_text TYPE STRING.

lv_text = 'ABADAFAX'.

FIND FIRST OCCURRENCE OF 'A'
    IN SECTION OFFSET 2 LENGTH 4 OF lv_text
    RESULTS DATA(ls_result).

WRITE: /'OFFSET = ', ls_result-OFFSET,
       /'LENGTH = ', ls_result-LENGTH.

Like searching word in limited paragraph to few lines.

Example - Match Count
#

DATA: lv_count TYPE I,
      lv_text  TYPE STRING.

lv_text = 'ABADAFAX'.
FIND ALL OCCURRENCES OF 'A' IN lv_text MATCH COUNT lv_count.

WRITE: 'lv_count = ', lv_count.

Like counting how many times word appears in sentence.

Example - Match Offset
#

DATA: lv_offset1 TYPE I,
      lv_offset2 TYPE I,
      lv_text    TYPE STRING.

lv_text = 'ABADAFAX'.

FIND ALL OCCURRENCES OF 'A' IN lv_text MATCH OFFSET lv_offset1.
FIND FIRST OCCURRENCE OF 'A' IN lv_text MATCH OFFSET lv_offset2.

WRITE:  'lv_offset1 = ', lv_offset1,
      / 'lv_offset2 = ', lv_offset2.

Like noting word position in sentence to know where it begins or ends.

Example - Combination
#

DATA: lv_text TYPE STRING.

lv_text = 'ABADAFAX'.

FIND ALL OCCURRENCES OF 'A' IN lv_text
    MATCH COUNT DATA(lv_count).

FIND ALL OCCURRENCES OF 'A' IN lv_text
    MATCH OFFSET DATA(lv_offset1).

FIND FIRST OCCURRENCE OF 'A' IN lv_text
    MATCH OFFSET DATA(lv_offset2).

WRITE: /'lv_count   = ', lv_count,
       /'lv_offset1 = ', lv_offset1,
       /'lv_offset2 = ', lv_offset2.

Know how many times word appears and at exact position.

  • Visualize string as sentence to scan for word
  • FIRST OCCURRENCE = first found word
  • ALL OCCURRENCES = all found words
  • MATCH COUNT = how many words
  • MATCH OFFSET = word position in sentence

Summary
#

  • FIND = search pattern in string
  • Can return position, length, occurrence count, or results in structure/table

Like scanning text to identify and locate precise words


Translate
#

Objectives
#

  • Understand use of TRANSLATE for text manipulation
  • Know how to convert string to uppercase or lowercase
  • Know how to apply transformation mask on string

Definition
#

TRANSLATE modifies case or applies mask on character string.

Like taking sentence and transforming it entirely to uppercase, lowercase, or according to precise substitution code.

UPPER / LOWER parameters are useful for standardizing text before comparison or display. USING mask lets you transform letter by letter according to specific logic.

Syntax
#

TRANSLATE text {TO {UPPER | LOWER} CASE} | {USING mask}.
  • TO UPPER CASE: converts all characters to uppercase
  • TO LOWER CASE: converts all characters to lowercase
  • USING mask: applies transformation logic defined by mask
  • UPPER = write everything in capital letters
  • LOWER = write everything in lowercase
  • USING mask = apply special substitution code letter by letter, like coded message

Basic Example
#

DATA: lv_text1 TYPE STRING,
      lv_text2 TYPE STRING.

lv_text1 = lv_text2 = 'Hello World'.

TRANSLATE lv_text1 TO UPPER CASE.
TRANSLATE lv_text2 TO LOWER CASE.

WRITE: / 'lv_text1 = ', lv_text1,
       / 'lv_text2 = ', lv_text2.
  • lv_text1 → HELLO WORLD
  • lv_text2 → hello world

Transform sentence to uppercase or lowercase to standardize writing.

Very useful before comparing two strings to avoid errors due to case.

Example with Mask
#

DATA: lv_text3 TYPE STRING.

lv_text3 = 'Barbcbdbarb'.

TRANSLATE lv_text3 USING 'ABBAabba'.

WRITE: / 'lv_text3 = ', lv_text3.
  • Mask ABBAabba:

    • A → B
    • B → A
    • a → b
    • b → a
  • Final result: Abracadabra

Replace certain letters with others according to precise code, like substitution game or coded message.

Mask acts letter by letter, replacing each found character with corresponding one in mask. Practical for correcting or transforming strings according to defined pattern.

Verify that target variable is STRING type to avoid errors.

Summary
#

  • TRANSLATE = modify case (UPPER / LOWER) or apply mask (USING)
  • Allows standardizing or transforming text before processing
  • Results stored directly in target variable
  • USING mask allows complex letter-by-letter transformations
  • Advised usage: normalize text before comparison, display or automatic processing

Clear
#

Objectives
#

  • Understand role of CLEAR to reinitialize variables
  • Know how to reinitialize one or multiple variables simultaneously
  • Apply CLEAR on different data types: strings, numerics, dates, times

Definition
#

CLEAR reinitializes or removes variable content.

Like emptying box content to reuse it.

CLEAR instruction resets each variable to default value according to its type

  • String → empty (’’)
  • Numeric → 0
  • Date → 00000000
  • Time → 000000

Syntax
#

CLEAR dobj.
  • dobj: variable or list of variables to reinitialize

Set all box objects to zero or empty before starting new use.

Reinitialize variables before calculation or repetitive processing to avoid residual values.

Example
#

DATA: lv_result(50) TYPE C,
      lv_int(5)     TYPE I,
      lv_date       TYPE D,
      lv_hour       TYPE T.

lv_result = 'Hello World'.
lv_int    = 5.
lv_date   = SY-DATUM.
lv_hour   = SY-UZEIT.

WRITE:/ 'Before CLEAR'.
WRITE:/ 'Result: ', lv_result.
WRITE:/ 'Integer: ', lv_int.
WRITE:/ 'Date: ', lv_date.
WRITE:/ 'Time: ', lv_hour.

CLEAR: lv_result,
       lv_int,
       lv_date,
       lv_hour.

WRITE:/.
WRITE:/ 'After CLEAR'.
WRITE:/ 'Result: ', lv_result.
WRITE:/ 'Integer: ', lv_int.
WRITE:/ 'Date: ', lv_date.
WRITE:/ 'Time: ', lv_hour.

After CLEAR, all boxes are empty and ready to receive new information.

  • CLEAR works on all variable types: strings, numerics, dates, times…
  • Can CLEAR multiple variables at once by separating with commas
  • Very useful to reinitialize before new calculation or data processing

Even if variable is already empty or zero, CLEAR is safe and has no side effects.

Summary
#

  • CLEAR removes variable content
  • Reinitializes all variables to default values
  • Can handle one or multiple variables simultaneously
  • Advised usage to avoid value residues before new processing

Offset (Reorganization)
#

Objectives
#

  • Understand OFFSET functionality for extracting substrings
  • Know how to manipulate start position and number of characters to extract
  • Apply OFFSET to reorganize strings, for example dates

Definition
#

OFFSET selects specific portion of character string from given position and defined number of characters.

Like taking piece of baguette from certain position and certain length.

Each character in string has position, starting at 0. OFFSET allows saying: “I want to start here and take that many characters.”

Syntax
#

Variable[+pos](nbre)
  • pos: start position in string (0 = first position)
  • nbre: number of characters to extract

Like cutting sentence from precise word and take only few letters or words.

Position always starts at 0, otherwise you risk retrieving wrong character.

Example: Reorganize Date
#

DATA: lv_date(10) TYPE C.

CONCATENATE SY-DATUM+6(2)
            SY-DATUM+4(2)
            SY-DATUM(4)
  INTO lv_date
  SEPARATED BY '-'.

CONDENSE lv_date NO-GAPS.

WRITE:/ SY-DATUM,
      / lv_date.
  • SY-DATUM+6(2): from 6th position, take 2 characters → day
  • SY-DATUM+4(2): from 4th position, take 2 characters → month
  • SY-DATUM(4): take first 4 characters → year

Take date in YYYYMMDD format, cut pieces corresponding to day, month and year, then rearrange in new order in new box.

  • First position in string always starts at 0
  • Very useful to reformat strings, extract substrings or manipulate dates
  • Often combined with CONCATENATE to rebuild string in new order

Like cutting puzzle elements to put them back in order you want.

Summary
#

  • Variable+pos extracts portion of string
  • pos indicates start position
  • nbre indicates number of characters to take
  • Very useful to reorganize and reformat strings, notably dates or codes

Related

Introduction to ABAP
·14 mins· loading · loading
SAP ERP Back-End
ABAP Program Structure
··12 mins· loading · loading
SAP ERP Back-End
ABAP Variables & Declarations in ABAP
··11 mins· loading · loading
SAP ERP Back-End
Dracula Theme
·1 min· loading · loading
SAP ERP
Business Functions and SAP - Complete Guide
··7 mins· loading · loading
ERP SAP
Introduction to SAP
··6 mins· loading · loading
ERP SAP