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: 

tablecontrol-bdc

rcvalluri
Explorer
0 Kudos
129

hi!

to handle table control for any screen resolution we set defsize = 'X' in ctu_params.

can anybody explain how this works internally. I mean if my monitor shows 3visible lines in a tablecontrol and i run the same program in another pc having more resolution,does that monitor also show 3visible lines.I think i confused you.anyway tell me how it works internally.i want to know more.

2 REPLIES 2

Former Member
0 Kudos
54

Following is a code for tableconttrol BDC for Transaction VD51.

&----


*& Report ZM_SD_BDC_VD51

*&

&-BDC FOR TRANSACTION VD51----


*&

*&

&----


REPORT ZM_SD_BDC_VD51 no standard page heading line-size 255.

DATA : BEGIN OF ITAB OCCURS 10,

KUNNR LIKE KNMT-KUNNR, "Customer no.

VKORG LIKE KNMT-VKORG, "Sales organization

VTWEG LIKE KNMT-VTWEG, "Distribution channel

END OF ITAB.

DATA: BEGIN OF ITAB1 OCCURS 10,

KUNNR LIKE KNMT-KUNNR, "Customer Number

VKORG LIKE KNMT-VKORG, "Sales organization

VTWEG LIKE KNMT-VTWEG, "Distribution channel

MATNR LIKE KNMT-MATNR, "Mat. No.

KDMAT LIKE KNMT-KDMAT, "Customer Material Desc

WERKS LIKE KNMT-WERKS, "Plant

LPRIO LIKE KNMT-LPRIO, "Delivery Priority

MINLF(17), "Min. Del. Qty

KZTLF LIKE KNMT-KZTLF, "Partial Del. Allowed

ANTLF(1), "Max no. of Partial Del.

UNTTO(5), "Under Del. Tolerance

UEBTO(5), "Over Del. Tolerance

VWPOS LIKE KNMT-VWPOS, "Item Usage

END OF ITAB1.

DATA: filetype like RLGRAP-FILENAME.

  • BDC STRUCTURE

DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

  • messages of call transaction

DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

DATA : WA_ITAB1 LIKE ITAB1.

DATA : BEGIN OF ERROR_FILE OCCURS 0,

KUNNR LIKE KNMT-KUNNR, "Customer Number

VKORG LIKE KNMT-VKORG, "Sales organization

VTWEG LIKE KNMT-VTWEG, "Distribution channel

MATNR LIKE KNMT-MATNR, "Mat. No.

KDMAT LIKE KNMT-KDMAT, "Customer Material Desc

WERKS LIKE KNMT-WERKS, "Plant

LPRIO LIKE KNMT-LPRIO, "Delivery Priority

MINLF(17), "Min. Del. Qty

KZTLF LIKE KNMT-KZTLF, "Partial Del. Allowed

ANTLF(1), "Max no. of Partial Del.

UNTTO(5), "Under Del. Tolerance

UEBTO(5), "Over Del. Tolerance

VWPOS LIKE KNMT-VWPOS, "Item Usage

TEXT(100),

END OF ERROR_FILE.

data: v_text(100),

v_v1 like balm-msgv1,

v_v2 like balm-msgv2,

v_v3 like balm-msgv3,

v_v4 like balm-msgv4.

parameters : v_mode type mode.

parameters: p_fname like rlgrap-filename,

p_error TYPE rlgrap-filename.

*default 'C:\Documents and Settings\Administrator\Desktop\ERROR.txt'.

      • End of data declaration *******************************************

at selection-screen on value-request for p_fname.

call function 'F4_FILENAME'

exporting

program_name = syst-cprog

dynpro_number = syst-dynnr

field_name = ''

importing

file_name = p_fname.

at selection-screen on value-request for p_error.

call function 'F4_FILENAME'

exporting

program_name = syst-cprog

dynpro_number = syst-dynnr

field_name = ''

importing

file_name = p_error.

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

start-of-selection.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

  • CODEPAGE = ' '

FILENAME = P_FNAME

FILETYPE = 'DAT'

TABLES

DATA_TAB = ITAB1.

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

ITAB[] = ITAB1[].

DELETE ADJACENT DUPLICATES FROM ITAB COMPARING ALL FIELDS.

SORT ITAB BY KUNNR VKORG VTWEG.

SORT ITAB1 BY KUNNR VKORG VTWEG.

LOOP AT ITAB.

perform bdc_dynpro using 'SAPMV10A' '0100'.

perform bdc_field using 'BDC_CURSOR'

'MV10A-KUNNR'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'MV10A-KUNNR'

ITAB-KUNNR.

perform bdc_field using 'MV10A-VKORG'

ITAB-VKORG.

perform bdc_field using 'MV10A-VTWEG'

ITAB-VTWEG.

LOOP AT ITAB1 INTO WA_ITAB1 WHERE KUNNR = ITAB-KUNNR

AND VKORG = ITAB-VKORG

AND VTWEG = ITAB-VTWEG.

PERFORM ZFILL_DATA.

ENDLOOP.

perform bdc_dynpro using 'SAPMV10A' '0200'.

perform bdc_field using 'BDC_CURSOR'

'MV10A-MATNR(01)'.

perform bdc_field using 'BDC_OKCODE'

'=SICH'.

CALL TRANSACTION 'VD51' USING BDCDATA UPDATE 'S' MODE V_MODE

MESSAGES INTO MESSTAB.

REFRESH BDCDATA.

CLEAR MESSTAB.

LOOP AT MESSTAB.

MOVE : MESSTAB-msgv1 to v_v1,

MESSTAB-msgv2 to v_v2,

MESSTAB-msgv3 to v_v3,

MESSTAB-msgv4 to v_v4.

CALL FUNCTION 'MESSAGE_PREPARE'

EXPORTING

LANGUAGE = sy-langu

MSG_ID = MESSTAB-MSGID

MSG_NO = MESSTAB-MSGNR

msg_var1 = v_v1

msg_var2 = v_v2

msg_var3 = v_v3

msg_var4 = v_v4

IMPORTING

MSG_TEXT = V_TEXT

EXCEPTIONS

FUNCTION_NOT_COMPLETED = 1

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

move-corresponding wa_itab1 to error_file.

move v_text to error_file-text.

append error_file.

clear v_text.

ENDLOOP.

*ENDLOOP.

ENDLOOP.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

FILENAME = p_error

FILETYPE = 'DAT'

TABLES

DATA_TAB = ERROR_FILE.

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

FORM ZFILL_DATA.

perform bdc_dynpro using 'SAPMV10A' '0200'.

perform bdc_field using 'BDC_CURSOR'

'MV10A-MATNR(01)'.

perform bdc_field using 'BDC_OKCODE'

'=SELE'.

perform bdc_field using 'MV10A-SELKZ(01)'

'X'.

perform bdc_field using 'MV10A-MATNR(01)'

WA_ITAB1-MATNR.

perform bdc_field using 'MV10A-KDMAT(01)'

WA_ITAB1-KDMAT.

perform bdc_dynpro using 'SAPMV10A' '0300'.

perform bdc_field using 'BDC_CURSOR'

'MV10A-KDMAT'.

perform bdc_field using 'BDC_OKCODE'

'=BACK'.

perform bdc_field using 'MV10A-WERKS'

WA_ITAB1-WERKS.

perform bdc_field using 'MV10A-LPRIO'

WA_ITAB1-LPRIO.

perform bdc_field using 'MV10A-MINLF'

WA_ITAB1-MINLF.

perform bdc_field using 'MV10A-UNTTO'

WA_ITAB1-UNTTO.

perform bdc_field using 'MV10A-KZTLF'

WA_ITAB1-KZTLF.

perform bdc_field using 'MV10A-ANTLF'

WA_ITAB1-ANTLF.

perform bdc_field using 'MV10A-UEBTO'

WA_ITAB1-UEBTO.

perform bdc_field using 'MV10A-VWPOS'

WA_ITAB1-VWPOS.

perform bdc_dynpro using 'SAPMV10A' '0200'.

perform bdc_field using 'BDC_CURSOR'

'MV10A-MATNR(01)'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

ENDFORM.

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

----


  • Start new screen *

----


FORM BDC_DYNPRO USING PROGRAM DYNPRO.

CLEAR BDCDATA.

BDCDATA-PROGRAM = PROGRAM.

BDCDATA-DYNPRO = DYNPRO.

BDCDATA-DYNBEGIN = 'X'.

APPEND BDCDATA.

ENDFORM.

----


  • Insert field *

----


FORM BDC_FIELD USING FNAM FVAL.

IF FVAL <> ' '.

CLEAR BDCDATA.

BDCDATA-FNAM = FNAM.

BDCDATA-FVAL = FVAL.

APPEND BDCDATA.

ENDIF.

ENDFORM.

*--


end of program--


Maybe this would be helpful to u.

If this was helpful reward points.

regards,

sumeet

Former Member
0 Kudos
54

Please check the follwing code

&----


*& Include Z_93900_MATERIAL1_F01 *

&----


&----


*& Form extract_mat *

&----


*& text *

&----


*& --> p1 text *

*& <-- p2 text *

&----


*extraction of material.

FORM extract_mat.

  • Declaration for local variable

DATA l_mard TYPE mard .

SELECT m~matnr

r~labst

FROM mvke AS m

JOIN mard AS r

ON m~matnr = r~matnr

INTO CORRESPONDING FIELDS OF TABLE g_t_mat

WHERE m~vkorg = p_vkorg

AND m~vtweg = p_vtweg

AND r~lgort = p_olgort

AND r~labst > 0.

IF g_t_mat[] IS NOT INITIAL.

SELECT matnr meins FROM mara

INTO CORRESPONDING FIELDS OF TABLE g_t_mat2

FOR ALL ENTRIES IN g_t_mat

WHERE matnr = g_t_mat-matnr.

LOOP AT g_t_mat.

READ TABLE g_t_mat2 WITH KEY matnr = g_t_mat-matnr.

g_t_mat-meins = g_t_mat2-meins.

MODIFY g_t_mat TRANSPORTING meins.

CLEAR g_t_mat.

CLEAR g_t_mat2.

ENDLOOP.

  • Fetching required fields into temporary table

SELECT m~matnr

m~meins

c~vrbmt

FROM mara AS m

JOIN marc AS c

ON m~matnr = c~matnr

INTO CORRESPONDING FIELDS OF TABLE g_t_mat1

FOR ALL ENTRIES IN g_t_mat

WHERE c~vrbmt <> g_t_mat-matnr

AND c~werks = p_owerks.

ENDIF.

APPEND LINES OF g_t_mat1[] TO g_t_mat[].

IF g_t_mat[] IS NOT INITIAL.

LOOP AT g_t_mat.

SELECT SINGLE * FROM mard

INTO l_mard

WHERE matnr = g_t_mat-matnr

AND werks = p_owerks

AND lgort = p_olgort

AND labst > 0.

  • Populating qty in main table

g_t_mat-labst = l_mard-labst .

CLEAR l_mard .

MODIFY g_t_mat.

ENDLOOP.

ENDIF.

LOOP AT g_t_mat.

IF g_t_mat-labst EQ 0.

DELETE TABLE g_t_mat.

CLEAR g_t_mat.

ENDIF.

ENDLOOP.

SORT g_t_mat BY matnr.

DELETE ADJACENT DUPLICATES FROM g_t_mat.

ADD 1 TO g_f_recs.

ENDFORM. " extract_mat

&----


*& Form extract_refmat

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


  • extract reference material number from new plant.

form extract_refmat .

SELECT vrbmt

FROM marc

INTO CORRESPONDING FIELDS OF TABLE g_t_mat3

WHERE werks = p_nwerks.

endform. " extract_refmat

&----


*& Form validate_mat *

&----


*& text *

&----


*& --> p1 text *

*& <-- p2 text *

&----


*validations on material.

FORM validate_mat.

SELECT matnr

FROM marc

INTO CORRESPONDING FIELDS OF TABLE g_t_mat3

WHERE werks = p_nwerks.

sort g_t_mat3[] by matnr.

LOOP AT g_t_mat.

read table g_t_mat3.

IF g_t_mat-matnr = g_t_mat3-matnr.

IF sy-subrc = 0.

MESSAGE s000 WITH text-010.

ENDIF.

ENDIF.

CLEAR g_t_mat.

ENDLOOP.

ENDFORM. " validate_mat

&----


*& Form validate_date *

&----


*& text *

&----


*& --> p1 text *

*& <-- p2 text *

&----


*validating date

FORM validate_date .

w_date = sy-datum.

CALL FUNCTION 'CONVERSION_EXIT_D3DAT_OUTPUT'

EXPORTING

input = w_date

IMPORTING

output = w_date1.

MOVE w_date1+6(4) TO w_date2.

ENDFORM. " validate_date

&----


*& Form UPDATE_PROCESSING

&----


FORM update_processing.

PERFORM construct_bdc_data .

ENDFORM. " UPDATE_PROCESSING

&----


*& Form Construct_BDC_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM construct_bdc_data .

LOOP AT g_t_mat.

REFRESH bdcdata.

AT NEW matnr.

w_line_i = 0.

PERFORM bdc_dynpro USING 'SAPMM07M' '0400'.

PERFORM bdc_field USING 'BDC_CURSOR' 'MKPF-BUDAT'.

PERFORM bdc_field USING 'BDC_OKCODE' '/00'.

PERFORM bdc_field USING 'MKPF-BKTXT' '93900 Golive'.

PERFORM bdc_field USING 'RM07M-BWARTWA' '309'.

PERFORM bdc_field USING 'RM07M-WERKS' p_owerks.

PERFORM bdc_field USING 'RM07M-LGORT' p_olgort.

PERFORM bdc_dynpro USING 'SAPMM07M' '0421'.

PERFORM bdc_field USING 'BDC_CURSOR' 'MSEG-ERFMG(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '/00'.

PERFORM bdc_field USING 'MSEGK-UMWRK' p_nwerks.

PERFORM bdc_field USING 'MSEGK-UMLGO' p_nlgort.

PERFORM bdc_field USING 'MSEGK-UMMAT' g_t_mat-matnr.

PERFORM bdc_field USING 'DKACB-FMORE' 'X'.

PERFORM bdc_dynpro USING 'SAPLKACB' '0002'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ENTE'.

ENDAT.

PERFORM bdc_detail.

PERFORM bdc_field USING 'DKACB-FMORE' 'X'.

PERFORM bdc_dynpro USING 'SAPLKACB' '0002'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ENTE'.

PERFORM bdc_dynpro USING 'SAPMM07M' '0410'.

PERFORM bdc_field USING 'BDC_OKCODE' 'BCK'.

PERFORM bdc_field USING 'BDC_CURSOR' 'MSEG-MATNR'.

PERFORM bdc_dynpro USING 'SAPMM07M' '0410'.

PERFORM bdc_field USING 'BDC_OKCODE' '/E'.

PERFORM bdc_field USING 'BDC_CURSOR' 'MSEG-MATNR'.

PERFORM bdc_dynpro USING 'SAPMM07M' '0420'.

PERFORM bdc_field USING 'BDC_OKCODE' '/E'.

PERFORM bdc_field USING 'BDC_CURSOR' 'MKPF-BUDAT'.

PERFORM call_transaction.

ENDLOOP.

ENDFORM. " Construct_BDC_data

&----


*& Form call_transaction

&----


  • text

----


  • --> p1 text

  • <-- p2 text

*----


FORM call_transaction .

DATA: w_mode VALUE 'N'.

  • Exucute transaction via Call Transaction

CALL TRANSACTION 'MB1B'

USING bdcdata

MODE w_mode

UPDATE 'S'

MESSAGES INTO t_msg .

  • check for all terminal error messages

READ TABLE t_msg WITH KEY msgtyp = 'S'

msgid = 'M7'

msgnr = '060'.

IF sy-subrc EQ 0.

g_t_mat-msg = text-002.

g_t_mat-status = 'G'.

g_t_mat-mblnr = t_msg-msgv1.

ELSE.

LOOP AT t_msg.

CHECK t_msg-msgtyp NE 'S'.

CHECK t_msg-msgtyp NE 'I'.

CHECK t_msg-msgtyp NE 'W'.

PERFORM get_msg_text USING t_msg-msgid t_msg-msgnr

CHANGING g_t_mat-msg.

g_t_mat-status = t_msg-msgtyp.

EXIT.

ENDLOOP.

ENDIF.

MODIFY g_t_mat TRANSPORTING status msg mblnr.

ENDFORM. " CALL TRANSACTION

&----


*& Form bdc_detail *

&----


*& text *

&----


*& --> p1 text *

*& <-- p2 text *

&----


FORM bdc_detail .

  • accumulate lines to determine if page_down required

DATA: w_qty_x(17).

ADD 1 TO w_line_i.

IF w_line_i > 12.

w_line_i = 2.

PERFORM bdc_dynpro USING 'SAPMM07M' '0421'.

PERFORM bdc_field USING 'BDC_OKCODE' '=NP'.

ENDIF.

w_qty_x = g_t_mat-labst.

  • material overview screen (with enter)

PERFORM bdc_dynpro USING 'SAPMM07M' '0421'.

PERFORM bdc_field USING 'BDC_CURSOR' 'MSEG-ERFME(01)'.

PERFORM bdc_field USING 'BDC_OKCODE' '=BU'.

PERFORM bdc_field_idx USING 'MSEG-MATNR' g_t_mat3-vrbmt w_line_i.

PERFORM bdc_field_idx USING 'MSEG-ERFMG' w_qty_x w_line_i.

PERFORM bdc_field_idx USING 'MSEG-ERFME' g_t_mat-meins w_line_i.

ENDFORM. " bdc_detail

&----


*& Form bdc_field_idx *

&----


*& text *

&----


*& --> p1 text *

*& <-- p2 text *

&----


FORM bdc_field_idx USING field LIKE bdcdata-fnam

value p_index TYPE i.

DATA: w_index_tx(2).

UNPACK p_index TO w_index_tx.

CLEAR bdcdata.

CONCATENATE field '(' w_index_tx ')' INTO field.

bdcdata-fnam = field.

bdcdata-fval = value.

APPEND bdcdata.

ENDFORM. " BDC_FIELD_IDX

&----


*& Form bdc_dynpro *

&----


*& text *

&----


FORM bdc_dynpro USING program dynpro.

CLEAR bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = 'X'.

APPEND bdcdata.

ENDFORM. " bdc_dynpro

&----


*& Form bdc_field *

&----


*& text *

&----


FORM bdc_field USING fnam fval.

CLEAR bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

APPEND bdcdata.

ENDFORM. " bdc_field

&----


*& Form GET_MSG_TEXT

&----


  • text

----


  • -->P_T_MSG_MSGID text

  • -->P_T_MSG_MSGNR text

  • <--P_W_DETAILS_MSG text

----


FORM get_msg_text USING p_msgid

p_msgnr

CHANGING p_text.

DATA : w_arbgb_tx LIKE t100-arbgb.

DATA : t100 LIKE t100.

  • GET MESSAGE TEXT

w_arbgb_tx = p_msgid.

CALL FUNCTION 'T100_SINGLE_READ'

EXPORTING

t100_sprsl = sy-langu

t100_arbgb = w_arbgb_tx

t100_msgnr = p_msgnr

IMPORTING

wt100 = t100

EXCEPTIONS

not_found = 1

OTHERS = 2.

CHECK sy-subrc = 0.

p_text = t100-text.

ENDFORM. " GET_MSG_TEXT

&----


*& Form bdc_create *

&----


*& text *

&----


*& --> p1 text *

*& <-- p2 text *

&----


FORM bdc_create .

PERFORM bdc_open_group.

PERFORM bdcdata_populate.

PERFORM bdc_close.

ENDFORM. " bdc_create

&----


*& Form bdc_open_group *

&----


*& text *

&----


*& --> p1 text *

*& <-- p2 text *

&----


FORM bdc_open_group .

DATA : w_user_tx LIKE apqi-userid.

w_user_tx = sy-uname.

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

client = sy-mandt

group = 'LT06'

keep = 'X'

user = w_user_tx

EXCEPTIONS

client_invalid = 01

destination_invalid = 02

group_invalid = 03

holddate_invalid = 04

internal_error = 05

queue_error = 06

running = 07

user_invalid = 08.

CASE sy-subrc.

WHEN 0.

WHEN OTHERS.

WRITE: / 'BDC OPEN ERROR', sy-subrc.

ENDCASE.

ENDFORM. " bdc_open_group

&----


*& Form bdc_populate *

&----


*& text *

&----


*& --> p1 text *

*& <-- p2 text *

&----


FORM bdcdata_populate .

LOOP AT g_t_mat.

REFRESH bdcdata.

PERFORM bdc_dynpro1 USING 'SAPML02B' '0203'.

PERFORM bdc_field1 USING 'BDC_CURSOR' 'RL02B-DUNKL'.

PERFORM bdc_field1 USING 'BDC_OKCODE' '/00'.

PERFORM bdc_field1 USING 'RL02B-MBLNR' g_t_mat-mblnr.

PERFORM bdc_field1 USING 'RL02B-MJAHR' w_date2.

PERFORM bdc_field1 USING 'RL02B-LGNUM' p_lgnum.

PERFORM bdc_field1 USING 'RL02B-DUNKL' 'D'.

w_tcode = 'LT06'.

PERFORM bdc_insert.

ENDLOOP.

ENDFORM. " bdcdata_populate

&----


*& Form bdc_insert *

&----


*& text *

&----


*& --> p1 text *

*& <-- p2 text *

&----


FORM bdc_insert.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

tcode = w_tcode

TABLES

dynprotab = bdcdata

EXCEPTIONS

internal_error = 1

not_open = 2

queue_error = 3

tcode_invalid = 4

printing_invalid = 5

posting_invalid = 6

OTHERS = 7.

CASE sy-subrc.

WHEN 0.

WHEN OTHERS.

WRITE: / 'BDC INSERT ERROR', sy-subrc.

ENDCASE.

ENDFORM. " bdc_insert

&----


*& Form bdc_close1 *

&----


*& text *

&----


*& --> p1 text *

*& <-- p2 text *

&----


FORM bdc_close.

CALL FUNCTION 'BDC_CLOSE_GROUP'

EXCEPTIONS

not_open = 1

queue_error = 2

OTHERS = 3.

CASE sy-subrc.

WHEN 0.

WHEN OTHERS.

WRITE: / 'BDC CLOSE ERROR', sy-subrc.

ENDCASE.

ENDFORM. " bdc_close

&----


*& Form bdc_dynpro1 *

&----


*& text *

&----


FORM bdc_dynpro1 USING program dynpro.

CLEAR bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = 'X'.

APPEND bdcdata.

ENDFORM. " bdc_dynpro

&----


*& Form bdc_feild1 *

&----


*& text *

&----


FORM bdc_field1 USING fnam fval.

CLEAR bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

APPEND bdcdata.

ENDFORM. " bdc_field