function znf_get_rest.
*"----------------------------------------------------------------------
*"*"Локальный интерфейс:
*" IMPORTING
*" REFERENCE(NCACC) TYPE /BIC/OINCACC
*" REFERENCE(CALDAY) TYPE DATS
*" EXPORTING
*" REFERENCE(NCORG) TYPE /BIC/OINCORG
*" REFERENCE(NCBISELEM) TYPE /BIC/OINCBISELEM
*" REFERENCE(NCCOSTCFU) TYPE /BIC/OINCCOSTCFU
*" REFERENCE(NCSUBD) TYPE /BIC/OINCSUBD
*" REFERENCE(NCPRODUCT) TYPE /BIC/OINCPRODUCT
*" REFERENCE(NCPARTY) TYPE /BIC/OINCPARTY
*" REFERENCE(NCDEAL) TYPE /BIC/OINCDEAL
*" REFERENCE(UPRDT) TYPE DATS
*"----------------------------------------------------------------------
data: l_d1 type d,
l_d2 type d ,
l_calday type d,
l_ncacc type /bic/oincacc ,
l_rec type trest .
" Инициализация временной таблицы
if f_rest <> 'X' .
l_d2 = calday .
l_d1 = l_d2 .
l_d1+6(2) = '01' .
l_d1 = l_d1 - 1 .
EXEC SQL.
OPEN C FOR
select t1.CALDAY,
t1."/BIC/NCACC",
t1."/BIC/NCORG",
t1."/BIC/NCBISELEM",
t1."/BIC/NCCOSTCFU",
t1."/BIC/NCSUBD",
t1."/BIC/NCPRODUCT",
t1."/BIC/NCPARTY",
t1."/BIC/NCDEAL"
from sapsr3."/BIC/ANORKORST00" t1 inner join
(select "/BIC/NCACC" as NCACC, max(CALDAY) as CALDAY
from sapsr3."/BIC/ANORKORST00"
where CALDAY between :l_d1 and :l_d2
group by "/BIC/NCACC"
) t2 on t1.CALDAY = t2.CALDAY and t1."/BIC/NCACC" = t2.NCACC
where t1.CALDAY between :l_d1 and :l_d2
order by t1."/BIC/NCACC"
ENDEXEC.
do.
EXEC SQL.
FETCH NEXT C INTO
:l_calday,
:l_ncacc,
:NCORG,
:NCBISELEM,
:NCCOSTCFU,
:NCSUBD,
:NCPRODUCT,
:NCPARTY,
:NCDEAL
ENDEXEC.
if sy-subrc <> 0.
exit.
else .
clear l_rec .
l_rec-calday = l_calday .
l_rec-ncacc = l_ncacc .
l_rec-ncorg = ncorg .
l_rec-ncbiselem = ncbiselem .
l_rec-nccostcfu = nccostcfu .
l_rec-ncsubd = ncsubd .
l_rec-ncproduct = ncproduct .
l_rec-ncparty = ncparty .
l_rec-ncdeal = ncdeal .
append l_rec to table_rest .
endif.
enddo.
EXEC SQL.
CLOSE C
ENDEXEC.
f_rest = 'X' .
endif .
clear ncorg .
clear ncbiselem .
clear nccostcfu .
clear ncsubd .
clear ncproduct .
clear ncparty .
clear ncdeal .
clear uprdt .
loop at table_rest into l_rec
where ncacc = ncacc .
ncorg = l_rec-ncorg .
ncbiselem = l_rec-ncbiselem .
nccostcfu = l_rec-nccostcfu .
ncsubd = l_rec-ncsubd .
ncproduct = l_rec-ncproduct .
ncparty = l_rec-ncparty .
ncdeal = l_rec-ncdeal .
uprdt = l_rec-calday .
exit .
endloop .
endfunction.
*"----------------------------------------------------------------------
*"*"Локальный интерфейс:
*" IMPORTING
*" REFERENCE(NCACC) TYPE /BIC/OINCACC
*" REFERENCE(CALDAY) TYPE DATS
*" EXPORTING
*" REFERENCE(NCORG) TYPE /BIC/OINCORG
*" REFERENCE(NCBISELEM) TYPE /BIC/OINCBISELEM
*" REFERENCE(NCCOSTCFU) TYPE /BIC/OINCCOSTCFU
*" REFERENCE(NCSUBD) TYPE /BIC/OINCSUBD
*" REFERENCE(NCPRODUCT) TYPE /BIC/OINCPRODUCT
*" REFERENCE(NCPARTY) TYPE /BIC/OINCPARTY
*" REFERENCE(NCDEAL) TYPE /BIC/OINCDEAL
*" REFERENCE(UPRDT) TYPE DATS
*"----------------------------------------------------------------------
data: l_d1 type d,
l_d2 type d ,
l_calday type d,
l_ncacc type /bic/oincacc ,
l_rec type trest .
" Инициализация временной таблицы
if f_rest <> 'X' .
l_d2 = calday .
l_d1 = l_d2 .
l_d1+6(2) = '01' .
l_d1 = l_d1 - 1 .
EXEC SQL.
OPEN C FOR
select t1.CALDAY,
t1."/BIC/NCACC",
t1."/BIC/NCORG",
t1."/BIC/NCBISELEM",
t1."/BIC/NCCOSTCFU",
t1."/BIC/NCSUBD",
t1."/BIC/NCPRODUCT",
t1."/BIC/NCPARTY",
t1."/BIC/NCDEAL"
from sapsr3."/BIC/ANORKORST00" t1 inner join
(select "/BIC/NCACC" as NCACC, max(CALDAY) as CALDAY
from sapsr3."/BIC/ANORKORST00"
where CALDAY between :l_d1 and :l_d2
group by "/BIC/NCACC"
) t2 on t1.CALDAY = t2.CALDAY and t1."/BIC/NCACC" = t2.NCACC
where t1.CALDAY between :l_d1 and :l_d2
order by t1."/BIC/NCACC"
ENDEXEC.
do.
EXEC SQL.
FETCH NEXT C INTO
:l_calday,
:l_ncacc,
:NCORG,
:NCBISELEM,
:NCCOSTCFU,
:NCSUBD,
:NCPRODUCT,
:NCPARTY,
:NCDEAL
ENDEXEC.
if sy-subrc <> 0.
exit.
else .
clear l_rec .
l_rec-calday = l_calday .
l_rec-ncacc = l_ncacc .
l_rec-ncorg = ncorg .
l_rec-ncbiselem = ncbiselem .
l_rec-nccostcfu = nccostcfu .
l_rec-ncsubd = ncsubd .
l_rec-ncproduct = ncproduct .
l_rec-ncparty = ncparty .
l_rec-ncdeal = ncdeal .
append l_rec to table_rest .
endif.
enddo.
EXEC SQL.
CLOSE C
ENDEXEC.
f_rest = 'X' .
endif .
clear ncorg .
clear ncbiselem .
clear nccostcfu .
clear ncsubd .
clear ncproduct .
clear ncparty .
clear ncdeal .
clear uprdt .
loop at table_rest into l_rec
where ncacc = ncacc .
ncorg = l_rec-ncorg .
ncbiselem = l_rec-ncbiselem .
nccostcfu = l_rec-nccostcfu .
ncsubd = l_rec-ncsubd .
ncproduct = l_rec-ncproduct .
ncparty = l_rec-ncparty .
ncdeal = l_rec-ncdeal .
uprdt = l_rec-calday .
exit .
endloop .
endfunction.
Комментариев нет:
Отправить комментарий