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

ABAP Tab

Former Member
0 Likes
2,320

Hi,

I am new to Abap. I have a problem. When I upload my text file (.txt) to SAP, the spacing during the upload is different.Can someone help me.

My program tab is

DATA: V_SEPARATOR TYPE X.

DATA: L_VALUE TYPE I VALUE 09.  "09=TAB  44=,  124=|

V_SEPARATOR = L_VALUE.

Hi,

Step-1   Take a Backup of source data.

Step-2  Save the file in .XLS

Step-3 Save the source data(.XLS) FILE as CSV comma delimitted

Step-4 save the csv file into .txt(ms-dos) format

step-5 open the txt file u will see tab delimited will be replaced by ,

step-6 goto replace option find comma with SPACE Replace all

Thanks

Sudhi ranjan parija

13 REPLIES 13
Read only

Former Member
0 Likes
2,277

Hello,

Can you send your source code and file so that we can help?

Ali Murat

Read only

0 Likes
2,277

how do i send you the source code???

Read only

0 Likes
2,277

This message was moderated.

Read only

0 Likes
2,277

there are alot of given functions /classes for importing files.

but if you want to know how to do it manuel with open Dataset and read dataset, the best way is to read into a structure which consists only of char fields - make sure that the rows are fixed - e.g. by using leading 0 in number fields and using space in char fields. After that transfer to ur wanted structure and do the mappings into other filedtypes. like int or packed.

regards

Stefan Seeburger

Read only

Mohamed_Mukhtar
Active Contributor
0 Likes
2,277

Hello ,

Do a word wrap in notepad before uploading to SAP.

Thanks

Read only

Former Member
0 Likes
2,277

Hello,

I prepared a sample code for you. The below code is just enough for your requirement.

Please implement this code into your original source code. The below code is the part that reads the data from text file.

Regards

Ali Murat

DATA : BEGIN OF gt_p OCCURS 0       ,

          pernr LIKE pa0001-pernr   ,

          begda(10)                 ,

          status(4)                 ,

          msgtx(100)                ,

          mark                      ,

END OF gt_p.

DATA : file    TYPE STANDARD TABLE OF file_table.

DATA : wa_file TYPE STANDARD TABLE OF file_table WITH HEADER LINE.

DATA : rc TYPE i.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS : p_file(100) OBLIGATORY  DEFAULT  'C:\',

             p_mode LIKE ctu_params-dismode DEFAULT 'N' .

SELECTION-SCREEN END OF BLOCK b1     .

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  PERFORM get_filename.

FORM get_filename .

  CLEAR : file, file[].

  CALL METHOD cl_gui_frontend_services=>file_open_dialog

    EXPORTING

      window_title            = 'Select file'

      default_extension       = 'TXT'

      default_filename        = 'c:\bb.txt'

      initial_directory       = 'C:\'

    CHANGING

      file_table              = file

      rc                      = rc

    EXCEPTIONS

      file_open_dialog_failed = 1

      cntl_error              = 2

      error_no_gui            = 3

      not_supported_by_gui    = 4

      OTHERS                  = 5.

  IF sy-subrc <> 0.

    EXIT.

  ENDIF.

  READ TABLE file INTO wa_file INDEX 1.

  MOVE wa_file-filename TO p_file.

ENDFORM.                    " get_filename

  DATA : sfilename TYPE string.

  MOVE p_file TO sfilename.

  CALL METHOD cl_gui_frontend_services=>gui_upload

    EXPORTING

      filename                = sfilename

      filetype                = 'ASC'

      has_field_separator     = 'X'

    CHANGING

      data_tab                = gt_p[]

    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

      not_supported_by_gui    = 17

      error_no_gui            = 18

      OTHERS                  = 19.

  IF sy-subrc <> 0.

    EXIT.

  ENDIF.

Read only

Former Member
0 Likes
2,277

Hello

try this code

types: begin of tw_customer,
         kunnr  type kunnr,
         ktokd  type ktokd,
         name1  type name1_gp,
        end of tw_customer,
        tt_customer type standard table of tw_customer.

data: lf_fname type string,

       lt_customer type tt_customer.

selection-screen begin of block bk1 with frame title text-001.
parameters : pa_fname type localfile.
selection-screen end of block bk1.
at selection-screen on value-request for pa_fname.
* F4 functionality for File Name


   call function 'F4_FILENAME'
     exporting
       program_name  = syst-cprog
       dynpro_number = syst-dynnr
       field_name    = ' '
     importing
       file_name     = pa_fname.
   START-OF-SELECTION.
lf_fname = pa_fname.
call function 'GUI_UPLOAD'
     exporting
       filename            = lf_fname
       filetype            = 'ASC'
       has_field_separator = 'X'
       read_by_line        = 'X'
     tables
       data_tab            = lt_customer.
*ENDFORM.                    " F_GET_USERNAME



end-of-SELECTION.

Read only

Former Member
0 Likes
2,277

Hi guys,

Thank you for the solutions. It does somehow works but in my source data, the spacing of one row (Item1 and Item 2) is using spacing. In my original plan I used tab-delimeted.

Can someone help me how to changed the tab-delimeted to space.

Thank You

Read only

0 Likes
2,277

Hi,

Step-1   Take a Backup of source data.

Step-2  Save the file in .XLS

Step-3 Save the source data(.XLS) FILE as CSV comma delimitted

Step-4 save the csv file into .txt(ms-dos) format

step-5 open the txt file u will see tab delimited will be replaced by ,

step-6 goto replace option find comma with SPACE Replace all

Thanks

Sudhi ranjan parija

Read only

0 Likes
2,277

HI ranjan,

                  Can you tell me how to take source code back up..

Thank u

vamshi

Read only

0 Likes
2,277

Hi vamshi

Source DATA   backup is place tab delimited text file  in some other file.

Source code backup is coping  program into notepad for each and every include.

u can print it also in pdf by setting in abap editor.

thanks,

Sudhir

Read only

0 Likes
2,277

Sudhir,

Im trying to change it at SAP. Where do I change the tab delimit to space..

Read only

matt
Active Contributor
0 Likes
2,277

Just as a help, don't define the tab delimiter as you have; use instead the constant CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB