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

Rqd ABAP program

Former Member
0 Likes
878

Hi all,

I want to write or upload the flat file(csv file) to the apllication server.for this i need ABAP program in order to write the file to Application server.could u plz provide the code with explanation?.i will assign points for the correct answers.....

Thanks & regards,

nani

6 REPLIES 6
Read only

Former Member
0 Likes
817

Hi,

Maintaining InfoSources (Flat File)

Purpose

You can load data from flat files (CSV or ASCII files) into BW.

You can load the following data types:

...

1. Transaction Data

2. Master data, either directly or flexibly

¡ Attributes

¡ Texts

3. Hierarchies

Prerequisites

Note the following with regard to CSV files:

· Excel files use delimiters to separate fields. In the European version, a semi-colon ( is used as a delimiter. In the American version, a comma (,) is used. You can use other delimiters. You must specify the delimiter used in the Scheduler.

· Fields that are not filled in a CSV file are filled with a blank space if they are character fields and with a zero (0) if they are numerical fields.

· If delimiters are used inconsistently in a CSV file, the u201Cwrongu201D delimiter is read as a character, and both fields are merged into one field and possibly shortened. Subsequent fields are no longer in the correct order.

Note the following with regard to CSV files and ASCII files:

· If your file contains headers that you do not want to be loaded, on the External Data tab page in the Scheduler, specify the number of headers that you want the system to ignore during the data load. This gives you the option of keeping the column headers in your file.

· A conversion routine determines whether or not you have to specify leading zeros. See also Conversion Routines in BW.

· For dates, you usually use the format YYYYMMDD, without internal delimiters. Depending on the conversion routine, you can also use other formats.

· If you use IDocs to upload data, note the 1000 byte limit per data record length. This limit does not apply to data that is uploaded using the PSA.

Notes on Uploading

· When you upload external data, you have the option of loading the data from any workstation into BW. For performance reasons, however, you should store the data on an application server and load it from there into BW. This also enables you to load the data in the background.

· If you want to upload a large amount of transaction data from a flat file, and you are able to specify the file type of the flat file, you should create the flat file as an ASCII file. For performance reasons, uploading the data from an ASCII file is the most cost-effective method. Under certain circumstances, generating an ASCII file might involve more work.

Regards,

Jagadish

Read only

prasanth_kasturi
Active Contributor
Read only

0 Likes
817

Hi prasant!,

thanks for ur reply.......i didn't understand actually iam new to ABAP..can u explain clearly.i want to know wheather this small code is enough to download a flat file in to application server from desktop.plz provide the full code.

thanks

nani

Read only

0 Likes
817

Hi Nani,

Writing a file in file server is not a big deal once your internal table with data is ready.

All you need do is to use OPEN DATASET, TRANSFER and CLOSE DATASET.

OPEN DATASET creates the file in fileserver.

TRANSFER - Transfers the ITab contents to file server.

CLOSE DATASET closes the file in the application server.

You can view the file in Application server using t-code Al11.

Hope this explains you.

Thanks,

Arun

Read only

Former Member
0 Likes
817

Hi,

If I remember correctly, when using OPEN DATASET, the file name can not have spaces in the name. Try renaming your file removing spaces and retry.

For your code, you'll need to breakdown the CSV file by the delimiter.

This code makes an archive file while reading the main file.

OPEN DATASET filname IN TEXT MODE MESSAGE t_mesg.

IF sy-subrc NE 0.

MOVE 'X' TO t_error.

MESSAGE e100(z0) WITH 'Error reading file:' t_mesg.

EXIT.

ENDIF.

IF p_load = 'X'.

OPEN DATASET archfilname FOR OUTPUT IN TEXT MODE MESSAGE t_mesg.

IF sy-subrc NE 0.

MOVE 'X' TO t_error.

MESSAGE e100(z0) WITH 'Error opening achrive file:' t_mesg.

EXIT.

ENDIF.

ENDIF.

DO.

READ DATASET filname INTO my_rec.

IF sy-subrc NE 0.

EXIT.

ENDIF.

IF p_load = 'X'.

TRANSFER my_rec TO archfilname.

ENDIF.

SPLIT my_rec AT c_tab " Here my delimter was a tab change to ',' for comma

INTO in_rec-id

in_rec-fname

in_rec-lname

in_rec-addr

in_rec-apt

in_rec-city

in_rec-state

in_rec-zip

in_rec-branch

in_rec-phone1

in_rec-phone2

in_rec-phone3

in_rec-phone3_ext

in_rec-email

in_rec-hear

in_rec-prefcont

in_rec-ownland

in_rec-build

in_rec-ownhome

  • in_rec-get_promo

in_rec-cmt1

in_rec-subdate.

APPEND in_rec TO it_input.

ENDDO.

CLOSE DATASET filname.

IF p_load = 'X'.

CLOSE DATASET archfilname.

DELETE DATASET filname.

ENDIF.

ENDIF.

Refer This:

Regards,

Shiva Kumar

Read only

Former Member
0 Likes
817

Hi,

First upload the CSV file into Internal table and then write the internal table data into Application server

TYPES:  BEGIN OF tys_dummy,
                 dummy TYPE char1000,
             END OF tys_dummy.
DATA: gt_dummy   TYPE STANDARD TABLE OF tys_dummy ,
      gs_dummy    TYPE tys_dummy.

  CLEAR gv_file.
  gv_file = pa_file.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = gv_file
      filetype                = gc_asc
      has_field_separator     = gc_x
    TABLES
      data_tab                = gt_dummy
    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 NE gc_zero_num.
    MESSAGE i006.
    LEAVE LIST-PROCESSING.
  ENDIF.

* Check if the input file is blank
  IF gt_dummy[] IS INITIAL.
    MESSAGE i007.
    LEAVE LIST-PROCESSING.
  ENDIF.
* To remove quotes in the table
  LOOP AT gt_dummy INTO gs_dummy.                  
    gv_tabix = sy-tabix.
    DO.
      IF gs_dummy CA '"'.
        REPLACE '"' WITH space INTO gs_dummy.
      ELSE.
        WRITE gs_dummy TO gs_dummy NO-GAP.
        CONDENSE gs_dummy.
        MODIFY gt_dummy INDEX gv_tabix FROM gs_dummy.
        EXIT.
      ENDIF.
    ENDDO.
  ENDLOOP.

Here use
 OPEN DATASET '/tmp/csv.txt' IN TEXTMODE DEFAULT ENCODING. 
Loop at gt_dummy into gs_dummy.
TRANSFER gs_dummy to '/tmp/csv.txt' .
endloop.
CLOSE DATASET '/tmp/csv.txt' .

Regards

Kannaiah