Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

BDC For Vd01 Customer

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

USED TO TRANSFER THE DATA FROM THE EXCEL TO ITAB

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'


EXPORTING
*
I_FIELD_SEPERATOR
=
*
I_LINE_HEADER
=
I_TAB_RAW_DATA
= T_RAW
I_FILENAME
= P_FNAME
TABLES
I_TAB_CONVERTED_DATA = T_EORD
EXCEPTIONS
CONVERSION_FAILED
= 1
OTHERS
= 2.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

*FLAT FILE FOR THIS BDC


*050502 1000 10 00 ANIL KUMAR YARRAMASU 8-104-1 ANIL
KOTHAPETA,CHIRALA 523157
*050503 1000 10 00 ANJI BABU MARRIANJI 1-4-1 ANJI KADAVAKUDURU,CRL
523158
*050504 1000 10 00 PRAKASH BABU DOGUPARTHY 4-5-6 PRAK
JANDRAPETA,CHIRALA 523155
*&---------------------------------------------------------------------*
*&Report Z_BDC_VD01
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_BDC_VD01 NO STANDARD PAGE HEADING LINE-SIZE 255.
TYPES : BEGIN OF T_CUST,
KUNNR(10) TYPE C,
VKORG(4) TYPE C,
VTWEG(2) TYPE C,
SPART(2) TYPE C,
NAME1(35) TYPE C,
NAME2(35) TYPE C,
STRAS(35) TYPE C,
SORTL(10) TYPE C,
ORT01(35) TYPE C,
PSTLZ(6) TYPE C,
END OF T_CUST.
TYPES : TT_CUST TYPE STANDARD TABLE OF T_CUST.
DATA : LW_CUST TYPE T_CUST,
LT_CUST TYPE TT_CUST.
TYPES : BEGIN OF T_BDCDATA,
PROGRAM TYPE BDC_PROG,
DYNPRO TYPE BDC_DYNR,
DYNBEGIN TYPE BDC_START,
FNAM TYPE FNAM_____4,

FVAL TYPE BDC_FVAL,


END OF T_BDCDATA.
TYPES : TT_BDCDATA TYPE STANDARD TABLE OF T_BDCDATA.
DATA : LW_BDCDATA TYPE T_BDCDATA,
LT_BDCDATA TYPE TT_BDCDATA.
PARAMETERS : P_FILE TYPE LOCALFILE OBLIGATORY.
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.
PERFORM GET_DATA.
*-- Session method
* performopen_group.
PERFORM OPEN_SESSION.
LOOP AT LT_CUST INTO LW_CUST WHERE KUNNR NE SPACE.
REFRESH LT_BDCDATA.
*-- 1st
PERFORM BDC_DYNPRO
USING 'SAPMF02D' '0107'.
PERFORM BDC_FIELD
USING 'BDC_CURSOR' 'RF02D-KTOKD'.
PERFORM BDC_FIELD
USING 'BDC_OKCODE' '/00'.
PERFORM BDC_FIELD
USING 'RF02D-KUNNR' LW_CUST-KUNNR.
PERFORM BDC_FIELD
USING 'RF02D-VKORG' LW_CUST-VKORG.
PERFORM BDC_FIELD
USING 'RF02D-VTWEG' LW_CUST-VTWEG.
PERFORM BDC_FIELD
USING 'RF02D-SPART' LW_CUST-SPART.
PERFORM BDC_FIELD
USING 'RF02D-KTOKD' '0001'.
* --2nd
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM

BDC_DYNPRO
BDC_FIELD
BDC_FIELD
BDC_FIELD
BDC_FIELD
BDC_FIELD
BDC_FIELD
BDC_FIELD
BDC_FIELD
BDC_FIELD
BDC_FIELD
BDC_FIELD

USING 'SAPMF02D' '0110'.


USING 'BDC_CURSOR' 'KNA1-PSTLZ'.
USING 'BDC_OKCODE' '=VW'.
USING 'KNA1-ANRED' 'Mr.'.
USING 'KNA1-NAME1' LW_CUST-NAME1.
USING 'KNA1-NAME2' LW_CUST-NAME2.
USING 'KNA1-STRAS' LW_CUST-STRAS.
USING 'KNA1-SORTL' LW_CUST-SORTL.
USING 'KNA1-ORT01' LW_CUST-ORT01.
USING 'KNA1-PSTLZ' LW_CUST-PSTLZ.
USING 'KNA1-LAND1' 'IN'.
USING 'KNA1-SPRAS' 'EN'.

* -- 3rd
PERFORM BDC_DYNPRO
USING 'SAPMF02D' '0120'.
PERFORM BDC_FIELD
USING 'BDC_CURSOR' 'KNA1-LZONE'.

PERFORM BDC_FIELD
PERFORM BDC_FIELD

USING 'BDC_OKCODE' '=VW'.


USING 'KNA1-LZONE' '0000000001'.

*-- 4th
PERFORM BDC_DYNPRO
USING 'SAPMF02D' '0125'.
PERFORM BDC_FIELD
USING 'BDC_CURSOR' 'KNA1-NIELS'.
PERFORM BDC_FIELD
USING 'BDC_OKCODE' '=VW'.
*--5th
PERFORM BDC_DYNPRO
USING 'SAPMF02D' '0340'.
PERFORM BDC_FIELD
USING 'BDC_CURSOR' 'RF02D-KUNNR'.
PERFORM BDC_FIELD
USING 'BDC_OKCODE' '=VW'.
*--6th
PERFORM
PERFORM
PERFORM
PERFORM

BDC_DYNPRO
USING 'SAPMF02D' '0370'.
BDC_FIELD
USING 'BDC_CURSOR' 'RF02D-KUNNR'.
BDC_FIELD
USING 'BDC_OKCODE' '=VW'.
BDC_FIELD
USING 'KNA1-CIVVE' 'X'.

*--7th
PERFORM BDC_DYNPRO
USING 'SAPMF02D' '0360'.
PERFORM BDC_FIELD
USING 'BDC_CURSOR' 'KNVK-NAMEV(01)'.
PERFORM BDC_FIELD
USING 'BDC_OKCODE' '=VW'.
*--8th
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM

BDC_DYNPRO
BDC_FIELD
BDC_FIELD
BDC_FIELD
BDC_FIELD
BDC_FIELD

USING 'SAPMF02D' '0310'.


USING 'BDC_CURSOR' 'KNVV-BZIRK'.
USING 'BDC_OKCODE' '=VW'.
USING 'KNVV-AWAHR' '100'.
USING 'KNVV-WAERS' 'EUR'.
USING 'KNVV-KALKS' '1'.

*--9th
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM
PERFORM

BDC_DYNPRO
BDC_FIELD
BDC_FIELD
BDC_FIELD
BDC_FIELD
BDC_FIELD

USING 'SAPMF02D' '0315'.


USING 'BDC_CURSOR' 'KNVV-VSBED'.
USING 'BDC_OKCODE' '=VW'.
USING 'KNVV-KZAZU' 'X'.
USING 'KNVV-VSBED' '01'.
USING 'KNVV-ANTLF' '9'.

*--10th
PERFORM BDC_DYNPRO
USING 'SAPMF02D' '0320'.
PERFORM BDC_FIELD
USING 'BDC_CURSOR' 'KNVV-PERFK'.
PERFORM BDC_FIELD
USING 'BDC_OKCODE' '=VW'.
*--11th
PERFORM
PERFORM
PERFORM
PERFORM

BDC_DYNPRO
USING 'SAPMF02D' '1350'.
BDC_FIELD
USING 'BDC_CURSOR' 'KNVI-TAXKD(01)'.
BDC_FIELD
USING 'BDC_OKCODE' '=UPDA'.
BDC_FIELD
USING 'KNVI-TAXKD(01)' '0'.

*--end of 11
* perform bdc_transaction using 'VD01'.
PERFORM SESSION_METHOD.

CLEAR LW_CUST.
ENDLOOP.
* performclose_group.
PERFORM CLOSE_SESSION.
*&---------------------------------------------------------------------*
*&Form GET_DATA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM GET_DATA .
DATA : L_FNM TYPE STRING.
L_FNM = P_FILE.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME
= L_FNM
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
= LT_CUST
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.
ENDFORM." GET_DATA
*&---------------------------------------------------------------------*
*&Form open_session
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM OPEN_SESSION .
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT
= SY-MANDT
GROUP
= 'ZVD01_SES' "SESS NAME GO TO SM35
KEEP
= 'X'
USER
= 'USER2'
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.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM." open_session
*&---------------------------------------------------------------------*
*&Form CLOSE_SESSION
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM CLOSE_SESSION .
CALL FUNCTION 'BDC_CLOSE_GROUP'.
WRITE : 'Session created process it in sm35'.
ENDFORM." CLOSE_SESSION
*&---------------------------------------------------------------------*
*&Form SESSION_METHOD
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*

* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM SESSION_METHOD .
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE
= 'VD01'
TABLES
DYNPROTAB
= LT_BDCDATA
EXCEPTIONS
INTERNAL_ERROR = 1
NOT_OPEN
=2
QUEUE_ERROR
=3
TCODE_INVALID = 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS
= 7.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM." SESSION_METHOD
*----------------------------------------------------------------------*
*
-->PROGRAM text
*
-->DYNPRO
text
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR LW_BDCDATA.
LW_BDCDATA-PROGRAM = PROGRAM.
LW_BDCDATA-DYNPRO = DYNPRO.
LW_BDCDATA-DYNBEGIN = 'X'.
APPEND LW_BDCDATA TO LT_BDCDATA.
ENDFORM.
"BDC_DYNPRO
*&---------------------------------------------------------------------*
*&Form BDC_FIELD
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->FNAM
text
*
-->FVAL
text
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
CLEAR LW_BDCDATA.
LW_BDCDATA-FNAM = FNAM.
LW_BDCDATA-FVAL = FVAL.
APPEND LW_BDCDATA TO LT_BDCDATA.
ENDFORM.
"BDC_FIELD

You might also like