09-09-2008 9:06 AM
Hi,
i saved excel file into CSV file in that file amount filed contains comma.now iam uploading csv file into internal table using GUI_UPLOAD iam getting data into internal table.
internaltable contains row like
1100,600000,1114,"1,89",Hours on Project. 1,89 is amount
filed.how can i split the above internal table and move to another internal table.another internal table row contains like 1100 600000 1114 1,89 Hours on Project. Please provide me solution.
Regards,
Suresh
09-09-2008 9:17 AM
09-09-2008 9:17 AM
09-09-2008 9:18 AM
hi...
if you are using gui_upload then use the split at ',' command for splitting the data into the fields of internal table.
the fields will get split seperately into the fields without ','.
09-09-2008 9:20 AM
Hello,
I don't know if there is a direct FM to do this.. if not you can try the following approach
for each row
read each character
if the char is a " (and the prev char is not a backslash) then set a flag to true, if the flag is already true then set it to false
if the char is a comma and the flag is false then replace the comma with some value symbol such as ***
modify the itab from the current workarea
in the end split the itab to ur reqd table based on *** instead of a comma
09-09-2008 9:42 AM
hi,
1. split this 1100,600000,1114,"1,89",Hours on Project by " into 3 fields.
2. split the first and last fields by ,.
3. transfer those field into your internal table.
regards,
Peter
09-09-2008 9:57 AM
There is a function module for converting file to CSV format please find the code below :
&----
*& Report ZCRPT_PP_013
*&
&----
*&
*&
&----
REPORT zcrpt_pp_013.
no standard page heading
line-size 80
line-count 65(0)
message-id ...
----
Dev. Class : *
Report Name : *
Program Type : *
Created by : *
Created on : *
Transaction Code : *
Module Name : *
Object ID : *
Description : *
SAP Release : 4.6 C *
Change Request : *
----
TYPE-POOLS : slis, truxs.
----
1 : Tables Defination *
----
TABLES : mseg,mara,makt,mard,t001w.
----
2 : Selection Screen *
----
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_matnr FOR mard-matnr.
PARAMETERS : p_werks LIKE mard-werks.
SELECTION-SCREEN END OF BLOCK b1.
*SELECTION-SCREEN BEGIN OF BLOCK m WITH FRAME.
*PARAMETERS: p_file TYPE rlgrap-filename.
*SELECTION-SCREEN END OF BLOCK m.
----
3 : Internal Table Declaration *
----
DATA : BEGIN OF it_mara OCCURS 0,
place1(12),
place2(12),
matnr LIKE mard-matnr,
maktx LIKE makt-maktx,
labst LIKE mard-labst,
werks like mard-werks,
place3(12),
date(10) ,
END OF it_mara.
DATA: it_mara1 TYPE truxs_t_text_data.
DATA : layout TYPE slis_layout_alv,
event TYPE slis_t_event ,
wa_event TYPE slis_alv_event,
variant TYPE disvariant.
DATA : alvly TYPE slis_layout_alv.
DATA : alvev TYPE slis_t_event.
DATA : fcat TYPE slis_t_fieldcat_alv.
DATA : w_fcat TYPE slis_fieldcat_alv.
----
: Start of Selection *
----
START-OF-SELECTION.
perform build_layout.
PERFORM select.
PERFORM process.
PERFORM display.
END-OF-SELECTION.
************************************************************************
*
F o r m R o u t i n e s S t a r t s H e r e *
*
************************************************************************
&----
*& Form SELECT
&----
text
----
--> p1 text
<-- p2 text
----
FORM select .
SELECT matnr werks FROM mard
INTO CORRESPONDING FIELDS OF TABLE it_mara
WHERE matnr IN s_matnr
AND werks LIKE p_werks.
LOOP AT it_mara.
SELECT SUM( labst ) FROM mard INTO it_mara-labst
WHERE matnr = it_mara-matnr
AND werks = it_mara-werks.
SELECT SINGLE maktx INTO it_mara-maktx FROM makt
WHERE matnr = it_mara-matnr.
MODIFY it_mara TRANSPORTING maktx labst.
ENDLOOP.
ENDFORM. "SELECT
&----
*& Form PROCESS
&----
text
----
--> p1 text
<-- p2 text
----
FORM process .
LOOP AT it_mara.
WRITE sy-datum TO it_mara-date USING EDIT MASK '__/__/____'.
WRITE 'VIKROLI' TO it_mara-place1.
WRITE 'VIKROLI' TO it_mara-place2.
WRITE 'Stock' TO it_mara-place3.
WRITE '2101' TO it_mara-werks.
MODIFY it_mara TRANSPORTING place1 place2 labst place3 date.
ENDLOOP.
DELETE ADJACENT DUPLICATES FROM it_mara COMPARING ALL FIELDS.
DELETE it_mara WHERE labst EQ ' '.
CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
EXPORTING
I_FIELD_SEPERATOR = ';'
I_LINE_HEADER =
I_FILENAME =
I_APPL_KEEP = ' '
TABLES
i_tab_sap_data = it_mara
CHANGING
I_TAB_CONVERTED_DATA = it_mara1
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.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'C:\Documents and Settings\coconut1\Desktop\ticket\FG_VIKROLI.csv'
FILETYPE = 'ASC'
WRITE_FIELD_SEPARATOR = ','
IMPORTING
FILELENGTH =
tables
data_tab = it_mara1
FIELDNAMES =
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.
ENDFORM. " PROCESS
&----
*& Form DISPLAY
&----
text
----
--> p1 text
<-- p2 text
----
FORM display .
w_fcat-fieldname = 'PLACE1'.
w_fcat-tabname = 'it_mara'.
w_fcat-col_pos = 1.
w_fcat-outputlen = '10' .
APPEND w_fcat TO fcat.
CLEAR w_fcat.
w_fcat-fieldname = 'PLACE2'.
w_fcat-tabname = 'it_mara'.
w_fcat-col_pos = 2.
w_fcat-outputlen = '10' .
APPEND w_fcat TO fcat.
CLEAR w_fcat.
w_fcat-fieldname = 'MATNR'.
w_fcat-tabname = 'it_mara'.
w_fcat-col_pos = 3.
w_fcat-outputlen = '15' .
APPEND w_fcat TO fcat.
CLEAR w_fcat.
w_fcat-fieldname = 'MAKTX'.
w_fcat-tabname = 'it_mara'.
w_fcat-col_pos = 4.
w_fcat-outputlen = '40' .
APPEND w_fcat TO fcat.
CLEAR w_fcat.
w_fcat-fieldname = 'LABST'.
w_fcat-tabname = 'it_mara'.
w_fcat-col_pos = 5.
w_fcat-outputlen = '15' .
APPEND w_fcat TO fcat.
CLEAR w_fcat.
w_fcat-fieldname = 'PLACE3'.
w_fcat-tabname = 'it_mara'.
w_fcat-col_pos = 6.
w_fcat-outputlen = '15' .
APPEND w_fcat TO fcat.
CLEAR w_fcat.
w_fcat-fieldname = 'DATE'.
w_fcat-tabname = 'it_mara'.
w_fcat-col_pos = 7.
w_fcat-outputlen = '15' .
APPEND w_fcat TO fcat.
CLEAR w_fcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER = ' '
I_BUFFER_ACTIVE = ' '
i_callback_program = sy-repid
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = ' '
I_CALLBACK_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_END_OF_LIST = ' '
I_STRUCTURE_NAME =
I_BACKGROUND_ID = ' '
I_GRID_TITLE =
I_GRID_SETTINGS =
is_layout = alvly
it_fieldcat = fcat
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT =
IT_FILTER =
IS_SEL_HIDE =
I_DEFAULT = 'X'
i_save = 'X'
IS_VARIANT =
IT_EVENTS =
IT_EVENT_EXIT =
IS_PRINT =
IS_REPREP_ID =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
I_HTML_HEIGHT_TOP = 0
I_HTML_HEIGHT_END = 0
IT_ALV_GRAPHICS =
IT_HYPERLINK =
IT_ADD_FIELDCAT =
IT_EXCEPT_QINFO =
IR_SALV_FULLSCREEN_ADAPTER =
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = it_mara
EXCEPTIONS
PROGRAM_ERROR = 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. " DISPLAY
&----
*& Form build_layout
&----
text
----
--> p1 text
<-- p2 text
----
form build_layout .
alvly-no_input = 'X'.
alvly-no_colhead = 'X'.
alvly-zebra = 'X'.
alvly-colwidth_optimize = 'X'.
endform. " build_layout
09-10-2008 6:29 AM