Sample Program: Data Transfer

The following ABAP program demonstrates the data transfer process. The program does the following:

  • reads customer address data from a sequential file
  • checks the data for unacceptable records
  • performs conversions on the data
  • writes the data back out to a sequential file using the format required by the SAP standard batch input program Batch Input Interface for Customers (ABAP program RFBIDE00).

REPORT BITFER.

* SAP structures for batch input processing:
TABLES: BGR00, BKN00, BKNA1.

* Structure of existing data to be transferred:
DATA: BEGIN OF OLDREC,
TELE1(10) TYPE C,
CUSTNR(8) TYPE C,
TITLE(2) TYPE C,
NAME1(30) TYPE C,
END OF OLDREC.

* Auxiliary structure for initializing fields:
DATA: BEGIN OF AUXREC.
INCLUDE STRUCTURE BKNA1.
DATA: END OF AUXREC.

* SAP fields for converted data:
DATA: CUSTNR LIKE BKN00-KUNNR,
NAME1 LIKE BKNA1-NAME1,
TELE1 LIKE BKNA1-TELF1.

* For initializing fields:
DATA: N TYPE I.
FIELD-SYMBOLS <F>.

* File and session names, NODATA character:
PARAMETERS:
OLDFILE(20) DEFAULT ‘/tmp/oldfile’ LOWER CASE,
SAPFILE(20) DEFAULT ‘/tmp/sapfile’ LOWER CASE,
ERRFILE(20) DEFAULT ‘/tmp/errfile’ LOWER CASE,
SESSION(20) DEFAULT ‘ADDRDAT’ LOWER CASE,
NODATA DEFAULT ‘/’ LOWER CASE.

START-OF-SELECTION.
OPEN DATASET: OLDFILE FOR INPUT IN TEXT MODE,
SAPFILE FOR OUTPUT IN TEXT MODE,
ERRFILE FOR OUTPUT IN TEXT MODE.

* Open batch input session as first SAPFILE entry:
* program:
MOVE: ‘O’ TO BGR00-STYPE,
SESSION TO BGR00-GROUP,
SY-MANDT TO BGR00-MANDT,
SY-UNAME TO BGR00-USNAM,
NODATA TO BGR00-NODATA.
TRANSFER BGR00 TO SAPFILE.

* Initialize data fields with NODATA:
DO.
ADD 1 TO N.
ASSIGN COMPONENT N OF STRUCTURE AUXREC TO <F>.
IF SY-SUBRC NE 0. EXIT. ENDIF.
MOVE BGR00-NODATA TO <F>.
ENDDO.
MOVE AUXREC TO BKNA1.

* Read and convert existing data:
DO.
" Read data record:
READ DATASET OLDFILE INTO OLDREC.
IF SY-SUBRC NE 0. EXIT. ENDIF.
" Check data and transfer only certain records:
IF OLDREC-CUSTNR(5) NE ‘AABBC’
OR OLDREC-CUSTNR(6) EQ ‘AABBCD’
OR OLDREC-TELE1 EQ SPACE.
TRANSFER OLDREC TO ERRFILE.
* TEXT-001: ‘Data not transferred for customer:’
WRITE: / TEXT-001, OLDREC-CUSTNR.
ELSE.
" Convert the customer number to SAP convention:
IF OLDREC-CUSTNR+5(1) = ‘C’.
IF OLDREC-CUSTNR+5(1) = ‘D’.
ENDIF.
" Convert abbreviations to full words:
CASE OLDREC-TITLE.
WHEN ‘Co’. BKNA1-TITLE = ‘Company’.
WHEN ‘Corp’. BKNA1-TITLE = ‘Corporation’.
WHEN OTHERS. BKNA1-TITLE = NODATA.
ENDCASE.
" Convert records from old format to SAP format:
MOVE: OLDREC-CUSTNR TO CUSTNR,
OLDREC-NAME1 TO NAME1,
OLDREC-TELE1 TO TELE1.
" Fill SAP structures:
MOVE: ‘1’ TO BKNOO-STYPE,
‘XD02’ TO BKNOO-TCODE,
CUSTNR TO BKNOO-CKUNNR.
MOVE: ‘2’ TO BKNA1-STYPE,
‘BKNA1’ TO BKNA1-TBNAM,
‘TELE1 TO BKNA1-TELF1,
NODATA TO BNKA1-SENDE.
" Transfer data to SAPFILE:
TRANSFER: BKNOO TO SAPFILE,
BKNA1 TO SAPFILE.
* TEXT-02: ‘Data was transferred for customer:’
WRITE: / TEXT-002, OLDREC-CUSTNR, BKNOO-CUSTNR.
ENDIF.
ENDDO.
CLOSE DATASET: OLDFILE, SAPFILE, ERRFILE.