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's

Former Member
0 Kudos

Hi genius,

how to handle the table control (not the screen elements) in BDC.

Thanks in advance

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi,

check this one

REPORT ZCALL_TRANS_TAB1 .

TABLES: LFA1,LFBK,lfb1.

data: BEGIN OF it_vendor occurs 0,

LIFNR LIKE LFA1-LIFNR,

bukrs like lfb1-bukrs,

END OF it_vendor.

DATA: BEGIN OF IT_BANK occurs 0,

LIFNR LIKE LFA1-LIFNR,

BANKS LIKE LFBK-BANKS,

BANKL LIKE LFBK-BANKL,

BANKN LIKE LFBK-BANKN,

koinh like lfbk-koinh,

END OF IT_BANK.

data: it_bdcdata like bdcdata occurs 0 with header line.

data: it_messages like bdcmsgcoll occurs 0 with header line.

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

*selection screen.

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

selection-screen: begin of block b1 with frame.

parameters: p_file like rlgrap-filename default 'c:/vendor.txt'

obligatory.

parameters: p_file1 like rlgrap-filename default 'c:/xyz.txt'

obligatory.

selection-screen: end of block b1.

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

*at selection screen.

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

at selection-screen on value-request for p_file.

perform f4_help using p_file.

at selection-screen on value-request for p_file1.

perform f4_help1 using p_file1.

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

*start of selection

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

start-of-selection.

*******uploading file

perform upload_file using p_file P_FILE1.

******open session.

perform populate_data.

&----


*& Form f4_help

&----


form f4_help using p_p_file.

data: l_file type ibipparms-path.

call function 'F4_FILENAME'

importing

file_name = l_file.

p_file = l_file.

endform. " f4_help

&----


*& Form POPULATE_DATA

&----


form populate_data .

DATA: L_STRING TYPE STRing.

DATA: L_COUNTER(2) TYPE n.

loop at it_vendor.

perform bdc_dynpro using 'SAPMF02K' '0106'.

perform bdc_field using 'BDC_CURSOR'

'RF02K-D0130'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RF02K-LIFNR'

it_vendor-lifnr.

perform bdc_field using 'RF02K-BUKRS'

it_vendor-bukrs.

perform bdc_field using 'RF02K-D0130'

'X'.

perform bdc_dynpro using 'SAPMF02K' '0130'.

perform bdc_field using 'BDC_CURSOR'

'LFBK-bankn(03)'.

perform bdc_field using 'BDC_OKCODE'

'=UPDA'.

*********bank details

CLEAR l_COUNTER.

LOOP AT IT_BANK WHERE LIFNR = IT_VENDOR-LIFNR.

l_COUNTER = l_COUNTER + 1.

clear l_string.

CONCATENATE 'lfbk-banks(' l_counter ')' into l_string.

perform bdc_field using l_string

it_bank-banks.

clear l_string.

CONCATENATE 'lfbk-bankl(' l_counter ')' into l_string.

perform bdc_field using l_string

it_bank-bankl.

clear l_string.

CONCATENATE 'lfbk-bankn(' l_counter ')' into l_string.

perform bdc_field using l_string

it_bank-bankn.

endloop.

******CALL TRANSACTION.

call transaction 'FK02' using it_bdcdata mode 'A'

messages into it_messages.

write:/ sy-subrc.

perform format_messages.

clear it_bdcdata.

refresh it_bdcdata.

endloop.

endform. " POPULATE_DATA

&----


*& Form FORMAT_MESSAGES

&----


form format_messages .

data: l_msg(100).

loop at it_messages.

call function 'FORMAT_MESSAGE'

exporting

id = it_messages-msgid

lang = sy-langu

no = it_messages-msgnr

v1 = it_messages-msgv1

v2 = it_messages-msgv2

v3 = it_messages-msgv3

v4 = it_messages-msgv4

importing

msg = l_msg

exceptions

not_found = 1

others = 2

.

write:/ l_msg.

endloop.

endform. " FORMAT_MESSAGES

&----


*& Form bdc_dynpro

&----


form bdc_dynpro using value(p_program)

value(p_screen).

it_bdcdata-program = p_program.

it_bdcdata-dynpro = p_screen.

it_bdcdata-dynbegin = 'X'.

append it_bdcdata.

clear it_bdcdata.

endform. " bdc_dynpro

&----


*& Form bdc_field

&----


form bdc_field using value(p_fnam)

value(p_fval).

it_bdcdata-fnam = p_fnam.

it_bdcdata-fval = p_fval.

append it_bdcdata.

clear it_bdcdata.

endform. " bdc_field

&----


*& Form upload_file

&----


form upload_file using p_p_file

p_p_file1.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

  • CODEPAGE = ' '

FILENAME = P_P_FILE

FILETYPE = 'DAT'

  • HEADLEN = ' '

  • LINE_EXIT = ' '

  • TRUNCLEN = ' '

  • USER_FORM = ' '

  • USER_PROG = ' '

  • DAT_D_FORMAT = ' '

  • IMPORTING

  • FILELENGTH =

TABLES

data_tab = IT_VENDOR

  • EXCEPTIONS

  • CONVERSION_ERROR = 1

  • FILE_OPEN_ERROR = 2

  • FILE_READ_ERROR = 3

  • INVALID_TYPE = 4

  • NO_BATCH = 5

  • UNKNOWN_ERROR = 6

  • INVALID_TABLE_WIDTH = 7

  • GUI_REFUSE_FILETRANSFER = 8

  • CUSTOMER_ERROR = 9

  • NO_AUTHORITY = 10

  • OTHERS = 11

.

IF sy-subrc <> 0.

MESSAGE I000(ZZ) WITH 'UNABLE TO UPLOAD'.

STOP.

ENDIF.

*******UPLOADING BANK DETAILS

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

  • CODEPAGE = ' '

FILENAME = P_P_FILE1

FILETYPE = 'DAT'

  • HEADLEN = ' '

  • LINE_EXIT = ' '

  • TRUNCLEN = ' '

  • USER_FORM = ' '

  • USER_PROG = ' '

  • DAT_D_FORMAT = ' '

  • IMPORTING

  • FILELENGTH =

TABLES

data_tab = IT_BANK

EXCEPTIONS

CONVERSION_ERROR = 1

FILE_OPEN_ERROR = 2

FILE_READ_ERROR = 3

INVALID_TYPE = 4

NO_BATCH = 5

UNKNOWN_ERROR = 6

INVALID_TABLE_WIDTH = 7

GUI_REFUSE_FILETRANSFER = 8

CUSTOMER_ERROR = 9

NO_AUTHORITY = 10

OTHERS = 11

.

IF sy-subrc <> 0.

MESSAGE I000(ZZ) WITH 'UNABLE TO UPLOAD'.

STOP.

ENDIF.

endform. " upload_file

&----


*& Form f4_help1

  • -->P_P_FILE1 text

----


form f4_help1 using p_p_file1.

data:l_file1 type ibipparms-path.

CALL FUNCTION 'F4_FILENAME'

IMPORTING

FILE_NAME = l_file1.

p_file1 = l_file1.

endform. " f4_help1

http://sap-img.com/abap/bdc-example-using-table-control-in-bdc.htm

Regards,

Sankar

3 REPLIES 3

Former Member
0 Kudos

hi,

check this one

REPORT ZCALL_TRANS_TAB1 .

TABLES: LFA1,LFBK,lfb1.

data: BEGIN OF it_vendor occurs 0,

LIFNR LIKE LFA1-LIFNR,

bukrs like lfb1-bukrs,

END OF it_vendor.

DATA: BEGIN OF IT_BANK occurs 0,

LIFNR LIKE LFA1-LIFNR,

BANKS LIKE LFBK-BANKS,

BANKL LIKE LFBK-BANKL,

BANKN LIKE LFBK-BANKN,

koinh like lfbk-koinh,

END OF IT_BANK.

data: it_bdcdata like bdcdata occurs 0 with header line.

data: it_messages like bdcmsgcoll occurs 0 with header line.

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

*selection screen.

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

selection-screen: begin of block b1 with frame.

parameters: p_file like rlgrap-filename default 'c:/vendor.txt'

obligatory.

parameters: p_file1 like rlgrap-filename default 'c:/xyz.txt'

obligatory.

selection-screen: end of block b1.

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

*at selection screen.

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

at selection-screen on value-request for p_file.

perform f4_help using p_file.

at selection-screen on value-request for p_file1.

perform f4_help1 using p_file1.

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

*start of selection

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

start-of-selection.

*******uploading file

perform upload_file using p_file P_FILE1.

******open session.

perform populate_data.

&----


*& Form f4_help

&----


form f4_help using p_p_file.

data: l_file type ibipparms-path.

call function 'F4_FILENAME'

importing

file_name = l_file.

p_file = l_file.

endform. " f4_help

&----


*& Form POPULATE_DATA

&----


form populate_data .

DATA: L_STRING TYPE STRing.

DATA: L_COUNTER(2) TYPE n.

loop at it_vendor.

perform bdc_dynpro using 'SAPMF02K' '0106'.

perform bdc_field using 'BDC_CURSOR'

'RF02K-D0130'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RF02K-LIFNR'

it_vendor-lifnr.

perform bdc_field using 'RF02K-BUKRS'

it_vendor-bukrs.

perform bdc_field using 'RF02K-D0130'

'X'.

perform bdc_dynpro using 'SAPMF02K' '0130'.

perform bdc_field using 'BDC_CURSOR'

'LFBK-bankn(03)'.

perform bdc_field using 'BDC_OKCODE'

'=UPDA'.

*********bank details

CLEAR l_COUNTER.

LOOP AT IT_BANK WHERE LIFNR = IT_VENDOR-LIFNR.

l_COUNTER = l_COUNTER + 1.

clear l_string.

CONCATENATE 'lfbk-banks(' l_counter ')' into l_string.

perform bdc_field using l_string

it_bank-banks.

clear l_string.

CONCATENATE 'lfbk-bankl(' l_counter ')' into l_string.

perform bdc_field using l_string

it_bank-bankl.

clear l_string.

CONCATENATE 'lfbk-bankn(' l_counter ')' into l_string.

perform bdc_field using l_string

it_bank-bankn.

endloop.

******CALL TRANSACTION.

call transaction 'FK02' using it_bdcdata mode 'A'

messages into it_messages.

write:/ sy-subrc.

perform format_messages.

clear it_bdcdata.

refresh it_bdcdata.

endloop.

endform. " POPULATE_DATA

&----


*& Form FORMAT_MESSAGES

&----


form format_messages .

data: l_msg(100).

loop at it_messages.

call function 'FORMAT_MESSAGE'

exporting

id = it_messages-msgid

lang = sy-langu

no = it_messages-msgnr

v1 = it_messages-msgv1

v2 = it_messages-msgv2

v3 = it_messages-msgv3

v4 = it_messages-msgv4

importing

msg = l_msg

exceptions

not_found = 1

others = 2

.

write:/ l_msg.

endloop.

endform. " FORMAT_MESSAGES

&----


*& Form bdc_dynpro

&----


form bdc_dynpro using value(p_program)

value(p_screen).

it_bdcdata-program = p_program.

it_bdcdata-dynpro = p_screen.

it_bdcdata-dynbegin = 'X'.

append it_bdcdata.

clear it_bdcdata.

endform. " bdc_dynpro

&----


*& Form bdc_field

&----


form bdc_field using value(p_fnam)

value(p_fval).

it_bdcdata-fnam = p_fnam.

it_bdcdata-fval = p_fval.

append it_bdcdata.

clear it_bdcdata.

endform. " bdc_field

&----


*& Form upload_file

&----


form upload_file using p_p_file

p_p_file1.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

  • CODEPAGE = ' '

FILENAME = P_P_FILE

FILETYPE = 'DAT'

  • HEADLEN = ' '

  • LINE_EXIT = ' '

  • TRUNCLEN = ' '

  • USER_FORM = ' '

  • USER_PROG = ' '

  • DAT_D_FORMAT = ' '

  • IMPORTING

  • FILELENGTH =

TABLES

data_tab = IT_VENDOR

  • EXCEPTIONS

  • CONVERSION_ERROR = 1

  • FILE_OPEN_ERROR = 2

  • FILE_READ_ERROR = 3

  • INVALID_TYPE = 4

  • NO_BATCH = 5

  • UNKNOWN_ERROR = 6

  • INVALID_TABLE_WIDTH = 7

  • GUI_REFUSE_FILETRANSFER = 8

  • CUSTOMER_ERROR = 9

  • NO_AUTHORITY = 10

  • OTHERS = 11

.

IF sy-subrc <> 0.

MESSAGE I000(ZZ) WITH 'UNABLE TO UPLOAD'.

STOP.

ENDIF.

*******UPLOADING BANK DETAILS

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

  • CODEPAGE = ' '

FILENAME = P_P_FILE1

FILETYPE = 'DAT'

  • HEADLEN = ' '

  • LINE_EXIT = ' '

  • TRUNCLEN = ' '

  • USER_FORM = ' '

  • USER_PROG = ' '

  • DAT_D_FORMAT = ' '

  • IMPORTING

  • FILELENGTH =

TABLES

data_tab = IT_BANK

EXCEPTIONS

CONVERSION_ERROR = 1

FILE_OPEN_ERROR = 2

FILE_READ_ERROR = 3

INVALID_TYPE = 4

NO_BATCH = 5

UNKNOWN_ERROR = 6

INVALID_TABLE_WIDTH = 7

GUI_REFUSE_FILETRANSFER = 8

CUSTOMER_ERROR = 9

NO_AUTHORITY = 10

OTHERS = 11

.

IF sy-subrc <> 0.

MESSAGE I000(ZZ) WITH 'UNABLE TO UPLOAD'.

STOP.

ENDIF.

endform. " upload_file

&----


*& Form f4_help1

  • -->P_P_FILE1 text

----


form f4_help1 using p_p_file1.

data:l_file1 type ibipparms-path.

CALL FUNCTION 'F4_FILENAME'

IMPORTING

FILE_NAME = l_file1.

p_file1 = l_file1.

endform. " f4_help1

http://sap-img.com/abap/bdc-example-using-table-control-in-bdc.htm

Regards,

Sankar

Former Member
0 Kudos

suppsoe u will have to solve this during recording only. during recording do the following steps:

1. use the POSITION button below the table control

2. then select the row u wnt to

3. then press the TICK Buttons or Press Enter

4. and now finally press the button of action which u wnted to perform in the transaction

Former Member
0 Kudos

Create Table Control

• Step 1 (Create new structure for table control)

Type is name of structure (ZTC_EKKO) and press create

• Step 2 (Create Program)

Goto transaction SE80(Object Navigator) -> Repository Browser -> Program.

Enter your program name, please ensure that is begins with SAPMZ…… as this is a module pool (dialog program).

Press enter to create, and press yes!

Ensure that you create a top include, and press Enter.

Accept the name created for the top include.

Press Enter.

Press Save

• Step 3 (Create TOP include)

Double click on the top include and enter following ABAP code:

Tables: ZTC_EKKO.

controls: tc100 type tableview using screen 100.

data: ok_code type sy-ucomm.

data: it_ekko type standard

table of ZTC_EKKO initial size 0,

wa_ekko type ZTC_EKKO.

data: ok_code type sy-ucomm.

Press Save and Activate

• Step 4 (Create screen)

Right click the program to create a screen 100 for the dialog. Enter Short description, set screen type to Normal and enter 0 or blank into Next screen. Then move to Element List tab and enter the OK code as OK_CODE (i.e. the same as what you declared in the top include with data: ok_code type sy-ucomm).

• Step 5 (Create table control)

Press the Layout button to bring up the screen painter editor.

Press table control button and drag it on to the screen, enter the name of table control created in TOP include (TC100). Now press the yellow button for attributes and set the table control as below options

• Step 6 (Populate table control )

Press the orange button (Fields). On the next screen enter ZTC_EKKO and press the ‘Get from Dict’ button. Select the fields you want (all) and press enter. Now drag them onto your Table Control.

Below is the result, there will been syntax errors if we check now! So Save and go back into the flow logic tab.

• Step 7 (Create flow control )

Within the flow logic of screen 100 and create two modules, one to select the data from the database and the other to move the selected fields into the table control. Also insert the two loop statements to populate and retrieve the lines of the table control.

PROCESS BEFORE OUTPUT.

  • MODULE STATUS_0100.

module data_retrieval.

loop at it_ekko into wa_ekko with control TC100.

module populate_screen.

endloop.

*

PROCESS AFTER INPUT.

loop at it_ekko.

endloop.

  • MODULE USER_COMMAND_0100.

Double click the module data_retrieval to create and click yes to get past the popup. Ensure that a new include is created to hold all the PBO modules (default). Press enter.

Select 10 rows of data from the EKKO table and load into the internal table it_ekko. Go back to the flow logic to load this data into the Table Control.

sample code of handling table control in BDC.

REPORT Y730_BDC5 .

*HANDLING TABLE CONTROL IN BDC

DATA : BEGIN OF IT_DUMMY OCCURS 0,

DUMMY(100) TYPE C,

END OF IT_DUMMY.

DATA : BEGIN OF IT_XK01 OCCURS 0,

LIFNR(10) TYPE C,

BUKRS(4) TYPE C,

EKORG(4) TYPE C,

KTOKK(4) TYPE C,

NAME1(30) TYPE C,

SORTL(10) TYPE C,

LAND1(3) TYPE C,

SPRAS(2) TYPE C,

AKONT(6) TYPE C,

FDGRV(2) TYPE C,

WAERS(3) TYPE C,

END OF IT_XK01,

BEGIN OF IT_BANK OCCURS 0,

BANKS(3) TYPE C,

BANKL(10) TYPE C,

BANKN(10) TYPE C,

KOINH(30) TYPE C,

LIFNR(10) TYPE C,

END OF IT_BANK.

DATA : IT_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE,

IT_BDCMSGCOLL LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

FILENAME = 'C:\VENDOR.TXT'

FILETYPE = 'ASC'

TABLES

DATA_TAB = IT_DUMMY.

LOOP AT IT_DUMMY.

IF IT_DUMMY-DUMMY+0(2) = '11'.

IT_XK01-LIFNR = IT_DUMMY-DUMMY+2(10).

IT_XK01-BUKRS = IT_DUMMY-DUMMY+12(4).

IT_XK01-EKORG = IT_DUMMY-DUMMY+16(4).

IT_XK01-KTOKK = IT_DUMMY-DUMMY+20(4).

IT_XK01-NAME1 = IT_DUMMY-DUMMY+24(30).

IT_XK01-SORTL = IT_DUMMY-DUMMY+54(10).

IT_XK01-LAND1 = IT_DUMMY-DUMMY+64(3).

IT_XK01-SPRAS = IT_DUMMY-DUMMY+67(2).

IT_XK01-AKONT = IT_DUMMY-DUMMY+69(6).

IT_XK01-FDGRV = IT_DUMMY-DUMMY+75(2).

IT_XK01-WAERS = IT_DUMMY-DUMMY+77(3).

APPEND IT_XK01.

ELSE.

IT_BANK-BANKS = IT_DUMMY-DUMMY+2(3).

IT_BANK-BANKL = IT_DUMMY-DUMMY+5(10).

IT_BANK-BANKN = IT_DUMMY-DUMMY+15(10).

IT_BANK-KOINH = IT_DUMMY-DUMMY+25(30).

IT_BANK-LIFNR = IT_DUMMY-DUMMY+55(10).

APPEND IT_BANK.

ENDIF.

ENDLOOP.

LOOP AT IT_XK01.

REFRESH IT_BDCDATA.

perform bdc_dynpro using 'SAPMF02K' '0100'.

perform bdc_field using 'BDC_CURSOR'

'RF02K-REF_LIFNR'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RF02K-LIFNR'

IT_XK01-LIFNR.

perform bdc_field using 'RF02K-BUKRS'

IT_XK01-BUKRS.

perform bdc_field using 'RF02K-EKORG'

IT_XK01-EKORG.

perform bdc_field using 'RF02K-KTOKK'

IT_XK01-KTOKK.

perform bdc_dynpro using 'SAPMF02K' '0110'.

perform bdc_field using 'BDC_CURSOR'

'LFA1-TELX1'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'LFA1-NAME1'

IT_XK01-NAME1.

perform bdc_field using 'LFA1-SORTL'

IT_XK01-SORTL.

perform bdc_field using 'LFA1-LAND1'

IT_XK01-LAND1.

perform bdc_field using 'LFA1-SPRAS'

IT_XK01-SPRAS.

perform bdc_dynpro using 'SAPMF02K' '0120'.

perform bdc_field using 'BDC_CURSOR'

'LFA1-KUNNR'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_dynpro using 'SAPMF02K' '0130'.

perform bdc_field using 'BDC_CURSOR'

'LFBK-KOINH(02)'.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

DATA : FNAM(20) TYPE C,

IDX TYPE C.

MOVE 1 TO IDX.

LOOP AT IT_BANK WHERE LIFNR = IT_XK01-LIFNR.

CONCATENATE 'LFBK-BANKS(' IDX ')' INTO FNAM.

perform bdc_field using FNAM

IT_BANK-BANKS.

CONCATENATE 'LFBK-BANKL(' IDX ')' INTO FNAM.

perform bdc_field using FNAM

IT_BANK-BANKL.

CONCATENATE 'LFBK-BANKN(' IDX ')' INTO FNAM.

perform bdc_field using FNAM

IT_BANK-BANKN.

CONCATENATE 'LFBK-KOINH(' IDX ')' INTO FNAM.

perform bdc_field using FNAM

IT_BANK-KOINH.

IDX = IDX + 1.

ENDLOOP.

perform bdc_dynpro using 'SAPMF02K' '0130'.

perform bdc_field using 'BDC_CURSOR'

'LFBK-BANKS(01)'.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

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'

IT_XK01-AKONT.

perform bdc_field using 'LFB1-FDGRV'

IT_XK01-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'

IT_XK01-WAERS.

perform bdc_dynpro using 'SAPMF02K' '0320'.

perform bdc_field using 'BDC_CURSOR'

'WYT3-PARVW(01)'.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

perform bdc_dynpro using 'SAPLSPO1' '0300'.

perform bdc_field using 'BDC_OKCODE'

'=YES'.

CALL TRANSACTION 'XK01' USING IT_BDCDATA

MODE 'A'

UPDATE 'S'

MESSAGES INTO IT_BDCMSGCOLL.

ENDLOOP.

FORM BDC_DYNPRO USING PROG SCR.

CLEAR IT_BDCDATA.

IT_BDCDATA-PROGRAM = PROG.

IT_BDCDATA-DYNPRO = SCR.

IT_BDCDATA-DYNBEGIN = 'X'.

APPEND IT_BDCDATA.

ENDFORM.

FORM BDC_FIELD USING FNAM FVAL.

CLEAR IT_BDCDATA.

IT_BDCDATA-FNAM = FNAM.

IT_BDCDATA-FVAL = FVAL.

APPEND IT_BDCDATA.

ENDFORM.

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, 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.

<b>

also do refer

regards,

srinivas

<b>*reward for useful answers*</b>