|
REPORT Z_DELIMIT_DOWNLOAD. * Inserting a Tab Delimited between the Fields in the Internal Table * * This program allows you to insert any Tab Delimited characters easily. * * You have to create the customized Function in SE37 First. * * The customized functions will replace all the fields in your internal table * with your desired Tab Delimited characters. * * Written by : SAP Basis, ABAP Programming and Other IMG Stuff * http://www.erpgreat.com * * *Replace DELIMIT with "," in the function DATA: BEGIN OF ITAB OCCURS 100, TXT01(10), TXT02(10), END OF ITAB. SELECTION-SCREEN BEGIN OF BLOCK FILE_OP WITH FRAME TITLE TEXT-030. SELECTION-SCREEN BEGIN OF LINE. PARAMETERS: DLOAD AS CHECKBOX DEFAULT ' '. SELECTION-SCREEN COMMENT 4(30) TEXT-027. PARAMETERS: FILE LIKE RLGRAP-FILENAME DEFAULT 'C:\TEMP\ZTEST.TXT'. SELECTION-SCREEN END OF LINE. SELECTION-SCREEN END OF BLOCK FILE_OP. ITAB-TXT01 = 'TEXT01'. ITAB-TXT02 = 'TEXT01'. APPEND ITAB. ITAB-TXT01 = 'TEXT02'. ITAB-TXT02 = 'TEXT02'. APPEND ITAB. PERFORM DOWNLOAD. *---------------------------------------------------------------------* * FORM DOWNLOAD * *---------------------------------------------------------------------* * ........ * *---------------------------------------------------------------------* FORM DOWNLOAD. DATA: BEGIN OF DUMP OCCURS 0, C(2048) TYPE C, END OF DUMP. REFRESH DUMP. CALL FUNCTION 'Z_DELIMIT_DOWNLOAD' EXPORTING DELIMIT = ',' TABLES INTAB = ITAB OUTTAB = DUMP EXCEPTIONS CONVERSION_FAILED = 01. LOOP AT DUMP. WRITE:/ DUMP. ENDLOOP. CALL FUNCTION 'WS_DOWNLOAD' EXPORTING FILENAME = FILE FILETYPE = 'DAT' MODE = ' ' TABLES DATA_TAB = DUMP EXCEPTIONS FILE_OPEN_ERROR = 01 FILE_WRITE_ERROR = 02 INVALID_FILESIZE = 03 INVALID_TABLE_WIDTH = 04 INVALID_TYPE = 05 NO_BATCH = 06 UNKNOWN_ERROR = 07. ENDFORM. ************************************************* * This Function modules need to be created first. ************************************************* FUNCTION Z_DELIMIT_DOWNLOAD . *"---------------------------------------------------------------------- *"*"Local interface: *" IMPORTING *" REFERENCE(DELIMIT) *" TABLES *" INTAB *" OUTTAB *"---------------------------------------------------------------------- FIELD-SYMBOLS: <F>. DATA: LEN TYPE I, NUM TYPE I, DELIMIT_LEN TYPE I. DELIMIT_LEN = STRLEN( DELIMIT ). LOOP AT INTAB. CLEAR OUTTAB. NUM = 0. DO. * Get name of next structure field into <f> ASSIGN COMPONENT SY-INDEX OF STRUCTURE INTAB TO <F>. IF SY-SUBRC <> 0. EXIT. ENDIF. " No more fields in structure LEN = STRLEN( <F> ). WRITE: <F> TO OUTTAB+NUM(LEN). " Write field to output table NUM = NUM + LEN. WRITE: DELIMIT TO OUTTAB+NUM(DELIMIT_LEN). NUM = NUM + DELIMIT_LEN. ENDDO. APPEND OUTTAB. ENDLOOP. ENDFUNCTION. |
Related ABAP Topics:
Get help for your ABAP problems
ABAP Books
More ABAP Tips
SAP Basis, ABAP Programming and Other IMG Stuff http://www.erpgreat.com All the site contents are Copyright © www.erpgreat.com
and the content authors. All rights reserved.
|