DATA(kostl_text) = NEW cl_hrpa_ui_convert_0859( )->get_txt_costcenter( iv_kokrs = lv_kokrs iv_kostl = lv_kostl iv_date = sy-datum ).
# Class is using FUBA 'HRCA_COSTCENTER_GETDETAIL'
Category: ABAP
ABAP
[HR] Abrechnungsergebnisse lesen
Reports:
RPCALCD0 – Abrechnungsprogramm Deutschland (Name des HR-Formulars lässt sich über T-Code HRFORMS ermitteln)
RPCLSTRD – Anzeige des Clusters RD (Abrechnungsergebnisse Deutschland), Tcode: PC_PAYRESULT
H99_DISPLAY_PAYRESULT – Anzeigen von Abrechnungsergebnissen
Abrechnungsergebnistabelle:
Eine sehr schöne Übersicht über die Tabellen: https://l3consulting.de/die-tabellen-im-abrechnungscluster-des-sap-hcm-verstehen/
Die Tabelle RT enthält die Ergebnislohnarten der ausgewählten Abrechnungsperiode. (RT_ = komprimierte Darstellung)
Funktionsbausteine:
HR_GET_PAYROLL_RESULTS – Lesen von Abrechnungsergebnissen für Monats- und Jahresreports
PYXX_READ_PAYROLL_RESULT – Generischer Import von Abrechnungsergebnissen
HRCM_PAYROLL_RESULTS_GET – Abrechnungsdaten einer Person ermitteln
Hinweise zu Bausteinen: https://blog.hr-manager.de/2011/09/abap-abrechnungsergebnisse-lesen-per.html
Logische Datenbank:
Eine weitere Möglichkeit ist die Nutzung der logischen Datenbank PNP. Die Verwendung logischer Datenbanken ist jedoch obsolet (zumindest in anderen Modulen) und sollten daher eigentlich nicht mehr verwendet werden.
*&---------------------------------------------------------------------*
*& Report ZGETPAYROLL
*& Eigenschaften: Selektionsbildvariante 900, HR-Reportklasse PY_DEF.
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZGETPAYROLL.
TABLES: PERNR, PYORGSCREEN, PYTIMESCREEN.
INFOTYPES: 0002.
NODES: PAYROLL TYPE PAYDE_RESULT.
DATA: WA_RT TYPE PC207.
START-OF-SELECTION.
GET PERNR.
RP_PROVIDE_FROM_LAST P0002 SPACE PN-BEGDA PN-ENDDA.
WRITE:/ PERNR-PERNR, P0002-VORNA, P0002-NACHN.
GET PAYROLL.
LOOP AT PAYROLL-INTER-RT INTO WA_RT.
WRITE:/ WA_RT-LGART, WA_RT-BETRG.
ENDLOOP.
END-OF-SELECTION.
Oder in Kombination mit einem Fuba:
*&---------------------------------------------------------------------*
*& Report ZGETPAYROLL
*& Eigenschaften: HR-Reportklasse __M00001.
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZGETPAYROLL.
TABLES: pernr. "Necessary for get pernr
INFOTYPES: 0001, "Organisatorische Zuord
0002, "Daten zur Person
0006, "Anschrift
0057. "Mitgliedschaften
DATA: l_payroll_result TYPE payat_result OCCURS 0 WITH HEADER LINE.
START-OF-SELECTION.
GET pernr.
rp_provide_from_last p0001 '' pn-begda pn-endda.
CALL FUNCTION 'HR_GET_PAYROLL_RESULTS'
EXPORTING
pernr = pernr-pernr
permo = pn-permo
pabrj = pn-pabrj
pabrp = pn-pabrp
actual = space "X actual, ' ' retro-differences
waers = 'EUR'
TABLES
result_tab = l_payroll_result
EXCEPTIONS
no_results = 0
wrong_structure_of_result_tab = 2
OTHERS = 4.
IF sy-subrc NE 0.
RETURN. "nächste Pernr
ENDIF.
[ABAP] Download internal table as TXT or CSV
" ty_output and tt_output are just dummy types
DATA: l_output_line TYPE ty_output,
l_output_lines TYPE tt_output,
l_csv_output TYPE truxs_t_text_data,
l_txt_output TYPE TABLE OF string,
PARAMETERS: p_alv RADIOBUTTON GROUP rb1 DEFAULT 'X' USER-COMMAND radio,
p_csv RADIOBUTTON GROUP rb1,
p_flcsv TYPE rlgrap-filename DEFAULT 'c:\temp\file.csv',
p_txt RADIOBUTTON GROUP rb1,
p_fltxt TYPE rlgrap-filename DEFAULT 'c:\temp\file.txt'.
" fill table l_output_lines with your data you want to export as txt or csv
IF p_csv = abap_true.
CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
TABLES
i_tab_sap_data = l_output_lines
CHANGING
i_tab_converted_data = l_csv_output.
TRY.
cl_gui_frontend_services=>gui_download( EXPORTING filename = CONV #( p_flcsv )
filetype = 'ASC'
CHANGING data_tab = l_csv_output ).
CATCH cx_root INTO DATA(e_text).
MESSAGE e_text->get_text( ) TYPE 'I'.
ENDTRY.
ELSEIF p_txt = abap_true.
LOOP AT l_output_lines INTO l_output_line.
CALL FUNCTION 'SO_STRUCT_TO_CHAR'
EXPORTING
ip_struct = l_output_line
IMPORTING
ep_string = l_string.
APPEND l_string TO l_txt_output.
ENDLOOP.
TRY.
cl_gui_frontend_services=>gui_download( EXPORTING filename = CONV #( p_fltxt )
filetype = 'ASC'
CHANGING data_tab = l_txt_output ).
CATCH cx_root INTO e_text.
MESSAGE e_text->get_text( ) TYPE 'I'.
ENDTRY.
ENDIF.
[ABAP Env] gCTS
https://blogs.sap.com/2020/05/30/sap-cloud-platform-abap-environment-lifecycle-management-introduction/
https://blogs.sap.com/2020/05/30/sap-cloud-platform-abap-environment-lifecycle-management-sample-scenarios/
Git | Git is a distributed version-control system |
CTS | Change and Transport Management System |
gCTS | Git-based CTS (the evolution of the classical CTS) |
abapGit | An open-source Git client that allows you to import existing code into your ABAP system |
Repository | A Repository is a collection of objects, their directory structure, and metadata |
Transport requests | A transport request records all the changes in your ABAP development system. With gCTS: Once a transport request is released, the changes are pushed into your central Git repository in the cloud as a commit represented by a commit ID. |
[ABAP] SE80 Shortcuts
Meine meist verwendeten Workbench Shortcuts:
Strg D | Zeile verdoppeln |
Strg J | In Kommentaren -> 1 Buchstaben groß |
Strg I | Suchen abwärts (startet beim tippen) |
Strg Shift I | Suchen aufwärts (startet beim tippen) |
Strg K | Text groß/klein switchen. Alternativ (Strg U für groß, Strg L für klein) |
Strg Shift S | Coding in Datei speichern |
Strg Shift L | Ganze Zeile löschen |
Strg Shift X | Ganze Zeile löschen und einrücken |
Ctrl / | Jump to the “command field” where we enter t-codes |
Alt Shift Pfeiltasten | Coding Block markieren (alternativ Alt + Maus) |
[ABAP] Calculation
* ab ABAP 7.54
DATA field TYPE p decimals 2.
field += 4.
field -= 2.
field *= 3.
field /= 2.
*obsolet: ADD, SUBSTRACT, MULTIPLY, DIVIDE
[ABAP] Display a database table
cl_salv_gui_table_ida=>create( iv_table_name = 'SFLIGHT' )->fullscreen( )->display( ).
Example report in your system: SALV_IDA_DISPLAY_DATA_SIMPLE
[ABAP] Alpha conversion
DATA(lv_matnr) = VALUE matnr( 0000000001 ).
DATA(character_string) = VALUE string( ).
character_string = |Your Material Number is { lv_matnr ALPHA = IN }|. "Adds leading zeros
character_string = |Your Material Number is { lv_matnr ALPHA = OUT }|. "Removes leading zeros
[ABAP Env] Create Data Model & OData Service
Recently I worked through the tutorial on creating a travel bookings app in the SAP Cloud Platform ABAP Environment.
Find a good introduction and overview on this topic here: Getting Started with ABAP in the Cloud – Part I
And the travel bookings app tutorial here: Getting Started with ABAP in the Cloud – Part II
These are my notes on the steps needed to create the data model and publish it as oData service.
# | Layer | Nomenclature | Description |
---|---|---|---|
1 | Database Table | ZTABLE | Place your raw data first |
2 | Data Definition (Interface View) | ZI_ | Relation between different tables (e.g. currency or text table) |
3 | Projection View (Consumption View) | ZC_ | Configure the UI depending on your scenario. Use different projection views for different usages of the same interface view and the same physical table. |
4 | Service Definition | ZSD_ | Expose the projection view (and underlying associations like currency, country…) as service |
5 | Service Binding | ZSB_ | How to we want to make the service available? Defines the binding type (OData V2 / OData V4) Activate it with the “Activate” Button within the editor window. Select the Entity and hit “Preview…” to see whtat we defined in our projection view. |
If you’ve done this, you are able to view the data in a generated Fiori Elements app. But if you also want to create, edit, delete data, you’ll have to add some behavior functionality.
6 | Behavior Definition on Data Definition | ZI_ | Created on top of the Data Definition. Will get the same name es the Data Definition. Implementation Type: Managed Defines the operations create, delete, edit. |
7 | Behavior Implementation on Definition View | ZBP_I_ | The code for the behavior… For the travel app tutorial, some logic for a generated unique key and field validation. The class inherits from cl_abap_behavior_handler. |
8 | Behavior Definition on Projection View | ZC_ | Created on top of the Projection View. Will get the same name es the Projection View. Defines the operations create, delete, edit. |
[ABAP] Select-Option for ALV Layout


SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-b03.
PARAMETERS: p_vari TYPE slis_vari.
SELECTION-SCREEN END OF BLOCK b3.
INITIALIZATION.
"Load default layout
DATA: ls_layout TYPE salv_s_layout_info,
ls_key TYPE salv_s_layout_key.
ls_key-report = sy-repid.
ls_layout = cl_salv_layout_service=>get_default_layout( s_key = ls_key
restrict = '1' ).
p_vari = ls_layout-layout.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vari.
"Value Help
DATA: ls_layout TYPE salv_s_layout_info,
ls_key TYPE salv_s_layout_key.
ls_key-report = sy-repid.
ls_layout = cl_salv_layout_service=>f4_layouts( s_key = ls_key
restrict = '1' ).
p_vari = ls_layout-layout.