types begin of ty_source_package.
include type _ty_s_sc_1.
types summa type /bic/oinfrest.
types end of ty_source_package.
lt_source_package type standard table of ty_source_package,
wa_source_package like line of lt_source_package,
или
wa_source_package type ty_source_package,
start routine:
include type _ty_s_sc_1.
types summa type /bic/oinfrest.
types end of ty_source_package.
lt_source_package type standard table of ty_source_package,
wa_source_package like line of lt_source_package,
или
wa_source_package type ty_source_package,
start routine:
*"----------------------------------------------------------------------
types begin of ty_source_package.
include type _ty_s_sc_1.
types end of ty_source_package.
data:
l_dfrom type d,
l_dto type d,
l_char10 type c length 10, "Для преобразования даты
l_idx type i,
lt_source_package type standard table of ty_source_package,
wa_source_package like line of lt_source_package,
l_day_count type i.
*-----------------------------------------------------------------------
*" 1. Зачищаем исходный пакет:
clear SOURCE_PACKAGE.
*" 2. Получаем границы периода:
select single low
from tvarvc
into l_char10
where name = 'ZSO_NOCRERSA_PERIOD'.
*" Обработка формата даты с точками
if strlen( l_char10 ) = 10.
concatenate l_char10+6(4) "Год
l_char10+3(2) "Месяц
l_char10+0(2) "День
into l_char10.
endif.
l_dfrom = l_char10.
select single high
from tvarvc
into l_char10
where name = 'ZSO_NOCRERSA_PERIOD'.
*" Обработка формата даты с точками
if strlen( l_char10 ) = 10.
concatenate l_char10+6(4) "Год
l_char10+3(2) "Месяц
l_char10+0(2) "День
into l_char10.
endif.
l_dto = l_char10.
*" Количество дней
l_day_count = l_dto - l_dfrom.
*" 3. Адский селект через Open-SQL:
EXEC SQL.
OPEN C FOR
select t1.CALDAY, t1."/BIC/NCCREDIT", t1."/BIC/NCACC",
t1."/BIC/NCCOVER", t1."/BIC/NCRELTYPE", t1."/BIC/NFREST",
t1."/BIC/NFRESTBS", SUMMA, t1."/BIC/NFBTRATE",
t1."/BIC/NCACCCUR",
t1."/BIC/NFRESMIN", t1."/BIC/NFRESRAS", t1."/BIC/NCBAL1",
t1."/BIC/NCBAL2", t1."/BIC/NCCREDACC", t1."/BIC/NCBRANCH",
t1."/BIC/NCSRCSYS", t1."/BIC/NCRELMSFO", t1."/BIC/NCHARREL",
t1."/BIC/NCPARTY", t1."/BIC/NCCRKACH", t1."/BIC/NCCRFINP",
t1."/BIC/NCCRKK", t1."/BIC/NCSTNB", t1."/BIC/NFTRRATE",
t1."/BIC/NFRCOUNT", t1."/BIC/NCCOKIND", t1."/BIC/NCCOKACH",
t1."/BIC/NCFUNDDOG", t1."/BIC/NFSUMDOG", 'N' as RECORDMODE,
'20150101' as NCDT, t1."/BIC/NCRELUSER",
t1."/BIC/NCDLASTPR", t1."/BIC/NCCRPROD", t1."/BIC/NCCRPRODP",
t1."/BIC/NCPTTYPE", t1."/BIC/NCDEAL", t1."/BIC/NCHOMOPRF",
t1."/BIC/NCCOZALP", t1."/BIC/NCCOPOSLZ", t1."/BIC/NCEXDT",
t1."/BIC/NCCRPOS", t1."/BIC/NCSORT", t1."/BIC/NFSORT",
t1."/BIC/NCDLASTP2", t1."/BIC/NCCOSTCFU", t1."/BIC/NCBISELEM",
t1."/BIC/NCALGCFU", t1."/BIC/NCFZ209", t1."/BIC/NCSUBD",
t1."/BIC/NCPARTVIP", t1."/BIC/NCACCAREA", t1."/BIC/NCACCHAR",
t1."/BIC/NCRESIDEN", t1."/BIC/NCPRODUCT", t1."/BIC/NCDETYP",
t1."/BIC/NCFNOPER", t1."/BIC/NCREQID", t1."/BIC/NCCREDDOG",
'1 ' as RECORD
from sapsr3."/BIC/ANOCRERST00" t1 inner join
(select "/BIC/NCACC" as NCACC, "/BIC/NCCREDIT" as NCCREDIT,
"/BIC/NCCOVER" as NCCOVER, max(CALDAY) as CALDAY,
sum("/BIC/NFRESTBS") as SUMMA
from sapsr3."/BIC/ANOCRERST00"
where CALDAY between :l_dfrom and :l_dto
group by "/BIC/NCACC", "/BIC/NCCREDIT", "/BIC/NCCOVER"
) t2 on t1.CALDAY = t2.CALDAY and t1."/BIC/NCACC" = t2.NCACC
and t1."/BIC/NCCREDIT" = t2.NCCREDIT
and t1."/BIC/NCCOVER" = t2.NCCOVER
where t1.CALDAY between :l_dfrom and :l_dto
and t1."/BIC/NFRESTBS" <> 0
ENDEXEC.
*" 4. Забираем результат:
do.
EXEC SQL.
FETCH NEXT C INTO :wa_source_package
ENDEXEC.
if sy-subrc <> 0.
exit.
else.
l_idx = l_idx + 1.
wa_source_package-record = l_idx.
wa_source_package-/bic/nfresta =
wa_source_package-/bic/nfresta / l_day_count.
append wa_source_package to SOURCE_PACKAGE.
endif.
enddo.
EXEC SQL.
CLOSE C
ENDEXEC.
*-----------------------------------------------------------------------
types begin of ty_source_package.
include type _ty_s_sc_1.
types end of ty_source_package.
data:
l_dfrom type d,
l_dto type d,
l_char10 type c length 10, "Для преобразования даты
l_idx type i,
lt_source_package type standard table of ty_source_package,
wa_source_package like line of lt_source_package,
l_day_count type i.
*-----------------------------------------------------------------------
*" 1. Зачищаем исходный пакет:
clear SOURCE_PACKAGE.
*" 2. Получаем границы периода:
select single low
from tvarvc
into l_char10
where name = 'ZSO_NOCRERSA_PERIOD'.
*" Обработка формата даты с точками
if strlen( l_char10 ) = 10.
concatenate l_char10+6(4) "Год
l_char10+3(2) "Месяц
l_char10+0(2) "День
into l_char10.
endif.
l_dfrom = l_char10.
select single high
from tvarvc
into l_char10
where name = 'ZSO_NOCRERSA_PERIOD'.
*" Обработка формата даты с точками
if strlen( l_char10 ) = 10.
concatenate l_char10+6(4) "Год
l_char10+3(2) "Месяц
l_char10+0(2) "День
into l_char10.
endif.
l_dto = l_char10.
*" Количество дней
l_day_count = l_dto - l_dfrom.
*" 3. Адский селект через Open-SQL:
EXEC SQL.
OPEN C FOR
select t1.CALDAY, t1."/BIC/NCCREDIT", t1."/BIC/NCACC",
t1."/BIC/NCCOVER", t1."/BIC/NCRELTYPE", t1."/BIC/NFREST",
t1."/BIC/NFRESTBS", SUMMA, t1."/BIC/NFBTRATE",
t1."/BIC/NCACCCUR",
t1."/BIC/NFRESMIN", t1."/BIC/NFRESRAS", t1."/BIC/NCBAL1",
t1."/BIC/NCBAL2", t1."/BIC/NCCREDACC", t1."/BIC/NCBRANCH",
t1."/BIC/NCSRCSYS", t1."/BIC/NCRELMSFO", t1."/BIC/NCHARREL",
t1."/BIC/NCPARTY", t1."/BIC/NCCRKACH", t1."/BIC/NCCRFINP",
t1."/BIC/NCCRKK", t1."/BIC/NCSTNB", t1."/BIC/NFTRRATE",
t1."/BIC/NFRCOUNT", t1."/BIC/NCCOKIND", t1."/BIC/NCCOKACH",
t1."/BIC/NCFUNDDOG", t1."/BIC/NFSUMDOG", 'N' as RECORDMODE,
'20150101' as NCDT, t1."/BIC/NCRELUSER",
t1."/BIC/NCDLASTPR", t1."/BIC/NCCRPROD", t1."/BIC/NCCRPRODP",
t1."/BIC/NCPTTYPE", t1."/BIC/NCDEAL", t1."/BIC/NCHOMOPRF",
t1."/BIC/NCCOZALP", t1."/BIC/NCCOPOSLZ", t1."/BIC/NCEXDT",
t1."/BIC/NCCRPOS", t1."/BIC/NCSORT", t1."/BIC/NFSORT",
t1."/BIC/NCDLASTP2", t1."/BIC/NCCOSTCFU", t1."/BIC/NCBISELEM",
t1."/BIC/NCALGCFU", t1."/BIC/NCFZ209", t1."/BIC/NCSUBD",
t1."/BIC/NCPARTVIP", t1."/BIC/NCACCAREA", t1."/BIC/NCACCHAR",
t1."/BIC/NCRESIDEN", t1."/BIC/NCPRODUCT", t1."/BIC/NCDETYP",
t1."/BIC/NCFNOPER", t1."/BIC/NCREQID", t1."/BIC/NCCREDDOG",
'1 ' as RECORD
from sapsr3."/BIC/ANOCRERST00" t1 inner join
(select "/BIC/NCACC" as NCACC, "/BIC/NCCREDIT" as NCCREDIT,
"/BIC/NCCOVER" as NCCOVER, max(CALDAY) as CALDAY,
sum("/BIC/NFRESTBS") as SUMMA
from sapsr3."/BIC/ANOCRERST00"
where CALDAY between :l_dfrom and :l_dto
group by "/BIC/NCACC", "/BIC/NCCREDIT", "/BIC/NCCOVER"
) t2 on t1.CALDAY = t2.CALDAY and t1."/BIC/NCACC" = t2.NCACC
and t1."/BIC/NCCREDIT" = t2.NCCREDIT
and t1."/BIC/NCCOVER" = t2.NCCOVER
where t1.CALDAY between :l_dfrom and :l_dto
and t1."/BIC/NFRESTBS" <> 0
ENDEXEC.
*" 4. Забираем результат:
do.
EXEC SQL.
FETCH NEXT C INTO :wa_source_package
ENDEXEC.
if sy-subrc <> 0.
exit.
else.
l_idx = l_idx + 1.
wa_source_package-record = l_idx.
wa_source_package-/bic/nfresta =
wa_source_package-/bic/nfresta / l_day_count.
append wa_source_package to SOURCE_PACKAGE.
endif.
enddo.
EXEC SQL.
CLOSE C
ENDEXEC.
*-----------------------------------------------------------------------
Комментариев нет:
Отправить комментарий