Skip to Content
0
Oct 06, 2020 at 10:07 AM

How retrive Java script variable to SAP abap program.

53 Views

Hello Everyone,

I have wrriten one java script in SAP ABAP program in SE38. Which does the the digital signature. signing happens properly. But here is the problem.I am getting signed base64 response in one of the java script variable called DATA.

I want to populate that variable in ABAP. So that I can store signed base64 in one of the custome SAP table. How can I do that?

Below is the code.

 DATA: datatosign TYPE string,
        value      TYPE string,
        outputpath TYPE string,
        hd_copy    TYPE string,
        lv_vbeln TYPE vbrk-vbeln.

  DATA(test)         = |var connection = new WebSocket ('wss://127.0.0.1:2042');|.
  DATA(log)          = |console.log('Connection Opened');|.
  DATA(ser_con)      = |alert('Please check the server connection: ' + error);|.
  DATA(com_data)     = |alert('completeData length ' + completeData.length);|.
  DATA(non_split)    = |alert('not splitting');|.
  DATA(split)        = |alert('splitting');|.
  DATA(split_len)    = |alert('splitLength ' + splitLength);|.
  DATA(complete)     = |completeData = splitData[0] + 'completed';|.
  DATA(jcomplete)    = |completeData = splitData[j] + 'completed';|.
  DATA(serv_coneror) = |alert('Please check the server connection: ' + error);|.
  DATA(send_more)    = |if(e.data == 'sendmore')|.
  DATA(start_index)  = |startindex=data.indexOf('completed');|.
 

 DATA(formsign)     = |<input type="button" value="FormSign" onClick='setData("signData",document.getElementById("name").value)'>|.
 

 DATA(completedata) = |var completeData = '';|.
  DATA(actualdata)   = |var actualData = '';|.
  DATA(textid)       = |var textId = '';|.

  move ls_temp-vbeln to lv_vbeln.

  hd_copy = 'Original For Buyer'.
  CONCATENATE 'D:/Invoice/' lv_vbeln '_' hd_copy '.pdf' INTO outputpath.

  CONCATENATE 'msg="action=signpdf\ndatatosign=' lv_base64 '\nsignaction=3\noutputpath=' outputpath '\nsigntype=sign\nexpirycheck=true\ncoordinate=425,100,545,160\nissuername=\ncerttype=ALL\ncertclass=0\npageno=All";'
              INTO value.

* JS Source
  CONCATENATE
 '<html>'
 '<script type="text/javascript">'
 'testWebSocket();'
 'function testWebSocket()'
  '{'
    'alert("Connecting WebSocket");'
    test
  'connection.onopen = function () {'
  log
  '};'
  'connection.onerror = function (error)'
  '{'
  ser_con
  'document.getElementById("signData").value=error;'
  '};'
  'connection.onmessage = function (e)'
  '{'
  'if(e.data.indexOf("subProtocol")==-1)'
  'alert(e.data);'

  'setData("signData", "signData");'

  '};'
  completedata
  'var splitData = [];'
  'var i = 0;'
  'var splitLength = 0;'
  'var j = 0;'
  actualdata
  textid
  'var k = 0;'
  'var bufLength = 16300;'       "16300
  'function setData(txf1, msg)'
  '{'
     'alert("in set Fuction");'
       value
  'actualData = msg;'
  'textId = txf1;'
  'completeData = msg;'
*    com_data
  'if(completeData.length < bufLength)'
  '{'
*    non_split
  'splitData[0] = msg;'
  'call(txf1,msg);'
  '}'
  'else'
  '{'
*    split
  'splitLength = completeData.length / bufLength;'
*    split_len
  '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)'
  '{'
  'var data="";'
  'var startindex="";'
  'if(msg.length < bufLength)'
  '{'
  complete
  'connection.send(completeData);'
  '}'
  'else'
  '{'
  'if(j == i-1)'
  '{'
  jcomplete
  '}'
  'else{'
  'completeData = splitData[j];'
  '}'
  'j++;'
  'connection.send(completeData);'
  '}'
  'connection.onerror = function (error)'
  '{'
  serv_coneror
  'document.getElementById("signData").value=error;'
  '};'
  'connection.onmessage = function (e)'
  '{'
  'if(e.data.indexOf("subProtocol")==-1)'
  '{'
  send_more
  '{'
  'call(textId, actualData);'
  '}'
  'else{'
  'data = data + e.data;'
  start_index
  'if(startindex != -1)'
  '{'


   'alert(data)'
  'document.getElementById(txf1).value=data;'
 

 'splitData = [];'
  'i = 0;'
  'splitLength = 0;'
  'j = 0;'
  'k = 0;'
  '}'
  '}'
  '}'
  '};'
  '}'

  '}'
  '</script>'
'</html>' INTO ev_htmlstring SEPARATED BY cl_abap_char_utilities=>cr_lf.