You are on page 1of 28

SAP R/3 Release 4.

7
SAP Development ABAP Training

Data Interfaces: Exercise Solutions

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

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

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 LIKE TBTCO-JOBNAME DEFAULT 'ABAPxxJOB5'.

DATA: JOBCOUNT LIKE TBTCO-JOBCOUNT.


CONSTANTS: PROGRAM LIKE SY-REPID VALUE ' YAPXX05_1'.
START-OF-SELECTION.
CALL FUNCTION 'JOB_OPEN'
EXPORTING
JOBNAME
= JOBNAME
IMPORTING
JOBCOUNT
= JOBCOUNT
EXCEPTIONS
CANT_CREATE_JOB
=1
INVALID_JOB_DATA
=2
JOBNAME_MISSING
=3
OTHERS
= 4.
IF SY-SUBRC = 0.
WRITE: / 'Job opened successfully'.
ELSE.
WRITE: / 'Error with JOB_OPEN - SY-SUBRC =', SY-SUBRC.
ENDIF.

Page 2

March 2005

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

CALL FUNCTION 'JOB_SUBMIT'


EXPORTING
AUTHCKNAM
= SY-UNAME
JOBCOUNT
= JOBCOUNT
JOBNAME
= JOBNAME
REPORT
= PROGRAM
EXCEPTIONS
BAD_PRIPARAMS
=1
...
OTHERS
= 10.
IF SY-SUBRC = 0.
WRITE: / 'Job step inserted successfully'.
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

March 2005

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

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

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

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

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

STREET

LIKE KNA1-STRAS

DEFAULT '10 Walnut

LIKE KNA1-TELF1

DEFAULT

St.',
PHONE
5900',
FAX
575-5515'.

LIKE KNA1-TELFX

'215-575-

DEFAULT '215-

DATA: BEGIN OF OUTREC,


CUSTNUM
LIKE KNA1-KUNNR,
NAME
LIKE KNA1-NAME1,
STREET
LIKE KNA1-STRAS,
PHONE
LIKE KNA1-TELF1,
FAX
LIKE KNA1-TELFX,
END OF OUTREC.
START-OF-SELECTION.
OPEN DATASET OUTFILE FOR APPENDING IN TEXT MODE.
MOVE:

CUSTNUM
NAME
STREET
PHONE
FAX

TO OUTREC-CUSTNUM,
TO OUTREC-NAME,
TO OUTREC-STREET,
TO OUTREC-PHONE,
TO OUTREC-FAX.

TRANSFER OUTREC TO OUTFILE.


WRITE: / OUTREC-CUSTNUM, 'transferred to file'.
CLOSE DATASET OUTFILE.

Page 6

March 2005

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

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

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

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

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

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

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

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

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

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

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

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

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

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.

* The subroutines are on the next two pages

Page 13

March 2005

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

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

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

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 15

March 2005

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

Chapters 5 - 6
Exercise 1
REPORT YDIXX5_1 .
CONSTANTS: INFILE(30) VALUE './file1xx'.
DATA:

BDC_TAB LIKE STANDARD TABLE OF BDCDATA INITIAL SIZE 17 WITH


HEADER LINE,
SESSION LIKE APQI-GROUPID VALUE 'SESSION1-XX'.

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.

Page 16

March 2005

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

START-OF-SELECTION.
OPEN DATASET INFILE FOR INPUT IN TEXT MODE.

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
QUEUE_ERROR
RUNNING
SYSTEM_LOCK_ERROR
=9
USER_INVALID
OTHERS

=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

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

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

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

' ' '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 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 19

March 2005

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

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:

BDC_TAB LIKE STANDARD TABLE OF BDCDATA INITIAL SIZE 8 WITH HEADER


LINE,
SESSION LIKE APQI-GROUPID VALUE 'SESSION2-XX'.

Page 20

March 2005

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

DATA: BEGIN OF INREC,


VENDNUM(16),
NAME(30),
SORT(20),
COUNTRY(3),
END OF INREC.
START-OF-SELECTION.
OPEN DATASET INFILE FOR INPUT IN TEXT MODE.

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
QUEUE_ERROR
RUNNING
SYSTEM_LOCK_ERROR
=9
USER_INVALID
OTHERS

=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

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

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

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

' ' '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 23

March 2005

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

Chapter 7
Exercise 1
REPORT YDIXX7_1 .
PARAMETERS:

DISPMODE DEFAULT 'A'.

CONSTANTS: INFILE(30) VALUE './file5xx',


SYNCHRONOUS VALUE 'S'.
DATA: BDC_TAB LIKE STANDARD TABLE OF BDCDATA INITIAL SIZE 8 WITH HEADER
LINE.
DATA: BEGIN OF INREC,
VENDNUM(16) TYPE C
NAME(30)
TYPE C
SORT(20)
TYPE C
COUNTRY(3) TYPE C
END OF INREC.

Page 24

March 2005

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

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.

*
*

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:
*
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

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

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

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

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

SAP R/3 Release 4.7


SAP Development ABAP Training

Data Interfaces: Exercise Solutions

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

You might also like