Maintain contact person in customer master

REPORT  ztest.

*--------------------------------------------------------------------*
*  VARIABLE DEFINITION
*--------------------------------------------------------------------*
DATA: w_kna1 TYPE kna1.

*--------------------------------------------------------------------*
*  INTERNAL TABLE DEFINITION
*--------------------------------------------------------------------*
DATA: it_addr TYPE STANDARD TABLE OF bapiad3vl WITH HEADER LINE,
      it_smtp TYPE STANDARD TABLE OF bapiadsmtp WITH HEADER LINE,
      it_smtpx TYPE STANDARD TABLE OF bapiadsmtx WITH HEADER LINE,
      it_xknvk TYPE STANDARD TABLE OF fknvk WITH HEADER LINE,
      it_yknvk TYPE STANDARD TABLE OF fknvk WITH HEADER LINE,
      it_return TYPE STANDARD TABLE OF bapiret2 WITH HEADER LINE.
*--------------------------------------------------------------------*
*  SELECTION SCREEN
*--------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE text-001.
PARAMETERS: p_kunnr TYPE bapi4003_1-objkey_c OBLIGATORY,
            p_parnr TYPE bapi4003_1-objkey_p OBLIGATORY,
            p_email LIKE adr6-smtp_addr OBLIGATORY.
SELECTION-SCREEN END OF BLOCK blk.

*--------------------------------------------------------------------*
*  START-OF-SELECTION
*--------------------------------------------------------------------*
START-OF-SELECTION.
*Maintain customer data
  SELECT SINGLE * FROM kna1 INTO w_kna1 WHERE kunnr EQ p_kunnr.
  IF sy-subrc EQ 0.
    SELECT  * FROM knvk INTO CORRESPONDING FIELDS OF TABLE it_xknvk WHERE kunnr EQ p_kunnr AND
                                                                                parnr EQ p_parnr.
    IF sy-subrc EQ 0.
      it_yknvk[] = it_xknvk[].
      READ TABLE it_xknvk INDEX 1.
      it_xknvk-name1 = 'TEST'.
      it_xknvk-kz    = 'U'.
      MODIFY it_xknvk INDEX 1.
      CALL FUNCTION 'SD_CUSTOMER_MAINTAIN_ALL'
        EXPORTING
          i_kna1                  = w_kna1
          pi_postflag             = 'X'
        TABLES
          t_xknvk                 = it_xknvk[]
          t_yknvk                 = it_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
          OTHERS                  = 23.
      IF sy-subrc EQ 0.
*Maintain contact person's address data
        CALL FUNCTION 'BAPI_ADDRESSCONTPART_GETDETAIL'
          EXPORTING
            obj_type_p = 'BUS1006001'
            obj_id_p   = p_parnr
            obj_type_c = 'KNA1'
            obj_id_c   = p_kunnr
            context    = 5
          TABLES
            bapiad3vl  = it_addr[]
            bapiadsmtp = it_smtp[].
        IF sy-subrc EQ 0.
          READ TABLE it_smtp INDEX 1.
          it_smtp-e_mail = p_email.
          MODIFY it_smtp INDEX 1.
          it_smtpx-e_mail = 'X'.
          it_smtpx-updateflag = 'U'.
          APPEND it_smtpx.
          CALL FUNCTION 'BAPI_ADDRESSCONTPART_CHANGE'
            EXPORTING
              obj_type_p  = 'BUS1006001'
              obj_id_p    = p_parnr
              obj_type_c  = 'KNA1'
              obj_id_c    = p_kunnr
              context     = 5
            TABLES
              bapiadsmtp  = it_smtp[]
              bapiadsmt_x = it_smtpx[]
              return      = it_return[].
          IF sy-subrc EQ 0.
            CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
              EXPORTING
                wait = 'X'.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.

你可能感兴趣的:(C++,c,C#)