Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Need a small change in this code, GUI_DOWNLOAD. FILE NAME ??

Former Member
0 Kudos

Hi All,

I want to write a program to download data from VBAK. I have tried this and working fine but I have made my file name constant. Instead I want user to make a choice of file name and its location to save.

Also please review this code and let me know, how can I improve my programming skills...

&----


*& Report ZSAI1

*&

&----


*&

*&

&----


REPORT ZSAI1.

tables : vbak.

data : begin of it_vbak occurs 0,

vbeln like vbak-vbeln,

auart like vbak-auart,

audat like vbak-audat,

end of it_vbak.

data : i_filename type string value 'C:\Documents and Settings\venki\Desktop\text.xls'.

selection-screen begin of block sc1 with frame.

select-options : s_vbeln for vbak-vbeln.

selection-screen Skip 3.

parameters : i_excel radiobutton group Rb1,

i_text radiobutton group Rb1.

selection-screen end of block sc1.

perform select_dt.

.

if i_excel = 'X'.

perform download_excel.

endif.

&----


*& Form download_excel

&----


FORM download_excel .

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

FILENAME = i_filename

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 =

TABLES

DATA_TAB = it_vbak

  • 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.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " download_excel

&----


*& Form download_text

&----


FORM download_text .

ENDFORM. " download_text

&----


*& Form select_dt

&----


FORM select_dt .

select vbeln auart audat from vbak

into table it_vbak where

vbeln in s_vbeln.

ENDFORM. " select_dt

Thank You once gain.

Regards

Venkat

Message was edited by:

venkat Kumbham

1 ACCEPTED SOLUTION

Former Member
0 Kudos

SELECTION-SCREEN: BEGIN OF BLOCK IMP WITH FRAME TITLE TEXT-003.

PARAMETERS: P_FN_IMP LIKE RLGRAP-FILENAME OBLIGATORY. "File Name

SELECTION-SCREEN: END OF BLOCK IMP.

----


  • At Selection Screen *

----


AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FN_IMP.

*-- Get the File Dialog

PERFORM SELECT_FILENAME.

&----


*

*& Form download

&----


  • text

----


  • -->P_LV_ERROR_FILENAME text

----


FORM DOWNLOAD .

DATA : LV_FNAME TYPE STRING.

LV_FNAME = P_FN_IMP

*-- Download the Error Records into a File.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = LV_FNAME

TABLES

DATA_TAB = I_ERR_FILE

EXCEPTIONS

OTHERS = 22.

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. " download

7 REPLIES 7

Former Member
0 Kudos

SELECTION-SCREEN: BEGIN OF BLOCK IMP WITH FRAME TITLE TEXT-003.

PARAMETERS: P_FN_IMP LIKE RLGRAP-FILENAME OBLIGATORY. "File Name

SELECTION-SCREEN: END OF BLOCK IMP.

----


  • At Selection Screen *

----


AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FN_IMP.

*-- Get the File Dialog

PERFORM SELECT_FILENAME.

&----


*

*& Form download

&----


  • text

----


  • -->P_LV_ERROR_FILENAME text

----


FORM DOWNLOAD .

DATA : LV_FNAME TYPE STRING.

LV_FNAME = P_FN_IMP

*-- Download the Error Records into a File.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = LV_FNAME

TABLES

DATA_TAB = I_ERR_FILE

EXCEPTIONS

OTHERS = 22.

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. " download

0 Kudos

You can call this FM - F4_FILENAME for providing the user the POP UP for selecting File. The file path is returned on param - FILE_NAME.

You can pass this Filepath to your FM for download path. rest is fine.

0 Kudos

Hi Mahesh,

Thank you very much for your reply and code.

I am not getting any value to select a file name. when I push f4 it is taking for a while. more over after program runs without any dialog or gives no output.

Please check the code once again.

REPORT ZSAI1.

tables : vbak.

PARAMETERS:p_fn_imp LIKE RLGRAP-FILENAME OBLIGATORY. "File Name

data : begin of it_vbak occurs 0,

vbeln like vbak-vbeln,

auart like vbak-auart,

audat like vbak-audat,

end of it_vbak.

selection-screen begin of block sc1 with frame.

select-options : s_vbeln for vbak-vbeln.

selection-screen Skip 3.

parameters : i_excel radiobutton group Rb1,

i_text radiobutton group Rb1.

selection-screen end of block sc1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fn_imp.

perform select_dt.

.

if i_excel = 'X'.

perform download_excel.

endif.

&----


*& Form download_excel

&----


FORM download_excel .

data : lv_fname type string .

lv_fname = p_fn_imp.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

FILENAME = lv_fname

FILETYPE = 'ASC'

TABLES

DATA_TAB = it_vbak

  • FIELDNAMES =

EXCEPTIONS

OTHERS = 22

Thank for your help, Points awarded.

Venkat

0 Kudos

Hello Venkat,

I gave exact code to you ,please copy and paste the code ,see the results

Thanks

Seshu

0 Kudos

Hi Mahesh, Seshu and Others.

Thank you very much for your inputs, My issue is resolved . I am closing thread and alloting points.

it is really nice to share knowledge. Thank you once again.

Just want to say that first time, I missed get_filename subroutine to call FM WS_FILENAME_GET.

Thank you,

Regards

Venkat.

Former Member
0 Kudos

Check the below code :

REPORT ZSAI1.

tables : vbak.

data : begin of it_vbak occurs 0,

vbeln like vbak-vbeln,

auart like vbak-auart,

audat like vbak-audat,

end of it_vbak.

data v_file type string.

*data : i_filename type string value

*'C:\Documents and Settings\venki\Desktop\text.xls'.

selection-screen begin of block sc1 with frame.

select-options : s_vbeln for vbak-vbeln.

selection-screen Skip 3.

parameters p_file like rlgrap-filename.

parameters : i_excel radiobutton group Rb1,

i_text radiobutton group Rb1.

selection-screen end of block sc1.

at selection-screen on value-request for p_file.

  • F4 value for file

perform file_get.

start-of-selection.

perform select_dt.

.

if i_excel = 'X'.

perform download_excel.

endif.

&----


*& Form download_excel

&----


FORM download_excel .

v_file = p_file.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

FILENAME = v_file

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 =

TABLES

DATA_TAB = it_vbak

  • 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.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " download_excel

&----


*& Form download_text

&----


FORM download_text .

ENDFORM. " download_text

&----


*& Form select_dt

&----


FORM select_dt .

select vbeln auart audat from vbak

into table it_vbak where

vbeln in s_vbeln.

ENDFORM. " select_dt

&----


*& Form file_get

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM file_get.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

DEF_PATH = 'C:\Temp\'

MASK = ',.,..'

MODE = 'O'

TITLE = 'Select File'(007)

IMPORTING

FILENAME = P_file

EXCEPTIONS

INV_WINSYS = 1

NO_BATCH = 2

SELECTION_CANCEL = 3

SELECTION_ERROR = 4

OTHERS = 5.

ENDFORM. " file_get

Thanks

Seshu

Former Member
0 Kudos

Use this, to choice the location and the name:

  

 DATA:  lv_path      TYPE string VALUE 'def_file_nm.xls',
        lv_fullpath  TYPE string,
        lc_c         TYPE string.

CALL METHOD cl_gui_frontend_services=>file_save_dialog
    EXPORTING
      window_title        = 'title window'
      default_extension   = '.xls'
      default_file_name   = lv_path
      initial_directory   = lc_c
    CHANGING
      filename            = lv_path
      path                = lc_c
      fullpath            = lv_fullpath
    EXCEPTIONS
      cntl_error          = 1
      error_no_gui        = 2
      OTHERS              = 3
          .


CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = lv_fullpath
FILETYPE = 'ASC'
TABLES
DATA_TAB = it_vbak
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.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

Tell me if it's ok

Message was edited by:

Pasquale Isolato