-1

If I log in SAP R/3 and execute the transaction code MM60 then it will show some UI screen for Material list and ask for material number. If I specify a material number and execute then it will show me the output i.e. material list.

Here the story ends if I am a SAP R/3 user.

But what if I want to do the same above steps using java program and get the result in java itself instead of going to SAP R/3? I want to do this basically because I want to use that output data for BI tool.

Suppose I am using JCO3 for connection with R/3.

EDIT Based on the info in the link I tried to do something like below code but it does not schedule any job in background nor it downloads any spool file, etc. I've manually sent a doc to spool and tried giving its ID in the code. This is for MM60.

    JCoContext.begin(destination);
    function = mRepository.getFunction("BAPI_XBP_JOB_OPEN");
    JCoParameterList input = function.getImportParameterList();
    input.setValue("JOBNAME", "jb1");
    input.setValue("EXTERNAL_USER_NAME", "sap*");
    function.execute(destination);
    JCoFunction function2 = mRepository.getFunction("BAPI_XBP_JOB_ADD_ABAP_STEP");
    function2.getImportParameterList().setValue("JOBNAME", "jb1");
    function2.getImportParameterList().setValue("EXTERNAL_USER_NAME", "sap*");
    function2.getImportParameterList().setValue("ABAP_PROGRAM_NAME", "RMMVRZ00");
    function2.getImportParameterList().setValue("ABAP_VARIANT_NAME", "KRUGMANN");
    function2.getImportParameterList().setValue("SAP_USER_NAME", "sap*");
    function2.getImportParameterList().setValue("LANGUAGE", destination.getLanguage());
    function2.execute(destination);

    function3.getImportParameterList().setValue("JOBNAME", "jb1");
    function3.getImportParameterList().setValue("EXTERNAL_USER_NAME", "sap*");
    function3.getImportParameterList().setValue("EXT_PROGRAM_NAME", "RMMVRZ00");
    function3.getImportParameterList().setValue("SAP_USER_NAME", "sap*");
    function3.execute(destination);

    JCoFunction function4 = mRepository.getFunction("BAPI_XBP_JOB_CLOSE");
    function4.getImportParameterList().setValue("JOBNAME", "jb1");
    function4.getImportParameterList().setValue("EXTERNAL_USER_NAME", "sap*");
    function4.execute(destination);

    JCoFunction function5 = mRepository.getFunction("BAPI_XBP_JOB_START_ASAP");
    function5.getImportParameterList().setValue("JOBNAME", "jb1");
    function5.getImportParameterList().setValue("EXTERNAL_USER_NAME", "sap*");
    function5.execute(destination);

    JCoFunction function6 = mRepository.getFunction("RSPO_DOWNLOAD_SPOOLJOB");
    function6.getImportParameterList().setValue("ID", "31801");
    function6.getImportParameterList().setValue("FNAME", "abc");

    function6.execute(destination);
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
ABC
  • 354
  • 2
  • 3
  • 13
  • @downvoters: Can you please explain reasons?? – ABC Dec 15 '17 at 07:15
  • You request is not clear at all, I thin I'm not the only one that doesn't understand what you want to do and the architecture you have in place, we can't help you without more info – Almiriad Dec 15 '17 at 09:04
  • updated..Hope u get it. I am new in sap thing this might be the reason I am not able to ask properly.. – ABC Dec 15 '17 at 10:18

2 Answers2

2

You cannot execute an SAP transaction through JCo. What you can do, is run remote-enabled function modules. So you need to either write a function module of your own, providing exactly the functionality you require, or find an SAP function module, that does what you need (or close enough to be useful).

mwittrock
  • 2,871
  • 1
  • 17
  • 20
  • Thanks for that. I've edited the question so as to add the codes what I've tried based on the help link from SAP. Can you please check it and guide me on how to proceed further? That will b really helpful for newbies lik me.. – ABC Dec 18 '17 at 05:40
  • You need to call BAPI_TRANSACTION_COMMIT as your last step, in order to have your data actually committed to the database. BAPI function modules do no commit work. See SAP note 798535 (https://launchpad.support.sap.com/#/notes/798535) if you want to dig into the details. – mwittrock Dec 19 '17 at 11:46
  • No luck.. I tried committing it but its not working. My code doesn't even schedule a job in the background..Any guesses? I am not able to access the link though says s-user needed.. – ABC Dec 20 '17 at 14:34
1

Your code has the following issues:

  • XBP BAPIs can only be used if you declare their usage via BAPI_XMI_LOGON and BAPI_XMI_LOGOFF. Pass the parameters interface = 'XBP', version = '3.0', extcompany = 'any name you want'.
  • You start the program RMMVRZ00 (which corresponds to the program directly behind the transaction code MM60) with the program variant KRUGMANN which is defined at SAP side with a given material number, but your goal is probably to pass a varying material number, so you should first change the material number in the program variant via BAPI_XBP_VARIANT_CHANGE.
  • After calling BAPI_XBP_JOB_OPEN, you should read the returned value of the JOBCOUNT parameter, and pass it to all subsequent BAPI_XBP_JOB_* calls, along with JOBNAME (I mean, two jobs may be named identically, JOBCOUNT is there to identify the job uniquely).
  • After calling BAPI_XBP_JOB_START_ASAP, you should wait for the job to be finished, by repeatedly calling BAPI_XBP_JOB_STATUS_GET until the job status is A (aborted) or F (finished successfully).
  • You hardcode the spool number generated by the program. To retrieve the spool number, you may call BAPI_XBP_JOB_SPOOLLIST_READ which returns all spool data of the job.
  • Moreover I'm not sure whether you may call the function module RSPO_DOWNLOAD_SPOOLJOB to download the spool data to a file on your java computer. If it doesn't work, you may use the spool data returned by BAPI_XBP_JOB_SPOOLLIST_READ and do whatever you want.

In short, I think that the sequence should be:

  • BAPI_XMI_LOGON
  • BAPI_XBP_VARIANT_CHANGE
  • BAPI_XBP_JOB_OPEN
  • BAPI_XBP_JOB_ADD_ABAP_STEP
  • BAPI_XBP_JOB_CLOSE
  • BAPI_XBP_JOB_START_ASAP
  • Calling repeatedly BAPI_XBP_JOB_STATUS_GET until status is A or F
    • Note that it may take some time if there are many jobs waiting in the SAP queue
  • BAPI_XBP_JOB_SPOOLLIST_READ
  • Eventually RSPO_DOWNLOAD_SPOOLJOB if it works
  • BAPI_XMI_LOGOFF
  • Eventually BAPI_TRANSACTION_COMMIT because XMI writes an XMI log.
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48