Ayuda SAP

Borrar acreedor SD_CUSTOMER_MAINTAIN_ALL

Etiquetas: #<Tag:0x00007f4450632bf8> #<Tag:0x00007f44506329f0>

Hola mi gente del mejor foro de sap en español xD. Hoy me mandaron a revisar una app fiori que sirve para ampliar clientes y mi problema es que al ampliarlo borra el acreedor, debugguee y llegue a ver esta función SD_CUSTOMER_MAINTAIN_ALL , dejare por acá el código a ver si alguien puede observar el error, quizás no se si se esta llamando mal la función . Estoy debuggeando pero no se por que lo hace o como.

*"----------------------------------------------------------------------
*"*"Interfase local
*"  CHANGING
*"     VALUE(STR) TYPE  STRING OPTIONAL
*"----------------------------------------------------------------------

  DATA : ld_kunnr             TYPE kunnr.
  DATA : ld_sd_cust_1321_done TYPE c.
  DATA : ld_addnr             TYPE ad_addrnum.
  DATA : nameaux               TYPE string.
*
*----------------------------------------------------------------------*
* DECLARACION DE TABLAS INTERNAS Y ESTRUCTURAS
*----------------------------------------------------------------------*
*
  DATA : wa_kna1              TYPE kna1.                                " Maestro de clientes (parte general)
  DATA : wa_knb1              TYPE knb1.                                " Maestro de clientes (sociedad)
  DATA : wa_knvv              TYPE knvv.                                " Maestro de clientes datos comerciales
  DATA : wa_knvk              TYPE knvk.
  DATA : wa_bapiaddr1         TYPE bapiaddr1.                           " Estructura de referencia BAPI p.direcciones (org./empresa)
  DATA : wa_bapiaddr2         TYPE bapiaddr2.                           " Estructura referencia BAPI p.direcciones (personas físicas)
*
  DATA : it_xknvi TYPE STANDARD TABLE OF fknvi,             " Change document structure; generated using RSSCD000
         wa_xknvi TYPE fknvi,
         wx_xknvi TYPE fknvi.
*
  DATA : it_xknvp TYPE STANDARD TABLE OF fknvp,             " Change document structure; generated using RSSCD000
         wa_xknvp TYPE fknvp,
         wx_xknvp TYPE fknvp.

  DATA : it_xknb5 TYPE STANDARD TABLE OF fknb5,             " Change document structure; generated using RSSCD000
         wa_xknb5 TYPE fknb5,
         wx_xknb5 TYPE fknb5.

*
  DATA : it_xknvk TYPE STANDARD TABLE OF fknvk,             " Change document structure; generated using RSSCD000
         wa_xknvk TYPE fknvk,
         wx_xknvk TYPE fknvk.
*
  DATA : it_yknvp TYPE STANDARD TABLE OF fknvp,             " Change document structure; generated using RSSCD000
         wa_yknvp TYPE fknvp,
         wx_yknvp TYPE fknvp.


*
  DATA : it_ad1vl TYPE STANDARD TABLE OF bapiad1vl,         " Estructura BAPI p.distribución tp.dirección 1
         wa_ad1vl TYPE bapiad1vl.
  DATA : it_adsmtp TYPE STANDARD TABLE OF bapiadsmtp,        " Estructura BAPI p.direcciones correo electr.(Bus.Addr.Serv.)
         wa_adsmtp TYPE bapiadsmtp.
  DATA : it_adtel TYPE STANDARD TABLE OF bapiadtel,         " Estructura BAPI p.números teléfono (Business Address Serv.)
         wa_adtel TYPE bapiadtel.
  DATA : it_return TYPE STANDARD TABLE OF bapiret2,          " Parámetro de retorno
         wa_return TYPE bapiret2.
  DATA : it_ad1vlx TYPE STANDARD TABLE OF bapiad1vlx,        " Estructura referencia modif.BAPI p.estructura BAPIAD1VL
         wa_ad1vlx TYPE bapiad1vlx.
  DATA : it_adtelx TYPE STANDARD TABLE OF bapiadtelx,        " Estructura referencia modif.BAPI p.estructura BAPIADTEL
         wa_adtelx TYPE bapiadtelx.
  DATA : it_adsmtx TYPE STANDARD TABLE OF bapiadsmtx,        " Estructura referencia modif.BAPI p.estructura BAPIADSMTP
         wa_adsmtx TYPE bapiadsmtx.
*
  DATA : wx_kna1          TYPE kna1.
  DATA: esquema           TYPE string,
        direccioncompleta TYPE string,
        tratamiento       TYPE string,
        parner_number     TYPE char70,
        w_tsad3t          TYPE tsad3t,
        ls_bapi           TYPE bapi4003_1,
        it_adrc_cust      TYPE adrc,
        lt_return         LIKE bapiret2 OCCURS 10 WITH HEADER LINE,
        lt_smtpx          LIKE bapiadsmtx OCCURS 10 WITH HEADER LINE,
        lt_3x             LIKE bapiad3vlx OCCURS 10 WITH HEADER LINE,
        lt_3              LIKE bapiad3vl OCCURS 10 WITH HEADER LINE,
        lt_smtp           LIKE bapiadsmtp OCCURS 10 WITH HEADER LINE,
        lt_bapiadtel      LIKE bapiadtel  OCCURS 10 WITH HEADER LINE,
        lt_bapiadtel_x    LIKE bapiadtelx OCCURS 10 WITH HEADER LINE.

  DATA: p_cont     TYPE bapi4003_1-context,
        p_addr     TYPE adr6-smtp_addr,
        p_condpago TYPE string.


  TYPES: BEGIN OF ty_data_cliente,
           numcliente      TYPE string,
           orgventa        TYPE string,
           canal           TYPE string,
           sector          TYPE string,
           ofi_venta       TYPE string,
           lista_precio    TYPE string,
           centrosum       TYPE string,
           zonaventas      TYPE string,
           grupovendedores TYPE string,
           user            TYPE string,
         END OF ty_data_cliente.

  DATA: ti_info_cliente TYPE STANDARD TABLE OF ty_data_cliente,
        tab_tsad3t      TYPE STANDARD TABLE OF tsad3t WITH HEADER LINE,
        it_knvv         TYPE STANDARD TABLE OF knvv,
        wa_knvv2        TYPE knvv,
        wa_knvv3        TYPE knvv.
  DATA: wa_info_cliente TYPE ty_data_cliente,
        lv_tabix        TYPE sytabix,
        p_flag          TYPE char1.

  DATA: str_json TYPE string.
  DATA: ld_kunnrlocal TYPE string.
  DATA: canal_numero TYPE i.
  DATA: ti_str TYPE TABLE OF string,
        wa_str TYPE string.


*----------------------------------------------------------------------*
*  INICIO SECUENCIA DE MODIFICACIÓN DE CLIENTES
*----------------------------------------------------------------------*
  str_json = str.
  CLEAR str.
  CALL METHOD zcl_json_star=>deserialize( EXPORTING json = str_json CHANGING data = wa_info_cliente ).

*   -------------------------------------------------------------------*
*    LLENADO TBI : IT_KNA1 ( MAESTR DE CLIENTES DATOS GENERALES )
*   -------------------------------------------------------------------*

  SELECT SINGLE * INTO @DATA(kna1_temp) FROM kna1 WHERE kunnr EQ @wa_info_cliente-numcliente AND ktokd EQ '0001'.



*
  CLEAR   : wa_kna1, nameaux.
*
  wa_kna1-kunnr   = kna1_temp-kunnr.
  wa_kna1-regio   = kna1_temp-regio.
  wa_kna1-anred   = kna1_temp-anred.
  wa_kna1-ktokd   = kna1_temp-ktokd.                       " Grupo de Cuentas Deudor
  wa_kna1-stras   = kna1_temp-stras.
  wa_kna1-counc   = kna1_temp-counc.
  wa_kna1-cityc   = kna1_temp-cityc.
  wa_kna1-lzone   = kna1_temp-lzone.
  wa_kna1-stcd1   = kna1_temp-stcd1.
  wa_kna1-kukla   = kna1_temp-kukla.
  wa_kna1-brsch   = kna1_temp-brsch.
  wa_kna1-bran1   = kna1_temp-bran1.
  wa_kna1-land1   = 'CL'.
  wa_kna1-spras   = 'S'.
  wa_kna1-hzuor   = 00.
  wa_kna1-ernam   = sy-uname.
  wa_kna1-erdat   = sy-datum.

  SELECT * INTO @DATA(knvv_temp) FROM knvv WHERE kunnr EQ @wa_info_cliente-numcliente.
    APPEND knvv_temp TO it_knvv.
  ENDSELECT.

  canal_numero = wa_info_cliente-canal.

  LOOP AT it_knvv INTO wa_knvv2.

    IF wa_knvv2-vtweg EQ '25'.
      IF wa_info_cliente-canal EQ '13' OR wa_info_cliente-canal EQ '14' OR  wa_info_cliente-canal EQ '15'.
        lv_tabix = sy-tabix.
        p_flag = 'X'.
        EXIT.
      ENDIF.
    ELSE.
      lv_tabix = 1.
      p_flag = ''.
    ENDIF.
  ENDLOOP.

  CLEAR   : wa_knvv.

  READ TABLE it_knvv INTO wa_knvv3 INDEX lv_tabix.

  IF p_flag EQ 'X'.
    IF wa_info_cliente-sector EQ '16' .
      p_condpago  = '0004'.
    ELSE.
      IF canal_numero BETWEEN 10 AND 20.
        p_condpago = '0001'.
      ELSEIF canal_numero BETWEEN 25 AND 35.
        p_condpago = '0003'.
      ELSE.
        p_condpago = wa_knvv3-zterm.
      ENDIF.

    ENDIF.

  ELSE.
    IF wa_info_cliente-sector EQ '16'.
      p_condpago  = '0004'.
    ELSE.
      IF canal_numero BETWEEN 10 AND 20.
        p_condpago = '0001'.
      ELSEIF canal_numero BETWEEN 25 AND 35.
        p_condpago = '0003'.
      ELSE.
        p_condpago = wa_knvv3-zterm.
      ENDIF.
    ENDIF.
  ENDIF.




  wa_knvv-kunnr   =  kna1_temp-kunnr.                                   " Numero de Cliente
  wa_knvv-vkorg   =  wa_info_cliente-orgventa.                         " Organizacion de Venta
  wa_knvv-vtweg   =  wa_info_cliente-canal.                            " Canal de distribución
  wa_knvv-spart   =  wa_info_cliente-sector.                           " Sector
  wa_knvv-kdgrp   =  knvv_temp-kdgrp.                     " Grupo de clientes
  wa_knvv-waers   = 'CLPD'.                                            " Moneda
  IF wa_info_cliente-canal EQ '10' OR wa_info_cliente-canal EQ '11' OR  wa_info_cliente-canal EQ '12'.
    IF wa_info_cliente-sector EQ '10'.
      esquema = '2'.
    ELSE.
      esquema = '3'.
    ENDIF.
  ELSE.
    esquema = '3'.
  ENDIF.
  wa_knvv-kalks   = esquema.    " Esquema calculo del paciente
  wa_knvv-versg   = '1'.
  IF wa_info_cliente-sector EQ '16'.
    wa_knvv-pltyp   =  '25'.
  ELSEIF   wa_info_cliente-sector EQ '12'.
    wa_knvv-pltyp   =  '40'.
  ELSE.
    wa_knvv-pltyp   =  wa_info_cliente-lista_precio.
  ENDIF.
  " Grupo de estadísticas cliente
  " Tipo de lista de precios
  wa_knvv-awahr   = '100'.                                            " Probabilidad de pedido de posición
  wa_knvv-antlf   = '9'.                                              " Cantidad máxima de entregas parciales permitidas p/posición
  wa_knvv-kzazu   = 'X'.                                              " Indicador de agrupamiento de pedidos
  wa_knvv-bzirk   = wa_info_cliente-zonaventas.                              " zona ventas
  wa_knvv-lprio   = 00.                                               " prioridad de entrega
  wa_knvv-vsbed   = wa_knvv3-vsbed.                    " cond de expedicion
  wa_knvv-perfk   = wa_knvv3-perfk.             " calendario de facturacion
  wa_knvv-perrl   = wa_knvv3-perrl.            " lista de facturas
  wa_knvv-ktgrd   = wa_knvv3-ktgrd .                 " grtupo de imputación
  wa_knvv-zterm   = p_condpago.                         " Clave de condiciones de pago
  wa_knvv-vwerk   = wa_info_cliente-centrosum.                        " Centro suministrador
  wa_knvv-vkgrp   = wa_info_cliente-grupovendedores.                       " grupo de vendedores
  wa_knvv-vkbur   = wa_info_cliente-ofi_venta.                        " Oficina de ventas
  wa_knvv-ernam   = sy-uname.
  wa_knvv-erdat   = sy-datum.


  CALL FUNCTION 'SD_CUSTOMER_MAINTAIN_ALL'
    EXPORTING
      i_kna1                  = wa_kna1
      i_knvv                  = wa_knvv
*     i_bapiaddr1             = wa_bapiaddr1
      pi_postflag             = 'X'
      I_CUSTOMER_IS_CONSUMER  = 'X' " 28.03.2019 se agrega para datos de control de crédito automáticos RU
      pi_cam_changed          = 'X'
    IMPORTING
      e_kunnr                 = ld_kunnr
      o_kna1                  = wx_kna1
      e_sd_cust_1321_done     = ld_sd_cust_1321_done
**    TABLES
**      t_xknb5                    = it_xknb5
**      t_xknvi                    = it_xknvi
**      t_xknvp                    = it_xknvp
**      t_xknvk                    = it_xknvk
    EXCEPTIONS
      client_error            = 1
      kna1_incomplete         = 2
      knb1_incomplete         = 3
      knb5_incomplete         = 4
      knvv_incomplete         = 5
      kunnr_not_unique        = 6
      sales_area_not_unique   = 7
      sales_area_not_valid    = 8
      insert_update_conflict  = 9
      number_assignment_error = 10
      number_not_in_range     = 11
      number_range_not_extern = 12
      number_range_not_intern = 13
      account_group_not_valid = 14
      parnr_invalid           = 15
      bank_address_invalid    = 16
      tax_data_not_valid      = 17
      no_authority            = 18
      company_code_not_unique = 19
      dunning_data_not_valid  = 20
      knb1_reference_invalid  = 21
      cam_error               = 22
      OTHERS                  = 23.

  IF ( sy-subrc EQ 0 ).
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.

    ld_kunnrlocal = ld_kunnr.



    IF canal_numero BETWEEN 10 AND 20.

      wa_str = 'WE'.
      APPEND wa_str TO ti_str.
      REFRESH : it_xknvp.
      CLEAR   : it_xknvp, wa_xknvp, wx_xknvp.
      CLEAR: ld_kunnr,wx_kna1, wa_kna1, wa_knb1,wa_knvv, wa_bapiaddr1, wa_bapiaddr2, ld_sd_cust_1321_done.
      "para solicitante
      LOOP AT ti_str INTO wa_str.
        wa_xknvp-mandt             = '600'.
        wa_xknvp-kunnr              = kna1_temp-kunnr.
        wa_xknvp-parvw              = wa_str.
        wa_xknvp-vkorg              = wa_info_cliente-orgventa.
        wa_xknvp-vtweg              = wa_info_cliente-canal.
        wa_xknvp-spart              = wa_info_cliente-sector.
        wa_xknvp-kunn2              = kna1_temp-kunnr.
        wa_xknvp-kz                 = 'I'.
        APPEND wa_xknvp TO it_xknvp.
      ENDLOOP.

      CALL FUNCTION 'SD_CUSTOMER_MAINTAIN_ALL'
        EXPORTING
*         i_bapiaddr1             = wa_bapiaddr1
          pi_cam_changed          = 'X'
        IMPORTING
          e_kunnr                 = ld_kunnr
          o_kna1                  = wx_kna1
          e_sd_cust_1321_done     = ld_sd_cust_1321_done
        TABLES
**      t_xknb5                    = it_xknb5
**      t_xknvi                    = it_xknvi
          t_xknvp                 = it_xknvp
**      t_xknvk                    = it_xknvk
        EXCEPTIONS
          client_error            = 1
          kna1_incomplete         = 2
          knb1_incomplete         = 3
          knb5_incomplete         = 4
          knvv_incomplete         = 5
          kunnr_not_unique        = 6
          sales_area_not_unique   = 7
          sales_area_not_valid    = 8
          insert_update_conflict  = 9
          number_assignment_error = 10
          number_not_in_range     = 11
          number_range_not_extern = 12
          number_range_not_intern = 13
          account_group_not_valid = 14
          parnr_invalid           = 15
          bank_address_invalid    = 16
          tax_data_not_valid      = 17
          no_authority            = 18
          company_code_not_unique = 19
          dunning_data_not_valid  = 20
          knb1_reference_invalid  = 21
          cam_error               = 22
          OTHERS                  = 23.

      IF ( sy-subrc EQ 0 ).
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            wait = 'X'.
      ENDIF.
    ENDIF.

    CLEAR str.
    CONCATENATE 'Se ha ampliado el cliente n°: ' wa_info_cliente-numcliente INTO str SEPARATED BY space.

  ELSE.

    CLEAR str.
    str = 'Ha ocurrido un error en la ampliación del cliente.'.
  ENDIF.

Creo que el problema es que debo pasarle el LINR (acreedor) a la función SD_CUSTOMER_MAINTAIN_ALL para que mantenga el Acreedor o sino lo estaría tomando como una actualización, espero alguien me pueda confirmar esto. Saludos!