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:Β 

Dumping data from internal table to local file.

Former Member
0 Kudos

Hi all,

Here is the sample code with which I am trying to write the contents of an internal table to a local file using ws_download function module.

The error it shows is : error when opening the download file.

please check the code and tell where i am going wrong.

REPORT zv_ittable_localfile.

DATA : BEGIN OF itab OCCURS 0 ,

carrid LIKE sflight-carrid,

connid LIKE sflight-connid,

fldate LIKE sflight-fldate,

END OF itab.

SELECT carrid connid fldate

INTO CORRESPONDING FIELDS OF TABLE itab

FROM sflight.

*loop at itab.

*write πŸ˜• itab-carrid,itab-connid,itab-fldate.

*endloop.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

FILENAME = 'C:/Documents and

Settings/nsi/Desktop/vijay'

FILETYPE = 'ASC'

MODE = ' '

TABLES

data_tab = itab

  • FIELDNAMES =

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_WRITE_ERROR = 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.

points will be awarded.

Regards,

Vijay.

14 REPLIES 14

Former Member
0 Kudos

Give an extension to the file.

Hi Vijay,

Close the file when you are uploading or executing the program.

Message was edited by: Phani Kiran Nudurupati

0 Kudos

Hi,

The file is already closed. check what I have to specify at the mode in export parameters I do not know what should be spcified there.

Regards,

Vijay.

0 Kudos

I actually have no problem running your code. It writes the file successfully.

Regards,

Rich Heilman

0 Kudos

The function module GUI_DOWNLOAD is a more recent version, please try using it.




report zrich_0001.

data : begin of itab occurs 0 ,
carrid like sflight-carrid,
connid like sflight-connid,
fldate like sflight-fldate,
end of itab.

select carrid connid fldate
into corresponding fields of table itab
from sflight.


*loop at itab.
*write πŸ˜• itab-carrid,itab-connid,itab-fldate.
*endloop.

call function 'GUI_DOWNLOAD'
  exporting
    filename
    = 'C:/Documents and Settings/heilmanr/Desktop/text.txt'
  tables
    data_tab                      = itab
 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.


Regards,

Rich Heilman

0 Kudos

Hi rich,

what are the values you have passed to file name, file type and write mode expport parameters.

Reards,

vijay.

0 Kudos

Nothing to specify vijay.Its absolutely fine.It worked for me too.

0 Kudos


REPORT  ZTESTAA                                 .




DATA : BEGIN OF itab OCCURS 0 ,
carrid LIKE sflight-carrid,
connid LIKE sflight-connid,
fldate LIKE sflight-fldate,
END OF itab.

SELECT carrid connid fldate
INTO CORRESPONDING FIELDS OF TABLE itab
FROM sflight.


*loop at itab.
*write πŸ˜• itab-carrid,itab-connid,itab-fldate.
*endloop.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING
FILENAME = 'C:test.txt'
FILETYPE = 'ASC'
MODE = ' '

TABLES
data_tab = itab
* FIELDNAMES =
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_WRITE_ERROR = 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.

the code is working fine...

i checked it is working,i changed the filename.

may be the file path you have give wrong. give properly

regards

vijay

0 Kudos

When you give mode as 'A' it will append the file with the new data when ever you execute the program.IF mode is space it will Overwrite the data.

File name & file type is as given by you.

0 Kudos

Hi Vijay,

When you are downloading to desktop and using the directories that are longer than 8 characters, particularly with spaces etc, you cannot hardcode the directory as you did. You have to take it from the screen as a parameter and pass it to the call. That way the conversion from the long name directories to underlying DOS 8 character directory names will be taken care of by the system. Here is the code.


DATA : BEGIN OF itab OCCURS 0 ,
         carrid LIKE sflight-carrid,
         connid LIKE sflight-connid,
         fldate LIKE sflight-fldate.
DATA: END OF itab.

PARAMETERS: p_file LIKE rlgrap-filename.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
*       EXPORTING
*            program_name  = syst-repid
*            dynpro_number = syst-dynnr
*            field_name    = ' '
*            static        = ' '
*            mask          = ' '
       CHANGING
            file_name     = p_file
       EXCEPTIONS
            mask_too_long = 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.

START-OF-SELECTION.
  SELECT carrid connid fldate
    INTO CORRESPONDING FIELDS OF TABLE itab
    FROM sflight.

  CALL FUNCTION 'WS_DOWNLOAD'
      EXPORTING
        filename = p_file
        filetype = 'ASC'
        mode = ' '
      TABLES
        data_tab = itab
*       FIELDNAMES =
      EXCEPTIONS
        file_open_error = 1
        file_write_error = 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.

govind_seenivasan
Participant
0 Kudos

Hi,

Check the directory is exists and valid.

Thanks

Govind.

Former Member
0 Kudos

try

FILENAME = 'C:\Documents and

Settings\nsi\Desktop\vijay.txt'

Former Member
0 Kudos

Hi Vijay,

The thing is u did not mention the file type like (.txt).

it is as simple as that.

please go through below code.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

FILENAME = 'C:/vijay.txt'

FILETYPE = 'ASC'

MODE = ' '

TABLES

data_tab = itab

  • FIELDNAMES =

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_WRITE_ERROR = 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.

use the code like this.

cheers,

vengal.

0 Kudos

DATA : BEGIN OF itab OCCURS 0 ,

carrid LIKE sflight-carrid,

connid LIKE sflight-connid,

fldate LIKE sflight-fldate,

END OF itab.

SELECT carrid connid fldate

INTO CORRESPONDING FIELDS OF TABLE itab

FROM sflight.

*loop at itab.

*write πŸ˜• itab-carrid,itab-connid,itab-fldate.

*endloop.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

FILENAME = 'C:\test.txt'

FILETYPE = 'ASC'

MODE = ' '

TABLES

data_tab = itab

  • FIELDNAMES =

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_WRITE_ERROR = 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.

0 Kudos

DATA : BEGIN OF itab OCCURS 0 ,

carrid LIKE sflight-carrid,

connid LIKE sflight-connid,

fldate LIKE sflight-fldate,

END OF itab.

SELECT carrid connid fldate

INTO CORRESPONDING FIELDS OF TABLE itab

FROM sflight.

*loop at itab.

*write πŸ˜• itab-carrid,itab-connid,itab-fldate.

*endloop.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

FILENAME = 'C:\test.txt'

FILETYPE = 'ASC'

MODE = ' '

TABLES

data_tab = itab

  • FIELDNAMES =

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_WRITE_ERROR = 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.