Sample ABAP program to upload CSV data into Internal table and sending it to Application server
REPORT.
*--Attaching type group to program TYPE-POOLS KCDE. *--Structure type TYPES: BEGIN OF TY-STD, RONO TYPE C LENGTH 4, NAME1 TYPE C LENGTH 20, GEN TYPE C LENGTH 6, FEES TYPE C LENGTH 10, END OF TY_STD. *--Header line and Internal table DATA WKA TYPE TY_STD. DATA ITABLE TYPE TABLE OF TY_STD. *--Header line and internal table for CSV data DATA IS_CSV TYPE LINE OF KCDE_INTERN. DATA IT_CSV TYPE KCDE_INTERN. *--Application server files are known as "Datasets" *--here "fname" is the Dataset DATA FNAME TYPE C LENGTH 40 VALUE 'StudentsInfo.txt'. *--Convert CSV flat file data into internal table CALL FUNCTION 'KCD_CSV_FILE_TO_INTERN_CONVERT' EXPORTING I_FILENAME = 'C:\Documents and Settings\Administrator\Desktop\Students.csv' I_SEPARATOR = ',' TABLES E_INTERN = IT_CSV. LOOP AT IT_CSV INTO IS_CSV. CASE IS_CSV-COL. WHEN 1. WA-RONO = IS_CSV-VALUE. WHEN 2. WA-NAME1 = IS_CSV-VALUE. WHEN 3. WA-GEN = IS_CSV-VALUE. WHEN 4. WA- FEES = IS_CSV-VALUE. ENDCASE. AT END OF ROW. APPEND WKA TO ITABLE CLEAR WKA. ENDAT. ENDLOOP. *--Sending data to application server OPEN DATASET FNAME FOR OUTPUT IN TEXT MODE ENCODING DEFAULT. LOOP AT ITABLE INTO WKA. TRANSFER WKA TO FNAME. ENDLOOP. CLOSE DATASET FNAME. .
Comments
Post a Comment