Age: 180 Joined: 04 Oct 2007 Posts: 1218 Location: Санкт-Петербург
Posted: Thu Mar 27, 2008 10:52 am Post subject:
Документ сторнирован полностью или частично, если существует другой документ, ссылающийся на исходный через поля
MSEG-SMBLN = MSEG-MBLNR
MSEG-SJAHR = MSEG-MJAHR
MSEG-SMBLP = MSEG-ZEILE
Список сторнирующих документов виден в вьюхе M_MBMPS
Для примера кусок кода
Code:
*----------------------------------------------------------------------*
* INCLUDE *
*----------------------------------------------------------------------*
TYPE-POOLS: vrm.
CONSTANTS: c_ja VALUE 'X',
c_nein VALUE ' ',
null TYPE c VALUE '0'.
*types
TYPES: BEGIN OF t_mbew,
matnr LIKE mbew-matnr,
bwkey LIKE mbew-bwkey,
bklas LIKE mbew-bklas,
END OF t_mbew.
TYPES: BEGIN OF imrep_organ_typ,
mandt LIKE t001-mandt,
bukrs LIKE t001-bukrs,
butxt LIKE t001-butxt,
waers LIKE t001-waers,
ktopl LIKE t001-ktopl,
lfgja LIKE marv-lfgja,
lfmon LIKE marv-lfmon,
vmgja LIKE marv-vmgja,
vmmon LIKE marv-vmmon,
vjgja LIKE marv-vjgja,
vjmon LIKE marv-vjmon,
bwkey LIKE t001k-bwkey,
bwmod LIKE t001k-bwmod,
xvkbw LIKE t001k-xvkbw, " Kennzeichen: Verkaufspreisbew. aktiv
werks LIKE t001w-werks,
name1 LIKE t001w-name1,
lgort LIKE t001l-lgort,
lgobe LIKE t001l-lgobe,
END OF imrep_organ_typ.
TYPES: BEGIN OF t030_typ.
INCLUDE STRUCTURE t030.
TYPES: txt50 LIKE skat-txt50,
xkomo LIKE t030r-xkomo,
xbwmo LIKE t030r-xbwmo,
xbkla LIKE t030r-xbkla,
xdiko LIKE t030r-xdiko.
TYPES: END OF t030_typ.
TYPES: BEGIN OF mbew_typ,
mandt LIKE mbew-mandt,
matnr LIKE mbew-matnr,
bwkey LIKE mbew-bwkey,
bwtar LIKE mbew-bwtar,
lvorm LIKE mbew-lvorm,
lbkum LIKE mbew-lbkum,
* field size extended "n497391
salk3(10) TYPE p DECIMALS 2, "n497391
vprsv LIKE mbew-vprsv,
verpr LIKE mbew-verpr,
stprs LIKE mbew-stprs,
peinh LIKE mbew-peinh,
bklas LIKE mbew-bklas,
salkv LIKE mbew-salkv,
lfgja LIKE mbew-lfgja,
lfmon LIKE mbew-lfmon,
bwtty LIKE mbew-bwtty,
pstat LIKE mbew-pstat,
vksal LIKE mbew-vksal,
eklas LIKE mbew-eklas,
qklas LIKE mbew-qklas,
sobkz LIKE ebew-sobkz,
vbeln LIKE ebew-vbeln,
posnr LIKE ebew-posnr,
pspnr LIKE qbew-pspnr,
bukrs LIKE t001-bukrs,
butxt LIKE t001-butxt,
xkonto LIKE ska1-saknr,
lifnr LIKE obew-lifnr, "n497391
ke_xwart TYPE c, " Wertartikel: Verkaufswert
xvkbw LIKE t001k-xvkbw,
no_sum TYPE c.
TYPES: END OF mbew_typ.
*ranges
RANGES: r_matnr FOR mseg-matnr,
r_gjahr FOR mseg-gjahr,
r_bwkey FOR mbew-bwkey,
r_budat FOR bkpf-budat,
r_bwart FOR mseg-bwart,
r_bwart2 FOR mseg-bwart,
ibklas FOR mbew-bklas,
so_bukrs_save FOR t001-bukrs.
*data
DATA: BEGIN OF it_t001 OCCURS 0,
bukrs TYPE t001-bukrs,
END OF it_t001.
DATA: BEGIN OF xmarav OCCURS 0,
matnr LIKE marav-matnr,
mtart LIKE marav-mtart,
lvorm LIKE marav-lvorm,
meins LIKE marav-meins,
maktx LIKE marav-maktx.
DATA: END OF xmarav.
DATA: rc LIKE sy-subrc,
xkonto LIKE ska1-saknr. "Sachkonto
DATA: xmbew TYPE mbew_typ OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF material OCCURS 0,
matnr LIKE xmbew-matnr,
END OF material,
BEGIN OF it_bsim OCCURS 0,
matnr LIKE bsim-matnr,
bwkey LIKE bsim-bwkey,
bwtar LIKE bsim-bwtar,
dmbtr LIKE bsim-dmbtr,
menge LIKE bsim-menge,
meins LIKE bsim-meins,
shkzg LIKE bsim-shkzg,
budat LIKE bkpf-budat,
xauto LIKE mseg-xauto,
* bustm LIKE mseg-bustm,
* insmk LIKE mseg-insmk,
bwart LIKE mseg-bwart,
ebeln LIKE mseg-ebeln,
ebelp LIKE mseg-ebelp,
mblnr LIKE mseg-mblnr,
mjahr LIKE mseg-mjahr,
zeile LIKE mseg-zeile,
sjahr LIKE mseg-sjahr,
smbln LIKE mseg-smbln,
smblp LIKE mseg-smblp,
elikz LIKE mseg-elikz,
belnr LIKE bsim-belnr,
gjahr LIKE bsim-gjahr,
buzei LIKE bsim-buzei,
END OF it_bsim,
BEGIN OF itab_res OCCURS 0,
bwkey LIKE bsim-bwkey,
bwtar LIKE bsim-bwtar,
konto LIKE ska1-saknr,
matnr LIKE mseg-matnr,
menge LIKE mseg-menge,
meins LIKE mseg-meins,
dmbtr LIKE ckps-wertb,
waers LIKE mseg-waers,
menge_1 LIKE mseg-menge,
meins_1 LIKE mseg-meins,
dmbtr_1 LIKE ckps-wertb,
waers_1 LIKE mseg-waers,
menge_2 LIKE mseg-menge,
meins_2 LIKE mseg-meins,
dmbtr_2 LIKE ckps-wertb,
waers_2 LIKE mseg-waers,
menge_3 LIKE mseg-menge,
meins_3 LIKE mseg-meins,
dmbtr_3 LIKE ckps-wertb,
waers_3 LIKE mseg-waers,
menge_4 LIKE mseg-menge,
meins_4 LIKE mseg-meins,
dmbtr_4 LIKE ckps-wertb,
waers_4 LIKE mseg-waers,
END OF itab_res.
* AVL data
DATA: wa_res LIKE itab_res. " For double_click
DATA: message_text(40) TYPE c,
index_z LIKE sy-tabix.
DATA: BEGIN OF x030_key,
mandt LIKE sy-mandt,
ktopl LIKE t030-ktopl,
ktosl LIKE t030-ktosl,
bwmod LIKE t030-bwmod,
komok LIKE t030-komok,
bklas LIKE t030-bklas.
DATA: END OF x030_key.
DATA: BEGIN OF organ OCCURS 0. "note 358829
INCLUDE TYPE imrep_organ_typ. "note 358829
DATA: xbkla LIKE t030r-xbkla. "note 358829
DATA: END OF organ. "note 358829
DATA: it030 TYPE t030_typ OCCURS 0 WITH HEADER LINE.
DATA: alv_grid TYPE REF TO cl_gui_alv_grid,
container TYPE REF TO cl_gui_custom_container,
dt TYPE TABLE OF lvc_t_data,
gt_alv_fieldcat TYPE slis_t_fieldcat_alv,
gt_lvc_fcat TYPE lvc_t_fcat,
gl_lvc_fcat TYPE lvc_s_fcat,
gt_sort TYPE lvc_t_sort,
g_layo TYPE lvc_s_layo.
TYPES:
ty_matnrrange TYPE RANGE OF mseg-matnr,
BEGIN OF ty_bwkeyrange,
bukrs TYPE bukrs,
range TYPE RANGE OF bsim-bwkey,
END OF ty_bwkeyrange,
* Material ledger data
BEGIN OF ty_ckml,
matnr TYPE ckmlhd-matnr,
bwkey TYPE ckmlhd-bwkey,
bwtar TYPE ckmlhd-bwtar,
* vbeln TYPE ckmlhd-vbeln,
* posnr TYPE ckmlhd-posnr,
pspnr TYPE ckmlhd-pspnr,
kalnr TYPE ckmlhd-kalnr,
waers TYPE ckmlcr-waers,
salk3 TYPE ckmlcr-salk3,
bdatj TYPE ckmlcr-bdatj,
bpoper TYPE ckmlcr-poper,
END OF ty_ckml,
BEGIN OF ty_bsis,
bukrs TYPE bsis-bukrs,
belnr TYPE bsis-belnr,
gjahr TYPE bsis-gjahr,
buzei TYPE bsis-buzei,
amount TYPE bsis-wrbtr,
* wrbtr TYPE bsis-wrbtr,
* dmbe2 TYPE bsis-dmbe2,
* dmbe3 TYPE bsis-dmbe3,
* shkzg TYPE bsis-shkzg,
END OF ty_bsis,
BEGIN OF ty_currency,
number TYPE i,
cc_curtp TYPE curtp, "Currency type from company code
ml_curtp TYPE curtp, "Currency type from material ledger
waers TYPE waers, "Currency
END OF ty_currency.
DATA:
it_currency TYPE TABLE OF ty_currency,
wa_currency TYPE ty_currency,
it_bwkeytable TYPE TABLE OF ty_bwkeyrange,
wa_bwkeytable TYPE ty_bwkeyrange,
it_rangestable TYPE TABLE OF ty_matnrrange,
it_ckml TYPE TABLE OF ty_ckml,
it_ckmlcr TYPE TABLE OF ckmlcr,
* it_bsis TYPE SORTED TABLE OF ty_bsis
* WITH NON-UNIQUE KEY bukrs belnr gjahr buzei,
it_bsis TYPE TABLE OF ty_bsis
WITH NON-UNIQUE KEY belnr gjahr buzei,
* WITH HEADER LINE,
g_bwkeyrange TYPE RANGE OF bsim-bwkey,
wa_bwkeyrange LIKE LINE OF g_bwkeyrange,
g_curtp TYPE curtp,
g_multicurr TYPE char1,
g_currency_num TYPE i,
g_err_msg(100) TYPE c.
FIELD-SYMBOLS:
<fs_matnrrange> TYPE ty_matnrrange,
<fs_bwkeytable> TYPE ty_bwkeyrange,
<fs-ckml> TYPE ty_ckml,
<fs_currency> TYPE ty_currency,
<fs_bsis> TYPE ty_bsis.
DATA: t_curtp_dropdown TYPE vrm_values.
DATA: f_curtp_dropdown TYPE vrm_value.
CONSTANTS:
c_init_currency TYPE waers VALUE 'CRU'.
CONSTANTS:
c_tcode TYPE sy-tcode VALUE 'ZE_MB_TURNOVER'.
TYPES:
* ty_hkontrange TYPE RANGE OF bsis-hkont,
* Type of bsim for values
BEGIN OF ty_bsim_belnr,
matnr LIKE bsim-matnr,
bwkey LIKE bsim-bwkey,
bwtar LIKE bsim-bwtar,
* dmbtr LIKE bsim-dmbtr,
shkzg LIKE bsim-shkzg,
* budat LIKE bkpf-budat,
* belnr LIKE bsim-belnr,
* gjahr LIKE bsim-gjahr,
* buzei LIKE bsim-buzei,
dmbtr LIKE bsim-dmbtr,
END OF ty_bsim_belnr,
* Type of bsim for quantities
BEGIN OF ty_bsim_mblnr,
matnr LIKE bsim-matnr,
bwkey LIKE bsim-bwkey,
bwtar LIKE bsim-bwtar,
menge LIKE bsim-menge,
meins LIKE bsim-meins,
shkzg LIKE bsim-shkzg,
budat LIKE bkpf-budat,
bwart LIKE mseg-bwart,
xauto LIKE mseg-xauto,
ebeln LIKE mseg-ebeln,
ebelp LIKE mseg-ebelp,
elikz LIKE mseg-elikz,
mblnr LIKE mseg-mblnr,
mjahr LIKE mseg-mjahr,
zeile LIKE mseg-zeile,
sjahr LIKE mseg-sjahr,
smbln LIKE mseg-smbln,
smblp LIKE mseg-smblp,
END OF ty_bsim_mblnr.
DATA:
wa_fieldstab(72) TYPE c,
it_selecttab LIKE TABLE OF wa_fieldstab,
it_grouptab LIKE TABLE OF wa_fieldstab,
l_low_date TYPE bkpf-budat,
l_high_date TYPE bkpf-budat,
bsim_mblnr_tmp TYPE ty_bsim_mblnr.
DATA:
* Internal tables with material amounts
* 1. Amounts for current bukrs (in cycle) - In selected Period
it_bsim_belnr_bukrs_ip TYPE TABLE OF ty_bsim_belnr,
* 2. Amounts for current bukrs (in cycle) - Post Period
it_bsim_belnr_bukrs_pp TYPE TABLE OF ty_bsim_belnr,
* 3. Amounts In selected Period
it_bsim_belnr_ip TYPE TABLE OF ty_bsim_belnr,
* 2. Amounts - Post Period
it_bsim_belnr_pp TYPE TABLE OF ty_bsim_belnr,
* Internal tables with material quantities
it_bsim_mblnr TYPE TABLE OF ty_bsim_mblnr
WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK abgrenzung WITH FRAME TITLE text-001.
SELECT-OPTIONS:
s_matnr FOR mbew-matnr MATCHCODE OBJECT mat1
MEMORY ID mat,
s_bukrs FOR t001k-bukrs MEMORY ID buk,
s_bwkey FOR t001k-bwkey MEMORY ID bwk,
s_bwtar FOR mbew-bwtar MEMORY ID bwt,
s_bklas FOR mbew-bklas,
s_skont FOR ska1-saknr.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(24) text-003.
SELECTION-SCREEN POSITION 33.
PARAMETERS p_monat LIKE bkpf-monat DEFAULT sy-datum+4(2).
SELECTION-SCREEN POSITION 36.
PARAMETERS p_gjahr LIKE mseg-mjahr DEFAULT sy-datum(4).
SELECTION-SCREEN COMMENT 52(2) text-004.
SELECTION-SCREEN POSITION 58.
PARAMETERS p_monat2 LIKE bkpf-monat DEFAULT sy-datum+4(2).
SELECTION-SCREEN POSITION 61.
PARAMETERS p_gjahr2 LIKE mseg-mjahr DEFAULT sy-datum(4).
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK abgrenzung.
SELECTION-SCREEN BEGIN OF BLOCK umfang WITH FRAME TITLE text-051.
PARAMETERS:
nullb LIKE am07m-senul, " Materialien mit Nullbestand
keinzel LIKE am07m-kgebe. " Bewertungskreisebene
SELECTION-SCREEN END OF BLOCK umfang.
START-OF-SELECTION.
REFRESH s_bukrs.
INSERT LINES OF so_bukrs_save INTO TABLE s_bukrs.
PERFORM organisation.
DATA: l_poper LIKE t009b-poper.
*calculating first and last periods
MOVE 'I' TO r_gjahr-sign.
MOVE 'BT' TO r_gjahr-option.
MOVE p_gjahr TO r_gjahr-low.
MOVE p_gjahr2 TO r_gjahr-high.
APPEND r_gjahr.
MOVE 'I' TO r_budat-sign.
MOVE 'BT' TO r_budat-option.
APPEND r_budat.
MOVE 'I' TO r_bwkey-sign.
MOVE 'EQ' TO r_bwkey-option.
LOOP AT organ.
r_bwkey-low = organ-bwkey.
COLLECT r_bwkey.
ENDLOOP.
*1. Getting FI parameters
CLEAR xmbew. "388498
SELECT mandt matnr bwkey bwtar lvorm lbkum salk3
vprsv verpr stprs peinh bklas salkv lfgja lfmon
bwtty pstat vksal eklas qklas
FROM mbew INTO CORRESPONDING FIELDS OF xmbew
FOR ALL ENTRIES IN organ WHERE bwkey EQ organ-bwkey
AND matnr IN s_matnr
AND bwtar IN s_bwtar
AND bklas IN s_bklas.
CHECK NOT xmbew-bklas IS INITIAL.
APPEND xmbew.
ENDSELECT.
CLEAR xmbew. "388498
SELECT mandt matnr bwkey bwtar lbkum salk3
vprsv verpr stprs peinh bklas salkv lfgja lfmon
bwtty vksal sobkz vbeln posnr
FROM ebew INTO CORRESPONDING FIELDS OF xmbew
FOR ALL ENTRIES IN organ WHERE bwkey EQ organ-bwkey
AND matnr IN s_matnr
AND bwtar IN s_bwtar
AND bklas IN s_bklas.
CHECK NOT xmbew-bklas IS INITIAL.
xmbew-no_sum = 'X'.
APPEND xmbew.
ENDSELECT.
CLEAR xmbew. "388498
SELECT mandt matnr bwkey bwtar lbkum salk3
vprsv verpr stprs peinh bklas salkv lfgja lfmon
bwtty vksal sobkz pspnr
FROM qbew INTO CORRESPONDING FIELDS OF xmbew
FOR ALL ENTRIES IN organ WHERE bwkey EQ organ-bwkey
AND matnr IN s_matnr
AND bwtar IN s_bwtar
AND bklas IN s_bklas.
CHECK NOT xmbew-bklas IS INITIAL.
xmbew-no_sum = 'X'.
APPEND xmbew.
ENDSELECT.
* consider valuated subcontractor stocks from OBEW "n497391
CLEAR xmbew. "n497391
SELECT mandt matnr bwkey bwtar lbkum salk3 "n497391
vprsv verpr stprs peinh bklas salkv "n497391
lfgja lfmon bwtty vksal sobkz lifnr "n497391
FROM obew INTO CORRESPONDING FIELDS OF xmbew "n497391
FOR ALL ENTRIES IN organ "n497391
WHERE bwkey EQ organ-bwkey "n497391
AND matnr IN s_matnr "n497391
AND bwtar IN s_bwtar "n497391
AND bklas IN s_bklas. "n497391
CHECK NOT xmbew-bklas IS INITIAL. "n497391
xmbew-no_sum = 'X'. "n497391
APPEND xmbew. "n497391
ENDSELECT. "n497391
IF xmbew[] IS INITIAL.
MESSAGE s002(zeruxx_gc).
EXIT.
ENDIF.
* Lesen des Materialstammes:
CLEAR r_matnr.
MOVE 'I' TO r_matnr-sign.
MOVE 'EQ' TO r_matnr-option.
LOOP AT xmbew.
MOVE xmbew-matnr TO material-matnr.
COLLECT material.
MOVE xmbew-matnr TO r_matnr-low.
COLLECT r_matnr.
ENDLOOP.
* For every material we need the material master MARA. If the
* logon language is present in MAKT, we also need the text.
* INNER JOIN or OUTER JOIN cannot be used because the language-condition
* canot be handled in one statement.
SELECT matnr mtart lvorm meins "353378
INTO CORRESPONDING FIELDS OF TABLE xmarav "353378
FROM mara "353378
FOR ALL ENTRIES IN material "353378
WHERE matnr = material-matnr. "353378
PERFORM selektion_bearbeiten.
SORT xmbew BY matnr bwkey bwtar.
LOOP AT xmbew.
IF NOT keinzel IS INITIAL OR xmbew-bwtty IS INITIAL.
CHECK xmbew-bwtar IS INITIAL.
ELSEIF keinzel IS INITIAL AND NOT xmbew-bwtty IS INITIAL.
CHECK NOT xmbew-bwtar IS INITIAL.
ENDIF.
READ TABLE xmarav WITH KEY matnr = xmbew-matnr BINARY SEARCH.
IF sy-subrc IS INITIAL.
itab_res-meins = xmarav-meins.
itab_res-meins_1 = xmarav-meins.
itab_res-meins_2 = xmarav-meins.
itab_res-meins_3 = xmarav-meins.
itab_res-meins_4 = xmarav-meins.
ENDIF.
READ TABLE organ WITH KEY mandt = sy-mandt
bwkey = xmbew-bwkey BINARY SEARCH.
IF sy-subrc IS INITIAL.
itab_res-waers = organ-waers.
itab_res-waers_1 = organ-waers.
itab_res-waers_2 = organ-waers.
itab_res-waers_3 = organ-waers.
itab_res-waers_4 = organ-waers.
ENDIF.
MESSAGE s000(zeruxx_gc) WITH text-m01 INTO sy-msgli.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = sy-msgli.
* otherwise
* here get only amount
SELECT matnr bwkey
bwtar dmbtr
shkzg budat
FROM bsim
APPENDING CORRESPONDING FIELDS OF TABLE it_bsim
WHERE matnr IN r_matnr
AND bwkey IN r_bwkey
AND bwtar IN s_bwtar
AND budat >= r_budat-low.
* here get only quantity
MESSAGE s000(zeruxx_gc) WITH text-m03 INTO sy-msgli.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = sy-msgli.
SELECT i~matnr i~werks AS bwkey
i~bwtar i~menge i~meins
i~shkzg h~budat i~bwart i~xauto
i~ebeln i~ebelp i~elikz
i~mblnr i~mjahr i~zeile
i~sjahr i~smbln i~smblp
FROM mseg AS i
INNER JOIN mkpf AS h ON h~mblnr = i~mblnr
AND h~mjahr = i~mjahr
APPENDING CORRESPONDING FIELDS OF TABLE it_bsim
WHERE i~matnr IN r_matnr
AND i~werks IN r_bwkey
AND h~budat >= r_budat-low.
* exclude transfer movement
CLEAR r_bwart.
MOVE 'I' TO r_bwart-sign.
MOVE 'EQ' TO r_bwart-option.
SELECT * FROM t156t WHERE spras = 'E'.
IF t156t-btext(2) EQ 'TR' OR t156t-btext(2) EQ 'TF'.
r_bwart-low = t156t-bwart.
COLLECT r_bwart.
ENDIF.
ENDSELECT.
* here get only quantity
MESSAGE s000(zeruxx_gc) WITH text-m04 INTO sy-msgli.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = sy-msgli.
DATA: bsim_tmp LIKE it_bsim,
tabix_tmp LIKE sy-tabix.
SORT itab_res BY matnr bwkey bwtar.
SORT it_bsim BY ebeln ebelp elikz sjahr smbln smblp.
LOOP AT it_bsim.
IF NOT it_bsim-ebeln IS INITIAL AND
it_bsim-bwart IN r_bwart.
bsim_tmp = it_bsim.
tabix_tmp = sy-tabix.
* search document "Delivery completed" indicator
READ TABLE it_bsim WITH KEY ebeln = bsim_tmp-ebeln
ebelp = bsim_tmp-ebelp
elikz = 'X' BINARY SEARCH.
IF sy-subrc IS INITIAL.
* test "Delivery completed" document did't canceled
READ TABLE it_bsim WITH KEY ebeln = it_bsim-ebeln
ebelp = it_bsim-ebelp
elikz = ''
sjahr = it_bsim-mjahr
smbln = it_bsim-mblnr
smblp = it_bsim-zeile
BINARY SEARCH.
CHECK sy-subrc IS INITIAL.
* IF NOT SY-SUBRC IS INITIAL.
* IF bsim_tmp-xauto = 'X' AND (
* bsim_tmp-bwart EQ '301' OR
* bsim_tmp-bwart EQ '302' ).
* BREAK-POINT.
* ELSE.
* CONTINUE.
* ENDIF.
* ENDIF.
ENDIF.
sy-tabix = tabix_tmp.
it_bsim = bsim_tmp.
ENDIF.
IF nullb IS INITIAL.
* delete zero stock
MESSAGE s000(zeruxx_gc) WITH text-m05 INTO sy-msgli.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = sy-msgli.
DELETE itab_res
WHERE menge IS initial
AND menge_1 IS initial
AND menge_2 IS initial
AND menge_3 IS initial
AND menge_4 IS initial.
ENDIF.
Joined: 27 Mar 2008 Posts: 4 Location: moscow region
Posted: Mon Mar 31, 2008 1:40 pm Post subject: вывод нестонированных ДМ
vga, подскажите, пожалуйста, что мне нужно дописать к этому коду, чтобы получилась работоспособная полноценная программа? только data для используемых переменных?
Age: 180 Joined: 04 Oct 2007 Posts: 1218 Location: Санкт-Петербург
Posted: Mon Mar 31, 2008 2:41 pm Post subject:
Часть недостающих функций. До ума вам придется самому доводить, бизнес задачи у отчетов думаю разные.
Code:
*---------------------------------------------------------------------*
* CLASS lcl_event_receiver DEFINITION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_hotspot_click
FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING e_row_id e_column_id.
ENDCLASS.
*---------------------------------------------------------------------*
* CLASS lcl_event_receiver IMPLEMENTATION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
* Grid Event
METHOD handle_hotspot_click.
CLEAR wa_res.
READ TABLE itab_res INDEX e_row_id-index INTO wa_res.
CHECK e_row_id-rowtype IS INITIAL.
IF e_column_id-fieldname EQ 'KONTO'.
DATA l_bukrs TYPE bukrs.
SELECT SINGLE bukrs INTO l_bukrs
FROM t001k WHERE bwkey = wa_res-bwkey.
SET PARAMETER ID 'SAK' FIELD wa_res-konto.
SET PARAMETER ID 'BUK' FIELD l_bukrs.
CALL TRANSACTION 'FS03'.
ELSEIF e_column_id-fieldname EQ 'MATNR'.
SET PARAMETER ID 'MAT' FIELD wa_res-matnr.
CALL TRANSACTION 'MM03'.
ENDIF.
ENDMETHOD.
ENDCLASS.
*&---------------------------------------------------------------------*
*& Form write_to_alv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM write_to_alv TABLES itab.
ENDFORM. " write_to_alv
*&---------------------------------------------------------------------*
*& Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_9000 OUTPUT.
SET PF-STATUS '9000'.
SET TITLEBAR '9000'.
LOOP AT gt_lvc_fcat INTO gl_lvc_fcat.
CASE gl_lvc_fcat-fieldname.
WHEN 'BWKEY'.
gl_lvc_fcat-no_out = 'X'.
WHEN 'BWTAR'.
gl_lvc_fcat-no_out = 'X'.
WHEN 'MATNR'.
gl_lvc_fcat-hotspot = 'X'.
gl_lvc_fcat-fix_column = 'X'.
WHEN 'KONTO'.
gl_lvc_fcat-hotspot = 'X'.
gl_lvc_fcat-fix_column = 'X'.
WHEN 'DMBTR'.
gl_lvc_fcat-do_sum = 'X'.
gl_lvc_fcat-coltext = 'Open Amount'.
WHEN 'MENGE'.
gl_lvc_fcat-do_sum = 'X'.
gl_lvc_fcat-coltext = 'Open Quantity'.
WHEN 'DMBTR_1'.
gl_lvc_fcat-do_sum = 'X'.
gl_lvc_fcat-coltext = 'Receipt Amount'.
WHEN 'MENGE_1'.
gl_lvc_fcat-do_sum = 'X'.
gl_lvc_fcat-coltext = 'Receipt Quantity'.
WHEN 'DMBTR_2'.
gl_lvc_fcat-do_sum = 'X'.
gl_lvc_fcat-coltext = 'Issue Amount'.
WHEN 'MENGE_2'.
gl_lvc_fcat-do_sum = 'X'.
gl_lvc_fcat-coltext = 'Issue Quantity'.
WHEN 'DMBTR_3'.
gl_lvc_fcat-do_sum = 'X'.
gl_lvc_fcat-coltext = 'Turnover Amount'.
WHEN 'MENGE_3'.
gl_lvc_fcat-do_sum = 'X'.
gl_lvc_fcat-coltext = 'Turnover Quantity'.
WHEN 'DMBTR_4'.
gl_lvc_fcat-do_sum = 'X'.
gl_lvc_fcat-coltext = 'Closing Amount'.
WHEN 'MENGE_4'.
gl_lvc_fcat-do_sum = 'X'.
gl_lvc_fcat-coltext = 'Closing Quantity'.
ENDCASE.
MODIFY gt_lvc_fcat FROM gl_lvc_fcat.
ENDLOOP.
DATA:
wa_sort TYPE lvc_t_sort WITH HEADER LINE.
wa_sort-fieldname = 'KONTO'.
wa_sort-up = 'X'.
wa_sort-spos = 1.
wa_sort-subtot = 'X'.
APPEND wa_sort TO gt_sort.
DATA text(20).
g_layo-grid_title = text-060.
WRITE r_budat-low TO text.
CONCATENATE g_layo-grid_title text
INTO g_layo-grid_title SEPARATED BY space.
CLEAR text.
WRITE r_budat-high TO text.
CONCATENATE g_layo-grid_title '-' text
INTO g_layo-grid_title SEPARATED BY space.
SET HANDLER lcl_event_receiver=>handle_hotspot_click FOR alv_grid.
ENDMODULE. " PERFORM_ALV OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.
DATA: ok_code LIKE sy-ucomm.
CASE ok_code.
WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
IF NOT container IS INITIAL.
CALL METHOD container->free.
FREE container.
* CALL METHOD CL_GUI_CFW=>FLUSH.
ENDIF.
* if not alv_grid is initial.
* call method alv_grid->free.
* endif.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
*& Form ORGANISATION
*&---------------------------------------------------------------------*
* Einlesen der Tabellen T001, T001K, T030, T030R *
*----------------------------------------------------------------------*
FORM organisation.
SELECT DISTINCT t001~mandt t001~bukrs t001~butxt t001~waers t001~ktopl
t001k~bwkey t001k~bwmod t001k~xvkbw
INTO CORRESPONDING FIELDS OF TABLE organ
FROM t001 INNER JOIN t001k
ON t001~mandt = t001k~mandt AND
t001~bukrs = t001k~bukrs
WHERE t001k~bukrs IN s_bukrs
AND t001k~bwkey IN s_bwkey.
SORT organ.
* Buchungsperioden (aktuelle und Vorperioden) werden aus MARV gelesen,
* in die Organisationsatabelle ORGAN gestellt und von dort in die
* Ausgabetabellen SALDO und HEADER _bertragen
LOOP AT organ.
ON CHANGE OF organ-bukrs.
CALL FUNCTION 'MARV_SINGLE_READ'
EXPORTING
bukrs = organ-bukrs
IMPORTING
wmarv = marv
EXCEPTIONS
not_found = 1
wrong_call = 2
OTHERS = 3.
ENDON.
IF sy-subrc IS INITIAL.
MOVE-CORRESPONDING marv TO organ.
MODIFY organ.
ELSE.
DELETE organ.
ENDIF.
ENDLOOP.
* If already here not more entries in ORGAN (wrong CC or combination)
* leave. The rest of this report is not designed to recognize this
* and totally fails with SELECT ... FOR ALL ENTRIES IN ORGAN.
CHECK NOT organ[] IS INITIAL. "357162
* 'inner join' ist nur f_r transparente Tabellen, jedoch nicht f_r
* Pooltabellen m_glich.
SELECT * FROM t030r
FOR ALL ENTRIES IN organ WHERE ktopl EQ organ-ktopl
AND ktosl EQ 'BSX'.
IF t030r-xbkla IS INITIAL.
CLEAR s_bklas. REFRESH s_bklas.
ENDIF.
SELECT * FROM t030 WHERE ktopl EQ t030r-ktopl
AND ktosl EQ 'BSX'
AND bklas IN s_bklas
AND konts IN s_skont.
* Stimmt die automatische Kontenfindung f_r die Bestandsbuchung
* mit den zulфssigen Customizing-Einstellungen (vergleiche mit
* Include DFKB1INT) _berein (keine Kontomodifikation und keine
* voneinander abweichende Soll- und Habenkonten erlaubt)?
IF NOT t030-komok IS INITIAL OR "note209823
t030-konts NE t030-konth. "note209823
MOVE t030-ktopl TO message_text.
WRITE 'BSX' TO message_text+10.
WRITE t030-konts TO message_text+20.
CONDENSE message_text.
MESSAGE s147(m8) WITH message_text.
* Kontenfindung f_r den Eintrag & nicht m_glich
EXIT.
ENDIF.
ON CHANGE OF t030-ktopl OR t030-konts.
SELECT SINGLE * FROM skat WHERE spras = sy-langu
AND ktopl = t030-ktopl
AND saknr = t030-konts.
ENDON.
MOVE-CORRESPONDING t030 TO it030.
MOVE-CORRESPONDING skat TO it030.
MOVE-CORRESPONDING t030r TO it030.
APPEND it030.
ENDSELECT.
* Bewertungsmodifikation eingeschaltet?
IF t030r-xbwmo IS INITIAL. "note 358829
LOOP AT organ WHERE ktopl EQ t030r-ktopl "note 358829
AND bwmod NE space. "note 358829
CLEAR organ-bwmod. "note 358829
MODIFY organ. "note 358829
ENDLOOP. "note 358829
ENDIF. "note 358829
LOOP AT organ WHERE ktopl EQ t030r-ktopl. "note 358829
organ-xbkla = t030r-xbkla. "note 358829
MODIFY organ. "note 358829
ENDLOOP. "note 358829
ENDSELECT.
SORT it030 BY bklas.
IF NOT s_skont IS INITIAL.
DESCRIBE TABLE it030 LINES index_z.
IF index_z IS INITIAL.
MESSAGE s055 WITH s_skont-low s_bukrs-low.
* Das Sachkonto & ist im Buchungskreis & nicht vorhanden
EXIT.
ENDIF.
LOOP AT it030.
ON CHANGE OF it030-bklas.
CHECK it030-bklas IN s_bklas.
MOVE 'I' TO ibklas-sign.
MOVE 'EQ' TO ibklas-option.
MOVE it030-bklas TO ibklas-low.
APPEND ibklas.
ENDON.
ENDLOOP.
DESCRIBE TABLE ibklas LINES index_z.
IF index_z IS INITIAL.
MESSAGE s843.
* Zu den vorgegebenen Daten ist kein Bestand vorhanden
EXIT.
ENDIF.
ENDIF.
SORT it030.
ENDFORM. " ORGANISATION
*&---------------------------------------------------------------------*
*& Form SELEKTION_BEARBEITEN
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM selektion_bearbeiten.
SORT xmbew BY bwkey bklas.
LOOP AT xmbew.
* Wertartikel: Verkaufswerte anzeigen
READ TABLE organ WITH KEY mandt = sy-mandt
bwkey = xmbew-bwkey BINARY SEARCH.
IF NOT organ-xvkbw IS INITIAL.
* Verkaufspreisbewertung ist in diesem Bewertungskreis aktiv geschaltet.
* Es muп gepr_ft werden, ob es sich um einen Wertartikel handelt.
MOVE c_ja TO xmbew-xvkbw.
READ TABLE xmarav "353378
WITH KEY matnr = xmbew-matnr BINARY SEARCH."353378
* Die Materialart des Artikels wird gelesen:
SELECT SINGLE * FROM t134m WHERE bwkey = xmbew-bwkey
AND mtart = xmarav-mtart.
IF sy-subrc IS INITIAL.
IF t134m-wertu = c_ja AND t134m-mengu = c_nein.
* Es handelt sich um einen Wertartikel
MOVE c_ja TO xmbew-ke_xwart.
ELSE.
* Es handelt sich nicht um einen Wertartikel
MOVE c_nein TO xmbew-ke_xwart.
ENDIF.
ELSE.
* Materialart nicht gefunden.
* error fixed ( reported by extended syntax check ) "n490469
MESSAGE s001 "n490469
WITH 'T134M' xmbew-bwkey xmarav-mtart space. "n490469
ENDIF.
ELSE.
MOVE c_nein TO xmbew-ke_xwart.
MOVE c_nein TO xmbew-xvkbw.
ENDIF.
* IF xmbew-ke_xwart IS INITIAL. "Nullbestand
* IF xmbew-lbkum = null.
* DELETE xmbew.
* CHECK xmbew-lbkum NE null.
* ENDIF.
* ELSEIF NOT xmbew-ke_xwart IS INITIAL.
* IF xmbew-vksal = null.
* DELETE xmbew.
* CHECK xmbew-vksal NE null.
* ENDIF.
* ENDIF.
ON CHANGE OF xmbew-bklas OR xmbew-bwkey.
rc = 0.
PERFORM sachkonto.
ENDON.
IF rc NE 0.
DELETE xmbew.
CHECK rc = 0.
ENDIF.
MOVE xkonto TO xmbew-xkonto.
MOVE organ-bukrs TO xmbew-bukrs.
MOVE organ-butxt TO xmbew-butxt.
MODIFY xmbew.
ENDLOOP.
ENDFORM. " SELEKTION_BEARBEITEN
*---------------------------------------------------------------------*
* FORM SACHKONTO *
*---------------------------------------------------------------------*
* Ermitteln Sachkonto und Sachkontentext *
*---------------------------------------------------------------------*
FORM sachkonto.
CLEAR: organ, it030.
READ TABLE organ WITH KEY bwkey = xmbew-bwkey.
x030_key-mandt = sy-mandt.
x030_key-ktopl = organ-ktopl.
x030_key-ktosl = 'BSX'.
x030_key-bwmod = organ-bwmod.
x030_key-bklas = xmbew-bklas. "note 358829
IF organ-xbkla IS INITIAL. "note 358829
CLEAR x030_key-bklas. "note 358829
ENDIF. "note 358829
READ TABLE it030 WITH KEY x030_key.
xkonto = it030-konts.
IF NOT sy-subrc IS INITIAL.
rc = 4.
ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
* FORM print_report *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM print_report.
LOOP AT gt_alv_fieldcat INTO wa_alv_fieldcat.
CASE wa_alv_fieldcat-fieldname.
WHEN 'BWKEY'.
wa_alv_fieldcat-no_out = 'X'.
WHEN 'BWTAR'.
wa_alv_fieldcat-no_out = 'X'.
WHEN 'MATNR'.
wa_alv_fieldcat-hotspot = 'X'.
wa_alv_fieldcat-fix_column = 'X'.
WHEN 'KONTO'.
wa_alv_fieldcat-hotspot = 'X'.
wa_alv_fieldcat-fix_column = 'X'.
WHEN 'DMBTR'.
rename_field 'Open Amount'.
WHEN 'MENGE'.
rename_field 'Open Quantity'.
WHEN 'DMBTR_1'.
rename_field 'Receipt Amount'.
WHEN 'MENGE_1'.
rename_field 'Receipt Quantity'.
WHEN 'DMBTR_2'.
rename_field 'Issue Amount'.
WHEN 'MENGE_2'.
rename_field 'Issue Quantity'.
WHEN 'DMBTR_3'.
rename_field 'Turnover Amount'.
WHEN 'MENGE_3'.
rename_field 'Turnover Quantity'.
WHEN 'DMBTR_4'.
rename_field 'Closing Amount'.
WHEN 'MENGE_4'.
rename_field 'Closing Quantity'.
ENDCASE.
MODIFY gt_alv_fieldcat FROM wa_alv_fieldcat.
ENDLOOP.
DATA:
lt_sort TYPE slis_t_sortinfo_alv,
wa_sort TYPE slis_sortinfo_alv.
wa_sort-fieldname = 'KONTO'.
wa_sort-up = 'X'.
wa_sort-spos = 1.
wa_sort-subtot = 'X'.
APPEND wa_sort TO lt_sort.
DATA text(20).
g_layo-grid_title = text-060.
WRITE r_budat-low TO text.
CONCATENATE g_layo-grid_title text
INTO g_layo-grid_title SEPARATED BY space.
CLEAR text.
WRITE r_budat-high TO text.
CONCATENATE g_layo-grid_title '-' text
INTO g_layo-grid_title SEPARATED BY space.
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.