Wednesday, May 25, 2011

BDC using Session method.

Go sm35.

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..


report zbdcxk01
no standard page heading line-size 255.

*include bdcrecx1.

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: i_record type table of ty_record,
w_record type ty_record.

DATA : I_BDCDATA TYPE TABLE OF BDCDATA,
W_BDCDATA TYPE BDCDATA.


DATA: CLIENT TYPE APQI-MANDANT," SY-MANDT Client
DEST TYPE APQI-DESTSYS ,"FILLER8 Target system for ODC/no longer relevant
GROUP TYPE APQI-GROUPID," FILLER12 Session name
HOLDDATE TYPE APQI-STARTDATE," FILLER8 Session locked until specified date
KEEP TYPE APQI-QERASE," FILLER1 Indicator to keep processed sessions
USER TYPE APQI-USERID," FILLER12 Batch input user
RECORD TYPE APQI-PUTACTIVE," FILLER1 Indicator: BI recording ('X' or ' ')
PROG TYPE APQI-PROGID," SY-CPROG Creator Program
DCPFM TYPE USDEFAULTS-DCPFM," '%' Decimal Character Used
DATFM TYPE USDEFAULTS-DATFM." '%' Date Format Used

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.

perform open_group.

LOOP AT I_RECORD INTO W_RECORD.
*do.
CLEAR : I_BDCDATA[].



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.
perform close_group.


FORM OPEN_GROUP.

GROUP = 'RAVINDRA_SESS'.
USER = SY-UNAME.
KEEP = 'X'.
*HOLDDATE = ''.

* open batchinput group
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING CLIENT = SY-MANDT
GROUP = GROUP
USER = USER
KEEP = KEEP.
* HOLDDATE = HOLDDATE.
WRITE: /(30) 'BDC_OPEN_GROUP'(I02),
(12) 'returncode:'(I05),
SY-SUBRC.

ENDFORM.

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.
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.
* ENDIF.
ENDFORM.

FORM BDC_TRANSACTION USING TCODE.

CALL FUNCTION 'BDC_INSERT'
EXPORTING TCODE = TCODE
TABLES DYNPROTAB = I_BDCDATA.

ENDFORM.
FORM CLOSE_GROUP.
* close batchinput group
CALL FUNCTION 'BDC_CLOSE_GROUP'.
WRITE: /(30) 'BDC_CLOSE_GROUP'(I04),
(12) 'returncode:'(I05),
SY-SUBRC.

ENDFORM.

Note: data will not be save in SAPDB.

go to sm35.

check the session name.

process the session.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.