Problem solve Get help with specific problems with your technologies, process and projects.

Use Excel instead of Tab delimited text in BDC programs

Use Excel files instead of tab delimited text files for uploading data into SAP R/3.

There is no need for users to save the Excel files as tab delimited text files for uploading the data into SAP R/3. Use Excel files instead! The code below was written in 4.6C.

 

REPORT ZEXCEL_TO_ITAB no standard page heading line-size 250.
*-------------------------------------------------------------*
*  Description :
*  This is the simple example of getting  the data from 
*  an excel file and stored in an internal table. 
*  Now there is no need to convert the excel file to a tab
*  delimited file for uploading the data into the SAP R/3
*  by using the BDC Programs.
*  
*
*  Author : Jaswinder Singh Bhatti
*           ( a student of ABAP )
*  Mail me at bhatti_jassi@hotmail.com
*             bhatti_jassi@yahoo.co.in
*
*  SAP Version : 4.6C
*-------------------------------------------------------------*


* Internal Table Defination..........................
DATA:   BEGIN OF JTABLE OCCURS 0,
         DOCID_001(25)  TYPE C,   
         FIELD_002(25)  TYPE C,   
         FIELD_003(25)  TYPE C,   
         FIELD_004(25)  TYPE C,   
         FIELD_005(25)  TYPE C,   
         FIELD_006(25)  TYPE C,   
         FIELD_007(255) TYPE C,   
         FIELD_008(25)  TYPE C,   
         FIELD_009(25)  TYPE C,   
         FIELD_010(25)  TYPE C,   
         MSG_011(50)    TYPE C,   
       END OF JTABLE.

* Selection Screen....................................
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
 PARAMETERS:  P_FILE LIKE RLGRAP-FILENAME
                DEFAULT 'c:JJJJJJJJJJ.xls' OBLIGATORY.   " File Name
SELECTION-SCREEN END OF BLOCK B1.


* At Selection Screen Event...........................
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
 CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
      EXPORTING
           MASK      = '*.xls'
           STATIC    = 'X'
      CHANGING
           FILE_NAME = P_FILE
      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.

* Start of selection Event.............................
START-OF-SELECTION.

 PERFORM C200-UPLOAD_FILE TABLES   JTABLE
                          USING    P_FILE.
* End of selection Event...............................
end-of-selection.

loop at jtable.
write:/ jtable-DOCID_001,
        jtable-FIELD_002,
        jtable-FIELD_003,
        jtable-FIELD_004,
        jtable-FIELD_005,
        jtable-FIELD_006,
        jtable-FIELD_007,
        jtable-FIELD_008,
        jtable-FIELD_009,
        jtable-FIELD_010,
        jtable-MSG_011.
endloop.

FORM C200-UPLOAD_FILE TABLES   P_TABLE
                     USING    P_FILE.
* Data Declarations.......................................
 DATA : L_INTERN TYPE  KCDE_CELLS OCCURS 0 WITH HEADER LINE.
 DATA : L_INDEX TYPE I.
 DATA : L_START_COL TYPE I VALUE '1',
        L_START_ROW TYPE I VALUE '1',
        L_END_COL   TYPE I VALUE '256',
        L_END_ROW   TYPE I VALUE '65536'.

* Field Symbols...........................................
 FIELD-SYMBOLS : >FS>.

 CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'
      EXPORTING
           FILENAME    = P_FILE
           I_BEGIN_COL = L_START_COL
           I_BEGIN_ROW = L_START_ROW
           I_END_COL   = L_END_COL
           I_END_ROW   = L_END_ROW
      TABLES
           INTERN      = L_INTERN
      EXCEPTIONS
           INCONSISTENT_PARAMETERS  = 1
           UPLOAD_OLE               = 2
           OTHERS                   = 3.
         .
 IF sy-subrc >> 0.
*  MESSAGE E002(ZA).                    " File Error
   FORMAT COLOR COL_BACKGROUND INTENSIFIED.
   WRITE : / 'File Error'.
   EXIT.
 ENDIF.

 IF L_INTERN[] IS INITIAL.
*   MESSAGE E003(ZA).                          " No Data Uploaded
   FORMAT COLOR COL_BACKGROUND INTENSIFIED.
   WRITE : / 'No Data Uploaded'.
   EXIT.
 ELSE.
   SORT L_INTERN BY ROW COL.
   LOOP AT L_INTERN.
     MOVE L_INTERN-COL TO L_INDEX.
     ASSIGN COMPONENT L_INDEX OF STRUCTURE P_TABLE TO >FS>.
     MOVE L_INTERN-VALUE TO <FS>.
     AT END OF ROW.
       APPEND P_TABLE.
       CLEAR P_TABLE.
     ENDAT.
   ENDLOOP.
 ENDIF.

ENDFORM.

Dig Deeper on SAP integration

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchContentManagement

SearchHRSoftware

Close