0% found this document useful (0 votes)
123 views3 pages

BDC For xd01

The document contains code to extract data from an Excel file, populate a database table with the extracted data, and then use BDC functionality to create customer master records in SAP from the extracted data. Key steps include converting the Excel file to an internal table, looping through the table to populate fields and insert BDC calls, and opening and closing the BDC session.

Uploaded by

Saheb Chatterjee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
123 views3 pages

BDC For xd01

The document contains code to extract data from an Excel file, populate a database table with the extracted data, and then use BDC functionality to create customer master records in SAP from the extracted data. Key steps include converting the Excel file to an internal table, looping through the table to populate fields and insert BDC calls, and opening and closing the BDC session.

Uploaded by

Saheb Chatterjee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

REPORT Z_BDC_TESTXD01.

type-POOLS: TRUXS.
PARAMETERS: p_file TYPE rlgrap-filename.

TYPES:BEGIN OF ty_final,
bukrs TYPE bukrs,
ktokd TYPE ktokd,
anred TYPE ANRED,
name1 TYPE name1,
stras TYPE stras,
pfach TYPE pfach,
ort01 TYPE ort01,
pstlz TYPE pstlz,
ort02 type ort02,
land1 TYPE land1,
regio TYPE regio,
spras TYPE char2,
END OF ty_final.

DATA:it_final type TABLE OF ty_final,


it_raw TYPE truxs_t_text_data,
it_bdcdata type TABLE OF bdcdata,
wa_bdcdata type bdcdata,
wa_final TYPE ty_final,
it_msg TYPE TABLE OF bdcmsgcoll,
it_msg1 TYPE TABLE OF bdcmsgcoll,
wa_msg TYPE bdcmsgcoll,
wa_msg1 TYPE bdcmsgcoll.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.


CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = 'p_file '
IMPORTING
FILE_NAME = p_file.

START-OF-SELECTION.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'


EXPORTING
* I_FIELD_SEPERATOR =
* I_LINE_HEADER =
I_TAB_RAW_DATA = it_raw
I_FILENAME = p_file
TABLES
I_TAB_CONVERTED_DATA = it_final.

CALL FUNCTION 'BDC_OPEN_GROUP'


EXPORTING
* CLIENT = SY-MANDT
* DEST = FILLER8
GROUP = 'arijit'
* HOLDDATE = FILLER8
KEEP = 'X'
USER = sy-uname
* RECORD = FILLER1
* PROG = SY-CPROG
* DCPFM = '%'
* DATFM = '%'
* IMPORTING
* QID =
EXCEPTIONS
CLIENT_INVALID = 1
DESTINATION_INVALID = 2
GROUP_INVALID = 3
GROUP_IS_LOCKED = 4
HOLDDATE_INVALID = 5
INTERNAL_ERROR = 6
QUEUE_ERROR = 7
RUNNING = 8
SYSTEM_LOCK_ERROR = 9
USER_INVALID = 10
OTHERS = 11
.

LOOP at it_final into wa_final.

refresh it_bdcdata.

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'
wa_final-bukrs."'1000'.
perform bdc_field using 'RF02D-KTOKD'
wa_final-ktokd."'ZAG1'.
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'
wa_final-anred."'Ms'.
perform bdc_field using 'KNA1-NAME1'
wa_final-name1."'ani roy'.
perform bdc_field using 'KNA1-STRAS'
wa_final-stras."'16-4'.
perform bdc_field using 'KNA1-PFACH'
wa_final-pfach."'MMandir'.
perform bdc_field using 'KNA1-ORT01'
wa_final-ort01."'kolkata'.
perform bdc_field using 'KNA1-PSTLZ'
wa_final-pstlz."'70065'.
perform bdc_field using 'KNA1-ORT02'
wa_final-ort02."'north 24 pg'.
perform bdc_field using 'KNA1-LAND1'
wa_final-land1."'us'.
perform bdc_field using 'KNA1-REGIO'
wa_final-regio."'tx'.
perform bdc_field using 'KNA1-SPRAS'
wa_final-spras."'en'.
perform bdc_dynpro using 'SAPMF02D' '0120'.
perform bdc_field using 'BDC_CURSOR'
'KNA1-LIFNR'.
perform bdc_field using 'BDC_OKCODE'
'=UPDA'.

CALL FUNCTION 'BDC_INSERT'


EXPORTING
TCODE = 'XD01'
* POST_LOCAL = NOVBLOCAL
* PRINTING = NOPRINT
* SIMUBATCH = ' '
* CTUPARAMS = ' '
TABLES
DYNPROTAB = it_bdcdata.
* EXCEPTIONS
* INTERNAL_ERROR = 1
* NOT_OPEN = 2
* QUEUE_ERROR = 3
* TCODE_INVALID = 4
* PRINTING_INVALID = 5
* POSTING_INVALID = 6
* OTHERS = 7
.
ENDLOOP.

CALL FUNCTION 'BDC_CLOSE_GROUP'


EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3
.

FORM BDC_DYNPRO USING PROGRAM DYNPRO.


CLEAR wa_BDCDATA.
wa_BDCDATA-PROGRAM = PROGRAM.
wa_BDCDATA-DYNPRO = DYNPRO.
wa_BDCDATA-DYNBEGIN = 'X'.
APPEND wa_BDCDATA to it_bdcdata.
ENDFORM.

*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL <> space.
CLEAR wa_BDCDATA.
wa_BDCDATA-FNAM = FNAM.
wa_BDCDATA-FVAL = FVAL.
APPEND wa_BDCDATA to it_bdcdata.
ENDIF.
ENDFORM.

You might also like