Saturday, October 9, 2010

The final touch (add a htmp page on SAP screen)

It's a known fact that however complex your program is when it come to the user. The look and feel of the output is what matters most. This is blog post is about a simple trick that we can do to make the look and feel better.
Have you ever wondered that when you develop a tool to your customer on a area ( eg: Order Automation tool ). That its better if you can get them a initial screen with some fancy graphics on it where you will be able to give multiple links to different Transactions.
If yes this is one approach that I figured out
Adding a HTML page on SAP

Ok now that I have given a brief idea on what I am talking about. I’ll just walk you through example where a html page is added to initial transaction of a automation tool
Below Is the final output what we are going to get (I have added some SAP images since it is a example case )


 Ok now some basic steps we need to create the above
1)      The html page uploaded to your SAP system (tcode : SMW0)
2)      The images you required to be uploaded in the SAP system )(tcode : SMW0)
Please note that to trigger the event you need something similar to the below part to be added to the html code
<td><a href=SAPEVENT:ZORD_SPLIT ><strong><i>Order Spliti>strong>a>td>

The code to call the relevant transaction is as below
class cl_myevent_handler definition.

  
public section.
    
methods: on_sapevent
               
for event sapevent of cl_gui_html_viewer
                 
importing action frame getdata postdata query_table.

endclass.

data: evt_receiver type ref to cl_myevent_handler.

* CLASS CL_GUI_CFW DEFINITION LOAD.


class cl_myevent_handler implementation.

  
method on_sapevent.
    
case action.
      
WHEN 'ZORD'.
        
CALL TRANSACTION 'ZORD'.
      
WHEN 'ZORD_SPLIT'.
        
CALL TRANSACTION 'ZORD_SPLIT'.
    
endcase.


  
endmethod.
In this test case I have created a container as HTML_CONTROL

if html_control is initial.

    prog_repid = sy-repid.

    
create object my_container
        
exporting
            container_name = 
'HTML_CONTROL'.

    
create object html_control
         
exporting
              parent    = my_container.
    
if sy-subrc ne 0.
*      do nothing.
    
endif.

* register event
    myevent-eventid = html_control->m_id_sapevent.
    myevent-appl_event = 
'x'.
    
append myevent to myevent_tab.
    
call method html_control->set_registered_events
        
exporting
           
events = myevent_tab.

    
create object evt_receiver.

    
set handler evt_receiver->on_sapevent
                
for html_control.

    
perform load_graphics.
    
perform load_home_page.

  
endif.

You can call load graphics and map you html image with your image uploaded to SAP
   call method html_control->load_mime_object
     
exporting
          object_id  = 
'ZSAP_IMG'
          object_url = 
‘image.jpeg’
     
exceptions
          
others     = 1.
The once load call your html page as below
  call method html_control->load_html_document
       
exporting
            document_id  = 
'ZTEST_PAGE_6'
       
importing
            assigned_url = doc_url
       
exceptions
            
others       = 1.

  
if sy-subrc eq 0.
    
call method html_control->show_url
         
exporting
              url = doc_url.
  
endif.
If you call your screen now you should see the html page with all the images and links .
For a abaper this is not a big piece of work but adding something like this will always give you some extra hip

No comments:

Google