Reg: DATASET of fixed length
I want my dataset to consist of 128 byte fixed length records, with spaces padding out the record length to 128 bytes
Can u help me how to code in ABAP programming or IS THERE ANY UNIX command for the same?
Hi sreenivas,
On the unix front , you can try 'awk' and 'sed' for formatting your input/output.
Check man pages for the above mentioned command.
Regards,
Siddhesh
Similar Messages
-
Upload a Fixed Length file in terms of Bytes..
Hi,
Here is my query.
I have a fixed length file that I need to upload into my program from my presentation server.
The file is in a Shift-JIS Format.
The file is a fixed length format. But it is fixed interms of the number of bytes that each column occupies.
Eg. The 1st column takes 8 bytes, the second 15 bytes, so on and so forth. We do not know the no. of characters each column takes... just the numbe of bytes.
This is how I had approached the upload.
I created an internal table with just one field of type XSTRING.
I used GUI_UPLOAD FM with CODEPAGE = `8000`.
But i noticed during debugging that in each record, the moment a SPACE occured in the input file, it would stop reading and go to the next record in the file. Meaning, I loose all the data after the first occurance of SPACE.
Am I missing something here?? Why does the FM truncate after the first SPACE. ??
Do I need to declare the internal table in any other format..??" May be placing a carriage return end of each records
" will solve your problem
class cl_abap_char_utilities definition load.
data : begin of itab,
field1(1) type c,
field2(2) type c,
field3(3) type c,
field4(4) type c,
crlf(2) type c value cl_abap_char_utilities=>cr_lf. "<<<See this line<<<
data : end of itab.
Data : begin of itab1 occurs 0.
Field(20) type c.
Data : end of itab1.
Loop at itab.
Move itab to itab1.
Append itab1.
Endloop.
Open dataset ........
Loop at itab1.
Transfer itab1 TO dataset.
Endloop.
a® -
Greetings,
I'm creating an application that need to create a fixed length file on a UNIX system and need help. I have an internal table(s) which contain structures with fields of different lengths (type c) and so I have a routine that concatenates these fields into a single record to be sent to a file using the open dataset. This process is squeezing out all my spaces and so my fixed length file is lost. Can someone assist in creating a fixed length file from an internal table without using delimiters?
Thanks!" May be placing a carriage return end of each records
" will solve your problem
class cl_abap_char_utilities definition load.
data : begin of itab,
field1(1) type c,
field2(2) type c,
field3(3) type c,
field4(4) type c,
crlf(2) type c value cl_abap_char_utilities=>cr_lf. "<<<See this line<<<
data : end of itab.
Data : begin of itab1 occurs 0.
Field(20) type c.
Data : end of itab1.
Loop at itab.
Move itab to itab1.
Append itab1.
Endloop.
Open dataset ........
Loop at itab1.
Transfer itab1 TO dataset.
Endloop.
a® -
Uploading data into a fixed length file
hello experts,
I got a task to upload data into a fixed length positional file from internal table.So please help me.
regards,
sriram.Hi there. What you basically need to do is set up the path and name for the export file, move your records to an output table, and then transfer the data to the file that you have specified. We usually set up our export programs so that the user can choose to download the file locally or onto the application server. So first we define the following fields on the selection screen:
PARAMETERS: p_file(128) LOWER CASE OBLIGATORY. "File
*path name from system standard
PARAMETERS: p_path LIKE rlgrap-filename MODIF ID fpn. "Path Name
PARAMETERS: p_local AS CHECKBOX. "Local File Flag
Then we use this to set the path to the application server:
INITIALIZATION.
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
logical_filename = 'Z_AO_HR_UP_LOAD'
parameter_1 = space
IMPORTING
emergency_flag = lw_emergency_flag
file_name = p_path
EXCEPTIONS
file_not_found = 1
OTHERS = 2.
AT SELECTION-SCREEN OUTPUT.
make path name display only
LOOP AT SCREEN.
CHECK screen-group1 = 'FPN'.
screen-input = 0. "Output (Display) only
MODIFY SCREEN.
ENDLOOP.
After your START-OF-SELECTION statement, you need to open the file for output:
IF p_local NE ztc_on.
Get Path/file Name using logical filename.
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
logical_filename = 'Z_AO_HR_UP_LOAD'
parameter_1 = p_file
IMPORTING
emergency_flag = lw_emergency_flag
file_name = p_path
EXCEPTIONS
file_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
w_message = 'No Output file - Missing Logical File Z_AO_HR_UP_LOAD'.
WRITE: / w_message.
IF sy-batch = 'X'. "Is this in a job?
NEW-PAGE.
PERFORM end_of_selection.
MESSAGE e000(38) WITH w_message. "This causes the job to cancel
ELSE.
MESSAGE i000(38) WITH w_message.
ENDIF.
w_stop = 'X'.
STOP.
ENDIF.
*Check if output file is already present.
OPEN DATASET p_path FOR INPUT IN TEXT MODE.
IF sy-subrc EQ 0.
CLOSE DATASET p_path.
WRITE: 'Output Data file already present ', p_path.
*Use the following for logging error message
CONCATENATE 'Ouput Data file already present ' p_path INTO
w_message.
IF sy-batch = ztc_on. "Is this in a job?
NEW-PAGE.
PERFORM end_of_selection.
MESSAGE e000(38) WITH w_message. "This causes the job to cancel
ELSE.
MESSAGE i000(38) WITH w_message.
ENDIF.
w_stop = 'X'.
STOP.
ENDIF.
OPEN DATASET p_path FOR OUTPUT IN TEXT MODE.
IF sy-subrc <> 0.
WRITE: 'Unable to open output dataset - ', p_path.
*Use the following for logging error message
CONCATENATE 'Unable to open output dataset - ' p_path INTO
w_message.
IF sy-batch = ztc_on. "Is this in a job?
NEW-PAGE.
PERFORM end_of_selection.
MESSAGE e000(38) WITH w_message. "This causes the job to cancel
ELSE.
MESSAGE i000(38) WITH w_message.
ENDIF.
w_stop = 'X'.
STOP.
ENDIF.
ENDIF.
Next you perform all of the steps to put your data in the internal table. After the end of selection we then transfer the data from the original internal table (which has many separate fields defined) to a second internal table, t_outfile, in which each record has a single field that is the total length of the original itab record:
*Internal table for Output data
DATA : BEGIN OF t_outfile OCCURS 0,
text(1000).
DATA : END OF t_outfile.
Then you can download your file, checking whether it goes to a local drive or the application server:
IF p_local EQ ztc_on.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
filename = p_file
TABLES
data_tab = t_outfile
EXCEPTIONS
file_open_error = 1
file_write_error = 2
invalid_filesize = 3
invalid_table_width = 4
invalid_type = 5
no_batch = 6
unknown_error = 7
gui_refuse_filetransfer = 8
OTHERS = 9.
ELSE.
LOOP AT t_outfile.
TRANSFER t_outfile TO p_path.
ENDLOOP.
ENDIF.
Now close your dataset if it is on the application server:
IF p_local NE ztc_on.
CLOSE DATASET p_path.
ENDIF.
I hope this helps!
- April King -
Program for converting fixed length file to csv
Hello All,
My requirement is to write a program which will read a file of fixed length separator (file where fields are separated by their length) from application server and convert to CSV file (fields separated by comma) .
Please help me with code sample.
regards
SantoshHi Santosh,
SAP_CONVERT_TO_CSV_FORMAT
Hope the above FM helps you.
Very usefull thread
reg:currency and quantity
Have A Nice Day
Chaitanya. -
Export Data To Fixed Length File
Hello,
I have a requirement to export a couple of files that need to be in a fixed length format.
I've tried opening the dataset and writing the records passing the column that the records should appear:
WRITE /, field1, 10 field2, etc...
I've also tried to do it through SAP_CONVERT_TO_CSV_FORMAT and the text version as well.
Is there a predefined function that will allow me to export as fixed length?
Thank you in advanceHi Jeff,
Following is the code to do the same:
DATA: file TYPE string VALUE `flights.dat`,
wa TYPE spfli.
FIELD-SYMBOLS TYPE x.
OPEN DATASET file FOR OUTPUT IN BINARY MODE.
SELECT *
FROM spfli
INTO wa.
ASSIGN wa TO CASTING.
TRANSFER TO file.
* TRANSFER LENGTH 200 to file.
ENDSELECT.
CLOSE DATASET file.
Best regards,
Prashant -
Option to read fixed-length format, EXCEL or ASCII TAB delimited
Hi Experts,
I have a requirement for giving an option to read fixed-length format, EXCEL or ASCII TAB delimited in the selection screen.Kindly help me how can i read the fixed length format?
Thanks,
AnkitaAs far as I could have understood your problem
You have to read the file with
Open dataset 'file path+name' FOR INPUT in text mode encoding default.
and move its contents to string type variable
Transfer to 'file path+name' to v_string.
Now as per your requirements you need to use Offsets to transfer the data into a work area.
For example
wa_task-year= v_string(4).
wa_task-month= v_string+4(2).
Please confirm if this is your requirement. -
Need to download a file which si space delimted and has fixed length char
Hi,
I have a custom report which downloads an output file in text format.I need the contents to be space delimited.My file data contains numbers as well as characters.I ahve pased the parameter WRITE_FIELD_SEPARATOR = ' ' in the FM.Hwoever the space is introduced only oif the column value is a character.If its a number/digit,the columns are not seperated by space.
Now my data appears like that:
0000101310179.28 +0827200808 DHLBSRF VISA AUG 2008US021SW111 RYAN,BICOVNY
I want my data to be like this :
0000101310 179.28 + 0827200808 DHLBSRF VISA AUG 2008 US02 1SW111 RYAN,BICOVNY
DO I need to pass any additinal parametre?Also for fixed length characrets,do i need to pack/unpack data before passing to the FM ?
Thanks.Hi,
try this way.
REPORT ztest_notepad.
DATA: BEGIN OF it_download OCCURS 0,
data TYPE string,
END OF it_download.
DATA: BEGIN OF it_vbrk OCCURS 0,
vbeln TYPE vbrk-vbeln,
fkart TYPE vbrk-fkart,
fktyp TYPE vbrk-fktyp,
netwr TYPE vbrk-netwr,
END OF it_vbrk.
DATA : l_netwr TYPE char21.
"START-OF-SELECTION.
START-OF-SELECTION.
SELECT vbeln
fkart
fktyp
netwr
FROM vbrk
INTO CORRESPONDING FIELDS OF TABLE it_vbrk
UP TO 100 ROWS.
LOOP AT it_vbrk.
l_netwr = it_vbrk-netwr.
CONCATENATE it_vbrk-vbeln
it_vbrk-fkart
it_vbrk-fktyp
l_netwr
INTO it_download-data
SEPARATED BY space.
APPEND it_download.
CLEAR it_download.
ENDLOOP.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'C:\test.txt'
filetype = 'ASC'
TABLES
data_tab = it_download.
Thanks
Venkat.O -
Loading "fixed length" text files in UTF8 with SQL*Loader
Hi!
We have a lot of files, we load with SQL*Loader into our database. All Datafiles have fixed length columns, so we use POSITION(pos1, pos2) in the ctl-file. Till now the files were in WE8ISO8859P1 and everything was fine.
Now the source-system generating the files changes to unicode and the files are in UTF8!
The SQL-Loader docu says "The start and end arguments to the POSITION parameter are interpreted in bytes, even if character-length semantics are in use in a datafile....."
As I see this now, there is no way to say "column A starts at "CHARACTER Position pos1" and ends at "Character Position pos2".
I tested with
load data
CHARACTERSET AL32UTF8
LENGTH SEMANTICS CHARACTER
replace ...
in the .ctl file, but when the first character with more than one byte encoding (for example ü ) is in the file, all positions of that record are mixed up.
Is there a way to load these files in UTF8 without changing the file-definition to a column-seperator?
Thanks for any hints - charlyI have not tested this but you should be able to achieve what you want by using LENGTH SEMANTICS CHARACTER and by specifying field lengths (e.g. CHAR(5)) instead of only their positions. You could still use the POSITION(*+n) syntax to skip any separator columns that contain only spaces or tabs.
If the above does not work, an alternative would be to convert all UTF8 files to UTF16 before loading so that they become fixed-width.
-- Sergiusz -
Import data from a Fixed Length File into Oracle database
Hi,
I would like to import data from a Fixed Length text file into a table using HTML DB application.
As of now, i have a .sql file(that uses external table) to import the data into Oracle tables
I would like to integrate this in my HTML DB application so that the user can directly import the data into the table.
Sample data
XXXYYYYZZZZZ
Data should be read to table that has
Col1 Col2 Col3
XXX YYYY ZZZZZHi,
I would like to import data from a Fixed Length text
file into a table using HTML DB application.AFAIK, fixed length imports are not something you can do directly with the HTML DB tools or available APIs.
As of now, i have a .sql file(that uses external
table) to import the data into Oracle tables
I would like to integrate this in my HTML DB
application so that the user can directly import the
data into the table.Any fixed-length data needs to have a specification associated with it that indicates which character position begins a new column and what each column represents. Some also include what datatype should be used for each of those.
If you really want to do this I would suggest that you create a table that you can store the file spec in. It would probably have columns for field name, start position, length or end position, datatype and any alias/column name you might want to apply. You would then use this table in a PL/SQL procedure (probably a package with the main processing procedure and various supporting procedures/functions) to read the file into memory, apply the file spec to each line and then do inserts into your table.
Obviously, this is just a concept or strategy. Implementing it will depend on your PL/SQL skills and determination. If you want to pursue this strategy I'm sure you can find some jump-starts by doing a search on the PL/SQL forum.
This may not sound like an answer - but the answer is you need to code it to fit your requirements. Hope that helps.
Earl -
Parameters for Ingesting wide fixed-length files?
I created an SSIS process to ingest fixed-length text files into this table.
CREATE TABLE [dbo].[Temp_Source_Fixed](
[Column 0] [text] NULL,
[ID] [int] IDENTITY(1,1) NOT NULL,
CONSTRAINT [Temp_Source_Fixed_ID] PRIMARY KEY CLUSTERED
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
It works fine with most of the files, but one file has almost 26000 characters per row and the process halts with a truncation error.
I suspect that if I change a parameter on the connection manager it will work, since I can manually use
the SSMS wizard to import manually if I specify Text Stream (DT_Text) for the data type of Column 0 versus String (DT_STR).
For the connection manager I have
In the connection string I have Provider=SQLNCLI10.1 and Auto Translate=False.
In Misc parameters, DelayValidation=False.
For the Data Flow Task I have
DefaultBufferSize is 10485760
Any ideas on what I need to change?
Thanks,
Jnana
Jnana SivanandaYou need the column in question defined in SSIS as DT_Text.
You need to either drop the flat file connector and re-do it with this datatype, or access the Advanced Editor input and output column and alter its datatype there
Arthur
MyBlog
Twitter -
Issue with Mapping Spaces for Receiver Flat File Fixed Length
Hi Mapping experts,
my scenario is receiver FILE (fixed length)
so if a validation applied on a target field returns false then I need to pass the spaces having the number of characters defined for that field
example
targetField length = 8
using "IF" function to perform validation, if validation is true THEN = FIELD
if validation is false ELSE = "________" (underscore to represent 8 spaces)
the problem is the validation is of multiple occurences in one queue and if the "true" statement is on the 6th row, I get _________ which is the value of the 1st row (which is correct because rows 1 to 5 are all false therefore having the value of ELSE which is _______ mapped to it)
How can I get the value of the TRUE row regardless of what row it is located?
e.g. IF = input is 5 rows of validation, TRUE is in the 3rd row, i will get the 3rd row value
IF = input is 5 rows of validation, NO TRUE Value, return 8 spaces
right now when i Display Queue values are
iF:in0 iF:in1 iF:in2 iF:out
1111 false [_________] [_________]
2222 false [_________]
3333 true 3333
4444 false [_________]
5555 false [_________]
In above Queue i only get the value of the 1st row which is ________ --> because my target field occurrences definition in Data Type is 0....1
if I change Data Type occurrences to 1...unbounded I get 5 target fields generated --> WRONG because target file is fixed field, so only one occurence of that target field is requiredCan you give me the idea of what validation are you using so that anyone can help you with the UDF straightaway
because you need to have a UDf in place which will iterate the number of times the field occurs and then it will check the entire queue first ,where validation is true and only at the instant it will return the value
if the entire queue is value it will return the 8 underscores
I hope this is what you wanted
regards
ninad -
Can Open Hub create a fixed length file, not CSV?
I've been given a requirement to produce a file that is not a CSV file, but a file of a fixed length where all of the fields are always in the same positions.
For example, a material "batch" number can be of variable length. They want it to always appear on the file in positions 10-20, even if in some cases it is 10 digits and in other cases it is 4 digits. There should be spaces to fill in the remaining digits.
Can the Open Hub BADI be used to do this? It seems like it always wants to compress the data (so to speak) and stick a seperator in there and the BADI is not helping.
Thanks for your help!
Chris OrlandoSimplest: Use LJustify() or RJustify() on your lines of data.
EG:
<cfset FileLine = RJustify (LineOfText, 128)> -
Gui_download issue - trailing spaces getting truncated for fixed length fil
Hi All,
I have a requirement where I need to download an internal table as a fixed length file.
The code is as follows:
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
FILENAME = L_FILE
FILETYPE = 'ASC'
APPEND = 'X'
WRITE_FIELD_SEPARATOR = ' '
HEADER = '00'
TRUNC_TRAILING_BLANKS = ' '
WRITE_LF = ' '
COL_SELECT = ' '
COL_SELECT_MASK = ' '
DAT_MODE = ' '
IMPORTING
FILELENGTH =
TABLES
DATA_TAB = IT_TEXT
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
Each row in the internal table IT_TEXT is 242 chars long.
The FM is truncatinf the trailing blanks on the file. How do I get the FM to not truncate the trailing blanks in each row?
My internal table has multiple rows and the number of rows on the table should be same as the number of rows on the downloaded file.
I tried setting the WRITE_LF parameter to space.
In this case, the trailing spaces are not truncated(which is as per my requirement), BUT all the rows in the internal table appear in a single line on the downloaded file instead of multiple rows.
I also tried setting the TRUNC_TRAILING_BLANKS field to space but that does not work either. Spaces at the end of the row are still truncated.
so the requirement is: the spaces at the end of each row should not be truncated and
each row on the internal table should have a corresponding row on the downloaded file.
(it is a fixed length file)
I also tried using the following code
class cl_abap_char_utilities definition load.
DATA: BEGIN OF IT_TEXT OCCURS 0,
TEXT(242) TYPE C,
cr_lf TYPE c VALUE cl_abap_char_utilities=>cr_lf,
END OF IT_TEXT.
when i compile, i get the following error
The type "CL_ABAP_CHAR_UTILITIES" is unknown.
Im using R/3 4.6C. Could this be a problem?
Please suggest a solution for this problem.
Thanks!
Sandeep
Edited by: sandeep reddy on Jul 25, 2008 7:16 PMHi,
Try this..This worked..Add a dummy character at the end of the internal table...Then pass trunc_trailing_blanks = ' '...
PARAMETERS: p_file TYPE rlgrap-filename
DEFAULT 'c:\test_download.txt'.
DATA: BEGIN OF s_data,
data TYPE char10,
dummy, " Added this.
END OF s_data.
DATA: t_data LIKE TABLE OF s_data.
s_data-data = 'Test'.
APPEND s_data TO t_data.
s_data-data = 'Test2'.
APPEND s_data TO t_data.
s_data-data = 'Test3'.
APPEND s_data TO t_data.
s_data-data = 'Test4'.
APPEND s_data TO t_data.
* Download.
DATA: v_file TYPE string.
v_file = p_file.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = v_file
trunc_trailing_blanks = ' '
TABLES
data_tab = t_data
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.
Thanks
Naren -
XSLT Mapping : XML to Fixed Length File
Hi,
I have to code a XSLT mapping which converts the XML into a Fixed Length File Format. I am getting the output but it has some garbage values (Some extra spaces in front of first record and also extra blank lines before the first record)
I am pasting my xsl sheet :
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="yes" media-type="text/plain"/>
<xsl:template match="Employees">
<xsl:for-each select="Employee">
<xsl:value-of select="Name"/>
<xsl:value-of select="ID"/>
<xsl:value-of select="ADD"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
My input XML file is as follows:
<?xml version="1.0"?>
<p1:Test02 xmlns:p1="http://www.infosys.com/xi/training/hyd/66289">
<Employees>
<Employee>
<Name>Anurag</Name>
<ID>1121</ID>
<ADD>Hyderabad</ADD>
</Employee>
<Employee>
<Name>Divya</Name>
<ID>1122</ID>
<ADD>Hyderabad</ADD>
</Employee>
<Employee>
<Name>Rasmi</Name>
<ID>1123</ID>
<ADD>Bangalore</ADD>
</Employee>
</Employees>
</p1:Test02>
And the output i am receiving is as follows:
Anurag1121Hyderabad
Divya1122Hyderabad
Rasmi1123Bangalore
Please do help.....hi,
>>>>
<xsl:output method="text" indent="yes" media-type="text/plain"/>
you allow the spaces by using indent="yes"
try with indent="no"
Regards,
michal
<a href="/people/michal.krawczyk2/blog/2005/06/28/xipi-faq-frequently-asked-questions"><b>XI / PI FAQ - Frequently Asked Questions</b></a>
Maybe you are looking for
-
Firefox does not close properly making reopening later impossible without rebooting computer.
I live in Texas and my sister lives in Georgia. We are both experiencing problems with closing Firefox. It appears to close properly but when I try to reopen later in the day, my computer tells me that it is still running in the back ground and canno
-
The best practice for creating reports and dashboard
Hello guys I am trying to put together a list of best practice on how to create reports and dashboards using OBIEE presentation service. I know a lot of those dos and donts are just corporate words that don't apply consistantly in real world environm
-
How to validate File Path given for upload
Hi All, I am trying to upload a file using the File Upload Control. I have already bound the data and resource property with the context attributes. Can someone please suggest that what can be done to validate the file path? For eg. if i enter "abcd"
-
How do you get the Warp Stabilizer VFX to work in After Effects CC?
Upon launching the Warp Stabilizer VFX an error message appears: "After Effects error. Couild not launch Adobe Analysis Server. (515) (25 101)" Am running MAC OSX 10.9.2 An error message also appears on launching After Effects CC: "Quicktime is n
-
I'm using the PS CC latest version. I started typeing some copy out for a layout and when I typed a ' photoshop inserted a > so instead of something like "they're" photoshop would substitue "they>re". I had to go into preferences and turn off smartqu