BC420_46C - 007Sequential Files

Embed Size (px)

Citation preview

  • 8/11/2019 BC420_46C - 007Sequential Files

    1/48

    0

    SAP AG 1999

    File Monitor

    Sequential Files

    Local Sequential Files

    Logical File Names

    Sequential Files: Contents

    SAP AG BC420 7-1

  • 8/11/2019 BC420_46C - 007Sequential Files

    2/48

    0.2

    SAP AG 1999

    Use the file monitor to monitor files anddirectories

    Read and write to sequential files on thea lication ser!er and the resentation ser!er

    Maintain and use logical file names

    "t the conclusion of this unit# $ou will %e a%le to:

    Sequential Files: Unit &%'ecti!es

    SAP AG BC420 7-2

  • 8/11/2019 BC420_46C - 007Sequential Files

    3/48

    0.(

    SAP AG 1999

    Course &!er!iew )iagram

    )aten*%ernahme

    )+ ,or-%ench

    LSM ,or-%ench

    rinci les of Standard)ata /ansfer

    ) i r e c

    t 0 n u

    t

    1"

    / "

    R e c o r d e r

    Course &!er!iew

    1 a

    t c h 0 n u

    t

    C a

    l l / r a n s a c

    t i o n

    (

    3)

    1asics

    4

    5

    6

    7 80

    8880

    9

    88

    86

    8(

    82

    88

    82

    8

    2

    SAP AG BC420 7-3

  • 8/11/2019 BC420_46C - 007Sequential Files

    4/48

    0.6

    SAP AG 1999

    &!er!iew of Content Sequential Files

    &!er!iew ; File Monitor &!er!iew ; File Monitor

    Sequential FilesSequential Files

    Local Sequential FilesLocal Sequential Files

    Logical File NamesLogical File Names

    SAP AG BC420 7-4

  • 8/11/2019 BC420_46C - 007Sequential Files

    5/48

    0.4

    SAP AG 1999

    R

  • 8/11/2019 BC420_46C - 007Sequential Files

    6/48

    0.5

    SAP AG 1999

    " lication

    R

  • 8/11/2019 BC420_46C - 007Sequential Files

    7/48

    0.

    SAP AG 1999

    78.98.:;;; :

  • 8/11/2019 BC420_46C - 007Sequential Files

    8/48

    0.7

    SAP AG 1999

    #irectory 22iwdf?9?:2sapmnt2trans

    "ame *ength )reator *ast )hange0000000000000000000000000000000000000000000000000000000000000000000000...B)?79T!$T F;9 Administ :8.98.:;;; :9=

  • 8/11/2019 BC420_46C - 007Sequential Files

    9/48

    0.9

    SAP AG 1999

    &!er!iew ; File Monitor &!er!iew ; File Monitor

    Sequential FilesSequential Files

    Local Sequential FilesLocal Sequential Files

    Logical File NamesLogical File Names

    &!er!iew of Content Sequential Files =2>

    SAP AG BC420 7-9

  • 8/11/2019 BC420_46C - 007Sequential Files

    10/48

    0.80

    SAP AG 1999

    rocessfile

    & enfile

    Closefile

    File rocessing

    Before data records can be written to a sequential file or read from a file, the file has to be opened.

    After processing the file is closed again.

    SAP AG BC420 7-10

  • 8/11/2019 BC420_46C - 007Sequential Files

    11/48

    0.88

    SAP AG 1999

    &!er!iew )iagram: Read File

    No

    ?es

    )efine structure& en file

    Read data record

    rocess datarecord

    Close file

    3nd of filereached@

    A file processing program must define the required structures for the data records using a TAB*!$or #ATA statement. These structures are used as program0internal wor3 areas for the data records.

    The P!" statement is used to begin file processing and open the source and target sequential filesfor reading or writing.

    Rea)ing: The %!A# #ATA$!T statement is used to rea) the records from the source file into thedata structures for later processing in the program.

    ,riting: T%A"$(!% statements are used to trans*er the filled structures to the target file.

    The )* $! #ATA$!T statement is used to end file processing and close the sequential files.

    SAP AG BC420 7-11

  • 8/11/2019 BC420_46C - 007Sequential Files

    12/48

    0.82

    SAP AG 1999

    &!er!iew )iagram: ,rite File

    No

    ?es

    Fill structure

    /ransfer structure

    Close file

    More data records@

    & en file )efine structure

    $ee slide 6%ead file6.

    SAP AG BC420 7-12

  • 8/11/2019 BC420_46C - 007Sequential Files

    13/48

    0.8(

    SAP AG 1999

    REPORT xxx.:OPEN DATASET newfile FOR APPENDING.IF sy-subrc NE 0. EXIT. ENDIF.:

    OPEN DATASET filen!"e# $FOR %INP&T ' O&TP&T ' APPENDING().

    rocessfile

    & enfile

    Closefile

    F&R N U/ is the default

    & en File

    You can explicitly open a file using the command P!" #ATA$!T Hfile nameI.

    +f the file can be opened, $Y0$ B%) is set to 9, otherwise it is set to >. Any errors are ignored.

    /e recommend, for reasons of clarity, that you open the file explicitly. sing the P!" #ATA$!Tstatement allows you to test whether an error has occurred when you open the file &$Y0$ B%) J>'. +f you do not explicitly open the file, a %!A# #ATA$!T or T%A"$(!% command will attemptto open the file using the default mode. +n this case, if an open error occurs, you cannot trap the error and the program will terminate processing.

    Possible additions=

    ( % +"P Tpens an existing file to read it. +f the file was already open, the file is read from the beginning.

    ( % +"P T is the default.

    ( % TP Tpens the file to write it. +f the file exists already, the contents are deleted. +f the file does not

    exist, it is created.

    ( % APP!"#+"5pens the file to append records to the end of the file. +f the file does not exist, it is created. +f the

    file exists and was already open, the pointer to the next record is moved to the end of the file.

    SAP AG BC420 7-13

  • 8/11/2019 BC420_46C - 007Sequential Files

    14/48

    0.86

    SAP AG 1999

    REPORT xxx.:OPEN DATASET newfile FOR APPENDING *ESSAGE +ex+.IF sy-subrc NE 0. EXIT. ENDIF.:

    OPEN DATASET filen!"e# $FOR %INP&T ' O&TP&T ' APPENDING() $IN %,INAR *ODE ' TEXT *ODE() $*ESSAGE fiel #).

    1 N"R? M&)3 is the default

    rocessfile

    Fileo en

    Closefile

    & en File: "dditions

    /hen you open a file, you can choose between B+"A%Y and T! T mode.

    +" B+"A%Y #! 0 the length of the data input from a %!A# #ATA$!T or output from aT%A"$(!% is dependent on the length of the structure being used in the operation.

    +" T! T #! 0 the length of the data input from a %!A# #ATA$!T or output is dependent onthe end of record indicator.

    /ithout an addition the file in the binary mode is opened.

    Th P!" command can also return a message by using the addition !$$A5! HfieldI. Theassociated operating system message is stored in the field HfieldI, if there is an error opening thefile.

    SAP AG BC420 7-14

  • 8/11/2019 BC420_46C - 007Sequential Files

    15/48

    0.84

    SAP AG 1999

    R

  • 8/11/2019 BC420_46C - 007Sequential Files

    16/48

    0.85

    SAP AG 1999

    R

  • 8/11/2019 BC420_46C - 007Sequential Files

    17/48

    0.8

    SAP AG 1999

    R

  • 8/11/2019 BC420_46C - 007Sequential Files

    18/48

    0.87

    SAP AG 1999

    1/OSE DATASET filen!"e#.

    DE/ETE DATASET filen!"e#.

    rocessfile

    & enfile

    Closefile

    Close < )elete File

    The command )* $! #ATA$!T Hfile name I closes a sequential file. !rrors are ignored the sameas with P!" #ATA$!T.

    /ithin a program when the screen is changed all open files are shut and opened again with their oldstatus when processing is started again.

    All files are closed when the program is exited.

    /e recommend, for reasons of clarity, that you open and close the file directly. P!" #ATA$!T hasalso the advantage that if an error does occur when you open the file &$Y0$ B%) J >', it will notresult in a termination.

    A file is not implicitly closed, if %!A# #ATA$!T reaches the end of the file.

    /ith the command #!*!T! #ATA$!T Hfile nameI you can physically delete a sequential file.The file will then not longer exist in the operating system. nce it has been deleted, $Y0$ B%) isset to 9.

    The current file status can be displayed in debugging.

    SAP AG BC420 7-18

  • 8/11/2019 BC420_46C - 007Sequential Files

    19/48

    0.89

    SAP AG 1999

    "/" is the NODATA character

    ... ... < ... < b5nb; TO 2u+file;. ...ENDOO.

    Fills session header

    a#s the data

    $el# structure for record layout b%n&&'init is filled !ith NODATA

    (nitiali)es structure

    The code shows the important steps from initialiKing the help structures through to writing the recordlayouts.

    SAP AG BC420 7-22

  • 8/11/2019 BC420_46C - 007Sequential Files

    23/48

    0.2(

    SAP AG 1999

    3Aam le of Formatting

    REPORT xxx.:FOR* f2r"!+. 1ASE rec3le7!cy-s6r!s. ?4EN 8E8. Rec3c2n

  • 8/11/2019 BC420_46C - 007Sequential Files

    24/48

    0.26

    SAP AG 1999

    &!er!iew ; File Monitor &!er!iew ; File Monitor

    Sequential FilesSequential Files

    Local Sequential FilesLocal Sequential Files

    Logical File NamesLogical File Names

    &!er!iew of Content Sequential Files =(>

    SAP AG BC420 7-24

  • 8/11/2019 BC420_46C - 007Sequential Files

    25/48

    0.24

    SAP AG 1999

    1A// F&N1TION@DO?N/OAD@

    1A// F&N1TION@DO?N/OAD@

    1A// F&N1TION@&P/OAD@

    1A// F&N1TION@&P/OAD@

    Con!ersiona ro riate for file t$ e

    Con!ersiona ro riate for for file t$ e

    resentation ser!er

    File name:

    File t$ e:

    )ownload and U load

    sing the function module # /"* A# you can transfer the contents of an internal table to a localfile.

    sing the function module P* A# you can transfer the contents from a local sequential file intoan internal table.

    !nter the whole file path and name of the local file &e.g. L-tmp-myfileL for a nix file and e.g. L)=2Y(+*!.T TL for a P) file'.

    The presentation server must 3now the directory.

    )ustomers can choose an appropriate file name.

    The system as3s you for the file name and file type.The data is then converted into the appropriate file type.

    SAP AG BC420 7-25

  • 8/11/2019 BC420_46C - 007Sequential Files

    26/48

    0.25

    SAP AG 1999

    C"LL FUNC/ &N G)&,NL&")G3+ &R/ NH 1 NIF L3S J3 D Klength of %inar$ file C&)3 "H3 D Kdo not use F L3N"M3 D Kdefault file name F L3/? 3 D Kdefault file t$ e /3M D Ktitle of file dialog M&)3 D Kwrite mode ,E8INIF&RM"/ D K!alue column for ,E8 file t$ e ,E8INIS J3 D Kwidth of !alue column for ,E8 file t$ e ,E8I/IF&RM"/ D Kformat of teAt column for ,E8 file t$ e ,E8I/IS J3 D Kwidth of teAt column for ,E8 file t$ e

    M &R/ NH "C/IF L3N"M3 D Kfile name !alue entered "C/IF L3/? 3 D Kfile t$ e !alue entered F L3S J3 D KNum%er of %$tes transferred

    /"1L3S )"/"I/"1 D K/ransfer ta%le with file contents

    )&,NL&") Function Module

    (or the function module # /"* A# you need an internal table for the data transfer. You candefine this table to fit your data structure and then fill it with your data.

    /ith the parameter #! you can decide which write mode is used &LAL for extend file, L L for createnew file'.

    +f you want, you can specify default values for the file name and file type and enter a title for the filedialog.

    The + P %T parameters specify the actual values entered by the user for the file name and file typeand also the number of bytes transferred.

    +f the function module # /"* A# stores a file under # $, the export parameter ) #!PA5!must be set to L+B O. The parameter has no other meaning.

    All ! P %T+"5 parameters are optional.

    +f a binary file is to be created, the file length must be specified. +n this case the transfer table mustconsist of one column of type &hexadecimal numbers'.

    SAP AG BC420 7-26

  • 8/11/2019 BC420_46C - 007Sequential Files

    27/48

    0.2

    SAP AG 1999

    REPORT s!6bc B03seC 3 2wnl2! .

    T PES: ,EGIN OF rec+y6e>5unnr /I E 5n!;-5unnr>l!n ; /I E 5n!;-l!n ;>n!"e; /I E 5n!;-n!"e;>s+r!s /I E 5n!;-s+r!s>2r+0; /I E 5n!;-2r+0;>

    6s+l /I E 5n!;-6s+l >END OF rec+y6e.

    DATA: i+!b T PE STANDARD TA,/E OF rec+y6e ?IT4 E 5unnr ?IT4 4EADER /INE.

    SE/E1T 5unnr l!n ; n!"e; s+r!s 2r+0; 6s+lFRO* 5n!; INTO 1ORRESPONDING FIE/DS OF TA,/E i+!b.

    1A// F&N1TION 8DO?N/OAD8TA,/ES

    !+!3+!b i+!b....

    3Aam le: )&,NL&")

    +n the coding example the $!*!)T commands reads customer data from table D"A: and puts it intoan internal table that has already been defined.

    Then the function module # /"* A# stores the internal table on the presentation server.

    SAP AG BC420 7-27

  • 8/11/2019 BC420_46C - 007Sequential Files

    28/48

    0.27

    SAP AG 1999

    C"LL FUNC/ &N GU L&")G

    3+ &R/ NH C&)3 "H3 D Kdo not use F L3N"M3 D Kdefault file name F L3/? D Kdefault file t$ e /3M D Ktitle of file dialog

    M &R/ NH

    F L3S J3D D Kfile length

    /"1L3S )"/"I/"1 D K/ransfer ta%le with file contents

    U L&") Function Module

    (or the function module P* A# you need an internal table for the data transfer. You can definethis table to fit your data structure at the start of the program.

    +f you want, you can specify default values for the file name and file type and enter a title for the filedialog.

    +f the function module P* A# stores a file under # $, the export parameter ) #!PA5! must beset to L+B O. The parameter has no other meaning.

    SAP AG BC420 7-28

  • 8/11/2019 BC420_46C - 007Sequential Files

    29/48

    0.29

    SAP AG 1999

    REPORT s!6bc B03seC 3u6l2! .T PES: ,EGIN OF rec+y6e>

    5unnr /I E 5n!;-5unnr> l!n ; /I E 5n!;-l!n ;> n!"e; /I E 5n!;-n!"e;> s+r!s /I E 5n!;-s+r!s> 2r+0; /I E 5n!;-2r+0;> 6s+l /I E 5n!;-6s+l >

    END OF rec+y6e.

    DATA: i+!b +y6e s+!n !r +!ble 2f rec+y6e wi+ 5ey 5unnr.

    1A// F&N1TION 8&P/OAD8TA,/ES

    !+!3+!b i+!b.... /OOP AT i+!b. ?RITE: 9 i+!b-5unnr> i+!b-l!n ;> i+!b-n!"e; 0H>

    i+!b-s+r!s 0H> i+!b-6s+l > i+!b-2r+0; 0H.END/OOP.

    3Aam le: U L&")

    +n the coding example the function module P* A# reads a local sequential file from the presentation server and puts it in an internal table that has already been defined.

    Then the internal table is output using * P.

    SAP AG BC420 7-29

  • 8/11/2019 BC420_46C - 007Sequential Files

    30/48

    0.(0

    SAP AG 1999

    &!er!iew ; File Monitor &!er!iew ; File Monitor

    Sequential FilesSequential Files

    Local Sequential FilesLocal Sequential Files

    Logical File NamesLogical File Names

    &!er!iew of Content Sequential Files =6>

    SAP AG BC420 7-30

  • 8/11/2019 BC420_46C - 007Sequential Files

    31/48

    0.(8

    SAP AG 1999

    *N(+

    NT

    ,,,

    Logicalfile name

    h$sicalfile name

    /usr

  • 8/11/2019 BC420_46C - 007Sequential Files

    32/48

    0.(2

    SAP AG 1999

    Logical ath and Logical File

    8.> )efinition of logical ath-'.AT$ Demo for lo , #ath

    2.> "ssignment logOcal ath h$sical ath

    (.> )efinition of logical file

    S$ntaA Hrouh$sical ath

    )efinition

    h$sical fileLogical ath

    Name

    )efinitionName

    W(NDOW0 NT 1trans1mnt12filename3

    B456&,txt -'.AT$

    Demo for lo ical file-'F(7E

    Results with N/ ser!er: 1trans1mnt1B456&,txt

    You can create logical paths and files using the )ustomiKing transaction 1(+*!1.

    Platform0specific physical path must contain the reserved word H(+*!"A !I as the placeholderfor the file name. +t may also contain other reserved words 0 see the documentation &(: help'.

    SAP AG BC420 7-32

  • 8/11/2019 BC420_46C - 007Sequential Files

    33/48

    0.((

    SAP AG 1999

    Reser!ed ,ords

    DATE# EAR# *ONT4# DA #

    3Aam les of reser!ed words =

    h$sical fileLogical ath

    )efinitionName

    B456&'2DATE3,txt -'.AT$

    Demo for lo ical file !ith date-'F(7E'DATE

    Results with N/ Ser!er: 1trans1mnt1B456&'6&&&&689,txt

    /hese fields are set%$ the currents$stem date

    You can used reserved words that are replaced at runtime by current values. These reserved wordsare always contained within angle brac3ets.

    You can see an overview of all the reserved words in the documentation about logical file names &(:help'.

    SAP AG BC420 7-33

  • 8/11/2019 BC420_46C - 007Sequential Files

    34/48

    0.(6

    SAP AG 1999

    DATA: file li5e filen!"e-filein+ern....

    1A// F&N1TION 8FI/E3GET3NA*E8 EXPORTING l27ic!l3filen!"e J3FI/E8 I*PORTING FI/E3NA*E file EX1EPTIONS FI/E3NOT3FO&ND ; OT4ERS B.

    IF sy-subrc # 0. ?ri+e: 9 8file n2+ f2un 8. EXIT.E/SE. ?ri+e: 9 86 ysic!l file is > file.ENDIF....

    (he lo$ical %ile is animport parameter o% the

    %unction module

    Dependin$ on the operatin$

    system the physical %ilename is returned

    F L3IH3/IN"M3 Function Module

    The file name form is dependent on the operating system. Portable programs can be implemented byusing the function module -IL"_G"'_(A!" . This function module provides the physical filename associated with a specified logical file name. You can find a description of the function modulein the documentation for the (unction Builder &*ibrary of function modules'.

    SAP AG BC420 7-34

  • 8/11/2019 BC420_46C - 007Sequential Files

    35/48

    0.(4

    SAP AG 1999

    Use the file monitor to monitor files anddirectories on the a lication ser!er

    Use the R3") and /R"NSF3R statements to readand write to sequential files

    Use the u load and download function modules toread and write to internal ta%les as local

    sequential files on the resentation ser!er Create logical files in Customi ing and call themin "1" rograms through the function moduleF L3IH3/IN"M3

    ?ou are now a%le to:

    Sequential Files: Unit Summar$

    SAP AG BC420 7-35

  • 8/11/2019 BC420_46C - 007Sequential Files

    36/48

    ".ercise 1/nit: Se0uential -iles

    'opic: op2ing a Se0uential *ile *ro+ t3e ApplicationServer to t3e resentation Server

    /rite a program that reads a sequential file containing external datafrom the application server and writes it to the presentation server&P)'.

    rogra+: J,1 B03KK31OP 3DE,3TO3P1

    Solution: SAP,1 B03SELS31OP 3DE,3TO3P1

    /rite ZBC420_##_COPY_DEB_TO_PC to copy source file BC420_DEBI.LEG from theapplication server to the presentation server. &e.g. to )=2temp2B)?79@ @#!B+.*!5'.The source file containing debtor data can be found in the #+%@C ! directory on theapplication server.

    )reate the program in the development class ZBC420-## . se the function module Download .The file name of the source file and the target file should be specified as the parameters on theselection screen.

    The parameter for the function module must have a specific data type &see function moduleinterface'.

    The structure of the source file REC_LEGACY can be included into the program using theinclude SAPBC420_SE I_DEBI_LEGACYS!R"C .

    Tip=/hen you define the file within the program, the path details may be omitted as the#+%@C ! directory is automatically used.

    SAP AG BC420 7-36

  • 8/11/2019 BC420_46C - 007Sequential Files

    37/48

    Solution 1

    /nit: Se0uential -iles

    Solution SA B 45$_S"6S_ O Y_D"B_'O_*&---------------------------------------------------------------------*

    *& Report SAPBC420_SEQS_COPY_DEB_TO_PC

    *&---------------------------------------------------------------------*

    *& Downloads !le "le#a$% de !tors' to PC *

    *&---------------------------------------------------------------------*

    REPORT SAPBC420_SEQS_COPY_DEB_TO_PC(

    * le#a$% de !tor - str)$t)re

    +C, DE sap $420_se.!_de !_le#a$%str)$(

    * /le w!t le#a$% data

    para1eters as/le"300' t%pe $ de a)lt 5 $420_de !(le#56

    p$/le t%pe R,7RAP- ,E+A8E de a)lt 5C 9Te1p9BC420_::_DEB (,E75 lower $ase(

    * nternal ta le or lo$al dataset de/ned w!t Ta le /elds

    DATA !ta l!;e STA+DARD TAB,E O REC_,E7ACY

    < T= >EY ;)nnr < T= =EADER , +E(

    open dataset as/le !n te?t 1ode(

    ! s%-s) r$ @ 0(

    wr!te 5ERROR $o)ld not open /le 56 as/le(

    end! (

    * read le#a$% data ro1 Appl(-Ser er and download to PC

    do(

    read dataset as/le !nto re$_le#a$%(

    ! s%-s) r$ @ 0( e?!t( end! (

    append re$_le#a$% to !ta (

    enddo(

    SAP AG BC420 7-37

  • 8/11/2019 BC420_46C - 007Sequential Files

    38/48

    $lose dataset as/le(

    * )st $ e$; ! !ta !s o;a%

    loop at !ta !nto re$_le#a$%(

    wr!te re$_le#a$%(endloop(

    CA,, +CT O+ 5DO+O

  • 8/11/2019 BC420_46C - 007Sequential Files

    39/48

    ".ercise 5/nit: Se0uential -iles

    'opic: op2ing a Se0uential -ile *ro+ t3e resentationServer to t3e Application Server

    /rite a program that reads a sequential file containing external datafrom the presentation server &P)' and writes it to the applicationserver.

    rogra+: J,1 B03KK31OP 3DE,3TO3AS

    Solution: SAP,1 B03SELS31OP 3DE,3TO3AS

    /rite program ZBC420_##_COPY_DEB_TO_AS to copy source file BC420_##_DEBI.LEG from the presentation server to the application server.You should find source file B)?79@ @#!B+.*!5 in directory 1)=2temp21 on the presentationserver &see exercise :'. +f you cannot find it, you can create it there using programSAPBC420_SEQS_COPY_DEB_TO_PC .

    )reate the program in the development class ZBC420-## . se the function module "pload .The file name of the source file and the target file should be specified as parameters on the

    selection screen.The parameter for the function module must have a specific data type &see function moduleinterface'.

    The structure of the source file REC_LEGACY can be included in the program using theinclude SAPBC420_SE I_DEBI_LEGACYS!R"C .

    #isplay the file in the file monitor &Al::'.

    Tip=/hen you define the file within the program, the path details may be omitted as the#+%@C ! directory is automatically used.

    SAP AG BC420 7-39

  • 8/11/2019 BC420_46C - 007Sequential Files

    40/48

    Solution 5

    /nit: Se0uential -iles

    Solution SA B 45$_S"6S_ O Y_D"B_'O_AS*&---------------------------------------------------------------------*

    *& Report SAPBC420_SEQS_COPY_DEB_TO_AS *

    *&---------------------------------------------------------------------*

    *& Trans ers !le ro1 PC to Appl!$at!on Ser er *

    *&---------------------------------------------------------------------*REPORT SAPBC420_SEQS_COPY_DEB_TO_AS(

    * le#a$%-/le str)$t)r

    !n$l)de SAPBC420_SEQ _DEB _,E7ACYSTR C(

    * /le de/n!t!ons

    PARA8ETERS as/le"300' TYPE $ DE A ,T 5 $420_::_de !(le#56

    p$/le t%pe R,7RAP- ,E+A8E

    DE A ,T 5C 9Te1p9 $420_::_de !(le#5(

    * nternal ta le or lo$al dataset de/ned w!t Ta le /elds

    DATA !ta , >E STA+DARD TAB,E O re$_le#a$%

    < T= >EY ;)nnr < T= =EADER , +E(

    * pload t e data ro1 t e PC !nto t e !nternal ta le !ta

    CA,, +CT O+ 5 P,OAD5

    EFPORT +7 /lena1e G p$/le

    TAB,ES

    data_ta G !ta

    EFCEPT O+S

    $on ers!on_error G 3

    !n al!d_ta le_w!dt G 2

    !n al!d_t%pe G J

    no_ at$ G 4

    )n;nown_error G K

    #)!_re )se_/letrans er G L

    SAP AG BC420 7-40

  • 8/11/2019 BC420_46C - 007Sequential Files

    41/48

    OT=ERS G M(

    s%-s) r$ @ 0(

  • 8/11/2019 BC420_46C - 007Sequential Files

    42/48

    ".ercise 7/nit: Se0uential -iles

    'opic: ,or&ing %it3 Se0uential -iles 8 reating aonversion rogra+ *or Debtor Data

    /riting of a program that reads a sequential file with legacy data, thatconverts the legacy data to the record layout format and then writes inan output file.

    The data transfer from the # 0/B must be started with this outputfile. The result is a B+ session, which is run later.

    The analysis of the transfer process to be selected, as well as the analysis

    of the $AP record layout structures has been completed.You should write a conversion program now, in order to convert thelegacy data in the $AP record layout format.

    rogra+: J,1 B03KK31ON=ERT3DE,I

    'e+plate progra+: SAP,1 B03SELT31ON=ERT3DE,I; 2r SAP,1 B03SELT31ON=ERT3DE,IB

    Solution: SAP,1 B03SELS31ON=ERT3DE,I

    : /rite a program J,1 B03KK31ON=ERT3DE,I to import and convert legacy debtorsin the source file BC420_##_DEBI.LEG.

    The path is automatically generated in the template program and must not be especiallyset. (ile BC420_##_DEBI.SAP should be written as the output file.

    Tips=The necessary source and target structures are already set in +")* #! files, too.There are two template programs. You should use one of them as a template for yoursolution.SAPBC420_SEQT_CONVERT_DEBI1 contains a large number of notes concerning thestatements that are still missing. Please complete them.

    SAPBC420_SEQT_CONVERT_DEBI2 contains fewer statements and therefore should be used by participants with a sound 3nowledge of ABAP.

    :0: The opening and closing of the sequential files is specified according to thetemplate program &the data variables in il$% o&' il$and $(( il$ are already

    predefined with the matching path and can be used directly'.

    :07 (orm routines to initialiKe and fill the record layouts are already prepared and partly contain coding. Please complete the coding.

    SAP AG BC420 7-42

  • 8/11/2019 BC420_46C - 007Sequential Files

    43/48

    :0 %ead the legacy data in a loop. Build the record layout structures in this loop.$ave the record layout structures in the target file.+ncorrect records are records in which the old debtor number has not been filledin &filled with a blan3 character'. /rite these incorrect records in the error file.

    :0 0: You have to format some fields before you assign them to the recordlayout fields=

    :0 07 Assign the old debtor number to the field BD"B:0A*TD". )reate thedebtor in the system with a new legacy number. The new number should

    be a reformatted :90digit debtor number. se 1 9 ;; 5 1 as a prefix.Because of the predefined variable aux3unnr&:9', this has already been

    performed. (ill in the last four digits of this new debtor number using theloop index $Y0+"#! &numbers 999:099:9 are supplied via a wor3 field

    " '. This is how the following debtor numbers are created= 9 ;;5$$$1 to 9 ;; 5$$1$ .

    :0 0 (or another formatting example change the language 3ey &$AP languageis 7 digits'. C+"T= se or write a form routine C)*+ER!_LA*G"AGE% in which the language 3ey is converted in a )A$! statement.Add the following languages= #0I#!, (0I(%, $0I!$, Q0IQA,!0I!".

    :0? /hen the program has been created, chec3 the structure of your record layout filewith the A*:: and the # 0/B.

    7 )reate a new run with two tas3s under your subproEect=ProEect name= &s$ old p(o,$ ' .$ubproEect name= &s$ old s& p(o,$ ' .%un definition name= BI-##% '(ans $( d$ 'o(s

    70: To be able to use your own programs in the # 0/B, you have to register themfirst. %egister your program RB)?79@ @) "4!%T@#!B+ as tas3 type APunder the program type %!P .

    707 )reate the following tas3=Technical name = /ap-## .#escription= ap debtorsTas3 type= AP$elect your mapping program from &the program type %!P 'S

    70 )reate the following tas3=Technical name = D$ i-##-load .#escription= *oad debtorsTas3 type= * A$elect the standard transfer program %(B+#!99 with program type B+"P.

    70? $tart the run and analyKe the flow trace.+mportant= /hen you perform the tas3 * A, chec3 the file f rst &flagchec3box'. +f there is no termination situation discovered, the session can becreated.

    70< Process the batch input session with the B+ onitor.

    SAP AG BC420 7-43

  • 8/11/2019 BC420_46C - 007Sequential Files

    44/48

    Solution 7

    /nit: Se0uential -iles

    Solution SA B 45$_S"6S_ O(#"R'_D"BI*&---------------------------------------------------------------------*

    *& Report SAPBC420_SEQS_CO+HERT_DEB *

    *&---------------------------------------------------------------------*

    *& So)r$e /le $onta!ns de !tors !n le#a$% or1at( *

    *& T !s data !s $on erted !nto SAP re$ord la%o)t or1at or data **& trans er w!t R B DE00 *

    *&---------------------------------------------------------------------*

    REPORT sap $420_se.s_$on ert_de ! 8ESSA7E- D $420 , +E-S IE 200(

    TAB,ES #r006 ;n006 ;na36 ;n 3(

    * !n$l)de $onta!ns str)$t)r o /le w!t SAP- or1atted data

    +C, DE sap $420_se.!_de !_le#a$%str)$(

    +C, DE $420_/ll_nodata(

    * elp str)$t)re "str)$t)re e.)als B>+00'

    DATA ;n00_nodata , >E ;n00(

    * elp str)$t)re "str)$t)re e.)als B>+A3'

    DATA ;na3_nodata , >E ;na3(

    * elp str)$t)re "str)$t)re e.)als B>+B3'

    DATA ;n 3_nodata , >E ;n 3(

    DATA n)1"4' TYPE n6 te?t"300'(

    PARA8ETERS

    new;)nnr"30' DE A ,T 5I-::-256 Nw!ll e new de !tor-no(

    !n/le"M0' de a)lt 5BC420_DEB (,E75 ,O

  • 8/11/2019 BC420_46C - 007Sequential Files

    45/48

    *--------------------

    * open /les

    OPE+ DATASET !n/le OR +P T + TEFT 8ODE 8ESSA7E te?t(

    s%-s) r$ +E 0(

    8ESSA7E e303 < T= !n/le(

    E+D ( OPE+ DATASET o)t/le3 OR O TP T + TEFT 8ODE 8ESSA7E te?t(

    s%-s) r$ +E 0(

    8ESSA7E e300 < T= o)t/le3(

    E+D (

    OPE+ DATASET err/le OR O TP T + TEFT 8ODE 8ESSA7E te?t(

    s%-s) r$ +E 0(

    8ESSA7E e300 < T= err/le(

    E+D (

    START-O -SE,ECT O+(

    *-------------------

    * /ll str)$t)re w!t nodata

    PER OR8 !n!t S +7 ;n00_nodata nodata(

    PER OR8 !n!t S +7 ;na3_nodata nodata(

    PER OR8 !n!t S +7 ;n 3_nodata nodata(

    * /ll str)$t)re #r00 PER OR8 /ll_ #r00(

    * wr!te data to /le

    TRA+S ER #r00 TO o)t/le3(

  • 8/11/2019 BC420_46C - 007Sequential Files

    46/48

    N wr!te data to /le

    TRA+S ER ;n00 TO o)t/le36

    ;na3 TO o)t/le36

    ;n 3 TO o)t/le3(

    +A5 TO ;n00-;to;d(

    n)1 G s%-!nde?( Ns%-!nde? !s set !n DO-E+DDO-,oop

    8OHE n)1 TO new;)nnr L"4'( N1o e new n)1 er

    8OHE new;)nnr TO ;n00-;)nnr(

    E+D OR8( N ,,_B>+00

    *&---------------------------------------------------------------------**& or1 ,,_B>+A3

    * /ll str)$t)re ;na3

    SAP AG BC420 7-46

  • 8/11/2019 BC420_46C - 007Sequential Files

    47/48

    *----------------------------------------------------------------------*

    OR8 /ll_ ;na3(

    8OHE 525 TO ;na3-st%pe6

    5B>+A35 TO ;na3-t na16

    re$_le#a$%-na1e3 TO ;na3-na1e36

    re$_le#a$%-sortl TO ;na3-sortl6 re$_le#a$%-stras TO ;na3-stras6

    re$_le#a$%-ort03 TO ;na3-ort036

    re$_le#a$%-pstl TO ;na3-pstl 6

    re$_le#a$%-land3 TO ;na3-land36

    re$_le#a$%-tel 3 TO ;na3-tel 3(

    PER OR8 $on ert_lan#)a#e( ND- DE E- E+ and so on

    re$_le#a$%-st$e# S + T A,(

    8OHE nodata TO ;na3-st$e#(

    E,SE(

    8OHE re$_le#a$%-st$e# TO ;na3-st$e#(

    E+D (

    E+D OR8( N ,,_B>+A3

    *&---------------------------------------------------------------------*

    *& or1 ,,_B>+B3

    * /ll str)$t)re ;n 3*----------------------------------------------------------------------*

    OR8 /ll_ ;n 3(

    8OHE 525 TO ;n 3-st%pe6

    5B>+B35 TO ;n 3-t na16

    53200005 TO ;n 3-a;ont6

    re$_le#a$%-;)nnr TO ;n 3-alt;n(

    * wr!te 5Alte +)11er G 56 re$_le#a$%-;)nnr(

    E+D OR8( N ,,_B>+B3

    SAP AG BC420 7-47

  • 8/11/2019 BC420_46C - 007Sequential Files

    48/48

    *---------------------------------------------------------------------*

    * OR8 Con ert_lan#) *

    *---------------------------------------------------------------------*

    OR8 $on ert_lan#)a#e(

    CASE re$_le#a$%-spras(