quinta-feira, 29 de fevereiro de 2024

RAP - Tratar Autorizações para funções especificas

 Deixar como global.











Nesse caso se eu tenho um objeto de autorização para criar/modificar e exibir. Se estiver como exibir eu desativo os botões, no caso tenho o botão standard e outro customizado.

















Pode ser assim tbm.
https://github.com/SAP-samples/abap-platform-rap-opensap/blob/main/week3/unit6.md








































===== EXEMPLO FUNCIONAL USANDO A FORMA DA SAP
-- Detalhe, testando pelo eclipse pelo binding não funciona, somente depois do deploy no ambiente do cliente


METHOD get_instance_authorizations.

    DATA lv_exibir TYPE abap_bool.

    READ ENTITIES OF ZPP_I_OrdensEncFrangoCorte IN LOCAL MODE
     ENTITY OrdemProd ALL FIELDS
     WITH CORRESPONDING #( keys )
     RESULT DATA(lt_ordens) FAILED failed.

    CHECK lt_ordens IS NOT INITIAL.

    LOOP AT lt_ordens INTO DATA(lw_ordens).

      CLEAR lv_exibir.

      AUTHORITY-CHECK OBJECT 'ZPP_ENCFRC'
       ID 'ACTVT' FIELD '02'
       ID 'WERKS' FIELD lw_ordens-werks.

      IF sy-subrc <> 0.

        AUTHORITY-CHECK OBJECT 'ZPP_ENCFRC'
         ID 'ACTVT' FIELD '03'
         ID 'WERKS' FIELD lw_ordens-werks.

        IF sy-subrc <> 0.
          APPEND VALUE #( %tky        = lw_ordens-%tky
                          %msg        = new_message_with_text( severity = if_abap_behv_message=>severity-error
                                        text   = |Sem autorização para centro: { lw_ordens-werks }| )
                        ) TO reported-ordemprod.
        ENDIF.

        lv_exibir = abap_true.

      ENDIF.

      APPEND VALUE #( %tky = lw_ordens-%tky
                      %update = COND #( WHEN lv_exibir = abap_true THEN if_abap_behv=>auth-unauthorized ELSE if_abap_behv=>auth-allowed )
                      %action-ExecOrdem = COND #( WHEN lv_exibir = abap_true THEN if_abap_behv=>auth-unauthorized ELSE if_abap_behv=>auth-allowed )
                      %action-refreshTela = COND #( WHEN lv_exibir = abap_true THEN if_abap_behv=>auth-unauthorized ELSE if_abap_behv=>auth-allowed )
                ) TO result.

    ENDLOOP.

  ENDMETHOD.









RAP - Desabilitando campos no object page nos eventos CREATE/UPDATE

 Na verdade testei somente no UPDATE mas acho q funcion no CREATE tbm.

A validação de dados de entrada não é feito qdo se clica no botão de update, é feita antes.. eu me bati um monte para fazer essa validação












sábado, 17 de fevereiro de 2024

RAP - Facets(Object list page) - Várias formas

 Adicionando campos no cabeçalho.



Resultado











========================================

Adionando abas 




Resultado



















=================================
Adicionando outra lista no object pages
- Primeiro passo criar uma entidade da lista que vai ser criado, no meu caso os impostos de um item da NF

@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Impostos '
define root view entity ZI_Impostos
  as select from I_BR_NFTax

{

  key BR_NotaFiscal               as Docnum,
  key BR_NotaFiscalItem           as Itmnum,
  key BR_TaxType                  as Taxtype,
  key TaxGroup                    as TaxGrp,
      @Semantics.amount.currencyCode: 'Currency'
      BR_NFItemBaseAmount         as Base,
      BR_NFItemTaxRate            as Rate,
      @Semantics.amount.currencyCode: 'Currency'
      BR_NFItemTaxAmount          as TaxValue,
      BR_NFItemExcludedBaseAmount as ExcBase,
      @Semantics.amount.currencyCode: 'Currency'
      BR_NFItemOtherBaseAmount    as OthBas,
      SalesDocumentCurrency       as Currency

}

Criei uma projection view tbm mas não sei se é necessário

@EndUserText.label: 'Impostos da Nota Fiscal Importação (Projection)'
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.allowExtensions: true
define root view entity ZC_Impostos
  provider contract transactional_query
  as projection on ZI_Impostos
{
  key Docnum,
  key Itmnum,
  key Taxtype,
  key TaxGrp,
      Base,
      Rate,
      TaxValue,
      ExcBase,
      OthBas,
      Currency
}

Criei um METADATA
@Metadata.layer: #CORE
annotate entity ZC_Impostos with
{
  @UI:{ lineItem: [{ position: 10 }] }
  @EndUserText.label: 'Tipo Imposto'
  Taxtype;
  @UI:{ lineItem: [{ position: 20 }] }
  @EndUserText.label: 'Grupo Imposto'
  TaxGrp;
  @UI:{ lineItem: [{ position: 30 }] }
  @EndUserText.label: 'Base'
  Base;
  @UI:{ lineItem: [{ position: 40 }] }
  @EndUserText.label: 'Taxa'
  Rate;
  @UI:{ lineItem: [{ position: 50 }] }
  @EndUserText.label: 'Valor Imposto'
  TaxValue;
  @UI:{ lineItem: [{ position: 60 }] }
  @EndUserText.label: 'Base excluída'
  ExcBase;
  @UI:{ lineItem: [{ position: 70 }] }
  @EndUserText.label: 'Outras Bases'
  OthBas;
  @UI:{ lineItem: [{ position: 80 }] }
    @EndUserText.label: 'Moeda'
  Currency;

}

Fiz a associação a minha projection principal 
@EndUserText.label: 'Dados gestão importação (projection)'
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.allowExtensions: true
define root view entity ZC_DadosGestaoImportacao
  provider contract transactional_query
  as projection on ZI_DadosGestaoImportacao
  association [0..*] to ZC_Impostos as _ImpList on $projection.docnum = _ImpList.Docnum
                                                     and $projection.itmnum = _ImpList.Itmnum  

{
  key zuonr,
  key belnr,
  key gjahr,
  key buzei,
      bldat,
      budat,
      usnam,
      xblnr,
      bukrs,
      --@ObjectModel.foreignKey.association: '_Lfa1'
      @ObjectModel.text.element: ['NomeFornecedor']
      lifnr,
      waers,

      _ImpList
    
No METADATA principal criei o facet para associação
-- TAB dados Impostos
  {
      id: 'Impostos',
      purpose: #STANDARD,
      type: #LINEITEM_REFERENCE,
      label: 'Impostos',
      position: 50,
      targetElement: '_ImpList'

  }
  ]

E não esquecer de adicionar a entidade no SERVICE DEFINITION
@EndUserText.label: 'Dados de Gestao de importação'
define service ZSD_DadosGestaoImportacao {
  expose ZC_DadosGestaoImportacao;
  expose ZC_Impostos;
}

Resultado















segunda-feira, 12 de fevereiro de 2024

Collect usando FOR IN GROUPS

Código exemplo abaixo, pegando dados de remessa

sELECT likp~vbeln,

       likp~ernam,

       lips~matnr,
       lips~lfimg
  INTO TABLE @DATA(lt_likp)

  FROM likp INNER JOIN lips ON lips~vbeln = likp~vbeln
 WHERE likp~lfart = 'ZVME'.

"Criar estrutura que quer fazer a somatória
TYPES: BEGIN OF ty_rem,
         matnr TYPE lips-matnr,
         lfimg TYPE lips-lfimg,
       END OF ty_rem.

TYPES ty_t_rem TYPE TABLE OF ty_rem WITH DEFAULT KEY.

DATA w_lips TYPE ty_rem.

BREAK-POINT.

DATA(lt_lips) = VALUE ty_t_rem( FOR GROUPS w_lips_x OF <ls_collect> IN lt_likp
                     GROUP BY ( matnr = <ls_collect>-matnr )
                     LET coll_line = REDUCE #( INIT ls_sum TYPE ty_rem
                                                      FOR ls_sum_likp IN GROUP w_lips_x
                                                        NEXT ls_sum-lfimg = ls_sum-lfimg + ls_sum_likp-lfimg
                                                             ls_sum-matnr = ls_sum_likp-matnr
                                                        ) IN ( coll_line ) ).
BREAK-POINT.

segunda-feira, 5 de fevereiro de 2024

Leitura de dados de estrutura BOPF

 Transações importantes

BOBX - Estruturas dos BOPF

BOBT - Teste de estrutura BOPF

Ex: /SCMTMS/TOR

Transação BOBX

- Clicar na estrutura desejada








BOBT - teste de query

Do lado esquerdo na BOBT tem as queries disponíveis.

Do lado direito na BOBX a localização das querys disponíveis na visão de estrutura

















Pegando exemplo de dados da remessa na query PLANNING_ATTRIBUTES

Registros encontrados





Fazendo pelo código do programa

"Service Manager
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-trq_base_btd_id.

*"Selection Parameters
DATA(lt_selparVALUE /bobf/t_frw_query_selparamattribute_name lv_attname
                                                      sign 'I'
                                                      option 'EQ'
                                                      low '0080000180' ).

*"Query key

data lt_key TYPE /BOBF/T_FRW_KEY.
data lt_docref type /scmtms/t_tor_root_k.

"Execução da query
lo_srv_mgr->queryEXPORTING iv_query_key /scmtms/if_tor_c=>sc_query-root-planning_attributes
                             "it_filter_key =
                             it_selection_parameters lt_selpar
                             "is_query_options =
                             iv_fill_data abap_true
                             "it_requested_attributes =
                   IMPORTING "eo_message = DATA(lo_message)
                      et_key lt_key
                      et_data lt_docref
                      ).


====== Abaixo de onde vem as informações na BOBX











====== Para ler os dados da estrutura abaixo do ROOT.

Transação BOBT













=========  Código ==========

Como faz parte da estrutura ROOT pega os dados a partir das chaves retornadas da leitura do root

DELETE lt_key WHERE key not in lt_r_key.

data lt_doc_tr type /SCMTMS/T_TOR_ITEM_TR_K.

  lo_srv_mgr->retrieve_by_association(
      EXPORTING
        iv_node_key             /scmtms/if_tor_c=>sc_node-root
        it_key                  lt_key                             " Key Table
        iv_edit_mode            /bobf/if_conf_c=>sc_edit_read_only " Change Mode
        iv_fill_data            abap_true                          " Data element for domain BOOLE: TRUE (='X') and FALSE (=' ')
        iv_association /scmtms/if_tor_c=>sc_association-root-item_tr_main
      IMPORTING
        "eo_message              = lo_message                         " Interface of Message Object
        et_data                 lt_doc_tr
        et_failed_key           DATA(lt_failed_key)                " Key Table
    ).










E assim sucessivamente, com outras estruturas sob o mesmo nó

data lt_doc_tr_seal type /SCMTMS/T_TOR_SEAL_K.

  lo_srv_mgr->retrieve_by_association(
      EXPORTING
        iv_node_key             /scmtms/if_tor_c=>sc_node-root
        it_key                  lt_key                             " Key Table
        iv_edit_mode            /bobf/if_conf_c=>sc_edit_read_only " Change Mode
        iv_fill_data            abap_true                          " Data element for domain BOOLE: TRUE (='X') and FALSE (=' ')
        iv_association /scmtms/if_tor_c=>sc_association-root-seal
      IMPORTING
        "eo_message              = lo_message                         " Interface of Message Object
        et_data                 lt_doc_tr_seal
        et_failed_key           lt_failed_key                " Key Table
    ).

data lt_doc_tr_item type /SCMTMS/T_TOR_ITEM_TR_K.

  lo_srv_mgr->retrieve_by_association(
      EXPORTING
        iv_node_key             /scmtms/if_tor_c=>sc_node-root
        it_key                  lt_key                             " Key Table
        iv_edit_mode            /bobf/if_conf_c=>sc_edit_read_only " Change Mode
        iv_fill_data            abap_true                          " Data element for domain BOOLE: TRUE (='X') and FALSE (=' ')
        iv_association /scmtms/if_tor_c=>sc_association-root-item_tr
      IMPORTING
        "eo_message              = lo_message                         " Interface of Message Object
        et_data                 lt_doc_tr_item
        et_failed_key           lt_failed_key                " Key Table
    ).