SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

BAPI_PBSRVAPS_GETDETAIL



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SAP Other
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Sat Oct 20, 2007 12:00 pm    Post subject: BAPI_PBSRVAPS_GETDETAIL Reply with quote

Code:

*---------------------------------------------------------------------*
* DATA DECLARATIONS
*---------------------------------------------------------------------*

TABLES: /sapapo/matkey,
/sapapo/matmap,
/bi0/9aplocno.

DATA: vit_selection LIKE bapi10030pbselection
OCCURS 0 WITH HEADER LINE,
vit_selection_temp LIKE bapi10030pbselection
OCCURS 0 WITH HEADER LINE,
vit_group_by LIKE bapi10030pbselection
OCCURS 0 WITH HEADER LINE,
vit_kf_selection LIKE bapi10030keyfigure
OCCURS 0 WITH HEADER LINE,
vit_t_s LIKE bapi10030pbtimeserieso
OCCURS 0 WITH HEADER LINE,
vit_t_s_all LIKE bapi10030pbtimeserieso
OCCURS 0 WITH HEADER LINE,
vit_t_s_i LIKE bapi10030pbtimeseriesitemo
OCCURS 0 WITH HEADER LINE,
vit_t_s_i_all LIKE bapi10030pbtimeseriesitemo
OCCURS 0 WITH HEADER LINE,
vit_c_c LIKE bapi10030pbcharo
OCCURS 0 WITH HEADER LINE,
vit_c_c_all LIKE bapi10030pbcharo
OCCURS 0 WITH HEADER LINE,
vit_return LIKE bapiret2
OCCURS 0 WITH HEADER LINE,
vit_onelocation LIKE s_locations OCCURS 0 WITH HEADER LINE,

p_datfrm TYPE sydatum.

DATA: l_lines TYPE i,
l_cnt TYPE i,
l_exit TYPE c,
l_max_lines TYPE i,
l_max_plus_1 TYPE i,
lit_items LIKE bapi10030pbselection
OCCURS 0 WITH HEADER LINE,
vit_ver_loc LIKE bapi10030pbselection
OCCURS 0 WITH HEADER LINE.

DATA: v_first_day_save LIKE v_first_day.

DATA: v_im3_msg LIKE z0sis_msg.

DATA: lv_errflg(3) .

DATA: BEGIN OF ls_cluster_id,
intf LIKE z022-intf,
ifrun LIKE z022-ifrun,
wstep LIKE z022-wstep,
type(6) TYPE c,
END OF ls_cluster_id.

*DECLARING INTERNAL TABLE THAT WILL HAVE RECORDS CONTAINING INPUT DATA

DATA: BEGIN OF rsparams OCCURS 0.
INCLUDE STRUCTURE rsparams.
DATA END OF rsparams.

IMPORT lv_errflg FROM MEMORY ID c_zpmo0009_memoryid.

FREE MEMORY ID c_zpmo0009_memoryid.

IF lv_errflg = 'ERR'.

EXIT.

ENDIF.

ls_cluster_id-intf = z022-intf.
ls_cluster_id-ifrun = z022-ifrun .
ls_cluster_id-wstep = '0000'.
ls_cluster_id-type = 'UPARAM'.

IMPORT rsparams FROM DATABASE indx(im) ID ls_cluster_id.

READ TABLE rsparams WITH KEY selname = 'P_DATFRM'.

IF sy-subrc = 0.

p_datfrm = rsparams-low.

ELSE.

CLEAR p_datfrm.

ENDIF.

*---------------------------------------------------------------------*
* PROCESSING LOGIC
*---------------------------------------------------------------------*

PERFORM process-selection TABLES
vit_selection
vit_group_by
vit_kf_selection
s_locations
s_material
s_proc
USING
version
z022.

PERFORM combine_locations TABLES
s_locations
it_locations.

vit_loc[] = it_locations[].

SORT vit_loc BY low.

DELETE ADJACENT DUPLICATES FROM vit_loc COMPARING low.

LOOP AT vit_loc INTO vfl_loc.

vit_loc_xref-location = vfl_loc-low.

APPEND vit_loc_xref.

ENDLOOP.

SELECT * FROM /gil/spo_mw_xref INTO vfl_xref
FOR ALL ENTRIES IN vit_loc_xref WHERE
rec_type = c_osb AND
value_01 = vit_loc_xref-location.

APPEND vfl_xref TO vit_xref.

ENDSELECT.

LOOP AT it_locations.

READ TABLE vit_xref INTO vfl_xref WITH KEY
value_01 = it_locations-low.
IF sy-subrc <> 0.

* to update run log

CLEAR v_im3_msg.
v_im3_msg-id = 'Z0'.
v_im3_msg-ty = 'E'.
v_im3_msg-no = '097'.
v_im3_msg-v1 = text-010.
v_im3_msg-v2 = it_locations-low.

CALL FUNCTION 'Z0_WRITE_IFRUN_PROTOCOL'
EXPORTING
msg = v_im3_msg.

DELETE it_locations WHERE low = it_locations-low.

ENDIF.

ENDLOOP.

PERFORM get-extract-dates USING p_1prd p_1week p_day p_datfrm.

v_first_day_save = v_first_day.

LOOP AT it_locations.

v_first_day = v_first_day_save.

PERFORM build-location-materials TABLES
vit_selection
vit_onelocation
s_material
s_proc
s_material_phase
USING
version
it_locations.

IF vit_matloc[] IS INITIAL.
CONTINUE.
ENDIF.

CLEAR vit_selection.
DELETE vit_selection WHERE characteristic_name EQ c_material_char.

REFRESH: vit_data.
CLEAR: vit_data.

LOOP AT vit_matloc.
vit_selection-characteristic_name = c_material_char.
vit_selection-char_val_sign = c_include.
vit_selection-char_val_option = c_equal.
vit_selection-char_val_low = vit_matloc-matnr.

APPEND vit_selection.
CLEAR vit_selection.

vit_data-product = vit_matloc-matnr.

vit_data-location = vit_matloc-locno.

APPEND vit_data.

ENDLOOP.

SELECT matid matnr FROM /sapapo/matkey
INTO TABLE vit_mat_temp
FOR ALL ENTRIES IN vit_data
WHERE matnr = vit_data-product.

SELECT locid locno FROM /sapapo/loc
INTO TABLE vit_loc_temp
FOR ALL ENTRIES IN vit_data
WHERE locno = vit_data-location.

LOOP AT vit_data.

READ TABLE vit_mat_temp
WITH KEY product = vit_data-product.

IF sy-subrc = 0.

vit_data-matid = vit_mat_temp-matid.

MODIFY vit_data TRANSPORTING matid WHERE
product = vit_mat_temp-product.

ENDIF.

READ TABLE vit_loc_temp
WITH KEY locno = vit_data-location.

IF sy-subrc = 0.

vit_data-locid = vit_loc_temp-locid.

MODIFY vit_data TRANSPORTING locid WHERE
location = vit_loc_temp-locno.

ENDIF.

ENDLOOP.

IF s_material[] IS NOT INITIAL.
READ TABLE vit_selection
WITH KEY characteristic_name = c_material_char.
IF sy-subrc <> 0.
CONTINUE.
ENDIF.
ENDIF.

REFRESH: vit_t_s, vit_t_s_i, vit_c_c.

CLEAR: l_lines,
l_exit.

READ TABLE vit_selection WITH KEY characteristic_name = c_version.

IF sy-subrc <> 0.

* this builds Version selection criteria for BAPI_PBSRVAPS_GETDETAIL
vit_selection-characteristic_name = c_version.
vit_selection-char_val_low = version.
vit_selection-char_val_sign = c_include.
vit_selection-char_val_option = c_equal.
vit_selection-char_val_high = ''.
APPEND vit_selection.
CLEAR vit_selection.

ENDIF.

DESCRIBE TABLE vit_selection[] LINES l_lines.

* Reduce count to ignore Version and Location characteristics.
l_lines = l_lines - 2.

CLEAR: l_max_lines,
l_max_plus_1,
l_cnt.

l_max_lines = p_maxrec.
l_max_plus_1 = l_max_lines + 1.

IF l_lines <= l_max_lines OR l_max_lines = 0.


PERFORM get-detail TABLES
vit_selection
vit_group_by
vit_kf_selection
vit_t_s
vit_t_s_i
vit_c_c
vit_return
USING
planningbook
logical_system
business_system_group.

PERFORM livecache-key-fig TABLES
vit_t_s
vit_t_s_i
vit_c_c
vit_output
vit_data
USING
version
p_datfrm.

ELSE.

REFRESH lit_items.
REFRESH vit_ver_loc.

* Save char. for Version and Location
vit_ver_loc[] = vit_selection[].
DELETE vit_ver_loc WHERE characteristic_name EQ c_material_char.

DELETE vit_selection[]
WHERE characteristic_name NE c_material_char.

lit_items[] = vit_selection[].

DO.
l_cnt = l_cnt + 1.

IF l_lines > l_max_lines.
DELETE lit_items[] FROM l_max_plus_1 TO l_lines.
ENDIF.

* Call the BAPI
APPEND LINES OF vit_ver_loc[] TO lit_items[].

REFRESH: vit_t_s, vit_t_s_i, vit_c_c.

PERFORM get-detail TABLES
lit_items
vit_group_by
vit_kf_selection
vit_t_s
vit_t_s_i
vit_c_c
vit_return
USING
planningbook
logical_system
business_system_group.

PERFORM livecache-key-fig TABLES
vit_t_s
vit_t_s_i
vit_c_c
vit_output
vit_data
USING
version
p_datfrm.

IF l_exit = 'X'.
* After processing all records, exit from the loop
EXIT.
ENDIF.

lit_items[] = vit_selection[].
l_lines = l_max_lines * l_cnt.

DELETE lit_items FROM 1 TO l_lines.

DESCRIBE TABLE lit_items LINES l_lines.

IF l_lines <= l_max_lines.
l_exit = 'X'.
ENDIF.
ENDDO.

ENDIF.

PERFORM prepare-output TABLES
vit_output
vit_data
USING
version
p_datfrm.

ENDLOOP.

PERFORM delete_zero_qty TABLES
vit_final_output.

IF vit_final_output[] IS INITIAL.

* to update run log

CLEAR v_im3_msg.
v_im3_msg-id = 'Z0'.
v_im3_msg-ty = 'E'.
v_im3_msg-no = '097'.
v_im3_msg-v1 = text-011.

CALL FUNCTION 'Z0_WRITE_IFRUN_PROTOCOL'
EXPORTING
msg = v_im3_msg.

EXIT.

ENDIF.

PERFORM insert_header TABLES
vit_final_output.

APPEND LINES OF vit_final_output TO extract_rec.

ENDFUNCTION.

*---------------------------------------------------------------------*
* FORM PROCESS-SELECTION *
*---------------------------------------------------------------------*
* Form builds the necessary parameters required for bapi: *
* BAPI_PBSRVAPS_GETDETAIL *
*---------------------------------------------------------------------*
* The following tables are required by the bapi_PBSRVAPS_GETDETAIL *
* --> VIT_SELECTION *
* --> VIT_GROUP_BY *
* --> VIT_KF_SELECTION *
* --> LOCATIONS *
* --> VERSION *
*---------------------------------------------------------------------*
FORM process-selection TABLES
vit_selection STRUCTURE bapi10030pbselection
vit_group_by STRUCTURE bapi10030pbgroupby
vit_kf_selection STRUCTURE bapi10030keyfigure
s_locations STRUCTURE /scf/locnorng_str
s_material STRUCTURE e1bpproductrange
s_proc STRUCTURE /sapapo/beskz_rstr
USING
version
z022.

DATA: BEGIN OF lit_matkey OCCURS 0,
matnr(40),
att01(40),
END OF lit_matkey.

DATA : lit_matnr TYPE TABLE OF /sapapo/matkey-matnr WITH HEADER LINE.

DATA l_message(40).

DATA l_material(40).

DATA:l_tabix LIKE sy-tabix.

* build group by selection criteria for BAPI_PBSRVAPS_GETDETAIL
sy-subrc = 0.
vit_group_by = c_country.
APPEND vit_group_by.
CLEAR vit_group_by.
vit_group_by = c_material_char.
APPEND vit_group_by.
CLEAR vit_group_by.

* Key figure selection for BAPI_PBSRVAPS_GETDETAIL
vit_kf_selection = c_9admdse.
APPEND vit_kf_selection.
CLEAR vit_kf_selection.

vit_kf_selection = c_9admddt.
APPEND vit_kf_selection.
CLEAR vit_kf_selection.

vit_kf_selection = c_9afprod.
APPEND vit_kf_selection.
CLEAR vit_kf_selection.

vit_kf_selection = c_9approd.
APPEND vit_kf_selection.
CLEAR vit_kf_selection.

vit_kf_selection = c_9atship.
APPEND vit_kf_selection.
CLEAR vit_kf_selection.

vit_kf_selection = c_9apship.
APPEND vit_kf_selection.
CLEAR vit_kf_selection.

vit_kf_selection = c_9admdp1.
APPEND vit_kf_selection.
CLEAR vit_kf_selection.

vit_kf_selection = c_9adfcst.
APPEND vit_kf_selection.
CLEAR vit_kf_selection.

vit_kf_selection = c_workdays.
APPEND vit_kf_selection.
CLEAR vit_kf_selection.

* this builds Version selection criteria for BAPI_PBSRVAPS_GETDETAIL
vit_selection-characteristic_name = c_version.
vit_selection-char_val_low = version.
vit_selection-char_val_sign = c_include.
vit_selection-char_val_option = c_equal.
vit_selection-char_val_high = ''.
APPEND vit_selection.
CLEAR vit_selection.

ENDFORM. "PROCESS-SELECTION
*---------------------------------------------------------------------*
* FORM get-extract-dates *
*---------------------------------------------------------------------*
* This form obtains: *
* The last periods last day *
* The current period from todays date. *
* The first day in the current period. *
* The last day in the period. *
* The day of the week 1 = monday 7 = sunday *
* The reports last period, 20 months out (=19th future period) *
*---------------------------------------------------------------------*
FORM get-extract-dates USING p_1prd p_1week p_day p_datfrm.

* Get the current week of the year

DATA: l_week LIKE scal-week,
v_to_day LIKE sy-datum.

DATA: lv_week_temp(10) TYPE c.

DATA: lv_temp1(10) TYPE c,
lv_fract(10) TYPE c,
lv_tot_week(10) TYPE c.

CALL FUNCTION 'DATE_GET_WEEK'
EXPORTING
date = p_datfrm
IMPORTING
week = l_week
EXCEPTIONS
date_invalid = 1
OTHERS = 2.
IF sy-subrc <> 0.
RAISE conv_date_error.
ENDIF.

* Get the date of the first day of the current week.
CALL FUNCTION 'WEEK_GET_FIRST_DAY'
EXPORTING
week = l_week
IMPORTING
date = v_first_day-wk
EXCEPTIONS
week_invalid = 1
OTHERS = 2.
IF sy-subrc <> 0.
RAISE conv_date_error.
ENDIF.

DATA: l_date LIKE sy-datum.
l_date = v_first_day-wk.
v_first_day = l_date.
v_to_day = v_first_day-wk.
v_from_week = l_week.

IF p_1prd IS NOT INITIAL.
* Processing for the to week calculation
* Obtain the current period from todays date
CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
EXPORTING
i_date = p_datfrm
i_periv = c_fiscal-cal
IMPORTING
e_buper = v_period
e_gjahr = v_year
EXCEPTIONS
input_false = 1
t009_notfound = 2
t009b_notfound = 3
OTHERS = 4.
IF sy-subrc <> 0.
RAISE conv_date_error.
ENDIF.

* Save actual period
v_actual_period = v_period.

* Obtain the first day of the current period
CALL FUNCTION 'FIRST_DAY_IN_PERIOD_GET'
EXPORTING
i_gjahr = v_year
i_periv = c_fiscal-cal
i_poper = v_period
IMPORTING
e_date = v_first-day
EXCEPTIONS
input_false = 1
t009_notfound = 2
t009b_notfound = 3
OTHERS = 4.
IF sy-subrc <> 0.
RAISE conv_date_error.
ELSE.
v_first-day-b = v_first-day.
ENDIF.

* Obtain the last day of the current period
CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'
EXPORTING
i_gjahr = v_year
i_periv = c_fiscal-cal
i_poper = v_period
IMPORTING
e_date = v_last-day-end-per
EXCEPTIONS
input_false = 1
t009_notfound = 2
t009b_notfound = 3
OTHERS = 4.
IF sy-subrc <> 0.
RAISE conv_date_error.
ENDIF.

* calculate last day of nth future period that user inputs
DO p_1prd TIMES.

v_last-day-end-per = v_last-day-end-per + 1.

CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
EXPORTING
i_date = v_last-day-end-per
i_periv = c_fiscal-cal
IMPORTING
e_buper = v_future_period
e_gjahr = v_future_year
EXCEPTIONS
input_false = 1
t009_notfound = 2
t009b_notfound = 3
OTHERS = 4.
IF sy-subrc <> 0.
RAISE conv_date_error.
ENDIF.

CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'
EXPORTING
i_gjahr = v_future_year
i_periv = c_fiscal-cal
i_poper = v_future_period
IMPORTING
e_date = v_last-day-end-per
EXCEPTIONS
input_false = 1
t009_notfound = 2
t009b_notfound = 3
OTHERS = 4.

IF sy-subrc <> 0.
RAISE conv_date_error.
ENDIF.

ENDDO.

*Get to week from the last day of last period
CALL FUNCTION 'DATE_GET_WEEK'
EXPORTING
date = v_last-day-end-per
IMPORTING
week = v_to_week
EXCEPTIONS
date_invalid = 1
OTHERS = 2.
IF sy-subrc <> 0.
RAISE conv_date_error.
ENDIF.

ENDIF. "p_1prd

IF p_1week IS NOT INITIAL.

DO p_1week TIMES.
v_to_day = v_to_day + 7.
ENDDO.

*Get to week by calculating the nth week
CALL FUNCTION 'DATE_GET_WEEK'
EXPORTING
date = v_to_day
IMPORTING
week = v_to_week
EXCEPTIONS
date_invalid = 1
OTHERS = 2.
IF sy-subrc <> 0.
RAISE conv_date_error.
ENDIF.

ENDIF.

IF p_day IS NOT INITIAL.

lv_week_temp = p_day / 7.

SPLIT lv_week_temp AT '.' INTO lv_temp1 lv_fract.

IF lv_fract IS NOT INITIAL.

lv_tot_week = lv_temp1 + 1.

ELSE.

lv_tot_week = lv_temp1.

ENDIF.

DO lv_tot_week TIMES.
v_to_day = v_to_day + 7.
ENDDO.

*Get to week by calculating the nth week
CALL FUNCTION 'DATE_GET_WEEK'
EXPORTING
date = v_to_day
IMPORTING
week = v_to_week
EXCEPTIONS
date_invalid = 1
OTHERS = 2.
IF sy-subrc <> 0.
RAISE conv_date_error.
ENDIF.

ENDIF.

ENDFORM. "get-extract-dates

*---------------------------------------------------------------------*
* FORM GET-DETAIL *
*---------------------------------------------------------------------*
* This form executes the bapi: BAPI_PBSRVAPS_GETDETAIL *
* The BAPI extracts data from livecache in the format of the *
* planning book requested. Also the date range is built *
* dynamically using start date specified on the selection screen*
* of the program as the starting point. *
*---------------------------------------------------------------------*
* Parameters for BAPI follow: *
* --> VIT_SELECTION *
* --> VIT_GROUP_BY *
* --> VIT_KF_SELECTION *
* --> VIT_T_S *
* --> VIT_T_S_I *
* --> VIT_C_C *
* --> VIT_RETURN *
* --> PLANNING_BOOK *
* --> LOGICAL_SYSTEM *
* --> BUSINESS_SYSTEM_GROUP *
*---------------------------------------------------------------------*
FORM get-detail
TABLES
lit_items STRUCTURE bapi10030pbselection
vit_group_by STRUCTURE bapi10030pbselection
vit_kf_selection STRUCTURE bapi10030keyfigure
vit_t_s STRUCTURE bapi10030pbtimeserieso
vit_t_s_i STRUCTURE bapi10030pbtimeseriesitemo
vit_c_c STRUCTURE bapi10030pbcharo
vit_return STRUCTURE bapiret2
USING
planning_book
logical_system
business_system_group.

DATA: l_from_week TYPE /sapapo/cdps_eval_date_from,
l_to_week TYPE /sapapo/cdps_eval_date_to.

DATA: lv_mess(220) TYPE c.
DATA: lv_len(4) TYPE c.

DATA: l_im3_msg LIKE z0sis_msg.

CONCATENATE v_from_week+4(2) v_from_week+0(4)
INTO l_from_week.

CONCATENATE v_to_week+4(2) v_to_week+0(4)
INTO l_to_week.

CALL FUNCTION 'BAPI_PBSRVAPS_GETDETAIL'
EXPORTING
planningbook = planning_book
period_type = 'B'
date_from = l_from_week
date_to = l_to_week
logical_system = logical_system
business_system_group = business_system_group
TABLES
selection = lit_items
group_by = vit_group_by
key_figure_selection = vit_kf_selection
time_series = vit_t_s
time_series_item = vit_t_s_i
characteristics_combination = vit_c_c
return = vit_return.

LOOP AT vit_return.

IF vit_return-type = 'E'.

MOVE vit_return-message TO lv_mess.

lv_len = STRLEN( lv_mess ).

IF lv_len <= 110.

CLEAR l_im3_msg.
l_im3_msg-id = 'Z0'.
l_im3_msg-ty = 'E'.
l_im3_msg-no = '097'.
l_im3_msg-v1 = lv_mess+0(50).
l_im3_msg-v2 = lv_mess+50(60).

CALL FUNCTION 'Z0_WRITE_IFRUN_PROTOCOL'
EXPORTING
msg = l_im3_msg.

ELSEIF lv_len > 110 AND lv_len <= 220.

CLEAR l_im3_msg.
l_im3_msg-id = 'Z0'.
l_im3_msg-ty = 'E'.
l_im3_msg-no = '097'.
l_im3_msg-v1 = lv_mess+0(50).
l_im3_msg-v2 = lv_mess+50(60).

CALL FUNCTION 'Z0_WRITE_IFRUN_PROTOCOL'
EXPORTING
msg = l_im3_msg.

* Continue appending message

CLEAR l_im3_msg.
l_im3_msg-id = 'Z0'.
l_im3_msg-ty = 'E'.
l_im3_msg-no = '097'.
l_im3_msg-v3 = lv_mess+110(50).
l_im3_msg-v4 = lv_mess+160(60).

CALL FUNCTION 'Z0_WRITE_IFRUN_PROTOCOL'
EXPORTING
msg = l_im3_msg.

ENDIF.

ENDIF.

ENDLOOP.

ENDFORM. "get-detail

*&--------------------------------------------------------------------*
*& Form BUILD-LOCATION-MATERIALS
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM build-location-materials TABLES
vit_selection STRUCTURE bapi10030pbselection
vit_onelocation STRUCTURE /scf/locnorng_str
s_material STRUCTURE e1bpproductrange
s_proc STRUCTURE /sapapo/beskz_rstr
s_material_phase STRUCTURE /GIL/MATNR_PHASE_RANGE
USING
version
it_locations STRUCTURE it_locations.

data: lv_phase(2) type c.

DELETE vit_selection WHERE characteristic_name EQ '9ALOCNO'.
vit_selection-characteristic_name = '9ALOCNO'.
vit_selection-char_val_sign = it_locations-sign.
vit_selection-char_val_option = it_locations-option.
vit_selection-char_val_low = it_locations-low.
vit_selection-char_val_high = it_locations-high.
APPEND vit_selection.
CLEAR vit_selection.

CLEAR vit_onelocation.
REFRESH vit_onelocation.
APPEND it_locations TO vit_onelocation.

CLEAR: vit_matloc.
REFRESH: vit_matloc.

* Build materials selections.
IF NOT s_material[] IS INITIAL.
v_flag = 'X'.
LOOP AT s_material.
IF NOT s_material-low IS INITIAL.
SHIFT s_material-low RIGHT DELETING TRAILING ' '.
OVERLAY s_material-low WITH
'0000000000000000000000000000000000000000'.
ENDIF.
IF NOT s_material-high IS INITIAL.
SHIFT s_material-high RIGHT DELETING TRAILING ' '.
OVERLAY s_material-high WITH
'0000000000000000000000000000000000000000'.
ENDIF.
MODIFY s_material INDEX sy-tabix.
ENDLOOP.
ENDIF.

IF version = '000'.
* SELECT matnr locno lsuom matid
* FROM /sapapo/v_matloc AS mloc LEFT JOIN /sapapo/matlotsz AS mlot
* ON mloc~lszid = mlot~lszid
* INTO TABLE vit_matloc
* WHERE mloc~matnr IN s_material AND
* mloc~locno IN vit_onelocation AND
* mloc~beskz IN s_proc.

SELECT mloc~matnr locno mloc~matid att01
FROM /sapapo/v_matloc AS mloc INNER JOIN /sapapo/matkey AS mkey
ON mloc~matid = mkey~matid
INTO TABLE vit_matloc
WHERE mloc~matnr IN s_material AND
mloc~locno IN vit_onelocation AND
mloc~beskz IN s_proc.

ELSE.
* SELECT matnr locno lsuom matid
* FROM /sapapo/v_mlsim AS mloc LEFT JOIN /sapapo/matlotsz AS mlot
* ON mloc~lszid = mlot~lszid
* INTO TABLE vit_matloc
* WHERE mloc~matnr IN s_material AND
* mloc~locno IN vit_onelocation AND
* mloc~beskz IN s_proc AND
* mloc~vrsioex = version.

SELECT mloc~matnr locno mloc~matid att01
FROM /sapapo/v_mlsim AS mloc INNER JOIN /sapapo/matkey AS mkey
ON mloc~matid = mkey~matid
INTO TABLE vit_matloc
WHERE mloc~matnr IN s_material AND
mloc~locno IN vit_onelocation AND
mloc~beskz IN s_proc AND
mloc~vrsioex = version.
ENDIF.

loop at vit_matloc.

lv_phase = vit_matloc-phase+8(2).

if lv_phase not in s_material_phase.

delete vit_matloc.

endif.

endloop.

ENDFORM. "BUILD-LOCATION-MATERIALS

*&--------------------------------------------------------------------*
*& Form combine_locations
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->S_LOCATIONStext
* -->IT_LOCATIONStext
*---------------------------------------------------------------------*
FORM combine_locations TABLES
s_locations STRUCTURE /scf/locnorng_str
it_locations STRUCTURE it_locations.

CLEAR it_locations.
LOOP AT s_locations.
it_locations-sign = s_locations-sign.
it_locations-option = s_locations-option.
it_locations-low = s_locations-low.
it_locations-high = s_locations-high.
APPEND it_locations.
CLEAR it_locations.
ENDLOOP.

ENDFORM. "combine_locations

*---------------------------------------------------------------------*
* FORM PREPARE-OUTPUT *
*---------------------------------------------------------------------*
* Form populates the internal table in output format *
*---------------------------------------------------------------------*
* The following tables are required *
* --> vit_t_s *
* --> vit_t_s_i *
* --> vit_c_c. *
*---------------------------------------------------------------------*
FORM prepare-output TABLES
vit_output STRUCTURE vit_output
vit_data STRUCTURE vit_data
USING
version
p_datfrm.

DATA: lit_loc_prod TYPE /sapapo/epegkey_tab.

DATA: lfl_loc_prod LIKE LINE OF lit_loc_prod.

DATA: lit_pegkey TYPE /sapapo/pegkey_tab.

DATA: lfl_pegkey LIKE LINE OF lit_pegkey.

DATA:lit_missing_key TYPE /sapapo/epegkey_tab.

DATA: lfl_missing_key LIKE LINE OF lit_missing_key.

DATA: lit_pegid TYPE /sapapo/pegid_tab.

DATA: lfl_pegid LIKE LINE OF lit_pegid.

DATA: lv_atpcat TYPE /sapapo/atpcat.

DATA: lit_stock TYPE /sapapo/matstock OCCURS 0.

DATA: lfl_stock LIKE LINE OF lit_stock.

DATA: lit_rc TYPE /sapapo/om_stock_rc_tab.

DATA: lfl_rc LIKE LINE OF lit_rc.

DATA: lit_output_inv LIKE vit_output OCCURS 0.

DATA: lfl_output_inv LIKE LINE OF lit_output_inv.

DATA: BEGIN OF vit_char_comb OCCURS 0,
char_comb_id TYPE bapi10030pbcharo-char_comb_id,
location TYPE /sapapo/loc-locno,
product TYPE /sapapo/matkey-matnr,
END OF vit_char_comb.

DATA: BEGIN OF lit_stock_temp OCCURS 0,
pegid TYPE /sapapo/pegid,
stock TYPE /sapapo/stock,
END OF lit_stock_temp.

DATA: BEGIN OF lit_atpcat OCCURS 0,
atpcat TYPE /sapapo/atpcat,
END OF lit_atpcat.

DATA: lv_per TYPE bapi10030pbtimeseriesitemo-period_begin,
lv_per_beg(15) TYPE c.

DATA: lv_value TYPE i.

DATA: lv_inv TYPE i.

DATA: lv_version TYPE /sapapo/vrsioid.

DATA: lv_datefrm TYPE sy-datum.

DATA: lv_temp_date TYPE sy-datum.

DATA: l_im3_msg LIKE z0sis_msg.

REFRESH: lit_loc_prod,
lit_pegkey,
lit_missing_key,
lit_pegid,
lit_stock,
lit_rc.

CLEAR: lfl_loc_prod,
lfl_pegkey,
lfl_missing_key,
lfl_pegid,
lfl_stock,
lfl_rc.

CLEAR: lv_atpcat.

MOVE version TO lv_version.

lv_datefrm = p_datfrm.

LOOP AT vit_data.

lfl_loc_prod-matid = vit_data-matid.

lfl_loc_prod-locid = vit_data-locid.

lfl_loc_prod-simid = version.

APPEND lfl_loc_prod TO lit_loc_prod.

SHIFT vit_data-product LEFT DELETING LEADING '0'.

MODIFY vit_data INDEX sy-tabix
TRANSPORTING product .

ENDLOOP.

REFRESH: lit_missing_key,
lit_pegkey.

CALL FUNCTION '/SAPAPO/DM_MAT_GET_PEGID_MULT'
EXPORTING
it_epegkey = lit_loc_prod
IMPORTING
et_pegkey = lit_pegkey
et_epegkey_missing = lit_missing_key
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc <> 0.

READ TABLE lit_loc_prod INTO lfl_loc_prod INDEX 1.

IF sy-subrc = 0.

READ TABLE vit_data WITH KEY
locid = lfl_loc_prod-locid.

IF sy-subrc = 0.

* to update run log

CLEAR l_im3_msg.
l_im3_msg-id = 'Z0'.
l_im3_msg-ty = 'E'.
l_im3_msg-no = '097'.
l_im3_msg-v1 = text-008.
l_im3_msg-v2 = vit_data-location.

CALL FUNCTION 'Z0_WRITE_IFRUN_PROTOCOL'
EXPORTING
msg = l_im3_msg.

ENDIF.

ENDIF.

ENDIF.

IF lit_missing_key[] IS NOT INITIAL.

LOOP AT lit_missing_key INTO lfl_missing_key.

READ TABLE vit_data WITH KEY
matid = lfl_missing_key-matid
locid = lfl_missing_key-locid .

IF sy-subrc = 0.

* to update run log

CLEAR l_im3_msg.
l_im3_msg-id = 'Z0'.
l_im3_msg-ty = 'E'.
l_im3_msg-no = '097'.
l_im3_msg-v1 = text-015.
CONCATENATE vit_data-location '/' vit_data-product INTO l_im3_msg-v2
.

CALL FUNCTION 'Z0_WRITE_IFRUN_PROTOCOL'
EXPORTING
msg = l_im3_msg.

ENDIF.

ENDLOOP.

ENDIF.

LOOP AT lit_pegkey INTO lfl_pegkey.

lfl_pegid = lfl_pegkey-pegid.
APPEND lfl_pegid TO lit_pegid.

CLEAR lfl_pegid.

READ TABLE vit_data WITH KEY
matid = lfl_pegkey-matid
locid = lfl_pegkey-locid.

IF sy-subrc = 0.

vit_data-pegid = lfl_pegkey-pegid.

MODIFY vit_data TRANSPORTING pegid WHERE
matid = lfl_pegkey-matid AND
locid = lfl_pegkey-locid.
ENDIF.

ENDLOOP.

lit_atpcat-atpcat = c_cc.
APPEND lit_atpcat.
CLEAR lit_atpcat.

lit_atpcat-atpcat = c_ci.
APPEND lit_atpcat.
CLEAR lit_atpcat.

lit_atpcat-atpcat = c_cf.
APPEND lit_atpcat.
CLEAR lit_atpcat.

lit_atpcat-atpcat = c_cs.
APPEND lit_atpcat.
CLEAR lit_atpcat.

LOOP AT lit_atpcat.

lv_atpcat = lit_atpcat-atpcat.

CALL FUNCTION '/SAPAPO/DM_STOCK_GET_BY_PEGID'
EXPORTING
iv_simid = lv_version
it_pegid = lit_pegid
iv_stocktype = '00'
iv_atpcat = lv_atpcat
TABLES
et_stock = lit_stock
et_rc = lit_rc
EXCEPTIONS
lc_connect_failed = 1
lc_appl_error = 2
lc_com_error = 3
no_pegid = 4
OTHERS = 5.
IF sy-subrc <> 0.

READ TABLE lit_pegid INTO lfl_pegid INDEX 1.

IF sy-subrc = 0.

READ TABLE vit_data WITH KEY
pegid = lfl_pegid.
IF sy-subrc = 0.

* to update run log

CLEAR l_im3_msg.
l_im3_msg-id = 'Z0'.
l_im3_msg-ty = 'E'.
l_im3_msg-no = '097'.
l_im3_msg-v1 = text-008.
l_im3_msg-v2 = vit_data-location.

CALL FUNCTION 'Z0_WRITE_IFRUN_PROTOCOL'
EXPORTING
msg = l_im3_msg.

ENDIF.

ENDIF.

ENDIF.

REFRESH lit_stock_temp.

CLEAR lit_stock_temp.

LOOP AT lit_stock INTO lfl_stock.

MOVE-CORRESPONDING lfl_stock TO lit_stock_temp.

COLLECT lit_stock_temp.

ENDLOOP.

LOOP AT vit_data.

CLEAR lfl_output_inv.

CONCATENATE 'SC' lv_datefrm INTO lfl_output_inv-version.

lfl_output_inv-matnr = vit_data-product.

lfl_output_inv-plant = vit_data-location.

lfl_output_inv-uom = 'GU'.

lv_temp_date = lv_datefrm - 1.

lfl_output_inv-period = lv_temp_date.

lfl_output_inv-split = 'D'.

lfl_output_inv-conblkinv = 0.

lfl_output_inv-conunrestinv = 0.

lfl_output_inv-conqltyinsp = 0.

lfl_output_inv-qmrct = 0.

lfl_output_inv-depdem = 0.

lfl_output_inv-distdem = 0.

lfl_output_inv-stdprodfxd = 0.

lfl_output_inv-stdprodpln = 0.

lfl_output_inv-distrectfxd = 0.

lfl_output_inv-distrectpln = 0.

lfl_output_inv-custorders = 0.

lfl_output_inv-custindreq = 0.

lfl_output_inv-affsn = 0.

lfl_output_inv-non_affsn = 0.

lfl_output_inv-stdprice = 0.

lfl_output_inv-currency = 0.

CLEAR lv_inv.

IF lv_atpcat = c_cc.

READ TABLE lit_stock_temp WITH KEY
pegid = vit_data-pegid.
IF sy-subrc = 0.

lv_inv = lit_stock_temp-stock.

lfl_output_inv-unrestinv = lv_inv.

lfl_output_inv-mrp_inv = lv_inv.

APPEND lfl_output_inv TO lit_output_inv.

CLEAR lfl_output_inv.

ELSE.

lfl_output_inv-unrestinv = 0.

lfl_output_inv-mrp_inv = 0.

APPEND lfl_output_inv TO lit_output_inv.

CLEAR lfl_output_inv.

ENDIF.

ENDIF.

IF lv_atpcat = c_ci.

READ TABLE lit_stock_temp WITH KEY
pegid = vit_data-pegid.
IF sy-subrc = 0.

lv_inv = lit_stock_temp-stock.

lfl_output_inv-blockinv = lv_inv.

MODIFY lit_output_inv FROM lfl_output_inv
TRANSPORTING blockinv
WHERE matnr = vit_data-product AND
plant = vit_data-location.
ELSE.

lfl_output_inv-blockinv = 0.

MODIFY lit_output_inv FROM lfl_output_inv
TRANSPORTING blockinv
WHERE matnr = vit_data-product AND
plant = vit_data-location.
ENDIF.

ENDIF.

IF lv_atpcat = c_cf.

READ TABLE lit_stock_temp WITH KEY
pegid = vit_data-pegid.
IF sy-subrc = 0.

lv_inv = lit_stock_temp-stock.

lfl_output_inv-qltyinsp = lv_inv.

MODIFY lit_output_inv FROM lfl_output_inv
TRANSPORTING qltyinsp
WHERE matnr = vit_data-product AND
plant = vit_data-location.
ELSE.

lfl_output_inv-qltyinsp = 0.

MODIFY lit_output_inv FROM lfl_output_inv
TRANSPORTING qltyinsp
WHERE matnr = vit_data-product AND
plant = vit_data-location.
ENDIF.

ENDIF.

IF lv_atpcat = c_cs.

READ TABLE lit_stock_temp WITH KEY
pegid = vit_data-pegid.
IF sy-subrc = 0.

lv_inv = lit_stock_temp-stock.

lfl_output_inv-intransit = lv_inv.

MODIFY lit_output_inv FROM lfl_output_inv
TRANSPORTING intransit
WHERE matnr = vit_data-product AND
plant = vit_data-location.
ELSE.

lfl_output_inv-intransit = 0.

MODIFY lit_output_inv FROM lfl_output_inv
TRANSPORTING intransit
WHERE matnr = vit_data-product AND
plant = vit_data-location.
ENDIF.

ENDIF.

ENDLOOP. " vit_data

ENDLOOP. " lit_atpcat

APPEND LINES OF lit_output_inv TO vit_final_output.

REFRESH lit_output_inv.

APPEND LINES OF vit_output TO vit_final_output.

REFRESH vit_output.

ENDFORM. "PREPARE-OUTPUT

*---------------------------------------------------------------------*
* delete_zero_qty *
*---------------------------------------------------------------------*
* Form deletes records which have all the zero qty *
*---------------------------------------------------------------------*
* The following tables are required *
* --> vit_final_output *
*---------------------------------------------------------------------*

FORM delete_zero_qty TABLES
vit_final_output.

LOOP AT vit_final_output INTO vfl_final_output.

IF vfl_final_output-depdem = 0 AND
vfl_final_output-distdem = 0 AND
vfl_final_output-stdprodfxd = 0 AND
vfl_final_output-stdprodpln = 0 AND
vfl_final_output-distrectfxd = 0 AND
vfl_final_output-distrectpln = 0 AND
vfl_final_output-custorders = 0 AND
vfl_final_output-custindreq = 0 AND
vfl_final_output-unrestinv = 0 AND
vfl_final_output-mrp_inv = 0 AND
vfl_final_output-blockinv = 0 AND
vfl_final_output-qltyinsp = 0 AND
vfl_final_output-intransit = 0.

DELETE TABLE vit_final_output FROM vfl_final_output.

CONTINUE.

ENDIF.

READ TABLE vit_xref INTO vfl_xref WITH KEY
value_01 = vfl_final_output-plant.
IF sy-subrc = 0.

CLEAR vfl_final_output-plant.

vfl_final_output-plant = vfl_xref-value_06.

MODIFY vit_final_output FROM vfl_final_output.

ENDIF.

SHIFT: vfl_final_output-unrestinv RIGHT DELETING TRAILING space.

SHIFT vfl_final_output-blockinv RIGHT DELETING TRAILING space.

SHIFT vfl_final_output-qltyinsp RIGHT DELETING TRAILING space.

SHIFT vfl_final_output-conblkinv RIGHT DELETING TRAILING space.

SHIFT vfl_final_output-intransit RIGHT DELETING TRAILING space.

SHIFT vfl_final_output-mrp_inv RIGHT DELETING TRAILING space.

SHIFT vfl_final_output-conunrestinv RIGHT DELETING TRAILING space.

SHIFT vfl_final_output-conqltyinsp RIGHT DELETING TRAILING space.

SHIFT vfl_final_output-qmrct RIGHT DELETING TRAILING space.

SHIFT vfl_final_output-depdem RIGHT DELETING TRAILING space.

SHIFT vfl_final_output-distdem RIGHT DELETING TRAILING space.

SHIFT vfl_final_output-stdprodfxd RIGHT DELETING TRAILING space.

SHIFT vfl_final_output-stdprodpln RIGHT DELETING TRAILING space.

SHIFT vfl_final_output-distrectfxd RIGHT DELETING TRAILING space.

SHIFT vfl_final_output-distrectpln RIGHT DELETING TRAILING space.

SHIFT vfl_final_output-custorders RIGHT DELETING TRAILING space.

SHIFT vfl_final_output-custindreq RIGHT DELETING TRAILING space.

SHIFT vfl_final_output-affsn RIGHT DELETING TRAILING space.

SHIFT vfl_final_output-non_affsn RIGHT DELETING TRAILING space.

SHIFT vfl_final_output-stdprice RIGHT DELETING TRAILING space.

SHIFT vfl_final_output-currency RIGHT DELETING TRAILING space.

SHIFT vfl_final_output-matnr RIGHT DELETING TRAILING ' '.

OVERLAY vfl_final_output-matnr WITH '0000000000'.

MODIFY vit_final_output FROM vfl_final_output.

ENDLOOP.

ENDFORM. "delete_zero_qty

*---------------------------------------------------------------------*
* insert header *
*---------------------------------------------------------------------*
* Form inserts header to the output file *
*---------------------------------------------------------------------*
* The following tables are required *
* --> vit_final_output *
*---------------------------------------------------------------------*

FORM insert_header TABLES
vit_final_output.

* Preparation of header record

vfl_header-version = 'Version'.

vfl_header-matnr = 'Product'.

vfl_header-plant = 'Loc'.

vfl_header-uom = 'UOM'.

vfl_header-period = 'Period'.

vfl_header-split = 'SP'.

vfl_header-unrestinv = 'Qty1'.

vfl_header-blockinv = 'Qty2'.

vfl_header-qltyinsp = 'Qty3'.

vfl_header-conblkinv = 'Qty4'.

vfl_header-intransit = 'Qty5'.

vfl_header-mrp_inv = 'Qty6'.

vfl_header-conunrestinv = 'Qty7'.

vfl_header-conqltyinsp = 'Qty8'.

vfl_header-qmrct = 'Qty9'.

vfl_header-depdem = 'Qty10'.

vfl_header-distdem = 'Qty11'.

vfl_header-stdprodfxd = 'Qty12'.

vfl_header-stdprodpln = 'Qty13'.

vfl_header-distrectfxd = 'Qty14'.

vfl_header-distrectpln = 'Qty15'.

vfl_header-custorders = 'Qty16'.

vfl_header-custindreq = 'Qty17'.

vfl_header-affsn = 'Qty18'.

vfl_header-non_affsn = 'Qty19'.

vfl_header-stdprice = 'STDPR'.

vfl_header-currency = 'CURR'.

INSERT vfl_header INTO vit_final_output INDEX 1.

ENDFORM. "insert_header

*---------------------------------------------------------------------*
* FORM PREPARE-OUTPUT *
*---------------------------------------------------------------------*
* Form populates the internal table in output format *
*---------------------------------------------------------------------*
* The following tables are required *
* --> vit_t_s *
* --> vit_t_s_i *
* --> vit_c_c. *
*---------------------------------------------------------------------*
FORM livecache-key-fig TABLES
vit_t_s STRUCTURE bapi10030pbtimeserieso
vit_t_s_i STRUCTURE bapi10030pbtimeseriesitemo
vit_c_c STRUCTURE bapi10030pbcharo
vit_output STRUCTURE vit_output
vit_data STRUCTURE vit_data
USING
version
p_datfrm.

DATA: lit_loc_prod TYPE /sapapo/epegkey_tab.

DATA: lfl_loc_prod LIKE LINE OF lit_loc_prod.

DATA: lit_pegkey TYPE /sapapo/pegkey_tab.

DATA: lfl_pegkey LIKE LINE OF lit_pegkey.

DATA:lit_missing_key TYPE /sapapo/epegkey_tab.

DATA: lfl_missing_key LIKE LINE OF lit_missing_key.

DATA: lit_pegid TYPE /sapapo/pegid_tab.

DATA: lfl_pegid LIKE LINE OF lit_pegid.

DATA: lv_atpcat TYPE /sapapo/atpcat.

DATA: lit_stock TYPE /sapapo/matstock OCCURS 0.

DATA: lfl_stock LIKE LINE OF lit_stock.

DATA: lit_rc TYPE /sapapo/om_stock_rc_tab.

DATA: lfl_rc LIKE LINE OF lit_rc.

DATA: lit_output_inv LIKE vit_output OCCURS 0.

DATA: lfl_output_inv LIKE LINE OF lit_output_inv.

DATA: BEGIN OF vit_char_comb OCCURS 0,
char_comb_id TYPE bapi10030pbcharo-char_comb_id,
location TYPE /sapapo/loc-locno,
product TYPE /sapapo/matkey-matnr,
END OF vit_char_comb.

DATA: BEGIN OF lit_stock_temp OCCURS 0,
pegid TYPE /sapapo/pegid,
stock TYPE /sapapo/stock,
END OF lit_stock_temp.

DATA: BEGIN OF lit_atpcat OCCURS 0,
atpcat TYPE /sapapo/atpcat,
END OF lit_atpcat.

DATA: lv_per TYPE bapi10030pbtimeseriesitemo-period_begin,
lv_per_beg(15) TYPE c.

DATA: lv_value TYPE i.

DATA: lv_inv TYPE i.

DATA: lv_version TYPE /sapapo/vrsioid.

DATA: lv_datefrm TYPE sy-datum.

DATA: lv_temp_date TYPE sy-datum.

DATA: l_im3_msg LIKE z0sis_msg.

MOVE version TO lv_version.

lv_datefrm = p_datfrm.

LOOP AT vit_c_c.

vit_char_comb-char_comb_id = vit_c_c-char_comb_id.

IF vit_c_c-characteristic_name = c_country.

vit_char_comb-location = vit_c_c-characteristic_value.

ELSEIF vit_c_c-characteristic_name = c_material_char.

vit_char_comb-product = vit_c_c-characteristic_value.

APPEND vit_char_comb.
CLEAR vit_char_comb.

ENDIF.

ENDLOOP.

LOOP AT vit_char_comb.

READ TABLE vit_t_s WITH KEY
char_comb_id = vit_char_comb-char_comb_id
key_figure = c_workdays.

IF sy-subrc = 0.

LOOP AT vit_t_s_i WHERE
time_series_id = vit_t_s-time_series_id.
CLEAR lv_per.

lv_per = vit_t_s_i-period_begin.

CONCATENATE 'SC' lv_datefrm INTO vit_output-version.

vit_output-matnr = vit_char_comb-product.

vit_output-plant = vit_char_comb-location.

vit_output-uom = 'GU'.

MOVE vit_t_s_i-period_begin TO lv_per_beg.

* Begin of CD001+

IF lv_per_beg+0(8) <= lv_datefrm.

vit_output-period = lv_datefrm.

ELSE.

vit_output-period = lv_per_beg+0(8).

ENDIF.

* End of CD001+

IF vit_t_s_i-time_series_value = 1.

CLEAR vit_output-split.

ELSEIF vit_t_s_i-time_series_value > 1 AND
vit_t_s_i-time_series_value <= 5.

vit_output-split = c_w5.

ELSEIF vit_t_s_i-time_series_value = 6.

vit_output-split = c_w6.

ELSEIF vit_t_s_i-time_series_value = 7.

vit_output-split = c_w7.

ENDIF.

vit_output-unrestinv = 0.

vit_output-blockinv = 0.

vit_output-qltyinsp = 0.

vit_output-conblkinv = 0.

vit_output-intransit = 0.

vit_output-mrp_inv = 0.

vit_output-conunrestinv = 0.

vit_output-conqltyinsp = 0.

vit_output-qmrct = 0.

vit_output-affsn = 0.

vit_output-non_affsn = 0.

vit_output-stdprice = 0.

vit_output-currency = 0.

READ TABLE vit_t_s WITH KEY
char_comb_id = vit_char_comb-char_comb_id
key_figure = c_9admdse.
IF sy-subrc = 0.

READ TABLE vit_t_s_i WITH KEY
time_series_id = vit_t_s-time_series_id
period_begin = lv_per.
IF sy-subrc = 0.

MOVE vit_t_s_i-time_series_value TO lv_value.

vit_output-depdem = lv_value.

CLEAR lv_value.

ELSE.

vit_output-depdem = 0.

ENDIF.

ENDIF.

READ TABLE vit_t_s WITH KEY
char_comb_id = vit_char_comb-char_comb_id
key_figure = c_9admddt.
IF sy-subrc = 0.

READ TABLE vit_t_s_i WITH KEY
time_series_id = vit_t_s-time_series_id
period_begin = lv_per.
IF sy-subrc = 0.

MOVE vit_t_s_i-time_series_value TO lv_value.

vit_output-distdem = lv_value.

CLEAR lv_value.

ELSE.

vit_output-distdem = 0.

ENDIF.

ENDIF.

READ TABLE vit_t_s WITH KEY
char_comb_id = vit_char_comb-char_comb_id
key_figure = c_9afprod.

IF sy-subrc = 0.

READ TABLE vit_t_s_i WITH KEY
time_series_id = vit_t_s-time_series_id
period_begin = lv_per.

IF sy-subrc = 0.

MOVE vit_t_s_i-time_series_value TO lv_value.

vit_output-stdprodfxd = lv_value.

CLEAR lv_value.

ELSE.

vit_output-stdprodfxd = 0.

ENDIF.

ENDIF.

READ TABLE vit_t_s WITH KEY
char_comb_id = vit_char_comb-char_comb_id
key_figure = c_9approd.

IF sy-subrc = 0.

READ TABLE vit_t_s_i WITH KEY
time_series_id = vit_t_s-time_series_id
period_begin = lv_per.

IF sy-subrc = 0.

MOVE vit_t_s_i-time_series_value TO lv_value.

vit_output-stdprodpln = lv_value.

CLEAR lv_value.

ELSE.

vit_output-stdprodpln = 0.

ENDIF.

ENDIF.

READ TABLE vit_t_s WITH KEY
char_comb_id = vit_char_comb-char_comb_id
key_figure = c_9atship.

IF sy-subrc = 0.

READ TABLE vit_t_s_i WITH KEY
time_series_id = vit_t_s-time_series_id
period_begin = lv_per.
IF sy-subrc = 0.

MOVE vit_t_s_i-time_series_value TO lv_value.

vit_output-distrectfxd = lv_value.

CLEAR lv_value.

ELSE.

vit_output-distrectfxd = 0.

ENDIF.

ENDIF.

READ TABLE vit_t_s WITH KEY
char_comb_id = vit_char_comb-char_comb_id
key_figure = c_9apship.
IF sy-subrc = 0.

READ TABLE vit_t_s_i WITH KEY
time_series_id = vit_t_s-time_series_id
period_begin = lv_per.

IF sy-subrc = 0.

MOVE vit_t_s_i-time_series_value TO lv_value.

vit_output-distrectpln = lv_value.

CLEAR lv_value.

ELSE.

vit_output-distrectpln = 0.

ENDIF.

ENDIF.

READ TABLE vit_t_s WITH KEY
char_comb_id = vit_char_comb-char_comb_id
key_figure = c_9admdp1.

IF sy-subrc = 0.

READ TABLE vit_t_s_i WITH KEY
time_series_id = vit_t_s-time_series_id
period_begin = lv_per.

IF sy-subrc = 0.

MOVE vit_t_s_i-time_series_value TO lv_value.

vit_output-custorders = lv_value.

CLEAR lv_value.

ELSE.

vit_output-custorders = 0.

ENDIF.

ENDIF.

READ TABLE vit_t_s WITH KEY
char_comb_id = vit_char_comb-char_comb_id
key_figure = c_9adfcst.
IF sy-subrc = 0.

READ TABLE vit_t_s_i WITH KEY
time_series_id = vit_t_s-time_series_id
period_begin = lv_per.
IF sy-subrc = 0.

MOVE vit_t_s_i-time_series_value TO lv_value.

vit_output-custindreq = lv_value.

CLEAR lv_value.

ELSE.

vit_output-custindreq = 0.

ENDIF.

ENDIF.

APPEND vit_output.

CLEAR vit_output.

ENDLOOP. " vit_t_s_i

ENDIF. " read table vit_t_s

ENDLOOP. " vit_char_comb

ENDFORM. " livecache-key-fig
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SAP Other All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.