06-16-2008 3:38 PM
Hi friends,
Have a look at my code.
The basic requirement is to load into table PTRV_KMSUM.
I was able to do that using GUI upload FM from a notepad .
But now the requirement is using a CSV file to load into PTRV_KMSUM.
REPORT zhr_t_ptrv_kmsum NO STANDARD PAGE HEADING LINE-SIZE 200.
.
**************************************************
INTERNAL TABLE DECLARATION *
**************************************************
TYPES : BEGIN OF flat_itab,
rec(500) TYPE c,
END OF flat_itab.
DATA: data_tab TYPE TABLE OF flat_itab WITH HEADER LINE. " Internal table to hold CSV file data
DATA: it_kmsum TYPE STANDARD TABLE OF ptrv_kmsum WITH HEADER LINE.
***************************************************
SPECIFY THE FILE LOCATION *
***************************************************
PARAMETERS: p_file TYPE rlgrap-filename.
DATA: v_file TYPE string.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
file_name = p_file.
MOVE p_file TO v_file.
***************************************************
POPULATE THE INTERNAL TABLE FROM THE CSV FILE *
***************************************************
CALL FUNCTION 'TEXT_CONVERT_CSV_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR = ','
I_LINE_HEADER =
i_tab_raw_data = data_tab
I_FILENAME = v_file
tables
i_tab_converted_data = it_kmsum
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.
************************************************************
NOW LOAD INTO THE TABLE PTRV_KMSUM FROM THE INTERNAL TABLE
************************************************************
CALL FUNCTION 'TRIPS_WRITE_KMSUM'
TABLES
kmsum = it_kmsum
EXCEPTIONS
MODIFY_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.
Note:- I am getting the following error message.
The function module interface allows you to specify only fieldsd of a particular type under 'I_FILENAME'.
The field 'V_FILE' specified here is a different field type.
Regards,
Hari kiran
06-16-2008 3:42 PM
06-16-2008 3:42 PM
you can load the csv file and then pass it to the table using split.
06-16-2008 3:42 PM
06-16-2008 3:44 PM
For TEXT_CONVERT_CSV_TO_SAP
You have to define v_file as RLGRAP-FILENAME and not as a string
06-16-2008 3:45 PM
Let me try it out .
I will get back to you all.
Thank you all for replying.
Regards,
Hari Kiran
06-16-2008 3:53 PM
Friends,
I tried the following.
I commented v_file.
I have kept p_file from my code.
I passed that in fm"TEXT_CONVERT_CSV_TO_SAP.
Didn't get the earlier error message. But got the following one....
The function module interface allows you to specify only fields of a particular type under "I_TAB_RAW_DATA".
The field "DATA_TAB" specified here is a different field type.
Inputs please,
Regards,
Hari Kiran
06-16-2008 3:44 PM
Hi Friend,
Make the type of V_FILE to RLGRAP-FILENAME (now it is string).
Hope it will solve ur problem.
Regards
Krishnendu
06-16-2008 4:01 PM
here's the changed code,
REPORT zhr_t_ptrv_kmsum NO STANDARD PAGE HEADING LINE-SIZE 200.
.
**************************************************
INTERNAL TABLE DECLARATION *
**************************************************
TYPES : BEGIN OF flat_itab,
rec(500) TYPE c,
END OF flat_itab.
DATA: data_tab TYPE TABLE OF flat_itab WITH HEADER LINE. " Internal table to hold CSV file data
DATA: it_kmsum TYPE STANDARD TABLE OF ptrv_kmsum WITH HEADER LINE.
***************************************************
SPECIFY THE FILE LOCATION *
***************************************************
PARAMETERS: p_file TYPE rlgrap-filename.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
file_name = p_file.
***************************************************
POPULATE THE INTERNAL TABLE FROM THE CSV FILE *
***************************************************
CALL FUNCTION 'TEXT_CONVERT_CSV_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR = ','
I_LINE_HEADER =
i_tab_raw_data = data_tab
I_FILENAME = p_file
tables
i_tab_converted_data = it_kmsum
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.
************************************************************
NOW LOAD INTO THE TABLE PTRV_KMSUM FROM THE INTERNAL TABLE
************************************************************
CALL FUNCTION 'TRIPS_WRITE_KMSUM'
TABLES
kmsum = it_kmsum
EXCEPTIONS
MODIFY_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.
06-16-2008 3:44 PM
Declare the field v_file of type RLGRAP-FILENAME instead of STRING. It solves your problem.
Regards,
Kiran Bobbala
06-16-2008 4:12 PM
06-16-2008 4:29 PM
(change the data type) in place of the below code
TYPES : BEGIN OF flat_itab,
rec(500) TYPE c,
END OF flat_itab.
DATA: data_tab TYPE TABLE OF flat_itab WITH HEADER LINE. " Internal table to hold CSV file data
place this.
data:
this table with out header line
data_tab type TRUXS_T_TEXT_DATA,
work area for the table.
wa_data_tab(4096) type c .
Edited by: S.r.v.r.Kumar on Jun 16, 2008 8:59 PM
06-16-2008 4:37 PM
Kumar,
Edit it in my code and just paste it back.
Thanks for replying.
Regards,
Hari kiran
06-16-2008 4:46 PM
paste the below code
*************************************************
TYPE-POOLS truxs.
DATA:
data_tab TYPE truxs_t_text_data,
wa_data_tab(4096) TYPE c.
*******************************************************
delete the below code from ur program
TYPES : BEGIN OF flat_itab,
rec(500) TYPE c,
END OF flat_itab.
DATA: data_tab TYPE TABLE OF flat_itab WITH HEADER LINE.
********************************************************
i will not change all the program, if you have any dought ask me i will give answers.
i am not worried about points.
if i write the whole code what you will do.
06-16-2008 5:00 PM
Ha ha ha LOL.
I agree with you kumar.
I only need guidance and definitely not someone who will write the whole code for me.
Ok. Here is some thing I tried and got the following message---
I changed the code to----
data_tab type standard table of flat_itab.
The following is the short dump I got---
It was tried to transfer internal table "DATA_TAB " to the formal parameter "I_TAB_RAW_DATA". In doing so, a type conflict occured between formal and the actual parameter.
The condition flagged below have been violated:
(" ") the access type specified for the table are not compatible. The compatibility rules are defined by the following hierarchy:
ANY TABLE(INDEX_TABLE(STANDARD_TABLE, SORTED TABLE), HASHED TABLE)
A fixed acess type is only compatible with it's predecessors in the hierarchy.
(Example: STANDARD_TABLE) is compatible with INDEX_TABLE and ANY_TABLE, but is not compatible with HASED TABLE)
("X") The row type of the two tables are not compatible.
("X") The table keys of the two tables donot match.
(" ") One of the two tables is defined with a unique key(UNIQUE); the other is defined with a non-unique key (NON-UINQUE)
Kumar, the following are the fields in PTRV_KMSUM.----
mandt ,
pernr,
perna,
zland ,
hrgio ,
pkwkl,
kzpmf,
sivgl ,
kmsum.
I am giving data in my CSV file for the above fields including MANDT.
Here's a record of mine in my CSV file
240,00012047,2009,08,,PET,P,,1060
I haven't passed data for couple of fields.
I was able to pass similar data using GUI _upload
I will be trying your code and get back to you.
Warm regards,
Hari Kiran
06-16-2008 5:16 PM
Kumar ,
I tried your code.
Made the changes you asked.
There is no error now.
But when I executed it and checked the table PTRV_KMSUM;
Data is not getting placed.
Are you sure , if the changes you asked are all I need to do or do I need to do something else.
Here's my code now-------
REPORT zhr_t_ptrv_kmsum NO STANDARD PAGE HEADING LINE-SIZE 200.
MESSAGE-ID /rpm/migration.
TYPE-POOLS truxs.
**************************************************
INTERNAL TABLE DECLARATION *
**************************************************
*
*TYPES : BEGIN OF flat_itab,
*rec(500) TYPE c,
*END OF flat_itab.
*
data: data_tab type TRUXS_T_TEXT_DATA,
wa_data_tab(4096) type c .
*DATA: data_tab TYPE standard table of flat_itab." WITH *HEADER LINE. " Internal table to hold flat file data
DATA: it_kmsum TYPE STANDARD TABLE OF ptrv_kmsum." "WITH HEADER LINE.
***************************************************
SPECIFY THE FILE LOCATION *
***************************************************
PARAMETERS: p_file TYPE rlgrap-filename.
*DATA: v_file(75) TYPE c. "string.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
file_name = p_file.
***************************************************
POPULATE THE INTERNAL TABLE FROM THE CSV FILE***************************************************
CALL FUNCTION 'TEXT_CONVERT_CSV_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR = ','
I_LINE_HEADER =
i_tab_raw_data = data_tab
I_FILENAME = p_file
tables
i_tab_converted_data = it_kmsum
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.
************************************************************
NOW LOAD INTO THE TABLE PTRV_KMSUM FROM THE INTERNAL TABLE
************************************************************
CALL FUNCTION 'TRIPS_WRITE_KMSUM'
TABLES
kmsum = it_kmsum
EXCEPTIONS
MODIFY_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.
Warm regards,
Hari Kiran
06-16-2008 5:46 PM
REPORT zhr_t_ptrv_kmsum NO STANDARD PAGE HEADING LINE-SIZE 200.
*MESSAGE-ID /rpm/migration.
TYPE-POOLS truxs.
**************************************************
*INTERNAL TABLE DECLARATION *
**************************************************
data: i_tab_raw_data type TRUXS_T_TEXT_DATA,
wa_data_tab(4096) type c .
data:g_file type string.
DATA: it_kmsum TYPE STANDARD TABLE OF ptrv_kmsum.
data:i_tab_converted_data type STANDARD TABLE OF PTRV_KMSUM.
**************************************************
*SPECIFY THE FILE LOCATION *
***************************************************
PARAMETERS: p_file TYPE rlgrap-filename.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
file_name = p_file.
start-of-selection.
g_file = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = g_file
TABLES
data_tab = i_tab_raw_data
.
CALL FUNCTION 'TEXT_CONVERT_TEX_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR = ','
I_LINE_HEADER = I_LINE_HEADER
i_tab_raw_data = i_tab_raw_data
I_FILENAME = I_FILENAME
TABLES
i_tab_converted_data = i_tab_converted_data
EXCEPTIONS
CONVERSION_FAILED = 1
.
************************************************************
*NOW LOAD INTO THE TABLE PTRV_KMSUM FROM THE INTERNAL TABLE
************************************************************
CALL FUNCTION 'TRIPS_WRITE_KMSUM'
TABLES
kmsum = i_tab_converted_data
EXCEPTIONS
MODIFY_ERROR = 1
OTHERS = 2
.
IF sy-subrc eq 0.
MESSAGE ID SY-MSGID TYPE 'S' NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
06-16-2008 6:08 PM
Hi kumar,
no syntax error nothing.
Everything looks great.It executed.
I got the green colored "Nike"symbol or "ok" symbol
in status bar with 0.00 besides it when I executed.
But data didn't get placed.
I had a doubt In GUI _UPLOAD.
You didnt give the file type???
Reply soon.
Thank you so much once again.
06-17-2008 8:33 AM
write a break-point before the statement CALL FUNCTION 'TRIPS_WRITE_KMSUM'. and check data in table i_tab_converted_data. you will get all the data that is there in ur file, i think there is a problem in 'TRIPS_WRITE_KMSUM' function module or data in the file.
no need to pass file type in GUI uplode if the file is notepad
by the by what is ur file type.
Edited by: S.r.v.r.Kumar on Jun 17, 2008 1:03 PM
06-17-2008 12:47 PM
Sorry Kumar for the late reply.
Had to go home last night. It was getting late.
Just logged in now.
Ya, I will place the breakpoint and check if data is getting placed in the Internal table or not. That will clear a lot of things.
And I will be given a CSV file , with '~' as the field separator.
I have already loaded data into PTRV_KMSUM table from notepad.Didn't have much problem doping that.
Problem is with this CSV loading.
Thanks again for replying.
Warm regards,
Hari Kiran
06-17-2008 2:23 PM
Kumar,
'TEXT_CONVERT_TEXT_TO_SAP' will load the CSV file into the internal Table.
Don't need to use GUI Upload then.
But in your code you used GUI_UPLOAD.
Guess , that needs to be changed.
I will try out that Break point and see if data is getting placed in the internal table from the CSV file or not.
Reply soon,
Warm regards,
Hari.
06-17-2008 2:46 PM
Hi ,
In debugging mode I am getting the message-----
"Specified table name not recognised " for
i_tab_converted_data.
I had the placed the break point in the FM --Text_Convert_CSV_to_SAP.
I have also not used GUI_UPLOAD.
I want to pull the data from CSV file using the FM Text_Convert_CSV_to_SAP.Then place it in a internal table.
Then load using the FM " TRIPS_WRITE_KMSUM".
Warm regards,
Hari Kiran