ERPClimb logoERPClimb
ABAP Core
ABAP Developmentbeginner 8 min read

ABAP Core Part 2: DATA, TYPES, CONSTANTS, Work Areas and Internal Tables

Preview · a free account unlocks the full lesson

Key takeaway

Declare data the way real ECC/S/4 programs do: TYPES, DATA and CONSTANTS, dictionary types, structures (work areas) and internal tables, filling them with APPEND, CLEAR/REFRESH/FREE, and naming conventions — with the modern inline and VALUE syntax as a side note.

In this lessonShow sections

Visual overview

ABAP Core Part 2: DATA, TYPES, CONSTANTS, Work Areas and Internal Tables — learning sheetIn one line: Declare data the way real ECC/S/4 programs do: TYPES, DATA and CONSTANTS, dictionary types, structures (work areas) and internal tables, filling them with APPEND, CLEAR/REFRESH/FREE, and naming conventions — with the modern inline and VALUE syntax as a side note.ERPClimb.com / ABAP / LESSON 2/10 / LEARNING SHEETABAP Core Part 2: DATA, TYPES, CONSTANTS, Work Areas andInternal Tables1 · IN ONE LINEDeclare data the way real ECC/S/4 programs do: TYPES, DATA and CONSTANTS, dictionary types,structures (work areas) and internal tables, filling them with APPEND, CLEAR/REFRESH/FREE,and naming conventions — with the modern inline and VALUE syntax as a side note.2 · KEY IDEAS EXPLAINEDTypes — The BlueprintTYPES: BEGIN OF ty_flight,Data — Variables, Work Areas, TablesDATA lv_count TYPE i. " elementary variableConstants — Fixed ValuesCONSTANTS lc_max_rows TYPE i VALUE 100.Filling A TableFill the work area field by field, then APPEND it:3 · DO · AVOIDBest practice!Common mistakeUse dictionary types for business fields.Declare close to first use (inline where ithelps readability).Use CONSTANTS for fixed codes.✕Declaring everything globally at the top.✕Using generic types (c LENGTH 10) instead ofdictionary types.✕Magic literals instead of constants.4 · IN A REAL PROJECTA legacy report declared 60 global variables at the top, many with TYPE c LENGTH 10 for airline and documentnumbers, and used the literal 'O' for "open" in 14 places. A change of the status code required arisky search-and-replace, and a truncated customer number caused wrong postings. The refactoring introduced…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Part 1 of this series ran a first program; now it's time to learn how to declare the data a program actually works with, which is the foundation for everything else. TYPES defines a type, which allocates no memory on its own — it just describes a shape. DATA creates a real variable from a type. CONSTANTS creates a value that never changes afterward.

A type is declared like TYPES: BEGIN OF ty_flight, carrid TYPE s_carr_id, connid TYPE s_conn_id, fldate TYPE s_date, seatsmax TYPE s_seatsmax, seatsocc TYPE s_seatsocc, END OF ty_flight, followed by TYPES ty_flights TYPE STANDARD TABLE OF ty_flight to describe a table of that structure.

Variables, work areas, and tables are then created from those types with DATA: DATA lv_count TYPE i declares an elementary variable, DATA ls_flight TYPE ty_flight declares a structure, which acts as a work area holding one row, and DATA lt_flights TYPE ty_flights declares an internal table, which holds many rows of that structure.

Most projects follow a naming convention: lv_ for a local variable, ls_ or wa_ for a structure, lt_ or it_ for a table, gv_/gs_/gt_ for global versions of each, p_ for a parameter, and s_ for a select-option.

Free account

Create a free account to keep reading

You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.

  • Full explanation
  • Code example
  • Real project scenario
  • Common mistakes
  • Best practices
  • Interview angle

One tap with Google works too. Every topic keeps its first lesson open to everyone.

Keep exploring

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.