Application Development and Automation 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: 
Read only

bdc problem

Former Member
0 Likes
344

if we have thousand records then which method from LMSW ,call transaction and session method for uploading the data into the sap system.

1 REPLY 1
Read only

Former Member
0 Likes
306

Hi,

For large no of data such as 1000 records for one transaction you have to use transaction method.For uploading several transaction at a time you have to use session method.

The procedure is as follows :

1.Use transaction code SHDB for recording purpose and make it sure that you will do as much correct as possible while recording because it will generate the coding based on reecording.

2.After generating the code edit the code by inserting the loop at internal table before the perform bdxrex. statement.

3.Get the values from flat file to internal table and loop the internal table before the bdcrexc.

4.Just get clear overview about the bdc recording and start doing recording after that edit the coding after reviewing two more times.

5. I will give the code below use that and have a clear idea about the session method.

The code is below just copy and paste it you will get a clear idea bdc recording.

&----


*& Report Y0007_BDC

*&

&----


&*********************************************************************

  • Program Name : Y0007_BDC Create Date: 01/12/2007 *

  • Author's Name: Sakthi Saravanan.C Last Update:

  • DRF Number :

*

  • *

  • Program Title: UPDATING IT 0007 for overtime Z fields. *

  • *

  • Description :

  • Updating the infotype 0007 using BDC recording for *

  • updating the overtime Z fields. *

  • *

----


  • Change History *

----


  • Mod. # | Date | Developer | Description

----


  • 1. |01.12.2007|Sakthi Saravanan.C |BDC recording for updating

  • overtime Z fields in IT 0007

*

  • 2 |

*

************************************************************************

*&

&----


report Y0007_BDC NO STANDARD PAGE HEADING MESSAGE-ID RP LINE-SIZE 180." LINE-COUNT 28.

  • no standard page heading line-size 255.

*********************************************************************

  • DATA DECLARATION *

**********************************************************************

TYPES : BEGIN OF TY_0007,

PERNR TYPE PERNR, " PERNR

SCHKZ TYPE SCHKN, " Work Schudule

ZTERF TYPE PT_ZTERF, " Time Magmt Status

R1 TYPE C,

R2 TYPE C,

R3 TYPE C,

END OF TY_0007.

DATA : INT_0007 TYPE STANDARD TABLE OF TY_0007 WITH HEADER LINE,

WA_0007 TYPE TY_0007.

DATA: P_FNAME TYPE IBIPPARMS-PATH.

DATA : begin of int_out occurs 0,

pernr type persno,

mesg(300),

end of int_out.

DATA : BEGIN OF int_err occurs 0,

pernr type persno,

mesg(300),

end of int_err.

include bdcrecx1.

**********************************************************************

  • SELECTION SCREEN *

**********************************************************************

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

SELECTION-SCREEN BEGIN OF BLOCK B WITH FRAME.

PARAMETERS : P_PATH TYPE string.

SELECTION-SCREEN END OF BLOCK B.

SELECTION-SCREEN END OF BLOCK A.

**********************************************************************

  • CALL FUNCTION FOR INPUT FILE NAME *

**********************************************************************

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_path.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

DYNPRO_NUMBER = SYST-DYNNR

FIELD_NAME = ' '

IMPORTING

FILE_NAME = P_FNAME.

p_path = p_fname.

IF SY-SUBRC <> 0.

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

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

ENDIF.

start-of-selection.

**********************************************************************

  • GUI_UPLOAD FUNCTION MODULE *

**********************************************************************

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = P_PATH

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = INT_0007

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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

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

ENDIF.

perform open_group.

*Looping pernr values*

LOOP AT INT_0007 INTO WA_0007.

perform bdc_dynpro using 'SAPMP50A' '1000'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

*INSERTING THE PERNR VALUE*

perform bdc_field using 'RP50G-PERNR'

WA_0007-PERNR. "'00001011'.

perform bdc_field using 'RP50G-TIMR6'

'X'.

perform bdc_field using 'BDC_CURSOR'

'RP50G-CHOIC'.

perform bdc_field using 'RP50G-CHOIC'

'0007'.

perform bdc_dynpro using 'SAPMP50A' '1000'.

perform bdc_field using 'BDC_CURSOR'

'RP50G-PERNR'.

perform bdc_field using 'BDC_OKCODE'

'=INS'.

perform bdc_field using 'RP50G-PERNR'

WA_0007-PERNR. "'1011'.

perform bdc_field using 'RP50G-TIMR6'

'X'.

perform bdc_field using 'RP50G-CHOIC'

'Planned Working Time - 0007'.

perform bdc_dynpro using 'MP000700' '2000'.

perform bdc_field using 'BDC_OKCODE'

'=UPD'.

perform bdc_field using 'P0007-BEGDA'

'12/01/2007'.

perform bdc_field using 'P0007-ENDDA'

'12/31/9999'.

*INSERTING THE WORK SCHEDULE*

perform bdc_field using 'P0007-SCHKZ'

WA_0007-SCHKZ. "'N12'.

perform bdc_field using 'P0007-ZTERF'

WA_0007-ZTERF. "'1'.

*INSERTING THE OVERTIME CLASS*

IF WA_0007-R1 = 'X'.

perform bdc_field using 'ZHQ0007-OVT_ELGBLE'

'X'.

ELSEIF WA_0007-R2 = 'X'.

perform bdc_field using 'ZHQ0007-OVT_NOTELG'

'X'.

ELSEIF WA_0007-R3 = 'X'.

perform bdc_field using 'ZHQ0007-OVT_TMPELG'

'X'.

ENDIF.

*BDC output for transaction code*

  • perform f_bdc_output using 'pa30'.

PERFORM BDC_TRANSACTION USING 'PA30'.

ENDLOOP.

top-of-page.

INCLUDE ZWUHDG20 . "Global Data , Start-of-Sel. and Code

INCLUDE ZWUHDG30 . "Top-of-page and Call function

*Writing the output*

  • PERFORM f_write_output.

perform close_group.

&----


*& Form f_write_output

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f_write_output .

*For Successfull Records*

if int_OUT[] IS NOT INITIAL.

WRITE : /50 TEXT-004 color 4.

write : / sy-uline.

LOOP AT INT_OUT.

WRITE : /40 int_out-pernr,50 '-->',54 int_out-mesg.

ENDLOOP.

ENDIF.

write / sy-uline.

SKIP 2.

*For Error records*

if int_err[] IS NOT INITIAL.

WRITE /53 text-005 color 6.

write / sy-uline.

LOOP AT int_err.

write :/40 int_err-pernr,50 '-->',54 int_err-mesg.

ENDLOOP.

endif.

write / sy-uline.

ENDFORM. " f_write_output

&----


*& Form f_bdc_output

&----


  • text

----


  • -->P_0369 text

----


FORM f_bdc_output USING VALUE(P_0369).

DATA: L_MSTRING(480).

DATA: L_SUBRC LIKE SY-SUBRC.

REFRESH MESSTAB.

*Capturing the output message*

CALL TRANSACTION 'PA30' USING BDCDATA

MODE CTUMODE

UPDATE CUPDATE

MESSAGES INTO MESSTAB.

L_SUBRC = SY-SUBRC.

IF SMALLLOG <> 'X'.

LOOP AT MESSTAB.

*Selection for capturing the text for records*

SELECT SINGLE * FROM T100 WHERE SPRSL = MESSTAB-MSGSPRA

AND ARBGB = MESSTAB-MSGID

AND MSGNR = MESSTAB-MSGNR.

IF SY-SUBRC = 0.

*Moving the text from T100 to local variable*

L_MSTRING = T100-TEXT.

IF ( MESSTAB-MSGTYP = 'W' or

MESSTAB-MSGTYP = 'S' OR

MESSTAB-MSGTYP = 'E' ).

*Moving the success records pernr and text to internal table*

IF MESSTAB-MSGTYP = 'S'.

INT_OUT-PERNR = WA_0007-PERNR.

INT_OUT-MESG = L_MSTRING.

APPEND INT_OUT.

CLEAR INT_OUT.

*Moving the success records pernr and text to internal table*

ELSEIF MESSTAB-MSGTYP = 'E'.

*For getting the error text exactly*

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.

INT_ERR-PERNR = WA_0007-PERNR.

INT_ERR-MESG = L_MSTRING.

APPEND INT_ERR.

CLEAR INT_ERR.

ENDIF.

ENDIF.

ENDIF.

ENDLOOP.

SKIP.

ENDIF.

&----


*& CALL FUNCTION 'BDC_OPEN_GROUP'

&----


IF L_SUBRC <> 0 AND E_GROUP <> SPACE.

IF E_GROUP_OPENED = ' '.

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

CLIENT = SY-MANDT

GROUP = E_GROUP

USER = E_USER

KEEP = E_KEEP

HOLDDATE = E_HDATE.

E_GROUP_OPENED = 'X'.

ENDIF.

&----


*& CALL FUNCTION 'BDC_INSERT'

&----


CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = 'PA30'

TABLES

DYNPROTAB = BDCDATA.

&----


*& CALL FUNCTION '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.

ENDIF.

REFRESH BDCDATA.

ENDFORM. " f_bdc_output

Thanks,

Sakthi C

*Rewards if usefull*