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

Former Member
0 Likes
583

hi,

for example i have 11 records in a given range and this 11 records should be updated using bdc...when iam doing that its looping 11 times but only one record is updating...only the first record is saving the other records are not...

plz advise..

regards..

4 REPLIES 4
Read only

Former Member
0 Likes
541

Hi,

check out the code prob this will help u as this is updating multiple records in two different transaction

*Report : BDC on Transaction BGM1 & Transaction ME12

*Transaction Code :

*Description : BDC report on transaction BGM1 to internally generate

  • master warrnty number and then BDC on ME12 to update

  • info record by entering generated master warranty no.

  • in field Vend. mat.group. The input flat file will have

  • Vendor no & Material No.

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

  • types Declaration *

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

types: begin of t_tab1 ,

vendor(10),

material(18),

pur_org(4),

wglif(18),

end of t_tab1.

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

  • Data Declaration *

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

data : begin of it_tab5 occurs 0,

vendor(10),

material(18),

end of it_tab5.

**DATA : BEGIN OF IT_TAB6 OCCURS 0,

    • VENDOR(10),

    • MATERIAL(18),

    • END OF IT_TAB6.

data: it_tab1 type standard table of t_tab1 with header line.

data: wa_tab1 type t_tab1.

data: wa_tab2 type t_tab1.

data: it_tab3 like bdcdata occurs 0 with header line.

data: it_tab4 like bdcdata occurs 0 with header line.

data: it_tab2 type table of bdcmsgcoll with header line.

data: d_file_name like ibipparms-path,

d_file_name1 type string.

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

  • Start-of-selection *

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

start-of-selection.

        • FM for finding the flat file

call function 'F4_FILENAME'

  • EXPORTING

  • PROGRAM_NAME = SYST-CPROG

  • DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

importing

file_name = d_file_name.

d_file_name1 = d_file_name.

******FM for uploading data from flat file into internal table

call function 'GUI_UPLOAD'

exporting

filename = d_file_name1

filetype = 'ASC'

  • HAS_FIELD_SEPARATOR = ' '

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

tables

data_tab = it_tab5

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.

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

  • End-of-selection *

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

end-of-selection.

sort it_tab5 by vendor.

loop at it_tab5.

perform bdc_dynpro using 'SAPLBG00' 0101 .

perform bdc_field using 'BDC_OKCODE' '/00' .

perform bdc_dynpro using 'SAPLBG00' 1000 .

perform bdc_field using 'BDC_OKCODE' '=BUCH' .

perform bdc_field using 'BDC_SUBSCR'

'SAPLBG00 1101KOPF_1000'.

perform bdc_field using 'GBGMK-GAART' '2' .

perform bdc_field using 'GBGMK-GAERB' 'X' .

perform bdc_field using 'BDC_SUBSCR'

'SAPLBG00 1103TAB_SUB_1000'.

perform bdc_field using 'BDC_CURSOR' 'GBGMP-LSTNR(01)' .

perform bdc_field using 'GBGMP-LSTNR(01)' it_tab5-material .

call transaction 'BGM1' using it_tab3 mode 'A' messages into it_tab2.

refresh it_tab3.

        • ON CHANGE OF IT_TAB5-VENDOR.

        • EXIT.

        • ENDON.

****

        • ENDLOOP.

****

        • LOOP AT IT_TAB5.

wa_tab1-pur_org = 'ABCP'.

loop at it_tab2.

endloop.

perform bdc_dynpro using 'SAPMM06I' 0100 .

perform bdc_field using 'BDC_CURSOR' 'EINE-EKORG' .

perform bdc_field using 'BDC_OKCODE' '/00' .

perform bdc_field using 'EINA-LIFNR' it_tab5-vendor .

perform bdc_field using 'EINA-MATNR' it_tab5-material .

perform bdc_field using 'EINE-EKORG' wa_tab1-pur_org .

perform bdc_field using 'RM06I-NORMB' 'X' .

perform bdc_dynpro using 'SAPMM06I' 0101 .

perform bdc_field using 'BDC_CURSOR' 'EINA-WGLIF' .

perform bdc_field using 'BDC_OKCODE' '=BU' .

perform bdc_field using 'EINA-WGLIF' it_tab2-msgv1 .

call transaction 'ME12' using it_tab3 mode 'A'.

refresh it_tab3.

refresh it_tab2.

endloop.

&----


*& Form BDC_DYNPRO

&----


  • Start new screen

----


  • -->P_FNAM text

  • -->P_FVAL text

----


form bdc_dynpro using program

dynpro.

clear it_tab3.

it_tab3-program = program.

it_tab3-dynpro = dynpro.

it_tab3-dynbegin = 'X'.

append it_tab3.

endform. " BDC_DYNPRO

&----


*& Form BDC_FIELD

&----


  • Insert field

----


  • -->P_FNAM text

  • -->P_FVAL text

----


form bdc_field using fnam

fval.

clear it_tab3.

it_tab3-fnam = fnam.

it_tab3-fval = fval.

append it_tab3.

endform. " BDC_FIELD

else provide the code where u r getting the problem

reward if helpful

Read only

former_member609120
Contributor
0 Likes
541

Check if the SAVE Code is being perfomed for each record..you may have put it outside the loop..hence it is saving only one record..

Read only

Former Member
0 Likes
541

Hi.

Try this.

REPORT DEMO1.

  • Following internal table is to upload flat file.

DATA: BEGIN OF ITAB OCCURS 0,

ID(10),

NAME(25),

CITY(25),

END OF ITAB.

*Following internal table BDCDATA is to pass date from internal table to session.

DATA: BDCTAB LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

  • Variables

DATA: DATE1 LIKE SY-DATUM. DATE1 = SY-DATUM - 1. “ This is for Hold Date

  • To upload flat file to internal table.

CALL FUNCTION UPLOAD

EXPORTING

FILE NAME = ‘C:\FF.TXT’

FILE TYPE = ‘ASC”

TABLES

DATA_TAB = ITAB

EXCEPTIONS

CONVERSION_ERROR = 1

INVALID_TABLE_WIDTH = 2

INVALID_TYPE = 3

NO_BATCH = 4

UNKNOWN_ERROR = 5

OTHERS = 6.

If sy-subrc = 0.

  • Calling Function to Create a Session

CALL FUNCTION ‘BDC_OPEN_GROUP’

EXPORTING

CLIENT = SY-MANDT

GROUP = ‘POTHURI’

HOLDDATE = DATE1

KEEP = ‘X’

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.

If sy-subrc = 0.

*--


MAIN Logic--


LOOP AT ITAB

PERFORM GENERATE_DATA. “ Populating BDCDATA Table

CALL FUNCTION ‘BDC_INSERT’

EXPORTING

TCODE = ‘TFBA’

TABLES

DYNPROTAB = BDCTAB

EXCEPTIONS

INTERNAL_ERROR = 1

NOT_OPEN = 2

QUEUE_ERROR = 3

TCODE_INVALID = 4

PRINTING_INVALID = 5

POSTING_INVALID = 6

OTHERS = 7.

REFRESH BDCTAB

ENDLOOP.

  • Calling function to close the session

CALL FUNCTION ‘BDC_CLOSE_GROUP’

EXCEPTIONS

NOT_OPEN = 1

QUEUE_ERROR = 2

OTHERS = 3.

Endif.

Endif.

&----


*& Form GENERATE_DATA

&----


  • Create BDC Data

&----


FORM GENERATE_DATA

  • Passing information for 1st screen on BDCDATA

BDCTAB-PROGRAM = ‘SAPMTFBA’.

BDCTAX-DYNPRO = 100.

BDCTAP-DYNBEGIN = ‘X’.

APPEND BCDTAB.CLEAR BDCTAB.

  • Passing field information to BDCDATA

BDCTAB-FNAM = ‘SCUSTOM-ID’

BDCTAB-FVAL = ITAB-ID.

APPEND BDCTAB.CLEAR BDCTAB.

  • Passing BDC_OKCODE to BDCDATA

BDCTAB-FNAM = ‘BDC_OKCODE’.

BDCTAB-FVAL = ‘/5’.

APPEND BDCTAB.CLEAR BDCTAB.

  • Passing screen information for next screen to BDCDATA

BDCTAB-PROGRAM = ‘SAPMTFBA’.

BDCTAB-DYNPRO = 200.

BDCTAB-DYNBEGIN = ‘X’.

APPEND BDCTAB.CLEAR BDCTAB.

  • Passing screen information to BDCDATA

BDCTAB-FNAM = ‘SCUSTOM-NAME’.

BDCTAB-FVAL = ITAB-NAME.

APPEND BDCTAB.CLEAR BDCTAB.

  • Passing screen information to BDCDATA

BDCTAB-FNAM = ‘SCUSTOM-CITY’.

BDCTAB-FVAL = ITAB-CITY.

APPEND BDCTAB.CLEAR BDCTAB.

  • Passing BDC_OKCODE to BDCDATA

BDCTAB-FNAM = ‘BDC_OKCODE’.

BDCTAB-FVAL = ‘SAVE’.

APPEND BDCTAB.CLEAR BDCTAB.

ENDFORM. “GENERATE_DATA

AN EXAMPLE WITH CALL TRANSACTION

Same steps to be repeated for CALL TRANSACTION

The only difference between the two types of interface is in Session method, you create session and store information about screen and data into session. When session is processed the data is transferred to database. While in CALL TRANSACTION, data is transferred directly to database table.

REPORT DEMO1.

  • Follow above Code till MAIN Logic. Even the Subroutine should be copied

LOOP AT ITAB

PERFORM GENERATE_DATA, “Populating BDCDATA Table

Call transaction ‘TFBA’ using BCDDATA Mode ‘A’ Update ‘S’.

REFRESH BDCTAB

ENDLOOP.

regards.

sowjanya.b

Read only

Former Member
0 Likes
541

hiya... this is my code :

EPORT ztestbdc NO STANDARD PAGE HEADING

MESSAGE-ID zsd

LINE-SIZE 132 LINE-COUNT 60.

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

*

  • DATABASE TABLES

*

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

*

tables : kna1.

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

*

  • INTERNAL TABLES

*

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

*

types : BEGIN OF lt_itab ,

kunnr LIKE kna1-kunnr,

zzdiscountam LIKE kna1-zzdiscountam,

zzdiscountva LIKE kna1-zzdiscountva,

zzlastdddate LIKE kna1-zzlastdddate,

END OF lt_itab.

DATA: it_itab TYPE STANDARD TABLE OF lt_itab INITIAL SIZE 0.

DATA: wa_itab TYPE lt_itab.

DATA: gv_bdcmode TYPE c VALUE 'A',

lv_save TYPE c,

gv_exit TYPE c,

lv_from(10) TYPE c,

lv_to(10) TYPE c,

gt_errors TYPE TABLE OF solisti1 WITH HEADER LINE.

CONSTANTS: c_system_msgtyp LIKE bdcmsgcoll-msgtyp VALUE 'S',

c_discountsave_msgid LIKE bdcmsgcoll-msgid VALUE 'VK',

c_discountsave_msgnr LIKE bdcmsgcoll-msgnr VALUE '023'.

TYPE-POOLS busei.

DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE,

messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.

DATA: gs_ci_include TYPE ci_cust,

gs_ci_include_x TYPE ci_cust_x,

gs_salesarea TYPE busei_ccom_salesarea,

gt_addresses TYPE zbus_ei_bupa_address_t,

gs_kna1 TYPE kna1,

gs_zcrmtab_client TYPE zcrmtab_client,

gv_ship_to_address TYPE bss_adr,

gt_addons TYPE TABLE OF zbut0000000000 WITH HEADER LINE,

gt_addons_new TYPE TABLE OF zbut0000000000 WITH HEADER LINE.

DATA : FNAM(20) TYPE C,

IDX TYPE C.

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

*

  • WORKING VARIABLES

*

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

*

DATA: stored_client_name LIKE kna1-name1.

DATA: stored_date_heading(10).

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

*

  • PARAMETERS / SELECT OPTIONS

*

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

*

SELECT-OPTIONS : s_kunnr FOR kna1-kunnr.

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

*

INITIALIZATION.

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

*

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

*

AT SELECTION-SCREEN.

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

*

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

*

START-OF-SELECTION.

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

*

SELECT kunnr

zzdiscountam

zzdiscountva

zzlastdddate

FROM kna1

INTO CORRESPONDING FIELDS OF TABLE it_itab

WHERE kunnr IN s_kunnr.

SELECT SINGLE vkorg vtweg spart

INTO (gs_salesarea-salesarea-sales_org,

gs_salesarea-salesarea-channel,

gs_salesarea-salesarea-division)

FROM knvv

WHERE kunnr IN s_kunnr.

CLEAR bdcdata. REFRESH bdcdata.

CLEAR messtab. REFRESH messtab.

PERFORM bdc_load USING 'SAPMV13A' '0100' 'X' ' ' ' '.

PERFORM bdc_load USING ' ' ' ' ' ' 'RV13A-KSCHL' 'K007'.

PERFORM bdc_load USING ' ' ' ' ' ' 'BDC_OKCODE' '/00'.

PERFORM bdc_load USING 'RV13A307' '1000' 'X' ' ' ' '.

PERFORM bdc_load USING ' ' ' ' ' ' 'F001'

gs_salesarea-salesarea-sales_org.

PERFORM bdc_load USING ' ' ' ' ' ' 'F002'

gs_salesarea-salesarea-channel.

PERFORM bdc_load USING ' ' ' ' ' ' 'F003-LOW' s_kunnr-low.

PERFORM bdc_load USING ' ' ' ' ' '

'F003-HIGH' s_kunnr-high.

PERFORM bdc_load USING ' ' ' ' ' ' 'BDC_OKCODE' '=HIZ1'.

LOOP AT it_itab into wa_itab.

PERFORM bdc_load USING 'SAPMV13A' '1307' 'X' ' ' ' '.

PERFORM bdc_load USING ' ' ' ' ' ' 'KOMG-KUNNR(01)' wa_itab-kunnr.

PERFORM bdc_load USING ' ' ' ' ' ' 'KONP-KBETR(01)'

wa_itab-zzdiscountam.

PERFORM bdc_load USING ' ' ' ' ' ' 'RV13A-DATAB(01)' lv_from.

PERFORM bdc_load USING ' ' ' ' ' ' 'RV13A-DATBI(01)' lv_to.

PERFORM bdc_load USING ' ' ' ' ' ' 'BDC_OKCODE' '=SICH'.

CALL TRANSACTION 'VK12' USING bdcdata

MODE gv_bdcmode

UPDATE 'N'

MESSAGES INTO messtab.

LOOP AT messtab.

IF messtab-msgtyp = c_system_msgtyp

AND messtab-msgid = c_discountsave_msgid

AND messtab-msgnr = c_discountsave_msgnr.

lv_save = 'X'.

ENDIF.

ENDLOOP.

IF lv_save IS INITIAL.

gv_exit = 'X'.

gt_errors-line = 'Failed to insert/update discount'.

LOOP AT messtab.

PERFORM message_capture USING messtab-msgid

messtab-msgnr

messtab-msgv1

messtab-msgv2

messtab-msgv3

messtab-msgv4

CHANGING gt_errors-line.

APPEND gt_errors.

ENDLOOP.

EXIT.

ENDIF.

ENDLOOP.

plz advise...(at the moment its doing only for one record and looping 11 times for the same record)

thanks