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

concatenate

Former Member
0 Likes
865

Hi gurus

My problem is when im downloading data from sap to flat file .I want that fields like

1;11;07;2007;"05:1049 ";"65 ";"ABD ALMOHSEN KHARAFI ";"

  • this format how can i get that.Pls help me out on this.My sample code is mensioned below .

but when im donloadind data it will come like 000021343rma1200 this it is coming

but i dont want this type.

REPORT ZDOWNLOAD_COR1.

parameters:p_aufnr type afko-aufnr.

selection-screen begin of block b1.

parameters:p_dwnlod radiobutton group rad1 type c default 'X' .

parameters:p_upload radiobutton group rad1.

selection-screen end of block b1.

initialization.

types:begin of ty_afpo,

aufnr type aufnr,

dauat type aufart,

psmng type co_psmng,

end of ty_afpo.

TYPES:begin of ty_afko,

aufnr type aufnr,

getri type CO_getri,

gamng type gamng,

gmein type meins,

plnbez type matnr,

end of ty_afko.

data:t_afko type standard table of ty_afko,

w_afko type ty_afko.

data:t_afpo type standard table of ty_afpo,

w_afpo type ty_afpo .

data:i_tafpo type standard table of ty_afpo ,

w_tafpo type ty_afpo.

at selection-screen .

START-OF-SELECTION.

select aufnr

getri

gamng

gmein

plnbez

from afko

into table t_afko where aufnr = p_aufnr.

check t_afko[] is not initial.

select aufnr

dauat

psmng

from afpo

into table t_afpo

for all entries in t_afko

where aufnr = t_afko-aufnr.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

FILENAME = 'C:
blank.txt'

FILETYPE = 'DAT'

TABLES

DATA_TAB = T_AFpO

.

IF SY-SUBRC <> 0.

ENDIF.

LOOP AT I_TAFPO into w_tafpo.

write: w_tafpo-aufnr.

ENDLOOP.

Pls check this code and suggest me

Thanks in advance

Hi ,

Link URL could not open..So , I am posting some more .

Hi ,

Try this.

The program below demonstrates the above functionality. Here, we are reading data from table EKKO and downloading the data as '|' delimited file.

Editor's note: This tip works on SAP versions 4.6 or higher.

Code

REPORT y_ss_test_ekko .

To hold selection data

DATA: i_ekko TYPE STANDARD TABLE OF ekko.

To hold converted text data

DATA: i_text(4096) TYPE c OCCURS 0.

Selection Screen

PARAMETERS: p_ebeln LIKE ekko-ebeln.

Select data into an ITAB based on the selection Criteria

SELECT * FROM ekko

INTO TABLE i_ekko

WHERE ebeln = p_ebeln.

Process further only if found some data

IF NOT i_ekko[] IS INITIAL.

Convert data in internal table to a delimited text data

CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'

EXPORTING

i_field_seperator = '|'

TABLES

i_tab_sap_data = i_ekko

CHANGING

i_tab_converted_data = i_text

EXCEPTIONS

conversion_failed = 1

OTHERS = 2.

IF sy-subrc 0.

WRITE: / 'Program failed to Convert data.'.

ELSE.

Download convert data to Presentation Server

CALL FUNCTION 'DOWNLOAD'

TABLES

data_tab = i_text

EXCEPTIONS

OTHERS = 8.

IF sy-subrc 0.

WRITE: / 'Program failed to download data.'.

ENDIF.

ENDIF.

ENDIF.

Regards

Sourabh Verma

6 REPLIES 6
Read only

Former Member
0 Likes
825

Hi,

Use the Function Module SAP_CONVERT_TO_CSV_FORMAT to convert the internal table into Comma seperated format then download this

internal table using the Function Module GUI_DOWNLOAD.

REPORT zvenkat_test2.

TYPE-POOLS: truxs.

TYPES:

BEGIN OF t_line,

vbeln LIKE vbap-vbeln,

posnr LIKE vbap-posnr,

END OF t_line.

DATA:w_line TYPE t_line.

DATA:itab TYPE STANDARD TABLE OF t_line.

DATA:itab1 TYPE truxs_t_text_data.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text_001.

PARAMETERS p_file TYPE localfile DEFAULT 'C:Test.txt'.

SELECTION-SCREEN END OF BLOCK b1.

*----


"At selection-screen on value-request for p_file.

*----


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

PERFORM f4_help.

START-OF-SELECTION.

PERFORM get_data.

END-OF-SELECTION.

PERFORM convert_to_csv.

PERFORM download_data.

&----


*& Form f4_help

&----


FORM f4_help .

DATA:

l_file_name LIKE ibipparms-path .

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

field_name = 'P_FILE'

IMPORTING

file_name = l_file_name.

p_file = l_file_name.

ENDFORM. " f4_help

&----


*& Form get_data

&----


FORM get_data .

SELECT

vbeln

posnr

UP TO 10 ROWS

FROM vbap

INTO TABLE itab.

ENDFORM. " get_data

&----


*& Form convert_to_csv

&----


FORM convert_to_csv .

CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'

EXPORTING

i_field_seperator = ';'

TABLES

i_tab_sap_data = itab

CHANGING

i_tab_converted_data = itab1

EXCEPTIONS

conversion_failed = 1

OTHERS = 2.

IF sy-subrc 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. " convert_to_csv

&----


*& Form download_data

&----


FORM download_data .

DATA l_filename TYPE string.

l_filename = p_file.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = l_filename

TABLES

data_tab = itab1

EXCEPTIONS

OTHERS = 1.

ENDFORM. " download_data

Refer this thread .

Just now there was a discussion similar to your requirement.

[https://www.sdn.sap.com/irj/sdn/forums]

Hope this helps.

Regards

Sourabh

Read only

0 Likes
825

Hi ,

Link URL could not open..So , I am posting some more .

Hi ,

Try this.

The program below demonstrates the above functionality. Here, we are reading data from table EKKO and downloading the data as '|' delimited file.

Editor's note: This tip works on SAP versions 4.6 or higher.

Code

REPORT y_ss_test_ekko .

To hold selection data

DATA: i_ekko TYPE STANDARD TABLE OF ekko.

To hold converted text data

DATA: i_text(4096) TYPE c OCCURS 0.

Selection Screen

PARAMETERS: p_ebeln LIKE ekko-ebeln.

Select data into an ITAB based on the selection Criteria

SELECT * FROM ekko

INTO TABLE i_ekko

WHERE ebeln = p_ebeln.

Process further only if found some data

IF NOT i_ekko[] IS INITIAL.

Convert data in internal table to a delimited text data

CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'

EXPORTING

i_field_seperator = '|'

TABLES

i_tab_sap_data = i_ekko

CHANGING

i_tab_converted_data = i_text

EXCEPTIONS

conversion_failed = 1

OTHERS = 2.

IF sy-subrc 0.

WRITE: / 'Program failed to Convert data.'.

ELSE.

Download convert data to Presentation Server

CALL FUNCTION 'DOWNLOAD'

TABLES

data_tab = i_text

EXCEPTIONS

OTHERS = 8.

IF sy-subrc 0.

WRITE: / 'Program failed to download data.'.

ENDIF.

ENDIF.

ENDIF.

Regards

Sourabh Verma

Read only

0 Likes
825

Hi Sourabh,

Thank u very much for the quick reply.I used that also to convert csv format.But my problem is not csv format.I want "rama"; like this format of every field.If u help me out on this im very glad .

Read only

0 Likes
825

Ramakrishna, Check the following sample code. I have writen some logic. It works fine. I mentioned where exactlyi changed logic .

*&---------------------------------------------------------------------*
*& Report  ZVENKAT_CSV_FILE_UPLOAD
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zvenkat_csv_file_download.

TYPE-POOLS: truxs.
TYPES:
  BEGIN OF ty_line,
    vbeln LIKE vbap-vbeln,
    posnr LIKE vbap-posnr,
  END OF ty_line.

DATA: itab   TYPE STANDARD TABLE OF ty_line WITH DEFAULT KEY.
DATA: itab1  TYPE truxs_t_text_data,
      w_tab LIKE LINE OF itab1.

START-OF-SELECTION.
  PERFORM get_data.
  PERFORM convert_to_csv_format.
  PERFORM download.

*&---------------------------------------------------------------------*
  "      Form  get_data
*&---------------------------------------------------------------------*
FORM get_data.
  SELECT
  vbeln
  posnr
  UP TO 10 ROWS
  FROM vbap
  INTO TABLE itab.
ENDFORM.                    "get_data
*&---------------------------------------------------------------------*
"      Form  convert_to_csv_format
*&---------------------------------------------------------------------*
FORM convert_to_csv_format.
  CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
    EXPORTING
      i_field_seperator    = ';'
    TABLES
      i_tab_sap_data       = itab
    CHANGING
      i_tab_converted_data = itab1
    EXCEPTIONS
      conversion_failed    = 1
      OTHERS               = 2.
  IF sy-subrc  <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  DATA:off TYPE i.
  "Replace ; with ";" using the below statement
  REPLACE ALL OCCURRENCES OF REGEX ';'
  IN TABLE itab1 WITH '";"'
  RESPECTING CASE.
  "Setting " to first and last.
  " If u have record like 00001":"xyz001 it will make "00001";"xyz001"
  LOOP AT itab1 INTO w_tab .
    SHIFT w_tab RIGHT BY 2 PLACES.
    w_tab+1(1) = '"'.
    off = STRLEN( w_tab ).
    SHIFT w_tab LEFT.
    off = off - 1.
    w_tab+off(1) = '"'.
    MODIFY itab1 INDEX sy-tabix  FROM w_tab.
  ENDLOOP.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
ENDFORM.                    "convert_to_csv_format
*&---------------------------------------------------------------------*
"      Form  download
*&---------------------------------------------------------------------*
FORM download.
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      filename = 'c:\VENKAT\test1.txt'
    TABLES
      data_tab = itab1
    EXCEPTIONS
      OTHERS   = 1.

  IF sy-subrc EQ 0.
    WRITE: 'Data downloaded successfully'.
  ENDIF.
ENDFORM.                    "download
I hope that ur problem is solved. Regards, Venkat.O

Read only

0 Likes
825

Hi venkat,

Thats very good answer its working fine.Thanks a lot.I gave u the points also..If i have any douts i vll b revert back to u.Can i have ur mail id please.

Regards

yogi

Read only

Former Member
0 Likes
825

Hi,

Refer to the following code:

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = wf_fname3

filetype = 'ASC'

write_field_separator = ';'

dat_mode = 'X'

confirm_overwrite = ' '

append = 'X'

TABLES

data_tab = int_equi_extract

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.

IF sy-subrc <> 0.

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

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

ENDIF.

ENDIF.

Hope this helps.

Reward if helpful.

Regards,

Sipra