9

I would like to know if anyone knows if it is possible to run a SAP User Compare from c# using ERPConnect 4 from Theobald? If so, how?

I can open a connection to SAP and run functions - just don't know how to do User Compare.

EDIT: It seems like we have to run the report PFCG_TIME_DEPENDENCY.

If anyone knows how to run a report with ERPConnect, or if there exists a functional module in SAP that can run a report, that will also help.

Cameron Castillo
  • 2,712
  • 10
  • 47
  • 77
  • are you sure you want to run PFCG_TIME_DEPENDENCY? That is a report usually used in a background job to reassign user profiles based on validity dates. It is not a report you would run for data collection. The report actually calls another report, RHAUTUPD_NEW with the parameter REORG set. – Dirk Trilsbeek Oct 06 '15 at 10:39
  • Yes, I need to run the User Comparison on demand. PFCG_TIME_DEPENDENCY seems like one method to do it. To date i was not able to find another method. – Cameron Castillo Oct 06 '15 at 10:42
  • afaik you can't run reports remotely. But you can schedule a background job for immediate execution. But you wouldn't get any return value from that report back to your c# client, the SAP system would just schedule the job and execute it as soon as a background process is available. You would just get the information that the background job has been created. – Dirk Trilsbeek Oct 06 '15 at 11:17
  • another, more complex solution would be a custom BAPI implementation. You would create a RFC enabled function module that in turn calls your report immediately. Not sure how you could get any information from the report execution back to the custom BAPI, but if you get anything, you could return that to your c# client. In your c# client, you would just call your custom BAPI. – Dirk Trilsbeek Oct 06 '15 at 11:20
  • Thanks Dirk. Do you know how I can schedule a background job with ERPConnect? – Cameron Castillo Oct 06 '15 at 13:36
  • there are several BAPIs to create and start jobs. The BAPI to create a new job is BAPI_XBP_JOB_OPEN, then there is BAPI_XBP_JOB_ADD_ABAP_STEP to add a single step to the job, there is BAPI_XBP_JOB_START_ASAP to start a job as soon as possible. There are more BAPIs to deal with jobs, e.g. to read job logs, check job status etc. They all seem to be RFC enabled and you should be able to call them from ERPConnect. – Dirk Trilsbeek Oct 06 '15 at 14:05
  • Thanks - this is a good idea. I've tried creating the job with the items you mentioned and using Theobald's Connection.CreateFunction method. No errors, but it's also not creating the job. I will keep on trying. – Cameron Castillo Oct 06 '15 at 14:45
  • I don't know if you may need to call BAPI_TRANSACTION_COMMIT after all other BAPI calls. You would then also have to call BAPI_TRANSACTION_COMMIT in the same session as all other BAPI calls. There are a few threads about BAPI_TRANSACTION_COMMIT here on SF, some BAPIs need it, some don't. – Dirk Trilsbeek Oct 06 '15 at 18:12
  • Thanks Dirk. I've tried a number of things with the BAPI and BAPI Commit calls, but it just does not want to create that job. Will look for some FM's that can help. – Cameron Castillo Oct 07 '15 at 04:50
  • I looked a bit further into this. You first need to log on to XBP using BAPI BAPI_XMI_LOGON, otherwise you will get error message EXM 028 for the BAPI job calls. Then, after calling JOB_OPEN and ADD_ABAP_STEP, you have to call JOB_CLOSE too, before you can schedule the job execution with START_ASAP. After that you apparently need to log off from XBP using BAPI_XMI_LOGOFF. – Dirk Trilsbeek Oct 07 '15 at 06:46
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/91620/discussion-between-cameron-castillo-and-dirk-trilsbeek). – Cameron Castillo Oct 07 '15 at 14:44

1 Answers1

0

I am not exactly sure what your comparison has to include, but I assume, that you want to compare attributes of the users. If that is the case, you could download the users data from the SAP tables. Here is a starting point for what tables you probably need: http://www.tcodesearch.com/sap-tables/detail?id=USR01

USER01 is the user master record, containing all user with it's main attributes. You can find other interesting related user table through the link above.

To read a table using Erpconnect, look at this link: https://my.theobald-software.com/index.php?/Knowledgebase/Article/View/21/23/reading-sap-tables-directly

You need to create an instance of the ReadTable class. Then you add the fields you are interested in using the AddField method (e.g. MANDT and BNAME for the USR01 table). You could but don't have to enter filter criteria using the AddCriteria method. If you do add multiple creteria, be sure to add boolean operators like "and" or "or":

table.AddCriteria("LANGU = 'D'"); 
table.AddCriteria("AND MANDT = '007'"); 

Finally set the table name of the table you want to download and execute the Run-Method. After that you can loop through the results stored in <your RunTable-Instance>.Result.Rows

Sascha

Sascha
  • 1,210
  • 1
  • 17
  • 33
  • Thanks, the 'User Comparison' is the SAP functionality that refreshes the user's rights in SAP's cache. Basically it should run t-code PFUD. I can run other t-codes but just not PFUD. So it's not actually 'comparing' users, but that's the terminology the SAP use. – Cameron Castillo Nov 26 '15 at 11:51