2014 Aug 05 2:39 PM
Hello,
This program works good in Foreground, can some one help me to execute it in Background?
I tried via sm37 - sm36 (job wizar) - right button execute in Background, but it doesn't succeed.
It's work perfect in Foreground...
<irrelevant code is removed>
Message was edited by: Suhas Saha
2014 Aug 05 2:48 PM
Hi
I've seen many gui object and/or fm: they can't work in background
Max
2014 Aug 05 2:50 PM
2014 Aug 05 2:55 PM
Hi,
the problem is that not every report is made for run in both modes. you need to identify the "bug" in your programm. if its a sap-programm and there is nothing mentioned in the description i would ask sap for help.
if its your own programm i would write a logfile at important programm steps to check things because you can not debug a programm running in background.
regards
Stefan Seeburger
2014 Aug 05 3:03 PM
How
It depends on you need to do
You need to considere all interactions with the GUI has your pc (Presentation) as reference, this reference can't exist in background (because the program works on server (Application)).
So you need to replace every action with GUI with the corresponding action with Application: for exaple
if you get a file from your PC or network (in generally from Presentation), in background you should pick up the file from Application Server
Max
2014 Aug 05 3:12 PM
the xml file 'FI_Extract_1000_20140804_144444_295.XML' i pick it up from Application server !!!
i have this code in my program...
p_filref = '\\SAPSERVER\f\SAFT\ivat\FI_Extract_1000_20140804_144444_295.XML'.
in AL11, i have directory 'ivat' where i store my xml file..
2014 Aug 05 3:36 PM
It doesn't mean the directory doesn't exist If you can't see a directory by AL11
AL11 shows only the mapped directory, anyway:
\\SAPSERVER\f\SAFT\ivat\.....doesn't seem a right path... Can you see \\SAPSERVER\f\SAFT\?
How do you read the file?
Max
2014 Aug 05 3:40 PM
i renamed the the directory ivat to IVAT.
i read file with the class method import_from_file.
create object gcl_xml.
*Upload XML File
call method gcl_xml->import_from_file
exporting
filename = p_filref
receiving
retcode = gv_subrc.
if gv_subrc = 0.
call method gcl_xml->render_2_xstring
importing
retcode = gv_subrc
stream = gv_xml_string
size = gv_size.
if gv_subrc = 0.
refresh gt_xml_data[].
* Convert XML to internal table
call function 'SMUM_XML_PARSE'
exporting
xml_input = gv_xml_string
tables
xml_table = gt_xml_data
return = gt_return.
endif.
endif.
2014 Aug 05 3:47 PM
2014 Aug 05 3:48 PM
2014 Aug 05 3:53 PM
Hi,
does your programm generate a logfile if the file exists and got up/downloaded correctly?
if yes and everything is correct this wont be the issue.
regards
Stefan Seeburger
2014 Aug 05 4:03 PM
Yes
I've understood that, but I don't know the code of method gcl_xml->import_from_file, so can you give the class of the object gcl_xml?
Is it a local class? If it's so you should post the code of the method
Is it a global class? If it's so you should give the class name
Max
2014 Aug 05 4:08 PM
I do the following steps in my program:
- i make reference to a xml file stored in application server \\SAPSERVER\f\SAFT\IVAT\test.xml
- i make automatically extraction of data with extractor program using the statement Submit stored in directory in application server
- i import the both xml files to internal table
- i compare the both internal tables if they have the same data or not.
-
. if there is difference - > i send Email to my outlook inbox saying 'there is a difference in data'
. if there is NO difference - > i send Email to my outlook inbox saying 'there is NO difference '
But i don't generate the logfile !!!
2014 Aug 05 4:10 PM
this is the code of the method:
method import_from_file .
data: lt_data type swxmlcont,
l_filename type string,
l_size type i.
*
* call function 'WS_UPLOAD'
* EXPORTING
* filename = filename
* filetype = 'BIN'
* IMPORTING
* filelength = l_size
* TABLES
* data_tab = lt_data
* EXCEPTIONS
* CONVERSION_ERROR = 1
* FILE_OPEN_ERROR = c_not_found
* FILE_READ_ERROR = 3
* INVALID_TYPE = 4
* NO_BATCH = 5
* INVALID_TABLE_WIDTH = 6
* GUI_REFUSE_FILETRANSFER = 7
* CUSTOMER_ERROR = 8
* others = 99.
*
l_filename = filename.
call method cl_gui_frontend_services=>gui_upload
exporting
filename = l_filename
filetype = 'BIN'
* HAS_FIELD_SEPARATOR = SPACE
* HEADER_LENGTH = 0
importing
filelength = l_size
* HEADER =
changing
data_tab = lt_data
exceptions
file_open_error = c_not_found
file_read_error = 3
invalid_type = 4
no_batch = 5
gui_refuse_filetransfer = 7
others = 99.
retcode = sy-subrc.
if retcode = 0.
retcode = create_with_table( table = lt_data size = l_size ).
endif.
endmethod.
2014 Aug 05 4:20 PM
Good
the problem is here:
call method cl_gui_frontend_services=>gui_upload
As I said before this method works online only, I can't work in background:
that method find the file in your Presentation Server, not in Application Server
So you need to change your program in order to run in background and read the file from Application, something like this:
method import_from_file .
data: lt_data type swxmlcont,
l_filename type string,
l_size type i.
if p_application = 'X'.
*
* call function 'WS_UPLOAD'
* EXPORTING
* filename = filename
* filetype = 'BIN'
* IMPORTING
* filelength = l_size
* TABLES
* data_tab = lt_data
* EXCEPTIONS
* CONVERSION_ERROR = 1
* FILE_OPEN_ERROR = c_not_found
* FILE_READ_ERROR = 3
* INVALID_TYPE = 4
* NO_BATCH = 5
* INVALID_TABLE_WIDTH = 6
* GUI_REFUSE_FILETRANSFER = 7
* CUSTOMER_ERROR = 8
* others = 99.
*
l_filename = filename.
call method cl_gui_frontend_services=>gui_upload
exporting
filename = l_filename
filetype = 'BIN'
* HAS_FIELD_SEPARATOR = SPACE
* HEADER_LENGTH = 0
importing
filelength = l_size
* HEADER =
changing
data_tab = lt_data
exceptions
file_open_error = c_not_found
file_read_error = 3
invalid_type = 4
no_batch = 5
gui_refuse_filetransfer = 7
others = 99.
retcode = sy-subrc.
if retcode = 0.
retcode = create_with_table( table = lt_data size = l_size).
endif.
else.
opend dataset i_filename <option you need>.
do.
read dataset i_filename into it_data.
if sy-subrc <> 0. exit. endif.
append it_data.
enddo.
endif.
endmethod.
But you need to know where the file is saved in your application
Max
2014 Aug 05 4:30 PM
2014 Aug 05 4:42 PM
i do this code in comment, and i added your code as following:
* create object gcl_xml.
*
**Upload XML File
* call method gcl_xml->import_from_file
* exporting
* filename = p_filref
* receiving
* retcode = gv_subrc.
*
* if gv_subrc = 0.
* call method gcl_xml->render_2_xstring
* importing
* retcode = gv_subrc
* stream = gv_xml_string
* size = gv_size.
* if gv_subrc = 0.
*
* refresh gt_xml_data[].
*
** Convert XML to internal table
* call function 'SMUM_XML_PARSE'
* exporting
* xml_input = gv_xml_string
* tables
* xml_table = gt_xml_data
* return = gt_return.
* endif.
* endif.
DATA lt_data type swxmlcont WITH HEADER LINE.
open dataset p_filref FOR OUTPUT in TEXT MODE ENCODING DEFAULT .
do.
read dataset p_filref into lt_data.
if sy-subrc <> 0. exit. endif.
append lt_data.
enddo.
i get just "Starting tool..." without result
2014 Aug 05 4:44 PM
Yes
You need to do that
Now you're looking a file in your Presentation, so in a directory of your network:
\\SAPSERVER\f\SAFT\IVAT\
so you have to speak about that to your basis, because if SAPSERVER is the server of SAP it belongs to Application too, but perhaps the path can be called in different way
Try to use this fm:
/SAPDMC/LSM_F4_SERVER_FILE
here you can see all Application Server, so you can see also the paths not mapped in AL11
Max
2014 Aug 05 4:46 PM
That's ok
but you make sure the value in p_filref:
Usually the value is different if it's a path from Application or path from presentation
Max
2014 Aug 05 5:01 PM
2014 Aug 05 5:06 PM
when i use:
open dataset p_filref FOR INPUT in BINARY MODE. i receive no dump, but also no data is copy it to lt_data. with the code read dataset p_filref into lt_data.
2014 Aug 05 5:06 PM
Hi
How have you defined F?
It has to be string (char type): you shouldn't have any problem to save your file in a char table, because you're reading a XML file, so ascii file
Max,
2014 Aug 05 5:09 PM
2014 Aug 05 5:17 PM
2014 Aug 05 5:20 PM
i resolved with this code :
DATA: BEGIN OF lt_data OCCURS 0,
data(720),
end of lt_data .
but when i do
do.
read dataset p_filref into lt_data-data.
if sy-subrc <> 0. exit. endif.
append lt_data.
enddo.
i receive sy-subrc = 4 no data !!!
perhaps it doen't retreive the file from directory D:\usr\sap\put\ ..... ? !!
2014 Aug 05 5:30 PM
Hi
You need to check OPEN DATASET statament; if the file is not in the path => SY-SUBRC <> 0
Max
2014 Aug 06 9:10 AM
i deed it in the code below:
do.
read dataset p_filref into lt_data-data.
if sy-subrc <> 0. exit. endif.
append lt_data.
enddo.
!!!!
2014 Aug 06 9:19 AM
HI
READ DATASET retunrs sy-subrc <> 0 if the reading is over or if file is empty
Max
2014 Aug 06 9:56 AM
i must use the FM RZL_READ_DIR_LOCAL to retrieve the file from application server.
but when i got the file, i got "FI_Extract_1000_20140806_103607_000073847800000000" instead 'FI_Extract_1000_20140806_103607_925.XML' !!!
in App Server, i saved the file as following :
any idea?
2014 Aug 06 10:11 AM
2014 Aug 06 1:00 PM
ok, i got the file, but when i execute the code
read dataset filename(direct+filename) into wa.
I receive sy-subrc = 4, and when i double click on the file name in AL11, i receive unable to display this file !!
any idea ?
2014 Aug 06 2:24 PM
2014 Aug 06 2:33 PM
Hi ouail roukbi,
do you have authorisation "write and read" for this directory? normaly the open dataset command returns an error if authorisation is missing as max bianchi is refering.
(if you use the extention "message" you can catch the error)
regards
Stefan Seeburger
2014 Aug 06 2:37 PM
i resolved it with the statement call 'ALERTS', i receive now this data:
how can i convert this format of data to internal table ?
any idea ?
i want to display it as following, if it's possible :
any idea ?
2014 Aug 06 2:47 PM
Hi
You can use an abap transformation or there are some class to manage xml tag
max
2014 Aug 07 11:07 AM
Hi Max,
i can get file data from application server with dataset, but when i want to test this code in background sending email to my outlook inbox, receive no mail.
When i make debugging for this job, i receive well email !!
this is the code for sending email:
create object lr_outlook 'Outlook.Application'.
call method of lr_outlook 'CREATEITEM' = lr_mi
EXPORTING
#1 = 0.
set property of lr_mi 'TO' = '[email protected]'.
set property of lr_mi 'SUBJECT' = 'Compare The Referece File With The Extraction File'.
get property of lr_mi 'BODY' = lv_sig.
concatenate ' The Refence File Info ------------------------------------------------------- The Extraction File Info'
cl_abap_char_utilities=>newline cl_abap_char_utilities=>newline into lv_body.
if count is not initial.
concatenate 'There is Difference:' cl_abap_char_utilities=>newline into lv_body.
loop at it_difference.
concatenate lv_body it_difference-value_r ' *** ' it_difference-value_e ' *** ' it_difference-docnr ' *** ' it_difference-year
cl_abap_char_utilities=>newline into lv_body.
endloop.
else.
concatenate 'No Difference, The both content are the same:' cl_abap_char_utilities=>newline into lv_body.
endif.
loop at itab.
concatenate lv_body itab-name1 ' : ' itab-value1 '----------------------' into lv_body.
concatenate lv_body itab-name2 ' : ' itab-value2 cl_abap_char_utilities=>newline into lv_body.
endloop.
concatenate lv_body lv_sig into lv_body.
set property of lr_mi 'Body' = lv_body.
call method of lr_mi 'SEND'.
set property of lr_outlook 'Visible' = 1.
free object lr_outlook.
any suggestion ?
2014 Aug 07 11:26 AM
The problem is alwyas the same
In order to send a mail you're using OLE object to manage Outlook, but this tecnique works on Presentation, so online only.
You need to replace your code with code to send a mail via SAP (scot)
You can find out many samples in scn
Max
2014 Aug 07 12:07 PM
via SAP (scot), you well get email in your SAP inbox, i want receive email to my outlook inbox...
2014 Aug 07 12:55 PM
Hi ouail roukbi,
i already sent alot mails from SAP (via Tcode Scot) to my outlook inbox.
regards
Stefan Seeburger
2014 Aug 07 12:58 PM
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |