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

table control in BDC

Former Member
0 Likes
1,592

Hi!

Can anybody help me out that what is table control in BDC.

What is the use of it and when do we use BAPI as an alternative

to BDC.I am very new to this concepts.

thanks

Amit

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,524

Hi Amit,

When you are handling data for table control, (For example adding bank details while creating a vendor in XK01), you will do the recording procedure and write the code for it.

While doing the recording procedure, the table displayed in your monitor for entering the bank details (is called as table control), will display a maximum of 5 rows at a time (for example). After entering 5 bank details for a vendor, If you need to add 6th record then you will have to press page down and add 6th record. After recording is done, the code will be generated and the execution will be fine in your system to create any number of vendors with any number of bank details for each vendor.

But while i execute the program in my system, the table control may not display 5 rows at a time. It may display 4 or 7 rows at a time (For example). Because the number of rows displayed in one screen for a table control depends on the Resolution of the monitor which you are using.

So you will have to handle the logic for Page down in the BDC Program, so that while executing the BDC program for migrating data to a transaction (like XK01) which has a table control is executed appropriately regardless of Monitor resolutions.

Any more queries you have, let me know.

Thanks and Regards,

Suresh

10 REPLIES 10
Read only

Former Member
0 Likes
1,524

Hi,

refer this in SDN.

My Home > ABAP Development > FAQ > BDC >table control

Hope this would help.

Read only

Former Member
0 Likes
1,524

Hi,

check this link......it can help u hot...

[bdctable control|https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/sampleBDCforTableControl]

Regards

Kiran

Read only

Former Member
0 Likes
1,525

Hi Amit,

When you are handling data for table control, (For example adding bank details while creating a vendor in XK01), you will do the recording procedure and write the code for it.

While doing the recording procedure, the table displayed in your monitor for entering the bank details (is called as table control), will display a maximum of 5 rows at a time (for example). After entering 5 bank details for a vendor, If you need to add 6th record then you will have to press page down and add 6th record. After recording is done, the code will be generated and the execution will be fine in your system to create any number of vendors with any number of bank details for each vendor.

But while i execute the program in my system, the table control may not display 5 rows at a time. It may display 4 or 7 rows at a time (For example). Because the number of rows displayed in one screen for a table control depends on the Resolution of the monitor which you are using.

So you will have to handle the logic for Page down in the BDC Program, so that while executing the BDC program for migrating data to a transaction (like XK01) which has a table control is executed appropriately regardless of Monitor resolutions.

Any more queries you have, let me know.

Thanks and Regards,

Suresh

Read only

0 Likes
1,524

Hi! Suresh

In connection to my previous question and your reply I would like to

know in case of bank details entry for customer or vendor how do write the

code for handling the table control.

thankx in advance

Amit

Read only

0 Likes
1,524

Hi,

Herewith is a sample program. Please debug it to understand the logic. The Transfer_Data subroutine does the entire process. I have given comments for your better understanding.

report ZSS_BDC_XK01_PDN_PGM

no standard page heading line-size 255.

INCLUDE zss_bdc_xk01_pdn_pgm_decl.

INCLUDE zss_bdc_xk01_pdn_pgm_form.

----


  • At-Selection screen

----


  • For F4 help to get the filename from the Presentation server

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

PERFORM select_file.

----


  • Start of Selection

----


START-OF-SELECTION.

  • To upload data from flat file into internal table

PERFORM upload_file.

  • To create vendor by transferring records to XK01 from flat file

PERFORM transfer_data.

----


  • End of Selection

----


END-OF-SELECTION.

  • To format the messages and display it

PERFORM display_messages.

&----


*& Include ZSS_BDC_XK01_PDN_PGM_DECL

&----


----


  • data definition

----


  • Workarea for processing records from flat file

DATA: BEGIN OF g_r_xk01,

lifnr LIKE rf02k-lifnr,

bukrs LIKE rf02k-bukrs,

ekorg LIKE rf02k-ekorg,

ktokk LIKE rf02k-ktokk,

name1 LIKE lfa1-name1,

sortl LIKE lfa1-sortl,

land1 LIKE lfa1-land1,

spras LIKE lfa1-spras,

banks LIKE lfbk-banks,

bankl LIKE lfbk-bankl,

bankn LIKE lfbk-bankn,

koinh LIKE lfbk-koinh,

waers LIKE lfm1-waers,

END OF g_r_xk01.

  • Table holds the data from flat file

DATA: g_t_xk01 LIKE STANDARD TABLE OF g_r_xk01.

  • Batchinputdata of single transaction

DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.

  • messages of call transaction

DATA: g_t_messages TYPE STANDARD TABLE OF bdcmsgcoll.

  • Workarea for messages of call transaction

DATA: g_r_messages TYPE bdcmsgcoll.

  • Name of flat file

DATA: g_f_filename TYPE string.

  • To write the Message

DATA: g_f_message TYPE string.

  • To count the number of line items

DATA: g_f_count TYPE i.

----


  • Selection screen

----


  • Input field to get the name of flat file

PARAMETERS p_file TYPE rlgrap-filename.

&----


*& Include ZSS_BDC_XK01_PDN_PGM_FORM

&----


&----


*& Form transfer_data

&----


  • To create vendor by transferring records to XK01 from flat file

----


FORM transfer_data.

  • Flag For AT NEW event

DATA l_f_atnew_flag.

  • Flag For AT END event

DATA l_f_atend_flag.

CLEAR g_r_xk01.

LOOP AT g_t_xk01 INTO g_r_xk01.

  • To create a new Vendor

AT NEW ktokk.

g_f_count = 0.

l_f_atnew_flag = 'X'. " Setting the flag when a new vendor number is found

ENDAT.

  • To add the header items to the BDCDATA internal table

IF l_f_atnew_flag = 'X'.

  • Adds the header item

PERFORM start_of_header.

CLEAR l_f_atnew_flag. " Clearing the flag when header is added for a new vendor

ENDIF.

  • Fills the line items for bank detail

PERFORM add_line_items.

  • Checking for the end of a Vendor and sets the flag accordingly

AT END OF ktokk.

l_f_atend_flag = 'X'.

ENDAT.

  • If an end of vendor is found, Creates a New vendor with the details in the BDCDATA internal table

IF l_f_atend_flag = 'X'.

  • Fills the rest of the screen fields after Filling Bank details

PERFORM end_of_header.

  • Calling the transaction XK01 in NO SCREEN mode and in Synchronous mode

CALL TRANSACTION 'XK01' USING bdcdata MODE 'N' UPDATE 'S' MESSAGES INTO g_t_messages.

CLEAR bdcdata.

REFRESH bdcdata.

CLEAR l_f_atend_flag.

ENDIF.

ENDLOOP.

ENDFORM. " transfer_data

----


  • Start new screen *

----


FORM bdc_dynpro USING program dynpro.

CLEAR bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = 'X'.

APPEND bdcdata.

ENDFORM. "BDC_DYNPRO

----


  • Insert field *

----


FORM bdc_field USING fnam fval.

CLEAR bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

APPEND bdcdata.

ENDFORM. "BDC_FIELD

&----


*& Form display_messages

&----


  • To format the messages and display it

----


FORM display_messages .

LOOP AT g_t_messages INTO g_r_messages.

  • To format the message string and to display it

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = g_r_messages-msgid

lang = sy-langu

no = g_r_messages-msgnr

v1 = g_r_messages-msgv1

v2 = g_r_messages-msgv2

v3 = g_r_messages-msgv3

v4 = g_r_messages-msgv4

IMPORTING

msg = g_f_message

  • EXCEPTIONS

  • NOT_FOUND = 1

  • OTHERS = 2

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

  • To display the messages in appropriate color

IF g_r_messages-msgtyp = 'E'.

WRITE: / g_f_message COLOR 6 INVERSE ON. " Error messages are displayed in Red color

ELSE.

WRITE: / g_f_message COLOR 5 INVERSE ON. " Success messages are displayed in Green color

ENDIF.

ENDLOOP.

ENDFORM. " display_messages

&----


*& Form start_of_header

&----


  • Adds the header item to BDCDATA internal table

----


FORM start_of_header .

PERFORM bdc_dynpro USING 'SAPMF02K' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RF02K-KTOKK'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

  • Fills vendor code

PERFORM bdc_field USING 'RF02K-LIFNR'

g_r_xk01-lifnr.

  • Fills Company code

PERFORM bdc_field USING 'RF02K-BUKRS'

g_r_xk01-bukrs.

  • Fills Purchasing organisation

PERFORM bdc_field USING 'RF02K-EKORG'

g_r_xk01-ekorg.

  • Fills account group

PERFORM bdc_field USING 'RF02K-KTOKK'

g_r_xk01-ktokk.

PERFORM bdc_dynpro USING 'SAPMF02K' '0110'.

PERFORM bdc_field USING 'BDC_CURSOR'

'LFA1-SPRAS'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

  • Fills the name of the vendor

PERFORM bdc_field USING 'LFA1-NAME1'

g_r_xk01-name1.

  • Fills the search term

PERFORM bdc_field USING 'LFA1-SORTL'

g_r_xk01-sortl.

  • Fills the Country

PERFORM bdc_field USING 'LFA1-LAND1'

g_r_xk01-land1.

  • Fills the language field

PERFORM bdc_field USING 'LFA1-SPRAS'

g_r_xk01-spras.

PERFORM bdc_dynpro USING 'SAPMF02K' '0120'.

PERFORM bdc_field USING 'BDC_CURSOR'

'LFA1-KUNNR'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

ENDFORM. " start_of_header

&----


*& Form add_line_items

&----


  • Fills the line items for bank detail

----


FORM add_line_items.

  • To pass the field name to the bdc_field subroutine, for Every fields of bank details

DATA l_f_fnam TYPE fnam_____4.

DATA l_f_count_value.

  • Setting the index of the count

g_f_count = g_f_count + 1.

  • Page down after every 5 line items (According to my monitor resolution)

IF g_f_count > 5.

PERFORM bdc_dynpro USING 'SAPMF02K' '0130'.

PERFORM bdc_field USING 'BDC_CURSOR'

'LFBK-BANKS(01)'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=P+'.

g_f_count = 1.

ENDIF.

MOVE g_f_count TO l_f_count_value.

  • Finds the dynpro

PERFORM bdc_dynpro USING 'SAPMF02K' '0130'.

CLEAR l_f_fnam.

CONCATENATE 'LFBK-KOINH(0' l_f_count_value ')' INTO l_f_fnam.

PERFORM bdc_field USING 'BDC_CURSOR'

l_f_fnam.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTR'.

  • Fills the Bank country key

CLEAR l_f_fnam.

CONCATENATE 'LFBK-BANKS(0' l_f_count_value ')' INTO l_f_fnam.

PERFORM bdc_field USING l_f_fnam

g_r_xk01-banks.

  • Fills the Bank key

CLEAR l_f_fnam.

CONCATENATE 'LFBK-BANKL(0' l_f_count_value ')' INTO l_f_fnam.

PERFORM bdc_field USING l_f_fnam

g_r_xk01-bankl.

  • Fills the Bank Account number

CLEAR l_f_fnam.

CONCATENATE 'LFBK-BANKN(0' l_f_count_value ')' INTO l_f_fnam.

PERFORM bdc_field USING l_f_fnam

g_r_xk01-bankn.

  • Fills the Account holder name

CLEAR l_f_fnam.

CONCATENATE 'LFBK-KOINH(0' l_f_count_value ')' INTO l_f_fnam.

PERFORM bdc_field USING l_f_fnam

g_r_xk01-koinh.

ENDFORM. " add_line_items

&----


*& Form end_of_header

&----


  • Fills the rest of the screen fields after Filling Bank details

----


FORM end_of_header .

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' '0380'.

PERFORM bdc_field USING 'BDC_CURSOR'

'KNVK-NAMEV(01)'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTR'.

PERFORM bdc_dynpro USING 'SAPMF02K' '0210'.

PERFORM bdc_field USING 'BDC_CURSOR'

'LFB1-AKONT'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

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

  • Fills the order currency field

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'

g_r_xk01-waers.

PERFORM bdc_dynpro USING 'SAPMF02K' '0320'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RF02K-LIFNR'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTR'.

ENDFORM. " end_of_header

For any more queries, Please feel free to ask me.

Best Regards,

Suresh

Read only

Former Member
0 Likes
1,524

Hi,

the BAPI and BDC are actually meant for different pruposes.

BAPI are developed for webservices in which the calling

application can directly call the BAPI and carry out the

required operations, where as in BDC we have to write a

code and then we need to get the data in SAP system in a

perticular format and validate the same and then carry out

the updation or other operations, in case of BAPI is a

business object repository object which can be called from

any application. where as for BDC program we need to get

the input file and execute it manually or as a batch job.

Many of us face probelms in upgradation projects for BDC

programs as the screen sequance of some other settings gets

changed so we need to redo the coding(recording) of BDC and

for some transactions its not possible to record as well

such a enjoy transactions, in these cases BAPI is a very

good and proper alternative.

THIS LINK IS 'using control BDC'

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

Thanks,

Neelima.

Read only

Former Member
0 Likes
1,524

hi,

refer the given below link

https://wiki.sdn.sap.com/wiki/display/ABAP/bdcontable+control

Thanks

Arun

Read only

Former Member
0 Likes
1,524

Hi,

Check the below Thread

https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/sampleBDCforTableControl

Hope this helps you.

Regards,

Anki Reddy

Read only

Former Member
0 Likes
1,524

Hi Amit,

After recording identify the screen elements for the table control,

and for each header you loop at the item level and place the part which is invloved

in table control inside the loop.

Regards,

Manoj Kumar P

Read only

Former Member
0 Likes
1,524

Hi Amit,

Please attach the following codes also:

&----


*& Form select_file

&----


  • To select the name of flat file from Presentation server

----


FORM select_file .

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

program_name = syst-repid

dynpro_number = syst-dynnr

field_name = ' '

static = ' '

mask = ' '

CHANGING

file_name = p_file

EXCEPTIONS

mask_too_long = 1

OTHERS = 2.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " select_file

&----


*& Form upload_file

&----


  • To upload data from flat file into internal table

----


FORM upload_file .

g_f_filename = p_file.

  • To load the file from the presentation server to the internal table

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = g_f_filename

filetype = 'ASC'

has_field_separator = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • VIRUS_SCAN_PROFILE =

  • NO_AUTH_CHECK = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

data_tab = g_t_xk01

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

ENDFORM. " upload_file

The flat file (Input file saved in your desktop with .TXT format) for giving as input in Selection screen.

Example:

( all input data seperated by a TAB )

SS19 IN01 0001 0001 Suresh SS19 IN EN AT 10010 123455167 Sundar INR

SS19 IN01 0001 0001 Suresh SS19 IN EN AT 12345 123455267 Suresh INR

SS19 IN01 0001 0001 Suresh SS19 AU EN AT 10010 123455367 Pandian INR

SS19 IN01 0001 0001 Suresh SS19 IN EN AT 10010 123455467 Sundar INR

SS19 IN01 0001 0001 Suresh SS19 IN EN AT 12345 123455567 Suresh INR

SS19 IN01 0001 0001 Suresh SS19 AU EN AT 10010 123455667 Pandian INR

SS20 IN01 0001 0001 Suresh SS20 AT EN AT 10010 123455167 Sundar INR

SS10 IN01 0001 0001 Suresh SS10 AT EN AT 12345 123455267 Suresh INR

SS10 IN01 0001 0001 Suresh SS10 AT EN AT 10010 123455167 Sundar INR

Best Regards,

Suresh