*&---------------------------------------------------------------------*
*& Report ZSQVI
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zsqvi.
TABLES: aqltq.
CLASS lcl_handle_events DEFINITION DEFERRED.
DATA: gr_events TYPE REF TO lcl_handle_events.
CLASS lcl_handle_events DEFINITION.
PUBLIC SECTION.
METHODS:
on_link_click FOR EVENT link_click OF cl_salv_events_table
IMPORTING row column.
ENDCLASS. "lcl_handle_events DEFINITION
CLASS lcl_handle_events IMPLEMENTATION.
METHOD on_link_click.
PERFORM frm_call_sqvi USING row column.
ENDMETHOD. "on_single_click
ENDCLASS. "lcl_handle_events IMPLEMENTATION
SELECT-OPTIONS:
s_qnum FOR aqltq-qnum.
DATA: BEGIN OF gs_alv,
qnum TYPE aqltq-qnum,
num TYPE aqltq-num,
text TYPE aqltq-text,
bname TYPE usr02-bname,
uname TYPE sy-uname,
num_u TYPE aqltq-num,
END OF gs_alv.
DATA: gt_alv LIKE TABLE OF gs_alv.
START-OF-SELECTION.
PERFORM frm_get_data.
PERFORM frm_alv_data.
*&---------------------------------------------------------------------*
*& Form frm_get_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_get_data .
SELECT qnum,num,text FROM aqltq INTO CORRESPONDING FIELDS OF TABLE @gt_alv
WHERE qnum IN @s_qnum
AND sprsl = @sy-langu.
DATA: BEGIN OF dbbn OCCURS 100.
INCLUDE STRUCTURE aqdbbn.
DATA: END OF dbbn.
IMPORT dbbn
FROM DATABASE aqldb(aq) ID 'BC'
IGNORING CONVERSION ERRORS.
LOOP AT gt_alv ASSIGNING FIELD-SYMBOL(<ls_alv>).
<ls_alv>-bname = dbbn[ num = <ls_alv>-num ]-bname .
<ls_alv>-uname = sy-uname.
<ls_alv>-num_u = dbbn[ bname = <ls_alv>-uname ]-num.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_alv_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_alv_data .
DATA: lo_alv TYPE REF TO cl_salv_table.
cl_salv_table=>factory(
* EXPORTING
* r_container = gc_container_10
IMPORTING
r_salv_table = lo_alv
CHANGING
t_table = gt_alv ).
DATA: lr_functions TYPE REF TO cl_salv_functions_list.
lr_functions = lo_alv->get_functions( ).
lr_functions->set_all( 'X' ).
*... §4 set layout
DATA: lr_layout TYPE REF TO cl_salv_layout,
ls_key TYPE salv_s_layout_key.
lr_layout = lo_alv->get_layout( ).
*... §4.1 set the Layout Key
ls_key-report = sy-repid.
ls_key-handle = 2.
lr_layout->set_key( ls_key ).
*... §4.2 set usage of default Layouts
lr_layout->set_default( 'X' ).
*... §4.3 set Layout save restriction
DATA: lv_restrict TYPE salv_de_layout_restriction.
lv_restrict = 1.
lr_layout->set_save_restriction( lv_restrict ). "
*... §4.4 set initial Layout
*... set the columns technical
*优化宽度
DATA: lr_columns TYPE REF TO cl_salv_columns_table,
lr_column TYPE REF TO cl_salv_column_table.
lr_columns = lo_alv->get_columns( ).
lr_columns->set_optimize( 'X' ).
*设置字段描述
DEFINE set_text.
TRY.
lr_column ?= lr_columns->get_column( &1 ).
lr_column->set_short_text( &2 ).
lr_column->set_medium_text( &2 ).
lr_column->set_long_text( &2 ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
END-OF-DEFINITION.
set_text 'TEXT' '查询描述'.
set_text 'BNAME' '查询所属用户'.
set_text 'UNAME' '当前用户'.
set_text 'NUM_U' '当前用户所属用户组'.
lr_column ?= lr_columns->get_column( 'QNUM' ).
lr_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
* lr_column->set_icon( if_salv_c_bool_sap=>true ).
*... §6 register to the events of cl_salv_table
DATA: lr_events TYPE REF TO cl_salv_events_table.
lr_events = lo_alv->get_event( ).
CREATE OBJECT gr_events.
*... §6.3 register to the event LINK_CLICK
SET HANDLER gr_events->on_link_click FOR lr_events.
"... 设置抬头标题
DATA: lr_display_settings TYPE REF TO cl_salv_display_settings,
l_title TYPE lvc_title.
DATA: lv_lines TYPE i.
lv_lines = lines( gt_alv ).
l_title = '总行数:' && lv_lines && ',点击查询ID修改'.
lr_display_settings = lo_alv->get_display_settings( ).
lr_display_settings->set_list_header( l_title ).
lo_alv->display( ).
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_call_sqvi
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> ROW
*& --> COLUMN
*& --> TEXT_I06
*&---------------------------------------------------------------------*
FORM frm_call_sqvi USING iv_row
iv_column.
DATA: BEGIN OF headbg.
INCLUDE STRUCTURE aqhdbg.
DATA: END OF headbg.
DATA: BEGIN OF dbbg OCCURS 50.
INCLUDE STRUCTURE aqdbbg.
DATA: END OF dbbg,
dbbg_text(30). " Langtext der Benutzergruppe
DATA: BEGIN OF dbbn OCCURS 100.
INCLUDE STRUCTURE aqdbbn.
DATA: END OF dbbn.
DATA: BEGIN OF bgkey,
'BC',
END OF bgkey.
* Zuordnung Sachgebiete zu Benutzergruppen
DATA: BEGIN OF dbbs OCCURS 100.
INCLUDE STRUCTURE aqdbbs.
DATA: END OF dbbs.
READ TABLE gt_alv INTO gs_alv INDEX iv_row.
IF sy-subrc = 0.
IMPORT headbg dbbg dbbs dbbn
FROM DATABASE aqldb(aq) ID bgkey
IGNORING CONVERSION ERRORS.
"交换用户组
dbbn[ num = gs_alv-num ]-bname = gs_alv-uname.
dbbn[ num = gs_alv-num_u ]-bname = gs_alv-bname.
dbbg[ num = gs_alv-num ]-bgcnam = gs_alv-uname.
dbbg[ num = gs_alv-num ]-bgunam = gs_alv-uname.
dbbg[ num = gs_alv-num_u ]-bgcnam = gs_alv-bname.
dbbg[ num = gs_alv-num_u ]-bgunam = gs_alv-bname.
EXPORT headbg dbbg dbbs dbbn
TO DATABASE aqldb(aq) ID bgkey.
CALL FUNCTION 'Z_CALL_SQVI'
EXPORTING
qnum_001 = gs_alv-qnum.
"换回来
dbbn[ num = gs_alv-num ]-bname = gs_alv-bname.
dbbn[ num = gs_alv-num_u ]-bname = gs_alv-uname.
dbbg[ num = gs_alv-num ]-bgcnam = gs_alv-bname.
dbbg[ num = gs_alv-num ]-bgunam = gs_alv-bname.
dbbg[ num = gs_alv-num_u ]-bgcnam = gs_alv-uname.
dbbg[ num = gs_alv-num_u ]-bgunam = gs_alv-uname.
EXPORT headbg dbbg dbbs dbbn
TO DATABASE aqldb(aq) ID bgkey.
ENDIF.
ENDFORM.
FUNCTION Z_CALL_SQVI.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(CTU) LIKE APQI-PUTACTIVE DEFAULT 'X'
*" VALUE(MODE) LIKE APQI-PUTACTIVE DEFAULT 'E'
*" VALUE(UPDATE) LIKE APQI-PUTACTIVE DEFAULT 'L'
*" VALUE(GROUP) LIKE APQI-GROUPID OPTIONAL
*" VALUE(USER) LIKE APQI-USERID OPTIONAL
*" VALUE(KEEP) LIKE APQI-QERASE OPTIONAL
*" VALUE(HOLDDATE) LIKE APQI-STARTDATE OPTIONAL
*" VALUE(NODATA) LIKE APQI-PUTACTIVE DEFAULT '/'
*" VALUE(QNUM_001) TYPE AQS_QUNAME
*" EXPORTING
*" VALUE(SUBRC) LIKE SYST-SUBRC
*" TABLES
*" MESSTAB STRUCTURE BDCMSGCOLL OPTIONAL
*"----------------------------------------------------------------------
subrc = 0.
perform bdc_nodata using NODATA.
perform open_group using GROUP USER KEEP HOLDDATE CTU.
perform bdc_dynpro using 'SAPMS38R' '3050'.
perform bdc_field using 'BDC_CURSOR'
'RS38R-QNUM'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RS38R-QNUM'
QNUM_001.
perform bdc_transaction tables messtab
using 'SQVI'
CTU
MODE
UPDATE.
if sy-subrc <> 0.
subrc = sy-subrc.
exit.
endif.
perform close_group using CTU.
ENDFUNCTION.
INCLUDE BDCRECXY .