Use Excel instead of Tab delimited text in BDC programs

Use Excel instead of Tab delimited text in BDC programs

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
         

    Requires Free Membership to View

    When you register, you will start receiving targeted emails from my award-winning team of editorial writers. Our goal is to keep you informed on the hottest topics and biggest challenges faced by SAP professionals today.

    Hannah Smalltree, Editorial Director

    By submitting your registration information to SearchSAP.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchSAP.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

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.

This was first published in January 2003

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.

    Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.