Quellcodes der BSP-Demos ZBSPDemo1 default.htm: <%@page language="abap"%> <!doctype html> <head> <title> Einfacher Test </title> </head> <body> <h1> Willkommen in der BSP-Welt </h1> <%-- Dies ist ein BSP-Kommentar --%> <center> <!-- Statisch = HTML : --> Hallo alle miteinander! <br> <!-- Dynamsch = Skript: --> <% do 5 times. %> <font size = <%=sy-index.%> > Hello World! <br> <% enddo. %> </center> <script language="javascript"> document.write("dies ist clientside JS - ausgeführt durch Browser!"); alert( "Hier lebt clientside JS!" ); </script> <img src="../public/tutorial/scalability.jpg"> Grundsätzlicher Aufbau einer BSP-Seite: HTML + ABAP + JS
ZBSPDemo2 default.htm: <%@ page language="abap" %> <%@ include file="navigation.htm" %> <table> <tr><td> <h3> Einstieg </h3></td></tr> </table> about.htm: <%@page language="abap"%> <%@ include file="navigation.htm" %> <h3> Portal </h3> <br> <h3>unser Motto: Formlos - Fristlos - Zwecklos! </h3> <br> <h4> by BAMOS 2005.</h4> ========== gruss TYPE STRING Grussformel woanders.htm: %@ page language="abap" %> <%@ include file="navigation.htm" %> <table> <tr><td> <h3> Weitere Infos </h3></td></tr> </table> <img src="blackb47.gif" height=200 width=200 border=1> Einfügen Include Aufnahme von MIME- Objekten und CSS Statische Seitennavigation
ZBSPDemo2 navigation.htm: <%@page language="abap" %> <head> <! Einbinden eines SAP-Stylesheets -> <link rel="stylesheet" href="../../sap/public/bc/bsp/styles/sapbsp.css"> <title> Portal </title> </head> <! Verwenden eines SAP-Stylesheet-Elements -> <body class="bsptbvcellstd"> <h2> Hereinmarschiert in die Demo!! </h2> <table cellpadding=1> <tr height=30> <td align="center" width="100"> <a href="default.htm"> Wieder zum um Einstieg </a> </td> <td align="center" width="100"> <a href="woanders.htm"> Weitere banale Infos </a> </td> <td align="center" width="100"> <a href="about.htm"> Ueber uns </a> </td> </tr> </table> <hr>
ZBSPFORMHTML default.htm: <%@page language="abap" %> <head> <title> Einstieg </title> </head> <body> <% data: fm type String. fm = Firma %> <center> <h1> Dateneingabe </h1> Weitergabe von Daten an selbe Seite oder Folgeseite <form method="get"> <input type = "text" name = "Firma" value = <%=Firma.%> > <input type = "SUBMIT" name = "Senden" value = "Get an gleiche Seite!" > <br> Daten auf Server: <%=fm. %> <br> <form action="next.htm" method="post"> <input type = "text" name = "Firma" value = "SAP" > <input type = "SUBMIT" name = "Senden" value = "Post an Folgeseite!" > </center> ========== Firma auto TYPE STRING Testvariable next.htm: <%@page language="abap" %> <head> <title> Folgeseite </title> </head> <body> <% data: fm type String. fm = Firma. %> <center> <h1> Datenausgabe </h1> <br> Daten auf Server: <%=fm. %> <br> <a href="default.htm?firma=ibm"> Wieder zum um Einstieg </a> </center> ========== Firma auto TYPE STRING Testvariable Seitennavigation + Wertübergabe mit klassischer HTML-Form
default.htm: <%@page language="abap"%> <head> <title> Einstieg </title> </head> <body> <center> <h1> Anmeldung </h1> Als Mitarbeiter oder Administrator anmelden: Hallo alle miteinander! <form method = "POST" > <input type = "SUBMIT" name = "OnInputProcessing(opt_1)" value = "Mitarbeiter" > <input type = "SUBMIT" name = "OnInputProcessing(opt_2)" value = "Administrator" > </center> OnInputProcessing: CASE event_id. WHEN 'opt_1'. navigation->goto_page( 'mitarbeiter.htm' ). WHEN 'opt_2'. navigation->next_page( 'start_adm' ). ENDCASE. mitarbeiter.htm: <%@page language="abap"%> <head> <title> Mitarbeiter </title> </head> <body> <center> <h1> Anmeldung für Mitarbeiter </h1> Als Mitarbeiter anmelden:...<br> <a href=default.htm> Hier gehts statisch zurück <a> </center> admin.htm: <%@page language="abap"%> <head> <title> Administratror </title> </head> <body> <center> <h1> Anmeldung für den Administrator</h1> Als Administrator anmelden:... <br> <a href=default.htm> Hier gehts statisch zurück <a> </center> ZBSPDemo3 Aufruf OnInputProcessing und Navigation zur Folgeseite mit navigation- Objekt
ZBSPAUTO default.htm : %@ page language="abap" %> <body > <h2> Willkommen </h2> Sie können ewas eingeben - bleibts erhalten? <img height="130" src="../public/tutorial/book2.jpg "> <img height="130" src="../public/tutorial/book2.jpg "> <img height="130" src="../public/tutorial/book2.jpg "> <form method="post"> Nachname <input type=text name="authorlname" value="<%= authorlname %>" > Vorname <input type=text name="authorfname" value="<%= authorfname %>" > <input type=submit name="oninputprocessing(select)" value="selbstaufruf der Seite"> ==================== authorfname TYPE STRING Autor Vorname authorlname TYPE STRING Autor Nachname OnInitialization : * Nur das Auto-Seitenattribut wurde übertragen * und steht hier und im Layout wieder zur Verfügung data: s1 type string, s2 type string. s1 = authorfname. s2 = authorlname. OnInputProcessing : * Nur auto-seitenattribute kommen an und sind hier mit Werten gefüllt: Weitergabe von Formularwerten an Auto-Seitenattribute der Folge-BS data: alast type string, afirst type string. alast = authorlname. afirst = authorfname. * Aber alle Formfelder abgreifbar auch wenn sie kein gleichnamiges auto-seitenattribut haben: alast = request->get_form_field('authorlname'). afirst = request->get_form_field('authorfname'). case event_id. when 'select'. * Nur bei auto-seitenattributen funktioniert die Übergabe - an OnInitialization + Layout : navigation->set_parameter( 'authorlname' ). navigation->set_parameter( 'authorfname' ). navigation->goto_page( 'default.htm' ). when others. endcase.
ZBSPAUTO2 default.htm : <%@ page language="abap" %> <body > <h2> Willkommen </h2> Sie können ewas eingeben - bleibts erhalten? <form method="post"> Name <input type=text name="customer" value="<%= customer %>" > Stadt <input type=text name="city" value="<%= city %>" > <input type=submit name="oninputprocessing(same_imp)" value="selbstaufruf - Implizit"> <input type=submit name="oninputprocessing(same_exp)" value="selbstaufruf - Explizit"> <input type=submit name="oninputprocessing(next)" value="nächste Seite"> city TYPE STRING Ort customer TYPE STRING Kundenname OnInitialization : * Test der Verfügbarkeit der Seitenattribute data: s1 type string, s2 type string. s1 = customer. s2 = city. OnInputProcessing : * Bei implizitem Selbsraufruf ist explizite Werteübergabe nicht erforderlich * Bei explizitem Selbsraufruf ist explizite Werteübergabe erforderlich customer = request->get_form_field( 'customer' ). city = request->get_form_field( 'city' ). case event_id. when 'same_imp'. * navigation->set_parameter( 'customer' ). * navigation->set_parameter( 'city' ). when 'same_exp'. navigation->set_parameter( 'customer' ). navigation->set_parameter( 'city' ). navigation->goto_page( 'default.htm' ). when 'next'. navigation->set_parameter( 'customer' ). navigation->set_parameter( 'city' ). navigation->goto_page( 'next.htm' ). when others. endcase. Austesten der Weitergabe von Werten bei expliziter und impliziter Navigation
ZBSPAUTO2 next.htm : <%@ page language="abap" %> <body > <h2> Willkommen </h2> Sie können ewas eingeben - bleibts erhalten? <form method="post"> Name <input type=text name="customer" value="<%= customer %>" > Stadt <input type=text name="city" value="<%= city %>" > <input type=submit name="oninputprocessing(back)" value="zurück"> city TYPE STRING Ort customer TYPE STRING Kundenname OnInitialization : * Test der Verfügbarkeit der Seitenattribute data: s1 type string, s2 type string. s1 = customer. s2 = city. OnInputProcessing : customer = request->get_form_field( 'customer' ). city = request->get_form_field( 'city' ). case event_id. when 'back'. navigation->set_parameter( 'customer' ). navigation->set_parameter( 'city' ). navigation->goto_page( 'default.htm' ). when others. endcase.
ZBSPBooks default.htm : <%@ page language="abap" %> <body > <h2> Willkommen im Buchkatalog </h2> Sie können: Liste aller Autoren ausgeben. Liste aller Bücher eines Autors ausgeben. Liste aller Bücher aller Autoren ausgeben - Eingabe von space. <img height="130" src="../public/tutorial/book2.jpg "> <img height="130" src="../public/tutorial/book2.jpg "> <img height="130" src="../public/tutorial/book2.jpg "> Beispiel mit mehreren BSPs und Zugriff auf DB. Zusammenspiel grundsätzlicher BSP-Elemente <form method="post"> Nachname <input type=text name="authorlname" value="" > Vorname <input type=text name="authorfname" value="" > <input type=submit name="oninputprocessing(select)" value="bücher dieses Autors"> <input type=submit name="oninputprocessing(authors)" value="zur Autorenliste"> <script language="javascript" > document.forms(0).elements('authorlname').focus(); </script> OnInputProcessing : case event_id. when 'select'. navigation->set_parameter( 'authorlname' ). navigation->set_parameter( 'authorfname' ). navigation->next_page( 'TORESULTS' ). when 'authors'. navigation->next_page( 'TOAUTHORS' ). when others. endcase.
ZBSPBooks authors.htm : %@ page language="abap" %> <body> <h2> Liste der Autoren </h2> <table border=1> <tr> <td><b> Vorname </b></td> <td><b> Nachanme </b></td> </tr> <% data: wa_author type zbsauthors. loop at authors into wa_author. %> <tr> <td> <%= wa_author-authfname %> </td> <td> <%= wa_author-authlname %> </td> </tr> <% endloop. %> </table> <a href = default.htm> Zum Einstieg </a> ======================= authors TYPE ZAUTHORTAB_TYPE interne Tabelle für Autoren OnInialization : select * from zbsauthors into table authors. sort authors by authlname. delete adjacent duplicates from authors comparing authlname authfname. Types : types: zauthortab_type type standard table of zbsauthors.
ZBSPBooks results.htm : <%@ page language="abap" %> <body> <h2> Ergebnis der Büchersuche </h2> <% if authors is initial.%> <h3> Leider keine Treffer für: <%= authorlname %>, <%= authorfname %>. </h3> <% else. %> <h3> Die Treffer lauten: </h3> <table border=1> <tr> <td> ISBN </td> <td> Title </td> <td> Verlag </td> <td> Erscheinungsjahr </td> </tr> <% data: wa_book type zbsbooks, wa_author type zbsauthors. loop at authors into wa_author. loop at books into wa_book where isbn = wa_author-isbn. %> <tr> <td> <%= wa_book-isbn %> </td> <td> <%= wa_book-title %> </td> <td> <%= wa_book-publisher %> </td> <td> <%= wa_book-publyear %> </td> </tr> <% endloop. endloop. %> </table> <% endif. %> <a href = default.htm> Zum Einstieg </a> ======================= authorfname TYPE STRING Autor Vorname authorlname TYPE STRING Autor Nachname authors TYPE ZAUTHORTAB_TYPE interne Tabelle für Autoren books TYPE ZBOOKTAB_TYPE interne Tabelle für Bücher
ZBSPBooks results.htm : OnInialization : select * from zbsauthors into table authors. if authorlname is initial. authorlname = '*'. endif. if authorfname is initial. authorfname = '*'. endif. delete authors where not authlname cp authorlname or not authfname cp authorfname. select * from zbsbooks into table books. Types : types: zauthortab_type type standard table of zbsauthors. types: zbooktab_type type standard table of zbsbooks.
ZBSPFormular default.htm : <%@page language="abap" %> Zugriff auf verschiedene <head> <title> Einstieg </title> </head> HTML-Eingabeelemente in <body> Eventhandler <center> <h1> Dateneingabe </h1> Eingabe von Benutzerdaten in typische Formularelemente: <br /> <form method="post"> <select name="kategorie"> <option value="buch"> Bücher </option> <option value="cd"> CDs </option> <option value="all"> Alles </option> </select> <select name="jahr"> <% data: counter(4) type n. do 4 times. counter = sy-index + 2005. %> <option value="<%= counter%>"> <%= counter%> </option> <% enddo. %> </select> <input type = "text" name = "Titel" value="etwas" > <br /><br /> <input type = "checkbox" name = "sofort" /> Sofortversand <br /> <input type = "checkbox" name = "geschenk" /> Geschenkverpackung <br /><br /> <input type = "radio" name = "zahlung" value="bar" /> Barzahlung <br /> <input type = "radio" name = "zahlung" value="cc" /> Kreditkarte <br /><br /> <input type = "SUBMIT" name = "OnInputProcessing" value = "Und Weg!" > </center> OnInputProcessing : data: s1 type string, s2 type string, s3 type string, s4 type string, s5 type string. data: y(4) type n. s1 = request->get_form_field( 'Titel' ). s2 = request->get_form_field( 'kategorie' ). y = request->get_form_field( 'jahr' ). s3 = request->get_form_field( 'sofort' ). s4 = request->get_form_field( 'geschenk' ). s5 = request->get_form_field( 'zahlung' ). *... Datenverarbeitung - Fortführung der Transaktion...
ZBSPDBase default.htm : <%@ page language="abap" %> <body > <h2> Flugverbindungen </h2> Gewünschte Fluglinie: Übung: Zugriff auf DB in OnInitialization + Darstellen der Ergebnisse im Layout Typdeklarationen, interne Tabelle und Arbeitsbereich... <form method="post"> Nachname <input type=text name="carrier" value="<%= carrier %>" > <input type=submit name="oninputprocessing(select)" value="verbindungsübersicht"> =============== carrier TYPE STRING Fluglinie OnInputProcessing : case event_id. when 'select'. navigation->set_parameter( 'carrier' ). navigation->next_page( 'TORESULTS' ). when others. endcase. OnInitialization : carrier = 'LH'.
ZBSPDBase results.htm : <%@ page language="abap" %> <body> <h2> Verbindungen </h2> <% if my_flights is initial.%> <h3> Leider keine Treffer für: <%= carrier %>. </h3> <% else. %> <h3> Treffer lauten: </h3> <table border=1> <tr> <td> Verbindung </td> <td> Datum </td> <td> Preis </td> <td> Währung </td> <td> Flugzeugtype </td> <td> Plätze </td> <td> Besetze Plätze </td> </tr> <% data: wa_flights type sflight. loop at my_flights into wa_flights. %> <tr> <td> <%= wa_flights-connid %> </td> <td> <%= wa_flights-fldate %> </td> <td> <%= wa_flights-price %> </td> <td> <%= wa_flights-currency %> </td> <td> <%= wa_flights-planetype %> </td> <td> <%= wa_flights-seatsmax %> </td> <td> <%= wa_flights-seatsocc %> </td> </tr> <% endloop. %> </table> <% endif. %> <form method="post"> <input type=submit name="oninputprocessing(back)" value="zurück"> ================== carrier TYPE STRING Fluglinie my_flights TYPE ZFLIGHT_TYPE interne Tabelle für Verbindungen OnInputProcessing : case event_id. when 'back'. navigation->goto_page( 'default.htm' ). when others. endcase. OnInitialization : select * from sflight into table my_flights where carrid = carrier. Types: types: zflight_type type standard table of sflight.
ZBSPSessionTest default.htm : <%@ page language="abap" %> <body > <h2> Willkommen </h2> In OnInitialization gesetzt : <%= oninitwert %> <% layoutwert = 'Wird im Layout gesetzt!'. %> Im Layout gesetzt: <%= layoutwert %> Und diese Werte werden im Formuar eingegeben: <form method="post"> Name <input type=text name="customer" value="<%= customer %>" > Stadt <input type=text name="city" value="<%= city %>" > <input type=submit name="oninputprocessing(same_imp)" value="selbstaufruf - Implizit"> <input type=submit name="oninputprocessing(same_exp)" value="selbstaufruf - Explizit"> <input type=submit name="oninputprocessing(next)" value="nächste Seite"> city TYPE STRING Ort customer TYPE STRING Kundenname layoutwert TYPE STRING Testvariable2 oninitwert TYPE STRING Testvariable OnInitialization : * Test der Verfügbarkeit der Seitenattribute data: s1 type string, s2 type string. s1 = customer. s2 = city. Stateless und Stateful: Lebensdauer von Seitenattribut- Werten. Übergabe in OnInitialization, Layout, Form - Zugriff in OnInputprocessing oninitwert = 'Mein OnInit-Wert!'. OnInputProcessing : data: dummy1 type string, dummy2 type string. dummy1 = oninitwert. dummy2 = layoutwert. customer = request->get_form_field( 'customer' ). city = request->get_form_field( 'city' ). case event_id. when 'same_imp'. * navigation->set_parameter( 'customer' ). navigation->set_parameter( 'city' ). when 'same_exp'. navigation->set_parameter( 'customer' ). navigation->set_parameter( 'city' ). navigation->goto_page( 'default.htm' ). when 'next'. navigation->set_parameter( 'customer' ). navigation->set_parameter( 'city' ). navigation->goto_page( 'next.htm' ). when others. endcase.
ZBSPSessionTest next.htm : <%@ page language="abap" %> <body > <h2> Willkommen </h2> Etwas eingeben - bleibts erhalten? <form method="post"> Name <input type=text name="customer" value="<%= customer %>" > Stadt <input type=text name="city" value="<%= city %>" > <input type=submit name="oninputprocessing(back)" value="zurück"> ================ city TYPE STRING Ort customer TYPE STRING Kundenname OnInitialization : * Test der Verfügbarkeit der Seitenattribute data: s1 type string, s2 type string. s1 = customer. s2 = city. OnInputProcessing : customer = request->get_form_field( 'customer' ). city = request->get_form_field( 'city' ). case event_id. when 'back'. navigation->set_parameter( 'customer' ). navigation->set_parameter( 'city' ). navigation->goto_page( 'default.htm' ). when others. endcase.
ZBSPSession default.htm : %@ page language="abap" %> <SCRIPT> function findcookie( sname ) { var i = 0; var acookie = document.cookie.split("; "); var outvalue = null; while ((i < acookie.length) && (outvalue == null)) { var thiscookie = acookie[i].split("="); if (thiscookie[0] == sname) { outvalue = unescape(thiscookie[1]); i++; return outvalue; </SCRIPT> <body > <h2> Willkommen </h2> Abfrage von Infos zu Session-ID und Session-Cookie: <form method="post"> <input type=submit name="oninputprocessing(sful)" value="stateful"> <input type=submit name="oninputprocessing(sless)" value="stateless"> <form> Find cookie: <INPUT TYPE="TEXT" NAME="cookiename" VALUE="sap-contextid"> <INPUT TYPE="BUTTON" VALUE="Go" onclick="alert(findcookie(cookiename.value))"> Session-Info via Runtime-Objekt: <%= runtime->session_id %> OnInputProcessing : case event_id. when 'sful'. runtime->keep_context = 1. navigation->goto_page( 'default.htm' ). when 'sless'. runtime->keep_context = 0. navigation->goto_page( 'default.htm' ). when others. endcase. Stateless und Stateful: Auslesen Session-Cookie und runtime-info. Verhalten beim Deaktivieren von Session-Cookies im Browser
ZBSPState1 default.htm : <%@ page language="abap" %> <body > <h2> Willkommen </h2> Durchgang Nummer: <%= counter %> um: <%= page->to_string( value = sy-uzeit format = if_bsp_page~co_format_long ) %> am: <% page->write( value = sy-datum ). %> <form method="post"> <input type=submit name="oninputprocessing(select)" value="hochzählen"> <input type=submit name="oninputprocessing(sful)" value="stateful"> <input type=submit name="oninputprocessing(sless)" value="stateless"> ====================== counter TYPE I Zähler OnInputProcessing : data: test type i. test = counter. case event_id. when 'select'. * counter = counter + 1. when 'sful'. runtime->keep_context = 1. when 'sless'. runtime->keep_context = 0. when others. Stateless und Stateful: Hochzählen eines Seitenattributs. Verhalten beim Deaktivieren von Session-Cookies im Browser endcase. OnInitialization : * Veränderung des Zustands: counter = counter + 1.
ZClientDemo *&-----------------------------------------------------------------* *& Demo für ICM in Client-Rolle: Aufruf einer Website *&-----------------------------------------------------------------* REPORT ZCLIENTDEMO. DATA: myurl TYPE STRING, myclient TYPE REF TO IF_HTTP_CLIENT, rc TYPE I, len TYPE I, offset TYPE I, content TYPE STRING. CONSTANTS: linsz TYPE I VALUE 80. myurl = 'http://www.sap.de'. cl_http_client=>create_by_url( exporting url = myurl importing client = myclient ). myclient->send( ). myclient->receive( ). myclient->response->get_status( importing code = rc ). content = myclient->response->get_cdata( ). myclient->close( ). len = strlen( content ). WHILE offset < len. WRITE: AT /1(linsz) content+offset. ADD linsz TO offset. ENDWHILE. WAS als Client:: Auslesen HTML-Strom einer Webseite
========== default.htm: %@page language="abap"%> <head> <title> Einfacher Test </title> </head> <body> <center> <h1> <%=otr(zbsptest/gruss)%> </h1> <otr> Dies ist ein langer Text, der nur einmal vorkommt. <br> Deshalb wird er als Langtext abgelegt. </otr> </center> <% data: text type string. text = cl_bsp_runtime=>get_otr_text( 'ZBSPTEST/gruss' ). %> Ausgabe: <%= text. %> ZBSPDemo_OTR Ablegen von OTR-Kurzund Langtexten. Mit Doppelklick in die OTR-TAs ============
ZMailDemo *& Versenden von Mails aus WAS mittels SMTP-PlugIn REPORT ZMAILDEMO. DATA: send_request TYPE REF TO cl_bcs. DATA: document TYPE REF TO cl_document_bcs. DATA: mail_itab TYPE soli_tab. DATA: wamail TYPE soli. DATA: textlength TYPE so_obj_len. DATA: sender TYPE REF TO cl_sapuser_bcs. DATA: address TYPE adr6-smtp_addr. DATA: recipient TYPE REF TO if_recipient_bcs. DATA: bcs_exception TYPE REF TO cx_bcs. DATA: message TYPE string. TRY. send_request = cl_bcs=>create_persistent( ). wamail = 'Dies ist nur ein kleiner Test!'. append wamail to mail_itab. textlength = strlen( wamail ). document = cl_document_bcs=>create_document( i_type = 'RAW' i_text = mail_itab i_length = textlength i_subject = 'BSP Nur eine Testmail' ). CALL METHOD send_request->set_document( document ). sender = cl_sapuser_bcs=>create( sy-uname ). CALL METHOD send_request->set_sender EXPORTING i_sender = sender. address = 'neuendorf@ba-mosbach.de'. recipient = cl_cam_address_bcs=>create_internet_address( address ). CALL METHOD send_request->add_recipient EXPORTING i_recipient = recipient i_express = ' ' i_copy = ' ' i_blind_copy = ' '. CALL METHOD send_request->send( ). COMMIT WORK. CATCH cx_bcs INTO bcs_exception. message = bcs_exception->get_text( ). write: message. ENDTRY. write: 'Das wars!'. Versenden von emails, Erzeugen aller Instanzen und Aufruf der relevanten Methoden
========== default.htm: <%@page language="abap" %> <%@extension name="htmlb" prefix="htmlb" %> ZBSPEXT_1 <htmlb:content design="design2003" > <htmlb:page title="tableview Demo" > <htmlb:form> <% DATA: flights type standard table of sflight. Select * from sflight into table flights. %> <htmlb: tableview id = "f1" table = "<%= flights %>" design = "ALTERNATING" filter = "SERVER" sort = "SERVER" headervisible = "TRUE" headertext = "SAP Flight Table" visiblerowcount = "10" /> Verwenden Extension TableView in minimaler Form Ausgabe von Werten der sflight </htmlb:form> </htmlb:page> </htmlb:content> ============
========== default.htm: <%@page language="abap"%> <body > <h2> Willkommen </h2> Eingabe der URL: <form method="post"> URL <input type=text name="myurl" value="http://www.amazon.de" > <input type=submit name="oninputprocessing(select)" value="zur Anzeige!"> ============ OnInputProcessing : case event_id. when 'select'. navigation->set_parameter( 'myurl' ). navigation->goto_page( 'next.htm' ). when others. endcase. ============ next.htm <%@page language="abap"%> <%=content %> ============ OnInitialization : DATA: myclient TYPE REF TO IF_HTTP_CLIENT, rc TYPE I. cl_http_client=>create_by_url( exporting url = myurl importing client = myclient ). myclient->send( ). myclient->receive( ). myclient->response->get_status( importing code = rc ). content = myclient->response->get_cdata( ). myclient->close( ). ============ default.htm: =============== myurl TYPE STRING next.htm: ============== content TYPE STRING myurl TYPE STRING ZBSPCLIENT SAP WAS als HTTP-Client inklusive Anzeige der angeforderten Seite
========== default.htm : ZBSP_AJAX <%@page language="abap"%> <head> <title> Ajax Test </title> <script language="javascript"> var request = null; function createrequest() { try { request = new XMLHttpRequest(); catch (trymicrosoft) { try { request = new ActiveXObject("Msxml2.XMLHTTP"); catch (othermicrosoft) { try { request = new ActiveXObject("Microsoft.XMLHTTP"); catch (failed) { request = null; Ansprechen WAS via AJAX mittels XMLHTTPRequest- Objekt if (request == null) alert("error creating request object!"); function gettime() { createrequest(); var url = "results.htm"; request.open("get", url, true); request.onreadystatechange = updatepage; request.send(null); function updatepage() { if (request.readystate == 4) { var newtime = request.responsetext; var timeel = document.getelementbyid("time"); replacetext(timeel, newtime);
========== default.htm: function replacetext(el, text) { if (el!= null) { cleartext(el); var newnode = document.createtextnode(text); el.appendchild(newnode); ZBSP_AJAX function cleartext(el) { if (el!= null) { if (el.childnodes) { for (var i = 0; i < el.childnodes.length; i++) { var childnode = el.childnodes[i]; el.removechild(childnode); </script> </head> <body> <h1> Zeitanzeige via Ajax </h1> Die aktuelle Zeit - frisch und asynchron vom Server : <h1> <span id="time"> 000000 </span> </h1> <form method="get"> <input value="zeit aktualisieren" type="button" onclick="gettime();" /> ============ results.htm <%@page language="abap"%> <%= sy-uzeit. %> ============