Posted: Thu Apr 01, 2010 10:49 am Post subject: Поиск ФМ для замены MB5B
Добрый день!
Нахожусь в поисках, каким ФМ можно получить складской запас на произвольную дату, наподобии MB5B.
Получить результаты работы транзакции MB5B могу (хранятся в таблице BESTANG), но для работы моего отчета нужны дополнительные условия:
1) Накладывать фильтр на тип стока (например, в результат выводить только 'Valuated Unrestricted-Use Stock')
2) MB5B выдет еще список материальных документов за период, которые мне не нужны.
Спасибо за инфу. mb5b, как оказывается использует не оптимальный алгоритм выборки, если тужны только запасы на выбранную дату, без списка материальных документов. _________________ Молитва - это запрос разработчику на изменение кода программы.
Коллеги, большое спасибо за почти готовое решение!
Использование исторических таблиц дописать не проблема, но все же у меня остается недопонимание, как сделать фильтрацию по типам стоков 'Stock Type' (MSEG-INSMK).
MB5B, как видно из примера, берет текущее состояние стока, затем откручивает назад запас по материальным документам. Но она учитывает суммарный объем на стоке, без деления по Типу стоков.
Можно ли с уверенность сказать по полю в материальном документе MSEG-INSMK, что если поле MSEG-INSMK имеет значение 'Blocked', то нужно откатывать назад MARD-SPEME (Blocked Stock),
если MSEG-INSMK = 'Quality inspection', то нужно изменять MARD-INSME (Stock in Quality Inspection)?
Посмотрел в продуктиве, из всех документов в MSEG поле INSMK имеет значение 'Blocked' только у 5 записей, хотя в MARD блокированные запасы имеются как минимум у нескольких тысяч материалов. Значит запас может быть заблокирован не только через материальный документ (или через материальный документ, но с другим статусом, не обязательно MSEG-INSMK = 'Blocked').
Как в этом случае определить заблокированный запас на произвольную дату?
* First run - make cache
CALL FUNCTION 'ZE_MB5B_GET_BESTAND'
EXPORTING
range_budat = s_budat[]
range_matnr = s_matnr[]
range_werks = s_werks[]
range_insmk = s_insmk[]
i_use_history = p_histr
i_take_transit = p_trans
CHANGING
t_bestand = bestand[].
* Get Stock data on each day of selected period ( default 30 days )
READ TABLE s_budat INDEX 1.
l_date = s_budat-low.
DO.
sy-tabix = sy-index MOD 10.
IF sy-tabix IS INITIAL.
CALL FUNCTION 'TH_REDISPATCH'.
ENDIF.
REFRESH lr_date.
lr_date-sign = 'I'.
lr_date-option = 'EQ'.
lr_date-low = l_date.
CLEAR lr_date-high.
APPEND lr_date.
IF NOT l_date IN s_budat.
EXIT.
ENDIF.
CALL FUNCTION 'ZE_MB5B_GET_BESTAND'
EXPORTING
range_budat = lr_date[]
range_matnr = s_matnr[]
range_werks = s_werks[]
range_insmk = s_insmk[]
i_use_history = p_histr
i_take_transit = p_trans
CHANGING
t_bestand = bestand[].
SORT bestand BY werks matnr.
LOOP AT bestand.
CHECK NOT bestand-endmenge IS INITIAL.
WRITE: / l_date, bestand-werks, bestand-matnr, bestand-endmenge.
ENDLOOP.
l_date = l_date + 1.
ENDDO.
FREE bestand.
Код функции см. ниже _________________ Молитва - это запрос разработчику на изменение кода программы.
Last edited by vga on Fri Jul 30, 2010 3:11 pm; edited 1 time in total
Спасибо за инфу. mb5b, как оказывается использует не оптимальный алгоритм выборки, если тужны только запасы на выбранную дату, без списка материальных документов.
В 2005-м году столкнулся с тем, что данные по запасам в таблице MARDH оказались неактуальными. Дело оказалось в том, что использовали транзакцию MMPI для отката периода (note 487381). Так что нужно быть бдительным. Не знаю, правда, как сейчас с этим делом обстоит у SAP...
mb5b, как оказывается использует не оптимальный алгоритм выборки, если тужны только запасы на выбранную дату, без списка материальных документов.
Писала как-то программу на основании исторических таблиц (для 4.7), но например нужная нам msprh заполнялась вкривь и вкось (даже без отката периода), и с саппортом попереписывались, но в конечном итоге плюнули и вернулись к старому неоптимальному, но проверенному алгоритму. Хотя та программа работала в разы быстрее, это да.
Ноты ставили все, какие только были Потом надоело.
Может, в 6.0 уже поправили (говорят, что поначалу и с MARDH были те же проблемы, потом залатали), но осадочек всё равно остался
А кто-то активно пользуется историческими таблицами, не глючат?
Age: 165 Joined: 04 Oct 2007 Posts: 1218 Location: Санкт-Петербург
Posted: Fri Jul 30, 2010 3:14 pm Post subject:
Обновленная версия:
Code:
************************************************************************
*
* Function Module Name : ZE_MB5B_GET_BESTAND
* Reference program (copy from) : MB5B, MB5TD
* Development specification ID : xxx
* Process team contact person/team name: xxx
* Date created : 30.03.2010
* Programmer : Valery Afanasyev
* Description : Get result table of tr. MB5B
************************************************************************
FUNCTION ze_mb5b_get_bestand.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(RANGE_BUDAT) TYPE TABLE OPTIONAL
*" REFERENCE(RANGE_MATNR) TYPE TABLE OPTIONAL
*" REFERENCE(RANGE_WERKS) TYPE TABLE OPTIONAL
*" REFERENCE(RANGE_LGORT) TYPE TABLE OPTIONAL
*" REFERENCE(RANGE_INSMK) TYPE TABLE OPTIONAL
*" REFERENCE(I_TAKE_TRANSIT) TYPE AS4FLAG OPTIONAL
*" REFERENCE(I_USE_HISTORY) TYPE AS4FLAG OPTIONAL
*" CHANGING
*" REFERENCE(T_BESTAND) TYPE TABLE
*"----------------------------------------------------------------------
* PARAMETERS LGBST LIKE AM07M-LGBST RADIOBUTTON GROUP BART DEFAULT 'X'.
CONSTANTS:
lc_periv TYPE t009b-periv VALUE 'Z5',
lc_labst_1 TYPE zeinsmk-insmk VALUE '1', "Valuated Unrestricted-Use Stock
lc_insme_2 TYPE zeinsmk-insmk VALUE '2', "Stock in Quality Inspection
lc_speme_3 TYPE zeinsmk-insmk VALUE '3', "Blocked Stock
lc_retme_4 TYPE zeinsmk-insmk VALUE '4', "Blocked Stock Return
lc_einme_5 TYPE zeinsmk-insmk VALUE '5', "Total Stock of All Restricted Batches
lc_umlme_6 TYPE zeinsmk-insmk VALUE '6', "Stock in transfer (from one storage location to another)
c_labst_space TYPE mseg-insmk VALUE '', "Unrestricted-use
c_labst_f TYPE mseg-insmk VALUE 'F', "Unrestricted-use
c_insme_2 TYPE mseg-insmk VALUE '2', "Quality inspection
c_insme_x TYPE mseg-insmk VALUE 'X', "Quality inspection
c_speme_s TYPE mseg-insmk VALUE 'S', "Blocked
c_speme_3 TYPE mseg-insmk VALUE '3'. "(Cust)Total Stock of All Restricted Batches
DATA: lgbst TYPE am07m-lgbst VALUE 'X',
l_date TYPE sy-datum,
l_date_high TYPE sy-datum,
l_use_cache TYPE c,
l_append TYPE c.
DATA: l_lfmon TYPE mardh-lfmon,
l_slper TYPE buper, "YYYYMM selection period
l_maper TYPE buper. "YYYYMM material period
RANGES: lr_budat FOR bkpf-budat,
lr_matnr FOR mseg-matnr,
lr_werks FOR mseg-werks,
lr_lgort FOR mseg-lgort,
lr_insmk FOR zeinsmk-insmk.
* If no date is given at all, the range is set to the maximum
* extend (1.1.0000 - 31.12.9999).
* If only datum-low is set, it is interpreted as the day for
* which the analysis is wanted --> datum-high is filled up.
IF lr_budat[] IS INITIAL.
lr_budat-sign = 'I'.
lr_budat-option = 'BT'.
lr_budat-low = '00000101'.
lr_budat-high = '99991231'.
APPEND lr_budat.
ENDIF.
READ TABLE lr_budat INDEX 1.
IF lr_budat-low IS INITIAL.
lr_budat-low = '00000101'.
IF lr_budat-high IS INITIAL.
lr_budat-high = '99991231'.
ENDIF.
ELSE.
IF lr_budat-high IS INITIAL.
lr_budat-high = lr_budat-low.
ENDIF.
ENDIF.
IF NOT i_use_history IS INITIAL.
CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
EXPORTING
day_in = lr_budat-high
IMPORTING
last_day_of_month = l_date_high.
ELSE.
l_date_high = '99991231'.
ENDIF.
IF NOT g_use_cache IS INITIAL AND
lr_matnr[] EQ gr_matnr[] AND
lr_werks[] EQ gr_werks[] AND
lr_lgort[] EQ gr_lgort[].
l_use_cache = 'X'.
ENDIF.
l_date = lr_budat-low.
WHILE NOT l_use_cache IS INITIAL.
IF NOT l_date IN lr_budat.
EXIT.
ENDIF.
IF NOT l_date IN gr_budat.
CLEAR l_use_cache.
ENDIF.
l_date = l_date + 1.
ENDWHILE.
IF l_use_cache IS INITIAL.
gr_budat[] = lr_budat[].
gr_matnr[] = lr_matnr[].
gr_werks[] = lr_werks[].
gr_lgort[] = lr_lgort[].
ELSE.
* Restore cached data
g_t_mseg_lean[] = gt_mseg_lean_cache[].
ENDIF.
IF l_use_cache IS INITIAL.
g_use_cache = 'X'.
REFRESH: gt_mardh, imard, imara, g_t_makt, g_t_mseg_lean,
g_ra_xauto, g_t_mseg_or.
*--{ VGA ECDK933356:insert
DATA: BEGIN OF lt_menge OCCURS 0,
werks LIKE ekpo-werks,
matnr LIKE ekpo-matnr,
menge LIKE ekbe-menge,
meins LIKE ekpo-meins,
END OF lt_menge.
* Program RM07MTRB_DATE (Transaction MB5TD)
* block scope of list
DATA:
xtram LIKE am07m-mb5t_sel VALUE 'X',
xnlcc LIKE am07m-mb5t_selcc VALUE 'X',
xelik LIKE am07m-also_elikz VALUE 'X', "VGA ECDK935237
xloek LIKE am07m-also_deleted,
xsper LIKE am07m-also_deleted. "n1268193
TYPES : BEGIN OF stype_makt_key,
matnr LIKE makt-matnr,
END OF stype_makt_key.
DATA : g_s_makt_key TYPE stype_makt_key,
g_t_makt_key TYPE STANDARD TABLE OF
stype_makt_key
WITH DEFAULT KEY.
TYPES : BEGIN OF stype_mdbs,
matnr LIKE ekpo-matnr,
ebeln LIKE ekpo-ebeln,
ebelp LIKE ekpo-ebelp,
pstyp LIKE ekpo-pstyp,
sobkz LIKE ekpo-sobkz,
umren LIKE ekpo-umren,
umrez LIKE ekpo-umrez,
meins LIKE ekpo-meins,
werks LIKE ekpo-werks,
bukrs LIKE ekko-bukrs,
menge LIKE eket-menge,
netwr LIKE ekpo-netwr,
waers LIKE ekko-waers,
wamng LIKE eket-wamng,
wemng LIKE eket-wemng,
wkurs LIKE ekko-wkurs,
kufix LIKE ekko-kufix,
reswk LIKE ekko-reswk,
retpo LIKE ekpo-retpo,
bstmg LIKE ekpo-menge,
elikz LIKE ekpo-elikz,
loekz LIKE ekpo-loekz,
bstyp LIKE ekpo-bstyp,
END OF stype_mdbs.
DATA : g_s_xmdbs TYPE stype_mdbs,
g_s_xmdbs_sum TYPE stype_mdbs,
g_t_xmdbs TYPE STANDARD TABLE OF stype_mdbs.
DATA : g_s_ekbe TYPE stype_ekbe,
g_t_ekbe TYPE STANDARD TABLE OF stype_ekbe.
FIELD-SYMBOLS : <g_fs_ekbe> TYPE stype_ekbe.
* define range tables in the modern form
DATA : gt_ra_elikz TYPE RANGE OF ekpo-elikz,
gs_ra_elikz LIKE LINE OF gt_ra_elikz,
gt_ra_loekz TYPE RANGE OF ekpo-loekz,
gs_ra_loekz LIKE LINE OF gt_ra_loekz,
gt_ra_bewtp TYPE RANGE OF ekbe-bewtp,
gs_ra_bewtp LIKE LINE OF gt_ra_bewtp.
DATA : g_s_xtab6 TYPE stype_xtab6,
g_t_xtab6 TYPE stab_xtab6.
* the main table fpr the stock transfer PO items
TYPES : BEGIN OF stype_bestand.
INCLUDE TYPE stype_xtab6.
TYPES : maktx LIKE makt-maktx,
name1 LIKE t001w-name1,
mb5td_budat TYPE mb5td-mb5td_budat,
mb5td_trame TYPE mb5td-mb5td_trame,
mb5td_calc_trame TYPE mb5td-mb5td_calc_trame,
mb5td_calc_dmbtr TYPE mb5td-mb5td_calc_dmbtr,
sotxt TYPE t148t-sotxt,
color TYPE slis_t_specialcol_alv,
bukrs TYPE t001-bukrs,
bukrs_reswk TYPE mcw_breswk,
mb5td_ccomp TYPE mb5td-mb5td_ccomp,
bsakz TYPE ekko-bsakz,
ccomp TYPE ekpo-ccomp,
* Dummy field for adjust fields in header and item
dummy TYPE alv_dummy.
TYPES : END OF stype_bestand.
TYPES : stab_bestand TYPE STANDARD TABLE OF
stype_bestand
WITH DEFAULT KEY.
DATA : g_s_bestand TYPE stype_bestand,
g_t_bestand TYPE stab_bestand.
* working area for save and restore the parameters
DATA : BEGIN OF g_save,
werks LIKE t001w-werks,
matnr LIKE mkol-matnr,
END OF g_save.
* for the special text indicators and their texts
TYPES : BEGIN OF stype_t148t,
sobkz TYPE t148t-sobkz,
sotxt TYPE t148t-sotxt,
END OF stype_t148t.
DATA : g_s_t148t TYPE stype_t148t,
g_t_t148t_key TYPE STANDARD TABLE OF
stype_t148t
WITH DEFAULT KEY,
g_t_t148t TYPE HASHED TABLE OF
stype_t148t
WITH UNIQUE KEY sobkz.
* for control break
TYPES : BEGIN OF stype_group,
matnr TYPE mara-matnr,
werks TYPE marc-werks,
sobkz TYPE t148-sobkz,
END OF stype_group,
stab_group TYPE STANDARD TABLE OF
stype_group
WITH DEFAULT KEY.
* working tables for current and calculated stocks in transit
TYPES : BEGIN OF stype_trame,
matnr TYPE mara-matnr,
werks TYPE marc-werks,
sobkz TYPE t148-sobkz,
trame TYPE mb5td-mb5td_calc_trame,
dmbtr TYPE mb5td-mb5td_calc_dmbtr,
END OF stype_trame,
htab_trame TYPE HASHED TABLE OF
stype_trame
WITH UNIQUE KEY matnr werks sobkz.
DATA : g_s_trame TYPE stype_trame,
g_t_trame TYPE htab_trame,
g_s_trame_date TYPE stype_trame,
g_t_trame_date TYPE htab_trame.
* define working area with print parameters
DATA : gs_mmim_rep_print TYPE mmim_rep_print.
DATA : g_flag_initialization(01) TYPE c,
g_flag_no_esdus(01) TYPE c,
g_flag_ekbe_found(01) TYPE c,
g_flag_launched(01) TYPE c,
g_flag_interface_check(01) TYPE c,
g_flag_color_pos(01) TYPE c,
g_flag_color_neg(01) TYPE c,
g_flag_colorize(01) TYPE c.
DATA : BEGIN OF g_flag_break,
sum_ekbe(01) TYPE c VALUE 'X',
trame_date(01) TYPE c VALUE 'X',
group_2(01) TYPE c VALUE 'X',
ucomm_sum(01) TYPE c VALUE 'X',
END OF g_flag_break.
TYPES : BEGIN OF stype_makt,
matnr TYPE makt-matnr,
maktx TYPE makt-maktx,
END OF stype_makt.
DATA : l_s_makt TYPE stype_makt,
l_t_makt TYPE HASHED TABLE OF
stype_makt
WITH UNIQUE KEY matnr.
IF NOT i_take_transit IS INITIAL.
************************************************************************
* organisation.
************************************************************************
*FORM organisation.
SELECT werks name1 bukrs
INTO CORRESPONDING FIELDS OF TABLE gt_organ
FROM t001w INNER JOIN t001k "#EC CI_BUFFJOIN
ON t001w~bwkey = t001k~bwkey
WHERE werks IN lr_werks.
* AND bukrs IN bukrs.
*ENDFORM. " ORGANISATION
* fill the rgange table depending on the parameters
REFRESH : gt_ra_elikz, gt_ra_loekz, gt_ra_bewtp.
CLEAR : gs_ra_elikz, gs_ra_loekz, gs_ra_bewtp.
* a) for the Item category in purchasing document
* new handling from release 4.70 and higher
* b) for the "Delivery Completed" Indicator
IF xelik IS INITIAL.
* select only POs without "Delivery Completed" Indicator
* otherwise let the range table empty -> take all
MOVE : 'I' TO gs_ra_elikz-sign,
'EQ' TO gs_ra_elikz-option.
APPEND gs_ra_elikz TO gt_ra_elikz.
ENDIF.
* c) for the Deletion indicator in purchasing document
* note 1268193 introduces the new field xsper for del. po "n1268193
* IF xloek IS INITIAL. "n1268193
* select only POs without Deletion indicator
* otherwise let the range table empty -> take all
MOVE : 'I' TO gs_ra_loekz-sign,
'EQ' TO gs_ra_loekz-option.
APPEND gs_ra_loekz TO gt_ra_loekz.
* ENDIF. "n1268193
* in case xloek and xsper is set, nothing needs to be done "n1268193
* in case xloek is set: "n1268193
IF NOT xloek IS INITIAL. "n1268193
MOVE : 'I' TO gs_ra_loekz-sign, "n1268193
'EQ' TO gs_ra_loekz-option, "n1268193
'X' TO gs_ra_loekz-low. "n1268193
APPEND gs_ra_loekz TO gt_ra_loekz. "n1268193
ENDIF. "n1268193
* in case xsper is set: "n1268193
IF NOT xsper IS INITIAL. "n1268193
MOVE : 'I' TO gs_ra_loekz-sign, "n1268193
'EQ' TO gs_ra_loekz-option, "n1268193
'S' TO gs_ra_loekz-low. "n1268193
APPEND gs_ra_loekz TO gt_ra_loekz. "n1268193
ENDIF. "n1268193
* d) for the PO history category
MOVE : 'I' TO gs_ra_bewtp-sign,
'EQ' TO gs_ra_bewtp-option,
'E' TO gs_ra_bewtp-low.
APPEND gs_ra_bewtp TO gt_ra_bewtp.
MOVE : 'U' TO gs_ra_bewtp-low.
APPEND gs_ra_bewtp TO gt_ra_bewtp.
* select the PO data and calculate the stock in transit
* PERFORM database_selection
* TABLES g_t_xtab6
* USING xnlcc " cross company
* xtram. " non cross company
************************************************************************
* database_selection
************************************************************************
*FORM database_selection
* tables l_t_ztab3 type stab_xtab6
* using l_cross_company type am07m-xselk
* l_non_cross_company type am07m-xselk.
* define local working areas
DATA : l_s_ztab3 TYPE stype_xtab6.
DATA : BEGIN OF l_s_t001,
bukrs LIKE t001-bukrs,
waers LIKE t001-waers,
END OF l_s_t001.
DATA : l_s_xmara TYPE stype_xmara.
DATA: l_dmbtr TYPE fc_vlc_eq,
l_bsakz TYPE ekko-bsakz.
* at first look for the PO headers and PO items
SELECT ekpo~matnr
ekko~ebeln
ekpo~ebelp
ekpo~pstyp
ekpo~sobkz
ekpo~umren
ekpo~umrez
ekpo~meins
ekpo~werks
ekko~bukrs
ekpo~netwr
ekko~waers
ekko~wkurs
ekko~kufix
ekko~reswk
ekpo~retpo
ekpo~menge
ekpo~elikz
ekpo~loekz
ekpo~bstyp
ekpo~ccomp
ekko~bsakz
ekko~ekorg
INTO TABLE g_t_po
FROM ekpo INNER JOIN ekko
ON ekpo~mandt = ekko~mandt
AND ekpo~ebeln = ekko~ebeln
WHERE ekpo~matnr IN lr_matnr
* AND ekpo~ebeln IN so_ebeln
* AND ekpo~ebelp IN so_ebelp
AND ekpo~werks IN lr_werks
* and ekpo~sobkz in sobkz
AND ekpo~loekz IN gt_ra_loekz
AND ekpo~elikz IN gt_ra_elikz
AND ekpo~bstyp IN ('F', 'L') " F = PO, L = sched. agreement
AND ekpo~wepos <> space " GR is expected
* and ekko~reswk in reswk
AND ekko~reswk <> space.
* evaluate the results :
LOOP AT g_t_po INTO g_s_po.
* check authorization for the purchasing organization
* IF NOT cl_mmim_auth=>check( i_object = 'M_BEST_EKO'
* i_value1 = g_s_po-ekorg ) IS INITIAL.
* DELETE g_t_po.
* CONTINUE.
* ENDIF.
* check authorization for the plant
* IF NOT cl_mmim_auth=>check( i_object = 'M_MATE_WRK'
* i_value1 = g_s_po-werks ) IS INITIAL.
* DELETE g_t_po.
* CONTINUE.
* ENDIF.
* Processing for UB/NB-logic
* Determine posting logic for document item.
IF g_s_po-bsakz = 'T' OR g_s_po-ccomp = '1'.
l_bsakz = 'T'.
ELSE.
l_bsakz = space.
ENDIF.
* Delete if not requested
IF ( l_bsakz = 'T' AND xtram IS INITIAL ) OR
( l_bsakz = space AND xnlcc IS INITIAL ).
DELETE g_t_po.
CONTINUE.
ENDIF.
* ST-PO-consignment:
* Delete if no classical stock in transit PSTYP 0,3,7. At the moment
* this is only the case in case of consignment transport order
IF g_s_po-pstyp NA '037'.
DELETE g_t_po.
CONTINUE.
ENDIF.
** For UB-documents, clear NETWR. Since 4.6C, it is possible to
** maintain prices for UB-POs too, but this is irrelevant for the
** valuation in MM-IM. UB transit stock is already valuated and
** should not be shown in the report MB5T.
* IF l_bsakz = 'T'.
* CLEAR g_s_po-netwr.
* ENDIF.
* Store derived BSAKZ in the table
g_s_po-bsakz = l_bsakz.
MODIFY g_t_po FROM g_s_po
TRANSPORTING bsakz.
ENDLOOP.
*--{ VGA ECDK937025:insert
CALL FUNCTION 'TH_REDISPATCH'.
*--} VGA ECDK937025:end
* go on when there is at least one entry in this table
*--{ VGA ECDK934929:replace
* CHECK NOT g_t_po[] IS INITIAL.
IF NOT g_t_po[] IS INITIAL.
*--} VGA ECDK934929:end
* read the matching entries from the PO history table
SELECT
ebeln
ebelp
vgabe
gjahr
belnr
buzei
bewtp
budat
menge
*--{ VGA ECDK937025:delete
* bpmng
*--} VGA ECDK937025:end
shkzg
*--{ VGA ECDK937025:delete
* matnr
* werks
*--} VGA ECDK937025:end
FROM ekbe
INTO TABLE gt_ekbe_cache
FOR ALL ENTRIES IN g_t_po
WHERE ebeln = g_t_po-ebeln
AND ebelp = g_t_po-ebelp
AND bewtp IN gt_ra_bewtp
AND budat LE lr_budat-high.
SORT gt_ekbe_cache BY ebeln ebelp vgabe gjahr belnr buzei.
*--{ VGA ECDK937025:insert
CALL FUNCTION 'TH_REDISPATCH'.
*--} VGA ECDK937025:end
SORT g_t_po BY ebeln ebelp.
**********************************************************
*endform. " database_selection
**********************************************************
*--{ VGA ECDK937025:moved from below to cached section
FIELD-SYMBOLS: <fs_po> LIKE g_s_po.
LOOP AT g_t_po ASSIGNING <fs_po>.
* fill key table for reading MARA and MAKT
MOVE <fs_po>-matnr TO g_s_makt_key-matnr.
COLLECT g_s_makt_key INTO g_t_makt_key.
ENDLOOP.
* Read material base units (and again a lot of work for a little field)
IF NOT g_t_makt_key[] IS INITIAL.
SELECT matnr meins FROM mara
INTO TABLE gt_xmara
FOR ALL ENTRIES IN g_t_makt_key
WHERE matnr = g_t_makt_key-matnr.
ENDIF.
*--} VGA ECDK937025:end
ENDIF. "
*--} VGA ECDK933356:end
*********************************
* RM07MLBD
*form f0700_prepare_tied_empties. "n547170
*********************************
"n547170
MOVE : 'F' TO g_ra_xauto-low, "n547170
space TO g_ra_xauto-high, "n547170
'EQ' TO g_ra_xauto-option, "n547170
'I' TO g_ra_xauto-sign. "n547170
APPEND g_ra_xauto. "n547170
"n547170
MOVE : 'L' TO g_ra_xauto-low. "n547170
APPEND g_ra_xauto. "n547170
"n547170
MOVE : 'M' TO g_ra_xauto-low. "n547170
APPEND g_ra_xauto. "n547170
"n547170
MOVE : 'W' TO g_ra_xauto-low. "n547170
APPEND g_ra_xauto. "n547170
"n547170
*********************************
* PERFORM eingaben_pruefen.
*********************************
* consider and prepare select-options depending on the required
* special stock indicator
REFRESH g_ra_sobkz.
CLEAR g_ra_sobkz.
IF lgbst = 'X'. "only Storage loc./batch stock
* create ranges table : select only sobkz = space
*********************************
* PERFORM F0500_APPEND_RA_SOBKZ USING C_SPACE.
*********************************
* create ranges table with special stock indicator
CLEAR g_ra_sobkz.
MOVE : c_space TO g_ra_sobkz-low,
'I' TO g_ra_sobkz-sign,
'EQ' TO g_ra_sobkz-option.
APPEND g_ra_sobkz.
ENDIF.
*--{ VGA ECDK934929:insert
*********************************
*FORM F0600_CREATE_RANGE_LGORT.
*********************************
IF lgbst = 'X'. "only Storage loc./batch stock
* add an exclusion for storage location = space
MOVE : 'E' TO lr_lgort-sign,
'EQ' TO lr_lgort-option.
APPEND lr_lgort.
ENDIF.
*--} VGA ECDK934929:end
*********************************
*FORM AKTUELLE_BST_LGBST_MARD.
*********************************
SELECT * FROM mard
INTO CORRESPONDING FIELDS OF TABLE imard
WHERE matnr IN lr_matnr
AND werks IN lr_werks
AND lgort IN lr_lgort.
*--{ VGA ECDK933125:insert
IF NOT i_use_history IS INITIAL.
DATA: l_buper TYPE t009b-poper.
CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
EXPORTING
i_date = lr_budat-low
i_periv = lc_periv "Version der Periodenermittlung
IMPORTING
e_buper = l_buper
EXCEPTIONS
input_false = 1
t009_notfound = 1
t009b_notfound = 1.
IF sy-subrc IS INITIAL.
l_lfmon = l_buper.
ELSE.
l_lfmon = lr_budat-low+4(2).
* IF l_lfmon >= 12.
* l_lfmon = 16.
* ENDIF.
ENDIF.
IF NOT imard[] IS INITIAL.
SELECT * INTO TABLE gt_mardh
FROM mardh
FOR ALL ENTRIES IN imard
WHERE matnr EQ imard-matnr
AND werks EQ imard-werks
AND lgort EQ imard-lgort
AND ( lfgja GT lr_budat-low+0(4) OR
( lfgja EQ lr_budat-low+0(4) AND
*--{ VGA ECDK934929:replace
* See Note 193554 - Stock/valuation data of previous periods
* lfmon GT l_lfmon ) ).
lfmon GE l_lfmon ) ).
*--} VGA ECDK934929:end
IF NOT g_t_mat_key[] IS INITIAL. "n451923
* select the material masters
SELECT matnr meins mtart FROM mara
INTO CORRESPONDING FIELDS OF TABLE imara
FOR ALL ENTRIES IN g_t_mat_key
WHERE matnr = g_t_mat_key-matnr.
* select the short text for all materials
* take only the necessary fields "n451923
* SELECT matnr maktx FROM makt "n451923
* INTO CORRESPONDING FIELDS OF TABLE g_t_makt "n451923
* FOR ALL ENTRIES IN g_t_mat_key
* WHERE matnr = g_t_mat_key-matnr
* AND spras = sy-langu.
*
SORT imara BY matnr. "n451923
* SORT g_t_makt BY matnr. "n451923
FREE g_t_mat_key.
ENDIF.
* standard access, the database optimizer looks for the
* access path
SELECT "(G_T_MSEG_FIELDS)
* mkpf~blart
mkpf~budat
* mkpf~cpudt
* mkpf~cputm
mkpf~mblnr
mkpf~mjahr
* mkpf~usnam
* mkpf~vgart
* mkpf~xabln
mseg~bustm
mseg~bustw
mseg~bwart
* mseg~bwtar
mseg~charg
mseg~dmbtr
* mseg~dmbum
mseg~insmk
mseg~kzbew
* mseg~kzbws
mseg~kzvbr
mseg~kzzug
mseg~lgort
mseg~matnr
mseg~meins
mseg~menge
mseg~mengu
mseg~shkzg
mseg~sjahr
mseg~smbln
mseg~smblp
mseg~sobkz
mseg~waers
mseg~werks
mseg~wertu
mseg~xauto
mseg~zeile
INTO CORRESPONDING FIELDS OF TABLE g_t_mseg_lean
FROM mkpf AS mkpf
JOIN mseg AS mseg ON mkpf~mandt = mseg~mandt
AND mkpf~mblnr = mseg~mblnr
AND mkpf~mjahr = mseg~mjahr
WHERE mseg~matnr IN lr_matnr
AND mseg~werks IN lr_werks
AND mseg~lgort IN lr_lgort
AND mseg~sobkz IN g_ra_sobkz
AND mkpf~budat GE lr_budat-low
AND mkpf~budat LE l_date_high.
* check whether the found MM doc items contain retail and
* and beverage specific values
* check authority in this loop - endloop
LOOP AT g_t_mseg_lean ASSIGNING <g_fs_mseg_lean>.
* b) look for special indicators
IF NOT <g_fs_mseg_lean>-xauto IS INITIAL.
IF <g_fs_mseg_lean>-xauto IN g_ra_xauto.
MOVE 'X' TO g_cust_tied_empties.
ENDIF.
ENDIF.
ENDLOOP.
*--{ VGA ECDK937025:insert
CALL FUNCTION 'TH_REDISPATCH'.
*--} VGA ECDK937025:end
* function for tied empties is active and "n547170
* stock type = storage location/batch ? "n547170
IF NOT g_cust_tied_empties IS INITIAL AND "n547170
NOT lgbst IS INITIAL. "n547170
* sort the results by documents numbers und items "n547170
SORT g_t_mseg_lean BY mblnr mjahr zeile. "n547170
ENDIF. "n547170
* process table withe the results form the database selection
LOOP AT g_t_mseg_lean INTO g_s_mseg_lean.
CLEAR g_flag_delete.
* ELSE.
* b) check the combination of special stock indicator and
* storage location
IF g_s_mseg_lean-sobkz = 'O' OR
g_s_mseg_lean-sobkz = 'V' OR
g_s_mseg_lean-sobkz = 'W'.
* these entries must not have a storage location
IF NOT g_s_mseg_lean-lgort IS INITIAL.
MOVE 'X' TO g_flag_delete.
ENDIF.
ELSE.
*--{ VGA ECDK933356:insert
IF i_take_transit IS INITIAL.
*--} VGA ECDK933356:end
* the others entries should have a storage location
IF g_s_mseg_lean-lgort IS INITIAL.
MOVE 'X' TO g_flag_delete.
ENDIF.
*--{ VGA ECDK933356:insert
ENDIF.
*--} VGA ECDK933356:end
ENDIF.
IF g_flag_delete = 'X'.
DELETE g_t_mseg_lean.
CONTINUE. "take the next entry
ENDIF.
* function for tied empties is active and "n547170
* stock type = storage location/batch ? "n547170
IF NOT g_cust_tied_empties IS INITIAL AND "n547170
NOT lgbst IS INITIAL. "n547170
"n547170
* check whether this line was generated automatically "n547170
IF g_s_mseg_lean-xauto = 'X'. "n547170
* look for the origin line "n547170
COMPUTE g_f_zeile = g_s_mseg_lean-zeile - 1. "n547170
"n547170
* check whether the previous line contains the "n547170
* original posting "n547170
IF g_s_mseg_pr-matnr = g_s_mseg_lean-matnr AND "n547170
g_s_mseg_pr-mblnr = g_s_mseg_lean-mblnr AND "n547170
g_s_mseg_pr-mjahr = g_s_mseg_lean-mjahr AND "n547170
g_s_mseg_pr-zeile = g_f_zeile. "n547170
* the previous entry contains the original line "n547170
"n547170
IF g_s_mseg_pr-xauto IN g_ra_xauto. "n547170
* the previous line contains a matching value "n547170
* XAUTO -> save it in working table "n547170
APPEND g_s_mseg_pr TO g_t_mseg_or. "n547170
ENDIF. "n547170
ELSE. "n547170
* the previous entry does not contain the original "n547170
* posting : save the key "n547170
g_s_mseg_key-matnr = g_s_mseg_lean-matnr. "n547170
g_s_mseg_key-mblnr = g_s_mseg_lean-mblnr. "n547170
g_s_mseg_key-mjahr = g_s_mseg_lean-mjahr. "n547170
g_s_mseg_key-zeile = g_f_zeile. "n547170
APPEND g_s_mseg_key TO g_t_mseg_key. "n547170
ENDIF. "n547170
ENDIF. "n547170
"n547170
* save the current entry in the buffer previous entry "n547170
MOVE-CORRESPONDING g_s_mseg_lean TO g_s_mseg_pr. "n547170
ENDIF. "n547170
ENDLOOP.
* function for tied empties is active and "n547170
* stock type = storage location/batch ? "n547170
IF NOT g_cust_tied_empties IS INITIAL AND "n547170
NOT lgbst IS INITIAL. "n547170
"n547170
* Select the missing items with the origin posting lines "n547170
* and append them into the working table "n547170
IF NOT g_t_mseg_key[] IS INITIAL. "n547170
SELECT mblnr mjahr zeile matnr xauto "n547170
FROM mseg "n547170
APPENDING TABLE g_t_mseg_or "n547170
FOR ALL ENTRIES IN g_t_mseg_key "n547170
WHERE mblnr = g_t_mseg_key-mblnr "n547170
AND mjahr = g_t_mseg_key-mjahr "n547170
AND zeile = g_t_mseg_key-zeile "n547170
AND xauto IN g_ra_xauto. "only F, L, M, W "n547170
ENDIF. "n547170
"n547170
SORT g_t_mseg_or BY mblnr mjahr zeile matnr. "n547170
"n547170
* process the MM docs in any cases : "n547170
* - delete the lines with the special value for XAUTO "n547170
* - check lines who were created automatically whether "n547170
* the original line has a special value for XAUTO "n547170
LOOP AT g_t_mseg_lean INTO g_s_mseg_lean. "n547170
CLEAR g_flag_delete. "n547170
"n547170
* evaluate field XAUTO "n547170
IF g_s_mseg_lean-xauto IS INITIAL. "n547170
* no action "n547170
ELSEIF g_s_mseg_lean-xauto IN g_ra_xauto. "n547170
* delete MM docs with XAUTO = 'F', 'L', 'M', 'W' "n547170
MOVE 'X' TO g_flag_delete. "n547170
"n547170
ELSEIF g_s_mseg_lean-xauto = 'X'. "n547170
IF NOT g_t_mseg_or[] IS INITIAL. "n547170
* check field XAUTO of the original MM doc item "n547170
COMPUTE g_f_zeile = g_s_mseg_lean-zeile - 1. "n547170
"n547170
READ TABLE g_t_mseg_or "n547170
INTO g_s_mseg_or "n547170
WITH KEY mblnr = g_s_mseg_lean-mblnr "n547170
mjahr = g_s_mseg_lean-mjahr "n547170
zeile = g_f_zeile "n547170
matnr = g_s_mseg_lean-matnr "n547170
BINARY SEARCH. "n547170
"n547170
IF sy-subrc IS INITIAL. "n547170
* the original line was a posting for a tied "n547170
* empties material -> delete this entry "n547170
MOVE 'X' TO g_flag_delete. "n547170
ENDIF. "n547170
ENDIF. "n547170
ENDIF. "n547170
"n547170
IF g_flag_delete = 'X'. "n547170
DELETE g_t_mseg_lean. "n547170
ENDIF. "n547170
ENDLOOP. "n547170
"n547170
* release the space of the working tables "n547170
FREE : g_t_mseg_or, g_t_mseg_key. "n547170
ENDIF. "n547170
DATA: BEGIN OF k2 OCCURS 0,
bwart LIKE t156s-bwart,
END OF k2.
REFRESH k2.
* select the movement types from the selected documents
LOOP AT g_t_mseg_lean INTO g_s_mseg_lean.
MOVE g_s_mseg_lean-bwart TO k2-bwart.
COLLECT k2.
ENDLOOP.
* Read data for movement type from new tables
* T156SY/C/Q with function module from release >=46B
DATA: t_st156s LIKE st156s OCCURS 0
WITH HEADER LINE.
IF sy-subrc = 0. "311588
LOOP AT t_st156s.
MOVE-CORRESPONDING t_st156s TO it156.
APPEND it156.
ENDLOOP.
ENDIF.
ENDLOOP.
SORT it156 BY bwart wertu mengu sobkz kzbew kzzug kzvbr.
SELECT * FROM t156m INTO CORRESPONDING FIELDS OF TABLE it156x
FOR ALL ENTRIES IN it156 WHERE bustm EQ it156-bustm.
LOOP AT it156.
CLEAR it156-lbbsa.
READ TABLE it156x WITH KEY bustm = it156-bustm.
it156-lbbsa = it156x-lbbsa.
MODIFY it156.
ENDLOOP.
DATA: rc TYPE i. "147374
LOOP AT g_t_mseg_lean INTO g_s_mseg_lean.
* find and delete reversal movements / only in releases >= 45B
* IF NOT NOSTO IS INITIAL AND
* NOT ( G_S_MSEG_LEAN-SMBLN IS INITIAL OR
* G_S_MSEG_LEAN-SMBLP IS INITIAL ).
* MOVE-CORRESPONDING G_S_MSEG_LEAN
* TO STORNO.
*
* APPEND STORNO.
* DELETE G_T_MSEG_LEAN.
* CONTINUE.
* ENDIF.
rc = sy-subrc. "147374
IF g_s_mseg_lean-bustm = space AND
g_s_mseg_lean-bustw = space AND
rc = 0. "147374
MOVE : it156-bustm TO g_s_mseg_lean-bustm, "147374
it156-bustw TO g_s_mseg_lean-bustw. "147374
ENDIF.
IF rc = 0. "147374
MOVE : it156-lbbsa TO g_s_mseg_lean-lbbsa.
IF NOT it156-bwagr IS INITIAL.
MOVE : it156-bwagr TO g_s_mseg_lean-bwagr.
ELSE.
MOVE : 'REST' TO g_s_mseg_lean-bwagr.
ENDIF.
ELSE.
MOVE : 'REST' TO g_s_mseg_lean-bwagr.
ENDIF. "147374
MODIFY g_t_mseg_lean FROM g_s_mseg_lean.
ENDLOOP.
* store data to cache
gt_mseg_lean_cache[] = g_t_mseg_lean[].
*--{ VGA ECDK935151:insert
SELECT * FROM t156m INTO TABLE gt_t156m.
SORT gt_t156m BY bustm zustd cnt02.
*--} VGA ECDK935151:end
*--{ VGA ECDK937025:insert
CALL FUNCTION 'TH_REDISPATCH'.
*--} VGA ECDK937025:end
ENDIF.
************************************************************
* End Cached section
************************************************************
aktdat = sy-datlo + 30.
IF NOT ( lr_budat-high IS INITIAL OR lr_budat-high > aktdat ).
LOOP AT g_t_mseg_lean INTO g_s_mseg_lean
WHERE budat > lr_budat-high.
MOVE-CORRESPONDING g_s_mseg_lean TO imsweg.
l_append = 'X'.
IF g_s_mseg_lean-xauto IS INITIAL.
READ TABLE gt_t156m WITH KEY bustm = g_s_mseg_lean-bustm
zustd = g_s_mseg_lean-insmk
cnt02 = '01'
BINARY SEARCH.
ELSEIF g_s_mseg_lean-xauto = 'X'.
READ TABLE gt_t156m WITH KEY bustm = g_s_mseg_lean-bustm
zustd = g_s_mseg_lean-insmk
cnt02 = '02'
BINARY SEARCH.
ENDIF.
IF sy-subrc IS INITIAL.
CASE gt_t156m-smard+1(1).
WHEN '0'.
imsweg-insmk = c_labst_space.
WHEN 'Q'.
imsweg-insmk = c_insme_x.
WHEN 'S'.
imsweg-insmk = c_speme_s.
WHEN 'R'.
imsweg-insmk = lc_retme_4.
WHEN 'U'.
imsweg-insmk = lc_umlme_6.
WHEN 'K'.
imsweg-insmk = lc_einme_5.
ENDCASE.
IF NOT lc_labst_1 IN lr_insmk."Valuated Unrestricted-Use Stock
IF imsweg-insmk EQ c_labst_space OR
imsweg-insmk EQ c_labst_f.
CLEAR l_append.
ENDIF.
ENDIF.
IF NOT lc_insme_2 IN lr_insmk."Stock in Quality Inspection
IF imsweg-insmk EQ c_insme_2 OR
imsweg-insmk EQ c_insme_x.
CLEAR l_append.
ENDIF.
ENDIF.
IF NOT lc_speme_3 IN lr_insmk. "Blocked Stock
IF imsweg-insmk EQ c_speme_3 OR
imsweg-insmk EQ c_speme_s.
CLEAR l_append.
ENDIF.
ENDIF.
IF NOT lc_retme_4 IN lr_insmk. "Blocked Stock Return
IF imsweg-insmk EQ lc_retme_4.
CLEAR l_append.
ENDIF.
ENDIF.
IF NOT lc_einme_5 IN lr_insmk. "Total Stock of All Restricted Batches
IF imsweg-insmk EQ lc_einme_5.
CLEAR l_append.
ENDIF.
ENDIF.
*--{ VGA ECDK935151:insert
IF NOT lc_umlme_6 IN lr_insmk. "Stock in transfer (from one storage location to another)
IF imsweg-insmk EQ lc_umlme_6.
CLEAR l_append.
ENDIF.
ENDIF.
ELSE.
CLEAR l_append.
ENDIF.
*--} VGA ECDK935151:end
IF NOT l_append IS INITIAL.
APPEND imsweg.
ENDIF.
*--} VGA ECDK933125:end
DELETE g_t_mseg_lean.
ENDLOOP.
ENDIF.
* IF NOT index_2 IS INITIAL.
* IF bwbst = ' '.
* IF xchar = ' '.
SORT imsweg BY werks matnr shkzg. "auf Materialebene
LOOP AT imsweg.
IF ( imsweg-xauto IS INITIAL ) OR
( imsweg-bustm <> 'MA02' AND imsweg-bustm <> 'MA05' ).
MOVE-CORRESPONDING imsweg TO weg_mat.
COLLECT weg_mat.
ELSE.
DELETE imsweg.
ENDIF.
ENDLOOP.
*------------- Summen von 'datum-low' bis 'datum-high' ----------------*
* IF bwbst = ' '.
* IF xchar = ' '. "auf Materialebene
SORT g_t_mseg_lean BY werks matnr shkzg DESCENDING.
LOOP AT g_t_mseg_lean INTO g_s_mseg_lean.
IF ( g_s_mseg_lean-xauto IS INITIAL ) OR
( g_s_mseg_lean-bustm <> 'MA02' AND
g_s_mseg_lean-bustm <> 'MA05' ).
MOVE-CORRESPONDING g_s_mseg_lean TO sum_mat.
COLLECT sum_mat.
ELSE.
DELETE g_t_mseg_lean.
ENDIF.
ENDLOOP.
************************************
*FORM bestaende_berechnen.
************************************
* ELSEIF lgbst = 'X'.
*-------------------- ... auf Materialebene ---------------------------*
* IF xchar = ' '.
*--{ VGA ECDK933125:insert
IF NOT i_use_history IS INITIAL.
CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
EXPORTING
day_in = sy-datum
IMPORTING
last_day_of_month = l_date.
ELSE.
l_date = '99991231'.
ENDIF.
CONCATENATE l_date_high+0(4) l_date_high+4(2) INTO l_slper.
*--} VGA ECDK933125:end
LOOP AT imard.
*--{ VGA ECDK933125:insert
IF NOT i_use_history IS INITIAL.
* Read stocks from store location or history
IF l_date_high NE l_date.
LOOP AT gt_mardh WHERE matnr = imard-matnr AND
werks = imard-werks AND
lgort = imard-lgort.
* Format MARDH period for comparison (CCYYMM)
CONCATENATE gt_mardh-lfgja gt_mardh-lfmon INTO l_maper.
*--{ VGA ECDK934929:replace
* See Note 193554 - Stock/valuation data of previous periods
* IF l_maper GT l_slper. "Take stocks from this period!
IF l_maper GE l_slper. "Take stocks from this period!
*--} VGA ECDK934929:end
MOVE-CORRESPONDING gt_mardh TO imard.
EXIT.
ENDIF.
ENDLOOP. "at it_mardh
ENDIF.
ENDIF.
*--} VGA ECDK933125:end
MOVE-CORRESPONDING imard TO bestand.
* In 'bestand' wird uber die Lagerorte summiert.
IF NOT i_take_transit IS INITIAL.
ADD imard-umlme TO bestand-endmenge.
ENDIF.
*--{ VGA ECDK933356:end
IF lc_labst_1 IN lr_insmk."Valuated Unrestricted-Use Stock
ADD imard-labst TO bestand-endmenge.
ENDIF.
IF lc_insme_2 IN lr_insmk."Stock in Quality Inspection
ADD imard-insme TO bestand-endmenge.
ENDIF.
IF lc_speme_3 IN lr_insmk. "Blocked Stock
ADD imard-speme TO bestand-endmenge.
*--{ VGA ECDK934929:delete
* ADD imard-retme TO bestand-endmenge. "Blocked Stock Return
*--} VGA ECDK934929:end
ENDIF.
IF lc_retme_4 IN lr_insmk. "Blocked Stock Return
ADD imard-retme TO bestand-endmenge.
ENDIF.
IF lc_einme_5 IN lr_insmk. "Total Stock of All Restricted Batches
ADD imard-einme TO bestand-endmenge.
ENDIF.
*--} VGA ECDK933125:end
READ TABLE imara WITH KEY matnr = bestand-matnr.
MOVE imara-meins TO bestand-meins.
COLLECT bestand.
ENDLOOP.
IF NOT i_take_transit IS INITIAL.
* select the PO data and calculate the stock in transit
* PERFORM database_selection
* TABLES g_t_xtab6
* USING xnlcc " cross company
* xtram. " non cross company
************************************************************************
* database_selection
************************************************************************
*FORM database_selection
* tables l_t_ztab3 type stab_xtab6
* using l_cross_company type am07m-xselk
* l_non_cross_company type am07m-xselk.
* at first look for the PO headers and PO items
*
* go on when there is at least one entry in this table
*
* read the matching entries from the PO history table
* SELECT * FROM ekbe
* INTO CORRESPONDING FIELDS OF TABLE g_t_ekbe
* FOR ALL ENTRIES IN g_t_po
* WHERE ebeln = g_t_po-ebeln
* AND ebelp = g_t_po-ebelp
* AND bewtp IN gt_ra_bewtp
* AND budat LE lr_budat-high
* ORDER BY PRIMARY KEY.
REFRESH g_t_ekbe.
LOOP AT gt_ekbe_cache INTO g_s_ekbe.
CHECK g_s_ekbe-budat LE lr_budat-high.
APPEND g_s_ekbe TO g_t_ekbe.
ENDLOOP.
* process the PO data
LOOP AT g_t_po INTO g_s_po.
CLEAR g_s_xmdbs.
* look for matching PO history entries
* PERFORM get_po_history.
*----------------------------------------------------------------------*
* get_po_history
*----------------------------------------------------------------------*
*form get_po_history.
DATA : l_tabix LIKE sy-tabix.
CLEAR : g_s_xmdbs_sum, g_flag_ekbe_found.
* set start point in table gt_ekbe
READ TABLE g_t_ekbe ASSIGNING <g_fs_ekbe>
WITH KEY ebeln = g_s_po-ebeln
ebelp = g_s_po-ebelp
BINARY SEARCH.
* go on when one entry found
CHECK sy-subrc IS INITIAL.
MOVE sy-tabix TO l_tabix.
LOOP AT g_t_ekbe ASSIGNING <g_fs_ekbe>
FROM l_tabix.
IF <g_fs_ekbe>-ebeln = g_s_po-ebeln AND
<g_fs_ekbe>-ebelp = g_s_po-ebelp.
*----------------------------------------------------------------------*
* form_po_history_sums
*----------------------------------------------------------------------*
****************************
*form form_po_history_sums.
****************************
* dynamic break-point : at form_po_history_sums
IF g_flag_break-sum_ekbe = 'X'.
BREAK-POINT ID mmim_rep_mb5td.
ENDIF.
CASE <g_fs_ekbe>-bewtp. " check PO history category
WHEN 'E'. " goods receipt
MOVE 'X' TO g_flag_ekbe_found.
CASE <g_fs_ekbe>-shkzg. " consider debit/credit indicator
WHEN 'S'. "received
IF g_s_po-retpo IS INITIAL.
SUBTRACT <g_fs_ekbe>-menge FROM g_s_xmdbs_sum-wemng.
ELSE.
ADD <g_fs_ekbe>-menge TO g_s_xmdbs_sum-wemng.
ENDIF.
WHEN 'H'.
IF g_s_po-retpo IS INITIAL.
ADD <g_fs_ekbe>-menge TO g_s_xmdbs_sum-wemng.
ELSE.
SUBTRACT <g_fs_ekbe>-menge FROM g_s_xmdbs_sum-wemng.
ENDIF.
ENDCASE.
WHEN 'U'.
MOVE 'X' TO g_flag_ekbe_found.
CASE <g_fs_ekbe>-shkzg. " consider debit/credit indicator
WHEN 'H'. " delivered
IF g_s_po-retpo IS INITIAL.
ADD <g_fs_ekbe>-menge TO g_s_xmdbs_sum-wamng.
ELSE.
SUBTRACT <g_fs_ekbe>-menge FROM g_s_xmdbs_sum-wamng.
ENDIF.
WHEN 'S'.
IF g_s_po-retpo IS INITIAL.
SUBTRACT <g_fs_ekbe>-menge FROM g_s_xmdbs_sum-wamng.
ELSE.
ADD <g_fs_ekbe>-menge TO g_s_xmdbs_sum-wamng.
ENDIF.
* go on when PO history found
CHECK : g_flag_ekbe_found = 'X'.
* fill working table l_t_xmdbs with the data from
* PO header, PO item, and sums from PO history
MOVE-CORRESPONDING g_s_po TO g_s_xmdbs.
MOVE : g_s_po-menge TO g_s_xmdbs-bstmg,
g_s_xmdbs_sum-wemng TO g_s_xmdbs-wemng,
g_s_xmdbs_sum-wamng TO g_s_xmdbs-wamng.
APPEND g_s_xmdbs TO g_t_xmdbs.
* fill key table for reading Special Stock Descriptions
* IF NOT g_s_po-sobkz IS INITIAL.
* MOVE g_s_po-sobkz TO g_s_t148t-sobkz.
* COLLECT g_s_t148t INTO g_t_t148t_key.
* ENDIF.
* fill key table for the supplying plants
* IF g_s_po-reswk NE g_s_organ_reswk-werks.
* MOVE g_s_po-reswk TO g_s_organ_reswk-werks.
* COLLECT g_s_organ_reswk INTO g_t_organ_reswk_key.
* ENDIF.
ENDLOOP.
REFRESH g_t_xtab6. "structure of xtab6 !!!!!
LOOP AT g_t_xmdbs INTO g_s_xmdbs.
MOVE-CORRESPONDING g_s_xmdbs TO l_s_ztab3.
* calculate stock in transit = goods issue - goods receipt
* field WEMNG will contains negative figures because the normal
* decreases the stock in transit
COMPUTE l_s_ztab3-bstmg = g_s_xmdbs-wamng + g_s_xmdbs-wemng.
* ignore POs when GI = GR
CHECK NOT l_s_ztab3-bstmg IS INITIAL.
* R/3 can really make you go nuts with these things like returns
IF NOT g_s_xmdbs-retpo IS INITIAL.
COMPUTE l_s_ztab3-bstmg = 0 - l_s_ztab3-bstmg.
ENDIF.
* look for the bae unit of measurement
READ TABLE gt_xmara INTO l_s_xmara
WITH TABLE KEY matnr = l_s_ztab3-matnr.
IF sy-subrc IS INITIAL.
l_s_ztab3-meins = l_s_xmara-meins.
ENDIF.
** Currency fields
* COMPUTE l_s_ztab3-netwr = l_s_ztab3-bstmg
* * g_s_xmdbs-netwr
* / g_s_xmdbs-bstmg.
* l_s_ztab3-bwaer = g_s_xmdbs-waers.
*
** Convert purchase order value to local currency using fixed rate
** from PO or, if not present, actual rate of the day.
* IF l_s_t001-bukrs <> g_s_xmdbs-bukrs.
* SELECT SINGLE bukrs waers
* INTO CORRESPONDING FIELDS OF l_s_t001
* FROM t001
* WHERE bukrs = g_s_xmdbs-bukrs.
* ENDIF.
*
* l_s_ztab3-waers = l_s_t001-waers.
*
* IF l_s_ztab3-waers = l_s_ztab3-bwaer.
* l_s_ztab3-dmbtr = l_s_ztab3-netwr.
* ELSE.
* IF g_s_xmdbs-kufix IS INITIAL.
* CLEAR g_s_xmdbs-wkurs. " KURS initial --> read from TCURR
* ENDIF.
*
* CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
* EXPORTING
* date = sy-datlo
* foreign_amount = l_s_ztab3-netwr
* foreign_currency = l_s_ztab3-bwaer
* local_currency = l_s_ztab3-waers
* rate = g_s_xmdbs-wkurs
* IMPORTING
* local_amount = l_s_ztab3-dmbtr.
* ENDIF.
APPEND l_s_ztab3 TO g_t_xtab6.
ENDLOOP.
**********************************************************
*endform. " database_selection
**********************************************************
REFRESH lt_menge.
LOOP AT g_t_xtab6 INTO g_s_xtab6.
* Eliminate data not in CC-selection
READ TABLE gt_organ
WITH TABLE KEY werks = g_s_xtab6-werks
TRANSPORTING NO FIELDS.
CHECK sy-subrc = 0.
MOVE-CORRESPONDING g_s_xtab6 TO lt_menge.
COLLECT lt_menge.
ENDLOOP.
* release table space
FREE g_t_xtab6.
ENDIF.
SORT lt_menge BY matnr werks meins.
FIELD-SYMBOLS: <fs_bestand> LIKE bestand.
IF NOT i_take_transit IS INITIAL.
LOOP AT bestand ASSIGNING <fs_bestand>.
READ TABLE lt_menge
WITH KEY matnr = <fs_bestand>-matnr
werks = <fs_bestand>-werks
meins = <fs_bestand>-meins
BINARY SEARCH.
CHECK sy-subrc IS INITIAL.
<fs_bestand>-endmenge = <fs_bestand>-endmenge + lt_menge-menge.
ENDLOOP.
ENDIF.
*--{ VGA ECDK933356:end
*-------------------- ... auf Materialebene ---------------------------*
* ELSEIF lgbst = 'X'.
* IF xchar = ' '.
LOOP AT bestand.
CLEAR sum_mat-menge.
READ TABLE sum_mat WITH KEY werks = bestand-werks
matnr = bestand-matnr
shkzg = 'S'.
MOVE sum_mat-menge TO bestand-soll.
CLEAR sum_mat-menge.
READ TABLE sum_mat WITH KEY werks = bestand-werks
matnr = bestand-matnr
shkzg = 'H'.
MOVE sum_mat-menge TO bestand-haben.
bestand-anfmenge = bestand-endmenge - bestand-soll
+ bestand-haben.
MODIFY bestand.
ENDLOOP.
t_bestand[] = bestand[].
ENDFUNCTION.
_________________ Молитва - это запрос разработчику на изменение кода программы.
Last edited by vga on Mon Aug 16, 2010 2:39 pm; edited 1 time in total
INCLUDE rm07mldd.
RANGES: gr_budat FOR bkpf-budat,
gr_matnr FOR mseg-matnr,
gr_werks FOR mseg-werks,
gr_lgort FOR mseg-lgort.
DATA: gt_mseg_lean_cache TYPE stab_mseg_lean.
DATA: gt_mardh TYPE TABLE OF mardh WITH HEADER LINE.
DATA: g_use_cache TYPE c.
*--{ VGA ECDK935151:insert
DATA: gt_t156m TYPE TABLE OF t156m WITH HEADER LINE.
*--} VGA ECDK935151:end
*--{ VGA ECDK933356:insert
* Data for plant, name and company code
TYPES : BEGIN OF g_stype_organ,
werks LIKE t001w-werks,
name1 LIKE t001w-name1,
bukrs LIKE t001k-bukrs,
END OF g_stype_organ,
g_htab_organ TYPE HASHED TABLE OF g_stype_organ
WITH UNIQUE KEY werks,
g_stab_organ TYPE STANDARD TABLE OF
g_stype_organ
WITH DEFAULT KEY.
DATA : gs_organ TYPE g_stype_organ,
gt_organ TYPE g_htab_organ.
FIELD-SYMBOLS : <g_fs_organ> TYPE g_stype_organ.
DATA : g_s_organ_reswk TYPE g_stype_organ,
g_t_organ_reswk_key TYPE g_stab_organ,
g_t_organ_reswk TYPE g_htab_organ.
* for the data form the PO header EKKO and items EKPO
TYPES : BEGIN OF stype_po,
matnr LIKE ekpo-matnr,
ebeln LIKE ekpo-ebeln,
ebelp LIKE ekpo-ebelp,
pstyp LIKE ekpo-pstyp,
sobkz LIKE ekpo-sobkz,
umren LIKE ekpo-umren,
umrez LIKE ekpo-umrez,
meins LIKE ekpo-meins,
werks LIKE ekpo-werks,
bukrs LIKE ekko-bukrs,
netwr LIKE ekpo-netwr,
waers LIKE ekko-waers,
wkurs LIKE ekko-wkurs,
kufix LIKE ekko-kufix,
reswk LIKE ekko-reswk,
retpo LIKE ekpo-retpo,
menge LIKE ekpo-menge,
elikz LIKE ekpo-elikz,
loekz LIKE ekpo-loekz,
bstyp LIKE ekpo-bstyp,
ccomp TYPE ekpo-ccomp,
bsakz TYPE ekko-bsakz,
ekorg TYPE ekko-ekorg,
END OF stype_po.
DATA : g_s_po TYPE stype_po,
g_t_po TYPE STANDARD TABLE OF stype_po.
* for the data of the PO history
TYPES : BEGIN OF stype_ekbe,
ebeln LIKE ekbe-ebeln,
ebelp LIKE ekbe-ebelp,
vgabe LIKE ekbe-vgabe,
gjahr LIKE ekbe-gjahr,
belnr LIKE ekbe-belnr,
buzei LIKE ekbe-buzei,
bewtp LIKE ekbe-bewtp,
budat LIKE ekbe-budat,
menge LIKE ekbe-menge,
*--{ VGA ECDK937025:delete
* bpmng LIKE ekbe-bpmng,
*--} VGA ECDK937025:end
shkzg LIKE ekbe-shkzg,
*--{ VGA ECDK937025:delete
* matnr LIKE ekbe-matnr,
* werks LIKE ekbe-werks,
*--} VGA ECDK937025:end
END OF stype_ekbe.
DATA : gt_ekbe_cache TYPE STANDARD TABLE OF stype_ekbe.
* Interface structure for function module
TYPES : BEGIN OF stype_xtab6,
werks LIKE ekpo-werks,
matnr LIKE ekpo-matnr,
menge LIKE ekbe-menge,
meins LIKE ekpo-meins,
dmbtr LIKE ekbe-dmbtr,
waers LIKE ekbe-waers,
netwr LIKE ekpo-netwr,
bwaer LIKE ekko-waers,
ebeln LIKE ekbe-ebeln,
ebelp LIKE ekbe-ebelp,
sobkz LIKE mdbs-sobkz,
pstyp LIKE mdbs-pstyp,
bstmg LIKE ekbe-menge,
bstme LIKE ekpo-meins,
reswk LIKE ekko-reswk,
elikz LIKE ekpo-elikz,
loekz LIKE ekpo-loekz,
bstyp LIKE ekpo-bstyp,
END OF stype_xtab6,
stab_xtab6 TYPE STANDARD TABLE OF stype_xtab6
WITH DEFAULT KEY.
*--} VGA ECDK933356:end
*--{ VGA ECDK937025:insert
TYPES : BEGIN OF stype_xmara,
matnr LIKE mara-matnr,
meins LIKE mara-meins,
END OF stype_xmara,
htab_xmara TYPE HASHED TABLE OF stype_xmara
WITH UNIQUE KEY matnr.
DATA: gt_xmara TYPE htab_xmara.
*--} VGA ECDK937025:end
_________________ Молитва - это запрос разработчику на изменение кода программы.
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 can 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.