‎2008 Feb 11 3:20 AM
hi friends ,
in bdc , how can you handle the table controls ???
‎2008 Feb 11 3:26 AM
Hi Deepti,
HI,
Refer the link:
http://www.sap-img.com/abap/bdc-example-using-table-control-in-bdc.htm
The concept is easy: it has to indicate the index of the table control in the field name, so if you have to populate the first record of table control:
BDC-FIELDNAME = <FIELDNAME>(01).
If you fill the second row:
BDC-FIELDNAME = <FIELDNAME>(02).
and so....
Now the problem is usually on how many records you have to load, because u can fill only the rows of table control available in the screen, If you have more records than it can be displayed yuo have to simulate the command to go next page.
The number of recod can be displayed can depend on pc resolution and many program haven't command to go to next page (in this case it could be impossible create a BDC program9.
A way to create a bdc program resolution indipendent is to work on the first and second row.
- Place the first hit in the first row of bdc;
- Place the second insert in the second row of bdc;
- Place the last hit to the top of table control;
- Place the next hit in the second row;
- Place the last hit to the top of table control;
- Place the next hit in the second row;
- .... and so
For more info: Search in SDN with TABLE CONTROL IN BDC.
Will get a lot of related links.
Reward points if this Helps.
Manish
‎2008 Feb 11 6:45 AM
Hai.
check this.
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.
sowjanya.b
‎2008 Feb 11 6:59 AM
hi deepti,
I am sending sample program for XK01 T.code .
i have used all the mandatory fields for header
u copy and paste this program and debugg this program, u will understand.
hope u could develop the flat file as i have used all mandatory fields for header fields.
if u r unable u reply me i will send u flat file also
Reward is useful.
regards
shashikanth naram
REPORT ZNSK_TABLE_CONTROL
NO STANDARD PAGE HEADING LINE-SIZE 255.
&----
*& Structure Declarations
&----
Structure declaration for Header STRUCTURE
TYPES: BEGIN OF TY_HEADER,
LIFNR TYPE LIF16,
BUKRS TYPE BUKRS,
EKORG TYPE EKORG,
KTOKK TYPE KTOKK,
ANRED TYPE ANRED,
NAME1 TYPE NAME1_GP,
SORTL TYPE SORTL,
LAND1 TYPE LAND1_GP,
AKONT TYPE AKONT,
FDGRV TYPE FDGRV,
WAERS TYPE BSTWA,
END OF TY_HEADER,
STRUCTURE DECLARATION FOR ITEM STRUCTURE
BEGIN OF TY_ITEM,
LIFNR TYPE LIF16,
BANKS TYPE BANKS,
BANKL TYPE BANKK,
BANKN TYPE BANKN,
KOINH TYPE KOINH_FI,
END OF TY_ITEM,
STRUCTURE DECLARATION FOR SOURCE STRUCTURE
BEGIN OF TY_UPLOAD,
F1 TYPE CHAR16,
F2 TYPE CHAR4,
F3 TYPE CHAR15,
F4(18) TYPE C,
F5(60) TYPE C,
F6 TYPE CHAR35,
F7 TYPE CHAR10,
F8 TYPE CHAR3,
F9 TYPE CHAR10,
F10 TYPE CHAR10,
F11 TYPE CHAR13,
END OF TY_UPLOAD.
&----
*& Internal table Declarations
&----
INTERNAL TABLE FOR TY_UPLOAD
DATA: T_UPLOAD TYPE STANDARD TABLE OF TY_UPLOAD INITIAL SIZE 0,
INTENAL TABLE FOR TY_HEADER
T_HEADER TYPE STANDARD TABLE OF TY_HEADER INITIAL SIZE 0,
INTERNAL TABLE FOR TY_ITEM
T_ITEM TYPE STANDARD TABLE OF TY_ITEM INITIAL SIZE 0,
INTERNAL TABLE FOR BDCDATA
T_BDCDATA TYPE STANDARD TABLE OF BDCDATA INITIAL SIZE 0,
&----
*& WORK AREA Declarations
&----
WORK AREA FOR SOURCE STRUCTURE
W_UPLOAD TYPE TY_UPLOAD,
WORK AREA FOR HEADER STRUCTURE
W_HEADER TYPE TY_HEADER,
WORK AREA FOR ITEM STRUCTURE
W_ITEM TYPE TY_ITEM,
WORK AREA FOR BDCDATA.
W_BDCDATA TYPE BDCDATA,
ADDITIONAL WORK AREA FOR UPLOAD STRUCTURE
L_UPLOAD TYPE TY_UPLOAD.
&----
*& SELECTION-SCREEN Declarations
&----
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
PARAMETERS: P_FLNAME TYPE FILENAME.
SELECTION-SCREEN END OF BLOCK B1.
START-OF-SELECTION.
UPLOADING THE DATA
PERFORM UPLOAD_DATA.
POPULATING THE BDCDATA TABLE
PERFORM BDC_DATA.
INCLUDE BDCRECX1.
START-OF-SELECTION.
&----
*& Form UPLOAD_DATA
&----
text
----
FORM UPLOAD_DATA .
DATA: L_FLNAME TYPE STRING .
L_FLNAME = P_FLNAME.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = L_FLNAME
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = T_UPLOAD.
LOOP AT T_UPLOAD INTO L_UPLOAD.
W_UPLOAD = L_UPLOAD.
AT NEW F1.
W_HEADER-LIFNR = W_UPLOAD-F1.
W_HEADER-BUKRS = W_UPLOAD-F2.
W_HEADER-EKORG = W_UPLOAD-F3.
W_HEADER-KTOKK = W_UPLOAD-F4.
W_HEADER-ANRED = W_UPLOAD-F5.
W_HEADER-NAME1 = W_UPLOAD-F6.
W_HEADER-SORTL = W_UPLOAD-F7.
W_HEADER-LAND1 = W_UPLOAD-F8.
W_HEADER-AKONT = W_UPLOAD-F9.
W_HEADER-FDGRV = W_UPLOAD-F10.
W_HEADER-WAERS = W_UPLOAD-F11.
APPEND W_HEADER TO T_HEADER.
CLEAR W_UPLOAD.
CONTINUE.
ENDAT.
W_ITEM-LIFNR = W_UPLOAD-F1.
W_ITEM-BANKS = W_UPLOAD-F2.
W_ITEM-BANKL = W_UPLOAD-F3.
W_ITEM-BANKN = W_UPLOAD-F4.
W_ITEM-KOINH = W_UPLOAD-F5.
APPEND W_ITEM TO T_ITEM.
CLEAR W_ITEM.
ENDLOOP.
ENDFORM. " UPLOAD_DATA
&----
*& Form BDC_DATA
&----
text
----
FORM BDC_DATA .
HEADER SCREEN(1)
CLEAR W_HEADER.
LOOP AT T_HEADER INTO W_HEADER.
REFRESH T_BDCDATA.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0100'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RF02K-EKORG'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'RF02K-LIFNR'
W_HEADER-LIFNR.
PERFORM BDC_FIELD USING 'RF02K-BUKRS'
W_HEADER-BUKRS.
PERFORM BDC_FIELD USING 'RF02K-EKORG'
W_HEADER-EKORG.
PERFORM BDC_FIELD USING 'RF02K-KTOKK'
W_HEADER-KTOKK.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0110'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFA1-LAND1'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'LFA1-ANRED'
W_HEADER-ANRED.
PERFORM BDC_FIELD USING 'LFA1-NAME1'
W_HEADER-NAME1.
PERFORM BDC_FIELD USING 'LFA1-SORTL'
W_HEADER-SORTL.
PERFORM BDC_FIELD USING 'LFA1-LAND1'
W_HEADER-LAND1.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0120'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFA1-KUNNR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
ITEM SCREEN
DATA: N TYPE C.
N = 1.
CLEAR W_ITEM.
LOOP AT T_ITEM INTO W_ITEM WHERE LIFNR = W_HEADER-LIFNR.
DATA: L_BANKS TYPE CHAR20,
L_BANKL TYPE CHAR20,
L_BANKN TYPE CHAR20,
L_BANKK TYPE CHAR20.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0130'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFBK-KOINH(03)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=ENTR'.
CONCATENATE 'LFBK-BANKS' '(' '0' N ')' INTO L_BANKS.
PERFORM BDC_FIELD USING L_BANKS
W_ITEM-BANKS.
CONCATENATE 'LFBK-BANKL' '(' '0' N ')' INTO L_BANKL.
PERFORM BDC_FIELD USING L_BANKL
W_ITEM-BANKL.
CONCATENATE 'LFBK-BANKN' '(' '0' N ')' INTO L_BANKN.
PERFORM BDC_FIELD USING L_BANKN
W_ITEM-BANKN.
CONCATENATE 'LFBK-KOINH' '(' '0' N ')' INTO L_BANKK.
PERFORM BDC_FIELD USING L_BANKK
W_ITEM-KOINH.
N = N + 1.
ENDLOOP.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0130'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFBK-BANKS(01)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=ENTR'.
HEADER SCREEN(2).
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0210'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFB1-FDGRV'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'LFB1-AKONT'
W_HEADER-AKONT.
PERFORM BDC_FIELD USING 'LFB1-FDGRV'
W_HEADER-FDGRV.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0215'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFB1-ZTERM'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0220'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFB5-MAHNA'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0310'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFM1-WAERS'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'LFM1-WAERS'
W_HEADER-WAERS.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0320'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RF02K-LIFNR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=ENTR'.
PERFORM BDC_DYNPRO USING 'SAPLSPO1' '0300'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=YES'.
CALL TRANSACTION 'XK01' USING T_BDCDATA MODE 'A'.
ENDLOOP.
ENDFORM. " BDC_DATA
----
Start new screen *
----
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR W_BDCDATA.
W_BDCDATA-PROGRAM = PROGRAM.
W_BDCDATA-DYNPRO = DYNPRO.
W_BDCDATA-DYNBEGIN = 'X'.
APPEND W_BDCDATA TO T_BDCDATA.
ENDFORM. "BDC_DYNPRO
----
Insert field *
----
FORM BDC_FIELD USING FNAM FVAL.
CLEAR W_BDCDATA.
W_BDCDATA-FNAM = FNAM.
W_BDCDATA-FVAL = FVAL.
APPEND W_BDCDATA TO T_BDCDATA.
ENDFORM. "BDC_FIELD
‎2008 Feb 11 7:01 AM
Hi ,
For table control fields use the code:
Loop at itab .
n = n + 1.
Concatenate itab-fnam ( ' n ' ) into fnam1.
perfom bdc using fnam1 fval.
endloop.
Regards
Naveen gupta
PS: Reward Points if Helpfull.