Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

run in background

former_member445510
Active Participant
0 Likes
6,984

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

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

54 REPLIES 54
Read only

Former Member
0 Likes
1,034

Hi

I've seen many gui object and/or fm: they can't work in background

Max

Read only

0 Likes
1,034

Thank u,

How can i correct that ?

Read only

0 Likes
1,034

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

Read only

0 Likes
1,034

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

Read only

0 Likes
1,034

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..

Read only

0 Likes
1,034

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

Read only

0 Likes
1,034

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.

Read only

0 Likes
1,034

Which is the class?

Read only

0 Likes
1,034

sorry, i mean object method....

Read only

0 Likes
1,034

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

Read only

0 Likes
1,034

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

Read only

0 Likes
1,034

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 !!!

Read only

0 Likes
1,034

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.

Read only

0 Likes
1,034

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

Read only

0 Likes
1,034

thank u,

example of application server is that?

Read only

0 Likes
1,034

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


Read only

0 Likes
1,034

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


Read only

0 Likes
1,034

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

Read only

0 Likes
1,034

i receive that dump:

Any idea ?

Read only

0 Likes
1,034

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.

Read only

0 Likes
1,034

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,

Read only

0 Likes
1,034

how to define f?

sorry, i don't understand...

Read only

0 Likes
1,034

Can you post the defination of lt_data?

Read only

0 Likes
1,034

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\ ..... ? !!

Read only

0 Likes
1,034

Hi

You need to check OPEN DATASET statament; if the file is not in the path => SY-SUBRC <> 0

Max

Read only

0 Likes
1,034

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.


!!!!

Read only

0 Likes
1,034

HI

READ DATASET retunrs sy-subrc <> 0 if the reading is over or if file is empty

Max

Read only

0 Likes
1,034

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?

Read only

0 Likes
1,034

Hi

Have many Application server are in your system?

Max

Read only

0 Likes
1,034

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 ?

Read only

0 Likes
1,034

But the OPEN DATASET?

No error there?

Max

Read only

0 Likes
1,034

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

Read only

0 Likes
1,034

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 ?

Read only

0 Likes
1,034

Hi

You can use an abap transformation or there are some class to manage xml tag

max

Read only

0 Likes
1,034

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 ?

Read only

0 Likes
1,034

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

Read only

0 Likes
1,034

via SAP (scot), you well get email in your SAP inbox, i want receive email to my outlook inbox...

Read only

0 Likes
1,034

Hi

Read only

0 Likes
1,034