Müşteriye İlgili Kişi Eklenmesi-Silinmesi-Güncellenmesi

XD02`de İlgili Kişi sekmesinde bulunan ve KNVK tablosunda tutulan ilgili kişi verileri `SD_CUSTOMER_MAINTAIN_ALL` fonksiyonu ile müşteriye eklenebilir, güncellenebilir ve silinebilir.

 

 DATA:  lt_knvk TYPE fknvk_tab,
        lt_xknvk TYPE fknvk_tab,
        lt_yknvk TYPE fknvk_tab,
        ls_knvk LIKE LINE OF lt_knvk.

      REFRESH lt_knvk[].
      CLEAR ls_knvk.
      ls_knvk-parnr lv_parnr.
      ls_knvk-kunnr ls_kna1-kunnr.
      ls_knvk-name1 `Lokasyon`.
      ls_knvk-namev `Lokasyon`.
      ls_knvk-pafkt `03`.
      ls_knvk-abtnr `0013`.
      ls_knvk-loevm ls_kna1-loevm.
      "ls_knvk-kz    ls_kna1_in-updkz.
      APPEND ls_knvk TO lt_knvk.

    PERFORM f_set_xknvk USING lt_knvk CHANGING lt_xknvk
                                               lt_yknvk.

    CALL FUNCTION `SD_CUSTOMER_MAINTAIN_ALL`
      EXPORTING
        i_kna1                              ls_kna1
        i_knb1                              ls_knb1
        i_knvv                              ls_knvv
        i_bapiaddr1                         ls_bapiaddr1
        i_force_external_number_range       `X`
      IMPORTING
        e_kunnr                             lv_kunnr
      TABLES
        t_xknvk                             lt_xknvk
        t_yknvk                             lt_yknvk
      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
        error_message                       23
        OTHERS                              24.

    IF sy-subrc NE 0.
      CALL FUNCTION `BAPI_TRANSACTION_ROLLBACK`.

    ELSE.
      CALL FUNCTION `BAPI_TRANSACTION_COMMIT`
        EXPORTING
          wait `X`.
    ENDIF.

*&---------------------------------------------------------------------*
*&      Form  F_SET_XKNVK
*&---------------------------------------------------------------------*
FORM f_set_xknvk USING pt_knvk  TYPE fknvk_tab
              CHANGING pt_xknvk TYPE fknvk_tab
                       pt_yknvk TYPE fknvk_tab.

  DATABEGIN OF lt_knvk OCCURS 0,
          parnr TYPE parnr,
          kunnr TYPE kunnr,
          namev TYPE namev_vp,
          name1 TYPE name1_gp,
          abtnr TYPE abtnr_pa,
          pafkt TYPE pafkt,
          loevm TYPE loevm_x,
        END OF lt_knvk.

  DATAls_knvk LIKE LINE OF pt_knvk.

  REFRESHpt_xknvk[]pt_yknvk[].

  IF NOT pt_knvk[] IS INITIAL.
    SELECT parnr kunnr namev name1 abtnr pafkt loevm
      FROM knvk INTO TABLE lt_knvk
      FOR ALL ENTRIES IN pt_knvk
      WHERE parnr EQ pt_knvk-parnr.

    SORT lt_knvk BY parnr.
  ENDIF.

  LOOP AT pt_knvk INTO ls_knvk.

    "Silinecekler
    IF ls_knvk-loevm EQ `X`.
      CLEAR ls_knvk-kz.
      APPEND ls_knvk TO pt_yknvk.
      CONTINUE.
    ENDIF.

    READ TABLE lt_knvk WITH KEY parnr ls_knvk-parnr
                                BINARY SEARCH.
    IF sy-subrc EQ 0.
      "Yeni Hali
      ls_knvk-kz `U`.
      APPEND ls_knvk TO pt_xknvk.

      "Tablodan Gelen Eski Hali
      CLEAR ls_knvk.
      MOVE-CORRESPONDING lt_knvk TO ls_knvk.
      APPEND ls_knvk TO pt_yknvk.

    ELSE.
      ls_knvk-kz `I`.
      APPEND ls_knvk TO pt_xknvk.
    ENDIF.

  ENDLOOP.

  "DB tabloda var. Yeni gelen veriler arasında yoksa sil.
  IF NOT pt_knvk[] IS INITIAL.
    SELECT parnr kunnr namev name1 abtnr pafkt loevm
      FROM knvk INTO TABLE lt_knvk
      FOR ALL ENTRIES IN pt_knvk
      WHERE kunnr EQ pt_knvk-kunnr.

    SORT lt_knvk BY parnr.
  ENDIF.

  LOOP AT lt_knvk.
    CLEAR ls_knvk.
    MOVE-CORRESPONDING lt_knvk TO ls_knvk.

    READ TABLE pt_knvk TRANSPORTING NO FIELDS
                       WITH KEY parnr lt_knvk-parnr.
    IF sy-subrc EQ 0.
      CONTINUE.
    ELSE.
      CLEAR ls_knvk-kz.
      APPEND ls_knvk TO pt_yknvk.
    ENDIF.
  ENDLOOP.

ENDFORM.                    " F_SET_XKNVK