.
abap
OpenSQL (SAP) aggregates
* Récupérer les <id> qui ont plus d'un <code> distinct.
SELECT id COUNT( DISTINCT code ) FROM zmy_table INTO TABLE wlt_plop
GROUP BY id
HAVING COUNT( DISTINCT code ) > 1.
sql abap
<iframe width="100%" height="272" src="http://ginkobox.fr/vamp/index.php?embed=569cf482ea7de" type="text/html"></iframe>
Text only - Permalink - Snippet public post date 18/01/2016
ZDYN_CODE
REPORT zdyn_code.
DATA : wlt_code TYPE TABLE OF char256,
wlv_line LIKE LINE OF wlt_code,
wlv_prog TYPE char08,
wlv_msg TYPE char120,
wlv_lin TYPE char03,
wlv_wrd TYPE char10,
wlv_off TYPE char03.
wlv_line = 'PROGRAM SUBPOOL.'.
APPEND wlv_line TO wlt_code.
wlv_line = 'FORM f1.'.
APPEND wlv_line TO wlt_code.
wlv_line = ''.
APPEND wlv_line TO wlt_code.
APPEND wlv_line TO wlt_code.
APPEND wlv_line TO wlt_code.
wlv_line = 'BREAK-POINT.'.
APPEND wlv_line TO wlt_code.
wlv_line = ''.
APPEND wlv_line TO wlt_code.
wlv_line = 'ENDFORM.'.
APPEND wlv_line TO wlt_code.
DO.
EDITOR-CALL FOR wlt_code.
IF sy-subrc = 4.
EXIT.
ENDIF.
GENERATE SUBROUTINE POOL wlt_code NAME wlv_prog
MESSAGE wlv_msg
LINE wlv_lin
WORD wlv_wrd
OFFSET wlv_off.
IF sy-subrc <> 0.
MESSAGE i000(z_interfaces) WITH wlv_lin wlv_msg wlv_wrd wlv_off.
ELSE.
PERFORM f1 IN PROGRAM (wlv_prog).
EXIT.
ENDIF.
ENDDO.
abap
<iframe width="100%" height="1064" src="http://ginkobox.fr/vamp/index.php?embed=569cf44de8454" type="text/html"></iframe>
Text only - Permalink - Snippet public post date 18/01/2016
ALV in container (container can be defined from screen painter as a custom control)
DATA: alv TYPE REF TO cl_salv_table,
lo_functions TYPE REF TO cl_salv_functions_list.
DATA: wgr_container TYPE REF TO cl_gui_custom_container.
IF wgr_container IS NOT BOUND.
IF cl_salv_table=>is_offline( ) EQ if_salv_c_bool_sap=>false.
CREATE OBJECT wgr_container
EXPORTING
container_name = 'WGC_CONTAINER_PLOP'.
ENDIF.
TRY.
cl_salv_table=>factory(
EXPORTING r_container = wgr_container
container_name = 'WGC_CONTAINER_PLOP'
IMPORTING r_salv_table = alv
CHANGING t_table = wgt_plop ).
lo_functions = alv->get_functions( ).
lo_functions->set_all( abap_true ).
alv->display( ).
CATCH cx_salv_msg.
MESSAGE 'ALV display not possible' TYPE 'I'
DISPLAY LIKE 'E'.
ENDTRY.
ENDIF.
ALV abap screen
<iframe width="100%" height="686" src="http://ginkobox.fr/vamp/index.php?embed=567a702c55983" type="text/html"></iframe>
Text only - Permalink - Snippet public post date 23/12/2015
ALV handlers
PROGRAM zkmalve2.
DATA:
gt_usr TYPE TABLE OF usr02,
gs_usr TYPE usr02.
*----------------------------------------------------------------------*
* CLASS cl_event_handler DEFINITION
*----------------------------------------------------------------------*
CLASS cl_event_handler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS on_before_salv_function " BEFORE_SALV_FUNCTION
FOR EVENT if_salv_events_functions~before_salv_function
OF cl_salv_events_table
IMPORTING e_salv_function.
CLASS-METHODS on_after_salv_function " AFTER_SALV_FUNCTION
FOR EVENT if_salv_events_functions~before_salv_function
OF cl_salv_events_table
IMPORTING e_salv_function.
CLASS-METHODS on_added_function " ADDED_FUNCTION
FOR EVENT if_salv_events_functions~added_function
OF cl_salv_events_table
IMPORTING e_salv_function.
CLASS-METHODS on_top_of_page " TOP_OF_PAGE
FOR EVENT if_salv_events_list~top_of_page
OF cl_salv_events_table
IMPORTING r_top_of_page
page
table_index.
CLASS-METHODS on_end_of_page " END_OF_PAGE
FOR EVENT if_salv_events_list~end_of_page
OF cl_salv_events_table
IMPORTING r_end_of_page
page.
CLASS-METHODS on_double_click " DOUBLE_CLICK
FOR EVENT if_salv_events_actions_table~double_click
OF cl_salv_events_table
IMPORTING row
column.
CLASS-METHODS on_link_click " LINK_CLICK
FOR EVENT if_salv_events_actions_table~link_click
OF cl_salv_events_table
IMPORTING row
column.
ENDCLASS. "cl_event_handler DEFINITION
*----------------------------------------------------------------------*
* CLASS cl_event_handler IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS cl_event_handler IMPLEMENTATION.
METHOD on_before_salv_function.
BREAK-POINT.
ENDMETHOD. "on_before_salv_function
METHOD on_after_salv_function.
BREAK-POINT.
ENDMETHOD. "on_after_salv_function
METHOD on_added_function.
BREAK-POINT.
ENDMETHOD. "on_added_function
METHOD on_top_of_page.
BREAK-POINT.
ENDMETHOD. "on_top_of_page
METHOD on_end_of_page.
BREAK-POINT.
ENDMETHOD. "on_end_of_page
METHOD on_double_click.
BREAK-POINT.
ENDMETHOD. "on_double_click
METHOD on_link_click.
BREAK-POINT.
ENDMETHOD. "on_link_click
ENDCLASS. "cl_event_handler IMPLEMENTATION
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
* read sample data to internal table
SELECT * FROM usr02 UP TO 30 ROWS
APPENDING CORRESPONDING FIELDS OF TABLE gt_usr
ORDER BY bname.
PERFORM display_alv.
*&---------------------------------------------------------------------*
*& Form display_alv
*&---------------------------------------------------------------------*
FORM display_alv.
DATA:
lo_table TYPE REF TO cl_salv_table,
lo_events TYPE REF TO cl_salv_events_table,
lo_columns TYPE REF TO cl_salv_columns_table,
lo_column TYPE REF TO cl_salv_column_list.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = lo_table
CHANGING
t_table = gt_usr.
lo_events = lo_table->get_event( ).
SET HANDLER cl_event_handler=>on_before_salv_function FOR lo_events.
SET HANDLER cl_event_handler=>on_after_salv_function FOR lo_events.
SET HANDLER cl_event_handler=>on_added_function FOR lo_events.
SET HANDLER cl_event_handler=>on_top_of_page FOR lo_events.
SET HANDLER cl_event_handler=>on_end_of_page FOR lo_events.
SET HANDLER cl_event_handler=>on_double_click FOR lo_events.
SET HANDLER cl_event_handler=>on_link_click FOR lo_events.
* ALV-Toolbar
lo_table->set_screen_status(
pfstatus = 'STANDARD_FULLSCREEN'
report = 'SAPLSLVC_FULLSCREEN'
set_functions = lo_table->c_functions_all ).
* Set column as hotspot
lo_columns = lo_table->get_columns( ).
lo_column ?= lo_columns->get_column( 'BNAME' ).
lo_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
lo_table->display( ).
CATCH cx_salv_msg. " cl_salv_table=>factory()
WRITE: / 'cx_salv_msg exception'.
STOP.
CATCH cx_salv_not_found. " cl_salv_columns_table->get_column()
WRITE: / 'cx_salv_not_found exception'.
STOP.
ENDTRY.
ENDFORM. "display_alv
ALV abap
http://www.kerum.pl/infodepot/00007
<iframe width="100%" height="2846" src="http://ginkobox.fr/vamp/index.php?embed=5678114ad7fc9" type="text/html"></iframe>
Text only - Permalink - Snippet public post date 21/12/2015
Création de range à partir de table interne
FUNCTION zcreate_range.
*"----------------------------------------------------------------------
*"*"Interface locale :
*" IMPORTING
*" REFERENCE(I_FIELDNAME) TYPE CHAR30
*" TABLES
*" IT_TABLE
*" ET_RANGE
*"----------------------------------------------------------------------
************************************************************************
* Description : A module function capable of building a range from *
* any table !!! *
************************************************************************
FIELD-SYMBOLS : <ls_value> TYPE any,
<fieldname> TYPE any,
<ls_range> TYPE any,
<lit_range> TYPE STANDARD TABLE,
<ls_table> TYPE any.
ASSIGN i_fieldname TO <fieldname>.
ASSIGN et_range[] TO <lit_range>[].
ASSIGN et_range TO <ls_range>.
LOOP AT it_table ASSIGNING <ls_table>.
ASSIGN COMPONENT <fieldname> OF STRUCTURE <ls_table> TO <ls_value>.
<ls_range>(3) = 'IEQ'.
<ls_range>+3 = <ls_value>.
APPEND <ls_range> TO <lit_range>.
ENDLOOP.
SORT <lit_range>.
DELETE ADJACENT DUPLICATES FROM <lit_range>.
ENDFUNCTION.
abap
<iframe width="100%" height="812" src="http://ginkobox.fr/vamp/index.php?embed=55f19a2b6623c" type="text/html"></iframe>
Text only - Permalink - Snippet public post date 10/09/2015
Get tab-separated tabular data from clipboard and parse it
TYPES:
BEGIN OF ty_clipdata,
data TYPE c LENGTH 500,
END OF ty_clipdata.
DATA: lt_clipdata TYPE STANDARD TABLE OF ty_clipdata.
DATA: ls_clipdata LIKE LINE OF lt_clipdata.
DATA: lv_clip_len TYPE i.
CONSTANTS: c_tab TYPE c VALUE cl_bcs_convert=>gc_tab.
DATA: lt_record TYPE STANDARD TABLE OF ty_clipdata.
DATA: ls_record LIKE LINE OF lt_record.
FIELD-SYMBOLS: <lfs_field> TYPE any.
TYPES: BEGIN OF lty_agr,
myfield1 TYPE myfield,
myfield2 TYPE urfield,
END OF lty_agr.
DATA: lt_data TYPE STANDARD TABLE OF lty_agr,
ls_data TYPE lty_agr,
lt_agr_db TYPE STANDARD TABLE OF lty_agr.
FIELD-SYMBOLS: <lfs_data> LIKE LINE OF lt_data.
*&---------------------------------------------------------------------*
*& Form GET_CLIP_DATA
*&---------------------------------------------------------------------*
* Get tab-separated tabular data from clipboard and parse it
*----------------------------------------------------------------------*
FORM get_clip_data .
* --- Get clipboard ---
cl_gui_frontend_services=>clipboard_import(
IMPORTING
data = lt_clipdata
length = lv_clip_len
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4 ).
IF sy-subrc NE 0.
MESSAGE 'Error while importing data from clipboard' TYPE 'E'.
ENDIF.
* --- Parse data ---
LOOP AT lt_clipdata INTO ls_clipdata.
SPLIT ls_clipdata AT c_tab INTO TABLE lt_record.
" SPE >>>
IF lt_record[ 1 ]-data(2) <> 'ZS'. " Your filter
CONTINUE.
ENDIF.
" <<< SPE
APPEND INITIAL LINE TO lt_data ASSIGNING <lfs_data>.
LOOP AT lt_record INTO ls_record.
ASSIGN COMPONENT sy-tabix OF STRUCTURE <lfs_data> TO <lfs_field>.
IF sy-subrc EQ 0.
<lfs_field> = ls_record-data.
ENDIF.
ENDLOOP.
ENDLOOP.
IF lt_data[] IS INITIAL.
MESSAGE 'No data parsed from clipboard' TYPE 'E'.
ENDIF.
ENDFORM. " GET_CLIP_DATA
abap clipboard
<iframe width="100%" height="1316" src="http://ginkobox.fr/vamp/index.php?embed=555b6d0abd678" type="text/html"></iframe>
Text only - Permalink - Snippet public post date 19/05/2015
Display any itab in ALV
*&---------------------------------------------------------------------*
*& Form write_out
*&---------------------------------------------------------------------*
* List output
*----------------------------------------------------------------------*
FORM write_out USING p_table. "With inline declaration abap 740
DATA: alv TYPE REF TO cl_salv_table.
TRY.
cl_salv_table=>factory(
IMPORTING r_salv_table = alv
CHANGING t_table = p_table ).
DATA(lo_functions) = alv->get_functions( ).
lo_functions->set_all( abap_true ).
alv->display( ).
CATCH cx_salv_msg.
MESSAGE 'ALV display not possible' TYPE 'I'
DISPLAY LIKE 'E'.
ENDTRY.
ENDFORM. "write_out
*&---------------------------------------------------------------------*
*& Form write_out
*&---------------------------------------------------------------------*
* List output
*----------------------------------------------------------------------*
FORM write_out USING p_table. "Without inline declaration
DATA: alv TYPE REF TO cl_salv_table,
lo_functions TYPE REF TO cl_salv_functions_list.
TRY.
cl_salv_table=>factory(
IMPORTING r_salv_table = alv
CHANGING t_table = p_table ).
lo_functions = alv->get_functions( ).
lo_functions->set_all( abap_true ).
alv->display( ).
CATCH cx_salv_msg.
MESSAGE 'ALV display not possible' TYPE 'I'
DISPLAY LIKE 'E'.
ENDTRY.
ENDFORM. "write_out
ALV abap
<iframe width="100%" height="974" src="http://ginkobox.fr/vamp/index.php?embed=555b6c66366cf" type="text/html"></iframe>
Text only - Permalink - Snippet public post date 10/09/2015
ABAP Pattern translation
* Translate pattern from GUI to OpenSQL (* -> % ; + -> _)
TRANSLATE p_obj USING '*%+_'.
abap
<iframe width="100%" height="218" src="http://ginkobox.fr/vamp/index.php?embed=555b6bee444d0" type="text/html"></iframe>
Text only - Permalink - Snippet public post date 19/05/2015
ZSPLIT_WIN_FILE_PATH
FUNCTION zsplit_win_file_path.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(I_PATH) TYPE STRING
*" EXPORTING
*" REFERENCE(E_DIRECTORY) TYPE STRING
*" REFERENCE(E_FILENAME) TYPE STRING
*" REFERENCE(E_EXTENSION) TYPE STRING
*"----------------------------------------------------------------------
CONSTANTS c_sep TYPE char1 VALUE '\'.
SPLIT i_path AT c_sep INTO TABLE DATA(lt_elms).
DESCRIBE TABLE lt_elms LINES DATA(lv_len).
READ TABLE lt_elms INDEX lv_len INTO e_filename.
DELETE lt_elms INDEX lv_len.
SPLIT e_filename AT '.' INTO TABLE DATA(lt_name_elms).
DESCRIBE TABLE lt_name_elms LINES DATA(lv_name_len).
READ TABLE lt_name_elms INDEX lv_name_len INTO e_extension.
CONCATENATE LINES OF lt_elms INTO e_directory SEPARATED BY c_sep.
ENDFUNCTION.
file_path abap sap
<iframe width="100%" height="632" src="http://ginkobox.fr/vamp/index.php?embed=54c7b5262e606" type="text/html"></iframe>
Text only - Permalink - Snippet public post date 27/01/2015