Homelab, Linux, JS & 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] 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 DZeile verdoppeln
Strg JIn Kommentaren -> 1 Buchstaben groß
Strg ISuchen abwärts (startet beim tippen)
Strg Shift ISuchen aufwärts (startet beim tippen)
Strg KText groß/klein switchen. Alternativ (Strg U für groß, Strg L für klein)
Strg Shift SCoding in Datei speichern
Strg Shift LGanze Zeile löschen
Strg Shift XGanze Zeile löschen und einrücken
Ctrl /Jump to the “command field” where we enter t-codes
Alt Shift PfeiltastenCoding 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] 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.

#LayerNomenclatureDescription
1Database TableZTABLEPlace your raw data first
2Data Definition (Interface View)ZI_Relation between different tables (e.g. currency or text table)
3Projection 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.
4Service DefinitionZSD_Expose the projection view (and underlying associations like currency, country…) as service
5Service BindingZSB_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.

6Behavior Definition on Data DefinitionZI_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.
7Behavior Implementation on Definition ViewZBP_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.
8Behavior Definition on Projection ViewZC_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

Create a ALV Layout Variant
Select-Option for Layout Variant on Selectionscreen
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.