SEQUENTIAL FILES

Module Objectives

  • Describe the process of opening and closing files
  • Define binary mode and text mode
  • Define the TRANSFER and READ DATASET statements
  • Define the CLOSE DATASET and DELETE DATASET statements
  • Define ABAP statements to fill the fields of a structure
  • Define the process for reading, extending and creating a file

Data Imports and Exports

data imports and exports
Data imports and exports

Processing Files

there are three step of File processing.
  • Open file
  • Process file
  • Close file

Working with Sequential Files

Reading Data



OPEN DATASET <file name> FOR INPUT.


:


:


READ <file name> INTO <field>.


:


:


CLOSE DATASET <file name>.



Writing Data 





OPEN DATASET <file name> FOR OUTPUT.

: 




:

TRANSFER <field> TO <file name>.

: 




:

CLOSE DATASET <file name>.




style="display:block"
data-ad-format="fluid"
data-ad-layout="image-side"
data-ad-layout-key="-fg+5r+6h-fn+4k"
data-ad-client="ca-pub-4708127434193346"
data-ad-slot="2138425177">



 Example  Reading a File





REPORT YA80D035.


TABLES LFA1.


DATA: BEGIN OF REC,


LIFNR LIKE LFA1-LIFNR,


NAME1 LIKE LFA1-NAME1,


STRAS LIKE LFA1-STRAS,


ORT01 LIKE LFA1-ORT01,


END OF REC.


PARAMETERS


FILE(20) DEFAULT '/tmp/bc180/YA80D031'


LOWER CASE.


START-OF-SELECTION.


OPEN DATASET FILE FOR INPUT


IN TEXT MODE.


DO.


READ DATASET FILE INTO REC.


IF SY-SUBRC NE 0. EXIT. ENDIF.


WRITE: / REC-LIFNR, REC-NAME1,


/ REC-STRAS UNDER REC-NAME1,


/ REC-ORT01 UNDER REC-NAME1.


ENDDO.


CLOSE DATASET FILE.


Notes:

  • Changes for Open dataset with Unicode Checks active.
  • OPEN DATASETFILE FOR INPUT IN TEXT
  • MODE encoding utf-8.



Example Creating File in Binary Mode 



REPORT YA80D039.


TABLES: LFA1, LFBK.


INCLUDE B180D03I.


PARAMETERS:


FILE(20) DEFAULT '/tmp/bc180/YA80D039'


LOWER CASE.


START-OF-SELECTION.


OPEN DATASET FILE FOR OUTPUT


IN BINARY MODE.


GET LFA1.


MOVE-CORRESPONDING LFA1 TO REC1.


MOVE 'A' TO REC1-FLAG.


TRANSFER REC1 TO FILE.


WRITE REC1.


GET LFBK.


MOVE-CORRESPONDING LFBK TO REC2.


MOVE 'B' TO REC2-FLAG.


TRANSFER REC2 TO FILE.


WRITE REC2.


END-OF-SELECTION.


CLOSE DATASET FILE.




Example Reading a File in Binary Mode 




REPORT YA80D03A.


TABLES: RBC180A, RBC180B.


DATA: FLAG.


PARAMETERS


FILE(20) DEFAULT '/tmp/bc180/YA80D039'


LOWER CASE.


START-OF-SELECTION.


OPEN DATASET FILE FOR INPUT


IN BINARY MODE.


DO.


READ DATASET FILE INTO FLAG.


IF SY-SUBRC NE 0. EXIT. ENDIF.


CASE FLAG.


WHEN 'A'.


READ DATASET FILE INTO RBC180A.


WRITE: / RBC180A-LIFNR, RBC180A-NAME1,


/ RBC180A-ORT01 UNDER RBC180A-NAME1.


WHEN 'B'.


READ DATASET FILE INTO RBC180B.


WRITE: / RBC180B-BANKS UNDER RBC180A-NAME1,


RBC180B-BANKL, RBC180B-BANKN.


ENDCASE.


ENDDO.


END-OF-SELECTION.


CLOSE DATASET FILE.


Comments

Popular posts from this blog

SAP ABAP SELECT STATEMENT

SAP ADOBE FORMS

ABAP AUTHORIZATION CONCEPT