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

GUI_UPLOAD to upload flat file to internal table

Hi Experts,

I have to upload a flat file which has multiple records ,from a local server.The fields in records are ~ saperated.

Presently i am only looking into uploading the flat file into internal table.

I have done the following coding;

TYPES: BEGIN OF gt_frmgt ,

tablety type c length 10 ,

tablenm type c length 30,

numin type c length 2,

END OF gt_frmgt.

TYPES: begin of gt_frmgto,

rec(1000) type c,

end of gt_frmgto.

DATA: Itgt_frmgt type table of gt_frmgt with header line.

DATA: itgt_frmgto type table of gt_frmgto with header line.

DATA: lfile_path type string.

PARAMETERS: f_path type localfile.

at selection-screen on value-request for f_path.

call function 'KD_GET_FILENAME_ON_F4'

EXPORTING

static = 'X'

CHANGING

file_name = f_path.

start-of-selection.

lfile_path = f_path.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = lfile_path

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • VIRUS_SCAN_PROFILE =

  • NO_AUTH_CHECK = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

DATA_TAB = itgt_frmgto

  • EXCEPTIONS

  • FILE_OPEN_ERROR = 1

  • FILE_READ_ERROR = 2

  • NO_BATCH = 3

  • GUI_REFUSE_FILETRANSFER = 4

  • INVALID_TYPE = 5

  • NO_AUTHORITY = 6

  • UNKNOWN_ERROR = 7

  • BAD_DATA_FORMAT = 8

  • HEADER_NOT_ALLOWED = 9

  • SEPARATOR_NOT_ALLOWED = 10

  • HEADER_TOO_LONG = 11

  • UNKNOWN_DP_ERROR = 12

  • ACCESS_DENIED = 13

  • DP_OUT_OF_MEMORY = 14

  • DISK_FULL = 15

  • DP_TIMEOUT = 16

  • OTHERS = 17

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

  • delete itgt_frmgto index 1.

loop at itgt_frmgto.

clear Itgt_frmgt.

split itgt_frmgto-rec at cl_abap_char_utilities=>vertical_tab

into Itgt_frmgt-tablety

Itgt_frmgt-tablenm

Itgt_frmgt-numin.

append Itgt_frmgt.

endloop.

loop at Itgt_frmgt.

write:/ Itgt_frmgt-tablety, Itgt_frmgt-tablenm, Itgt_frmgt-numin.

The input file in Local path is ;

XXXXXXX~~Export the invoice

2~19980501~19980531

// The first invoice:

0~00130698114000010004119980512059611000276233.350.1711076.66????321000789010005???????????????????130601000000000??????????18? 3352051????532611-3357211???~~~

0~????????176233.350.1711076.6676233.350~1510

// The second invoice:

0~00130698114000010007219980512059611000440482.000.175882.00????110108078901007?????????61? 68744479?????????????462088-07?????130601000000000??????????18? 3352051????532611-3357211???????????~~~

0~????????139780.000.175780.0039780.000~1510

0~????3.5"10702.000.17102.0070.20~1510

and the output is :

XXXXXXX~~

2~~1998050

// The fir

0~00~1

0~????~?

// The sec

0~00~1

0~????~?

0~????

I am unable to understand why this split is happening .According to me the first 3 fields should be displayed without field saperater.

It would be very much appreciated if any body has little idea about this.

Thankx,

Priya

Message was edited by:

Priya Parmeshwar Shiggaon

Message was edited by:

Priya Parmeshwar Shiggaon

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 05, 2007 at 09:12 AM

    Hi Priya,

    GUI_UPLOAD will not work in background mode. If you want to run the report in background you need the file on application server and you have to use open dataset to upload the file onto application server.

    Best Regards,

    Vibha

    *Please mark all the helpful answers

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      if it is one time upload then u can use transaction CG3Z n upload file on application server.

      u can tno use Gui_upload in background.

      Program to upload file via gui_upload in foreground -(open fiel in Excel format and then make changes and save it as text tab file and upload tht file) -

      REPORT Z_AMIT_BAPI

      no standard page heading line-size 255.

      parameters: p_file like rlgrap-filename default 'C:\temp\emp.txt'.

      data :begin of itab occurs 0,

      pernr(8),

      bdate(10),

      edate(10),

      mail(30) ,

      end of itab.

      Start-of-selection.

      Perform read_file.

      &----


      *& Form read_file

      &----


      • text

      ----


      • --> p1 text

      • <-- p2 text

      ----


      FORM read_file .

      DATA: full_file_name TYPE string.

      full_file_name = p_file.

      CALL FUNCTION 'GUI_UPLOAD'

      EXPORTING

      FILENAME = full_file_name

      FILETYPE = 'ASC'

      HAS_FIELD_SEPARATOR = ','

      • HEADER_LENGTH = 0

      • READ_BY_LINE = 'X'

      • DAT_MODE = ' '

      • CODEPAGE = ' '

      • IGNORE_CERR = ABAP_TRUE

      • REPLACEMENT = '#'

      • CHECK_BOM = ' '

      • NO_AUTH_CHECK = ' '

      • IMPORTING

      • FILELENGTH =

      • HEADER =

      TABLES

      DATA_TAB = itab

      EXCEPTIONS

      FILE_OPEN_ERROR = 1

      FILE_READ_ERROR = 2

      NO_BATCH = 3

      GUI_REFUSE_FILETRANSFER = 4

      INVALID_TYPE = 5

      NO_AUTHORITY = 6

      UNKNOWN_ERROR = 7

      BAD_DATA_FORMAT = 8

      HEADER_NOT_ALLOWED = 9

      SEPARATOR_NOT_ALLOWED = 10

      HEADER_TOO_LONG = 11

      UNKNOWN_DP_ERROR = 12

      ACCESS_DENIED = 13

      DP_OUT_OF_MEMORY = 14

      DISK_FULL = 15

      DP_TIMEOUT = 16

      OTHERS = 17

      .

      IF SY-SUBRC <> 0.

      MESSAGE e000(000) WITH 'Upload-Error; RC:' sy-subrc.

      ENDIF.

      ENDFORM. " read_file

      reward points if helpfull

      amit

  • author's profile photo Former Member
    Former Member
    Posted on Jan 05, 2007 at 09:20 AM

    Hi

    but the character of cl_abap_char_utilities=>vertical_tab is # not ~

    Max

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi

      If you need to split the file:

      loop at itgt_frmgto.
        clear Itgt_frmgt.
      *split itgt_frmgto-rec at cl_abap_char_utilities=>vertical_tab
        split itgt_frmgto-rec at '~' "<---------------------------
        into Itgt_frmgt-tablety
              Itgt_frmgt-tablenm
              Itgt_frmgt-numin.
        append Itgt_frmgt.
      endloop.

      Max

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.