sábado, 30 de maio de 2026

REGEX - pegando somente o nome do arquivo de um caminho sem extensão

Solução gerado pelo GEMINI


====== Arquivo local

DATA lv_file TYPE string.
lv_file = 'c:\temp\programa\teste.txt'.

" We use [^\\]+ to ensure it only captures characters that are NOT backslashes
DATA(lv_filename) = replace( val   = lv_file
                             regex = `.*\\([^\\]+)\.[^.]+$`
                             with  = `$1` ).

WRITE: / 'Extracted Name:', lv_filename. " Output: teste



====== Arquivo servidor

DATA lv_file TYPE string.
lv_file = '/sap/usr/files/teste.txt'.

" This regex works for BOTH 'c:\temp\teste.txt' and '/sap/usr/teste.txt'
DATA(lv_filename) = replace( val   = lv_file
                             regex = `.*[/\\]([^/\\]+)\.[^.]+$`
                             with  = `$1` ).

WRITE: / 'Extracted Name:', lv_filename. " Output: teste


  • .*\\ : Eats up everything until a backslash.

  • ([^\\]+) : Capture Group 1. Captures 1 or more characters that are NOT a backslash (teste). Because it refuses to capture backslashes, it is forced to only look at the very last part of the path.

  • \.[^.]+$ : Matches the literal dot and the extension at the end of the string.

  • sábado, 16 de maio de 2026

    Workflow - Funções/classes para debug do trigger para execução

     SAP_WAPI_CREATE_EVENT

    SWE_EVENT_CREATE

    SAP_WAPI_START_WORKFLOW

    SAP_WAPI_CREATE_EVENT

    CL_SWF_EVT_EVENT

    terça-feira, 24 de março de 2026

    CALL FUNCTION STARTING NEW TASK - CALLING

    - FUNÇÃO


    FUNCTION ZFM_TESTE_INVOICE_CREATE

    IMPORTING

    VALUE(is_header) TYPE bapi_incinv_create_header

    VALUE(it_tm) TYPE tb_bapi_incinv_create_tm_item

    VALUE(it_item) TYPE tab_bapi_incinv_create_item

    EXPORTING

    VALUE(ev_invoicenumber) TYPE rbkp-belnr

    VALUE(ev_fiscalyear) TYPE rbkp-gjahr

    VALUE(et_return) TYPE bapiret2_t.




    CLEAR: ev_invoicenumber, ev_fiscalyear.

    CLEAR et_return.


    CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE1'

    EXPORTING

    headerdata = is_header

    IMPORTING

    invoicedocnumber = ev_invoicenumber

    fiscalyear = ev_fiscalyear

    TABLES

    itemdata = it_item

    return = et_return

    tm_itemdata = it_tm.



    IF ev_invoicenumber IS NOT INITIAL.


    et_return = VALUE #( ( type = 'S' id = 'ZMM_DRC' number = '000' message_v1 = 'Faturamento criado com sucesso.' ) ).


    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    EXPORTING

    wait = abap_true.


    ELSE.


    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.


    ENDIF.


    ENDFUNCTION.

    ==== Chamada da função

    CALL FUNCTION 'ZFM_TESTE_INVOICE_CREATE' STARTING NEW TASK 'Z_TESTE_INV'

    CALLING zcl_teste_inv=>get_bapi_return ON END OF TASK

    EXPORTING

    is_header = ls_header

    it_tm = lt_tm

    it_item = lt_item.



    WAIT FOR ASYNCHRONOUS TASKS UNTIL gt_return[] is not initial.



    ==== Método CALL BACK


    CLASS-METHOD: get_bapi_return IMPORTING VALUE(p_task) TYPE clike,


    METHOD get_bapi_return.


    RECEIVE RESULTS FROM FUNCTION 'ZFM_TESTE_INVOICE_CREATE'

    IMPORTING

    et_return = gt_return

    ev_invoicenumber = gs_bapi_miro_ret-invoicedocnumber

    ev_fiscalyear = gs_bapi_miro_ret-fiscalyear

    EXCEPTIONS

    communication_failure = 1

    system_failure = 2.


    ENDMETHOD.




    terça-feira, 17 de março de 2026

    RAP - Fixando tamanho de colunas by annotation

    Dentro da annotation UI.lineitem existe a propriedade cssDefault.width definir o tamanho com a unidade  "rem" 


    {

    @UI.hidden : true

    key LogHandle : balloghndl;

    @UI.hidden : true

    key ExternalId : balnrext;

    @UI.lineItem: [{ position: 30 }]

    key logdate : aldate;

    @UI.lineItem: [{ position: 40 }]

    key logtime : altime;

    @UI.lineItem: [{ position: 50, criticality: 'criticality', criticalityRepresentation: #ONLY_ICON }]

    key MessageType : symsgty;

    @UI.lineItem: [{ position: 60 , cssDefault.width: '40rem' }]

    @EndUserText.label: 'Log Message'

    key MessageText : bapi_msg;

    @UI.hidden: true

    criticality : abap.char(1);

    }

    quinta-feira, 22 de janeiro de 2026

    CDS - Verificar se existe somente caractere em campo de texto

    No meu caso no campo de texto do cabeçalho do doc. de material vou splitar o campo para pegar a data e hora mas tem casos q pode ter texto então primeiro uso o REPLACE_REGEXPR para verificar se existe caracter no texto.

    o identificador '\D' significa algum caracter e preencho com "X" caso encontre, retorno somente 1 ocorrência, logo abaixo eu testo o ISCHAR se for "X" tem caracter se não é só número

           replace_regexpr( pcre => '\\D',

                     value => $projection.HeaderTxt,

                     with => 'X' ,

                     result_length => 1 )                             as isChar,

     




    quarta-feira, 21 de janeiro de 2026

    RAP - Passando valor default da entidade principal para CDS Abstract

     


    Campo na entidade principal













    Declaração na CDS Abstract

    @UI.defaultValue: #('ELEMENT_OF_REFERENCED_ENTITY: NumberOfCopies'  )



    segunda-feira, 19 de janeiro de 2026

    TM - Método para Atualização de status do transporte manual

      METHOD tm_shipping_event.
        DATA: lt_stop TYPE /scmtms/t_tor_stop_k.
        CLEAR rs_return.
        DATA(lo_srv_mgr) = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( /scmtms/if_tor_c=>sc_bo_key ).
        DATA(lv_bo_name) = /scmtms/if_tor_c=>sc_bo_name.
        DATA(lv_attname) =  /scmtms/if_tor_c=>sc_query_attribute-root-planning_attributes-tor_id.
    *"Selection Parameters
        DATA(lt_selpar) = VALUE /bobf/t_frw_query_selparam( ( attribute_name = lv_attname
                                                              sign = 'I'
                                                              option = 'EQ'
                                                              low = iv_freight_order ) ).
        DATA lt_key TYPE /bobf/t_frw_key.
        DATA lt_docref TYPE /scmtms/t_tor_root_k.
        "Execução da query
        lo_srv_mgr->query( EXPORTING iv_query_key = /scmtms/if_tor_c=>sc_query-root-planning_attributes
                                     it_selection_parameters = lt_selpar
                                     iv_fill_data = abap_true
                           IMPORTING "eo_message = DATA(lo_message)
                              et_key = lt_key
                              et_data = lt_docref
                              ).
        IF lt_key[] IS INITIAL.
          rs_return = VALUE #( id = 'ZJLTM' type = 'E' number = '002' message_v1 = iv_freight_order
                               message = cl_bs_soa_message_container=>get_msg_text( is_applmsg = VALUE #( type = 'E'
                                                                                                         id    = 'ZJLTM'
                                                                                                         number = '002'
                                                                                                         message_v1 = iv_freight_order
                                                                                                   ) ) ) .
          RETURN.
        ENDIF.
        "get first location
        lo_srv_mgr->retrieve_by_association(
          EXPORTING
                iv_node_key             = /scmtms/if_tor_c=>sc_node-root
                it_key                  = lt_key
                iv_fill_data            = abap_true
                iv_association          = /scmtms/if_tor_c=>sc_association-root-stop_first
          IMPORTING
                eo_message              = DATA(lo_message)
                et_data                 = lt_stop
                et_failed_key           = DATA(lt_failed_key) ).

        rs_return = get_tm_message( lo_message ).
        CHECK rs_return IS INITIAL.
        DATA(lt_stop_key) = VALUE  /bobf/t_frw_key_link( FOR ls_stop IN lt_stop
                                                           ( target_key = ls_stop-key
                                                             source_key = ls_stop-root_key )
                                                          ).
        IF lt_docref[ 1 ]-execution =  c_tm_exec_status.
          rs_return = tm_call_report_event(
                                                EXPORTING
                                                  iv_event    = c_tm_events-ready
                                                  iv_eventdate = iv_eventdate
                                                  it_root_key = lt_key
                                                  it_stop     = lt_stop_key  ).
          CHECK rs_return IS INITIAL.
        ENDIF.
        rs_return = tm_call_report_event(
                                              EXPORTING
                                                iv_event    = iv_event
                                                iv_eventdate = iv_eventdate
                                                it_root_key = lt_key
                                                it_stop     = lt_stop_key ).
        IF rs_return IS INITIAL.
          rs_return = VALUE #( id = 'ZJLTM' type = 'S' number = '003' ) .
        ENDIF.
      ENDMETHOD.