Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to proceed with BDC

Former Member
0 Kudos

Hi experts,

I am new to BDC. I am asked to upload data from excel sheet to table V_T604. I dont know how to proceed. Can you please suggest me what are all the steps to be done....

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Steps to create a BDC program.

1. Create an internal table with fields same as Excel sheet fields.

2. Declare an internal table with BDCDATA table to store the BDC recording.

3. Declare an internal table with BDCMSGCOL to store the error messages after

the execution of the BDC.

4. Write the code using the fun. module ALSM_EXCEL_TO_INTERNAL_TABLE

to upload the data from the excel sheet.

5. loop that internal table and write the Subroutines to fill the internal table

BDCDATA with the recording of a specified Transaction Code.

6. Using Call Transaction execute the BDC recording.

7. Check Sy-subrc = 0 and store the error messages in the internal table.

8. If you want you can pass those error reecords to a session using the SESSION method.

Here is an example of a BDC program, but this program is from a text file. Change the function module WS_UPLOAD with ALSM_EXCEL_TO_INTERNAL_TABLE

to upload an excel and write the program with your BDC reocrding. You can do recording using t-code SHDB.

Sample Program:

&----


*& Report : ZJAYARAM_DATASET_XD01

*& Title : Program for running BDC and creating error log

*& Author : JAYARAMA SARMA

*& Created on : 03/05/2004

*& Request

*& Desription : This program describes running bdc with file in

  • APPLICATION SERVER

&----


*& Modification Log

&----


*& Mod # Author Date Requested by

*& Reason for Change

&----


*& 00 #

*&

&----


REPORT ZJAYARAM_DATASET_XD01 NO STANDARD PAGE HEADING LINE-SIZE 132

LINE-COUNT 60

MESSAGE-ID Z00.

----


  • Table/Structure declarations. *

----


TABLES : KNA1. "Customer master

----


  • Constants declarations. *

----


CONSTANTS : C_MODE VALUE 'N',

C_UPDATE VALUE 'S',

C_X VALUE 'X',

C_SESS TYPE APQI-GROUPID VALUE 'ZCUSTOMER', "Session Name

C_XD01 LIKE TSTC-TCODE VALUE 'XD01'.

----


  • Variable declarations. *

----


DATA : V_FNAME(15) VALUE SPACE, " Name of file to be created

V_FAILREC TYPE I, " No of failed records

V_MSG(255), " Message Text

V_ERRREC TYPE I, " No of failed records

V_LINES TYPE I. " No of records

----


*-- FLAG DECLARATIONS

----


DATA : FG_DATA_EXIST VALUE 'X', " Check for data

FG_SESSION_OPEN VALUE ' '. " Check for Session Open

----


  • Structures / Internal table declarations *

----


*-- Structure to hold BDC data

TYPES : BEGIN OF T_BDCTABLE.

INCLUDE STRUCTURE BDCDATA.

TYPES END OF T_BDCTABLE.

*-- Structure to trap BDC messages

TYPES : BEGIN OF T_MSG.

INCLUDE STRUCTURE BDCMSGCOLL.

TYPES : END OF T_MSG.

*-- Structure to trap ERROR messages

TYPES : BEGIN OF T_ERR_MSG,

MESSAGE(255),

END OF T_ERR_MSG.

*--Internal table to store flat file data

DATA:BEGIN OF IT_KNA1 OCCURS 0,

KUNNR LIKE KNA1-KUNNR,

KTOKD LIKE T077D-KTOKD,

NAME1 LIKE KNA1-NAME1,

SORTL LIKE KNA1-SORTL,

ORT01 LIKE KNA1-ORT01,

PSTLZ LIKE KNA1-PSTLZ,

LAND1 LIKE KNA1-LAND1,

SPRAS LIKE KNA1-SPRAS,

LZONE LIKE KNA1-LZONE,

END OF IT_KNA1.

*-- Internal table to hold BDC data

DATA: IT_BDCDATA TYPE STANDARD TABLE OF T_BDCTABLE WITH HEADER LINE,

*-- Internal Table to store ALL messages

IT_MSG TYPE STANDARD TABLE OF T_MSG WITH HEADER LINE,

*-- Internal Table to store error messages

IT_ERR_MSG TYPE STANDARD TABLE OF T_ERR_MSG WITH HEADER LINE.

----


  • Selection Screen. *

----


SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

PARAMETERS : P_FLNAME(15) OBLIGATORY.

SELECTION-SCREEN END OF BLOCK B1.

SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.

SELECTION-SCREEN BEGIN OF LINE.

PARAMETERS : R_LIST RADIOBUTTON GROUP GRP1.

SELECTION-SCREEN COMMENT 5(20) TEXT-003.

PARAMETERS : R_SESS RADIOBUTTON GROUP GRP1.

SELECTION-SCREEN COMMENT 30(20) TEXT-004.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK B2.

----


  • Event:Initialization *

----


INITIALIZATION.

----


  • AT Selection Screen. *

----


AT SELECTION-SCREEN.

----


  • Event: Start-of-Selection *

----


START-OF-SELECTION.

V_FNAME = P_FLNAME.

PERFORM GET_DATA.

PERFORM GENERATE_DATASET.

----


  • Event: End-of-Selection *

----


END-OF-SELECTION.

IF FG_DATA_EXIST = ' '.

MESSAGE I010 WITH TEXT-009.

EXIT.

ENDIF.

PERFORM GENERATE_BDCDATA.

PERFORM DISPLAY_ERR_RECS.

----


  • Event: top-of-page

----


TOP-OF-PAGE.

//////////////////////////////////////////////////////////////////////

*

  • FORM DEFINITIONS *

*

*//////////////////////////////////////////////////////////////////////

&----


*& Form get_data

&----


  • Subroutine to get the data from mard

----


  • --> p1 text

  • <-- p2 text

----


FORM GET_DATA.

CALL FUNCTION 'UPLOAD'

EXPORTING

  • CODEPAGE = ' '

FILENAME = 'C:\XD01.TXT'

FILETYPE = 'DAT'

  • ITEM = ' '

  • FILEMASK_MASK = ' '

  • FILEMASK_TEXT = ' '

  • FILETYPE_NO_CHANGE = ' '

  • FILEMASK_ALL = ' '

  • FILETYPE_NO_SHOW = ' '

  • LINE_EXIT = ' '

  • USER_FORM = ' '

  • USER_PROG = ' '

  • SILENT = 'S'

  • IMPORTING

  • FILESIZE =

  • CANCEL =

  • ACT_FILENAME =

  • ACT_FILETYPE =

TABLES

DATA_TAB = IT_KNA1

  • EXCEPTIONS

  • CONVERSION_ERROR = 1

  • INVALID_TABLE_WIDTH = 2

  • INVALID_TYPE = 3

  • NO_BATCH = 4

  • UNKNOWN_ERROR = 5

  • GUI_REFUSE_FILETRANSFER = 6

  • OTHERS = 7

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

IF IT_KNA1[] IS INITIAL.

FG_DATA_EXIST = ' '.

ENDIF.

ENDFORM. " get_data

&----


*& Form GENERATE_DATASET

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM GENERATE_DATASET.

MESSAGE I010 WITH 'OPENING FILE IN APPLICATION SERVER'.

**--Creating a data set in application server

OPEN DATASET V_FNAME FOR OUTPUT IN TEXT MODE.

**---Transfering data from internal table to dataset

MESSAGE I010 WITH 'TRANSFERING DATA FROM INETERAL TABLE TO THE FILE'.

LOOP AT IT_KNA1.

TRANSFER IT_KNA1 TO V_FNAME.

ENDLOOP.

**--Closing the dataset

MESSAGE I010 WITH 'CLOSING THE FILE'.

CLOSE DATASET V_FNAME.

ENDFORM. " GENERATE_DATASET

&----


*& Form BDC_DYNPRO

&----


  • text

----


  • -->P_0467 text

  • -->P_0468 text

----


FORM BDC_DYNPRO USING PROGRAM DYNPRO.

CLEAR IT_BDCDATA.

IT_BDCDATA-PROGRAM = PROGRAM.

IT_BDCDATA-DYNPRO = DYNPRO.

IT_BDCDATA-DYNBEGIN = 'X'.

APPEND IT_BDCDATA.

ENDFORM.

&----


*& Form BDC_FIELD

&----


  • text

----


  • -->P_0472 text

  • -->P_0473 text

----


FORM BDC_FIELD USING FNAM FVAL.

IF NOT FVAL IS INITIAL.

CLEAR IT_BDCDATA.

IT_BDCDATA-FNAM = FNAM.

IT_BDCDATA-FVAL = FVAL.

APPEND IT_BDCDATA.

ENDIF.

ENDFORM.

&----


*& Form GENERATE_BDCDATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM GENERATE_BDCDATA.

REFRESH IT_KNA1.

  • Opening dataset for reading

OPEN DATASET V_FNAME FOR INPUT IN TEXT MODE.

        • Reading the file from application server

DO.

CLEAR: IT_KNA1,IT_BDCDATA.

REFRESH IT_BDCDATA.

READ DATASET V_FNAME INTO IT_KNA1.

IF SY-SUBRC <> 0.

EXIT.

ELSE.

  • Populate BDC Data for Initial Screen

PERFORM : BDC_DYNPRO USING 'SAPMF02D' '0100',

BDC_FIELD USING 'BDC_CURSOR' 'RF02D-KUNNR',

BDC_FIELD USING 'BDC_OKCODE' '/00',

BDC_FIELD USING 'RF02D-KUNNR' IT_KNA1-KUNNR,

BDC_FIELD USING 'RF02D-KTOKD' IT_KNA1-KTOKD.

  • Populate BDC Data for Second Screen

PERFORM : BDC_DYNPRO USING 'SAPMF02D' '0110',

BDC_FIELD USING 'BDC_CURSOR' 'KNA1-NAME1',

BDC_FIELD USING 'BDC_OKCODE' '/00',

BDC_FIELD USING 'KNA1-NAME1' IT_KNA1-NAME1,

BDC_FIELD USING 'KNA1-SORTL' IT_KNA1-SORTL,

BDC_FIELD USING 'KNA1-ORT01' IT_KNA1-ORT01,

BDC_FIELD USING 'KNA1-PSTLZ' IT_KNA1-PSTLZ,

BDC_FIELD USING 'KNA1-LAND1' IT_KNA1-LAND1,

BDC_FIELD USING 'KNA1-SPRAS' IT_KNA1-SPRAS.

  • Populate BDC Data for Third Screen

PERFORM : BDC_DYNPRO USING 'SAPMF02D' '0120',

BDC_FIELD USING 'BDC_CURSOR' 'KNA1-LZONE',

BDC_FIELD USING 'BDC_OKCODE' '=UPDA',

BDC_FIELD USING 'KNA1-LZONE' IT_KNA1-LZONE.

CALL TRANSACTION C_XD01 USING IT_BDCDATA

MODE C_MODE

UPDATE C_UPDATE

MESSAGES INTO IT_MSG.

IF SY-SUBRC <> 0.

*--In case of error list display

IF R_LIST = C_X.

V_ERRREC = V_ERRREC + 1.

PERFORM FORMAT_MESSAGE.

IT_ERR_MSG-MESSAGE = V_MSG.

APPEND IT_ERR_MSG.

CLEAR : V_MSG,IT_ERR_MSG.

ENDIF.

*--In case of session log

IF R_SESS = C_X.

*-- In case of transaction fails.

IF FG_SESSION_OPEN = ' '.

FG_SESSION_OPEN = C_X.

PERFORM BDC_OPEN_GROUP.

ENDIF. " IF FG_SESSION_OPEN = ' '.

*-- Insert BDC Data..

PERFORM BDC_INSERT_DATA.

ENDIF. " IF R_SESS = C_X.

ENDIF. " IF SY-SUBRC <> 0.

ENDIF. " IF SY-SUBRC <> 0.

ENDDO.

  • Closing the dataset

CLOSE DATASET V_FNAME.

*-- Close the session if opened

IF FG_SESSION_OPEN = C_X.

PERFORM BDC_CLOSE_GROUP.

CALL TRANSACTION 'SM35'.

ENDIF.

ENDFORM. " GENERATE_BDCDATA

&----


*& Form BDC_OPEN_GROUP

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM BDC_OPEN_GROUP.

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

CLIENT = SY-MANDT

  • DEST = FILLER8

GROUP = C_SESS

  • HOLDDATE = FILLER8

KEEP = C_X

USER = SY-UNAME

  • RECORD = FILLER1

  • 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

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " BDC_OPEN_GROUP

&----


*& Form BDC_INSERT_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM BDC_INSERT_DATA.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = C_XD01

  • POST_LOCAL = NOVBLOCAL

  • PRINTING = NOPRINT

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

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " BDC_INSERT_DATA

&----


*& Form BDC_CLOSE_GROUP

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM BDC_CLOSE_GROUP.

CALL FUNCTION 'BDC_CLOSE_GROUP'

EXCEPTIONS

NOT_OPEN = 1

QUEUE_ERROR = 2

OTHERS = 3

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " BDC_CLOSE_GROUP

&----


*& Form FORMAT_MESSAGE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM FORMAT_MESSAGE.

CLEAR V_LINES.

DESCRIBE TABLE IT_MSG LINES V_LINES.

READ TABLE IT_MSG INDEX V_LINES.

CLEAR V_MSG.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = IT_MSG-MSGID

LANG = IT_MSG-MSGSPRA

NO = IT_MSG-MSGNR

V1 = IT_MSG-MSGV1

V2 = IT_MSG-MSGV2

V3 = IT_MSG-MSGV3

V4 = IT_MSG-MSGV4

IMPORTING

MSG = V_MSG

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " FORMAT_MESSAGE

&----


*& Form DISPLAY_ERR_RECS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM DISPLAY_ERR_RECS.

LOOP AT IT_ERR_MSG.

WRITE: / IT_ERR_MSG-MESSAGE.

ENDLOOP.

ENDFORM. " DISPLAY_ERR_RECS

Regards,

Jayaram...

10 REPLIES 10

former_member181962
Active Contributor
0 Kudos

Hi Buvana,

Step 1) Upload the excel data into an internal table using the FM: GUI_UPLOAD.

Step 2) Do a BDC for SM30 transaction for the VIEW V_T604.

(To create a BDC for Sm30 , you need to record the transaction using SHDB transaction.)

Regards,

Ravi

Former Member
0 Kudos

Hi Buvana,

First move all the data from excel file to internal table by using the FM ALSM_EXCEL_TO_INTERNAL_TABLE. After that from internal table to view byusing the recording and neccessary coding.

Reply for queries.

Regards,

Kumar.

Former Member
0 Kudos

Hi Buvana,

V_T604 is the maintenance view.

Just Go to SHDB ,

Create new recording for transaction SM30.

Enter a new record. and save the recording.

click the program push button to create the Abap program for BDC.

Then you add the FM "ALSM_EXCEL_TO_INTERNAL_TABLE" To get the data from excel to itab.

Change the necessary coding in Program (Loops).

Regards

Rusidar

Former Member
0 Kudos

Hi,

Steps to create a BDC program.

1. Create an internal table with fields same as Excel sheet fields.

2. Declare an internal table with BDCDATA table to store the BDC recording.

3. Declare an internal table with BDCMSGCOL to store the error messages after

the execution of the BDC.

4. Write the code using the fun. module ALSM_EXCEL_TO_INTERNAL_TABLE

to upload the data from the excel sheet.

5. loop that internal table and write the Subroutines to fill the internal table

BDCDATA with the recording of a specified Transaction Code.

6. Using Call Transaction execute the BDC recording.

7. Check Sy-subrc = 0 and store the error messages in the internal table.

8. If you want you can pass those error reecords to a session using the SESSION method.

Here is an example of a BDC program, but this program is from a text file. Change the function module WS_UPLOAD with ALSM_EXCEL_TO_INTERNAL_TABLE

to upload an excel and write the program with your BDC reocrding. You can do recording using t-code SHDB.

Sample Program:

&----


*& Report : ZJAYARAM_DATASET_XD01

*& Title : Program for running BDC and creating error log

*& Author : JAYARAMA SARMA

*& Created on : 03/05/2004

*& Request

*& Desription : This program describes running bdc with file in

  • APPLICATION SERVER

&----


*& Modification Log

&----


*& Mod # Author Date Requested by

*& Reason for Change

&----


*& 00 #

*&

&----


REPORT ZJAYARAM_DATASET_XD01 NO STANDARD PAGE HEADING LINE-SIZE 132

LINE-COUNT 60

MESSAGE-ID Z00.

----


  • Table/Structure declarations. *

----


TABLES : KNA1. "Customer master

----


  • Constants declarations. *

----


CONSTANTS : C_MODE VALUE 'N',

C_UPDATE VALUE 'S',

C_X VALUE 'X',

C_SESS TYPE APQI-GROUPID VALUE 'ZCUSTOMER', "Session Name

C_XD01 LIKE TSTC-TCODE VALUE 'XD01'.

----


  • Variable declarations. *

----


DATA : V_FNAME(15) VALUE SPACE, " Name of file to be created

V_FAILREC TYPE I, " No of failed records

V_MSG(255), " Message Text

V_ERRREC TYPE I, " No of failed records

V_LINES TYPE I. " No of records

----


*-- FLAG DECLARATIONS

----


DATA : FG_DATA_EXIST VALUE 'X', " Check for data

FG_SESSION_OPEN VALUE ' '. " Check for Session Open

----


  • Structures / Internal table declarations *

----


*-- Structure to hold BDC data

TYPES : BEGIN OF T_BDCTABLE.

INCLUDE STRUCTURE BDCDATA.

TYPES END OF T_BDCTABLE.

*-- Structure to trap BDC messages

TYPES : BEGIN OF T_MSG.

INCLUDE STRUCTURE BDCMSGCOLL.

TYPES : END OF T_MSG.

*-- Structure to trap ERROR messages

TYPES : BEGIN OF T_ERR_MSG,

MESSAGE(255),

END OF T_ERR_MSG.

*--Internal table to store flat file data

DATA:BEGIN OF IT_KNA1 OCCURS 0,

KUNNR LIKE KNA1-KUNNR,

KTOKD LIKE T077D-KTOKD,

NAME1 LIKE KNA1-NAME1,

SORTL LIKE KNA1-SORTL,

ORT01 LIKE KNA1-ORT01,

PSTLZ LIKE KNA1-PSTLZ,

LAND1 LIKE KNA1-LAND1,

SPRAS LIKE KNA1-SPRAS,

LZONE LIKE KNA1-LZONE,

END OF IT_KNA1.

*-- Internal table to hold BDC data

DATA: IT_BDCDATA TYPE STANDARD TABLE OF T_BDCTABLE WITH HEADER LINE,

*-- Internal Table to store ALL messages

IT_MSG TYPE STANDARD TABLE OF T_MSG WITH HEADER LINE,

*-- Internal Table to store error messages

IT_ERR_MSG TYPE STANDARD TABLE OF T_ERR_MSG WITH HEADER LINE.

----


  • Selection Screen. *

----


SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

PARAMETERS : P_FLNAME(15) OBLIGATORY.

SELECTION-SCREEN END OF BLOCK B1.

SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.

SELECTION-SCREEN BEGIN OF LINE.

PARAMETERS : R_LIST RADIOBUTTON GROUP GRP1.

SELECTION-SCREEN COMMENT 5(20) TEXT-003.

PARAMETERS : R_SESS RADIOBUTTON GROUP GRP1.

SELECTION-SCREEN COMMENT 30(20) TEXT-004.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK B2.

----


  • Event:Initialization *

----


INITIALIZATION.

----


  • AT Selection Screen. *

----


AT SELECTION-SCREEN.

----


  • Event: Start-of-Selection *

----


START-OF-SELECTION.

V_FNAME = P_FLNAME.

PERFORM GET_DATA.

PERFORM GENERATE_DATASET.

----


  • Event: End-of-Selection *

----


END-OF-SELECTION.

IF FG_DATA_EXIST = ' '.

MESSAGE I010 WITH TEXT-009.

EXIT.

ENDIF.

PERFORM GENERATE_BDCDATA.

PERFORM DISPLAY_ERR_RECS.

----


  • Event: top-of-page

----


TOP-OF-PAGE.

//////////////////////////////////////////////////////////////////////

*

  • FORM DEFINITIONS *

*

*//////////////////////////////////////////////////////////////////////

&----


*& Form get_data

&----


  • Subroutine to get the data from mard

----


  • --> p1 text

  • <-- p2 text

----


FORM GET_DATA.

CALL FUNCTION 'UPLOAD'

EXPORTING

  • CODEPAGE = ' '

FILENAME = 'C:\XD01.TXT'

FILETYPE = 'DAT'

  • ITEM = ' '

  • FILEMASK_MASK = ' '

  • FILEMASK_TEXT = ' '

  • FILETYPE_NO_CHANGE = ' '

  • FILEMASK_ALL = ' '

  • FILETYPE_NO_SHOW = ' '

  • LINE_EXIT = ' '

  • USER_FORM = ' '

  • USER_PROG = ' '

  • SILENT = 'S'

  • IMPORTING

  • FILESIZE =

  • CANCEL =

  • ACT_FILENAME =

  • ACT_FILETYPE =

TABLES

DATA_TAB = IT_KNA1

  • EXCEPTIONS

  • CONVERSION_ERROR = 1

  • INVALID_TABLE_WIDTH = 2

  • INVALID_TYPE = 3

  • NO_BATCH = 4

  • UNKNOWN_ERROR = 5

  • GUI_REFUSE_FILETRANSFER = 6

  • OTHERS = 7

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

IF IT_KNA1[] IS INITIAL.

FG_DATA_EXIST = ' '.

ENDIF.

ENDFORM. " get_data

&----


*& Form GENERATE_DATASET

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM GENERATE_DATASET.

MESSAGE I010 WITH 'OPENING FILE IN APPLICATION SERVER'.

**--Creating a data set in application server

OPEN DATASET V_FNAME FOR OUTPUT IN TEXT MODE.

**---Transfering data from internal table to dataset

MESSAGE I010 WITH 'TRANSFERING DATA FROM INETERAL TABLE TO THE FILE'.

LOOP AT IT_KNA1.

TRANSFER IT_KNA1 TO V_FNAME.

ENDLOOP.

**--Closing the dataset

MESSAGE I010 WITH 'CLOSING THE FILE'.

CLOSE DATASET V_FNAME.

ENDFORM. " GENERATE_DATASET

&----


*& Form BDC_DYNPRO

&----


  • text

----


  • -->P_0467 text

  • -->P_0468 text

----


FORM BDC_DYNPRO USING PROGRAM DYNPRO.

CLEAR IT_BDCDATA.

IT_BDCDATA-PROGRAM = PROGRAM.

IT_BDCDATA-DYNPRO = DYNPRO.

IT_BDCDATA-DYNBEGIN = 'X'.

APPEND IT_BDCDATA.

ENDFORM.

&----


*& Form BDC_FIELD

&----


  • text

----


  • -->P_0472 text

  • -->P_0473 text

----


FORM BDC_FIELD USING FNAM FVAL.

IF NOT FVAL IS INITIAL.

CLEAR IT_BDCDATA.

IT_BDCDATA-FNAM = FNAM.

IT_BDCDATA-FVAL = FVAL.

APPEND IT_BDCDATA.

ENDIF.

ENDFORM.

&----


*& Form GENERATE_BDCDATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM GENERATE_BDCDATA.

REFRESH IT_KNA1.

  • Opening dataset for reading

OPEN DATASET V_FNAME FOR INPUT IN TEXT MODE.

        • Reading the file from application server

DO.

CLEAR: IT_KNA1,IT_BDCDATA.

REFRESH IT_BDCDATA.

READ DATASET V_FNAME INTO IT_KNA1.

IF SY-SUBRC <> 0.

EXIT.

ELSE.

  • Populate BDC Data for Initial Screen

PERFORM : BDC_DYNPRO USING 'SAPMF02D' '0100',

BDC_FIELD USING 'BDC_CURSOR' 'RF02D-KUNNR',

BDC_FIELD USING 'BDC_OKCODE' '/00',

BDC_FIELD USING 'RF02D-KUNNR' IT_KNA1-KUNNR,

BDC_FIELD USING 'RF02D-KTOKD' IT_KNA1-KTOKD.

  • Populate BDC Data for Second Screen

PERFORM : BDC_DYNPRO USING 'SAPMF02D' '0110',

BDC_FIELD USING 'BDC_CURSOR' 'KNA1-NAME1',

BDC_FIELD USING 'BDC_OKCODE' '/00',

BDC_FIELD USING 'KNA1-NAME1' IT_KNA1-NAME1,

BDC_FIELD USING 'KNA1-SORTL' IT_KNA1-SORTL,

BDC_FIELD USING 'KNA1-ORT01' IT_KNA1-ORT01,

BDC_FIELD USING 'KNA1-PSTLZ' IT_KNA1-PSTLZ,

BDC_FIELD USING 'KNA1-LAND1' IT_KNA1-LAND1,

BDC_FIELD USING 'KNA1-SPRAS' IT_KNA1-SPRAS.

  • Populate BDC Data for Third Screen

PERFORM : BDC_DYNPRO USING 'SAPMF02D' '0120',

BDC_FIELD USING 'BDC_CURSOR' 'KNA1-LZONE',

BDC_FIELD USING 'BDC_OKCODE' '=UPDA',

BDC_FIELD USING 'KNA1-LZONE' IT_KNA1-LZONE.

CALL TRANSACTION C_XD01 USING IT_BDCDATA

MODE C_MODE

UPDATE C_UPDATE

MESSAGES INTO IT_MSG.

IF SY-SUBRC <> 0.

*--In case of error list display

IF R_LIST = C_X.

V_ERRREC = V_ERRREC + 1.

PERFORM FORMAT_MESSAGE.

IT_ERR_MSG-MESSAGE = V_MSG.

APPEND IT_ERR_MSG.

CLEAR : V_MSG,IT_ERR_MSG.

ENDIF.

*--In case of session log

IF R_SESS = C_X.

*-- In case of transaction fails.

IF FG_SESSION_OPEN = ' '.

FG_SESSION_OPEN = C_X.

PERFORM BDC_OPEN_GROUP.

ENDIF. " IF FG_SESSION_OPEN = ' '.

*-- Insert BDC Data..

PERFORM BDC_INSERT_DATA.

ENDIF. " IF R_SESS = C_X.

ENDIF. " IF SY-SUBRC <> 0.

ENDIF. " IF SY-SUBRC <> 0.

ENDDO.

  • Closing the dataset

CLOSE DATASET V_FNAME.

*-- Close the session if opened

IF FG_SESSION_OPEN = C_X.

PERFORM BDC_CLOSE_GROUP.

CALL TRANSACTION 'SM35'.

ENDIF.

ENDFORM. " GENERATE_BDCDATA

&----


*& Form BDC_OPEN_GROUP

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM BDC_OPEN_GROUP.

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

CLIENT = SY-MANDT

  • DEST = FILLER8

GROUP = C_SESS

  • HOLDDATE = FILLER8

KEEP = C_X

USER = SY-UNAME

  • RECORD = FILLER1

  • 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

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " BDC_OPEN_GROUP

&----


*& Form BDC_INSERT_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM BDC_INSERT_DATA.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = C_XD01

  • POST_LOCAL = NOVBLOCAL

  • PRINTING = NOPRINT

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

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " BDC_INSERT_DATA

&----


*& Form BDC_CLOSE_GROUP

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM BDC_CLOSE_GROUP.

CALL FUNCTION 'BDC_CLOSE_GROUP'

EXCEPTIONS

NOT_OPEN = 1

QUEUE_ERROR = 2

OTHERS = 3

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " BDC_CLOSE_GROUP

&----


*& Form FORMAT_MESSAGE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM FORMAT_MESSAGE.

CLEAR V_LINES.

DESCRIBE TABLE IT_MSG LINES V_LINES.

READ TABLE IT_MSG INDEX V_LINES.

CLEAR V_MSG.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = IT_MSG-MSGID

LANG = IT_MSG-MSGSPRA

NO = IT_MSG-MSGNR

V1 = IT_MSG-MSGV1

V2 = IT_MSG-MSGV2

V3 = IT_MSG-MSGV3

V4 = IT_MSG-MSGV4

IMPORTING

MSG = V_MSG

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " FORMAT_MESSAGE

&----


*& Form DISPLAY_ERR_RECS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM DISPLAY_ERR_RECS.

LOOP AT IT_ERR_MSG.

WRITE: / IT_ERR_MSG-MESSAGE.

ENDLOOP.

ENDFORM. " DISPLAY_ERR_RECS

Regards,

Jayaram...

0 Kudos

Hi Jayaram,

Thanks a lot for your valuable reply. It helped me a lot. But can you explain me the about need of creating a data set in application server.

Also there is a loop statement DO in the FORM GENERATE BDC DATA step. If we just put DO...END DO alone, will it not result in a infinite loop.

Please explain me these things kindly. Thanks in advance

0 Kudos

Hey Buvana,

Don't confuse abt that Data

Set creation . That's actually my requirement to create a dataset and read the dataset from appliction server and do the BDC. I just gave you an example program which I had. One more thing is that 'Do..Enddo' won't go to Infinite loop because it will come when all the records were processed. You can see that there is a sy-subrc check after the read statement and Exit. Pls let me know if you still need any clarification.

Regards,

Jayaram...

0 Kudos

Hi Jayaram,

Thanks a lot for your reply. In my program i'm asked to upload excel data which is present in application or presentation server to V_T604. So is that enough that i just upload the data into internal table and from there i move it to BDC table.

Also can you please explain the role of call transaction. Is that on calling this transaction using bdcdata, the contents of bdc will be transferred to the database view.

Also could you please explain me about what is session log? Why are you doing BDC_OPEN_GROUP and BDC_INSERT_DATA there. It would be great if you could help me in clearing these doubts..

Very very sorrry for disturbing you. Thanks a lot.

Former Member
0 Kudos

Hi Buvana,

First of all , before you move your data from excel sheet to the internal table, you need to specify a location for uploading the excel sheet into your internal table.

for this u need to use two specific FM's .

the first one for file selection : WS_FILENAME_GET.

The second one for data upload : TEXT_CONVERT_XLS_TO_SAP.

Afetr doing this the regular part of mapping comes and then we can run the session and then execute and release it.

Hope this will resolve your query.

Reward all the helpful answers.

Regards

Former Member
0 Kudos

I am expecting some more explanations.

0 Kudos

Hi Buvana,

Check this material. This might help you.

BATCH DATA COMMUNICATION

About Data Transfer In R/3 System

When a company decides to implement the SAP R/3 to manage business-critical data, it usually does not start from a no-data situation. Normally, a SAP R/3 project comes into replace or complement existing application.

In the process of replacing current applications and transferring application data, two situations might occur:

• The first is when application data to be replaced is transferred at once, and only once.

• The second situation is to transfer data periodically from external systems to SAP and vice versa.

• There is a period of time when information has to be transferred from existing application, to SAP R/3, and often this process will be repetitive.

The SAP system offers two primary methods for transferring data into SAP systems. From non-SAP systems or legacy system. These two methods are collectively called “batch input” or “batch data communication”.

1. SESSION METHOD

2. CALL TRANSACTION

3. DIRECT INPUT

Advantages offered by BATCH INPUT method:

1. Can process large data volumes in batch.

2. Can be planned and submitted in the background.

3. No manual interaction is required when data is transferred.

4. Data integrity is maintained as whatever data is transferred to the table is through transaction. Hence batch input data is submitted to all the checks and validations.

To implement one of the supported data transfers, you must often write the program that exports the data from your non-SAP system. This program, known as a “data transfer” program must map the data from the external system into the data structure required by the SAP batch input program.

The batch input program must build all of the input to execute the SAP transaction.

Two main steps are required:

• To build an internal table containing every screen and every field to be filled in during the execution of an SAP transaction.

• To pass the table to SAP for processing.

Prerequisite for Data Transfer Program

Writing a Data Transfer Program involves following prerequisites:

Analyzing data from local file

Analyzing transaction

Analyzing transaction involves following steps:

• The transaction code, if you do not already know it.

• Which fields require input i.e., mandatory.

• Which fields can you allow to default to standard values.

• The names, types, and lengths of the fields that are used by a transaction.

• Screen number and Name of module pool program behind a particular transaction.

To analyze a transaction::

• Start the transaction by menu or by entering the transaction code in the command box.

(You can determine the transaction name by choosing System – Status.)

• Step through the transaction, entering the data will be required for processing your batch input data.

• On each screen, note the program name and screen (dynpro) number.

(dynpro = dyn + pro. Dyn = screen, pro = number)

• Display these by choosing System – Status. The relevant fields are Program (dynpro) and Dynpro number. If pop-up windows occur during execution, you can get the program name and screen number by pressing F1 on any field or button on the screen.

The technical info pop-up shows not only the field information but also the program and screen.

• For each field, check box, and radio button on each screen, press F1 (help) and then choose Technical Info.

Note the following information:

- The field name for batch input, which you’ll find in its own box.

- The length and data type of the field. You can display this information by double clicking on the Data Element field.

• Find out the identification code for each function (button or menu) that you must execute to process the batch-input data (or to go to new screen).

Place the cursor on the button or menu entry while holding down the left mouse button. Then press F1.

In the pop-up window that follows, choose Technical info and note the code that is shown in the Function field.

You can also run any function that is assigned to a function key by way of the function key number. To display the list of available function keys, click on the right mouse button. Note the key number that is assigned to the functions you want to run.

Once you have program name, screen number, field name (screen field name), you can start writing.

DATA TRANSFER program.

Declaring internal table

First Integral Table similar to structure like local file.

Declaring internal table like BDCDATA

The data from internal table is not transferred directly to database table, it has to go through transaction. You need to pass data to particular screen and to particular screen-field. Data is passed to transaction in particular format, hence there is a need for batch input structure.

The batch input structure stores the data that is to be entered into SAP system and the actions that are necessary to process the data. The batch input structure is used by all of the batch input methods. You can use the same structure for all types of batch input, regardless of whether you are creating a session in the batch input queue or using CALL TRANSACTION.

This structure is BDCDATA, which can contain the batch input data for only a single run of a transaction. The typical processing loop in a program is as follows:

• Create a BDCDATA structure

• Write the structure out to a session or process it with CALL TRANSACTION USING; and then

• Create a BDCDATA structure for the next transaction that is to be processed.

Within a BDCDATA structure, organize the data of screens in a transaction. Each screen that is processed in the course of a transaction must be identified with a BDCDATA record. This record uses the Program, Dynpro, and Dynbegin fields of the structure.

The screen identifier record is followed by a separate BDCDATA record for each value, to be entered into a field. These records use the FNAM and FVAL fields of the BDCDATA structure. Values to be entered in a field can be any of the following:

• Data that is entered into screen fields.

• Function codes that are entered into the command field. Such function codes execute functions in a transaction, such as Save or Enter.

The BDCDATA structure contains the following fields:

• PROGRAM: Name of module pool program associated with the screen. Set this field only for the first record for the screen.

• DYNPRO: Screen Number. Set this field only in the first record for the screen.

• DYNBEGIN: Indicates the first record for the screen. Set this field to X, only for the first record for the screen. (Reset to ‘ ‘ (blank) for all other records.)

• FNAM: Field Name. The FNAM field is not case-sensitive.

• FVAL: Value for the field named in FNAM. The FVAL field is case-sensitive. Values assigned to this field are always padded on the right, if they are less than 132 characters. Values must be in character format.

Transferring data from local file to internal table

Data is uploaded to internal table by UPLOAD of WS_UPLOAD function.

Population of BDCDATA

For each record of internal table, you need to populate Internal table, which is similar to BDCDATA structure.

All these five initial steps are necessary for any type of BDC interface.

DATA TRANSFER program can call SESSION METHOD or CALL TRANSACTION. The initial steps for both the methods are same.

First step for both the methods is to upload the data to internal table. From Internal Table, the data is transferred to database table by two ways i.e., Session method and Call transaction.

SESSION METHOD

About Session method

In this method you transfer data from internal table to database table through sessions.

In this method, an ABAP/4 program reads the external data that is to be entered in the SAP System and stores the data in session. A session stores the actions that are required to enter your data using normal SAP transaction i.e., Data is transferred to session which in turn transfers data to database table.

Session is intermediate step between internal table and database table. Data along with its action is stored in session i.e., data for screen fields, to which screen it is passed, the program name behind it, and how the next screen is processed.

When the program has finished generating the session, you can run the session to execute the SAP transactions in it. You can either explicitly start and monitor a session or have the session run in the background processing system.

Unless session is processed, the data is not transferred to database table.

BDC_OPEN_GROUP

You create the session through program by BDC_OPEN_GROUP function.

Parameters to this function are:

• User Name: User name

• Group: Name of the session

• Lock Date: The date on which you want to process the session.

• Keep: This parameter is passed as ‘X’ when you want to retain session after

processing it or ‘ ‘ to delete it after processing.

BDC_INSERT

This function creates the session & data is transferred to Session.

Parameters to this function are:

• Tcode: Transaction Name

• Dynprotab: BDC Data

BDC_CLOSE_GROUP

This function closes the BDC Group. No Parameters.

Some additional information for session processing

When the session is generated using the KEEP option within the BDC_OPEN_GROUP, the system always keeps the sessions in the queue, whether it has been processed successfully or not.

However, if the session is processed, you have to delete it manually. When session processing is completed successfully while KEEP option was not set, it will be removed automatically from the session queue. Log is not removed for that session.

If the batch-input session is terminated with errors, then it appears in the list of INCORRECT session and it can be processed again. To correct incorrect session, you can analyze the session. The Analysis function allows to determine which screen and value has produced the error. If you find small errors in data, you can correct them interactively, otherwise you need to modify batch input program, which has generated the session or many times even the data file.

CALL TRANSACTION

About CALL TRANSACTION

A technique similar to SESSION method, while batch input is a two-step procedure, Call Transaction does both steps online, one after the other. In this method, you call a transaction from your program by

Call transaction <tcode> using <BDCTAB>

Mode <A/N/E>

Update <S/A>

Messages into <MSGTAB>.

Parameter – 1 is transaction code.

Parameter – 2 is name of BDCTAB table.

Parameter – 3 here you are specifying mode in which you execute transaction

A is all screen mode. All the screen of transaction are displayed.

N is no screen mode. No screen is displayed when you execute the transaction.

E is error screen. Only those screens are displayed wherein you have error record.

Parameter – 4 here you are specifying update type by which database table is updated.

S is for Synchronous update in which if you change data of one table then all the related Tables gets updated. And sy-subrc is returned i.e., sy-subrc is returned for once and all.

A is for Asynchronous update. When you change data of one table, the sy-subrc is returned. And then updating of other affected tables takes place. So if system fails to update other tables, still sy-subrc returned is 0 (i.e., when first table gets updated).

Parameter – 5 when you update database table, operation is either successful or unsuccessful or operation is successful with some warning. These messages are stored in internal table, which you specify along with MESSAGE statement. This internal table should be declared like BDCMSGCOLL, a structure available in ABAP/4. It contains the following fields:

1. Tcode: Transaction code

2. Dyname: Batch point module name

3. Dynumb: Batch input Dyn number

4. Msgtyp: Batch input message type (A/E/W/I/S)

5. Msgspra: Batch input Lang, id of message

6. Msgid: Message id

7. MsgvN: Message variables (N = 1 - 4)

For each entry, which is updated in database, table message is available in BDCMSGCOLL. As BDCMSGCOLL is structure, you need to declare a internal table which can contain multiple records (unlike structure).

Steps for CALL TRANSACTION method

1. Internal table for the data (structure similar to your local file)

2. BDCTAB like BDCDATA

3. UPLOAD or WS_UPLOAD function to upload the data from local file to itab. (Considering file is local file)

4. Loop at itab.

Populate BDCTAB table.

Call transaction <tcode> using <BDCTAB>

Mode <A/N/E>

Update <S/A>.

Refresh BDCTAB.

Endloop.

(To populate BDCTAB, You need to transfer each and every field)

The major differences between Session method and Call transaction are as follows:

SESSION METHOD CALL TRANSACTION

1. Data is not updated in database table unless Session is processed. Immediate updation in database table.

2. No sy-subrc is returned. Sy-subrc is returned.

3. Error log is created for error records. Errors need to be handled explicitly

4. Updation in database table is always synchronous Updation in database table can be synchronous Or Asynchronous.

Error Handling in CALL TRANSACTION

When Session Method updates the records in database table, error records are stored in the log file. In Call transaction there is no such log file available and error record is lost unless handled. Usually you need to give report of all the error records i.e., records which are not inserted or updated in the database table. This can be done by the following method:

Steps for the error handling in CALL TRANSACTION

1. Internal table for the data (structure similar to your local file)

2. BDCTAB like BDCDATA

3. Internal table BDCMSG like BDCMSGCOLL

4. Internal table similar to Ist internal table

(Third and fourth steps are for error handling)

5. UPLOAD or WS_UPLOAD function to upload the data from the local file to itab. (Considering file is local file)

6. Loop at itab.

Populate BDCTAB table.

Call transaction <tr.code> using <Bdctab>

Mode <A/N/E>

Update <S/A>

Messages <BDCMSG>.

Perform check.

Refresh BDCTAB.

Endloop.

7 Form check.

IF sy-subrc <> 0. (Call transaction returns the sy-subrc if updating is not successful).

Call function Format_message.

(This function is called to store the message given by system and to display it along with record)

Append itab2.

Display the record and message.

Hope this resolves your query.

Reward all the helpful answers.

Regards