Table Scanner - Abap

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 29

*&--------------------------------------------------------------------*& Report TABLE_SCANNER

*&
*&---------------------------------------------------------------------*
*&
*& Select tables by domain, data element or tabname
*& and scan them for a given value
*& result is shown in splitter control within up to 256 ALV grids
*&
*& additional features:
*& - save situation before refresh and show differences after refresh
*&
(-> user settings)
*& - jump to DDIC for selected fields (double click)
*& - show technical names or field lables (->user settings)
*& - select any values from the result list and re-submit scanner
*& (where used button)
*& - all ALV functions like sort, filter, layouts per table
*&
*& prerequisite: SAP_BASIS 640
*&---------------------------------------------------------------------*
*
*
*
*

useful demo programs


BCALV_EDIT_01 edit on/off
BCALV_DEMO_TOOLTIP colors(tooltips
SALV_DEMO_TABLE_COLUMNS Colors

REPORT table_scanner.
CONSTANTS: gc_se16
TYPE sytcode VALUE 'SE16',
gc_alv_screen TYPE sydynnr VALUE '0100',
gc_list_screen TYPE sydynnr VALUE '0200',
gc_col_column TYPE fieldname VALUE '/TABLESCANNER/TABCOL',
gc_col_red
TYPE n VALUE 6,
gc_col_green TYPE n VALUE 5,
gc_col_yellow TYPE n VALUE 3,
gc_max_row_height TYPE i VALUE 30000.
TABLES: tadir,
dd01l,
dd02l,
dd03l,
dd25l,
dd27s.

"object directory
"Domains
"tables
"table fields
"views
"view fields

TYPES: ty_value TYPE sbf_lookup.


TYPES: BEGIN OF ty_table,
tabname TYPE tabname,
fieldname TYPE fieldname,
keyflag TYPE keyflag,
domname TYPE domname,
devclass TYPE devclass,
ddtext
TYPE ddtext,
entries TYPE REF TO data,
entries2 TYPE REF TO data, "snapshot
count
TYPE sydbcnt,
container TYPE REF TO cl_gui_splitter_container,
row
TYPE sytabix,
alv
TYPE REF TO cl_gui_alv_grid,
salv
TYPE REF TO cl_salv_table,
col, "col_column_created

edit,
selkz,
END OF ty_table.
TYPES: BEGIN OF ty_sub_splitter,
container TYPE REF TO cl_gui_splitter_container,
height TYPE i,
END OF ty_sub_splitter.
DATA: gt_tables
TYPE
g_container
TYPE
g_gui_control_splitter TYPE
gt_sub_splitter
TYPE
g_with_edit
TYPE
ok_code TYPE syucomm.

TABLE OF ty_table,
REF TO cl_gui_custom_container,
REF TO cl_gui_splitter_container,
TABLE OF ty_sub_splitter,
abap_bool,

FIELD-SYMBOLS: <gs_table> LIKE LINE OF gt_tables.


*&---------------------------------------------------------------------*
* selection screen
DATA: v TYPE ty_value.
SELECT-OPTIONS values FOR v OBLIGATORY.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF BLOCK fields WITH FRAME TITLE t_fields.
SELECT-OPTIONS fieldnam FOR dd03l-fieldname.
SELECT-OPTIONS rollname FOR dd03l-rollname.
SELECT-OPTIONS domain FOR dd01l-domname.
PARAMETERS
key
TYPE aind_keyfl AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK fields.
SELECTION-SCREEN BEGIN OF BLOCK tables WITH FRAME TITLE t_tables.
SELECT-OPTIONS tabname FOR dd02l-tabname.
SELECT-OPTIONS devclass FOR tadir-devclass.
SELECT-OPTIONS contflag FOR dd02l-contflag.
PARAMETERS
dbviews TYPE classview AS CHECKBOX.
PARAMETERS
maxsel TYPE tbmaxsel DEFAULT 250.
SELECTION-SCREEN END OF BLOCK tables.
PARAMETERS
level
TYPE char3 NO-DISPLAY.
* selection screen 2000 for user settings
SELECTION-SCREEN BEGIN OF SCREEN 2000.
PARAMETERS convexit TYPE tbconvert AS CHECKBOX DEFAULT 'X'.
PARAMETERS changlog TYPE char1
AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN SKIP 1.
PARAMETERS rb_name TYPE eufieldnam RADIOBUTTON GROUP name
DEFAULT 'X'.
PARAMETERS rb_text TYPE eufieldtxt RADIOBUTTON GROUP name.
SELECTION-SCREEN SKIP 1.
PARAMETERS rb_alv TYPE tbalv_grid RADIOBUTTON GROUP disp
DEFAULT 'X'.
PARAMETERS rb_list TYPE tbalv_stan RADIOBUTTON GROUP disp.
SELECTION-SCREEN END OF SCREEN 2000.
* selection screen 3000 for search value
SELECTION-SCREEN BEGIN OF SCREEN 3000.
PARAMETERS scstring TYPE sc_string OBLIGATORY.
SELECTION-SCREEN END OF SCREEN 3000.
*
AT SELECTION-SCREEN OUTPUT.

PERFORM selection_screen_output.
AT SELECTION-SCREEN ON BLOCK fields.
IF fieldnam[] IS INITIAL AND
rollname[] IS INITIAL AND
domain[] IS INITIAL AND
sy-ucomm(1) NE '%'. "multiple selection
MESSAGE e237(law_messages).
ENDIF.
INITIALIZATION.
PERFORM initialization.
AT USER-COMMAND.
ok_code = sy-ucomm.
PERFORM user_command.
*&---------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM get_tables.
LOOP AT gt_tables ASSIGNING <gs_table>.
PERFORM select_data.
ENDLOOP.
IF rb_alv EQ abap_true.
PERFORM alv_show.
CALL SCREEN gc_alv_screen.
ELSE.
CALL SCREEN gc_list_screen.
ENDIF.
*---------------------------------------------------------------------*
* ALV grid classes
*---------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive,
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm,
handle_double_click
FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column.
PRIVATE SECTION.
ENDCLASS.

"lcl_event_receiver DEFINITION

*---------------------------------------------------------------------*
*
CLASS lcl_event_receiver IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_toolbar.
PERFORM handle_toolbar CHANGING e_object e_interactive.
ENDMETHOD.
"handle_toolbar
*------------------------------------------------------------------METHOD handle_user_command.

PERFORM handle_user_command USING e_ucomm.


ENDMETHOD.
"handle_user_command
*------------------------------------------------------------------METHOD handle_double_click.
PERFORM handle_double_click USING e_row e_column.
ENDMETHOD.
"handle_double_click
*----------------------------------------------------------------ENDCLASS.
"lcl_event_receiver IMPLEMENTATION
DATA: g_event_receiver TYPE REF TO lcl_event_receiver.
*&--------------------------------------------------------------------*
*&
Form assign_current_table
*&--------------------------------------------------------------------*
FORM assign_current_table.
DATA: l_control TYPE REF TO cl_gui_control,
l_alv TYPE REF TO cl_gui_alv_grid.
CALL METHOD cl_gui_container=>get_focus
IMPORTING
control = l_control
EXCEPTIONS
OTHERS = 0.
CATCH SYSTEM-EXCEPTIONS move_cast_error = 4.
l_alv ?= l_control.
ENDCATCH.
CHECK sy-subrc EQ 0.
READ TABLE gt_tables ASSIGNING <gs_table> WITH KEY alv = l_alv.
ASSERT sy-subrc EQ 0.
ENDFORM.

"assign_current_table

*&--------------------------------------------------------------------*
*&
Form handle_toolbar
*&--------------------------------------------------------------------*
FORM handle_toolbar
CHANGING e_object TYPE REF TO cl_alv_event_toolbar_set
e_interactive TYPE char01.
DATA: ls_toolbar TYPE stb_button,
lt_icon TYPE TABLE OF stypeicon.
* append a separator to normal toolbar
CLEAR ls_toolbar.
MOVE 3 TO ls_toolbar-butn_type.
APPEND ls_toolbar TO e_object->mt_toolbar.
IF g_with_edit EQ abap_true.
* append button for change
CLEAR ls_toolbar.
MOVE 'CHANGE' TO ls_toolbar-function.
PERFORM get_icon USING icon_toggle_display_change
CHANGING ls_toolbar.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDIF.
IF <gs_table>-edit EQ abap_true.
* append button for save
CLEAR ls_toolbar.

MOVE 'SAVE' TO ls_toolbar-function.


PERFORM get_icon USING icon_system_save
CHANGING ls_toolbar.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDIF.
append button for DDIC
CLEAR ls_toolbar.
MOVE 'SHOWDDIC' TO ls_toolbar-function.
PERFORM get_icon USING icon_database_table
CHANGING ls_toolbar.
APPEND ls_toolbar TO e_object->mt_toolbar.
append button for where used
CLEAR ls_toolbar.
MOVE 'WHEREUSED' TO ls_toolbar-function.
PERFORM get_icon USING icon_reference_list
CHANGING ls_toolbar.
APPEND ls_toolbar TO e_object->mt_toolbar.
append button for refresh
CLEAR ls_toolbar.
MOVE 'REFRESH' TO ls_toolbar-function.
PERFORM get_icon USING icon_refresh
CHANGING ls_toolbar.
APPEND ls_toolbar TO e_object->mt_toolbar.
"ICON_SYSTEM_MODUS_CREATE
append button for collaps table
CLEAR ls_toolbar.
IF <gs_table>-count IS INITIAL.
MOVE 'EXPAND' TO ls_toolbar-function.
PERFORM get_icon USING icon_data_area_expand
CHANGING ls_toolbar.
ELSE.
MOVE 'COLLAPSE' TO ls_toolbar-function.
PERFORM get_icon USING icon_data_area_collapse
CHANGING ls_toolbar.
ENDIF.
CONCATENATE <gs_table>-tabname ': "' <gs_table>-ddtext '"'
INTO ls_toolbar-text.
APPEND ls_toolbar TO e_object->mt_toolbar.

ENDFORM.

"handle_toolbar

*&--------------------------------------------------------------------*
*&
Form handle_user_command
*&--------------------------------------------------------------------*
FORM handle_user_command USING e_ucomm TYPE syucomm.
DATA: lt_rows
ls_row
ls_col
lt_fieldcat
l_fnam
l_dref

TYPE
TYPE
TYPE
TYPE
TYPE
TYPE

lvc_t_row,
lvc_s_row,
lvc_s_col,
lvc_t_fcat,
d021s-fnam,
REF TO data.

FIELD-SYMBOLS: <lt_entries> TYPE STANDARD TABLE,


<lt_entries2> TYPE STANDARD TABLE,
<ls_entry> TYPE any,
<ls_dbtab> TYPE any.
PERFORM assign_current_table.

CASE e_ucomm.
WHEN 'REFRESH'.
PERFORM refresh_table.
WHEN 'CLOSE'.
g_gui_control_splitter->remove_control( row
= <gs_table>-row
column = 1 ).
DELETE gt_tables WHERE tabname = <gs_table>-tabname.
WHEN 'COLLAPSE'.
CLEAR <gs_table>-count.
PERFORM set_pane_height USING <gs_table>.
CALL METHOD <gs_table>-alv->refresh_table_display.
WHEN 'EXPAND'.
ASSIGN <gs_table>-entries->* TO <lt_entries>.
DESCRIBE TABLE <lt_entries> LINES <gs_table>-count.
PERFORM set_pane_height USING <gs_table>.
CALL METHOD <gs_table>-alv->refresh_table_display.
WHEN 'SHOWDDIC'.
CALL METHOD <gs_table>-alv->get_current_cell
IMPORTING
es_col_id = ls_col.
l_fnam = ls_col-fieldname.
CALL FUNCTION 'RS_DD_FIEL_SHOW'
"#EC FB_OLDED
EXPORTING
fname = l_fnam
objname = <gs_table>-tabname.
WHEN 'WHEREUSED'.
CALL METHOD <gs_table>-alv->get_current_cell
IMPORTING
es_col_id = ls_col
es_row_id = ls_row.
PERFORM where_used USING ls_row ls_col.
WHEN 'NEWMODE'.
WHEN 'CHANGE'.
TRANSLATE <gs_table>-edit USING 'X X'.
PERFORM set_table_for_first_display.
WHEN 'SAVE'.
CREATE DATA l_dref TYPE (<gs_table>-tabname).
ASSIGN l_dref->* TO <ls_dbtab>.
ASSIGN <gs_table>-entries->* TO <lt_entries>.
ASSIGN <gs_table>-entries2->* TO <lt_entries2>.
*
save new values
<lt_entries2>[] = <lt_entries>[].
PERFORM select_data.
DELETE (<gs_table>-tabname) FROM TABLE <lt_entries>.
LOOP AT <lt_entries2> ASSIGNING <ls_entry>.
MOVE-CORRESPONDING <ls_entry> TO <ls_dbtab>.
INSERT (<gs_table>-tabname) FROM <ls_dbtab>.
ENDLOOP.
<lt_entries>[] = <lt_entries2>[].
*
update alv
CLEAR <gs_table>-edit.
PERFORM set_table_for_first_display.
ENDCASE.
ENDFORM.
"handle_user_command
*&--------------------------------------------------------------------*
*&
Form handle_double_click
*&--------------------------------------------------------------------*
FORM handle_double_click USING is_row
TYPE lvc_s_row

is_column TYPE lvc_s_col.


PERFORM handle_user_command USING 'SHOWDDIC'.
ENDFORM.

"handle_double_click

*&--------------------------------------------------------------------*
*&
Form where_used
*&--------------------------------------------------------------------*
FORM where_used USING is_row
TYPE lvc_s_row
is_column TYPE lvc_s_col.
DATA: lr_values
ls_value
lt_rows
ls_row
ls_varid
lf_level
lt_dfies

TYPE
LIKE
TYPE
LIKE
TYPE
LIKE
TYPE

RANGE OF ty_value,
LINE OF lr_values,
lvc_t_row,
LINE OF lt_rows,
varid,
level,
TABLE OF dfies WITH HEADER LINE.

FIELD-SYMBOLS: <lt_entries> TYPE INDEX TABLE,


<ls_entry_now> TYPE any,
<lf_field> TYPE any.
PERFORM assign_current_table.
CALL FUNCTION
EXPORTING
tabname
fieldname
TABLES
dfies_tab
EXCEPTIONS
OTHERS

'DDIF_FIELDINFO_GET'
= <gs_table>-tabname
= is_column-fieldname
= lt_dfies
= 0.

READ TABLE lt_dfies INDEX 1.


ASSERT sy-subrc EQ 0.
CALL METHOD <gs_table>-alv->get_selected_rows
IMPORTING
et_index_rows = lt_rows.
ls_value = 'IEQ'.
IF lt_rows[] IS INITIAL.
* no row selected -> get value of clicked cell
CALL METHOD <gs_table>-alv->get_current_cell
IMPORTING
e_value = ls_value-low.
APPEND ls_value TO lr_values.
ELSE.
* some rows selected -> get several values
ASSIGN <gs_table>-entries->* TO <lt_entries>.
LOOP AT lt_rows INTO ls_row.
READ TABLE <lt_entries> ASSIGNING <ls_entry_now>
INDEX ls_row-index.
ASSERT sy-subrc EQ 0.
ASSIGN COMPONENT is_column-fieldname OF STRUCTURE <ls_entry_now>
TO <lf_field>.
ls_value-low = <lf_field>.
APPEND ls_value TO lr_values.

ENDLOOP.
SORT lr_values.
DELETE ADJACENT DUPLICATES FROM lr_values.
ENDIF.
* check whether there is a varint
SELECT SINGLE * FROM varid INTO
WHERE report EQ
AND variant EQ

with the domain name


ls_varid
sy-repid
lt_dfies-rollname.

IF sy-subrc EQ 0 AND ls_varid-edat < '20050523'.


MESSAGE i634(db) WITH ls_varid-variant sy-repid.
CLEAR ls_varid.
ENDIF.
lf_level = level + 1.
IF ls_varid IS INITIAL.
SUBMIT (sy-repid) VIA SELECTION-SCREEN
WITH values IN lr_values
WITH rollname EQ lt_dfies-rollname
WITH domain EQ lt_dfies-domname
WITH key
EQ key
WITH dbviews EQ dbviews
WITH level
EQ lf_level
AND RETURN.
ELSE.
SUBMIT (sy-repid) VIA SELECTION-SCREEN
USING SELECTION-SET ls_varid-variant
WITH values IN lr_values
WITH rollname EQ lt_dfies-rollname
WITH domain EQ lt_dfies-domname
WITH key
EQ key
WITH dbviews EQ dbviews
WITH level
EQ lf_level
AND RETURN.
ENDIF.
ENDFORM.

"where_used

*&---------------------------------------------------------------------*
*&
Form get_icon
*&---------------------------------------------------------------------*
FORM get_icon USING
i_icon
TYPE icon_d
CHANGING cs_toolbar TYPE stb_button.
cs_toolbar-icon = i_icon.
CLEAR cs_toolbar-disabled.
SELECT SINGLE
INTO
WHERE
AND

shorttext quickinfo FROM icont


(cs_toolbar-text, cs_toolbar-quickinfo)
id
EQ i_icon
langu EQ sy-langu.

CLEAR cs_toolbar-text.
ENDFORM.

" get_icon

*&--------------------------------------------------------------------*

*&
Form initialization
*&--------------------------------------------------------------------*
FORM initialization.
CALL FUNCTION 'AUTHORITY_CHECK_TCODE'
EXPORTING
tcode = gc_se16
EXCEPTIONS
ok
= 1
not_ok = 2
OTHERS = 3.
IF sy-subrc NE 1.
MESSAGE e077(s#) WITH gc_se16.
ENDIF.
* generate screen
PERFORM generate_screen USING gc_list_screen.
* get texts for selection screen titles
SELECT SINGLE ddtext FROM dd02t INTO t_tables
WHERE tabname
EQ 'DD02L'
AND ddlanguage EQ sy-langu
AND as4local EQ 'A'
AND as4vers
EQ 0.
SELECT SINGLE ddtext FROM
WHERE
AND
AND
AND
ENDFORM.

dd02t INTO
tabname
ddlanguage
as4local
as4vers

t_fields
EQ 'DD03L'
EQ sy-langu
EQ 'A'
EQ 0.

"initialization

*&--------------------------------------------------------------------*
*&
Form selection_screen_output
*&--------------------------------------------------------------------*
*
get selection texts dynamically
*---------------------------------------------------------------------*
FORM selection_screen_output.
FIELD-SYMBOLS: <sn>.
DATA: lf_name LIKE dcobjdef-name,
lf_tabname LIKE dfies-tabname,
lf_fieldname LIKE dfies-fieldname,
lf_length LIKE sy-fdpos,
ls_dd04v LIKE dd04v,
lt_dfies LIKE TABLE OF dfies WITH HEADER LINE.
STATICS: lt_sscr LIKE TABLE OF rsscr WITH HEADER LINE,
lf_repid LIKE sy-repid.
IF sy-repid NE lf_repid.
LOAD REPORT sy-repid PART 'SSCR' INTO lt_sscr.
lf_repid = sy-repid.
ENDIF.
LOOP AT SCREEN.
CHECK screen-group3 EQ 'TXT'.
ASSIGN (screen-name) TO <sn>.
CHECK sy-subrc EQ 0.

check if text is identical to technical name


SEARCH screen-name FOR '_%' STARTING AT 3.
lf_length = sy-fdpos .
lf_name = screen-name+2(lf_length).
CHECK <sn> EQ lf_name.

get text from ddic (database field or data element)


CLEAR: ls_dd04v, lt_sscr.
READ TABLE lt_sscr WITH KEY name = lf_name.
CHECK lt_sscr-dbfield NE space.
IF lt_sscr-dbfield CS '-'.
SPLIT lt_sscr-dbfield AT '-' INTO lf_tabname lf_fieldname.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = lf_tabname
fieldname = lf_fieldname
TABLES
dfies_tab = lt_dfies
EXCEPTIONS
OTHERS
= 3.
IF sy-subrc EQ 0.
READ TABLE lt_dfies INDEX 1.
MOVE-CORRESPONDING lt_dfies TO ls_dd04v.
ENDIF.
ELSE.
lf_name = lt_sscr-dbfield.
IF screen-name CS 'CHANGLOG'.
lf_name = 'BU_XNOFILTER'.
ENDIF.
CALL FUNCTION 'DDIF_DTEL_GET'
EXPORTING
name
= lf_name
langu
= sy-langu
IMPORTING
dd04v_wa = ls_dd04v
EXCEPTIONS
OTHERS = 0.
ENDIF.

move ddic text to parameter text.


CHECK ls_dd04v-rollname NE space.
CHECK ls_dd04v-scrtext_l NE space.
<sn> = ls_dd04v-scrtext_l.
ENDLOOP.

ENDFORM.

"selection_screen_output

*&---------------------------------------------------------------------*
*&
Form get_tables
*&---------------------------------------------------------------------*
FORM get_tables .
DATA: lr_table_type
lr_line_type
lt_comp
ls_comp
ls_table

TYPE
TYPE
TYPE
LIKE
LIKE

REF TO cl_abap_tabledescr,
REF TO cl_abap_structdescr,
cl_abap_structdescr=>component_table,
LINE OF lt_comp,
LINE OF gt_tables,

lt_dd01l
lt_dd02t
ls_dfies
lt_domname

TYPE
TYPE
TYPE
TYPE

TABLE OF dd01l WITH HEADER LINE,


TABLE OF dd02t WITH HEADER LINE,
dfies,
TABLE OF domname.

FIELD-SYMBOLS: <ls_table> LIKE LINE OF gt_tables.


DEFINE addfield.
split &1 at '-' into ls_table-tabname ls_table-fieldname.
append ls_table to gt_tables.
END-OF-DEFINITION.
* get database tables
SELECT dd03l~tabname dd03l~fieldname dd03l~keyflag domname
devclass
FROM dd03l
INNER JOIN dd02l
ON dd03l~tabname EQ dd02l~tabname
INNER JOIN tadir
"#EC CI_BUFFJOIN
ON tadir~obj_name EQ dd02l~tabname
AND tadir~pgmid
EQ 'R3TR'
AND tadir~object EQ 'TABL'
INTO CORRESPONDING FIELDS OF TABLE gt_tables
WHERE domname
IN domain
AND rollname
IN rollname
AND fieldname
IN fieldnam
AND ( tabclass EQ 'TRANSP' OR
tabclass EQ 'CLUSTER' OR
tabclass EQ 'POOL' )
AND dd02l~tabname IN tabname
AND dd02l~contflag IN contflag
AND tadir~devclass IN devclass.
IF dbviews NE space.
* get database views
SELECT dd27s~viewname dd27s~viewfield "domname?
FROM dd27s INNER JOIN dd25l
ON dd27s~viewname EQ dd25l~viewname
AND dd27s~as4local EQ dd25l~as4local
AND dd27s~as4vers EQ dd25l~as4vers
APPENDING CORRESPONDING FIELDS OF TABLE gt_tables
FOR ALL ENTRIES IN gt_tables
WHERE tabname
EQ gt_tables-tabname
AND fieldname
EQ gt_tables-fieldname
AND viewclass
EQ 'D'.
"database view
DELETE gt_tables WHERE fieldname CA '*-'. "remove special viewfields
ENDIF.
IF key NE space.
DELETE gt_tables WHERE keyflag EQ space.
ENDIF.
* add some additional table fields with different domains
IF 1 = 0.
IF 'MATNR' IN domain.
addfield: 'BDCP-CDOBJID',
'BDCP2-CDOBJID',
'CDHDR-OBJECTID',
'CDPOS_UID-OBJECTID',
'PCDHDR-OBJECTID',
'PCDPOS_UID-OBJECTID',

'CDSOLMIG_HDR-OBJECTID',
'CDSOLMIG_HDR-OBJECTID',
'CUCO-OBJEK'.
ENDIF.
IF 'AENNR' IN domain.
addfield: 'JEST-OBJNR'.
ENDIF.
ENDIF.
CHECK gt_tables[] IS NOT INITIAL.
SORT gt_tables.
SELECT tabname ddtext
FROM dd02t INTO CORRESPONDING FIELDS OF TABLE lt_dd02t
FOR ALL ENTRIES IN gt_tables
WHERE tabname
EQ gt_tables-tabname
AND ddlanguage EQ sy-langu.
SORT lt_dd02t BY tabname.
LOOP AT gt_tables ASSIGNING <ls_table>.
READ TABLE lt_dd02t WITH KEY tabname = <ls_table>-tabname
BINARY SEARCH.
IF sy-subrc EQ 0.
<ls_table>-ddtext = lt_dd02t-ddtext.
ENDIF.
*
*

create internal table dynamically


(here without col_column) because of performance
TRY.
CREATE DATA <ls_table>-entries
TYPE STANDARD TABLE OF (<ls_table>-tabname)
WITH NON-UNIQUE DEFAULT KEY.
CATCH cx_sy_create_data_error.
DELETE gt_tables.
CONTINUE.
ENDTRY.
* collect domains
COLLECT <ls_table>-domname INTO lt_domname.
ENDLOOP.
* get domains
SELECT * FROM
FOR
WHERE
AND
AND

dd01l INTO TABLE lt_dd01l


ALL ENTRIES IN lt_domname
domname EQ lt_domname-table_line
as4local EQ 'A'
as4vers EQ 0.

* compare domains
READ TABLE lt_dd01l INDEX 1.
LOOP AT lt_dd01l FROM 2 WHERE
OR
OR
OR
OR
OR
OR
EXIT.
ENDLOOP.

datatype
leng
outputlen
decimals
lowercase
signflag
convexit

NE
NE
NE
NE
NE
NE
NE

lt_dd01l-datatype
lt_dd01l-leng
lt_dd01l-outputlen
lt_dd01l-decimals
lt_dd01l-lowercase
lt_dd01l-signflag
lt_dd01l-convexit.

IF sy-subrc NE 0.
all domains are similar -> input conversion
MOVE-CORRESPONDING lt_dd01l TO ls_dfies.
LOOP AT values.
PERFORM input_conversion USING ls_dfies
CHANGING: values-low,
values-high.
MODIFY values.
ENDLOOP.
ENDIF.

ENDFORM.

" get_tables

*&--------------------------------------------------------------------*
*&
Form show_tables
*&--------------------------------------------------------------------*
*
show result of gt_table in popup.
*---------------------------------------------------------------------*
FORM show_tables.
DATA: lr_table
lr_columns
lr_column
lr_functions

TYPE
TYPE
TYPE
TYPE

REF
REF
REF
REF

TO
TO
TO
TO

cl_salv_table,
cl_salv_columns,
cl_salv_column_table,
cl_salv_functions.

TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = lr_table
CHANGING
t_table
= gt_tables ).
lr_columns = lr_table->get_columns( ).
lr_columns->set_optimize( abap_true ).
lr_column ?= lr_columns->get_column( 'ROW' ).
lr_column->set_technical( abap_true ).
lr_column ?= lr_columns->get_column( 'SELKZ' ).
lr_column->set_technical( abap_true ).
lr_column ?= lr_columns->get_column( 'EDIT' ).
lr_column->set_technical( abap_true ).
lr_column ?= lr_columns->get_column( 'COL' ).
lr_column->set_technical( abap_true ).
lr_column ?= lr_columns->get_column( 'COUNT' ).
lr_column->set_zero( abap_false ).
CATCH cx_salv_msg.
CATCH cx_salv_not_found.
CATCH cx_salv_existing cx_salv_wrong_call.
ENDTRY.
lr_functions = lr_table->get_functions( ).
lr_functions->set_all( abap_true ).
lr_table->set_screen_popup(
start_column = 2
end_column = 100
start_line = 2
end_line
= 40 ).

"#EC NO_HANDLER
"#EC NO_HANDLER

lr_table->display( ).
ENDFORM.
"show_tables
*&--------------------------------------------------------------------*
*&
Form input_conversion
*&--------------------------------------------------------------------*
FORM input_conversion USING is_dfies TYPE dfies
CHANGING ch_value.
DATA lc_func TYPE funcname VALUE 'SMAN_IF_CONVERT_TO_INTERN'.
CALL FUNCTION lc_func
EXPORTING
ls_struc
=
ld_input_value =
IMPORTING
ld_output_value =
EXCEPTIONS
OTHERS
=

is_dfies
ch_value
ch_value
0.

IF is_dfies-lowercase IS INITIAL.
TRANSLATE ch_value TO UPPER CASE.
ENDIF.
ENDFORM.

"#EC TRANSLANG

"input_conversion

*&--------------------------------------------------------------------*
*&
Form select_data
*&--------------------------------------------------------------------*
FORM select_data.
types: ch72(72).
DATA: lf_total TYPE sydbcnt,
lf_percentage TYPE i,
lt_where TYPE TABLE OF ch72 WITH HEADER LINE.
FIELD-SYMBOLS: <lt_entries> TYPE ANY TABLE.
DESCRIBE TABLE gt_tables LINES lf_total.
CHECK <gs_table>-fieldname IS NOT INITIAL.
lf_percentage = sy-tabix * 100 / lf_total.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = lf_percentage
text
= <gs_table>-tabname.
*

build where condition dynamically


REFRESH lt_where.
CONCATENATE <gs_table>-fieldname 'IN values'
INTO lt_where SEPARATED BY space.
APPEND lt_where.

"#EC NOTEXT

select dynamically, CORRESPONDING needed for database views


ASSIGN <gs_table>-entries->* TO <lt_entries>.
SELECT * FROM (<gs_table>-tabname)
INTO CORRESPONDING FIELDS OF TABLE <lt_entries>
UP TO maxsel ROWS
WHERE (lt_where).

<gs_table>-count = sy-dbcnt.
IF <gs_table>-count NE 0.
SORT <lt_entries>. "not during SELECT cause of performance
PERFORM append_col_column. "convert entries, create entries2
ENDIF.
ENDFORM.

"select_data

*&--------------------------------------------------------------------*
*&
Form write_result
*&--------------------------------------------------------------------*
FORM write_result.
DATA: lf_length TYPE syfleng,
lt_dfies TYPE TABLE OF dfies WITH HEADER LINE.
FIELD-SYMBOLS: <ls_table> LIKE LINE OF gt_tables,
<lt_entries> TYPE ANY TABLE,
<ls_entry_now> TYPE any,
<lf_field> TYPE any.
*

LOOP AT gt_tables ASSIGNING <ls_table> WHERE count NE 0.


write entries to screen
lf_length = strlen( <ls_table>-tabname ).
WRITE: / <ls_table>-tabname(lf_length) COLOR COL_HEADING,
<ls_table>-ddtext.
CALL FUNCTION
EXPORTING
tabname
TABLES
dfies_tab
EXCEPTIONS
OTHERS

'DDIF_FIELDINFO_GET'
= <ls_table>-tabname
= lt_dfies
= 0.

ASSIGN <ls_table>-entries->* TO <lt_entries>.


LOOP AT <lt_entries> ASSIGNING <ls_entry_now>.
LOOP AT lt_dfies WHERE keyflag NE space.
ASSIGN COMPONENT lt_dfies-fieldname
OF STRUCTURE <ls_entry_now> TO <lf_field>
TYPE lt_dfies-inttype.
*
write field (currently without conversion exit)
IF sy-tabix EQ 1.
WRITE / <lf_field> COLOR COL_KEY.
ELSE.
WRITE <lf_field> COLOR COL_KEY.
ENDIF.
ENDLOOP.
ENDLOOP.
ULINE.
ENDLOOP.
ENDFORM.

"write_result

*&--------------------------------------------------------------------*
*&
Form alv_show
*&--------------------------------------------------------------------*
FORM alv_show.
DATA: lf_panes TYPE sylinno,

lf_column TYPE sycolno,


lf_count TYPE sydbcnt,
lf_max
TYPE sydbcnt VALUE 16,
ls_layout TYPE lvc_s_layo,
ls_variant TYPE disvariant,
lt_fieldcat TYPE lvc_t_fcat,
ls_fieldcat TYPE lvc_s_fcat,
lt_exclude TYPE ui_functions.
DATA: lf_splitters
TYPE sydbcnt,
l_container
TYPE REF TO cl_gui_container,
ls_sub_splitter TYPE ty_sub_splitter.
PERFORM generate_screen USING gc_alv_screen.
CLEAR sy-dbcnt.
LOOP AT gt_tables ASSIGNING <gs_table> WHERE count NE 0.
ADD 1 TO lf_count.
ADD <gs_table>-count TO sy-dbcnt.
ENDLOOP.
IF lf_count EQ 0.
MESSAGE s210(e1).
RETURN.
ENDIF.
MESSAGE s256(eu) WITH lf_count sy-dbcnt.
lf_splitters = ( lf_count DIV lf_max ) + 1.
IF g_container IS INITIAL.
* the main splitter
CREATE OBJECT g_container
EXPORTING
container_name = 'CONT1'.
CREATE OBJECT g_gui_control_splitter
EXPORTING
parent
= g_container
rows
= lf_splitters
columns
= 1
no_autodef_progid_dynnr = space
EXCEPTIONS
others
= 1.
g_gui_control_splitter->set_row_mode(
cl_gui_splitter_container=>mode_absolute ).
g_gui_control_splitter->set_border( space ).
*

create sub splitters


DO lf_splitters TIMES.
IF sy-index < lf_splitters.
lf_panes = lf_max.
ELSE.
lf_panes = lf_count MOD lf_max.
ENDIF.
CALL METHOD g_gui_control_splitter->get_container

EXPORTING
row
= sy-index
column
= 1
RECEIVING
container = l_container.
CREATE OBJECT ls_sub_splitter-container
EXPORTING
parent
= l_container
rows
= lf_panes
columns
= 1
no_autodef_progid_dynnr = space
EXCEPTIONS
others
= 1.
ls_sub_splitter-container->set_row_mode(
cl_gui_splitter_container=>mode_absolute ).
ls_sub_splitter-container->set_border( space ).
APPEND ls_sub_splitter TO gt_sub_splitter.
ENDDO.
*

one receiver for all


CREATE OBJECT g_event_receiver.
ENDIF.
PERFORM alv_show_loop.

ENDFORM.

"alv_show

*&--------------------------------------------------------------------*
*&
Form alv_show_loop
*&--------------------------------------------------------------------*
FORM alv_show_loop.
DATA: lf_column TYPE sycolno,
lf_splitter TYPE sytabix,
lf_count TYPE sydbcnt,
lf_max
TYPE sydbcnt VALUE 16,
l_splitter_container TYPE REF TO cl_gui_container.
FIELD-SYMBOLS: <l_sub_splitter> LIKE LINE OF gt_sub_splitter.
LOOP AT gt_sub_splitter ASSIGNING <l_sub_splitter>.
CLEAR <l_sub_splitter>-height.
ENDLOOP.
LOOP AT gt_tables ASSIGNING <gs_table> WHERE count NE 0.
ADD 1 TO lf_count.
lf_column = 1.
lf_splitter
= ( lf_count DIV lf_max ) + 1.
<gs_table>-row = lf_count MOD lf_max.
IF <gs_table>-row EQ 0.
<gs_table>-row = lf_max.

SUBTRACT 1 FROM lf_splitter.


ENDIF.
READ TABLE gt_sub_splitter INDEX lf_splitter
ASSIGNING <l_sub_splitter>.
<gs_table>-container = <l_sub_splitter>-container.
CALL METHOD <gs_table>-container->get_container
EXPORTING
row
= <gs_table>-row
column
= lf_column
RECEIVING
container = l_splitter_container.
*

create alv-grid
IF <gs_table>-alv IS INITIAL.
CREATE OBJECT <gs_table>-alv
EXPORTING
i_parent = l_splitter_container.
SET HANDLER:
g_event_receiver->handle_user_command FOR <gs_table>-alv,
g_event_receiver->handle_toolbar
FOR <gs_table>-alv,
g_event_receiver->handle_double_click FOR <gs_table>-alv.
ENDIF.
PERFORM set_pane_height USING <gs_table>.
PERFORM set_table_for_first_display.

add height to splitter


<l_sub_splitter>-height =
+
+
+

<l_sub_splitter>-height
50
"Header, toolar
19 * <gs_table>-count "Entries
20.
"Scrollbar

ADD 4 TO <l_sub_splitter>-height.

"separator

IF <l_sub_splitter>-height > gc_max_row_height.


<l_sub_splitter>-height = gc_max_row_height.
ENDIF.
ENDLOOP.
LOOP AT gt_sub_splitter ASSIGNING <l_sub_splitter>.
CALL METHOD g_gui_control_splitter->set_row_height
EXPORTING
id
= sy-tabix
height = <l_sub_splitter>-height.
ENDLOOP.
ENDFORM.

"alv_show_loop

*&--------------------------------------------------------------------*
*&
Form set_table_for_first_display
*&--------------------------------------------------------------------*
FORM set_table_for_first_display.
DATA: ls_layout TYPE lvc_s_layo,
ls_variant TYPE disvariant,

lt_fieldcat TYPE lvc_t_fcat,


ls_fieldcat TYPE lvc_s_fcat,
lt_exclude TYPE ui_functions.
FIELD-SYMBOLS: <lt_entries> TYPE ANY TABLE,
<l_sub_splitter> LIKE LINE OF gt_sub_splitter.
* prepare alv options.
ls_variant-report = sy-repid.
APPEND
APPEND
APPEND
APPEND
APPEND
APPEND
APPEND

cl_gui_alv_grid=>mc_mb_export
cl_gui_alv_grid=>mc_mb_subtot
cl_gui_alv_grid=>mc_mb_sum
cl_gui_alv_grid=>mc_mb_view
cl_gui_alv_grid=>mc_fc_graph
cl_gui_alv_grid=>mc_fc_info
cl_gui_alv_grid=>mc_fc_print

TO
TO
TO
TO
TO
TO
TO

lt_exclude.
lt_exclude.
lt_exclude.
lt_exclude.
lt_exclude.
lt_exclude.
lt_exclude.

ls_layout-sel_mode = 'A'.
ls_layout-cwidth_opt = 'X'.
ls_layout-ctab_fname = gc_col_column.
ASSIGN <gs_table>-entries->* TO <lt_entries>.
*
*

CONCATENATE <gs_table>-tabname ': "' <gs_table>-ddtext '"'


INTO ls_layout-grid_title.
ls_variant-report = <gs_table>-tabname.
PERFORM modify_fieldcat CHANGING lt_fieldcat.

CALL METHOD <gs_table>-alv->set_table_for_first_display


EXPORTING
*
i_structure_name
= <gs_table>-tabname
is_variant
= ls_variant
is_layout
= ls_layout
i_save
= 'U' "only user
it_toolbar_excluding = lt_exclude
CHANGING
it_fieldcatalog
= lt_fieldcat
it_outtab
= <lt_entries>.
* raise event toolbar
CALL METHOD <gs_table>-alv->set_toolbar_interactive.
ENDFORM.
"alv_set_table_for_first_display
*&--------------------------------------------------------------------*
*&
Form modify_fieldcatalog
*&--------------------------------------------------------------------*
FORM modify_fieldcat CHANGING ct_fieldcat TYPE lvc_t_fcat.
FIELD-SYMBOLS <ls_fieldcat> TYPE lvc_s_fcat.
* modify default fieldcat
REFRESH ct_fieldcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = <gs_table>-tabname
CHANGING
ct_fieldcat
= ct_fieldcat.

LOOP AT ct_fieldcat ASSIGNING <ls_fieldcat>.


<ls_fieldcat>-lzero = abap_true.
IF convexit IS INITIAL.
<ls_fieldcat>-no_convext = abap_true. "not enough
CLEAR <ls_fieldcat>-convexit.
"also important
ELSE.
<ls_fieldcat>-no_convext = abap_false.
ENDIF.
IF rb_name EQ abap_true.
<ls_fieldcat>-scrtext_s =
<ls_fieldcat>-scrtext_m =
<ls_fieldcat>-scrtext_l =
<ls_fieldcat>-reptext = <ls_fieldcat>-fieldname.
ENDIF.
IF <ls_fieldcat>-fieldname = <gs_table>-fieldname.
* SPACE, 'X' oder 'Cxyz' (x:'1'-'9'; y,z: '0'=off '1'=on)
* wird das Feld mit 'X' gesetzt, benutzt ALV eine voreingestellte Farbe
* (Farbkodierung), haben die restlichen Zahlen die folgende Bedeutung:
* x: Farbnummer
* y: intensivierte Darstellung an/aus
* z: inverse Darstellung an/aus
* Weitere Informationen zur Farbkodierung finden Sie in der F1-Hilfe zur
* FORMAT -Anweisung.
*{ COL_BACKGROUND } 0 GUI-abhngig
*{ 1 | COL_HEADING } 1 Graublau
*{ 2 | COL_NORMAL } 2 Hellgrau
*{ 3 | COL_TOTAL } 3 Gelb
*{ 4 | COL_KEY } 4 Blaugrn
*{ 5 | COL_POSITIVE } 5 Grn
*{ 6 | COL_NEGATIVE } 6 Rot
*{ 7 | COL_GROUP } 7 Violett
IF <ls_fieldcat>-key IS INITIAL.
<ls_fieldcat>-emphasize = 'C300'. "gelb
ELSE.
*
fr Keyfelder klappt die Farbnderung nicht???
<ls_fieldcat>-emphasize = 'C310'. "gelb intensiv
ENDIF.
ENDIF.
<ls_fieldcat>-edit = <gs_table>-edit.
ENDLOOP.
ENDFORM.
"modify_fieldcat
*&--------------------------------------------------------------------*
*&
Form generate_screen
*&--------------------------------------------------------------------*
FORM generate_screen USING i_dynnr TYPE sydynnr.
DATA: lt_dynp_fields
lt_containers
lt_flow_logic
ls_dynp_header
lf_count

TYPE
TYPE
TYPE
TYPE
TYPE

dyfatc_tab WITH HEADER LINE,


dycatt_tab WITH HEADER LINE,
TABLE OF rpy_dyflow,
rpy_dyhead,
p.

CALL FUNCTION 'RPY_DYNPRO_READ'


EXPORTING
progname
= 'BCALV_GRID_11'
dynnr
= gc_alv_screen
IMPORTING
header
= ls_dynp_header

TABLES
fields_to_containers
containers
flow_logic
EXCEPTIONS
OTHERS
ls_dynp_header-program
ls_dynp_header-screen
ls_dynp_header-lines
ls_dynp_header-columns

=
=
=
=

= lt_dynp_fields
= lt_containers
= lt_flow_logic
= 0.
sy-repid.
i_dynnr.
80.
150.

CASE i_dynnr.
WHEN gc_alv_screen.
LOOP AT gt_tables ASSIGNING <gs_table> WHERE count NE 0.
lf_count = lf_count
+ '0.9' * <gs_table>-count
+ '3.4'.
ENDLOOP.
ADD 2 TO lf_count.
IF lf_count > 255.
* MESSAGE w398(00) WITH 'Hit list does not match on the screen.'.
lf_count = 255.
ENDIF.
ls_dynp_header-lines
lt_containers-line
lt_containers-column
lt_containers-length
lt_containers-height
MODIFY lt_containers

= lf_count.
= 1.
= 1.
= ls_dynp_header-columns.
= ls_dynp_header-lines.
TRANSPORTING line column length height
WHERE name = 'CONT1'.

WHEN gc_list_screen.
DELETE lt_containers WHERE name = 'CONT1'.
lf_count = 80.
ENDCASE.
CALL FUNCTION 'RPY_DYNPRO_INSERT'
EXPORTING
suppress_corr_checks
= 'X'
suppress_exist_checks
= 'X'
suppress_dict_support
= 'X'
suppress_extended_checks = 'X'
header
= ls_dynp_header
TABLES
containers
= lt_containers
fields_to_containers
= lt_dynp_fields
flow_logic
= lt_flow_logic
EXCEPTIONS
OTHERS
= 0.
ENDFORM.
"generate_screen
*&--------------------------------------------------------------------*
*&
Form set_height
*&--------------------------------------------------------------------*
FORM set_pane_height USING ls_table TYPE ty_table.
DATA: lf_height TYPE i.

lf_height = 50
+ 19 * ls_table-count
+ 20.

"Header, toolar
"Entries
"Scrollbar

IF lf_height > gc_max_row_height.


lf_height = gc_max_row_height.
ENDIF.
CALL METHOD <gs_table>-container->set_row_height
EXPORTING
id
= ls_table-row
height = lf_height.
ENDFORM.
"set_height
*&---------------------------------------------------------------------*
*&
Module STATUS OUTPUT
*&---------------------------------------------------------------------*
MODULE pbo OUTPUT.
CASE sy-dynnr.
WHEN gc_alv_screen.
PERFORM status USING 'TAB_LIS4'.
WHEN gc_list_screen.
PERFORM write_result.
PERFORM status USING 'TAB_LIS4'. "'LISTE_ALV'.
SUPPRESS DIALOG.
LEAVE TO LIST-PROCESSING.
ENDCASE.
ENDMODULE.
" STATUS OUTPUT
*&--------------------------------------------------------------------*
*&
Form status
*&--------------------------------------------------------------------*
FORM status USING i_status.
CONSTANTS: lc_program TYPE progname VALUE 'SAPLSETB'.
DATA: lt_functions
l_title

TYPE STANDARD TABLE OF rseul_fun,


TYPE sytitle.

STATICS: lt_cua_exclude TYPE TABLE OF gui_func. "syucomm.


IF lt_cua_exclude[] IS INITIAL.
CALL FUNCTION 'RS_CUA_GET_STATUS_FUNCTIONS'
EXPORTING
program = lc_program
status
= i_status
TABLES
functions = lt_functions
EXCEPTIONS
OTHERS
= 0.
lt_cua_exclude[] = lt_functions[].
DELETE lt_cua_exclude WHERE table_line
OR table_line
OR table_line
OR table_line
OR table_line
OR table_line

EQ
EQ
EQ
EQ
EQ
EQ

'BACK'
'%EX'
'%SC'
'RW'
'SOUP'
'SODO'

OR
OR
OR
OR
OR

table_line
table_line
table_line
table_line
table_line

EQ
EQ
EQ
EQ
EQ

'HILF'
'MARK'
'DMAR'
'REFR'
'FNAM'.

ENDIF.
SET PF-STATUS i_status OF PROGRAM lc_program
EXCLUDING lt_cua_exclude.
* READ TABLE values INDEX 1.
* CONCATENATE sy-repid ' (' values-low ')' INTO l_title.
CONDENSE level NO-GAPS.
IF level IS INITIAL.
l_title = sy-repid.
ELSE.
CONCATENATE sy-repid ' (' level ')' INTO l_title.
ENDIF.
SET TITLEBAR 'POP' OF PROGRAM 'SAPLKKBL' WITH l_title.
ENDFORM.
"status
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE pai INPUT.
PERFORM user_command.
ENDMODULE.
" USER_COMMAND INPUT
*&---------------------------------------------------------------------*
*&
Form user_command
*&---------------------------------------------------------------------*
*
handle button from global applicatio toolbar
*----------------------------------------------------------------------*
FORM user_command.
DATA: lc_edit
lf_system
lt_rows
ls_row
ls_col

TYPE
TYPE
TYPE
TYPE
TYPE

sy-ucomm VALUE '&SAP_EDIT',


sy-sysid,
lvc_t_roid,
lvc_s_roid,
lvc_s_scol.

CASE ok_code.
WHEN 'BACK' OR 'ENTR'.
CLEAR sy-ucomm.
LEAVE TO SCREEN 0.
WHEN 'MARK' OR 'DMAR'.
LOOP AT gt_tables ASSIGNING <gs_table>
WHERE alv IS NOT INITIAL.
REFRESH lt_rows.
IF ok_code EQ 'MARK'.
DO <gs_table>-count TIMES.
ls_row-row_id = sy-index.
APPEND ls_row TO lt_rows.
ENDDO.
ENDIF.
<gs_table>-alv->set_selected_rows( it_row_no = lt_rows ).
ENDLOOP.
WHEN '%SC'. "search

*
*

*
*
*
*
*
*
*

CALL SELECTION-SCREEN 3000 STARTING AT 10 10.


CHECK sy-subrc EQ 0.
PERFORM search_value USING scstring.
WHEN 'REFR'. "SNAP "snapshot
make sure that same number of tables after refresh
DELETE gt_tables WHERE count EQ 0.
*********************
IF sy-dynnr EQ gc_alv_screen.
LOOP AT gt_tables ASSIGNING <gs_table>
WHERE alv IS NOT INITIAL.
PERFORM refresh_table.
ENDLOOP.
ELSE.
LOOP AT gt_tables ASSIGNING <gs_table>.
PERFORM select_data.
ENDLOOP.
call list again
LEAVE TO SCREEN gc_list_screen.
ENDIF.
WHEN 'HILF'.
PERFORM show_tables.
WHEN 'FNAM'. "Benutzerparameter.
CALL FUNCTION 'RS_WORKBENCH_CUSTOMIZING'
EXPORTING
choice
= 'DB'
IMPORTING
setting
= rseumod
EXCEPTIONS
OTHERS
= 1.
DATA: l_rb_name,
l_rb_alv,
l_convexit.
l_rb_name = rb_name.
l_rb_alv = rb_alv.
l_convexit = convexit.
CALL SELECTION-SCREEN '2000' STARTING AT 10 10
ENDING AT 60 20.
IF sy-subrc NE 0.
cancel button pressed.
ELSEIF rb_name EQ l_rb_name AND
rb_alv EQ l_rb_alv AND
convexit EQ l_convexit.
no relevant change.
ELSEIF rb_alv EQ abap_true.
IF sy-dynnr EQ gc_alv_screen.
PERFORM alv_show_loop.
ELSE.
PERFORM alv_show.
LEAVE TO SCREEN gc_alv_screen.
ENDIF.
ELSE.
LEAVE TO SCREEN gc_list_screen.
ENDIF.
WHEN lc_edit.
only for developers and only in SAP systems
CALL FUNCTION 'TR_SYS_PARAMS'
IMPORTING
systemtype
= lf_system
EXCEPTIONS
no_systemname = 1

no_systemtype = 2.
IF lf_system NE lc_edit+1(3).
MESSAGE i031(s_cus_img_tool).
sy-subrc = 1.
ENDIF.
IF sy-subrc EQ 0.
AUTHORITY-CHECK OBJECT 'S_DEVELOP'
ID 'ACTVT'
FIELD '01'
ID 'OBJTYPE' FIELD 'DEBUG'
ID 'DEVCLASS' DUMMY
ID 'OBJNAME' DUMMY
ID 'P_GROUP' DUMMY.
ENDIF.
IF sy-subrc EQ 0.
AUTHORITY-CHECK OBJECT 'S_DEVELOP'
ID 'ACTVT'
FIELD '02'
ID 'OBJTYPE' FIELD 'DEBUG'
ID 'DEVCLASS' DUMMY
ID 'OBJNAME' DUMMY
ID 'P_GROUP' DUMMY.
ENDIF.
IF sy-subrc EQ 0.
AUTHORITY-CHECK OBJECT 'S_DEVELOP'
ID 'ACTVT'
FIELD '03'
ID 'OBJTYPE' FIELD 'DEBUG'
ID 'DEVCLASS' DUMMY
ID 'OBJNAME' DUMMY
ID 'P_GROUP' DUMMY.
ENDIF.
IF sy-subrc EQ 0.
g_with_edit = abap_true.
ELSE.
g_with_edit = abap_false.
MESSAGE i202(37).
ENDIF.
LOOP AT gt_tables ASSIGNING <gs_table> WHERE count NE 0.
<gs_table>-alv->refresh_table_display( ).
ENDLOOP.
WHEN OTHERS.
RETURN.
ENDCASE.
CLEAR ok_code.
ENDFORM.

" user_command

*&--------------------------------------------------------------------*
*&
Form refresh_table
*&--------------------------------------------------------------------*
FORM refresh_table.
DATA: ls_col
lt_col_red
lt_col_green
lr_line_type
lr_table_type
lt_comp
ls_comp
dref

TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
LIKE
TYPE

lvc_s_scol,
lvc_t_scol,
lvc_t_scol,
REF TO cl_abap_structdescr,
REF TO cl_abap_tabledescr,
cl_abap_structdescr=>component_table,
LINE OF lt_comp,
REF TO data.

DATA: lt_dfies TYPE TABLE OF dfies WITH HEADER LINE.

DATA: lf_force_refresh.
FIELD-SYMBOLS: <lt_entries_now>
<lt_entries_before>
<ls_entry_now>
<ls_entry_before>
<ls_key>
<lf_field_now>
<lf_field_before>
<lt_col>

TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE

STANDARD TABLE,
STANDARD TABLE,
any,
any,
any,
any,
any,
lvc_t_scol.

* color for new/deleted lines


ls_col-color-col = gc_col_green.
APPEND ls_col TO lt_col_green.
ls_col-color-col = gc_col_red.
APPEND ls_col TO lt_col_red.
IF changlog EQ abap_true.
save old values
ASSIGN <gs_table>-entries->* TO <lt_entries_now>.
ASSIGN <gs_table>-entries2->* TO <lt_entries_before>.
<lt_entries_before>[] = <lt_entries_now>[].
* remove the red lines, force refresh in case green or yellow cells
LOOP AT <lt_entries_before> ASSIGNING <ls_entry_before>.
ASSIGN COMPONENT gc_col_column
OF STRUCTURE <ls_entry_before> TO <lt_col>.
IF <lt_col> = lt_col_red.
DELETE <lt_entries_before>.
lf_force_refresh = abap_true.
ELSEIF <lt_col> IS NOT INITIAL.
lf_force_refresh = abap_true.
ENDIF.
ENDLOOP.
* get new values
PERFORM select_data.
*
make key structure
CLEAR lt_comp[].
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = <gs_table>-tabname
TABLES
dfies_tab = lt_dfies
EXCEPTIONS
OTHERS
= 1.
LOOP AT lt_dfies WHERE keyflag NE space.
CLEAR ls_comp.
ls_comp-name = lt_dfies-fieldname.
ls_comp-type ?= cl_abap_datadescr=>describe_by_name(
lt_dfies-rollname ).
APPEND ls_comp TO lt_comp.
ENDLOOP.
*

lr_line_type = cl_abap_structdescr=>create( lt_comp ).


CREATE DATA dref TYPE HANDLE lr_line_type.
ASSIGN dref->* TO <ls_key>.
compare entries.
SORT <lt_entries_now>.
LOOP AT <lt_entries_now> ASSIGNING <ls_entry_now>.
ASSIGN COMPONENT gc_col_column
OF STRUCTURE <ls_entry_now> TO <lt_col>.

<lt_col> = lt_col_green.
ENDLOOP.

LOOP AT <lt_entries_before> ASSIGNING <ls_entry_before>.


MOVE-CORRESPONDING <ls_entry_before> TO <ls_key>.
READ TABLE <lt_entries_now> WITH KEY <ls_key>
ASSIGNING <ls_entry_now> BINARY SEARCH.
IF sy-subrc EQ 0.
exists -> reset colors
ASSIGN COMPONENT gc_col_column
OF STRUCTURE <ls_entry_before> TO <lt_col>.
REFRESH <lt_col>.
ASSIGN COMPONENT gc_col_column
OF STRUCTURE <ls_entry_now> TO <lt_col>.
REFRESH <lt_col>.
IF <ls_entry_now> NE <ls_entry_before>.
compare each field
LOOP AT lt_dfies WHERE keyflag EQ space.
ASSIGN COMPONENT lt_dfies-fieldname
OF STRUCTURE <ls_entry_before> TO <lf_field_before>.
ASSIGN COMPONENT lt_dfies-fieldname
OF STRUCTURE <ls_entry_now> TO <lf_field_now>.
IF <lf_field_now> NE <lf_field_before>.
evtl. tooltip with old value BCALV_DEMO_TOOLTIP
ls_col-fname = lt_dfies-fieldname.
ls_col-color-col = gc_col_yellow.
APPEND ls_col TO <lt_col>.
ENDIF.
ENDLOOP.
lf_force_refresh = abap_true.
ENDIF.
ELSE.
entry was deleted, insert old entry and make grey
ASSIGN COMPONENT gc_col_column
OF STRUCTURE <ls_entry_before> TO <lt_col>.
<lt_col> = lt_col_red.
INSERT <ls_entry_before> INTO <lt_entries_now> INDEX sy-tabix.
lf_force_refresh = abap_true.
ENDIF.
ENDLOOP.
ELSE. "changelog
save old values
ASSIGN <gs_table>-entries->* TO <lt_entries_now>.
ASSIGN <gs_table>-entries2->* TO <lt_entries_before>.
<lt_entries_before>[] = <lt_entries_now>[].
PERFORM select_data.
ENDIF.

* trigger update of ALV


IF lf_force_refresh EQ abap_true OR
<lt_entries_now>[] NE <lt_entries_before>[].
DESCRIBE TABLE <lt_entries_now> LINES <gs_table>-count.
PERFORM set_pane_height USING <gs_table>.
<gs_table>-alv->refresh_table_display( ).
ENDIF.
ENDFORM.

"refresh_tables

*&--------------------------------------------------------------------*

*&
Form search_value
*&--------------------------------------------------------------------*
FORM search_value USING i_pattern.
DATA: ls_elem_descr TYPE
ls_struct_descr TYPE
ls_comp_descr TYPE
ls_col
TYPE
lf_character(200),
lf_found.

REF TO cl_abap_elemdescr,
REF TO cl_abap_structdescr,
LINE OF abap_compdescr_tab,
lvc_s_scol,

FIELD-SYMBOLS: <lt_entries> TYPE STANDARD TABLE,


<ls_entry> TYPE any,
<lf_field> TYPE any,
<lt_col> TYPE lvc_t_scol.
LOOP AT gt_tables ASSIGNING <gs_table> WHERE alv IS NOT INITIAL.
CLEAR lf_found.
ASSIGN <gs_table>-entries->* TO <lt_entries>.
IF <gs_table>-col IS INITIAL.
PERFORM append_col_column.
PERFORM set_table_for_first_display.
ENDIF.
ASSIGN <gs_table>-entries->* TO <lt_entries>.
LOOP AT <lt_entries> ASSIGNING <ls_entry>.
IF sy-tabix EQ 1.
ls_struct_descr ?= cl_abap_typedescr=>describe_by_data(
<ls_entry> ).
ENDIF.
ASSIGN COMPONENT gc_col_column
OF STRUCTURE <ls_entry> TO <lt_col>.
REFRESH <lt_col>.
LOOP AT ls_struct_descr->components INTO ls_comp_descr
WHERE name NE gc_col_column.
ASSIGN COMPONENT ls_comp_descr-name
OF STRUCTURE <ls_entry> TO <lf_field>.
WRITE <lf_field> TO lf_character.
IF lf_character CP i_pattern.
ls_col-fname = ls_comp_descr-name.
ls_col-color-col = gc_col_yellow.
APPEND ls_col TO <lt_col>.
lf_found = abap_true.
ENDIF.
ENDLOOP.
ENDLOOP.
IF lf_found EQ abap_true.
<gs_table>-alv->refresh_table_display( ).
ENDIF.
ENDLOOP.
ENDFORM.
"search_value
*&--------------------------------------------------------------------*
*&
Form append_col_column
*&--------------------------------------------------------------------*
*
dynamically append a new column to internal tables.
*---------------------------------------------------------------------*
FORM append_col_column.
DATA: lr_line_type TYPE REF TO cl_abap_structdescr,
lr_table_type TYPE REF TO cl_abap_tabledescr,

lt_comp
ls_comp
dref

TYPE cl_abap_structdescr=>component_table,
LIKE LINE OF lt_comp,
TYPE REF TO data.

FIELD-SYMBOLS: <lt_entries_now>
<lt_entries_before>
<ls_entry_now>
<ls_entry_before>

TYPE
TYPE
TYPE
TYPE

STANDARD TABLE,
STANDARD TABLE,
any,
any.

CHECK <gs_table>-col IS INITIAL.


<gs_table>-col = abap_true.
* create line type dynamically
CLEAR: lt_comp[], ls_comp.
ls_comp-as_include = abap_true.
ls_comp-type ?= cl_abap_datadescr=>describe_by_name(
<gs_table>-tabname ).
APPEND ls_comp TO lt_comp.
* append col_tab
CLEAR ls_comp.
ls_comp-name = gc_col_column.
ls_comp-type ?= cl_abap_datadescr=>describe_by_name(
'LVC_T_SCOL' ).
APPEND ls_comp TO lt_comp.
lr_line_type = cl_abap_structdescr=>create( lt_comp ).
lr_table_type = cl_abap_tabledescr=>create( lr_line_type ).
DO 2 TIMES.
create internal table dynamically
CASE sy-index.
WHEN 1.
ASSIGN <gs_table>-entries->* TO <lt_entries_before>.
CREATE DATA <gs_table>-entries TYPE HANDLE lr_table_type.
ASSIGN <gs_table>-entries->* TO <lt_entries_now>.
WHEN 2.
UNASSIGN <lt_entries_before>.
ASSIGN <gs_table>-entries2->* TO <lt_entries_before>.
CREATE DATA <gs_table>-entries2 TYPE HANDLE lr_table_type.
ASSIGN <gs_table>-entries2->* TO <lt_entries_now>.
ENDCASE.
CHECK <lt_entries_before> IS ASSIGNED.
CHECK <lt_entries_before>[] IS NOT INITIAL.
* create workarea
CREATE DATA dref TYPE HANDLE lr_line_type.
ASSIGN dref->* TO <ls_entry_now>.
* copy old table to new table
LOOP AT <lt_entries_before> ASSIGNING <ls_entry_before>.
MOVE-CORRESPONDING <ls_entry_before> TO <ls_entry_now>.
APPEND <ls_entry_now> TO <lt_entries_now>.
ENDLOOP.
FREE <lt_entries_before>.
ENDDO.
*

ENDFORM.

"append_col_column

You might also like