На входе Excel файл, содержащий 3 столбца (Правило графика, День, ОГРВ). 1 строка в Excel файле - шапка для таблицы, сами данные начиная со второй строки:
Code:
ПГРВ Дата ОГРВ
V1000235 14.11.2012 11/1
V1000235 15.11.2012 11/2
Необходимо создать (скопировать из какого-нибудь SALV отчета) статус SALV_STANDARD:
Code:
gr_table->set_screen_status(
pfstatus = 'SALV_STANDARD'
report = sy-repid
в статусе должны быть кнопки для выделения(отмены) строк списка, а также кнопка для запуска самого процесса обновления T552A (с командой UPLOAD):

ну собственно и сам код (можно грузить как через PT02, так и напрямую в T552A):
Code:
report zhr_mws_create.
include <icon>.
include <color>.
tables: t508a,
t550a,
t552a,
t001p.
data: gs_t552a type t552a.
data: gt_t550a type table of t550a with header line.
data: bdcdata like bdcdata occurs 0 with header line.
data: messtab like bdcmsgcoll occurs 0 with header line.
*---------------------------------------------------------------------*
type-pools: shlp,
f4typ,
sdydo.
*---------------------------------------------------------------------*
data: i type i,
dbeg type d,
dend type d.
data: kjahr type sjahr,
monat type monat.
*---------------------------------------------------------------------*
data: gt_color type lvc_t_scol,
gs_color type lvc_s_scol.
data: gt_fieldname like rstrucinfo occurs 0 with header line.
*---------------------------------------------------------------------*
types: begin of t_outtab,
schkz type schkn,
cdatu type hrmss_cat_appr_workdate,
tprog type tprog,
* ftkla type ftkla,
* tagty type tagty,
perio type prd01,
zeity type dzeity,
mofid type hident,
mosid type mosid,
datum type datum,
stsch type pxastat,
sttpr type pxastat,
stupl type pxastat,
tprbd type tprog,
tprog_tx type tptxt,
tprbd_tx type tptxt.
types: t_color type lvc_t_scol.
types: end of t_outtab.
data: gt_outtab type table of t_outtab,
gs_outtab type t_outtab.
field-symbols: <outtab> type t_outtab.
*---------------------------------------------------------------------*
types: begin of t_upload,
schkz like zhr_mws_upload-schkz,
perio like zhr_mws_upload-perio,
datum like zhr_mws_upload-datum,
tprog like zhr_mws_upload-tprog,
* ftkla like zhr_mws_upload-ftkla,
* tagty like zhr_mws_upload-tagty,
zeity like zhr_mws_upload-zeity,
mofid like zhr_mws_upload-mofid,
mosid like zhr_mws_upload-mosid,
cdatu like zhr_mws_upload-cdatu,
end of t_upload.
data: gt_upload type sorted table of t_upload
with unique key schkz perio datum
with header line.
*---------------------------------------------------------------------*
types: begin of t_t550s,
motpr type motpr,
tprog type tprog,
ttext type tptxt,
end of t_t550s.
data: gt_t550s type sorted table of t_t550s
with unique key motpr tprog
with header line.
*---------------------------------------------------------------------*
selection-screen: begin of block 1 with frame title text-001. " Ссылочные данные
parameters: persa type persa default 'UP01'. " Раздел персонала для группировок
selection-screen: end of block 1.
selection-screen: begin of block 2 with frame title text-002.
parameters: file(128) default 'C:\*.XLS' lower case.
selection-screen skip.
parameters: r_pt radiobutton group r1, " Использовать для апдейте T552A транзакции PT01/02
r_di radiobutton group r1 default 'X'. " Работать напрямую с T552A
selection-screen: end of block 2.
*&---------------------------------------------------------------------*
* SALV
*&---------------------------------------------------------------------*
data: gr_table type ref to cl_salv_table.
class lcl_handle_events definition deferred.
data: gr_events type ref to lcl_handle_events.
*---------------------------------------------------------------------*
* CLASS lcl_handle_events DEFINITION
class lcl_handle_events definition.
public section.
methods:
on_user_command for event added_function of cl_salv_events
importing e_salv_function.
endclass. "lcl_handle_events DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_handle_events IMPLEMENTATION
class lcl_handle_events implementation.
method on_user_command.
perform user_command using e_salv_function.
endmethod. "on_user_command
endclass. "lcl_handle_events IMPLEMENTATION
*---------------------------------------------------------------------*
at selection-screen on value-request for file.
perform filename_get.
*---------------------------------------------------------------------*
start-of-selection.
perform read_t550s.
perform read_field_list.
perform upload_file tables gt_outtab
using file.
*---------------------------------------------------------------------*
end-of-selection.
perform indicator using 'Формирование отчета ...' 0.
perform data_process.
sort gt_outtab by schkz perio datum.
perform display_data.
*&---------------------------------------------------------------------*
*& Form DATA_PROCESS
*&---------------------------------------------------------------------*
form data_process .
data: status(4).
data: ls_t552a type t552a.
field-symbols: <tpr> type tprog.
data: tpr(20) type c.
loop at gt_outtab assigning <outtab>.
call function 'DATE_STRING_CONVERT'
exporting
date_format = '6'
date_string = <outtab>-cdatu
importing
result_date = <outtab>-datum.
at new schkz.
* Проверяем есть ли ПГРВ
select single * from t508a where zeity = '1' " Категория сотрудников для графиков
and mofid = t001p-mofid
and mosid = t001p-mosid
and schkz = <outtab>-schkz
and endda >= <outtab>-datum
and begda <= <outtab>-datum.
if sy-subrc = 0.
status = icon_led_green.
else.
status = icon_led_red.
endif.
endat.
concatenate <outtab>-datum+4(2) <outtab>-datum(4)
into <outtab>-perio.
move: '1' to <outtab>-zeity,
t001p-mofid to <outtab>-mofid,
t001p-mosid to <outtab>-mosid,
status to <outtab>-stsch.
* Проверяем есть ли ОГРВ
select * from t550a up to 1 rows
where motpr = t001p-mosid
and tprog = <outtab>-tprog
and endda >= <outtab>-datum
and begda <= <outtab>-datum.
endselect.
if sy-subrc = 0.
<outtab>-sttpr = icon_led_green.
else.
<outtab>-sttpr = icon_led_red.
endif.
kjahr = <outtab>-perio+2(4).
monat = <outtab>-perio(2).
if ls_t552a-zeity ne <outtab>-zeity or
ls_t552a-mofid ne <outtab>-mofid or
ls_t552a-mosid ne <outtab>-mosid or
ls_t552a-schkz ne <outtab>-schkz or
ls_t552a-kjahr ne kjahr or
ls_t552a-monat ne monat.
select single * from t552a into ls_t552a
where zeity eq <outtab>-zeity
and mofid eq <outtab>-mofid
and mosid eq <outtab>-mosid
and schkz eq <outtab>-schkz
and kjahr eq kjahr
and monat eq monat.
endif.
if ls_t552a is not initial.
concatenate: 'LS_T552A-TPR' <outtab>-datum+6(2) into tpr.
assign: (tpr) to <tpr>.
if sy-subrc = 0.
<outtab>-tprbd = <tpr>.
endif.
endif.
if <outtab>-tprog is not initial.
read table gt_t550s with key motpr = t001p-mosid
tprog = <outtab>-tprog.
if sy-subrc = 0.
move gt_t550s-ttext to <outtab>-tprog_tx.
endif.
endif.
if <outtab>-tprbd is not initial.
read table gt_t550s with key motpr = t001p-mosid
tprog = <outtab>-tprbd.
if sy-subrc = 0.
move gt_t550s-ttext to <outtab>-tprbd_tx.
endif.
endif.
if <outtab>-tprbd ne <outtab>-tprog.
perform set_color using col_negative 0 0.
<outtab>-stupl = icon_positive.
if <outtab>-sttpr ne icon_led_green or
<outtab>-stsch ne icon_led_green.
<outtab>-stupl = icon_incomplete.
endif.
else.
<outtab>-stupl = icon_okay.
endif.
endloop.
endform. " DATA_PROCESS
*--------------------------------------------------------------------*
* Form user_command
*--------------------------------------------------------------------*
form user_command using i_function type salv_de_function.
data: lr_selections type ref to cl_salv_selections,
lt_rows type salv_t_row,
l_row type i.
data: ok.
case i_function.
when 'UPLOAD'.
call function 'POPUP_CONTINUE_YES_NO'
exporting
textline1 = 'Выполнить загрузку графиков?'(003)
titel = 'Загрузка графиков'(004)
importing
answer = ok.
check ok = 'J'.
*
lr_selections = gr_table->get_selections( ).
lt_rows = lr_selections->get_selected_rows( ).
*
loop at lt_rows into l_row.
read table gt_outtab into gs_outtab index l_row.
if sy-subrc = 0 and gs_outtab-stupl = icon_positive.
move-corresponding gs_outtab to gt_upload.
insert gt_upload into table gt_upload.
endif.
endloop.
if gt_upload[] is not initial.
case 'X'.
when r_pt. perform upload_mws. " Изменение графиков через пакетник PT01/PT02
when r_di. perform direct_mws. " Изменение графиков через прямой апдейт T552A
endcase.
endif.
gr_table->refresh( ).
when others.
endcase.
endform. " user_command
*&---------------------------------------------------------------------*
*& Form direct_mws
*&---------------------------------------------------------------------*
form direct_mws .
data: ls_upload type t_upload.
field-symbols: <tpr> type tprog, " ОГРВ
<var> type varia. " Вариант ОГРВ
data: tpr(20) type c,
var(20) type c.
loop at gt_upload.
ls_upload = gt_upload.
* AT NEW PERIO
at new perio.
kjahr = ls_upload-perio+2(4).
monat = ls_upload-perio(2).
select single * from t552a where zeity eq ls_upload-zeity
and mofid eq ls_upload-mofid
and mosid eq ls_upload-mosid
and schkz eq ls_upload-schkz
and kjahr eq kjahr
and monat eq monat.
if sy-subrc = 0.
gs_t552a = t552a.
else.
message i016(hrtim00ws) with ls_upload-schkz ls_upload-mosid ls_upload-perio.
exit.
endif.
endat.
* EVERY DAY
concatenate: 'GS_T552A-TPR' gt_upload-datum+6(2) into tpr,
'GS_T552A-VAR' gt_upload-datum+6(2) into var.
assign: (tpr) to <tpr>,
(var) to <var>.
if sy-subrc = 0.
* ОГРВ
if ls_upload-tprog is not initial.
if gt_t550a[] is initial.
perform read_t550a using gt_upload-datum.
endif.
read table gt_t550a with key mandt = sy-mandt
motpr = gs_t552a-mosid
tprog = <tpr>
varia = <var> binary search.
if sy-subrc = 0.
subtract gt_t550a-sollz from gs_t552a-solst.
endif.
move: ls_upload-tprog to <tpr>.
read table gt_t550a with key mandt = sy-mandt
motpr = gs_t552a-mosid
tprog = <tpr>
varia = <var> binary search.
if sy-subrc = 0.
add gt_t550a-sollz to gs_t552a-solst.
endif.
endif.
endif.
at end of perio.
modify t552a from gs_t552a.
endat.
endloop.
endform. " UPLOAD_MWS
*&---------------------------------------------------------------------*
*& Form upload_mws
*&---------------------------------------------------------------------*
form upload_mws .
data: ls_upload type t_upload.
data: pshft_tpr(15) value 'PSHFT-TPR**(**)',
diw(2) type n, " Текущий день недели
wim(2) type n. " Номер текущ.недели в месяце
data: tcode(20),
ok_code(20).
loop at gt_upload.
ls_upload = gt_upload.
at new perio.
kjahr = ls_upload-perio+2(4).
monat = ls_upload-perio(2).
select single * from t552a where zeity eq ls_upload-zeity
and mofid eq ls_upload-mofid
and mosid eq ls_upload-mosid
and schkz eq ls_upload-schkz
and kjahr eq kjahr
and monat eq monat.
if sy-subrc = 0.
tcode = 'PT02'.
ok_code = '=MODI'.
else.
continue.
* tcode = 'PT01'.
* ok_code = '=ADD'.
endif.
clear bdcdata[].
perform bdc_dynpro using 'SAPMP51S' '1000'.
perform bdc_field using: 'BDC_OKCODE' ok_code,
'PSHFT-ZEITY' ls_upload-zeity,
'PSHFT-MOFID' ls_upload-mofid,
'PSHFT-MOSID' ls_upload-mosid,
'PSHFT-SCHKZ' ls_upload-schkz,
'PSHFT-PRD01' ls_upload-perio,
'PSHFT-PRD02' ls_upload-perio,
'KALENDER' 'X'.
perform bdc_dynpro using 'SAPMP51S' '1010'.
perform bdc_field using: 'BDC_OKCODE' '=UP1'.
endat.
clear: diw, wim.
perform get_day_position using ls_upload-datum
changing diw wim.
if diw is not initial and
wim is not initial.
move diw to pshft_tpr+9(2).
move wim to pshft_tpr+12(2).
perform bdc_field using pshft_tpr ls_upload-tprog.
endif.
at end of perio.
check bdcdata[] is not initial.
call transaction tcode using bdcdata
mode 'E' "N-фон E-только ошибки A-все экраны
update 'S' "S-синхронно A-асинхрон L-локально
messages into messtab.
if messtab[] is initial.
* message i056(auth_wiz).
else.
* loop at messtab where msgtyp = 'E'
* or msgtyp = 'A'.
* message i051(eclviewer).
* exit.
* endloop.
endif.
endat.
endloop.
endform. " UPLOAD_MWS
*&--------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&--------------------------------------------------------------------*
form bdc_dynpro using program dynpro.
clear bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
append bdcdata.
endform. "BDC_DYNPRO
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
form bdc_field using fnam fval.
clear bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
append bdcdata.
endform. "BDC_FIELD
*&---------------------------------------------------------------------*
*& Form get_day_position
*&---------------------------------------------------------------------*
form get_day_position using d type d
changing diw type num2
wim type num2.
data: diw_pack type p, " Текущий день недели (упакованный)
fdim type d. " Первый день в месяце
data: fweek type kweek, " Первая неделя месяца
sweek type kweek. " Текущая неделя месяца
* First day of month
fdim = d.
move '01' to fdim+6(2).
* First Week of Month number
call function 'DATE_GET_WEEK'
exporting
date = fdim
importing
week = fweek
exceptions
date_invalid = 1
others = 2.
* Source Week of Month number
call function 'DATE_GET_WEEK'
exporting
date = d
importing
week = sweek
exceptions
date_invalid = 1
others = 2.
if sweek+4(2) < fweek+4(2).
sweek+4(2) = 53.
endif.
wim = sweek - fweek + 1.
call function 'DAY_IN_WEEK'
exporting
datum = d
importing
wotnr = diw_pack.
diw = diw_pack.
endform. "get_day_position
*&---------------------------------------------------------------------*
*& Form display_data
*&---------------------------------------------------------------------*
form display_data.
data: lr_content type ref to cl_salv_form_element.
data: lr_layout type ref to cl_salv_layout,
ls_key type salv_s_layout_key.
data: lr_events type ref to cl_salv_events_table.
data: ls_color type lvc_s_colo.
data: lr_columns type ref to cl_salv_columns_table,
lr_column type ref to cl_salv_column_table.
cl_salv_table=>factory(
importing
r_salv_table = gr_table
changing
t_table = gt_outtab ).
lr_columns = gr_table->get_columns( ).
include zpm_salv_macros.
data: lr_selections type ref to cl_salv_selections.
lr_selections = gr_table->get_selections( ).
lr_selections->set_selection_mode( if_salv_c_selection_mode=>multiple ).
set_text: 'STSCH' 'ПГРВ' 'ПГРВ' 'ПГРВ',
'STTPR' 'ОГРВ' 'ОГРВ' 'ОГРВ',
'STUPL' 'СтатЗакач.' 'Статус закачки' 'Статус закачки',
'TPROG' 'Закач.ОГРВ' 'Закачиваемый ОГРВ' 'Закачиваемый ОГРВ',
'TPRBD' 'Сущст.ОГРВ' 'Существующий ОГРВ' 'Существующий ОГРВ'.
set_icon: 'STSCH', 'STTPR', 'STUPL'.
set_color: 'SCHKZ' col_key 0 0,
'TPROG' col_key 0 0,
'TPRBD' col_key 0 0.
set_tech: 'ZEITY',
'MOFID',
'MOSID'.
try.
lr_columns->set_color_column( 'T_COLOR' ).
catch cx_salv_data_error.
endtry.
* Status
gr_table->set_screen_status(
pfstatus = 'SALV_STANDARD'
report = sy-repid
set_functions = gr_table->c_functions_all ).
lr_layout = gr_table->get_layout( ).
ls_key-report = sy-repid.
lr_layout->set_key( ls_key ).
lr_layout->set_default( 'X' ).
lr_layout->set_save_restriction( 1 ).
lr_events = gr_table->get_event( ).
create object gr_events.
set handler gr_events->on_user_command for lr_events.
gr_table->display( ).
endform. " display_data
*&---------------------------------------------------------------------*
*& Form set_color
*&---------------------------------------------------------------------*
form set_color using p_col
p_int
p_inv.
clear gt_color[].
loop at gt_fieldname where compname ne 'T_COLOR'.
clear gs_color.
move: gt_fieldname-compname to gs_color-fname,
p_col to gs_color-color-col,
p_int to gs_color-color-int,
p_inv to gs_color-color-inv.
append gs_color to gt_color.
endloop.
<outtab>-t_color = gt_color.
endform. " SET_COLOR
*&---------------------------------------------------------------------*
*& Form UPLOAD_FILE
*&---------------------------------------------------------------------*
form upload_file tables p_tab structure gs_outtab
using file.
data: i_subrc type sysubrc,
l_intern type alsmex_tabline occurs 0 with header line,
l_index type i,
l_start_col type i value '1',
l_start_row type i value '2',
l_end_col type i value '256',
l_end_row type i value '65536'.
field-symbols : <fs>.
perform indicator using 'Загрузка файла ...' 0.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = file
i_begin_col = l_start_col
i_begin_row = l_start_row
i_end_col = l_end_col
i_end_row = l_end_row
tables
intern = l_intern
exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3.
i_subrc = sy-subrc.
if sy-subrc > 0.
message i000(zm) with 'Error opening PC file ... RC =' sy-subrc.
exit.
endif.
if l_intern[] is initial.
message i000(zm) with 'No data uploaded!'.
exit.
else.
sort l_intern by row col.
loop at l_intern.
move l_intern-col to l_index.
assign component l_index of structure p_tab to <fs>.
move l_intern-value to <fs>.
at end of row.
append p_tab.
clear p_tab.
endat.
endloop.
endif.
endform. " UPLOAD_FILE
*&---------------------------------------------------------------------*
*& Form FILENAME_GET
*&---------------------------------------------------------------------*
form filename_get .
call function 'WS_FILENAME_GET'
exporting
def_filename = ' '
def_path = 'C:\'
mask = ',*.*.'
mode = '0'
title = text-002
importing
filename = file
exceptions
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
others = 5.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform. " FILENAME_GET
*&---------------------------------------------------------------------*
*& Form indicator
*&---------------------------------------------------------------------*
form indicator using c type text60
i type i.
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = c
percentage = i.
endform. "indicator
*&---------------------------------------------------------------------*
*& Form READ_T550A
*&---------------------------------------------------------------------*
form read_t550a using datum type d .
select * into table gt_t550a from t550a where motpr = t001p-mosid
and seqno = '01'
and begda <= datum
and endda >= datum.
endform. "read_t550a
*&---------------------------------------------------------------------*
*& Form READ_T001P
*&---------------------------------------------------------------------*
form read_t550s.
select * from t001p up to 1 rows where werks = persa.
endselect.
select * from t550s into corresponding fields of table gt_t550s
where spras = sy-langu
and motpr = t001p-mosid.
endform. " READ_T001P
*&---------------------------------------------------------------------*
*& Form READ_FIELD_LIST
*&---------------------------------------------------------------------*
form read_field_list .
call function 'GET_COMPONENT_LIST'
exporting
program = sy-repid
fieldname = 'GS_OUTTAB'
tables
components = gt_fieldname.
endform. " READ_FIELD_LIST
и маленький инклудик ZPM_SALV_MACROS:
Code:
*&---------------------------------------------------------------------*
*& Include ZPM_SALV_MACROS
*&---------------------------------------------------------------------*
define set_text.
try.
lr_column ?= lr_columns->get_column( &1 ).
lr_column->set_short_text( &2 ).
lr_column->set_medium_text( &3 ).
lr_column->set_long_text( &4 ).
lr_column->set_tooltip( &4 ).
catch cx_salv_not_found.
endtry.
end-of-definition.
define set_icon.
try.
lr_column ?= lr_columns->get_column( &1 ).
lr_column->set_icon( if_salv_c_bool_sap=>true ).
catch cx_salv_not_found.
endtry.
end-of-definition.
define set_symbol.
try.
lr_column ?= lr_columns->get_column( &1 ).
lr_column->set_symbol( if_salv_c_bool_sap=>true ).
catch cx_salv_not_found.
endtry.
end-of-definition.
define set_color.
try.
lr_column ?= lr_columns->get_column( &1 ).
ls_color-col = &2.
ls_color-int = &3.
ls_color-inv = &4.
lr_column->set_color( ls_color ).
catch cx_salv_not_found.
endtry.
end-of-definition.
define set_tooltip.
try.
lr_column ?= lr_columns->get_column( &1 ).
lr_column->set_tooltip( &2 ).
catch cx_salv_not_found.
endtry.
end-of-definition.
define set_tech.
try.
lr_column ?= lr_columns->get_column( &1 ).
lr_column->set_technical( if_salv_c_bool_sap=>true ).
catch cx_salv_not_found.
endtry.
end-of-definition.
define set_no_zero.
try.
lr_column ?= lr_columns->get_column( &1 ).
lr_column->set_zero( if_salv_c_bool_sap=>false ).
catch cx_salv_not_found.
endtry.
end-of-definition.
define set_hotspot.
try.
lr_column ?= lr_columns->get_column( &1 ).
lr_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
catch cx_salv_not_found.
endtry.
end-of-definition.
define set_key.
try.
lr_column ?= lr_columns->get_column( &1 ).
lr_column->set_key( if_salv_c_bool_sap=>true ).
catch cx_salv_not_found.
endtry.
end-of-definition.