09-17-2022 11:09 AM
I need to read response from my local html file in my sap program. I have seen most of the sample code tries to read URL. If I try those codes it is checking the 'https:' or 'http' in the URL and as I have local file ( file:///C:/Users/COMPANY/Desktop/SIG/Data/test1.html) it is not getting http and showing error. Please help.
Contents of html file is as follows:
<html>
<head>
<SCRIPT type="text/javascript">
function testWebSocket()
{
var connection = new WebSocket('wss://999.9.9.1:2212');
connection.onopen = function () {
console.log('Connection Opened');
};
connection.onerror = function (error)
{
alert('Please check the server connection: ' + error);
document.getElementById("signData").value=error;
};
connection.onmessage = function (e)
{
if(e.data.indexOf("subProtocol")==-1)
{
alert(e.data);
setData("signData", "signData");
}
{}
};
var completeData = '';
var splitData = [];
var i = 0;
var splitLength = 0;
var j = 0;
var actualData = '';
var textId = '';
var k = 0;
var bufLength = 16300;
alert("Begin");
function setData(txf1, msg)
{
alert("in set Fuction");
msg="action=signpdf\ndatatosign=' '\nsignaction=3\noutputpath=\nsigntype=sign\nexpirycheck=true\ncoordinate=425,100,545,160\nissuername=\ncerttype=ALL\ncertclass=0\npageno=All\ncoSign=true";
actualData = msg;
textId = txf1;
completeData = msg;
//alert('completeData length ' + completeData.length);
if(completeData.length < bufLength)
{
//alert('not splitting');
splitData[0] = msg;
call(txf1,msg);
}
else
{
//alert('splitting');
splitLength = completeData.length / bufLength;
//alert('splitLength ' + splitLength);
var t = 0;
var tt = k + bufLength + 1;
for(i = 0; i < splitLength; i++)
{
splitData[i] = completeData.substring(t, tt);
k = k + bufLength;
t = k + 1;
tt = t + bufLength;
}
call(txf1,msg);
}
}
function call(txf1,msg)
{
if(connection==null)
{
alert('Please check the server connection2');
return;
}
var data="";
var startindex="";
if(msg.length < bufLength)
{
completeData = splitData[0] + 'completed';
connection.send(completeData);
}
else
{
if(j == i-1)
{
completeData = splitData[j] + 'completed';
}
else{
completeData = splitData[j];
}
j++;
connection.send(completeData);
}
connection.onerror = function (error)
{
alert('Please check the server connection: ' + error);
document.getElementById("signData").value=error;
};
connection.onmessage = function (e)
{
if(e.data.indexOf("subProtocol")==-1)
{
if(e.data == 'sendmore')
{
call(textId, actualData);
}
else{
data = data + e.data;
startindex=data.indexOf('completed');
if(startindex != -1)
{
// Client can use the signature
alert(data)
//document.getElementById(txf1).value=data;
splitData = [];
i = 0;
splitLength = 0;
j = 0;
actualData = '';
textId = '';
k = 0;
}
}
}
};
}
}
</script>
</head>
<body>
<p>Click the following button to call websocket</p>
<input type = "button" onclick = "testWebSocket()" value = "Sign
">
</body>
</html>
09-20-2022 1:06 AM
Please have a look at how DEMO_HTML_INPUT program from SAP in SE38. It demos how to get data from HTML page into ABAP.
09-18-2022 9:00 AM
What error is it showing? What are you doing to obtain this error? What is your code?
09-19-2022 9:30 AM
Is it an html file on your application server or on cient side?
09-19-2022 10:32 AM
We have created the html file in our presentation server. There is a button in the html file against which there is a java script. We need to capture the the response from the java script after the button is pressed. Please advise.
11-08-2022 2:19 PM
09-20-2022 1:06 AM
Please have a look at how DEMO_HTML_INPUT program from SAP in SE38. It demos how to get data from HTML page into ABAP.
09-21-2022 9:13 AM
From what version is that available? On a 7.31 I have DEMO_HTML_BROWSER only.
09-21-2022 11:50 AM
Not sure of the version in which this was provided. I have attached the source code here:
REPORT demo_html_input.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
PRIVATE SECTION.
CLASS-METHODS handle_sapevent
FOR EVENT sapevent
OF cl_abap_browser
IMPORTING action
query_table.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
DATA error_list TYPE cl_abap_browser=>html_table.
SET HANDLER handle_sapevent.
DATA(html_str) =
`<html>`
&& ` <head>`
&& ` <meta http-equiv="content-type" `
&& ` content="text/html; `
&& ` charset=utf-8">`
&& ` <script language="JavaScript">`
&& ` function sendInput(form) `
&& ` { fname=form.name; `
&& ` document[fname].submit();} `
&& ` function InputKeyDown(form) {`
&& ` if(event.keyCode == 13) {`
&& ` fname=form.name;`
&& ` document[fname].submit();} }`
&& ` </script>`
&& ` </head>`
&& ` <body>`
&& ` <form name="INPUT" accept-charset="utf-8" `
&& ` method="post" action="SAPEVENT:INPUT"> `
&& ` <input type="text" id="in1" name="field1" `
&& ` size=30 maxlength=30 title="" value="aaa" `
&& ` onKeyDown="InputKeyDown(this.form);"><br>`
&& ` <input type="text" id="in2" name="field2" `
&& ` size=30 maxlength=30 title="" value="bbb" `
&& ` onKeyDown="InputKeyDown(this.form);"><br>`
&& ` <input type="text" id="in3" name="field3" `
&& ` size=30 maxlength=30 title="" value="ccc" `
&& ` onKeyDown="InputKeyDown(this.form);"><br><br>`
&& ` <button id="enterButton" type="button" `
&& ` title="Enter" onClick="sendInput(INPUT);" `
&& ` onKeypress="if(event.keycode=13) `
&& ` sendInput(INPUT);">`
&& ` Enter</button>`
&& ` </form>`
&& ` </body>`
&& `</html>`.
cl_abap_browser=>show_html(
EXPORTING
html_string = html_str
title = 'Input Demo'
IMPORTING
html_errors = error_list ).
IF error_list IS NOT INITIAL.
MESSAGE 'Error in HTML' TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
ENDMETHOD.
METHOD handle_sapevent.
DATA(out) = cl_demo_output_stream=>open( ).
SET HANDLER cl_demo_output_html=>handle_output FOR out.
out->write_data( iv_name = 'ACTION' ia_value = action ).
out->write_data( iv_name = 'QUERY_TABLE' ia_value = query_table ).
out->close( ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
09-21-2022 12:00 PM
Thanks, but it cannot be activated because of a missing parameter, I guess this is why it was not supplied in our system.
09-24-2022 1:30 PM
Thanks juwin.thomas2.
I had tried copying the program demo_html_input. But the parameter html_string is of type string and it was unable to capture the entire html file as the length of my file is quite large approx 5000 characters.
Hence I used the parameter html which is an internal table. But it is not working as expected. Can you please provide a sample program where html table is used and it is capturing the output form the html response.
09-24-2022 6:08 PM
String has the capability to take unlimited length. So, 5000 chars shouldn't be any issue. When you say "not working as expected", what do you mean?