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 loop processing problem

naimkhans_babi
Active Participant
0 Kudos

Dear Friends!

How are you. I have developed one BDC program, I am trying to post the line items for the given purchase order. my problem is everyhting goes fine with the program but when one line item processed it update the data base... and then rest are not processed...

like

po number : item no

111 1 <--- it update the first record.

111 2 <---- } this two items are not procesed.

111 3 <-----}

112 1

my code is :

LOOP AT int_record1 WHERE po_number = int_record-po_number AND

exnum = int_record-exnum AND

exdat = int_record-exdat AND

detail_zeile = int_record-detail_zeile.

l_index = l_index + 1.

PERFORM bdc_dynpro USING 'SAPLMIGO' '1000'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=OK_SP_CH'.

CONCATENATE 'GOSPLIT-ERFMG(' l_index ')' INTO l_field.

PERFORM bdc_field USING 'BDC_CURSOR'

l_field.

PERFORM bdc_field USING l_field

int_record1-erfmg1.

CLEAR l_field.

CONCATENATE 'GOSPLIT-LGOBE(' l_index ') ' INTO l_field.

PERFORM bdc_field USING 'BDC_CURSOR'

l_field.

PERFORM bdc_field USING l_field

int_record1-lgobe1.

CLEAR l_field.

CONCATENATE 'GOSPLIT-CHARG(' l_index ') ' INTO l_field.

PERFORM bdc_field USING 'BDC_CURSOR'

l_field.

PERFORM bdc_field USING l_field

int_record1-charg.

PERFORM bdc_dynpro USING 'SAPLMIGO' '1000'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_dynpro USING 'SAPLMIGO' '1000'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=OK_GOON'.

PERFORM bdc_dynpro USING 'SAPLMIGO' '0001'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=OK_GO'.

PERFORM bdc_field USING 'J_1IEXHEAD-EXNUM'

int_record-exnum.

PERFORM bdc_field USING 'J_1IEXHEAD-EXDAT'

int_record-exdat.

PERFORM bdc_dynpro USING 'SAPLMIGO' '0001'. <--- this should process after all the line item processesd....

PERFORM bdc_field USING 'BDC_OKCODE'

'=OK_POST1'.

PERFORM bdc_transaction USING 'MIGO'.

CLEAR l_index.

ENDLOOP.

please help me rectify this problem

Any help will be appreciated.

Rgads

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

YOU HAVE TO TAKE TWO INTERNAL TABLES

HEADER INTO ONE itab AND OTHER item DATA INTO OTHER itab1.

loop at header itab.

loop at item itab where ...f1 = itab-f2...

.......process all items

endloop.

endloop.

see the sample code for PR bdc

REPORT zmm_pr_upload_mat

NO STANDARD PAGE HEADING

LINE-SIZE 255.

  • Standard Include for Selection Screen

INCLUDE bdcrecx1.

  • Internal Table for Upload Data

DATA: BEGIN OF i_pr OCCURS 0,

  • Header Screen

sno(3), " SNo

bsart(004), " PR Type

epstp(001), " Item Category

knttp(001), " Account Assignment

eeind(010), " Delivery Date

  • lpein(001), " Category of Del Date

werks(004), " Plant

lgort(004), " Storage Location

ekgrp(003), " Purchasing Group

matkl(009), " Material Group

bednr(010), " Tracking No

afnam(012), " Requisitioner

  • Item Details

matnr(018), " Material No

menge(017), " Quantity

  • badat(010),

  • frgdt(010),

preis(014), " Valuation Price

  • waers(005), " Currency

  • peinh(005),

  • wepos(001),

  • repos(001),

sakto(010), " GL Account

kostl(010), " Cost Center

  • bnfpo(005),

END OF i_pr.

  • Internal Table for header Data

DATA: BEGIN OF it_header OCCURS 0,

sno(3), " SNo

bsart(004), " PR Type

epstp(001), " Item Category

knttp(001), " Account Assignment

eeind(010), " Delivery Date

werks(004), " Plant

lgort(004), " Storage Location

ekgrp(003), " Purchasing Group

matkl(009), " Material Group

bednr(010), " Tracking No

afnam(012), " Requisitioner

END OF it_header.

  • Internal Table for Item Data

DATA: BEGIN OF it_item OCCURS 0,

sno(3), " SNo

matnr(018), " Material No

menge(017), " Quantity

preis(014), " Valuation Price

sakto(010), " GL Account

kostl(010), " Cost Center

END OF it_item.

  • Data Variables & Constants

CONSTANTS : c_x VALUE 'X'. " Flag

DATA : v_l(2), " Counter

v_rowno(5), " Row No

v_2(2), " Counter

v_rows LIKE sy-srows, " Rows in TC

v_field(45). " String

  • Parameters

PARAMETERS: p_file LIKE ibipparms-path. " Filename

  • At selection-screen on Value Request for file Name

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  • Get the F4 Values for the File

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

IMPORTING

file_name = p_file.

  • Start of Selection

START-OF-SELECTION.

  • Open the BDC Session

PERFORM open_group.

  • Upload the File into internal Table

CALL FUNCTION 'UPLOAD'

EXPORTING

filename = p_file

filetype = 'DAT'

TABLES

data_tab = i_pr

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.

SORT i_pr BY sno.

LOOP AT i_pr.

MOVE-CORRESPONDING i_pr TO it_item.

APPEND it_item.

CLEAR it_item.

AT END OF sno.

READ TABLE i_pr INDEX sy-tabix.

MOVE-CORRESPONDING i_pr TO it_header.

APPEND it_header.

CLEAR it_header.

ENDAT.

ENDLOOP.

SORT it_header BY sno.

SORT it_item BY sno.

v_rows = sy-srows - 6.

  • Upload the Data from Internal Table

LOOP AT it_header.

  • Header Data

PERFORM bdc_dynpro USING 'SAPMM06B' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR'

'EBAN-BEDNR'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'EBAN-BSART'

it_header-bsart.

PERFORM bdc_field USING 'RM06B-EPSTP'

it_header-epstp.

PERFORM bdc_field USING 'EBAN-KNTTP'

it_header-knttp.

PERFORM bdc_field USING 'RM06B-EEIND'

it_header-eeind.

  • PERFORM bdc_field USING 'RM06B-LPEIN'

  • it_header-lpein.

PERFORM bdc_field USING 'EBAN-WERKS'

it_header-werks.

PERFORM bdc_field USING 'EBAN-LGORT'

it_header-lgort.

PERFORM bdc_field USING 'EBAN-EKGRP'

it_header-ekgrp.

PERFORM bdc_field USING 'EBAN-MATKL'

it_header-matkl.

PERFORM bdc_field USING 'EBAN-BEDNR'

it_header-bednr.

PERFORM bdc_field USING 'EBAN-AFNAM'

it_header-afnam.

  • Item Details

v_l = 0.

  • To add no. of rows

v_2 = 0 .

  • As the screen is showing 13 rows defaulted to 130

v_rowno = 130 .

LOOP AT it_item WHERE sno = it_header-sno.

v_l = v_l + 1.

IF v_l = 14 .

IF v_2 = 12 .

v_2 = 12 .

v_l = 2 .

  • From second time onwards it is displaying 12 rows only

v_rowno = v_rowno + 120 .

PERFORM bdc_dynpro USING 'SAPMM06B' '0106'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RM06B-BNFPO'.

PERFORM bdc_field USING 'RM06B-BNFPO'

v_rowno.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

ELSE.

  • V_2 initialized to 12 for second screen purpose

v_2 = 12 .

v_l = 2 .

PERFORM bdc_dynpro USING 'SAPMM06B' '0106'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RM06B-BNFPO'.

PERFORM bdc_field USING 'RM06B-BNFPO'

v_rowno .

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

ENDIF.

ENDIF.

PERFORM bdc_dynpro USING 'SAPMM06B' '0106'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

CLEAR v_field.

CONCATENATE 'EBAN-MATNR(' v_l ')' INTO v_field.

PERFORM bdc_field USING v_field it_item-matnr.

CLEAR v_field.

CONCATENATE 'EBAN-MENGE(' v_l ')' INTO v_field.

PERFORM bdc_field USING v_field it_item-menge.

PERFORM bdc_dynpro USING 'SAPMM06B' '0102'.

PERFORM bdc_field USING 'BDC_CURSOR'

'EBAN-PREIS'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'EBAN-PREIS'

it_item-preis.

PERFORM bdc_dynpro USING 'SAPMM06B' '0505'.

PERFORM bdc_field USING 'BDC_CURSOR'

'EBKN-SAKTO'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTE'.

PERFORM bdc_field USING 'EBKN-SAKTO'

it_item-sakto.

  • Cost Center

PERFORM bdc_dynpro USING 'SAPLKACB' '0002'.

PERFORM bdc_field USING 'BDC_CURSOR'

'COBL-KOSTL'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTE'.

PERFORM bdc_field USING 'COBL-KOSTL'

it_item-kostl.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTE'.

ENDLOOP.

PERFORM bdc_dynpro USING 'SAPMM06B' '0106'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RM06B-BNFPO'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BU'.

  • Call The Transaction

PERFORM bdc_transaction USING 'ME51'.

ENDLOOP.

  • Close the BDC Session

PERFORM close_group.

See the doc

How to deal with table control / step loop in BDC

Steploop and table contol is inevitable in certain transactions. When we run BDC for such transactions, we will face the situation: how many visible lines of steploop/tablecontrol are on the screen? Although we can always find certain method to deal with it, such as function code 'NP', 'POPO', considering some extreme situation: there is only one line visible one the screen, our BDC program should display an error message. (See transaction 'ME21', we you resize your screen to let only one row visible, you can not enter mutiple lines on this screen even you use 'NP')

Now with the help of Poonam on sapfans.com developement forum, I find a method with which we can determine the number of visible lines on Transaction Screen from our Calling BDC program. Maybe it is useless to you, but I think it will give your some idea.

Demo ABAP code has two purposes:

1. how to determine number of visible lines and how to calculte page number;

(the 'calpage' routine has been modify to meet general purpose usage)

2. using field symbol in BDC program, please pay special attention to the difference in Static ASSIGN and Dynamic ASSIGN.

Now I begin to describe the step to implement my method:

(I use transaction 'ME21', screen 121 for sample,

the method using is Call Transation Using..)

Step1: go to screen painter to display the screen 121, then we can count the fixed line on this screen, there is 7 lines above the steploop and 2 lines below the steploop, so there are total 9 fixed lines on this screen. This means except these 9 lines, all the other line is for step loop. Then have a look at steploop itselp, one entry of it will occupy two lines.

(Be careful, for table control, the head and the bottom scroll bar will possess another two fixed lines, and there is a maximum number for table line)

Now we have : FixedLine = 9

LoopLine = 2(for table control, LoopLine is always equal to 1)

Step2: go to transaction itself(ME21) to see how it roll page, in ME21, the first line of new page is always occupied by the last line of last page, so it begin with index '02', but in some other case, fisrt line is empty and ready for input.

Now we have: FirstLine = 0

or FirstLine = 1 ( in our case, FirstLine is 1 because the first line of new page is fulfilled)

Step3: write a subroutine calcalculating number of pages

(here, the name of actual parameter is the same as formal parameter)

global data: FixedLine type i, " number of fixed line on a certain screen

LoopLine type i, " the number of lines occupied by one steploop item

FirstLine type i, " possbile value 0 or 1, 0 stand for the first line of new " scrolling screen is empty, otherwise is 1

Dataline type i, " number of items you will use in BDC, using DESCRIBE to get

pageno type i, " you need to scroll screen how many times.

line type i, " number of lines appears on the screen.

index(2) type N, " the screen index for certain item

begin type i, " from parameter of loop

end type i. " to parameter of loop

*in code sample, the DataTable-linindex stands for the table index number of this line

form calpage using FixedLine type i (see step 1)

LoopLine type i (see step 1)

FirstLine type i (see step 2)

DataLine type i ( this is the item number you will enter in transaction)

changing pageno type i (return the number of page, depends on run-time visible line in table control/ Step Loop)

changing line type i.(visible lines one the screen)

data: midd type i,

vline type i, "visible lines

if DataLine eq 0.

Message eXXX.

endif.

vline = ( sy-srows - FixedLine ) div LoopLine.

*for table control, you should compare vline with maximum line of

*table control, then take the small one that is min(vline, maximum)

*here only illustrate step loop

if FirstLine eq 0.

pageno = DataLine div vline.

if pageno eq 0.

pageno = pageno + 1.

endif.

elseif FirstLine eq 1.

pageno = ( DataLine - 1 ) div ( vline - 1 ) + 1.

midd = ( DataLine - 1 ) mod ( vline - 1).

if midd = 0 and DataLine gt 1.

pageno = pageno - 1.

endif.

endif.

line = vline.

endform.

Step4 write a subroutine to calculate the line index for each item.

form calindex using Line type i (visible lines on the screen)

FirstLine type i(see step 2)

LineIndex type i(item index)

changing Index type n. (index on the screen)

if FirstLine = 0.

index = LineIndex mod Line.

if index = '00'.

index = Line.

endif.

elseif FirstLine = 1.

index = LineIndex mod ( Line - 1 ).

if ( index between 1 and 0 ) and LineIndex gt 1.

index = index + Line - 1.

endif.

if Line = 2.

index = index + Line - 1.

endif.

endif.

endform.

Step5 write a subroutine to calculate the loop range.

form calrange using Line type i ( visible lines on the screen)

DataLine type i

FirstLine type i

loopindex like sy-index

changing begin type i

end type i.

If FirstLine = 0.

if loopindex = 1.

begin = 1.

if DataLine <= Line.

end = DataLine.

else.

end = Line.

endif.

elseif loopindex gt 1.

begin = Line * ( loopindex - 1 ) + 1.

end = Line * loopindex.

if end gt DataLine.

end = DataLine.

endif.

endif.

elseif FirstLine = 1.

if loopindex = 1.

begin = 1.

if DataLine <= Line.

end = DataLine.

else.

end = Line.

endif.

elseif loop index gt 1.

begin = ( Line - 1 ) * ( loopindex - 1 ) + 2.

end = ( Line - 1 ) * ( loopindex - 1 ) + Line.

if end gt DataLine.

end = DataLine.

endif.

endif.

endif.

endform.

Step6 using field sysbol in your BDC, for example: in ME21, but you should calculate each item will correponding to which index in steploop/Table Control

form creat_bdc.

field-symbols: <material>, <quan>, <indicator>.

data: name1(14) value 'EKPO-EMATN(XX)',

name2(14) value 'EKPO-MENGE(XX)',

name3(15) value 'RM06E-SELKZ(XX)'.

assign: name1 to <material>,

name2 to <quan>,

name3 to <indicator>.

.

do pageno times.

if sy-index gt 1

*insert scroll page ok_code"

endif.

.

.

perform calrange using Line DataLine FirstLine sy-index

changing begin end.

.

.

loop at DataTable from begin to end.

perform calindex using Line FirstLine DataTable-LineIndex changing Index.

name1+11(2) = Index.

name2+11(2) = Index.

name3+12(2) = Index.

.

.

perform bdcfield using <material> DataTable-matnr.

perform bdcfield using <quan> DataTable-menge.

perform bdcfield using <indicator> DataTable-indicator.

.

.

.

endloop.

enddo.

Regards

Anji

1 REPLY 1

Former Member
0 Kudos

Hi

YOU HAVE TO TAKE TWO INTERNAL TABLES

HEADER INTO ONE itab AND OTHER item DATA INTO OTHER itab1.

loop at header itab.

loop at item itab where ...f1 = itab-f2...

.......process all items

endloop.

endloop.

see the sample code for PR bdc

REPORT zmm_pr_upload_mat

NO STANDARD PAGE HEADING

LINE-SIZE 255.

  • Standard Include for Selection Screen

INCLUDE bdcrecx1.

  • Internal Table for Upload Data

DATA: BEGIN OF i_pr OCCURS 0,

  • Header Screen

sno(3), " SNo

bsart(004), " PR Type

epstp(001), " Item Category

knttp(001), " Account Assignment

eeind(010), " Delivery Date

  • lpein(001), " Category of Del Date

werks(004), " Plant

lgort(004), " Storage Location

ekgrp(003), " Purchasing Group

matkl(009), " Material Group

bednr(010), " Tracking No

afnam(012), " Requisitioner

  • Item Details

matnr(018), " Material No

menge(017), " Quantity

  • badat(010),

  • frgdt(010),

preis(014), " Valuation Price

  • waers(005), " Currency

  • peinh(005),

  • wepos(001),

  • repos(001),

sakto(010), " GL Account

kostl(010), " Cost Center

  • bnfpo(005),

END OF i_pr.

  • Internal Table for header Data

DATA: BEGIN OF it_header OCCURS 0,

sno(3), " SNo

bsart(004), " PR Type

epstp(001), " Item Category

knttp(001), " Account Assignment

eeind(010), " Delivery Date

werks(004), " Plant

lgort(004), " Storage Location

ekgrp(003), " Purchasing Group

matkl(009), " Material Group

bednr(010), " Tracking No

afnam(012), " Requisitioner

END OF it_header.

  • Internal Table for Item Data

DATA: BEGIN OF it_item OCCURS 0,

sno(3), " SNo

matnr(018), " Material No

menge(017), " Quantity

preis(014), " Valuation Price

sakto(010), " GL Account

kostl(010), " Cost Center

END OF it_item.

  • Data Variables & Constants

CONSTANTS : c_x VALUE 'X'. " Flag

DATA : v_l(2), " Counter

v_rowno(5), " Row No

v_2(2), " Counter

v_rows LIKE sy-srows, " Rows in TC

v_field(45). " String

  • Parameters

PARAMETERS: p_file LIKE ibipparms-path. " Filename

  • At selection-screen on Value Request for file Name

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  • Get the F4 Values for the File

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

IMPORTING

file_name = p_file.

  • Start of Selection

START-OF-SELECTION.

  • Open the BDC Session

PERFORM open_group.

  • Upload the File into internal Table

CALL FUNCTION 'UPLOAD'

EXPORTING

filename = p_file

filetype = 'DAT'

TABLES

data_tab = i_pr

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.

SORT i_pr BY sno.

LOOP AT i_pr.

MOVE-CORRESPONDING i_pr TO it_item.

APPEND it_item.

CLEAR it_item.

AT END OF sno.

READ TABLE i_pr INDEX sy-tabix.

MOVE-CORRESPONDING i_pr TO it_header.

APPEND it_header.

CLEAR it_header.

ENDAT.

ENDLOOP.

SORT it_header BY sno.

SORT it_item BY sno.

v_rows = sy-srows - 6.

  • Upload the Data from Internal Table

LOOP AT it_header.

  • Header Data

PERFORM bdc_dynpro USING 'SAPMM06B' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR'

'EBAN-BEDNR'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'EBAN-BSART'

it_header-bsart.

PERFORM bdc_field USING 'RM06B-EPSTP'

it_header-epstp.

PERFORM bdc_field USING 'EBAN-KNTTP'

it_header-knttp.

PERFORM bdc_field USING 'RM06B-EEIND'

it_header-eeind.

  • PERFORM bdc_field USING 'RM06B-LPEIN'

  • it_header-lpein.

PERFORM bdc_field USING 'EBAN-WERKS'

it_header-werks.

PERFORM bdc_field USING 'EBAN-LGORT'

it_header-lgort.

PERFORM bdc_field USING 'EBAN-EKGRP'

it_header-ekgrp.

PERFORM bdc_field USING 'EBAN-MATKL'

it_header-matkl.

PERFORM bdc_field USING 'EBAN-BEDNR'

it_header-bednr.

PERFORM bdc_field USING 'EBAN-AFNAM'

it_header-afnam.

  • Item Details

v_l = 0.

  • To add no. of rows

v_2 = 0 .

  • As the screen is showing 13 rows defaulted to 130

v_rowno = 130 .

LOOP AT it_item WHERE sno = it_header-sno.

v_l = v_l + 1.

IF v_l = 14 .

IF v_2 = 12 .

v_2 = 12 .

v_l = 2 .

  • From second time onwards it is displaying 12 rows only

v_rowno = v_rowno + 120 .

PERFORM bdc_dynpro USING 'SAPMM06B' '0106'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RM06B-BNFPO'.

PERFORM bdc_field USING 'RM06B-BNFPO'

v_rowno.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

ELSE.

  • V_2 initialized to 12 for second screen purpose

v_2 = 12 .

v_l = 2 .

PERFORM bdc_dynpro USING 'SAPMM06B' '0106'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RM06B-BNFPO'.

PERFORM bdc_field USING 'RM06B-BNFPO'

v_rowno .

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

ENDIF.

ENDIF.

PERFORM bdc_dynpro USING 'SAPMM06B' '0106'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

CLEAR v_field.

CONCATENATE 'EBAN-MATNR(' v_l ')' INTO v_field.

PERFORM bdc_field USING v_field it_item-matnr.

CLEAR v_field.

CONCATENATE 'EBAN-MENGE(' v_l ')' INTO v_field.

PERFORM bdc_field USING v_field it_item-menge.

PERFORM bdc_dynpro USING 'SAPMM06B' '0102'.

PERFORM bdc_field USING 'BDC_CURSOR'

'EBAN-PREIS'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'EBAN-PREIS'

it_item-preis.

PERFORM bdc_dynpro USING 'SAPMM06B' '0505'.

PERFORM bdc_field USING 'BDC_CURSOR'

'EBKN-SAKTO'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTE'.

PERFORM bdc_field USING 'EBKN-SAKTO'

it_item-sakto.

  • Cost Center

PERFORM bdc_dynpro USING 'SAPLKACB' '0002'.

PERFORM bdc_field USING 'BDC_CURSOR'

'COBL-KOSTL'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTE'.

PERFORM bdc_field USING 'COBL-KOSTL'

it_item-kostl.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTE'.

ENDLOOP.

PERFORM bdc_dynpro USING 'SAPMM06B' '0106'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RM06B-BNFPO'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BU'.

  • Call The Transaction

PERFORM bdc_transaction USING 'ME51'.

ENDLOOP.

  • Close the BDC Session

PERFORM close_group.

See the doc

How to deal with table control / step loop in BDC

Steploop and table contol is inevitable in certain transactions. When we run BDC for such transactions, we will face the situation: how many visible lines of steploop/tablecontrol are on the screen? Although we can always find certain method to deal with it, such as function code 'NP', 'POPO', considering some extreme situation: there is only one line visible one the screen, our BDC program should display an error message. (See transaction 'ME21', we you resize your screen to let only one row visible, you can not enter mutiple lines on this screen even you use 'NP')

Now with the help of Poonam on sapfans.com developement forum, I find a method with which we can determine the number of visible lines on Transaction Screen from our Calling BDC program. Maybe it is useless to you, but I think it will give your some idea.

Demo ABAP code has two purposes:

1. how to determine number of visible lines and how to calculte page number;

(the 'calpage' routine has been modify to meet general purpose usage)

2. using field symbol in BDC program, please pay special attention to the difference in Static ASSIGN and Dynamic ASSIGN.

Now I begin to describe the step to implement my method:

(I use transaction 'ME21', screen 121 for sample,

the method using is Call Transation Using..)

Step1: go to screen painter to display the screen 121, then we can count the fixed line on this screen, there is 7 lines above the steploop and 2 lines below the steploop, so there are total 9 fixed lines on this screen. This means except these 9 lines, all the other line is for step loop. Then have a look at steploop itselp, one entry of it will occupy two lines.

(Be careful, for table control, the head and the bottom scroll bar will possess another two fixed lines, and there is a maximum number for table line)

Now we have : FixedLine = 9

LoopLine = 2(for table control, LoopLine is always equal to 1)

Step2: go to transaction itself(ME21) to see how it roll page, in ME21, the first line of new page is always occupied by the last line of last page, so it begin with index '02', but in some other case, fisrt line is empty and ready for input.

Now we have: FirstLine = 0

or FirstLine = 1 ( in our case, FirstLine is 1 because the first line of new page is fulfilled)

Step3: write a subroutine calcalculating number of pages

(here, the name of actual parameter is the same as formal parameter)

global data: FixedLine type i, " number of fixed line on a certain screen

LoopLine type i, " the number of lines occupied by one steploop item

FirstLine type i, " possbile value 0 or 1, 0 stand for the first line of new " scrolling screen is empty, otherwise is 1

Dataline type i, " number of items you will use in BDC, using DESCRIBE to get

pageno type i, " you need to scroll screen how many times.

line type i, " number of lines appears on the screen.

index(2) type N, " the screen index for certain item

begin type i, " from parameter of loop

end type i. " to parameter of loop

*in code sample, the DataTable-linindex stands for the table index number of this line

form calpage using FixedLine type i (see step 1)

LoopLine type i (see step 1)

FirstLine type i (see step 2)

DataLine type i ( this is the item number you will enter in transaction)

changing pageno type i (return the number of page, depends on run-time visible line in table control/ Step Loop)

changing line type i.(visible lines one the screen)

data: midd type i,

vline type i, "visible lines

if DataLine eq 0.

Message eXXX.

endif.

vline = ( sy-srows - FixedLine ) div LoopLine.

*for table control, you should compare vline with maximum line of

*table control, then take the small one that is min(vline, maximum)

*here only illustrate step loop

if FirstLine eq 0.

pageno = DataLine div vline.

if pageno eq 0.

pageno = pageno + 1.

endif.

elseif FirstLine eq 1.

pageno = ( DataLine - 1 ) div ( vline - 1 ) + 1.

midd = ( DataLine - 1 ) mod ( vline - 1).

if midd = 0 and DataLine gt 1.

pageno = pageno - 1.

endif.

endif.

line = vline.

endform.

Step4 write a subroutine to calculate the line index for each item.

form calindex using Line type i (visible lines on the screen)

FirstLine type i(see step 2)

LineIndex type i(item index)

changing Index type n. (index on the screen)

if FirstLine = 0.

index = LineIndex mod Line.

if index = '00'.

index = Line.

endif.

elseif FirstLine = 1.

index = LineIndex mod ( Line - 1 ).

if ( index between 1 and 0 ) and LineIndex gt 1.

index = index + Line - 1.

endif.

if Line = 2.

index = index + Line - 1.

endif.

endif.

endform.

Step5 write a subroutine to calculate the loop range.

form calrange using Line type i ( visible lines on the screen)

DataLine type i

FirstLine type i

loopindex like sy-index

changing begin type i

end type i.

If FirstLine = 0.

if loopindex = 1.

begin = 1.

if DataLine <= Line.

end = DataLine.

else.

end = Line.

endif.

elseif loopindex gt 1.

begin = Line * ( loopindex - 1 ) + 1.

end = Line * loopindex.

if end gt DataLine.

end = DataLine.

endif.

endif.

elseif FirstLine = 1.

if loopindex = 1.

begin = 1.

if DataLine <= Line.

end = DataLine.

else.

end = Line.

endif.

elseif loop index gt 1.

begin = ( Line - 1 ) * ( loopindex - 1 ) + 2.

end = ( Line - 1 ) * ( loopindex - 1 ) + Line.

if end gt DataLine.

end = DataLine.

endif.

endif.

endif.

endform.

Step6 using field sysbol in your BDC, for example: in ME21, but you should calculate each item will correponding to which index in steploop/Table Control

form creat_bdc.

field-symbols: <material>, <quan>, <indicator>.

data: name1(14) value 'EKPO-EMATN(XX)',

name2(14) value 'EKPO-MENGE(XX)',

name3(15) value 'RM06E-SELKZ(XX)'.

assign: name1 to <material>,

name2 to <quan>,

name3 to <indicator>.

.

do pageno times.

if sy-index gt 1

*insert scroll page ok_code"

endif.

.

.

perform calrange using Line DataLine FirstLine sy-index

changing begin end.

.

.

loop at DataTable from begin to end.

perform calindex using Line FirstLine DataTable-LineIndex changing Index.

name1+11(2) = Index.

name2+11(2) = Index.

name3+12(2) = Index.

.

.

perform bdcfield using <material> DataTable-matnr.

perform bdcfield using <quan> DataTable-menge.

perform bdcfield using <indicator> DataTable-indicator.

.

.

.

endloop.

enddo.

Regards

Anji