SAP ABAP Technology

New ABAP Keyword Documentation for SAP

ABAP-Programmierung

Program Samples

Load Excel into table

Run Time Type Services (RTTS)#

Types according to CL_ABAP_ELEMDESCR
KIND_CLASSC
KIND_ELEME
KIND_INTFI
KIND_REFR
KIND_STRUCTS
KIND_TABLET
TRUEX
TYPEKIND_ANY~
TYPEKIND_CHARCCHAR
TYPEKIND_CLASS*
TYPEKIND_CLIKE&
TYPEKIND_CSEQUENCE?
TYPEKIND_DATA#
TYPEKIND_DATEDDATS
TYPEKIND_DECFLOAT/
TYPEKIND_DECFLOAT16a
TYPEKIND_DECFLOAT34e
TYPEKIND_DREFl
TYPEKIND_FLOATF
TYPEKIND_HEXX
TYPEKIND_INTI
TYPEKIND_INT1b
TYPEKIND_INT2s
TYPEKIND_INTF+
TYPEKIND_IREFm
TYPEKIND_NUMN
TYPEKIND_NUMERIC%
TYPEKIND_OREFr
TYPEKIND_PACKEDPCURR,DEC
TYPEKIND_SIMPLE$
TYPEKIND_STRINGg
TYPEKIND_STRUCT1u
TYPEKIND_STRUCT2v
TYPEKIND_TABLEh
TYPEKIND_TIMET
TYPEKIND_Ww
TYPEKIND_XSEQUENCE!
TYPEKIND_XSTRINGy
TYPEKIND_BREFj
TYPEPROPKIND_DBMAXLEND
TYPEPROPKIND_HASCLIENTC
UNDEFINED-

Character conversion (codepage)#

See here and here or Abap-xstring
fb.SCP_REPLACE_STRANGE_CHARSChange German special chars (Umlaute)
CL_XMS_PART_UTIL
CL_ABAP_CONV_IN_CECode Page and Endian Conversion (External -> System Format)
CL_ABAP_CONV_OUT_CEConverts ABAP data objects to an external binary format
CL_ABAP_CONV_X2X_CEConverts of ABAP data objects between two external binary formats
CL_ABAP_CHAR_UTILITIESVarious attributes and methods for character sets and byte order
CL_NLS_STRUC_CONTAINERCorrects alignment of structures in containers of type C (or STRING). You need to make this correction if East-Asian characters ("full-width" characters in Chinese, Japanese, and Korean) are to be copied from a non-Unicode to a Unicode system or vice versa. You do not need to make the correction if you use the method CONVERT_STRUC from this class.
DATA: l_xstring_input   TYPE xstring,
        l_string_output   TYPE string,
        l_encoding        TYPE abap_encoding,  "see table TCP00
        l_r_converter     TYPE REF TO cl_abap_conv_in_ce.
 
      " Convert file data to string
      TRY.
          CALL METHOD cl_abap_conv_in_ce=>create
            EXPORTING
              input       = l_xstring_input
              encoding    = l_encoding
              replacement = '#'
              ignore_cerr = abap_false
            RECEIVING
              conv        = l_r_converter.
 
          CALL METHOD l_r_converter->read
            IMPORTING
              data = l_string_output.
 
        CATCH cx_root.
           " Conversion error
          EXIT.
      ENDTRY.

General system information#

CL_HRCE_MASTERSWITCHES=>IS_CLIENT_PRODUCTIVE( ) = 'X'/' '

Shortcuts#

Ctrl + < comment out all marked line
Ctrl + Shift + < uncomment all mrkes lines

Search in Reports#

RPINCL10Standard
RPR_ABAP_SOURCE_SCANScan ABAP Report Sourcen
x.CODE_SCANNERABAP Search (=r.AFX_CODE_SCANNER)
RSRSCAN1
RKCTSEAR

Append#

There is a weird shortcut for APPEND.
When you record a session, the code is generated like
CLEAR bdctab.
bdctab-program = 'SAPMSSY0'.	
bdctab-dynpro = '120'.
bdctab-dynbegin = 'X'.
APPEND bdctab.
The first CLEAR and the field assignments refer to a structure bdctab.
This structure is the header line (deprecated) from itab bdctab. So bdctab is used in different contexts.
If an ABAP command needs a structure, the header line "bdctab" is automatically taken.
If an ABAP command need an itab, the table "bcdtab" is taken, you can use
 APPEND bdctab[] 
to indicate that the table should be used.
APPEND bdctab is a shortcut and should at least be
 APPEND bcdtab to bdctab[] 
But this is outdated also, though still generated from SAP ECC 6.0.
See more explanations here.

Execute OS commands on the server#

  • function module SXPG_COMMAND_EXECUTE in connection with SM49/SM69
  • WS_EXECUTE
  • CL_GUI_FRONTEND_SERVICES=>EXECUTE
  • TH_POPUP
  • call 'SYSTEM' id 'COMMAND'

Remote Execution#

   SUBMIT {rep|(name)} ...

Text Manipulation#

class CL_ABAP_CHAR_UTILITIES
concatenate
strlendescribe field

Note:

replace all occurrences of ' ' in p_filen with '_' in character mode.
will raise an exception REPLACE_INFINITE_LOOP, use the following:
replace all occurrences of regex '\s{1}' in p_filen with '_'.
(or use TRANSLATE)

Using XSTRING#

see xstring

File Handling#

  • CL_GUI_FRONTEND_SERVICES=>FILE_*
  • OPEN/GET DATASET
  • FB EPS_GET*
  • FB SCMS*

Date Handling#

Vormonat:
DATA: ultimo TYPE d.
ultimo      = sy-datum. 
ultimo+6(2) = '01'.          " = erster Tag dieses Monats
ultimo      = ultimo - 1.    " = letzter Tag dieses Monats
Achtung: Funktioniert nicht beim Jahreswechsel, hier muss extra geprüft werden.

Import Excel to SAP#

f.TEXT_CONVERT_XLS_TO_SAPFastest
f.ALSM_EXCEL_TO_INTERNAL_TABLEStandard
f.KCD_EXCEL_OLE_TO_INT_CONVERTlimited to 9999 rows
f.FILE_READ_AND_CONVERT_SAP_DATA6x slower
Per OLECREATE OBJECT H_EXCEL 'Excel.Application' + CALL METHOD OF H_EXCEL 'Workbooks' = H_WRKBK ...

Dynamic / Generic SQL#

Native SQL, see reports
ADBC_DEMO
RSDU_EXEC_SQL

Open SQL

REPORT  z_bi_blogdyn1.
PARAMETERS: p_tab TYPE tabname DEFAULT 'T001'.
START-OF-SELECTION.
  DATA:          dref    TYPE REF TO data,
                 tref    TYPE REF TO data,
                 gt_fcat TYPE lvc_t_fcat.

  FIELD-SYMBOLS: <wa>    TYPE ANY,
                 <itab>  TYPE STANDARD TABLE.

  CREATE DATA dref TYPE (p_tab).
  ASSIGN dref->* TO <wa>.

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
       EXPORTING
            i_structure_name       = p_tab
       CHANGING
            ct_fieldcat            = gt_fcat[]
       EXCEPTIONS
            inconsistent_interface = 1
            program_error          = 2
            OTHERS                 = 3.

  CALL METHOD cl_alv_table_create=>create_dynamic_table
     EXPORTING
       it_fieldcatalog           = gt_fcat
     IMPORTING
       ep_table                  = tref
     EXCEPTIONS
       generate_subpool_dir_full = 1
       OTHERS                    = 2.

  ASSIGN tref->* TO <itab>.

  SELECT * FROM (p_tab) INTO TABLE <itab>.

  LOOP AT <itab> INTO <wa>.
    WRITE: / <wa>.
  ENDLOOP.

Gray out selection parameters#

 AT SELECTION-SCREEN OUTPUT.
      LOOP AT SCREEN.
        IF SCREEN-NAME = 'STEP080'. " name is upper case always
             SCREEN-input = 0.      " grau out
             MODIFY SCREEN.
         ENDIF.
      ENDLOOP.

Cluster tables#

HR Clusters | Cluster Discussion
x.PECLUSTERHR-Cluster bearbeiten
v.V_T52RELIDPflegeview für die Beschreibung der Cluster in PCLx
t.T52RELIDHR: Beschreibung der Cluster in den Tabellen PCLx
p.PCALPaket PCAL (all cluster stuff)
t.T52B5Zuordnung von Werten zu Objekten (CLST,PDP,1)
t.HRDCT_D_TABLESIndex Table for Declustering Transparent Tables

ABAP Objects / Class#

t.SEOCLASSClasses
t.SEOCOMPOComponents (Methods)
v.VSEOCLASSview on class
t.SEOMETARELMeta-Beziehung (see RELTYPE: Interface, Vererbung, Erweiterung)
t.TMDIRClasses and its methods
cl.CL_OO_CLASSClass Reflection Helper class

Loop through table of objects with keyword TABLE_LINE:

DATA: gt_records type standard table of ref to zhrzxx_mig_tabledata,
      lo_record type ref to zhrzxx_mig_tabledata.
LOOP AT gt_records INTO lo_record
      WHERE table_line->mv_infty = '0001'.
      [...]
ENDLOOP.

Tabellen DD0*

ABAP Dictionary#

f.DDIF_FIELDINFO_GET
f.DDIF_FIELDLABEL_GET
fm.DDIF_DOMA_GET
fm.RSD_DTEL_GET
CL_ABAP_TYPEDESCR

Wildcards#

SQLSelektion Screen
0 to many%*
single char_+

Business Application Log (BAL)#

SLG0Anwendungs-Log: Objektpflege (Objekt+Unterobjekt ist nötig, um auf DB zu sichern)
SLG1Anwendungs-Log: Protokolle anzeigen
SLG2Anwendungs-Log: Protokolle löschen
SLGNAnwendungs-Log: Nummernkreispflege
SLGTAnmelden zentraler Objektkatalog

Für die Protokollierung sollten die von SAP vorgesehenen Funktionsbausteine in der Funktionsgruppe SBAL verwendet werden. Die Beispielprogramme „SBAL_DEMO*“ bieten einen guten Einstieg und Überblick.

SAP Application Log – Leitfaden für Anwender

r.SBAL_DOCUMENTATION
CL_HRPAY00_MESSAGE_HANDLER

BAL_AMODAL Anwendungs-Log: INDX-Tabelle für amodale K
BAL_INDX Anwendungs-Log: INDX-Tabelle
BALC Anwendungs-Log: Kontext des Prokolls bzw.
BALDAT Anwendungs-Log: Daten eines Protokolls
BALHANDLE Anwendungs-Log: Dummy-Tabelle für Sperrobj
BALHDR Anwendungs-Log: Protokollkopf
BALHDRP Anwendungs-Log: Protokollparameter
BALM Anwendungs-Log: Protokollnachrichten
BALMP Anwendungs-Log: Nachrichtenparameter
BALOBJ Anwendungs-Log: Objekte
BALOBJT Anwendungs-Log: Texte zu den Objekten
BALSUB Anwendungs-Log: Unterobjekte
BALSUBT Anwendungs-Log: Unterobjekttexte
CIFBALSEL Anwendungs-Log: CIF-Erweiterung für Protok