[go: up one dir, main page]

0% found this document useful (0 votes)
20 views27 pages

7.11 - Data Interface Exercises Solutions

The document provides exercise solutions for SAP Development ABAP Training, focusing on data interfaces in ECC 6.0. It includes various exercises that involve examining background job statuses, handling file input/output operations, and creating vendor transactions using BDC (Batch Data Communication). Each exercise is accompanied by relevant ABAP code snippets and explanations for successful execution and error handling.

Uploaded by

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

7.11 - Data Interface Exercises Solutions

The document provides exercise solutions for SAP Development ABAP Training, focusing on data interfaces in ECC 6.0. It includes various exercises that involve examining background job statuses, handling file input/output operations, and creating vendor transactions using BDC (Batch Data Communication). Each exercise is accompanied by relevant ABAP code snippets and explanations for successful execution and error handling.

Uploaded by

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

ECC 6.

0
Data Interfaces: Exercise Solutions 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.

Dec-2008
Page 1
ECC 6.0
Data Interfaces: Exercise Solutions 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: JOBCOUNT TYPE TBTCO-JOBCOUNT.

CONSTANTS: PROGRAM TYPE 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.

CALL FUNCTION 'JOB_SUBMIT'


EXPORTING
AUTHCKNAM = SY-UNAME
JOBCOUNT = JOBCOUNT
JOBNAME = JOBNAME
REPORT = PROGRAM.
*EXCEPTIONS
*BAD_PRIPARAMS =1
*. . .
*OTHERS. = 10.

Dec-2008
Page 2
ECC 6.0
Data Interfaces: Exercise Solutions SAP Development ABAP Training

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.

Dec-2008
Page 3
ECC 6.0
Data Interfaces: Exercise Solutions 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.

Dec-2008
Page 4
ECC 6.0
Data Interfaces: Exercise Solutions SAP Development ABAP Training

OUTREC-LANG = WA_YVENDOR-LANG.

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.

Dec-2008
Page 5
ECC 6.0
Data Interfaces: Exercise Solutions 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'.

Dec-2008
Page 6
ECC 6.0
Data Interfaces: Exercise Solutions SAP Development ABAP Training

PARAMETERS: CUSTNUM TYPE KUNNR DEFAULT 'ABAPxx-001',


NAME TYPE NAME1 DEFAULT 'Buyer, Inc.',
STREET TYPE STRAS DEFAULT '10 Walnut St.',
PHONE TYPE TELF1 DEFAULT '215-575-5900',
FAX TYPE TELFX DEFAULT '215-575-5515'.

DATA: BEGIN OF OUTREC,


CUSTNUM TYPE KUNNR,
NAME TYPE NAME1,
STREET TYPE STRAS,
PHONE TYPE TELF1,
FAX TYPE TELFX,
END OF OUTREC.

START-OF-SELECTION.
OPEN DATASET OUTFILE FOR APPENDING IN TEXT MODE ENCODING DEFAULT.

OUTREC-CUSTNUM = CUSTNUM.
OUTREC-NAME = NAME.
OUTREC-STREET = STREET.
OUTREC-PHONE = PHONE.
OUTREC-FAX = FAX.

TRANSFER OUTREC TO OUTFILE.

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

CLOSE DATASET OUTFILE.

Dec-2008
Page 7
ECC 6.0
Data Interfaces: Exercise Solutions 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: / 'Customer #:', INREC-CUSTNUM,


/ 'Name :', INREC-NAME,
/ 'Street :', INREC-STREET,
/ 'Phone :', INREC-PHONE,
/ 'Fax :', INREC-FAX.
ULINE.
ENDDO.

CLOSE DATASET INFILE.

Dec-2008
Page 8
ECC 6.0
Data Interfaces: Exercise Solutions 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'

Dec-2008
Page 9
ECC 6.0
Data Interfaces: Exercise Solutions SAP Development ABAP Training

* APPEND =''
* WRITE_FIELD_SEPARATOR =''
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,

Dec-2008
Page 10
ECC 6.0
Data Interfaces: Exercise Solutions SAP Development ABAP Training

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.

DATA: IN_ITAB TYPE STANDARD TABLE OF INREC,


WA_IN_ITAB TYPE INREC.

START-OF-SELECTION.

CALL FUNCTION 'GUI_UPLOAD'


EXPORTING
FILENAME = 'c:\file3xx'
FILETYPE = 'ASC'
* HAS_FIELD_SEPARATOR =''
TABLES
DATA_TAB = IN_ITAB
* 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.

Dec-2008
Page 11
ECC 6.0
Data Interfaces: Exercise Solutions SAP Development ABAP Training

LOOP AT IN_ITAB INTO WA_IN_ITAB.


WRITE: / 'Vendor # :', WA_IN_ITAB-VENDNUM,
/ 'Company Code :', WA_IN_ITAB-COMPANY,
/ 'Account Group :', WA_IN_ITAB-ACCTGROUP,
/ 'Name :', WA_IN_ITAB-NAME,
/ 'Sort term :', WA_IN_ITAB-SORT,
/ '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.

Dec-2008
Page 12
ECC 6.0
Data Interfaces: Exercise Solutions SAP Development ABAP Training

Chapter 4

Exercise 1

‘Create Vendor’ Transaction Code: FK01

PROGRAM DYNPRO DYNBEGIN FNAM FVAL

SAPMF02K 0105 X

RF02K-LIFNR ABAPxx-nnn

RF02K-BUKRS 0001

RF02K-KTOKK 0001

BDC_OKCODE /00

SAPMF02K 0110 X

LFA1-NAME1 Vendor

LFA1-SORTL NUM

LFA1-ORT01 Miami

LFA1-PSTLZ 33143

LFA1-LAND1 US

LFA1-REGIO FL

LFA1-SPRAS EN

SAPMF02K 0120 * X

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.

Dec-2008
Page 13
ECC 6.0
Data Interfaces: Exercise Solutions 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',

Dec-2008
Page 14
ECC 6.0
Data Interfaces: Exercise Solutions SAP Development ABAP Training

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

FORM POPULATE_BDC_TAB USING FLAG VAR1 VAR2.

CLEAR WA_BDC_TAB.

IF FLAG = '1'.
WA_BDC_TAB-PROGRAM = VAR1.
WA_BDC_TAB-DYNPRO = VAR2.
WA_BDC_TAB-DYNBEGIN = 'X'.
ELSE.
WA_BDC_TAB-FNAM = VAR1.
WA_BDC_TAB-FVAL = VAR2.
ENDIF.

APPEND WA_BDC_TAB TO BDC_TAB.

ENDFORM.

Dec-2008
Page 15
ECC 6.0
Data Interfaces: Exercise Solutions 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

Dec-2008
Page 16
ECC 6.0
Data Interfaces: Exercise Solutions SAP Development ABAP Training

SYSTEM_LOCK_ERROR =9
USER_INVALID = 10
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.

Dec-2008
Page 17
ECC 6.0
Data Interfaces: Exercise Solutions SAP Development ABAP Training

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-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 = VAR1.
WA_BDC_TAB-DYNPRO = VAR2.
WA_BDC_TAB-DYNBEGIN = 'X'.
ELSE.
WA_BDC_TAB-FNAM = VAR1.
WA_BDC_TAB-FVAL = VAR2.
ENDIF.

APPEND WA_BDC_TAB TO BDC_TAB.

Dec-2008
Page 18
ECC 6.0
Data Interfaces: Exercise Solutions SAP Development ABAP Training

ENDFORM.

Dec-2008
Page 19
ECC 6.0
Data Interfaces: Exercise Solutions SAP Development ABAP Training

Exercise 2

PROGRAM DYNPRO DYNBEGIN FNAM FVAL

SAPMF02K 0106 X

BDC_CURSOR USE_ZAV

BDC_OKCODE /00

RF02K-LIFNR Vendor001

RF02K-BUKRS 0001

RF02K-D0110 X

USE_ZAV X

SAPMF02K 0110 X

BDC_OKCODE =UPDA

BDC_SUBSCR SAPLSZA1
0300ADDRESS
BDC_SUBSCR SAPLSZA1
0301COUNTRY_S
BDC_CURSOR ADDR1_DATA-
COUNTRY
ADDR1_DATA-NAME1 Vendor001_chang

ADDR1_DATA-SORT1 ABAP1

ADDR1_DATA -CITY1 Philadelphia

ADDR1_DATA -COUNTRY IN

ADDR1_DATA -LANGU EN

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

Dec-2008
Page 20
ECC 6.0
Data Interfaces: Exercise Solutions SAP Development ABAP Training

DATA: BEGIN OF INREC,


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 =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.
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'

Dec-2008
Page 21
ECC 6.0
Data Interfaces: Exercise Solutions SAP Development ABAP Training

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,
'' 'RF02K-BUKRS' '0001',
'' 'RF02K-KTOKK' '0001',
'' 'USE_ZAV' 'X',

'1' 'SAPMF02K' '0111',


' ' 'BDC_OKCODE' '=UPDA',
'' 'BDC_SUBSCR' 'SAPLSZA1 0300ADDRESS',
'' 'BDC_SUBSCR' 'SAPLSZA1 0301COUNTRY_SCREEN',

Dec-2008
Page 22
ECC 6.0
Data Interfaces: Exercise Solutions SAP Development ABAP Training

'' '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 WA_BDC_TAB.

IF FLAG = '1'.
WA_BDC_TAB-PROGRAM = VAR1.
WA_BDC_TAB-DYNPRO = VAR2.
WA_BDC_TAB-DYNBEGIN = 'X'.
ELSE.
WA_BDC_TAB-FNAM = VAR1.
WA_BDC_TAB-FVAL = VAR2.
ENDIF.

APPEND WA_BDC_TAB TO BDC_TAB.

ENDFORM.
Chapter 7

Exercise 1

REPORT YDIXX7_1 .

PARAMETERS: DISPMODE TYPE C DEFAULT 'A'.

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


SYNCHRONOUS VALUE 'S'.

DATA: BDC_TAB TYPE STANDARD TABLE OF BDCDATA ,


WA_BDC_TAB TYPE BDCDATA.

DATA: BEGIN OF INREC,


VENDNUM(16) TYPE C,
NAME(30) TYPE C,
SORT(20) TYPE C,
COUNTRY(3) TYPE C,
END OF INREC.

Dec-2008
Page 23
ECC 6.0
Data Interfaces: Exercise Solutions SAP Development ABAP Training

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.

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,

Dec-2008
Page 24
ECC 6.0
Data Interfaces: Exercise Solutions SAP Development ABAP Training

' ' '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
*&---------------------------------------------------------------------*
* 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 = VAR1.
WA_BDC_TAB-DYNPRO = VAR2.
WA_BDC_TAB-DYNBEGIN = 'X'.
ELSE.
WA_BDC_TAB-FNAM = VAR1.
WA_BDC_TAB-FVAL = VAR2.
ENDIF.

APPEND WA_BDC_TAB TO BDC_TAB.

ENDFORM. "POPULATE_BDC_TAB

Exercise 2

Dec-2008
Page 25
ECC 6.0
Data Interfaces: Exercise Solutions SAP Development ABAP Training

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.

Dec-2008
Page 26
ECC 6.0
Data Interfaces: Exercise Solutions 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.

Dec-2008
Page 27

You might also like