Vous êtes sur la page 1sur 14

Old FM :-

FUNCTION ***get_fr_prperiod .
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_REQUNR) TYPE SRSC_S_IF_SIMPLE-REQUNR
*" VALUE(I_DSOURCE) TYPE SRSC_S_IF_SIMPLE-DSOURCE OPTIONAL
*" VALUE(I_MAXSIZE) TYPE SRSC_S_IF_SIMPLE-MAXSIZE OPTIONAL
*" VALUE(I_INITFLAG) TYPE SRSC_S_IF_SIMPLE-INITFLAG OPTIONAL
*" VALUE(I_READ_ONLY) TYPE SRSC_S_IF_SIMPLE-READONLY OPTIONAL
*" TABLES
*" I_T_SELECT TYPE SRSC_S_IF_SIMPLE-T_SELECT OPTIONAL
*" I_T_FIELDS TYPE SRSC_S_IF_SIMPLE-T_FIELDS OPTIONAL
*" E_T_DATA STRUCTURE ZST_BI_FR_PRPERIOD OPTIONAL
*" EXCEPTIONS
*" NO_MORE_DATA
*" ERROR_PASSED_TO_MESS_HANDLER
*"----------------------------------------------------------------------

*---------------------------------------------------------------------*
* DataSources
* TABLES: zcommvtbfha. "Commodity Transaction
TYPES: BEGIN OF ty_con_header,
contract_no TYPE zfr_con_header-contract_no,
vessel TYPE zfr_con_header-vessel,
END OF ty_con_header.
*Types for Contract Header
TYPES: BEGIN OF t_vyg_hdr,
vyg_no TYPE zfr_vyg_hdr-vyg_no,
END OF t_vyg_hdr.
*types for Header Data (Voyage)
DATA: it_con_header TYPE HASHED TABLE OF ty_con_header WITH UNIQUE KEY
contract_no WITH HEADER LINE.
*internal table for Contract Header
DATA: it_prper TYPE STANDARD TABLE OF ty_prper.
* internal table for BW interface pricing period
DATA: it_vyg_cargo TYPE STANDARD TABLE OF ty_vyg_cargo WITH HEADER LINE.
*internal table for Cargo (Voyage)
DATA: it_doc_status TYPE STANDARD TABLE OF ty_doc_status WITH HEADER LINE.
*internal table for Document statuses
DATA: it_doc_prtnr TYPE STANDARD TABLE OF ty_doc_prtnr WITH HEADER LINE.
*internal table for Document Partners
FIELD-SYMBOLS: <fs_es> TYPE ty_prper,
<fs_vyg> TYPE ty_vyg_cargo.
* CONSTANTS: c_null TYPE zfr_doc_status-item_no VALUE '000000'.
* Auxiliary Selection criteria structure
DATA: l_s_select TYPE srsc_s_select.
* Maximum number of lines for DB table
STATICS: s_s_if TYPE srsc_s_if_simple,
* counter
s_counter_datapakid TYPE sy-tabix,
x_nr_lines TYPE rsaapi_if-maxsize,
x_ln TYPE i,
* cursor
s_cursor TYPE cursor,
* itab
e_t_2_data TYPE zst_bi_fr_prperiod OCCURS 0.
* Select ranges
* These fields have been marked as 'selection fields' in the DataSource.
RANGES: r_contract_no FOR zfr_contract_md-contract_no, "Contract number
r_changed_on FOR zfr_contract_md-changed_on. "timstamp for delta
calculation
* Initialization mode (first call by SAPI) or data transfer mode
* (following calls) ?
IF i_initflag = sbiwa_c_flag_on.
************************************************************************
* Initialization: check input parameters
* buffer input parameters
* prepare data selection
************************************************************************
* Check DataSource validity
CASE i_dsource.
WHEN zcl_constants=>c_char26_fr_prperiod1_tran.
WHEN OTHERS.
IF 1 = 2. MESSAGE e009(r3). ENDIF.
* this is a typical log call. Please write every error message like this
log_write zcl_constants=>c_msgty_e "message type
zcl_constants=>c_symsgid_r3 "message class
zcl_constants=>c_wdr_text_key_009 "message
number
i_dsource "message variable 1
zcl_constants=>c_char1_space. "message
variable 2
RAISE error_passed_to_mess_handler.
ENDCASE.
*
APPEND LINES OF i_t_select TO s_s_if-t_select.
* Fill parameter buffer for data extraction calls
s_s_if-requnr = i_requnr.
s_s_if-dsource = i_dsource.
s_s_if-maxsize = i_maxsize.
* Fill field list table for an optimized select statement
* (in case that there is no 1:1 relation between InfoSource fields
* and database table fields this may be far from beeing trivial)
APPEND LINES OF i_t_fields TO s_s_if-t_fields.
ELSE. "Initialization mode or data extraction ?
************************************************************************
* Select data
************************************************************************
IF s_counter_datapakid = 0.
* Fill range tables BW will only pass down simple selection criteria
* of the type SIGN = 'I' and OPTION = 'EQ' or OPTION = 'BT'.
LOOP AT s_s_if-t_select INTO l_s_select WHERE fieldnm =
zcl_constants=>c_char12_contract_no.
MOVE-CORRESPONDING l_s_select TO r_contract_no.
APPEND r_contract_no.
CLEAR r_contract_no.
ENDLOOP.
*
LOOP AT s_s_if-t_select INTO l_s_select WHERE fieldnm =
zcl_constants=>c_char10_changed_on.
MOVE-CORRESPONDING l_s_select TO r_changed_on.
APPEND r_changed_on.
CLEAR r_changed_on.
ENDLOOP.
* search the contracts that have changed since last load

SELECT contract_no vessel


FROM zfr_con_header INTO TABLE it_con_header
WHERE changed_on IN r_changed_on
AND contract_no IN r_contract_no.
* extract all the contracts
IF NOT ( it_con_header[] IS INITIAL ).
SELECT *
FROM zfr_con_prperiod INTO CORRESPONDING FIELDS OF TABLE it_prper
FOR ALL ENTRIES IN it_con_header
WHERE contract_no = it_con_header-contract_no.
ENDIF.
* get statuses for pricing periods
SELECT *
INTO CORRESPONDING FIELDS OF TABLE it_doc_status
FROM zfr_doc_status
FOR ALL ENTRIES IN it_con_header
WHERE doc_category = zcl_constants=>c_zfr_de_document_category_c
AND document_no = it_con_header-contract_no
AND item_no NE 0
AND ( status_type = zcl_constants=>c_zfr_de_status_type_pp
OR status_type = zcl_constants=>c_zfr_de_status_type_cl ) .
* prepare internal table for partner functions
IF NOT ( it_con_header[] IS INITIAL ).
SELECT doc_category document_no item_no parvw parza partner
INTO CORRESPONDING FIELDS OF TABLE it_doc_prtnr
FROM zfr_doc_prtnr
FOR ALL ENTRIES IN it_con_header
WHERE doc_category = zcl_constants=>c_zfr_de_document_category_c
AND document_no = it_con_header-contract_no
AND ( parvw = zcl_constants=>c_parvw_bc
OR parvw = zcl_constants=>c_parvw_bo
OR parvw = zcl_constants=>c_parvw_ag
OR parvw = zcl_constants=>c_parvw_lf ).
ENDIF.
* loop at collected data and fill remaining fields
LOOP AT it_prper ASSIGNING <fs_es>.
READ TABLE it_con_header WITH KEY contract_no = <fs_es>-contract_no.
IF sy-subrc = 0.
<fs_es>-vessel = it_con_header-vessel.
ENDIF.
* Status
READ TABLE it_doc_status WITH KEY document_no = <fs_es>-contract_no
item_no = <fs_es>-period_id
sub_item_no = <fs_es>-item_no
status_type =
zcl_constants=>c_zfr_de_status_type_pp.
IF sy-subrc = 0.
<fs_es>-frstatpp = it_doc_status-status.
ENDIF.
*
READ TABLE it_doc_status WITH KEY document_no = <fs_es>-contract_no
item_no = <fs_es>-period_id
sub_item_no = space
status_type =
zcl_constants=>c_zfr_de_status_type_cl.
IF sy-subrc = 0.
<fs_es>-frstatcl = it_doc_status-status.
ENDIF.
* partner functions
LOOP AT it_doc_prtnr WHERE doc_category =
zcl_constants=>c_zfr_de_document_category_c
AND document_no = <fs_es>-contract_no.
CASE it_doc_prtnr-parvw.
WHEN zcl_constants=>c_parvw_bo.
<fs_es>-broker_ow = it_doc_prtnr-partner.
WHEN zcl_constants=>c_parvw_bc.
<fs_es>-broker_ch = it_doc_prtnr-partner.
WHEN zcl_constants=>c_parvw_lf.
<fs_es>-vendor = it_doc_prtnr-partner.
WHEN zcl_constants=>c_parvw_ag.
<fs_es>-customer = it_doc_prtnr-partner.
ENDCASE.
ENDLOOP.
*
APPEND <fs_es> TO e_t_data.
ENDLOOP.
*
e_t_2_data[] = e_t_data[].
CLEAR e_t_data. REFRESH e_t_data.
*
s_counter_datapakid = s_counter_datapakid + 1.
*
ENDIF.
************************************************************************
* Transfer data
************************************************************************
* Determine number of lines to transfer.
*
DESCRIBE TABLE e_t_2_data LINES x_nr_lines.
*
IF s_s_if-maxsize EQ space.
s_s_if-maxsize = 10000.
ENDIF.
*
IF x_nr_lines NE 0.
IF x_nr_lines GT s_s_if-maxsize.
x_ln = s_s_if-maxsize.
ELSE.
x_ln = x_nr_lines.
ENDIF.
* transfer data to data package and delete it from the buffer
APPEND LINES OF e_t_2_data FROM 1 TO x_ln TO e_t_data.
DELETE e_t_2_data FROM 1 TO x_ln.
ELSE.
RAISE no_more_data.
ENDIF.
*
ENDIF. "Initialization mode or data extraction ?
*
ENDFUNCTION.

New FM :-

FUNCTION ****get_fr_prperiod_new .
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_REQUNR) TYPE SRSC_S_IF_SIMPLE-REQUNR
*" VALUE(I_DSOURCE) TYPE SRSC_S_IF_SIMPLE-DSOURCE OPTIONAL
*" VALUE(I_MAXSIZE) TYPE SRSC_S_IF_SIMPLE-MAXSIZE OPTIONAL
*" VALUE(I_INITFLAG) TYPE SRSC_S_IF_SIMPLE-INITFLAG OPTIONAL
*" VALUE(I_READ_ONLY) TYPE SRSC_S_IF_SIMPLE-READONLY OPTIONAL
*" TABLES
*" I_T_SELECT TYPE SRSC_S_IF_SIMPLE-T_SELECT OPTIONAL
*" I_T_FIELDS TYPE SRSC_S_IF_SIMPLE-T_FIELDS OPTIONAL
*" E_T_DATA STRUCTURE ZST_BI_FR_PRPERIOD OPTIONAL
*" EXCEPTIONS
*" NO_MORE_DATA
*" ERROR_PASSED_TO_MESS_HANDLER
*"----------------------------------------------------------------------

*CONSTANTS: c_null LIKE zfr_doc_status-item_no VALUE '000000',


* c_delt LIKE zfr_doc_status-status VALUE 'DLT'.
TYPES: BEGIN OF ty_con_cargo.
INCLUDE STRUCTURE zst_bi_fr_cargo.
TYPES: END OF ty_con_cargo.
*types for BW Extract strcuture Contract Item
TYPES: BEGIN OF t_con_per.
INCLUDE STRUCTURE zbwfr_conperiod.
TYPES: END OF t_con_per.
*types for BW interface contract periods
TYPES: BEGIN OF ty_prper.
INCLUDE STRUCTURE zst_bi_fr_prperiod.
TYPES: END OF ty_prper.
* types for BW interface pricing period
TYPES:
BEGIN OF ty_vyg_cargo,
ref_doc_no TYPE zfr_vyg_cargo-ref_doc_no,
ref_item_no TYPE zfr_vyg_cargo-ref_item_no,
vyg_no TYPE zfr_vyg_cargo-vyg_no,
vyg_itm TYPE zfr_vyg_cargo-item_no,
est_qty TYPE zfr_vyg_cargo-est_qty,
est_qty_uom TYPE zfr_vyg_cargo-est_qty_uom,
bol_qty TYPE zfr_vyg_cargo-bol_qty,
bol_qty_uom TYPE zfr_vyg_cargo-bol_qty_uom,
outturn_qty TYPE zfr_vyg_cargo-outturn_qty,
outturn_qty_uom TYPE zfr_vyg_cargo-outturn_qty_uom,
master_dec_qty TYPE zfr_vyg_cargo-master_dec_qty,
master_qty_uom TYPE zfr_vyg_cargo-master_qty_uom,
bol_date TYPE zfr_vyg_cargo-bol_date,
bolnr TYPE zfr_vyg_cargo-bolnr,
swfact TYPE zfr_vyg_cargo-swfact,
schd_no TYPE zfr_vyg_hdr-schd_no,
frstatd1 TYPE zst_bi_fr_cargo-frstatd1,
frstatvidi TYPE zst_bi_fr_cargo-frstatvidi,
vessel TYPE zfr_vyg_hdr-vessel,
l_port_call TYPE zfr_vyg_cargo-l_port_call,
d_port_call TYPE zfr_vyg_cargo-d_port_call,
END OF ty_vyg_cargo.
*types for Cargo (Voyage)
TYPES:
BEGIN OF ty_doc_prtnr,
doc_category TYPE zfr_doc_prtnr-doc_category,
document_no TYPE zfr_doc_prtnr-document_no,
item_no TYPE zfr_doc_prtnr-item_no,
parvw TYPE zfr_doc_prtnr-parvw,
parza TYPE zfr_doc_prtnr-parza,
partner TYPE zfr_doc_prtnr-partner,
END OF ty_doc_prtnr.
*types for Document Partners
TYPES:
BEGIN OF ty_doc_status,
doc_category TYPE zfr_doc_status-doc_category,
document_no TYPE zfr_doc_status-document_no,
item_no TYPE zfr_doc_status-item_no,
sub_item_no TYPE zfr_doc_status-sub_item_no,
status_type TYPE zfr_doc_status-status_type,
status TYPE zfr_doc_status-status,
END OF ty_doc_status.
*types for Document statuses
TYPES:
BEGIN OF ty_schedule,
* ref_doc_cat LIKE zfr_schedule-ref_doc_cat,
ref_doc_no TYPE zfr_schedule-ref_doc_no,
* ref_doc_item_no LIKE zfr_schedule-ref_doc_item_no,
portnr TYPE zfr_schedule-portnr,
call_port TYPE zfr_schedule-call_port,
schd_no TYPE zfr_schedule-schd_no,
item_no TYPE zfr_schedule-item_no,
END OF ty_schedule.
* types for Schedule Data

TYPES:
BEGIN OF ty_doc_flow.
INCLUDE STRUCTURE zfr_doc_flow.
TYPES : END OF ty_doc_flow.
* types for Document Flow Data
*****************************************************************
* TABLES: zcommvtbfha. "Commodity Transaction
TYPES: BEGIN OF ty_con_header,
contract_no TYPE zfr_con_header-contract_no,
vessel TYPE zfr_con_header-vessel,
END OF ty_con_header.
*Types for Contract Header
TYPES: BEGIN OF t_vyg_hdr,
vyg_no TYPE zfr_vyg_hdr-vyg_no,
END OF t_vyg_hdr.
DATA : get_obj TYPE REF TO zap_cl_bi_get_fr_prperiod.
CREATE OBJECT get_obj.
*types for Header Data (Voyage)
* DATA: it_con_header TYPE HASHED TABLE OF ty_con_header WITH UNIQUE KEY
contract_no WITH HEADER LINE.
DATA: it_con_header TYPE TABLE OF ty_con_header.
*internal table for Contract Header
* DATA: it_prper TYPE STANDARD TABLE OF ty_prper.
** internal table for BW interface pricing period
* DATA: it_vyg_cargo TYPE STANDARD TABLE OF ty_vyg_cargo WITH HEADER LINE.
**internal table for Cargo (Voyage)
* DATA: it_doc_status TYPE STANDARD TABLE OF ty_doc_status WITH HEADER LINE.
**internal table for Document statuses
* DATA: it_doc_prtnr TYPE STANDARD TABLE OF ty_doc_prtnr WITH HEADER LINE.
**internal table for Document Partners
FIELD-SYMBOLS: <fs_es> TYPE ty_prper,
<fs_vyg> TYPE ty_vyg_cargo.
* CONSTANTS: c_null TYPE zfr_doc_status-item_no VALUE '000000'.
* Auxiliary Selection criteria structure
DATA: l_s_select TYPE srsc_s_select.
* Maximum number of lines for DB table
STATICS: s_s_if TYPE srsc_s_if_simple,
* counter
s_counter_datapakid TYPE sy-tabix,
x_nr_lines TYPE rsaapi_if-maxsize,
x_ln TYPE i,
* cursor
s_cursor TYPE cursor,
* itab
e_t_2_data TYPE zst_bi_fr_prperiod OCCURS 0.
* Select ranges
* These fields have been marked as 'selection fields' in the DataSource.
RANGES: r_contract_no FOR zfr_contract_md-contract_no, "Contract number
r_changed_on FOR zfr_contract_md-changed_on. "timstamp for delta
calculation
* Initialization mode (first call by SAPI) or data transfer mode
* (following calls) ?
IF i_initflag = sbiwa_c_flag_on.
************************************************************************
* Initialization: check input parameters
* buffer input parameters
* prepare data selection
************************************************************************
* Check DataSource validity
CASE i_dsource.
WHEN DS NAME.
WHEN OTHERS.
IF 1 = 2. MESSAGE e009(r3). ENDIF.
* this is a typical log call. Please write every error message like this
log_write zcl_constants=>c_msgty_e "message type
zcl_constants=>c_symsgid_r3 "message class
zcl_constants=>c_wdr_text_key_009 "message
number
i_dsource "message variable 1
zcl_constants=>c_char1_space. "message
variable 2
RAISE error_passed_to_mess_handler.
ENDCASE.
*
APPEND LINES OF i_t_select TO s_s_if-t_select.
* Fill parameter buffer for data extraction calls
s_s_if-requnr = i_requnr.
s_s_if-dsource = i_dsource.
s_s_if-maxsize = i_maxsize.
* Fill field list table for an optimized select statement
* (in case that there is no 1:1 relation between InfoSource fields
* and database table fields this may be far from beeing trivial)
APPEND LINES OF i_t_fields TO s_s_if-t_fields.
ELSE. "Initialization mode or data extraction ?
************************************************************************
* Select data
************************************************************************
IF s_counter_datapakid = 0.
* Fill range tables BW will only pass down simple selection criteria
* of the type SIGN = 'I' and OPTION = 'EQ' or OPTION = 'BT'.
LOOP AT s_s_if-t_select INTO l_s_select WHERE fieldnm =
zcl_constants=>c_char12_contract_no.
MOVE-CORRESPONDING l_s_select TO r_contract_no.
APPEND r_contract_no.
CLEAR r_contract_no.
ENDLOOP.
*
LOOP AT s_s_if-t_select INTO l_s_select WHERE fieldnm =
zcl_constants=>c_char10_changed_on.
MOVE-CORRESPONDING l_s_select TO r_changed_on.
APPEND r_changed_on.
CLEAR r_changed_on.
ENDLOOP.
* search the contracts that have changed since last load

SELECT DISTINCT contract_no vessel


FROM zfr_con_header INTO TABLE it_con_header
WHERE changed_on IN r_changed_on
AND contract_no IN r_contract_no.

CALL METHOD get_obj->extract_data


EXPORTING
it_con_header = it_con_header
gc_doc_category = zcl_constants=>c_zfr_de_document_category_c
gc_stat_type_1 = zcl_constants=>c_zfr_de_status_type_pp
gc_stat_type_2 = zcl_constants=>c_zfr_de_status_type_cl
gc_parvw_bc = zcl_constants=>c_parvw_bc
gc_parvw_bo = zcl_constants=>c_parvw_bo
gc_parvw_ag = zcl_constants=>c_parvw_ag
gc_parvw_lf = zcl_constants=>c_parvw_lf
IMPORTING
it_final = e_t_data[].

DELETE ADJACENT DUPLICATES FROM e_t_data[] COMPARING contract_no


item_no.

e_t_2_data[] = e_t_data[].
CLEAR e_t_data. REFRESH e_t_data.
*
s_counter_datapakid = s_counter_datapakid + 1.
*
ENDIF.
************************************************************************
* Transfer data
************************************************************************
* Determine number of lines to transfer.
*
DESCRIBE TABLE e_t_2_data LINES x_nr_lines.
*
IF s_s_if-maxsize EQ space.
s_s_if-maxsize = 10000.
ENDIF.
*
IF x_nr_lines NE 0.
IF x_nr_lines GT s_s_if-maxsize.
x_ln = s_s_if-maxsize.
ELSE.
x_ln = x_nr_lines.
ENDIF.
* transfer data to data package and delete it from the buffer
APPEND LINES OF e_t_2_data FROM 1 TO x_ln TO e_t_data.
DELETE e_t_2_data FROM 1 TO x_ln.
ELSE.
RAISE no_more_data.
ENDIF.
*
ENDIF. "Initialization mode or data extraction ?
*
ENDFUNCTION.

AMDP
CLASS *****_get_fr_prperiod DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_amdp_marker_hdb. "AMDP marker Interface
TYPES: BEGIN OF ty_con_header,
contract_no TYPE zfr_con_header-contract_no,
vessel TYPE zfr_con_header-vessel,
END OF ty_con_header,
tt_con_header TYPE TABLE OF ty_con_header.
*Types for Contract Header
TYPES: BEGIN OF t_vyg_hdr,
vyg_no TYPE zfr_vyg_hdr-vyg_no,
END OF t_vyg_hdr.
TYPES:
BEGIN OF ty_doc_status,
doc_category TYPE zfr_doc_status-doc_category,
document_no TYPE zfr_doc_status-document_no,
item_no TYPE zfr_doc_status-item_no,
sub_item_no TYPE zfr_doc_status-sub_item_no,
status_type TYPE zfr_doc_status-status_type,
* status TYPE zfr_doc_status-status,
frstatpp TYPE zfr_doc_status-status,
frstatcl TYPE zfr_doc_status-status,
END OF ty_doc_status,
tt_doc_stat TYPE TABLE OF ty_doc_status.
TYPES:
BEGIN OF ty_doc_prtnr,
doc_category TYPE zfr_doc_prtnr-doc_category,
document_no TYPE zfr_doc_prtnr-document_no,
item_no TYPE zfr_doc_prtnr-item_no,
broker_ch TYPE zfr_doc_prtnr-parvw,
broker_ow TYPE zfr_doc_prtnr-parvw,
vendor TYPE zfr_doc_prtnr-parvw,
customer TYPE zfr_doc_prtnr-parvw,
parza TYPE zfr_doc_prtnr-parza,
partner TYPE zfr_doc_prtnr-partner,
END OF ty_doc_prtnr,
tt_doc_prtnr TYPE TABLE OF ty_doc_prtnr.
TYPES:
BEGIN OF ty_prper,
contract_no TYPE zfr_con_prperiod-contract_no,
item_no TYPE zfr_con_prperiod-item_no,
period_id TYPE zfr_con_prperiod-period_id,
item_cat TYPE zfr_con_prperiod-item_cat,
from_period TYPE zfr_con_prperiod-from_period,
to_period TYPE zfr_con_prperiod-to_period,
tzone TYPE zfr_con_prperiod-tzone,
for_duration TYPE zfr_con_prperiod-for_duration,
for_duration_uom TYPE zfr_con_prperiod-for_duration_uom,
werks TYPE zfr_con_prperiod-werks,
comments TYPE zfr_con_prperiod-comments,
baltic_e_perc TYPE zfr_con_prperiod-baltic_e_perc,
market_rate TYPE zfr_con_prperiod-market_rate,
market_rate_cuky TYPE zfr_con_prperiod-market_rate_cuky,
curve TYPE zfr_con_prperiod-curve,
END OF ty_prper,
tt_prper TYPE TABLE OF ty_prper.
DATA: l_s_select TYPE srsc_s_select.
* Maximum number of lines for DB table
DATA: s_s_if TYPE srsc_s_if_simple,
* counter
s_counter_datapakid TYPE sy-tabix,
x_nr_lines TYPE rsaapi_if-maxsize,
x_ln TYPE i,
s_cursor TYPE cursor,
e_t_2_data TYPE zst_bi_fr_prperiod.

TYPES :tt_final TYPE TABLE OF zst_bi_fr_prperiod.

METHODS extract_data
IMPORTING
VALUE(it_con_header) TYPE tt_con_header
VALUE(gc_doc_category) TYPE char2
VALUE(gc_stat_type_1) TYPE char2
VALUE(gc_stat_type_2) TYPE char2
VALUE(gc_parvw_bc) TYPE parvw
VALUE(gc_parvw_bo) TYPE parvw
VALUE(gc_parvw_ag) TYPE parvw
VALUE(gc_parvw_lf) TYPE parvw

EXPORTING
VALUE(it_final) TYPE tt_final.

PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.

CLASS ***** get_fr_prperiod IMPLEMENTATION.

METHOD extract_data BY DATABASE PROCEDURE


FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING zfr_con_prperiod zfr_doc_status zfr_doc_prtnr .

it_prper = SELECT DISTINCT


c.contract_no,
c.item_no,
c.period_id,
c.item_cat,
c.from_period,
c.to_period,
c.tzone,
c.for_duration,
c.for_duration_uom,
c.werks,
c.comments,
c.baltic_e_perc,
c.market_rate,
c.market_rate_cuky,
c.curve
FROM zfr_con_prperiod AS c
INNER JOIN :it_con_header AS a
ON c.contract_no = a.contract_no
ORDER BY c.contract_no;
*where contract_no = (select contract_no from :it_con_header);

it_doc_stat = SELECT DISTINCT


b.doc_category,
b.document_no,
b.item_no,
b.sub_item_no,
b.status_type,
CASE
WHEN b.document_no = c.contract_no
AND b.item_no = c.period_id
AND b.sub_item_no = c.item_no
AND b.status_type = :gc_stat_type_1
THEN b.status
END as frstatpp,
CASE
WHEN b.document_no = c.contract_no
AND b.item_no = c.period_id
AND b.sub_item_no = ' '
AND b.status_type = :gc_stat_type_2
THEN b.status
END AS frstatcl
from zfr_doc_status as b
INNER JOIN :it_prper AS c
on b.document_no = c.contract_no
where b.doc_category = gc_doc_category
and b.item_no <> 0
and (( b.status_type = gc_stat_type_1)
OR (b.status_type = gc_stat_type_2 ))
ORDER BY document_no;

it_doc_prtnr = select DISTINCT


d.doc_category,
d.document_no,
d.item_no,
* d.parvw,
CASE
WHEN d.parvw = :gc_parvw_bc
THEN d.partner
END AS broker_ch,
CASE
WHEN d.parvw = :gc_parvw_bo
THEN d.partner
END AS broker_ow,
CASE
WHEN d.parvw = :gc_parvw_ag
THEN d.partner
END AS vendor,
CASE
WHEN d.parvw = :gc_parvw_lf
THEN d.partner
END AS customer,
d.parza,
d.partner
FROM zfr_doc_prtnr as d
INNER JOIN :it_prper AS c
ON d.document_no = c.contract_no
WHERE d.doc_category = gc_doc_category
*and document_no = (select contract_no from :it_con_header)
AND ( d.parvw = :gc_parvw_bc
or d.parvw = :gc_parvw_bo
or d.parvw = :gc_parvw_ag
or d.parvw = :gc_parvw_lf )
ORDER BY document_no;

it_final = SELECT DISTINCT


vyg_no,
vyg_itm,
contract_no,
item_no,
period_id,
item_cat,
from_period,
to_period,
tzone,
for_duration,
for_duration_uom,
werks,
comments,
baltic_e_perc,
market_rate,
market_rate_cuky,
curve,
changed_on,
vessel,
frstatpp,
frstatcl,
broker_ch,
broker_ow,
vendor,
customer
from(
select distinct
' ' as vyg_no,
' ' as vyg_itm,
c.contract_no,
c.item_no,
c.period_id,
c.item_cat,
c.from_period,
c.to_period,
c.tzone,
c.for_duration,
c.for_duration_uom,
c.werks,
c.comments,
c.baltic_e_perc,
c.market_rate,
c.market_rate_cuky,
c.curve,
' ' AS changed_on,
a.vessel,
b.frstatpp,
b.frstatcl,
d.broker_ch,
d.broker_ow,
d.vendor,
d.customer
FROM :it_prper as c
INNER JOIN :it_con_header as a
on c.contract_no = a.contract_no
INNER JOIN :it_doc_stat as b
on b.document_no = c.contract_no
INNER JOIN :it_doc_prtnr as d
on d.document_no = c.contract_no)
ORDER BY contract_no, item_no;
ENDMETHOD.
ENDCLASS.

Extract Structure
VYG_NO
VYG_ITM
CONTRACT_NO
ITEM_NO
PERIOD_ID
ITEM_CAT
FROM_PERIOD
TO_PERIOD
TZONE
FOR_DURATION
FOR_DURATION_UOM
WERKS
COMMENTS
BALTIC_E_PERC
MARKET_RATE
MARKET_RATE_CUKY
CURVE
CHANGED_ON
VESSEL
FRSTATPP
FRSTATCL
BROKER_CH
BROKER_OW
VENDOR
CUSTOMER