Sap Abap

secondsky/sap-skills/plugins/sap-abap/skills/sap-abap

作者 secondsky652a861d3ed422b71f01c8805f9ec03b14017cd8GPL-3.0收錄於 2026年10月9日更新於 2026年10月9日

Comprehensive ABAP development skill for SAP systems. Use when writing ABAP code, working with internal tables, structures, ABAP SQL, object-oriented programming, RAP (RESTful Application Programming Model), CDS views, EML statements, ABAP Cloud development, string processing, dynamic programming, RTTI/RTTC, field symbols, data references, exception handling, or ABAP unit testing. Covers both classic ABAP and modern ABAP for Cloud Development patterns.

AI 產生的概覽

為傳統與雲端 SAP 版本撰寫與審查 ABAP 程式碼提供參考指引。

功能
此技能依據 SAP 速查表提供 ABAP 開發指引,涵蓋資料型別、內表、ABAP SQL、建構運算式、物件導向、例外處理、字串處理、動態程式設計、RAP/EML、CDS 檢視和單元測試。它包含從 7.40 SP08 到 ABAP Cloud 的版本相容性表、錯誤目錄、效能提示,以及 28 個隨附參考檔案。它產出的是程式碼樣式、相容性替代做法和疑難排解建議,而非可執行的成品。
適用情境
適用於撰寫或審查 ABAP 程式碼、將傳統 ABAP 現代化為相容於 ABAP Cloud 的樣式、實作 ABAP SQL 或 RAP/EML、設計單元測試,或診斷受支援版本中的語言與執行階段行為問題。
執行需求
不隨附指令碼或執行環境,僅有指示說明與 Markdown 參考檔案。代理程式不需要憑證或網路存取,但來源文件連結指向 SAP Help 與 GitHub 儲存庫。

SAP ABAP Development Skill

Related Skills

  • sap-abap-cds: Use when developing CDS views for ABAP-backed Fiori applications or defining data models with annotations
  • sap-btp-cloud-platform: Use when working with ABAP Environment on BTP or deploying ABAP applications to the cloud
  • sap-cap-capire: Use when connecting ABAP systems with CAP applications or integrating with OData services
  • sap-fiori-tools: Use when building Fiori applications with ABAP backends or consuming OData services from ABAP systems
  • sap-api-style: Use when documenting ABAP APIs or following SAP API documentation standards

When to Use This Skill

Use this skill when writing or reviewing ABAP code, modernizing classic ABAP to ABAP Cloud-compatible patterns, working with RAP or EML, implementing ABAP SQL, designing unit tests, or troubleshooting language/runtime behavior across supported ABAP releases.

Version Compatibility

This skill covers ABAP syntax from 7.40 SP08 through ABAP Cloud. Features requiring a higher release are annotated with inline comments in code examples using the format " [7.xx+] or noted in reference files. The table below summarizes the key version boundaries.

Feature7.40 SP027.40 SP057.40 SP087.507.517.527.54
Inline declarations DATA(...)xxxxxxx
Constructor operators (VALUE, NEW, CONV, COND, SWITCH, REF, EXACT, CAST)xxxxxxx
Table expressions itab[...]xxxxxxx
String templatesxxxxxxx
WITH EMPTY KEYxxxxxxx
line_exists(), line_index()xxxxxxx
ABAP SQL: @ host variablesxxxxxx
ABAP SQL: comma-separated listsxxxxxx
ABAP SQL: SQL expressions in SELECTxxxxxx
CORRESPONDING operatorxxxxxx
Table comprehensions (FOR)xxxxxx
LET expressionsxxxxxx
REDUCE operatorxxxxx
FILTER operatorxxxxx
BASE additionxxxxx
LOOP AT ... GROUP BYxxxxx
ABAP SQL: dbtab~* in SELECTxxxxx
ABAP SQL: RIGHT OUTER JOINxxxxxx
CDS views with parametersxxxxx
FINAL(...) inline declarationxxxx
Host expressions @( expr )xxxx
UNION in SELECTxxxx
IS INSTANCE OF / CASE TYPE OFxxxx
int8 typexxxx
CDS table functionsxxxx
CDS access control (implicit)xxxx
$session.user/client/system_languagexxxx
Test seams (TEST-SEAM)xxxx
Common Table Expressions (WITH)xxx
OFFSET in SELECTxxx
UPPER/LOWER in CDSxxx
Enumerated typesxxx
Internal tables as data source FROM @itabxx
WITH PRIVILEGED ACCESSxx
utclong type and functionsx

On a 7.40 system: Replace any FINAL(...) with DATA(...), and avoid 7.50+ features marked in bold above. Most modern ABAP syntax (VALUE, NEW, CONV, inline declarations, table expressions, REDUCE, FILTER, GROUP BY) is available since 7.40 SP08.

Table of Contents

Quick Reference

Data Types and Declarations

abap
" Elementary typesDATA num TYPE i VALUE 123.DATA txt TYPE string VALUE `Hello`.DATA flag TYPE abap_bool VALUE abap_true.
" Inline declarationsDATA(result) = some_method( ).FINAL(immutable) = `constant value`.              " [7.50+] Use DATA(...) on 7.40
" StructuresDATA: BEGIN OF struc,        id   TYPE i,        name TYPE string,      END OF struc.
" Internal tablesDATA itab TYPE TABLE OF string WITH EMPTY KEY.DATA sorted_tab TYPE SORTED TABLE OF struct WITH UNIQUE KEY id.DATA hashed_tab TYPE HASHED TABLE OF struct WITH UNIQUE KEY id.

Internal Tables - Essential Operations

abap
" Create with VALUEitab = VALUE #( ( col1 = 1 col2 = `a` )                ( col1 = 2 col2 = `b` ) ).
" Read operationsDATA(line) = itab[ 1 ].                    " By indexDATA(line2) = itab[ col1 = 1 ].            " By keyREAD TABLE itab INTO wa INDEX 1.READ TABLE itab ASSIGNING FIELD-SYMBOL(<fs>) WITH KEY col1 = 1.
" Modify operationsMODIFY TABLE itab FROM VALUE #( col1 = 1 col2 = `updated` ).itab[ 1 ]-col2 = `changed`.
" Loop processingLOOP AT itab ASSIGNING FIELD-SYMBOL(<line>).  <line>-col2 = to_upper( <line>-col2 ).ENDLOOP.
" DeleteDELETE itab WHERE col1 > 5.DELETE TABLE itab FROM VALUE #( col1 = 1 ).

ABAP SQL Essentials

abap
" SELECT into tableSELECT * FROM dbtab INTO TABLE @DATA(result_tab).   " @ syntax: 7.40 SP05+
" SELECT with conditionsSELECT carrid, connid, fldate                          " comma syntax: 7.40 SP05+  FROM zdemo_abap_fli  WHERE carrid = 'LH'  INTO TABLE @DATA(flights).
" Aggregate functionsSELECT carrid, COUNT(*) AS cnt, AVG( price ) AS avg_price  FROM zdemo_abap_fli  GROUP BY carrid  INTO TABLE @DATA(stats).
" JOIN operationsSELECT a~carrid, a~connid, b~carrname  FROM zdemo_abap_fli AS a  INNER JOIN zdemo_abap_carr AS b ON a~carrid = b~carrid  INTO TABLE @DATA(joined).
" Modification statementsINSERT dbtab FROM @struc.UPDATE dbtab FROM @struc.MODIFY dbtab FROM TABLE @itab.DELETE FROM dbtab WHERE condition.

Constructor Expressions

abap
" VALUE - structures and tablesDATA(struc) = VALUE struct_type( comp1 = 1 comp2 = `text` ).DATA(itab) = VALUE itab_type( ( a = 1 ) ( a = 2 ) ( a = 3 ) ).
" NEW - create instancesDATA(dref) = NEW i( 123 ).DATA(oref) = NEW zcl_my_class( param = value ).
" CORRESPONDING - structure/table mappingtarget = CORRESPONDING #( source ).target = CORRESPONDING #( source MAPPING target_field = source_field ).
" COND/SWITCH - conditional valuesDATA(text) = COND string( WHEN flag = abap_true THEN `Yes` ELSE `No` ).DATA(result) = SWITCH #( code WHEN 1 THEN `A` WHEN 2 THEN `B` ELSE `X` ).
" CONV - type conversionDATA(dec) = CONV decfloat34( 1 / 3 ).
" FILTER - table filteringDATA(filtered) = FILTER #( itab WHERE status = 'A' ).
" REDUCE - aggregationDATA(sum) = REDUCE i( INIT s = 0 FOR wa IN itab NEXT s = s + wa-amount ).

Object-Oriented ABAP

abap
" Class definitionCLASS zcl_example DEFINITION PUBLIC FINAL CREATE PUBLIC.  PUBLIC SECTION.    METHODS constructor IMPORTING iv_name TYPE string.    METHODS get_name RETURNING VALUE(rv_name) TYPE string.    CLASS-METHODS factory RETURNING VALUE(ro_instance) TYPE REF TO zcl_example.  PRIVATE SECTION.    DATA mv_name TYPE string.ENDCLASS.
CLASS zcl_example IMPLEMENTATION.  METHOD constructor.    mv_name = iv_name.  ENDMETHOD.  METHOD get_name.    rv_name = mv_name.  ENDMETHOD.  METHOD factory.    ro_instance = NEW #( `Default` ).  ENDMETHOD.ENDCLASS.
" Interface implementationCLASS zcl_impl DEFINITION PUBLIC.  PUBLIC SECTION.    INTERFACES zif_my_interface.ENDCLASS.

Exception Handling

abap
TRY.    DATA(result) = risky_operation( ).  CATCH cx_sy_zerodivide INTO DATA(exc).    DATA(msg) = exc->get_text( ).  CATCH cx_root INTO DATA(any_exc).    " Handle any exception  CLEANUP.    " Cleanup codeENDTRY.
" Raising exceptionsRAISE EXCEPTION TYPE zcx_my_exception  EXPORTING textid = zcx_my_exception=>error_occurred.
" With COND/SWITCHDATA(val) = COND #( WHEN valid THEN result                    ELSE THROW zcx_my_exception( ) ).

String Processing

abap
" ConcatenationDATA(full) = first && ` ` && last.txt &&= ` appended`.
" String templatesDATA(msg) = |Name: { name }, Date: { date DATE = ISO }|.
" FunctionsDATA(upper) = to_upper( text ).DATA(len) = strlen( text ).DATA(found) = find( val = text sub = `search` ).DATA(replaced) = replace( val = text sub = `old` with = `new` occ = 0 ).DATA(parts) = segment( val = text index = 2 sep = `,` ).
" FIND/REPLACE statementsFIND ALL OCCURRENCES OF pattern IN text RESULTS DATA(matches).REPLACE ALL OCCURRENCES OF old IN text WITH new.

Dynamic Programming

abap
" Field symbolsFIELD-SYMBOLS <fs> TYPE any.ASSIGN struct-component TO <fs>.ASSIGN struct-(comp_name) TO <fs>.  " Dynamic component
" Data referencesDATA dref TYPE REF TO data.dref = REF #( variable ).CREATE DATA dref TYPE (type_name).dref->* = value.
" RTTI - Get type informationDATA(tdo) = cl_abap_typedescr=>describe_by_data( dobj ).DATA(components) = CAST cl_abap_structdescr( tdo )->components.
" RTTC - Create types dynamicallyDATA(elem_type) = cl_abap_elemdescr=>get_string( ).CREATE DATA dref TYPE HANDLE elem_type.

Bundled Resources

This skill includes 28 comprehensive reference files covering all aspects of ABAP development:

Related Skills

  • sap-abap-cds: For CDS view development and ABAP Cloud data modeling
  • sap-btp-cloud-platform: For ABAP Environment setup and BTP deployment
  • sap-cap-capire: For CAP service integration and ABAP system connections
  • sap-fiori-tools: For Fiori application development with ABAP backends
  • sap-api-style: For API documentation standards and best practices

Quick Access

  • Reference Guide: references/skill-reference-guide.md - Complete guide to all reference files
  • Internal Tables: references/internal-tables.md - Complete table operations
  • ABAP SQL: references/abap-sql.md - Comprehensive SQL reference
  • Object Orientation: references/object-orientation.md - Classes and interfaces

Development Topics

  • references/constructor-expressions.md - VALUE, NEW, COND, REDUCE
  • references/rap-eml.md - RAP and EML operations
  • references/cds-views.md - CDS view development
  • references/string-processing.md - String functions and regex
  • references/unit-testing.md - ABAP Unit framework
  • references/performance.md - Optimization techniques
  • ... and 18 more specialized references

Common Patterns

Safe Table Access (Avoid Exceptions)

abap
" Using VALUE with OPTIONALDATA(line) = VALUE #( itab[ key = value ] OPTIONAL ).
" Using VALUE with DEFAULTDATA(line) = VALUE #( itab[ 1 ] DEFAULT VALUE #( ) ).
" Check before accessIF line_exists( itab[ key = value ] ).  DATA(line) = itab[ key = value ].ENDIF.

Functional Method Chaining

abap
DATA(result) = NEW zcl_builder( )  ->set_name( `Test` )  ->set_value( 123 )  ->build( ).

FOR Iteration Expressions

abap
" Transform tableDATA(transformed) = VALUE itab_type(  FOR wa IN source_itab  ( id = wa-id name = to_upper( wa-name ) ) ).
" With WHEREDATA(filtered) = VALUE itab_type(  FOR wa IN source WHERE ( status = 'A' )  ( wa ) ).
" With INDEX INTODATA(numbered) = VALUE itab_type(  FOR wa IN source INDEX INTO idx  ( line_no = idx data = wa ) ).

ABAP Cloud Compatibility

abap
" Use released APIs onlyDATA(uuid) = cl_system_uuid=>create_uuid_x16_static( ).DATA(date) = xco_cp=>sy->date( )->as( xco_cp_time=>format->iso_8601_extended )->value.DATA(time) = xco_cp=>sy->time( )->as( xco_cp_time=>format->iso_8601_extended )->value.
" Output in cloud (if_oo_adt_classrun)out->write( result ).
" Avoid: sy-datum, sy-uzeit, DESCRIBE TABLE, WRITE, MOVE...TO

ABAP 7.40 Compatibility

When targeting ABAP 7.40 systems, replace 7.50+ syntax with these patterns:

abap
" Instead of FINAL (7.50+):FINAL(value) = `constant`.              " 7.50+DATA(value) = `constant`.               " 7.40 compatible
" Instead of host expressions (7.50+):SELECT * FROM dbtab WHERE col = @( lv_val ).   " 7.50+SELECT * FROM dbtab WHERE col = @lv_val.        " 7.40 compatible
" Instead of UNION (7.50+):SELECT a FROM tab1 UNION SELECT a FROM tab2.    " 7.50+" Use two separate SELECTs on 7.40 and combine in ABAP:SELECT a FROM tab1 INTO TABLE @DATA(r1).SELECT a FROM tab2 INTO TABLE @DATA(r2).DATA(combined) = VALUE itab_type( FOR l1 IN r1 ( l1 )                                  FOR l2 IN r2 ( l2 ) ).
" Instead of IS INSTANCE OF (7.50+):IF oref IS INSTANCE OF zcl_my_class.    " 7.50+" 7.40 alternative — use typed CAST with exception handling:TRY.    DATA(lo) = CAST zcl_my_class( oref ).  " 7.40+  CATCH cx_sy_move_cast_error.    " oref is not compatible with zcl_my_classENDTRY.
" Instead of CTEs WITH (7.51+):WITH +cte AS ( SELECT ... ) SELECT ...  " 7.51+" Use subqueries or temporary tables on 7.40

Error Catalog

CX_SY_ITAB_LINE_NOT_FOUND

Cause: Table expression access to non-existent line Solution: Use OPTIONAL, DEFAULT, or check with line_exists( )

CX_SY_ZERODIVIDE

Cause: Division by zero Solution: Check divisor before operation

CX_SY_RANGE_OUT_OF_BOUNDS

Cause: Invalid substring access or array bounds Solution: Validate offset and length before access

CX_SY_CONVERSION_NO_NUMBER

Cause: String cannot be converted to number Solution: Validate input format before conversion

CX_SY_REF_IS_INITIAL

Cause: Dereferencing unbound reference Solution: Check IS BOUND before dereferencing


Performance Tips

  1. Use SORTED/HASHED tables for frequent key access
  2. Prefer field symbols over work areas in loops for modification
  3. Use PACKAGE SIZE for large SELECT results
  4. Avoid SELECT in loops - use FOR ALL ENTRIES or JOINs
  5. Use secondary keys for different access patterns
  6. Minimize CORRESPONDING calls - explicit assignments are faster

Source Documentation

All content based on SAP official ABAP Cheat Sheets:

來源與署名

來源:secondsky/sap-skills位於plugins/sap-abap/skills/sap-abap提交652a861

授權條款: GPL-3.0

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架