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 ABAP Program to Upload a file's data to Presentation Server

Former Member
0 Likes
9,894

I created a .txt file which contains simple string " Hello " . I want 2 upload this string 2 presentaion server,for that i called GUI_UPLOAD METHOD also,am getting problem while declaration of Internal table at beging,that Hello string does't going to presentaion server...can u send the program....!

4 REPLIES 4
Read only

Former Member
0 Likes
5,725

Hi Aravind,

If i have understood your question correctly ....declare your internal table with a character string variable and upload it accordingly...

i.e,


data : begin of itab occurs 0,
         string(100),
        end of itab.
 

use this itab in the UPLOAD FM ....

Regards,

Santosh

Read only

Former Member
0 Likes
5,725

hi this is the program for both the servers,

&----


*& Report ZTESTPROGRAMFORUPLOAD

*&

&----


*&

*&

&----


REPORT ZTESTPROGRAMFORUPLOAD message-id zmsg.

tables:pa0002.

types:begin of ty_pa0000,

pernr like pa0000-pernr,

endda like pa0000-begda,

end of ty_pa0000.

types:begin of ty_pa0002,

pernr like pa0002-pernr,

begda like pa0002-begda,

endda like pa0002-endda,

vorna like pa0002-vorna,

nachn like pa0002-nachn,

end of ty_pa0002.

data:it_pa0000 type standard table of ty_pa0000 with header line,

it_pa0002 type standard table of ty_pa0002 with header line.

data: v_pernr like pa0002-pernr,

v_lines type i.

DATA: W_MSG(150) TYPE C.

SELECTION-SCREEN BEGIN OF BLOCK FILE WITH FRAME TITLE TEXT-FIL.

*SELECTION-SCREEN BEGIN OF LINE.

PARAMETERS: P_PC RADIOBUTTON GROUP RAD USER-COMMAND USR. "PC

*SELECTION-SCREEN COMMENT 3(5) TEXT-SC1.

PARAMETERS: P_UNIX RADIOBUTTON GROUP RAD DEFAULT 'X'. "UNIX

*SELECTION-SCREEN COMMENT 11(5) TEXT-SC2.

parameters:p_file like rlgrap-filename.

*SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK FILE.

at selection-screen on value-request for p_file.

perform f4_help.

START-OF-SELECTION.

*---Get the active employyes

select pernr

endda

from pa0000

into table it_pa0000 up to 100 rows

where endda >= sy-datum

and begda <= sy-datum

and stat2 = '3'.

if sy-subrc = 0.

sort it_pa0000 by pernr endda descending.

delete adjacent duplicates from it_pa0000 comparing pernr.

endif.

select pernr

begda

endda

vorna

nachn

from pa0002

into table it_pa0002

for all entries in it_pa0000

where pernr = it_pa0000-pernr.

sort it_pa0002 by pernr.

delete adjacent duplicates from it_pa0002 comparing pernr.

append it_pa0002.

  • endloop.

END-OF-SELECTION.

describe table it_pa0002 lines v_lines .

*---get data into Application Server.

PERFORM OUTPUT_CORPEDIA_VENDOR_FILE .

SKIP 2.

WRITE:/ 'FILE NAME :' , P_FILE .

WRITE:/ 'NO OF RECORDS DOWNLOADED : ', V_LINES .

&----


*& Form f4_help

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form f4_help .

IF P_UNIX = 'X'.

  • F4 help for UNIX

CALL FUNCTION 'F4_DXFILENAME_4_DYNP'

EXPORTING

DYNPFIELD_FILENAME = 'P_FILE'

DYNAME = SY-CPROG

DYNUMB = SY-DYNNR

FILETYPE = 'P'

LOCATION = 'A'

SERVER = ''.

IF SY-SUBRC <> 0.

MESSAGE E000 WITH TEXT-E01 P_FILE.

ENDIF.

ELSEIF P_PC = 'X'.

  • F4 help for PC

clear p_file.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

DEF_PATH = P_FILE

MASK = ',..'

MODE = '0 '

TITLE = 'Choose File'

IMPORTING

FILENAME = P_FILE

EXCEPTIONS

INV_WINSYS = 1

NO_BATCH = 2

SELECTION_CANCEL = 3

SELECTION_ERROR = 4

OTHERS = 5.

ENDIF.

endform. " f4_help

&----


*& Form OUTPUT_CORPEDIA_VENDOR_FILE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form OUTPUT_CORPEDIA_VENDOR_FILE .

IF P_PC = 'X'.

data: v_pcfile type string.

v_pcfile = p_file.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = v_pcfile

FILETYPE = 'ASC'

WRITE_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = it_pa0002.

sort it_pa0002 by pernr.

delete adjacent duplicates from it_pa0002.

else.

data: outrec(200) type c .

OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE encoding DEFAULT.

loop at it_pa0002.

outrec+0(8) = it_pa0002-pernr.

outrec+18(8) = it_pa0002-begda.

outrec+36(8) = it_pa0002-endda.

outrec+54(40) = it_pa0002-vorna.

outrec+104(40) = it_pa0002-nachn.

transfer outrec to p_file.

clear outrec.

endloop.

CLOSE DATASET OUTREC.

IF SY-SUBRC = 0.

CLEAR W_MSG.

CONCATENATE 'Corpedia Vendor Demographic File successfully written to:'

P_FILE

INTO W_MSG SEPARATED BY SPACE.

ULINE. SKIP.

WRITE : W_MSG.

ENDIF.

ENDIF.

endform. " OUTPUT_CORPEDIA_VENDOR_FILE

regards,

venkat.

Read only

Former Member
0 Likes
5,725

This will handle a tab delmited file. If you only have one field, it will also work fine.


DATA:
  BEGIN OF in_rec,
    leadid                   TYPE zleadid,
    branch_to                TYPE werks_d,
  END OF in_rec,
  it_conv LIKE STANDARD TABLE OF in_rec.


PARAMETERS: zfile         LIKE rlgrap-filename OBLIGATORY.



    CALL FUNCTION 'WS_UPLOAD'
         EXPORTING
              filename        = zfile
              filetype        = 'DAT'
         TABLES
              data_tab        = it_conv
         EXCEPTIONS
              file_open_error = 2
              file_read_error = 3.

Read only

Former Member
0 Likes
5,725

You should do like this

report ztest_1.

data: begin of itab occurs 0,

str type string,

end of itab.

itab-str = 'hello'.

append itab.

data: fname type string.

fname = 'C:\Documents and Settings\hbf5099.HALHOUSTON\Desktop\test.txt'.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

FILENAME = fname

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 = ' '

  • WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE

  • SHOW_TRANSFER_STATUS = ABAP_TRUE

  • IMPORTING

  • FILELENGTH =

TABLES

DATA_TAB = itab

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