четверг, 31 марта 2016 г.

Regex. Пример

Исходный текст:
*        SCRIPT_ID     = '1'.
*        WARH_ID       = 'ZMM_D85S'.
*        SCRIPT_NAME   = 'Проверка на заполненность ДСО'.

    result_table =
        select 'ERR' as result
        from "/BIC/AZMM_D85S00"
        where "/BIC/ZPER_DT" = to_char (add_days(current_date, -1), 'YYYYMM') || '01'
        having count(*) <= 100;
    

FIND FIRST OCCURRENCE OF REGEX `result_table\s*=\s*(.*);`
        IN l_string
        IGNORING CASE
        SUBMATCHES r_script. " Весь текст селекта

    FIND FIRST OCCURRENCE OF REGEX `SCRIPT_ID\s*=\s*'([^']*)`
        IN l_string
        IGNORING CASE
        SUBMATCHES r_script_id. " ZMM_D85S

вторник, 22 марта 2016 г.

Как вытащить список методов у любого класса?

CL_OO_OBJECT=>GET_INSTANCE( <имя класса> )->GET_METHODS( PUBLIC_METHODS_ONLY = 'X' )


Динамически получаем тип выходной таблицы метода:
  TRY.
      pcl_oo_object cl_oo_object=>get_instance(
        p_class_name
        ).

      p_result_table_type_name pcl_oo_object->get_parameter_type(
          cpdname p_cpdname
          sconame 'RESULT_TABLE'
        )-type.

      p_result_table_type |{ class_name }=>{ p_result_table_type_name }|.

    CATCH cx_root INTO px_exc.
      pv_str px_exc->get_text).
      MESSAGE pv_str TYPE 'I'.
  ENDTRY.

четверг, 10 марта 2016 г.

Exception condition "DP_OUT_OF_MEMORY" triggered

Дамп при загрузке файлов через GUI_UPLOAD.

GUI 7.40 sp5, но дамп всё равно ловится.

Помогло полностью перезапустить SAP Logon.




Категория              Программная ошибка ABAP
ДинамОшибка            RAISE_EXCEPTION
АВАР-прогр.            ZNN_LOGISTIC_CENTER_XML_PARSER
Прикладной компонент   Не присвоено
Дата и время           09.03.2016 16:45:46


 Краткий текст
     Exception condition "DP_OUT_OF_MEMORY" triggered

 Что произошло?
     The current ABAP program has encountered an unexpected situation.

 Что Вы можете сделать?
     Note down which actions and inputs caused the error.

     To process the problem further, contact you SAP system
     administrator.

     Using Transaction ST22 for ABAP Dump Analysis, you can look
     at and manage termination messages, and you can also
     keep them for a long time.

 Анализ ошибки
     A RAISE statement in program "CL_GUI_FRONTEND_SERVICES======CP" has raised
      exception condition "DP_OUT_OF_MEMORY".
     Since the exception was not caught by a program higher up in the call
     hierarchy, processing was terminated.

     Short text for exception condition:
     You can find detailed documentation about the exception condition in
     transaction SE37 (Function Library). You can find the name of the
     function module called from the display of active calls.

пятница, 4 марта 2016 г.

Нарезаем string на строки определённой длины

DATA:
    lo_conv TYPE REF TO cl_abap_conv_in_ce,
lt_xml_result TYPE STANDARD TABLE OF char2048,
l_string      TYPE string,
l_data        TYPE xstring.

  lo_conv cl_abap_conv_in_ce=>create(
    EXPORTING encoding 'UTF-8'
      input l_data
      ).

  WHILE lo_conv->is_at_end EQ abap_false.
    CALL METHOD lo_conv->read
      EXPORTING
        n    2048
      IMPORTING
        data l_string.

    APPEND l_string TO lt_xml_result.
  ENDWHILE.

среда, 2 марта 2016 г.

Вывод содержимого любой таблицы в xml


report ZTST.

types:
  begin of ts_output,
    id type i,
    tab type string,
    descr type string,
    data type ref to data,
  end of ts_output,
  tt_output type table of ts_output
.

data:
  gv_tabname type tabname,
  gt_output type tt_output,
  gv_result_html type string.

select-options:
  so_tabnm for gv_tabname no intervals
.

start-of-selection.
perform f_get_data
  using so_tabnm[]
  changing gt_output
.

perform f_format_table_html
  using gt_output "it_tab
  changing gv_result_html "cv_html
.


gv_result_html |<meta charset="utf-8"><body>{ gv_result_html }</body>|.

data:
  lt_export type table of string.

append gv_result_html to lt_export.

call method cl_gui_frontend_services=>gui_download
  exporting
*    bin_filesize              =
    filename                  'C:\Temp\Demo.html'
    filetype                  'ASC'
    codepage                  '1504'
    write_bom                 ''
  changing
    data_tab                  lt_export
  .

if sy-subrc <> 0.
* Implement suitable error handling here
endif.



**********************************************************************
form f_get_data
  using i_tabname type any table
  changing ct_output type tt_output

.

  data:
    lo_result type ref to cl_sql_result_set,
    lo_tab_handler type ref to cl_abap_tabledescr,
    lo_res type ref to data,
    lv_sql type string
  .

  field-symbols:
    <lfs_tabname_range> type any,
    <lfs_tabname> type any
  .


  loop at i_tabname
    assigning <lfs_tabname_range>.

    assign component 'LOW'
      of structure <lfs_tabname_range>
      to <lfs_tabname>
    .

    lv_sql |select * from "{ <lfs_tabname> }"|.

    lo_result cl_sql_connection=>get_connection(
    )->create_statement(
    )->execute_query(
      lv_sql
    ).


    lo_tab_handler cl_abap_tabledescr=>get(
      p_line_type cast cl_abap_datadescr(
        cl_abap_structdescr=>describe_by_data_ref(
          lo_result->get_struct_ref(
            lo_result->get_metadata)
          )
        )
      )
    )
    .

    create data lo_res type handle lo_tab_handler.

    lo_result->set_param_table(
      lo_res
    ).

    lo_result->next_package).
    lo_result->close).

    append value #(
      id sy-tabix
      tab <lfs_tabname>
      descr |Содержимое таблицы { <lfs_tabname> }|
      data lo_res
    to ct_output.

  endloop.


endform.
**********************************************************************

**********************************************************************
form f_format_table_html
  using it_tab type any table
  changing cv_html type string
.

  data:
    lt_fields type cl_abap_structdescr=>component_table,
    lv_class_name type string
  .

  data:
    lv_cell_val type string,
    lv_row_val type string
  .

  field-symbols:
    <lfs_field> like line of lt_fields,
    <lfs_table_row> type any,
    <lfs_data> type any,
    <lfs_data_as_tab> type any table
  .


  lt_fields cast cl_abap_structdescr(
    cast cl_abap_tabledescr(
      cl_abap_tabledescr=>describe_by_data(
        it_tab
      )
    )->get_table_line_type)
  )->get_components(
  ).


  cv_html '<table border="1px">'.

  loop at it_tab
    assigning <lfs_table_row>.

    lv_row_val '<tr>'.

    loop at lt_fields
      assigning <lfs_field>.

      assign component <lfs_field>-name
        of structure <lfs_table_row>
        to <lfs_data>
      .

      if <lfs_field>-name 'DATA'.

        assign <lfs_data>->to <lfs_data_as_tab>.

        perform f_format_table_html
          using <lfs_data_as_tab>
          changing lv_cell_val
        .

        lv_cell_val |<details><summary>Table data</summary>|
          && |<p>{ lv_cell_val }</p></details>|.

        else.
          lv_cell_val <lfs_data>.

      endif.

      lv_row_val lv_row_val
        && |<td>{ lv_cell_val }</td>|.

    endloop.

    lv_row_val |{ lv_row_val }</tr>|.
    cv_html cv_html
      && cl_abap_char_utilities=>newline
      && lv_row_val
    .

  endloop.

  cv_html |{ cv_html }</table>|.

*  cl_demo_output=>display_html( cv_html ).
endform.
**********************************************************************