04-02-2008 2:24 PM
1 Can you explain table control in BDC as a theritical and program code?
2. In BDC open dataset file for output in text mode
encoding default. what is the use of encouding can u explain?
3how many types of secondary indexes?
4. can u give the some sap-script programs?
Edited by: Alvaro Tejada Galindo on Apr 2, 2008 3:11 PM
04-02-2008 2:28 PM
REPORT zva01_bdc NO STANDARD PAGE HEADING.
----
TYPE DECLARATIONS *
----
TYPES : BEGIN OF st_data,
data(1500) TYPE c,
END OF st_data.
*To store header field values for call transaction
TYPES : BEGIN OF st_header,
ind1(1) TYPE c, " Indicator
hcount TYPE i, " Counter to map Item Details
auart TYPE vbak-auart, " Order Type
vkorg TYPE vbak-vkorg, " Sales Organisation
kunnr1 TYPE vbak-kunnr, " Sold-to-Party
kunnr2 TYPE vbak-kunnr, " Ship-to-Party
vtweg TYPE vbak-vtweg, " Distribution Channel
spart TYPE vbak-spart, " Division
bstnk TYPE vbak-bstnk, " Customer purchase order number
END OF st_header.
*To store item field values for call transaction
TYPES : BEGIN OF st_item,
ind2(1) TYPE c, " Indicator
icount TYPE i, " Counter to map Item Details
posnr TYPE vbap-posnr, " Item Number
matnr TYPE vbap-matnr, " Material Number
kwmeng(17) TYPE c, " Quantity
pstyv TYPE vbap-pstyv, " Item Category
werks TYPE vbap-werks, " Plant
END OF st_item.
Types for Error Log File
TYPES : BEGIN OF st_errh,
ind1(1) TYPE c, " Line Indicator
hcount TYPE i, " Counter to map Item Details
auart TYPE vbak-auart, " Order Type
vkorg TYPE vbak-vkorg, " Sales Organisation
kunnr1 TYPE vbak-kunnr, " Sold-to-Party
kunnr2 TYPE vbak-kunnr, " Ship-to-Party
vtweg TYPE vbak-vtweg, " Distribution Channel
spart TYPE vbak-spart, " Division
bstnk TYPE vbak-bstnk, " Customer purchase order number
matnr TYPE vbap-matnr, " Material Number
field TYPE string, " Field Name
value TYPE string, " Field Value
desc TYPE string, " Error Message
END OF st_errh.
Structure for internal table to store Plants for validation
TYPES : BEGIN OF st_werks,
werks TYPE vbap-werks,
END OF st_werks.
*Structure for internal table to store Order Type for validation
TYPES : BEGIN OF st_auart,
auart TYPE vbak-auart,
END OF st_auart.
*Structure for internal table to store Sales Org for validation
TYPES : BEGIN OF st_vkorg,
vkorg TYPE vbak-vkorg,
END OF st_vkorg.
*Structure for internal table to store Distribution Channel for Validation
TYPES : BEGIN OF st_vtweg,
vkorg TYPE vbak-vkorg,
vtweg TYPE vbak-vtweg,
END OF st_vtweg.
*Structure for internal table to store Distribution Channel for Validation
TYPES : BEGIN OF st_makt,
matnr TYPE makt-matnr,
maktx TYPE makt-maktx,
END OF st_makt.
----
DATA DECLARATIONS
----
DATA : it_data TYPE STANDARD TABLE OF st_data, " Flat Internal Table to Store the File
wa_data TYPE st_data.
DATA : it_header TYPE STANDARD TABLE OF st_header, " Internal Table to store Header Details
wa_header TYPE st_header.
DATA : it_item TYPE STANDARD TABLE OF st_item, " Internal Table to store Item Details
wa_item TYPE st_item.
DATA : it_werks TYPE STANDARD TABLE OF st_werks, " Internal Table to store Plant Values for Pre Validation
wa_werks TYPE st_werks.
DATA : it_auart TYPE STANDARD TABLE OF st_auart, " Internal Table to store OrderType for Pre Validation
wa_auart TYPE st_auart.
DATA : it_vkorg TYPE STANDARD TABLE OF st_vkorg, " Internal Table to store Sales Organisation for Pre Validation
wa_vkorg TYPE st_vkorg.
DATA : it_vtweg TYPE STANDARD TABLE OF st_vtweg, " Internal Table to store Distribution Channel for Pre Validation
wa_vtweg TYPE st_vtweg.
DATA : it_makt TYPE STANDARD TABLE OF st_makt, " Internal Table to store Material Description
wa_makt TYPE st_makt.
Internal Type the custom table for insertion into data base.
DATA :
wa_cus_head TYPE z20t_head_sales,
wa_cus_item TYPE z20t_item_sales.
Internal Table to hold the errors.
DATA :
wa_errh TYPE st_errh,
it_errh TYPE STANDARD TABLE OF st_errh.
*To hold Split data and to check item or header details
DATA :
l_check1(1) TYPE c,
l_check2 TYPE string.
DATA:
l_filename TYPE string. " To store File name
DATA:
l_counter TYPE n LENGTH 2, " To count line items
l_hcount TYPE i, " Counter to identify item
l_err TYPE i VALUE 0, " Error identificaton flag.
l_errflag TYPE i VALUE 0. " Error identificaton flag.
Variable storing the TAB
DATA: tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab. " To store TAB value.
BDC Data Table declaration
DATA :
wa_bdcdata TYPE bdcdata,
it_bdcdata TYPE STANDARD TABLE OF bdcdata. " BDCDATA Internal Table
MSG collection table
DATA : it_bdcmsg TYPE STANDARD TABLE OF bdcmsgcoll, " Internal Table to store Messages
wa_bdcmsg TYPE bdcmsgcoll.
DATA : l_exist TYPE c, " To validate GUI File
l_acheck TYPE c, " To Validate Application Server File
l_flag TYPE i VALUE 0,
l_postr TYPE string.
DATA: l_file TYPE ibipparms-path. " To store F4 return file name
DATA : l_mabnr TYPE string, " To concatenate the field name and store gor BDC
l_pstyv TYPE string,
l_kwmeng TYPE string,
l_werks TYPE string,
l_vbeln TYPE vbak-vbeln.
*Audit Report Counters
DATA : l_total TYPE i VALUE 0, " Total No. of Records
l_succ TYPE i VALUE 0, " Total no. od successfull records
l_error TYPE i VALUE 0, " No. Error Records
l_tran TYPE i VALUE 0, " No. of succesfull Transactions
l_trane TYPE i VALUE 0. " No. of error transactions
DATA: l_meins TYPE vbap-meins, " To insert into Custom Table
l_netpr TYPE vbap-netpr,
l_waerk TYPE vbap-waerk.
DATA: l_trstr TYPE string, " To upload string to application server
l_coun TYPE string, " To transfer counter to string
l_quan TYPE string. " To validate for Quantity Field
DATA: l_date TYPE c LENGTH 8.
DATA:
l_str_vbeln TYPE string.
----
SELECTION SCREEN *
----
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : rad1 RADIOBUTTON GROUP g1 DEFAULT 'X' USER-COMMAND usr . " Presentation Server
PARAMETERS : p_input(150) TYPE c MODIF ID pr, " Presentation File Name
p_errpre(150) TYPE c MODIF ID pr. " Presentation Error Log fileName
PARAMETERS : rad2 RADIOBUTTON GROUP g1. " Application Server
PARAMETERS :p_inputa(150) TYPE c MODIF ID ap, " Application Server Input File name
p_errapl(150) TYPE c MODIF ID ap. " Application Server Log File
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.
PARAMETERS : p_sess TYPE apqi-groupid. " Session Name
SELECTION-SCREEN END OF BLOCK b3.
----
SELECTION-SCREEN OUTPUT *
----
AT SELECTION-SCREEN OUTPUT.
PERFORM screen_output.
----
F4 Helps *
----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_input.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
IMPORTING
file_name = l_file.
p_input = l_file.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_inputa.
CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
EXPORTING
directory = '.\'
FILEMASK = ' '
IMPORTING
serverfile = p_inputa
EXCEPTIONS
canceled_by_user = 1
OTHERS = 2
.
----
SCREEN VALIDATION *
----
AT SELECTION-SCREEN ON p_input. " For Presentation File Path and Name
IF sy-ucomm NE 'USR'.
IF p_input IS NOT INITIAL.
CALL FUNCTION 'TMP_GUI_GET_FILE_EXIST'
EXPORTING
fname = p_input
IMPORTING
exist = l_exist
EXCEPTIONS
fileinfo_error = 1
OTHERS = 2
.
IF l_exist = ' '.
MESSAGE i100(z20mes).
ENDIF.
ENDIF.
ENDIF.
AT SELECTION-SCREEN ON p_inputa. " For applicatoin file name and path.
IF sy-ucomm NE 'USR'.
IF p_inputa IS NOT INITIAL.
CALL FUNCTION 'FILE_GET_NAME_USING_PATH'
EXPORTING
client = sy-mandt
logical_path = 'TMP'
file_name = p_inputa
IMPORTING
file_name_with_path = l_acheck
EXCEPTIONS
path_not_found = 1
missing_parameter = 2
operating_system_not_found = 3
file_system_not_found = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE e101(z20mes).
ENDIF.
ENDIF.
ENDIF.
AT SELECTION-SCREEN ON p_sess. " Session Name
IF sy-ucomm NE 'USR'.
IF p_inputa IS NOT INITIAL.
IF p_sess IS INITIAL.
MESSAGE e099(z20mes).
ENDIF.
ELSEIF p_input IS NOT INITIAL.
IF p_sess IS INITIAL.
MESSAGE e099(z20mes).
ENDIF.
ENDIF.
ENDIF.
----
START-OF-SELECTION *
----
START-OF-SELECTION.
When the radio button two is selected that is file is downloaded from the application server
IF rad2 = 'X'.
PERFORM action_appl.
When the radio button 1 is selected the file is downloaded from the presentation layer
ELSEIF rad1 = 'X'.
PERFORM action_pre.
ENDIF.
----
END-OF-SELECTION *
----
END-OF-SELECTION.
Validating the values
PERFORM pre_valid.
Populating BDCDATA and calling Transaction
PERFORM call_transfer.
Audit Report Creation
PERFORM audit_report.
&----
*& Form action_appl
&----
When data has to fetches from Apllication Server
----
FORM action_appl.
OPEN DATASET p_inputa FOR INPUT IN TEXT MODE ENCODING DEFAULT
WITH SMART LINEFEED.
IF sy-subrc NE 0.
MESSAGE e101(z20mes).
ELSE.
DO.
READ DATASET p_inputa INTO wa_data.
IF sy-subrc EQ 0.
APPEND wa_data TO it_data.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
CLOSE DATASET p_inputa.
LOOP AT it_data INTO wa_data.
SPLIT wa_data-data AT tab INTO : l_check1 l_check2.
IF l_check1 = 'H'.
SPLIT wa_data-data AT tab
INTO:
wa_header-ind1
wa_header-auart
wa_header-vkorg
wa_header-kunnr1
wa_header-kunnr2
wa_header-vtweg
wa_header-spart
wa_header-bstnk.
l_hcount = l_hcount + 1.
wa_header-hcount = l_hcount.
APPEND wa_header TO it_header.
CLEAR wa_header.
ELSEIF l_check1 = 'I'.
SPLIT wa_data-data AT tab
INTO:
wa_item-ind2
wa_item-posnr
wa_item-matnr
wa_item-kwmeng
wa_item-pstyv
wa_item-werks.
wa_item-icount = l_hcount.
APPEND wa_item TO it_item.
CLEAR wa_item.
ENDIF.
ENDLOOP.
ENDFORM. "action_appl
&----
*& Form action_pre
&----
When data has to be fetched from Presentation Server
----
FORM action_pre.
l_filename = p_input.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = l_filename
filetype = 'ASC'
HAS_FIELD_SEPARATOR = ' '
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 = it_data
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 it_data INTO wa_data.
SPLIT wa_data-data AT tab INTO : l_check1 l_check2.
IF l_check1 = 'H'.
SPLIT wa_data-data AT tab
INTO:
wa_header-ind1
wa_header-auart
wa_header-vkorg
wa_header-kunnr1
wa_header-kunnr2
wa_header-vtweg
wa_header-spart
wa_header-bstnk.
l_hcount = l_hcount + 1.
wa_header-hcount = l_hcount.
APPEND wa_header TO it_header.
CLEAR wa_header.
l_total = l_total + 1.
ELSEIF l_check1 = 'I'.
SPLIT wa_data-data AT tab
INTO:
wa_item-ind2
wa_item-posnr
wa_item-matnr
wa_item-kwmeng
wa_item-pstyv
wa_item-werks.
wa_item-icount = l_hcount.
APPEND wa_item TO it_item.
CLEAR wa_item.
l_total = l_total + 1.
ENDIF.
ENDLOOP.
ENDFORM. "action_pre
&----
*& Form call_transfer
&----
BDCDATA internal table insertion for call transactrion
----
FORM call_transfer.
LOOP AT it_header INTO wa_header.
PERFORM bdc_dynpro USING 'SAPMV45A' '0101'.
PERFORM bdc_field USING 'BDC_CURSOR'
'VBAK-VKORG'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'VBAK-AUART'
wa_header-auart.
PERFORM bdc_field USING 'VBAK-VKORG'
wa_header-vkorg.
PERFORM bdc_field USING 'VBAK-VTWEG'
wa_header-vtweg.
PERFORM bdc_field USING 'VBAK-SPART'
wa_header-spart.
PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'BDC_CURSOR'
'VBKD-BSTKD'.
PERFORM bdc_field USING 'VBKD-BSTKD'
wa_header-bstnk.
PERFORM bdc_field USING 'KUAGV-KUNNR'
wa_header-kunnr1.
PERFORM bdc_field USING 'KUWEV-KUNNR'
wa_header-kunnr2.
PERFORM bdc_field USING 'RV45A-KETDAT'
'01.10.2007'.
PERFORM bdc_field USING 'RV45A-KPRGBZ'
'D'.
WRITE sy-datum TO l_date DD/MM/YY.
PERFORM bdc_field USING 'VBKD-PRSDT'
l_date .
LOOP AT it_item INTO wa_item WHERE icount = wa_header-hcount.
l_counter = l_counter + 1.
IF l_counter GE 2.
l_counter = 2.
ENDIF.
PERFORM bdc_field USING 'VBKD-BSTKD'
wa_header-bstnk.
PERFORM bdc_field USING 'KUAGV-KUNNR'
wa_header-kunnr1.
PERFORM bdc_field USING 'KUWEV-KUNNR'
wa_header-kunnr2.
PERFORM bdc_field USING 'RV45A-KETDAT'
'01.10.2007'.
PERFORM bdc_field USING 'RV45A-KPRGBZ'
'D'.
PERFORM bdc_field USING 'VBKD-PRSDT'
sy-datum.
PERFORM bdc_field USING 'VBKD-ZTERM'
'ZB01'.
PERFORM bdc_field USING 'VBKD-INCO1'
'CIF'.
PERFORM bdc_field USING 'VBKD-INCO2'
'Berlin'.
PERFORM bdc_field USING 'BDC_CURSOR'
'VBAP-WERKS(L_COUNTER)'.
CONCATENATE 'RV45A-MABNR(' l_counter ')' INTO l_mabnr.
PERFORM bdc_field USING l_mabnr
wa_item-matnr.
CONCATENATE 'VBAP-PSTYV(' l_counter ')' INTO l_pstyv.
PERFORM bdc_field USING l_pstyv
wa_item-pstyv.
CONCATENATE 'VBAP-POSNR(' l_counter ')' INTO l_posnr.
*
PERFORM bdc_field USING l_posnr
wa_item-posnr.
CONCATENATE 'RV45A-KWMENG(' l_counter ')' INTO l_kwmeng.
PERFORM bdc_field USING l_kwmeng
wa_item-kwmeng.
CONCATENATE 'VBAP-WERKS(' l_counter ')' INTO l_werks.
PERFORM bdc_field USING l_werks wa_item-werks.
l_succ = l_succ + 1.
PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=POAN'.
ENDLOOP.
PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=SICH'.
PERFORM bdc_field USING 'VBKD-BSTKD'
'SRV-TestPO3-36'.
PERFORM bdc_field USING 'KUAGV-KUNNR'
'1000'.
PERFORM bdc_field USING 'KUWEV-KUNNR'
'1000'.
PERFORM bdc_field USING 'RV45A-KETDAT'
'01.10.2007'.
PERFORM bdc_field USING 'RV45A-KPRGBZ'
'D'.
PERFORM bdc_field USING 'VBKD-PRSDT'
'29.09.2007'.
PERFORM bdc_field USING 'VBKD-ZTERM'
'ZB01'.
PERFORM bdc_field USING 'VBKD-INCO1'
'CIF'.
PERFORM bdc_field USING 'VBKD-INCO2'
'Berlin'.
PERFORM bdc_field USING 'BDC_CURSOR'
l_mabnr.
l_counter = 0.
PERFORM bdc_transaction USING 'VA01'.
l_succ = l_succ + 1.
ENDLOOP.
ENDFORM. "call_transfer
&----
*& Form bdc_dynpro
&----
text
----
-->PROGRAM text
-->DYNPRO text
----
FORM bdc_dynpro USING program dynpro.
wa_bdcdata-program = program.
wa_bdcdata-dynpro = dynpro.
wa_bdcdata-dynbegin = 'X'.
APPEND wa_bdcdata TO it_bdcdata.
CLEAR wa_bdcdata.
ENDFORM. " bdc_dynpro
&----
*& Form bdc_field
&----
text
----
-->FNAM text
-->FVAL text
----
FORM bdc_field USING fnam fval.
wa_bdcdata-fnam = fnam.
wa_bdcdata-fval = fval.
APPEND wa_bdcdata TO it_bdcdata.
CLEAR wa_bdcdata.
ENDFORM. " bdc_field
&----
*& Form bdc_transaction
&----
CAll Transaction VA01
----
-->TCODE text
----
FORM bdc_transaction USING tcode.
Call Transaction method of entry of data into the database table
*passing tcode and the BDC table
CALL TRANSACTION tcode USING it_bdcdata
MODE 'P'
UPDATE 'S'
MESSAGES INTO it_bdcmsg.
l_tran = l_tran + 1.
WAIT UP TO 5 SECONDS.
GET PARAMETER ID 'AUN' FIELD l_vbeln.
CONCATENATE l_vbeln l_str_vbeln INTO l_str_vbeln SEPARATED BY space.
Collecting error messages
LOOP AT it_bdcmsg INTO wa_bdcmsg WHERE msgtyp = 'E'.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = wa_bdcmsg-msgid
lang = sy-langu
no = wa_bdcmsg-msgnr
v1 = wa_bdcmsg-msgv1
v2 = wa_bdcmsg-msgv2
v3 = wa_bdcmsg-msgv3
v4 = wa_bdcmsg-msgv4
IMPORTING
msg = l_msger
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.
l_flag = 1.
ENDLOOP.
*If Error Exist the BDC Session is open to maintain the error session
IF l_flag = 1.
PERFORM bdc_open.
PERFORM insert_bdc.
PERFORM bdc_close.
l_trane = l_trane + 1.
CLEAR it_bdcdata.
ELSE.
Populating the Custome Tables.
PERFORM custom_header. " Populating Custom Header table.
PERFORM custom_item. " Populating Custom Item Table
CLEAR it_bdcdata.
ENDIF.
ENDFORM. "bdc_transaction
&----
*& Form bdc_open
&----
BDC Session open with p_sess
----
FORM bdc_open.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
DEST = FILLER8
group = p_sess
HOLDDATE = FILLER8
KEEP = FILLER1
user = sy-uname
RECORD = FILLER1
PROG = SY-CPROG
DCPFM = '%'
DATFM = '%'
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
.
ENDFORM. "bdc_open
&----
*& Form insert_bdc
&----
text
----
FORM insert_bdc.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = 'VA01'
TABLES
dynprotab = it_bdcdata.
ENDFORM. "insert_bdc
&----
*& Form bdc_close
&----
text
----
FORM bdc_close.
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3
.
ENDFORM. "bdc_close
&----
*& Form Custom_header
&----
Populating Custom Header Table
----
FORM custom_header.
wa_cus_head-mandt = sy-mandt.
wa_cus_head-vbeln = l_vbeln.
wa_cus_head-vkorg = wa_header-vkorg.
wa_cus_head-vtweg = wa_header-vtweg.
wa_cus_head-spart = wa_header-spart.
wa_cus_head-auart = wa_header-auart.
wa_cus_head-kunnr1 = wa_header-kunnr1.
wa_cus_head-kunnr2 = wa_header-kunnr2.
wa_cus_head-bstnk = wa_header-bstnk.
wa_cus_head-bstdk = sy-datum.
wa_cus_head-ernam = sy-uname.
wa_cus_head-erdat = sy-datum.
wa_cus_head-erzet = sy-uzeit.
INSERT into z20t_head_sales values wa_cus_head.
ENDFORM. "custom_header
&----
*& Form custom_item
&----
Populating Custom Item Table
----
FORM custom_item.
LOOP AT it_item INTO wa_item WHERE icount = wa_header-hcount.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_item-posnr
IMPORTING
output = wa_item-posnr.
SELECT SINGLE
meins netpr waerk
FROM vbap
INTO (l_meins,l_netpr,l_waerk)
WHERE vbeln = l_vbeln AND posnr = wa_item-posnr.
LOOP AT it_makt INTO wa_makt WHERE matnr = wa_item-matnr.
wa_cus_item-mandt = sy-mandt.
wa_cus_item-vbeln = l_vbeln.
wa_cus_item-posnr = wa_item-posnr.
wa_cus_item-matnr = wa_item-matnr.
wa_cus_item-maktx = wa_makt-maktx. " From MAKT
wa_cus_item-pstyv = wa_item-pstyv.
wa_cus_item-dzmeng = wa_item-kwmeng.
wa_cus_item-meins = l_meins.
wa_cus_item-werks = wa_item-werks.
wa_cus_item-netpr = l_netpr.
wa_cus_item-waerk = l_waerk.
INSERT into z20t_item_sales values wa_cus_item.
ENDLOOP.
ENDLOOP.
ENDFORM. "custom_item
&----
*& Form pre_valid
&----
Pre Validation for the Fields
----
FORM pre_valid.
*Selecting Plant Values for validation.
SELECT werks
FROM t001w
INTO TABLE it_werks
FOR ALL ENTRIES IN it_item
WHERE werks = it_item-werks.
*Selecting Order Type for validation.
SELECT auart
FROM tvak
INTO TABLE it_auart
FOR ALL ENTRIES IN it_header
WHERE auart = it_header-auart.
*Selecting Organisation for validation.
SELECT vkorg
FROM tvko
INTO TABLE it_vkorg
FOR ALL ENTRIES IN it_header
WHERE vkorg = it_header-vkorg.
*Selecting Distribution Channel for validation.
SELECT
vkorg vtweg
FROM tvkov
INTO TABLE it_vtweg
FOR ALL ENTRIES IN it_header
WHERE vkorg = it_header-vkorg.
*Selecting Maktx from MAKT
SELECT
matnr maktx
FROM makt
INTO TABLE it_makt
FOR ALL ENTRIES IN it_item
WHERE matnr = it_item-matnr.
*Header Details Validation
LOOP AT it_header INTO wa_header.
IF wa_header-kunnr1 IS INITIAL. " Sold to Party Validation
l_err = 1.
l_error = l_error + 1.
PERFORM transfer_head.
wa_errh-field = 'Sold to Party'(010).
wa_errh-value = wa_header-kunnr1.
wa_errh-desc = 'Sold to Party cannot be initial'(011).
APPEND wa_errh TO it_errh.
CLEAR wa_errh.
ENDIF.
IF wa_header-kunnr2 IS INITIAL. " Ship to Party Validation
l_err = 1.
l_error = l_error + 1.
PERFORM transfer_head.
wa_errh-field = 'Ship to Party'(012).
wa_errh-value = wa_header-kunnr2.
wa_errh-desc = 'Ship to Party cannot be initial'(013).
APPEND wa_errh TO it_errh.
CLEAR wa_errh.
ENDIF.
IF wa_header-auart IS INITIAL. " Order Type Validation
l_err = 1.
l_error = l_error + 1.
PERFORM transfer_head.
wa_errh-field = 'Order Type'(014).
wa_errh-value = wa_header-auart.
wa_errh-desc = 'Order Type cannot be initial'(015).
APPEND wa_errh TO it_errh.
CLEAR wa_errh.
ELSE.
LOOP AT it_auart INTO wa_auart. " Order Type Value Check
IF wa_header-auart = wa_auart-auart.
l_errflag = 1.
ENDIF.
ENDLOOP.
IF l_errflag EQ 0.
l_err = 1.
l_error = l_error + 1.
PERFORM transfer_head.
wa_errh-field = 'Order Type '(016).
wa_errh-value = wa_header-auart.
wa_errh-desc = ' Order Type does not exist '(017).
APPEND wa_errh TO it_errh.
CLEAR wa_errh.
ENDIF.
ENDIF.
l_errflag = 0.
IF wa_header-vkorg IS NOT INITIAL. " Sales Organisation Value Validation
LOOP AT it_vkorg INTO wa_vkorg.
IF wa_header-vkorg = wa_vkorg-vkorg.
l_errflag = 1.
ENDIF.
ENDLOOP.
IF l_errflag = 0.
l_err = 1.
l_error = l_error + 1.
PERFORM transfer_head.
wa_errh-field = 'Sales Organisation'(018).
wa_errh-value = wa_header-vkorg.
wa_errh-desc = 'Sales Organisation does not exist'(019).
APPEND wa_errh TO it_errh.
CLEAR wa_errh.
ENDIF.
ENDIF.
l_errflag = 0.
IF wa_header-vtweg IS NOT INITIAL. " Distribution Channel Value Validation
LOOP AT it_vtweg INTO wa_vtweg WHERE vkorg = wa_header-vkorg.
IF wa_header-vtweg = wa_vtweg-vtweg.
l_errflag = 1.
ENDIF.
ENDLOOP.
IF l_errflag = 0.
l_err = 1.
l_error = l_error + 1.
PERFORM transfer_head.
wa_errh-field = 'Distribution Channel'(020).
wa_errh-value = wa_header-vtweg.
wa_errh-desc = 'Sales Organisation does not exist'(021).
APPEND wa_errh TO it_errh.
CLEAR wa_errh.
ENDIF.
ENDIF.
*Item Details Validation
LOOP AT it_item INTO wa_item WHERE icount = wa_header-hcount.
IF wa_item-posnr IS NOT INITIAL. " Item Number Value Validation
l_postr = wa_item-posnr.
CALL FUNCTION 'CATS_ITS_MAKE_STRING_NUMERICAL'
EXPORTING
input_string = l_postr
IMPORTING
VALUE =
EXCEPTIONS
not_numerical = 1
OTHERS = 2
.
IF sy-subrc NE 0.
l_err = 1.
l_error = l_error + 1.
PERFORM transfer_head.
wa_errh-field = 'Item Number'(022).
wa_errh-value = wa_item-posnr.
wa_errh-desc = 'Item Number Should be numeric'(023).
APPEND wa_errh TO it_errh.
CLEAR wa_errh.
ENDIF.
ENDIF.
IF wa_item-kwmeng IS NOT INITIAL.
l_quan = wa_item-kwmeng.
CALL FUNCTION 'CATS_ITS_MAKE_STRING_NUMERICAL' " Quantity Field Validation
EXPORTING
input_string = l_quan
EXCEPTIONS
not_numerical = 1
OTHERS = 2
.
IF sy-subrc NE 0.
l_err = 1.
l_error = l_error + 1.
PERFORM transfer_head.
wa_errh-field = 'Quantity'(024).
wa_errh-value = wa_item-kwmeng.
wa_errh-desc = 'Quantity Should be numeric'(025).
APPEND wa_errh TO it_errh.
CLEAR wa_errh.
ENDIF.
ENDIF.
IF wa_item-werks IS INITIAL. " Plant Validation
l_err = 1.
l_error = l_error + 1.
PERFORM transfer_head.
wa_errh-field = 'Plant'(026).
wa_errh-value = wa_item-werks.
wa_errh-desc = 'Plant field is initial'(027).
APPEND wa_errh TO it_errh.
CLEAR wa_errh.
ELSE.
LOOP AT it_werks INTO wa_werks.
IF wa_item-werks = wa_werks-werks.
l_errflag = 1.
ENDIF.
ENDLOOP.
IF l_errflag = 0.
l_errflag = 0.
l_err = 1.
l_error = l_error + 1.
PERFORM transfer_head.
wa_errh-field = 'Plant'(028).
wa_errh-value = wa_item-werks.
wa_errh-desc = 'Plant does not exist'(029).
APPEND wa_errh TO it_errh.
CLEAR wa_errh.
ENDIF.
ENDIF.
ENDLOOP.
IF l_err = 1.
DELETE it_header INDEX sy-tabix.
l_err = 0.
ENDIF.
ENDLOOP.
IF l_error >= 1.
PERFORM er_load.
ENDIF.
ENDFORM. "pre_valid
&----
*& Form transfer_head
&----
To transfer into work area
----
FORM transfer_head.
wa_errh-ind1 = wa_header-ind1.
wa_errh-hcount = wa_header-hcount.
wa_errh-vkorg = wa_header-vkorg.
wa_errh-vtweg = wa_header-vtweg.
wa_errh-spart = wa_header-spart.
wa_errh-auart = wa_header-auart.
wa_errh-kunnr1 = wa_header-kunnr1.
wa_errh-kunnr2 = wa_header-kunnr2.
wa_errh-bstnk = wa_header-bstnk.
wa_errh-matnr = wa_item-matnr.
ENDFORM. "transfer_head
&----
*& Form er_load
&----
To load error file into the Server
----
FORM er_load.
IF rad1 = 'X'.
DATA : l_errpre TYPE string.
l_errpre = p_errpre.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
filename = l_errpre
filetype = 'ASC'
TABLES
data_tab = it_errh
FIELDNAMES =
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22
.
ELSEIF rad2 = 'X'.
OPEN DATASET p_errapl FOR OUTPUT IN TEXT MODE ENCODING DEFAULT
WITH SMART LINEFEED.
IF sy-subrc NE 0.
MESSAGE e101(z20mes).
ELSE.
LOOP AT it_errh INTO wa_errh.
l_coun = wa_errh-hcount.
CONCATENATE
wa_errh-ind1
l_coun
wa_errh-vkorg
wa_errh-vtweg
wa_errh-spart
wa_errh-auart
wa_errh-kunnr1
wa_errh-kunnr2
wa_errh-bstnk
wa_errh-matnr
wa_errh-field
wa_errh-value
wa_errh-desc
INTO l_trstr SEPARATED BY ' '.
TRANSFER l_trstr TO p_errapl.
ENDLOOP.
CLOSE DATASET p_errapl.
ENDIF.
l_err = 0.
ENDIF.
ENDFORM. "er_load
&----
*& Form audit_report
&----
Audit Report to displayed
----
FORM audit_report.
IF l_tran > 0.
PERFORM info_popup.
ENDIF.
WRITE 😕 'PROCESSING SUMMARY:'(047).
SKIP.
WRITE 😕 'Program Name:'(048), 45 sy-cprog.
WRITE 😕 'Input File Name:'(049), 45 p_input, p_inputa.
WRITE 😕 'BDC Session Name:'(004), 45 p_sess.
SKIP.
WRITE 😕 'STATISTICS:'.
SKIP.
WRITE 😕 'Total No. of Records: '(005), 45 l_total.
WRITE 😕 'No. of sucess Records: '(006), 45 l_succ.
WRITE 😕 'No of Records in error: '(007), 45 l_error.
WRITE 😕 'Number of Transactions Posted: '(008), 45 l_tran.
WRITE 😕 'Number of Transactions failed: '(009), 45 l_trane.
ENDFORM. "audit_report
&----
*& Form screen_output
&----
Scrren Output when swaped between radio buttons
----
FORM screen_output.
LOOP AT SCREEN.
IF rad1 = 'X'.
IF screen-group1 = 'AP'.
screen-input = '0'.
ENDIF.
ELSE.
IF screen-group1 = 'PR'.
screen-input = '0'.
ENDIF.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
ENDFORM. "screen_output
&----
*& Form screen_valid
&----
text
----
FORM info_popup.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = 'Sales Order(s) Created'
txt1 = l_str_vbeln
txt2 = 'Audit Summary'
TXT3 = ' '
TXT4 = ' '
.
ENDFORM. "info_popup
04-02-2008 6:06 PM
Hi,
An example abap program of handling Table Control during bdc programming.
REPORT zmm_bdcp_purchaseorderkb02
NO STANDARD PAGE HEADING LINE-SIZE 255.
----
Declaring internal tables *
----
*-----Declaring line structure
DATA : BEGIN OF it_dummy OCCURS 0,
dummy(255) TYPE c,
END OF it_dummy.
*-----Internal table for line items
DATA : BEGIN OF it_idata OCCURS 0,
ematn(18), "Material Number.
menge(13), "Qyantity.
netpr(11), "Net Price.
werks(4), "Plant.
ebelp(5), "Item Number.
END OF it_idata.
*-----Deep structure for header data and line items
DATA : BEGIN OF it_me21 OCCURS 0,
lifnr(10), "Vendor A/c No.
bsart(4), "A/c Type.
bedat(8), "Date of creation of PO.
ekorg(4), "Purchasing Organisation.
ekgrp(3), "Purchasing Group.
x_data LIKE TABLE OF it_idata,
END OF it_me21.
DATA : x_idata LIKE LINE OF it_idata.
DATA : v_delimit VALUE ','.
DATA : v_indx(3) TYPE n.
DATA : v_fnam(30) TYPE c.
DATA : v_count TYPE n.
DATA : v_ne TYPE i.
DATA : v_ns TYPE i.
*include bdcrecx1.
INCLUDE zmm_incl_purchaseorderkb01.
----
Search help for file *
----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
IMPORTING
file_name = p_file.
START-OF-SELECTION.
----
To upload the data into line structure *
----
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = p_file
filetype = 'DAT'
TABLES
data_tab = it_dummy.
----
Processing the data from line structure to internal tables *
----
REFRESH:it_me21.
CLEAR :it_me21.
LOOP AT it_dummy.
IF it_dummy-dummy+0(01) = 'H'.
v_indx = v_indx + 1.
CLEAR it_idata.
REFRESH it_idata.
CLEAR it_me21-x_data.
REFRESH it_me21-x_data.
SHIFT it_dummy.
SPLIT it_dummy AT v_delimit INTO it_me21-lifnr
it_me21-bsart
it_me21-bedat
it_me21-ekorg
it_me21-ekgrp.
APPEND it_me21.
ELSEIF it_dummy-dummy+0(01) = 'L'.
SHIFT it_dummy.
SPLIT it_dummy AT v_delimit INTO it_idata-ematn
it_idata-menge
it_idata-netpr
it_idata-werks
it_idata-ebelp.
APPEND it_idata TO it_me21-x_data.
MODIFY it_me21 INDEX v_indx.
ENDIF.
ENDLOOP.
----
To open the group *
----
PERFORM open_group.
----
To populate the bdcdata table for header data *
----
LOOP AT it_me21.
v_count = v_count + 1.
REFRESH it_bdcdata.
PERFORM subr_bdc_table USING: 'X' 'SAPMM06E' '0100',
' ' 'BDC_CURSOR' 'EKKO-LIFNR',
' ' 'BDC_OKCODE' '/00',
' ' 'EKKO-LIFNR' it_me21-lifnr,
' ' 'RM06E-BSART' it_me21-bsart,
' ' 'RM06E-BEDAT' it_me21-bedat,
' ' 'EKKO-EKORG' it_me21-ekorg,
' ' 'EKKO-EKGRP' it_me21-ekgrp,
' ' 'RM06E-LPEIN' 'T'.
PERFORM subr_bdc_table USING: 'X' 'SAPMM06E' '0120',
' ' 'BDC_CURSOR' 'RM06E-EBELP',
' ' 'BDC_OKCODE' '/00'.
MOVE 1 TO v_indx.
*-----To populate the bdcdata table for line item data
LOOP AT it_me21-x_data INTO x_idata.
CONCATENATE 'EKPO-EMATN(' v_indx ')' INTO v_fnam.
PERFORM subr_bdc_table USING ' ' v_fnam x_idata-ematn.
CONCATENATE 'EKPO-MENGE(' v_indx ')' INTO v_fnam.
PERFORM subr_bdc_table USING ' ' v_fnam x_idata-menge.
CONCATENATE 'EKPO-NETPR(' v_indx ')' INTO v_fnam.
PERFORM subr_bdc_table USING ' ' v_fnam x_idata-netpr.
CONCATENATE 'EKPO-WERKS(' v_indx ')' INTO v_fnam.
PERFORM subr_bdc_table USING ' ' v_fnam x_idata-werks.
v_indx = v_indx + 1.
PERFORM subr_bdc_table USING: 'X' 'SAPMM06E' '0120',
' ' 'BDC_CURSOR' 'RM06E-EBELP',
' ' 'BDC_OKCODE' '/00'.
ENDLOOP.
PERFORM subr_bdc_table USING: 'X' 'SAPMM06E' '0120',
' ' 'BDC_CURSOR' 'RM06E-EBELP',
' ' 'BDC_OKCODE' '=BU'.
PERFORM bdc_transaction USING 'ME21'.
ENDLOOP.
PERFORM close_group.
----
End of selection event *
----
END-OF-SELECTION.
IF session NE 'X'.
*-----To display the successful records
WRITE :/10 text-001. "Sucess records
WRITE :/10 SY-ULINE(20).
SKIP.
IF it_sucess IS INITIAL.
WRITE 😕 text-002.
ELSE.
WRITE 😕 text-008, "Total number of Succesful records
35 v_ns.
SKIP.
WRITE:/ text-003, "Vendor Number
17 text-004, "Record number
30 text-005. "Message
ENDIF.
LOOP AT it_sucess.
WRITE:/4 it_sucess-lifnr,
17 it_sucess-tabix CENTERED,
30 it_sucess-sucess_rec.
ENDLOOP.
SKIP.
*-----To display the erroneous records
WRITE:/10 text-006. "Error Records
WRITE:/10 SY-ULINE(17).
SKIP.
IF it_error IS INITIAL.
WRITE:/ text-007. "No error records
ELSE.
WRITE:/ text-009, "Total number of erroneous records
35 v_ne.
SKIP.
WRITE:/ text-003, "Vendor Number
17 text-004, "Record number
30 text-005. "Message
ENDIF.
LOOP AT it_error.
WRITE:/4 it_error-lifnr,
17 it_error-tabix CENTERED,
30 it_error-error_rec.
ENDLOOP.
REFRESH it_sucess.
REFRESH it_error.
ENDIF.
CODE IN INCLUDE.
----
Include ZMM_INCL_PURCHASEORDERKB01
----
DATA: it_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
DATA: it_MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
DATA: E_GROUP_OPENED.
*-----Internal table to store sucess records
DATA:BEGIN OF it_sucess OCCURS 0,
msgtyp(1) TYPE c,
lifnr LIKE ekko-lifnr,
tabix LIKE sy-tabix,
sucess_rec(125),
END OF it_sucess.
DATA: g_mess(125) type c.
*-----Internal table to store error records
DATA:BEGIN OF it_error OCCURS 0,
msgtyp(1) TYPE c,
lifnr LIKE ekko-lifnr,
tabix LIKE sy-tabix,
error_rec(125),
END OF it_error.
----
Selection screen
----
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS session RADIOBUTTON GROUP ctu. "create session
SELECTION-SCREEN COMMENT 3(20) text-s07 FOR FIELD session.
SELECTION-SCREEN POSITION 45.
PARAMETERS ctu RADIOBUTTON GROUP ctu. "call transaction
SELECTION-SCREEN COMMENT 48(20) text-s08 FOR FIELD ctu.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 3(20) text-s01 FOR FIELD group.
SELECTION-SCREEN POSITION 25.
PARAMETERS group(12). "group name of session
SELECTION-SCREEN COMMENT 48(20) text-s05 FOR FIELD ctumode.
SELECTION-SCREEN POSITION 70.
PARAMETERS ctumode LIKE ctu_params-dismode DEFAULT 'N'.
"A: show all dynpros
"E: show dynpro on error only
"N: do not display dynpro
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 48(20) text-s06 FOR FIELD cupdate.
SELECTION-SCREEN POSITION 70.
PARAMETERS cupdate LIKE ctu_params-updmode DEFAULT 'L'.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 3(20) text-s03 FOR FIELD keep.
SELECTION-SCREEN POSITION 25.
PARAMETERS: keep AS CHECKBOX. "' ' = delete session if finished
"'X' = keep session if finished
SELECTION-SCREEN COMMENT 48(20) text-s09 FOR FIELD e_group.
SELECTION-SCREEN POSITION 70.
PARAMETERS e_group(12). "group name of error-session
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 51(17) text-s03 FOR FIELD e_keep.
SELECTION-SCREEN POSITION 70.
PARAMETERS: e_keep AS CHECKBOX. "' ' = delete session if finished
"'X' = keep session if finished
SELECTION-SCREEN END OF LINE.
PARAMETERS:p_file LIKE rlgrap-filename.
----
at selection screen *
----
AT SELECTION-SCREEN.
group and user must be filled for create session
IF SESSION = 'X' AND
GROUP = SPACE. "OR USER = SPACE.
MESSAGE E613(MS).
ENDIF.
----
create batchinput session *
----
FORM OPEN_GROUP.
IF SESSION = 'X'.
SKIP.
WRITE: /(20) 'Create group'(I01), GROUP.
SKIP.
*----open batchinput group
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = GROUP
USER = sy-uname.
WRITE:/(30) 'BDC_OPEN_GROUP'(I02),
(12) 'returncode:'(I05),
SY-SUBRC.
ENDIF.
ENDFORM. "OPEN_GROUP
----
end batchinput session *
----
FORM CLOSE_GROUP.
IF SESSION = 'X'.
*------close batchinput group
CALL FUNCTION 'BDC_CLOSE_GROUP'.
WRITE: /(30) 'BDC_CLOSE_GROUP'(I04),
(12) 'returncode:'(I05),
SY-SUBRC.
ELSE.
IF E_GROUP_OPENED = 'X'.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
WRITE: /.
WRITE: /(30) 'Fehlermappe wurde erzeugt'(I06).
ENDIF.
ENDIF.
ENDFORM. "CLOSE_GROUP
----
Start new transaction according to parameters *
----
FORM BDC_TRANSACTION USING TCODE TYPE ANY.
DATA: L_SUBRC LIKE SY-SUBRC.
*------batch input session
IF SESSION = 'X'.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = TCODE
TABLES
DYNPROTAB = it_BDCDATA.
WRITE: / 'BDC_INSERT'(I03),
TCODE,
'returncode:'(I05),
SY-SUBRC,
'RECORD:',
SY-INDEX.
ELSE.
REFRESH it_MESSTAB.
CALL TRANSACTION TCODE USING it_BDCDATA
MODE CTUMODE
UPDATE CUPDATE
MESSAGES INTO it_MESSTAB.
L_SUBRC = SY-SUBRC.
WRITE: / 'CALL_TRANSACTION',
TCODE,
'returncode:'(I05),
L_SUBRC,
'RECORD:',
SY-INDEX.
ENDIF.
----
Message handling for Call Transaction *
----
perform subr_mess_hand using g_mess.
*-----Erzeugen fehlermappe
IF L_SUBRC <> 0 AND E_GROUP <> SPACE.
IF E_GROUP_OPENED = ' '.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = E_GROUP
USER = sy-uname
KEEP = E_KEEP.
E_GROUP_OPENED = 'X'.
ENDIF.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = TCODE
TABLES
DYNPROTAB = it_BDCDATA.
ENDIF.
REFRESH it_BDCDATA.
ENDFORM. "BDC_TRANSACTION
----
Form subr_bdc_table *
----
text
----
-->P_0220 text *
-->P_0221 text *
-->P_0222 text *
----
FORM subr_bdc_table USING VALUE(P_0220) TYPE ANY
VALUE(P_0221) TYPE ANY
VALUE(P_0222) TYPE ANY.
CLEAR it_bdcdata.
IF P_0220 = ' '.
CLEAR it_bdcdata.
it_bdcdata-fnam = P_0221.
it_bdcdata-fval = P_0222.
APPEND it_bdcdata.
ELSE.
it_bdcdata-dynbegin = P_0220.
it_bdcdata-program = P_0221.
it_bdcdata-dynpro = P_0222.
APPEND it_bdcdata.
ENDIF.
ENDFORM. " subr_bdc_table
----
Form subr_mess_hand *
----
text *
----
-->P_G_MESS text *
----
FORM subr_mess_hand USING P_G_MESS TYPE ANY.
LOOP AT IT_MESSTAB.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = it_messtab-msgid
LANG = it_messtab-msgspra
NO = it_messtab-msgnr
v1 = it_messtab-msgv1
v2 = it_messtab-msgv2
IMPORTING
MSG = P_G_MESS
EXCEPTIONS
OTHERS = 0.
CASE it_messtab-msgtyp.
when 'E'.
it_error-error_rec = P_G_MESS.
it_error-lifnr = it_me21-lifnr.
it_error-tabix = v_count.
APPEND IT_ERROR.
when 'S'.
it_sucess-sucess_rec = P_G_MESS.
it_sucess-lifnr = it_me21-lifnr.
it_sucess-tabix = v_count.
APPEND IT_SUCESS.
endcase.
ENDLOOP.
Describe table it_sucess lines v_ns.
Describe table it_error lines v_ne.
ENDFORM. " subr_mess_hand
Thanks&Regards,
Phani,
<REMOVED BY MODERATOR>
Edited by: Alvaro Tejada Galindo on Apr 2, 2008 1:52 PM
04-02-2008 6:38 PM
Hai,
Check this.
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 with the help of Poonam on sapfans.com developement forum, 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.
check this links.
For BDC:
[http://myweb.dal.ca/hchinni/sap/bdc_home.htm][http://www.sap-img.com/abap/learning-bdc-programming.htm][http://www.sapdevelopment.co.uk/bdc/bdchome.htm][http://www.sap-img.com/abap/difference-between-batch-input-and-call-transaction-in-bdc.htm][http://help.sap.com/saphelp_47x200/helpdata/en/69/c250684ba111d189750000e8322d00/frameset.htm][http://www.sapbrain.com/TUTORIALS/TECHNICAL/BDC_tutorial.html][http://www.sap-img.com/abap/difference-between-batch-input-and-call-transaction-in-bdc.htm][http://www.sap-img.com/abap/question-about-bdc-program.htm][http://www.itcserver.com/blog/2006/06/30/batch-input-vs-call-transaction/][http://www.planetsap.com/bdc_main_page.htm][ ]
<REMOVED BY MODERATOR>
Thanks& Regards,
Kalyan.
Edited by: Alvaro Tejada Galindo on Apr 2, 2008 3:11 PM