Homelab, Linux, JS & ABAP (~˘▾˘)~
 

[ABAP] Progress indicator

SELECT * FROM sflight INTO TABLE @DATA(flights).

LOOP AT flights INTO DATA(flight).
  WAIT UP TO 1 SECONDS.
  cl_progress_indicator=>progress_indicate( i_text               = |Processing flight { flight-connid } as { sy-tabix } / { lines( flights ) }|
                                            i_processed          = sy-tabix
                                            i_total              = lines( flights )
                                            i_output_immediately = abap_true ).
ENDLOOP.

[ABAP] xsdbool

Somehow I always forget that there is a boolean function in ABAP. That’s why I’m writing this post to hopefully remember it better. 🙂

If you just want to check something for truthiness, you can do it in the following three ways:

IF sy-subrc = 0.
  result = abap_true.
ELSE.
  result = abap_false.
ENDIF.
result = SWITCH #( sy-subrc WHEN 0 THEN abap_true
                                   ELSE abap_false ).
result = xsdbool( sy-subrc = 0 )

[ABAP] SALV – Access column name

  TRY.
      cl_salv_table=>factory( IMPORTING r_salv_table = DATA(lo_alv)
                              CHANGING  t_table      = lt_output ).
    CATCH cx_salv_msg INTO DATA(lx_salv).
      WRITE: / lx_salv->get_text( ).
  ENDTRY.

  DATA(columns) = lo_alv->get_columns( ).
  DATA(lt_cols) = columns->get( ).

  LOOP AT lt_cols INTO DATA(ls_cols).
    DATA(lo_column) = ls_cols-r_column.
    CASE ls_cols-columnname.
      WHEN 'MANDT'
        lo_column->set_visible( abap_false ).
    ENDCASE.
  ENDLOOP.

[ABAP] Filter table using VALUE FOR

DATA(lt_result) = VALUE z_type( FOR line IN lt_table
                                WHERE ( value IN lr_values )
                                ( field = ls_line-value ) ).

[ABAP] Selection Screen Tabbed Block

SELECTION-SCREEN BEGIN OF BLOCK bl4 WITH FRAME TITLE TEXT-t01.
SELECTION-SCREEN BEGIN OF TABBED BLOCK tbl FOR 10 LINES.
SELECTION-SCREEN TAB (15) tbl_tab1 USER-COMMAND tab1 DEFAULT SCREEN 1001.
SELECTION-SCREEN TAB (15) tbl_tab2 USER-COMMAND tab2 DEFAULT SCREEN 1002.
SELECTION-SCREEN TAB (15) tbl_tab3 USER-COMMAND tab3 DEFAULT SCREEN 1003.
SELECTION-SCREEN END OF BLOCK tbl.
SELECTION-SCREEN END OF BLOCK bl4.

* Subscreen 1001 Tab1
SELECTION-SCREEN BEGIN OF SCREEN 1001 AS SUBSCREEN.
PARAMETERS p_bool1 TYPE abap_bool AS CHECKBOX.
SELECTION-SCREEN END OF SCREEN 1001.

* Subscreen 1002 Tab2
SELECTION-SCREEN BEGIN OF SCREEN 1002 AS SUBSCREEN.
PARAMETERS p_btp1 TYPE flag RADIOBUTTON GROUP rbg DEFAULT 'X'.
PARAMETERS p_btp2 TYPE flag RADIOBUTTON GROUP rbg.
PARAMETERS p_btp3 TYPE flag RADIOBUTTON GROUP rbg.
SELECTION-SCREEN END OF SCREEN 1002.

* Subscreen 1003 Tab3
SELECTION-SCREEN BEGIN OF SCREEN 1003 AS SUBSCREEN.
PARAMETERS p_bool2 TYPE flag AS CHECKBOX.
SELECTION-SCREEN END OF SCREEN 1003.

INITIALIZATION.

  " provide tab names
  tbl_tab1 = 'Tab1'.
  tbl_tab2 = 'Tab2'.
  tbl_tab3 = 'Tab3'.

  " set active tab (activetab value must be in uppercase)
  tbl-activetab = 'TAB2'.
  tbl-dynnr     = 1002.
  tbl-prog      = sy-repid.

AT SELECTION-SCREEN.

  " click on tabstrip event
  CASE sy-ucomm.
    WHEN 'TAB1'.
      MESSAGE 'TAB1' TYPE 'S'.
    WHEN 'TAB2'.
      MESSAGE 'TAB2' TYPE 'S'.
    WHEN 'TAB3'.
      MESSAGE 'TAB3' TYPE 'S'.
  ENDCASE.

[ABAP] Display Table data as HTML

REPORT z_table_to_html.

TRY.

    SELECT * FROM sflight INTO TABLE @DATA(flights) UP TO 100 ROWS.

    cl_demo_output=>write_data( flights ).

    DATA(lv_html) = cl_demo_output=>get( ).

    cl_abap_browser=>show_html( title       = 'Flights'
                                html_string = lv_html
                                container   = cl_gui_container=>default_screen ).

    " force cl_gui_container=>default_screen
    WRITE: space.

  CATCH cx_root INTO DATA(e).
    WRITE: / e->get_text( ).
ENDTRY.

[ABAP] Get URL for BSP Page

    cl_http_ext_webapp=>create_url_for_bsp_application( EXPORTING bsp_application      = bsp_application            " Name der BSP Applikation
                                                                  bsp_start_page       = bsp_start_page             " Startseite der BSP Applikation
                                                                  bsp_start_parameters = bsp_start_parameters       " Startparameter der BSP Applikation
                                                        IMPORTING abs_url              = DATA(lv_absolute_url ).    " Absolute URL (Protokol, Host, Port, ...) der BSP Applikation

[ABAP] Display PDF in HTML Control

  DATA lt_data TYPE STANDARD TABLE OF x255.
  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer     = lv_xstring "pdf data
    TABLES
      binary_tab = lt_data.  

 DATA(o_html) = NEW cl_gui_html_viewer( parent = cl_gui_container=>default_screen ).

* URL zu HTML holen
  DATA: lv_url TYPE swk_url.
  o_html->load_data( EXPORTING type         = 'BIN'
                               subtype      = 'PDF'
                     IMPORTING assigned_url = lv_url
                     CHANGING  data_table   = lt_data ).
* HTML anzeigen
  o_html->show_url( lv_url ).

* erzwingt Anzeige über cl_gui_container=>default_screen
  WRITE: / space.