Posted: Fri Oct 12, 2007 12:07 am Post subject: Salary upload using BDC
See the sample BDC program for a FI transaction
look at it and do the recording for FB50 using SHDB and do it.
Code:
REPORT ZFIBDC1_1 NO STANDARD PAGE HEADING MESSAGE-ID ZT.
***********************************************************************
* Declaration of internal tables
************************************************************************
* internal table for selecting data from flat file
DATA : BEGIN OF IT_DATA OCCURS 0,
BLDAT(10), " Document Date
BUDAT(10), " Posting date
NEWBS(2), " Posting key
NEWKO(17), " Vendor account
NEWUM, " G/L indicator
WRBTR(16), " Amount
SGTXT(50), " Text
PRCTR(10), " Profit center
END OF IT_DATA.
* internal table for bdcdata
DATA : IT_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
* internal table to handle messages
DATA : IT_MESSAGES LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
************************************************************************
* Variables & Flag declaration
************************************************************************
* variables declaration
DATA : V_MESG(50).
* flag declaration
DATA : V_BLART(2) VALUE 'AB', " Document Type
V_NEWBS1(2) VALUE '40', " Posting Key
V_NEWKO1(17) VALUE '171110 ', " GL account
FG_BDC,
FG_FLAG1 TYPE I.
************************************************************************
* selection screen
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.
************************************************************************
* parameter
************************************************************************
PARAMETERS : P_FILE LIKE RLGRAP-FILENAME OBLIGATORY.
SELECTION-SCREEN END OF BLOCK BLK1.
************************************************************************
* initialization
************************************************************************
INITIALIZATION.
* peform to initialize parameter
PERFORM INIT_PARM.
************************************************************************
* start of selection
************************************************************************
start-of-selection.
* perform to upload it_data
PERFORM UP_LOAD_IT_DATA.
* perform transfer data
PERFORM TRANSFER_DATA.
* end of selection
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form INIT_PARM
*&---------------------------------------------------------------------*
* Initializing parameter
*----------------------------------------------------------------------*
FORM INIT_PARM.
P_FILE = 'C:\'.
ENDFORM. " INIT_PARM
*&---------------------------------------------------------------------*
*& Form UP_LOAD_IT_DATA
*&---------------------------------------------------------------------*
* Transfering data from file to internal table
*----------------------------------------------------------------------*
FORM UP_LOAD_IT_DATA.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = P_FILE
FILETYPE = 'ASC'
TABLES
DATA_TAB = IT_DATA
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TABLE_WIDTH = 4
INVALID_TYPE = 5
NO_BATCH = 6
UNKNOWN_ERROR = 7
GUI_REFUSE_FILETRANSFER = 8
OTHERS = 9.
IF SY-SUBRC = 2 .
FG_FLAG1 = 1.
MESSAGE I001.
ENDIF.
ENDFORM. " UP_LOAD_IT_DATA
*&---------------------------------------------------------------------*
*& Form TRANSFER_DATA
*&---------------------------------------------------------------------*
* Processing the data
*----------------------------------------------------------------------*
FORM TRANSFER_DATA.
FG_BDC = 'N'.
LOOP AT IT_DATA.
* perform to fill it_bdcdata.
PERFORM FILL_IT_BDCDATA.
CALL TRANSACTION 'F-51' USING IT_BDCDATA MODE 'N' UPDATE 'S'
MESSAGES INTO IT_MESSAGES.
IF SY-SUBRC <> 0.
FG_FLAG1 = 1.
* if error occurs in transaction mode run bdc session for that data
PERFORM BDC_PROCESS.
ENDIF.
* Handles error messages
PERFORM ERROR_MESSAGES.
CLEAR : IT_BDCDATA,IT_DATA,IT_MESSAGES.
REFRESH : IT_BDCDATA,IT_MESSAGES.
ENDLOOP.
IF FG_FLAG1 = 0.
MESSAGE I003.
ENDIF.
IF FG_BDC = 'O'.
* close bdc if it is open
PERFORM CLOSE_BDC.
ENDIF.
ENDFORM. " TRANSFER_DATA
*&---------------------------------------------------------------------*
*& Form FILL_IT_BDCDATA
*&---------------------------------------------------------------------*
* Filling Bdcdata structure with it_data
* Some fields have been commented for future updations --------------*
*----------------------------------------------------------------------*
FORM FILL_IT_BDCDATA.
PERFORM BDC_DYNPRO USING : 'SAPMF05A' '0122'.
PERFORM BDC_FIELD USING : 'BDC_OKCODE' '/00',
: 'BDC_CURSOR' 'RF05A-NEWUM',
: 'BKPF-BLDAT' IT_DATA-BLDAT,
: 'BKPF-BLART' V_BLART,
: 'BKPF-BUKRS' 'NBC1',
: 'BKPF-BUDAT' IT_DATA-BUDAT,
: 'BKPF-WAERS' 'INR',
: 'RF05A-NEWBS' IT_DATA-NEWBS,
: 'RF05A-NEWKO' 'E1',
: 'RF05A-NEWUM' IT_DATA-NEWUM,
: 'RF05A-XPOS1(04)' 'X'.
IF IT_DATA-NEWUM IS INITIAL.
PERFORM BDC_DYNPRO USING : 'SAPMF05A' '0302'.
PERFORM BDC_FIELD USING : 'BDC_OKCODE' '/00',
'BDC_CURSOR' 'RF05A-NEWKO',
'BSEG-WRBTR' IT_DATA-WRBTR,
'BSEG-SGTXT' IT_DATA-SGTXT,
'RF05A-NEWBS' V_NEWBS1,
'RF05A-NEWKO' V_NEWKO1.
PERFORM BDC_DYNPRO USING : 'SAPMF05A' '0300'.
PERFORM BDC_FIELD USING : 'BDC_OKCODE' '/00',
'BDC_CURSOR' 'BSEG-SGTXT',
'BSEG-WRBTR' '*',
'BSEG-SGTXT' '+',
'BDC_SUBSCR' 'saplkacb'.
PERFORM BDC_DYNPRO USING : 'SAPLKACB' '0002'.
PERFORM BDC_FIELD USING : 'BDC_OKCODE' '=ENTE',
'BDC_CURSOR' 'COBL-PRCTR',
'COBL-PRCTR' IT_DATA-PRCTR,
'BDC_SUBSCR' 'SAPLKACB'.
PERFORM BDC_DYNPRO USING : 'SAPMF05A' '0300'.
PERFORM BDC_FIELD USING : 'BDC_OKCODE' '=BU',
'BDC_CURSOR' 'BSEG-WRBTR',
'BDC_SUBSCR' 'SAPLKACB'.
PERFORM BDC_DYNPRO USING : 'SAPLKACB' '0002'.
PERFORM BDC_FIELD USING : 'BDC_OKCODE' '=ENTE',
'BDC_CURSOR' 'COBL-AUFNR',
'BDC_SUBSCR' 'SAPLKACB'.
ELSE.
PERFORM BDC_DYNPRO USING : 'SAPMF05A' '0304'.
PERFORM BDC_FIELD USING : 'BDC_OKCODE' '/00',
'BDC_CURSOR' 'RF05A-NEWKO',
'BSEG-WRBTR' IT_DATA-WRBTR,
'BSEG-PRCTR' IT_DATA-PRCTR,
'BSEG-SGTXT' IT_DATA-SGTXT,
'RF05A-NEWBS' V_NEWBS1,
'RF05A-NEWKO' V_NEWKO1.
PERFORM BDC_DYNPRO USING : 'SAPMF05A' '0300'.
PERFORM BDC_FIELD USING : 'BDC_OKCODE' '=BU',
'BDC_CURSOR' 'BSEG-SGTXT',
'BSEG-WRBTR' '*',
'BSEG-SGTXT' '+',
'BDC_SUBSCR' 'saplkacb'.
PERFORM BDC_DYNPRO USING : 'SAPLKACB' '0002'.
PERFORM BDC_FIELD USING : 'BDC_OKCODE' '=ENTE',
'BDC_CURSOR' 'COBL-PRCTR',
'COBL-PRCTR' IT_DATA-PRCTR,
'BDC_SUBSCR' 'SAPLKACB'.
ENDIF.
ENDFORM. " FILL_IT_BDCDATA
*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
* Filling the it_bdcdata table with program name & screen number
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM LIKE BDCDATA-PROGRAM
DYNPRO LIKE BDCDATA-DYNPRO.
IT_BDCDATA-PROGRAM = PROGRAM.
IT_BDCDATA-DYNPRO = DYNPRO.
IT_BDCDATA-DYNBEGIN = 'X'.
APPEND IT_BDCDATA.
CLEAR IT_BDCDATA.
ENDFORM. " BDC_DYNPRO
*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
* Filling it_bdcdata with field name and field value
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM LIKE BDCDATA-FNAM
FVAL.
IT_BDCDATA-FNAM = FNAM.
IT_BDCDATA-FVAL = FVAL.
APPEND IT_BDCDATA.
CLEAR IT_BDCDATA.
ENDFORM. " BDC_FIELD
*&---------------------------------------------------------------------*
*& Form BDC_PROCESS
*&---------------------------------------------------------------------*
* Open bdc session if call transaction fails
*----------------------------------------------------------------------*
FORM BDC_PROCESS.
IF FG_BDC = 'N'.
* open bdc session
PERFORM OPEN_BDC.
FG_BDC = 'O'.
ENDIF.
IF FG_BDC = 'O'.
* insert data into bdc session
PERFORM INSERT_BDC.
ENDIF.
ENDFORM. " BDC_PROCESS
*&---------------------------------------------------------------------*
*& Form OPEN_BDC
*&---------------------------------------------------------------------*
* Calling function module to open bdc session
*----------------------------------------------------------------------*
FORM OPEN_BDC.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = 'SMM1'
KEEP = 'X'
USER = SY-UNAME
EXCEPTIONS
CLIENT_INVALID = 1
DESTINATION_INVALID = 2
GROUP_INVALID = 3
GROUP_IS_LOCKED = 4
HOLDDATE_INVALID = 5
INTERNAL_ERROR = 6
QUEUE_ERROR = 7
RUNNING = 8
SYSTEM_LOCK_ERROR = 9
USER_INVALID = 10
OTHERS = 11.
ENDFORM. " OPEN_BDC
*&---------------------------------------------------------------------*
*& Form INSERT_BDC
*&---------------------------------------------------------------------*
* Insert it_bdcdata into bdc by calling function module bdc_insert
*----------------------------------------------------------------------*
FORM INSERT_BDC.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'MM01'
TABLES
DYNPROTAB = IT_BDCDATA
EXCEPTIONS
INTERNAL_ERROR = 1
NOT_OPEN = 2
QUEUE_ERROR = 3
TCODE_INVALID = 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS = 7.
ENDFORM. " INSERT_BDC
*&---------------------------------------------------------------------*
*& Form ERROR_MESSAGES
*&---------------------------------------------------------------------*
* Displaying error messages
*----------------------------------------------------------------------*
FORM ERROR_MESSAGES.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = SY-MSGID
LANG = '-D'
IMPORTING
MSG = V_MESG
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
LOOP AT IT_MESSAGES WHERE MSGTYP = 'E'.
WRITE : / 'Message :'(I06) ,V_MESG.
CLEAR IT_MESSAGES.
ENDLOOP.
ENDFORM. " ERROR_MESSAGES
*&---------------------------------------------------------------------*
*& Form CLOSE_BDC
*&---------------------------------------------------------------------*
* Closing bdc session
*----------------------------------------------------------------------*
FORM CLOSE_BDC.
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3.
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.