METHOD get_month_name.
DATA: month_names TYPE TABLE OF t247.
CALL FUNCTION 'MONTH_NAMES_GET'
TABLES
month_names = month_names
EXCEPTIONS
OTHERS = 0.
TRY.
r_name = month_names[ mnr = i_month ]-ltx.
CATCH cx_sy_itab_line_not_found.
ENDTRY.
ENDMETHOD.
Tag: abap
[ABAP] ALV column header
DATA: o_salv TYPE REF TO cl_salv_table.
cl_salv_table=>factory( IMPORTING r_salv_table = o_salv
CHANGING t_table = l_lines ).
LOOP AT o_salv->get_columns( )->get( ) REFERENCE INTO DATA(l_column).
DATA(lo_column) = CAST cl_salv_column( l_column->r_column ).
lo_column->set_fixed_header_text( 'L' ).
ENDLOOP.
o_salv->get_columns( )->get_column( 'TEST1' )->set_long_text( 'Test1 Header' ).
o_salv->get_columns( )->get_column( 'TEST2' )->set_long_text( 'Test2 Header' ).
[ABAP] Read cost center description
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'
[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] 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.