Difference between revisions of "SAP ABAP UNIX"

From SapWiki
Line 1: Line 1:
 
==Ejecutar comando de sistema operativo==
 
==Ejecutar comando de sistema operativo==
(Los comandos se definen en la tran. SM69)
+
(Los comandos se definen en la tran. SM69)
Función SXPG_COMMAND_EXECUTE
+
Función SXPG_COMMAND_EXECUTE
  
ejemplo:
+
ejemplo:
  
  FORM mueve_ficheros USING p_file p_dir p_dire CHANGING p_subrc.
+
<nowiki>FORM mueve_ficheros USING p_file p_dir p_dire CHANGING p_subrc.
+
 
    DATA: BEGIN OF lt_btcxpm OCCURS 0.
+
    DATA: BEGIN OF lt_btcxpm OCCURS 0.
        INCLUDE STRUCTURE btcxpm.
+
        INCLUDE STRUCTURE btcxpm.
    DATA: END OF lt_btcxpm.
+
    DATA: END OF lt_btcxpm.
    DATA: l_para LIKE sxpgcolist-parameters,
+
    DATA: l_para LIKE sxpgcolist-parameters,
          l_aux_dir1(200),
+
          l_aux_dir1(200),
          l_aux_dir2(200),
+
          l_aux_dir2(200),
          l_string TYPE string.
+
          l_string TYPE string.
+
 
    CONCATENATE p_dir  '/' p_file INTO l_aux_dir1.
+
    CONCATENATE p_dir  '/' p_file INTO l_aux_dir1.
    CONCATENATE  p_dire '/' p_file INTO l_aux_dir2.
+
    CONCATENATE  p_dire '/' p_file INTO l_aux_dir2.
    CONCATENATE l_aux_dir1 l_aux_dir2 INTO l_para SEPARATED BY space.
+
    CONCATENATE l_aux_dir1 l_aux_dir2 INTO l_para SEPARATED BY space.
+
 
    IF sy-subrc <> 0.
+
    IF sy-subrc <> 0.
* Implement suitable error handling here
+
* Implement suitable error handling here
    ENDIF.
+
    ENDIF.
+
 
    CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
+
    CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
      EXPORTING
+
      EXPORTING
        commandname                  = 'ZMV'
+
        commandname                  = 'ZMV'
        additional_parameters        = l_para
+
        additional_parameters        = l_para
      TABLES
+
      TABLES
        exec_protocol                = lt_btcxpm
+
        exec_protocol                = lt_btcxpm
      EXCEPTIONS
+
      EXCEPTIONS
        no_permission                = 1
+
        no_permission                = 1
        command_not_found            = 2
+
        command_not_found            = 2
        parameters_too_long          = 3
+
        parameters_too_long          = 3
        security_risk                = 4
+
        security_risk                = 4
        wrong_check_call_interface    = 5
+
        wrong_check_call_interface    = 5
        program_start_error          = 6
+
        program_start_error          = 6
        program_termination_error    = 7
+
        program_termination_error    = 7
        x_error                      = 8
+
        x_error                      = 8
        parameter_expected            = 9
+
        parameter_expected            = 9
        too_many_parameters          = 10
+
        too_many_parameters          = 10
        illegal_command              = 11
+
        illegal_command              = 11
        wrong_asynchronous_parameters = 12
+
        wrong_asynchronous_parameters = 12
        cant_enq_tbtco_entry          = 13
+
        cant_enq_tbtco_entry          = 13
        jobcount_generation_error    = 14
+
        jobcount_generation_error    = 14
        OTHERS                        = 15.
+
        OTHERS                        = 15.
    p_subrc = sy-subrc.
+
    p_subrc = sy-subrc.
+
 
    IF sy-subrc <> 0.
+
    IF sy-subrc <> 0.
      CASE sy-subrc.
+
      CASE sy-subrc.
        WHEN 1.
+
        WHEN 1.
          MESSAGE e010(0t) WITH 'Sin autorizacion para comando OS ZMV' INTO l_string. "#EC NOTEXT
+
          MESSAGE e010(0t) WITH 'Sin autorizacion para comando OS ZMV' INTO l_string. "#EC NOTEXT
        WHEN 2.
+
        WHEN 2.
          MESSAGE e010(0t) WITH 'Comando OS ZMV no existe' INTO l_string. "#EC NOTEXT
+
          MESSAGE e010(0t) WITH 'Comando OS ZMV no existe' INTO l_string. "#EC NOTEXT
        WHEN OTHERS.
+
        WHEN OTHERS.
          MESSAGE e010(0t) WITH 'ZMV errorcode: ' sy-subrc INTO l_string. "#EC NOTEXT
+
          MESSAGE e010(0t) WITH 'ZMV errorcode: ' sy-subrc INTO l_string. "#EC NOTEXT
      ENDCASE.
+
      ENDCASE.
+
 
      WRITE:/ l_string.
+
      WRITE:/ l_string.
    ENDIF.
+
    ENDIF.
  ENDFORM.
+
  ENDFORM.</nowiki>
  
 
==PUT/GET archivos a/desde servidor FTP==
 
==PUT/GET archivos a/desde servidor FTP==

Revision as of 20:50, 4 April 2020

Ejecutar comando de sistema operativo

(Los comandos se definen en la tran. SM69) Función SXPG_COMMAND_EXECUTE

ejemplo:

FORM mueve_ficheros USING p_file p_dir p_dire CHANGING p_subrc.

    DATA: BEGIN OF lt_btcxpm OCCURS 0.
        INCLUDE STRUCTURE btcxpm.
    DATA: END OF lt_btcxpm.
    DATA: l_para LIKE sxpgcolist-parameters,
          l_aux_dir1(200),
          l_aux_dir2(200),
          l_string TYPE string.

    CONCATENATE p_dir   '/' p_file INTO l_aux_dir1.
    CONCATENATE  p_dire '/' p_file INTO l_aux_dir2.
    CONCATENATE l_aux_dir1 l_aux_dir2 INTO l_para SEPARATED BY space.

    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.

    CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
      EXPORTING
        commandname                   = 'ZMV'
        additional_parameters         = l_para
      TABLES
        exec_protocol                 = lt_btcxpm
      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.
    p_subrc = sy-subrc.

    IF sy-subrc <> 0.
      CASE sy-subrc.
        WHEN 1.
          MESSAGE e010(0t) WITH 'Sin autorizacion para comando OS ZMV' INTO l_string. "#EC NOTEXT
        WHEN 2.
          MESSAGE e010(0t) WITH 'Comando OS ZMV no existe' INTO l_string. "#EC NOTEXT
        WHEN OTHERS.
          MESSAGE e010(0t) WITH 'ZMV errorcode: ' sy-subrc INTO l_string. "#EC NOTEXT
      ENDCASE.

      WRITE:/ l_string.
    ENDIF.
  ENDFORM.

PUT/GET archivos a/desde servidor FTP

Funciones: FTP_CONNECT, FTP_COMMAND, FTP_R3_TO_CLIENT, FTP_SERVER_TO_R3
Programa ejemplo: RSFTP003

Unix Varios

Trn. SM69 : Comandos Sistema Operativo

FM. BRAN_DIR_CREATE : crear directorio (ojo con las validaciones internas pero se puede usar de base)

Trn. CG3Z / Reporte RC1TCG3Z : Upload fichero a servidor
Trn. CG3Y / Reporte RC1TCG3Y : Download fichero desde servidor

FM. CACS_FILE_COPY : copiar de servidor a PC y viceversa

Rep. RSBDCOS0 : Ejecutar comando SO (grabado en log sistema y ficheros Trace)