Application Development and Automation 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: 
Read only

sample code for downloading in application server.

Former Member
0 Likes
929

hi,

please give me sample code for downloading the file in application server using open data set .

points sure.

regards

prabhu

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
839

Here is an example of writing a file to the application server.


report zrich_0001.

parameters: d1 type localfile default '/usr/sap/TST/SYS/Test.txt'.

data: begin of itab occurs 0,
      field1(20) type c,
      field2(20) type c,
      field3(20) type c,
      end of itab.
data: str type string.

constants: con_tab type x value '09'.

* if you have a newer version, then you can use this instead.
*constants:
*    con_tab  type c value cl_abap_char_utilities=>HORIZONTAL_TAB.

start-of-selection.

itab-field1 = 'ABC'.
itab-field2 = 'DEF'.
itab-field3 = 'GHI'.
append itab.

itab-field1 = '123'.
itab-field2 = '456'.
itab-field3 = '789'.
append itab.

  open dataset d1 for output in text mode.
  loop at itab.
    concatenate itab-field1 itab-field2 itab-field2 into str
                  separated by con_tab.
    transfer str to d1.
  endloop.
  close dataset d1.

Regards,

RIch Heilman

6 REPLIES 6
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
840

Here is an example of writing a file to the application server.


report zrich_0001.

parameters: d1 type localfile default '/usr/sap/TST/SYS/Test.txt'.

data: begin of itab occurs 0,
      field1(20) type c,
      field2(20) type c,
      field3(20) type c,
      end of itab.
data: str type string.

constants: con_tab type x value '09'.

* if you have a newer version, then you can use this instead.
*constants:
*    con_tab  type c value cl_abap_char_utilities=>HORIZONTAL_TAB.

start-of-selection.

itab-field1 = 'ABC'.
itab-field2 = 'DEF'.
itab-field3 = 'GHI'.
append itab.

itab-field1 = '123'.
itab-field2 = '456'.
itab-field3 = '789'.
append itab.

  open dataset d1 for output in text mode.
  loop at itab.
    concatenate itab-field1 itab-field2 itab-field2 into str
                  separated by con_tab.
    transfer str to d1.
  endloop.
  close dataset d1.

Regards,

RIch Heilman

Read only

Manohar2u
Active Contributor
Read only

Former Member
0 Likes
839

Hi Prabhu,

Check this link.

Reward if useful.

Thanks

Aneesh.

Read only

Former Member
0 Likes
839

hi,

Here is the code

REPORT ZSANTESTAPP NO STANDARD PAGE HEADING

LINE-SIZE 255

LINE-COUNT 65

MESSAGE-ID 00.

SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-001.

PARAMETERS : P_FILE LIKE RLGRAP-FILENAME OBLIGATORY DEFAULT

'c:\'.

SELECTION-SCREEN END OF BLOCK B2 .

data: begin of itab occurs 0,

str1(6000) type c,

end of itab.

data: dsn(50) type c value

'/celestica/interface/corp/in/work/735.txt'.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

DEF_FILENAME = P_FILE

MASK = ',.,..'

MODE = 'O'

TITLE = TEXT-033

IMPORTING

FILENAME = P_FILE

EXCEPTIONS

INV_WINSYS = 1

NO_BATCH = 2

SELECTION_CANCEL = 3

SELECTION_ERROR = 4

OTHERS = 5.

CASE SY-SUBRC.

WHEN 1.

MESSAGE E001 WITH TEXT-073.

STOP.

WHEN 2.

MESSAGE E001 WITH TEXT-074.

STOP.

ENDCASE.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

  • CODEPAGE = ' '

FILENAME = p_file

FILETYPE = 'ASC'

  • HEADLEN = ' '

  • LINE_EXIT = ' '

  • TRUNCLEN = ' '

  • USER_FORM = ' '

  • USER_PROG = ' '

  • DAT_D_FORMAT = ' '

  • IMPORTING

  • FILELENGTH =

TABLES

data_tab = itab

  • EXCEPTIONS

  • CONVERSION_ERROR = 1

  • FILE_OPEN_ERROR = 2

  • FILE_READ_ERROR = 3

  • INVALID_TYPE = 4

  • NO_BATCH = 5

  • UNKNOWN_ERROR = 6

  • INVALID_TABLE_WIDTH = 7

  • GUI_REFUSE_FILETRANSFER = 8

  • CUSTOMER_ERROR = 9

  • OTHERS = 10

.

IF sy-subrc <> 0.

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

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

ENDIF.

OPEN DATASET dsn FOR output in TEXT MODE .

CHECK SY-SUBRC = 0.

loop at itab.

TRANSFER itab-str1 TO dsn.

endloop.

close dataset dsn.

Reward points if it is helpful.

Regards,

Sangeetha.a

Read only

Former Member
0 Likes
839

Hi

try the Transaction

<b>CG3Y</b>

to download the file on application server to Local system

without writing the code.

Reward points for useful Answers

Regards

Anji

Read only

Former Member
0 Likes
839

hi,

u follow this syntax for down loading data into application server.

<u> FOR CREATING FILE OVER APPLICATION SERVER.</u>

<b>open dataset <name of dataset> for output.

loop at <internal table> from <n> to <n>.

transfer <internal table> to <name of dataset>.

endloop.

close dataset <name of dataset>.</b>

<u>READING DATA FROM APPLICATION SERVER.</u>

<b>open dataset <name of dataset> for input.

do.

read dataset <file name> into <internal table>.

if sy-subrc < > 0.

exit.

endif.

    • here u provide logic as per u r requirement.

enddo.

close dataset <name of dataset></b>

regards,

sudheer.