‎2007 Aug 28 6:38 AM
please anyone can help me in this code i.e how to update the database yusing table control please make changes in my code if required
this is my code
report ZTEST_XK01
no standard page heading line-size 255.
*include bdcrecx1.
***************PARAMETERS DECLERATIONS*********
PARAMETERS : P_file type rlgrap-filename, P_FILE1 TYPE RLGRAP-FILENAME
.
**************internal table decleration*******
data : bdcdata type standard table of bdcdata with header line.
data : begin of t_lfa1 occurs 0,
lifnr like RF02K-LIFNR,
BUKRS LIKE RF02K-BUKRS,
EKORG LIKE RF02K-EKORG,
KTOKK LIKE RF02K-KTOKK,
ANRED LIKE LFA1-ANRED,
NAME1 LIKE LFA1-NAME1,
SORTL LIKE LFA1-SORTL,
LAND1 LIKE LFA1-LAND1,
AKONT LIKE LFB1-AKONT,
ZTERM LIKE LFB1-ZTERM,
END OF T_LFA1.
DATA : BEGIN OF T_LFBK OCCURS 0,
BANKS LIKE LFBK-BANKS,
BANKL LIKE LFBK-BANKL,
END OF T_LFBK.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = p_FILE
.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE1.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = P_FILE1
.
start-of-selection.
data : v_file type string.
move p_file to v_file.
data : e_file type string.
move p_file1 to e_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = v_file
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 =
IMPORTING
FILELENGTH =
HEADER =
TABLES
DATA_TAB = T_LFA1
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.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = E_FILE
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 =
IMPORTING
FILELENGTH =
HEADER =
TABLES
DATA_TAB = T_LFBK
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.
loop at t_lfa1.
perform bdc_dynpro using 'SAPMF02K' '0100'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-KTOKK'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-LIFNR'
t_lfa1-lifnr.
perform bdc_field using 'RF02K-BUKRS'
t_lfa1-bukrs.
perform bdc_field using 'RF02K-EKORG'
t_lfa1-ekorg.
perform bdc_field using 'RF02K-KTOKK'
t_lfa1-ktokk.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-SORTL'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFA1-ANRED'
t_lfa1-anred.
perform bdc_field using 'LFA1-NAME1'
t_lfa1-name1.
perform bdc_field using 'LFA1-SORTL'
t_lfa1-sortl.
perform bdc_field using 'LFA1-LAND1'
t_lfa1-land1.
perform bdc_dynpro using 'SAPMF02K' '0120'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-KUNNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
loop at t_lfbk .
data : val(2) type c.
data :v_fil type c.
concatenate 'lfbk-banks(' val ')' into v_fil.
perform bdc_field using v_fil
t_lfbk-BANKS.
concatenate 'lfbk-bankl(' val ')' into v_fil.
perform bdc_field using v_fil
t_lfbk-BANKl.
val = 01.
val = val + 1.
if val > 5.
val = 5.
perform bdc_dynpro using 'SAPMF02K' '0130'.
perform bdc_field using 'BDC_CURSOR'
'LFBK-BANKL(val)'.
perform bdc_field using 'BDC_OKCODE'
'ENTR'.
perform bdc_field using 'LFBK-BANKL(val)'
v_fil.
perform bdc_field using 'LFBK-BANKS(val)'
v_fil.
*perform bdc_field using 'LFBK-BANKS(02)'
'IN'.
*perform bdc_field using 'LFBK-BANKS(03)'
'in'.
*perform bdc_field using 'LFBK-BANKS(04)'
'in'.
*perform bdc_field using 'LFBK-BANKS(05)'
'in'.
*perform bdc_field using 'LFBK-BANKL(02)'
'00000142'.
*perform bdc_field using 'LFBK-BANKL(03)'
'sunny'.
*perform bdc_field using 'LFBK-BANKL(04)'
'sunny'.
*perform bdc_field using 'LFBK-BANKL(05)'
'sunny'.
*perform bdc_dynpro using 'SAPMF02K' '0130'.
*perform bdc_field using 'BDC_CURSOR'
'LFBK-BANKS(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
endif.
endloop.
perform bdc_dynpro using 'SAPMF02K' '0210'.
perform bdc_field using 'BDC_CURSOR'
'LFB1-AKONT'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFB1-AKONT'
'160000'.
perform bdc_dynpro using 'SAPMF02K' '0215'.
perform bdc_field using 'BDC_CURSOR'
'LFB1-ZTERM'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFB1-ZTERM'
'0001'.
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_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'
‎2007 Aug 28 7:50 AM
hi,
check this example
*demo on recording for handling btable control fieldds in bdc
*for recording first got to shdb tcode and record there.and the n go to program option
report ZBDC_XK01
no standard page heading line-size 255.
TABLES : rf02k,lfa1,lfbk.
DATA : BEGIN OF it_ven OCCURS 0,
lifnr LIKE rf02k-lifnr,
ktokk LIKE rf02k-ktokk,
name1 LIKE lfa1-name1,
sortl LIKE lfa1-sortl,
land1 LIKE lfa1-land1,
spras LIKE lfa1-spras,
banks(6) TYPE c,
bankl(17) TYPE c,
bankn(19) TYPE c,
END OF it_ven.
DATA : BEGIN OF banks OCCURS 0,
banks LIKE lfbk-banks,
END OF banks,
BEGIN OF bankl OCCURS 0,
bankl LIKE lfbk-bankl,
END OF bankl,
BEGIN OF bankn OCCURS 0,
bankn LIKE lfbk-bankn,
END OF bankn.
DATA : fld(20) TYPE c,
cnt(2) TYPE n.
data : bdctab like bdcdata occurs 0 with header line.
include bdcrecx1.
start-of-selection.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'Z:\sr.TXT'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
IMPORTING
FILELENGTH =
HEADER =
tables
data_tab = IT_VEN
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.
perform open_group.
LOOP AT it_ven.
REFRESH bdcdata.
REFRESH : banks,bankl,bankn..
SPLIT it_ven-BANKS AT ',' INTO TABLE banks.
SPLIT it_ven-BANKL AT ',' INTO TABLE bankl.
SPLIT it_ven-BANKN AT ',' INTO TABLE bankn.
perform bdc_dynpro using 'SAPMF02K' '0100'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-KTOKK'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-LIFNR'
IT_VEN-LIFNR.
perform bdc_field using 'RF02K-KTOKK'
IT_VEN-KTOKK.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-SPRAS'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFA1-NAME1'
IT_VEN-NAME1.
perform bdc_field using 'LFA1-SORTL'
IT_VEN-SORTL.
perform bdc_field using 'LFA1-LAND1'
IT_VEN-LAND1.
perform bdc_field using 'LFA1-SPRAS'
IT_VEN-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-BANKN(02)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
*perform bdc_field using 'LFBK-BANKS(01)'
'DE'.
*perform bdc_field using 'LFBK-BANKS(02)'
'DE'.
*perform bdc_field using 'LFBK-BANKL(01)'
'10020030'.
*perform bdc_field using 'LFBK-BANKL(02)'
'67270003'.
*perform bdc_field using 'LFBK-BANKN(01)'
'12345'.
*perform bdc_field using 'LFBK-BANKN(02)'
'66666'.
MOVE 1 TO cnt.
LOOP AT BANKS.
CONCATENATE 'LFBK-BANKS(' cnt ') ' INTO fld.
PERFORM bdc_field USING fld BANKS-BANKS.
cnt = cnt + 1.
ENDLOOP.
MOVE 1 TO cnt.
LOOP AT BANKL.
CONCATENATE 'LFBK-BANKL(' cnt ') ' INTO fld.
PERFORM bdc_field USING fld bankl-bankl.
cnt = cnt + 1.
ENDLOOP.
MOVE 1 TO cnt.
LOOP AT BANKN.
CONCATENATE 'LFBK-BANKN(' cnt ') ' INTO fld.
PERFORM bdc_field USING fld BANKN-BANKN.
cnt = cnt + 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 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
perform bdc_transaction using 'XK01'.
ENDLOOP.
perform close_group.
‎2007 Aug 28 10:52 AM
Hi,
you can check the following piece of code.
*Batchinputdata of single transaction
DATA : tbl_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
*Input records
DATA : BEGIN OF tbl_input OCCURS 0,
lifnr LIKE lfa1-lifnr, "Account number of vendor or
banks LIKE lfbk-banks, "Bank country key
bankl LIKE lfbk-bankl, "Bank key
bankn LIKE lfbk-bankn, "Bank account number
koinh LIKE lfbk-koinh, "Account holder name
bvtyp LIKE lfbk-bvtyp, "Partner bank type
banka LIKE bnka-banka, "Name of bank
stcd3 LIKE lfa1-stcd3, "Tax number 3
scacd LIKE lfa1-scacd, "Standard carrier access code
zwels LIKE lfb1-zwels, "List of the Payment Methods to be
"Considered
lnrzb LIKE lfb1-lnrzb, "Alternate payee
iban LIKE tiban-iban, "IBAN (International Bank Account
" Number)
valid_from(10) TYPE c, "Start of IBAN validity
swift LIKE bnka-swift, "SWIFT Code for International
"Payments
bukrs LIKE zgroup_code_xref-bukrs,
"Company code
land1 LIKE t001-land1, "Country
END OF tbl_input.
----
*Constants
----
*CONSTANTS
CONSTANTS: c_tcode TYPE tstc-tcode VALUE 'XK02', "For holding
"the TCODE
c_keep(1) TYPE c VALUE 'X', "To hold X
c_tabctrl TYPE i VALUE '6', "For holding
c_and TYPE c VALUE '&',
c_tab TYPE x VALUE '09'.
----
START-OF-SELECTION *
----
START-OF-SELECTION.
IF p_appser NE 'X' .
*Download from presentation server
PERFORM pres_file_download .
ELSE.
*Download from application server
PERFORM appl_file_download.
ENDIF.
DESCRIBE TABLE tbl_input LINES w_rec.
*Banking details upload
IF p_bank = 'X'.
IF NOT tbl_input[] IS INITIAL.
PERFORM data_fetching.
ELSE.
WRITE : text-017.
EXIT.
ENDIF.
PERFORM data_validation.
PERFORM final_data_prep.
IF p_test NE 'X'.
<b> PERFORM bdc_data_load</b>.
ENDIF.
*Linking alternate payee
ELSE.
IF NOT tbl_input[] IS INITIAL.
PERFORM data_fetching_zalt.
ENDIF.
PERFORM data_validation_zalt.
PERFORM final_data_prep_zalt.
PERFORM zalt_data_load.
ENDIF.
&----
*& <b>Form bdc_data_load</b>
&----
FORM bdc_data_load.
PERFORM open_group.
DATA : l_cnt(2) TYPE n. "TIR-70118
SORT tbl_final BY lifnr bukrs.
SORT tbl_lfbk BY lifnr.
LOOP AT tbl_final.
AT NEW bukrs.
PERFORM 1_screen.
PERFORM cursor_location.
ENDAT.
PERFORM table_control.
l_cnt = l_cnt + 1. "TIR-70118
AT END OF bukrs.
*Begin of addition for TIR-70118
MOVE l_cnt TO tbl_lfbk-cnt.
tbl_lfbk-lifnr = tbl_final-lifnr.
COLLECT tbl_lfbk.
SORT tbl_lfbk BY lifnr.
CLEAR l_cnt.
*End of addition for TIR-70118
PERFORM last_screen.
PERFORM insert_bdc.
REFRESH tbl_bdcdata.
ENDAT.
ENDLOOP.
PERFORM close_group.
ENDFORM. " bdc_data_load
&----
*& <b> Form 1_screen</b>
&----
FORM 1_screen.
PERFORM bdc_dynpro USING 'SAPMF02K' '0101'.
PERFORM bdc_field USING : 'BDC_CURSOR'
'RF02K-D0215',
'BDC_OKCODE'
'/00',
'RF02K-LIFNR'
tbl_final-lifnr,
'RF02K-BUKRS'
tbl_final-bukrs,
'RF02K-D0110'
'',
'RF02K-D0120'
'X',
'RF02K-D0130'
'X',
'RF02K-D0215'
'X'.
PERFORM bdc_dynpro USING 'SAPMF02K' '0120'.
PERFORM bdc_field USING : 'BDC_CURSOR'
'LFA1-TXJCD',
'BDC_OKCODE'
'/00'.
*Begin of changes for TIR-70118
IF NOT tbl_final-stcd3 IS INITIAL.
PERFORM bdc_field USING : 'LFA1-STCD3'
tbl_final-stcd3.
ENDIF.
IF NOT tbl_final-scacd IS INITIAL.
PERFORM bdc_field USING : 'LFA1-SCACD'
tbl_final-scacd.
ENDIF.
*End of changes for TIR-70118
PERFORM bdc_dynpro USING 'SAPMF02K' '0130'.
ENDFORM. " 1_screen
&----
*& <b> Form cursor_location</b>
&----
FORM cursor_location.
DATA : l_times TYPE i.
CLEAR tbl_lfbk. "TIR-70118
READ TABLE tbl_lfbk WITH KEY lifnr = tbl_final-lifnr
BINARY SEARCH.
IF sy-subrc = 0.
l_times = tbl_lfbk-cnt DIV 5.
w_count = ( tbl_lfbk-cnt MOD 5 ) + 1.
DO l_times TIMES.
PERFORM page_down.
ENDDO.
ELSE.
w_count = 1.
ENDIF.
CLEAR l_times.
ENDFORM. " cursor_location
&----
*& <b> Form table_control</b>
&----
FORM table_control.
CONCATENATE 'LFBK-BANKS(' w_count ')'
INTO w_fld1.
PERFORM bdc_field USING 'BDC_CURSOR'
w_fld1.
CLEAR w_fld1.
IF NOT ( tbl_final-banks IS INITIAL ). "TIR-70118
PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTR'.
CONCATENATE 'LFBK-BANKS(' w_count ')'
INTO w_fld1.
PERFORM bdc_field USING w_fld1
tbl_final-banks.
CLEAR w_fld1.
CONCATENATE 'LFBK-BANKL(' w_count ')'
INTO w_fld1.
PERFORM bdc_field USING w_fld1
tbl_final-bankl.
CLEAR w_fld1.
CONCATENATE 'LFBK-BANKN(' w_count ')'
INTO w_fld1.
PERFORM bdc_field USING w_fld1
tbl_final-bankn.
CONCATENATE 'LFBK-KOINH(' w_count ')'
INTO w_fld1.
PERFORM bdc_field USING w_fld1
tbl_final-koinh.
CONCATENATE 'LFBK-BKONT(' w_count ')'
INTO w_fld1.
PERFORM bdc_field USING w_fld1
tbl_final-bkont.
CONCATENATE 'LFBK-BVTYP(' w_count ')'
INTO w_fld1.
PERFORM bdc_field USING w_fld1
tbl_final-bvtyp.
CONCATENATE 'LFBK-BKREF(' w_count ')'
INTO w_fld1.
PERFORM bdc_field USING w_fld1
tbl_final-bkref.
CLEAR w_fld1.
IF NOT tbl_final-swift IS INITIAL.
PERFORM swift_screen.
ENDIF.
IF NOT tbl_final-iban IS INITIAL.
PERFORM iban_screen.
ENDIF.
PERFORM bdc_dynpro USING 'SAPMF02K' '0130'.
<b> w_count = w_count + 1.
IF w_count EQ c_tabctrl.
w_count = 1.
PERFORM page_down</b>.
ENDIF.
ENDIF.
ENDFORM. " table_control
&----
*& <b> Form page_down</b>
&----
FORM page_down.
PERFORM bdc_field USING 'BDC_OKCODE'
'=P+'.
PERFORM bdc_field USING 'BDC_CURSOR'
'LFBK-BANKS(01)'.
PERFORM bdc_dynpro USING 'SAPMF02K'
'0130'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
ENDFORM. " page_down
&----
*& Form <b>Insert_BDC</b>
&----
This form takes the transaction code and populates the data
----
FORM submit_bdc .
**Function module that takes the TCODE and populate the data
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = c_tcode
TABLES
dynprotab = tbl_bdcdata
EXCEPTIONS
internal_error = 1
not_open = 2
queue_error = 3
tcode_invalid = 4
printing_invalid = 5
posting_invalid = 6
OTHERS = 7.
*Incase of error while populatin data
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. "End of Submit_bdc
**********************************************************************************************
I think this code can help for you, let me know if any doubts.
Reward with points, if it helpful for u.
Regards,
Vijay
‎2007 Aug 28 1:22 PM
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
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.
Sample code
Following is a 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.
regards,
srinivas
<b>*reward for useful answers*</b>