DATA: BEGIN OF r_vbfa,
vbelv LIKE vbfa-vbelv,
posnv LIKE vbfa-posnv,
vbeln LIKE vbfa-vbeln,
vbtyp_n LIKE vbfa-vbtyp_n,
rfmng LIKE vbfa-rfmng,
erdat LIKE vbfa-erdat,
END OF r_vbfa.
DATA: i_vbfa LIKE r_vbfa OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF r_vbep,
vbeln LIKE vbep-vbeln,
posnr LIKE vbep-posnr,
etenr LIKE vbep-etenr,
edatu LIKE vbep-edatu,
wmeng LIKE vbep-wmeng,
bmeng LIKE vbep-bmeng,
END OF r_vbep.
DATA: lfmng LIKE vbfa-rfmng,
kwmeng LIKE vbap-kwmeng,
index TYPE i,
summe TYPE p DECIMALS 2,
edatu_eintlg TYPE d,
lfnkd LIKE vblb-lfnkd,
lfdkd LIKE vblb-lfdkd.
* Kontrolle auf Belegnummer
SELECT SINGLE * FROM vbak
WHERE vbeln = vbelv.
IF sy-subrc <> 0.
RAISE beleg_ungueltig.
EXIT.
ENDIF.
* gibt es gewдhlte Eintlg. ьberhaupt ?
IF NOT etenr IS INITIAL.
SELECT SINGLE * FROM vbep
WHERE vbeln = vbelv
AND posnr = posnv
AND etenr = etenr.
IF sy-subrc <> 0.
RAISE eintlg_ungueltig.
EXIT.
ENDIF.
ENDIF.
CLEAR: lfnkd, lfdkd.
CASE vbak-vbtyp.
WHEN 'E'.
CLEAR: vblb, lfnkd.
SELECT * FROM vblb
WHERE vbeln = vbak-vbeln
ORDER BY abrdt ASCENDING.
ENDSELECT.
lfnkd = vblb-lfnkd.
lfdkd = vblb-lfdkd.
ENDCASE.
CLEAR: lfmng, kz_nixoffen.
SELECT vbelv posnv vbeln vbtyp_n rfmng erdat
FROM vbfa INTO r_vbfa
WHERE vbelv = vbelv
AND posnv = posnv.
CASE r_vbfa-vbtyp_n.
WHEN 'J'.
IF vbak-vbtyp = 'E' AND r_vbfa-vbeln > lfnkd.
* wenn Korrekturlieferung --> keine Liefermenge, Gautsch, am: 01.07.02
SELECT SINGLE * FROM likp WHERE vbeln = r_vbfa-vbeln.
IF sy-subrc <> 0. CLEAR likp. ENDIF.
IF likp-lfart <> 'ZLKO'.
ADD r_vbfa-rfmng TO lfmng.
ENDIF.
ENDIF.
IF vbak-vbtyp = 'C'.
ADD r_vbfa-rfmng TO lfmng.
ENDIF.
* WHEN 'H' OR 'T'.
* IF vbak-vbtyp = 'E' AND r_vbfa-erdat > lfdkd.
* SUBTRACT r_vbfa-rfmng FROM lfmng.
* ENDIF.
* IF vbak-vbtyp = 'C'.
* SUBTRACT r_vbfa-rfmng FROM lfmng.
* ENDIF.
ENDCASE.
ENDSELECT.
* handelt es sich um einen SD-Lieferplan oder Kauftr. ?
CASE vbak-vbtyp.
WHEN 'E'.
CLEAR kwmeng.
IF etenr IS INITIAL.
* bilde KW-Meng zu allen Einteilungen
SELECT vbeln posnr etenr edatu wmeng bmeng
FROM vbep INTO r_vbep
WHERE vbeln = vbelv
AND posnr = posnv.
ADD r_vbep-wmeng TO kwmeng.
ENDSELECT.
ELSE.
* hole Einteilungsdatum
SELECT SINGLE * FROM vbep
WHERE vbeln = vbelv
AND posnr = posnv
AND etenr = etenr.
IF sy-subrc = 0.
CLEAR edatu_eintlg.
edatu_eintlg = vbep-edatu.
* bilde KW-Meng bis zu Einteilung
SELECT vbeln posnr etenr edatu wmeng bmeng
FROM vbep INTO r_vbep
WHERE vbeln = vbelv
AND posnr = posnv
ORDER BY edatu ASCENDING.
IF r_vbep-edatu > edatu_eintlg.
EXIT.
ENDIF.
ADD r_vbep-wmeng TO kwmeng.
ENDSELECT.
ENDIF.
ENDIF.
***********
WHEN 'C'.
CLEAR kwmeng.
IF etenr IS INITIAL.
* bilde KW-Meng zu allen Einteilungen
SELECT vbeln posnr etenr edatu wmeng bmeng
FROM vbep INTO r_vbep
WHERE vbeln = vbelv
AND posnr = posnv.
ADD r_vbep-bmeng TO kwmeng.
ENDSELECT.
ELSE.
* hole Einteilungsdatum
SELECT SINGLE * FROM vbep
WHERE vbeln = vbelv
AND posnr = posnv
AND etenr = etenr.
IF sy-subrc = 0.
CLEAR edatu_eintlg.
edatu_eintlg = vbep-edatu.
* bilde KW-Meng bis zu Einteilung
SELECT vbeln posnr etenr edatu wmeng bmeng
FROM vbep INTO r_vbep
WHERE vbeln = vbelv
AND posnr = posnv
ORDER BY edatu ASCENDING.
IF r_vbep-edatu > edatu_eintlg.
EXIT.
ENDIF.
ADD r_vbep-bmeng TO kwmeng.
ENDSELECT.
ENDIF.
ENDIF.
ENDCASE.
DATA: lv_vbeln TYPE vbak-vbeln,
lv_vbelp TYPE vbap-posnr.
DATA: lt_vbap TYPE TABLE OF vbapvb,
lt_vbup TYPE TABLE OF vbupvb,
lt_vbep TYPE TABLE OF vbepvb,
lt_vbfa TYPE TABLE OF vbfavb.
lv_vbeln = '0030000103'.
lv_vbelp = '20'.
SELECT * FROM vbap INTO TABLE lt_vbap WHERE vbeln = lv_vbeln
AND posnr = lv_vbelp.
SELECT * FROM vbup INTO TABLE lt_vbup WHERE vbeln = lv_vbeln.
SELECT * FROM vbfa INTO TABLE lt_vbfa WHERE vbelv = lv_vbeln
ORDER BY PRIMARY KEY.
SORT lt_vbfa BY mandt vbelv posnv vbeln posnn vbtyp_n.
SELECT * FROM vbep INTO TABLE lt_vbep WHERE vbeln = lv_vbeln
AND posnr = lv_vbelp.
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.