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

Wrapper Class for executing External Commands



 
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: 1639

PostPosted: Fri Sep 07, 2007 11:45 pm    Post subject: Wrapper Class for executing External Commands Reply with quote

Author: Roberto Pagni

Description

This snippet contains a wrapper class to check, execute and get log for any external system command. It embeds FM from function group SXPG in a single class using service methods.
Code:

*---------------------------------------------------------------------*
*       CLASS ZCL_TRIGGER_XCOM  DEFINITION
*---------------------------------------------------------------------*
* Autore: Roberto Pagni
*---------------------------------------------------------------------*
class ZCL_TRIGGER_SYSCOM definition
  public
  create public .
*"* public components of class ZCL_TRIGGER_SYSCOM
*"* do not include other source files here!!!
public section.
  type-pools ABAP .
  constants CL_C_PREFIX type CHAR10 value 'Z_XCOM_'. "#EC NOTEXT
  data MY_NAME type SXPGCOLIST-NAME read-only .
  data MY_PARAMETERS type STRING read-only .
  methods CONSTRUCTOR
    importing
      !APPLICATION type CHAR3 optional
      !MODE type CHAR1 optional
      !HRACCESS_COMPANY type CHAR3 optional
      !PARAMS type STRING
    exceptions
      COMMAND_FAILURE .
  class-methods CLASS_CONSTRUCTOR .
  methods EXECUTE
    returning
      value(EXIT_CODE) type EXTCMDEXEX-EXITCODE .
  methods GET_LOG
    exporting
      !EXP_LOG type STANDARD TABLE .
 *"* protected components of class ZCL_TRIGGER_SYSCOM
*"* do not include other source files here!!!
protected section.
 *"* private components of class ZCL_TRIGGER_SYSCOM
*"* do not include other source files here!!!
private section.
  data:
    my_log TYPE TABLE OF btcxpm .
  events COMMAND_EXECUTED .
  methods GENERATE_XCOM
    importing
      !APPLICATION type CHAR3 optional
      !MODE type CHAR1 optional
      !HRACCESS_COMPANY type CHAR3 optional
      !FULL_COMMAND type SXPGCOLIST-NAME optional
    exporting
      !NAME type SXPGCOLIST-NAME
    exceptions
      PARAMETERS_ERROR .
  methods CHECK
    importing
      !COMMAND_NAME type STRING
    returning
      value(IS_OK) type ABAP_BOOL .
  methods DEQUEUE
    for event COMMAND_EXECUTED of ZCL_TRIGGER_SYSCOM .
METHOD class_constructor.
  CALL FUNCTION 'ENQUEUE_E_SXPGCOM'
    EXCEPTIONS
      foreign_lock   = 1
      system_failure = 2
      OTHERS         = 3.
  IF sy-subrc <> 0. ENDIF.
ENDMETHOD.
METHOD constructor.
  DATA: command_name TYPE sxpgcolist-name.* // Generate XCOM name  TRY. * // This method contains 3 exporting parameters, valid only for actual customer* // Just use command_name parameter to check and execute a single external command    me->generate_xcom( EXPORTING application       = application
                                 mode              = mode
                                 hraccess_company  = hraccess_company
                       IMPORTING name              = command_name ).
  ENDTRY.
  IF command_name IS INITIAL.
    RAISE command_failure.
  ELSE.
    my_name = command_name.
* // Additional Params:
    my_parameters = params.
  ENDIF.
ENDMETHOD.
METHOD execute.
  DATA: lv_command     TYPE sxpgcolist-name,
        lv_params      TYPE sxpgcolist-parameters.
  DATA: lt_log         TYPE TABLE OF btcxpm,
        ls_log         TYPE btcxpm.
  lv_command = me->my_name.
  lv_params  = me->my_parameters.
  CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
    EXPORTING
      commandname                   = lv_command
      additional_parameters         = lv_params
    IMPORTING
      exitcode                      = exit_code
    TABLES
      exec_protocol                 = lt_log
    EXCEPTIONS
      no_permission                 = 1
      command_not_found             = 2
      parameters_too_long           = 3
      security_risk                 = 4
      wrong_check_call_interface    = 5
      program_start_error           = 6
      program_termination_error     = 7
      x_error                       = 8
      parameter_expected            = 9
      too_many_parameters           = 10
      illegal_command               = 11
      wrong_asynchronous_parameters = 12
      cant_enq_tbtco_entry          = 13
      jobcount_generation_error     = 14
      OTHERS                        = 15.
  me->my_log[] = lt_log[].
  IF exit_code EQ 0.
    RAISE EVENT command_executed.
  ENDIF.
ENDMETHOD.
METHOD get_log.
  APPEND LINES OF me->my_log TO exp_log.
ENDMETHOD.
METHOD generate_xcom.
  DATA: lv_help_struc TYPE string.
* // Checks on parameters.
  IF NOT full_command IS SUPPLIED AND NOT application      IS SUPPLIED
                                  AND NOT mode             IS SUPPLIED
                                  AND NOT hraccess_company IS SUPPLIED.
    RAISE parameters_error.
  ENDIF.
* // FIXED PREFIX_APPLICATION+MODE+HRACCESS_COMPANY -> Specific for "Bollato INAIL"
  IF NOT full_command IS SUPPLIED.
    CONCATENATE cl_c_prefix application mode hraccess_company INTO lv_help_struc.
  ELSE.
    lv_help_struc = full_command.
  ENDIF.
* // Check the command created:
  IF me->check( lv_help_struc ) EQ abap_true.
    name = lv_help_struc.
  ELSE.
    CLEAR name.
    RETURN.
  ENDIF.
ENDMETHOD.
METHOD check.
  DATA: lcl_command TYPE sxpgcolist-name.
  lcl_command = command_name.
  CALL FUNCTION 'SXPG_COMMAND_CHECK'
    EXPORTING
      commandname                = lcl_command
    EXCEPTIONS
      no_permission              = 1
      command_not_found          = 2
      parameters_too_long        = 3
      security_risk              = 4
      wrong_check_call_interface = 5
      x_error                    = 6
      too_many_parameters        = 7
      parameter_expected         = 8
      illegal_command            = 9
      communication_failure      = 10
      system_failure             = 11
      OTHERS                     = 12.
  IF sy-subrc EQ 0.    "ok
    is_ok = abap_true.
  ELSE.
    is_ok = abap_false.
  ENDIF.
ENDMETHOD.
METHOD dequeue.
  CALL FUNCTION 'DEQUEUE_E_SXPGCOM'.
ENDMETHOD.
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.