Sunteți pe pagina 1din 7

REPORT ZFI_BDC_F02

NO STANDARD PAGE HEADING LINE-SIZE 255.


***INCLUDE BDCRECX1.
******************************* Declarations
DATA BEGIN OF MESSTAB OCCURS 0.
INCLUDE STRUCTURE BDCMSGCOLL.
DATA END OF MESSTAB.
DATA BEGIN OF BDCDATA OCCURS 0.
INCLUDE STRUCTURE BDCDATA.
DATA END OF BDCDATA.
TYPES : BEGIN OF TY_BDC,
IND(1),
BLDAT(10),
BUKRS(4),
BUDAT(10),
BLART(2),
WAERS(5),
XBLNR(16),
BKTXT(25),

Indicator
Doc date
company code
Posting date
Document type
Currency Key
Reference
header text

"
"
"
"
"
"
"
"
"
"

Posting Key
GL Account
SPL GL Indicatror
Amount
assignment
Item Text
Business Area
Cost center
Order
Profit Center

BSCHL(2),
HKONT(10),
UMSKZ(1),
WRBTR(16),
ZUONR(18),
SGTXT(50),
GSBER(4),
KOSTL(10),
AUFNR(10),
PRCTR(10),

"
"
"
"
"
"
"
"

COUNTER(5) TYPE N,

" Counter

END OF TY_BDC.
DATA :

LT_HEADER TYPE TABLE OF TY_BDC WITH HEADER LINE,


LT_ITEM
TYPE TABLE OF TY_BDC WITH HEADER LINE.

DATA :

LT_FILE
LIKE TABLE OF ALSMEX_TABLINE WITH HEADER LINE,
CNT(5) TYPE N.

FIELD-SYMBOLS:<L_FS>.
******************************** Selection Screen
SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETER
: P_FILE TYPE RLGRAP-FILENAME OBLIGATORY,
P_MODE TYPE CTU_PARAMS-DISMODE.
SELECTION-SCREEN : END OF BLOCK B1.
******************************** F4 For Upload File
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'


EXPORTING
PROGRAM_NAME = SYST-REPID
DYNPRO_NUMBER = SYST-DYNNR
CHANGING
FILE_NAME
= P_FILE
EXCEPTIONS
MASK_TOO_LONG = 1
OTHERS
= 2.
IF SY-SUBRC <> 0.
ENDIF.
********************** Start Of Selection
START-OF-SELECTION.
REFRESH: BDCDATA, MESSTAB.
PERFORM UPLOAD.
PERFORM PROCESS.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&
Form UPLOAD
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM UPLOAD .
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME
= P_FILE
I_BEGIN_COL
= '1'
I_BEGIN_ROW
= '2'
I_END_COL
= '18'
I_END_ROW
= '65536'
TABLES
INTERN
= LT_FILE
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE
= 2
OTHERS
= 3.
IF SY-SUBRC <> 0.
ENDIF.
LOOP AT LT_FILE.
ASSIGN COMPONENT LT_FILE-COL
OF STRUCTURE LT_HEADER TO <L_FS>.
MOVE LT_FILE-VALUE TO <L_FS> .
AT END OF ROW.
IF LT_HEADER-IND EQ 'H'.

LT_HEADER-COUNTER = CNT + 1.
CNT = LT_HEADER-COUNTER.
APPEND LT_HEADER.
ELSE.
LT_HEADER-COUNTER = CNT.
APPEND LT_HEADER TO LT_ITEM.
ENDIF.
CLEAR LT_HEADER.
ENDAT.
ENDLOOP.
ENDFORM.

" UPLOAD

*&---------------------------------------------------------------------*
*&
Form PROCESS
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM PROCESS .
*** PERFORM OPEN_GROUP.
LOOP AT LT_HEADER.
PERFORM BDC_DYNPRO
PERFORM BDC_FIELD
PERFORM BDC_FIELD
PERFORM BDC_FIELD
PERFORM BDC_FIELD
PERFORM BDC_FIELD
PERFORM BDC_FIELD
***
PERFORM BDC_FIELD
***
PERFORM BDC_FIELD
PERFORM BDC_FIELD
PERFORM BDC_FIELD
***perform bdc_field
***

USING 'SAPMF05A' '0100'.


USING 'BDC_CURSOR'
'RF05A-NEWKO'.
USING 'BDC_OKCODE'
'/00'.
USING 'BKPF-BLDAT' LT_HEADER-BLDAT.
USING 'BKPF-BLART' LT_HEADER-BLART.
USING 'BKPF-BUKRS' LT_HEADER-BUKRS.
USING 'BKPF-BUDAT' LT_HEADER-BUDAT.
USING 'BKPF-MONAT'
'8'.
USING 'BKPF-WAERS' LT_HEADER-WAERS.
USING 'BKPF-XBLNR' LT_HEADER-XBLNR.
USING 'BKPF-BKTXT' LT_HEADER-BKTXT.
using 'FS006-DOCID'
'*'.

LOOP AT LT_ITEM WHERE COUNTER = LT_HEADER-COUNTER.


********************* Posting Key 40
IF LT_ITEM-BSCHL = '40'.
PERFORM BDC_FIELD
PERFORM BDC_FIELD

USING 'RF05A-NEWBS' LT_ITEM-BSCHL.


USING 'RF05A-NEWKO' LT_ITEM-HKONT.

PERFORM BDC_DYNPRO

USING 'SAPMF05A' '0300'.

PERFORM BDC_FIELD

USING 'BDC_CURSOR'
'BSEG-SGTXT'.

PERFORM BDC_FIELD

USING 'BDC_OKCODE'
'=ZK'.

PERFORM BDC_FIELD
PERFORM BDC_FIELD
PERFORM BDC_FIELD

USING 'BSEG-WRBTR' LT_ITEM-WRBTR.


USING 'BSEG-ZUONR' LT_ITEM-ZUONR.
USING 'BSEG-SGTXT' LT_ITEM-SGTXT.

PERFORM BDC_DYNPRO
PERFORM BDC_FIELD

USING 'SAPLKACB' '0002'.


USING 'BDC_CURSOR'
'COBL-PRCTR'.
USING 'BDC_OKCODE'
'=ENTE'.

PERFORM BDC_FIELD
PERFORM
PERFORM
PERFORM
PERFORM

BDC_FIELD
BDC_FIELD
BDC_FIELD
BDC_FIELD

PERFORM BDC_DYNPRO
PERFORM BDC_FIELD
PERFORM BDC_FIELD

USING
USING
USING
USING

'COBL-GSBER'
'COBL-KOSTL'
'COBL-AUFNR'
'COBL-PRCTR'

LT_ITEM-GSBER.
LT_ITEM-KOSTL.
LT_ITEM-AUFNR.
LT_ITEM-PRCTR.

USING 'SAPMF05A' '0330'.


USING 'BDC_CURSOR'
'RF05A-NEWKO'.
USING 'BDC_OKCODE'
'/00'.

********************** Posting Key 50


ELSEIF LT_ITEM-BSCHL = '50'.
PERFORM BDC_FIELD
PERFORM BDC_FIELD

USING 'RF05A-NEWBS'
USING 'RF05A-NEWKO'

PERFORM BDC_DYNPRO
PERFORM BDC_FIELD

USING 'SAPMF05A' '0300'.


USING 'BDC_CURSOR'
'BSEG-SGTXT'.
USING 'BDC_OKCODE'
'=ZK'.

PERFORM BDC_FIELD

LT_ITEM-BSCHL.
LT_ITEM-HKONT.

PERFORM BDC_FIELD
PERFORM BDC_FIELD
PERFORM BDC_FIELD

USING 'BSEG-WRBTR'
USING 'BSEG-ZUONR'
USING 'BSEG-SGTXT'

PERFORM BDC_DYNPRO
PERFORM BDC_FIELD

USING 'SAPLKACB' '0002'.


USING 'BDC_CURSOR'
'COBL-KOSTL'.
USING 'BDC_OKCODE'
'=ENTE'.

PERFORM BDC_FIELD
PERFORM
PERFORM
PERFORM
PERFORM

BDC_FIELD
BDC_FIELD
BDC_FIELD
BDC_FIELD

PERFORM BDC_DYNPRO
PERFORM BDC_FIELD
PERFORM BDC_FIELD

USING
USING
USING
USING

'COBL-GSBER'
'COBL-KOSTL'
'COBL-AUFNR'
'COBL-PRCTR'

LT_ITEM-WRBTR.
LT_ITEM-ZUONR.
LT_ITEM-SGTXT.

LT_ITEM-GSBER.
LT_ITEM-KOSTL.
LT_ITEM-AUFNR.
LT_ITEM-PRCTR.

USING 'SAPMF05A' '0330'.


USING 'BDC_CURSOR'
'RF05A-NEWKO'.
USING 'BDC_OKCODE'

'/00'.
ELSEIF LT_ITEM-BSCHL = '35'.
*********************posting Key 35
PERFORM BDC_FIELD
PERFORM BDC_FIELD

USING 'RF05A-NEWBS'
USING 'RF05A-NEWKO'

PERFORM BDC_DYNPRO
PERFORM BDC_FIELD

USING 'SAPMF05A' '0302'.


USING 'BDC_CURSOR'
'BSEG-SGTXT'.
USING 'BDC_OKCODE'
'=ZK'.

PERFORM BDC_FIELD
PERFORM
PERFORM
PERFORM
PERFORM

BDC_FIELD
BDC_FIELD
BDC_FIELD
BDC_FIELD

USING
USING
USING
USING

PERFORM BDC_DYNPRO
PERFORM BDC_FIELD

'BSEG-WRBTR'
'BSEG-GSBER'
'BSEG-ZUONR'
'BSEG-SGTXT'

LT_ITEM-BSCHL.
LT_ITEM-HKONT.

LT_ITEM-WRBTR.
LT_ITEM-GSBER.
LT_ITEM-ZUONR.
LT_ITEM-SGTXT.

USING 'SAPMF05A' '0332'.


USING 'BDC_CURSOR'
'RF05A-NEWUM'.
USING 'BDC_OKCODE'
'/00'.

PERFORM BDC_FIELD

ELSEIF LT_ITEM-BSCHL = '39'.


******************Posting Key 39
PERFORM BDC_FIELD
PERFORM BDC_FIELD
PERFORM BDC_FIELD

USING 'RF05A-NEWBS'
USING 'RF05A-NEWKO'
USING 'RF05A-NEWUM'

PERFORM BDC_DYNPRO
PERFORM BDC_FIELD

USING 'SAPMF05A' '0304'.


USING 'BDC_CURSOR'
'BSEG-PRCTR'.
USING 'BDC_OKCODE'
'=BS'.

PERFORM BDC_FIELD
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM

BDC_FIELD
BDC_FIELD
BDC_FIELD
BDC_FIELD
BDC_FIELD
BDC_FIELD

PERFORM BDC_DYNPRO
PERFORM BDC_FIELD

USING
USING
USING
USING
USING
USING

'BSEG-WRBTR'
'BSEG-GSBER'
'BSEG-AUFNR'
'BSEG-PRCTR'
'BSEG-ZUONR'
'BSEG-SGTXT'

LT_ITEM-WRBTR.
LT_ITEM-GSBER.
LT_ITEM-AUFNR.
LT_ITEM-PRCTR.
LT_ITEM-ZUONR.
LT_ITEM-SGTXT.

USING 'SAPMF05A' '0700'.


USING 'BDC_CURSOR'
'RF05A-NEWBS'.

ENDIF.
************************
ENDLOOP.
PERFORM BDC_DYNPRO
PERFORM BDC_FIELD

LT_ITEM-BSCHL.
LT_ITEM-HKONT.
LT_ITEM-UMSKZ.

USING 'SAPMF05A' '0330'.


USING 'BDC_CURSOR'
'RF05A-NEWKO'.

PERFORM BDC_FIELD

*
*
*

PERFORM BDC_DYNPRO
PERFORM BDC_FIELD
PERFORM BDC_FIELD

***

USING 'BDC_OKCODE'
'/00'.
USING 'SAPMF05A' '0700'.
USING 'BDC_CURSOR'
'RF05A-NEWBS'.
USING 'BDC_OKCODE'
'=BU'.

PERFORM BDC_TRANSACTION USING 'F-02'.

CALL TRANSACTION 'F-02' USING BDCDATA MODE P_MODE UPDATE 'S' MESSAGES INTO M
ESSTAB.
ENDLOOP.
*** PERFORM CLOSE_GROUP.
DELETE MESSTAB WHERE MSGV1 IS INITIAL.
LOOP AT MESSTAB WHERE MSGTYP = 'S'.
WRITE : / 'Document Posted...', MESSTAB-MSGV1.
ENDLOOP.
ENDFORM.

" PROCESS

*************************************************************
*&---------------------------------------------------------------------*
*&
Form BDC_FIELD
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->FNAM
text
*
-->FVAL
text
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDFORM.
"BDC_FIELD
*&---------------------------------------------------------------------*
*&
Form BDC_DYNPRO
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->PROGRAM
text
*
-->DYNPRO
text
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.

ENDFORM.

"BDC_DYNPRO