Skip to Content
author's profile photo Former Member
Former Member

calling a abap method in a javascript

Hi all,

I've been browsing a bit through this forum, but there has no answer been completely covering my problem...

I would like to call an abap method in the javascript in order to check some values...

This is what I have done:

<script language="JavaScript" defer="defer">

function do_checks(htmlbevent)

{

try

{

var doubles = "<%= controller->check_doubles( )%>";

if(doubles == true){

var Check = confirm("Test??");

if(Check == false){

htmlbevent.cancelSubmit = true;

}

}

}

catch(e)

{

}

}

</script>

The method has the following code:

mehod check_doubles. " returning parameter = rv_double of type flag

rv_double = abap_true.

endmethod.

the button is defined like this...

<htmlb:button

id = "Save"

onClick = "save"

onClientClick = "do_checks(htmlbevent);"

text = "<%= otr(crm_ic_appl/Save) %>"

/>

The funny thing is, that the controller->check_doubles( ). is already processed at load of the page (although there is no on_load used somewhere...

If I leave out the " if(doubles == true){ } ", the javascript reacts as foreseen..., but when I keep the " if(doubles == true){ } ", the javascript doesn't go through the method anymore...

Can anybody help me out here???

Thanks!!

Micha

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Posted on Jan 08, 2007 at 04:28 PM

    Hi,

    You can call them FM inside the javascript something like below...

    <script language="JavaScript">
    function yourFM()
    {
    <%
       DATA: guid TYPE GUID_32.
       CALL FUNCTION 'GUID_CREATE' IMPORTING ev_guid_32 = guid.
    %>
    }
    
    </script>

    <b>To call the class & method:</b>

    <script language="JavaScript">
        function yourFM()
        {
          <% CLASS cl_bsp_login_application DEFINITION LOAD. %>
          var EXIT_URL  = "<%= CL_BSP_LOGIN_APPLICATION=>GET_SESSIONEXIT_URL( page = page ) %>";
         
             }
      </script>

    But i am not clear what do you want to achieve. I didnt understand what you are trying to do with you code. Could you give more detail?

    <i>* Reward each useful answer</i>

    Raja T

    Message was edited by:

    Raja Thangamani

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 08, 2007 at 04:51 PM

    <i>If I leave out the " if(doubles == true){ } ", the javascript reacts as foreseen..., but when I keep the " if(doubles == true){ } ", the javascript doesn't go through the method anymore...</i>

    YOu need to check the return value in "doubles".

    Just add

    alert(doubles);

    and check-out what is the value of doubles and then you can use that value in IF condition. Because the values will be treated different in JavaScript & in ABAP.

    Raja T

    Add a comment
    10|10000 characters needed characters exceeded

    • You're right... unless you make another call using Javascript to the Web Application server. This will keep the current page on, while giving you the opportunity to process some data on the server side, and get a result that you will exploit using Javascript once again.

      <b>I am not saying it is an easy task, though !</b>

      Best regards,

      Guillaume

  • Posted on Jan 09, 2007 at 09:11 AM

    Hi Micha,

    You must understand that the only way to run some ABAP at runtime is to call the Web Application server.

    But, the Javascript works on the client side. In fact, your function <i>do_checks</i> is created when the server gives out the page to the user : that is why you see it running.

    If you want to have ABAP processed at runtime, you have to make a new request to the ABAP server.

    -> this can be done with some AJAX, check the weblogs in SDN about this

    /people/sap.user72/blog/2005/08/15/ajax-and-htmlb--a-sample-bsp-application

    and others...

    To sum it up, if you want to have runtime check then

    1) Do it all in Javascript

    2) Use AJAX to make a request to the WAS and processed the XML returned

    Hope this is clearer!

    Best regards,

    Guillaume

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.