2007 Dec 26 10:14 AM
Hi Experts,
Please can any one send me the example program for uploading Excel data into sap by using bdc..
Thanks in Advance...
Regards
Srihari.
2007 Dec 26 10:25 AM
Hi,
USE FM gui_download.
Check this,
/people/harry.dietz/blog/2005/11/11/yet-another-from-database-or-internal-table-to-excel
Tou can use this FM also,
CALL FUNCTION 'WS_EXCEL'
EXPORTING
FILENAME = 'C:/Rep.XLS'
SYNCHRON = ' '
TABLES
DATA = LT_EXCEL " internal table u want to download to excel
EXCEPTIONS
UNKNOWN_ERROR = 1
OTHERS = 2
UPLOAD / Download Programs to PC
http://abap4.tripod.com/Upload_and_Download_ABAP_Source_Code.html
http://www.sapgenie.com/abap/code/abap13.htm
http://sap.ittoolbox.com/code/archives.asp?d=3333&a=s&i=10
http://www.sap-img.com/abap/download-and-upload-your-abap-program.htm
http://www.geocities.com/rmtiwari/Resources/Utilities/WebViewer.html
Thanks,
2007 Dec 26 10:36 AM
hi,
it is older version program, instead of ws_upload, use GUI_upload function
REPORT ZFBDCASS
LINE-COUNT 60 LINE-SIZE 132 NO STANDARD PAGE HEADING.
T A B L E S
TABLES : ANLA, " Asset master record-segment
ANLZ, " Time-dependent asset allocations
ANEK, " Document header asset posting
ANEP. " Asset line item
I N T E R N A L - T A B L E S
DATA: BEGIN OF IT_UPLOAD OCCURS 1,
LINE(1000),
END OF IT_UPLOAD.
*
DATA : BEGIN OF IT_UPLOAD1 OCCURS 1,
BUKRS LIKE ANLA-BUKRS, " Company Code
ANLKL LIKE ANLA-ANLKL, " Asset Class
ANLUE LIKE ANLA-ANLUE, " Old Legacy Asset No
TXT50 LIKE ANLA-TXT50, " Name of the Asset
CAPDAT(10), " Captilized on Date
DPSTDAT1(10), " Depreciation Start Date for 10
DPSTDAT2(10), " Depreciation Start Date for 11
AFASL1 LIKE ANLB-AFASL, " Depreciation Key for 10
AFASL2 LIKE ANLB-AFASL, " Depreciation Key for 11
NDJAR1 LIKE ANLB-NDJAR, " Useful Life for 01
NDPER1 LIKE ANLB-NDPER, " Useful life in period for 01
ANBTR(15), " Amount Posted
KOSTL LIKE ANLZ-KOSTL, " Cost Center
WERKS LIKE ANLZ-WERKS, " Plant
KANSW(15), " Amount Posted for 10 & 11
NDJAR2 LIKE ANLB-NDJAR, " Useful Life for 10 & 11
END OF IT_UPLOAD1.
BDCDATA
DATA : BEGIN OF IT_BDCDATA OCCURS 1.
INCLUDE STRUCTURE BDCDATA.
DATA : END OF IT_BDCDATA.
DATA : IT_BDCDATA1 LIKE IT_BDCDATA OCCURS 1 WITH HEADER LINE.
BDCMSGCOLL
DATA : BEGIN OF IT_BDCMSGCOLL OCCURS 1.
INCLUDE STRUCTURE BDCMSGCOLL.
DATA : END OF IT_BDCMSGCOLL.
DATA : IT_BDCMSGCOLL1 LIKE IT_BDCMSGCOLL OCCURS 1 WITH HEADER LINE.
DATA : V_MSG(50), V_ERR_CNT TYPE I, V_SUCC_CNT TYPE I,
V_TOT_CNT TYPE I, V_FLAG_ERR(1), V_FLAG_SUCC(1).
DATA : BEGIN OF IT_ERROR OCCURS 1,
ANLUE(12), " Old Legacy Asset No
END OF IT_ERROR.
C O N S T A N T S
CONSTANTS : C_TAB TYPE X VALUE '09'. " Tab delimiter file
S E L E C T I O N S C R E E N
PARAMETERS : P_FILE1 LIKE RLGRAP-FILENAME " Input Filename
DEFAULT 'C:\Assetmaster.txt'.
S T A R T - O F - S E L E C T I O N
START-OF-SELECTION.
*
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = P_FILE1
FILETYPE = 'ASC'
TABLES
DATA_TAB = IT_UPLOAD
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
OTHERS = 8.
IF SY-SUBRC NE 0.
MESSAGE E012(Z2) WITH 'File Not Found'.
ENDIF.
*
LOOP AT IT_UPLOAD.
SPLIT IT_UPLOAD-LINE
AT C_TAB INTO
IT_UPLOAD1-BUKRS
IT_UPLOAD1-ANLKL
IT_UPLOAD1-ANLUE
IT_UPLOAD1-TXT50
IT_UPLOAD1-CAPDAT
IT_UPLOAD1-DPSTDAT1
IT_UPLOAD1-DPSTDAT2
IT_UPLOAD1-AFASL1
IT_UPLOAD1-AFASL2
IT_UPLOAD1-NDJAR1
IT_UPLOAD1-NDPER1
IT_UPLOAD1-ANBTR
IT_UPLOAD1-KOSTL
IT_UPLOAD1-WERKS
IT_UPLOAD1-KANSW
IT_UPLOAD1-NDJAR2.
APPEND IT_UPLOAD1.
CLEAR IT_UPLOAD1.
ENDLOOP.
LOOP AT IT_UPLOAD1.
V_TOT_CNT = V_TOT_CNT + 1.
CLEAR : V_FLAG_ERR, V_FLAG_SUCC.
PERFORM BDC_DYNPRO USING: 'X' '0105' 'SAPLAIST'.
PERFORM BDC_FIELD USING: 'BDC_OKCODE' '/00',
'BDC_CURSOR' 'ANLA-ANLKL',
'ANLA-ANLKL' IT_UPLOAD1-ANLKL,
'ANLA-BUKRS' IT_UPLOAD1-BUKRS.
PERFORM BDC_DYNPRO USING: 'X' '0140' 'SAPLAIST'.
PERFORM BDC_FIELD USING: 'BDC_OKCODE' '/00',
'BDC_CURSOR' 'ANLA-INKEN',
'ANLA-TXT50' IT_UPLOAD1-TXT50,
'ANLA-INKEN' 'X',
'ANLA-AKTIV' IT_UPLOAD1-CAPDAT.
PERFORM BDC_DYNPRO USING: 'X' '0145' 'SAPLAIST'.
PERFORM BDC_FIELD USING: 'BDC_OKCODE' '/00',
'BDC_CURSOR' 'ANLZ-WERKS',
'ANLZ-KOSTL' IT_UPLOAD1-KOSTL,
'ANLZ-WERKS' IT_UPLOAD1-WERKS.
PERFORM BDC_DYNPRO USING: 'X' '0160' 'SAPLAIST'.
PERFORM BDC_FIELD USING: 'BDC_OKCODE' 'D190',
'BDC_CURSOR' 'ANLA-ANLUE',
'ANLA-ANLUE' IT_UPLOAD1-ANLUE.
PERFORM BDC_DYNPRO USING: 'X' '0190' 'SAPLAIST'.
PERFORM BDC_FIELD USING: 'BDC_OKCODE' 'BUCH',
'BDC_CURSOR' 'ANLB-AFABG(03)',
'ANLB-AFASL(02)' IT_UPLOAD1-AFASL1,
'ANLB-AFASL(03)' IT_UPLOAD1-AFASL2,
'ANLB-NDJAR(01)' IT_UPLOAD1-NDJAR1,
'ANLB-NDPER(01)' IT_UPLOAD1-NDPER1,
'ANLB-NDJAR(02)' IT_UPLOAD1-NDJAR2,
'ANLB-NDJAR(03)' IT_UPLOAD1-NDJAR2,
'ANLB-AFABG(02)' IT_UPLOAD1-DPSTDAT1,
'ANLB-AFABG(03)' IT_UPLOAD1-DPSTDAT2.
PERFORM BDC_DYNPRO USING: 'X' '0300' 'SAPLSPO1'.
PERFORM BDC_FIELD USING: 'BDC_OKCODE' '=YES'.
CALL TRANSACTION 'AS01' USING IT_BDCDATA
MODE 'A'
UPDATE 'S'
MESSAGES INTO IT_BDCMSGCOLL.
IF SY-SUBRC EQ 0.
READ TABLE IT_BDCMSGCOLL WITH KEY TCODE = 'AS01'
DYNAME = 'SAPLAIST'
DYNUMB = '0403'
MSGTYP = 'S'.
IF SY-SUBRC EQ 0.
V_MSG = IT_BDCMSGCOLL-MSGV1.
V_FLAG_SUCC = 'X'.
ENDIF.
PERFORM BDC_DYNPRO1 USING: 'X' '0100' 'SAPMA01B'.
PERFORM BDC_FIELD1 USING: 'BDC_OKCODE' '/00',
'BDC_CURSOR' 'ANEK-BUDAT',
'ANBZ-ANLN1' V_MSG,
'ANBZ-BUKRS' IT_UPLOAD1-BUKRS,
'ANEK-BLDAT' IT_UPLOAD1-CAPDAT,
'ANEK-BUDAT' IT_UPLOAD1-CAPDAT,
'ANBZ-PERID' IT_UPLOAD1-CAPDAT+0(1),
'ANBZ-BWASL' '100'.
PERFORM BDC_DYNPRO1 USING: 'X' '110' 'SAPMA01B'.
PERFORM BDC_FIELD1 USING: 'BDC_OKCODE' 'EPOS',
'BDC_CURSOR' 'RA01B-GKONT',
'ANBZ-DMBTR' IT_UPLOAD1-ANBTR,
'RA01B-GKONT' '119020'.
PERFORM BDC_DYNPRO1 USING: 'X' '0250' 'SAPMA01B'.
PERFORM BDC_FIELD1 USING: 'BDC_OKCODE' 'AUSF',
'BDC_CURSOR' 'ANEP-AFABE(01)',
'ANEP-ANBTR(02)' IT_UPLOAD1-KANSW,
'ANEP-ANBTR(03)' IT_UPLOAD1-KANSW.
PERFORM BDC_DYNPRO1 USING: 'X' '0110' 'SAPMA01B'.
PERFORM BDC_FIELD1 USING: 'BDC_OKCODE' 'UPDA',
'BDC_CURSOR' 'ANBZ-DMBTR'.
CALL TRANSACTION 'AB01' USING IT_BDCDATA1
MODE 'A'
UPDATE 'S'
MESSAGES INTO IT_BDCMSGCOLL1.
IF SY-SUBRC NE 0.
V_FLAG_ERR = 'X'.
ENDIF.
ELSE.
V_FLAG_ERR = 'X'.
ENDIF.
IF V_FLAG_ERR = 'X'.
V_ERR_CNT = V_ERR_CNT + 1.
IT_ERROR-ANLUE = IT_UPLOAD1-ANLUE. " Old Legacy Asset No
APPEND IT_ERROR.
CLEAR IT_ERROR.
ENDIF.
IF V_FLAG_SUCC = 'X'.
V_SUCC_CNT = V_SUCC_CNT + 1.
ENDIF.
CLEAR : IT_UPLOAD1, IT_BDCDATA, IT_BDCDATA1, IT_BDCMSGCOLL.
REFRESH : IT_BDCDATA, IT_BDCDATA1, IT_BDCMSGCOLL.
ENDLOOP.
&----
E N D - O F - S E L E C T I O N
&----
END-OF-SELECTION.
WRITE:/ '***********************************************************'.
WRITE:/ 'Total No. of Records: ', V_TOT_CNT.
WRITE:/ 'Success Record Count: ', V_SUCC_CNT.
WRITE:/ 'Error Record Count: ', V_ERR_CNT.
WRITE:/ '***********************************************************'.
IF NOT IT_ERROR[] IS INITIAL.
WRITE:/ ''.
WRITE:/5 'OLD LEGACY ASSET NO'.
WRITE:/5 '----
'.
LOOP AT IT_ERROR.
WRITE:/5 IT_ERROR-ANLUE.
ENDLOOP.
ENDIF.
----
*& Form BDC_DYNPRO
----
Update of BDC Program, Screen and DynBegin
----
FORM BDC_DYNPRO USING DYNBEGIN
DYNPRO
PROGRAM.
IT_BDCDATA-DYNBEGIN = DYNBEGIN.
IT_BDCDATA-DYNPRO = DYNPRO.
IT_BDCDATA-PROGRAM = PROGRAM.
APPEND IT_BDCDATA.
CLEAR IT_BDCDATA.
ENDFORM. " BDC_DYNPRO
----
*& Form BDC_FIELD
----
Update the field name and values
----
FORM BDC_FIELD USING FNAM
FVAL.
IT_BDCDATA-FNAM = FNAM.
IT_BDCDATA-FVAL = FVAL.
APPEND IT_BDCDATA.
CLEAR IT_BDCDATA.
ENDFORM. " BDC_FIELD
&----
----
*& Form BDC_DYNPRO1
&----
FORM BDC_DYNPRO1 USING DYNBEGIN1
DYNPRO1
PROGRAM1.
IT_BDCDATA1-DYNBEGIN = DYNBEGIN1.
IT_BDCDATA1-DYNPRO = DYNPRO1.
IT_BDCDATA1-PROGRAM = PROGRAM1.
APPEND IT_BDCDATA1.
CLEAR IT_BDCDATA1.
ENDFORM. " BDC_DYNPRO1
*&----
----
*& Form BDC_FIELD1
*&----
FORM BDC_FIELD1 USING FNAM1
FVAL1.
IT_BDCDATA1-FNAM = FNAM1.
IT_BDCDATA1-FVAL = FVAL1.
APPEND IT_BDCDATA1.
CLEAR IT_BDCDATA1.
ENDFORM. " BDC_FIELD1
regards,
pavan
2007 Dec 26 10:43 AM
2007 Dec 26 10:51 AM
Hi
Srihari
Please go though the following lines of code:
************************************************************************
D A T A D E C L A R A T I O N *
************************************************************************
TABLES: ANEP,
BKPF.
TYPES: BEGIN OF TY_TABDATA,
MANDT LIKE SY-MANDT, " Client
ZSLNUM LIKE ZSHIFTDEPN-ZSLNUM, " Serial Number
ZASSET LIKE ZSHIFTDEPN-ZASSET, " Original asset that was transferred
ZYEAR LIKE ZSHIFTDEPN-ZYEAR, " Fiscal Year
ZPERIOD LIKE ZSHIFTDEPN-ZPERIOD, " Fiscal Period
ZSHIFT1 LIKE ZSHIFTDEPN-ZSHIFT1, " Shift No. 1
ZSHIFT2 LIKE ZSHIFTDEPN-ZSHIFT1, " Shift No. 2
ZSHIFT3 LIKE ZSHIFTDEPN-ZSHIFT1, " Shift No. 3
END OF TY_TABDATA.
*----
Declaration of the Internal Table with Header Line comprising of the uploaded data.
*----
DATA: BEGIN OF IT_FILE_UPLOAD OCCURS 0.
INCLUDE STRUCTURE ALSMEX_TABLINE. " Rows for Table with Excel Data
DATA: END OF IT_FILE_UPLOAD.
************************************************************************
S E L E C T I O N - S C R E E N *
************************************************************************
SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME,
BEGIN OF BLOCK B2 WITH FRAME.
PARAMETERS: P_FNAME LIKE RLGRAP-FILENAME OBLIGATORY.
SELECTION-SCREEN: END OF BLOCK B2,
END OF BLOCK B1.
************************************************************************
E V E N T : AT S E L E C T I O N - S C R E E N *
************************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAME.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
PROGRAM_NAME = SYST-REPID
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
STATIC = 'X'
MASK = '.'
CHANGING
FILE_NAME = P_FNAME
EXCEPTIONS
MASK_TOO_LONG = 1
OTHERS = 2
.
IF SY-SUBRC 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
************************************************************************
E V E N T : S T A R T - O F - S E L E C T I O N *
************************************************************************
START-OF-SELECTION.
*
Upload Excel file into Internal Table.
*
PERFORM UPLOAD_EXCEL_FILE.
*
Organize the uploaded data into another Internal Table.
*
PERFORM ORGANIZE_UPLOADED_DATA.
************************************************************************
E V E N T : E N D - O F - S E L E C T I O N *
************************************************************************
END-OF-SELECTION.
&----
*& Form UPLOAD_EXCEL_FILE
&----
text
-
--> p1 text
<-- p2 text
-
FORM UPLOAD_EXCEL_FILE .
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = P_FNAME
I_BEGIN_COL = 1
I_BEGIN_ROW = 3
I_END_COL = 7
I_END_ROW = 32000
TABLES
INTERN = IT_FILE_UPLOAD
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3
.
IF SY-SUBRC 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " UPLOAD_EXCEL_FILE
&----
*& Form ORGANIZE_UPLOADED_DATA
&----
text
-
--> p1 text
<-- p2 text
-
FORM ORGANIZE_UPLOADED_DATA .
SORT IT_FILE_UPLOAD BY ROW
COL.
LOOP AT IT_FILE_UPLOAD.
CASE IT_FILE_UPLOAD-COL.
....................................................
WHEN 1.
WA_TABDATA-ZSLNUM = IT_FILE_UPLOAD-VALUE.
WHEN 2.
WA_TABDATA-ZASSET = IT_FILE_UPLOAD-VALUE.
WHEN 3.
WA_TABDATA-ZYEAR = IT_FILE_UPLOAD-VALUE.
WHEN 4.
WA_TABDATA-ZPERIOD = IT_FILE_UPLOAD-VALUE.
WHEN 5.
WA_TABDATA-ZSHIFT1 = IT_FILE_UPLOAD-VALUE.
WHEN 6.
WA_TABDATA-ZSHIFT2 = IT_FILE_UPLOAD-VALUE.
WHEN 7.
WA_TABDATA-ZSHIFT3 = IT_FILE_UPLOAD-VALUE.
....................................................
ENDCASE.
AT END OF ROW.
WA_TABDATA-MANDT = SY-MANDT.
APPEND WA_TABDATA TO IT_TABDATA.
CLEAR: WA_TABDATA.
ENDAT.
ENDLOOP.
ENDFORM. " ORGANIZE_UPLOADED_DATA
In the subroutine --> ORGANIZE_UPLOADED_DATA, data are organized as per the structure declared above.
if helpfull plzzz reward..