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

Tab delimiter

Former Member
0 Likes
1,012

Hi All,

I have a input file which i have to transfer to Application server with Tab delimeter.

Please let me know hw to write the code for Tab delimeter.

Akshitha.

Hi All,

I have a input file which i have to transfer to Application server with Tab delimeter.

Please let me know hw to write the code for Tab delimeter.

Akshitha.

6 REPLIES 6
Read only

Former Member
0 Likes
959

Hi,

Check this thread

regards,

theja

Read only

Former Member
0 Likes
959

Hello,

Write the code like this.


CONSTANTS: CON_TAB TYPE X VALUE '09'.
  OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE.
  IF SY-SUBRC = 0.
    LOOP AT G_T_OUTTAB.
      CLEAR L_F_NETWR.
      WRITE: G_T_OUTTAB-NETWR TO L_F_NETWR,
             G_T_OUTTAB-ERDAT_OR TO L_F_ERDAT_OR,
             G_T_OUTTAB-ERDAT_IN TO L_F_ERDAT_IN,
             G_T_OUTTAB-ERDAT_DE TO L_F_ERDAT_DE.
      CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT'
           EXPORTING
                INPUT  = G_T_OUTTAB-PS_PSP_PNR
           IMPORTING
                OUTPUT = L_F_POSID.

        CONCATENATE G_T_OUTTAB-VBELN
                    G_T_OUTTAB-POSNR
                    G_T_OUTTAB-VKBUR
                    L_F_POSID
                    G_T_OUTTAB-BSTKD
                    L_F_NETWR
                    L_F_ERDAT_OR
                    L_F_ERDAT_IN
                    G_T_OUTTAB-VBELN_IN
                    L_F_ERDAT_DE
                    G_T_OUTTAB-VBELN_DE
                    INTO OUTPUT
                    SEPARATED BY CON_TAB.
      TRANSFER OUTPUT TO P_FILE.
      CLEAR L_F_NETWR.
    ENDLOOP.
  ELSE.
    MESSAGE E041(S9) WITH P_FILE.
  ENDIF.
  CLOSE DATASET P_FILE.

Cheers,

Vasanth

Read only

0 Likes
959

Hi,

Im getting error, con_tab should be declared as type C, N, D, T so ...on.....

Read only

0 Likes
959

Hello,

Noway it should work. The same code is working in my system.

Cheers,

Vasanth

Read only

0 Likes
959

Hi there

In Unicode systems there IS a problem in that you can no longer define 'X' type fields so use the attributes of the class shown below for these. You can see other values by looking at the class attributes (SE24).


DATA: l_tab(1) TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.

.

Of course a possible get around is to use a CSV ( comma delimited) file then you CAN use a character (type C) field.

The problem with a comma of course is that your data fields might have commas in them as data.

comma(1) type c.

move ',' to comma. Or define as a constant.

I'd go for using the class attribute shown above.

Cheers

jimbo

Read only

Former Member
0 Likes
959

C'mon guys again it's 2008 -- use OO stuff it's easier and works. Forget 1970's old Dinosaur technology non OO Abap.

Note also in Unicode Systems you can no longer define TYPE X fields either.

My example here does an Upload from a PC but simply reverse the process for download. (Change if you want to do it to the application server - use Open dataset etc).

Use strings as well - makes everything a lot easier especially if you are working on a Unicode system.

The Tab delimiter is defined as



DATA: l_tab(1) TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.

The rest of the code.




DATA  l_rc TYPE sy-subrc.
DATA  ul_file TYPE string.
DATA: t_excel TYPE TABLE OF string.
DATA  wa_excel TYPE string.

DATA: l_tab(1) TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
* fields in your file 
DATA: BEGIN OF s1,
     wa_fld1   TYPE string,
     wa_fld2   TYPE string,
     wa_fld3   TYPE string,
     wa_fld4   TYPE string,
     wa_fld5 TYPE string,
END OF s1.
SELECTION-SCREEN SKIP 1.
DATA: x_tab(1) TYPE c.
DATA: string_length type I.

PARAMETERS: p_file TYPE rlgrap-filename
      DEFAULT 'C:\TEMP\usermigration1.txt'.
* Select file to be uploaded
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
      static    = 'X'
    CHANGING
      file_name = p_file.

START-OF-SELECTION.
  ul_file = p_file.
  x_tab = ','.
  IF ul_file IS INITIAL.
    EXIT.
  ENDIF.
  PERFORM upload_file.
  PERFORM process_file.

FORM upload_file.
  CALL METHOD cl_gui_frontend_services=>gui_upload
    EXPORTING
      filename                = ul_file
      filetype                = 'ASC'
*    has_field_separator    = 'X'
   CHANGING
      data_tab                = t_excel
  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
      OTHERS                  = 12.


  IF sy-subrc <> 0.
    l_rc = sy-subrc.
    MESSAGE 'Error during GUI_UPLOAD'(002) TYPE 'E'.
  ENDIF.
ENDFORM.                    "upload_file

form process_file.

 LOOP AT t_excel INTO wa_excel.
clear wa_elements.
clear s1.
      SPLIT  wa_excel  AT i_tab INTO s1-wa_fld1 s1-wa_fld2 s1-wa_fld3
      s1-wa_fld4  s1-wa_fld5.
    check s1-wa_fld1 ca '0123456789'.
    translate s1-wa_fld2 to upper case.
    translate s1-wa_fld3 to upper case.
    translate s1-wa_fld4 to upper case.
    translate s1-wa_fld5 to upper case.


      MOVE-CORRESPONDING s1 TO wa_elements.
       string_length  = strlen( wa_elements-wa_fld5 ).

* do whatever you want with uploaded EXCEL tab delimited * file
endform.

Cheers

jimbo