BDC - Call Transaction
For Developing BDC using CALL TRANSACTION method we need to do the recording of the corresponding transaction using T-Code SHDB usually provided by functional consultant & flat file in which data is stored.
Flat file can be Text file or Excel File.
In CALL TRANSACTION we also have to create the Error Log file.
Here is one simple example of BDC for freshers.
no standard page heading line-size 255.
type-pools: truxs.
*include bdcrecx1.
TYPES: BEGIN OF ty_str,
matnr TYPE mara-matnr,
mbrsh TYPE mara-mbrsh,
mtart TYPE mara-mtart,
maktx TYPE makt-maktx,
meins TYPE mara-meins ,
matkl TYPE MARA-MATKL,
end of ty_str.
data: itab TYPE TABLE OF ty_str.
data: wa TYPE ty_str.
*----------------------------------------------------------------------*
* data definition
*----------------------------------------------------------------------*
* Batchinputdata of single transaction
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
* messages of call transaction
DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
* error session opened (' ' or 'X')
DATA: E_GROUP_OPENED.
* message texts
TABLES: T100.
data: i_tab_raw_data TYPE TRUXS_T_TEXT_DATA.
PARAMETERS: p_file TYPE IBIPPARMS-PATH.
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.
" convert text file to internal table
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR = 'X'
I_LINE_HEADER = 'X'
i_tab_raw_data = i_tab_raw_data
i_filename = p_file
tables
i_tab_converted_data = itab
EXCEPTIONS
CONVERSION_FAILED = 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.
loop at itab into wa.
*perform open_group.
REFRESH BDCDATA.
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MTART'.
perform bdc_field using 'BDC_OKCODE'
'=AUSW'.
perform bdc_field using 'RMMG1-MATNR'
WA-MATNR.
perform bdc_field using 'RMMG1-MBRSH'
WA-MBRSH.
perform bdc_field using 'RMMG1-MTART'
WA-MTART.
perform bdc_dynpro using 'SAPLMGMM' '0070'.
perform bdc_field using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
'X'.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'MAKT-MAKTX'
WA-MAKTX.
perform bdc_field using 'BDC_CURSOR'
'MARA-MATKL'.
perform bdc_field using 'MARA-MEINS'
WA-MEINS.
perform bdc_field using 'MARA-MATKL'
WA-MATKL.
perform bdc_field using 'MARA-MTPOS_MARA'
'NORM'.
*perform bdc_transaction using 'MM01'.
*perform close_group.
*
CALL TRANSACTION 'MM01' USING BDCDATA MODE 'N'
UPDATE 'S' MESSAGES INTO MESSTAB.
PERFORM MESSTAB.
ENDLOOP.
*----------------------------------------------------------------------*
* 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.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form MESSTAB
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form MESSTAB .
DATA: MSG(80) TYPE C.
LOOP AT MESSTAB.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = MESSTAB-MSGID
LANG = SY-LANGU
* NO = MESSTAB-MSGNO
V1 = MESSTAB-MSGV1
V2 = MESSTAB-MSGV2
V3 = MESSTAB-MSGV3
V4 = MESSTAB-MSGV4
IMPORTING
MSG = MSG
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.
WRITE: / MSG.
ENDLOOP.
REFRESH MESSTAB.
endform. " MESSTAB
No comments:
Post a Comment