0% found this document useful (0 votes)
228 views4 pages

SAP BDC Data Upload Script

The document describes uploading data from a file into an ABAP program using BDC functions. It defines data structures to hold the uploaded data and BDC data. It then uploads the file, loops through the uploaded records, performs BDC functions to navigate screens and enter data, and inserts the transactions using BDC_INSERT.

Uploaded by

Sanjay P
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
228 views4 pages

SAP BDC Data Upload Script

The document describes uploading data from a file into an ABAP program using BDC functions. It defines data structures to hold the uploaded data and BDC data. It then uploads the file, loops through the uploaded records, performs BDC functions to navigate screens and enter data, and inserts the transactions using BDC_INSERT.

Uploaded by

Sanjay P
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

report ZSESSION_1

no standard page heading line-size 255.


TYPES: BEGIN OF TY_FINAL,
BUKRS TYPE BUKRS,
EKORG TYPE EKORG,
KTOKK TYPE KTOKK,
ANRED TYPE ANRED,
NAME1 TYPE NAME1,
SORTL TYPE SORTL,
AKONT TYPE AKONT,
WAERS TYPE WAERS,
END OF TY_FINAL.
DATA : IT_FINAL TYPE TABLE OF TY_FINAL,
WA_FINAL TYPE TY_FINAL.
DATA : IT_BDCDATA TYPE TABLE OF BDCDATA,
WA_BDCDATA TYPE BDCDATA.
*include bdcrecx1.
start-of-selection.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT
= SY-MANDT
* DEST
= FILLER8
GROUP
= 'SANJU'
* HOLDDATE
= FILLER8
KEEP
= 'X'
USER
= SY-UNAME
* RECORD
= FILLER1
* PROG
= SY-CPROG
* DCPFM
= '%'
* DATFM
= '%'
* IMPORTING
* QID
=
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.
*perform open_group.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING

filename
= 'D:\BDCXK.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
= IT_FINAL
* 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 'DATA UPLOAD' TYPE 'I'.
ENDIF.
*

LOOP AT IT_FINAL INTO WA_FINAL.


perform bdc_dynpro
perform bdc_field
perform bdc_field
perform bdc_field
perform bdc_field
perform bdc_field
perform bdc_dynpro
perform bdc_field
perform bdc_field
perform bdc_field

using 'SAPMF02K' '0100'.


using 'BDC_CURSOR'
'RF02K-KTOKK'.
using 'BDC_OKCODE'
'/00'.
using 'RF02K-BUKRS'
WA_FINAL-BUKRS."'1000'.
using 'RF02K-EKORG'
WA_FINAL-EKORG."'1000'.
using 'RF02K-KTOKK'
WA_FINAL-KTOKK."'CPD'.
using 'SAPMF02K' '0110'.
using 'BDC_CURSOR'
'LFA1-SORTL'.
using 'BDC_OKCODE'
'/00'.
using 'LFA1-ANRED'
WA_FINAL-ANRED."'mr'.

perform bdc_field

using 'LFA1-NAME1'
WA_FINAL-NAME1."'jaggu'.
perform bdc_field
using 'LFA1-SORTL'
WA_FINAL-SORTL."'JAG'.
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'
'LFA1-LNRZA'.
perform bdc_field
using 'BDC_OKCODE'
'=ENTR'.
perform bdc_dynpro
using 'SAPMF02K' '0210'.
perform bdc_field
using 'BDC_CURSOR'
'LFB1-AKONT'.
perform bdc_field
using 'BDC_OKCODE'
'/00'.
perform bdc_field
using 'LFB1-AKONT'
WA_FINAL-AKONT."'31000'.
perform bdc_dynpro
using 'SAPMF02K' '0215'.
perform bdc_field
using 'BDC_CURSOR'
'LFB1-ZTERM'.
perform bdc_field
using 'BDC_OKCODE'
'/00'.
perform bdc_dynpro
using 'SAPMF02K' '0220'.
perform bdc_field
using 'BDC_CURSOR'
'LFB1-BUSAB'.
perform bdc_field
using 'BDC_OKCODE'
'/00'.
perform bdc_dynpro
using 'SAPMF02K' '0310'.
perform bdc_field
using 'BDC_CURSOR'
'LFM1-WAERS'.
perform bdc_field
using 'BDC_OKCODE'
'/00'.
perform bdc_field
using 'LFM1-WAERS'
WA_FINAL-WAERS."'inr'.
perform bdc_dynpro
using 'SAPMF02K' '0320'.
perform bdc_field
using 'BDC_CURSOR'
'RF02K-LIFNR'.
perform bdc_field
using 'BDC_OKCODE'
'=ENTR'.
*perform bdc_transaction using 'XK01'.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE
= 'XK01'
* POST_LOCAL
= NOVBLOCAL
* PRINTING
= NOPRINT
* SIMUBATCH
= ' '
* CTUPARAMS
= ' '
TABLES
dynprotab
= IT_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.
*perform close_group.
REFRESH IT_BDCDATA.
ENDLOOP.
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN
= 1
QUEUE_ERROR
= 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.
*----------------------------------------------------------------------*
*
Start new screen
*
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR WA_BDCDATA.
WA_BDCDATA-PROGRAM = PROGRAM.
WA_BDCDATA-DYNPRO = DYNPRO.
WA_BDCDATA-DYNBEGIN = 'X'.
APPEND WA_BDCDATA TO IT_BDCDATA.
ENDFORM.
*----------------------------------------------------------------------*
*
Insert field
*
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
* IF FVAL <> NODATA.
CLEAR WA_BDCDATA.
WA_BDCDATA-FNAM = FNAM.
WA_BDCDATA-FVAL = FVAL.
APPEND WA_BDCDATA TO IT_BDCDATA.
* ENDIF.
ENDFORM.

You might also like