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

uploading entries into table using bdc

0 Likes
2,237

hi,

I have save the recording first in the bdc and i got the source code in program. i want to add more entries multiple into the same tabel "zmat". with different zmatcode & zmat-zdesp.

please help me how to write the code. or what changes i have to do.

report ZRAJESH_BDC_01

no standard page heading line-size 255.

include bdcrecx1.

start-of-selection.

perform open_group.

perform bdc_dynpro using 'SAPLZMAT' '0002'.

perform bdc_field using 'BDC_CURSOR'

'ZMAT-ZMATCODE(01)'.

perform bdc_field using 'BDC_OKCODE'

'=NEWL'.

perform bdc_dynpro using 'SAPLZMAT' '0003'.

perform bdc_field using 'BDC_CURSOR'

'ZMAT-ZDESP'.

perform bdc_field using 'BDC_OKCODE'

'=SAVE'.

perform bdc_field using 'ZMAT-ZMATCODE'

'rajeshswami'.

perform bdc_field using 'ZMAT-ZDESP'

'test 1001'.

perform bdc_dynpro using 'SAPLZMAT' '0003'.

perform bdc_field using 'BDC_CURSOR'

'ZMAT-ZDESP'.

perform bdc_field using 'BDC_OKCODE'

'=NEXT'.

perform bdc_field using 'ZMAT-ZDESP'

'TEST 1001'.

perform bdc_dynpro using 'SAPLZMAT' '0003'.

perform bdc_field using 'BDC_CURSOR'

'ZMAT-ZDESP'.

perform bdc_field using 'BDC_OKCODE'

'=SAVE'.

perform bdc_field using 'ZMAT-ZMATCODE'

'ram 0001'.

perform bdc_field using 'ZMAT-ZDESP'

'test 0001'.

perform bdc_dynpro using 'SAPLZMAT' '0003'.

perform bdc_field using 'BDC_CURSOR'

'ZMAT-ZDESP'.

perform bdc_field using 'BDC_OKCODE'

'=UEBE'.

perform bdc_field using 'ZMAT-ZDESP'

'TEST 0001'.

perform bdc_dynpro using 'SAPLZMAT' '0002'.

perform bdc_field using 'BDC_CURSOR'

'ZMAT-ZMATCODE(02)'.

perform bdc_field using 'BDC_OKCODE'

'=BACK'.

perform bdc_dynpro using 'SAPLZMAT' '0002'.

perform bdc_field using 'BDC_CURSOR'

'ZMAT-ZMATCODE(02)'.

perform bdc_field using 'BDC_OKCODE'

'=BACK'.

perform bdc_transaction using 'ZMAT'.

perform close_group.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,154

Hi,

I think you passing directly hard coded values to your BDC code. So, it will run only for 1 set of data.

e.g.

bdc_field using 'ZMAT-ZMATCODE' 'ram 0001'.

You will have to modify your BDC code. Instead of passing hard coded values, you will have to pass internal table (work area) variables to youe BDC.

bdc_field using 'ZMAT-ZMATCODE' wa_itab-zmatcode.

Put your BDC code inside the loop at the internal table.

Let me know if need more help.

Thanks,

Archana

Edited by: Archana Pawar on Mar 4, 2010 7:12 AM

14 REPLIES 14
Read only

Former Member
0 Likes
2,154

Hi Rajesh,

I would request you to paste the above pasted-code in between the tags.

Just paste the above mentioned tag just before and after your pasted-code.

so, that it will retain its format and would help me reading it clearly.

Regards,

Shravan Parepalli

Edited by: shravan_parepalli on Mar 4, 2010 6:46 AM

Read only

0 Likes
2,154

report ZRAJESH_BDC_01

no standard page heading line-size 255.

& include bdcrecx1. &

& start-of-selection. &

& perform open_group. &

& perform bdc_dynpro using 'SAPLZMAT' '0002'. &

& perform bdc_field using 'BDC_CURSOR'

'ZMAT-ZMATCODE(01)'. &

& perform bdc_field using 'BDC_OKCODE'

'=NEWL'. &

& perform bdc_dynpro using 'SAPLZMAT' '0003'. &

& perform bdc_field using 'BDC_CURSOR'

'ZMAT-ZDESP'. &

& perform bdc_field using 'BDC_OKCODE'

'=SAVE'. &

& perform bdc_field using 'ZMAT-ZMATCODE'

'rajeshswami'. &

& perform bdc_field using 'ZMAT-ZDESP'

'test 1001'. &

& perform bdc_dynpro using 'SAPLZMAT' '0003'. &

& perform bdc_field using 'BDC_CURSOR'

'ZMAT-ZDESP'. &

& perform bdc_field using 'BDC_OKCODE'

'=NEXT'. &

& perform bdc_field using 'ZMAT-ZDESP'

'TEST 1001'. &

& perform bdc_dynpro using 'SAPLZMAT' '0003'. &

& perform bdc_field using 'BDC_CURSOR'

'ZMAT-ZDESP'. &

& perform bdc_field using 'BDC_OKCODE'

'=SAVE'. &

perform bdc_field using 'ZMAT-ZMATCODE'

'ram 0001'. &

perform bdc_field using 'ZMAT-ZDESP'

'test 0001'. &

perform bdc_dynpro using 'SAPLZMAT' '0003'.

perform bdc_field using 'BDC_CURSOR'

'ZMAT-ZDESP'. &

perform bdc_field using 'BDC_OKCODE'

'=UEBE'. &

perform bdc_field using 'ZMAT-ZDESP'

'TEST 0001'. &

perform bdc_dynpro using 'SAPLZMAT' '0002'.

perform bdc_field using 'BDC_CURSOR'

'ZMAT-ZMATCODE(02)'. &

perform bdc_field using 'BDC_OKCODE'

'=BACK'. &

perform bdc_dynpro using 'SAPLZMAT' '0002'.

perform bdc_field using 'BDC_CURSOR'

'ZMAT-ZMATCODE(02)'. &

perform bdc_field using 'BDC_OKCODE'

'=BACK'. &

perform bdc_transaction using 'ZMAT'. &

perform close_group.

Read only

0 Likes
2,154

Hi Rajesh,

Its as simple as executing BDC in a loop.

1. Create a workarea like 'wa_zmat' of the type of your table i.e., 'zmat'

data: wa_zmat like line of zmat.

2. Loop your internal table into the work area. And now, replace all the hardcoded values which you have already entered

like 'rajeshswami' with the corresponding wa_zmat's field.

Regards,

Shravan Parepalli

Read only

Former Member
0 Likes
2,155

Hi,

I think you passing directly hard coded values to your BDC code. So, it will run only for 1 set of data.

e.g.

bdc_field using 'ZMAT-ZMATCODE' 'ram 0001'.

You will have to modify your BDC code. Instead of passing hard coded values, you will have to pass internal table (work area) variables to youe BDC.

bdc_field using 'ZMAT-ZMATCODE' wa_itab-zmatcode.

Put your BDC code inside the loop at the internal table.

Let me know if need more help.

Thanks,

Archana

Edited by: Archana Pawar on Mar 4, 2010 7:12 AM

Read only

0 Likes
2,154

hi ,

how to put bdc inside the loop please can you explain me..iam trying to upload data not by hard code. like you said

i have wrote the code like this.

report ZRAJESH_07 &

no standard page heading line-size 255. &

data: itab type table of zmat, &

wa_itab like line of itab. &

include bdcrecx1. &

start-of-selection. &

perform open_group. &

perform bdc_dynpro using 'SAPLZMAT' '0002'. &

perform bdc_field using 'BDC_CURSOR' &

'VIM_POSITION_INFO'. &

perform bdc_field using 'BDC_OKCODE' &

'=NEWL'. &

perform bdc_dynpro using 'SAPLZMAT' '0003'. &

perform bdc_field using 'BDC_CURSOR' &

'ZMAT-ZDESP'. &

perform bdc_field using 'BDC_OKCODE' &

'=SAVE'. &

perform bdc_field using 'ZMAT-ZMATCODE' &

'raj1'. &

perform bdc_field using 'ZMAT-ZDESP' &

'test raj'. &

perform bdc_dynpro using 'SAPLZMAT' '0003'. &

perform bdc_field using 'BDC_CURSOR' &

'ZMAT-ZDESP'. &

perform update_nextdata using 'raj2' 'test raj2'. &

perform bdc_transaction using 'ZMAT1'. &

perform close_group. &

form update_nextdata using wa_itab-ZMATCODE wa_itab-ZMAT-ZDESP. &

perform bdc_field using 'BDC_OKCODE' &

'=NEXT'. &

*perform bdc_field using 'ZMAT-ZDESP' &

  • 'TEST RAJ'. &

perform bdc_dynpro using 'SAPLZMAT' '0003'. &

perform bdc_field using 'BDC_CURSOR' &

'ZMAT-ZDESP'. &

perform bdc_field using 'BDC_OKCODE' &

'=SAVE'. &

perform bdc_field using 'ZMAT-ZMATCODE' &

wa_itab-ZMATCODE. &

perform bdc_field using 'ZMAT-ZDESP' &

wa_itab-ZDESP. &

perform bdc_dynpro using 'SAPLZMAT' '0003'. &

perform bdc_field using 'BDC_CURSOR' &

'ZMAT-ZDESP'. &

perform bdc_field using 'BDC_OKCODE' &

'=ENDE'. &

perform bdc_field using 'ZMAT-ZDESP' &

'RAJ2 TEST'. &

endform. &

Read only

0 Likes
2,154

Hi,

Refer below BDC code, which is modified from your BDC code.

perform bdc_dynpro using 'SAPLZMAT' '0002'. 
perform bdc_field using 'BDC_CURSOR'
			'ZMAT-ZMATCODE(01)'.
perform bdc_field using 'BDC_OKCODE'
			'=NEWL'.
perform bdc_dynpro using 'SAPLZMAT' '0003'.
perform bdc_field using 'BDC_CURSOR'
			'ZMAT-ZDESP'. 
perform bdc_field using 'BDC_OKCODE'
			'=SAVE'.
perform bdc_field using 'ZMAT-ZMATCODE'
			'rajeshswami'.---- Here, instead of name you give wa_itab-name ie.e corresponding field from your internal table.
perform bdc_field using 'ZMAT-ZDESP'
			'test 1001'. ---- Here,give corresponding field from your internal table.
perform bdc_dynpro using 'SAPLZMAT' '0003'. 
perform bdc_field using 'BDC_CURSOR'
			'ZMAT-ZDESP'.
perform bdc_field using 'BDC_OKCODE'
			'=NEXT'.
perform bdc_field using 'ZMAT-ZDESP'
			'TEST 1001'. ---- Here,give corresponding field from your internal table.
perform bdc_dynpro using 'SAPLZMAT' '0003'.
perform bdc_field using 'BDC_CURSOR'
			'ZMAT-ZDESP'.
perform bdc_field using 'BDC_OKCODE'
			'=SAVE'.
perform bdc_field using 'ZMAT-ZMATCODE'
			'ram 0001'. ---- Here,give corresponding field from your internal table.
perform bdc_field using 'ZMAT-ZDESP'
			'test 0001'. ---- Here,give corresponding field from your internal table.
perform bdc_dynpro using 'SAPLZMAT' '0003'.
perform bdc_field using 'BDC_CURSOR'
			'ZMAT-ZDESP'. 
perform bdc_field using 'BDC_OKCODE'
			'=UEBE'. 
perform bdc_field using 'ZMAT-ZDESP'
			'TEST 0001'. ---- Here,give corresponding field from your internal table.
perform bdc_dynpro using 'SAPLZMAT' '0002'.
perform bdc_field using 'BDC_CURSOR'
			'ZMAT-ZMATCODE(02)'. 
perform bdc_field using 'BDC_OKCODE'
			'=BACK'. 
perform bdc_dynpro using 'SAPLZMAT' '0002'.
perform bdc_field using 'BDC_CURSOR'
			'ZMAT-ZMATCODE(02)'. 
perform bdc_field using 'BDC_OKCODE'
			'=BACK'. 
perform bdc_transaction using 'ZMAT'.

Thanks,

Archana

Read only

0 Likes
2,154

hi archana , first thanks for helping me.

well this the code which i wrote.

report ZRAJESH_07 &

no standard page heading line-size 255. &

PARAMETERS: zcode type ZMAT-ZMATCODE, &

zdesp type ZMAT-ZDESP. &

data: itab type table of zmat, &

wa_itab like line of itab. &

include bdcrecx1. &

start-of-selection. &

perform open_group. &

perform bdc_dynpro using 'SAPLZMAT' '0002'. &

perform bdc_field using 'BDC_CURSOR' &

'VIM_POSITION_INFO'. &

perform bdc_field using 'BDC_OKCODE' &

'=NEWL'. &

perform bdc_dynpro using 'SAPLZMAT' '0003'. &

perform bdc_field using 'BDC_CURSOR' &

'ZMAT-ZDESP'. &

perform bdc_field using 'BDC_OKCODE' &

'=SAVE'. &

perform bdc_field using 'ZMAT-ZMATCODE' &

'raj1'. &

perform bdc_field using 'ZMAT-ZDESP' &

'test raj'. &

perform bdc_dynpro using 'SAPLZMAT' '0003'. &

perform bdc_field using 'BDC_CURSOR' &

'ZMAT-ZDESP'. &

perform update_nextdata using 'zcode' 'zdesp'. &

perform bdc_transaction using 'ZMAT1'. &

perform close_group. &

form update_nextdata using wa_itab-ZMATCODE wa_itab-ZMAT-ZDESP. &

loop at itab into wa_itab. &

perform bdc_field using 'BDC_OKCODE' &

'=NEXT'.

*perform bdc_field using 'ZMAT-ZDESP' &

  • 'TEST RAJ'.

perform bdc_dynpro using 'SAPLZMAT' '0003'. &

perform bdc_field using 'BDC_CURSOR' &

'ZMAT-ZDESP'. &

perform bdc_field using 'BDC_OKCODE' &

'=SAVE'. &

perform bdc_field using 'ZMAT-ZMATCODE' &

wa_itab-ZMATCODE. &

perform bdc_field using 'ZMAT-ZDESP' &

wa_itab-ZDESP. &

perform bdc_dynpro using 'SAPLZMAT' '0003'. &

perform bdc_field using 'BDC_CURSOR' &

'ZMAT-ZDESP'. &

perform bdc_field using 'BDC_OKCODE' &

'=ENDE'. &

perform bdc_field using 'ZMAT-ZDESP' &

'RAJ2 TEST'. &

endloop. &

endform. &

regards,

<<Email address removed>>

Edited by: Matt on Mar 4, 2010 3:41 PM

Read only

0 Likes
2,154

Hi,

First of all let me tell you few things:

BDC is used to upload data in batches. So, suppose if we have data in the form of file (flat file), we can use BDC in this case.

So, in order to use BDC, we should be able to read this data. So, we use FM 'GUI_UPLOAD' and take all the contents of the file into an internal table. This internal table will contains all the fields of that of the file.

Once your data is in internal table, you need to put it one by one in your tcode and execute it for every tcode. So, in order to achieve this, you need to write BDC code.

BDC code will be done from SHDB recording. From that recording you will have to write your BDC code and place it withing the loop.

Thanks,

Archana

Read only

0 Likes
2,154

Goto Note pad Enter the input data as per the ZMAT structure.Save it in local folder.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = 'c:\so.txt'

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

tables

data_tab = itab

Please Check Archana mentiond in codes and change it.

<<email address removed Dont specify the mail id here

Edited by: Matt on Mar 4, 2010 3:41 PM

Read only

matt
Active Contributor
0 Likes
2,154

Do not post your email address or other personal information on these forums

Read only

Former Member
0 Likes
2,154

hi

For multiple Entries .You have to pass the data in Flat file.(C:/so.txt)

In notepad you have to enter the multiple data and save it in the system.Input data and internal table structure should be same.

Example coding.

CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    filename                      = 'c:\so.txt'
   FILETYPE                      = 'ASC'
   HAS_FIELD_SEPARATOR           = 'X'

   tables
    data_tab                      = itab

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 into wa.
perform bdc_dynpro      using 'SAPMV45A' '0102'.
perform bdc_field       using 'BDC_CURSOR'
                              'VBAK-VBELN'.
perform bdc_field       using 'BDC_OKCODE'
                              '=SUCH'.
perform bdc_field       using 'VBAK-VBELN'
                              wa-VBELN_001.
perform bdc_field       using 'BDC_OKCODE'
                              '=SUCH'.
perform bdc_dynpro      using 'SAPMV45A' '4001'.
perform bdc_field       using 'BDC_OKCODE'
                              '=T\02'.
CONCATENATE 'RV45A-KWMENG( ' wa-vbap_selkz_04_015(001)') '  INTO temp2.
perform bdc_field       using temp2
                              wa-KWMENG_04_016(019).

perform bdc_dynpro      using 'SAPMV45A' '4001'.
perform bdc_field       using 'BDC_OKCODE'
                              '=SICH'.
perform bdc_transaction using 'VA02'.
ENDLOOP.

Read only

0 Likes
2,154

report ZRAJESH_07

no standard page heading line-size 255.

include bdcrecx1. &

start-of-selection. &

perform open_group. &

perform bdc_dynpro using 'SAPLZMAT' '0002'. &

perform bdc_field using 'BDC_CURSOR' &

'VIM_POSITION_INFO'. &

perform bdc_field using 'BDC_OKCODE' &

'=NEWL'. &

perform bdc_dynpro using 'SAPLZMAT' '0003'. &

perform bdc_field using 'BDC_CURSOR' &

'ZMAT-ZDESP'. &

perform bdc_field using 'BDC_OKCODE' &

'=SAVE'. &

perform bdc_field using 'ZMAT-ZMATCODE' &

'raj1'. &

perform bdc_field using 'ZMAT-ZDESP' &

'test raj'. &

perform bdc_dynpro using 'SAPLZMAT' '0003'. &

perform bdc_field using 'BDC_CURSOR' &

'ZMAT-ZDESP'. &

perform update_nextdata using 'raj2' 'test raj2'. &

perform bdc_transaction using 'ZMAT1'. &

perform close_group. &

form update_nextdata using ZMAT-ZMATCODE ZMAT-ZDESP. &

perform bdc_field using 'BDC_OKCODE' &

'=NEXT'. &

*perform bdc_field using 'ZMAT-ZDESP' &

  • 'TEST RAJ'. &

perform bdc_dynpro using 'SAPLZMAT' '0003'. &

perform bdc_field using 'BDC_CURSOR' &

'ZMAT-ZDESP'. &

perform bdc_field using 'BDC_OKCODE' &

'=SAVE'. &

perform bdc_field using 'ZMAT-ZMATCODE' &

ZMAT-ZMATCODE. &

perform bdc_field using 'ZMAT-ZDESP' &

ZMAT-ZDESP. &

perform bdc_dynpro using 'SAPLZMAT' '0003'. &

perform bdc_field using 'BDC_CURSOR' &

'ZMAT-ZDESP'. &

perform bdc_field using 'BDC_OKCODE' &

'=ENDE'. &

perform bdc_field using 'ZMAT-ZDESP' &

'RAJ2 TEST'. &

endform. &

i got the ouput just trying the different way please suggest me .

Read only

0 Likes
2,154

Hi,

First of all, you need to have data in your internal table. If suppose ZMAT is your internal table. You will need to upload data from your excel file/ text file into internal table, using FM GUI_UPLOAD. Then, you can use this internal table to loop at.

Then within loop you will have to write your modified code.

Just try this much. I will let you know how to write BDC code.

Thanks,

Archana

Read only

Former Member
0 Likes
2,154

Hi Swami ,

Do you have any table control for the screen that u recorded.That means do you want enter all the records in ITAB processing the BDC recording steps into the screen.then the below code may be useful to you.

LOOP AT i_item INTO wa_item WHERE plnnr = wa_header-plnnr . * Loop through the records in the ITAB

PERFORM bdc_dynpro USING 'SAPLCPDI' ' 3400'.

v_count = v_count + 1. *Increment the counter for each record

CONCATENATE 'PLPOD-VORNR(' v_count')' INTO v_val. *Contatenate the fieldname + counter ( Line in the table control)

PERFORM bdc_field USING 'BDC_CURSOR' v_val.

PERFORM bdc_field USING 'BDC_OKCODE' '=LTXT'.

CONCATENATE 'RC27X-FLG_SEL(' v_count')' INTO v_val.

PERFORM bdc_field USING v_val 'X'.

CONCATENATE 'PLPOD-ARBEH(' v_count')' INTO v_val.

PERFORM bdc_field USING v_val 'HR'. "wa_item-arbeh. *Contatenate the fieldname + counter ( Line in the table control)

CONCATENATE 'PLPOD-ANZZL(' v_count')' INTO v_val.

PERFORM bdc_field USING v_val wa_item-anzzl.

CONCATENATE 'plpod-dauno(' v_count')' INTO v_val.

PERFORM bdc_field USING v_val wa_item-dauno.

CONCATENATE 'PLPOD-DAUNE(' v_count')' INTO v_val.

PERFORM bdc_field USING v_val 'HR'. "wa_item-daune.

CONCATENATE 'PLPOD-INDET(' v_count')' INTO v_val.

PERFORM bdc_field USING v_val '2'. "wa_item-indet.

PERFORM bdc_dynpro USING 'SAPLSTXX' '1100'.

PERFORM bdc_field USING 'BDC_CURSOR' lv_txpargraph.

PERFORM bdc_field USING 'BDC_OKCODE' '=EDNP'.

if v_count > 20 * ( No.of visible lines)

give the OK code for page dowm.

clear v_count.

endif.

endloop.

After this call transaction, this statement continues.

This recording is specific to IA05 T.code you change accordingly to ur T.code.

Regards,

Pallavi.