SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

List active SAP users via RFC calls - C program and RemoteFM



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Connect to External system, Unix и Perl
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Sat Nov 17, 2007 7:54 pm    Post subject: List active SAP users via RFC calls - C program and RemoteFM Reply with quote

C program
Code:
 
/*
This C program lists the active sap users of a specified SAP instance
by calling an ABAP function module. The program can be placed to
/sapnmt/SID/exe, and can be used just before stopping the system.
*/

#include
#include
#include
#include "saprfc.h"
#include "sapitab.h"
 
main( void )
{
   static RFC_OPTIONS        rfc_opt;
   static RFC_CONNOPT_R3ONLY rfc_connopt_r3only;
   static RFC_PARAMETER      exporting[1];
   static RFC_PARAMETER      importing[1];
   static RFC_TABLE          tables[1];
   RFC_HANDLE                handle;
   RFC_RC                    rc;
   char *                    exception_ptr;
   ITAB_H                    ltab;
   char                      lst[100];
   char *                    lpt;
   int                       line, lnr, len;
 
   rfc_opt.client   = "055";
   rfc_opt.user     = "TEST";
   rfc_opt.language = "E";
   rfc_opt.password = "INITPASS";
   rfc_opt.trace    = 0;
   rfc_opt.mode     = RFC_MODE_R3ONLY;
   rfc_opt.connopt = &rfc_connopt_r3only;
 
   rfc_connopt_r3only.hostname = "nti68mto";
   rfc_connopt_r3only.sysnr = 9;
 
   ltab    = ItCreate( "BARMI", 100, 0, 0 );
 
   importing[0].name = NULL;
   exporting[0].name = NULL;
   tables[0].name = "A";
   tables[0].nlen = 1;
   tables[0].type = TYPC;
   tables[0].ithandle = ltab;
   tables[0].leng = 100;
 
   handle = RfcOpen( &rfc_opt );
   if( handle == RFC_HANDLE_NULL )
   {
        return 1;
   }
   rc = RfcCallReceive( handle,
                        "Z_TST",
                        exporting,
                        importing,
                        tables,
                        &exception_ptr );
   RfcClose( handle );
   if (rc) return 1;
 
   lnr = ItFill( ltab );
   for ( line=1; line <= lnr; line++)
   {
     lpt = (char *) ItGetLine( ltab, line );
     len = ab_csize( lpt, 100 );
     memcpy( lst, (char *) ItGetLine( ltab, line ), len);
     lst[len] = '\0';
     fprintf( stdout, "%s\n", lst );
   }
   return 0;
}


Server remote function module
Code:

* This function module can be called from a C program to list the
* active users of the system. The structure ZTEST has to be created
* by se11.
*
FUNCTION Z_TST.
*"----------------------------------------------------------------------
*"*"Local interface:
*"       TABLES
*"              A STRUCTURE  ZTEST
*"----------------------------------------------------------------------
DATA: OPCODE TYPE X VALUE 2.
DATA: BEGIN OF USR_TABL OCCURS 10.
          INCLUDE STRUCTURE UINFO.
DATA: END OF USR_TABL.
CALL 'ThUsrInfo' ID 'OPCODE' FIELD OPCODE
    ID 'TAB' FIELD USR_TABL-*SYS*.
A-A = 'CLIENT  USER   LAST_ACCESS_TIME  EXT_SESS INT_SESS'.
APPEND A.
CLEAR A.
  LOOP AT USR_TABL.
    A-A+1(3) = USR_TABL-MANDT.
    A-A+8(12) = USR_TABL-BNAME.
    A-A+21(8) = USR_TABL-ZEIT.
    A-A+37(1) = USR_TABL-EXTMODI.
    A-A+46(1) = USR_TABL-INTMODI.
    APPEND A.
  ENDLOOP.
ENDFUNCTION.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Connect to External system, Unix и Perl All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.