Difference between revisions of "SAP ABAP VARIOS"

From SapWiki
 
(26 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
==Ejecutar trn. SE16N sin AUTH - FM SE16N_START==
 
==UUID ver nota 935047 - Creating and using GUIDs (UUIDs)==
 
==UUID ver nota 935047 - Creating and using GUIDs (UUIDs)==
 
  FORM generar_iddocumento_2 CHANGING p_resultado.
 
  FORM generar_iddocumento_2 CHANGING p_resultado.
Line 219: Line 220:
  
 
==Bajar tabla en formato CSV (función hr_cl_if_prvd_generate_file) ==
 
==Bajar tabla en formato CSV (función hr_cl_if_prvd_generate_file) ==
 +
===Ejemplo 1===
 
  <nowiki>FUNCTION hr_cl_if_prvd_generate_file.
 
  <nowiki>FUNCTION hr_cl_if_prvd_generate_file.
 
*"----------------------------------------------------------------------
 
*"----------------------------------------------------------------------
Line 361: Line 363:
 
ENDFUNCTION.</nowiki>
 
ENDFUNCTION.</nowiki>
 
===EJEMPLO 2===
 
===EJEMPLO 2===
P_TABLA    Importing Type ANY TABLE
+
<nowiki>
P_TABLA_CSV Exporting Type ZARCHIVO_CSV_TAB (type table of DXRAW)
+
TYPES: BEGIN OF ty_pernr,
 +
        pernr TYPE p0001-pernr,
 +
        begda type begda,
 +
        dias type i,
 +
        sueldo type p DECIMALS 0,
 +
      END OF ty_pernr.
 +
 
 +
data: lt_pernr type TABLE OF ty_pernr,
 +
      lt_tabla_csv TYPE ppe_cust_table,
 +
      ls_pernr type ty_pernr.
 +
 
 +
ls_pernr-pernr = '00000001'.
 +
ls_pernr-begda = sy-datum.
 +
ls_pernr-sueldo = 620000.
 +
ls_pernr-dias = 30.
 +
 
 +
append ls_pernr to lt_pernr.
 +
 
 +
PERFORM CREAR_CSV USING lt_pernr CHANGING lt_tabla_csv.
 +
* salida: 00000001;03/09/2021;30;620000
  
<nowiki>
+
form CREAR_CSV using p_tabla type ANY TABLE
method CREAR_CSV.
+
                CHANGING P_TABLA_CSV type ppe_cust_table.
 
   CONSTANTS: c_field_separator TYPE c VALUE ';',
 
   CONSTANTS: c_field_separator TYPE c VALUE ';',
 
             c_darl_number(12) TYPE c VALUE '1234567890 '.
 
             c_darl_number(12) TYPE c VALUE '1234567890 '.
Line 372: Line 393:
 
         it_components      TYPE abap_compdescr_tab,
 
         it_components      TYPE abap_compdescr_tab,
 
         wa_components      LIKE LINE OF it_components.
 
         wa_components      LIKE LINE OF it_components.
 
  DATA lt_data TYPE ZARCHIVO_CSV_TAB. "ppe_cust_table.
 
  
 
   DATA: l_struc_index    TYPE syindex,
 
   DATA: l_struc_index    TYPE syindex,
 
         l_len_string      TYPE i,
 
         l_len_string      TYPE i,
         l_max_field      TYPE DXRAW, "CHAR16384, "char1024,
+
         l_max_field      TYPE char1024,
         l_struc_raw_data  TYPE DXRAW, "CHAR16384, "char1024,
+
         l_struc_raw_data  TYPE char1024,
 
         l_start_string    TYPE i,
 
         l_start_string    TYPE i,
 
         l_len_field_sep  TYPE i,
 
         l_len_field_sep  TYPE i,
Line 407: Line 426:
  
 
         CASE wa_components-type_kind .
 
         CASE wa_components-type_kind .
           WHEN 'P'.
+
           WHEN 'P' or 'I'.
             WRITE <fs_field> TO l_date_extern.
+
             WRITE <fs_field> TO l_date_extern NO-GROUPING.
 
             CATCH SYSTEM-EXCEPTIONS conversion_errors  = 4.
 
             CATCH SYSTEM-EXCEPTIONS conversion_errors  = 4.
 
               IF sy-subrc <> '0'.
 
               IF sy-subrc <> '0'.
Line 422: Line 441:
 
             REPLACE FIRST OCCURRENCE OF REGEX '(\d{4})(\d{2})(\d{2})' IN l_date_extern
 
             REPLACE FIRST OCCURRENCE OF REGEX '(\d{4})(\d{2})(\d{2})' IN l_date_extern
 
                                           WITH '$3/$2/$1'.
 
                                           WITH '$3/$2/$1'.
 +
          ASSIGN l_date_extern TO <fs_field>.
 
         ENDCASE.
 
         ENDCASE.
  
Line 444: Line 464:
 
     ENDDO.
 
     ENDDO.
  
     APPEND l_struc_raw_data TO lt_data.
+
     APPEND l_struc_raw_data TO P_TABLA_CSV..
  
 
   ENDLOOP.
 
   ENDLOOP.
 +
endform.</nowiki>
 +
===Ejemplo 3===
 +
<nowiki>
 +
FORM crear_csv USING p_tabla TYPE ANY TABLE
 +
                CHANGING p_tabla_csv TYPE ppe_cust_table.
 +
  CONSTANTS: c_field_separator TYPE c VALUE ';',
 +
            c_darl_number(12) TYPE c VALUE '1234567890 '.
  
   p_tabla_csv[] = lt_data[].
+
   DATA: l_struc_index    TYPE syindex,
endmethod.</nowiki>
+
        l_len_string      TYPE i,
 +
        l_max_field      TYPE char1024,
 +
        l_struc_raw_data  TYPE char1024,
 +
        l_start_string    TYPE i,
 +
        l_len_field_sep  TYPE i,
 +
        l_date_extern(30) TYPE c,
 +
        l_help_id        TYPE tline-tdline,
 +
        l_tabix          TYPE sytabix.
  
==Obtener vía F4 archivo y directorio en un reporte==
+
  FIELD-SYMBOLS <fs_field> TYPE any.
PARAMETERS p_file TYPE string LOWER CASE OBLIGATORY.
+
  FIELD-SYMBOLS <ls_envio> TYPE any.
PARAMETERS p_dir TYPE string LOWER CASE.
+
 
   
+
  l_len_field_sep = strlen( c_field_separator ).
===Archivo===
+
 
* Ejemplo 1
+
  DATA: lr_tab        TYPE REF TO data,
<nowiki>*--------------------------------------------------------------------*
+
        lr_typedesc  TYPE REF TO cl_abap_typedescr,
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
+
        lr_tabdesc    TYPE REF TO cl_abap_tabledescr,
*--------------------------------------------------------------------*
+
        lr_datadesc  TYPE REF TO cl_abap_datadescr,
  DATA: lt_file_table TYPE filetable,
+
        lr_structdesc TYPE REF TO cl_abap_structdescr.
        ls_file_table LIKE LINE OF lt_file_table,
+
  FIELD-SYMBOLS: <ls_structcomp> TYPE abap_compdescr.
        l_subrc      TYPE i.
+
 
 +
* GET REFERENCE OF p_tabla INTO lr_tab.
 +
*  lr_typedesc  ?= cl_abap_tabledescr=>describe_by_data_ref( lr_tab ).
 +
  lr_typedesc  ?= cl_abap_tabledescr=>describe_by_data( p_tabla ).
 +
  lr_tabdesc    ?= lr_typedesc.
 +
  lr_datadesc  = lr_tabdesc->get_table_line_type( ).
 +
  lr_structdesc ?= lr_datadesc.
 +
 
 +
  LOOP AT p_tabla ASSIGNING <ls_envio>.
 +
    CLEAR: l_struc_index, l_len_string, l_struc_raw_data, l_start_string.
 +
 
 +
    DO.
 +
      ADD 1 TO l_struc_index.
 +
      CLEAR l_len_string.
 +
      READ TABLE lr_structdesc->components ASSIGNING <ls_structcomp> INDEX sy-index.
 +
      IF sy-subrc = 0.
 +
        ASSIGN COMPONENT <ls_structcomp>-name OF STRUCTURE <ls_envio> TO <fs_field>.
 +
 
 +
        CASE <ls_structcomp>-type_kind .
 +
          WHEN 'P' OR 'I'.
 +
            IF <ls_structcomp>-type_kind = 'P'.
 +
              WRITE <fs_field> TO l_date_extern CURRENCY 'CLP' NO-GROUPING.
 +
            ELSE.
 +
              WRITE <fs_field> TO l_date_extern NO-GROUPING.
 +
            ENDIF.
  
  CALL METHOD cl_gui_frontend_services=>file_open_dialog
+
            CATCH SYSTEM-EXCEPTIONS conversion_errors  = 4.
    EXPORTING
+
              IF sy-subrc <> '0'.
      window_title            = 'Seleccione Archivo XML'
+
*               MESSAGE e899(ux) WITH l_type <f_source> l_help_id
*     default_extension      =
+
*                                     l_tabix RAISING conversion_failed.
*     default_filename        =
+
              ENDIF.
*    file_filter             =
+
             ENDCATCH.
*    with_encoding          =
+
            CONDENSE l_date_extern.
*    initial_directory      =
+
            ASSIGN l_date_extern TO <fs_field>.
      multiselection          = space
+
          WHEN 'D'.
    CHANGING
+
             MOVE <fs_field> TO l_date_extern.
      file_table              = lt_file_table
+
*20191220 -> 20/12/2019
      rc                      = l_subrc
+
            REPLACE FIRST OCCURRENCE OF REGEX '(\d{4})(\d{2})(\d{2})' IN l_date_extern
*    user_action             =
+
                                          WITH '$3/$2/$1'.
*     file_encoding          =
+
            ASSIGN l_date_extern TO <fs_field>.
    EXCEPTIONS
+
        ENDCASE.
      file_open_dialog_failed = 1
 
      cntl_error              = 2
 
      error_no_gui            = 3
 
      not_supported_by_gui    = 4
 
      OTHERS                  = 5.
 
  IF sy-subrc = 0.
 
    READ TABLE lt_file_table INTO ls_file_table INDEX 1.
 
    p_file = ls_file_table.
 
  ENDIF.</nowiki>
 
  
* Ejemplo 2, el archivo seleccionado queda en el history de p_file
+
      ELSE.
<nowiki>*--------------------------------------------------------------------*
+
         EXIT.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
+
       ENDIF.
*--------------------------------------------------------------------*
 
  DATA: lt_file_tab TYPE STANDARD TABLE OF sdokpath,
 
         ls_file_tab TYPE sdokpath.
 
 
 
  CALL FUNCTION 'TMP_GUI_FILE_OPEN_DIALOG'
 
    EXPORTING
 
      window_title  = 'Seleccione Archivo XML'
 
       multiselection = space
 
    TABLES
 
      file_table    = lt_file_tab
 
    EXCEPTIONS
 
      cntl_error    = 1
 
      OTHERS        = 2.
 
  IF sy-subrc = 0.
 
    READ TABLE lt_file_tab INTO ls_file_tab INDEX 1.
 
    p_file = ls_file_tab.
 
  ENDIF.</nowiki>
 
  
===Directorio===
+
      IF l_struc_index <> 1.
 +
        l_max_field+l_len_string(l_len_field_sep) = c_field_separator.
 +
        l_len_string = l_len_field_sep.
 +
      ENDIF.
 +
*      IF <fs_field> CO c_darl_number.
 +
*        CONDENSE <fs_field> NO-GAPS.
 +
*      ELSE.
 +
*        CONDENSE <fs_field>.
 +
*      ENDIF.
 +
      l_max_field+l_len_string = <fs_field>.
 +
      l_len_string = strlen( l_max_field ).
 +
      CHECK l_len_string <> '0'.
 +
      l_struc_raw_data+l_start_string(l_len_string) = l_max_field.
 +
      l_start_string = l_start_string + l_len_string.
 +
    ENDDO.
 +
 
 +
    APPEND l_struc_raw_data TO p_tabla_csv.
 +
 
 +
  ENDLOOP.
  
====Ejemplo 1====
+
ENDFORM.
  <nowiki>*--------------------------------------------------------------------*
+
</nowiki>
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_dir.
+
===Ejemplo 4===
*--------------------------------------------------------------------*
+
  <nowiki>
   CALL METHOD cl_gui_frontend_services=>directory_browse
+
FORM crear_csv USING p_tabla TYPE ANY TABLE
    EXPORTING
+
                CHANGING p_tabla_csv TYPE ppe_cust_table.
      window_title        = 'Seleccione Directorio'
+
   CONSTANTS: c_field_separator TYPE c VALUE ';',
*    initial_folder      = 'C:\TEMP\'
+
            c_darl_number(12) TYPE c VALUE '1234567890 '.
     CHANGING
+
 
      selected_folder     = p_dir
+
  DATA: l_struc_index     TYPE syindex,
    EXCEPTIONS
+
        l_len_string     TYPE i,
      cntl_error          = 1
+
        l_max_field      TYPE char1024,
      error_no_gui         = 2
+
        l_struc_raw_data  TYPE char1024,
      not_supported_by_gui = 3
+
         l_start_string    TYPE i,
      OTHERS              = 4.
+
        l_len_field_sep  TYPE i,
  IF sy-subrc <> 0.
+
        l_date_extern(30) TYPE c,
*              Implement suitable error handling here
+
        l_help_id        TYPE tline-tdline,
  ENDIF.</nowiki>
+
        l_tabix          TYPE sytabix.
  
====Ejemplo 2====
+
  FIELD-SYMBOLS <fs_field> TYPE any.
<nowiki>*--------------------------------------------------------------------*
+
   FIELD-SYMBOLS <ls_envio> TYPE any.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
 
*--------------------------------------------------------------------*
 
  DATA: lt_dr TYPE STANDARD TABLE OF dynpread,
 
        ls_dr LIKE LINE OF lt_dr.
 
   DATA: lv_dynprog TYPE sy-repid,
 
        lv_dynpnr  TYPE sy-dynnr VALUE '1000'.
 
  
   CLEAR ls_dr.
+
   l_len_field_sep = strlen( c_field_separator ).
  REFRESH lt_dr.
 
  
   ls_dr-fieldname = 'P_LOC'.
+
   DATA: lr_tab        TYPE REF TO data,
   ls_dr-stepl = 0.
+
        lr_typedesc  TYPE REF TO cl_abap_typedescr,
   APPEND ls_dr TO lt_dr.
+
        lr_tabdesc    TYPE REF TO cl_abap_tabledescr,
 +
        lr_datadesc   TYPE REF TO cl_abap_datadescr,
 +
        lr_structdesc TYPE REF TO cl_abap_structdescr.
 +
   FIELD-SYMBOLS: <ls_structcomp> TYPE abap_compdescr.
  
   MOVE sy-repid TO lv_dynprog.
+
   lr_typedesc  ?= cl_abap_tabledescr=>describe_by_data( p_tabla ).
 +
  lr_tabdesc    ?= lr_typedesc.
 +
  lr_datadesc  =  lr_tabdesc->get_table_line_type( ).
 +
  lr_structdesc ?= lr_datadesc.
  
   CALL FUNCTION 'DYNP_VALUES_READ'
+
   DATA: lt_campo TYPE cl_abap_structdescr=>component_table,
    EXPORTING
+
        ls_campo TYPE abap_componentdescr.
      dyname              = lv_dynprog
 
      dynumb              = lv_dynpnr
 
    TABLES
 
      dynpfields          = lt_dr
 
    EXCEPTIONS
 
      invalid_abapworkarea = 1
 
      invalid_dynprofield  = 2
 
      invalid_dynproname  = 3
 
      invalid_dynpronummer = 4
 
      invalid_request      = 5
 
      no_fielddescription  = 6
 
      invalid_parameter    = 7
 
      undefind_error      = 8
 
      double_conversion    = 9
 
      OTHERS              = 10.
 
  IF sy-subrc <> 0.
 
    MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
 
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
 
  ENDIF.
 
  
   READ TABLE lt_dr INTO ls_dr INDEX 1.
+
   lt_campo = lr_structdesc->get_components( ).
  
   IF ls_dr-fieldvalue = 'X'.
+
   LOOP AT p_tabla ASSIGNING <ls_envio>.
    CALL METHOD cl_gui_frontend_services=>directory_browse
+
     CLEAR: l_struc_index, l_len_string, l_struc_raw_data, l_start_string.
*      EXPORTING
 
*        window_title        = 'Seleccione Directorio'
 
      CHANGING
 
        selected_folder      = p_file
 
      EXCEPTIONS
 
        cntl_error          = 1
 
        error_no_gui        = 2
 
        not_supported_by_gui = 3
 
        OTHERS              = 4.
 
    IF sy-subrc <> 0.
 
*              Implement suitable error handling here
 
     ENDIF.
 
  ENDIF.</nowiki>
 
  
==Leer archivo CSV==
+
    DO.
<nowiki>REPORT  ytest_csv.
+
      ADD 1 TO l_struc_index.
 +
      CLEAR l_len_string.
 +
      READ TABLE lt_campo INTO ls_campo INDEX sy-index.
 +
      IF sy-subrc = 0.
 +
        ASSIGN COMPONENT ls_campo-name OF STRUCTURE <ls_envio> TO <fs_field>.
  
TYPE-POOLS truxs.
+
        CASE ls_campo-type->type_kind. .
 +
          WHEN 'P' OR 'I'.
 +
            IF ls_campo-type->type_kind = 'P'.
 +
              IF ls_campo-type->absolute_name = '\TYPE=PAD_AMT7S'.
 +
                WRITE <fs_field> TO l_date_extern CURRENCY 'CLP' NO-GROUPING.
 +
              ELSE.
 +
                WRITE <fs_field> TO l_date_extern NO-GROUPING.
 +
              ENDIF.
 +
            ELSE.
 +
              WRITE <fs_field> TO l_date_extern NO-GROUPING.
 +
            ENDIF.
  
TYPES: BEGIN OF ty_data,
+
            CATCH SYSTEM-EXCEPTIONS conversion_errors  = 4.
  col01(100),
+
              IF sy-subrc <> '0'.
  col02(100),
+
              ENDIF.
  col03(100),
+
            ENDCATCH.
  col04(100),
+
            CONDENSE l_date_extern.
  col05(100),
+
            ASSIGN l_date_extern TO <fs_field>.
END OF ty_data.
+
          WHEN 'D'.
DATA gt_data TYPE TABLE OF ty_data WITH HEADER LINE.
+
            MOVE <fs_field> TO l_date_extern.
DATA : rawdata TYPE truxs_t_text_data.
+
*20191220 -> 20/12/2019
*--------------------------------------------------------------------*
+
            REPLACE FIRST OCCURRENCE OF REGEX '(\d{4})(\d{2})(\d{2})' IN l_date_extern
*
+
                                          WITH '$3/$2/$1'.
*--------------------------------------------------------------------*
+
            ASSIGN l_date_extern TO <fs_field>.
PARAMETERS: p_file TYPE string LOWER CASE.
+
        ENDCASE.
  
*--------------------------------------------------------------------*
+
      ELSE.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
+
        EXIT.
*--------------------------------------------------------------------*
+
      ENDIF.
CALL FUNCTION 'GUI_FILE_LOAD_DIALOG'
+
 
  IMPORTING
+
      IF l_struc_index <> 1.
    FULLPATH                = p_file
+
        l_max_field+l_len_string(l_len_field_sep) = c_field_separator.
          .
+
        l_len_string = l_len_field_sep.
*--------------------------------------------------------------------*
+
      ENDIF.
START-OF-SELECTION.
 
*--------------------------------------------------------------------*
 
  
  PERFORM get_data.
+
      l_max_field+l_len_string = <fs_field>.
 +
      l_len_string = strlen( l_max_field ).
 +
      CHECK l_len_string <> '0'.
 +
      l_struc_raw_data+l_start_string(l_len_string) = l_max_field.
 +
      l_start_string = l_start_string + l_len_string.
 +
    ENDDO.
  
*--------------------------------------------------------------------*
+
    APPEND l_struc_raw_data TO p_tabla_csv.
END-OF-SELECTION.
 
*--------------------------------------------------------------------*
 
  
*&---------------------------------------------------------------------*
+
  ENDLOOP.
*&      Form  get_data
+
 
*&---------------------------------------------------------------------*
+
ENDFORM.</nowiki>
*      text
 
*----------------------------------------------------------------------*
 
FORM get_data.
 
  DATA ld_filename TYPE string.
 
  
  ld_filename = p_file.
+
==Obtener vía F4 archivo y directorio en un reporte==
 +
PARAMETERS p_file TYPE string LOWER CASE OBLIGATORY.
 +
PARAMETERS p_dir TYPE string LOWER CASE.
 +
 +
===Archivo===
 +
* Ejemplo 1
 +
<nowiki>*--------------------------------------------------------------------*
 +
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
 +
*--------------------------------------------------------------------*
 +
  DATA: lt_file_table TYPE filetable,
 +
        ls_file_table LIKE LINE OF lt_file_table,
 +
        l_subrc      TYPE i.
  
   CALL FUNCTION 'GUI_UPLOAD'
+
   CALL METHOD cl_gui_frontend_services=>file_open_dialog
 
     EXPORTING
 
     EXPORTING
       filename                = ld_filename
+
       window_title            = 'Seleccione Archivo XML'
       filetype                = 'ASC'
+
*    default_extension      =
     TABLES
+
*    default_filename        =
       data_tab                = rawdata
+
*    file_filter            =
 +
*    with_encoding          =
 +
*    initial_directory      =
 +
       multiselection          = space
 +
     CHANGING
 +
       file_table              = lt_file_table
 +
      rc                      = l_subrc
 +
*    user_action            =
 +
*    file_encoding          =
 
     EXCEPTIONS
 
     EXCEPTIONS
       file_open_error        = 1
+
       file_open_dialog_failed = 1
       file_read_error        = 2
+
       cntl_error              = 2
       no_batch                = 3
+
       error_no_gui            = 3
       gui_refuse_filetransfer = 4
+
       not_supported_by_gui    = 4
      invalid_type            = 5
+
       OTHERS                  = 5.
      no_authority            = 6
+
   IF sy-subrc = 0.
      unknown_error          = 7
+
     READ TABLE lt_file_table INTO ls_file_table INDEX 1.
      bad_data_format        = 8
+
    p_file = ls_file_table.
      header_not_allowed      = 9
+
   ENDIF.</nowiki>
      separator_not_allowed  = 10
 
      header_too_long        = 11
 
      unknown_dp_error        = 12
 
      access_denied          = 13
 
      dp_out_of_memory        = 14
 
      disk_full              = 15
 
      dp_timeout              = 16
 
       OTHERS                  = 17.
 
   IF sy-subrc <> 0.
 
     EXIT.
 
  ENDIF.
 
   DATA ls_rawdata LIKE LINE OF rawdata.
 
  
   CALL FUNCTION 'TEXT_CONVERT_CSV_TO_SAP'
+
* Ejemplo 2, el archivo seleccionado queda en el history de p_file
 +
<nowiki>*--------------------------------------------------------------------*
 +
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
 +
*--------------------------------------------------------------------*
 +
  DATA: lt_file_tab TYPE STANDARD TABLE OF sdokpath,
 +
        ls_file_tab TYPE sdokpath.
 +
 
 +
   CALL FUNCTION 'TMP_GUI_FILE_OPEN_DIALOG'
 
     EXPORTING
 
     EXPORTING
       i_field_seperator    = ';'
+
       window_title  = 'Seleccione Archivo XML'
       i_tab_raw_data      = rawdata
+
       multiselection = space
 
     TABLES
 
     TABLES
       i_tab_converted_data = gt_data
+
       file_table    = lt_file_tab
 
     EXCEPTIONS
 
     EXCEPTIONS
       conversion_failed    = 1
+
       cntl_error    = 1
       OTHERS               = 2.
+
       OTHERS         = 2.
 +
  IF sy-subrc = 0.
 +
    READ TABLE lt_file_tab INTO ls_file_tab INDEX 1.
 +
    p_file = ls_file_tab.
 +
  ENDIF.</nowiki>
  
  BREAK-POINT.
+
===Directorio===
  
ENDFORM.                    "get_data</nowiki>
+
====Ejemplo 1====
 
+
<nowiki>*--------------------------------------------------------------------*
Para definir otro separador a parte de ;  usar
+
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_dir.
 
+
*--------------------------------------------------------------------*
<nowiki>
+
  CALL METHOD cl_gui_frontend_services=>directory_browse
data l_sep(1) type c value ','.
+
    EXPORTING
 +
      window_title        = 'Seleccione Directorio'
 +
*    initial_folder      = 'C:\TEMP\'
 +
    CHANGING
 +
      selected_folder      = p_dir
 +
    EXCEPTIONS
 +
      cntl_error          = 1
 +
      error_no_gui        = 2
 +
      not_supported_by_gui = 3
 +
      OTHERS              = 4.
 +
  IF sy-subrc <> 0.
 +
*              Implement suitable error handling here
 +
  ENDIF.</nowiki>
  
CALL FUNCTION 'TEXT_CONVERT_TEX_TO_SAP'
+
====Ejemplo 2====
  EXPORTING
+
  <nowiki>*--------------------------------------------------------------------*
  I_FIELD_SEPERATOR          = l_sep
+
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
    i_tab_raw_data            = rawdata
+
*--------------------------------------------------------------------*
  tables
+
  DATA: lt_dr TYPE STANDARD TABLE OF dynpread,
    i_tab_converted_data      = gt_file
+
        ls_dr LIKE LINE OF lt_dr.
  EXCEPTIONS
+
  DATA: lv_dynprog TYPE sy-repid,
  CONVERSION_FAILED          = 1
+
        lv_dynpnr  TYPE sy-dynnr VALUE '1000'.
  OTHERS                    = 2
 
          .
 
</nowiki>
 
  
== Leer archivo Excel==
+
  CLEAR ls_dr.
<nowiki>REPORT YTEST_SUBIR_EXCEL.
+
  REFRESH lt_dr.
  
DATA: gt_data TYPE TABLE OF T001,
+
  ls_dr-fieldname = 'P_LOC'.
      l_i_tab_raw_data  TYPE truxs_t_text_data,
+
  ls_dr-stepl = 0.
      gd_tfile TYPE IBIPPARMS-PATH.
+
  APPEND ls_dr TO lt_dr.
  
PARAMETERS p_file type string obligatory.
+
  MOVE sy-repid TO lv_dynprog.
  
*--------------------------------------------------------------------*
+
   CALL FUNCTION 'DYNP_VALUES_READ'
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
 
*--------------------------------------------------------------------*
 
  DATA: lt_file_table TYPE filetable,
 
        ls_file_table LIKE LINE OF lt_file_table,
 
        l_subrc      TYPE i.
 
 
 
   CALL METHOD cl_gui_frontend_services=>file_open_dialog
 
 
     EXPORTING
 
     EXPORTING
       window_title            = 'Seleccione Archivo EXCEL'
+
       dyname              = lv_dynprog
       multiselection          = space
+
       dynumb              = lv_dynpnr
     CHANGING
+
     TABLES
       file_table              = lt_file_table
+
       dynpfields          = lt_dr
      rc                      = l_subrc
 
 
     EXCEPTIONS
 
     EXCEPTIONS
       file_open_dialog_failed = 1
+
       invalid_abapworkarea = 1
       cntl_error              = 2
+
       invalid_dynprofield  = 2
       error_no_gui            = 3
+
       invalid_dynproname  = 3
       not_supported_by_gui   = 4
+
       invalid_dynpronummer = 4
       OTHERS                 = 5.
+
      invalid_request      = 5
   IF sy-subrc = 0.
+
      no_fielddescription  = 6
     READ TABLE lt_file_table INTO ls_file_table INDEX 1.
+
      invalid_parameter   = 7
    p_file = ls_file_table.
+
      undefind_error      = 8
  ENDIF.
+
      double_conversion    = 9
 
+
       OTHERS               = 10.
*--------------------------------------------------------------------*
+
   IF sy-subrc <> 0.
START-OF-SELECTION.
+
     MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
*--------------------------------------------------------------------*
+
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
data l_file type RLGRAP-FILENAME.
+
  ENDIF.
  
move p_file to l_file.
+
  READ TABLE lt_dr INTO ls_dr INDEX 1.
  
* Read data from Excel shet
+
  IF ls_dr-fieldvalue = 'X'.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
+
    CALL METHOD cl_gui_frontend_services=>directory_browse
EXPORTING
+
*     EXPORTING
  i_tab_raw_data       = l_i_tab_raw_data
+
*        window_title        = 'Seleccione Directorio'
  i_filename           = l_file
+
      CHANGING
TABLES
+
        selected_folder      = p_file
  i_tab_converted_data = gt_data
+
       EXCEPTIONS
EXCEPTIONS
+
        cntl_error           = 1
  conversion_failed    = 1
+
        error_no_gui        = 2
  OTHERS              = 2.
+
        not_supported_by_gui = 3
 +
        OTHERS              = 4.
 +
    IF sy-subrc <> 0.
 +
*              Implement suitable error handling here
 +
    ENDIF.
 +
  ENDIF.</nowiki>
  
IF sy-subrc <> 0.
+
==Leer archivo CSV==
  case sy-subrc.
+
<nowiki>REPORT  ytest_csv.
    when 1.
 
  MESSAGE i000(0k) WITH 'Error en Cargar Archivo.'
 
                      'Favor de validar que archivo'
 
                      'no este abierto por otra aplicación' DISPLAY LIKE 'E'.
 
  when OTHERS.
 
    MESSAGE i000 WITH 'Operación Cancelada' DISPLAY LIKE 'W'.
 
  ENDCASE.
 
  RETURN.
 
ENDIF.</nowiki>
 
  
==Leer archivo XML==
+
TYPE-POOLS truxs.
<nowiki>REPORT YLEE_XML.
 
data gt_data type TABLE OF string.
 
data: g_string type string,
 
      g_xstring type xstring.
 
  
PARAMETERS p_file type string LOWER CASE OBLIGATORY.
+
TYPES: BEGIN OF ty_data,
 +
  col01(100),
 +
  col02(100),
 +
  col03(100),
 +
  col04(100),
 +
  col05(100),
 +
END OF ty_data.
 +
DATA gt_data TYPE TABLE OF ty_data WITH HEADER LINE.
 +
DATA : rawdata TYPE truxs_t_text_data.
 +
*--------------------------------------------------------------------*
 +
*
 +
*--------------------------------------------------------------------*
 +
PARAMETERS: p_file TYPE string LOWER CASE.
 +
 
 +
*--------------------------------------------------------------------*
 +
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
 +
*--------------------------------------------------------------------*
 +
CALL FUNCTION 'GUI_FILE_LOAD_DIALOG'
 +
  IMPORTING
 +
    FULLPATH                = p_file
 +
          .
 +
*--------------------------------------------------------------------*
 +
START-OF-SELECTION.
 +
*--------------------------------------------------------------------*
 +
 
 +
  PERFORM get_data.
 +
 
 +
*--------------------------------------------------------------------*
 +
END-OF-SELECTION.
 +
*--------------------------------------------------------------------*
 +
 
 +
*&---------------------------------------------------------------------*
 +
*&      Form  get_data
 +
*&---------------------------------------------------------------------*
 +
*      text
 +
*----------------------------------------------------------------------*
 +
FORM get_data.
 +
  DATA ld_filename TYPE string.
 +
 
 +
  ld_filename = p_file.
 +
 
 +
  CALL FUNCTION 'GUI_UPLOAD'
 +
    EXPORTING
 +
      filename                = ld_filename
 +
      filetype                = 'ASC'
 +
    TABLES
 +
      data_tab                = rawdata
 +
    EXCEPTIONS
 +
      file_open_error        = 1
 +
      file_read_error        = 2
 +
      no_batch                = 3
 +
      gui_refuse_filetransfer = 4
 +
      invalid_type            = 5
 +
      no_authority            = 6
 +
      unknown_error          = 7
 +
      bad_data_format        = 8
 +
      header_not_allowed      = 9
 +
      separator_not_allowed  = 10
 +
      header_too_long        = 11
 +
      unknown_dp_error        = 12
 +
      access_denied          = 13
 +
      dp_out_of_memory        = 14
 +
      disk_full              = 15
 +
      dp_timeout              = 16
 +
      OTHERS                  = 17.
 +
  IF sy-subrc <> 0.
 +
    EXIT.
 +
  ENDIF.
 +
  DATA ls_rawdata LIKE LINE OF rawdata.
 +
 
 +
  CALL FUNCTION 'TEXT_CONVERT_CSV_TO_SAP'
 +
    EXPORTING
 +
      i_field_seperator    = ';'
 +
      i_tab_raw_data      = rawdata
 +
    TABLES
 +
      i_tab_converted_data = gt_data
 +
    EXCEPTIONS
 +
      conversion_failed    = 1
 +
      OTHERS              = 2.
 +
 
 +
  BREAK-POINT.
 +
 
 +
ENDFORM.                    "get_data</nowiki>
 +
 
 +
Para definir otro separador a parte de ;  usar
 +
 
 +
<nowiki>
 +
data l_sep(1) type c value ','.
 +
 
 +
CALL FUNCTION 'TEXT_CONVERT_TEX_TO_SAP'
 +
  EXPORTING
 +
  I_FIELD_SEPERATOR          = l_sep
 +
    i_tab_raw_data            = rawdata
 +
  tables
 +
    i_tab_converted_data      = gt_file
 +
EXCEPTIONS
 +
  CONVERSION_FAILED          = 1
 +
  OTHERS                    = 2
 +
          .
 +
</nowiki>
 +
 
 +
== Leer archivo Excel==
 +
<nowiki>REPORT YTEST_SUBIR_EXCEL.
 +
 
 +
DATA: gt_data TYPE TABLE OF T001,
 +
      l_i_tab_raw_data  TYPE truxs_t_text_data,
 +
      gd_tfile TYPE IBIPPARMS-PATH.
 +
 
 +
PARAMETERS p_file type string obligatory.
 +
 
 +
*--------------------------------------------------------------------*
 +
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
 +
*--------------------------------------------------------------------*
 +
  DATA: lt_file_table TYPE filetable,
 +
        ls_file_table LIKE LINE OF lt_file_table,
 +
        l_subrc      TYPE i.
 +
 
 +
  CALL METHOD cl_gui_frontend_services=>file_open_dialog
 +
    EXPORTING
 +
      window_title            = 'Seleccione Archivo EXCEL'
 +
      multiselection          = space
 +
    CHANGING
 +
      file_table              = lt_file_table
 +
      rc                      = l_subrc
 +
    EXCEPTIONS
 +
      file_open_dialog_failed = 1
 +
      cntl_error              = 2
 +
      error_no_gui            = 3
 +
      not_supported_by_gui    = 4
 +
      OTHERS                  = 5.
 +
  IF sy-subrc = 0.
 +
    READ TABLE lt_file_table INTO ls_file_table INDEX 1.
 +
    p_file = ls_file_table.
 +
  ENDIF.
 +
 
 +
*--------------------------------------------------------------------*
 +
START-OF-SELECTION.
 +
*--------------------------------------------------------------------*
 +
data l_file type RLGRAP-FILENAME.
 +
 
 +
move p_file to l_file.
 +
 
 +
* Read data from Excel shet
 +
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
 +
EXPORTING
 +
  i_tab_raw_data      = l_i_tab_raw_data
 +
  i_filename          = l_file
 +
TABLES
 +
  i_tab_converted_data = gt_data
 +
EXCEPTIONS
 +
  conversion_failed    = 1
 +
  OTHERS              = 2.
 +
 
 +
IF sy-subrc <> 0.
 +
  case sy-subrc.
 +
    when 1.
 +
  MESSAGE i000(0k) WITH 'Error en Cargar Archivo.'
 +
                      'Favor de validar que archivo'
 +
                      'no este abierto por otra aplicación' DISPLAY LIKE 'E'.
 +
  when OTHERS.
 +
    MESSAGE i000 WITH 'Operación Cancelada' DISPLAY LIKE 'W'.
 +
  ENDCASE.
 +
  RETURN.
 +
ENDIF.</nowiki>
 +
 
 +
===Clase cl_fdt_xl_spreadsheet===
 +
====leer excel====
 +
<nowiki>
 +
FORM leer_excel USING i_file . "CHANGING rt_table TYPE STANDARD TABLE.
 +
  DATA: lt_xtab TYPE cpt_x255,
 +
        lv_size TYPE i.
 +
 
 +
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
 +
    EXPORTING
 +
*    percentage = l_percent
 +
      text = TEXT-003.
 +
 
 +
*    IF i_filetype = abap_true. "******.XLSX UPLOAD*********
 +
  cl_gui_frontend_services=>gui_upload( EXPORTING filename  = i_file
 +
                                                  filetype  = 'BIN'
 +
                                        IMPORTING filelength = lv_size
 +
                                        CHANGING data_tab  = lt_xtab
 +
                                        EXCEPTIONS
 +
                                                  file_open_error = 1
 +
                                                  file_read_error = 2
 +
                                                  error_no_gui            = 3
 +
                                                  not_supported_by_gui    = 4
 +
                                                  OTHERS                  = 5 ).
 +
  IF sy-subrc <> 0.
 +
*        RAISE EXCEPTION TYPE zcx_excel_exception EXPORTING i_message = |Invalid File { i_file }| ##no_text.
 +
  ENDIF.
 +
*    ELSE."******.CSV UPLOAD*********
 +
*
 +
*      cl_gui_frontend_services=>gui_upload( EXPORTING filename  = i_file
 +
*                                                      filetype  = 'ASC'
 +
*                                                      has_field_separator = abap_true
 +
*                                            IMPORTING filelength = lv_size
 +
*                                            CHANGING data_tab  = lt_xtab
 +
*                                            EXCEPTIONS
 +
*                                                    file_open_error = 1
 +
*                                                    file_read_error = 2
 +
*                                                    error_no_gui            = 3
 +
*                                                    not_supported_by_gui    = 4
 +
*                                                    OTHERS                  = 5 ).
 +
*      IF sy-subrc <> 0.
 +
*        RAISE EXCEPTION TYPE zcx_excel_exception EXPORTING i_message = |Invalid File { i_file }| ##no_text.
 +
*      ENDIF.
 +
*
 +
*    ENDIF.
 +
 
 +
  cl_scp_change_db=>xtab_to_xstr( EXPORTING im_xtab    = lt_xtab
 +
                                            im_size    = lv_size
 +
                                  IMPORTING ex_xstring = DATA(lv_xstring) ).
 +
 
 +
  DATA(lo_excel) = NEW cl_fdt_xl_spreadsheet( document_name = i_file
 +
                                              xdocument    = lv_xstring ).
 +
  lo_excel->if_fdt_doc_spreadsheet~get_worksheet_names(
 +
    IMPORTING worksheet_names = DATA(lt_worksheets) ).
 +
 
 +
  DATA rt_table TYPE REF TO data.
 +
  FIELD-SYMBOLS: <fs_carga> TYPE ty_carga,
 +
                <fs_data>  TYPE any,
 +
                <fs_field> TYPE any.
 +
  FIELD-SYMBOLS: <fs_fname> TYPE file_table,
 +
                <ft_data>  TYPE STANDARD TABLE.
 +
 
 +
  LOOP AT lt_worksheets INTO DATA(ls_worksheets).
 +
    rt_table = lo_excel->if_fdt_doc_spreadsheet~get_itab_from_worksheet( ls_worksheets ).
 +
 
 +
*  rt_table = lo_excel->if_fdt_doc_spreadsheet~get_itab_from_worksheet( lt_worksheets[ 2 ] ).
 +
 
 +
    ASSIGN rt_table->* TO <ft_data>.
 +
 
 +
    LOOP AT <ft_data> ASSIGNING <fs_data>.
 +
      IF sy-tabix EQ 1. " Skip the Header
 +
        CONTINUE.
 +
      ENDIF.
 +
      CHECK NOT <fs_data> IS INITIAL.
 +
      UNASSIGN <fs_carga>.
 +
      APPEND INITIAL LINE TO gt_carga ASSIGNING <fs_carga>.
 +
 
 +
      DO 20 TIMES.
 +
        UNASSIGN <fs_field>.
 +
        ASSIGN COMPONENT sy-index OF STRUCTURE <fs_data> TO <fs_field>.
 +
        CHECK <fs_field> IS ASSIGNED AND NOT <fs_field> IS INITIAL.
 +
        CASE sy-index.
 +
*  Fill the values into the internal table based on the columns in excel file
 +
          WHEN 1.
 +
            <fs_carga>-rut_p = <fs_field>.
 +
          WHEN 2.
 +
            <fs_carga>-dig_p = <fs_field>.
 +
          WHEN 3.
 +
            <fs_carga>-pat_p = <fs_field>.
 +
          WHEN 4.
 +
            <fs_carga>-mat_p = <fs_field>.
 +
          WHEN 5.
 +
            <fs_carga>-nom_p = <fs_field>.
 +
          WHEN 6.
 +
            <fs_carga>-rut_c = <fs_field>.
 +
          WHEN 7.
 +
            <fs_carga>-dig_c = <fs_field>.
 +
          WHEN 8.
 +
            <fs_carga>-pat_c = <fs_field>.
 +
          WHEN 9.
 +
            <fs_carga>-mat_c = <fs_field>.
 +
          WHEN 10.
 +
            <fs_carga>-nom_c = <fs_field>.
 +
          WHEN 11.
 +
            <fs_carga>-sex_c = <fs_field>.
 +
          WHEN 12.
 +
            <fs_carga>-pa_c  = <fs_field>.
 +
          WHEN 13.
 +
            <fs_carga>-pa_t  = <fs_field>.
 +
          WHEN 14.
 +
            <fs_carga>-tip_c = <fs_field>.
 +
          WHEN 15.
 +
            <fs_carga>-vig  = <fs_field>.
 +
          WHEN 16.
 +
            IF <fs_field> <> space.
 +
              <fs_carga>-fec_ini = <fs_field>.
 +
            ELSE.
 +
              <fs_carga>-fec_ini = '00000000'.
 +
            ENDIF.
 +
          WHEN 17.
 +
            IF <fs_field> <> space.
 +
              <fs_carga>-fec_ven = <fs_field>.
 +
            ELSE.
 +
              <fs_carga>-fec_ven = '00000000'.
 +
            ENDIF.
 +
          WHEN 18.
 +
            <fs_carga>-fec_der = <fs_field>.
 +
          WHEN 19.
 +
            <fs_carga>-tr = <fs_field>.
 +
          WHEN 20.
 +
            IF <fs_field> <> space.
 +
              <fs_carga>-fec_nac  = <fs_field>.
 +
            ELSE.
 +
              <fs_carga>-fec_nac = '00000000'.
 +
            ENDIF.
 +
          WHEN OTHERS.
 +
        ENDCASE.
 +
      ENDDO.
 +
    ENDLOOP.
 +
 
 +
  ENDLOOP.
 +
*    IF rt_table IS INITIAL.
 +
*      RAISE EXCEPTION TYPE zcx_excel_exception EXPORTING i_message = 'No Data found in Excel File' ##no_text.
 +
*    ENDIF.
 +
 
 +
ENDFORM.</nowiki>
 +
====crear excel====
 +
<nowiki>
 +
TYPES: BEGIN OF ty_data,
 +
        field01(80) TYPE c,
 +
        field02(80) TYPE c,
 +
        field03(80) TYPE c,
 +
        field04(80) TYPE c,
 +
      END OF ty_data.
 +
TYPES ty_data_tab TYPE STANDARD TABLE OF ty_data.
 +
 
 +
DATA gt_data TYPE ty_data_tab .
 +
DATA wa_data LIKE LINE OF gt_data.
 +
 
 +
wa_data-field01 = 'HHHHHH'.
 +
wa_data-field03 = 'AAAAAAAAAAAAAA'.
 +
APPEND wa_data TO gt_data.
 +
 
 +
wa_data-field01 = 'JJJJJJJJJJJJ'.
 +
wa_data-field03 = 'BBBBBBBBBBBBBBBBBB'.
 +
APPEND wa_data TO gt_data.
 +
 
 +
PERFORM crear_excel.
 +
FORM crear_excel.
 +
  DATA: lo_datadescr  TYPE REF TO cl_abap_datadescr.
 +
 
 +
  DATA: lt_column TYPE if_fdt_doc_spreadsheet=>t_column,
 +
        ls_column TYPE if_fdt_doc_spreadsheet=>s_column,
 +
        ld_name  TYPE if_fdt_types=>text,
 +
        lv_name  TYPE if_fdt_types=>name.
 +
 
 +
  DATA: cl_descr_struc_ref TYPE REF TO cl_abap_structdescr,
 +
        it_components      TYPE abap_compdescr_tab,
 +
        wa_components      LIKE LINE OF it_components.
 +
 
 +
  FIELD-SYMBOLS <fs_field> TYPE any.
 +
 
 +
  IF it_components[] IS INITIAL.
 +
    cl_descr_struc_ref ?= cl_abap_typedescr=>describe_by_data( wa_data ).
 +
* obtener campos de estructura
 +
    it_components = cl_descr_struc_ref->components.
 +
  ENDIF.
 +
 
 +
*  ls_column-name        = 'Field01'.
 +
*  ls_column-display_name = 'Field01'.
 +
*  lo_datadescr          ?= cl_abap_typedescr=>describe_by_data( ld_name  ). " change it to the actual data type
 +
*  ls_column-type        = lo_datadescr .
 +
*  APPEND ls_column TO lt_column.
 +
*
 +
*  ls_column-name        = 'Field02'.
 +
*  ls_column-display_name = 'Field02'.
 +
*  lo_datadescr          ?= cl_abap_typedescr=>describe_by_data( ld_name  ). " change it to the actual data type
 +
*  ls_column-type        = lo_datadescr .
 +
*  APPEND ls_column TO lt_column.
 +
*
 +
*  ls_column-name        = 'Field03'.
 +
*  ls_column-display_name = 'Field03'.
 +
*  lo_datadescr          ?= cl_abap_typedescr=>describe_by_data( ld_name  ). " change it to the actual data type
 +
*  ls_column-type        = lo_datadescr .
 +
*  APPEND ls_column TO lt_column.
 +
*
 +
*  ls_column-name        = 'Field04'.
 +
*  ls_column-display_name = 'Field04'.
 +
*  lo_datadescr          ?= cl_abap_typedescr=>describe_by_data( ld_name  ). " change it to the actual data type
 +
*  ls_column-type        = lo_datadescr .
 +
*  APPEND ls_column TO lt_column.
 +
 
 +
  LOOP AT it_components INTO wa_components.
 +
    ASSIGN COMPONENT wa_components-name OF STRUCTURE wa_data TO <fs_field>.
 +
 
 +
    ls_column-name        = wa_components-name.
 +
    ls_column-display_name = wa_components-name.
 +
    lo_datadescr          ?= cl_abap_typedescr=>describe_by_data( <fs_field> ). " change it to the actual data type
 +
    ls_column-type        = lo_datadescr .
 +
    APPEND ls_column TO lt_column.
 +
  ENDLOOP.
 +
 
 +
  DATA lt_data TYPE REF TO data.
 +
  DATA lv_xstring TYPE xstring.
 +
  FIELD-SYMBOLS: <lt_data> TYPE ANY TABLE.
 +
 
 +
  CREATE DATA lt_data TYPE ty_data_tab.
 +
 
 +
  ASSIGN lt_data->* TO <lt_data>.
 +
  <lt_data> = gt_data.
 +
 
 +
  lv_xstring = cl_fdt_xl_spreadsheet=>if_fdt_doc_spreadsheet~create_document(
 +
                                                      columns        = lt_column
 +
                                                      itab          = lt_data
 +
                                                      iv_call_type  = 1 "if_fdt_doc_spreadsheet=>gc_call_simulation
 +
                                                      name          = 'testtest' ).
 +
 
 +
  DATA: l_xtab TYPE cpt_x255,
 +
        l_size TYPE i.
 +
 
 +
  cl_scp_change_db=>xstr_to_xtab( EXPORTING im_xstring = lv_xstring
 +
                                  IMPORTING ex_xtab    = l_xtab
 +
                                            ex_size    = l_size ).
 +
 
 +
  CALL FUNCTION 'GUI_DOWNLOAD'
 +
    EXPORTING
 +
      bin_filesize = l_size
 +
      filename    = 'c:\temp\testtest.xlsx'
 +
      filetype    = 'BIN'
 +
    TABLES
 +
      data_tab    = l_xtab
 +
    EXCEPTIONS
 +
      OTHERS      = 1.
 +
 
 +
  IF sy-subrc <> 0.
 +
 
 +
  ENDIF.
 +
 
 +
ENDFORM.
 +
</nowiki>
 +
 
 +
===Enviar Email con anexo Excel===
 +
Programa BCS_EXAMPLE_7 (clase cl_bcs_convert=>string_to_solix)
 +
 
 +
==Leer archivo XML==
 +
<nowiki>REPORT YLEE_XML.
 +
data gt_data type TABLE OF string.
 +
data: g_string type string,
 +
      g_xstring type xstring.
 +
 
 +
PARAMETERS p_file type string LOWER CASE OBLIGATORY.
 +
 
 +
*--------------------------------------------------------------------*
 +
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
 +
*--------------------------------------------------------------------*
 +
  DATA: lt_file_table TYPE filetable,
 +
        ls_file_table LIKE LINE OF lt_file_table,
 +
        l_subrc      TYPE i.
 +
 
 +
  CALL METHOD cl_gui_frontend_services=>file_open_dialog
 +
    EXPORTING
 +
      window_title            = 'Seleccione Archivo XML'
 +
      multiselection          = space
 +
    CHANGING
 +
      file_table              = lt_file_table
 +
      rc                      = l_subrc
 +
    EXCEPTIONS
 +
      file_open_dialog_failed = 1
 +
      cntl_error              = 2
 +
      error_no_gui            = 3
 +
      not_supported_by_gui    = 4
 +
      OTHERS                  = 5.
 +
  IF sy-subrc = 0.
 +
    READ TABLE lt_file_table INTO ls_file_table INDEX 1.
 +
    p_file = ls_file_table.
 +
  ENDIF.
 +
 
 +
*--------------------------------------------------------------------*
 +
START-OF-SELECTION.
 +
*--------------------------------------------------------------------*
 +
CALL FUNCTION 'GUI_UPLOAD'
 +
  EXPORTING
 +
    filename                      = p_file
 +
    FILETYPE                      = 'ASC'
 +
  tables
 +
    data_tab                      = gt_data
 +
EXCEPTIONS
 +
  FILE_OPEN_ERROR              = 1
 +
  FILE_READ_ERROR              = 2
 +
  NO_BATCH                      = 3
 +
  GUI_REFUSE_FILETRANSFER      = 4
 +
  INVALID_TYPE                  = 5
 +
  NO_AUTHORITY                  = 6
 +
  UNKNOWN_ERROR                = 7
 +
  BAD_DATA_FORMAT              = 8
 +
  HEADER_NOT_ALLOWED            = 9
 +
  SEPARATOR_NOT_ALLOWED        = 10
 +
  HEADER_TOO_LONG              = 11
 +
  UNKNOWN_DP_ERROR              = 12
 +
  ACCESS_DENIED                = 13
 +
  DP_OUT_OF_MEMORY              = 14
 +
  DISK_FULL                    = 15
 +
  DP_TIMEOUT                    = 16
 +
  OTHERS                        = 17
 +
IF sy-subrc <> 0.
 +
* Implement suitable error handling here
 +
  return.
 +
ENDIF.
  
*--------------------------------------------------------------------*
+
loop at gt_data into data(ls_data).
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
+
  if sy-tabix = 1.
*--------------------------------------------------------------------*
+
    g_string = ls_data.
   DATA: lt_file_table TYPE filetable,
+
   else.
        ls_file_table LIKE LINE OF lt_file_table,
+
    CONCATENATE g_string ls_data into g_string.
        l_subrc      TYPE i.
+
  endif.
 +
ENDLOOP.
  
  CALL METHOD cl_gui_frontend_services=>file_open_dialog
+
* encodings se puede ver en ayuda busqueda H_TCP00
    EXPORTING
+
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
      window_title            = 'Seleccione Archivo XML'
 
      multiselection          = space
 
    CHANGING
 
      file_table              = lt_file_table
 
      rc                      = l_subrc
 
    EXCEPTIONS
 
      file_open_dialog_failed = 1
 
      cntl_error              = 2
 
      error_no_gui            = 3
 
      not_supported_by_gui    = 4
 
      OTHERS                  = 5.
 
  IF sy-subrc = 0.
 
    READ TABLE lt_file_table INTO ls_file_table INDEX 1.
 
    p_file = ls_file_table.
 
  ENDIF.
 
 
 
*--------------------------------------------------------------------*
 
START-OF-SELECTION.
 
*--------------------------------------------------------------------*
 
CALL FUNCTION 'GUI_UPLOAD'
 
 
   EXPORTING
 
   EXPORTING
     filename                      = p_file
+
     text          = g_string
    FILETYPE                      = 'ASC'
+
*  MIMETYPE      = ' '
  tables
+
  ENCODING      = '1100' "ISO-8859-1  "'4110' " utf-8
    data_tab                      = gt_data
+
IMPORTING
 +
  BUFFER        = g_xstring
 
  EXCEPTIONS
 
  EXCEPTIONS
  FILE_OPEN_ERROR              = 1
+
   FAILED        = 1
  FILE_READ_ERROR              = 2
+
   OTHERS        = 2
  NO_BATCH                      = 3
+
           .
  GUI_REFUSE_FILETRANSFER      = 4
 
  INVALID_TYPE                  = 5
 
  NO_AUTHORITY                  = 6
 
  UNKNOWN_ERROR                = 7
 
  BAD_DATA_FORMAT              = 8
 
  HEADER_NOT_ALLOWED            = 9
 
  SEPARATOR_NOT_ALLOWED        = 10
 
  HEADER_TOO_LONG              = 11
 
  UNKNOWN_DP_ERROR              = 12
 
  ACCESS_DENIED                = 13
 
  DP_OUT_OF_MEMORY              = 14
 
  DISK_FULL                    = 15
 
  DP_TIMEOUT                    = 16
 
  OTHERS                        = 17
 
IF sy-subrc <> 0.
 
* Implement suitable error handling here
 
  return.
 
ENDIF.
 
 
 
loop at gt_data into data(ls_data).
 
  if sy-tabix = 1.
 
    g_string = ls_data.
 
  else.
 
    CONCATENATE g_string ls_data into g_string.
 
  endif.
 
ENDLOOP.
 
 
 
* encodings se puede ver en ayuda busqueda H_TCP00
 
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
 
  EXPORTING
 
    text          = g_string
 
*  MIMETYPE      = ' '
 
  ENCODING      = '1100' "ISO-8859-1  "'4110'  " utf-8
 
IMPORTING
 
  BUFFER        = g_xstring
 
EXCEPTIONS
 
   FAILED        = 1
 
   OTHERS        = 2
 
           .
 
 
IF sy-subrc <> 0.
 
IF sy-subrc <> 0.
 
* Implement suitable error handling here
 
* Implement suitable error handling here
Line 1,455: Line 1,928:
 
ENDIF.</nowiki>
 
ENDIF.</nowiki>
  
 +
===FM RMSL325_DISPLAY_MSG_POPUP or METHOD cl_rmsl_message=>display===
 +
<nowiki>
 +
*  call method for converting external to internal keys...
 +
    CALL METHOD cl_rmsl_srv_data_source=>get_int_from_ext_cl
 +
      EXPORTING
 +
        i_data_source_ext  = <ls_data_source_external>-data_source
 +
        i_data_source_type = l_data_source_type
 +
      IMPORTING
 +
        et_data_source_int = lt_data_source_internal
 +
        et_error          = lt_error.
 +
 +
*  handle errors
 +
    IF cl_rmsl_message=>is_error_containing_cl( lt_error ) = abap_true.
 +
      e_error_flag = abap_true.
 +
 +
      CALL METHOD cl_rmsl_message=>display
 +
        EXPORTING
 +
          it_message = lt_error.
 +
 +
    ENDIF.
 +
</nowiki>
 
===Leer mensajes===
 
===Leer mensajes===
 
  <nowiki>
 
  <nowiki>
Line 1,483: Line 1,977:
  
 
==crear n° RANDOM==
 
==crear n° RANDOM==
  * initialize random number generator
+
  <nowiki>
  prng = cl_abap_random_int=>create( min = 0 max = l_diff ).
+
data l_num type i.
 +
* initialize random number generator
 +
  DATA(rnd) = cl_abap_random_int=>create( seed = CONV i( sy-uzeit )
 +
                                        min = 0
 +
                                        max = 1000 ).
 +
if rnd is bound.
 +
  l_num = rnd->get_next( ).
 +
endif.
 +
</nowiki>
  
 
==Listado de Pragmas==
 
==Listado de Pragmas==
Line 1,517: Line 2,019:
 
APPEND ls_pernr_2 TO lt_pernr_2.
 
APPEND ls_pernr_2 TO lt_pernr_2.
 
  </nowiki>
 
  </nowiki>
 +
==Leer STACK==
 +
función SYSTEM_CALLSTACK
 +
===leer variable de stack===
 +
ASSIGN ('(MAIN_PROGRAM)VARIABLE[]') TO <FIELD-SYMBOL>.
 +
  <nowiki>
 +
  DATA ls_t681s TYPE t681s.
 +
  DATA: lw_var(40) TYPE c.
 +
  FIELD-SYMBOLS <fs> TYPE any.
 +
 +
  lw_var = '(SAPMV13A)T681S'.
 +
  ASSIGN (lw_var) TO <fs>.
 +
  IF sy-subrc = 0 AND <fs> IS ASSIGNED.
 +
    MOVE <fs> TO ls_t681s.
 +
  ENDIF.</nowiki>
 +
==NUMBER_GET_NEXT - rango de número: asignar siguiente n° (ver trn. SNRO , tabla NRIV )==
 +
<nowiki>
 +
CALL FUNCTION 'NUMBER_GET_NEXT'
 +
  EXPORTING
 +
    nr_range_nr            = iv_interval_number
 +
    object                  = iv_number_range_name
 +
    toyear                  = iv_fiscal_year
 +
    ignore_buffer          = abap_true
 +
  IMPORTING
 +
    number                  = ev_next_number
 +
  EXCEPTIONS
 +
    interval_not_found      = 1
 +
    number_range_not_intern = 2
 +
    object_not_found        = 3
 +
    quantity_is_0          = 4
 +
    quantity_is_not_1      = 5
 +
    interval_overflow      = 6
 +
    buffer_overflow        = 7
 +
    OTHERS                  = 8.</nowiki>

Latest revision as of 20:53, 24 July 2024

Contents

Ejecutar trn. SE16N sin AUTH - FM SE16N_START

UUID ver nota 935047 - Creating and using GUIDs (UUIDs)

FORM generar_iddocumento_2 CHANGING p_resultado.
  DATA lcl_request_id TYPE guid_32.

  TRY.
      lcl_request_id = cl_system_uuid=>create_uuid_c32_static( ).
    CATCH cx_uuid_error.
      ASSERT 1 = 0.
  ENDTRY.

  MOVE lcl_request_id TO p_resultado.
ENDFORM.
  • Examples:
*In the case that a single UUID needs to be created or converted the aliases which are defined in the class
*cl_system_uuid can be used.
*Example for static UUID creation in format binary (16 bytes):

DATA: l_uuid_x16 TYPE sysuuid_x16.
DATA: oref TYPE REF TO cx_uuid_error.

TRY.
  l_uuid_x16 = cl_system_uuid=>create_uuid_x16_static( ). " create uuid_x16
  CATCH cx_uuid_error INTO oref. " catch error
    DATA: s1 TYPE string.
    s1 = oref->get_text( ).
ENDTRY.

*Example for static UUID conversion:

DATA: l_uuid TYPE sysuuid_c22 VALUE 'oucIZjgq4Tg62803kedwLG'.
DATA: l_uuid_x16 TYPE sysuuid_x16.
DATA: l_uuid_c32 TYPE sysuuid_c32.
DATA: oref TYPE REF TO cx_uuid_error.

TRY.
  cl_system_uuid=>convert_uuid_c22_static( EXPORTING uuid = l_uuid
                                           IMPORTING uuid_x16 = l_uuid_x16
                                                     uuid_c32 = l_uuid_c32 ).
  CATCH cx_uuid_error INTO oref. " catch error
    DATA: s1 TYPE string.
    s1 = oref->get_text( ).
ENDTRY.

*To create more than one UUID, the class cl_uuid_factory can be used to create an object of the type
*cl_system_uuid which implements if_system_uuid. This object then can be used for both UUID creation and
*UUID conversion.
*Example for UUID creation with instance methods:

DATA: l_uuid_x16 TYPE sysuuid_x16.
DATA: system_uuid TYPE REF TO if_system_uuid.
DATA: oref TYPE REF TO cx_uuid_error.

system_uuid = cl_uuid_factory=>create_system_uuid( ).
TRY.
  l_uuid_x16 = system_uuid->create_uuid_x16( ). " create uuid_x16
  CATCH cx_uuid_error INTO oref. " catch error
    DATA: s1 TYPE string.
    s1 = oref->get_text( ).
ENDTRY.

*Example for UUID conversion with instance methods:

DATA: l_uuid TYPE sysuuid_c22 VALUE 'oucIZjgq4Tg62803kedwLG'.
DATA: l_uuid_x16 TYPE sysuuid_x16.
DATA: l_uuid_c32 TYPE sysuuid_c32.
DATA: system_uuid TYPE REF TO if_system_uuid.
DATA: oref TYPE REF TO cx_uuid_error.

system_uuid = cl_uuid_factory=>create_system_uuid( ).

TRY.
  system_uuid->convert_uuid_c22( EXPORTING uuid = l_uuid
                                 IMPORTING uuid_x16 = l_uuid_x16
                                           uuid_c32 = l_uuid_c32 ).
  CATCH cx_uuid_error INTO oref. " catch error
    DATA: s1 TYPE string.
    s1 = oref->get_text( ).
ENDTRY.

Grabar XSTRING en equipo como Binario(XML,PDF,etc.)

CONCATENATE ls_dir_d '\' i_vbeln '.xml'
             INTO ls_fullpath.
CALL METHOD cl_faa_tenv_services=>gui_download_xstring
  EXPORTING
    id_fullpath = ls_fullpath
    id_xstring  = i_xml.
IF sy-subrc <> 0.
ENDIF.
form gui_download USING i_xstring type xstring
                        i_fullpath type string
               CHANGING c_subrc type sy-subrc.
* Stores a XSTRING as file on frontend client

  DATA: lt_xtable   TYPE faa_t_tenv_xmlraw.
  DATA: ld_filesize TYPE i.

* Converting XString to XTable
  CALL METHOD cl_faa_tenv_services=>convert_xstring_to_xtable
    EXPORTING
      id_xstring    = i_xstring
    IMPORTING
      et_xtable     = lt_xtable
    EXCEPTIONS
      invalid_table = 1
      OTHERS        = 2.

  IF sy-subrc <> 0.
    c_subrc = sy-subrc.
    MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    RETURN.
  ENDIF.

* . Save XTable
  ld_filesize = xstrlen( i_xstring ).
  CALL METHOD cl_gui_frontend_services=>gui_download
    EXPORTING
      bin_filesize = ld_filesize
      filename     = i_fullpath
      filetype     = 'BIN'
    CHANGING
      data_tab     = lt_xtable
    EXCEPTIONS
      OTHERS       = 4.
  c_subrc = sy-subrc.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.


ENDform.                    "gui_download


*----------------------------------------------------------------------*
FORM download_server USING p_xstring TYPE xstring
                           p_path TYPE string
                  CHANGING p_subrc TYPE sy-subrc.
  DATA: lt_bin_tab    TYPE solix_tab,
        l_file_length TYPE i.
  data wa like LINE OF lt_bin_tab.

  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer        = p_xstring
    IMPORTING
      output_length = l_file_length
    TABLES
      binary_tab    = lt_bin_tab.

  OPEN DATASET p_path IN BINARY MODE FOR OUTPUT.
  IF sy-subrc = 0.
    p_subrc = 0.
    LOOP AT lt_bin_tab INTO wa.
      TRANSFER wa TO p_path.
    ENDLOOP.
    CLOSE DATASET p_path.
  ELSE.
    p_subrc = 1.
  ENDIF.

ENDFORM.                    "download_server

CL_GUI_FRONTEND_SERVICES

* OBTIENE PATH de "Mis Documentos"
CALL METHOD cl_gui_frontend_services=>get_upload_download_path
 CHANGING
   upload_path                 = ld_dir_u
   download_path               = ld_dir_d
 EXCEPTIONS
   CNTL_ERROR                  = 1
   ERROR_NO_GUI                = 2
   NOT_SUPPORTED_BY_GUI        = 3
   GUI_UPLOAD_DOWNLOAD_PATH    = 4
   UPLOAD_DOWNLOAD_PATH_FAILED = 5
   others                      = 6
       .

* Download File
call method cl_gui_frontend_services=>gui_download
  exporting
    filename                = tmpfilename
  changing
    data_tab                = it_logfile
  exceptions
    file_write_error        = 1
    no_batch                = 2
    gui_refuse_filetransfer = 3
    invalid_type            = 4
    no_authority            = 5
    unknown_error           = 6
    header_not_allowed      = 7
    separator_not_allowed   = 8
    filesize_not_allowed    = 9
    header_too_long         = 10
    dp_error_create         = 11
    dp_error_send           = 12
    dp_error_write          = 13
    unknown_dp_error        = 14
    access_denied           = 15
    dp_out_of_memory        = 16
    disk_full               = 17
    dp_timeout              = 18
    file_not_found          = 19
    dataprovider_exception  = 20
    control_flush_error     = 21
    not_supported_by_gui    = 22
    error_no_gui            = 23
    others                  = 24.
if sy-subrc <> 0.
  message id sy-msgid type sy-msgty number sy-msgno
             with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

Bajar tabla en formato CSV (función hr_cl_if_prvd_generate_file)

Ejemplo 1

FUNCTION hr_cl_if_prvd_generate_file.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  TABLES
*"      IT_DATA TYPE  STANDARD TABLE
*"----------------------------------------------------------------------
  FIELD-SYMBOLS: <f_source>.

  TYPES data_c(4096) TYPE c.
  TYPES t_data_c TYPE data_c OCCURS 0.

  CONSTANTS: c_field_separator TYPE c VALUE ';',
             c_darl_number(12)     TYPE c VALUE '1234567890 '.

  DATA: lt_data_csv      TYPE t_data_c,
        l_struc_index    TYPE syindex,
        l_len_string     TYPE i,
        l_max_field      TYPE data_c,
        l_struc_raw_data TYPE data_c,
        l_start_string   TYPE i,
        l_len_field_sep  TYPE i,
        l_type,
        l_date_extern(30) TYPE c,
        l_help_id LIKE tline-tdline,
        l_tabix TYPE sytabix.

  l_len_field_sep = STRLEN( c_field_separator ).

  LOOP AT it_data.
    CLEAR: l_struc_index, l_len_string, l_struc_raw_data, l_start_string.
    DO.
      ADD 1 TO l_struc_index.
      CLEAR l_len_string.
      ASSIGN COMPONENT l_struc_index OF STRUCTURE it_data TO <f_source>.
      IF sy-subrc <> '0'.
        EXIT.
      ELSE.
*         *       special processing when field is type data
        DESCRIBE FIELD <f_source> TYPE l_type.
        CASE l_type.
          WHEN 'P'.
            WRITE <f_source> TO l_date_extern.
            CATCH SYSTEM-EXCEPTIONS conversion_errors  = 4.
              IF sy-subrc <> '0'.
                MESSAGE e899(ux) WITH l_type <f_source> l_help_id
                                      l_tabix RAISING conversion_failed.
              ENDIF.
            ENDCATCH.
            ASSIGN l_date_extern TO <f_source>.
          WHEN 'X'.
            ASSIGN COMPONENT l_struc_index OF
                    STRUCTURE it_data TO <f_source> TYPE 'C'.
            WRITE <f_source> TO l_date_extern.
            ASSIGN l_date_extern TO <f_source>.
          WHEN 'T'.
            CLEAR l_date_extern.
            l_date_extern(2) = <f_source>(2).
            l_date_extern+2(1) = ':'.
            l_date_extern+3(2) = <f_source>+2(2).
            l_date_extern+5(1) = ':'.
            l_date_extern+6(2) = <f_source>+4(2).
            ASSIGN l_date_extern TO <f_source>.
          WHEN 'D'.
            CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
              EXPORTING
                date_internal = <f_source>
              IMPORTING
                date_external = l_date_extern
              EXCEPTIONS
                OTHERS        = 4.
            IF sy-subrc <> 0.
              MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
                    RAISING conversion_failed.
            ELSE.
              ASSIGN l_date_extern TO <f_source>.
            ENDIF.
          WHEN 'F'.
            CALL FUNCTION 'FLTP_CHAR_CONVERSION'
              EXPORTING
                input  = <f_source>
              IMPORTING
                flstr  = l_date_extern
              EXCEPTIONS
                OTHERS = 4.
            IF sy-subrc <> 0.
              MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
                    RAISING conversion_failed.
            ELSE.
              ASSIGN l_date_extern TO <f_source>.
            ENDIF.
          WHEN OTHERS.
        ENDCASE.
*        remember der seperation character!
        IF l_struc_index <> 1.
          l_max_field+l_len_string(l_len_field_sep) = c_field_separator.
          l_len_string = l_len_field_sep.
        ENDIF.
        IF <f_source> CO c_darl_number.
          CONDENSE <f_source> NO-GAPS.
        ELSE.
          CONDENSE <f_source>.
        ENDIF.
        l_max_field+l_len_string = <f_source>.
        l_len_string = STRLEN( l_max_field ).
        CHECK l_len_string <> '0'.
        l_struc_raw_data+l_start_string(l_len_string) = l_max_field.
        l_start_string = l_start_string + l_len_string.
      ENDIF.
    ENDDO.
    IF NOT l_struc_raw_data IS INITIAL.
      APPEND l_struc_raw_data TO lt_data_csv.
    ENDIF.
  ENDLOOP.

  CALL FUNCTION 'HR_99S_DOWNLOAD'
    EXPORTING
      p_initial_directory     = 'C:\'
      p_filename              = 'PREVIRED.txt'
      p_filetype              = 'ASC'
      p_write_lf              = 'X'
      p_trunc_blanks_eol      = 'X'
      p_trunc_blanks          = ' '
    TABLES
      data_tab                = lt_data_csv
    EXCEPTIONS
      file_save_dialog        = 1
      file_write_error        = 2
      no_batch                = 3
      gui_refuse_filetransfer = 4
      invalid_type            = 5
      unknown_error           = 6
      wrong_tab_format        = 7
      OTHERS                  = 8.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDFUNCTION.

EJEMPLO 2

TYPES: BEGIN OF ty_pernr,
         pernr TYPE p0001-pernr,
         begda type begda,
         dias type i,
         sueldo type p DECIMALS 0,
       END OF ty_pernr.

data: lt_pernr type TABLE OF ty_pernr,
      lt_tabla_csv TYPE ppe_cust_table,
      ls_pernr type ty_pernr.

ls_pernr-pernr = '00000001'.
ls_pernr-begda = sy-datum.
ls_pernr-sueldo = 620000.
ls_pernr-dias = 30.

append ls_pernr to lt_pernr.

PERFORM CREAR_CSV USING lt_pernr CHANGING lt_tabla_csv.
* salida: 00000001;03/09/2021;30;620000

form CREAR_CSV using p_tabla type ANY TABLE
                CHANGING P_TABLA_CSV type ppe_cust_table.
  CONSTANTS: c_field_separator TYPE c VALUE ';',
             c_darl_number(12) TYPE c VALUE '1234567890 '.

  DATA: cl_descr_struc_ref TYPE REF TO cl_abap_structdescr,
        it_components      TYPE abap_compdescr_tab,
        wa_components      LIKE LINE OF it_components.

  DATA: l_struc_index     TYPE syindex,
        l_len_string      TYPE i,
        l_max_field       TYPE char1024,
        l_struc_raw_data  TYPE char1024,
        l_start_string    TYPE i,
        l_len_field_sep   TYPE i,
        l_date_extern(30) TYPE c,
        l_help_id         type tline-tdline,
        l_tabix           TYPE sytabix.

  FIELD-SYMBOLS <fs_field> TYPE ANY.
  FIELD-SYMBOLS <ls_envio> TYPE ANY.

  l_len_field_sep = STRLEN( c_field_separator ).

  LOOP AT p_tabla ASSIGNING <ls_envio>.
    CLEAR: l_struc_index, l_len_string, l_struc_raw_data, l_start_string.

    IF it_components[] IS INITIAL.
      cl_descr_struc_ref ?= cl_abap_typedescr=>describe_by_data( <ls_envio> ).
* obtener campos de estructura
      it_components = cl_descr_struc_ref->components.
    ENDIF.

    DO.
      ADD 1 TO l_struc_index.
      CLEAR l_len_string.
      READ TABLE it_components INTO wa_components INDEX sy-index.
      IF sy-subrc = 0.
        ASSIGN COMPONENT wa_components-name OF STRUCTURE <ls_envio> TO <fs_field>.

        CASE wa_components-type_kind .
          WHEN 'P' or 'I'.
            WRITE <fs_field> TO l_date_extern NO-GROUPING.
            CATCH SYSTEM-EXCEPTIONS conversion_errors  = 4.
              IF sy-subrc <> '0'.
*                MESSAGE e899(ux) WITH l_type <f_source> l_help_id
*                                      l_tabix RAISING conversion_failed.
              ENDIF.
            ENDCATCH.
            CONDENSE l_date_extern.
            ASSIGN l_date_extern TO <fs_field>.
          WHEN 'D'.
            MOVE <fs_field> TO l_date_extern.
*20191220 -> 20/12/2019
            REPLACE FIRST OCCURRENCE OF REGEX '(\d{4})(\d{2})(\d{2})' IN l_date_extern
                                           WITH '$3/$2/$1'.
           ASSIGN l_date_extern TO <fs_field>.
        ENDCASE.

      ELSE.
        EXIT.
      ENDIF.

      IF l_struc_index <> 1.
        l_max_field+l_len_string(l_len_field_sep) = c_field_separator.
        l_len_string = l_len_field_sep.
      ENDIF.
*      IF <fs_field> CO c_darl_number.
*        CONDENSE <fs_field> NO-GAPS.
*      ELSE.
*        CONDENSE <fs_field>.
*      ENDIF.
      l_max_field+l_len_string = <fs_field>.
      l_len_string = STRLEN( l_max_field ).
      CHECK l_len_string <> '0'.
      l_struc_raw_data+l_start_string(l_len_string) = l_max_field.
      l_start_string = l_start_string + l_len_string.
    ENDDO.

    APPEND l_struc_raw_data TO P_TABLA_CSV..

  ENDLOOP.
endform.

Ejemplo 3

FORM crear_csv USING p_tabla TYPE ANY TABLE
                CHANGING p_tabla_csv TYPE ppe_cust_table.
  CONSTANTS: c_field_separator TYPE c VALUE ';',
             c_darl_number(12) TYPE c VALUE '1234567890 '.

  DATA: l_struc_index     TYPE syindex,
        l_len_string      TYPE i,
        l_max_field       TYPE char1024,
        l_struc_raw_data  TYPE char1024,
        l_start_string    TYPE i,
        l_len_field_sep   TYPE i,
        l_date_extern(30) TYPE c,
        l_help_id         TYPE tline-tdline,
        l_tabix           TYPE sytabix.

  FIELD-SYMBOLS <fs_field> TYPE any.
  FIELD-SYMBOLS <ls_envio> TYPE any.

  l_len_field_sep = strlen( c_field_separator ).

  DATA: lr_tab        TYPE REF TO data,
        lr_typedesc   TYPE REF TO cl_abap_typedescr,
        lr_tabdesc    TYPE REF TO cl_abap_tabledescr,
        lr_datadesc   TYPE REF TO cl_abap_datadescr,
        lr_structdesc TYPE REF TO cl_abap_structdescr.
  FIELD-SYMBOLS: <ls_structcomp> TYPE abap_compdescr.

*  GET REFERENCE OF p_tabla INTO lr_tab.
*  lr_typedesc   ?= cl_abap_tabledescr=>describe_by_data_ref( lr_tab ).
  lr_typedesc   ?= cl_abap_tabledescr=>describe_by_data( p_tabla ).
  lr_tabdesc    ?= lr_typedesc.
  lr_datadesc   =  lr_tabdesc->get_table_line_type( ).
  lr_structdesc ?= lr_datadesc.

  LOOP AT p_tabla ASSIGNING <ls_envio>.
    CLEAR: l_struc_index, l_len_string, l_struc_raw_data, l_start_string.

    DO.
      ADD 1 TO l_struc_index.
      CLEAR l_len_string.
      READ TABLE lr_structdesc->components ASSIGNING <ls_structcomp> INDEX sy-index.
      IF sy-subrc = 0.
        ASSIGN COMPONENT <ls_structcomp>-name OF STRUCTURE <ls_envio> TO <fs_field>.

        CASE <ls_structcomp>-type_kind .
          WHEN 'P' OR 'I'.
            IF <ls_structcomp>-type_kind = 'P'.
              WRITE <fs_field> TO l_date_extern CURRENCY 'CLP' NO-GROUPING.
            ELSE.
              WRITE <fs_field> TO l_date_extern NO-GROUPING.
            ENDIF.

            CATCH SYSTEM-EXCEPTIONS conversion_errors  = 4.
              IF sy-subrc <> '0'.
*                MESSAGE e899(ux) WITH l_type <f_source> l_help_id
*                                      l_tabix RAISING conversion_failed.
              ENDIF.
            ENDCATCH.
            CONDENSE l_date_extern.
            ASSIGN l_date_extern TO <fs_field>.
          WHEN 'D'.
            MOVE <fs_field> TO l_date_extern.
*20191220 -> 20/12/2019
            REPLACE FIRST OCCURRENCE OF REGEX '(\d{4})(\d{2})(\d{2})' IN l_date_extern
                                           WITH '$3/$2/$1'.
            ASSIGN l_date_extern TO <fs_field>.
        ENDCASE.

      ELSE.
        EXIT.
      ENDIF.

      IF l_struc_index <> 1.
        l_max_field+l_len_string(l_len_field_sep) = c_field_separator.
        l_len_string = l_len_field_sep.
      ENDIF.
*      IF <fs_field> CO c_darl_number.
*        CONDENSE <fs_field> NO-GAPS.
*      ELSE.
*        CONDENSE <fs_field>.
*      ENDIF.
      l_max_field+l_len_string = <fs_field>.
      l_len_string = strlen( l_max_field ).
      CHECK l_len_string <> '0'.
      l_struc_raw_data+l_start_string(l_len_string) = l_max_field.
      l_start_string = l_start_string + l_len_string.
    ENDDO.

    APPEND l_struc_raw_data TO p_tabla_csv.

  ENDLOOP.

ENDFORM.

Ejemplo 4

FORM crear_csv USING p_tabla TYPE ANY TABLE
                CHANGING p_tabla_csv TYPE ppe_cust_table.
  CONSTANTS: c_field_separator TYPE c VALUE ';',
             c_darl_number(12) TYPE c VALUE '1234567890 '.

  DATA: l_struc_index     TYPE syindex,
        l_len_string      TYPE i,
        l_max_field       TYPE char1024,
        l_struc_raw_data  TYPE char1024,
        l_start_string    TYPE i,
        l_len_field_sep   TYPE i,
        l_date_extern(30) TYPE c,
        l_help_id         TYPE tline-tdline,
        l_tabix           TYPE sytabix.

  FIELD-SYMBOLS <fs_field> TYPE any.
  FIELD-SYMBOLS <ls_envio> TYPE any.

  l_len_field_sep = strlen( c_field_separator ).

  DATA: lr_tab        TYPE REF TO data,
        lr_typedesc   TYPE REF TO cl_abap_typedescr,
        lr_tabdesc    TYPE REF TO cl_abap_tabledescr,
        lr_datadesc   TYPE REF TO cl_abap_datadescr,
        lr_structdesc TYPE REF TO cl_abap_structdescr.
  FIELD-SYMBOLS: <ls_structcomp> TYPE abap_compdescr.

  lr_typedesc   ?= cl_abap_tabledescr=>describe_by_data( p_tabla ).
  lr_tabdesc    ?= lr_typedesc.
  lr_datadesc   =  lr_tabdesc->get_table_line_type( ).
  lr_structdesc ?= lr_datadesc.

  DATA: lt_campo TYPE cl_abap_structdescr=>component_table,
        ls_campo TYPE abap_componentdescr.

  lt_campo = lr_structdesc->get_components( ).

  LOOP AT p_tabla ASSIGNING <ls_envio>.
    CLEAR: l_struc_index, l_len_string, l_struc_raw_data, l_start_string.

    DO.
      ADD 1 TO l_struc_index.
      CLEAR l_len_string.
      READ TABLE lt_campo INTO ls_campo INDEX sy-index.
      IF sy-subrc = 0.
        ASSIGN COMPONENT ls_campo-name OF STRUCTURE <ls_envio> TO <fs_field>.

        CASE ls_campo-type->type_kind. .
          WHEN 'P' OR 'I'.
            IF ls_campo-type->type_kind = 'P'.
              IF ls_campo-type->absolute_name = '\TYPE=PAD_AMT7S'.
                WRITE <fs_field> TO l_date_extern CURRENCY 'CLP' NO-GROUPING.
              ELSE.
                WRITE <fs_field> TO l_date_extern NO-GROUPING.
              ENDIF.
            ELSE.
              WRITE <fs_field> TO l_date_extern NO-GROUPING.
            ENDIF.

            CATCH SYSTEM-EXCEPTIONS conversion_errors  = 4.
              IF sy-subrc <> '0'.
              ENDIF.
            ENDCATCH.
            CONDENSE l_date_extern.
            ASSIGN l_date_extern TO <fs_field>.
          WHEN 'D'.
            MOVE <fs_field> TO l_date_extern.
*20191220 -> 20/12/2019
            REPLACE FIRST OCCURRENCE OF REGEX '(\d{4})(\d{2})(\d{2})' IN l_date_extern
                                           WITH '$3/$2/$1'.
            ASSIGN l_date_extern TO <fs_field>.
        ENDCASE.

      ELSE.
        EXIT.
      ENDIF.

      IF l_struc_index <> 1.
        l_max_field+l_len_string(l_len_field_sep) = c_field_separator.
        l_len_string = l_len_field_sep.
      ENDIF.

      l_max_field+l_len_string = <fs_field>.
      l_len_string = strlen( l_max_field ).
      CHECK l_len_string <> '0'.
      l_struc_raw_data+l_start_string(l_len_string) = l_max_field.
      l_start_string = l_start_string + l_len_string.
    ENDDO.

    APPEND l_struc_raw_data TO p_tabla_csv.

  ENDLOOP.

ENDFORM.

Obtener vía F4 archivo y directorio en un reporte

PARAMETERS p_file TYPE string LOWER CASE OBLIGATORY.
PARAMETERS p_dir TYPE string LOWER CASE.

Archivo

  • Ejemplo 1
*--------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*--------------------------------------------------------------------*
  DATA: lt_file_table TYPE filetable,
        ls_file_table LIKE LINE OF lt_file_table,
        l_subrc       TYPE i.

  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title            = 'Seleccione Archivo XML'
*     default_extension       =
*     default_filename        =
*     file_filter             =
*     with_encoding           =
*     initial_directory       =
      multiselection          = space
    CHANGING
      file_table              = lt_file_table
      rc                      = l_subrc
*     user_action             =
*     file_encoding           =
    EXCEPTIONS
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      not_supported_by_gui    = 4
      OTHERS                  = 5.
  IF sy-subrc = 0.
    READ TABLE lt_file_table INTO ls_file_table INDEX 1.
    p_file = ls_file_table.
  ENDIF.
  • Ejemplo 2, el archivo seleccionado queda en el history de p_file
*--------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*--------------------------------------------------------------------*
  DATA: lt_file_tab TYPE STANDARD TABLE OF sdokpath,
        ls_file_tab TYPE sdokpath.
  
  CALL FUNCTION 'TMP_GUI_FILE_OPEN_DIALOG'
    EXPORTING
      window_title   = 'Seleccione Archivo XML'
      multiselection = space
    TABLES
      file_table     = lt_file_tab
    EXCEPTIONS
      cntl_error     = 1
      OTHERS         = 2.
  IF sy-subrc = 0.
    READ TABLE lt_file_tab INTO ls_file_tab INDEX 1.
    p_file = ls_file_tab.
  ENDIF.

Directorio

Ejemplo 1

*--------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_dir.
*--------------------------------------------------------------------*
  CALL METHOD cl_gui_frontend_services=>directory_browse
    EXPORTING
      window_title         = 'Seleccione Directorio'
*     initial_folder       = 'C:\TEMP\'
    CHANGING
      selected_folder      = p_dir
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      not_supported_by_gui = 3
      OTHERS               = 4.
  IF sy-subrc <> 0.
*               Implement suitable error handling here
  ENDIF.

Ejemplo 2

*--------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*--------------------------------------------------------------------*
  DATA: lt_dr TYPE STANDARD TABLE OF dynpread,
        ls_dr LIKE LINE OF lt_dr.
  DATA: lv_dynprog TYPE sy-repid,
        lv_dynpnr  TYPE sy-dynnr VALUE '1000'.

  CLEAR ls_dr.
  REFRESH lt_dr.

  ls_dr-fieldname = 'P_LOC'.
  ls_dr-stepl = 0.
  APPEND ls_dr TO lt_dr.

  MOVE sy-repid TO lv_dynprog.

  CALL FUNCTION 'DYNP_VALUES_READ'
    EXPORTING
      dyname               = lv_dynprog
      dynumb               = lv_dynpnr
    TABLES
      dynpfields           = lt_dr
    EXCEPTIONS
      invalid_abapworkarea = 1
      invalid_dynprofield  = 2
      invalid_dynproname   = 3
      invalid_dynpronummer = 4
      invalid_request      = 5
      no_fielddescription  = 6
      invalid_parameter    = 7
      undefind_error       = 8
      double_conversion    = 9
      OTHERS               = 10.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  READ TABLE lt_dr INTO ls_dr INDEX 1.

  IF ls_dr-fieldvalue = 'X'.
    CALL METHOD cl_gui_frontend_services=>directory_browse
*      EXPORTING
*        window_title         = 'Seleccione Directorio'
      CHANGING
        selected_folder      = p_file
      EXCEPTIONS
        cntl_error           = 1
        error_no_gui         = 2
        not_supported_by_gui = 3
        OTHERS               = 4.
    IF sy-subrc <> 0.
*               Implement suitable error handling here
    ENDIF.
  ENDIF.

Leer archivo CSV

REPORT  ytest_csv.

TYPE-POOLS truxs.

TYPES: BEGIN OF ty_data,
  col01(100),
  col02(100),
  col03(100),
  col04(100),
  col05(100),
END OF ty_data.
DATA gt_data TYPE TABLE OF ty_data WITH HEADER LINE.
DATA : rawdata TYPE truxs_t_text_data.
*--------------------------------------------------------------------*
*
*--------------------------------------------------------------------*
PARAMETERS: p_file TYPE string LOWER CASE.

*--------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*--------------------------------------------------------------------*
 CALL FUNCTION 'GUI_FILE_LOAD_DIALOG'
  IMPORTING
    FULLPATH                = p_file
           .
*--------------------------------------------------------------------*
START-OF-SELECTION.
*--------------------------------------------------------------------*

  PERFORM get_data.

*--------------------------------------------------------------------*
END-OF-SELECTION.
*--------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_data.
  DATA ld_filename TYPE string.

  ld_filename = p_file.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = ld_filename
      filetype                = 'ASC'
    TABLES
      data_tab                = rawdata
    EXCEPTIONS
      file_open_error         = 1
      file_read_error         = 2
      no_batch                = 3
      gui_refuse_filetransfer = 4
      invalid_type            = 5
      no_authority            = 6
      unknown_error           = 7
      bad_data_format         = 8
      header_not_allowed      = 9
      separator_not_allowed   = 10
      header_too_long         = 11
      unknown_dp_error        = 12
      access_denied           = 13
      dp_out_of_memory        = 14
      disk_full               = 15
      dp_timeout              = 16
      OTHERS                  = 17.
  IF sy-subrc <> 0.
    EXIT.
  ENDIF.
  DATA ls_rawdata LIKE LINE OF rawdata.

  CALL FUNCTION 'TEXT_CONVERT_CSV_TO_SAP'
    EXPORTING
      i_field_seperator    = ';'
      i_tab_raw_data       = rawdata
    TABLES
      i_tab_converted_data = gt_data
    EXCEPTIONS
      conversion_failed    = 1
      OTHERS               = 2.

  BREAK-POINT.

ENDFORM.                    "get_data

Para definir otro separador a parte de ; usar

data l_sep(1) type c value ','.

CALL FUNCTION 'TEXT_CONVERT_TEX_TO_SAP'
  EXPORTING
   I_FIELD_SEPERATOR           = l_sep
    i_tab_raw_data             = rawdata
  tables
    i_tab_converted_data       = gt_file
 EXCEPTIONS
   CONVERSION_FAILED          = 1
   OTHERS                     = 2
          .

Leer archivo Excel

REPORT YTEST_SUBIR_EXCEL.

DATA: gt_data TYPE TABLE OF T001,
      l_i_tab_raw_data  TYPE truxs_t_text_data,
      gd_tfile TYPE IBIPPARMS-PATH.

PARAMETERS p_file type string obligatory.

*--------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*--------------------------------------------------------------------*
  DATA: lt_file_table TYPE filetable,
        ls_file_table LIKE LINE OF lt_file_table,
        l_subrc       TYPE i.

  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title            = 'Seleccione Archivo EXCEL'
      multiselection          = space
    CHANGING
      file_table              = lt_file_table
      rc                      = l_subrc
    EXCEPTIONS
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      not_supported_by_gui    = 4
      OTHERS                  = 5.
  IF sy-subrc = 0.
    READ TABLE lt_file_table INTO ls_file_table INDEX 1.
    p_file = ls_file_table.
  ENDIF.

*--------------------------------------------------------------------*
START-OF-SELECTION.
*--------------------------------------------------------------------*
data l_file type RLGRAP-FILENAME.

move p_file to l_file.

* Read data from Excel shet
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
  i_tab_raw_data       = l_i_tab_raw_data
  i_filename           = l_file
TABLES
  i_tab_converted_data = gt_data
EXCEPTIONS
  conversion_failed    = 1
  OTHERS               = 2.

IF sy-subrc <> 0.
  case sy-subrc.
    when 1.
  MESSAGE i000(0k) WITH 'Error en Cargar Archivo.'
                       'Favor de validar que archivo'
                       'no este abierto por otra aplicación' DISPLAY LIKE 'E'.
   when OTHERS.
     MESSAGE i000 WITH 'Operación Cancelada' DISPLAY LIKE 'W'.
   ENDCASE.
  RETURN.
ENDIF.

Clase cl_fdt_xl_spreadsheet

leer excel

FORM leer_excel USING i_file . "CHANGING rt_table TYPE STANDARD TABLE.
  DATA: lt_xtab TYPE cpt_x255,
        lv_size TYPE i.

  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
*     percentage = l_percent
      text = TEXT-003.

*    IF i_filetype = abap_true. "******.XLSX UPLOAD*********
  cl_gui_frontend_services=>gui_upload( EXPORTING filename   = i_file
                                                  filetype   = 'BIN'
                                        IMPORTING filelength = lv_size
                                         CHANGING data_tab   = lt_xtab
                                         EXCEPTIONS
                                                  file_open_error = 1
                                                  file_read_error = 2
                                                  error_no_gui            = 3
                                                  not_supported_by_gui    = 4
                                                  OTHERS                  = 5 ).
  IF sy-subrc <> 0.
*        RAISE EXCEPTION TYPE zcx_excel_exception EXPORTING i_message = |Invalid File { i_file }| ##no_text.
  ENDIF.
*    ELSE."******.CSV UPLOAD*********
*
*      cl_gui_frontend_services=>gui_upload( EXPORTING filename   = i_file
*                                                      filetype   = 'ASC'
*                                                      has_field_separator = abap_true
*                                            IMPORTING filelength = lv_size
*                                            CHANGING data_tab   = lt_xtab
*                                            EXCEPTIONS
*                                                    file_open_error = 1
*                                                    file_read_error = 2
*                                                    error_no_gui            = 3
*                                                    not_supported_by_gui    = 4
*                                                    OTHERS                  = 5 ).
*      IF sy-subrc <> 0.
*        RAISE EXCEPTION TYPE zcx_excel_exception EXPORTING i_message = |Invalid File { i_file }| ##no_text.
*      ENDIF.
*
*    ENDIF.

  cl_scp_change_db=>xtab_to_xstr( EXPORTING im_xtab    = lt_xtab
                                            im_size    = lv_size
                                  IMPORTING ex_xstring = DATA(lv_xstring) ).

  DATA(lo_excel) = NEW cl_fdt_xl_spreadsheet( document_name = i_file
                                              xdocument     = lv_xstring ).
  lo_excel->if_fdt_doc_spreadsheet~get_worksheet_names(
    IMPORTING worksheet_names = DATA(lt_worksheets) ).

  DATA rt_table TYPE REF TO data.
  FIELD-SYMBOLS: <fs_carga> TYPE ty_carga,
                 <fs_data>  TYPE any,
                 <fs_field> TYPE any.
  FIELD-SYMBOLS: <fs_fname> TYPE file_table,
                 <ft_data>  TYPE STANDARD TABLE.

  LOOP AT lt_worksheets INTO DATA(ls_worksheets).
    rt_table = lo_excel->if_fdt_doc_spreadsheet~get_itab_from_worksheet( ls_worksheets ).

*  rt_table = lo_excel->if_fdt_doc_spreadsheet~get_itab_from_worksheet( lt_worksheets[ 2 ] ).

    ASSIGN rt_table->* TO <ft_data>.

    LOOP AT <ft_data> ASSIGNING <fs_data>.
      IF sy-tabix EQ 1. " Skip the Header
        CONTINUE.
      ENDIF.
      CHECK NOT <fs_data> IS INITIAL.
      UNASSIGN <fs_carga>.
      APPEND INITIAL LINE TO gt_carga ASSIGNING <fs_carga>.

      DO 20 TIMES.
        UNASSIGN <fs_field>.
        ASSIGN COMPONENT sy-index OF STRUCTURE <fs_data> TO <fs_field>.
        CHECK <fs_field> IS ASSIGNED AND NOT <fs_field> IS INITIAL.
        CASE sy-index.
*  Fill the values into the internal table based on the columns in excel file
          WHEN 1.
            <fs_carga>-rut_p = <fs_field>.
          WHEN 2.
            <fs_carga>-dig_p = <fs_field>.
          WHEN 3.
            <fs_carga>-pat_p = <fs_field>.
          WHEN 4.
            <fs_carga>-mat_p = <fs_field>.
          WHEN 5.
            <fs_carga>-nom_p = <fs_field>.
          WHEN 6.
            <fs_carga>-rut_c = <fs_field>.
          WHEN 7.
            <fs_carga>-dig_c = <fs_field>.
          WHEN 8.
            <fs_carga>-pat_c = <fs_field>.
          WHEN 9.
            <fs_carga>-mat_c = <fs_field>.
          WHEN 10.
            <fs_carga>-nom_c = <fs_field>.
          WHEN 11.
            <fs_carga>-sex_c = <fs_field>.
          WHEN 12.
            <fs_carga>-pa_c  = <fs_field>.
          WHEN 13.
            <fs_carga>-pa_t  = <fs_field>.
          WHEN 14.
            <fs_carga>-tip_c = <fs_field>.
          WHEN 15.
            <fs_carga>-vig   = <fs_field>.
          WHEN 16.
            IF <fs_field> <> space.
              <fs_carga>-fec_ini = <fs_field>.
            ELSE.
              <fs_carga>-fec_ini = '00000000'.
            ENDIF.
          WHEN 17.
            IF <fs_field> <> space.
              <fs_carga>-fec_ven = <fs_field>.
            ELSE.
              <fs_carga>-fec_ven = '00000000'.
            ENDIF.
          WHEN 18.
            <fs_carga>-fec_der = <fs_field>.
          WHEN 19.
            <fs_carga>-tr = <fs_field>.
          WHEN 20.
            IF <fs_field> <> space.
              <fs_carga>-fec_nac  = <fs_field>.
            ELSE.
              <fs_carga>-fec_nac = '00000000'.
            ENDIF.
          WHEN OTHERS.
        ENDCASE.
      ENDDO.
    ENDLOOP.

  ENDLOOP.
*    IF rt_table IS INITIAL.
*      RAISE EXCEPTION TYPE zcx_excel_exception EXPORTING i_message = 'No Data found in Excel File' ##no_text.
*    ENDIF.

ENDFORM.

crear excel

TYPES: BEGIN OF ty_data,
         field01(80) TYPE c,
         field02(80) TYPE c,
         field03(80) TYPE c,
         field04(80) TYPE c,
       END OF ty_data.
TYPES ty_data_tab TYPE STANDARD TABLE OF ty_data.

DATA gt_data TYPE ty_data_tab .
DATA wa_data LIKE LINE OF gt_data.

wa_data-field01 = 'HHHHHH'.
wa_data-field03 = 'AAAAAAAAAAAAAA'.
APPEND wa_data TO gt_data.

wa_data-field01 = 'JJJJJJJJJJJJ'.
wa_data-field03 = 'BBBBBBBBBBBBBBBBBB'.
APPEND wa_data TO gt_data.

PERFORM crear_excel.
FORM crear_excel.
  DATA: lo_datadescr   TYPE REF TO cl_abap_datadescr.

  DATA: lt_column TYPE if_fdt_doc_spreadsheet=>t_column,
        ls_column TYPE if_fdt_doc_spreadsheet=>s_column,
        ld_name   TYPE if_fdt_types=>text,
        lv_name   TYPE if_fdt_types=>name.

  DATA: cl_descr_struc_ref TYPE REF TO cl_abap_structdescr,
        it_components      TYPE abap_compdescr_tab,
        wa_components      LIKE LINE OF it_components.

  FIELD-SYMBOLS <fs_field> TYPE any.

  IF it_components[] IS INITIAL.
    cl_descr_struc_ref ?= cl_abap_typedescr=>describe_by_data( wa_data ).
* obtener campos de estructura
    it_components = cl_descr_struc_ref->components.
  ENDIF.

*  ls_column-name         = 'Field01'.
*  ls_column-display_name = 'Field01'.
*  lo_datadescr          ?= cl_abap_typedescr=>describe_by_data( ld_name  ). " change it to the actual data type
*  ls_column-type         = lo_datadescr .
*  APPEND ls_column TO lt_column.
*
*  ls_column-name         = 'Field02'.
*  ls_column-display_name = 'Field02'.
*  lo_datadescr          ?= cl_abap_typedescr=>describe_by_data( ld_name  ). " change it to the actual data type
*  ls_column-type         = lo_datadescr .
*  APPEND ls_column TO lt_column.
*
*  ls_column-name         = 'Field03'.
*  ls_column-display_name = 'Field03'.
*  lo_datadescr          ?= cl_abap_typedescr=>describe_by_data( ld_name  ). " change it to the actual data type
*  ls_column-type         = lo_datadescr .
*  APPEND ls_column TO lt_column.
*
*  ls_column-name         = 'Field04'.
*  ls_column-display_name = 'Field04'.
*  lo_datadescr          ?= cl_abap_typedescr=>describe_by_data( ld_name  ). " change it to the actual data type
*  ls_column-type         = lo_datadescr .
*  APPEND ls_column TO lt_column.

  LOOP AT it_components INTO wa_components.
    ASSIGN COMPONENT wa_components-name OF STRUCTURE wa_data TO <fs_field>.

    ls_column-name         = wa_components-name.
    ls_column-display_name = wa_components-name.
    lo_datadescr          ?= cl_abap_typedescr=>describe_by_data( <fs_field> ). " change it to the actual data type
    ls_column-type         = lo_datadescr .
    APPEND ls_column TO lt_column.
  ENDLOOP.

  DATA lt_data TYPE REF TO data.
  DATA lv_xstring TYPE xstring.
  FIELD-SYMBOLS: <lt_data> TYPE ANY TABLE.

  CREATE DATA lt_data TYPE ty_data_tab.

  ASSIGN lt_data->* TO <lt_data>.
  <lt_data> = gt_data.

  lv_xstring = cl_fdt_xl_spreadsheet=>if_fdt_doc_spreadsheet~create_document(
                                                      columns        = lt_column
                                                      itab           = lt_data
                                                      iv_call_type   = 1 "if_fdt_doc_spreadsheet=>gc_call_simulation
                                                      name           = 'testtest' ).

  DATA: l_xtab TYPE cpt_x255,
        l_size TYPE i.

  cl_scp_change_db=>xstr_to_xtab( EXPORTING im_xstring = lv_xstring
                                  IMPORTING ex_xtab    = l_xtab
                                            ex_size    = l_size ).

  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      bin_filesize = l_size
      filename     = 'c:\temp\testtest.xlsx'
      filetype     = 'BIN'
    TABLES
      data_tab     = l_xtab
    EXCEPTIONS
      OTHERS       = 1.

  IF sy-subrc <> 0.

  ENDIF.

ENDFORM.

Enviar Email con anexo Excel

Programa BCS_EXAMPLE_7 (clase cl_bcs_convert=>string_to_solix)

Leer archivo XML

REPORT YLEE_XML.
data gt_data type TABLE OF string.
data: g_string type string,
      g_xstring type xstring.

PARAMETERS p_file type string LOWER CASE OBLIGATORY.

*--------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*--------------------------------------------------------------------*
  DATA: lt_file_table TYPE filetable,
        ls_file_table LIKE LINE OF lt_file_table,
        l_subrc       TYPE i.

  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title            = 'Seleccione Archivo XML'
      multiselection          = space
    CHANGING
      file_table              = lt_file_table
      rc                      = l_subrc
    EXCEPTIONS
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      not_supported_by_gui    = 4
      OTHERS                  = 5.
  IF sy-subrc = 0.
    READ TABLE lt_file_table INTO ls_file_table INDEX 1.
    p_file = ls_file_table.
  ENDIF.

*--------------------------------------------------------------------*
START-OF-SELECTION.
*--------------------------------------------------------------------*
CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    filename                      = p_file
    FILETYPE                      = 'ASC'
  tables
    data_tab                      = gt_data
 EXCEPTIONS
   FILE_OPEN_ERROR               = 1
   FILE_READ_ERROR               = 2
   NO_BATCH                      = 3
   GUI_REFUSE_FILETRANSFER       = 4
   INVALID_TYPE                  = 5
   NO_AUTHORITY                  = 6
   UNKNOWN_ERROR                 = 7
   BAD_DATA_FORMAT               = 8
   HEADER_NOT_ALLOWED            = 9
   SEPARATOR_NOT_ALLOWED         = 10
   HEADER_TOO_LONG               = 11
   UNKNOWN_DP_ERROR              = 12
   ACCESS_DENIED                 = 13
   DP_OUT_OF_MEMORY              = 14
   DISK_FULL                     = 15
   DP_TIMEOUT                    = 16
   OTHERS                        = 17
IF sy-subrc <> 0.
* Implement suitable error handling here
  return.
ENDIF.

loop at gt_data into data(ls_data).
  if sy-tabix = 1.
    g_string = ls_data.
  else.
    CONCATENATE g_string ls_data into g_string.
  endif.
ENDLOOP.

* encodings se puede ver en ayuda busqueda H_TCP00
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
  EXPORTING
    text           = g_string
*   MIMETYPE       = ' '
   ENCODING       = '1100' "ISO-8859-1  "'4110'  " utf-8
 IMPORTING
   BUFFER         = g_xstring
 EXCEPTIONS
   FAILED         = 1
   OTHERS         = 2
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

call function 'DISPLAY_XML_STRING'
  EXPORTING xml_string = g_xstring.

Leer Arhivo PDF y Visualizarlo

Programa

*&---------------------------------------------------------------------*
*& Report YLEE_PDF
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ylee_pdf.
DATA: g_html_container TYPE REF TO cl_gui_custom_container,
      g_html_control   TYPE REF TO cl_gui_html_viewer,
      g_url(255).

DATA gt_data  TYPE solix_tab.

DATA ok_code TYPE sy-ucomm.

PARAMETERS p_file TYPE string LOWER CASE OBLIGATORY.

*--------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*--------------------------------------------------------------------*
  DATA: lt_file_tab TYPE STANDARD TABLE OF sdokpath,
        ls_file_tab TYPE sdokpath.

  CALL FUNCTION 'TMP_GUI_FILE_OPEN_DIALOG'
    EXPORTING
      window_title   = 'Seleccione Archivo PDF'
      multiselection = space
    TABLES
      file_table     = lt_file_tab
    EXCEPTIONS
      cntl_error     = 1
      OTHERS         = 2.
  IF sy-subrc = 0.
    READ TABLE lt_file_tab INTO ls_file_tab INDEX 1.
    p_file = ls_file_tab.
  ENDIF.

*--------------------------------------------------------------------*
START-OF-SELECTION.
*--------------------------------------------------------------------*
  DATA l_lenght TYPE i.
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = p_file
      filetype                = 'BIN'
    IMPORTING
      filelength              = l_lenght
    TABLES
      data_tab                = gt_data
    EXCEPTIONS
      file_open_error         = 1
      file_read_error         = 2
      no_batch                = 3
      gui_refuse_filetransfer = 4
      invalid_type            = 5
      no_authority            = 6
      unknown_error           = 7
      bad_data_format         = 8
      header_not_allowed      = 9
      separator_not_allowed   = 10
      header_too_long         = 11
      unknown_dp_error        = 12
      access_denied           = 13
      dp_out_of_memory        = 14
      disk_full               = 15
      dp_timeout              = 16
      OTHERS                  = 17.
  IF sy-subrc <> 0.
    RETURN.
  ENDIF.

  CALL SCREEN 0100.
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'STATUS'. "Crear con 'BACK' 'EXIT' 'CANC' de tipo comando exit
  SET TITLEBAR 'T01'.      "PDF Viewer

  IF g_html_container IS INITIAL.
    CREATE OBJECT g_html_container
      EXPORTING
        container_name = 'PDF'.

    CREATE OBJECT g_html_control
      EXPORTING
        parent = g_html_container.

    CALL METHOD g_html_control->load_data
      EXPORTING
        type                   = 'application'
        subtype                = 'pdf'
      IMPORTING
        assigned_url           = g_url
      CHANGING
        data_table             = gt_data
      EXCEPTIONS
        dp_invalid_parameter   = 1
        dp_error_general       = 2
        cntl_error             = 3
        html_syntax_notcorrect = 4
        OTHERS                 = 5.
    IF sy-subrc <> 0.
    ENDIF.

    CALL METHOD g_html_control->show_url
      EXPORTING
        url                    = g_url
        in_place               = ' X'
      EXCEPTIONS
        cntl_error             = 1
        cnht_error_not_allowed = 2
        cnht_error_parameter   = 3
        dp_error_general       = 4
        OTHERS                 = 5.
    IF sy-subrc <> 0.
    ENDIF.
  ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  EXIT  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE exit INPUT.
  DATA l_ok_code TYPE sy-ucomm.

  l_ok_code = ok_code.
  CLEAR ok_code.

  CASE l_ok_code.
    WHEN 'BACK' OR 'EXIT' OR 'CANC'.
      CALL METHOD g_html_control->free
        EXCEPTIONS
          cntl_error        = 1
          cntl_system_error = 2
          OTHERS            = 3.
      IF sy-subrc <> 0.
*       Implement suitable error handling here
      ENDIF.

      SET SCREEN 0.
      LEAVE SCREEN.
  ENDCASE.
ENDMODULE.

Dynpro 0100

  • Crear custom container con Nombre PDF
  • Agregar Elemento OK_CODE de tipo OK
  • Crear Status GUI STATUS con 'BACK' 'EXIT' 'CANC' de tipo comando exit
  • Crear Título T01 "PDF Viewer"
PROCESS BEFORE OUTPUT.
 MODULE STATUS_0100.
*
PROCESS AFTER INPUT.
  module exit at EXIT-COMMAND.
* MODULE USER_COMMAND_0100.

Obtener Texto según Valor de dominio

TABLES: DD07L, DD07T, DD08L.

FORM get_domvalue USING p_domname p_value CHANGING p_text.
  DATA: l_domvalue TYPE dd07v-domvalue_l,
        l_ddtext TYPE dd07v-ddtext.

  l_domvalue = p_value.

  CALL FUNCTION 'DOMAIN_VALUE_GET'
    EXPORTING
      i_domname  = p_domname
      i_domvalue = l_domvalue
    IMPORTING
      e_ddtext   = l_ddtext
    EXCEPTIONS
      not_exist  = 1
      OTHERS     = 2.
  IF sy-subrc = 0.
    MOVE l_ddtext TO p_text.
  ELSE.
    CLEAR p_text.
  ENDIF.

ENDFORM.                    "get_domvalue

POPUP_TO_CONFIRM

data g_answer(1).
CALL FUNCTION 'POPUP_TO_CONFIRM'
  EXPORTING
    titlebar              = 'Se actualizaran Documentos en el Sistema'(p01)
    text_question         = '¿Desea Continuar?'(p02)
    text_button_1         = 'Sí'(p03)
    text_button_2         = 'No'(p04)
    default_button        = 2
    display_cancel_button = c_true
  IMPORTING
    answer                = g_answer.
IF g_answer <> '1'.
  RETURN.
ENDIF.

F4IF_INT_TABLE_VALUE_REQUEST y F4IF_FIELD_VALUE_REQUEST

En reporte

TYPES: BEGIN OF ty_subty,
         subty TYPE t554s-subty,
         atext TYPE t554t-atext,
       END OF ty_subty.

DATA gt_subty TYPE TABLE OF ty_subty.

SELECT-OPTIONS: s_pernr FOR wa_data-pernr MATCHCODE OBJECT prem,
                s_awart FOR p2001-awart.

*--------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_awart-low.
*--------------------------------------------------------------------*
  PERFORM f4_subty CHANGING s_awart-low.

*----------------------------------------------------------------------*
*       FORM .......
*----------------------------------------------------------------------*
FORM f4_subty CHANGING p_value.

  DATA lt_return TYPE TABLE OF ddshretval WITH HEADER LINE.

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield     = 'SUBTY'
      value_org    = 'S'
      window_title = 'Clase de Absentismo'
    TABLES
      value_tab    = gt_subty
      return_tab   = lt_return.
  READ TABLE lt_return INDEX 1.
  IF sy-subrc = 0.
    MOVE lt_return-fieldval TO p_value.
  ENDIF.
ENDFORM.

En dynpro

process on value-request.
 field T_TIEMPO-falla module VALUE_FALLA.

MODULE VALUE_FALLA INPUT.
  CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
   EXPORTING
     TABNAME                   = 'ZCP6'
     FIELDNAME                 = 'FALLA'
     SEARCHHELP                = 'ZCP9'
     DYNPPROG                  = syst-repid
     DYNPNR                    = syst-dynnr
     DYNPROFIELD               = 'T_TIEMPO-FALLA '
    
ENDMODULE.                 " VALUE_FALLA  INPUT

Agregar botones en la pantalla de selección de un Reporte

  • Primero declarar
tables SSCRFIELDS.

  • En la sección SELECT-OPTIONS, declarar
SELECTION-SCREEN FUNCTION KEY 1.
SELECTION-SCREEN FUNCTION KEY 2.

  • En la sección INITIALIZATION colocar
INITIALIZATION.
  MOVE 'Calculos'(001) TO SSCRFIELDS-FUNCTXT_01.
  MOVE 'Ayuda'(002)    TO SSCRFIELDS-FUNCTXT_02.
 
  • En AT SELECCTION-SCREEN :
AT SELECTION-SCREEN.
  CASE sscrfields-ucomm.
    WHEN  'FC01'.
* do something 
    when 'FC02'.
* do something
  ENDCASE.

SHA1 encode

CALL FUNCTION 'CALCULATE_HASH_FOR_CHAR'
  EXPORTING
*   ALG            = 'SHA1'
    data           = l_firma
    IMPORTING
    hashstring     = l_hashstring
  EXCEPTIONS
    unknown_alg    = 1
    param_error    = 2
    internal_error = 3
    OTHERS         = 4.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

BASE 64

desde un string en BASE64 obtener PDF binario

FORM get_pdf_bin USING p_archivo_b64 TYPE string
              CHANGING p_data_tab  TYPE solix_tab
                       p_xstring TYPE xstring.
  DATA lt_bin TYPE TABLE OF solix.
  DATA l_output_length TYPE  i.

  PERFORM decode_base_64x USING p_archivo_b64
                       CHANGING p_xstring.

  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer        = p_xstring
    IMPORTING
      output_length = l_output_length
    TABLES
      binary_tab    = lt_bin.  "p_data_tab.

  p_data_tab[] = lt_bin[].

ENDFORM.                    " GET_PDF_BIN
FORM decode_base_64x USING p_string_base64 TYPE string
                  CHANGING p_xstring TYPE xstring.
  DATA: l_http_utility TYPE REF TO cl_http_utility.

  CREATE OBJECT l_http_utility.

  CALL METHOD l_http_utility->decode_x_base64
    EXPORTING
      encoded = p_string_base64
    RECEIVING
      decoded = p_xstring.
ENDFORM.

Leer set de datos

  • Set de datos : transacciones GS02 GS03
  • funciones: G_SET_GET_ID_FROM_NAME --> G_SET_FETCH
data: ra_kdgrp type RANGE OF Knvv-KDGRP,
      wa_kdrgp LIKE LINE OF ra_kdgrp,
      l_aux type Knvv-KDGRP VALUE '85',
      l_setid type SETHIER-SETID,
      lt_lines type TABLE OF RGSBV WITH HEADER LINE.

CALL FUNCTION 'G_SET_GET_ID_FROM_NAME'
 EXPORTING
   SHORTNAME                      = 'ZSD_AAA_001'
IMPORTING
  NEW_SETID                      = l_setid
EXCEPTIONS
  NO_SET_FOUND                   = 1
  NO_SET_PICKED_FROM_POPUP       = 2
  WRONG_CLASS                    = 3
  WRONG_SUBCLASS                 = 4
  TABLE_FIELD_NOT_FOUND          = 5
  FIELDS_DONT_MATCH              = 6
  SET_IS_EMPTY                   = 7
  FORMULA_IN_SET                 = 8
  SET_IS_DYNAMIC                 = 9
  OTHERS                         = 10
         .
IF SY-SUBRC = 0.
* Implement suitable error handling here
 CALL FUNCTION 'G_SET_FETCH'
   EXPORTING
     SETNR                     = l_setid
  TABLES
    SET_LINES_BASIC           = lt_lines
  EXCEPTIONS
    NO_AUTHORITY              = 1
    SET_IS_BROKEN             = 2
    SET_NOT_FOUND             = 3
    OTHERS                    = 4
           .
 IF SY-SUBRC = 0.
* Implement suitable error handling here
   loop at lt_lines.
     wa_kdrgp-sign = 'I'.
     wa_kdrgp-option = 'BT'.
     wa_kdrgp-low = lt_lines-from.
     wa_kdrgp-high = lt_lines-to.
     append wa_kdrgp to ra_kdgrp.
   ENDLOOP.
 ENDIF.

 if l_aux in ra_kdgrp.
   write 'OK'.
 endif.
ENDIF.

Eliminar historial para campo especifico

 data l_rc type i.
 CALL METHOD cl_gui_frontend_services=>disablehistoryforfield
   EXPORTING
     fieldname                     = 'SVALD-VALUE'
     bdisabled                     = 'X'
   changing
     rc                            = l_rc
   EXCEPTIONS
     field_not_found               = 1
     disablehistoryforfield_failed = 2
     cntl_error                    = 3
     unable_to_disable_field       = 4
     others                        = 5
         .
 IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
 ENDIF.

Comprimir String (GZIP)

DATA: l_text_in TYPE string,
      l_text_out TYPE xstring,
      l_zip_length TYPE i.
TRY.
  tp_text_in = 'El corona virus me tiene chato'.
  cl_abap_gzip=>compress_text(
    EXPORTING
      text_in =      l_text_in
    IMPORTING
      gzip_out     = l_text_out
      gzip_out_len = l_zip_length
  ).
  CATCH cx_parameter_invalid_range.
  CATCH cx_sy_buffer_overflow.
  CATCH cx_sy_conversion_codepage.
  CATCH cx_root.
ENDTRY.

Uso de estructura BAPIRET2

 Se puede utilizar la función BALW_BAPIRETURN_GET2 para llenar estructura de tipo BAPIRET2, ejemplo:
* error entrega no existe
  move i_vbeln to ld_par1.

  CALL FUNCTION 'BALW_BAPIRETURN_GET2'
    EXPORTING
      TYPE             = 'E'
      CL               = 'VL'
      NUMBER           = 559
      PAR1             = ld_par1
   IMPORTING
     RETURN            = ls_return

Función VIEW_MAINTENANCE_CALL & VIEWCLUSTER_MAINTENANCE_CALL

Para actualizar tablas sin utilizar trn SM30

CALL FUNCTION 'VIEW_MAINTENANCE_CALL'
  EXPORTING
    action                               = 'U'
*   CORR_NUMBER                          = '          '
*   GENERATE_MAINT_TOOL_IF_MISSING       = ' '
*   SHOW_SELECTION_POPUP                 = ' '
    view_name                            = 'ZHCM_VIS_LIQ_POR'
*   NO_WARNING_FOR_CLIENTINDEP           = ' '
*   RFC_DESTINATION_FOR_UPGRADE          = ' '
*   CLIENT_FOR_UPGRADE                   = ' '
*   VARIANT_FOR_SELECTION                = ' '
*   COMPLEX_SELCONDS_USED                = ' '
*   CHECK_DDIC_MAINFLAG                  = ' '
*   SUPPRESS_WA_POPUP                    = ' '
* TABLES
*   DBA_SELLIST                          =
*   EXCL_CUA_FUNCT                       =
 EXCEPTIONS
   CLIENT_REFERENCE                     = 1
   FOREIGN_LOCK                         = 2
   INVALID_ACTION                       = 3
   NO_CLIENTINDEPENDENT_AUTH            = 4
   NO_DATABASE_FUNCTION                 = 5
   NO_EDITOR_FUNCTION                   = 6
   NO_SHOW_AUTH                         = 7
   NO_TVDIR_ENTRY                       = 8
   NO_UPD_AUTH                          = 9
   ONLY_SHOW_ALLOWED                    = 10
   SYSTEM_FAILURE                       = 11
   UNKNOWN_FIELD_IN_DBA_SELLIST         = 12
   VIEW_NOT_FOUND                       = 13
   MAINTENANCE_PROHIBITED               = 14
   OTHERS                               = 15
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
  MESSAGE e000(0k) WITH 'Error al actualizar tabla ZHCM_VIS_LIQ_POR'.
ENDIF.

Para actualizar cluster vista , Trn. SE54-->Tratar cluster de vistas

  CALL FUNCTION 'VIEWCLUSTER_MAINTENANCE_CALL'
       EXPORTING
            VIEWCLUSTER_NAME             = VCL_NAME        "VC_T52DE
            MAINTENANCE_ACTION           = ACT_STATUS      "U
       TABLES
            DBA_SELLIST                  = DBA_SELLIST
       EXCEPTIONS
            CLIENT_REFERENCE             = 1
            FOREIGN_LOCK                 = 2
            VIEWCLUSTER_NOT_FOUND        = 3
            VIEWCLUSTER_IS_INCONSISTENT  = 4
            MISSING_GENERATED_FUNCTION   = 5
            NO_UPD_AUTH                  = 6
            NO_SHOW_AUTH                 = 7
            OBJECT_NOT_FOUND             = 8
            NO_TVDIR_ENTRY               = 9
            NO_CLIENTINDEP_AUTH          = 10
            INVALID_ACTION               = 11
            SAVING_CORRECTION_FAILED     = 12
            SYSTEM_FAILURE               = 13
            UNKNOWN_FIELD_IN_DBA_SELLIST = 14
            MISSING_CORR_NUMBER          = 15
            OTHERS                       = 16.

* contenido DBA_SELLIST
* VIEWFIELD MOLGA
* NEGATION	                                   
* LEFTPAR   0
* OPERATOR  EQ
* VALUE     39

Ejemplo Batch Input

Variantes

trn. STVARV

tabla tvarvc

select single low into @data(l_low) from tvarvc where name = 'ZTEST'
                                                  and type = 'P'
                                                  and numb = '000'.

Traducción

Encontrar BADI para transacción

  1. Ir a TR SE24 e ingresar CL_EXITHANDLER .
  2. Ir a 'Methods' tab.
  3. Doble click en método 'Get Instance'.
  4. Colocar un breakpoint en 'CALL METHOD cl_exithandler => get_class_name_by_interface'.
  5. Correr transacción correspondiente.
  6. Al parar transacción, ver valor de campo 'EXIT_NAME' que corresponde a la BADI.

Como saber si un ambiente es de Desarrollo, Test o Productivo

Tabla T000 campo CCCATEGORY, donde:

  • P Productivo
  • T Test
  • C Customizing
  • D Presentación
  • E Formación
  • S Referencia SAP
DATA: ls_t000 TYPE t000.
 
SELECT SINGLE cccategory FROM t000 INTO CORRESPONDING FIELDS OF ls_t000
   WHERE mandt = sy-mandt.
IF ls_t000-cccategory = 'P'.
endif.

Clase cl_gui_calendar para F4 de fecha

ver programa ITSQ_CALENDAR, FM F4_DATE & DNO_UI_SUB_F4_DATE

Funciones para desplegar log de errores

DATA: l_dummy(200),
      l_pernr TYPE pernr-pernr.

CALL FUNCTION 'MESSAGES_INITIALIZE'
  EXCEPTIONS
    log_not_active       = 1
    wrong_identification = 2
    OTHERS               = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

l_pernr = '12345678'.
MESSAGE e000(0k) WITH 'Empleado' l_pernr 'invalido' INTO l_dummy.

DATA(count1) = 1.
CALL FUNCTION 'MESSAGE_STORE'
  EXPORTING
    arbgb                  = sy-msgid
    msgty                  = sy-msgty
    msgv1                  = sy-msgv1
    msgv2                  = sy-msgv2
    msgv3                  = sy-msgv3
    msgv4                  = sy-msgv4
    txtnr                  = sy-msgno
    zeile                  = count1
  EXCEPTIONS
    message_type_not_valid = 1
    not_active             = 2.
IF sy-subrc NE 0.
ENDIF.

CALL FUNCTION 'MESSAGES_SHOW'
  EXCEPTIONS
    inconsistent_range = 1
    no_messages        = 2
    OTHERS             = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

FM RMSL325_DISPLAY_MSG_POPUP or METHOD cl_rmsl_message=>display

*   call method for converting external to internal keys...
    CALL METHOD cl_rmsl_srv_data_source=>get_int_from_ext_cl
      EXPORTING
        i_data_source_ext  = <ls_data_source_external>-data_source
        i_data_source_type = l_data_source_type
      IMPORTING
        et_data_source_int = lt_data_source_internal
        et_error           = lt_error.

*   handle errors
    IF cl_rmsl_message=>is_error_containing_cl( lt_error ) = abap_true.
      e_error_flag = abap_true.

      CALL METHOD cl_rmsl_message=>display
        EXPORTING
          it_message = lt_error.

    ENDIF.

Leer mensajes

* copiado de RGJVEA10
  DATA: t_xmesg_old TYPE TABLE OF smesgx WITH HEADER LINE,
        l_count_old TYPE i.

* Check for messages in the message handler and save them
  CALL FUNCTION 'MESSAGES_COUNT'
    IMPORTING
      count  = l_count_old
    EXCEPTIONS
      OTHERS = 4.

  IF l_count_old > 0.
    CALL FUNCTION 'MESSAGE_EXPORT_IMPORT'
      EXCEPTIONS
        empty      = 1
        not_active = 2
        OTHERS     = 3.
    IF sy-subrc <> 0.
    ENDIF.

    IMPORT xmesg TO t_xmesg_old
           FROM MEMORY ID 'TEMP_MESG_EXP_IMP'.
  ENDIF.

crear n° RANDOM

 data l_num type i.
* initialize random number generator
 DATA(rnd) = cl_abap_random_int=>create( seed = CONV i( sy-uzeit )
                                         min  = 0
                                         max  = 1000 ).
 if rnd is bound.
   l_num = rnd->get_next( ).
 endif.

Listado de Pragmas

Reporte ABAP_SLIN_PRAGMAS

Crear Datos SFLIGHT

Sap provee de un modelo de datos, basado en aerolineas, para sus programas demo o training, para generar datos usar programa SAPBC_DATA_GENERATOR

Error: Generic type definitions cannot be used within structures

Evita el siguiente error al declarar un tipo tabla dentro de una estructura:

Dentro de estructuras no se permiten definiciones de tipo genéricas - Generic type definitions cannot be used within structures

* ejemplo 1 (no soportado en clases)
TYPES: BEGIN OF ty_pernr,
         pernr     TYPE p0001-pernr,
         p2003_tab TYPE p2003 OCCURS 0,
       END OF ty_pernr.

* ejemplo 2
TYPES: BEGIN OF ty_pernr_2,
         pernr     TYPE p0001-pernr,
         p2003_tab TYPE TABLE OF p2003 WITH NON-UNIQUE DEFAULT KEY,
       END OF ty_pernr_2.

DATA lt_pernr TYPE TABLE OF ty_pernr.
DATA lt_pernr_2 TYPE TABLE OF ty_pernr_2.
DATA ls_pernr_2 LIKE LINE OF lt_pernr_2.

ls_pernr_2-pernr = '10001469'.

SELECT * INTO CORRESPONDING FIELDS OF TABLE ls_pernr_2-p2003_tab FROM pa2003 WHERE pernr = '10001469'.
APPEND ls_pernr_2 TO lt_pernr_2.
 

Leer STACK

función SYSTEM_CALLSTACK

leer variable de stack

ASSIGN ('(MAIN_PROGRAM)VARIABLE[]') TO <FIELD-SYMBOL>.

 
  DATA ls_t681s TYPE t681s.
  DATA: lw_var(40) TYPE c.
  FIELD-SYMBOLS <fs> TYPE any.

  lw_var = '(SAPMV13A)T681S'.
  ASSIGN (lw_var) TO <fs>.
  IF sy-subrc = 0 AND <fs> IS ASSIGNED.
    MOVE <fs> TO ls_t681s.
  ENDIF.

NUMBER_GET_NEXT - rango de número: asignar siguiente n° (ver trn. SNRO , tabla NRIV )

CALL FUNCTION 'NUMBER_GET_NEXT'
  EXPORTING
    nr_range_nr             = iv_interval_number
    object                  = iv_number_range_name
    toyear                  = iv_fiscal_year
    ignore_buffer           = abap_true
  IMPORTING
    number                  = ev_next_number
  EXCEPTIONS
    interval_not_found      = 1
    number_range_not_intern = 2
    object_not_found        = 3
    quantity_is_0           = 4
    quantity_is_not_1       = 5
    interval_overflow       = 6
    buffer_overflow         = 7
    OTHERS                  = 8.