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: 

TRANSFER itab in file

0 Kudos

Hi i need to transfer itab to a txt file, and i can't type my itab.


FORM download  TABLES   p_data.
  DATA:
    lw_fname            TYPE string.

  OPEN DATASET lw_fname FOR APPENDING IN TEXT MODE ENCODING DEFAULT.
  TRANSFER p_data TO lw_fname.

at TRANSFER statement i get this short dump:

The current statement is defined for character-type data objects only.

Thanks

1 ACCEPTED SOLUTION

Sm1tje
Active Contributor
0 Kudos

What is it you are trying to do here? Send a file to the file server (application server), or to your desktop.

In case of desktop, indeed you can use the GUI_DOWNLOAD function modules, or better yet, the class CL_GUI_FRONTEND_SERVICES. However, if this is not the case, ignore all these remarks above.

For file to application server, you are sending data to a file called lw_fname. Does this file location also have a location, or is it empty?

For transferring a table, you should first LOOP at this table and transfer it line by line.

11 REPLIES 11

I355602
Advisor
Advisor
0 Kudos

Hi,

Use FM GUI_DOWNLOAD

Regards,

Tarun

former_member376453
Contributor
0 Kudos

Try this:


* Downloading the item data
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      filename                = str_fpath         " Give the file path where you want to download
      filetype                = 'ASC'              
      append                  = 'X'
      write_field_separator   = '#'
      codepage                = '4103'
      write_bom               = 'X'
    TABLES
      data_tab                = itab_report       " Your Itab name
    EXCEPTIONS
      file_write_error        = 1
      no_batch                = 2
      gui_refuse_filetransfer = 3
      invalid_type            = 4
      no_authority            = 5
      unknown_error           = 6
      header_not_allowed      = 7
      separator_not_allowed   = 8
      filesize_not_allowed    = 9
      header_too_long         = 10
      dp_error_create         = 11
      dp_error_send           = 12
      dp_error_write          = 13
      unknown_dp_error        = 14
      access_denied           = 15
      dp_out_of_memory        = 16
      disk_full               = 17
      dp_timeout              = 18
      file_not_found          = 19
      dataprovider_exception  = 20
      control_flush_error     = 21
      OTHERS                  = 22.

* Check sy-subrc
  IF sy-subrc <> 0.
    MESSAGE i188.         " Error in displaying the report
    LEAVE LIST-PROCESSING.
  ENDIF.

Former Member
0 Kudos

HI,

P_date should be of flat structure. If the P_DATA contains any decimal fields then they need to be converted to text and transfered to dataset. Use th FM 'HR_99S_COPY_STRUC1_STRUC2' to convert the work area to flat type

You can do this way.

DATA: l_string type STRING.

LOOP AT P_DATA.
 OPEN DATASET lw_fname FOR APPENDING IN TEXT MODE ENCODING DEFAULT.
IF SY_SUBRC EQ 0.

CALL FUNCTION 'HR_99S_COPY_STRUC1_STRUC2'
  EXPORTING
    p_struct1       = p_data
 IMPORTING
   P_STRUCT2       =  l_string.
  TRANSFER  l_stringTO lw_fname.
Clear l_string.
ENDIF.
ENDLOOP.

Sm1tje
Active Contributor
0 Kudos

What is it you are trying to do here? Send a file to the file server (application server), or to your desktop.

In case of desktop, indeed you can use the GUI_DOWNLOAD function modules, or better yet, the class CL_GUI_FRONTEND_SERVICES. However, if this is not the case, ignore all these remarks above.

For file to application server, you are sending data to a file called lw_fname. Does this file location also have a location, or is it empty?

For transferring a table, you should first LOOP at this table and transfer it line by line.

0 Kudos

Thanks for your answers

@Micky

Yeah it's for Application Server, I can see the file created but file is empty.

I also tried this code, but i get the same short dump.

OPEN DATASET lw_fname FOR APPENDING IN TEXT MODE ENCODING DEFAULT.
  LOOP AT p_data.
    TRANSFER p_data TO lw_fname.
  ENDLOOP.

@Avinash

I get this short dump at fm statement

Error in an ASSIGN ... CASTING statement in program "SAPLHR99S00_GENERIC".

I think it's because my table doesn't have a type.

0 Kudos

Hello,

Can you check the PERFORM for this subroutine? May be you can check the structure of the Internal table being passed to the subroutine & instead of using TABLES you can use USING with the FORM...ENDFORM.

I am just giving you an idea. May be this cannot be implemented here.

BR,

Suhas

0 Kudos

Thanks for your reply Suhas,

There like 10 perform using this subroutine, and each perform using different tables.

That's why i can't type p_data.

I need something similar of gui_download but for application server side.

0 Kudos

Hi Erick,

Did you ran a simple sample, to check if is everything oked ?:

OPEN DATASET lw_fname FOR APPENDING IN TEXT MODE ENCODING DEFAULT.
TRANSFER 'testando' TO lw_fname.
CLOSE DATASET lw_fname.

I tried to enhance your code, check if it work:

DATA: lv_temp TYPE string.
FIELD-SYMBOL: <fs_field> TYPE ANY.
OPEN DATASET lw_fname FOR APPENDING IN TEXT MODE ENCODING DEFAULT.
LOOP AT p_data.
  CLEAR lv_temp.
  DO.
    ASSIGN COMPONENT sy-index OF STRUCTURE p_data TO <fs_field>.
    IF sy-subrc NE 0. EXIT. ENDIF.
    CONCATENATE lv_temp <fs_field> INTO lv_temp.
  ENDDO.
  TRANSFER lv_temp TO lw_fname.
ENDLOOP.

  • Performance problems may happen if you use generic code, as exposed, for process IT with high number of records.

Regards,

Fernando Da Ros

0 Kudos

Thanks Fernando, problem solved.

former_member194669
Active Contributor
0 Kudos

Try this way


FORM download  TABLES   p_data.
  DATA:
    lw_fname            TYPE string.

class cl_abap_container_utilities definition load.

data : begin of i_output occurs 0,
      vardata type uab_text_value.
data : end of i_output.

loop at p_data
      call method cl_abap_container_utilities=>fill_container_c
        exporting
          im_value               = p_data
        importing
          ex_container           = i_output-vardata
        exceptions
          illegal_parameter_type = 1
          others                 = 2.
      append i_output.
endloop.
 
OPEN DATASET lw_fname FOR APPENDING IN TEXT MODE ENCODING DEFAULT.
  TRANSFER i_output TO lw_fname.

former_member376453
Contributor
0 Kudos

If you are trying to send it to Application server, then you can declare a work area with string length = total length of all you field (keep some more byte to accommodate the spaces.) Then concatenate your itab workarea separated by space in this string and transfer this string to Application server :


 IF p_hie EQ c_true .
   IF NOT itab_lhs IS INITIAL.
*Opening file on application server
    OPEN DATASET v_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

        IF sy-subrc EQ 0.
*--- Transfer the data to application Server

CLEAR v_field.
CONCATENATE:
      'CPN'
*      'PLANT'
*      'MAT NUM'
      'PROJECT NAME'
      'PROJ DESC'
      'PROD SCHD'
      'MAT NUM'
      'MAT DESC'
      'PROC TYPE'
      'MRP TYPE'
      'PDT'
      'PUR GRP.'
      'MRP CONTROLLER'
      'MAT GRP.'
      'SAFETY STOCK'
      'REORDER POINT'
      'MAX STOCK LVL'
      'VEND CONS HUB QTY'
      'FG HUB QTY'
      'FG QTY'
      'WIP QTY'
      'MRB QTY'
      'STOCK ROOM QTY'
      'STOCK QTY IN ALLNETTABLE LOC' INTO v_field
      SEPARATED BY c_tabdel.


      TRANSFER v_field TO v_file.