File import skips last record without blank line
The following code works great for importing a csv file and inserting the records into tables..
but the last record is not read unless there is a blank line after it..
what needs to be changed so that the last line works with or without a carriage return after it..
create or replace PACKAGE BODY "HTMLDB_TOOLS"
AS
TYPE varchar2_t IS TABLE OF VARCHAR2(32767) INDEX BY binary_integer;
-- Private functions --{{{
PROCEDURE delete_collection ( --{{{
-- Delete the collection if it exists
p_collection_name IN VARCHAR2
IS
BEGIN
IF (htmldb_collection.collection_exists(p_collection_name))
THEN
htmldb_collection.delete_collection(p_collection_name);
END IF;
END delete_collection; --}}}
PROCEDURE csv_to_array ( --{{{
-- Utility to take a CSV string, parse it into a PL/SQL table
-- Note that it takes care of some elements optionally enclosed
-- by double-quotes.
p_csv_string IN VARCHAR2,
p_array OUT wwv_flow_global.vc_arr2,
p_separator IN VARCHAR2 := ','
IS
l_start_separator PLS_INTEGER := 0;
l_stop_separator PLS_INTEGER := 0;
l_length PLS_INTEGER := 0;
l_idx BINARY_INTEGER := 0;
l_quote_enclosed BOOLEAN := FALSE;
l_offset PLS_INTEGER := 1;
BEGIN
l_length := NVL(LENGTH(p_csv_string),0);
IF (l_length <= 0)
THEN
RETURN;
END IF;
LOOP
l_idx := l_idx + 1;
l_quote_enclosed := FALSE;
IF SUBSTR(p_csv_string, l_start_separator + 1, 1) = '"'
THEN
l_quote_enclosed := TRUE;
l_offset := 2;
l_stop_separator := INSTR(p_csv_string, '"', l_start_separator + l_offset, 1);
ELSE
l_offset := 1;
l_stop_separator := INSTR(p_csv_string, p_separator, l_start_separator + l_offset, 1);
END IF;
IF l_stop_separator = 0
THEN
l_stop_separator := l_length + 1;
END IF;
p_array(l_idx) := (SUBSTR(p_csv_string, l_start_separator + l_offset,(l_stop_separator - l_start_separator - l_offset)));
EXIT WHEN l_stop_separator >= l_length;
IF l_quote_enclosed
THEN
l_stop_separator := l_stop_separator + 1;
END IF;
l_start_separator := l_stop_separator;
END LOOP;
END csv_to_array; --}}}
PROCEDURE get_records(p_blob IN blob,p_records OUT varchar2_t) --{{{
IS
l_record_separator VARCHAR2(2) := chr(13)||chr(10);
l_last INTEGER;
l_current INTEGER;
BEGIN
-- Sigh, stupid DOS/Unix newline stuff. If HTMLDB has generated the file,
-- it will be a Unix text file. If user has manually created the file, it
-- will have DOS newlines.
-- If the file has a DOS newline (cr+lf), use that
-- If the file does not have a DOS newline, use a Unix newline (lf)
IF (NVL(dbms_lob.instr(p_blob,utl_raw.cast_to_raw(l_record_separator),1,1),0)=0)
THEN
l_record_separator := chr(10);
END IF;
l_last := 1;
LOOP
l_current := dbms_lob.instr( p_blob, utl_raw.cast_to_raw(l_record_separator), l_last, 1 );
EXIT WHEN (nvl(l_current,0) = 0);
p_records(p_records.count+1) := utl_raw.cast_to_varchar2(dbms_lob.substr(p_blob,l_current-l_last,l_last));
l_last := l_current+length(l_record_separator);
END LOOP;
END get_records; --}}}
-- Utility functions --{{{
PROCEDURE parse_textarea ( --{{{
p_textarea IN VARCHAR2,
p_collection_name IN VARCHAR2
IS
l_index INTEGER;
l_string VARCHAR2(32767) := TRANSLATE(p_textarea,chr(10)||chr(13)||' ,','@@@@');
l_element VARCHAR2(100);
BEGIN
l_string := l_string||'@';
htmldb_collection.create_or_truncate_collection(p_collection_name);
LOOP
l_index := instr(l_string,'@');
EXIT WHEN NVL(l_index,0)=0;
l_element := substr(l_string,1,l_index-1);
IF (trim(l_element) IS NOT NULL)
THEN
htmldb_collection.add_member(p_collection_name,l_element);
END IF;
l_string := substr(l_string,l_index+1);
END LOOP;
END parse_textarea; --}}}
PROCEDURE parse_file( --{{{
p_file_name IN VARCHAR2,
p_collection_name IN VARCHAR2,
p_headings_item IN VARCHAR2,
p_columns_item IN VARCHAR2,
p_ddl_item IN VARCHAR2,
p_table_name IN VARCHAR2 DEFAULT NULL
IS
l_blob blob;
l_records varchar2_t;
l_record wwv_flow_global.vc_arr2;
l_datatypes wwv_flow_global.vc_arr2;
l_headings VARCHAR2(4000);
l_columns VARCHAR2(4000);
l_seq_id NUMBER;
l_num_columns INTEGER;
l_ddl VARCHAR2(4000);
BEGIN
IF (p_table_name is not null)
THEN
l_ddl := 'insert into '||p_table_name||' '||
'select '||v(p_columns_item)||' '||
'from htmldb_collections '||
'where seq_id > 0 and collection_name='''||p_collection_name||'''';
execute immediate l_ddl;
RETURN;
END IF;
BEGIN
select blob_content into l_blob from wwv_flow_files
where name=p_file_name;
EXCEPTION
WHEN NO_DATA_FOUND THEN
raise_application_error(-20000,'File not found, id='||p_file_name);
END;
get_records(l_blob,l_records);
IF (l_records.count < 2)
THEN
raise_application_error(-20000,'File must have at least 2 ROWS, ONE HEADER and ONE OR MORE DATA, id='||p_file_name);
END IF;
-- Initialize collection
htmldb_collection.create_or_truncate_collection(p_collection_name);
-- Get column headings
csv_to_array(l_records(1),l_record);
l_num_columns := l_record.count;
if (l_num_columns > 50) then
raise_application_error(-20000,'Max. of 50 columns allowed, id='||p_file_name);
end if;
-- Get column headings and names
FOR i IN 1..l_record.count
LOOP
l_headings := l_headings||':'||l_record(i);
l_columns := l_columns||',c'||lpad(i,3,'0');
END LOOP;
l_headings := ltrim(l_headings,':');
l_columns := ltrim(l_columns,',');
htmldb_util.set_session_state(p_headings_item,l_headings);
htmldb_util.set_session_state(p_columns_item,l_columns);
-- Save data into specified collection
FOR i IN 2..l_records.count
LOOP
csv_to_array(l_records(i),l_record);
l_seq_id := htmldb_collection.add_member(p_collection_name,'dummy');
FOR i IN 1..l_record.count
LOOP
htmldb_collection.update_member_attribute(
p_collection_name=> p_collection_name,
p_seq => l_seq_id,
p_attr_number => i,
p_attr_value => l_record(i)
END LOOP;
END LOOP;
DELETE FROM wwv_flow_files WHERE name=p_file_name;
END;
BEGIN
NULL;
END;
found someone that helped me.. here was the fix:
l_current := dbms_lob.instr( p_blob, utl_raw.cast_to_raw(l_record_separator), l_last, 1 );
-- START of new code, lines above as per existing
IF nvl(l_current,0) = 0 AND LENGTH(TRIM(utl_raw.cast_to_varchar2(dbms_lob.substr(p_blob,32767,l_last)))) > 0 THEN
p_records(p_records.count+1) := utl_raw.cast_to_varchar2(dbms_lob.substr(p_blob,32767,l_last));
END IF;
-- END of new code,, lines below as per existing
EXIT WHEN (nvl(l_current,0) = 0);
Similar Messages
-
Executable Jar files can't be run without command line
Hello,
A few months ago, I was messing with some executable jar files, but now I can't run them anymore without a batch file or command line, so how do I fix this?
Thanks in advance,
Yves W.
Edited by: Yves W on 18-dec-2010 15:56Open a command prompt.
Type
assoc .jarYou should get:
.jar=jarfileIf not, type:
assoc .jar=jarfileNow type:
ftype jarfileYou should get something like this (adjust the path to javaw.exe for your system):
jarfile="C:\Program Files\Java\jre6\bin\javaw.exe" -jar "%1" %*If not, type (adjust the path to javaw.exe for your system):
ftype jarfile="C:\Program Files\Java\jre6\bin\javaw.exe" -jar "%1" %* -
File receiver : blank line at end of file
Dear friends,
we are using file receiver with file content conversion , tp : FTP
The file has a flat structure & fixed length (no delimiters) :
reordset parameters used- fieldFixedLengths
each record is in a different line, but at the end of the records a blank line is inserted.
(no endSeparator is used.)
Can you pls advise hot to get rid of this extra blank lineHi Datta,
I am not sure but you can try with follwing parameters...
NameA.fixedLengthTooShortHandling Specify how you want the system to respond when column widths in the actual document exceed those defined in NameA.fieldFixedLengths. The following values are permitted:
· Error
Error means that processing of the document is terminated.
· Cut
Cut means that a value is shortened to the maximum permitted length.
· Ignore
Ignore means that the system applies the value completely, regardless of it being too long. Subsequent columns are moved correspondingly.
U can use ignore in your case.
For more info. plz check
http://help.sap.com/saphelp_nw04/helpdata/en/d2/bab440c97f3716e10000000a155106/frameset.htm
Regards
Sachin -
Out put file with three extra blank line
Hi Expert
i am snding some article data from sap to ftp location.from proxy class the internal table has all correct record .but in the out put file three blank line is coming with all the record at the end.
i have the following cc parameter
File.fieldNames Trans_type,Transfer_no,SrcSt_no,DestST_no,LPN_No,Transfer_date
File.fieldFixedLengths 1,30,10,10,10,8
then i added
File.endSeparator '0'.
but still 3 blank line is coming in the output file.
please suggest somthing.Hi !
Why are you using File.endSeparator '0'. ?
Are you sure your input data doesn't have those 3 blank records in the end? Check the message payload in the sxmb_moni transaction.
Regards,
Matias. -
Unable to remove the "blank" line at the end of the file
Hi Experts,
My requirement is to send data in 'Binary' form as an attachement to a mail address. I have followed as below.
Converted data into Binary form using the FM 'SCMS_TEXT_TO_BINARY'
Call FM SO_NEW_DOCUMENT_ATT_SEND_API1 to send mail.
Until this point, all works fine and I receive a text file as well. Howvever, a blank line gets appended at the end (after last line) of the file. Please let me know, how I would get rid-off this empty line. Please refer attachment.
Thanks in advance !Thanks Manish.
I have resoved the issue, following steps have been incorporated.
1. Find the output length of the file from the exporting parameter(output_length) of the Function module 'SCMS_TEXT_TO_BINARY'
2. Pass the output length to DOC_SIZE component to the second line of the itab packing_list of function module 'SO_NEW_DOCUMENT_ATT_SEND_API1'.
3. Pass the output length to DOC_SIZE component to document_data of function module 'SO_NEW_DOCUMENT_ATT_SEND_API1'.
So there it is, the blank line is gone....
Regards,
Umar Ali -
How to handle blank line in File adapter
Hi,
I am using a file adapter with CSV as input file. If I have a blank line in CSV file, BPEL is failing read it, no instance is created and file is archieved.
Please let me know how to handle this issue.
ThanksHi Yatan,
I am already using rejectedMessageHandlers, I am on 10.1.3.3.
Here's my bpel.xml
============
<?xml version = '1.0' encoding = 'UTF-8'?>
<BPELSuitcase>
<BPELProcess id="EmpAddressUpdABCSImpl" src="EmpAddressUpdABCSImpl.bpel">
<partnerLinkBindings>
<partnerLinkBinding name="ReadFile">
<property name="wsdlLocation">ReadFile.wsdl</property>
<property name="rejectedMessageHandlers">file://E:/HRARCHIVE/BadData</property>
</partnerLinkBinding>
<partnerLinkBinding name="InsertAddressUpd">
<property name="wsdlLocation">InsertAddressUpd.wsdl</property>
<property name="retryInterval">60</property>
</partnerLinkBinding>
</partnerLinkBindings>
<configurations>
<property name="sensorLocation">sensor.xml</property>
<property name="sensorActionLocation">sensorAction.xml</property>
</configurations>
<activationAgents>
<activationAgent className="oracle.tip.adapter.fw.agent.jca.JCAActivationAgent" partnerLink="ReadFile">
<property name="portType">Read_ptt</property>
<property name="rejectedMessageHandlers">file://E:/HRARCHIVE/BadData</property>
</activationAgent>
</activationAgents>
</BPELProcess>
</BPELSuitcase>
Someone told me that this can be achieved by changing the native schema, I tried many options but no result. Please suggest me.
-- Shirish -
Extra blank lines in source code
I have built a website in Dreamweaver CS4 and have a client editing pages in Contribute CS5. Both of us are working on Windows 7, and the site is hosted on Linux. When she makes edits to the page, something is introducing a GAZILLION blank lines in the source code. A typical page for this site is about 380 lines of code. The problem page is now more than 310,000 lines code with 100-200 blank lines between every "real" line of code. What the...?!
I need to know how to stop this and how to remove the blank lines from the source code using Dreamweaver.
The page in question lives here: http://www.alexandercitychamber.com/member-category.html
HELP!!!
JeffHello, Diane -
We've got two separate issues here, but I think we have the solution to both.
1. How to stop Contribute from adding blank lines in the code, and
2. How to clean up a GAZILLION lines of blank code in a document.
First, Number 1. I assume you're working in Dreamweaver. If not, I'm not sure how to guide you. But, when you define a Contribute Site, there is an area to specify administrative roles and permissions. Under each Role, at the bottom, you will see a popup for what kind of server the site is hosted on. The default is Windows. I had to change this to Unix (Linux) to match the hosting of our problem site. Find out what platform your host is using. You will have to specify this under each admistrative Role. After doing this, I had the client make some edits, then I opened the files in Dreamweaver. No new blank lines. I admit, I still have my fingers crossed somewhat.
Okay, now how to clean up your source code and remove blank lines. A developer friend found this on some forum I had not seen. I don't know where, but I am grateful to the person who wrote it. It didn't get all the blank lines in my files, but I think some of the others, which I removed manually, were probably from the client pasting content in from Word. Here's what to do:
1. Open the file in Dreamweaver
2. Click CTRL + F, or go to EDIT > FIND AND REPLACE
3. Select "Current document" in "Find In" (You can also select the folder if you have multiple files.
4. Search in "Source Code"
5. Check the box labeled "Use regular expression"
6. Type "[\r\n]{2,}" (without quotes) in "Find"
7. Type "\n" (without quotes) in "Replace"
8. Press "Replace All"
The operation chugged for a few minutes with my 301,000-line document. Yours may a take a little longer, but it did work. Good luck!
Jeff
[email protected] -
SQL Data Modeler adds blank line to UK Constraints
Oracle SQL Developer Data Modeler Version: 2.0.0 Build: 584
I'm migrating my schema designs from Oracle Designer to SQL Developer Data Modeler. When I get to the point of generating SQL files I consistently get an extra blank line added to every unique constraint. My primary key constraints are defined the same way, but they do not have the blank line. See below for an example of the SQL output:
ALTER TABLE ALIAS
ADD CONSTRAINT ALIAS_PK PRIMARY KEY ( ALIAS_NO )
USING INDEX TABLESPACE INDEX1
NOLOGGING
NOSORT
ALTER TABLE ALIAS
ADD CONSTRAINT ALIAS_UK UNIQUE ( ALIAS_NAME )
USING INDEX TABLESPACE INDEX1
NOLOGGING
NOSORT
This blank line causes errors when I execute the SQL script so I have to edit it before using. Did I forget to something or is this a bug?
Thanks,
Gail Binkley
Stanford UniversityHi Gail,
thanks for feedback. I logged bug for that.
Philip -
How to skip blank line (EOF char) at the end of the file while creating ?
Hi,
In my program I have to create a file in Text mode using OPEN DATASET statement. This file is being sent to a third party system for their processing. I came to know while creating the file using OPEN DATASET, one LF character is inserted end of the file resulting a blank line end of the file. Thus if my internal table contains 5 reocrds, in the created text file I can see 6 lines where last is a blank. My question is how to remove this blank line which is causing issue in the thirdparty system.
Here is the Code I have used.
TRY.
Write the file in Text Mode
OPEN DATASET lv_outpf FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE
WITH SMART LINEFEED
MESSAGE lv_msg.
IF lv_msg IS NOT INITIAL.
WRITE / lv_msg.
EXIT.
ENDIF.
LOOP AT itab_new INTO st.
TRANSFER st TO lv_outpf.
ENDLOOP.
CLOSE DATASET lv_outpf.
CATCH cx_root. "#EC No Handler
ENDTRY.an effective way to do it:
open your dataset in binary mode, transfer the records but between each record transfer the LF (or CRLF according to your need)
after the last record you don't transfer the LF -
Skipping Blank Lines in text File
I am working on an assignment in which i have to read from a text file and store the strings individually. The problem i have is that the text file has blank line between each set of strings. So i figured to use "fin.nextLine();" to skip that blank line and continue with storing the values. but i get
"Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Unknown Source)
at processmsg.ProcessMessages.choice1(ProcessMessages.java:68)
at processmsg.ProcessMessages.main(ProcessMessages.java:25)"
which is where the fin.nexLine() is at. How can i just skip that blank line?
System.out.println("Please enter the file location");
Scanner stdin = new Scanner(System.in);
String fileName = stdin.nextLine();
// read the information from the file
try {
Scanner fin = new Scanner(new File(fileName));
String tSendName = fin.nextLine();
while(tSendName != null)
String tRecieveName = fin.nextLine();
String tPhoneNumber = fin.nextLine();
String tDate = fin.nextLine();
String tTime = fin.nextLine();
String tStatus = fin.nextLine();
String tMessage = fin.nextLine();
PhoneMessage phonemessage = new PhoneMessage(tSendName, tRecieveName,
tPhoneNumber, tDate, tTime, tStatus, tMessage);
fin.nextLine();
tSendName = fin.nextLine();don't know if you want the whole code, the whole code is kind of large and spread out over 3 different classes. and yes the text file is standard
sender
reciever
phone number
date
time
status
message
sender
reciever
phone number
date
time
status
message
sender
reciever
phone number
date
time
status
message
private static void choice()
// scan the file location from the user
System.out.println("Please enter the file location");
Scanner stdin = new Scanner(System.in);
String fileName = stdin.nextLine();
// read the information from the file
try {
Scanner fin = new Scanner(new File(fileName));
String tSendName = fin.nextLine();
while(tSendName != null)
String tRecieveName = fin.next();
String tPhoneNumber = fin.next();
String tDate = fin.nextLine();
String tTime = fin.nextLine();
String tStatus = fin.nextLine();
String tMessage = fin.nextLine();
PhoneMessage phonemessage = new PhoneMessage(tSendName, tRecieveName,
tPhoneNumber, tDate, tTime, tStatus, tMessage);
// skip blank line between entries
fin.nextLine();
// test date string for correct format
int month = Integer.parseInt(tDate.substring(0,2));
int day = Integer.parseInt(tDate.substring(3,5));
int year = Integer.parseInt(tDate.substring(6,10));
// test time string for correct format
int hour = Integer.parseInt(tTime.substring(0,2));
int minute = Integer.parseInt(tTime.substring(3,5));
int second = Integer.parseInt(tTime.substring(6,8));
tSendName = fin.nextLine();
msgList.add(phonemessage);
fin.close();
} catch (FileNotFoundException e) {
System.out.println("The file " + fileName + " was not found!");
} catch (java.lang.NumberFormatException e) {
System.out.println("The date and/or time is not of the correct format");
} -
How to remove the last blank line in the downloaded text file?
Hi All,
I am downloading the one internal table content using the GUI_DOWNLOAD to a text file(.txt). The cursor is in last position of the text file where there is no content. For example consider the below is downloaded txt file:
This is test file.
Downloaded from the internal table
using GUI_DOWNLOAD
| <----
In above the internal table content first three lines..
Once I press page down in the text file, the cursor goes below the third line..(i.e., next to the last line)
How to avoid that ?
Thanks in Advance,
Regards,
RaghuI solved this problem with BIN mode.
See this code example
DATA: FILESIZE TYPE I.
CALL FUNCTION 'SCMS_TEXT_TO_BINARY'
IMPORTING
OUTPUT_LENGTH = filesize
TABLES
TEXT_TAB = i_record
BINARY_TAB = i_Record
filesize = filesize - 1. "TRUNCATED LAST LINE!!!
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE = filesize
filename = l_file
filetype = 'BIN'
TRUNC_TRAILING_BLANKS = 'X'
TRUNC_TRAILING_BLANKS_EOL = 'X'
WRITE_LF_AFTER_LAST_LINE = ' '
TABLES
data_tab = i_record
Hope this can help you. -
How to skip footer record in SQL*Loader input file
I have am using SQL*Loader in a batch import process.
The input files to SQL*Loader have a header record and footer record - always the 1st and last records in the file.
I need SQL*Loader to ignore these two records in every file when performing the import. I can easily ignore the header by using the SKIP function.
Does anybody know how to ignore the last record (footer) in an input file??
I do not want to physically pre-strip the footer since the business want all data files to have the header and footer records.Thanks - how do I use the when clause to specify the last line of the input file?
I am presuming it requires me to have a unique identifier at a given position on that last line. If I don't have such an identifier can I still use your solution?
Cheers Why not putting an idetifier at the end of your input file: echo "This_is_the_End" >> input_file ? -
How to skip first record while inserting data from a flat file to BW system
Hi Experts,
In my project we have to upload flat file into a BW system. I have written a program and it is working fine.
Now we have got another requirement. The flat file will have a header record (first row). While uploading the flat file we have to skip this record. How I can do so?
The code is as below:
FORM upload1.
DATA : wf_title TYPE string,
lt_filetab TYPE filetable,
l_separator TYPE char01,
l_action TYPE i,
l_count TYPE i,
ls_filetab TYPE file_table,
wf_delemt TYPE rollname,
wa_fieldcat TYPE lvc_s_fcat,
tb_fieldcat TYPE lvc_t_fcat,
rows_read TYPE i,
p_error TYPE char01,
l_file TYPE string.
DATA: wf_object(30) TYPE c,
wf_tablnm TYPE rsdchkview.
wf_object = 'myprogram'.
DATA i TYPE i.
DATA:
lr_mdmt TYPE REF TO cl_rsdmd_mdmt,
lr_mdmtr TYPE REF TO cl_rsdmd_mdmtr,
lt_idocstate TYPE rsarr_t_idocstate,
lv_subrc TYPE sysubrc.
TYPES : BEGIN OF test_struc,
/bic/myprogram TYPE /bic/oimyprogram,
txtmd TYPE rstxtmd,
END OF test_struc.
DATA : tb_assum TYPE TABLE OF /bic/pmyprogram.
DATA: wa_ztext TYPE /bic/tmyprogram,
myprogram_temp TYPE ziott_assum,
wa_myprogram TYPE /bic/pmyprogram.
DATA : test_upload TYPE STANDARD TABLE OF test_struc,
wa2 TYPE test_struc.
DATA : wa_test_upload TYPE test_struc,
ztable_data TYPE TABLE OF /bic/pmyprogram,
ztable_text TYPE TABLE OF /bic/tmyprogram,
wa_upld_text TYPE /bic/tmyprogram,
wa_upld_data TYPE /bic/pmyprogram,
t_assum TYPE ziott_assum.
DATA : wa1 LIKE test_upload.
wf_title = text-026.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = wf_title
default_extension = 'txt'
file_filter = 'Tab delimited Text Files (*.txt)'
CHANGING
file_table = lt_filetab
rc = l_count
user_action = l_action
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
OTHERS = 3. "#EC NOTEXT
IF sy-subrc <> 0.
EXIT.
ENDIF.
LOOP AT lt_filetab INTO ls_filetab.
l_file = ls_filetab.
ENDLOOP.
CHECK l_action = 0.
IF l_file IS INITIAL.
EXIT.
ENDIF.
l_separator = 'X'.
wa_fieldcat-fieldname = 'test'.
wa_fieldcat-dd_roll = wf_delemt.
APPEND wa_fieldcat TO tb_fieldcat.
CALL FUNCTION 'MESSAGES_INITIALIZE'.
CLEAR wa_test_upload.
Upload file from front-end (PC)
File format is tab-delimited ASCII
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = l_file
has_field_separator = l_separator
TABLES
data_tab = i_mara
data_tab = test_upload
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
IF sy-subrc <> 0.
EXIT.
ELSE.
CALL FUNCTION 'MESSAGES_INITIALIZE'.
IF test_upload IS NOT INITIAL.
DESCRIBE TABLE test_upload LINES rows_read.
CLEAR : wa_test_upload,wa_upld_data.
LOOP AT test_upload INTO wa_test_upload.
CLEAR : p_error.
rows_read = sy-tabix.
IF wa_test_upload-/bic/myprogram IS INITIAL.
p_error = 'X'.
MESSAGE s153 WITH wa_test_upload-/bic/myprogram sy-tabix.
CONTINUE.
ELSE.
TRANSLATE wa_test_upload-/bic/myprogram TO UPPER CASE.
wa_upld_text-txtmd = wa_test_upload-txtmd.
wa_upld_text-txtsh = wa_test_upload-txtmd.
wa_upld_text-langu = sy-langu.
wa_upld_data-chrt_accts = 'xyz1'.
wa_upld_data-co_area = '12'.
wa_upld_data-/bic/zxyzbcsg = 'Iy'.
wa_upld_data-objvers = 'A'.
wa_upld_data-changed = 'I'.
wa_upld_data-/bic/zass_mdl = 'rrr'.
wa_upld_data-/bic/zass_typ = 'I'.
wa_upld_data-/bic/zdriver = 'yyy'.
wa_upld_text-langu = sy-langu.
MOVE-CORRESPONDING wa_test_upload TO wa_upld_data.
MOVE-CORRESPONDING wa_test_upload TO wa_upld_text.
APPEND wa_upld_data TO ztable_data.
APPEND wa_upld_text TO ztable_text.
ENDIF.
ENDLOOP.
DELETE ADJACENT DUPLICATES FROM ztable_data.
DELETE ADJACENT DUPLICATES FROM ztable_text.
IF ztable_data IS NOT INITIAL.
CALL METHOD cl_rsdmd_mdmt=>factory
EXPORTING
i_chabasnm = 'myprogram'
IMPORTING
e_r_mdmt = lr_mdmt
EXCEPTIONS
invalid_iobjnm = 1
OTHERS = 2.
CALL FUNCTION 'MESSAGES_INITIALIZE'.
**Lock the Infoobject to update
CALL FUNCTION 'RSDG_IOBJ_ENQUEUE'
EXPORTING
i_objnm = wf_object
i_scope = '1'
i_msgty = rs_c_error
EXCEPTIONS
foreign_lock = 1
sys_failure = 2.
IF sy-subrc = 1.
MESSAGE i107(zddd_rr) WITH wf_object sy-msgv2.
EXIT.
ELSEIF sy-subrc = 2.
MESSAGE i108(zddd_rr) WITH wf_object.
EXIT.
ENDIF.
*****Update Master Table
IF ztable_data IS NOT INITIAL.
CALL FUNCTION 'RSDMD_WRITE_ATTRIBUTES_TEXTS'
EXPORTING
i_iobjnm = 'myprogram'
i_tabclass = 'M'
I_T_ATTR = lt_attr
TABLES
i_t_table = ztable_data
EXCEPTIONS
attribute_name_error = 1
iobj_not_found = 2
generate_program_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
CALL FUNCTION 'MESSAGE_STORE'
EXPORTING
arbgb = 'zddd_rr'
msgty = 'E'
txtnr = '054'
msgv1 = text-033
EXCEPTIONS
OTHERS = 3.
MESSAGE e054(zddd_rr) WITH 'myprogram'.
ELSE.
CALL FUNCTION 'MESSAGE_STORE'
EXPORTING
arbgb = 'zddd_rr'
msgty = 'S'
txtnr = '053'
msgv1 = text-033
EXCEPTIONS
OTHERS = 3.
ENDIF.
*endif.
*****update Text Table
IF ztable_text IS NOT INITIAL.
CALL FUNCTION 'RSDMD_WRITE_ATTRIBUTES_TEXTS'
EXPORTING
i_iobjnm = 'myprogram'
i_tabclass = 'T'
TABLES
i_t_table = ztable_text
EXCEPTIONS
attribute_name_error = 1
iobj_not_found = 2
generate_program_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
CALL FUNCTION 'MESSAGE_STORE'
EXPORTING
arbgb = 'zddd_rr'
msgty = 'E'
txtnr = '055'
msgv1 = text-033
EXCEPTIONS
OTHERS = 3.
ENDIF.
ENDIF.
ELSE.
MESSAGE s178(zddd_rr).
ENDIF.
ENDIF.
COMMIT WORK.
CALL FUNCTION 'RSD_CHKTAB_GET_FOR_CHA_BAS'
EXPORTING
i_chabasnm = 'myprogram'
IMPORTING
e_chktab = wf_tablnm
EXCEPTIONS
name_error = 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
****Release locks on Infoobject
CALL FUNCTION 'RSDG_IOBJ_DEQUEUE'
EXPORTING
i_objnm = 'myprogram'
i_scope = '1'.
ENDIF.
ENDIF.
PERFORM data_selection .
PERFORM update_alv_grid_display.
CALL FUNCTION 'MESSAGES_SHOW'.
ENDFORM.
Please let me know how I can skip first record of the flat file?
Regards,
Sgo through this hope u can get some idea
REPORT ztest no standard page heading line-size 255.
Declaration *
TYPES t_itab1 TYPE alsmex_tabline.
types: begin of t_csks,
kostl like csks-kostl,
end of t_csks.
types: begin of t_cska,
kstar like cska-kstar,
end of t_cska.
data: begin of t_flatfile,
docdate like COHEADER-BLDAT,
postdate like COHEADER-BUDAT,
doctext like COHEADER-BLTXT,
costele like RK23F-KSTAR,
amount like RK23F-WTGBTR,
scostctr like RK23F-SKOSTL,
rcostctr like RK23F-EKOSTL,
rintorder like RK23F-EAUFNR,
end of t_flatfile.
data: begin of t_flatfile1,
docdate like COHEADER-BLDAT,
postdate like COHEADER-BUDAT,
doctext like COHEADER-BLTXT,
costele like RK23F-KSTAR,
amount like RK23F-WTGBTR,
scostctr like RK23F-SKOSTL,
rcostctr like RK23F-EKOSTL,
rintorder like RK23F-EAUFNR,
NUM LIKE SY-INDEX,
end of t_flatfile1.
data: itab like table of t_flatfile with header line.
data: itab2 like table of t_flatfile1 with header line.
DATA: it_itab1 TYPE STANDARD TABLE OF t_itab1 WITH HEADER LINE,
MESSTAB1 LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE,
MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
data: begin of bdcdata occurs 0.
include structure bdcdata.
data: end of bdcdata.
data:t_lin type i VALUE '0',
u_rec type i VALUE '0',
s_rec type i VALUE '0'.
data: it_csks type standard table of t_csks,
wa_csks type t_csks.
data: it_cska type standard table of t_cska,
wa_cska type t_cska.
*Selection Screen
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-010.
parameters: p_docdat LIKE COHEADER-BLDAT obligatory,
p_postda LIKE COHEADER-BUDAT obligatory,
p_doctxt LIKE COHEADER-BLTXT.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-011.
parameters: p_file LIKE RLGRAP-FILENAME obligatory,
DIS_MODE LIKE CTU_PARAMS-DISMODE DEFAULT 'N'.
SELECTION-SCREEN END OF BLOCK b2.
A T S E L E C T I O N S C R E E N *
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM get_local_file_name USING p_file.
*Start of Selection
START-OF-SELECTION.
Perform get_Excel_data.
perform validate_data.
Perform Process_Data.
end-of-selection
end-of-selection.
perform display_data.
*& Form get_local_file_name
text
-->P_P_FILE text
FORM get_local_file_name USING P_P_FILE.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
CHANGING
file_name = p_file.
ENDFORM. " get_local_file_name
*& Form get_Excel_data
text
--> p1 text
<-- p2 text
FORM get_Excel_data .
FIELD-SYMBOLS : <FS>.
DATA : V_INDEX TYPE I.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file
i_begin_col = 1
i_begin_row = 2
i_begin_row = 1
i_end_col = 256
i_end_row = 9999 "65536
TABLES
intern = it_itab1
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
Message text-013 type 'E'.
ENDIF.
IF IT_ITAB1[] IS INITIAL.
Message text-001 type 'E'.
else. "IF IT_ITAB1[] IS INITIAL.
data: itab2 like itab occurs 0 with header line.
SORT IT_ITAB1 BY ROW COL.
LOOP AT IT_ITAB1.
MOVE :IT_ITAB1-COL TO V_INDEX.
ASSIGN COMPONENT V_INDEX OF STRUCTURE itab2 TO <FS>.
MOVE : IT_ITAB1-VALUE TO <FS>.
AT END OF ROW.
MOVE-CORRESPONDING itab2 TO itab.
APPEND itab.
CLEAR:itab,itab2.
ENDAT.
endloop.
describe table itab lines t_lin.
endif. "IF IT_ITAB1[] IS INITIAL.
ENDFORM. " get_Excel_data
*& Form Process_Data
text
--> p1 text
<-- p2 text
FORM Process_Data .
data:l_tabix type sy-tabix.
data:l_periv like t001-periv,
l_monat like bkpf-monat,
l_gjahr like bkpf-gjahr,
l_amt(21) type c.
data: l_ddate(10),
l_pdate(10).
WRITE p_docdat TO l_ddate.
WRITE p_postda TO l_pdate.
clear: l_periv,l_monat,l_gjahr.
select single periv from t001 into l_periv where bukrs = '5000'. "P_bukrs
if sy-subrc eq 0.
l_gjahr = p_postda+0(4).
call function 'FI_PERIOD_DETERMINE'
EXPORTING
i_budat = p_postda
i_bukrs = '5000' "p_bukrs
i_periv = l_periv
i_gjahr = l_gjahr
IMPORTING
e_monat = l_monat.
clear:l_periv.
endif.
loop at itab2.
refresh:bdcdata.
clear:bdcdata.
l_tabix = sy-tabix.
perform bdc_dynpro using 'SAPLK23F1' '1200'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'COHEADER-SEND_REC_REL'
'10SAP'.
perform bdc_field using 'RK23F-STATUS'
'S'.
perform bdc_field using 'COHEADER-BLDAT'
itab-docdate.
l_ddate.
perform bdc_field using 'COHEADER-BUDAT'
itab-postdate.
l_pdate.
perform bdc_field using 'COHEADER-PERIO'
l_monat. "'9'.
perform bdc_field using 'COHEADER-BLTXT'
itab-doctext.
p_doctxt.
perform bdc_field using 'RK23F-KSTAR'
itab2-costele.
WRITE itab2-amount TO l_amt.
l_amt = itab-amount.
condense l_amt no-gaps.
perform bdc_field using 'RK23F-WTGBTR'
l_amt.
itab-amount.
perform bdc_field using 'RK23F-WAERS'
'USD'.
*perform bdc_field using 'RK23F-SGTXT'
itab-doctext.
perform bdc_field using 'RK23F-SKOSTL'
itab2-scostctr.
perform bdc_field using 'BDC_CURSOR'
'RK23F-EAUFNR'.
perform bdc_field using 'RK23F-EKOSTL'
itab2-rcostctr.
perform bdc_field using 'RK23F-EAUFNR'
itab2-rintorder.
perform bdc_dynpro using 'SAPLK23F1' '1200'.
perform bdc_field using 'BDC_OKCODE'
'=POST'.
perform bdc_field using 'COHEADER-SEND_REC_REL'
'10SAP'.
perform bdc_field using 'RK23F-STATUS'
'S'.
perform bdc_field using 'COHEADER-BLDAT'
itab-docdate.
l_ddate.
perform bdc_field using 'COHEADER-BUDAT'
itab-postdate.
l_pdate.
perform bdc_field using 'COHEADER-PERIO'
'9'.
l_monat.
perform bdc_field using 'COHEADER-BLTXT'
itab-doctext.
p_doctxt.
perform bdc_field using 'BDC_CURSOR'
'RK23F-KSTAR'.
perform bdc_field using 'RK23F-WAERS'
'USD'.
CALL TRANSACTION 'KB15N' USING BDCDATA MODE DIS_MODE MESSAGES INTO MESSTAB.
If sy-subrc = 0.
s_rec = s_rec + 1.
ELSE.
u_rec = u_rec + 1.
move ITAB2-NUM to messtab1-msgv1.
concatenate itab2-costele ' | ' itab2-scostctr ' | ' itab2-rcostctr ' | ' itab2-rintorder into messtab1-msgv2.
condense messtab1-msgv2.
condense messtab1-msgv1.
append messtab1.
endif.
clear:itab2.
endloop.
ENDFORM. " Process_Data
BDC_DYNPRO *
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM. "BDC_DYNPRO
BDC_FIELD *
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL <> ''. "NODATA.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM. "BDC_FIELD
*& Form display_data
text
--> p1 text
<-- p2 text
FORM display_data .
skip 2.
write:/15 text-002.
skip 2.
write:/8 text-003.
SKIP.
write:/12 text-008,
25 P_DOCDAT.
SKIP.
write:/12 text-009,
25 P_POSTDA.
SKIP.
write:/12 text-012,
25 P_DOCTXT.
SKIP.
write:/12 text-004,
25 p_file.
skip 2.
write:/8 text-005,
60 t_lin.
skip.
write:/8 text-006,
60 s_rec.
skip.
write:/8 text-007,
60 u_rec.
skip.
write:/10 'row no',
20 'Information'.
skip.
loop at messtab1.
write:/10 messtab1-msgv1,
20 messtab1-msgv2.
clear:messtab1.
endloop.
ENDFORM. " display_data
*& Form validate_data
text
--> p1 text
<-- p2 text
FORM validate_data .
data: l_tabix1 type sy-tabix.
data: l_tabix2 type sy-tabix.
if not itab[] is initial.
select kostl from CSKS into table it_csks.
if sy-subrc eq 0.
sort it_csks by kostl.
endif.
select kstar from CSKA into table it_cska.
if sy-subrc eq 0.
sort it_cska by kstar.
endif.
loop at itab.
l_tabix1 = sy-tabix.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = itab-scostctr
IMPORTING
OUTPUT = itab-scostctr .
read table it_csks into wa_csks with key kostl = itab-scostctr.
if sy-subrc ne 0.
u_rec = u_rec + 1.
L_TABIX2 = l_tabix1 + 1.
move l_tabix2 to messtab1-msgv1.
move l_tabix1 to messtab1-msgv1.
move itab-rintorder to messtab1-msgv2.
concatenate itab-costele ' | ' itab-scostctr ' | ' itab-rcostctr ' | ' itab-rintorder into messtab1-msgv2.
condense messtab1-msgv2.
condense messtab1-msgv1.
append messtab1.
clear:wa_csks.
CLEAR:L_TABIX2.
continue.
endif.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = itab-rcostctr
IMPORTING
OUTPUT = itab-rcostctr .
read table it_csks into wa_csks with key kostl = itab-rcostctr.
if sy-subrc ne 0.
u_rec = u_rec + 1.
L_TABIX2 = l_tabix1 + 1.
move l_tabix2 to messtab1-msgv1.
move l_tabix1 to messtab1-msgv1.
concatenate itab-costele ' | ' itab-scostctr ' | ' itab-rcostctr ' | ' itab-rintorder into messtab1-msgv2.
condense messtab1-msgv2.
condense messtab1-msgv1.
append messtab1.
clear:wa_csks.
CLEAR:L_TABIX2.
continue.
endif.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = itab-costele
IMPORTING
OUTPUT = itab-costele .
read table it_cska into wa_cska with key kstar = itab-costele.
if sy-subrc ne 0.
u_rec = u_rec + 1.
L_TABIX2 = l_tabix1 + 1.
move l_tabix2 to messtab1-msgv1.
move l_tabix1 to messtab1-msgv1.
concatenate itab-costele ' | ' itab-scostctr ' | ' itab-rcostctr ' | ' itab-rintorder into messtab1-msgv2.
condense messtab1-msgv2.
condense messtab1-msgv1.
append messtab1.
clear:wa_csks.
CLEAR:L_TABIX2.
continue.
endif.
move-corresponding itab to itab2.
MOVE l_tabix1 TO ITAB2-NUM.
append itab2.
clear: itab2.
clear:itab.
endloop.
else.
message 'No records in File' type 'S'.
endif.
ENDFORM. " validate_data -
Extra Blank line inserted at the end of the target file
Hi,
This is File to File senario and target files created with a extra blank line at the end of the file.
Below is the source file structure and the content.
<ns0:MT_MOD_FL xmlns:ns0="http://file2file/MES">
<EMPLOYEE>
<ID>12</ID>
<Name>SREENI</Name>
<Designation>M2</Designation>
</EMPLOYEE>
<EMPLOYEE>
<ID>121</ID>
<Name>RAJA</Name>
<Designation>M3</Designation>
</EMPLOYEE>
</ns0:MT_MOD_FL>
Below is the generated target file
12 SREENI M2
121 RAJA M3
Here Generated target file suppose to have only two line instead of 3.
What exactly do i need to change to generate the file with 2 line.
I am not using any mapping as both source and target message structure are same.
IN FCC i used only fieldSeparator, even i have not used endSeparator.
Thanks in Advanace...Hi! Raghu,
Just go through the below Help..documantation
[http://help.sap.com/saphelp_nw04/helpdata/en/0d/5ab43b274a960de10000000a114084/frameset.htm]
NameA.endSeparator
To define an additional string as a separator after the last column in a row, specify it here. The system skips this string when it processes the last column (otherwise the system would treat it as part of the last column).
NameA.fieldSeparator
If you make an entry here, the system expects that the structure contains the specified character string (one or more characters) as a separator between the individual columns.
If you have not made an entry for fieldFixedLengths, this is the only specification to identify the individual columns in a row.
If you made a specification for fieldFixedLengths, the extra length of the separator is taken into account, but no further consistency checks are performed.
Regards::
Amar Srinivas Eli -
Blank line in receiver file adapter content conversion
Hi,
I am using a receiver file adapter. Everything is working fine. Except that a blank line is put by the file adapter between each records. It is a flat file format.
I have used the stting below. How do we remove the blank line?
Recordset : ACCTHDR,BATCHDR,TRANSREC,BATCHTLR,FILETLR
ACCTHDR.fieldFixedLengths 1,7,4,9,8,665
ACCTHDR.absoluteRowWidth 694
ACCTHDR.addHeaderLine 0
Thanks
Sachin KHi,
.endSeparator
The default value is a line break (no explicit separator after the last column; instead the structures are arranged line-by-line).
If you enter a character string here, the system adds it to the last column as a closing character. You can also make this specification in addition to NameA.fieldFixedLengths. To include a line break following the closing character, you must explicitly define it by attaching ´nl´ (including the quotation marks) to the string.
Regards
Agasthuri Doss
Maybe you are looking for
-
Testing ASP pages in DW CS3?
Hello. I need to start learning ASP, so I bought a book on it. I opened up a (very simple) sample ASP page from the accompanying CD ROM in Dreamweaver (CS3). The page opened and was viewable, but when I clicked F12 to preview in a browser, the page d
-
How to set a consistent Framerate
Hi, I'm making a top view racing game and I need to set the framerate to 30fps. I have tried the method in this game: http://homepage.ntlworld.com/pars/pacman/pac.zip Although I am successfully in getting a consistent 30fps, my game stalls for a very
-
Audio in iDVD 06 movie is running slow
I have been using iLife 06 for my last three movies and everything worked fine. Now I created an iDVD from my iMovie (where the sound worked fine) and all the audio in my movie sounds very slow. The audio in the iDVD menu works fine. What to do? G4
-
Where I can download corrupt pdf viewer for me?
I found some broken pdf files doing a raw recovery from Ontrack and receive similar issues when trying to open these files (I tried to match some up based on file size. How to view corrupted pdf? Where I can download corrupt pdfviewer for me?
-
Network Computer Can't See My CUPS Printer
I've installed my printer, and tried to follow the CUPS printer sharing wiki, but I haven't been able to get another computer to list it as a network printer. My printer (a HP LaserJet 1200) installed successfully on my up-to-date Arch Linux system,