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: 

BDC COING AND STEPS

Former Member
0 Kudos

send the coding and steps for bdc using the commands

1.bdc_open_group

2.bdc_insert

3.bdc_close_group

using these commands to upload the data

1 ACCEPTED SOLUTION

Former Member
0 Kudos

HI.

refer this one.

REPORT zmmat_mast

NO STANDARD PAGE HEADING LINE-SIZE 200.

----


*Programmer : Niraj Visnoi *

*Website : http://sap.niraj.tripod.com *

*Email : niraj_visnoi@rediffmail.com *

----


TABLES :mara, marc.

----


  • INTERNAL TABLES *

----


DATA: BEGIN OF bdcdata OCCURS 0.

INCLUDE STRUCTURE bdcdata.

DATA: END OF bdcdata.

DATA:BEGIN OF itab_basic OCCURS 0,

matnr LIKE mara-matnr,

zzmatnr LIKE mara-matnr,

END OF itab_basic.

DATA:BEGIN OF itab_mrp OCCURS 0,

matnr LIKE mara-matnr,

werks LIKE marc-werks,

zzgpind LIKE marc-zzgpind,

zzdate(10) type C ,

END OF itab_mrp.

DATA: BEGIN OF tab_mara OCCURS 0.

INCLUDE STRUCTURE mara.

DATA: END OF tab_mara.

DATA: BEGIN OF tab_marc OCCURS 0.

INCLUDE STRUCTURE marc.

DATA: END OF tab_marc.

DATA: ertab_basic LIKE itab_basic OCCURS 0 WITH HEADER LINE.

DATA: ertab_mrp LIKE itab_mrp OCCURS 0 WITH HEADER LINE.

DATA : v_ctr TYPE i VALUE 1. "Ctr for no orecords

DATA : v_group(12) . "BDC Group Name

DATA : v_group_ctr(3) TYPE n . "BDC Group Counter

DATA : v_no_lines TYPE i.

DATA: v_grpname(10) TYPE c.

SELECTION-SCREEN BEGIN OF BLOCK dt-entry

WITH FRAME TITLE text-002.

selection-screen begin of line .

selection-screen comment 01(49) text-101.

parameters : p_basic radiobutton group r1.

selection-screen end of line.

selection-screen begin of line .

selection-screen comment 01(49) text-102.

parameters : p_mrp2 radiobutton group r1.

selection-screen end of line.

*

*PARAMETERS :

  • p_basic RADIOBUTTON GROUP r1,

  • p_mrp2 RADIOBUTTON GROUP r1.

SELECTION-SCREEN END OF BLOCK dt-entry.

SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN BEGIN OF BLOCK fl-info

WITH FRAME TITLE text-003.

PARAMETER : p_dlhead AS CHECKBOX . "DEFAULT 'X'.

SELECTION-SCREEN END OF BLOCK fl-info.

*

SELECTION-SCREEN SKIP 1.

PARAMETER : p_max TYPE i DEFAULT '5000' . "No of rec / session

SET PF-STATUS 'UPLOAD'.

AT USER-COMMAND .

IF sy-ucomm = 'UPLOAD' .

IF p_basic = 'X'.

IF NOT itab_basic[] IS INITIAL .

PERFORM bdc_upload_basic.

ENDIF.

WRITE:/10 'Please execute the session in SM35 to Upload the data'.

FORMAT INTENSIFIED OFF COLOR OFF .

REFRESH itab_basic . CLEAR itab_basic .

SET PF-STATUS space.

ENDIF.

IF p_mrp2 = 'X'.

IF NOT itab_mrp[] IS INITIAL .

PERFORM bdc_upload_mrp.

ENDIF..

WRITE:/10 'Please execute the session in SM35 to Upload the data'.

REFRESH itab_mrp . CLEAR itab_mrp .

SET PF-STATUS space.

ENDIF.

ENDIF.

START-OF-SELECTION.

IF p_basic = 'X'.

CALL FUNCTION 'UPLOAD'

EXPORTING

  • CODEPAGE = ' '

filename = 'C:\mm02_basic.txt '

filetype = 'DAT'

TABLES

data_tab = itab_basic.

IF p_dlhead EQ 'X'.

READ TABLE itab_basic INDEX 1.

DELETE itab_basic INDEX 1.

CLEAR itab_basic.

ENDIF.

PERFORM blank_data_validation.

ENDIF.

IF p_mrp2 = 'X'.

  • v_grpname = 'MRP2'.

CALL FUNCTION 'UPLOAD'

EXPORTING

  • CODEPAGE = ' '

filename = 'C:\mm02_mrp.txt '

filetype = 'DAT'

TABLES

data_tab = itab_mrp.

IF p_dlhead EQ 'X'.

READ TABLE itab_mrp INDEX 1.

DELETE itab_mrp INDEX 1.

CLEAR itab_mrp.

ENDIF.

PERFORM valid_plant_check.

ENDIF.

IF sy-subrc <> 0.

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

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

ENDIF.

PERFORM display_data.

END-OF-SELECTION.

*----


*

  • Start new screen

*

*----


*

FORM bdc_dynpro USING program dynpro.

CLEAR bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = 'X'.

APPEND bdcdata.

ENDFORM.

*----


*

  • Insert field

*

*----


*

FORM bdc_field USING fnam fval.

CLEAR bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

APPEND bdcdata.

ENDFORM.

&----


*& Form blank_data_validation

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM blank_data_validation.

LOOP AT itab_basic.

IF itab_basic-matnr IS INITIAL OR itab_basic-zzmatnr IS INITIAL.

MOVE-CORRESPONDING itab_basic TO ertab_basic .

APPEND ertab_basic . CLEAR ertab_basic .

DELETE itab_basic.

CLEAR itab_basic.

CONTINUE.

ENDIF.

SELECT SINGLE * INTO tab_mara FROM mara WHERE matnr = itab_basic-matnr

.

IF sy-subrc <> 0.

MOVE-CORRESPONDING itab_basic TO ertab_basic .

APPEND ertab_basic . CLEAR ertab_basic .

DELETE itab_basic.

CLEAR itab_basic.

CONTINUE.

ENDIF.

*

ENDLOOP.

ENDFORM. " dt_qty_validation

&----


*& Form CALL_BDC_CLOSE_GROUP

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM call_bdc_close_group.

CALL FUNCTION 'BDC_CLOSE_GROUP'

EXCEPTIONS

not_open = 1

queue_error = 2.

IF sy-subrc NE 0.

WRITE: /5 'BDC CLOSE GROUP FAILED, return code = ', sy-subrc.

EXIT.

ENDIF.

ENDFORM. " CALL_BDC_CLOSE_GROUP

&----


*& Form CALL_BDC_INSERT

&----


  • text

----


  • -->P_0545 text

----


FORM call_bdc_insert USING v_tran_code.

DATA: xmode VALUE 'E'.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

tcode = v_tran_code

TABLES

dynprotab = bdcdata

EXCEPTIONS

internal_error = 1

not_open = 2

queue_error = 3.

IF sy-subrc NE 0.

WRITE: /5 'BDC insert GROUP FAILED, return code = ', sy-subrc.

EXIT.

ENDIF.

ENDFORM. " CALL_BDC_INSERT

&----


*& Form display_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display_data.

WRITE:/ 'Press','''Upload''',

'to create session with the following records'.

IF p_basic = 'X'.

PERFORM display_header.

FORMAT COLOR 2.

LOOP AT itab_basic.

WRITE :/2 itab_basic-matnr,'|',

23 itab_basic-zzmatnr,

54 '|'.

ENDIF.

ENDLOOP.

NEW-LINE.

ULINE (54).

ENDIF.

IF p_mrp2 = 'X'.

PERFORM display_header_mrp.

FORMAT COLOR 2.

LOOP AT itab_mrp.

WRITE :/2 itab_mrp-matnr,'|',

23 itab_mrp-werks,

33 '|',

37 itab_mrp-zzgpind,

49 '|',

52 itab_mrp-ZZDATE,

65 '|'.

ENDLOOP.

NEW-LINE.

ULINE (65).

FORMAT COLOR OFF.

SKIP 4.

WRITE 😕 'Records with Errors will not be Included in Session' .

PERFORM display_header_mrp.

FORMAT COLOR 2.

LOOP AT ertab_mrp.

IF NOT ertab_mrp IS INITIAL OR NOT ertab_mrp-matnr IS INITIAL.

WRITE :/2 ertab_mrp-matnr ,'|',

23 ertab_mrp-werks,

33 '|',

37 ertab_mrp-zzgpind,

49 '|' ,

52 ertab_mrp-zzdate,

65 '|'.

ENDIF.

ENDLOOP.

NEW-LINE.

ULINE (65).

ENDIF.

FORMAT COLOR OFF.

ENDFORM. " display_data

&----


*& Form BDC_UPLOAD_basic

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM bdc_upload_basic.

*CLEAR itab_basic. REFRESH itab_basic.

CLEAR : v_ctr , v_no_lines .

IF NOT itab_basic[] IS INITIAL .

v_group_ctr = '1' .

CONCATENATE 'BASIC_' v_group_ctr INTO v_group .

PERFORM open_group USING v_group .

LOOP AT itab_basic .

IF v_ctr GE p_max .

PERFORM call_bdc_close_group .

v_group_ctr = v_group_ctr + 1 .

CLEAR v_group .

CONCATENATE 'BASIC_' v_group_ctr INTO v_group .

PERFORM open_group USING v_group .

v_ctr = 0 .

ENDIF.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RMMG1-MATNR'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'RMMG1-MATNR'

itab_basic-matnr.

  • 'DEEPAKTESTMAT'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'.

PERFORM bdc_field USING 'BDC_CURSOR'

'MSICHTAUSW-DYTXT(01)'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTR'.

PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(01)'

'X'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BU'.

PERFORM bdc_field USING 'BDC_CURSOR'

'MARA-ZZMATNR'.

PERFORM bdc_field USING 'MARA-ZZMATNR'

itab_basic-zzmatnr.

  • 'ADV#AM29F010-70JI'.

PERFORM call_bdc_insert USING 'MM02'.

CLEAR bdcdata . REFRESH bdcdata .

v_no_lines = v_no_lines + 1 .

v_ctr = v_ctr + 1.

ENDLOOP.

PERFORM call_bdc_close_group.

SKIP 10.

WRITE :/10 'Session by name BASIC* created' .

WRITE :/10 'Total No of records uploaded - ' , v_no_lines .

ENDIF.

ENDFORM. " BDC_UPLOAD

&----


*& Form display_header

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display_header.

NEW-LINE.

  • set left scroll-boundary column 48.

FORMAT COLOR 1 INTENSIFIED ON.

ULINE (54).

WRITE :/' Avnet Material',

21'|' ,

23 'Green Product '

, 54 '|'.

NEW-LINE.

ULINE (54).

FORMAT COLOR OFF INTENSIFIED OFF.

ENDFORM.

&----


*& Form bdc_upload_mrp

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM bdc_upload_mrp.

  • PERFORM call_bdc_open_group2.

CLEAR : v_ctr , v_no_lines .

IF NOT itab_mrp[] IS INITIAL .

v_group_ctr = '1' .

CONCATENATE 'MRP_' v_group_ctr INTO v_group .

PERFORM open_group USING v_group .

LOOP AT itab_mrp .

IF v_ctr GE p_max .

PERFORM call_bdc_close_group .

v_group_ctr = v_group_ctr + 1 .

CLEAR v_group .

CONCATENATE 'MRP2_' v_group_ctr INTO v_group .

PERFORM open_group USING v_group .

v_ctr = 0 .

ENDIF.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RMMG1-MATNR'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'RMMG1-MATNR'

itab_mrp-matnr.

  • 'DEEPAKTESTMAT'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'.

PERFORM bdc_field USING 'BDC_CURSOR'

'MSICHTAUSW-DYTXT(13)'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTR'.

PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(13)'

'X'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0080'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RMMG1-WERKS'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTR'.

PERFORM bdc_field USING 'RMMG1-WERKS'

itab_mrp-werks.

  • 'sg11'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '4000'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'BDC_CURSOR'

'MARC-ZZGPIND'.

PERFORM bdc_field USING 'MARC-ZZGPIND'

itab_mrp-zzgpind.

  • 'G'.

PERFORM bdc_field USING 'BDC_CURSOR'

'MARC-ZZDATE'.

PERFORM bdc_field USING 'MARC-ZZDATE'

itab_mrp-zzdate.

  • 'G'.

PERFORM bdc_dynpro USING 'SAPLSPO1' '0300'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=YES'.

PERFORM call_bdc_insert USING 'MM02'.

CLEAR bdcdata . REFRESH bdcdata .

v_no_lines = v_no_lines + 1 .

v_ctr = v_ctr + 1.

ENDLOOP.

PERFORM call_bdc_close_group.

SKIP 10.

WRITE :/10 'Session by name MRP2* created' .

WRITE :/10 'Total No of records uploaded - ' , v_no_lines .

ENDIF.

ENDFORM. " bdc_upload_mrp

&----


*& Form display_header_mrp

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display_header_mrp.

NEW-LINE.

  • set left scroll-boundary column 48.

FORMAT COLOR 1 INTENSIFIED ON.

ULINE (65).

WRITE :/' Avnet Material',

21'|' ,

23 'Plant ' ,

33 '|',

35 'Indicator',

49 '|',

52 'Date',

65 '|' .

NEW-LINE.

ULINE (65).

FORMAT COLOR OFF INTENSIFIED OFF.

ENDFORM. " display_header_mrp

&----


*& Form valid_plant_check

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM valid_plant_check.

LOOP AT itab_mrp.

IF itab_mrp-matnr IS INITIAL OR itab_mrp-werks IS INITIAL OR

itab_mrp-zzgpind IS INITIAL.

MOVE-CORRESPONDING itab_mrp TO ertab_mrp .

APPEND ertab_mrp . CLEAR ertab_mrp .

DELETE itab_mrp.

CLEAR itab_mrp.

CONTINUE.

ENDIF.

SELECT SINGLE * INTO tab_marc FROM marc WHERE matnr = tab_marc-matnr

AND werks = itab_mrp-werks . .

IF sy-subrc = 0.

MOVE-CORRESPONDING itab_mrp TO ertab_mrp .

APPEND ertab_mrp . CLEAR ertab_mrp .

DELETE itab_mrp.

CLEAR itab_mrp.

CONTINUE.

ENDIF.

ENDLOOP.

ENDFORM. " valid_plant_check

----


  • FORM open_group *

----


  • ........ *

----


FORM open_group USING p_grp .

  • open batchinput group

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

client = sy-mandt

group = p_grp

user = sy-uname

keep = 'X'.

ENDFORM.

Check this

http://www.sap-img.com/ab001.htm

Regards,

Priyanka.

6 REPLIES 6

Former Member
0 Kudos

Steps:

1. Work out the transaction you would use to create the data manually.

2. Use transaction SHDB to record the creation of one material master data.

Click the New recording button or the Menu - Recording - Create

3. Save the recording, and then go back a screen and go to the overview.

4. Select the recording and click on Edit - Create Program. Give the program a Z name, and select transfer from recording.

5. Edit the program. You will see that all the data you entered is hard-coded into the program. You need to make the following changes:

5.1 After the start-of-selection, Call ws_upload to upload the file (the excel file needs to be saved as TAB separated).

5.2 After the open-group, Loop on the uploaded data. For each line, perform validation checks on the data, then modify the perform bdc_field commands to use the file data.

5.3. After perform bdc_transaction, add the endloop.

Execute the program. It will have options to create a batch session or to process directly.

These are all my finds . Might be it will be useful to you.

Direct call of transactions, session handling:

/nxxxx This terminates the current transaction, and starts transaction xxxx

/n This terminates the transaction. This generally corresponds to pressing F15 to go back.

/nend This termiantes all separate sessions and logs off (corresponds to System - Logoff).

/nex This terminates all separate sessions and logs off immediately (without any warning!).

/oxxxx This opens a new session and starts transaction xxxx in This session.

/o This lists existing sessions and allows deletion or opening of a new session.

/i This terminates the current session (corresponds to System End

/i1, /i2,... This terminates the session with the number given.

.xyzw Fast path: 'xyzw' refers to the underlined letters in the menus. This type of navigation is uncommon and is provided more for emergencies (such as a defective mouse).

Batch

The following commands can be entered in correction mode ('Process in foreground' or 'Display errors only') when processing a batch input session:

/n This terminates the current batch input transaction and characterizes it as

/bdel This deletes the current batch input transaction.

/bend This terminates batch input processing and sets the session to Failed

/bda This switches from Display errors only to Process in foreground

/bde This switches from Process in foreground to Display errors only

ABAP/4

/h This switches into debugging mode.

/hs This switches into debugging mode and activates the debugging of system functions.

Buffer

WARNING: Resetting buffers can significantly change the performance of the entire system for a long time.

It should therefore only be used where there is a good reason tdso. As of release 3.0B system administator authorization is required (authorization object (S_ADMI_FCD). The action is noted in the system log.

/$SYNC This resets all buffers of the application server

/$CUA This resets the CUA buffer of the application server

/$TAB This resets the TABLE buffers of the application server

/$NAM This resets the nametab buffer of the application server

/$DYNP This resets the screen buffer of the application server

Former Member
0 Kudos

HI.

refer this one.

REPORT zmmat_mast

NO STANDARD PAGE HEADING LINE-SIZE 200.

----


*Programmer : Niraj Visnoi *

*Website : http://sap.niraj.tripod.com *

*Email : niraj_visnoi@rediffmail.com *

----


TABLES :mara, marc.

----


  • INTERNAL TABLES *

----


DATA: BEGIN OF bdcdata OCCURS 0.

INCLUDE STRUCTURE bdcdata.

DATA: END OF bdcdata.

DATA:BEGIN OF itab_basic OCCURS 0,

matnr LIKE mara-matnr,

zzmatnr LIKE mara-matnr,

END OF itab_basic.

DATA:BEGIN OF itab_mrp OCCURS 0,

matnr LIKE mara-matnr,

werks LIKE marc-werks,

zzgpind LIKE marc-zzgpind,

zzdate(10) type C ,

END OF itab_mrp.

DATA: BEGIN OF tab_mara OCCURS 0.

INCLUDE STRUCTURE mara.

DATA: END OF tab_mara.

DATA: BEGIN OF tab_marc OCCURS 0.

INCLUDE STRUCTURE marc.

DATA: END OF tab_marc.

DATA: ertab_basic LIKE itab_basic OCCURS 0 WITH HEADER LINE.

DATA: ertab_mrp LIKE itab_mrp OCCURS 0 WITH HEADER LINE.

DATA : v_ctr TYPE i VALUE 1. "Ctr for no orecords

DATA : v_group(12) . "BDC Group Name

DATA : v_group_ctr(3) TYPE n . "BDC Group Counter

DATA : v_no_lines TYPE i.

DATA: v_grpname(10) TYPE c.

SELECTION-SCREEN BEGIN OF BLOCK dt-entry

WITH FRAME TITLE text-002.

selection-screen begin of line .

selection-screen comment 01(49) text-101.

parameters : p_basic radiobutton group r1.

selection-screen end of line.

selection-screen begin of line .

selection-screen comment 01(49) text-102.

parameters : p_mrp2 radiobutton group r1.

selection-screen end of line.

*

*PARAMETERS :

  • p_basic RADIOBUTTON GROUP r1,

  • p_mrp2 RADIOBUTTON GROUP r1.

SELECTION-SCREEN END OF BLOCK dt-entry.

SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN BEGIN OF BLOCK fl-info

WITH FRAME TITLE text-003.

PARAMETER : p_dlhead AS CHECKBOX . "DEFAULT 'X'.

SELECTION-SCREEN END OF BLOCK fl-info.

*

SELECTION-SCREEN SKIP 1.

PARAMETER : p_max TYPE i DEFAULT '5000' . "No of rec / session

SET PF-STATUS 'UPLOAD'.

AT USER-COMMAND .

IF sy-ucomm = 'UPLOAD' .

IF p_basic = 'X'.

IF NOT itab_basic[] IS INITIAL .

PERFORM bdc_upload_basic.

ENDIF.

WRITE:/10 'Please execute the session in SM35 to Upload the data'.

FORMAT INTENSIFIED OFF COLOR OFF .

REFRESH itab_basic . CLEAR itab_basic .

SET PF-STATUS space.

ENDIF.

IF p_mrp2 = 'X'.

IF NOT itab_mrp[] IS INITIAL .

PERFORM bdc_upload_mrp.

ENDIF..

WRITE:/10 'Please execute the session in SM35 to Upload the data'.

REFRESH itab_mrp . CLEAR itab_mrp .

SET PF-STATUS space.

ENDIF.

ENDIF.

START-OF-SELECTION.

IF p_basic = 'X'.

CALL FUNCTION 'UPLOAD'

EXPORTING

  • CODEPAGE = ' '

filename = 'C:\mm02_basic.txt '

filetype = 'DAT'

TABLES

data_tab = itab_basic.

IF p_dlhead EQ 'X'.

READ TABLE itab_basic INDEX 1.

DELETE itab_basic INDEX 1.

CLEAR itab_basic.

ENDIF.

PERFORM blank_data_validation.

ENDIF.

IF p_mrp2 = 'X'.

  • v_grpname = 'MRP2'.

CALL FUNCTION 'UPLOAD'

EXPORTING

  • CODEPAGE = ' '

filename = 'C:\mm02_mrp.txt '

filetype = 'DAT'

TABLES

data_tab = itab_mrp.

IF p_dlhead EQ 'X'.

READ TABLE itab_mrp INDEX 1.

DELETE itab_mrp INDEX 1.

CLEAR itab_mrp.

ENDIF.

PERFORM valid_plant_check.

ENDIF.

IF sy-subrc <> 0.

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

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

ENDIF.

PERFORM display_data.

END-OF-SELECTION.

*----


*

  • Start new screen

*

*----


*

FORM bdc_dynpro USING program dynpro.

CLEAR bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = 'X'.

APPEND bdcdata.

ENDFORM.

*----


*

  • Insert field

*

*----


*

FORM bdc_field USING fnam fval.

CLEAR bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

APPEND bdcdata.

ENDFORM.

&----


*& Form blank_data_validation

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM blank_data_validation.

LOOP AT itab_basic.

IF itab_basic-matnr IS INITIAL OR itab_basic-zzmatnr IS INITIAL.

MOVE-CORRESPONDING itab_basic TO ertab_basic .

APPEND ertab_basic . CLEAR ertab_basic .

DELETE itab_basic.

CLEAR itab_basic.

CONTINUE.

ENDIF.

SELECT SINGLE * INTO tab_mara FROM mara WHERE matnr = itab_basic-matnr

.

IF sy-subrc <> 0.

MOVE-CORRESPONDING itab_basic TO ertab_basic .

APPEND ertab_basic . CLEAR ertab_basic .

DELETE itab_basic.

CLEAR itab_basic.

CONTINUE.

ENDIF.

*

ENDLOOP.

ENDFORM. " dt_qty_validation

&----


*& Form CALL_BDC_CLOSE_GROUP

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM call_bdc_close_group.

CALL FUNCTION 'BDC_CLOSE_GROUP'

EXCEPTIONS

not_open = 1

queue_error = 2.

IF sy-subrc NE 0.

WRITE: /5 'BDC CLOSE GROUP FAILED, return code = ', sy-subrc.

EXIT.

ENDIF.

ENDFORM. " CALL_BDC_CLOSE_GROUP

&----


*& Form CALL_BDC_INSERT

&----


  • text

----


  • -->P_0545 text

----


FORM call_bdc_insert USING v_tran_code.

DATA: xmode VALUE 'E'.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

tcode = v_tran_code

TABLES

dynprotab = bdcdata

EXCEPTIONS

internal_error = 1

not_open = 2

queue_error = 3.

IF sy-subrc NE 0.

WRITE: /5 'BDC insert GROUP FAILED, return code = ', sy-subrc.

EXIT.

ENDIF.

ENDFORM. " CALL_BDC_INSERT

&----


*& Form display_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display_data.

WRITE:/ 'Press','''Upload''',

'to create session with the following records'.

IF p_basic = 'X'.

PERFORM display_header.

FORMAT COLOR 2.

LOOP AT itab_basic.

WRITE :/2 itab_basic-matnr,'|',

23 itab_basic-zzmatnr,

54 '|'.

ENDIF.

ENDLOOP.

NEW-LINE.

ULINE (54).

ENDIF.

IF p_mrp2 = 'X'.

PERFORM display_header_mrp.

FORMAT COLOR 2.

LOOP AT itab_mrp.

WRITE :/2 itab_mrp-matnr,'|',

23 itab_mrp-werks,

33 '|',

37 itab_mrp-zzgpind,

49 '|',

52 itab_mrp-ZZDATE,

65 '|'.

ENDLOOP.

NEW-LINE.

ULINE (65).

FORMAT COLOR OFF.

SKIP 4.

WRITE 😕 'Records with Errors will not be Included in Session' .

PERFORM display_header_mrp.

FORMAT COLOR 2.

LOOP AT ertab_mrp.

IF NOT ertab_mrp IS INITIAL OR NOT ertab_mrp-matnr IS INITIAL.

WRITE :/2 ertab_mrp-matnr ,'|',

23 ertab_mrp-werks,

33 '|',

37 ertab_mrp-zzgpind,

49 '|' ,

52 ertab_mrp-zzdate,

65 '|'.

ENDIF.

ENDLOOP.

NEW-LINE.

ULINE (65).

ENDIF.

FORMAT COLOR OFF.

ENDFORM. " display_data

&----


*& Form BDC_UPLOAD_basic

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM bdc_upload_basic.

*CLEAR itab_basic. REFRESH itab_basic.

CLEAR : v_ctr , v_no_lines .

IF NOT itab_basic[] IS INITIAL .

v_group_ctr = '1' .

CONCATENATE 'BASIC_' v_group_ctr INTO v_group .

PERFORM open_group USING v_group .

LOOP AT itab_basic .

IF v_ctr GE p_max .

PERFORM call_bdc_close_group .

v_group_ctr = v_group_ctr + 1 .

CLEAR v_group .

CONCATENATE 'BASIC_' v_group_ctr INTO v_group .

PERFORM open_group USING v_group .

v_ctr = 0 .

ENDIF.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RMMG1-MATNR'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'RMMG1-MATNR'

itab_basic-matnr.

  • 'DEEPAKTESTMAT'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'.

PERFORM bdc_field USING 'BDC_CURSOR'

'MSICHTAUSW-DYTXT(01)'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTR'.

PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(01)'

'X'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BU'.

PERFORM bdc_field USING 'BDC_CURSOR'

'MARA-ZZMATNR'.

PERFORM bdc_field USING 'MARA-ZZMATNR'

itab_basic-zzmatnr.

  • 'ADV#AM29F010-70JI'.

PERFORM call_bdc_insert USING 'MM02'.

CLEAR bdcdata . REFRESH bdcdata .

v_no_lines = v_no_lines + 1 .

v_ctr = v_ctr + 1.

ENDLOOP.

PERFORM call_bdc_close_group.

SKIP 10.

WRITE :/10 'Session by name BASIC* created' .

WRITE :/10 'Total No of records uploaded - ' , v_no_lines .

ENDIF.

ENDFORM. " BDC_UPLOAD

&----


*& Form display_header

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display_header.

NEW-LINE.

  • set left scroll-boundary column 48.

FORMAT COLOR 1 INTENSIFIED ON.

ULINE (54).

WRITE :/' Avnet Material',

21'|' ,

23 'Green Product '

, 54 '|'.

NEW-LINE.

ULINE (54).

FORMAT COLOR OFF INTENSIFIED OFF.

ENDFORM.

&----


*& Form bdc_upload_mrp

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM bdc_upload_mrp.

  • PERFORM call_bdc_open_group2.

CLEAR : v_ctr , v_no_lines .

IF NOT itab_mrp[] IS INITIAL .

v_group_ctr = '1' .

CONCATENATE 'MRP_' v_group_ctr INTO v_group .

PERFORM open_group USING v_group .

LOOP AT itab_mrp .

IF v_ctr GE p_max .

PERFORM call_bdc_close_group .

v_group_ctr = v_group_ctr + 1 .

CLEAR v_group .

CONCATENATE 'MRP2_' v_group_ctr INTO v_group .

PERFORM open_group USING v_group .

v_ctr = 0 .

ENDIF.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RMMG1-MATNR'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'RMMG1-MATNR'

itab_mrp-matnr.

  • 'DEEPAKTESTMAT'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'.

PERFORM bdc_field USING 'BDC_CURSOR'

'MSICHTAUSW-DYTXT(13)'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTR'.

PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(13)'

'X'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0080'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RMMG1-WERKS'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTR'.

PERFORM bdc_field USING 'RMMG1-WERKS'

itab_mrp-werks.

  • 'sg11'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '4000'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'BDC_CURSOR'

'MARC-ZZGPIND'.

PERFORM bdc_field USING 'MARC-ZZGPIND'

itab_mrp-zzgpind.

  • 'G'.

PERFORM bdc_field USING 'BDC_CURSOR'

'MARC-ZZDATE'.

PERFORM bdc_field USING 'MARC-ZZDATE'

itab_mrp-zzdate.

  • 'G'.

PERFORM bdc_dynpro USING 'SAPLSPO1' '0300'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=YES'.

PERFORM call_bdc_insert USING 'MM02'.

CLEAR bdcdata . REFRESH bdcdata .

v_no_lines = v_no_lines + 1 .

v_ctr = v_ctr + 1.

ENDLOOP.

PERFORM call_bdc_close_group.

SKIP 10.

WRITE :/10 'Session by name MRP2* created' .

WRITE :/10 'Total No of records uploaded - ' , v_no_lines .

ENDIF.

ENDFORM. " bdc_upload_mrp

&----


*& Form display_header_mrp

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display_header_mrp.

NEW-LINE.

  • set left scroll-boundary column 48.

FORMAT COLOR 1 INTENSIFIED ON.

ULINE (65).

WRITE :/' Avnet Material',

21'|' ,

23 'Plant ' ,

33 '|',

35 'Indicator',

49 '|',

52 'Date',

65 '|' .

NEW-LINE.

ULINE (65).

FORMAT COLOR OFF INTENSIFIED OFF.

ENDFORM. " display_header_mrp

&----


*& Form valid_plant_check

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM valid_plant_check.

LOOP AT itab_mrp.

IF itab_mrp-matnr IS INITIAL OR itab_mrp-werks IS INITIAL OR

itab_mrp-zzgpind IS INITIAL.

MOVE-CORRESPONDING itab_mrp TO ertab_mrp .

APPEND ertab_mrp . CLEAR ertab_mrp .

DELETE itab_mrp.

CLEAR itab_mrp.

CONTINUE.

ENDIF.

SELECT SINGLE * INTO tab_marc FROM marc WHERE matnr = tab_marc-matnr

AND werks = itab_mrp-werks . .

IF sy-subrc = 0.

MOVE-CORRESPONDING itab_mrp TO ertab_mrp .

APPEND ertab_mrp . CLEAR ertab_mrp .

DELETE itab_mrp.

CLEAR itab_mrp.

CONTINUE.

ENDIF.

ENDLOOP.

ENDFORM. " valid_plant_check

----


  • FORM open_group *

----


  • ........ *

----


FORM open_group USING p_grp .

  • open batchinput group

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

client = sy-mandt

group = p_grp

user = sy-uname

keep = 'X'.

ENDFORM.

Check this

http://www.sap-img.com/ab001.htm

Regards,

Priyanka.

Former Member
0 Kudos

<b>Award Points if useful</b>

Former Member
0 Kudos

Hi senthil,

Refer the below code

&----


*

*& Report Z34331_BDC *

*& *

&----


*& Creating a test program for uplaoding a CSV or XLS file and pass *

*& the internal table value to a BDC program *

&----


REPORT Z34331_BDC.

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

*for excel file

PARAMETERS: P_IFILE TYPE RLGRAP-FILENAME.

*for csv and txt file

*PARAMETERS: p_ifile TYPE dxfile-filename.

SELECTION-SCREEN END OF BLOCK B1.

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

PARAMETERS: P_SESS RADIOBUTTON GROUP G3 "create session

DEFAULT 'X' USER-COMMAND BDC,

P_CTU RADIOBUTTON GROUP G3. "call transaction

SELECTION-SCREEN END OF BLOCK B3.

*for csv and txt file

*DATA : BEGIN OF itab OCCURS 0,

  • str TYPE string,

  • END OF itab,

*for xls file

DATA : ITAB LIKE TABLE OF ALSMEX_TABLINE WITH HEADER LINE.

DATA : L_FILE TYPE STRING,

T_BDCDATA TYPE STANDARD TABLE OF BDCDATA,

WA_BDCDATA LIKE LINE OF T_BDCDATA.

*----


  • AT SELECTION SCREEN ON VALUE REQUEST

*----


  • Value request for the filename.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_IFILE.

PERFORM HELP_INPUT_FILE.

START-OF-SELECTION.

CLEAR L_FILE.

*for csv and txt file

  • l_file = p_ifile.

*for xls file

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = P_IFILE

I_BEGIN_COL = 1

I_BEGIN_ROW = 1

I_END_COL = 2

I_END_ROW = 2

TABLES

INTERN = ITAB

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 2

OTHERS = 3.

*for csv and txt file

  • CALL FUNCTION 'GUI_UPLOAD'

  • EXPORTING

  • filename = l_file

  • filetype = 'ASC'

  • TABLES

  • data_tab = itab

  • EXCEPTIONS

  • file_open_error = 1

  • file_read_error = 2

  • no_batch = 3

  • gui_refuse_filetransfer = 4

  • invalid_type = 5

  • no_authority = 6

  • unknown_error = 7

  • bad_data_format = 8

  • header_not_allowed = 9

  • separator_not_allowed = 10

  • header_too_long = 11

  • unknown_dp_error = 12

  • access_denied = 13

  • dp_out_of_memory = 14

  • disk_full = 15

  • dp_timeout = 16

  • OTHERS = 17.

*Start new session

IF P_SESS = 'X'.

PERFORM BDC_OPEN.

ENDIF.

LOOP AT ITAB.

PERFORM CREAT_BATCH_INPUT.

PERFORM BDC_INSERT.

IF P_CTU = 'X'.

CALL TRANSACTION 'SE38' USING T_BDCDATA MODE 'A'.

ENDIF.

ENDLOOP.

IF P_SESS = 'X'.

PERFORM BDC_CLOSE .

IF SY-SUBRC EQ 0.

MESSAGE I001(ZM) WITH 'Session created check in transaction SM35'.

ENDIF.

ENDIF.

&----


*& Form bdc_open

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM BDC_OPEN .

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

CLIENT = SY-MANDT

GROUP = 'ZMUK'

USER = SY-UNAME

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.

ENDFORM. " bdc_open

&----


*& Form creat_batch_input

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM CREAT_BATCH_INPUT .

PERFORM BDC_DYNPRO USING 'SAPLWBABAP' '0100'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=STRT'.

*for csv and txt file

  • PERFORM bdc_field USING 'RS38M-PROGRAMM'

  • itab-str.

*for xls file

PERFORM BDC_FIELD USING 'RS38M-PROGRAMM'

ITAB-VALUE.

PERFORM BDC_FIELD USING 'RS38M-FUNC_EDIT'

'X'.

PERFORM BDC_DYNPRO USING 'SAPLSLVC_FULLSCREEN' '0500'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=&F03'.

PERFORM BDC_DYNPRO USING 'SAPLWBABAP' '0100'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=BACK'.

*for csv and txt file

  • PERFORM bdc_field USING 'RS38M-PROGRAMM'

  • itab-str.

*for xls file

PERFORM BDC_FIELD USING 'RS38M-PROGRAMM'

ITAB-VALUE.

PERFORM BDC_FIELD USING 'RS38M-FUNC_EDIT'

'X'.

ENDFORM. " creat_batch_input

&----


*& Form bdc_insert

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM BDC_INSERT .

CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = 'SE38'

TABLES

DYNPROTAB = T_BDCDATA

EXCEPTIONS

INTERNAL_ERROR = 1

NOT_OPEN = 2

QUEUE_ERROR = 3

TCODE_INVALID = 4

PRINTING_INVALID = 5

POSTING_INVALID = 6

OTHERS = 7.

ENDFORM. " bdc_insert

&----


*& Form bdc_dynpro

&----


  • text

----


  • -->P_0168 text

  • -->P_0169 text

----


FORM BDC_DYNPRO USING P_PROGRAM TYPE ANY

P_DYNPRO TYPE ANY.

CLEAR WA_BDCDATA.

WA_BDCDATA-PROGRAM = P_PROGRAM.

WA_BDCDATA-DYNPRO = P_DYNPRO.

WA_BDCDATA-DYNBEGIN = 'X'.

APPEND WA_BDCDATA TO T_BDCDATA.

ENDFORM. " bdc_dynpro

&----


*& Form bdc_field

&----


  • text

----


  • -->P_0179 text

  • -->P_0180 text

----


FORM BDC_FIELD USING P_FNAM TYPE ANY

P_FVAL TYPE ANY.

CLEAR WA_BDCDATA.

WA_BDCDATA-FNAM = P_FNAM.

WA_BDCDATA-FVAL = P_FVAL.

CONDENSE WA_BDCDATA-FVAL.

APPEND WA_BDCDATA TO T_BDCDATA.

ENDFORM. " bdc_field

&----


*& Form bdc_close

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM BDC_CLOSE .

CALL FUNCTION 'BDC_CLOSE_GROUP'

EXCEPTIONS

NOT_OPEN = 1

QUEUE_ERROR = 2

OTHERS = 3.

ENDFORM. " bdc_close

*&----


**& Form help_input_file

*&----


    • text

*----


    • --> p1 text

    • <-- p2 text

*----


FORM HELP_INPUT_FILE .

DATA: LT_FILE_TABLE TYPE FILETABLE,

LA_FILE_TABLE LIKE LINE OF LT_FILE_TABLE,

L_RC TYPE I,

L_PCDSN TYPE CFFILE-FILENAME.

REFRESH LT_FILE_TABLE.

CLEAR LA_FILE_TABLE.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG

CHANGING

FILE_TABLE = LT_FILE_TABLE

RC = L_RC.

READ TABLE LT_FILE_TABLE INTO LA_FILE_TABLE INDEX 1.

L_PCDSN = LA_FILE_TABLE-FILENAME.

MOVE L_PCDSN TO P_IFILE.

ENDFORM. " help_input_file

Former Member
0 Kudos

Hi Senthil,

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.

Thanks,

Former Member
0 Kudos

HI,

STEPS : CREAT INTERNAL TABLE

READ THE DATA FROM FLAT FILE TO INTERNAL TABLE

OPEN THE SESSION

POPULATE THE DATA

CLOSE THE SESSION

ACTIVATE

RUN THE PROGRAM

GO SM35 AND RUN THE SESSION U CREATED IN BDC_OPEN_GROUP

&----


*& Report ZBDCSESSION

*&

&----


*&

*&

&----


REPORT ZBDCSESSION

no standard page heading line-size 255.

*

DATA: BEGIN OF ITAB OCCURS 0,

MATNR LIKE MARA-MATNR,

MBRSH LIKE MARA-MBRSH,

MTART LIKE MARA-MTART,

MAKTX LIKE MAKT-MAKTX,

MEINS LIKE MARA-MEINS,

END OF ITAB.

DATA: BEGIN OF jTAB OCCURS 0,

MATNR LIKE MARA-MATNR,

END OF jTAB.

DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

DATA ERROR_ITAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

DATA ERROR_TITAB LIKE ERROR_ITAB OCCURS 0 WITH HEADER LINE.

DATA L_MSG(50) TYPE C.

CONstants: C_MM01(6) TYPE C VALUE 'MM01',

C_A(1) TYPE C VALUE 'A',

C_N(1) TYPE C VALUE 'N'.

start-of-selection.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'C:\TEXT1.TXT'

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = ITAB

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17

.

IF SY-SUBRC <> 0.

MESSAGE ' INVALID DATA' TYPE 'E'.

ENDIF.

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

CLIENT = SY-MANDT

GROUP = 'ZBDCSESSION'

KEEP = 'X'

USER = SY-UNAME

PROG = SY-CPROG

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.

LOOP AT ITAB.

PERFORM FILL_DATA.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = 'MM01'

TABLES

DYNPROTAB = 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.

REFRESH BDCDATA.

IF SY-SUBRC = 0.

WRITE : / ITAB-MATNR,ITAB-MBRSH.

ENDIF.

CLEAR ITAB.

ENDLOOP.

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.

FORM FILL_DATA.

  • fIRST SCREEN

perform bdc_dynpro using 'SAPLMGMM' '0060'.

perform bdc_field using 'BDC_CURSOR'

'RMMG1-MTART'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RMMG1-MATNR'

ITAB-MATNR.

perform bdc_field using 'RMMG1-MBRSH'

ITAB-MBRSH.

perform bdc_field using 'RMMG1-MTART'

ITAB-MTART.

*SECOND SCREEN

perform bdc_dynpro using 'SAPLMGMM' '0070'.

perform bdc_field using 'BDC_CURSOR'

'MSICHTAUSW-DYTXT(01)'.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

perform bdc_field using 'MSICHTAUSW-KZSEL(01)'

'X' .

*THIRD SCREEN

perform bdc_dynpro using 'SAPLMGMM' '4004'.

perform bdc_field using 'BDC_OKCODE'

'=BU'.

perform bdc_field using 'MAKT-MAKTX'

ITAB-MAKTX.

perform bdc_field using 'BDC_CURSOR'

'MARA-MEINS'.

perform bdc_field using 'MARA-MEINS'

ITAB-MEINS.

ENDFORM.

*----


*

  • Start new screen

*

*----


*

FORM BDC_DYNPRO USING PROGRAM DYNPRO.

CLEAR BDCDATA.

BDCDATA-PROGRAM = PROGRAM.

BDCDATA-DYNPRO = DYNPRO.

BDCDATA-DYNBEGIN = 'X'.

APPEND BDCDATA.

ENDFORM.

*----


*

  • Insert field

*

*----


*

FORM BDC_FIELD USING FNAM FVAL.

CLEAR BDCDATA.

BDCDATA-FNAM = FNAM.

BDCDATA-FVAL = FVAL.

APPEND BDCDATA.

ENDFORM.

BY ASHOK KUMAR