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: 

Uploading file from presentation server

Former Member
0 Kudos

Hello !

I want to upload file with data <u>from the presentation server</u> into an Internal Table

(in my abap program).

I can't use 'gui_upload' function - because My

program ran in background.

Also - can't use 'upload' and 'ws_upload' functions

because they are obselete. (in ECC5)

What function can I use to upload the file in

background processing ?

Thanks ,

N.S.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

First upload your file using CG3Z transaction.

Then use the following code to read the file from application server.

CALL FUNCTION 'FILE_GET_NAME'

EXPORTING

LOGICAL_FILENAME = P_INFILE

IMPORTING

FILE_NAME = INPUTFILE

EXCEPTIONS

FILE_NOT_FOUND = 1

OTHERS = 2.

IF SY-SUBRC NE 0.

MESSAGE E899 WITH text-064 P_INFILE text-065.

ENDIF.

  • Open the inputfile for reading in text mode

OPEN DATASET INPUTFILE FOR INPUT IN TEXT MODE.

IF SY-SUBRC NE 0.

MESSAGE E899 WITH text-066 INPUTFILE text-067.

ENDIF.

DO.

READ DATASET INPUTFILE INTO TEXT2 . "LENGTH LENG.

MOVE TEXT2 TO I_MATCONV.

APPEND I_MATCONV.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ENDDO.

CLOSE DATASET INPUTFILE.

Regards,

Gayathri

6 REPLIES 6

ferry_lianto
Active Contributor
0 Kudos

Hi Nitzan,

You can use ABAP command <b>OPEN DATASET <dsn> [FOR ....] [IN ... MODE] AT POSITION <pos></b>.

And check this link for sample code.

http://www.sapgenie.com/abap/code/abap6.htm

Hope this will help.

Regards,

Ferry Lianto

0 Kudos

Hi,

You will first have to put the frontend file onto the Application server before using the OPEN DATASET statement in your program. For that you can use the Transaction CG3Z.

Regards,

Suresh Datti

Former Member
0 Kudos

Hi,

First upload your file using CG3Z transaction.

Then use the following code to read the file from application server.

CALL FUNCTION 'FILE_GET_NAME'

EXPORTING

LOGICAL_FILENAME = P_INFILE

IMPORTING

FILE_NAME = INPUTFILE

EXCEPTIONS

FILE_NOT_FOUND = 1

OTHERS = 2.

IF SY-SUBRC NE 0.

MESSAGE E899 WITH text-064 P_INFILE text-065.

ENDIF.

  • Open the inputfile for reading in text mode

OPEN DATASET INPUTFILE FOR INPUT IN TEXT MODE.

IF SY-SUBRC NE 0.

MESSAGE E899 WITH text-066 INPUTFILE text-067.

ENDIF.

DO.

READ DATASET INPUTFILE INTO TEXT2 . "LENGTH LENG.

MOVE TEXT2 TO I_MATCONV.

APPEND I_MATCONV.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ENDDO.

CLOSE DATASET INPUTFILE.

Regards,

Gayathri

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

As Suggested,use CG3Z transaction to put the file into application server.

Then use the following sample code,to read the file from there to internal table.

data : G_AFILE1(100) TYPE C,
       G_DATA(1000) TYPE C,
G_DELIM TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
DATA: BEGIN OF T_INPUT OCCURS 0, " Flat file data
       PERNR(9) TYPE C,
       AMOUNT(15) TYPE C,
       W_TYPE(5) TYPE C,
      END OF T_INPUT.




  OPEN DATASET G_AFILE1 FOR INPUT IN TEXT MODE ENCODING DEFAULT.
  IF SY-SUBRC = 0.
    DO.
      READ DATASET G_AFILE1 INTO G_DATA.
      IF SY-SUBRC = 0.
        SPLIT G_DATA AT G_DELIM INTO T_INPUT-PERNR  T_INPUT-AMOUNT                                                  T_INPUT-W_TYPE .
        IF SY-SUBRC = 0.
          APPEND T_INPUT.
          CLEAR T_INPUT.
        ELSE.
"Message:Incorrect data format in file
        ENDIF.
      ELSE.
        EXIT.                  "After reading last Record
      ENDIF.
    ENDDO.
  ELSE.
 "Message:File Opening Error
  ENDIF.

Former Member
0 Kudos

Hi,

<a href="http://www.sap-img.com/ab004.htm">http://www.sap-img.com/ab004.htm</a>

hope this link is useful..

regards,

chithra

0 Kudos

Thank you all.