Данная программа создаёт и кладёт в таблицу новых данных записи с recordmode=D, для записей, которые нужно удалить из активной таблицы по периоду и Исходной системе, которые только что успели загрузить в 40ю таблицу.
Заметка - на 40й таблице должны быть индексы по всем ключевым полям активной.
Если через Oracle, можно так:
CREATE INDEX SAPSR3."/BIC/ANOKOTUR40~02" ON SAPSR3."/BIC/ANOKOTUR40"
( "CALDAY" ,
"/BIC/NCBUHTRAN",
"/BIC/NCBISELEM",
"/BIC/NCBRANCH",
"/BIC/NCSRCSYS",
"/BIC/NCSTOPU",
"/BIC/NCCOSTCFU",
"/BIC/NCTRPART",
"/BIC/NCSUBD",
"/BIC/NCPRODUCT",
"/BIC/NCCORTYP",
"/BIC/NCBUDYEAR" ) tablespace PSAPSR3;
или tablespace LOCAL;
___________________________________________________________
Ещё одна версия, более дерзкая...
Заметка - на 40й таблице должны быть индексы по всем ключевым полям активной.
Если через Oracle, можно так:
CREATE INDEX SAPSR3."/BIC/ANOKOTUR40~02" ON SAPSR3."/BIC/ANOKOTUR40"
( "CALDAY" ,
"/BIC/NCBUHTRAN",
"/BIC/NCBISELEM",
"/BIC/NCBRANCH",
"/BIC/NCSRCSYS",
"/BIC/NCSTOPU",
"/BIC/NCCOSTCFU",
"/BIC/NCTRPART",
"/BIC/NCSUBD",
"/BIC/NCPRODUCT",
"/BIC/NCCORTYP",
"/BIC/NCBUDYEAR" ) tablespace PSAPSR3;
или tablespace LOCAL;
*&---------------------------------------------------------------------*
*& Report ZN_DELETE_INTERVAL
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report zn_delete_interval_dso40.
data :
dateto like /bic/mncsysdat -date0 ,
datefrom like /bic/mncsysdat -date0 ,
interv like /bic/mncsysint -/bic/nfinterv value 1,
srcsys like /bic/tncsrcsys -/bic/ncsrcsys value 1,
mon like /bic/anoaktdt00 - calmonth,
count type i value 0 .
data :
sources( 72 ) occurs 100 with header line,
name like sy -cprog ,
message ( 128),
line type i .
*-----------------------------------------------------------------------
parameters :
ods type rsdodsobject obligatory value check default 'NORKOTUR' ,
*ods_par type RSDODSOBJECT obligatory value check default 'NORKOTUR',
datefld like dd03l -fieldname obligatory value check default 'CALDAY' ,
*NCSYSDAT type /BIC/OINCSYSDAT obligatory value check default 'BY_HAND_LOAD',
*NCSYSINT type /BIC/OINCSYSINT obligatory value check default 'BY_HAND_EVERYDAY',
*NCSRCSYS type /BIC/OINCSRCSYS value check,
print as checkbox ,
execute as checkbox default 'X' .
*-----------------------------------------------------------------------
write : / ods , datefld.
perform build_source_code.
if print eq 'X'.
loop at sources.
write : / sy- tabix , sources .
endloop .
endif .
generate subroutine pool sources
name name
message message
line line .
if sy- subrc ne 0 .
write : / 'Syntax error, message' , message ,
/ 'in line' , line .
exit .
endif .
if execute eq 'X' .
write : / 'perform' , name .
perform do_delete in program ( name).
endif .
*&---------------------------------------------------------------------*
*& Form build_source_code
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form build_source_code.
tables dd03l.
data :
report_name type string ,
ods00 type string ,
ods40 type string ,
ods_par00 type string ,
linepk type string ,
fieldname like dd03l - fieldname,
datetos type string ,
datefroms type string ,
srcsyss type string ,
dateto like /bic/mncsysdat - date0,
datest type /bi0/oicalday ,
dateen type /bi0/oicalday ,
dateenocb type /bi0/oicalday ,
srcdso type /bic/oincsrcsys .
*-----------------------------------------------------------------------
concatenate 'ZNF_' ods '_DELETE_INTERVAL_DSO_DSO' into report_name .
concatenate '/BIC/A' ods '00' into ods00 .
concatenate '/BIC/A' ods '40' into ods40 .
*concatenate '/BIC/A' ods_par '00' into ods_par00.
*concatenate '''' dateto '''' into datetos.
*concatenate '''' datefrom '''' into datefroms.
*concatenate '''' srcsys '''' into srcsyss.
append :
'report ' to sources,
report_name to sources ,
'. ' to sources,
'form do_delete. ' to sources,
'data: ' to sources,
' line40 like ' to sources,
ods40 to sources ,
', ' to sources,
' dateST type /BI0/OICALDAY ' to sources,
', ' to sources,
' dateEN type /BI0/OICALDAY ' to sources,
', ' to sources,
' dateENOCB type /BI0/OICALDAY ' to sources,
', ' to sources,
' srcdso type /BIC/OINCSRCSYS ' to sources,
'. ' to sources,
*** Структура и таблица для комбинаций Дата - Исходная система .
'types: ' to sources ,
' begin of RUL_CHOISE , ' to sources,
' DAYLOAD type DATS , ' to sources,
' NCSRCSYS type /BIC/OINCSRCSYS , ' to sources,
' end of RUL_CHOISE . ' to sources,
'data: RULE_PARAMS_TABL type table of RUL_CHOISE , ' to sources,
' wa like line of RULE_PARAMS_TABL . ' to sources,
*** Начитываем все исходные системы со всеми датами . 'select' to sources ,
datefld to sources,
' /BIC/NCSRCSYS ' to sources,
' from ' to sources,
ods40 to sources ,
'into (wa-DAYLOAD, wa-NCSRCSYS )' to sources,
' group by ' to sources,
datefld to sources,
' /BIC/NCSRCSYS . ' to sources,
'write: / ''Комбинация Дата-Исходная система'', wa-DAYLOAD , wa-NCSRCSYS . ' to sources,
'append wa to RULE_PARAMS_TABL . ' to sources,
'endselect . ' to sources ,
* ПОИСК минимальной даты загрузки данных
'select min( ' to sources ,
datefld to sources ,
' )' to sources,
' into dateST ' to sources,
' from ' to sources ,
ods40 to sources,
'. ' to sources ,
' ' to sources ,
'write: / ''Минимальная дата '', dateST. ' to sources,
* ПОИСК максимальной даты загрузки данных
'select max( ' to sources,
datefld to sources ,
' ) ' to sources,
' into dateEN ' to sources,
' from ' to sources ,
ods40 to sources,
'. ' to sources ,
' ' to sources ,
'write: / ''Максимальная дата '', dateEN. ' to sources.
*>>>--------------- 28.04.2014
*Если DSO = NOOCB - берем максимальную дату не из 40 а из 00
*чтобы удалить данные в днях, которым откатили закрытие
if ods = 'NOOCB' .
append :
'select max( ' to sources,
datefld to sources,
' ) ' to sources,
' into dateENOCB ' to sources,
' from ' to sources,
ods00 to sources ,
'. ' to sources,
' ' to sources,
'write: / ''Максимальная дата '', dateENOCB. ' to sources,
' if dateENOCB gt dateEN. ' to sources,
*>
*** добавляем лишние даты
'select' to sources,
datefld to sources ,
' /BIC/NCSRCSYS ' to sources,
' from ' to sources,
ods00 to sources ,
'into (wa-DAYLOAD, wa-NCSRCSYS )' to sources,
' where ' to sources,
datefld to sources ,
' >= dateEN ' to sources ,
' and ' to sources ,
datefld to sources ,
' <= dateENOCB' to sources ,
' group by ' to sources,
datefld to sources,
' /BIC/NCSRCSYS . ' to sources,
'write: / ''Комбинация Дата-Исходная система NOOCB'', wa-DAYLOAD , wa-NCSRCSYS . ' to sources,
'append wa to RULE_PARAMS_TABL . ' to sources,
'endselect . ' to sources,
*<
' dateEN = dateENOCB.' to sources,
'ENDIF.' to sources.
endif .
*<<<---------------AILYCHEV 28.04.2014
* ПОИСК исходной системы
* 'select single /BIC/NCSRCSYS ' to sources,
* ' into srcdso ' to sources,
* ' from ' to sources,
* ods40 to sources,
* '. ' to sources,
* ' ' to sources,
*'write: / ''Исходная система '', srcdso . ' to sources,
append :
'select max( SID ) ' to sources,
' into line40-SID ' to sources,
' from ' to sources,
ods40 to sources ,
'. ' to sources,
'if line40-SID is initial. ' to sources,
' write: / ''SID not found''. ' to sources,
' exit. ' to sources,
'endif. ' to sources,
' ' to sources,
'select max( DATAPAKID ) ' to sources,
' into line40-DATAPAKID ' to sources,
' from ' to sources,
ods40 to sources ,
' where SID = line40-SID ' to sources,
'. ' to sources,
' ' to sources,
'line40-DATAPAKID = line40-DATAPAKID + 1. ' to sources,
'line40-RECORD = 0. ' to sources,
' ' to sources,
'line40-DATAPAKID = line40-DATAPAKID + 1. ' to sources,
'line40-RECORD = 0. ' to sources,
'select * ' to sources,
' into corresponding fields of line40 ' to sources,
' from ' to sources,
ods00 to sources,
'FOR ALL ENTRIES IN RULE_PARAMS_TABL' to sources,
' where ' to sources,
'/BIC/NCSRCSYS = RULE_PARAMS_TABL-NCSRCSYS and ' to sources,
datefld to sources,
' = RULE_PARAMS_TABL-DAYLOAD and ' to sources,
datefld to sources,
' >= dateST ' to sources,
' and ' to sources,
datefld to sources,
' <= dateEN' to sources ,
***** ' and /BIC/NCSRCSYS ' to sources ,
***** '= srcdso ' to sources ,
'. ' to sources,
' data SID like line40-SID. ' to sources,
' select single SID ' to sources,
' into SID ' to sources,
' from ' to sources,
ods40 to sources ,
' where ' to sources.
select fieldname
into fieldname
from dd03l
where tabname = ods00
and keyflag = 'X' .
if sy- dbcnt gt 1 .
append :
' and ' to sources.
endif .
concatenate 'line40-' fieldname into linepk .
append :
fieldname to sources ,
' = ' to sources,
linepk to sources .
endselect .
append :
' . ' to sources ,
' if SY-SUBRC ne 0. ' to sources,
' line40-RECORDMODE = ''D''. ' to sources,
' line40-RECORD = line40-RECORD + 1. ' to sources,
' insert into ' to sources,
ods40 to sources,
' values line40. ' to sources,
' endif. ' to sources ,
'endselect. ' to sources ,
'write: / ''Records to delete '', line40-RECORD. ' to sources,
'endform. ' to sources .
endform . "build_source_code
______________________form do_delete.
data :
line40 like /bic/anorkotur40 ,
sid like line40 -sid .
select max ( sid )
into line40 -sid
from /bic/anorkotur40 .
if line40- sid is initial.
write : / 'SID not found' .
exit .
endif .
select max ( datapakid )
into line40 -datapakid
from /bic/anorkotur40
where sid = line40 -sid .
line40- datapakid = line40 -datapakid + 1 .
line40- record = 0 .
select *
into corresponding fields of line40
from /bic/anorkotur00
where calday >= '20140701'
and calday <= '20140731'
and /bic/ncsrcsys = 'AKT' .
select single sid
into sid
from /bic/anorkotur40
where calday = line40 - calday
and /bic/ncbuhtran = line40 - /bic/ncbuhtran
and /bic/nctrpart = line40 - /bic/nctrpart.
if sy- subrc ne 0 .
line40- recordmode = 'D' .
line40- record = line40 - record + 1 .
insert into /bic/anorkotur40
values line40.
endif .
endselect .
write : / 'Records to delete ' , line40 - record.
*& Report ZN_DELETE_INTERVAL
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report zn_delete_interval_dso40.
data :
dateto like /bic/mncsysdat -date0 ,
datefrom like /bic/mncsysdat -date0 ,
interv like /bic/mncsysint -/bic/nfinterv value 1,
srcsys like /bic/tncsrcsys -/bic/ncsrcsys value 1,
mon like /bic/anoaktdt00 - calmonth,
count type i value 0 .
data :
sources( 72 ) occurs 100 with header line,
name like sy -cprog ,
message ( 128),
line type i .
*-----------------------------------------------------------------------
parameters :
ods type rsdodsobject obligatory value check default 'NORKOTUR' ,
*ods_par type RSDODSOBJECT obligatory value check default 'NORKOTUR',
datefld like dd03l -fieldname obligatory value check default 'CALDAY' ,
*NCSYSDAT type /BIC/OINCSYSDAT obligatory value check default 'BY_HAND_LOAD',
*NCSYSINT type /BIC/OINCSYSINT obligatory value check default 'BY_HAND_EVERYDAY',
*NCSRCSYS type /BIC/OINCSRCSYS value check,
print as checkbox ,
execute as checkbox default 'X' .
*-----------------------------------------------------------------------
write : / ods , datefld.
perform build_source_code.
if print eq 'X'.
loop at sources.
write : / sy- tabix , sources .
endloop .
endif .
generate subroutine pool sources
name name
message message
line line .
if sy- subrc ne 0 .
write : / 'Syntax error, message' , message ,
/ 'in line' , line .
exit .
endif .
if execute eq 'X' .
write : / 'perform' , name .
perform do_delete in program ( name).
endif .
*&---------------------------------------------------------------------*
*& Form build_source_code
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form build_source_code.
tables dd03l.
data :
report_name type string ,
ods00 type string ,
ods40 type string ,
ods_par00 type string ,
linepk type string ,
fieldname like dd03l - fieldname,
datetos type string ,
datefroms type string ,
srcsyss type string ,
dateto like /bic/mncsysdat - date0,
datest type /bi0/oicalday ,
dateen type /bi0/oicalday ,
dateenocb type /bi0/oicalday ,
srcdso type /bic/oincsrcsys .
*-----------------------------------------------------------------------
concatenate 'ZNF_' ods '_DELETE_INTERVAL_DSO_DSO' into report_name .
concatenate '/BIC/A' ods '00' into ods00 .
concatenate '/BIC/A' ods '40' into ods40 .
*concatenate '/BIC/A' ods_par '00' into ods_par00.
*concatenate '''' dateto '''' into datetos.
*concatenate '''' datefrom '''' into datefroms.
*concatenate '''' srcsys '''' into srcsyss.
append :
'report ' to sources,
report_name to sources ,
'. ' to sources,
'form do_delete. ' to sources,
'data: ' to sources,
' line40 like ' to sources,
ods40 to sources ,
', ' to sources,
' dateST type /BI0/OICALDAY ' to sources,
', ' to sources,
' dateEN type /BI0/OICALDAY ' to sources,
', ' to sources,
' dateENOCB type /BI0/OICALDAY ' to sources,
', ' to sources,
' srcdso type /BIC/OINCSRCSYS ' to sources,
'. ' to sources,
*** Структура и таблица для комбинаций Дата - Исходная система .
'types: ' to sources ,
' begin of RUL_CHOISE , ' to sources,
' DAYLOAD type DATS , ' to sources,
' NCSRCSYS type /BIC/OINCSRCSYS , ' to sources,
' end of RUL_CHOISE . ' to sources,
'data: RULE_PARAMS_TABL type table of RUL_CHOISE , ' to sources,
' wa like line of RULE_PARAMS_TABL . ' to sources,
*** Начитываем все исходные системы со всеми датами . 'select' to sources ,
datefld to sources,
' /BIC/NCSRCSYS ' to sources,
' from ' to sources,
ods40 to sources ,
'into (wa-DAYLOAD, wa-NCSRCSYS )' to sources,
' group by ' to sources,
datefld to sources,
' /BIC/NCSRCSYS . ' to sources,
'write: / ''Комбинация Дата-Исходная система'', wa-DAYLOAD , wa-NCSRCSYS . ' to sources,
'append wa to RULE_PARAMS_TABL . ' to sources,
'endselect . ' to sources ,
* ПОИСК минимальной даты загрузки данных
'select min( ' to sources ,
datefld to sources ,
' )' to sources,
' into dateST ' to sources,
' from ' to sources ,
ods40 to sources,
'. ' to sources ,
' ' to sources ,
'write: / ''Минимальная дата '', dateST. ' to sources,
* ПОИСК максимальной даты загрузки данных
'select max( ' to sources,
datefld to sources ,
' ) ' to sources,
' into dateEN ' to sources,
' from ' to sources ,
ods40 to sources,
'. ' to sources ,
' ' to sources ,
'write: / ''Максимальная дата '', dateEN. ' to sources.
*>>>--------------- 28.04.2014
*Если DSO = NOOCB - берем максимальную дату не из 40 а из 00
*чтобы удалить данные в днях, которым откатили закрытие
if ods = 'NOOCB' .
append :
'select max( ' to sources,
datefld to sources,
' ) ' to sources,
' into dateENOCB ' to sources,
' from ' to sources,
ods00 to sources ,
'. ' to sources,
' ' to sources,
'write: / ''Максимальная дата '', dateENOCB. ' to sources,
' if dateENOCB gt dateEN. ' to sources,
*>
*** добавляем лишние даты
'select' to sources,
datefld to sources ,
' /BIC/NCSRCSYS ' to sources,
' from ' to sources,
ods00 to sources ,
'into (wa-DAYLOAD, wa-NCSRCSYS )' to sources,
' where ' to sources,
datefld to sources ,
' >= dateEN ' to sources ,
' and ' to sources ,
datefld to sources ,
' <= dateENOCB' to sources ,
' group by ' to sources,
datefld to sources,
' /BIC/NCSRCSYS . ' to sources,
'write: / ''Комбинация Дата-Исходная система NOOCB'', wa-DAYLOAD , wa-NCSRCSYS . ' to sources,
'append wa to RULE_PARAMS_TABL . ' to sources,
'endselect . ' to sources,
*<
' dateEN = dateENOCB.' to sources,
'ENDIF.' to sources.
endif .
*<<<---------------AILYCHEV 28.04.2014
* ПОИСК исходной системы
* 'select single /BIC/NCSRCSYS ' to sources,
* ' into srcdso ' to sources,
* ' from ' to sources,
* ods40 to sources,
* '. ' to sources,
* ' ' to sources,
*'write: / ''Исходная система '', srcdso . ' to sources,
append :
'select max( SID ) ' to sources,
' into line40-SID ' to sources,
' from ' to sources,
ods40 to sources ,
'. ' to sources,
'if line40-SID is initial. ' to sources,
' write: / ''SID not found''. ' to sources,
' exit. ' to sources,
'endif. ' to sources,
' ' to sources,
'select max( DATAPAKID ) ' to sources,
' into line40-DATAPAKID ' to sources,
' from ' to sources,
ods40 to sources ,
' where SID = line40-SID ' to sources,
'. ' to sources,
' ' to sources,
'line40-DATAPAKID = line40-DATAPAKID + 1. ' to sources,
'line40-RECORD = 0. ' to sources,
' ' to sources,
'line40-DATAPAKID = line40-DATAPAKID + 1. ' to sources,
'line40-RECORD = 0. ' to sources,
'select * ' to sources,
' into corresponding fields of line40 ' to sources,
' from ' to sources,
ods00 to sources,
'FOR ALL ENTRIES IN RULE_PARAMS_TABL' to sources,
' where ' to sources,
'/BIC/NCSRCSYS = RULE_PARAMS_TABL-NCSRCSYS and ' to sources,
datefld to sources,
' = RULE_PARAMS_TABL-DAYLOAD and ' to sources,
datefld to sources,
' >= dateST ' to sources,
' and ' to sources,
datefld to sources,
' <= dateEN' to sources ,
***** ' and /BIC/NCSRCSYS ' to sources ,
***** '= srcdso ' to sources ,
'. ' to sources,
' data SID like line40-SID. ' to sources,
' select single SID ' to sources,
' into SID ' to sources,
' from ' to sources,
ods40 to sources ,
' where ' to sources.
select fieldname
into fieldname
from dd03l
where tabname = ods00
and keyflag = 'X' .
if sy- dbcnt gt 1 .
append :
' and ' to sources.
endif .
concatenate 'line40-' fieldname into linepk .
append :
fieldname to sources ,
' = ' to sources,
linepk to sources .
endselect .
append :
' . ' to sources ,
' if SY-SUBRC ne 0. ' to sources,
' line40-RECORDMODE = ''D''. ' to sources,
' line40-RECORD = line40-RECORD + 1. ' to sources,
' insert into ' to sources,
ods40 to sources,
' values line40. ' to sources,
' endif. ' to sources ,
'endselect. ' to sources ,
'write: / ''Records to delete '', line40-RECORD. ' to sources,
'endform. ' to sources .
endform . "build_source_code
______________________form do_delete.
data :
line40 like /bic/anorkotur40 ,
sid like line40 -sid .
select max ( sid )
into line40 -sid
from /bic/anorkotur40 .
if line40- sid is initial.
write : / 'SID not found' .
exit .
endif .
select max ( datapakid )
into line40 -datapakid
from /bic/anorkotur40
where sid = line40 -sid .
line40- datapakid = line40 -datapakid + 1 .
line40- record = 0 .
select *
into corresponding fields of line40
from /bic/anorkotur00
where calday >= '20140701'
and calday <= '20140731'
and /bic/ncsrcsys = 'AKT' .
select single sid
into sid
from /bic/anorkotur40
where calday = line40 - calday
and /bic/ncbuhtran = line40 - /bic/ncbuhtran
and /bic/nctrpart = line40 - /bic/nctrpart.
if sy- subrc ne 0 .
line40- recordmode = 'D' .
line40- record = line40 - record + 1 .
insert into /bic/anorkotur40
values line40.
endif .
endselect .
write : / 'Records to delete ' , line40 - record.
endform .
___________________________________________________________
Ещё одна версия, более дерзкая...
REPORT znn_dso_load_delete.
DATA :
gv_dtiobj TYPE rsdiobjnm ,
gv_error_message TYPE string .
*&---------------------------------------------------------------------*
*& Screen
*&---------------------------------------------------------------------*
PARAMETERS :
p_dsonam TYPE rsdodsobject OBLIGATORY. " default 'ZMM_D85'.
SELECT-OPTIONS :
so_iobj FOR gv_dtiobj NO INTERVALS .
*&---------------------------------------------------------------------*
*& End of Screen
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Report
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
INITIALIZATION .
PERFORM f_init.
*----------------------------------------------------------------------*
AT SELECTION-SCREEN
ON VALUE-REQUEST FOR p_dsonam .
PERFORM f_valreq_dso.
*----------------------------------------------------------------------*
AT SELECTION-SCREEN
ON VALUE-REQUEST FOR so_iobj -low .
PERFORM f_valreq_iobj.
*----------------------------------------------------------------------*
START-OF-SELECTION .
PERFORM f_check
CHANGING gv_error_message .
IF gv_error_message IS NOT INITIAL .
MESSAGE gv_error_message TYPE 'I' .
RETURN .
ENDIF .
CLEAR gv_error_message.
PERFORM f_main
CHANGING gv_error_message .
IF gv_error_message IS NOT INITIAL .
cl_demo_output=> display ( gv_error_message ).
MESSAGE gv_error_message TYPE 'I' .
RETURN .
ENDIF .
*&---------------------------------------------------------------------*
*& End of Report
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Forms
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
* Initialization
*----------------------------------------------------------------------*
FORM f_init.
"Select options restrict
CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
EXPORTING
restriction = VALUE sscr_restrict(
opt_list_tab = VALUE #(
(
name = 'EQ'
options -eq = 'X'
)
)
ass_tab = VALUE #(
(
kind = 'S'
name = 'SO_IOBJ'
sg_main = 'I'
op_main = 'EQ'
)
)
).
"
ENDFORM .
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* F4 for DSO
*----------------------------------------------------------------------*
FORM f_valreq_dso .
cl_rsd_odso=> f4 (
CHANGING
c_odsobject = p_dsonam
).
ENDFORM .
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* F4 for infoobject
*----------------------------------------------------------------------*
FORM f_valreq_iobj.
TYPES :
BEGIN OF ts_data ,
iobjnm TYPE rsdodsoiobj -iobjnm ,
posit TYPE rsdodsoiobj -posit ,
keyflag TYPE rsdodsoiobj -keyflag ,
END OF ts_data .
DATA :
lt_field_values TYPE TABLE OF dynpread ,
lt_select_data TYPE TABLE OF ts_data ,
lv_odsname LIKE p_dsonam ,
lt_values TYPE TABLE OF ddshretval .
FIELD-SYMBOLS :
<lfs_value> LIKE LINE OF lt_values ,
<lfs_screen_val> LIKE so_iobj .
"Get screen field values
lt_field_values = VALUE #(
( fieldname = 'P_DSONAM' )
).
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
dyname = sy - repid
dynumb = sy - dynnr
translate_to_upper = 'X'
TABLES
dynpfields = lt_field_values .
lv_odsname = lt_field_values[ fieldname = 'P_DSONAM' ]- fieldvalue .
"
"Get DSO fields
SELECT *
FROM rsdodsoiobj
INTO CORRESPONDING FIELDS OF TABLE @lt_select_data
WHERE objvers = 'A'
AND keyflag = 'X'
AND odsobject = @lv_odsname
ORDER BY posit ASCENDING
.
IF sy- subrc <> 0.
MESSAGE 'Укажите корректное имя DSO' TYPE 'I'.
RETURN .
ENDIF .
"
"Show F4 help
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'IOBJNM'
dynpprog = sy - repid
dynpnr = sy - dynnr
dynprofield = 'SO_IOBJ-LOW'
value_org = 'S'
multiple_choice = 'X'
TABLES
value_tab = lt_select_data
return_tab = lt_values .
"
IF lt_values IS INITIAL .
MESSAGE 'Ничего не выбрано' TYPE 'I'.
RETURN .
ENDIF .
"Move selected fields to select-option
CLEAR so_iobj[].
LOOP AT lt_values
ASSIGNING <lfs_value> .
APPEND VALUE # (
sign = 'I'
option = 'EQ'
low = <lfs_value> -fieldval
) TO so_iobj[] .
ENDLOOP .
"
"Set select-option screen value
READ TABLE so_iobj[]
INDEX 1
ASSIGNING <lfs_screen_val> .
lt_field_values = VALUE #(
( fieldname = 'SO_IOBJ-LOW' fieldvalue = <lfs_screen_val> -low )
).
CALL FUNCTION 'DYNP_VALUES_UPDATE'
EXPORTING
dyname = sy -repid
dynumb = sy -dynnr
TABLES
dynpfields = lt_field_values .
"
ENDFORM .
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* Main report
*----------------------------------------------------------------------*
FORM f_main
CHANGING iv_error_message TYPE string .
CONSTANTS :
lc_nl( 1 ) TYPE c
VALUE cl_abap_char_utilities =>newline ,
lc_tab( 1 ) TYPE c
VALUE cl_abap_char_utilities =>horizontal_tab .
DATA :
"Table info
lv_tab_name TYPE string ,
lv_tab_log_name TYPE string ,
lt_keys TYPE TABLE OF string ,
lv_field LIKE LINE OF lt_keys .
DATA :
"SQL aux variables
lv_sql TYPE string ,
lv_keys TYPE string ,
lv_filter_fields TYPE string ,
lt_other_fields TYPE TABLE OF string ,
lv_other_fields TYPE string ,
lo_conn TYPE REF TO cl_sql_connection ,
lo_prepared_statement TYPE REF TO cl_sql_prepared_statement ,
lx_exc TYPE REF TO cx_sql_exception ,
lv_error TYPE string .
DATA :
lv_rowcount TYPE i ,
lv_sid TYPE rssid ,
lv_datapid TYPE rsdatapid ,
lv_record TYPE rsarecord ,
lv_str TYPE string ,
lv_group_filter TYPE string .
FIELD-SYMBOLS :
<lfs_so_iobj> LIKE so_iobj .
lv_tab_name = |/BIC/A{ p_dsonam }00|.
lv_tab_log_name = |/BIC/A{ p_dsonam }40| .
"Get key fields
SELECT fieldname
FROM dd03l
INTO TABLE @lt_keys
WHERE tabname = @lv_tab_name
AND keyflag = 'X'
ORDER BY position ASCENDING
.
"
"Format key fields for select
lv_keys = lc_nl && lc_tab
&& |"{ lt_keys[ 1 ] }"|.
LOOP AT lt_keys
INTO lv_field
FROM 2 .
lv_keys = lv_keys && lc_nl && lc_tab
&& |, "{ lv_field }"|.
ENDLOOP .
lv_keys = lv_keys && lc_nl.
"
"Get "other" fields
SELECT fieldname
FROM dd03l
INTO TABLE @lt_other_fields
WHERE tabname = @lv_tab_name
AND keyflag = ''
AND fieldname <> 'RECORDMODE'
ORDER BY position ASCENDING
.
"
"Format "other" fields for insert
lv_other_fields = lc_tab && | , "{ lt_other_fields[ 1 ] }"|.
LOOP AT lt_other_fields
INTO lv_field
FROM 2 .
lv_other_fields = lv_other_fields && lc_nl && lc_tab
&& |, "{ lv_field }"|.
ENDLOOP .
lv_other_fields = lv_other_fields && lc_nl .
"
"Create reload groups
IF so_iobj IS NOT INITIAL .
lv_str = so_iobj[ 1 ] - low.
SELECT SINGLE fieldnm
FROM rsdiobj
INTO @lv_filter_fields
WHERE iobjnm = @lv_str
.
lv_filter_fields = lc_nl && lc_tab && | "{ lv_filter_fields }"| && lc_nl .
LOOP AT so_iobj[]
ASSIGNING <lfs_so_iobj>
FROM 2 .
SELECT SINGLE fieldnm
FROM rsdiobj
INTO @lv_str
WHERE iobjnm = @<lfs_so_iobj> - low
.
lv_filter_fields = lv_filter_fields && lc_tab
&& |, "{ lv_str }"| && lc_nl.
ENDLOOP .
lv_group_filter = |and ({ lv_filter_fields } ) in ( | && lc_nl
&& |select distinct{ lv_filter_fields } from "{ lv_tab_log_name }"| && lc_nl
&& |) | && lc_nl .
ENDIF .
"
"Compose SQL statement to execute
lv_sql = |insert into "{ lv_tab_log_name }" ({ lv_keys }|
&& |{ lv_other_fields }|
&& |{ lc_tab }, RECORDMODE| && lc_nl
&& |{ lc_tab }, SID| && lc_nl
&& |{ lc_tab }, DATAPAKID| && lc_nl
&& |{ lc_tab }, RECORD| && lc_nl
&& `)` && lc_nl
&& |select { lv_keys }|
&& |{ lv_other_fields }|
&& |{ lc_tab }, 'D' as RECORDMODE| && lc_nl
&& |{ lc_tab }, ? as SID| && lc_nl
&& |{ lc_tab }, ? as DATAPAKID| && lc_nl
&& |{ lc_tab }, row_number () over ( ) + ? as RECORD| && lc_nl
&& |from "{ lv_tab_name }"| && lc_nl
&& |where ( { lv_keys } ) not in ( | && lc_nl
&& |select { lv_keys } from "{ lv_tab_log_name }"| && lc_nl
&& |) | && lc_nl
&& lv_group_filter
.
WRITE / lv_sql.
cl_demo_output=> display ( lv_sql ).
"
"Get latest SID, datapackage # and record #
SELECT
MAX ( sid )
, MAX( datapakid )
, MAX( record )
FROM (lv_tab_log_name )
INTO (
@lv_sid
, @lv_datapid
, @lv_record
)
.
"
IF lv_sid IS INITIAL .
lv_sid = 1 .
ENDIF .
IF lv_datapid IS INITIAL .
lv_datapid = 1 .
ENDIF .
TRY .
"Create connection and prepared statement
lo_conn = cl_sql_connection =>get_connection ( ).
lo_prepared_statement = lo_conn ->prepare_statement ( lv_sql ).
"
"Set statement parameters
lo_prepared_statement-> set_param (
data_ref = REF #( lv_sid )
inout = cl_sql_prepared_statement =>c_param_in
).
lo_prepared_statement-> set_param (
data_ref = REF #( lv_datapid )
inout = cl_sql_prepared_statement =>c_param_in
).
lo_prepared_statement-> set_param (
data_ref = REF #( lv_record )
inout = cl_sql_prepared_statement =>c_param_in
).
"
"Execute statement and exit
lv_rowcount = lo_prepared_statement ->execute_update ( ).
WRITE / |{ lv_rowcount } rows inserted . |.
lo_conn-> commit ( ).
lo_conn-> close ( ).
"
CATCH cx_sql_exception INTO lx_exc .
iv_error_message = lx_exc ->get_text ( ).
RETURN .
ENDTRY .
ENDFORM .
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM f_check
CHANGING iv_error_message TYPE string .
SELECT COUNT (* )
FROM rsdodso
WHERE odsobject = @p_dsonam .
IF sy- subrc <> 0.
iv_error_message = 'Укажите корректный объект DSO' .
RETURN .
ENDIF .
SELECT COUNT (* )
FROM rsdodsoiobj
WHERE odsobject = @p_dsonam
AND iobjnm IN @so_iobj .
IF sy- subrc <> 0.
iv_error_message = 'Укажите корректные инфоообъекты для DSO' .
RETURN .
ENDIF .
ENDFORM .
DATA :
gv_dtiobj TYPE rsdiobjnm ,
gv_error_message TYPE string .
*&---------------------------------------------------------------------*
*& Screen
*&---------------------------------------------------------------------*
PARAMETERS :
p_dsonam TYPE rsdodsobject OBLIGATORY. " default 'ZMM_D85'.
SELECT-OPTIONS :
so_iobj FOR gv_dtiobj NO INTERVALS .
*&---------------------------------------------------------------------*
*& End of Screen
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Report
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
INITIALIZATION .
PERFORM f_init.
*----------------------------------------------------------------------*
AT SELECTION-SCREEN
ON VALUE-REQUEST FOR p_dsonam .
PERFORM f_valreq_dso.
*----------------------------------------------------------------------*
AT SELECTION-SCREEN
ON VALUE-REQUEST FOR so_iobj -low .
PERFORM f_valreq_iobj.
*----------------------------------------------------------------------*
START-OF-SELECTION .
PERFORM f_check
CHANGING gv_error_message .
IF gv_error_message IS NOT INITIAL .
MESSAGE gv_error_message TYPE 'I' .
RETURN .
ENDIF .
CLEAR gv_error_message.
PERFORM f_main
CHANGING gv_error_message .
IF gv_error_message IS NOT INITIAL .
cl_demo_output=> display ( gv_error_message ).
MESSAGE gv_error_message TYPE 'I' .
RETURN .
ENDIF .
*&---------------------------------------------------------------------*
*& End of Report
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Forms
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
* Initialization
*----------------------------------------------------------------------*
FORM f_init.
"Select options restrict
CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
EXPORTING
restriction = VALUE sscr_restrict(
opt_list_tab = VALUE #(
(
name = 'EQ'
options -eq = 'X'
)
)
ass_tab = VALUE #(
(
kind = 'S'
name = 'SO_IOBJ'
sg_main = 'I'
op_main = 'EQ'
)
)
).
"
ENDFORM .
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* F4 for DSO
*----------------------------------------------------------------------*
FORM f_valreq_dso .
cl_rsd_odso=> f4 (
CHANGING
c_odsobject = p_dsonam
).
ENDFORM .
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* F4 for infoobject
*----------------------------------------------------------------------*
FORM f_valreq_iobj.
TYPES :
BEGIN OF ts_data ,
iobjnm TYPE rsdodsoiobj -iobjnm ,
posit TYPE rsdodsoiobj -posit ,
keyflag TYPE rsdodsoiobj -keyflag ,
END OF ts_data .
DATA :
lt_field_values TYPE TABLE OF dynpread ,
lt_select_data TYPE TABLE OF ts_data ,
lv_odsname LIKE p_dsonam ,
lt_values TYPE TABLE OF ddshretval .
FIELD-SYMBOLS :
<lfs_value> LIKE LINE OF lt_values ,
<lfs_screen_val> LIKE so_iobj .
"Get screen field values
lt_field_values = VALUE #(
( fieldname = 'P_DSONAM' )
).
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
dyname = sy - repid
dynumb = sy - dynnr
translate_to_upper = 'X'
TABLES
dynpfields = lt_field_values .
lv_odsname = lt_field_values[ fieldname = 'P_DSONAM' ]- fieldvalue .
"
"Get DSO fields
SELECT *
FROM rsdodsoiobj
INTO CORRESPONDING FIELDS OF TABLE @lt_select_data
WHERE objvers = 'A'
AND keyflag = 'X'
AND odsobject = @lv_odsname
ORDER BY posit ASCENDING
.
IF sy- subrc <> 0.
MESSAGE 'Укажите корректное имя DSO' TYPE 'I'.
RETURN .
ENDIF .
"
"Show F4 help
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'IOBJNM'
dynpprog = sy - repid
dynpnr = sy - dynnr
dynprofield = 'SO_IOBJ-LOW'
value_org = 'S'
multiple_choice = 'X'
TABLES
value_tab = lt_select_data
return_tab = lt_values .
"
IF lt_values IS INITIAL .
MESSAGE 'Ничего не выбрано' TYPE 'I'.
RETURN .
ENDIF .
"Move selected fields to select-option
CLEAR so_iobj[].
LOOP AT lt_values
ASSIGNING <lfs_value> .
APPEND VALUE # (
sign = 'I'
option = 'EQ'
low = <lfs_value> -fieldval
) TO so_iobj[] .
ENDLOOP .
"
"Set select-option screen value
READ TABLE so_iobj[]
INDEX 1
ASSIGNING <lfs_screen_val> .
lt_field_values = VALUE #(
( fieldname = 'SO_IOBJ-LOW' fieldvalue = <lfs_screen_val> -low )
).
CALL FUNCTION 'DYNP_VALUES_UPDATE'
EXPORTING
dyname = sy -repid
dynumb = sy -dynnr
TABLES
dynpfields = lt_field_values .
"
ENDFORM .
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* Main report
*----------------------------------------------------------------------*
FORM f_main
CHANGING iv_error_message TYPE string .
CONSTANTS :
lc_nl( 1 ) TYPE c
VALUE cl_abap_char_utilities =>newline ,
lc_tab( 1 ) TYPE c
VALUE cl_abap_char_utilities =>horizontal_tab .
DATA :
"Table info
lv_tab_name TYPE string ,
lv_tab_log_name TYPE string ,
lt_keys TYPE TABLE OF string ,
lv_field LIKE LINE OF lt_keys .
DATA :
"SQL aux variables
lv_sql TYPE string ,
lv_keys TYPE string ,
lv_filter_fields TYPE string ,
lt_other_fields TYPE TABLE OF string ,
lv_other_fields TYPE string ,
lo_conn TYPE REF TO cl_sql_connection ,
lo_prepared_statement TYPE REF TO cl_sql_prepared_statement ,
lx_exc TYPE REF TO cx_sql_exception ,
lv_error TYPE string .
DATA :
lv_rowcount TYPE i ,
lv_sid TYPE rssid ,
lv_datapid TYPE rsdatapid ,
lv_record TYPE rsarecord ,
lv_str TYPE string ,
lv_group_filter TYPE string .
FIELD-SYMBOLS :
<lfs_so_iobj> LIKE so_iobj .
lv_tab_name = |/BIC/A{ p_dsonam }00|.
lv_tab_log_name = |/BIC/A{ p_dsonam }40| .
"Get key fields
SELECT fieldname
FROM dd03l
INTO TABLE @lt_keys
WHERE tabname = @lv_tab_name
AND keyflag = 'X'
ORDER BY position ASCENDING
.
"
"Format key fields for select
lv_keys = lc_nl && lc_tab
&& |"{ lt_keys[ 1 ] }"|.
LOOP AT lt_keys
INTO lv_field
FROM 2 .
lv_keys = lv_keys && lc_nl && lc_tab
&& |, "{ lv_field }"|.
ENDLOOP .
lv_keys = lv_keys && lc_nl.
"
"Get "other" fields
SELECT fieldname
FROM dd03l
INTO TABLE @lt_other_fields
WHERE tabname = @lv_tab_name
AND keyflag = ''
AND fieldname <> 'RECORDMODE'
ORDER BY position ASCENDING
.
"
"Format "other" fields for insert
lv_other_fields = lc_tab && | , "{ lt_other_fields[ 1 ] }"|.
LOOP AT lt_other_fields
INTO lv_field
FROM 2 .
lv_other_fields = lv_other_fields && lc_nl && lc_tab
&& |, "{ lv_field }"|.
ENDLOOP .
lv_other_fields = lv_other_fields && lc_nl .
"
"Create reload groups
IF so_iobj IS NOT INITIAL .
lv_str = so_iobj[ 1 ] - low.
SELECT SINGLE fieldnm
FROM rsdiobj
INTO @lv_filter_fields
WHERE iobjnm = @lv_str
.
lv_filter_fields = lc_nl && lc_tab && | "{ lv_filter_fields }"| && lc_nl .
LOOP AT so_iobj[]
ASSIGNING <lfs_so_iobj>
FROM 2 .
SELECT SINGLE fieldnm
FROM rsdiobj
INTO @lv_str
WHERE iobjnm = @<lfs_so_iobj> - low
.
lv_filter_fields = lv_filter_fields && lc_tab
&& |, "{ lv_str }"| && lc_nl.
ENDLOOP .
lv_group_filter = |and ({ lv_filter_fields } ) in ( | && lc_nl
&& |select distinct{ lv_filter_fields } from "{ lv_tab_log_name }"| && lc_nl
&& |) | && lc_nl .
ENDIF .
"
"Compose SQL statement to execute
lv_sql = |insert into "{ lv_tab_log_name }" ({ lv_keys }|
&& |{ lv_other_fields }|
&& |{ lc_tab }, RECORDMODE| && lc_nl
&& |{ lc_tab }, SID| && lc_nl
&& |{ lc_tab }, DATAPAKID| && lc_nl
&& |{ lc_tab }, RECORD| && lc_nl
&& `)` && lc_nl
&& |select { lv_keys }|
&& |{ lv_other_fields }|
&& |{ lc_tab }, 'D' as RECORDMODE| && lc_nl
&& |{ lc_tab }, ? as SID| && lc_nl
&& |{ lc_tab }, ? as DATAPAKID| && lc_nl
&& |{ lc_tab }, row_number () over ( ) + ? as RECORD| && lc_nl
&& |from "{ lv_tab_name }"| && lc_nl
&& |where ( { lv_keys } ) not in ( | && lc_nl
&& |select { lv_keys } from "{ lv_tab_log_name }"| && lc_nl
&& |) | && lc_nl
&& lv_group_filter
.
WRITE / lv_sql.
cl_demo_output=> display ( lv_sql ).
"
"Get latest SID, datapackage # and record #
SELECT
MAX ( sid )
, MAX( datapakid )
, MAX( record )
FROM (lv_tab_log_name )
INTO (
@lv_sid
, @lv_datapid
, @lv_record
)
.
"
IF lv_sid IS INITIAL .
lv_sid = 1 .
ENDIF .
IF lv_datapid IS INITIAL .
lv_datapid = 1 .
ENDIF .
TRY .
"Create connection and prepared statement
lo_conn = cl_sql_connection =>get_connection ( ).
lo_prepared_statement = lo_conn ->prepare_statement ( lv_sql ).
"
"Set statement parameters
lo_prepared_statement-> set_param (
data_ref = REF #( lv_sid )
inout = cl_sql_prepared_statement =>c_param_in
).
lo_prepared_statement-> set_param (
data_ref = REF #( lv_datapid )
inout = cl_sql_prepared_statement =>c_param_in
).
lo_prepared_statement-> set_param (
data_ref = REF #( lv_record )
inout = cl_sql_prepared_statement =>c_param_in
).
"
"Execute statement and exit
lv_rowcount = lo_prepared_statement ->execute_update ( ).
WRITE / |{ lv_rowcount } rows inserted . |.
lo_conn-> commit ( ).
lo_conn-> close ( ).
"
CATCH cx_sql_exception INTO lx_exc .
iv_error_message = lx_exc ->get_text ( ).
RETURN .
ENDTRY .
ENDFORM .
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM f_check
CHANGING iv_error_message TYPE string .
SELECT COUNT (* )
FROM rsdodso
WHERE odsobject = @p_dsonam .
IF sy- subrc <> 0.
iv_error_message = 'Укажите корректный объект DSO' .
RETURN .
ENDIF .
SELECT COUNT (* )
FROM rsdodsoiobj
WHERE odsobject = @p_dsonam
AND iobjnm IN @so_iobj .
IF sy- subrc <> 0.
iv_error_message = 'Укажите корректные инфоообъекты для DSO' .
RETURN .
ENDIF .
ENDFORM .
*----------------------------------------------------------------------*
Комментариев нет:
Отправить комментарий