7.11 - Data Interface Exercises Solutions
7.11 - Data Interface Exercises Solutions
0
SAP Development ABAP Training
Chapter 1
Exercise 1
Examining the background job in the Job Overview should indicate that this background job
executed successfully. Its status will be Finished.
Exercise 2
Examining the background job in the Job Overview should indicate that this background job
executed successfully. Its status will be Finished.
Exercise 3
Examining the background job in the Job Overview should indicate that this background job
executed successfully. Its status will be Finished.
Exercise 4
Examining the background job in the Job Overview should indicate that this background job did
not execute successfully. Its status will be Cancelled. If you analyze the job log, you will see
the message Error opening file - No such file or directory. This message is message number
020 from message class YTRABAPMSG. Because of this message, the job was cancelled.
Page 1
Dec-2008
ECC 6.0
SAP Development ABAP Training
Exercise 5
Examining the background job in the Job Overview should indicate that this background job
executed successfully. Its status will be Finished.
REPORT YDIXX1_5.
PARAMETERS:JOBNAME TYPE TBTCO-JOBNAME DEFAULT 'ABAPxxJOB5'.
DATA:
Page 2
Dec-2008
ECC 6.0
SAP Development ABAP Training
ELSE.
WRITE: / 'Error with JOB_SUBMIT - SY-SUBRC =', SY-SUBRC.
ENDIF.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
JOBCOUNT
= JOBCOUNT
JOBNAME
= JOBNAME
STRTIMMED
= 'X'.
*EXCEPTIONS
*CANT_START_IMMEDIATE
=1
*. . .
*OTHERS
= 8.
IF SY-SUBRC = 0.
WRITE: / 'Job closed successfully'.
ELSE.
WRITE: / 'Error with JOB_CLOSE - SY-SUBRC =', SY-SUBRC.
ENDIF.
Page 3
Dec-2008
ECC 6.0
SAP Development ABAP Training
Chapter 2
Exercise 1
REPORT YDIXX2_1.
CONSTANTS: OUTFILE(30) TYPE C VALUE './file1xx'.
DATA: WA_YVENDOR TYPE YVENDOR.
DATA: BEGIN OF OUTREC,
VENDNUM
TYPE YVENDOR-VENDNUM,
COMPANY
TYPE YVENDOR-COMPANY,
ACCTGROUP
TYPE YVENDOR-ACCTGROUP,
NAME
TYPE YVENDOR-NAME,
SORT
TYPE YVENDOR-SORT,
CITY
TYPE YVENDOR-CITY,
ZIPCODE
TYPE YVENDOR-ZIPCODE,
COUNTRY
TYPE YVENDOR-COUNTRY,
REGION
TYPE YVENDOR-REGION,
LANG
TYPE YVENDOR-LANG,
END OF OUTREC.
START-OF-SELECTION.
OPEN DATASET OUTFILE FOR OUTPUT IN TEXT MODE ENCODING .
SELECT VENDNUM
COMPANY
ACCTGROUP
NAME
SORT
CITY
ZIPCODE
COUNTRY
REGION
LANG
FROM YVENDOR INTO WA_YVENDOR WHERE UNAME = SY-UNAME.
OUTREC-VENDNUM = WA_YVENDOR-VENDNUM.
OUTREC-COMPANY = WA_YVENDOR-COMPANY.
OUTREC-ACCTGROUP = WA_YVENDOR-ACCTGROUP.
OUTREC-NAME
= WA_YVENDOR-NAME.
OUTREC-SORT
= WA_YVENDOR-SORT
.
OUTREC-CITY
= WA_YVENDOR-CITY.
OUTREC-ZIPCODE = WA_YVENDOR-ZIPCODE.
OUTREC-COUNTRY = WA_YVENDOR-COUNTRY.
OUTREC-REGION = WA_YVENDOR-REGION.
OUTREC-LANG
= WA_YVENDOR-LANG.
Page 4
Dec-2008
ECC 6.0
SAP Development ABAP Training
Page 5
Dec-2008
ECC 6.0
SAP Development ABAP Training
Exercise 2
REPORT YDIXX2_2.
CONSTANTS: INFILE(30) TYPE C VALUE './file1xx'.
DATA: BEGIN OF INREC,
VENDNUM
TYPE
YVENDOR-VENDNUM,
COMPANY
TYPE
YVENDOR-COMPANY,
ACCTGROUP
TYPE
YVENDOR-ACCTGROUP,
NAME
TYPE
YVENDOR-NAME,
SORT
TYPE
YVENDOR-SORT,
CITY
TYPE
YVENDOR-CITY,
ZIPCODE
TYPE
YVENDOR-ZIPCODE,
COUNTRY
TYPE
YVENDOR-COUNTRY,
REGION
TYPE
YVENDOR-REGION,
LANG
TYPE
YVENDOR-LANG,
END OF INREC.
START-OF-SELECTION.
OPEN DATASET INFILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.
DO.
READ DATASET INFILE INTO INREC.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
WRITE:
/ 'Vendor #
:',
INREC-VENDNUM,
/ 'Company Code :',
INREC-COMPANY,
/ 'Account Group :',
INREC-ACCTGROUP,
/ 'Name
:',
INREC-NAME,
/ 'Sort term :',
INREC-SORT,
/ 'City
:', INREC-CITY,
/ 'Zipcode
:',
INREC-ZIPCODE,
/ 'Country
:',
INREC-COUNTRY,
/ 'Region
:',
INREC-REGION,
/ 'Language
:',
INREC-LANG.
ULINE.
ENDDO.
CLOSE DATASET INFILE.
Exercise 3
REPORT YDIXX2_3.
CONSTANTS: OUTFILE(30) TYPE C VALUE './file2xx'.
PARAMETERS:CUSTNUM TYPE KUNNR
DEFAULT 'ABAPxx-001',
Page 6
Dec-2008
ECC 6.0
SAP Development ABAP Training
Page 7
Dec-2008
ECC 6.0
SAP Development ABAP Training
Exercise 4
REPORT YDIXX2_4.
CONSTANTS: INFILE(30) TYPE C VALUE './file2xx'.
DATA: BEGIN OF INREC,
CUSTNUM
TYPE KUNNR,
NAME
TYPE NAME1,
STREET
TYPE STRAS,
PHONE
TYPE TELF1,
FAX
TYPE TELFX,
END OF INREC.
START-OF-SELECTION.
OPEN DATASET INFILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.
DO.
READ DATASET INFILE INTO INREC.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
WRITE:
/ 'Name
:',
/ 'Street :',
/ 'Phone :',
/ 'Fax
:',
ULINE.
ENDDO.
Page 8
Dec-2008
ECC 6.0
SAP Development ABAP Training
Chapter 3
Exercise 1
REPORT YDIXX3_1 .
TYPES:
BEGIN OF OUTREC,
VENDNUM
TYPE YVENDOR-VENDNUM,
COMPANY
TYPE YVENDOR-COMPANY,
ACCTGROUP
TYPE YVENDOR-ACCTGROUP,
NAME
TYPE YVENDOR-NAME,
SORT
TYPE YVENDOR-SORT,
CITY
TYPE YVENDOR-CITY,
ZIPCODE
TYPE YVENDOR-ZIPCODE,
COUNTRY
TYPE YVENDOR-COUNTRY,
REGION
TYPE YVENDOR-REGION,
LANG
TYPE YVENDOR-LANG,
END OF OUTREC.
DATA: OUT_ITAB TYPE STANDARD TABLE OF OUTREC,
WA_OUT_ITAB TYPE OUTREC.
START-OF-SELECTION.
SELECT VENDNUM
COMPANY
ACCTGROUP
NAME
SORT
CITY
ZIPCODE
COUNTRY
REGION
LANG
FROM YVENDOR INTO TABLE OUT_ITAB WHERE USERNAME = SY-UNAME.
IF SY-SUBRC = 0.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE
=
FILENAME
= 'c:\file3xx'
FILETYPE
= 'ASC'
* APPEND
=''
* WRITE_FIELD_SEPARATOR
=''
Page 9
Dec-2008
ECC 6.0
SAP Development ABAP Training
TABLES
DATA_TAB
= OUT_ITAB
* FIELDNAMES
=
* EXCEPTIONS
* FILE_WRITE_ERROR
=1
* NO_BATCH
=2
* GUI_REFUSE_FILETRANSFER
=3
* INVALID_TYPE
=4
* NO_AUTHORITY
=5
* UNKNOWN_ERROR
=6
* HEADER_NOT_ALLOWED
=7
* SEPARATOR_NOT_ALLOWED
=8
* FILESIZE_NOT_ALLOWED
=9
* HEADER_TOO_LONG
= 10
* DP_ERROR_CREATE
= 11
* DP_ERROR_SEND
= 12
* DP_ERROR_WRITE
= 13
* UNKNOWN_DP_ERROR
= 14
* ACCESS_DENIED
= 15
* DP_OUT_OF_MEMORY
= 16
* DISK_FULL
= 17
* DP_TIMEOUT
= 18
* FILE_NOT_FOUND
= 19
* DATAPROVIDER_EXCEPTION
= 20
* CONTROL_FLUSH_ERROR
= 21
* OTHERS
= 22
.
IF SY-SUBRC <> 0.
WRITE: / 'Internal table transferred to file'.
ELSE.
WRITE: / 'Error transferring internal table to file'.
ENDIF.
ELSE.
WRITE: / 'No records transferred to file'.
ENDIF.
Exercise 2
REPORT YDIXX3_2 .
TYPES:
BEGIN OF INREC,
VENDNUM
TYPE YVENDOR-VENDNUM,
COMPANY
TYPE YVENDOR-COMPANY,
ACCTGROUP
TYPE YVENDOR-ACCTGROUP,
NAME
TYPE YVENDOR-NAME,
Page 10
Dec-2008
ECC 6.0
SAP Development ABAP Training
SORT
CITY
ZIPCODE
COUNTRY
REGION
LANG
END OF INREC.
TYPE YVENDOR-SORT,
TYPE YVENDOR-CITY,
TYPE YVENDOR-ZIPCODE,
TYPE YVENDOR-COUNTRY,
TYPE YVENDOR-REGION,
TYPE YVENDOR-LANG,
Page 11
Dec-2008
ECC 6.0
SAP Development ABAP Training
/
/
/
/
/
'City
:', WA_IN_ITAB-CITY,
'Zipcode
:', WA_IN_ITAB-ZIPCODE,
'Country
:', WA_IN_ITAB-COUNTRY,
'Region
:', WA_IN_ITAB-REGION,
'Language
:', WA_IN_ITAB-LANG,
ULINE.
ENDLOOP.
IF SY-SUBRC <> 0.
WRITE: / 'No entries in internal table'.
ENDIF.
ELSE.
WRITE: / 'Error transferring file to internal table'.
ENDIF.
Page 12
Dec-2008
ECC 6.0
SAP Development ABAP Training
Chapter 4
Exercise 1
Create Vendor Transaction Code: FK01
PROGRAM
DYNPRO
DYNBEGIN
SAPMF02K
0105
SAPMF02K
SAPMF02K
0110
0120 *
FNAM
FVAL
RF02K-LIFNR
ABAPxx-nnn
RF02K-BUKRS
0001
RF02K-KTOKK
0001
BDC_OKCODE
/00
LFA1-NAME1
Vendor
LFA1-SORTL
NUM
LFA1-ORT01
Miami
LFA1-PSTLZ
33143
LFA1-LAND1
US
LFA1-REGIO
FL
LFA1-SPRAS
EN
BDC_OKCODE **
=UPDA
Even though you are not filling any fields on screen 0120, you still have to reference it
because you must pass through it when proceeding in the transaction.
** We can save the record on screen 0120 because we do not have to fill any more fields.
Page 13
Dec-2008
ECC 6.0
SAP Development ABAP Training
Exercise 2
REPORT YDIXX4_2.
DATA: BDC_TAB TYPE STANDARD TABLE OF BDCDATA ,
WA_BDC_TAB TYPE BDCDATA.
START-OF-SELECTION.
PERFORM FILL_BDC_TAB.
*
The remaining code just creates a list with the contents of bdc_tab
WRITE:
/5 'Program',
15 'Screen',
25 'New Screen',
40 'Field Name',
55 'Field Value'.
ULINE /5(65).
LOOP AT BDC_TAB INTO WA_BDC_TAB.
WRITE:
/5 WA_BDC_TAB-PROGRAM,
15 WA_BDC_TAB-DYNPRO,
30 WA_BDC_TAB-DYNBEGIN,
40 WA_BDC_TAB-FNAM,
55 WA_BDC_TAB-FVAL.
ENDLOOP.
* The subroutines are on the next two pages
FORM FILL_BDC_TAB.
REFRESH BDC_TAB.
PERFORM POPULATE_BDC_TAB USING:
'1'
''
''
''
''
''
''
'SAPMF02K' '0105',
" initial create vendor screen
'BDC_CURSOR' 'USE_ZAV',
'BDC_OKCODE'
'/00',
'RF02K-LIFNR' INREC-VENDNUM,
'RF02K-BUKRS' '0001',
'RF02K-KTOKK' '0001',
'USE_ZAV' 'X',
'1'
'SAPMF02K' '0111',
' ' 'BDC_OKCODE'
'=UPDA',
''
'BDC_SUBSCR' 'SAPLSZA1
0300ADDRESS',
''
'BDC_SUBSCR' 'SAPLSZA1
0301COUNTRY_SCREEN',
''
'BDC_CURSOR'
'ADDR1_DATA-COUNTRY',
''
'ADDR1_DATA-NAME1' INREC-NAME,
''
'ADDR1_DATA-SORT1' INREC-SORT,
Page 14
Dec-2008
ECC 6.0
SAP Development ABAP Training
''
''
''
'ADDR1_DATA-CITY1' INREC-CITY,
'ADDR1_DATA-COUNTRY' INREC-COUNTRY,
'ADDR1_DATA-LANGU' 'EN'.
* note: Even though we are not filling any fields on screen 0120,
* we still have to reference it because we pass
* through it when proceeding in the transaction. Also,
* we can save the record on screen 0120.
ENDFORM.
FORM POPULATE_BDC_TAB USING FLAG VAR1 VAR2.
CLEAR WA_BDC_TAB.
IF FLAG = '1'.
WA_BDC_TAB-PROGRAM
WA_BDC_TAB-DYNPRO
WA_BDC_TAB-DYNBEGIN
ELSE.
WA_BDC_TAB-FNAM
WA_BDC_TAB-FVAL
ENDIF.
= VAR1.
= VAR2.
= 'X'.
= VAR1.
= VAR2.
Page 15
Dec-2008
ECC 6.0
SAP Development ABAP Training
Chapters 5 - 6
Exercise 1
REPORT YDIXX5_1 .
CONSTANTS: INFILE(30) TYPE C VALUE './file1xx'.
DATA: BDC_TAB TYPE STANDARD TABLE OF BDCDATA ,
WA_BDC_TAB TYPE BDCDATA,
SESSION LIKE APQI-GROUPID VALUE 'SESSION1-XX'.
DATA: BEGIN OF INREC,
VENDNUM
TYPE YVENDOR-VENDNUM,
COMPANY
TYPE YVENDOR-COMPANY,
ACCTGROUP
TYPE YVENDOR-ACCTGROUP,
NAME
TYPE YVENDOR-NAME,
SORT
TYPE YVENDOR-SORT,
CITY
TYPE YVENDOR-CITY,
ZIPCODE
TYPE YVENDOR-ZIPCODE,
COUNTRY
TYPE YVENDOR-COUNTRY,
REGION
TYPE YVENDOR-REGION,
LANG
TYPE YVENDOR-LANG,
END OF INREC.
START-OF-SELECTION.
OPEN DATASET INFILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT
= SY-MANDT
GROUP
= SESSION
*HOLDDATE
=''
KEEP
= 'X'
USER
= SY-UNAME
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
Page 16
Dec-2008
ECC 6.0
SAP Development ABAP Training
OTHERS
= 11.
IF SY-SUBRC = 0.
WRITE: / 'Batch input session --', SESSION, '-- opened'.
ELSE.
WRITE: / 'Error opening session - SY-SUBRC =', SY-SUBRC.
ENDIF.
DO.
READ DATASET INFILE INTO INREC.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
PERFORM FILL_BDC_TAB.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE
= 'FK01'
" transaction code must be capitalized
TABLES
DYNPROTAB
= BDC_TAB
EXCEPTIONS
INTERNAL_ERROR
=1
NOT_OPEN
=2
QUEUE_ERROR
=3
TCODE_INVALID
=4
OTHERS
= 5.
IF SY-SUBRC = 0.
WRITE: / INREC-VENDNUM, 'inserted into session'.
ELSE.
WRITE: / 'Error inserting', INREC-VENDNUM, 'SY-SUBRC =', SY-SUBRC.
ENDIF.
ENDDO.
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN
=1
QUEUE_ERROR
=2
OTHERS
= 3.
IF SY-SUBRC = 0.
WRITE: / 'Batch input session --', SESSION, '-- closed'.
ELSE.
WRITE: / 'Error closing session - SY-SUBRC =', SY-SUBRC.
ENDIF.
CLOSE DATASET INFILE.
FORM FILL_BDC_TAB.
Page 17
Dec-2008
ECC 6.0
SAP Development ABAP Training
REFRESH BDC_TAB.
PERFORM POPULATE_BDC_TAB USING:
'1'
''
''
''
''
''
''
'SAPMF02K' '0105',
" initial create vendor screen
'BDC_CURSOR' 'USE_ZAV',
'BDC_OKCODE'
'/00',
'RF02K-LIFNR' INREC-VENDNUM,
'RF02K-BUKRS' '0001',
'RF02K-KTOKK' '0001',
'USE_ZAV' 'X',
'1'
'SAPMF02K' '0111',
' ' 'BDC_OKCODE'
'=UPDA',
''
'BDC_SUBSCR' 'SAPLSZA1
0300ADDRESS',
''
'BDC_SUBSCR' 'SAPLSZA1
0301COUNTRY_SCREEN',
''
'BDC_CURSOR'
'ADDR1_DATA-COUNTRY',
''
'ADDR1_DATA-NAME1' INREC-NAME,
''
'ADDR1_DATA-SORT1' INREC-SORT,
' ' 'ADDR1_DATA-CITY1' INREC-CITY,
''
'ADDR1_DATA-COUNTRY' INREC-COUNTRY,
''
'ADDR1_DATA-LANGU' 'EN'.
* note: Even though we are not filling any fields on screen 0210,
* we still have to reference it because we pass
* through it when proceeding in the transaction.
ENDFORM.
FORM POPULATE_BDC_TAB USING FLAG VAR1 VAR2.
CLEAR WA_BDC_TAB.
IF FLAG = '1'.
WA_BDC_TAB-PROGRAM
WA_BDC_TAB-DYNPRO
WA_BDC_TAB-DYNBEGIN
ELSE.
WA_BDC_TAB-FNAM
WA_BDC_TAB-FVAL
ENDIF.
= VAR1.
= VAR2.
= 'X'.
= VAR1.
= VAR2.
Page 18
Dec-2008
ECC 6.0
SAP Development ABAP Training
Exercise 2
PROGRAM
DYNPRO
DYNBEGIN
SAPMF02K
0106
SAPMF02K
0110
FNAM
FVAL
BDC_CURSOR
USE_ZAV
BDC_OKCODE
/00
RF02K-LIFNR
Vendor001
RF02K-BUKRS
0001
RF02K-D0110
USE_ZAV
BDC_OKCODE
=UPDA
BDC_SUBSCR
ADDR1_DATA-NAME1
SAPLSZA1
0300ADDRESS
SAPLSZA1
0301COUNTRY_SC
ADDR1_DATACOUNTRY
Vendor001_chang
ADDR1_DATA-SORT1
ABAP1
ADDR1_DATA -CITY1
Philadelphia
ADDR1_DATA -COUNTRY
IN
ADDR1_DATA -LANGU
EN
BDC_SUBSCR
BDC_CURSOR
REPORT YDIXX5_2 .
CONSTANTS: INFILE(30) VALUE './file4xx'.
DATA: BDC_TAB LIKE STANDARD TABLE OF BDCDATA ,
WA_BDC_TAB TYPE BDCDATA,
SESSION LIKE APQI-GROUPID VALUE 'SESSION2-XX'.
DATA: BEGIN OF INREC,
Page 19
Dec-2008
ECC 6.0
SAP Development ABAP Training
VENDNUM(16) TYPE C,
NAME(30) TYPE C,
SORT(20) TYPE C,
COUNTRY(3) TYPE C,
END OF INREC.
START-OF-SELECTION.
OPEN DATASET INFILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT
= SY-MANDT
GROUP
= SESSION
*
HOLDDATE
KEEP
= 'X'
USER
= SY-UNAME
EXCEPTIONS
CLIENT_INVALID
DESTINATION_INVALID
=2
GROUP_INVALID
GROUP_IS_LOCKED
=4
HOLDDATE_INVALID
=5
INTERNAL_ERROR
QUEUE_ERROR
RUNNING
SYSTEM_LOCK_ERROR
=9
USER_INVALID
OTHERS
=''
=1
=3
=6
=7
=8
= 10
= 11.
IF SY-SUBRC = 0.
WRITE: / 'Batch input session --', SESSION, '-- opened'.
ELSE.
WRITE: / 'Error opening session - SY-SUBRC =', SY-SUBRC.
ENDIF.
DO.
READ DATASET INFILE INTO INREC.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
PERFORM FILL_BDC_TAB.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE
= 'FK02'
TABLES
Page 20
Dec-2008
ECC 6.0
SAP Development ABAP Training
DYNPROTAB
= BDC_TAB
EXCEPTIONS
INTERNAL_ERROR
=1
NOT_OPEN
=2
QUEUE_ERROR
=3
TCODE_INVALID
=4
OTHERS
= 5.
IF SY-SUBRC = 0.
WRITE: / INREC-VENDNUM, 'inserted into session'.
ELSE.
WRITE: / 'Error inserting', INREC-VENDNUM, 'SY-SUBRC =', SY-SUBRC.
ENDIF.
ENDDO.
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN
=1
QUEUE_ERROR
=2
OTHERS
= 3.
IF SY-SUBRC = 0.
WRITE: / 'Batch input session --', SESSION, '-- closed'.
ELSE.
WRITE: / 'Error closing session - SY-SUBRC =', SY-SUBRC.
ENDIF.
CLOSE DATASET INFILE.
FORM FILL_BDC_TAB.
REFRESH BDC_TAB.
PERFORM POPULATE_BDC_TAB USING:
'1'
''
''
''
''
''
''
'SAPMF02K' '0105',
" initial create vendor screen
'BDC_CURSOR' 'USE_ZAV',
'BDC_OKCODE'
'/00',
'RF02K-LIFNR' INREC-VENDNUM,
'RF02K-BUKRS' '0001',
'RF02K-KTOKK' '0001',
'USE_ZAV' 'X',
'1'
'SAPMF02K' '0111',
' ' 'BDC_OKCODE'
'=UPDA',
''
'BDC_SUBSCR' 'SAPLSZA1
0300ADDRESS',
''
'BDC_SUBSCR' 'SAPLSZA1
0301COUNTRY_SCREEN',
''
'BDC_CURSOR'
'ADDR1_DATA-COUNTRY',
''
'ADDR1_DATA-NAME1' INREC-NAME,
''
'ADDR1_DATA-SORT1' INREC-SORT,
''
'ADDR1_DATA-COUNTRY' INREC-COUNTRY,
''
'ADDR1_DATA-LANGU' 'EN'.
Page 21
Dec-2008
ECC 6.0
SAP Development ABAP Training
ENDFORM.
FORM POPULATE_BDC_TAB USING FLAG VAR1 VAR2.
CLEAR WA_BDC_TAB.
IF FLAG = '1'.
WA_BDC_TAB-PROGRAM
WA_BDC_TAB-DYNPRO
WA_BDC_TAB-DYNBEGIN
ELSE.
WA_BDC_TAB-FNAM
WA_BDC_TAB-FVAL
ENDIF.
= VAR1.
= VAR2.
= 'X'.
= VAR1.
= VAR2.
START-OF-SELECTION.
OPEN DATASET INFILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.
DO.
READ DATASET INFILE INTO INREC.
Page 22
Dec-2008
ECC 6.0
SAP Development ABAP Training
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
PERFORM FILL_BDC_TAB.
CALL TRANSACTION 'FK02'
USING
BDC_TAB
MODE
DISPMODE
UPDATE
SYNCHRONOUS.
*
in order to test the success of the actual update, the update mode
*
must be 'synchronous'. 'Asynchronous' updating is faster.
IF SY-SUBRC = 0.
WRITE: / 'Vendor', INREC-VENDNUM, 'updated successfully'.
ELSE.
WRITE: / 'Error updating vendor:', INREC-VENDNUM.
ENDIF.
ENDDO.
CLOSE DATASET INFILE.
*Bonus: If you wanted to create an error file with the unsuccessful records, you could
*
TRANSFER the contents of the field string INREC to an error file
when
*
SY-SUBRC does not equal zero after the CALL TRANSACTION
USING
*
statement.
FORM FILL_BDC_TAB.
REFRESH BDC_TAB.
PERFORM POPULATE_BDC_TAB USING:
'1'
''
''
''
''
''
''
'SAPMF02K' '0105',
" initial create vendor screen
'BDC_CURSOR' 'USE_ZAV',
'BDC_OKCODE'
'/00',
'RF02K-LIFNR' INREC-VENDNUM,
'RF02K-BUKRS' '0001',
'RF02K-KTOKK' '0001',
'USE_ZAV'
'X',
'1'
'SAPMF02K' '0111',
' ' 'BDC_OKCODE'
'=UPDA',
''
'BDC_SUBSCR' 'SAPLSZA1
0300ADDRESS',
''
'BDC_SUBSCR' 'SAPLSZA1
0301COUNTRY_SCREEN',
''
'BDC_CURSOR'
'ADDR1_DATA-COUNTRY',
Page 23
Dec-2008
ECC 6.0
SAP Development ABAP Training
''
''
''
''
'ADDR1_DATA-NAME1' INREC-NAME,
'ADDR1_DATA-SORT1' INREC-SORT,
'ADDR1_DATA-COUNTRY' INREC-COUNTRY,
'ADDR1_DATA-LANGU' 'EN'.
ENDFORM.
*&---------------------------------------------------------------------*
*&
Form POPULATE_BDC_TAB
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->FLAG
text
*
-->VAR1
text
*
-->VAR2
text
*----------------------------------------------------------------------*
FORM POPULATE_BDC_TAB USING FLAG VAR1 VAR2.
CLEAR WA_BDC_TAB.
IF FLAG = '1'.
WA_BDC_TAB-PROGRAM
WA_BDC_TAB-DYNPRO
WA_BDC_TAB-DYNBEGIN
ELSE.
WA_BDC_TAB-FNAM
WA_BDC_TAB-FVAL
ENDIF.
= VAR1.
= VAR2.
= 'X'.
= VAR1.
= VAR2.
"POPULATE_BDC_TAB
Exercise 2
The program in the previous exercise would change by using the CALL DIALOG statement
instead of the CALL TRANSACTION USING statement. This statement would be:
CALL DIALOG Z_DIALOG_FK02
USING
BDC_TAB
MODE
DISPMODE.
Notice that no update mode is specified. Instead, you need to code a COMMIT WORK
statement in the program to confirm the changes to the database.
Page 24
Dec-2008
ECC 6.0
SAP Development ABAP Training
Page 25
Dec-2008
ECC 6.0
SAP Development ABAP Training
Chapter 8
Exercise 1
(1) What is the function code associated with the Display pushbutton on the screen?
SHOP
Use the System > Status menu path and double click on the screen number to navigate
into the Screen Painter. In the Screen Painter, go to the Fullscreen Editor and look at
the attributes of the pushbutton field. The FctCode attributes will give you the function
code SHOP.
(2) What is the function code associated with the Utilities > Splitscreen editor menu path?
SE39
Use the System > Status menu path and double click on the GUI status name to
navigate into the Menu Painter. Expand the Menubar item and double click Utilities.
Double click Splitscreen editor to get the function attributes. The Splitscreen editor
branch is assigned the SE39 function code.
Page 26
Dec-2008