SAP ABAP - POST Data From SAP to Firebase Using Node js



ABAP Program

REPORT ZSAPTOFIREBASE.

DATA IT_DATA TYPE TABLE OF SFLIGHT.
DATA :
  LO_HTTP_CLIENT 
TYPE REF TO IF_HTTP_CLIENT,
  JSON_DATA      
TYPE STRING,
  JSON_POST      
TYPE XSTRING.


START-OF-SELECTION.
  
PERFORM F_POST_DATA.

FORM F_POST_DATA.
  
DATA LV_STATUS TYPE CHAR50.
  
REFRESH IT_DATA.

  
SELECT FROM SFLIGHT INTO TABLE IT_DATA UP TO ROWS.

  JSON_DATA 
/UI2/CL_JSON=>SERIALIZEDATA IT_DATA COMPRESS ABAP_TRUE PRETTY_NAME /UI2/CL_JSON=>PRETTY_MODE-CAMEL_CASE ).

  
CALL METHOD CL_HTTP_CLIENT=>CREATE_BY_URL(
    
EXPORTING
      URL                
'http://10.100.101.28:4000/sap'   "API - URL
    
IMPORTING
      
CLIENT             LO_HTTP_CLIENT
    
EXCEPTIONS
      ARGUMENT_NOT_FOUND 
1
      PLUGIN_NOT_ACTIVE  
2
      INTERNAL_ERROR     
3
      
OTHERS             ).

"  User Authentication.
  
CALL METHOD LO_HTTP_CLIENT->AUTHENTICATE(
    
EXPORTING
      
CLIENT   '400'
      USERNAME 
'USER01'
      PASSWORD 
'123456'
      
LANGUAGE ''
  
).

  
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
    
EXPORTING
      
TEXT   JSON_DATA
    
IMPORTING
      
BUFFER JSON_POST.

  LO_HTTP_CLIENT
->REQUEST->SET_METHOD'POST' ).
  LO_HTTP_CLIENT
->REQUEST->SET_CONTENT_TYPE'application/json' ).
  LO_HTTP_CLIENT
->REQUEST->SET_DATAJSON_POST ).

" Mengirim Request ke API
  LO_HTTP_CLIENT
->SEND(
      
EXCEPTIONS
        HTTP_COMMUNICATION_FAILURE 
1
        HTTP_INVALID_STATE        
).

" Menerima Response dari request
  LO_HTTP_CLIENT
->RECEIVE(
    
EXCEPTIONS
      HTTP_COMMUNICATION_FAILURE 
1
      HTTP_INVALID_STATE        
2
      HTTP_PROCESSING_FAILED    
).

" Cek Response dari request.
  
DATA LV_RESPONSE TYPE STRING.
  LV_RESPONSE 
LO_HTTP_CLIENT->RESPONSE->GET_CDATA( ).

ENDFORM.


__________________________________________________________________________________________ 


Node JS

const express    = require('express');
const bodyParser = require('body-parser');
var firebase     = require("firebase");
const app        = express();

const config = {
    apiKey: "AIzaSyA71hPWUdEqgymNFTHg462yFJ_bWDAkHcA",
    authDomain: "exam-aff8f.firebaseapp.com",
    databaseURL: "https://exam-aff8f.firebaseio.com",
    projectId: "exam-aff8f",
    storageBucket: "",
    messagingSenderId: "133123398372"
  };
firebase.initializeApp(config);

var fdatabase = firebase.database();
var ref = fdatabase.ref("/sap");

app.use(bodyParser.json());
app.listen(4000, () => console.log('Server berjalan di port 4000'));

//Route untuk menangkap data dari SAP
app.post('/sap', (request, response) => {
    let sapdata = request.body;

    ref.set({
        sapdata
    })
    console.log(sapdata);
    response.json('Success');
})


Demo result :


Full source code ABAP & Node JS
 

Comments

Popular posts from this blog

PHP MySql CRUD Dengan Konsep MVC

Laravel - Sistem Informasi Perpustakaan Sederhana Laravel

IT Asset Management Dengan PHP MySQL