[ABAP] Code-Vorlagen (ABAP Code Templates)

Im ABAP-Code Editor kann man sich Vorlagen (Templates) definieren: Using Code Templates oder auch berater-wiki.de

ifs (if mit sy-subrc)

IF sy-subrc = 0.
%SurroundedText%  |
ENDIF.

wri

WRITE: / |.

loop (einfacher LOOP it Feldsymbol)

LOOP AT %TABLE NAME% ASSIGNING FIELD-SYMBOL(<e>).
  |
ENDLOOP.

types (Struktur- und Tabellentyp)

TYPES : BEGIN OF ty_s_%TYPE NAME%,
%SurroundedText%          |
        END OF ty_s_%TYPE NAME%.

TYPES: ty_it_%TYPE NAME% TYPE STANDARD TABLE OF ty_s_%TYPE NAME% WITH DEFAULT KEY.

cla (lokale Klasse mit Constructor)

CLASS lcl_%CLASS_NAME% DEFINITION.
  PUBLIC SECTION.

    METHODS: constructor.

    METHODS: set_value
      IMPORTING
        par1 TYPE string.

    METHODS: get_value
      RETURNING VALUE(rv_ret) TYPE i.

  PRIVATE SECTION.
    DATA: gv_data TYPE i.
ENDCLASS.

CLASS lcl_%CLASS_NAME% IMPLEMENTATION.
  METHOD constructor.
  ENDMETHOD.

  METHOD set_value.
    gv_data = par1.
  ENDMETHOD.

  METHOD get_value.
    rv_ret = gv_data.
  ENDMETHOD.
ENDCLASS.

salv (SALV-Table mit Grundeinstellungen)

|
TRY.
* SALV-Table
    DATA: o_salv TYPE REF TO cl_salv_table.
  
    cl_salv_table=>factory( IMPORTING
                              r_salv_table   = o_salv
                            CHANGING
                              t_table        = %TABLE NAME% ).
  
* Grundeinstellungen
    o_salv->get_functions( )->set_all( abap_true ).
    o_salv->get_columns( )->set_optimize( abap_true ).
    o_salv->get_display_settings( )->set_list_header( 'Überschrift' ).
    o_salv->get_display_settings( )->set_striped_pattern( abap_true ).
    o_salv->get_selections( )->set_selection_mode( if_salv_c_selection_mode=>row_column ).
  
* Spaltenüberschriften: technischer Name und Beschreibungstexte, Short Text und Medium Text leer lassen für Autosize
    LOOP AT o_salv->get_columns( )->get( ) ASSIGNING FIELD-SYMBOL(<c>).
      DATA(o_col) = <c>-r_column.
      o_col->set_short_text( || ).
      o_col->set_medium_text( || ).
      o_col->set_long_text( |{ o_col->get_columnname( ) } [{ o_col->get_long_text( ) }]| ).
    ENDLOOP.
  
    o_salv->display( ).
  CATCH cx_root INTO DATA(e_txt).
    WRITE: / e_txt->get_text( ).
ENDTRY.

rem (Methodensignatur aus Eclipse)

|
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Public Method methodname - Text1
* |                            Text2
* |                            Text3
* +-------------------------------------------------------------------------------------------------+
* | [--->] i_var1  - Text1
* | [--->] i_var2  - Text2
* | [<---] ret_var - Text3
* +--------------------------------------------------------------------------------------</SIGNATURE>

cld (cl_demo_output in Vollbilddarstellung)

* Hier Objekte für die Ausgabe hinzufügen
cl_demo_output=>write_data( | ).

* HTML-Code vom Demo-Output holen
DATA(lv_html) = cl_demo_output=>get( ).

* Daten im Inline-Browser im SAP-Fenster anzeigen
cl_abap_browser=>show_html( EXPORTING
                              title        = 'Daten'
                              html_string  = lv_html
                              container    = cl_gui_container=>default_screen ).

* cl_gui_container=>default_screen erzwingen
WRITE: space.