To create a new file in application server and transfer data to ti
i am doing the following where i have to create a new file in application server and transfer data to tht file from an internal table.but its saying file cant be opened.the path i am giving to parameter p_prefil is /tmp/prachi.txt.
wats the prob..can anyone help.
DATA:L_WA_FINAL TYPE TY_FINAL,
l_wa_string type string.
OPEN DATASET P_PREFIL FOR OUTPUT IN text mode encoding default.
if sy-subrc <> 0.
write: ' file cannot be opened'.
stop.
endif.
LOOP AT P_I_FINAL INTO L_WA_FINAL.
move l_wa_final to l_wa_string.
TRANSFER l_wa_string TO P_PREFIL.
if sy-subrc <> 0.
write: 'file can not be written'.
stop.
endif.
clear l_wa_final.
ENDLOOP.
CLOSE DATASET P_PREFIL.
if sy-subrc <> 0.
write: ' file cannot be closed'.
stop.
endif.
DATA:L_WA_FINAL TYPE TY_FINAL,
l_wa_string type string.
OPEN DATASET P_PREFIL FOR OUTPUT IN text mode encoding default.
if sy-subrc ne 0.
write: ' file cannot be opened'.
stop.
endif.
LOOP AT P_I_FINAL INTO L_WA_FINAL.
move l_wa_final to l_wa_string.
TRANSFER l_wa_string TO P_PREFIL.
write: 'file can not be written'.
clear l_wa_final.
ENDLOOP.
CLOSE DATASET P_PREFIL.
if sy-subrc ne 0.
write: ' file cannot be closed'.
stop.
endif.
Similar Messages
-
Creating a new file in application server
hai,
please rectify this, how to create a file in application server ?
can any one forward a sample code for creating a file in application server.
hazamHi Hazam,
Please check the below code.
Data : P_UFILE(60) " Unix File name
TYPE C
value '/emn_R3/hr/ben_age25_dep'.
CLEAR GD_SUBRC.
<b>OPEN DATASET</b> GD_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC <> 0.
GD_SUBRC = SY-SUBRC.
gs_error-pernr = gs_0021-pernr.
gs_error-ename = gd_ename.
gs_error-mess
= 'Can not open File:'(017) + gd_file.
append gs_error to gt_error.
clear gs_error.
* CLEAR GD_MSG1.
* CONCATENATE 'Can not open File:'(017)
* GD_FILE
* INTO GD_MSG1.
* WRITE : / GD_MSG1.
ELSE.
LOOP AT GT_BODY INTO GS_BODY.
<b>TRANSFER</b> GS_BODY TO GD_FILE.
ENDLOOP.
<b>CLOSE DATASET</b> GD_FILE.
ENDIF.
Hope this will help you.
Thanks&Regards,
Siri.
Message was edited by: Srilatha T -
What are the commands available to read a file from application server and
What are the commands available to read a file from application server and store the file into an internal table?
Hi,
To read a file from an Application Server to an Object there is a command in ABAP called <b>READ DATASET</b>. After that file is transported to that object you have to do a loop and put that data in an Internal Table.
This statement exports data from the file specified in dset into the data object dobj. For dobj, variables with elementary data types and flat structures can be specified. In Unicode programs, dobj must be character-type if the file was opened as a text file.
For dset, a character-type data object is expected - that is, an object that contains the platform-specific name of the file. The content is read from the file starting from the current file pointer. After the data transfer, the file pointer is positioned after the section that was read. Using the MAXIMUM LENGTH addition, the number of characters or bytes to be read from the file can be limited. Using ACTUAL LENGTH, the number of characters or bytes actually used can be determined.
In a Unicode program, the file must be opened with an arbitrary access type; otherwise, an exception that cannot be handled will be triggered.
If the file has not yet been opened in anon-Unicode program, it will be implicitly opened as a binary file for read access using the statement
OPEN DATASET dset FOR INPUT IN BINARY MODE.
. If a non-existing file is accessed, an exception that can be handled can be triggered.
Influence of Access Type
Files can be read independently of the access type. Whether data can be read or not depends solely on the position of the file pointer. If the latter is at the end of the file or after the file, no data can be read and sy-subrc will be set to 4.
Influence of the Storage Type
The import function will take place irrespective of the storage type in which the file was opened with the statement OPEN DATASET.
If the file was opened as a text file or as a legacy text file, the data is normally read from the current position of the file pointer to the next end-of-line marking, and the file pointer is positioned after the end-of-line marking. If the data object dobj is too short for the number of read characters, the superfluous characters and bytes are cut off. If it is longer, it will be filled with blanks to the right.
If the file was opened as a binary file or as a legacy-binary file, as much data is read that fits into the data object dobj. If the data object dobj is longer than the number of exported characters, it is filled with hexadecimal 0 on the right.
If the specified storage type makes conversion necessary, this is executed before the assignment to the data object dobj. Afterwards, the read data is placed, byte by byte, into the data object.
System Fields
sy-subrc Meaning
0 Data was read without reaching end of file.
4 Data was read and the end of the file was reached or there was an attempt to read after the end of the file.
Thanks,
Samantak.
<b>Rewards points for useful answers.</b> -
Infopackage-Load Many Files from Application Server and later Archive/Move
Hi All..
I have a doubt, I have a requirement of take many files to load into BI 7.0.. I used the infopackage before with option:
Load Binary File From Application server
I load information successfully... only with one file ...but If I can load many files (with different names) like the next list.. I think it's not a good idea modify the file name (path) on infopackage each time).. :
*All of this files will be on one server that itu2019s map into AL11.. Like
Infopfw
BW_LOAD_20090120.txt
BW_LOAD_20090125.txt
BW_LOAD_OTHER_1.txt
u2026.
Etc..
This directory it's not in BW server.. It's other server..but I can load form this location (one file by one)
Could you help me with this questions:
- How can I Use an infopackage with routine that take all the files..one by oneu2026 in order of creation dateu2026and load into Target? Is it possible?.. I have some knowledge of ABAP.. but I don´t know exactly how I can say to system this logicu2026
- In addition is it possible move this files to other locationu2026 like into Infopfwarchive u2026 just to have an history of files loaded.
I saw that in infopackage you have an option to create a routine.. in ABAP codeu2026 Iu2019m a little bit confused because I donu2019t know how I can specify all the path..
I try with:
Infopfw
InfopfwFile.csv
Infopfw
This is the abap code that automatically you see and you need to modifyu2026
Create a routine for file name
This routine will be called by the adapter,
when the infopackage is executed.
p_filename =
p_subrc = 0.
Thank you for your ideas or recommendations.
AlHi Reddy, thank you for your answer
I have some doubuts.. when you explain me the option:
All the above files are appending dates at the end of the file....
You can load the files through infopackage by using Routines and pick the files based on date at the end of the file..***
I need to ask you if you think that when you know the date of the file and the infopackage pick each file... thi can work for many files??... or how it's possible control this process?
About this option, I want to ask you If when you menction Unix code... where it's programed this code?.. in the routine of BW Infopackage??
****Or
Create two folders in your BW in Application server level, in AL11 (ask Basis team)
I call it is F1 and F2 folders.
First dump the files into F1 I assume that the file name in F1 is "BW_LOAD_20090120.txt", using Unix code you rename the file and then keep in the same foleder F1 or move to F2.
Then create InfoPackage and fix the file name (i.e. you renamed), so you don't need to change everyday your file name at infopackage level.Because in AL11 everyday the file are overwrite.
To I get BW_LOAD_20090120.txt file in F1, then I renamed to BW_LOAD.txt and loaded into BW, then tomorrow I get BW_LOAD_20090125.txt in F1, then I renamed to BW_LOAD.txt....
so in this way it will work.You need to schedule the Ubix script in AL11.
This is the way how to handle the application server...I'm using the same logic.
Thank you soo much.
Al -
Reading XML file from application server and put into internal table-4.6C
Dear All,
Is there any way of reading XML file from application server to SAP? I am using 4.6C. Function module SCMS_STRING_TO_XSTRING function module is not available. Please suggest.
Thanks and regards,
AtanuHi Atanu!
Simply use the XSLT transformation 'ID'.
FIELD-SYMBOLS <ls_result> TYPE ANY.
CREATE DATA lref_data TYPE (your_structure).
ASSIGN lref_data->* TO <ls_result>.
CALL TRANSFORMATION id
SOURCE XML xmlstr
RESULT result = <ls_result>.
"xmlstr" contains your XML file. Just read it into it via standard I/O operations. "<ls_result>" will contain your DDIC formatted content.
Best regards
Torsten -
How to Raise alert in XI when a new file reaches application server
Hey guys
i have a requirement in which i need to trigger a piece of ABAP code whenever a new file reaches a specific directory of Application server.
i m using File adapter on receiver side and i want to raise a trigger so that the ABAP code is executed automatically whenever some new file reaches the directory
we are running Win server
thanx
ahmad
Message was edited by:
AhmadHI,
It is possible to write a ABAP program to raise alert.and schedule it , In ABAP program we can check the file is existed or not in a specified folder if existes then we can raise Alert.Actually Alerts are maintained by SAP Alert Management only.
So , but not clear , you said you are using the File receiver adapter .
-- onoption is -this can bepossible with OS command .
-- also we can raise alert from Payload itself , why becz i understand whenever you are going to write a file with file adapter then you need to raise an alert right?
so if message is existed i mean data existed then from raise alert and store the file onoption
-- Also you can try calling an ABAP program as the auto-reaction method of the MTE in CCMS
Regards
Chilla
See the below links
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/434fa590-0201-0010-1e9a-c27e6283a0fe
SMS through SAP ABAP program
XI Alert from BPM with Follow-Up Activity
ABAP programming BAPI To XML
How to send qRFC Alert to Internet Email from AP0 3.1 running 4.6D BASIS
/people/gregor.wolf3/blog/2005/03/05/create-users-in-an-abap-system-with-bapi-ostermiler-java-utilities -
Create an XML File in Application server
Hello,
I have a requirement to create an XML File as Local File and as server File. For the local File it works fine and i got a Local XML File.
My problem is for the Server File.I found a solution in internet to convert in binary.But i don't get in the server File created the XML structure.
Here is My code for the unix server File
DATA ex_tab TYPE TABLE OF x255.
data: wa_tab type x255.
data: lv_line(255) type c.
**-- carica tabella gt_file
PERFORM CARICA_TAB_FILE.
LOOP AT GT_FILE.
MOVE-CORRESPONDING GT_FILE TO WA_SOURCE.
APPEND WA_SOURCE TO GT_SOURCE.
CLEAR WA_SOURCE.
ENDLOOP.
* Perform the XSLT stylesheet
TRY.
CALL TRANSFORMATION ZMESMO052_XML
SOURCE MATERIAL_DATA = GT_SOURCE[]
RESULT XML XML_RESULT .
CATCH CX_ROOT INTO GS_RIF_EX.
GS_VAR_TEXT = GS_RIF_EX->GET_TEXT( ).
MESSAGE GS_VAR_TEXT TYPE 'E'.
ENDTRY.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = XML_RESULT
TABLES
binary_tab = ex_tab.
CONCATENATE P_FILE '.xml' INTO P_FILE.
CONDENSE P_FILE.
TRANSLATE P_FILE TO LOWER CASE.
OPEN DATASET P_FILE FOR OUTPUT IN BINARY MODE.
IF SY-SUBRC NE 0.
MESSAGE E000(ZF) WITH ' Error opening File' P_FILE.
ENDIF.
loop at ex_tab into wa_tab.
move wa_tab to lv_line.
transfer lv_line to p_file.
endloop.
close dataset p_file.
And i Got a file like this
Any solution pleaseI Found the solution,
DATA EX_TAB TYPE TABLE OF X255.
DATA: WA_TAB TYPE X255.
DATA: LV_LINE(255) TYPE C.
DATA: L_CONVIN TYPE REF TO CL_ABAP_CONV_IN_CE.
DATA: L_HTML TYPE STRING.
DATA: L_VALUE TYPE STRING.
DATA: L_MSGSTR TYPE STRING.
DATA: FILENAME TYPE STRING.
**-- carica tabella gt_file
PERFORM CARICA_TAB_FILE.
LOOP AT GT_FILE.
MOVE-CORRESPONDING GT_FILE TO WA_SOURCE.
APPEND WA_SOURCE TO GT_SOURCE.
CLEAR WA_SOURCE.
ENDLOOP.
* Perform the XSLT stylesheet
TRY.
CALL TRANSFORMATION ZMESMO052_XML
SOURCE MATERIAL_DATA = GT_SOURCE[]
RESULT XML XML_RESULT .
CATCH CX_ROOT INTO GS_RIF_EX.
GS_VAR_TEXT = GS_RIF_EX->GET_TEXT( ).
MESSAGE GS_VAR_TEXT TYPE 'E'.
ENDTRY.
TRY.
CALL METHOD CL_ABAP_CONV_IN_CE=>CREATE
EXPORTING
ENCODING = 'UTF-8'
INPUT = XML_RESULT
RECEIVING
CONV = L_CONVIN.
CALL METHOD L_CONVIN->READ
IMPORTING
DATA = L_HTML.
CATCH CX_ROOT.
L_MSGSTR = 'Conversion error'.
ENDTRY.
SEARCH L_HTML FOR '><'.
CLEAR L_VALUE.
L_VALUE = CL_ABAP_CHAR_UTILITIES=>NEWLINE.
CONCATENATE '>' L_VALUE '<' INTO L_VALUE.
IF SY-SUBRC = 0.
REPLACE ALL OCCURRENCES OF '><' IN L_HTML WITH L_VALUE IN
CHARACTER MODE.
ENDIF.
CONCATENATE P_FILE '.xml' INTO P_FILE.
CONDENSE P_FILE.
TRANSLATE P_FILE TO LOWER CASE.
FILENAME = P_FILE.
OPEN DATASET FILENAME FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE
WITH UNIX LINEFEED.
TRANSFER L_HTML TO FILENAME.
CLOSE DATASET FILENAME. -
New Directory in Application server Required for data upload
Hi,
I need to load data in SAP application server. i will use CG3X to load the data.
I need to create a new directory in the application server to load all my flat files. Does any one know how to create a directoty?
Please provide list of steps and transactions used for creating this.
ThnksGo to t-code FILE.
Click on Logical file path definition and hit the New Entries button
Enter your logical path name, say ZXXX
Go back to FILE
In the right window, click on the block on the left to highlight the line you just created.
Now double-click on Assignment of physical paths to logical path
Now click New Entries.
Select your syntax group (this is just your O/S)
Here you can enter your physical path. -
Read the file on application server and Z table as Link in ALV report.
Hi ,
I need some suggession on following requirement.
I need to develop an ALV report where, I have to display 6 column. Four rows are kind of data which i am getting from some tables. But other two column are link to Excel files. So following are the two cases
Case 1: One of these column has a link, and when you select this link , an Excel file gets open and this Excel file is stored in Application server.
Case 2: The other column, will have a link and after selecting the link, an Excel file gets open but this time the Excel file is coming from a Z table( Stored as File name..file type and File content).
Please give some light on these two cases.
Regards
PGHi PG,
If I understood you have to handle some different links.
Well,
you can try to do this:
1- when you fill the fieldcat structure you have to add --> fieldcat-hotspot = 'X', for each column you want to handle like hotspot.
2- manage the method hotspot_click of class cl_event_receiver where you can handle your different excel files.
Let me know,
bye
Alessandro -
Reading file from ftp server and importing data into table
Hi experts,
Well basically i have text files with different layout that have been uploaded on an ftp server. Now i have to write a procedure to fetch those files, read them and insert data in a table... can that be done?
your precious help would be greatly helpful.
Thanksdeclare
file1 UTL_FILE.FILE_TYPE;
filename varchar2(1000) := 'GTECHFILES';
str long;
begin
file1 := UTL_FILE.FOPEN (filename,'agent_dump_csv.rep','r',32767);
loop
UTL_FILE.GET_LINE ( file1, str );
--dbms_output.put_line('Value is :'||to_char(str));
end loop;
UTL_FILE.FCLOSE( file1 );
exception
when no_data_found then
dbms_output.put_line('END OF FILE');
UTL_FILE.FCLOSE( file1 ) ;
when others then
UTL_FILE.FCLOSE( file1 ) ;
dbms_output.put_line('ERROR: '||sqlcode||':'||sqlerrm) ;
end;
i have managed to write this piece of code and all lines are being read and now i need to insert data into my table and the fields are seperated by a `|` i am strill trying to figure how to do that now. help ...
Edited by: Kevin CK on 17-Jan-2010 22:40 -
How to create a new page in SRM5.0 and return data
Hi,Everyone,
I want to create a new page,for example:
when user select a po item,and then we want to create a custom button at po item basic data screen,when user click the custom button,
we want to pop up a new page for our custom logic.at the pop up page,when user complete some data selection, and then the data should return or refresh to po item.
And now,I have a question for that:
How can i return or refresh data(for example,the price) to po item. I have create a bsp page for our pop-up page.
Thanks.
andyHI,Masa,
Thanks for your reply. and it's a very useful ways.and i will consider for that way.
But i think if there have any other way ?
for example: i create a bsp page for our new page,and through the custom button of po basic item page. and that can realize.but how can i return data to the select item.
Thanks.
Regards,
Andy -
Create tab seperated file on application server
Hi all
I need to create a file with Tab separation. I have a solution on a 4.7 system as shown below. But this does not work on a 4.6 system as the class does not exist.
How can I do this on a 4.6 system?
Thank you four your reply.
Herbert
CONSTANTS c_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
LOOP AT t_material.
CONCATENATE
t_material-id
t_material-brand
t_material-desc
t_material-level
t_material-flag
INTO w_line
SEPARATED BY c_tab.
TRANSFER w_line TO w_file2.
ENDLOOP.do this way...
Table to store final data
CONSTANTS: cns_09(2) TYPE n VALUE 09,
c_val1 TYPE c VALUE 'X'.
DATA: g_deli(1) TYPE c.
table to place delimiter
DATA: BEGIN OF it_hex,
tab TYPE x,
END OF it_hex.
ASSIGN g_deli TO <fs> TYPE c_val1.
it_hex-tab = cns_09.
<fs> = it_hex-tab.
LOOP AT t_material.
CONCATENATE
t_material-id
t_material-brand
t_material-desc
t_material-level
t_material-flag
INTO w_line
SEPARATED BY g_deli.
TRANSFER w_line TO w_file2.
ENDLOOP. -
FTP without creating files on Application server
hello everyone,
in an internal table i have around 100 records each of length around 3500 chararters. i want to send this data to the client via ftp in the form of txt file. since the lenght of each record exceeds 1000 bytes, i thought of sending the data directly to the ftp server without creating the file on the application server. is this feasible. please provide the necessary steps to achieve this.Hi,
The FTP involves a lot of complexity but you can do the SCP(secure copy) instead. And what u can do is first create a file on application server and then u can delete it...
the sample code is below..
#!/bin/ksh
scp <filename> <destination>
rm -f <filename> -
Append data into the file in application server
Hi Friends,
I have an issue where i have a job which has three different stepst for same program. If i run the job the program will create a file in the application server and append the other two steps in the same file without overwriting the file or creating a new file.
My problem is like its creating three different files in application server for that particular job since it has three steps . Its not appending into one particular file .
I am using the FM 'Z_INTERFACE_FILE_WRITE' where i have used the pi_append in the exportng parameter . ITs working when i specify the file in local system. It is appending correctly when i run the report normally to apppend into local system.
But when i schedule a job to append the file in application server its creating three different files.
Kindly help me if anyone is aware of this issue
Thanks in advance
KishoreHi,
Please use open dataset to write and append files.Please check the logic of Z FM which you are using .
To open and write into a file use
OPEN DATASET FNAME FOR OUTPUT.
To append data into existing file use
OPEN DATASET FNAME FOR APPENDING.
To write into file:
v_file = file path on application server
OPEN DATASET v_file FOR output.
IF sy-subrc NE 0.
write:/ 'error opening file'.
ELSE.
TRANSFER data TO v_file.
ENDIF.
CLOSE DATASET v_file.
For appending :
OPEN DATASET v_file fOR APPENDING.(file is opened for appending data position is set to the end of the file).
Thanks and Regards,
P.Bharadwaj -
File from application server-- Email ?
Hi,
I need to pickup a file from application server and Email the same to the intended receipents through ABAP program
For that i had used the following code:
REPORT ZEMAIL_APP_SER_FAIL.
DATA :is_doc_chng TYPE sodocchgi1,
it_objtxt TYPE STANDARD TABLE OF solisti1,
is_objtxt TYPE solisti1,
it_objpack TYPE STANDARD TABLE OF sopcklsti1,
is_objpack TYPE sopcklsti1,
it_objbin TYPE STANDARD TABLE OF solisti1,
is_objbin TYPE solisti1,
it_reclist TYPE STANDARD TABLE OF somlreci1,
is_reclist TYPE somlreci1,
w_lines_tx TYPE i.
** Create Message Body
** Title and Description
*is_doc_chng-obj_name = 'MAIL'.
is_doc_chng-obj_descr = 'Auto genareted Mail from Application server'.
** main text
is_objtxt-line = 'This is an automatically generated mail. Please do not reply to it.'(028).
APPEND is_objtxt TO it_objtxt.
is_objtxt-line = space.
APPEND is_objtxt TO it_objtxt.
* write packing list (main)
DESCRIBE TABLE it_objtxt LINES w_lines_tx.
READ TABLE it_objtxt INTO is_objtxt INDEX w_lines_tx.
is_doc_chng-doc_size = ( w_lines_tx - 1 ) * 255 + STRLEN( is_objtxt ).
CLEAR is_objpack-transf_bin.
is_objpack-head_start = 1.
is_objpack-head_num = 0.
is_objpack-body_start = 1.
is_objpack-body_num = w_lines_tx.
is_objpack-doc_type = 'CVS'.
is_objpack-OBJ_NAME = 'GIND_EXP'.
is_objpack-Obj_langu = 'E'.
APPEND is_objpack TO it_objpack.
is_reclist-receiver = 'XXX'@'YYY'.COM'.
is_reclist-rec_type = 'A'.
Break-point.
*is_reclist-REC_ID = 'XXX@YYY'.COM'.
APPEND is_reclist TO it_reclist.
CLEAR is_reclist.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = is_doc_chng
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = it_objpack
contents_txt = it_objtxt
receivers = it_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
when i execute this program:
I get the following error msg:
Activation setting not yet maintained
May i know what is the problem?If you are sending an email, the receiver type should be U (internet mail address type). From your code it appears that you have input it as 'A'. I am not sure if the error message is related to this. Have you checked in transaction SOST, whether an email has been triggered from your program? At what point of execution is this error message triggered?
Maybe you are looking for
-
Hello folks, I have been looking to get an app to produce and work on music when not at home. I already have a sampler/sequencer program (Reason 4) I use on my desktop PC. I would like to take my musicmaking with me. GarageBand seems to be a very pop
-
Illustrator Conversion & Images
I'm trying to transition from InDeisgn to Illustrator. Nothing against ID but id like to pick up on my AI skills a bit. Most of my work requires a lot of imagery from web links. For example i'll get a link with 8 different images from a house. I c
-
How can I delete duplicates in calendar for mac
Is there an easy way to delete duplicates from calendar for Mac
-
How File Path will be decided for downloading Interactive form
Hi, I have error like... java.io.FileNotFoundException: temp\webdynpro\web\local\DynPro6\Components\com.dynpro.DynPro6\PurchaseRequisition.pdf (The system cannot find the path specified) Can any busy suggest how the path will be decided for local and
-
Numbers crashes when I try to open an Excel .xlsx file
I downloaded an Excel file from my brokerage with the .xlsx extension. In the past, I was able to open similar file with Numbers. Now, Numbers crashes whenever I try to open these types of files, even the ones I used with Numbers in the past. Any hel