F How to execute an external OS Commands in SAP ABAP | CodeTheta

How to execute an external OS Commands in SAP ABAP

September 09, 2023

lv_command is command name which we can configure through tcode - SM69
lv_targetsystem refers to GWD / GWP.

Code :

DATA : lv_command      TYPE sxpglogcmd,
         lv_targetsystem TYPE rfchost_ext.

DATA: lv_status TYPE btcxpgstat,
          lv_txt    TYPE string.

    CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
      EXPORTING
        commandname                   = im_commandname
        operatingsystem               = sy-opsys
        targetsystem                  = im_targetsystem
      IMPORTING
        status                        = lv_status
      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.
    IF sy-subrc <> 0.
      CONCATENATE sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO lv_txt.
      WRITE: lv_txt.
    else.
      write: 'success'.
    ENDIF.

IDE Used To Test This Code : ABAP Editor.
Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us. We will reply you as soon as possible.

Post a Comment