Monday, November 18, 2019

BDC to Create Customer Master in SAP (XD01)

BDC to Create Customer Master in SAP  (XD01):
I am pasting the code of BDC for Creating Customer Master in SAP using BDC .


REPORT zsdr_bdc_xd01
       NO STANDARD PAGE HEADING LINE-SIZE 255.

TABLESt100.
TYPES truxs_t_text_data(4096TYPE OCCURS 0.
DATAit_raw TYPE truxs_t_text_data.
DATA:   messtab LIKE bdcmsgcoll OCCURS WITH HEADER LINE.
DATA:   bdcdata LIKE bdcdata    OCCURS WITH HEADER LINE.
DATAl_mstring(480).

DATABEGIN OF it_bdc OCCURS 0,
        bukrs(04)" Company Code
        vkorg(04)" Sales Organization
        vtweg(02)" Destribution Channel
        spart(02)" Division
        ktokd(04)" Customer Account Group
        anred(15),
        name1(35),
        sortl(10),
        stras(35),
        ort02(35),
*       pfach(10),
        ort01(35),
        pstl2(10),
        land1(03),
        regio(03),
        telf2(10),
        STCD1(16),
        BAHNS(25),   
        BAHNE(25),   
        akont(10),
        zterm(04),
        awahr(03),
        vkbur(04),
        waers(05),
        kalks(01),
        lprio(02),
        kzazu(01),
        vsbed(02),
        vwerk(04),
        antlf(01),
        inco1(03),
        inco2(28),
        zterm1(04),
        ktgrd(02),
        panno(40),
        tinno(40),
        altkn(10),
      END OF it_bdc.

PARAMETERSp_dismod LIKE ctu_params-dismode DEFAULT 'A'.
PARAMETERSfilename TYPE rlgrap-filename    OBLIGATORY.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.

  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      field_name 'filename'
    IMPORTING
      file_name  filename.

START-OF-SELECTION.

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
*     I_FIELD_SEPERATOR    =
      i_line_header        'X'
      i_tab_raw_data       it_raw
      i_filename           filename
    TABLES
      i_tab_converted_data it_bdc
    EXCEPTIONS
      conversion_failed    1
      OTHERS               2.

*  PERFORM OPEN_GROUP.
  LOOP AT it_bdc.
    PERFORM bdc_dynpro      USING 'SAPMF02D' '0100'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'RF02D-KTOKD'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '/00'.
    PERFORM bdc_field       USING 'RF02D-BUKRS'
                                  it_bdc-bukrs."'1000'.
    PERFORM bdc_field       USING 'RF02D-VKORG'
                                  it_bdc-vkorg."'1000'.
    PERFORM bdc_field       USING 'RF02D-VTWEG'
                                  it_bdc-vtweg."'03'.
    PERFORM bdc_field       USING 'RF02D-SPART'
                                  it_bdc-spart."'01'.
    PERFORM bdc_field       USING 'RF02D-KTOKD'
                                  it_bdc-ktokd."'ZA02'.
    PERFORM bdc_dynpro      USING 'SAPMF02D' '0110'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'KNA1-SPRAS'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '/00'.
    PERFORM bdc_field       USING 'KNA1-ANRED'
                                  it_bdc-anred."'COMPANY'.
    PERFORM bdc_field       USING 'KNA1-NAME1'
                                  it_bdc-name1."'Raju'.
    PERFORM bdc_field       USING 'KNA1-SORTL'
                                  it_bdc-sortl."'RAJU'.
    PERFORM bdc_field       USING 'KNA1-STRAS'
                                  it_bdc-stras."'RAJU'.
    PERFORM bdc_field       USING 'KNA1-PFACH'
                                  it_bdc-pstl2.    " pfach.             "'123456'.
    PERFORM bdc_field       USING 'KNA1-ORT01'
                                  it_bdc-ort01."'hyderbad'.
    PERFORM bdc_field       USING 'KNA1-ORT02'
                                  it_bdc-ort02."'hyderbad'.
    PERFORM bdc_field       USING 'KNA1-PSTLZ'
                                  it_bdc-pstl2.             "'234567'.
    PERFORM bdc_field       USING 'KNA1-PSTL2'
                                  it_bdc-pstl2.             "'234567'.
    PERFORM bdc_field       USING 'KNA1-LAND1'
                                  it_bdc-land1."'IN'.
    PERFORM bdc_field       USING 'KNA1-REGIO'
                                  it_bdc-regio."'20'.
    PERFORM bdc_field       USING 'KNA1-SPRAS'
                                  'EN'.
    PERFORM bdc_field       USING 'KNA1-TELF1'
                                  it_bdc-telf2."9877655433.
*   PERFORM bdc_field       USING 'KNA1-TELF2'
*                                 it_bdc-telf2."9877655433.
    PERFORM bdc_dynpro      USING 'SAPMF02D' '0120'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'KNA1-LIFNR'.
     PERFORM bdc_field       USING 'KNA1-STCD1'
                                  it_bdc-stcd1.
    PERFORM bdc_field       USING 'KNA1-BAHNS'
                                  it_bdc-BAHNS.
    PERFORM bdc_field       USING 'KNA1-BAHNE'
                                  it_bdc-BAHNE.

    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=OPFI'.
    PERFORM bdc_dynpro      USING 'SAPLJ1I_MASTER' '0200'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=CIN_CUSTOMER_FC2'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'J_1IMOCUST-J_1IEXCD'.
    PERFORM bdc_dynpro      USING 'SAPLJ1I_MASTER' '0200'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '/00'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'J_1IMOCUST-J_1ILSTNO'.
    PERFORM bdc_field       USING 'J_1IMOCUST-J_1ICSTNO'
                                  it_bdc-panno.
    PERFORM bdc_field       USING 'J_1IMOCUST-J_1ILSTNO'
                                  it_bdc-tinno.
    PERFORM bdc_dynpro      USING 'SAPLJ1I_MASTER' '0200'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=BACK'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'J_1IMOCUST-J_1ICSTNO'.
*   PERFORM bdc_field       USING 'J_1IMOCUST-J_1ICSTNO'
*                                 it_bdc-panno.
*   PERFORM bdc_field       USING 'J_1IMOCUST-J_1ILSTNO'
*                                 it_bdc-tinno.
***
    PERFORM bdc_dynpro      USING 'SAPMF02D' '0120'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'KNA1-LIFNR'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '/00'.
    PERFORM bdc_dynpro      USING 'SAPMF02D' '0125'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'KNA1-NIELS'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '/00'.
    PERFORM bdc_dynpro      USING 'SAPMF02D' '0130'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'KNBK-BANKS(01)'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=ENTR'.
    PERFORM bdc_dynpro      USING 'SAPMF02D' '0340'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'KNVA-ABLAD(01)'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=ENTR'.
    PERFORM bdc_dynpro      USING 'SAPMF02D' '0370'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'KNEX-LNDEX(01)'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=ENTR'.
    PERFORM bdc_field       USING 'KNA1-CIVVE'
                                  'X'.
    PERFORM bdc_dynpro      USING 'SAPMF02D' '0360'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'KNVK-NAMEV(01)'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=ENTR'.
    PERFORM bdc_dynpro      USING 'SAPMF02D' '0210'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'KNB1-AKONT'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '/00'.
    PERFORM bdc_field       USING 'KNB1-AKONT'
                                  it_bdc-akont.             "'202700'.

    PERFORM bdc_field       USING 'KNB1-ALTKN'
                                  it_bdc-altkn.             "'202700'.
    PERFORM bdc_dynpro      USING 'SAPMF02D' '0215'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'KNB1-ZTERM'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '/00'.
    PERFORM bdc_field       USING 'KNB1-ZTERM'
                                  it_bdc-zterm."'0001'.
    PERFORM bdc_dynpro      USING 'SAPMF02D' '0220'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'KNB5-MAHNA'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '/00'.
    PERFORM bdc_field       USING 'KNB5-MAHNA'
                                  ''.
    PERFORM bdc_dynpro      USING 'SAPMF02D' '0230'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'KNB1-VRSNR'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '/00'.
    PERFORM bdc_dynpro      USING 'SAPMF02D' '0610'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '/00'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'KNBW-WITHT(01)'.
    PERFORM bdc_dynpro      USING 'SAPMF02D' '0310'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'KNVV-VKBUR'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '/00'.
    PERFORM bdc_field       USING 'KNVV-AWAHR'
                                  it_bdc-awahr."'100'.
    PERFORM bdc_field       USING 'KNVV-VKBUR'
                                  it_bdc-vkbur."'KT01'.
    PERFORM bdc_field       USING 'KNVV-WAERS'
                                  it_bdc-waers."'INR'.
    PERFORM bdc_field       USING 'KNVV-KALKS'
                                  it_bdc-kalks."'1'.
    PERFORM bdc_dynpro      USING 'SAPMF02D' '0315'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'KNVV-VWERK'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '/00'.
    PERFORM bdc_field       USING 'KNVV-LPRIO'
                                  it_bdc-lprio."'01'.
    PERFORM bdc_field       USING 'KNVV-KZAZU'
                                  it_bdc-kzazu."'X'.
    PERFORM bdc_field       USING 'KNVV-VSBED'
                                  it_bdc-vsbed."'Z1'.
    PERFORM bdc_field       USING 'KNVV-VWERK'
                                  it_bdc-vwerk."'1001'.
    PERFORM bdc_field       USING 'KNVV-ANTLF'
                                  it_bdc-antlf."'9'.
    PERFORM bdc_dynpro      USING 'SAPMF02D' '0320'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'KNVV-KTGRD'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=ENTS'.
    PERFORM bdc_field       USING 'KNVV-INCO1'
                                  it_bdc-inco1."'CIF'.
    PERFORM bdc_field       USING 'KNVV-INCO2'
                                  it_bdc-inco2."'FREIGHT'.
    PERFORM bdc_field       USING 'KNVV-ZTERM'
                                  it_bdc-zterm1."'0001'.
    PERFORM bdc_field       USING 'KNVV-KTGRD'
                                  it_bdc-ktgrd."'Z1'.
    PERFORM bdc_dynpro      USING 'SAPMF02D' '1350'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'KNVI-TAXKD(06)'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=ENTR'.
    PERFORM bdc_field       USING 'KNVI-TAXKD(01)'
                                  '1'.
    PERFORM bdc_field       USING 'KNVI-TAXKD(02)'
                                  '1'.
    PERFORM bdc_field       USING 'KNVI-TAXKD(03)'
                                  '1'.
    PERFORM bdc_field       USING 'KNVI-TAXKD(04)'
                                  '1'.
    PERFORM bdc_field       USING 'KNVI-TAXKD(05)'
                                 '1'.
*   PERFORM bdc_field       USING 'KNVI-TAXKD(06)'
*                                 '1'.
    PERFORM bdc_dynpro      USING 'SAPMF02D' '1350'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'KNVI-TAXKD(06)'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=ENTR'.
    PERFORM bdc_dynpro      USING 'SAPMF02D' '0324'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'KNVP-PARVW(01)'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                              '=ENTR'.
    CALL TRANSACTION 'XD01' USING bdcdata
                         MODE   p_dismod
                         UPDATE 'S'
                         MESSAGES INTO messtab.
    REFRESHbdcdata.
  ENDLOOP.

  LOOP AT messtab.
    SELECT SINGLE FROM t100 WHERE sprsl messtab-msgspra
                              AND   arbgb messtab-msgid
                              AND   msgnr messtab-msgnr.
    IF sy-subrc 0.
      l_mstring t100-text.
      IF l_mstring CS '&1'.
        REPLACE '&1' WITH messtab-msgv1 INTO l_mstring.
        REPLACE '&2' WITH messtab-msgv2 INTO l_mstring.
        REPLACE '&3' WITH messtab-msgv3 INTO l_mstring.
        REPLACE '&4' WITH messtab-msgv4 INTO l_mstring.
      ELSE.
        REPLACE '&' WITH messtab-msgv1 INTO l_mstring.
        REPLACE '&' WITH messtab-msgv2 INTO l_mstring.
        REPLACE '&' WITH messtab-msgv3 INTO l_mstring.
        REPLACE '&' WITH messtab-msgv4 INTO l_mstring.
      ENDIF.
      CONDENSE l_mstring.
      WRITE/ messtab-msgtypl_mstring(250).
    ELSE.
      WRITE/ messtab.
    ENDIF.
  ENDLOOP.
*&---------------------------------------------------------------------*
*&      Form  BDC_DYNPRO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->PROGRAM    text
*      -->DYNPRO     text
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
  CLEAR bdcdata.
  bdcdata-program  program.
  bdcdata-dynpro   dynpro.
  bdcdata-dynbegin 'X'.
  APPEND bdcdata.
ENDFORM.                    "BDC_DYNPRO


*----------------------------------------------------------------------*
*        Insert field                                                  *
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
*  IF FVAL <> NODATA.
  CLEAR bdcdata.
  bdcdata-fnam fnam.
  bdcdata-fval fval.
  APPEND bdcdata.
*  ENDIF.
ENDFORM.                    "BDC_FIELD
*  PERFORM CLOSE_GROUP.
*perform bdc_transaction using 'XD01'.

*perform close_group.