click on Recording.
click on New Recording.
recording: zbdcxk01.
transaction code:xk01.
give the details.
click on Save.
go to recording again.
select ur Recording name.
click on program.
give program name.
u will get the program thr..
include bdcrecx1.---this include contains the 2 method call transaction and session method.
PROGRAM ::
report zbdcxk01 no standard page heading line-size 255.
types: begin of ty_record,
* data element: LIF16
LIFNR TYPE LIFNR,
* data element: KTOKK
KTOKK TYPE KTOKK,
* data element: ANRED
ANRED TYPE ANRED,
* data element: NAME1_GP
NAME1 TYPE NAME1,
* data element: SORTL
SORTL TYPE SORTL,
* data element: LAND1_GP
LAND1 TYPE LAND1,
end of ty_record.
* data element: LIF16
LIFNR TYPE LIFNR,
* data element: KTOKK
KTOKK TYPE KTOKK,
* data element: ANRED
ANRED TYPE ANRED,
* data element: NAME1_GP
NAME1 TYPE NAME1,
* data element: SORTL
SORTL TYPE SORTL,
* data element: LAND1_GP
LAND1 TYPE LAND1,
end of ty_record.
data: i_record type table of ty_record,
w_record type ty_record.
DATA : I_BDCDATA TYPE TABLE OF BDCDATA,
W_BDCDATA TYPE BDCDATA.
DATA: I_MESSTAB TYPE TABLE OF BDCMSGCOLL,
W_MESSTAB TYPE BDCMSGCOLL.
DATA : IT_FILE type table of ALSMEX_TABLINE, "if data is brought from Excel sheet
wa_file type ALSMEX_TABLINE. "if data is brought from Excel sheet
w_record type ty_record.
DATA : I_BDCDATA TYPE TABLE OF BDCDATA,
W_BDCDATA TYPE BDCDATA.
DATA: I_MESSTAB TYPE TABLE OF BDCMSGCOLL,
W_MESSTAB TYPE BDCMSGCOLL.
DATA : IT_FILE type table of ALSMEX_TABLINE, "if data is brought from Excel sheet
wa_file type ALSMEX_TABLINE. "if data is brought from Excel sheet
start-of-selection.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = 'C:\Users\mouriuser54\Desktop\Ravi_XK01_INPUTDATA.XLSX'
I_BEGIN_COL = '1'
I_BEGIN_ROW = '1'
I_END_COL = '6'
I_END_ROW = '10'
TABLES
INTERN = IT_FILE
* EXCEPTIONS
* INCONSISTENT_PARAMETERS = 1
* UPLOAD_OLE = 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.
loop at it_file into wa_file.
case wa_file-col.
when 1.
w_record-LIFNR = wa_file-value.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = w_record-LIFNR
IMPORTING
OUTPUT = w_record-LIFNR
.
when 2.
w_record-KTOKK = wa_file-value.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = w_record-KTOKK
IMPORTING
OUTPUT = w_record-KTOKK.
when 3.
w_record-ANRED = wa_file-value.
when 4.
w_record-NAME1 = wa_file-value.
when 5.
w_record-SORTL = wa_file-value.
when 6.
w_record-LAND1 = wa_file-value.
endcase.
at end of row.
append w_record to i_record.
clear w_record.
endat.
endloop.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = 'C:\Users\mouriuser54\Desktop\Ravi_XK01_INPUTDATA.XLSX'
I_BEGIN_COL = '1'
I_BEGIN_ROW = '1'
I_END_COL = '6'
I_END_ROW = '10'
TABLES
INTERN = IT_FILE
* EXCEPTIONS
* INCONSISTENT_PARAMETERS = 1
* UPLOAD_OLE = 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.
loop at it_file into wa_file.
case wa_file-col.
when 1.
w_record-LIFNR = wa_file-value.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = w_record-LIFNR
IMPORTING
OUTPUT = w_record-LIFNR
.
when 2.
w_record-KTOKK = wa_file-value.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = w_record-KTOKK
IMPORTING
OUTPUT = w_record-KTOKK.
when 3.
w_record-ANRED = wa_file-value.
when 4.
w_record-NAME1 = wa_file-value.
when 5.
w_record-SORTL = wa_file-value.
when 6.
w_record-LAND1 = wa_file-value.
endcase.
at end of row.
append w_record to i_record.
clear w_record.
endat.
endloop.
*use it for text file loading.
*CALL FUNCTION 'GUI_UPLOAD'
* EXPORTING
* FILENAME = 'C:\Users\mouriuser54\Desktop\Ravi_XK01.TXT'
* 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 =
** NO_AUTH_CHECK = ' '
** IMPORTING
** FILELENGTH =
** HEADER =
* TABLES
* DATA_TAB = i_record[]
* 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.
* EXPORTING
* FILENAME = 'C:\Users\mouriuser54\Desktop\Ravi_XK01.TXT'
* 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 =
** NO_AUTH_CHECK = ' '
** IMPORTING
** FILELENGTH =
** HEADER =
* TABLES
* DATA_TAB = i_record[]
* 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 I_RECORD INTO W_RECORD.
*do.
CLEAR : I_BDCDATA[].
*read dataset dataset into record.
*if sy-subrc <> 0. exit. endif.
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'
W_RECORD-LIFNR.
perform bdc_field using 'RF02K-KTOKK'
W_RECORD-KTOKK.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-LAND1'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFA1-ANRED'
W_RECORD-ANRED.
perform bdc_field using 'LFA1-NAME1'
W_RECORD-NAME1.
perform bdc_field using 'LFA1-SORTL'
W_RECORD-SORTL.
perform bdc_field using 'LFA1-LAND1'
W_RECORD-LAND1.
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-BANKS(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_dynpro using 'SAPMF02K' '0380'.
perform bdc_field using 'BDC_CURSOR'
'KNVK-NAMEV(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_transaction using 'XK01'.
CLEAR : W_RECORD.
ENDLOOP.
*do.
CLEAR : I_BDCDATA[].
*read dataset dataset into record.
*if sy-subrc <> 0. exit. endif.
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'
W_RECORD-LIFNR.
perform bdc_field using 'RF02K-KTOKK'
W_RECORD-KTOKK.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-LAND1'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFA1-ANRED'
W_RECORD-ANRED.
perform bdc_field using 'LFA1-NAME1'
W_RECORD-NAME1.
perform bdc_field using 'LFA1-SORTL'
W_RECORD-SORTL.
perform bdc_field using 'LFA1-LAND1'
W_RECORD-LAND1.
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-BANKS(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_dynpro using 'SAPMF02K' '0380'.
perform bdc_field using 'BDC_CURSOR'
'KNVK-NAMEV(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_transaction using 'XK01'.
CLEAR : W_RECORD.
ENDLOOP.
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR W_BDCDATA.
W_BDCDATA-PROGRAM = PROGRAM.
W_BDCDATA-DYNPRO = DYNPRO.
W_BDCDATA-DYNBEGIN = 'X'.
APPEND W_BDCDATA TO I_BDCDATA.
CLEAR W_BDCDATA.
ENDFORM.
FORM BDC_FIELD USING FNAM FVAL.
* IF FVAL <> NODATA.
CLEAR W_BDCDATA.
W_BDCDATA-FNAM = FNAM.
W_BDCDATA-FVAL = FVAL.
APPEND W_BDCDATA TO I_BDCDATA.
CLEAR W_BDCDATA.
* ENDIF.
ENDFORM.
CLEAR W_BDCDATA.
W_BDCDATA-PROGRAM = PROGRAM.
W_BDCDATA-DYNPRO = DYNPRO.
W_BDCDATA-DYNBEGIN = 'X'.
APPEND W_BDCDATA TO I_BDCDATA.
CLEAR W_BDCDATA.
ENDFORM.
FORM BDC_FIELD USING FNAM FVAL.
* IF FVAL <> NODATA.
CLEAR W_BDCDATA.
W_BDCDATA-FNAM = FNAM.
W_BDCDATA-FVAL = FVAL.
APPEND W_BDCDATA TO I_BDCDATA.
CLEAR W_BDCDATA.
* ENDIF.
ENDFORM.
FORM BDC_TRANSACTION USING TCODE.
CALL TRANSACTION TCODE USING I_BDCDATA
MODE 'N'"CTUMODE'
UPDATE 'S'"CUPDATE
MESSAGES INTO I_MESSTAB.
ENDFORM.
Note: take always new data and once data is entered it will save in SAPDB.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.