‎2008 Apr 01 8:28 AM
Hi
Can anyone of you give me an simple example of BDC Direct Input method.
Vijay
‎2008 Apr 01 9:36 AM
Hi,
Try this example
{REPORT ZBDC_TRANSACTION .
TABLES:
bdcdata.
DATA :
message TYPE bdcmsgcoll,
msg(72) TYPE c.
DATA:
t_bdcdata TYPE STANDARD
TABLE OF bdcdata.
DATA:
BEGIN OF fs_material,
mbrsh TYPE c,
mtart(3) TYPE c,
maktx(10) TYPE c,
MEINS(10) TYPE c,
END OF fs_material.
DATA
t_messages LIKE STANDARD TABLE
OF bdcmsgcoll.
DATA:
t_material LIKE STANDARD TABLE
OF fs_material.
START-OF-SELECTION.
PERFORM get_data.
PERFORM create_material.
This subroutine is used to get data into internal table
FORM get_data .
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:\material_data.txt'
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = t_material
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. " IF sy-subrc 0.
ENDFORM. " get_data
This subroutine is used to call and fill data
FORM call_screen USING value(p_0065) type c
value(p_0066) type n .
CLEAR bdcdata.
bdcdata-program = p_0065.
bdcdata-dynpro = p_0066.
bdcdata-dynbegin = 'X'.
APPEND bdcdata TO t_bdcdata.
ENDFORM. " call_screen
This subroutine is used to fill data in fields
FORM fill_data USING value(p_0120)
value(p_0121).
CLEAR bdcdata.
bdcdata-fnam = p_0120.
bdcdata-fval = p_0121.
APPEND bdcdata TO t_bdcdata.
ENDFORM. " FILL_DATA
This form is used to create material trnasaction by using call transaction method.
FORM create_material .
LOOP AT t_material INTO fs_material.
PERFORM call_screen USING 'SAPLMGMM'
'0060'.
PERFORM fill_data USING 'RMMG1-MBRSH'
fs_material-mbrsh.
PERFORM fill_data USING 'RMMG1-MTART'
fs_material-mtart.
PERFORM fill_data USING 'BDC_OKCODE' '/00'.
PERFORM call_screen USING 'SAPLMGMM'
'0070'.
PERFORM fill_data USING 'MSICHTAUSW-KZSEL(01)' 'X'.
PERFORM fill_data USING 'MSICHTAUSW-KZSEL(02)' 'X'.
PERFORM fill_data USING 'BDC_OKCODE' '/00'.
PERFORM call_screen USING 'SAPLMGMM' '4004'.
PERFORM fill_data USING 'MAKT-MAKTX'
fs_material-maktx.
PERFORM fill_data USING 'MARA-MEINS'
fs_material-MEINS.
PERFORM fill_data USING 'BDC_OKCODE' '/00'.
PERFORM call_screen USING 'SAPLMGMM' '4004'.
PERFORM fill_data USING 'BDC_OKCODE' '=BU'.
CALL TRANSACTION 'MM01' USING t_bdcdata MODE 'A'.
ENDLOOP.
LOOP AT t_messages INTO message.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = message-msgid
lang = 'EN'
no = message-msgnr
v1 = message-msgv1
v2 = message-msgv2
v3 = message-msgv3
v4 = message-msgv4
IMPORTING
msg = msg
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc EQ 0.
WRITE / msg.
ENDIF. " IF sy-subrc EQ 0.
ENDLOOP.
}
If it is useful, reward points
Thanks,
Prasnna
‎2008 Apr 01 9:40 AM
Direct Input method is used for bulk transfer of data into SAP system.It results in faster execution since no screens are processed and the SAP database will be updated directly using the standard function modules.
Better example where direct input method will be used is... uploading the data for material master.....it includes lot of views so its very much difficult to capture all the views and record the tcode and map the data in such conditions its better to go with DI methods
Advantages:
in session method or Call Transaction method while uploading the data u do the validation by fallowing the screen sequence and field sequence where as in Direct Input validations can be done set of code so this make the process very fast so its advantageous to upload large amout of data.
you always use the standard sap provided program for this.
Here in Direct Input method very important thing is structure of flat file... so to know the structure first of all you have to download the data for one record into the internal table with the use of the same program then with the use of that structure u have to desing the flat file and upload the data.
Check this link for sample code to upload Material Master data, Direct Input Program is RMDATIND
http://www.sap123.com/showthread.php?p=159
RFBIBLOO FI Can be switched between direct input,batch input and CALL TRANSACTION. Posts documents.
RMDATIND MM Direct input. Imports material master records.
RVAFSSOO SD Direct input. Generates SD billing documents and FI follow-on documents from an external file.
http://aspalliance.com/articleViewer
Reward points..
‎2008 Apr 01 10:28 AM
One very good example of the direct input method is the function module "MATERIAL_MAINTAIN_DARK".This module is used to input all the related attributes of a material from a flat file to SAP(material master). One most important aspect about the direct input method is that the structure of the input flat file, and the method of tracing the errors occuring during the input can be done using the "BAPI_MESSAGE_GETDETAIL" function module, which can capture all the messages occuring during the update.
The direct input method is generally used for bulk data transfer.
Reward points if useful.
Thanks,
Archana
‎2008 Apr 01 10:33 AM
Hi
----
STRUCTURE DECLARATION
----
TYPES : BEGIN OF st_vendor,
ktokk TYPE rf02k-ktokk, "account group
anred TYPE lfa1-anred, "title
name1 TYPE lfa1-name1, "vendor name
sortl TYPE lfa1-sortl, "search term
pstlz TYPE lfa1-pstlz, "postal code
land1 TYPE lfa1-land1, "country
banks TYPE lfbk-banks,
bankl TYPE lfbk-bankl, "bank key
bankn TYPE lfbk-bankn, "account number
END OF st_vendor.
TYPES : BEGIN OF st_success,
lifnr TYPE lfa1-lifnr, "vendor number
name TYPE lfa1-name1, "vendor name
END OF st_success.
TYPES: BEGIN OF st_error,
linno TYPE i, "line number
message TYPE string, "error message
END OF st_error.
----
INTERNAL TABLE DECLARATIONS
WORK AREA DECLARATIONS
----
DATA : it_vendor TYPE STANDARD TABLE OF st_vendor,
wa_vendor TYPE st_vendor,
it_success TYPE STANDARD TABLE OF st_success,
wa_success TYPE st_success,
it_error TYPE STANDARD TABLE OF st_error,
wa_error TYPE st_error,
it_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE,
it_message LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
----
DATA DECLARATION
----
DATA : v_file TYPE string,
v_tcode(4) VALUE 'XK01',
v_index LIKE sy-tabix,
v_totalrec TYPE i,
v_errrec TYPE i,
v_succrec TYPE i.
----
SELECTION SCREEN
----
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_file TYPE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-010.
PARAMETERS p_mode LIKE ctu_params-dismode DEFAULT 'N' .
"A: show all dynpros
"E: show dynpro on error only
"N: do not display dynpro
PARAMETERS p_update LIKE ctu_params-updmode DEFAULT 'S'.
"S: synchronously
"A: asynchronously
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-011.
PARAMETERS : p_group(12) DEFAULT '50871'. "group name for error session
SELECTION-SCREEN END OF BLOCK b3.
----
AT SELECTION SCREEN ON VALUE-REQUEST
----
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.
----
START-OF-SELECTION
----
START-OF-SELECTION.
v_file = p_file.
*gui upload
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = v_file
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = it_vendor
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.
*loadind data into it_bdcdata
LOOP AT it_vendor INTO wa_vendor.
v_index = sy-tabix.
PERFORM load_bdcdata.
----
CALL TRANSACTION
----
CALL TRANSACTION v_tcode USING it_bdcdata
MODE p_mode
UPDATE p_update
MESSAGES INTO it_message.
*reading success
IF sy-subrc = 0.
READ TABLE it_message WITH KEY msgtyp = 'S'.
IF sy-subrc = 0.
wa_success-lifnr = it_message-msgv1.
wa_success-name = wa_vendor-name1.
APPEND wa_success TO it_success.
ENDIF.
ELSE.
*reading errors
READ TABLE it_message WITH KEY msgtyp = 'E'.
IF sy-subrc = 0.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = sy-msgid
no = it_message-msgnr
v1 = it_message-msgv1
v2 = it_message-msgv2
v3 = it_message-msgv3
v4 = it_message-msgv4
IMPORTING
msg = wa_error-message.
wa_error-linno = v_index.
APPEND wa_error TO it_error.
CLEAR wa_error.
ENDIF.
*session opening
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = p_group
holddate = sy-datum
keep = 'X'
user = sy-uname.
*inserting into session
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = 'XK01'
TABLES
dynprotab = it_bdcdata.
*closing session
CALL FUNCTION 'BDC_CLOSE_GROUP'.
ENDIF.
CLEAR: it_bdcdata, it_message.
REFRESH: it_bdcdata, it_message.
ENDLOOP.
----
SUMMARY DISPLAY
----
DESCRIBE TABLE it_vendor LINES v_totalrec.
DESCRIBE TABLE it_error LINES v_errrec.
v_succrec = v_totalrec - v_errrec .
WRITE : /1 text-004 COLOR 1.
WRITE : /2 'Total Records Processed :', 25 v_totalrec,
/2 'Error Records :', 25 v_errrec,
/2 'Successful Records :', 25 v_succrec.
SKIP 2.
WRITE : /1 text-005 COLOR 1.
LOOP AT it_error INTO wa_error.
WRITE:/2 wa_error-linno,
wa_error-message.
ENDLOOP.
SKIP 2.
WRITE : /1 text-009 COLOR 1.
ULINE AT : /2(46).
WRITE :/2 sy-vline ,(10) 'VENDOR NUM' , 15 sy-vline , 17 'VENDOR NAME' , 47 sy-vline.
ULINE AT : /2(46).
LOOP AT it_success INTO wa_success.
WRITE:/2 sy-vline , wa_success-lifnr, 15 sy-vline , 17 wa_success-name , 47 sy-vline.
ENDLOOP.
ULINE AT : /2(46).
&----
*& Form append_bdcdata
&----
FORM append_bdcdata USING p_flag p_fname p_fval.
CLEAR it_bdcdata.
IF p_flag = 'X'.
it_bdcdata-program = p_fname.
it_bdcdata-dynpro = p_fval.
it_bdcdata-dynbegin = 'X'.
APPEND it_bdcdata.
ELSEIF NOT p_fval IS INITIAL.
it_bdcdata-fnam = p_fname.
it_bdcdata-fval = p_fval.
APPEND it_bdcdata.
ENDIF.
ENDFORM. "append_bdcdata
&----
*& Form load_bdcdata
&----
FORM load_bdcdata .
PERFORM append_bdcdata USING : 'X' 'SAPMF02K' '0100',
' ' 'BDC_OKCODE' '/00',
' ' 'RF02K-KTOKK' wa_vendor-ktokk,
'X' 'SAPMF02K' '0110',
' ' 'BDC_OKCODE' '/00',
' ' 'LFA1-ANRED' wa_vendor-anred,
' ' 'LFA1-NAME1' wa_vendor-name1,
' ' 'LFA1-SORTL' wa_vendor-sortl,
' ' 'LFA1-PSTLZ' wa_vendor-pstlz,
' ' 'LFA1-LAND1' wa_vendor-land1,
'X' 'SAPMF02K' '0120',
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02K' '0130',
' ' 'BDC_OKCODE' '=ENTR',
' ' 'LFBK-BANKS(01)' wa_vendor-banks,
' ' 'LFBK-BANKL(01)' wa_vendor-bankl,
' ' 'LFBK-BANKN(01)' wa_vendor-bankn,
'X' 'SAPMF02K' '0130',
' ' 'BDC_OKCODE' '=ENTR',
'X' 'SAPLSPO1' '0300',
' ' 'BDC_OKCODE' '=YES'.
ENDFORM. " load_bdcdata
‎2008 Apr 01 11:56 PM
Hi ,
Direct Input Method:
To enhance the batch input procedure, the system offers the direct input technique, especially for transferring large amounts of data. In contrast to batch input, this technique does not create sessions, but stores the data directly. It does not process screens. To enter the data into the corresponding database tables directly, the system calls a number of function modules that execute any necessary checks. In case of errors, the direct input technique provides a restart mechanism. However, to be able to activate the restart mechanism, direct input programs must be executed in the background only. To maintain and start these programs, use program RBMVSHOW or Transaction BMV0.
Examples for direct input programs are:
Program Application
RFBIBL00 FI
RMDATIND MM
RVAFSS00 SD
RAALTD11 AM
RKEVEXT0 CO-PA
Reward points if helpful.
Thanks and Regards.