Search code examples
javaabapsaprfcjco

how to receive table data from abap that sending from java using RFC


I am using RFC function to receive data from sap abap side that sending from java. There is no error from java side . Problem is I cannot capture data from sap side. I need to save those data in a sap ztable.

This is my java code.

public class CreateAttendence extends TimerTask {

    RFCHandler handler;
    DBPool_SF pooler;
    DataSource dataSource;
    DataSource dataSource1;
    int rcount = 0;
    private Object[][] itemData;

    public CreateAttendence() {
        handler = new RFCHandler();
    }

    @Override
    public void run() {
        try {
            getItem();
            sendValuesToSap();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private void getItem() {
        // TODO Auto-generated method stub
        Connection con3 = null;
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Date date = new Date();
        System.out.println(dateFormat.format(date));

        String sbQuery3 = "SELECT * FROM attendance_log ";
        try {
            pooler = DBPool_SF.getInstance();
            dataSource1 = pooler.getDataSource();
        } catch (Exception e1) {
            e1.printStackTrace();
        }

        try {

            con3 = dataSource1.getConnection();
            con3.setAutoCommit(false);

            Statement st = con3.createStatement();
            ResultSet rs = st.executeQuery(sbQuery3);

            int lineitem = 0;

            try {
                rs.last();
                rcount = rs.getRow();
                rs.beforeFirst();
            } catch (Exception ex) {
                ex.printStackTrace();
            }

            itemData = new Object[6][rcount];

            while (rs.next()) {
                itemData[0][lineitem] = rs.getString("device_id");
                itemData[1][lineitem] = rs.getString("user_id");
                itemData[2][lineitem] = rs.getDate("check_in"); // in date
                itemData[3][lineitem] = rs.getDate("check_out"); // out date
                itemData[4][lineitem] = rs.getTime("check_in"); // in time
                itemData[5][lineitem] = rs.getTime("check_out"); // out time
                lineitem = lineitem + 1;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        try {
            con3.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    private void sendValuesToSap() {

        JCO.Table IT_LIST = null;

        try {

            if (rcount > 0) {

                handler.createRFCFunction("ZZSL_ATEND_CRT_LOG_TBL");
                IT_LIST = handler.getTablePara("IT_LIST");

                for (int x = 0; x < rcount; x++) {

                    IT_LIST.appendRow();

                    System.out.print(itemData[1][x] + " ");
                    System.out.print(itemData[2][x] + " ");
                    System.out.print(itemData[3][x] + " ");
                    System.out.print(itemData[4][x] + " ");
                    System.out.print(itemData[5][x] + " ");
                    System.out.println();
                
                    
                    IT_LIST.setValue("110", "MANDT");
                    IT_LIST.setValue(itemData[1][x], "PERNR");
                    IT_LIST.setValue(itemData[2][x], "DATE1");
                    IT_LIST.setValue(itemData[3][x], "DATE2");
                    IT_LIST.setValue(itemData[4][x], "TIN1");
                    IT_LIST.setValue(itemData[5][x], "TOUT1");

                }

                System.out.println(IT_LIST);

                handler.excFunction();
                handler.releaseClient();

            }

        } catch (Exception e) {
            // TODO: handle exception
            handler.releaseClient();
            e.printStackTrace();
        }

        finally {
            rcount = 0;
        }

    }

}

This is my ABAP code.

FUNCTION ZZSL_ATEND_CRT_LOG_TBL.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  TABLES
*"      IT_LIST STRUCTURE  ZSLATENLOG
*"      IT_LIST_T STRUCTURE  ZSLATENLOG
*"----------------------------------------------------------------------

DATA : wa_list LIKE LINE OF IT_LIST,
       wa_list_t LIKE LINE OF IT_LIST.


  INSERT ZSLATENLOG FROM IT_LIST.


ENDFUNCTION.

ZSLATENLOG is my z table.


Solution

  • Well I think you have to provide some more informations to answer this question but I will try it anyway.

    You are using the method createRFCFunction. Why? I would suggest to use this way to get the complete signature of your ABAP Function Module: JCoFunction function = destination.getRepository().getFunction("ZZSL_ATEND_CRT_LOG_TBL"); and eventually function.execute(destination); This way you get the meta information of the function module to call from the connected SAP System

    If this is not working could you please step through the list below and post a response

    1. Which version of JCO are you using?
    2. Is there a file named dev_jco_rfc.trc
      1. Take a look into this. It is very informative and can tell you if the credentials and or connection parameters are wrong
    3. The RFC Call is never triggered in SAP
      1. Is the SAP-System using ACL to restrict RFC Connections? Then you to get the basis adminstration to clear the connection in the whitelist
      2. Have you customized a connection at SM59.
      3. Is it the one you are using with your program?
      4. Have you tried a connection test when your Java program is running
      5. What does transaction SMGW tell you?
    4. The call is triggered in SAP and you can set a debugger on this
      1. What does the debugger say about the content of IT_LIST
      2. What kind of transaction framework are you using?
        1. Classical?
        2. OO?

    I hope this will help you.