Posted: Sat Sep 22, 2007 7:49 pm Post subject: Create document using Batch-input for 'FB01'
Batch input - Example 2 Upload transactions from Excel and book them ( FI )
Code:
REPORT ZKVTBOGF LINE-SIZE 180.
***************************************************************
* D A T A D E F I N I T I O N S
***************************************************************
TABLES: T001.
*--------------------------------------------------------------
* T Y P E R
*--------------------------------------------------------------
TYPES:
*----- Til indlæsning af rå data fra excel
BEGIN OF T_CSVFIL,
FELT1(300) TYPE C,
END OF T_CSVFIL,
*----- Data opslittet på felter fra t_csvfil
BEGIN OF T_BOGFDATA,
DBSCHL LIKE BSEG-BSCHL,
DHKONT LIKE BSEG-HKONT,
KBSCHL LIKE BSEG-BSCHL,
KHKONT LIKE BSEG-HKONT,
GSBER(4) TYPE C,
WAERS(5) TYPE C,
WRBTR(15) TYPE C,
DMBTR(15) TYPE C,
KOSTL(10) TYPE C,
ZUONR(1 TYPE C,
SGTXT(50) TYPE C,
END OF T_BOGFDATA.
*--------------------------------------------------------------
* D A T A
*--------------------------------------------------------------
DATA:
*---- Tabel til input af csv fil fra PC
I_CSVFIL TYPE T_CSVFIL OCCURS 100 WITH HEADER LINE,
*---- Opsplitning af de indlæste data i felter
I_BOGFDATA TYPE T_BOGFDATA OCCURS 100 WITH HEADER LINE,
*---- Tabel til koncvertering af felter til korrekt format
BEGIN OF I_BOGTAB OCCURS 500,
BUKRS LIKE BKPF-BUKRS,
BELNR LIKE BKPF-BELNR,
BLART LIKE BKPF-BLART,
BLDAT(10) TYPE C,
BUDAT(10) TYPE C,
CPUDT LIKE BKPF-CPUDT,
CPUTM LIKE BKPF-CPUTM,
AEDAT LIKE BKPF-AEDAT,
USNAM LIKE BKPF-USNAM,
TCODE LIKE BKPF-TCODE,
* bvorg like bkpf-bvorg,
XBLNR LIKE BKPF-XBLNR,
* dbblg like bkpf-dbblg,
BKTXT LIKE BKPF-BKTXT,
WAERS LIKE BKPF-WAERS,
* hwaer like bkpf-hwaer,
BUPER LIKE BSEG-ABPER,
DMBTR LIKE GLT0-TSL01,
WRBTR LIKE GLT0-TSL01,
HKONT LIKE BSEG-HKONT,
GSBER LIKE BSEG-GSBER,
KOSTL LIKE BSEG-KOSTL,
PRCTR LIKE BSEG-PRCTR,
AUFNR LIKE BSEG-AUFNR,
BSCHL LIKE BSEG-BSCHL,
ZUONR LIKE BSEG-ZUONR,
SGTXT LIKE BSEG-SGTXT,
END OF I_BOGTAB,
*---- Bruges til at gemme oplysninger fra forrige post
*---- der skal bogføres på næste skærm
I_OLD_BOGTAB LIKE I_BOGTAB OCCURS 1 WITH HEADER LINE.
*---- Internal table to store the data in dynpro format
DATA: BEGIN OF BDC_TAB OCCURS 5.
INCLUDE STRUCTURE BDCDATA.
DATA: END OF BDC_TAB.
*---- Størrelse på den indlæste fladfil
DATA: SIZE TYPE I.
***************************************************************
* S E L E C T I O N S C R E E N
***************************************************************
PARAMETERS:
* s_maxlin type i default 10, kun test
S_BUDAT LIKE BKPF-BUDAT DEFAULT SY-DATUM,
S_BLDAT LIKE BKPF-BLDAT DEFAULT SY-DATUM,
GROUP(12) OBLIGATORY DEFAULT 'KVT. BILAG', "session-ID
USER(12) OBLIGATORY DEFAULT SY-UNAME,
"user for start session in batch
KEEP AS CHECKBOX, "' ' = delete session if finished
"'X' = keep session if finished
HOLDDATE LIKE SY-DATUM.
***************************************************************
* E V E N T S
***************************************************************
*--------------------------------------------------------------
* S T A R T - O F - S E L E C T I O N
*--------------------------------------------------------------
START-OF-SELECTION.
PERFORM UPLOAD_FROM_DISK.
PERFORM FLYT_TIL_BOGTAB.
PERFORM DAN_BTCI_BILAG.
*--------------------------------------------------------------
* E N D - O F - S E L E C T I O N
*--------------------------------------------------------------
END-OF-SELECTION.
PERFORM SKRIV_RAPPORT.
***************************************************************
* F O R M S EXCL. BTCI
***************************************************************
*--------------------------------------------------------------
* F O R M U P L O A D _ F R O M _ D I S K
*
* Indlæser csv-fil fra disk. Filen læses først ind i tabellen
* i_csvfil hvor hver record kun består af en linie. Herefter
* deles denne linie op variable og lægges i i_bogfdata
*--------------------------------------------------------------
FORM UPLOAD_FROM_DISK.
DATA:
* Temporære mellemlagringsfelter
FB(2) TYPE C,
OMKSTED( TYPE C.
LOOP AT I_CSVFIL.
SPLIT I_CSVFIL-FELT1 AT ';' INTO I_BOGFDATA-DBSCHL
I_BOGFDATA-DHKONT
I_BOGFDATA-KBSCHL
I_BOGFDATA-KHKONT
I_BOGFDATA-GSBER
I_BOGFDATA-WAERS
I_BOGFDATA-WRBTR
I_BOGFDATA-DMBTR
FB
OMKSTED
I_BOGFDATA-ZUONR
I_BOGFDATA-SGTXT.
CONCATENATE FB OMKSTED INTO I_BOGFDATA-KOSTL.
APPEND I_BOGFDATA.
ENDLOOP.
SORT I_BOGFDATA BY WAERS.
ENDFORM.
*--------------------------------------------------------------
* F O R M F L Y T _ T I L _ B O G T A B
*
* Felterne færdigformateres og data gemmes i_bogtab
*--------------------------------------------------------------
FORM FLYT_TIL_BOGTAB.
* Bruges i test til at begrænse indlæsning
* data: test_antal type i.
*--------------------------------------------------------------
* F O R M S K R I V _ R A P P O R T
* Udskriver rapport over indlæste transer
*--------------------------------------------------------------
FORM SKRIV_RAPPORT.
LOOP AT I_BOGTAB.
WRITE: / I_BOGTAB-BSCHL,
I_BOGTAB-BUKRS,
I_BOGTAB-HKONT,
I_BOGTAB-KOSTL,
I_BOGTAB-GSBER,
I_BOGTAB-WAERS,
I_BOGTAB-DMBTR,
I_BOGTAB-WRBTR.
ENDLOOP.
ENDFORM.
***************************************************************
* F O R M S B T C I
***************************************************************
* D A N _ B T C I _ B I L A G
* Danner btci bilag
*--------------------------------------------------------------
FORM DAN_BTCI_BILAG.
DATA: ANTAL_LINIER TYPE I,
* Angiver om bilaget er bogført ( Bruges ved afslutning )
IS_BOOKED TYPE I.
IF ANTAL_LINIER = -1.
* Opret de t allerførste bilag
PERFORM NEW_DOCUMENT.
I_OLD_BOGTAB-WAERS = I_BOGTAB-WAERS.
ANTAL_LINIER = 0.
ELSEIF ANTAL_LINIER > 901 OR
I_BOGTAB-WAERS <> I_OLD_BOGTAB-WAERS.
* Afslut gammelt bilag
PERFORM BOOK_DOCUMENT.
IS_BOOKED = 1.
* Lav nyt bilag
* antal_linier = -1.
ANTAL_LINIER = 0.
PERFORM NEW_DOCUMENT.
ELSE.
* Ny linie
PERFORM DOCUMENT_LINE.
ANTAL_LINIER = ANTAL_LINIER + 1.
ENDIF.
* Max 999 linier i et bilag, afslut gammelt bilag og opret nyt
* Bemærk at max tallet skal være ulige, for at sikre at
* både debet og kredit posten bliver bogført i samme bilag
* if antal_linier > 901 or
* i_bogtab-waers <> i_old_bogtab-waers.
* Afslut gammelt bilag
* perform book_document.
* is_booked = 1.
* Lav nyt bilag
* antal_linier = -1.
* endif.
* Da en dynpro skal indeholde data fra den foregående
* record, er det nødvendigt at gemme disse data
I_OLD_BOGTAB = I_BOGTAB.
ENDLOOP.
IF IS_BOOKED = 0.
PERFORM BOOK_DOCUMENT.
ENDIF.
PERFORM CLOSE_GROUP.
ENDFORM.
*---------------------------------------------------------------------
* F O R M O P E N _ G R O U P
* Åben BTCI session
*---------------------------------------------------------------------
FORM OPEN_GROUP.
* skip.
* write: /(20) 'Create group'(i01), group.
* skip.
* open batchinput group
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = GROUP
USER = USER
KEEP = KEEP
HOLDDATE = HOLDDATE.
WRITE: /(30) 'BDC_OPEN_GROUP'(I02),
(12) 'returncode:'(I05),
SY-SUBRC.
ENDFORM. " OPEN_GROUP
*---------------------------------------------------------------------
* F O R M N E W _ D O C U M E N T
* Dan bilagshoved
*---------------------------------------------------------------------
FORM NEW_DOCUMENT.
REFRESH BDC_TAB.
* Læs firmakode oplysninger for det aktuelle selskab
PERFORM LES_T001.
ENDFORM. " NEW_DOCUMENT
*---------------------------------------------------------------------
* F O R M D O C U M E N T _ L I N E
* Danner en bilagslinie
*---------------------------------------------------------------------
FORM DOCUMENT_LINE.
DATA: TEXT_DMBTR(16) TYPE C,
TEXT_WRBTR(16) TYPE C.
* Formater beløb. For det tilfældes skyld at firmakode valuta
* ikke er dkk formateres i overensttemmelse med anden valuta
* iflg. t001.
WRITE I_OLD_BOGTAB-DMBTR
CURRENCY T001-WAERS NO-SIGN TO TEXT_DMBTR.
WRITE I_OLD_BOGTAB-WRBTR
CURRENCY I_OLD_BOGTAB-WAERS NO-SIGN TO TEXT_WRBTR.
* Beløbet skal kun udfyldes hvis bilagets
* valuta <> Company Code valuta.
IF I_OLD_BOGTAB-WAERS NE T001-WAERS.
PERFORM DYNPRO USING:
' ' 'BSEG-DMBTR' TEXT_DMBTR.
ENDIF.
*-- Dette er et ekstra skærmbillede der ikke ses ved
*-- on-line bogføring. Her skal/kan indsætteks kossted og fo område
PERFORM DYNPRO USING:
'X' 'SAPLKACB' '0002',
' ' 'BDC_OKCODE' '/8',
' ' 'COBL-GSBER' I_OLD_BOGTAB-GSBER.
* Koststed skal kun anvendes når der er tale om en driftskonto
IF I_OLD_BOGTAB-HKONT < 70000000.
PERFORM DYNPRO USING:
' ' 'COBL-KOSTL' I_OLD_BOGTAB-KOSTL.
ENDIF.
ENDFORM. " DOCUMENT_LINE
*---------------------------------------------------------------------
* F O R M B O O K _ D O C U M E N T
* Færdigbogføring af bilag. Bemærk at den sidste bilagslinie
* skal registreres før bogføringen gennemføres
*---------------------------------------------------------------------
FORM BOOK_DOCUMENT.
DATA: TEXT_DMBTR(16) TYPE C,
TEXT_WRBTR(16) TYPE C.
* Formater beløb. For det tilfældes skyld at firmakode valuta
* ikke er dkk formateres i overensttemmelse med anden valuta
* iflg. t001.
WRITE I_OLD_BOGTAB-DMBTR
CURRENCY T001-WAERS NO-SIGN TO TEXT_DMBTR.
WRITE I_OLD_BOGTAB-WRBTR
CURRENCY I_OLD_BOGTAB-WAERS NO-SIGN TO TEXT_WRBTR.
' ' 'BSEG-SGTXT' I_OLD_BOGTAB-SGTXT,
' ' 'BSEG-WRBTR' TEXT_WRBTR.
* Beløbet skal kun udfyldes hvis bilagets
* valuta <> Company Code valuta.
IF I_OLD_BOGTAB-WAERS NE T001-WAERS.
PERFORM DYNPRO USING:
' ' 'BSEG-DMBTR' TEXT_DMBTR.
ENDIF.
*-- Dette er et ekstra skærmbillede der ikke ses ved
*-- on-line bogføring. Her skal/kan indsætteks kossted og fo område
PERFORM DYNPRO USING:
'X' 'SAPLKACB' '0002',
' ' 'BDC_OKCODE' '/8',
' ' 'COBL-GSBER' I_OLD_BOGTAB-GSBER.
* Koststed skal kun anvendes når der er tale om en driftskonto
IF I_OLD_BOGTAB-HKONT < 70000000.
PERFORM DYNPRO USING:
' ' 'COBL-KOSTL' I_OLD_BOGTAB-KOSTL.
ENDIF.
* Bogfør
PERFORM BDC_TRANSACTION USING 'FB01'.
ENDFORM. " BOOK_DOCUMENT
*---------------------------------------------------------------------
* F O R M B D C _ T R A N S A C T I O N
* Dan Batch input bilag
*----------------------------------------------------------------------*
FORM BDC_TRANSACTION USING TCODE.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = TCODE
TABLES
*---------------------------------------------------------------------
* F O R M C L O S E _ G R O U P
* Luk batch input session
*---------------------------------------------------------------------
FORM CLOSE_GROUP.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
ENDFORM. " CLOSE_GROUP
*---------------------------------------------------------------------
* F O R M D Y N P R O
*---------------------------------------------------------------------
FORM DYNPRO USING DYNBEGIN NAME VALUE.
IF DYNBEGIN = 'X'.
CLEAR BDC_TAB.
MOVE: NAME TO BDC_TAB-PROGRAM,
VALUE TO BDC_TAB-DYNPRO,
'X' TO BDC_TAB-DYNBEGIN.
APPEND BDC_TAB.
ELSE.
CLEAR BDC_TAB.
MOVE: NAME TO BDC_TAB-FNAM,
VALUE TO BDC_TAB-FVAL.
APPEND BDC_TAB.
ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
* F O R M L E S _ T 0 0 1
* Læser oplysninger fra firmakode tabellen
*---------------------------------------------------------------------*
FORM LES_T001.
SELECT SINGLE * FROM T001 CLIENT SPECIFIED
WHERE MANDT = SY-MANDT AND
BUKRS = I_BOGTAB-BUKRS.
ENDFORM. " LES_T001
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.