Skip to Content
author's profile photo Former Member
Former Member

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

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Aug 30, 2007 at 02:49 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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.

  • author's profile photo Former Member
    Former Member
    Posted on Aug 30, 2007 at 03:15 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 30, 2007 at 03:11 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.