Posted: Sat Apr 12, 2008 12:13 am Post subject: Фактурирование для нескольких БЕ со ссылкой на заказ клиента
Code:
REPORT ZZIVAUFT MESSAGE-ID TT.
*
* Autor : Andreas Damrath 04.11.1996
*
* Im Standard k_nnen IV-Fakturen nur f_r lieferrelevante Auftragsarten
* erstellt werden.
* Da auch f_r Dienstleistungen, f_r die nicht unbedingt Leistungen
* erbracht werden, IV-Fakturen erstellt werden sollen, wird dieser
* User-Report den Kunden erstellt.
*
* 1.) Ist im Auftrag eine IV-Relevante Position vorhanden, so wird eine
* Nachrichtenart "ZZIV" erstellt.
* 2.) мber die Nachrichtensteuerung wird der Report aufgerufen.
* Faktura-Nr in der NAST.
* Faktura-Kopf lesen
* Faktura-Position lesen
* Pr_fung IV-Relevanz ( BUKRS usw. )
* Erzeugen IV-Faktura ( GN_INVOICE_CREATE )
* Belegfluп erstellen
*
*
************************************************************************
*
* Basis-DB
TABLES : NAST,
VBRK,
VBRP,
VBFA,
VBAK,
VBAP,
KONV.
* Hilfs-DB.
TABLES : TVKO.
* Tabellen
TABLES : T001K, " f_r den Werks- und Burks-Abgleich
T001W.
*
INCLUDE RVAFSSLI. " f_r GN_INVOICE_CREATE
* Hilfsfelder
DATA : CON_X(1) VALUE 'X', " Inhalt f_r Check-Felder
IV_RELEVANT(1), " Position IV-Rel.
RC_OK(1), " f_r F2-Pos / IV-Pos vorh.
SEL_TABIX LIKE SY-TABIX, " Anzahl selektierter Fakturen
CON_POSTING, " Schalter f_r Protokoll
RETCODE LIKE SY-SUBRC. " Status f_r die Verarbeitung
DATA : CON_FKART_BILL LIKE VBRK-FKART VALUE 'F2',
CON_FKART_CRED LIKE VBRK-FKART VALUE 'G2',
CON_FKART_DEBI LIKE VBRK-FKART VALUE 'L2',
CON_FKART_RENT LIKE VBRK-FKART VALUE 'FV',
CON_FKART_MAIN LIKE VBRK-FKART VALUE 'FV',
CON_FKART_CAN1 LIKE VBRK-FKART VALUE 'S1',
CON_FKART_CAN2 LIKE VBRK-FKART VALUE 'S2'.
DATA : LOC_IV_FKARA LIKE KOMFKGN-FKARA,
LOC_FKARA_IVA LIKE KOMFKGN-FKARA VALUE 'IVA',
LOC_FKARA_IGA LIKE KOMFKGN-FKARA VALUE 'IGA'.
* Hilfstabellen
* gefundene Fakturen entsprechend der Selektion
DATA : BEGIN OF SEL_VBRK_TAB OCCURS 0.
INCLUDE STRUCTURE VBRK.
DATA : END OF SEL_VBRK_TAB.
* Fakturen mit IV-Relevanten Positionen
DATA : BEGIN OF LOC_VBRK_TAB OCCURS 0.
INCLUDE STRUCTURE VBRK.
DATA : END OF LOC_VBRK_TAB.
* Fakturapositionen die IV-Relevant sind.
DATA : BEGIN OF LOC_VBRP_TAB OCCURS 0.
INCLUDE STRUCTURE VBRP.
DATA : END OF LOC_VBRP_TAB.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF BLOCK A WITH FRAME.
SELECTION-SCREEN SKIP 1.
PARAMETERS: FAKT_VO LIKE VBRK-VBELN MATCHCODE OBJECT VMCF.
PARAMETERS: FAKT_BI LIKE VBRK-VBELN MATCHCODE OBJECT VMCF.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN END OF BLOCK A.
AT SELECTION-SCREEN.
IF FAKT_VO IS INITIAL.
MESSAGE E053 WITH TEXT-001.
ENDIF.
IF SEL_TABIX NE 0.
LOOP AT SEL_VBRK_TAB.
CLEAR IV_RELEVANT.
SELECT * FROM VBRP
WHERE VBELN EQ SEL_VBRK_TAB-VBELN.
SELECT SINGLE * FROM T001W
WHERE WERKS EQ VBRP-WERKS.
SELECT SINGLE * FROM T001K
WHERE BWKEY EQ T001W-BWKEY.
IF T001K-BUKRS NE SEL_VBRK_TAB-BUKRS.
CLEAR RC_OK.
PERFORM CHECK_IV_FAKTURA_EXIST CHANGING RC_OK.
IF RC_OK IS INITIAL.
MOVE-CORRESPONDING VBRP TO LOC_VBRP_TAB.
APPEND LOC_VBRP_TAB.
IV_RELEVANT = CON_X.
ELSE.
RETCODE = 3. " cross company is exist
ENDIF. " rc_ok is initial
ELSE.
RETCODE = 2. " VBRP not cross company
ENDIF. " t001k-bukrs ne vbrk-bukrs.
ENDSELECT. " from vbrp
IF IV_RELEVANT EQ CON_X.
MOVE-CORRESPONDING SEL_VBRK_TAB TO LOC_VBRK_TAB.
APPEND LOC_VBRK_TAB.
ENDIF. " iv_relevant eq con_x
ENDLOOP. " at loc_vbrk_tab
ENDIF. " sel_tabix ne 0.
DESCRIBE TABLE LOC_VBRK_TAB LINES SEL_TABIX.
IF SEL_TABIX NE 0.
CLEAR RETCODE.
PERFORM BASEDATE_CREATE.
* perform gn_invoice_create.
ENDIF. " sel_tabix ne 0.
ENDFORM. " iv_fakturen using iv_fakt
*eject
*---------------------------------------------------------------------*
* FORM CHECK_IV_FAKTURA_EXIST *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* <--> RC_OK *
*---------------------------------------------------------------------*
FORM CHECK_IV_FAKTURA_EXIST CHANGING RC_OK.
SELECT * FROM VBFA
WHERE VBELV EQ VBRP-VBELN
AND POSNV EQ VBRP-POSNR.
IF VBFA-VBTYP_N EQ '5' OR
VBFA-VBTYP_N EQ '6'.
RC_OK = CON_X.
EXIT.
ENDIF. " vbfa-vbtyp_n eq '5' or '6'
ENDSELECT. " from vbfa
ENDFORM. " check_iv_faktura_exist
*eject
*---------------------------------------------------------------------*
* FORM BASEDATE_CREATE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM BASEDATE_CREATE.
LOOP AT LOC_VBRK_TAB.
* Datenaufbereitung nur bei Fakturaarten
* F2 = Normalfaktura G2 = Gutschriften S1 = Storno
* MV = Mietvertraegen WV = Wartungsvertrфgen.
* Sollten andere Fakturaarten verwendet werden, so sind diese im TOP
* zu фndern.
CLEAR : XKOMFKGN, XKOMFKKO. " xkomfk, xkomv.
REFRESH : XKOMFKGN, XKOMFKKO. " xkomfk, xkomv.
IF LOC_VBRK_TAB-FKART EQ CON_FKART_BILL OR
LOC_VBRK_TAB-FKART EQ CON_FKART_CRED OR
LOC_VBRK_TAB-FKART EQ CON_FKART_DEBI OR
LOC_VBRK_TAB-FKART EQ CON_FKART_RENT OR
LOC_VBRK_TAB-FKART EQ CON_FKART_MAIN OR
LOC_VBRK_TAB-FKART EQ CON_FKART_CAN1 OR
LOC_VBRK_TAB-FKART EQ CON_FKART_CAN2.
* ermitteln der neuen IV-Fakturaart.
PERFORM IV_FKART_CREATE USING LOC_VBRK_TAB-FKART
CHANGING LOC_IV_FKARA.
XKOMFKGN-FKARA = LOC_IV_FKARA.
SELECT SINGLE * FROM TVKO
WHERE VKORG EQ LOC_VBRK_TAB-VKORG.
LOOP AT LOC_VBRP_TAB
WHERE VBELN EQ LOC_VBRK_TAB-VBELN.
XKOMFKGN-MANDT = SY-MANDT.
* lesen der Auftragsart aus dem Auftrag.
SELECT SINGLE * FROM VBAK
WHERE VBELN EQ LOC_VBRP_TAB-AUBEL.
CHECK SY-SUBRC EQ 0.
XKOMFKGN-AUART = VBAK-AUART.
XKOMFKGN-WERKS = LOC_VBRP_TAB-WERKS.
SELECT SINGLE * FROM T001W
WHERE WERKS EQ LOC_VBRP_TAB-WERKS.
XKOMFKGN-VKORG = T001W-VKORG.
XKOMFKGN-VTWEG = T001W-VTWEG.
XKOMFKGN-SPART = LOC_VBRP_TAB-SPART.
XKOMFKGN-KUNAG = TVKO-KUNNR.
XKOMFKGN-VGBEL = LOC_VBRP_TAB-VBELN.
XKOMFKGN-VGPOS = LOC_VBRP_TAB-POSNR.
* xkomfkgn-vguep = loc_vbrp_tab-uepos.
XKOMFKGN-KALSM = LOC_VBRK_TAB-KALSM.
XKOMFKGN-KWMENG = LOC_VBRP_TAB-FKIMG.
XKOMFKGN-VRKME = LOC_VBRP_TAB-VRKME.
XKOMFKGN-VGTYP = LOC_VBRK_TAB-VBTYP.
XKOMFKGN-AUBEL = LOC_VBRP_TAB-AUBEL.
XKOMFKGN-AUPOS = LOC_VBRP_TAB-AUPOS.
XKOMFKGN-FKTYP = 'A'.
XKOMFKGN-MATNR = LOC_VBRP_TAB-MATNR.
XKOMFKGN-SHKZG = LOC_VBRP_TAB-SHKZG.
IF XKOMFKGN-FKARA EQ LOC_FKARA_IVA.
XKOMFKGN-SHKZG = 'H'.
ENDIF.
* lesen der Auftragsposition um den Positionstyp festzustellen
SELECT SINGLE * FROM VBAP
WHERE VBELN EQ LOC_VBRP_TAB-AUBEL
AND POSNR EQ LOC_VBRP_TAB-AUPOS.
CHECK SY-SUBRC EQ 0.
XKOMFKGN-PSTYV = VBAP-PSTYV.
APPEND XKOMFKGN.
* lesen der Konditionssфtze zur Fakturaposition.
SELECT * FROM KONV
WHERE KNUMV EQ LOC_VBRK_TAB-KNUMV
AND KPOSN EQ LOC_VBRP_TAB-POSNR.
CHECK: KONV-KNTYP NA 'GLRIE'.
CHECK: KONV-KOAID NA 'CD'.
XKOMFKKO-MANDT = XKOMFKGN-MANDT.
XKOMFKKO-KNUMV = XKOMFKGN-VGBEL.
XKOMFKKO-KPOSN = XKOMFKGN-VGPOS.
XKOMFKKO-KSCHL = KONV-KSCHL.
XKOMFKKO-KBETR = KONV-KBETR.
XKOMFKKO-WAERS = KONV-WAERS.
IF KONV-KRECH EQ 'B'.
XKOMFKKO-KBETR = KONV-KWERT.
XKOMFKKO-WAERS = LOC_VBRK_TAB-WAERK.
ENDIF.
APPEND XKOMFKKO.
ENDSELECT. " from konv
ENDLOOP. " at loc_vbrp_tab
PERFORM GN_INVOICE_CREATE.
ENDIF. " fkart eq F2/G2/FV/FV
ENDLOOP. " at loc_vbrk_tab
ENDFORM. " basedate_create
*eject
*---------------------------------------------------------------------*
* FORM GN_INVOICE_CREATE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM GN_INVOICE_CREATE.
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.