Professional Documents
Culture Documents
7.11 - Data Interface Exercises Solutions
7.11 - Data Interface Exercises Solutions
7
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
March 2005
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:
Page 2
March 2005
= 8.
IF SY-SUBRC = 0.
WRITE: / 'Job closed successfully'.
ELSE.
WRITE: / 'Error with JOB_CLOSE - SY-SUBRC =', SY-SUBRC.
ENDIF.
Page 3
March 2005
Chapter 2
Exercise 1
REPORT YDIXX2_1.
TABLES: YVENDOR.
CONSTANTS: OUTFILE(30) VALUE './file1xx'.
DATA: BEGIN OF OUTREC,
VENDNUM
LIKE YVENDOR-VENDNUM,
COMPANY
LIKE YVENDOR-COMPANY,
ACCTGROUP LIKE YVENDOR-ACCTGROUP,
NAME
LIKE YVENDOR-NAME,
SORT
LIKE YVENDOR-SORT,
CITY
LIKE YVENDOR-CITY,
ZIPCODE
LIKE YVENDOR-ZIPCODE,
COUNTRY
LIKE YVENDOR-COUNTRY,
REGION
LIKE YVENDOR-REGION,
LANG
LIKE YVENDOR-LANG,
END OF OUTREC.
START-OF-SELECTION.
OPEN DATASET OUTFILE FOR OUTPUT IN TEXT MODE.
SELECT * FROM YVENDOR WHERE UNAME = SY-UNAME.
MOVE-CORRESPONDING YVENDOR TO OUTREC.
TRANSFER OUTREC TO OUTFILE.
WRITE: / OUTREC-VENDNUM, 'transferred to file'.
ENDSELECT.
IF SY-SUBRC <> 0.
WRITE: / 'No records transferred to file'.
ENDIF.
CLOSE DATASET OUTFILE.
Page 4
March 2005
Exercise 2
REPORT YDIXX2_2.
CONSTANTS: INFILE(30) VALUE './file1xx'.
DATA: BEGIN OF INREC,
VENDNUM
LIKE YVENDOR-VENDNUM,
COMPANY
LIKE YVENDOR-COMPANY,
ACCTGROUP LIKE YVENDOR-ACCTGROUP,
NAME
LIKE YVENDOR-NAME,
SORT
LIKE YVENDOR-SORT,
CITY
LIKE YVENDOR-CITY,
ZIPCODE
LIKE YVENDOR-ZIPCODE,
COUNTRY
LIKE YVENDOR-COUNTRY,
REGION
LIKE YVENDOR-REGION,
LANG
LIKE YVENDOR-LANG,
END OF INREC.
START-OF-SELECTION.
OPEN DATASET INFILE FOR INPUT IN TEXT MODE.
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) VALUE './file2xx'.
PARAMETERS:
CUSTNUM
NAME
'Buyer, Inc.',
LIKE KNA1-KUNNR
DEFAULT 'ABAPxx-001',
LIKE KNA1-NAME1
DEFAULT
Page 5
March 2005
STREET
LIKE KNA1-STRAS
LIKE KNA1-TELF1
DEFAULT
St.',
PHONE
5900',
FAX
575-5515'.
LIKE KNA1-TELFX
'215-575-
DEFAULT '215-
CUSTNUM
NAME
STREET
PHONE
FAX
TO OUTREC-CUSTNUM,
TO OUTREC-NAME,
TO OUTREC-STREET,
TO OUTREC-PHONE,
TO OUTREC-FAX.
Page 6
March 2005
Exercise 4
REPORT YDIXX2_4.
CONSTANTS: INFILE(30) VALUE './file2xx'.
DATA: BEGIN OF INREC,
CUSTNUM
NAME
STREET
PHONE
FAX
END OF INREC.
LIKE KNA1-KUNNR,
LIKE KNA1-NAME1,
LIKE KNA1-STRAS,
LIKE KNA1-TELF1,
LIKE KNA1-TELFX,
START-OF-SELECTION.
OPEN DATASET INFILE FOR INPUT IN TEXT MODE.
DO.
READ DATASET INFILE INTO INREC.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
WRITE:
/
/
/
/
/ 'Customer #:',
'Name
:',
'Street :',
'Phone :',
'Fax
:',
INREC-CUSTNUM,
INREC-NAME,
INREC-STREET,
INREC-PHONE,
INREC-FAX.
ULINE.
ENDDO.
CLOSE DATASET INFILE.
Page 7
March 2005
Chapter 3
Exercise 1
REPORT YDIXX3_1 .
TABLES: YVENDOR.
TYPES:
BEGIN OF OUTREC,
VENDNUM
LIKE YVENDOR-VENDNUM,
COMPANY
LIKE YVENDOR-COMPANY,
ACCTGROUP LIKE YVENDOR-ACCTGROUP,
NAME
LIKE YVENDOR-NAME,
SORT
LIKE YVENDOR-SORT,
CITY
LIKE YVENDOR-CITY,
ZIPCODE
LIKE YVENDOR-ZIPCODE,
COUNTRY
LIKE YVENDOR-COUNTRY,
REGION
LIKE YVENDOR-REGION,
LANG
LIKE YVENDOR-LANG,
END OF OUTREC.
DATA: OUT_ITAB TYPE STANDARD TABLE OF OUTREC INITIAL SIZE 5 WITH HEADER
LINE.
START-OF-SELECTION.
SELECT * FROM YVENDOR WHERE USERNAME = SY-UNAME.
MOVE-CORRESPONDING YVENDOR TO OUT_ITAB.
APPEND OUT_ITAB.
ENDSELECT.
Page 8
March 2005
IF SY-SUBRC = 0.
CALL FUNCTION 'DOWNLOAD'
EXPORTING
FILENAME
= 'c:\file3xx'
TABLES
DATA_TAB
= OUT_ITAB
EXCEPTIONS
INVALID_FILESIZE
INVALID_TABLE_WIDTH
INVALID_TYPE
NO_BATCH
UNKNOWN_ERROR
OTHERS
=1
=2
=3
=4
=5
= 6.
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.
Page 9
March 2005
Exercise 2
REPORT YDIXX3_2 .
TYPES:
BEGIN OF INREC,
VENDNUM
LIKE YVENDOR-VENDNUM,
COMPANY
LIKE YVENDOR-COMPANY,
ACCTGROUP LIKE YVENDOR-ACCTGROUP,
NAME
LIKE YVENDOR-NAME,
SORT
LIKE YVENDOR-SORT,
CITY
LIKE YVENDOR-CITY,
ZIPCODE
LIKE YVENDOR-ZIPCODE,
COUNTRY
LIKE YVENDOR-COUNTRY,
REGION
LIKE YVENDOR-REGION,
LANG
LIKE YVENDOR-LANG,
END OF INREC.
DATA: IN_ITAB TYPE STANDARD TABLE OF INREC INITIAL SIZE 5 WITH HEADER LINE.
START-OF-SELECTION.
CALL FUNCTION 'UPLOAD'
EXPORTING
FILENAME = 'c:\file3xx'
FILETYPE
= 'DAT'
TABLES
DATA_TAB
= IN_ITAB
EXCEPTIONS
INVALID_FILESIZE
INVALID_TABLE_WIDTH
INVALID_TYPE
NO_BATCH
UNKNOWN_ERROR
OTHERS
=1
=2
=3
=4
=5
= 6.
Page 10
March 2005
IF SY-SUBRC = 0.
LOOP AT IN_ITAB.
WRITE:
/ 'Vendor #
:', IN_ITAB-VENDNUM,
/ 'Company Code :', IN_ITAB-COMPANY,
/ 'Account Group :', IN_ITAB-ACCTGROUP,
/ 'Name
:', IN_ITAB-NAME,
/ 'Sort term :', IN_ITAB-SORT,
/ 'City
:', IN_ITAB-CITY,
/ 'Zipcode
:', IN_ITAB-ZIPCODE,
/ 'Country
:', IN_ITAB-COUNTRY,
/ 'Region
:', IN_ITAB-REGION,
/ 'Language
:', 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 11
March 2005
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 12
March 2005
Exercise 2
REPORT YDIXX4_2.
DATA: BDC_TAB LIKE STANDARD TABLE OF BDCDATA INITIAL SIZE 17 WITH HEADER
LINE.
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.
WRITE:
/5 BDC_TAB-PROGRAM,
15 BDC_TAB-DYNPRO,
30 BDC_TAB-DYNBEGIN,
40 BDC_TAB-FNAM,
55 BDC_TAB-FVAL.
ENDLOOP.
Page 13
March 2005
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-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.
Page 14
March 2005
= VAR1.
= VAR2.
= 'X'.
= VAR1.
= VAR2.
APPEND BDC_TAB.
ENDFORM.
Page 15
March 2005
Chapters 5 - 6
Exercise 1
REPORT YDIXX5_1 .
CONSTANTS: INFILE(30) VALUE './file1xx'.
DATA:
Page 16
March 2005
START-OF-SELECTION.
OPEN DATASET INFILE FOR INPUT IN TEXT MODE.
=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.
Page 17
March 2005
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.
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,
Page 18
March 2005
= VAR1.
= VAR2.
= 'X'.
= VAR1.
= VAR2.
APPEND BDC_TAB.
ENDFORM.
Page 19
March 2005
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_S
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:
Page 20
March 2005
=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.
Page 21
March 2005
DO.
READ DATASET INFILE INTO INREC.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
PERFORM FILL_BDC_TAB.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE
= 'FK02'
" 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.
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,
Page 22
March 2005
'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'.
ENDFORM.
FORM POPULATE_BDC_TAB USING FLAG VAR1 VAR2.
CLEAR BDC_TAB.
IF FLAG = '1'.
BDC_TAB-PROGRAM
BDC_TAB-DYNPRO
BDC_TAB-DYNBEGIN
ELSE.
BDC_TAB-FNAM
BDC_TAB-FVAL
ENDIF.
= VAR1.
= VAR2.
= 'X'.
= VAR1.
= VAR2.
APPEND BDC_TAB.
ENDFORM.
Page 23
March 2005
Chapter 7
Exercise 1
REPORT YDIXX7_1 .
PARAMETERS:
Page 24
March 2005
START-OF-SELECTION.
OPEN DATASET INFILE FOR INPUT IN TEXT MODE.
DO.
READ DATASET INFILE INTO INREC.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
PERFORM FILL_BDC_TAB.
*
*
*Bonus:
*
when
*
USING
*
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
SY-SUBRC does not equal zero after the CALL TRANSACTION
statement.
Page 25
March 2005
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'.
ENDFORM.
FORM POPULATE_BDC_TAB USING FLAG VAR1 VAR2.
CLEAR BDC_TAB.
IF FLAG = '1'.
BDC_TAB-PROGRAM
BDC_TAB-DYNPRO
BDC_TAB-DYNBEGIN
ELSE.
BDC_TAB-FNAM
BDC_TAB-FVAL
ENDIF.
= VAR1.
= VAR2.
= 'X'.
= VAR1.
= VAR2.
APPEND BDC_TAB.
ENDFORM.
Page 26
March 2005
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 27
March 2005
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 28
March 2005