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: 

Hi abapers how to handle table control in bdc

Former Member
0 Kudos

hi experts please guide me

how to handle table control in bdc? could u please explain me briefly

thanks and regards

5 REPLIES 5

ferry_lianto
Active Contributor
0 Kudos

Hi,

Please check this link.

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

Regards,

Ferry Lianto

Former Member
0 Kudos

sayeed,

Go thru this code it may help you. check bold code for the table control..

report zsunil_bdc

no standard page heading line-size 255.

----


  • INTERNAL TABLES *

----


DATA: BEGIN OF IT_KNA1 OCCURS 0,

CUSTOMER LIKE RF02D-KUNNR,

COMPANY_CODE LIKE RF02D-BUKRS,

ACCOUNT_GROUP LIKE RF02D-KTOKD,

TITLE LIKE KNA1-ANRED,

NAME LIKE KNA1-NAME1,

SEARCH_TERM LIKE KNA1-SORTL,

STREET LIKE KNA1-STRAS,

CITY LIKE KNA1-ORT01,

POSTAL_CODE LIKE KNA1-PSTLZ,

COUNTRY LIKE KNA1-LAND1,

LANGUAGE_KEY LIKE KNA1-SPRAS,

CNTRY LIKE KNBK-BANKS,

BANK_KEY LIKE KNBK-BANKL,

BANK_ACCOUNT LIKE KNBK-BANKN,

REC_ACCOUNT LIKE KNB1-AKONT,

END OF IT_KNA1.

DATA: IT_BDCDATA TYPE BDCDATA OCCURS 0 WITH HEADER LINE.

DATA: IT_MESSAGES TYPE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

----


  • SELECTION SCREEN *

----


SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

PARAMETER P_FILE TYPE RLGRAP-FILENAME DEFAULT 'C:\CUSTOMER.TXT'

OBLIGATORY.

SELECTION-SCREEN END OF BLOCK B1.

----


  • AT SELECTION SCREEN *

----


AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

PERFORM HELP_FILE USING P_FILE.

----


  • START OF SELECTION *

----


START-OF-SELECTION.

*UPLOADING THE FILE FROM WORKSTATION

PERFORM UPLOAD_FILE USING P_FILE.

*POPULATING DATA.

PERFORM POPULATE_FILE.

&----


*& Form HELP_FILE

&----


  • text

----


  • -->P_P_FILE text

----


form HELP_FILE using p_p_file.

DATA: L_FILE TYPE IBIPPARMS-PATH.

CALL FUNCTION 'F4_FILENAME'

  • EXPORTING

  • PROGRAM_NAME = SYST-CPROG

  • DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

IMPORTING

FILE_NAME = L_FILE.

P_P_FILE = L_FILE.

endform. " HELP_FILE

&----


*& Form UPLOAD_FILE

&----


  • text

----


  • -->P_P_FILE text

----


form UPLOAD_FILE using p_p_file.

CALL FUNCTION 'UPLOAD'

EXPORTING

  • CODEPAGE = ' '

  • FILENAME = 'P_P_FILE'

FILETYPE = 'DAT'

  • ITEM = ' '

  • FILEMASK_MASK = ' '

  • FILEMASK_TEXT = ' '

  • FILETYPE_NO_CHANGE = ' '

  • FILEMASK_ALL = ' '

  • FILETYPE_NO_SHOW = ' '

  • LINE_EXIT = ' '

  • USER_FORM = ' '

  • USER_PROG = ' '

  • SILENT = 'S'

  • IMPORTING

  • FILESIZE =

  • CANCEL =

  • ACT_FILENAME =

  • ACT_FILETYPE =

TABLES

data_tab = IT_KNA1

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.

endform. " UPLOAD_FILE

&----


*& Form POPULATE_FILE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form POPULATE_FILE .

DATA: L_STRING TYPE STRING,

L_COUNTER(2) TYPE N,

V_INDEX TYPE SY-TABIX.

LOOP AT IT_KNA1.

V_INDEX = SY-TABIX.

AT NEW CUSTOMER.

READ TABLE IT_KNA1 INDEX V_INDEX.

IF SY-SUBRC = 0.

perform bdc_dynpro using 'SAPMF02D' '0105'.

perform bdc_field using 'BDC_CURSOR'

'RF02D-KTOKD'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RF02D-KUNNR'

IT_KNA1-CUSTOMER.

perform bdc_field using 'RF02D-BUKRS'

IT_KNA1-COMPANY_CODE.

perform bdc_field using 'RF02D-KTOKD'

IT_KNA1-ACCOUNT_GROUP.

*PERFORM BDC_FIELD USING 'RF02D-D0130'

  • 'X'.

perform bdc_dynpro using 'SAPMF02D' '0110'.

perform bdc_field using 'BDC_CURSOR'

'KNA1-SPRAS'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'KNA1-ANRED'

IT_KNA1-TITLE.

perform bdc_field using 'KNA1-NAME1'

IT_KNA1-NAME.

perform bdc_field using 'KNA1-SORTL'

IT_KNA1-SEARCH_TERM.

perform bdc_field using 'KNA1-STRAS'

IT_KNA1-STREET.

perform bdc_field using 'KNA1-ORT01'

IT_KNA1-CITY.

perform bdc_field using 'KNA1-PSTLZ'

IT_KNA1-POSTAL_CODE.

perform bdc_field using 'KNA1-LAND1'

IT_KNA1-COUNTRY.

perform bdc_field using 'KNA1-SPRAS'

IT_KNA1-LANGUAGE_KEY.

perform bdc_dynpro using 'SAPMF02D' '0120'.

perform bdc_field using 'BDC_CURSOR'

'KNA1-LIFNR'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_dynpro using 'SAPMF02D' '0130'.

PERFORM BDC_FIELD USING 'RF02D-D0130'

'X'.

perform bdc_field using 'BDC_CURSOR'

'KNBK-BANKN(01)'.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

perform bdc_dynpro using 'SAPMF02D' '0210'.

perform bdc_field using 'BDC_CURSOR'

'KNB1-AKONT'.

perform bdc_field using 'BDC_OKCODE'

'=UPDA'.

perform bdc_field using 'KNB1-AKONT'

IT_KNA1-REC_ACCOUNT.

perform bdc_dynpro using 'SAPLRSFH' '0100'.

perform bdc_field using 'BDC_OKCODE'

'/EBACK'.

perform bdc_field using 'BDC_CURSOR'

'RSIODYNP4-LOW(01)'.

ENDIF.

ENDAT.

L_COUNTER = L_COUNTER + 1.

CLEAR L_STRING.

CONCATENATE 'KNBK-BANKS(' L_COUNTER ')' INTO L_STRING.

PERFORM BDC_FIELD USING L_STRING

IT_KNA1-CNTRY.

CLEAR L_STRING.

CONCATENATE 'KNBK-BANKL(' L_COUNTER ')' INTO L_STRING.

PERFORM BDC_FIELD USING L_STRING

IT_KNA1-BANK_KEY.

CLEAR L_STRING.

CONCATENATE 'KNBK-BANKN(' L_COUNTER ')' INTO L_STRING.

PERFORM BDC_FIELD USING L_STRING

IT_KNA1-BANK_ACCOUNT.

AT END OF CUSTOMER.

READ TABLE IT_KNA1 INDEX V_INDEX.

IF SY-SUBRC = 0.

CALL TRANSACTION 'FD01' USING IT_BDCDATA MODE 'A' UPDATE 'S' MESSAGES

INTO IT_MESSAGES.

IF SY-SUBRC <> 0.

PERFORM EMPLOYEEID_ERROR.

*ELSE.

ENDIF.

WRITE: SY-SUBRC.

perform message_format_write.

*ENDIF.

*WRITE: SY-SUBRC.

CLEAR IT_BDCDATA.

REFRESH IT_BDCDATA.

ENDIF.

ENDAT.

ENDLOOP.

endform. " POPULATE_FILE

&----


*& Form bdc_dynpro

&----


  • text

----


  • -->P_0224 text

  • -->P_0225 text

----


form bdc_dynpro using value(p_0224)

value(p_0225).

IT_BDCDATA-PROGRAM = P_0224.

IT_BDCDATA-DYNPRO = P_0225.

IT_BDCDATA-DYNBEGIN = 'X'.

APPEND IT_BDCDATA.

CLEAR IT_BDCDATA.

endform. " bdc_dynpro

&----


*& Form bdc_field

&----


  • text

----


  • -->P_0229 text

  • -->P_0230 text

----


form bdc_field using value(p_0229)

value(p_0230).

IT_BDCDATA-FNAM = P_0229.

IT_BDCDATA-FVAL = P_0230.

APPEND IT_BDCDATA.

CLEAR IT_BDCDATA.

endform. " bdc_field

&----


*& Form EMPLOYEEID_ERROR

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form EMPLOYEEID_ERROR .

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

CLIENT = SY-MANDT

  • DEST = FILLER8

GROUP = 'Z50583_REC1'

  • HOLDDATE = FILLER8

KEEP = 'X'

USER = SY-UNAME

  • RECORD = FILLER1

  • PROG = SY-CPROG

  • IMPORTING

  • QID =

EXCEPTIONS

CLIENT_INVALID = 1

DESTINATION_INVALID = 2

GROUP_INVALID = 3

GROUP_IS_LOCKED = 4

HOLDDATE_INVALID = 5

INTERNAL_ERROR = 6

QUEUE_ERROR = 7

RUNNING = 8

SYSTEM_LOCK_ERROR = 9

USER_INVALID = 10

OTHERS = 11.

IF sy-subrc <> 0.

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

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

ENDIF.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = 'FD01'

  • POST_LOCAL = NOVBLOCAL

  • PRINTING = NOPRINT

  • SIMUBATCH = ' '

  • CTUPARAMS = ' '

TABLES

dynprotab = IT_BDCDATA

EXCEPTIONS

INTERNAL_ERROR = 1

NOT_OPEN = 2

QUEUE_ERROR = 3

TCODE_INVALID = 4

PRINTING_INVALID = 5

POSTING_INVALID = 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.

CALL FUNCTION 'BDC_CLOSE_GROUP'

EXCEPTIONS

NOT_OPEN = 1

QUEUE_ERROR = 2

OTHERS = 3.

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. " EMPLOYEEID_ERROR

&----


*& Form message_format_write

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form message_format_write .

DATA: L_MSG(200).

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = SY-MSGID

LANG = SY-LANGU

NO = SY-MSGNO

V1 = SY-MSGV1

V2 = SY-MSGV2

V3 = SY-MSGV3

V4 = SY-MSGV4

IMPORTING

MSG = L_MSG

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2.

WRITE: / L_MSG.

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. " message_format_write

~~Guduri

Former Member
0 Kudos

Hi,

You need to take an 1 offset of the field into a variable and pass it to OK code.

Thanks

Dany

Former Member
0 Kudos

Hi,

Check the following link:

http://www.sapbrain.com

Regards,

Bhaskar

0 Kudos

Hi Bhaskar Chikine,

Give the proper section in the link. you ae always specifying

http://www.sapbrain.com in all ur answers.

bye