Alles was ich noch auf die Reihe bekommen habe ist mein Selektionsbildschirm, der sieht wie folgt aus:Beschreibung
Es soll ein Report ZFI_Update_ZTAB erstellt werden, der den Wert eines selektierten Feldes aus einer kundeneigenen Tabelle (Z-Tabelle) ändert.
Der Inhalt des Feldes soll nur geändert werden, wenn dieses den bisher angegebenen Wert hat.
Dieser Report sollte:
• Im Vordergrund laufen
• Ein Protokoll liefern
• Die Option zum Test-Lauf haben
• Nur für Z-Tabellen ausführbar sein (sonst Ausgabe einer Fehlermeldung)
Lösungsvorschlag
Selektionsbildschirm:
Tabellenname
Name des zu ändernden Feldes
alter Wert des zu ändernden Feldes
neuer Wert des zu ändernden Feldes
Testlauf oder UPDATE-Lauf
Protokoll:
ALV-Grid Ausgabe, Selektionsparameter anzeigen
UPDATE:
Direkter Update der Z-Tabelle
Code: Alles auswählen.
REPORT ZFI_UPDATE_ZTAB.
START-OF-SELECTION.
SELECTION-SCREEN: BEGIN OF BLOCK b0 WITH FRAME TITLE text-001.
PARAMETERS: s_table(12) TYPE c OBLIGATORY.
SELECTION-SCREEN: END OF BLOCK b0.
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-002.
PARAMETERS: s_field(12) TYPE c OBLIGATORY.
SELECTION-SCREEN: END OF BLOCK b1.
SELECTION-SCREEN: BEGIN OF BLOCK b2 WITH FRAME TITLE text-003.
PARAMETERS: s_old(64) TYPE c OBLIGATORY,
s_new(64) TYPE c OBLIGATORY.
SELECTION-SCREEN: END OF BLOCK b2.
SELECTION-SCREEN: BEGIN OF BLOCK b3 WITH FRAME TITLE text-004.
PARAMETERS: s_test RADIOBUTTON GROUP rad1,
s_update RADIOBUTTON GROUP rad1.
SELECTION-SCREEN: END OF BLOCK b3.
DATA wa LIKE s_table.
Code: Alles auswählen.
*&---------------------------------------------------------------------*
*& Report ZFI_UPDATE_ZTAB
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zfi_update_ztab.
DATA:
ptrtable TYPE REF TO data,
ausgabe TYPE REF TO data,
testlauf(11) TYPE c,
updatelauf(13) TYPE c,
programm(24) TYPE c,
hits TYPE integer VALUE 0.
FIELD-SYMBOLS:
<fstable> TYPE ANY TABLE,
<fsausgabe> TYPE STANDARD TABLE,
<fswa> TYPE data,
<fswa_ausg> TYPE data,
<fsfield> TYPE data.
testlauf = 'TESTLAUF' .
updatelauf = 'UPDATELAUF'.
programm = 'ZFI_UPDATE_ZTAB'.
SELECTION-SCREEN: BEGIN OF BLOCK b0 WITH FRAME TITLE text-001.
PARAMETERS: s_table(30) TYPE c OBLIGATORY.
SELECTION-SCREEN: END OF BLOCK b0.
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-002.
PARAMETERS: s_field(12) TYPE c OBLIGATORY.
SELECTION-SCREEN: END OF BLOCK b1.
SELECTION-SCREEN: BEGIN OF BLOCK b2 WITH FRAME TITLE text-003.
PARAMETERS: s_old(64) TYPE c,
s_new(64) TYPE c.
SELECTION-SCREEN: END OF BLOCK b2.
SELECTION-SCREEN: BEGIN OF BLOCK b3 WITH FRAME TITLE text-004.
PARAMETERS: s_test RADIOBUTTON GROUP rad1,
s_update RADIOBUTTON GROUP rad1.
SELECTION-SCREEN: END OF BLOCK b3.
START-OF-SELECTION.
CREATE DATA ptrtable
TYPE TABLE OF (s_table).
ASSIGN ptrtable->* TO <fstable>.
CREATE DATA ausgabe
TYPE TABLE OF (s_table).
ASSIGN ausgabe->* TO <fsausgabe>.
SELECT * FROM (s_table) INTO TABLE <fstable>.
LOOP AT <fstable> ASSIGNING <fswa>.
ASSIGN COMPONENT s_field
OF STRUCTURE <fswa> TO <fsfield>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
IF <fsfield> = s_old.
APPEND <fswa> to <fsausgabe>.
hits = hits + 1.
ELSE.
CONTINUE.
ENDIF.
ENDLOOP.
PERFORM OUTPUT USING <fsausgabe>.
*&---------------------------------------------------------------------*
*& Form output
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM output USING fsausgabe TYPE STANDARD TABLE.
DATA: alv TYPE REF TO cl_salv_table
, liste LIKE if_salv_c_bool_sap=>true
, b_value TYPE sap_bool
, l_display_settings TYPE REF TO cl_salv_display_settings
, lr_functions TYPE REF TO cl_salv_functions
, l_columns TYPE REF TO cl_salv_columns_table
, titel TYPE lvc_title
, tool_function TYPE salv_de_function VALUE 'TST'
, tool_position TYPE salv_de_function_pos
, kopf_fus TYPE REF TO cl_salv_form_element
, kopf_txt TYPE REF TO cl_salv_form_text
, lr_grid TYPE REF TO cl_salv_form_layout_grid
, gr_layout TYPE REF TO cl_salv_layout
.
TRY.
cl_salv_table=>factory(
EXPORTING list_display = liste
IMPORTING r_salv_table = alv
CHANGING t_table = <fsausgabe>
).
l_columns = alv->get_columns( ).
** Spalten
PERFORM bew_col CHANGING l_columns.
l_columns->set_optimize( 'X' ). " Optimale Spaltenbreite
* T I T E L
l_display_settings = alv->get_display_settings( ).
l_display_settings->set_list_header( titel ).
* T O O L B A R
lr_functions = alv->get_functions( ).
lr_functions->set_all( abap_true ).
gr_layout = alv->get_layout( ).
* E I G E N E F U N K T I O N
DATA: l_text TYPE string,
l_icon TYPE string.
* K O P F
PERFORM kopf_vorbereiten USING hits s_new s_old CHANGING lr_grid.
alv->set_top_of_list( lr_grid ).
* A N Z E I G E N
alv->display( ).
CATCH cx_sy_ref_is_initial.
CATCH cx_salv_msg.
CATCH cx_salv_data_error.
MESSAGE 'ALV anzeige nicht möglich' TYPE 'E'.
ENDTRY.
ENDFORM. "output
*&---------------------------------------------------------------------*
*& Form GRID_PARAMETER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0093 text
* -->P_SY_CPROG text
* -->P_0095 text
* -->P_0096 text
* <--P_LR_GRID text
* <--P_LR_FLOW text
* <--P_LR_LABEL text
* <--P_LR_TEXT text
*----------------------------------------------------------------------*
FORM grid_parameter USING p_label
p_text
p_line
p_col
CHANGING p_lr_grid TYPE REF TO cl_salv_form_layout_grid
p_lr_flow TYPE REF TO cl_salv_form_layout_flow
p_lr_label TYPE REF TO cl_salv_form_label
p_lr_text TYPE REF TO cl_salv_form_text.
CALL METHOD p_lr_grid->create_flow
EXPORTING
row = p_line
column = p_col
* ROWSPAN =
* COLSPAN =
RECEIVING
r_value = p_lr_flow
.
CALL METHOD p_lr_flow->create_label
EXPORTING
* POSITION =
text = p_label
tooltip = p_label
* R_LABEL_FOR =
RECEIVING
r_value = p_lr_label
.
CALL METHOD p_lr_flow->create_text
EXPORTING
* POSITION =
text = p_text
tooltip = p_text
RECEIVING
r_value = p_lr_text
.
ENDFORM. " GRID_PARAMETER
*&---------------------------------------------------------------------*
*& Form BEW_COL
*&---------------------------------------------------------------------*
* config for colums, possibility to create custom description
*----------------------------------------------------------------------*
* <--P_L_COLUMNS text
*----------------------------------------------------------------------*
FORM bew_col CHANGING p_l_columns TYPE REF TO cl_salv_columns_table.
DATA: lt_col_bew TYPE salv_t_column_ref
, l_column TYPE REF TO cl_salv_column
.
FIELD-SYMBOLS: <col> LIKE LINE OF lt_col_bew.
TRY.
lt_col_bew = p_l_columns->get( ).
CATCH cx_sy_ref_is_initial.
ENDTRY.
LOOP AT lt_col_bew ASSIGNING <col>.
CASE <col>-columnname.
WHEN 'ACTION'.
<col>-r_column->set_short_text( 'Action' ).
<col>-r_column->set_medium_text( 'Action' ).
<col>-r_column->set_long_text( 'Action' ).
<col>-r_column->set_visible( 'X' ).
<col>-r_column->set_optimized( 'X' ).
WHEN OTHERS.
<col>-r_column->set_visible( 'X' ).
<col>-r_column->set_optimized( 'X' ).
ENDCASE.
ENDLOOP.
ENDFORM. " BEW_COL
*&---------------------------------------------------------------------*
*& Form KOPF_VORBEREITEN
*&---------------------------------------------------------------------*
* Edit headline
*----------------------------------------------------------------------*
* <--P_LR_GRID text
*----------------------------------------------------------------------*
FORM kopf_vorbereiten USING p_hits
p_s_new
p_s_old
CHANGING lr_grid TYPE REF TO cl_salv_form_layout_grid.
DATA : lr_grid1 TYPE REF TO cl_salv_form_layout_grid,
lr_flow TYPE REF TO cl_salv_form_layout_flow,
lr_label TYPE REF TO cl_salv_form_label,
lr_text TYPE REF TO cl_salv_form_text,
l_text TYPE string,
l_zahl_n8(8) TYPE n
.
CREATE OBJECT lr_grid.
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* H E A D E R
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CALL METHOD lr_grid->create_header_information
EXPORTING
row = 1
column = 1
* ROWSPAN =
* COLSPAN =
text = 'Feldwertänderung'
tooltip = 'Feldwertänderung'.
* receiving
* r_value =
* .
CALL METHOD lr_grid->create_grid
EXPORTING
row = 2
column = 1
* ROWSPAN =
* COLSPAN =
RECEIVING
r_value = lr_grid1
.
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* P A R A M E T E R
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* ZELE 3
PERFORM grid_parameter USING 'Programm:' programm '3' '1'
CHANGING lr_grid lr_flow lr_label lr_text.
* ZEILE 4
PERFORM grid_parameter USING 'System:' sy-sysid '4' '1'
CHANGING lr_grid lr_flow lr_label lr_text.
PERFORM grid_parameter USING 'Mandant:' sy-mandt '4' '2'
CHANGING lr_grid lr_flow lr_label lr_text.
PERFORM grid_parameter USING 'Ausgeführt von:' sy-uname '3' '2'
CHANGING lr_grid lr_flow lr_label lr_text.
* ZEILE 5
DATA : date1(12) TYPE c,
time1(8) TYPE c.
WRITE: sy-datum TO date1,
sy-uzeit TO time1.
DATA : tzonesys TYPE tznzonesys.
SELECT SINGLE tzonesys FROM ttzcu INTO tzonesys.
PERFORM grid_parameter USING 'Datum:' date1 '5' '1'
CHANGING lr_grid lr_flow lr_label lr_text.
PERFORM grid_parameter USING 'Lokale Zeit:' time1 '5' '2'
CHANGING lr_grid lr_flow lr_label lr_text.
* ZEILE 6
PERFORM grid_parameter USING 'Belege ges.:' p_hits '6' '1'
CHANGING lr_grid lr_flow lr_label lr_text.
PERFORM grid_parameter USING 'Aktueller Wert:' p_s_old '3' '4'
CHANGING lr_grid lr_flow lr_label lr_text.
PERFORM grid_parameter USING 'Neuer Wert:' p_s_new '4' '4'
CHANGING lr_grid lr_flow lr_label lr_text.
PERFORM grid_parameter USING 'Feldname:' s_field '4' '3'
CHANGING lr_grid lr_flow lr_label lr_text.
PERFORM grid_parameter USING 'Tabellenname:' s_table '3' '3'
CHANGING lr_grid lr_flow lr_label lr_text.
* ZEILE 8
IF s_test = 'X'.
PERFORM grid_parameter USING 'Programmablaufart:' testlauf '3' '12'
CHANGING lr_grid lr_flow lr_label lr_text.
ELSE.
PERFORM grid_parameter USING 'Programmablaufart:' updatelauf '1' '12'
CHANGING lr_grid lr_flow lr_label lr_text.
ENDIF.
ENDFORM. " KOPF_VORBEREITEN
Code: Alles auswählen.
<fsfield> = s_new.
UPDATE (s_table) FROM <fswa>.
Code: Alles auswählen.
DELETE (s_table) FROM <fswa>
<fsfield> = s_new.
INSERT (s_table) FROM <fswa>.