05-19-2015 5:16 PM
Hello All,
We are working on a issue where the a .csv file is generated from a z program and sent to the server directory, (AL11)
How do we store a .csv file without losing or changes to the characters, like in European languages where you have different letters.
Any help would be appreciated.
Thanks
V
05-19-2015 5:20 PM
My take would be do a small experiment with t-code CG3Z and load a .CSV file with all special characters into a apps server path and see how it behaves. If that works fine then there should not be any issues while you load with Open Dataset.
Regards
Venkat
05-26-2015 10:49 AM
Venkat,
Did the same exp and it works perfect, Here is the code we are using.
FORM display_output .
DATA : v_dload TYPE string,
v_dload1 TYPE ty_line,
l_path TYPE string,
l_codepage TYPE ABAP_ENCODING VALUE ''.
CONSTANTS lc_0 TYPE c VALUE '0'.
Write to application server
IF p_a_save = 'X'.
*****Test local file
IF p_server EQ 'X' AND p_a_save EQ 'X'.
*****Test local file
OPEN DATASET p_flname FOR OUTPUT IN LEGACY text MODE CODE PAGE '1406'.
IF sy-subrc = 0.
Here is the Character of person's last name "Skočovský" which shows
in ALV, and when we download from ALV it works fine. when opened from the server it shows as "Sko#ovský"
Did try binary code too. Any thoughts.
Thanks
Venkat
05-26-2015 12:40 PM
How have you opened the file? By looking through AL11? Did you consider that perhaps the issue is simply AL11 not displaying the contents properly? It may be that the software which will actually use the file will handle it perfectly correctly!
05-26-2015 1:43 PM
Hi Venkat,
If you are opening the file direct in server, then check weather the the Fonts are the same in your local system and application server system.
If Fonts miss, then system shows some default characters, in your case it's #.
Regards,
Praveer.
05-19-2015 5:55 PM
Hi Venkat,
Venkat CH is right.
You can transfer *.csv file to the application server using open dataset in binary mode.
In binary mode data is transferred byte by byte without any check of the data content.
05-19-2015 6:05 PM
Open dataset vg_file for ouput in binary mode.
close dataset.
and you can download them in whatever format you need based on the format you store.
Regards
S.Janagar
05-26-2015 10:59 AM
Hi
OPEN DATASET p_flname FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc = 0.
concatenate your data with 'comma' separation.
endif.
CLOSE DATASET p_flname.
regards,
Chandu
05-26-2015 12:30 PM
You can do something like this, although I recommend you to avoid it. Maybe you can store this information in SAP tables and it's far better than read AL11 always
CONCATENATE vl_dir_al11
c_dir_processar " /folder/processar/
vl_nome_arquivo
INTO vl_ds_processar_csv.
CONCATENATE vl_dir_al11
c_dir_enviar " /folder/enviar/
im_nome_arquivo
INTO vl_ds_enviar_csv.
CLOSE DATASET vl_ds_processar_csv.
OPEN DATASET vl_ds_processar_csv
FOR INPUT IN BINARY MODE
MESSAGE vl_message.
IF sy-subrc = 0.
READ DATASET vl_ds_processar_csv
INTO vl_conteudo_arquivo.
OPEN DATASET vl_ds_enviar_csv
FOR OUTPUT IN BINARY MODE
MESSAGE vl_message.
IF sy-subrc = 0.
TRANSFER vl_conteudo_arquivo TO vl_ds_enviar_csv.
CLOSE DATASET vl_ds_processar_csv.
OPEN DATASET vl_ds_processar_csv
FOR INPUT IN BINARY MODE.
DELETE DATASET vl_ds_processar_csv.
CLOSE DATASET vl_ds_processar_csv.
ENDIF.
ENDIF.
05-26-2015 1:37 PM
hi you can try like this.
1.in the first part i just collected the data from hr table and stored in a final table.
2.then used open data set and closed data set (chk the syntax)
3.keep it mind that u have to make the file name in the interface where u r wish to store the data and pass that path into ur prog,be care full about the name and case sensative
REPORT ZHR_ROOO1.
tables:PA0105,PA0001.
selection-screen:begin of block b1 with frame title text-001.
SELECT-OPTIONS: p_pernr for PA0105-Pernr no INTERVALS.
selection-screen:end of block b1.
TYPES : BEGIN OF ty_final1,
PERNR type PA0105-PErnr,
USRID type PA0105-USRID,
END OF ty_FINAL1.
TYPES : BEGIN OF ty_FINAL2,
PERNR type PA0105-PErnr,
ENAME type PA0001-Ename,
persg TYPE PA0001-persg,
END OF ty_FINAL2.
TYPES : BEGIN OF ty_FINALON,
PERNR type PA0105-PErnr,
ENAME type PA0001-Ename,
persg TYPE PA0001-persg,
END OF ty_FINALON.
TYPES : BEGIN OF ty_FINAL,
PERNR type PA0105-PErnr,
ENAME type PA0001-Ename,
USRID type PA0105-USRID,
ROLE(3) TYPE C , "PA0001-persg,
circle TYPE ZCIRCLE_NEW,
circletxt TYPE ZCIRCLE_TEXT,
END OF ty_FINAL.
TYPES : BEGIN OF ty_FINAL0,
PERNR(8) type c,
ENAME(30) type c,
USRID(10) type c,
role(3) TYPE c,
circle(4) TYPE c,
circletxt(30) TYPE c,
END OF ty_FINAL0.
TYPES : BEGIN OF ty_FINAL11,
PERNR type PERSNO,
stat2 type STAT2,
END OF ty_FINAL11.
TYPES : BEGIN OF ty_FINAL22,
pernr TYPE PERSNO,
CIRCLE TYPE ZCIRCLE_NEW,
END OF ty_FINAL22.
TYPES: BEGIN OF ty_header,
reptext_ddic(40) TYPE c,
END OF ty_header.
DATA: BEGIN OF itab_final OCCURS 0,
w_data(1000) TYPE c,
END OF itab_final.
SELECTION-SCREEN BEGIN OF BLOCK blk7 WITH FRAME TITLE text-007 .
PARAMETERS: p_disp AS CHECKBOX.
PARAMETERS: p_path TYPE sapwlpstrc-filename OBLIGATORY DEFAULT '/interface/sddata/'."'/interface/hrdata/empphn'.
SELECTION-SCREEN END OF BLOCK blk7 .
data: IT_FINAL1 TYPE STANDARD TABLE OF TY_FINAL1,
WA_FINAL1 type ty_FINAL1,
IT_FINAL2 TYPE STANDARD TABLE OF TY_FINAL2,
WA_FINAL2 type ty_FINAL2,
IT_FINALON TYPE STANDARD TABLE OF TY_FINALON,
WA_FINALON type ty_FINALON,
IT_FINAL TYPE STANDARD TABLE OF TY_FINAL WITH HEADER LINE,
WA_FINAL type ty_FINAL,
IT_FINAL0 TYPE ty_FINAL0 OCCURS 1,
WA_FINAL0 type ty_FINAL0,
IT_FINAL11 TYPE STANDARD TABLE OF TY_FINAL11,
WA_FINAL11 type ty_FINAL11,
IT_FINAL22 TYPE STANDARD TABLE OF TY_FINAL22,
WA_FINAL22 type ty_FINAL22,
IT_CIRCLE TYPE STANDARD TABLE OF ZHR_CIRCLE,
WA_CIRCLE type ZHR_CIRCLE,
w_message(100) TYPE c.
DATA: gt_header TYPE STANDARD TABLE OF ty_header,
gs_header TYPE ty_header.
type-pools :slis.
data: it_fieldcat type slis_t_fieldcat_alv,
wa_fieldcat type slis_fieldcat_alv, "variable for fieldcat
lv_s_layout type slis_layout_alv, "vaiable for layout
it_event type slis_t_event,
wa_event type slis_alv_event,
outputlen like dd03p-outputlen,
zebra(1) type c.
data: fieldcatalog type slis_t_fieldcat_alv with header line,
gd_tab_group type slis_t_sp_group_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid.
DATA: T_FCAT TYPE slis_t_fieldcat_alv, " Field Catalog for List Viewer Control
W_FCAT TYPE slis_fieldcat_alv, " ALV control: Field catalog
W_LAY TYPE slis_layout_alv .
CLEAR:it_final,it_final2,it_final0,it_final1,it_final1,wa_final,wa_final2,wa_final0,wa_final1,wa_final22.
START-OF-SELECTION.
SELECT PERNR ename persg
FROM pa0001
INTO CORRESPONDING FIELDS OF TABLE it_finalON
WHERE pernr IN P_PERNR
and endda = '99991231'
and persg ne 'B'
and persg ne 'D'.
IF it_finalON[] IS NOT INITIAL.
select pernr stat2 """"""""""""""active emp
from pa0000
into CORRESPONDING FIELDS OF TABLE it_final11
FOR ALL ENTRIES IN it_finalON
where pernr = it_finalON-pernr
and endda = '99991231'
and stat2 = '3'.
ENDIF.
if it_final11[] is NOT INITIAL. """"""""""""""""""""""phn no
select PERNR usrid
from pa0105
INTO CORRESPONDING FIELDS OF TABLE it_final
FOR ALL ENTRIES IN it_final11
WHERE pernr = it_final11-pernr
and subty = '0015'
and endda = '99991231' .
endif.
IF it_final[] is not INITIAL. """"""""""role
SELECT PERNR ename persg
FROM pa0001
INTO CORRESPONDING FIELDS OF TABLE it_final2
FOR ALL ENTRIES IN it_final11
WHERE pernr = it_final11-pernr
and endda = '99991231'
and persg ne 'B'
and persg ne 'D'.
ENDIF.
if it_final11[] is NOT INITIAL. """"""""""""""""""""""circle
select PERNR CIRCLE
from pa9030
INTO CORRESPONDING FIELDS OF TABLE it_final22
FOR ALL ENTRIES IN it_final11
WHERE pernr = it_final11-pernr
and subty = '04'
and endda = '99991231' .
endif.
if it_final22[] is NOT INITIAL. """"""""""""""""""""""circle name
select CIRCLETEXT
from ZHR_CIRCLE
INTO CORRESPONDING FIELDS OF TABLE IT_CIRCLE
FOR ALL ENTRIES IN it_final22
WHERE CIRCLE = it_final22-CIRCLE.
endif.
LOOP AT it_final into wa_final.
READ TABLE it_final2 INTO wa_final2 WITH KEY pernr = wa_final-pernr.
if sy-subrc = 0 .
CLEAR wa_final-role.
IF wa_final2-persg = '1' or
wa_final2-persg = '2' or
wa_final2-persg = '3' or
wa_final2-persg = '4' or
wa_final2-persg = '5' or
wa_final2-persg = '6' or
wa_final2-persg = '7' or
wa_final2-persg = '8' or
wa_final2-persg = '9' or
wa_final2-persg = 'A'.
wa_final-role = 'ON'.
ELSEIF
* wa_final2-persg = 'B' or
wa_final2-persg = 'C' or
* wa_final2-persg = 'D' or
wa_final2-persg = 'E' or
wa_final2-persg = 'S' .
CLEAR wa_final-role.
wa_final-role = 'OFF'.
ENDIF.
*wa_final-ename = wa_final2-ename.
READ TABLE it_final22 INTO wa_final22 WITH KEY pernr = wa_final-pernr.
IF sy-subrc = 0.
wa_final-circle = wa_final22-circle.
ENDIF.
SELECT SINGLE * FROM zhr_circle into wa_circle WHERE circle = wa_final22-circle.
IF sy-subrc = 0.
wa_final-circletxt = wa_circle-circletext.
ENDIF.
modify it_final FROM wa_final TRANSPORTING circle circletxt ROLE .
endif.
endloop.
if it_final[] is not initial.
sort it_final by pernr.
delete ADJACENT DUPLICATES FROM it_final COMPARING pernr.
if p_disp = 'X'.
perform build_fieldcatalog.
perform display_alv_report.
endif.
endif.
IF it_final[] IS NOT INITIAL.
sort it_final by pernr.
delete ADJACENT DUPLICATES FROM it_final COMPARING pernr.
LOOP AT it_final INTO wa_final.
wa_final0-pernr = wa_final-pernr.
*wa_final0-ename = wa_final-ename.
wa_final0-usrid = wa_final-usrid.
wa_final0-role = wa_final-role.
wa_final0-circle = wa_final-circle.
wa_final0-circletxt = wa_final-circletxt.
APPEND wa_final0 to it_final0.
ENDLOOP.
clear wa_final0.
wa_final0-circletxt = '***End of File***'.
APPEND wa_final0 TO IT_final0.
CLEAR: wa_final0.
PERFORM download_output.
ENDIF.
*&---------------------------------------------------------------------*
*& Form build_fieldcatalog
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form build_fieldcatalog .
PERFORM FIELDCAT USING 'PERNR' 'Personal No'.
* PERFORM FIELDCAT USING 'ENAME' 'Employee Name'.
PERFORM FIELDCAT USING 'USRID' 'Mobile No'.
PERFORM FIELDCAT USING 'ROLE' 'ROLE'.
PERFORM FIELDCAT USING 'CIRCLE' 'CIRCLE'.
PERFORM FIELDCAT USING 'CIRCLETXT' 'CIRCLETXT'.
W_LAY-Colwidth_optimize = 'X'.
ENDFORM. " BUILDCATLOG OUTPUT
*&---------------------------------------------------------------------*
*& Form FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->VALUE(P_0118) text
* -->VALUE(P_0119) text
*----------------------------------------------------------------------*
FORM FIELDCAT USING VALUE(P_0118)
VALUE(P_0119).
W_FCAT-FIELDNAME = P_0118.
W_FCAT-selTEXT_l = P_0119.
* W_FCAT-outputlen = '40'.
append w_fcat to t_fcat.
clear w_fcat.
ENDFORM. "FIELDCAT
*&---------------------------------------------------------------------*
*& Form display_alv_report
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form display_alv_report.
call function 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
* i_callback_top_of_page = 'TOP-OF-PAGE'
is_layout = gd_layout
it_fieldcat = t_fcat
TABLES
t_outtab = it_final.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
* clear it_final.
endform. "display_alv_report
*&---------------------------------------------------------------------*
*& Form download_output
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM download_output .
DATA:
file TYPE string,
ftp_file TYPE string.
DATA : lv_str TYPE string.
DATA : lv_str_1 TYPE string.
*data : con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
ftp_file = 'SAP_EMP_DATA_'.
IF p_path IS NOT INITIAL.
CONCATENATE p_path ftp_file sy-datum sy-uzeit '.CSV' INTO file.
* CONCATENATE p_path ftp_file '.CSV' INTO file.
OPEN DATASET file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc = 0.
WRITE : / 'File opened on application server' .
ELSE.
WRITE : / 'Unable to open file on application server'.
ENDIF.
LOOP AT it_final0 into wa_final0.
CLEAR :lv_str.
CONCATENATE wa_final0-pernr
* wa_final0-ename
wa_final0-usrid
wa_final0-role
wa_final0-circle
wa_final0-circletxt
INTO lv_str
SEPARATED BY '|' .
TRANSFER lv_str TO file.
CLEAR : wa_final0,
lv_str.
ENDLOOP.
* CONCATENATE '***End of File*** ' SY-DATUM INTO LV_STR_1 SEPARATED BY SPACE.
** lv_str = '***End of File*** '."LV_STR_1.
** TRANSFER lv_str TO file.
** CLEAR: lv_str , lv_str_1.
IF sy-subrc = 0.
WRITE : / 'Data transfer to file on application server complete.' .
ELSE.
WRITE : / 'Unable to transfer data to file on application server.'.
ENDIF.
CLOSE DATASET file.
IF sy-subrc = 0.
WRITE : / 'File closed on application server' .
ELSE.
WRITE : / 'Unable to close file on application server'.
ENDIF.
ELSE.
MESSAGE 'Please enter path for saving file' TYPE 'E'.
ENDIF.
ENDFORM.