quinta-feira, 15 de dezembro de 2022

Gravando conteúdo de arquivo em tabelas RAWSTRING


Fonte da informação: https://www.fareez.info/blog/how-to-store-files-in-database-in-abap/





 Gravando.

report  zupload.

parameters:
  p_fname type string lower case.

data:
      gs_store_file type zfar_store_file,
      gt_content type standard table of tdline,
      len type i,
      xstr_content type xstring.

start-of-selection.

  "Upload the file to Internal Table
  call function 'GUI_UPLOAD'
    exporting
      filename                = p_fname
      filetype                = 'BIN'
    importing
      filelength              = len
    tables
      data_tab                = gt_content
    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.
    message 'Unable to upload file' type 'E'.
  endif.

  "Convert binary itab to xstring
  call function 'SCMS_BINARY_TO_XSTRING'
    exporting
      input_length       = len
*     FIRST_LINE         = 0
*     LAST_LINE          = 0
   importing
     buffer             = xstr_content
    tables
      binary_tab         = gt_content
   exceptions
     failed             = 1
     others             = 2
            .
  if sy-subrc <> 0.
    message 'Unable to convert binary to xstring' type 'E'.
  endif.

  clear gs_store_file.

  gs_store_file-filename = p_fname.
  gs_store_file-file_content = xstr_content.

  "Insert file into table
  insert zfar_store_file from gs_store_file.

  if sy-subrc is initial.
    message 'Successfully uploaded' type 'S'.
  else.
    message 'Failed to upload' type 'E'.
  endif.

Lendo.

report  zdownload.

parameters:
  p_fname type zfar_store_file-filename lower case,
  p_path type string lower case.


data:
      gs_store_file type zfar_store_file,
      xstr_content type xstring,
      gt_content type standard table of tdline,
      len type i,
      str_fname type string.

start-of-selection.

  select single * from zfar_store_file
    into gs_store_file
    where filename = p_fname.

  xstr_content  = gs_store_file-file_content.

  "Convert xstring/rawstring to binary itab
  call function 'SCMS_XSTRING_TO_BINARY'
    exporting
      buffer        = xstr_content
    importing
      output_length = len
    tables
      binary_tab    = gt_content.
  .

  if sy-subrc <> 0.
    message 'Unable to convert xstring to binary'
      type 'E'.
  endif.

  str_fname = p_fname.

  call function 'GUI_DOWNLOAD'
    exporting
      bin_filesize            = len
      filename                = p_path
      filetype                = 'BIN'
    tables
      data_tab                = gt_content
    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
      others                  = 22.
  if sy-subrc <> 0.
    message 'Unable to download file from SAP'
      type 'E'.
  endif.





quarta-feira, 26 de outubro de 2022

Salvando arquivos utilizando o GOS - Business document

Utilizado para salvar um anexo dentro de uma integração PI/PO.

Criei um programa teste baseado nesse link

https://sapintegrationhub.com/abap/attach-any-file-sap-business-document-gos/

O programa basicamente seleciona um arquivo qualquer no PC e grava no formato GOS, no caso da integração é so pular alguns passos, já que o anexo em si já vem em formato binário X64.

Incluí nesse programa a rotina de gravar e de importar o arquivo do GOS.

Arquivos gravados podem ser consultados na tabela SOOD somente dados de informação 

Imaginei que teria que criar um objeto(BO) na transação SWO1 mas não é necessário, fiz um teste criando no objeto VBRK mesmo para ver. no meu caso vou usar o objeto VBAK vc pode consultar na tabela TOBJB

**** INCLUDE ZSZKF01 **

*&---------------------------------------------------------------------*
*& Include          ZSZKF01
*&---------------------------------------------------------------------*
*&amp;---------------------------------------------------------------------*
*&amp; Include          ZATTACH_FILE_FORMS
*&amp;---------------------------------------------------------------------*
*&amp;---------------------------------------------------------------------*
*&amp; Form OPEN_FILE_DIALOG
*&amp;---------------------------------------------------------------------*
*&amp; text
*&amp;---------------------------------------------------------------------*
*&amp; --&gt;  p1        text
*&amp; &lt;--  p2        text
*&amp;---------------------------------------------------------------------*
FORM open_file_dialog USING p_path.
  DATA: ls_file_table LIKE LINE OF gt_file_table,
        lv_rc         TYPE i.
  CLEAR p_path.
  REFRESH: gt_file_table.
  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title     = 'Select File'
      default_filename = '*.pdf'
      multiselection   = 'X'
    CHANGING
      file_table       = gt_file_table
      rc               = lv_rc.
  READ TABLE gt_file_table INDEX 1 INTO ls_file_table.
  p_path = ls_file_table-filename.
ENDFORM.
*&amp;---------------------------------------------------------------------*
*&amp; Form UPLOAD_FILE
*&amp;---------------------------------------------------------------------*
*&amp; text
*&amp;---------------------------------------------------------------------*
*&amp; --&gt;  p1        text
*&amp; &lt;--  p2        text
*&amp;---------------------------------------------------------------------*
FORM upload_file USING p_path.
  DATA:    lv_len TYPE i.
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename   = p_path
      filetype   = 'BIN'
    IMPORTING
      filelength = lv_len
    TABLES
      data_tab   = gt_content.
  PERFORM exception.
ENDFORM.
*&amp;---------------------------------------------------------------------*
*&amp; Form CONVERT_TO_BIN
*&amp;---------------------------------------------------------------------*
*&amp; text
*&amp;---------------------------------------------------------------------*
*&amp; --&gt;  p1        text
*&amp; &lt;--  p2        text
*&amp;---------------------------------------------------------------------*
FORM convert_to_bin .

  CALL FUNCTION 'SO_CONVERT_CONTENTS_BIN'
    EXPORTING
      it_contents_bin = gt_content[]
    IMPORTING
      et_contents_bin = gt_content[].
  PERFORM exception.
ENDFORM.
*&amp;---------------------------------------------------------------------*
*&amp; Form GET_FOLDER_ROOT_ID
*&amp;---------------------------------------------------------------------*
*&amp; text
*&amp;---------------------------------------------------------------------*
*&amp; --&gt;  p1        text
*&amp; &lt;--  p2        text
*&amp;---------------------------------------------------------------------*
FORM get_folder_root_id .
  CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
    EXPORTING
      region    = 'B'
    IMPORTING
      folder_id = gs_fol_id
    EXCEPTIONS
      OTHERS    = 1.
  PERFORM exception.
ENDFORM.
*&amp;---------------------------------------------------------------------*
*&amp; Form SAP_OFFICE_OBJECT
*&amp;---------------------------------------------------------------------*
*&amp; text
*&amp;---------------------------------------------------------------------*
*&amp; --&gt;  p1        text
*&amp; &lt;--  p2        text
*&amp;---------------------------------------------------------------------*
FORM sap_office_object USING p_vbeln.
  DATA:
    ls_obj_data TYPE sood1,
    lt_objhead  TYPE STANDARD TABLE OF soli.

  ls_obj_data-objsns   = 'O'.
  ls_obj_data-objla    = sy-langu.
  ls_obj_data-objdes   = gv_fname.
  ls_obj_data-file_ext = gv_ext.
  ls_obj_data-objlen   = lines( gt_content ) * 255.
  CONDENSE ls_obj_data-objlen.
  CALL FUNCTION 'SO_OBJECT_INSERT'
    EXPORTING
      folder_id             = gs_fol_id
      object_type           = 'EXT'
      object_hd_change      = ls_obj_data
    IMPORTING
      object_id             = gs_obj_id
    TABLES
      objhead               = lt_objhead
      objcont               = gt_content
    EXCEPTIONS
      active_user_not_exist = 35
      folder_not_exist      = 6
      object_type_not_exist = 17
      owner_not_exist       = 22
      parameter_error       = 23
      OTHERS                = 1000.
  PERFORM exception.
ENDFORM.
*&amp;---------------------------------------------------------------------*
*&amp; Form CREATE_BINARY_RELATION
*&amp;---------------------------------------------------------------------*
*&amp; text
*&amp;---------------------------------------------------------------------*
*&amp; --&gt;  p1        text
*&amp; &lt;--  p2        text
*&amp;---------------------------------------------------------------------*
FORM create_binary_relation USING p_vbeln p_botype.
  DATA:
    ls_folmem_k TYPE sofmk,
    ls_note     TYPE borident,
    lv_ep_note  TYPE borident-objkey,
    ls_object   TYPE borident.
  ls_object-objkey = p_vbeln.
  ls_object-objtype = p_botype.
  ls_note-objtype   = 'MESSAGE'.
  CONCATENATE gs_fol_id-objtp gs_fol_id-objyr gs_fol_id-objno gs_obj_id-objtp gs_obj_id-objyr gs_obj_id-objno INTO ls_note-objkey.
  CALL FUNCTION 'BINARY_RELATION_CREATE_COMMIT'
    EXPORTING
      obj_rolea    = ls_object
      obj_roleb    = ls_note
      relationtype = 'ATTA'
    EXCEPTIONS
      OTHERS       = 1.
  PERFORM exception.
ENDFORM.
*&amp;---------------------------------------------------------------------*
*&amp; Form SPLIT_FILE_PATH
*&amp;---------------------------------------------------------------------*
*&amp; text
*&amp;---------------------------------------------------------------------*
*&amp;      --&gt; P_PATH
*&amp;      --&gt; P_EXT
*&amp;      --&gt; P_FNAME
*&amp;---------------------------------------------------------------------*
FORM split_file_path  USING    p_path.
  DATA: lv_filename TYPE pcfile-path.
  CHECK p_path IS NOT INITIAL.
  lv_filename = p_path.
  CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
    EXPORTING
      complete_filename = lv_filename
*     CHECK_DOS_FORMAT  =
    IMPORTING
*     DRIVE             =
      extension         = gv_ext
*     NAME              =
      name_with_ext     = gv_fname
*     PATH              =
    EXCEPTIONS
      invalid_drive     = 1
      invalid_extension = 2
      invalid_name      = 3
      invalid_path      = 4
      OTHERS            = 5.
  PERFORM exception.
ENDFORM.
*&amp;---------------------------------------------------------------------*
*&amp; Form EXCEPTION
*&amp;---------------------------------------------------------------------*
*&amp; text
*&amp;---------------------------------------------------------------------*
*&amp; --&gt;  p1        text
*&amp; &lt;--  p2        text
*&amp;---------------------------------------------------------------------*
FORM exception .
  IF sy-subrc <> 0.
    MESSAGE ID     sy-msgid
          TYPE   sy-msgty
          NUMBER sy-msgno
          WITH   sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form import_gos
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM import_gos USING p_key p_path p_botype.

  DATA : wa_object       TYPE sibflporb,
         int_rel_options TYPE obl_t_relt,
         wa_rel_options  TYPE obl_s_relt,
         int_links       TYPE obl_t_link,
         wa_links        TYPE obl_s_link.
  wa_rel_options-low = 'ATTA'. "" Attachemnts
  wa_rel_options-sign = 'I'.
  wa_rel_options-option = 'EQ'.
  APPEND wa_rel_options TO int_rel_options.
  wa_object-instid = p_key.
  wa_object-typeid = p_botype. "" PR
  wa_object-catid  = 'BO'. "" Business Object
  REFRESH int_links[].
  TRY.
      CALL METHOD cl_binary_relation=>read_links_of_binrels
        EXPORTING
          is_object           = wa_object          " Start object
          it_relation_options = int_rel_options    " Link Types
          ip_role             = 'GOSAPPLOBJ'       " Role type
        IMPORTING
          et_links            = int_links.         " Table with Relationship Records
    CATCH cx_obl_parameter_error. " Incorrect Calling of Interface
    CATCH cx_obl_internal_error.  " Internal Error of Relationship Service
    CATCH cx_obl_model_error.     " Error with Model Roles
  ENDTRY.


  DATA : lv_doc_id      TYPE sofolenti1-doc_id,
         int_cont_bin   TYPE TABLE OF solisti1,
         int_cont_solix TYPE TABLE OF solix,
         wa_doc_data    TYPE sofolenti1.
  LOOP AT int_links INTO wa_links.
    lv_doc_id = wa_links-instid_b.
    REFRESH int_cont_bin[].
    REFRESH int_cont_solix[].
    CALL FUNCTION 'SO_DOCUMENT_READ_API1'
      EXPORTING
        document_id                = lv_doc_id
      IMPORTING
        document_data              = wa_doc_data
      TABLES
        contents_hex               = int_cont_solix
        object_content             = int_cont_bin
      EXCEPTIONS
        document_id_not_exist      = 1
        operation_no_authorization = 2
        x_error                    = 3
        OTHERS                     = 4.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.

    DATA: lv_lines    TYPE char20,
          lv_doc_size TYPE i,
          lv_xstring  TYPE xstring.
    IF int_cont_solix IS NOT INITIAL.
      IF wa_doc_data-obj_type = 'TXT'.
        lv_lines = lines( int_cont_solix ) * 255.
        SHIFT lv_lines LEFT DELETING LEADING ' '.
        lv_doc_size = lv_lines.
      ENDIF.
      "" Convert the binary data to Xstring
      CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
        EXPORTING
          input_length = lv_doc_size
        IMPORTING
          buffer       = lv_xstring
        TABLES
          binary_tab   = int_cont_solix
        EXCEPTIONS
          failed       = 1
          OTHERS       = 2.
      IF sy-subrc <> 0.
* Implement suitable error handling here
      ENDIF.
    ELSE.
      CALL FUNCTION 'SO_SOLITAB_TO_SOLIXTAB'
        EXPORTING
          ip_solitab  = int_cont_bin
        IMPORTING
          ep_solixtab = int_cont_solix.
*
      IF wa_doc_data-obj_type = 'TXT'.
        lv_lines = lines( int_cont_solix ) * 255.
        SHIFT lv_lines LEFT DELETING LEADING ' '.
        lv_doc_size = lv_lines.
      ENDIF.
*
      "" Convert the binary data to Xstring
      CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
        EXPORTING
          input_length = lv_doc_size
        IMPORTING
          buffer       = lv_xstring
        TABLES
          binary_tab   = int_cont_solix
        EXCEPTIONS
          failed       = 1
          OTHERS       = 2.
      IF sy-subrc <> 0.
* Implement suitable error handling here
      ENDIF.
      DATA:    lv_len TYPE i.
    ENDIF.
      data l_filename type string.
      CONCATENATE P_PATH wa_doc_data INTO l_filename SEPARATED BY '\'.
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
*         BIN_FILESIZE                    =
          filename = l_filename
          filetype = 'BIN'
*         APPEND   = ' '
*         WRITE_FIELD_SEPARATOR           = ' '
*   IMPORTING
*         FILELENGTH                      =
        TABLES
          data_tab = int_cont_solix.

  ENDLOOP.
ENDFORM.

******* PROGRAMA ZSZK

REPORT zszk.

DATA: gt_file_table TYPE filetable,   "Uploaded file information
      gt_content    TYPE soli_tab,    "Uploaded files content
      gs_fol_id     TYPE soodk,       "Folder ID
      gs_obj_id     TYPE soodk.       "Object ID
DATA: gv_ext   TYPE sood1-file_ext,   "File extension
      gv_fname TYPE sood1-objdes.     "File name
INCLUDE zszkf01.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
  PARAMETERS: p_path  TYPE string OBLIGATORY.                    "File path
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-002.
  PARAMETERS: p_botype TYPE tojtb-name OBLIGATORY DEFAULT 'ZSZK', "Business obj type
              "p_doc_no TYPE vbeln OBLIGATORY.     "Business document number
              p_key    LIKE swotobjid-objkey,
              p_imp    AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK b2.

INITIALIZATION.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
  PERFORM open_file_dialog USING p_path.            "Open file upload dialog box

START-OF-SELECTION.
  IF p_imp IS INITIAL.
    PERFORM upload_file USING p_path.                  "Upload file
    PERFORM convert_to_bin.                      "Convert file content to BIN
    PERFORM get_folder_root_id.                  "Get folder ID
    PERFORM split_file_path USING p_path.         "Find file extension and file name
    PERFORM sap_office_object USING p_KEY.          "Create SAP office object
    PERFORM create_binary_relation USING p_KEY p_botype. "Link office object and ment
  ELSE.
    PERFORM import_gos USING p_key p_path p_botype.
  ENDIF.


sexta-feira, 22 de julho de 2022

Rotina gravação / visualização de LOG (SLG1)

Nova forma de fazer.

*============ LEITURA DE LOG 

METHOD get_log.


    TRY.

        DATA(lo_filter) = cl_bali_log_filter=>create(

                                          )->set_create_info( user = sy-uname

                                          )->set_descriptor( object = 'ZSD_INDINT'

                                                             subobject = 'LOG_PROC'

                                                             external_id = CONV balnrext( iv_id ) ).


        DATA(lv_data_final) = utclong_current( ).

        DATA(lv_data_inicio) = utclong_add( val = lv_data_final

                                                       days = '30-' ).

        lo_filter->set_time_interval( start_time = lv_data_inicio

                                      end_time = lv_data_final ).


        lo_filter->set_maximum_log_number( max_log_number = 5 ).


        DATA(lo_log_table) = cl_bali_log_db=>get_instance( )->load_logs_w_items_via_filter( filter = lo_filter ).


      CATCH cx_bali_runtime INTO DATA(l_exception).

        RETURN.


    ENDTRY.


    LOOP AT lo_log_table INTO DATA(lr_log).


      " Get log header and output attributes of the header

      DATA(lv_header) = lr_log->get_header( ).


      APPEND INITIAL LINE TO rt_return ASSIGNING FIELD-SYMBOL(<lf_return>).

      <lf_return> = VALUE #( id = 'ZSD' type = 'I' number = '000'

                             message_v1 = |Data/hora log:|

                             message_v2 = lv_header->log_timestamp ).



      " Get all items and output some data which exist in all item categories

      DATA(lt_item_table) = lr_log->get_all_items( ).

      LOOP AT lt_item_table INTO DATA(lr_item_entry).


        " Output attributes which are specific for messages and exceptions

        IF lr_item_entry-item->category = if_bali_constants=>c_category_message.


          DATA(lo_message_ref) = CAST if_bali_message_getter( lr_item_entry-item ).

          APPEND INITIAL LINE TO rt_return ASSIGNING <lf_return>.

          <lf_return> = VALUE #( id = lo_message_ref->id

                                 type = lo_message_ref->severity

                                 number = lo_message_ref->number

                                 message_v1 = lo_message_ref->variable_1

                                 message_v2 = lo_message_ref->variable_2

                                 message_v3 = lo_message_ref->variable_3

                                 message_v4 = lo_message_ref->variable_4

                                 message = lo_message_ref->get_message_text( ) ).


        ENDIF.


      ENDLOOP.


    ENDLOOP.


  ENDMETHOD.





==========================================================
>>>>>>>>>>>>>>   GRAVAÇÃO
==========================================================

 FORM f_grava_log USING fu_bapiret2 TYPE bapiret2_t

              CHANGING fc_lognum TYPE balognr.

  DATA:
    l_log_handle   TYPE balloghndl,
    ls_log         TYPE bal_s_log,
    ls_log_message TYPE bal_s_msg,
    lt_log_handle  TYPE bal_t_logh,
    lt_log_num     TYPE bal_t_lgnm.

  CLEAR:
    lt_log_handle,
    lt_log_num.

  FIELD-SYMBOLS <lt_ldat> TYPE ANY TABLE.

  IF fc_lognum IS NOT INITIAL.
    PERFORM f_delete_log USING fc_lognum.
  ENDIF.

*--------------------------------------------------------------------*
* Set BAL LOG object
*--------------------------------------------------------------------*
  ls_log-object    gc_log_obj.
  ls_log-subobject gc_log_subobj.
  ls_log-aldate    sy-datum.
  ls_log-altime    sy-uzeit.
  ls_log-aluser    sy-uname.

*--------------------------------------------------------------------*
* Create new BAL LOG
*--------------------------------------------------------------------*
  CALL FUNCTION 'BAL_LOG_CREATE'
    EXPORTING
      i_s_log                 ls_log
    IMPORTING
      e_log_handle            l_log_handle
    EXCEPTIONS
      log_header_inconsistent 1
      OTHERS                  2.

*--------------------------------------------------------------------*
* Add messages to the LOG
*--------------------------------------------------------------------*
  LOOP AT fu_bapiret2 INTO DATA(ls_return)
                      WHERE type 'E'.

    ls_log_message-msgty ls_return-type.
    ls_log_message-msgid ls_return-id.
    ls_log_message-msgno ls_return-number.
    ls_log_message-msgv1 ls_return-message_v1.
    ls_log_message-msgv2 ls_return-message_v2.
    ls_log_message-msgv3 ls_return-message_v3.
    ls_log_message-msgv4 ls_return-message_v4.

    CALL FUNCTION 'BAL_LOG_MSG_ADD'
      EXPORTING
        i_log_handle     l_log_handle
        i_s_msg          ls_log_message
      EXCEPTIONS
        log_not_found    1
        msg_inconsistent 2
        log_is_full      3
        OTHERS           4.

  ENDLOOP.

*--------------------------------------------------------------------*
* Save the LOG to the database
*--------------------------------------------------------------------*
  APPEND l_log_handle TO lt_log_handle.

  "Elimino log sem o objeto subobjeto na função.
  ASSIGN ('(SAPLSBAL)G-T_LDAT[]'TO <lt_ldat>.
  IF sy-subrc 0.

    DELETE <lt_ldat>
     WHERE ('LOG-OBJECT = SPACE').

  ENDIF.

  CALL FUNCTION 'BAL_DB_SAVE'
    EXPORTING
      i_client         sy-mandt
      i_save_all       abap_true
      i_t_log_handle   lt_log_handle
    IMPORTING
      e_new_lognumbers lt_log_num
    EXCEPTIONS
      log_not_found    1
      save_not_allowed 2
      numbering_error  3
      OTHERS           4.

  IF lt_log_num[] IS NOT INITIAL.
    fc_lognum lt_log_num[ lineslt_log_num ]-lognumber.
  ENDIF.


ENDFORM.


==========================================================
>>>>>>>>>>>>>>   VISUALIZAÇÃO
==========================================================

FORM f_show_log USING fu_lognum TYPE balognr.

  DATA:
    lt_log_header   TYPE balhdr_t,
    ls_log_filter   TYPE bal_s_lfil,
    ls_display_prof TYPE bal_s_prof.

  CLEAR:
    lt_log_header,
    ls_log_filter,
    ls_display_prof.

  CHECK fu_lognum IS NOT INITIAL.

  APPEND INITIAL LINE TO ls_log_filter-lognumber  ASSIGNING FIELD-SYMBOL(<fs_log_num>).
  <fs_log_num>-sign   'I'.
  <fs_log_num>-option 'EQ'.
  <fs_log_num>-low    fu_lognum.
  APPEND INITIAL LINE TO ls_log_filter-object     ASSIGNING FIELD-SYMBOL(<fs_obj>).
  <fs_obj>-sign   'I'.
  <fs_obj>-option 'EQ'.
  <fs_obj>-low    gc_log_obj.
  APPEND INITIAL LINE TO ls_log_filter-subobject  ASSIGNING FIELD-SYMBOL(<fs_subobj>).
  <fs_subobj>-sign   'I'.
  <fs_subobj>-option 'EQ'.
  <fs_subobj>-low    gc_log_subobj.

  CALL FUNCTION 'BAL_DB_SEARCH'
    EXPORTING
      i_s_log_filter     ls_log_filter
    IMPORTING
      e_t_log_header     lt_log_header
    EXCEPTIONS
      log_not_found      1
      no_filter_criteria 2.

  IF sy-subrc <> 0.
    MESSAGE i030 DISPLAY LIKE 'E'.
  ENDIF.

  CALL FUNCTION 'BAL_DB_LOAD'
    EXPORTING
      i_t_log_header     lt_log_header
    EXCEPTIONS
      no_logs_specified  1
      log_not_found      2
      log_already_loaded 3.


  CALL FUNCTION 'BAL_DSP_PROFILE_POPUP_GET'
    IMPORTING
      e_s_display_profile ls_display_prof
    EXCEPTIONS
      OTHERS              1.

  IF sy-subrc IS NOT INITIAL.
    MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
      DISPLAY LIKE 'I'.
  ENDIF.

* Display in ALV popup
  ls_display_prof-use_grid          abap_true.
  ls_display_prof-disvariant-report sy-repid.
  ls_display_prof-disvariant-handle 'LOG'.
  ls_display_prof-pop_adjst  abap_true.

  CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
    EXPORTING
*     i_t_log_handle      = lt_log_handle
      i_s_display_profile ls_display_prof
    EXCEPTIONS
      OTHERS              1.

  IF sy-subrc IS NOT INITIAL.
    MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
      DISPLAY LIKE 'I'.
  ENDIF.

  READ TABLE lt_log_header INTO DATA(ls_log_headerINDEX 1.

* Free messages from the memory
  CALL FUNCTION 'BAL_LOG_REFRESH'
    EXPORTING
      i_log_handle  ls_log_header-log_handle
    EXCEPTIONS
      log_not_found 1
      OTHERS        2.

  IF sy-subrc IS NOT INITIAL.
    MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
      DISPLAY LIKE 'I'.
  ENDIF.

ENDFORM.


==========================================================
>>>>>>>>>>>>>>   ELIMINA LOG
==========================================================

*&---------------------------------------------------------------------*
*& Form F_DELETE_LOG
*&---------------------------------------------------------------------*
FORM f_delete_log USING fu_lognum TYPE balognr.

  DATAlt_log_del TYPE balhdr_t.

  SELECT *
    INTO TABLE lt_log_del
    FROM balhdr
   WHERE lognumber EQ fu_lognum.

  CHECK sy-subrc 0.

  CALL FUNCTION 'BAL_DB_DELETE'
    EXPORTING
      i_t_logs_to_delete lt_log_del
      i_package_size     100
      i_in_update_task   abap_true
    EXCEPTIONS
      no_logs_specified  1
      OTHERS             2.

ENDFORM.