Sunday, December 19, 2010
Use the Function Module SAP_CONVERT_TO_CSV_FORMAT to convert the internal table into Comma seperated format then download this
internal table using the Function Module GUI_DOWNLOAD.
REPORT zvenkat_test2.
TYPE-POOLS: truxs.
TYPES:
BEGIN OF t_line,
vbeln   LIKE vbap-vbeln,
posnr   LIKE vbap-posnr,
END OF t_line.
DATA:w_line TYPE t_line.
DATA:itab   TYPE STANDARD TABLE OF t_line.
DATA:itab1  TYPE truxs_t_text_data.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text_001.
PARAMETERS p_file TYPE localfile DEFAULT 'C:\Test.txt'.
SELECTION-SCREEN END OF BLOCK b1.
*---------------------------------------------------------------------
"At selection-screen on value-request for p_file.
*---------------------------------------------------------------------
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM f4_help.

START-OF-SELECTION.
PERFORM get_data.

END-OF-SELECTION.
PERFORM convert_to_csv.
PERFORM download_data.

*&---------------------------------------------------------------------*
*&      Form  f4_help
*&---------------------------------------------------------------------*
FORM f4_help .

DATA:
l_file_name LIKE  ibipparms-path  .

CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name  = syst-cprog
dynpro_number = syst-dynnr
field_name    = 'P_FILE'
IMPORTING
file_name     = l_file_name.

p_file = l_file_name.

ENDFORM.                                                    " f4_help
*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
FORM get_data .
SELECT
vbeln
posnr
UP TO 10 ROWS
FROM vbap
INTO TABLE itab.
ENDFORM.                    " get_data
*&---------------------------------------------------------------------*
*&      Form  convert_to_csv
*&---------------------------------------------------------------------*
FORM convert_to_csv .
CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
EXPORTING
i_field_seperator    = ';'
TABLES
i_tab_sap_data       = itab
CHANGING
i_tab_converted_data = itab1
EXCEPTIONS
conversion_failed    = 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.
ENDFORM.                    " convert_to_csv
*&---------------------------------------------------------------------*
*&      Form  download_data
*&---------------------------------------------------------------------*
FORM download_data .
DATA l_filename TYPE  string.
l_filename = p_file.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = l_filename
TABLES
data_tab = itab1
EXCEPTIONS
OTHERS   = 1.
ENDFORM.                    " download_data 

0 comments:

Post a Comment

Your useful comments, suggestions are appreciated.Your comments are moderated.

Followers

Contact Form

Name

Email *

Message *

Web Dynpro ABAP Book

An SAP Consultant

Follow US


Want to Contribute ?

If you are interested in writing about the new stuff you learn everyday while working, please write to the.sap.consultants@gmail.com.

Click on Contribution for more details.