Google Search - Blog...........

ABAP - Download A File With The Specified Delimit Character Dynamically.

Summary:

This is an ABAP program, downloads a file based on the user provided delimit characters on the selection screen dynamically.
In case of Tab delimit character, user has to provide 'T' so that program will create a tab delimit file.
Source Code:
*&---------------------------------------------------------------------*
*& Report ZFILE_WITH_DELCHAR
*&
*&---------------------------------------------------------------------*
REPORT zfile_with_delchar.
TABLES:
mara.

*******Types Declaration
TYPES:
**--File Output
BEGIN OF ty_out,
line(150),
END OF ty_out,

**--Material Data
BEGIN OF ty_mat,
matnr TYPE mara-matnr,
mtart TYPE mara-mtart,
mbrsh TYPE mara-mbrsh,
meins TYPE mara-meins,
END OF ty_mat.

DATA:
it_out TYPE STANDARD TABLE OF ty_out WITH HEADER LINE,
it_mat TYPE STANDARD TABLE OF ty_mat WITH HEADER LINE.

**--Selection-screen Design
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

**--Material numbers
SELECT-OPTIONS s_matnr FOR mara-matnr.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(15) text-002.

**--Delimit char
PARAMETERS: p_dchar TYPE c obligatory.
SELECTION-SCREEN COMMENT 20(20) text-003.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b1.
CLASS cl_abap_char_utilities DEFINITION LOAD.
START-OF-SELECTION.

**--Get the data from material table
SELECT matnr
mtart
mbrsh
meins
FROM mara
INTO TABLE it_mat
WHERE matnr IN s_matnr.

**--Prepare output file with specified delimit char
LOOP AT it_mat.
IF p_dchar = 'T'.
CONCATENATE it_mat-matnr
it_mat-mtart
it_mat-mbrsh
it_mat-meins
INTO it_out-line
SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
ELSE.

CONCATENATE it_mat-matnr
it_mat-mtart
it_mat-mbrsh
it_mat-meins
INTO it_out-line
SEPARATED BY p_dchar.
ENDIF.

APPEND it_out.
CLEAR: it_out,it_mat.
ENDLOOP.

**--Download the data
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE = BIN_FILESIZE
filename = 'C:\mat.txt'
* FILETYPE = 'ASC'
* APPEND = ' '
* WRITE_FIELD_SEPARATOR = ' '
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* DAT_MODE = ' '
* CONFIRM_OVERWRITE = ' '
* NO_AUTH_CHECK = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* WRITE_BOM = ' '
* TRUNC_TRAILING_BLANKS_EOL = 'X'
* WK1_N_FORMAT = ' '
* WK1_N_SIZE = ' '
* WK1_T_FORMAT = ' '
* WK1_T_SIZE = ' '
* IMPORTING
* FILELENGTH = FILELENGTH
TABLES
data_tab = it_out
* FIELDNAMES = FIELDNAMES
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22
.
IF sy-subrc = 0.
WRITE:/ 'File is downloaded'.
ENDIF.


ALSO READ:

- Download ABAP Source Code & TEXTPOOL To The Desktop.

- Downloading Programs Into A Folder In Presentation Server.

- Download SAP Data In XML Format.

- Download SAPScript Output To PDF File.

- Download Data From Application Server Files To Presentation Server Using FM C13Z_APPL_TO_FRONT_END.



RETURN TO MAIN INDEX:

- Sample Programs On Uploading & Downloading Files.

- Sample Programs On HR ABAP.

- Sample Report Programs On ALV List/ Grid Display.

- Sample Programs On Selection Screen.

- Sample Programs On BDC.

.....Back To MAIN INDEX.



No comments:

Post a Comment