complete raeference to abap basics

Upload: sathish

Post on 28-Feb-2018

234 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/25/2019 Complete Raeference to ABAP Basics

    1/83

    SAP-ABAP

    ENTERPRISE RESOURCE PLANNING (ERP):ERP is a package which provides solution for departmental functionalities of

    an organization.

    SAP ADVANTAGES:

    SAP can support any database at the back end.

    Platform independent.

    Supports multiple languages.

    Faster bw networks.

    !an support any database in the backend.

    "ransaction failure is very less comparing # other erp packages

    $%.%&'(.

    SAP life cycle implementti!n" Package evaluation.

    Pro)ect planning and designing.

    Proto type.

    *ap analysis.

    +usiness process re,engineering.

    sw installation and testing.

    End user training.

    Application transportation.

    *o live.

    Support and maintenance.

    SAP ln#$cpe:

    -evelopment server $functional(.

    uality server$ testing(.

    Production server $end,user uses the system(.

    R!le !f ABAPe%:

    Screen creation.

    "able creation.

    -ata migration.

    Reporting. Redirecting SAP data from d,base to op devices.$scripts / forms(.

    R&'0 real time data processing.ABAP&0 advanced business application programming. 1f a language

    provides a d,base by default is called 2thgeneration language.

    1

  • 7/25/2019 Complete Raeference to ABAP Basics

    2/83

    R&' ARCITECTURE CO*PONENTS:

    +" DISPATCER -"his component acts as an interface between the P3 and

    AS. 1t receives user4s re5uest from P3 and allocates a work area for eachre5uest from the user.

    ," OR. PROCESS, "his component allocates memory area for each

    re5uest received from dispatcher on a roll,in and roll,out basis. 6nce a

    re5uest is processed7 the memory area is rolled out to allocate for ne8tre5uest from dispatcher.

    '" DATABASE CONNECTIVIT/

    , 6PE9 S3 , 1t receives each user4s re5uest in open S3 format

    $19SER"7 :P-A"E7 -E3E"E7 ;6-1F

  • 7/25/2019 Complete Raeference to ABAP Basics

    3/83

    "he development ob)ects in SAP is divided into two types>

    REPOSITOR/ OB2ECTS

    E?E!:"A+3E PR6*RA;S

    19!3:-E PR6*RA;S

    ;6-:3E P663 PR6*RA;S

    ;ESSA*E !3ASSES

    S:+R6:"19E P663S

    F:9!"169 *R6:PS

    !3ASS P663S

    DATA DICTIONAR/ OB2ECTS

    "A+3ES

    =1E@S

    -A"A " E9 $6P"169A3(

    CREATING A PAC.AGE IN SAP:

    PA!BA*E is a folder created by A+APer to store his own development ob)ectsin SAP.

    N3i4ti!n$ t! c%ete pc54e:

    Enter 4SE#4 "code in !ommand Prompt area of SAP EAsy Access Screen ,

    Press Enter , 6pens Package +uilder Screen , Select Package Radiobutton

    , Specify Package 9ame starting with G or < , !lick on !reate pushbutton, 6pens an interface , Enter Short -escription for your package , Select

    Software !omponent as 6;E , !lick on Save , 6Pens another interfaceto assign re5uest number , !lick on !REA"E RE:ES" , 6pens interface

    , Enter short description , !lick on !ontinue , A Re5uest number is

    3

  • 7/25/2019 Complete Raeference to ABAP Basics

    4/83

    created and assigned for your package , !lick on !ontinue , A package iscreated , Save , !ome back.

    CREATING PROGRA*S IN SAP EDITOR:

    SE&D is the "code used to open A+AP editor7 where we create source code.

    N3i4ti!n$ t! c%ete $imple p%!4%m in SE'6 E#it!%:

    SE&D , 6pens A+AP Editor 1nitial screen , Specify program name starting

    with G or < , Select Source !ode radio button , !lick on !reate

    pushbutton , 6pens another interface , Enter short description forprogram , Select Program type as E8ecutable Program , !lick on Save ,

    Specify Package 9ame , Assign re5uest number , !lick on continue ,6pens A+AP Editor page.

    C7%cte%i$tic$ !f ABAP P%!4%m:

    A+AP is not case sensitive.

    A+AP is case sensitive only during comparison.

    Every A+AP statement should end with a period $full stop(.

    !"R3HS shortcut key is used to save A+AP codes in editor.

    !"R3HF shortcut key is used to transform the screen into!A9*E-1SP3A< mode.

    !"R3HF# shortcut key is used to check for synta8 errors in source

    code.

    !"R3HF& shortcut key is used to activate current program.

    ACTIVATION:"his concept is used to make the current ob)ect to be accessible by other

    ob)ects within the same client or different client or vice versa.

    FD function key is used to e8ecute the A+AP program $-irect

    Processing(.

    !"R3HI is used to comment the A+AP statement.

    !"R3H is used to de comment the A+AP statement.

    =AR1A+3E -E!3ARA"169 19 A+AP>-A"A is the statement used to declare variables in A+AP.

    E4" c!#e:-A"A A "

  • 7/25/2019 Complete Raeference to ABAP Basics

    5/83

    1n the above code7 A is a variable of integer type. A is assigned a value4%%4. @R1"E statement is used to print out the value of A.

    "he output of a program is printed in 3PS $list,processing screen(.

    "he default value of an integer data type is 4%4.

    "he default value of a character data type is 49:334. An integer variable takes character spaces in 3PS screen to print

    out its value and the value is printed in right,)ustified manner.

    "he first % character space is used to print the value and the th

    character space is for sign $positive or negative(.

    e4" c!#e:

    -A"A A "

  • 7/25/2019 Complete Raeference to ABAP Basics

    6/83

    ABAP GUI

    A+AP screens can be created using the following two statements>

    . PARA;E"ERS#. SE3E"169,S!REE9

    "he following statements are used in common>

    +" PARA*ETERSto create input bo8es7 checkbo8es and radio buttons.

    #. SE3E!"169,S!REE9 +E*19 6F 319E , E9- 6F 319E. , "his statement isused to create input fields in a same row.

    '" SELECTION-SCREEN CO**ENT. , "his statement is used to specify thepositions and label names for each input field declared using begin of line ,

    end of line.

    e4" c!#e

    Selection,screen begin of line.

    selection,screen comment %$K( lb# for field a.

    Parameters> a $%(.

    selection,screen comment K%$K( lb& for field b.

    parameters > b$%(.

    selection,screen comment $K( lb2.

    parameters > c$%(.

    selection,screen end of line.

    selection,screen pushbutton %$%( 3+ user,command P+.

    1nitialization.lb J 4PR19"4.

    lb# J 4enter A value4.lb& J 4enter + value4.

    at SE3E!"169,S!REE9.

    6

  • 7/25/2019 Complete Raeference to ABAP Basics

    7/83

    case sy,ucomm.when 4P+4.

    3EA=E "6 31S",PR6!ESS19*.write > a7 b .

    endcase.

    " SELECTION-SCREEN POSITION"

    "his statement is used to specify the position of input fields. "here are two

    attributes for specifying position using this statement. "hey are>

    P6SL36@

    P6SL1*

    E*.

    SE3E!"169,S!REE9 +E*19 6F 319E.

    SE3E!"169,S!REE9 P6S1"169 [email protected];E"ERS A$%(.

    SE3E!"169,S!REE9 P6S1"169 P6SL1*.PARA;E"ERS +$%(.

    SE3E!"169,S!REE9 E9- 6F 319E.

    0" SELECTION-SCREEN BEGIN O8 SCREEN - END O8 SCREEN"

    , "his statement is used to create a screen in *:1. A screen number should

    be specified for each user,defined screen. "his screen can be called withinthe program using the following statement>

    CALL $electi!n-SCREEN 9$c%eenn;m R+ RA-16+:""69 *R6:P A7

    R+# RA-16+:""69 *R6:P A7 R+& RA-16+:""69 *R6:P A.

    SE3E!"169,S!REE9 E9- 6F +36!B +#.

    7

  • 7/25/2019 Complete Raeference to ABAP Basics

    8/83

    SE3E!"169,S!REE9 P:S+:""69 %$%( 3+ :SER,!6;;A9- P+.SE3E!"169,S!REE9 E9- 6F S!REE9 %%.

    SE3E!"169,S!REE9 +E*19 6F S!REE9 #%% AS @19-6@ "1"3E "#.

    PARA;E"ERS > -$%(7 E$%(7 F$%(.

    SE3E!"169,S!REE9 E9- 6F S!REE9 #%%.

    initialization.

    t J 4SE3E!" !E!B+6?ES A9- RA-16+:""69S4.

    "# J 4PARA;E"ERS4.

    at selection,screen.

    case sy,ucomm.

    @E9 4P+4.

    !A33 S!REE9 #%%.

    E9-!ASE.

    >" SELECTION-SCREEN BEGIN O8 BLOC. - END O8 BLOC."

    "his statement is used to create blocks within the screen area.

    ?" SELECTION-SCREEN PUSBUTTON. , "his statement is used to create

    pushbuttons in *:1.

    S

  • 7/25/2019 Complete Raeference to ABAP Basics

    9/83

    "6P,6F,PA*E.E9-,6F,PA*E.

    E9-,6F,SE3E!"169.

    E*. !6-E

    PARA;E"ERS > A$%(7 +$%(.

    SE3E!"169,S!REE9 P:S+:""69 %$%( 3+ :SER,!6;;A9- P+.

    191"1A31GA"169.3+ J 4PR19" A4.

    A" SE3E!"169,S!REE9.

    !ASE S A$%(7 +$%(.

    9

  • 7/25/2019 Complete Raeference to ABAP Basics

    10/83

    SE3E!"169,S!REE9 P:S+:""69 %$%( 3+ :SER,!6;;A9- P+.selection,screen skip.

    SE3E!"169,S!REE9 P:S+:""69 %$%( 3+# :SER,!6;;A9- P+#.

    191"1A31GA"169.

    3+ J 4PR19" A4.lb# J 4E?1"4.

    A" SE3E!"169,S!REE9.

    !ASE S ;ARA,;"AR".

    E9-SE3E!".

    @R1"E > S"A319,36@7 S"A319,1*7 S"A319,S1*97 S"A319,6P"169.

    @henever a range is created using SE3E!",6P"169S statement7 SAP creates

    an internal table with the same variable name $S"A319 in this case( in thebackground with the following fields>

    10

  • 7/25/2019 Complete Raeference to ABAP Basics

    11/83

    36@1*

    S1*96P"169

    ++" SELECTION-SCREEN 8UNCTION .E/S"

    "he pushbuttons declared in the header part of the screen are referred to asF:9!"169 BE

  • 7/25/2019 Complete Raeference to ABAP Basics

    12/83

    @E9 4F!%4.!A33 "RA9SA!"169 4SE4.

    @E9 4F!%&4.

    !A33 "RA9SA!"169 4SE&N4.

    @E9 4F!%24.

    !A33 "RA9SA!"169 4SE&D4.

    @E9 4F!%K4.

    3EA=E PR6*RA;.

    E9-!ASE.

    @hen we create function keys7 SAP automatically generates name for each

    function key. "he name of first function key is 4F!%4 7 the second one is4F!%#47 etc.

    So the name range for function keys start from F!% , F!%K.

    E*. PR6*RA; "6 !A33 SE3E!"169,S!REE9 @1" P:S+:""69S

    SE3E!"169,S!REE9 +E*19 6F 319E.

    SE3E!"169,S!REE9 !6;;E9" %$K( 3+.

    PARA;E"ERS > A$%(.

    SE3E!"169,S!REE9 !6;;E9" 2%$K( 3+#.

    PARA;E"ERS > +$%(.

    SE3E!"169,S!REE9 E9- 6F 319E.

    SE3E!"169,S!REE9 P:S+:""69 %$%( 3+& :SER,!6;;A9- P+.

    SE3E!"169,S!REE9 SB1P.SE3E!"169,S!REE9 P:S+:""69 %$%( 3+K :SER,!6;;A9- P+&.

    SE3E!"169,S!REE9 SB1P.SE3E!"169,S!REE9 P:S+:""69 %$%( 3+2 :SER,!6;;A9- P+#.

    MSE3E!"169,S!REE9 +E*19 6F S!REE9 #%% AS @19-6@ "1"3E "#.

    SE3E!"169,S!REE9 +E*19 6F +36!B +.

    12

  • 7/25/2019 Complete Raeference to ABAP Basics

    13/83

    PARA;E"ERS > ! AS !E!B+6?7 !# AS !E!B+6?7 !& AS!E!B+6?.

    SE3E!"169,S!REE9 E9- 6F +36!B +.

    SE3E!"169,S!REE9 +E*19 6F +36!B +#.

    PARA;E"ERS > R+ RA-16+:""69 *R6:P A7 R+# RA-16+:""69 *R6:P A7

    R+& RA-16+:""69 *R6:P A.

    SE3E!"169,S!REE9 E9- 6F +36!B +#.

    MSE3E!"169,S!REE9 E9- 6F S!REE9 #%%.

    191"1A31GA"169.3+ J 4E9"ER A =A3:E4.

    3+# J 4E9"ER + =A3:E4.3+& J 4-1SP3A 4F1RS" RA-16+:""694.

    13

  • 7/25/2019 Complete Raeference to ABAP Basics

    14/83

    E3SE1F R+# J 4?4.@R1"E > 4SE!69- RA-16+:""694.

    E3SE1F R+& J 4?4.@R1"E > 4"1R- RA-16+:""694.

    E9-1F.

    @E9 4P+#4.

    3EA=E PR6*RA;.

    @E9 4P+&4.

    !A33 SE3E!"169,S!REE9 #%%.E9-!ASE.

    E9 , 31+RAR< E3P

    14

  • 7/25/2019 Complete Raeference to ABAP Basics

    15/83

    DATA DICTIONAR/

    -ata dictionary ob)ects are>

    "A+3ES

    =1E@S

    -A"A E3E;E9"S

    -6;A19S

    SEAR! E3P

    36!B 6+CE!"

    "

  • 7/25/2019 Complete Raeference to ABAP Basics

    16/83

    Application table stands for master and transaction data table.

    1n master table7 reads are more7 writes are less.

    1n transaction table7 reads are less7 writes are more.

    *intennce:

    Specifies whether a table can be modified in the future or not. 1t is

    suggested to create a built,in type table with 4;A19"E9A9!E A336@E-4.

    Tec7nicl Settin4$:

    "his area has two attributes namely>

    -ata !lass , Specifies whether the table is application table or customizing

    table.

    Size !ategory , Specifies initial size for the table inside the database.

    TABLES CLASSI8ICATION BASED ON BU88ERING:

    S19*3E +:FFER19* , @henever a table is created with this option and whenthe user tries to access records from the database table7 a buffer is created

    in AS for only a single record.

    *E9ER1! +:FFER19* , +y default7 a buffer is created in AS for a single

    record. +ut depending on selection criteria7 buffer size can be increased ordecreased.

    select M from ItableLname up to % rows.

    F:33< +:FFER19* , +ased on the size category specified7 a buffer is createdin AS for the table.

    TABLES CLASSI8ICATION BASED ON CLIENT:!31E9",-EPE9-E9" "A+3E , 1f a first field of a table is 4;A9-"47 this table is

    called client,dependent table. "his type of table datas can be accessed fromonly within the same client.

    !31E9",19-EPE9-E9" "A+3E , 1f the first field is not 4;A9-"47 then this

    table is called as !31E9",19-EPE9-E9" table.

    16

  • 7/25/2019 Complete Raeference to ABAP Basics

    17/83

    :se the following code to access records from the e8isting database table>

    tables zstudtable.

    select M from zstudtable.

    write > zstudtable,studid7 zstudtable,studname7 zstudtable,studmarks.endselect.

    ere7 "A+3ES statement will create a temporary table memory area in AS.

    CREATING TABLE USING DATA ELE*ENTS AND DO*AINS:

    DO*AIN :"his data dictionary ob)ect is used to assign data type and length

    for a field to be created in a table.

    DATA T/PE OR DATA ELE*ENT :"his data dictionary ob)ect acts as alabel for the domain.

    N3i4ti!n$ f!% c%etin4 #!min:

    SE , Select -omain radiobutton , Specify name of the domain startingwith G or < , !reate , Enter short description , Select data type ,

    Enter length , Save , Activate.

    N3i4ti!n$ f!% c%etin4 #t element:

    SE , Select -ata "ype radiobutton , Specify name of the data element

    starting with G or < , !reate , Enter short description , Select 4-omain4radiobutton , Specify name of the domain you created previously , Press

    Enter , Save , Activate , !ome back.

    !reate a table with the same navigations. Select 4-A"A E3E;E9"4

    P:S+:""69 from the Fields tab button.

    Enter field name , Select the checkbo8 of initial field to declare it as aprimary key , Specify data element name , Press Enter.

    17

  • 7/25/2019 Complete Raeference to ABAP Basics

    18/83

    VIES:

    =iew is a data dictionary ob)ect.

    1t e8ists logically inside the data dictionary.

    1t is used to fetch datas from more than one database table. 1n views7 we specify the tables and SAP will automatically generate a

    )oin condition code in the background.

    N3i4ti!n$ t! c%ete 3ie:

    SE , Select 4=1E@4 radiobutton , Specify view name starting with G or

    data IinternalLtableLname like IdatabaseLtableLname occurs Isize

    with header line.

    -A"A CE*A9 31BE ;ARA 6!!:RS % @1" EA-ER 319E.

    data stalin like kna occurs % with header line.

    ere7 6!!:RS % specifies that internal table should initially take D B+ of

    memory area in AS.

    kb J %#2 bytes

    6ccurs % J D M %#2 bytes

    Inte%nl t

  • 7/25/2019 Complete Raeference to ABAP Basics

    24/83

    S/NTA O8 inte%nl t +E*19 6F @A7

    9A;E$%(7 !6:RSE$%(7

    E9- 6F @A.

    @A,9A;E J 4PRA=194.@A,!6:RSE J 4S3SER=ER4.

    @A,9A;E J 4-EEPA4.@A,!6:RSE J 46RA!3E4.

    @A,9A;E J 4S

  • 7/25/2019 Complete Raeference to ABAP Basics

    25/83

    name$%(7 course$%(7

    end of itab.

    itab,name J 4karthik4.

    itab,course J 4abap4.append itab.

    itab,name J 4pravin4.

    itab,course J 4s5l4.

    append itab.

    loop at itab.write > itab,name7 itab,course.

    endloop.

    1n the above code7 when e8ecuted7 an internal table in the name of 1"A+ is

    created without header line.

    APPENDstatement is used to insert the values into body area of theinternal table even if the record already e8ists.

    COLLECTstatement is also used to insert the values into body area of theinternal table7 but will check for inde8 value. 1f the record already e8ists7 it

    wont insert the same value.

    LOOP-ENDLOOPstatement is used to view the contents of internal tablebody area. :sing this statement7 we can view the entire contents of internaltable.

    "o view a single line from body area of internal table7 use READstatement.

    eg. code using REA- S"A"E;E9">

    data itab like mara occurs % with header line.select M from mara into table itab.

    loop at itab.write > sy,tabi87 itab,matnr7 itab,mbrsh7 itab,mtart7 itab,meins.endloop.

    read table itab inde8 N%.write > sy,tabi8 color K7 itab,matnr7 itab,mbrsh7 itab,mtart7 itab,meins.

    25

  • 7/25/2019 Complete Raeference to ABAP Basics

    26/83

    A structure can hold only record by default. "o allocate e8tra memory spacefor a structure to hold more values7 use the statement 6!!:RS %. :sing this

    statement7 an internal table structure is created with D B+ memory of bodyarea without header line.

    eg.

    -A"A > +egin of syed occurs %7name$%(7

    course$%(7

    End of syed.

    "o create an internal table with EA-ER 319E7 use 4@1" EA-ER 319E4statement.

    eg.

    -A"A -EEPA 31BE Idatabase table name 6!!:RS % @1" EA-ER 319E.

    9ow7 an internal table is created with header line and body area.

    EADER LINE :

    "his is a structure to hold field attributes of a table. "he size is by default

    created to hold record.

    BOD/ AREA :

    "his is a storage area for holding records fetched from database table.

    STATE*ENTS TO RITE OUT TE CONTENTS O8 INTERNAL TABLE:

    366P,E9-366P , :sed to view or write out the entire contents of internaltable body area.

    REA- , :sed to view or write out a single record we specify using inde8

    value from the internal table body area.

    1f we use REA- statement7 SAP performs binary search by default to fetch

    the inde8 value.

    Eg. code to insert user,defined values into database table using internaltable structure>

    26

  • 7/25/2019 Complete Raeference to ABAP Basics

    27/83

    -A"A 1"A+ 31BE ;ARA 6!!:RS % @1" EA-ER 319E.

    1"A+,;A"9R J 4;A"9:;+ER%4.1"A+,;+RS J 4P4.

    1"A+,;"AR" J 4!6:P4.

    1"A+,;E19S J 4B*4.APPE9- 1"A+.

    1"A+,;A"9R J 4;A"9:;+ER%#4.

    1"A+,;+RS J 4P4.

    1"A+,;"AR" J 4!6:P4.1"A+,;E19S J 4B*4.

    APPE9- 1"A+.

    1"A+,;A"9R J 4;A"9:;+ER%&4.

    1"A+,;+RS J 4P4.1"A+,;"AR" J 4!6:P4.

    1"A+,;E19S J 4B*4.APPE9- 1"A+.

    366P A" 1"A+.

    19SER" 19"6 ;ARA =A3:ES 1"A+.

    1F S

  • 7/25/2019 Complete Raeference to ABAP Basics

    28/83

    T/PES O8 INTERNAL TABLE:

    1nternal table is basically divided into two types>

    . 19-E?E- 19"ER9A3 "A+3ES

    , S"R:!":RE- 19"ER9A3 "A+3E, S"A9-AR- 19"ER9A3 "A+3E

    , S6R"E- 19"ER9A3 "A+3E

    #. 969,19-E?E- 19"ER9A3 "A+3ES

    , ASE- 19"ER9A3 "A+3E

    STRUCTURED INTERNAL TABLE:

    Any internal table declared or created using +E*19 6F , E9- 6F statement

    is called as structured internal table.

    eg.

    -A"A > +E*19 6F Iinternal table name7

    ..attributes... E9- 6F Iinternal table name.

    STANDARD INTERNAL TABLE:

    "his type of internal table performs the search for a record in the body areausing 319EAR SEAR! "E!91:E.

    S/NTA:

    -A"A IinternalLtableLname 31BE S"A9-AR- "A+3E 6FIdatabaseLtableLname

    .@1" -EFA:3"969,:91:E BE 1"A+,;A"9R7 1"A+,;+RS7 1"A+,;"AR"7 1"A+,;E19S.

    E9-366P.

    1f we try to read a single value from the above internal table body area7 alinear search will be performed. @hereas7 for normal internal table7 the

    default search is binary search.

    SORTED INTERNAL TABLE:

    "his internal table will hold the records from the database table in a sorted

    manner.

    S 1"A+,;A"9R7 1"A+,;+RS7 1"A+,;"AR"7 1"A+,;E19S.E9-366P.

    NON-INDEED ASED INTERNAL TABLE:

    S

  • 7/25/2019 Complete Raeference to ABAP Basics

    30/83

    "his internal table is not assigned any inde8 value. "he retrieval of records

    from internal body area is based on key field or a row.

    Eg. code

    -A"A 1"A+ 31BE ASE- "A+3E 6F ;ARA @1" :91:E BE< ;"AR" @1"

    EA-ER319E 191"1A3 S1GE %.

    SE3E!" M FR6; ;ARA 19"6 "A+3E 1"A+.

    366P A" 1"A+.@R1"E > 1"A+,;A"9R7 1"A+,;+RS7 1"A+,;"AR"7 1"A+,;E19S.

    E9-366P.

    For this type of internal table7 we have to specify only the primary key for a

    retrieval function.

    S/STE* VARIABLES USED IN INTERNAL TABLE:

    S/-T8ILL, "his system variable is used to describe number of recordsfetched and inserted into body area of internal table. +efore using this

    statement7 we have to use 4-ES!R1+E "A+3E4 statement.

    S/-TABI, "his system variable is used to create a loop iteration counter

    for internal table body area.

    S/-DBCNT, "his system variable is used to describe number of recordsfetched from database table.

    Eg. code

    -A"A 1"A+ 31BE B9A 6!!:RS % @1" EA-ER 319E.

    SE3E!" M FR6; B9A 19"6 "A+3E 1"A+.@R1"E > S S S

  • 7/25/2019 Complete Raeference to ABAP Basics

    31/83

    SORTING TE INTERNAL TABLE A8TER 8ETCING VALUES:

    S

    -A"A 1"A+ 31BE B9A 6!!:RS % @1" EA-ER 319E.

    SE3E!" M FR6; B9A 19"6 "A+3E 1"A+.@R1"E > S S

  • 7/25/2019 Complete Raeference to ABAP Basics

    32/83

    SUBROUTINES

    8OR* - END8OR* statement is used to create subroutines.

    PER8OR*statement is used to invoke the subroutine created.

    Subroutines are used to call a piece of code fre5uently within the program or

    e8ternally from other program.

    LOCAL SUBROUTINES:

    "he subroutine is called locally from the same program using PERF6R;

    statement.

    eg. code of local subroutine without any value>

    PERF6R; S"A319.

    F6R; S"A319.

    -6 K "1;ES.@R1"E > 4@E3!6;E "6 A+AP4.

    E9--6.

    E9-F6R;.

    eg. code of e8ternal subroutine without any value>

    create an e8ecutable program and write the following code>

    REP6R" GS:+R6:"19ES# .

    PERF6R; S"A319.

    F6R; S"A319.

    -6 K "1;ES.@R1"E > 4@E3!6;E "6 A+AP4.

    E9--6.E9-F6R;.

    Save , Activate.

    32

  • 7/25/2019 Complete Raeference to ABAP Basics

    33/83

    !reate another e8ecutable program and write the following code>

    REP6R" GS:+R6:"19ES.

    PERF6R; S"A319$GS:+R6:"19ES#(.

    Save , Activate , E8ecute.

    @e have to specify name of the program where subroutine is created within

    the bracket whenever we try to invoke the subroutine e8ternally.

    PASS B/ RE8ERENCE:

    -A"A > A$%( =A3:E 419-1A47 + " A$%( =A3:E 419-1A47 + "

  • 7/25/2019 Complete Raeference to ABAP Basics

    34/83

    PERF6R; -1SP3A< "A+3ES 1"A+ .

    F6R; -1SP3A< "A+3ES 1"A+ S"R:!":RE B9A.

    366P A" 1"A+.

    @R1"E > 1"A+,B:99R7 1"A+,9A;E7 1"A+,3A9-7 1"A+,6R"%.E9-366P.

    E9-F6R;.

    34

  • 7/25/2019 Complete Raeference to ABAP Basics

    35/83

    Rep!%t$Fetching re5uired data from the database and redirecting to the output

    devices or displaying the data in 3PS screen as per client4s re5uirements is

    the concept behind report generation.

    T/PES O8 REPORTS:

    . *RAP1!A3 REP6R"S

    #. A3= REP6R"S $A+AP 31S" =1E@ER(.&. *R6:P REP6R"S

    2. 19"ERA!"1=E REP6R"S

    K. !3ASS1!A3 REP6R"S $F6R;A""E- / :9 F6R;A""E-(.

    order of e8ecution of classical report>

    191"1A31GA"169.A" SE3E!"169,S!REE9.

    S"AR",6F,SE3E!"169.

    "6P,6F,PA*E.E9-,6F,PA*E.

    E9- 6F SE3E!"169.

    6R-ER 6F E?E!:"169 6F 19"ERA!"1=E REP6R">

    191"1A31GA"169.

    A" :SER,!6;;A9-.S"AR",6F,SE3E!"169.

    "6P,6F,PA*E.

    "6P,6F,PA*E -:R19* 319E SE3E!"169.E9- 6F PA*E.

    E9- 6F SE3E!"169.

    Cl$$icl %ep!%t"

    REP6R" +E*19 6F it occurs %7

    carrid like spfli,carrid7 connid like spfli,connid7

    35

  • 7/25/2019 Complete Raeference to ABAP Basics

    36/83

    cityfrom like spfli,cityfrom7 cityto like spfli,cityto7

    fltime like spfli,fltime7 E9- 6F it.

    select,options> carrid for spfli,carrid7

    connid for spfli,connid7 cityfrom for spfli,cityfrom.

    start,of,selection.

    select M from spfli into corresponding fields of table it where carrid

    in carrid and connid in connid and cityfrom in cityfrom.

    loop at it.write> it,carrid7 it,connid7 it,cityfrom7 it,cityto 7 it,fltime input on.

    endloop.

    top,of,page.

    write>K 4flight details4 color !63LEA-19*7 iconLgreenLlight AS 1!69 .

    .write>K 4,,,,,,,,,,,,,,4.

    end,of,page.

    GRAPICAL REPORTS:

    "hese type of reports are used display the database table in a graphical

    format either in two,dimensional or three,dimensional format.

    8UNCTION *ODULES USED IN GRAPICAL REPORTS:

    GRAPH_2D

    GRAPH_3D

    eg. code to generate graphical report for annual company sales>

    -A"A > +E*19 6F 1"A+ 6!!:RS %7

    36

  • 7/25/2019 Complete Raeference to ABAP Basics

    37/83

    !6;P9A;E$#%(7 !6;PSA3ES "

    REUSE_ALV_GRID_DISPLAY

    REUSE_ALV_LIST_DISPLAY

    eg. code>

    -A"A 1"A+ 31BE ;ARA 6!!:RS % @1" EA-ER 319E.

    SE3E!" M FR6; ;ARA 19"6 "A+3E 1"A+.

    M!A33 F:9!"169 4RE:SELA3=L31S"L-1SP3A

  • 7/25/2019 Complete Raeference to ABAP Basics

    38/83

    !A33 F:9!"169 4RE:SELA3=L*R1-L-1SP3A

    -A"A +ASBAR 31BE ;ARA 6!!:RS % @1" EA-ER 319E.

    SE3E!" M FR6; ;ARA 19"6 "A+3E +ASBAR.

    @R1"E >K$N%( S S$N%( S2%$K%( 4"1S 1S EA-ER AREA F6R "E REP6R"4 !636R 2

    !E9"ERE-.

    38

  • 7/25/2019 Complete Raeference to ABAP Basics

    39/83

    @R1"E >K$#%( 4;A"ER1A3 9:;+ER47 #N$K( 419-:S"R< SE!"6R47 2K$K(4;A"ER1A3 "2%$K%( 4"1S 1S F66"ER AREA F6R "E REP6R"4 !636R N

    !E9"ERE-.@R1"E > 4!:RRE9" PA*E 9:;+ER 1S47 S

    . RE:SELA3=L31S"L-1SP3A 4!:S"6;ER ;AS"ER -E"A13S F6R4 !636R 27 1"A+,3A9- !636R2.

    SB1P .E9-69.

    @R1"E > 1"A+,B:99R7 1"A+,9A;E7 1"A+,3A9-7 1"A+,6R"%.

    E9-366P.

    "6P,6F,PA*E.@R1"E >2%$2%( 4"1S 1S !:S"6;ER ;AS"ER -A"A4 !636R K.

    AT 8IRST-ENDAT:"his processing block gets triggered at the first pass of internal table loop.

    eg. code>

    -A"A 1"A+ 31BE B9A 6!!:RS % @1" EA-ER 319E.

    SE3E!" M FR6; B9A 19"6 "A+3E 1"A+.

    40

  • 7/25/2019 Complete Raeference to ABAP Basics

    41/83

    S6R" 1"A+ +< 3A9-.

    366P A" 1"A+.A" F1RS".

    @R1"E > 4"1S 1S !:S"6;ER ;AS"ER -A"A4.

    SB1P .E9-A".

    @R1"E > 1"A+,B:99R7 1"A+,9A;E7 1"A+,3A9-7 1"A+,6R"%.E9-366P.

    "6P,6F,PA*E.@R1"E >2%$2%( 4"1S 1S !:S"6;ER ;AS"ER -A"A4 !636R K.

    AT LAST - ENDAT:

    "his processing block gets e8ecuted at the last pass of the internal table

    loop.

    eg. code>

    -A"A 1"A+ 31BE B9! 6!!:RS % @1" EA-ER 319E.SE3E!" M FR6; B9! 19"6 "A+3E 1"A+.

    S6R" 1"A+ +< *CAR.

    366P A" 1"A+.A" 3AS".

    S:;. Maggregate function@R1"E > 4"E *RA9-"6"A3 6F SA3ES 1S47 1"A+,:;%:.

    E9-A".@R1"E > 1"A+,B:99R7 1"A+,*CAR7 1"A+,:;%:.E9-366P.

    AT NE-ENDAT:

    @henever we use this control break statement7 make use of only the

    re5uired fields in the internal table.

    -A"A > +E*19 6F 1"A+ 6!!:RS %7 *CAR 31BE B9!,*CAR7

    :;%: 31BE B9!,:;%:7 E9- 6F 1"A+.

    SE3E!" *CAR :;%: FR6; B9! 19"6 "A+3E 1"A+.

    S6R" 1"A+ +< *CAR.

    366P A" 1"A+.

    41

  • 7/25/2019 Complete Raeference to ABAP Basics

    42/83

    A" 9E@ *CAR.SB1P .

    @R1"E > 4SA3ES -69E 19 "E F1S!A3 +E*19 6F 1"A+ 6!!:RS %7 *CAR 31BE B9!,*CAR7

    :;%: 31BE B9!,:;%:7 E9- 6F 1"A+.

    SE3E!" *CAR :;%: FR6; B9! 19"6 "A+3E 1"A+.

    S6R" 1"A+ +< *CAR.

    366P A" 1"A+.

    A" E9- 6F *CAR.S:;.

    @R1"E > 4"6"A3 SA3ES -69E 19 "E F1S!A3

  • 7/25/2019 Complete Raeference to ABAP Basics

    43/83

    "he list inde8 assigned for the primary list is %. "he list inde8 assigned forthe first secondary list is . "he secondary list inde8 ranges from ,#%.

    "he system variables used in interactive reports>

    S/-LSIND, olds the current list inde8.S/-LILLI, olds the line number in the list.

    S/-LISEL, olds the contents of the line selected.

    Eg. code>

    -A"A F3-9A;E$&%(.

    -A"A 1"A+ 31BE B9A 6!!:RS % @1" EA-ER 319E.SE3E!" M FR6; B9A 19"6 "A+3E 1"A+.

    S6R" 1"A+ +< 3A9-.

    366P A" 1"A+.@R1"E > 1"A+,B:99R7 1"A+,9A;E7 1"A+,3A9-7 1"A+,6R"%.

    E9-366P.

    A" 319E,SE3E!"169.

    *E" !:RS6R F1E3- F3-9A;E.1F F3-9A;E J 41"A+,B:99R4.

    @R1"E > 4"E !:RRE9" 31S" 19-E? 1S47 S

    -A"A S"R$&%( =A3:E 4SAP 1S A9 ERP4.-A"A> S$K(7 S#$K(7 S&$K(7 S2$K(.

    SP31" S"R A" 4 4 19"6 S S# S& S2.

    43

  • 7/25/2019 Complete Raeference to ABAP Basics

    44/83

    @R1"E > S7 S#7 S&7 S2.

    SEAR! , "his string function is used to search for the specified value in agiven string.

    eg. code>

    -A"A S"R$&%( =A3:E 4SAP 1S A9 ERP4.-A"A S$&( =A3:E 4A94.

    SEAR! S"R F6R S.

    @R1"E > S S$K( =A3:E 419-1A47 S#$K( =A3:E 41S47 S&$K( =A3:E 4*REA"4.

    !69!A"E9A"E S S# S& 19"6 S"R SEPARA"E- +< 4 4.@R1"E > S"R.

    SI8T, "his string function is used to move the string to the specified

    position $3EF"7 R1*"7 !1R!:3AR( based on the number of places specified.

    eg. code>

    M-A"A S"R$#%( =A3:E 4A+AP 1S 19 SAP4.

    MS1F" S"R +< K P3A!ES.

    M@R1"E S"R !636R K.

    M-A"A S"R$#%( =A3:E 4A+AP 1S 19 SAP4.MS1F" S"R R1*" +< K P3A!ES.

    M@R1"E S"R !636R K.

    M-A"A S"R$#%( =A3:E 4A+AP 1S 19 SAP4.

    MS1F" S"R !1R!:3AR +< K P3A!ES.M@R1"E S"R !636R K.

    TRANSLATE, "his string function is used to change the case of the given

    string value.

    44

  • 7/25/2019 Complete Raeference to ABAP Basics

    45/83

    eg. code>

    -A"A S"R$%( =A3:E 4!E99A14.

    "RA9S3A"E S"R "6 36@ER !ASE.

    @R1"E S"R.

    CONDENSE, "his string function is used to remove the blank spaces in thegiven string.

    eg. code>

    data str$&%( value 4 19-1A 1S *REA"4.!69-E9SE S"R.

    @R1"E S"R.

    REPLACE, "his string function is used to replace the given string with

    specified string value.

    eg. code>

    data str$&%( value 419-1A 1S *REA"4.

    -A"A S$%( =A3:E 4@R1"E4.REP3A!E 41S4 19 S"R @1" S.

    @R1"E S"R.

    STRLEN, "his string function is used to identify the length of the givenstring.

    Eg. code>

    data str$&%( value 419-1A 1S *REA"4.

    data len type i.len J S"R3E9$ S"R (.

    write len.

    OVERLA/8IND

    45

  • 7/25/2019 Complete Raeference to ABAP Basics

    46/83

    L!4icl Dt

    1t is a tool used to increase the report efficiency.

    1t is a collection of nodes7 where each node is created for one table fromthe database.

    "he first node created in the logical database is called as root node.

    :nder the root node7 we create any number of child nodes for the table.

    3ogical database is not an -ata -ictionary ob)ect. 1t is a repository

    ob)ect.

    S3-+ is the t,code to create the logical database or SE&.

    N3i4ti!n$:

    SE& , specify logical database name starting with G or y , create ,enter a short description , save under a pack , specify root node name

    , enter short description for root node , enter the database table name

    , click on create ,opens an interface with root node , select node ,click on selection push button from application toolbar , click on yes to

    generate from structure ,click on no to search help , select twocheckbo8es for field selections and free selections , click on transfer ,

    opens an include file , specify range variable as followsQ.

    Select,options > for kna,kunnr

    Replace with cusnum.

    save , activte , come back , select node ,click on source code

    pushbutton from application toolbar ,click on yes to generate program from

    structure and selections ,opens two include file , double click on theheader file , declare an internal table as followsQ

    tables kna.

    -ata itab like kna occurs % with header line.

    Save ,activate , comeback ,double click on 9888 $sys routine file(,double click on the node kna include file , write the following code

    between the F6R; and E9-F6R; .

    Select M from kan into table itab where kunnr in cusnum.

    Put kna. $M autogen code(.

    46

  • 7/25/2019 Complete Raeference to ABAP Basics

    47/83

    3oop at itab.

    @rite > itab,kunnr7itab,name7itab,land7itab,ort%.

    Endloop.

    Save , activate.

    Put statement is used to fetch records from the specified database table and

    insert into node created from that table in the logical database.

    "o invoke the logical database from SE&D7create an e8ecutable program ,specify logical database name in the attribute selection while creating the

    program , write the following code.

    9odes kna. $!reates link bw node and 3-+ and invoke pgm(

    *et kna. $to get the record from node in 3-+(.

    Save , activate , e8ecute.

    47

  • 7/25/2019 Complete Raeference to ABAP Basics

    48/83

    *ODULE POOL PROGRA**ING:

    M "hese are type ; programs in SAP.

    M Screen painter is a tool used to create *:1 in A+AP.

    M ;PP provides screen painter to create a screen for the program.M "hese programs cannot be e8ecuted directly.M !ustomer,specified "ransaction code $starting with G or

  • 7/25/2019 Complete Raeference to ABAP Basics

    49/83

    !ASE S 16$%(7 16#$%(.

    Save , Activate.

    9ow "o create "ransaction !ode7 right click on ;ain Program 9ame ,!reate , "ransaction , 6pens an interface , Enter "code name starting

    with G or < , Enter short description , !ontinue , 6pens interface ,Enter ;ain program name and Screen number to be called first , Save

    under a package , Assign a re5uest number.

    Activate all the ob)ects of ;PP program by right clicking on ;ain program

    9ame , !lick on Activate , Raises 46b)ects Activated4 message.

    "o e8ecute the ;PP program7 specify "code name in the !ommand Prompt

    area , Press Enter.

    EVENTS IN *PP:

    PR6!ESS +EF6RE 6:"P:" , "his event gets triggered whenever theprogram is e8ecuted using "code. "his event is used to assign initial defaultvalues to the screen components.

    PR6!ESS AF"ER 19P:" , "his event gets triggered after some user4s action

    in the screen $for eg7 after clicking pushbutton7 subse5uent eventfunctionalities(.

    49

  • 7/25/2019 Complete Raeference to ABAP Basics

    50/83

    PR6!ESS 69 =A3:E RE:ES" , "his event is used to assign F functionalityfor the screen components.

    PR6!ESS 69 E3P RE:ES" , "his event is used to assign F2 functionality

    for the input field in the screen.

    Eg. code to make field validations in ;PP program>

    :sing screen painter7 design a screen consisting of four input fields for client7

    username7 password and language as we have in login screen of SAP.

    Assign the first two input fields to one group called *R7 the third input field

    to a group *R#.

    !reate two pushbuttons and assign F!" codes.

    1n the "6P 19!3:-E F13E7 declare following variables>

    PR6*RA; SAP;

  • 7/25/2019 Complete Raeference to ABAP Basics

    51/83

    M SE" PF,S"A":S 4888888884.M SE" "1"3E+AR 48884.

    1F A J %.

    ;ESSA*E S%%$G;S*(.

    366P A" S!REE9.1F S!REE9,*R6:P J 4*R4.

    S!REE9,RE:1RE- J 44.E9-1F.

    1F S!REE9,*R6:P J 4*R#4.

    S!REE9,19=1S1+3E J 44.E9-1F.

    ;6-1F< S!REE9.E9-366P.

    A J .

    E9-1F.endmodule. S"A":SL%#%% 6:"P:"

    Save , Activate.

    !reate a "ransaction !ode , E8ecute the program.

    *PP SCREEN VALIDATIONS:

    Eg. code to make field validations in ;PP program>

    :sing screen painter7 design a screen consisting of four input fields for client7username7 password and language as we have in login screen of SAP.

    Assign the first two input fields to one group called *R7 the third input fieldto a group *R#.

    !reate two pushbuttons and assign F!" codes.

    1n the "6P 19!3:-E F13E7 declare following variables>

    PR6*RA; SAP;

  • 7/25/2019 Complete Raeference to ABAP Basics

    52/83

    module :SERL!6;;A9-L%#%% input.

    case sy,ucomm.

    @E9 436*194.

    !A33 "RA9SA!"169 4SE&D4.@E9 4E?1"4.

    3EA=E PR6*RA;.E9-!ASE.

    endmodule. :SERL!6;;A9-L%#%% 19P:"

    Save , Activate.

    1n P+6 module7 write the following code to assign default input field

    attributes>

    module S"A":SL%#%% output.M SE" PF,S"A":S 4888888884.

    M SE" "1"3E+AR 48884.

    1F A J %.

    ;ESSA*E S%%$G;S*(.366P A" S!REE9.

    1F S!REE9,*R6:P J 4*R4.S!REE9,RE:1RE- J 44.

    E9-1F.1F S!REE9,*R6:P J 4*R#4.S!REE9,19=1S1+3E J 44.

    E9-1F.;6-1F< S!REE9.

    E9-366P.

    A J .E9-1F.

    endmodule. S"A":SL%#%% 6:"P:"

    Save , Activate.

    !reate a "ransaction !ode , E8ecute the program.

    52

  • 7/25/2019 Complete Raeference to ABAP Basics

    53/83

    *en; Pinte%

    ADDING USER-DE8IND *ENUS TO TE INTERACTIVE REPORTS:

    ;enu Painter is a tool used to create user,defined menus7 application toolbar

    and function keys.

    SE" PF,S"A":S 4ImenuLname4 is the synta8 used in reports to access

    ;enu Painter directly to create user,defined menus.

    A menu bar consists of set of menus.

    ;enu contains set of menu items.Each menu item may have its own sub menu items.

    Another way of accessing ;enu Painter is using SE2 "code.

    Eg. code>

    @R1"E > 4SE3E!" 69E FR6; "E ;E9:4.

    SE" PF,S"A":S 4;

  • 7/25/2019 Complete Raeference to ABAP Basics

    54/83

    INSERTING RECORDS INTO DATABASE TABLE USING *PP SCREEN

    8IELDS:

    :sing -ictionaryProgram Fields $F( pushbutton from the application toolbar

    of *raphical Screen Painter7 we can create input fields for the database tablefield structures.

    N3i4ti!n$:

    . !reate ;PP program.

    #. 1n "op 1nclude File7 declare the following structure>

    -A"A SA+A9A 31BE B9A.

    Save , Activate.

    &. !reate Screen , !lick on 4-ictionaryProgram Fields $F(4 pushbutton

    from the application toolbar , 6pens an interface , Specify structurename $SA+A9A( , !lick on *et From Program pushbutton , 6pens

    interface , Select re5uired fields , Place on Screen painter , specifylabels , !reate two pushbuttons $19SER"7 E?1"( , Save , Flowlogic.

    2. 1n PA1 module7 specify following code>

    !ASE S

  • 7/25/2019 Complete Raeference to ABAP Basics

    55/83

    TABLE CONTROL CO*PONENTS:

    "able !ontrol component is used to view the table records and ifneeded7 we can directly modify table records and update the database table

    using table control.

    ere7 the records can be viewed in rows and columns format separated by

    horizontal and vertical lines.

    SYNTAX:

    CONTROLS

    -A"A 1"A+ 31BE B9A 6!!:RS % @1" EA-ER 319E.!69"R63S "A+!"R3 "

    55

  • 7/25/2019 Complete Raeference to ABAP Basics

    56/83

    !ASE S

  • 7/25/2019 Complete Raeference to ABAP Basics

    57/83

    N3i4ti!n$ t! c%ete t

    -A"A > 16$%(7 16#$%(7 16&$%(7 162$%(.

    !69"R63S BAR"1B "

  • 7/25/2019 Complete Raeference to ABAP Basics

    58/83

    !ASE S

    VR%_VALUEis a structure with following fields7

    BE< , !ode for the display value"E?" , !ontent of the display value

    =R;L=A3:ES is an internal table created for the above structure withoutheader line.

    -eclare an internal table $1"A+( of type =R;L=A3:ES and also declare an

    e8plicit structure $@A( to append values into internal table using 31BE 319E6F statement.

    =R;LSE"L=A3:ES is the function module used to fetch records from internaltable 1"A+ to input field 16.

    58

  • 7/25/2019 Complete Raeference to ABAP Basics

    59/83

    TABLE CONTROL:

    "his component is used to view the internal table records in ;PP screen.

    "able control modification>

    366P A" 1"A+,E9-366P statement in P+6 is used to fetch the records into

    internal table from db table.366P A" 1"A+,E9-366P statement in PA1 is used to view the current data in

    internal table through table control.

    "o make modification7 create one more internal table for the same dbtable

    structure used in top include file. "o move first internal table records to thenewly created one7 create a separate module to specify a statement for this

    purpose bw 366P,E9-366P in PA1.

    eg.

    PR6!ESS AF"ER 19P:".

    ;6-:3E :SERL!6;;A9-L%D%%.366P A" 1"A+.

    ;6-:3E 1"A+"61"A+. M 9ew module

    E9-366P.

    -ouble click on module name to specify following move statement.

    eg.

    ;6-:3E 1"A+"61"A+ 19P:".

    APPE9- 1"A+ "6 1"A+.E9-;6-:3E.

    1n Screen painter7 create 4;6-1F

    @E9 4;6-1F

  • 7/25/2019 Complete Raeference to ABAP Basics

    60/83

    E9-1F.

    E9-366P.

    SE3E!" M FR6; B9A 19"6 "A+3E 1"A+.

    "+!3,319ES J S

  • 7/25/2019 Complete Raeference to ABAP Basics

    61/83

    BATC DATA CO**UNICATION

    "o perform data migration from legacy database to SAP database7 we use

    batch data communications $+-!(.

    "o perform data migration7 following methods are available in +-!>

    +" DIRECT INPUT *ETOD

    ," CALL TRANSACTION *ETOD'" SESSION *ETOD"

    "he above three methods re5uire source code to perform data migration.

    "here are predefined tools available to perform data migration with onlyminimal source code. "hey are>

    +" LEGAC/ S/STE* *IGRATION OR.BENC (LS*)"

    ," RECORDING *ETOD

    DIRECT INPUT *ETOD:

    A#3nt4e$:

    :sing this method7 we can perform bulk data transfer.

    9o manual intervention is re5uired for direct input method.

    -ata migration time is very less.

    Di$#3nt4e$:

    Since no manual intervention is re5uired7 we cannot correct the errorrecord during runtime.

    "his method can be used only during SAP implementation7 not for

    support pro)ects.

    Eg. code>

    -A"A > +E*19 6F 1"A+ 6!!:RS %7

    S"R$#KK(7

    E9- 6F 1"A+.

    -A"A 1"A+ 31BE B9A 6!!:RS % @1" EA-ER 319E.

    !A33 F:9!"169 4:P36A-4E?P6R"19*

    F13E9A;E J 4!>T-1R."?"4

    61

  • 7/25/2019 Complete Raeference to ABAP Basics

    62/83

    F13E" 4RE!6R-S A3REA-< E?1S"S4.

    E9-1F.

    E9-366P.

    BATC DATA CO**UNICATIONS:

    "his concept deals with data migration from legacy system database into

    SAP database. @henever a company moves into SAP from legacy system7+-! is used to populate the new SAP database with their old re5uired

    records.

    *et7!#$ in BDC:

    . DIRECT INPUT *ETOD, :sing this method7 records from the flat file

    are uploaded first into an internal table created for the flat file structure.

    :sing a string function $SP31" functionality(7 the records are splitted basedon the separators and then inserted into a new internal table which is

    created for a table where the datas are to be inserted.

    eg. code>

    -A"A > +E*19 6F 1"A+ 6!!:RS %7

    S"R$#KK(7 E9- 6F 1"A+.

    -A"A 1"A+ 31BE B9A 6!!:RS % @1" EA-ER 319E.

    62

  • 7/25/2019 Complete Raeference to ABAP Basics

    63/83

    !A33 F:9!"169 4:P36A-4E?P6R"19*

    F13E9A;E J 4!>T+ASB."?"4 F13E" +E*19 6F 1"A+ 6!!:RS %7

    S"R$#KK(7

    E9- 6F 1"A+.

    !A33 F:9!"169 4:P36A-4

    E?P6R"19* F13E9A;E J 4!>TS"A3."?"4 F13E"

  • 7/25/2019 Complete Raeference to ABAP Basics

    64/83

    366P A" 1"A+.SP31" 1"A+,S"R A" 474 19"6 1"A+,B:99R 1"A+,9A;E 1"A+,6R"%

    1"A+,3A9-.APPE9- 1"A+.

    E9-366P.

    -A"A C"A+ 31BE +-!-A"A 6!!:RS % @1" EA-ER 319E.

    -A"A B"A+ 31BE +-!;S*!633 6!!:RS % @1" EA-ER 319E.

    366P A" 1"A+.

    PERF6R; PR6*19F6 :S19* 4SAP;GS"A319!"4 4%%4.

    PERF6R; F3-19F6 :S19* 4@A,B:99R4 1"A+,B:99R.

    PERF6R; F3-19F6 :S19* 4@A,9A;E4 1"A+,9A;E.PERF6R; F3-19F6 :S19* 4@A,3A9-4 1"A+,3A9-.

    PERF6R; F3-19F6 :S19* 4@A,6R"%4 1"A+,6R"%.

    !A33 "RA9SA!"169 4GS"A319!"4 :S19* C"A+ ;6-E 494 ;ESSA*ES 19"6B"A+.

    E9-366P.

    366P A" B"A+.@R1"E > B"A+,"!6-E7 B"A+,-

  • 7/25/2019 Complete Raeference to ABAP Basics

    65/83

    F6R; F3-19F6 :S19* F3-9A;E F3-=A3.

    !3EAR C"A+.

    C"A+,F9A; J F3-9A;E.

    C"A+,F=A3 J F3-=A3.

    APPE9- C"A+.

    &. +-! SESS169 ;E"6-.

    TOOLS USED IN BDC:

    3E*A!< S

    -A"A > +E*19 6F 1"A+ 6!!:RS %7

    S"R$#KK(7 E9- 6F 1"A+.

    !A33 F:9!"169 4:P36A-4E?P6R"19* F13E9A;E J 4!>TB9A."?"4

    F13E"

  • 7/25/2019 Complete Raeference to ABAP Basics

    66/83

    -A"A C"A+ 31BE +-!-A"A 6!!:RS % @1" EA-ER 319E.

    366P A" 1"A+.

    SP31" 1"A+,S"R A" 474 19"6 1"A+,B:99R 1"A+,9A;E 1"A+,6R"%

    1"A+,3A9-.APPE9- 1"A+.

    E9-366P.

    366P A" 1"A+.

    PERF6R; PR6*19F6 :S19* 4SAP;G!A33"RA9SA!"1694 4%%4.

    PERF6R; F3-19F6 :S19* 4BAR"1B,B:99R4 1"A+,B:99R.

    PERF6R; F3-19F6 :S19* 4BAR"1B,9A;E4 1"A+,9A;E.PERF6R; F3-19F6 :S19* 4BAR"1B,6R"%4 1"A+,6R"%.

    PERF6R; F3-19F6 :S19* 4BAR"1B,3A9-4 1"A+,3A9-.

    !A33 "RA9SA!"169 4G!A33"RA9S4 :S19* C"A+.

    E9-366P.

    F6R; PR6*19F6 :S19* PR6*9A;E S!R9:;.

    !3EAR C"A+.

    REFRES C"A+.

    C"A+,PR6*RA; J PR6*9A;E.

    C"A+,-

  • 7/25/2019 Complete Raeference to ABAP Basics

    67/83

    E9-F6R;.

    Save , Activate , E8ecute.

    1n the above code7

    BDCDATAis a structure used to populate the internal table records into thescreen fields. "he +-!-A"A structure has following components>

    PROGRA*, olds the name of ;PP program where the screen is created.D/NPRO, olds the screen number where the internal fields to be

    populated.D/NBEGIN, :sed to initiate the screen when the program is e8ecuted.

    "he default value to be specified is 4?4.

    8NA*, Specifies input field name in the screen where the data is to bepopulated.

    8VAL, Specifies from which internal table field7 the data should be passedto the screen field.

    CALL TRANSACTIONstatement is used to call the screen created to

    populate error records.

    S

    transaction. "he types of mode are>

    A , -isplay the screen.

    E , -isplay only error records from the flat file.9 , +ackground processing.

    :P-A"E> "his is used to specify the update task of records in the database

    table. "he types of update tasks are>

    A , Asynchronous update

    S , Synchronous update3 , 3ocal update

    A#3nt4e$ !f CALL TRANSACTION:

    M Error records can be modified.

    67

  • 7/25/2019 Complete Raeference to ABAP Basics

    68/83

    M "his method can be used in support pro)ects.BDC CALL TRANSACTION:

    -A"A > +E*19 6F 1"A+ 6!!:RS %7

    S"R$#KK(7

    E9- 6F 1"A+.

    -A"A 1"A+ 31BE B9A 6!!:RS % @1" EA-ER 319E.

    -A"A C"A+ 31BE +-!-A"A 6!!:RS % @1" EA-ER 319E.

    !A33 F:9!"169 4:P36A-4

    E?P6R"19* F13E9A;E J 4!>TBAR"1B."?"4

    F13E"

  • 7/25/2019 Complete Raeference to ABAP Basics

    69/83

    E9-F6R;.

    F6R; F3-19F6 :S19* F3-9A;E F3-=A3:E.!3EAR C"A+.

    C"A+,F9A; J F3-9A;E.

    C"A+,F=A3 J F3-=A3:E.APPE9- C"A+.

    E9-F6R;.

    CLEARstatement is used to delete the contents of the header line of

    internal table.RE8RESstatement is used to delete the contents of the body area of

    internal table.

    8REEstatement is used to delete the internal table after the program isclosed.

    DELETEstatement is used to delete some particular contents of the internaltable.

    S

    A , Foreground processing

    E , Errors only9 , +ackground processing

    @hen 494 is used7 a predefined structure called +-!;S*!633 should be used

    to collect the messages triggered during background processing.

    Synta8>

    -A"A B"A+ 31BE +-!;S*!633 6!!:RS % @1" EA-ER 319E.

    !A33 "RA9SA!"169 4

    69

  • 7/25/2019 Complete Raeference to ABAP Basics

    70/83

    :pdate specifies the task of updating records into database table.A , Asynchronous update , A return value is generated only after updating

    all the records in related tables.S , Synchronous update , A return value is generated for each record

    updation in related tables inside the database.

    BDC SESSION *ETOD:

    Since -irect 1nput and !all "ransaction methods cannot be used for support

    pro)ects due to the database availability and networking constraints7 SAP

    suggests to use Session ;ethod for data migration in support pro)ects.

    1n this method7 a session is created in the Application Server. A session hasa session memory used to hold the internal table records. @e can process

    the session later whenever database is available with free network traffic.

    8UNCTION *ODULES USED IN BDC SESSION *ETOD:

    . +-!L6PE9L*R6:P , "his F; is used to create a session in Appn. Server.

    #. +-!L19SER" , "his F; is used to insert the internal table records intosession memory.

    &. +-!L!36SEL*R6:P , "his F; is used to save the records in session

    memory and close it to process later.

    Eg. code>

    -A"A > +E*19 6F 1"A+ 6!!:RS %7 S"R$#KK(7 E9- 6F 1"A+.

    -A"A 1"A+ 31BE B9A 6!!:RS % @1" EA-ER 319E.

    -A"A C"A+ 31BE +-!-A"A 6!!:RS % @1" EA-ER 319E.

    !A33 F:9!"169 4:P36A-4E?P6R"19*

    F13E9A;E J 4!>TBAR"1B."?"4 F13E"

  • 7/25/2019 Complete Raeference to ABAP Basics

    71/83

    1"A+,3A9-.APPE9- 1"A+.

    E9-366P.

    !A33 F:9!"169 4+-!L6PE9L*R6:P4E?P6R"19*

    !31E9" J S

    PERF6R; F3-19F6 :S19* 4@A,9A;E4 1"A+,9A;E.PERF6R; F3-19F6 :S19* 4@A,6R"%4 1"A+,6R"%.

    PERF6R; F3-19F6 :S19* 4@A,3A9-4 1"A+,3A9-.

    !A33 F:9!"169 4+-!L19SER"4

    E?P6R"19* "!6-E J 4

    E9-366P.

    !A33 F:9!"169 4+-!L!36SEL*R6:P4.

    F6R; PR6*19F6 :S19* PR6*9A;E S!R9:;.

    !3EAR C"A+.

    REFRES C"A+.

    C"A+,PR6*RA; J PR6*9A;E.C"A+,-

  • 7/25/2019 Complete Raeference to ABAP Basics

    72/83

    !3EAR C"A+.

    C"A+,F9A; J F3-9A;E.

    C"A+,F=A3 J F3-=A3:E.

    APPE9- C"A+.

    E9-F6R;.

    Save , Activate , E8ecute , A session is created.

    "o process the session7 *6"6 S;&K "code.

    N3i4ti!n$ t! p%!ce$$ t7e $e$$i!n:

    S;&K , Select the session , click on PR6!ESS pushbutton from appn.toolbar , 6pens an interface , Select -1SP3A< ERR6RS 693< radiobutton

    , Process , 6pens the user,defined screen , ;odify and 1nsert therecords , Finally opens a message , !lick on Session 6verview

    pushbutton , !omes back to S;&K screen , Select the session , !lick on3og Pushbutton from appn. toolbar , "o view the detailed log7 select

    session from here , !lick Analyze 3og pushbutton from appn. toolbar ,

    6pens an interface , !lick on 3og !reated on...date... tab button , @ecan view the detailed log of transaction.

    1f +ackground mode is selected7 *6"6 S;& "code.

    S;& , !lick on 6wn Cobs pushbutton from appn. toolbar , Select sessionfrom the list , !lick on Cob 3og pushbutton from appn. toolbar , *ives you

    detailed log of background processing.

    72

  • 7/25/2019 Complete Raeference to ABAP Basics

    73/83

    LS* ( Le4cy Sy$tem *i4%ti!n !%5

  • 7/25/2019 Complete Raeference to ABAP Basics

    74/83

    1n this step we are adding fields to the 1nternal table created in Secondstep.

    Select the radiobutton , !lick on E8ecute , 6pens an interface , !hange

    ;ode of the screen , select the 1nternal table from the 3ist , !lick on

    !reate field from application toolbar , 9ame the Field $ ;A"9R ( , Enter-escription $any( , Set the Size $ D( , Specify -ata type $ ! ( , !lick

    on !ontinue. :sing the same step add 6ther Fields

    ;+RS $ 1ndustry ( $!(

    ;"AR" $;at type( 2 $!(;AB"? $;at -esc( 2% $!(

    ;E19S $;at measure( & $!(, save the Entries , !ome back.

    Step F. ;aintain Structure Relations

    1n this step we need to *enerate Relation between 1"A+ and Recording6b)ect.

    select , E8ecute , 6pens an interface , Relation ship 7 by defult

    generated by SAP , !hange mode of the screen , save the Entries ,

    !ome back.

    $tep F0. ;aintain Field ;apping and !onversion Rules ;apping the Fields of 1tab with Recording 6b)ect is the step to be

    processed.

    select , E8ecute , !hange ;ode of Screen , Select the Field From 3ist of

    recording ob)ect , !lick on Source Field From Application toolbar ,-isplays the 3ist of 1nternal table fields , -ouble click on Proper Field. 1n

    the same way map all Fields of Recording 6b)ect with All Fields of 1nternal

    table , Save the Entries , !ome back.

    Step U. ;aintain Fi8ed =alues7 "ranslations7 :ser,-efined Routines "his is optional Step 1n +-! of 3S;@

    E8ecute , !ome back.

    Step F?"Specify Files

    Select , E8ecute , 6pens an interface , !hange ;ode of Screen ,select legacy data on P! , !lick on !reate From Application toolbar ,

    9ame the File $ ->TN&%A;Tmatdata.t8t ( , Enter -escription $ any ( ,

    74

  • 7/25/2019 Complete Raeference to ABAP Basics

    75/83

    Sepecify Separator as !omma , !lick on !ontinue , Save the Entries, !ome back.

    Step F6"Assign Files

    1n this step we need to assign the Flat fiel 1nto 1nternal table created in

    Second step.

    select , E8ecute , !hange ;ode of the screen , Save the Entries ,!ome back.

    Step F"1mport -ata1n this step SAP Reads the Flat File data and stores in the form of

    .lsmw.read file.

    Select , E8ecute , 6pens an interface , !lick on E8ecute , Sap

    *enerates a report as Flat file is converted into .read file with 9umber oftransactions , !ome back , !ome back.

    Step F+"-isplay 1mported -ata

    Select ,E8ecute , 6pen an 1nterface , !lick on !ontinue , displays the

    data in 1nternal table $itab( , !ome back.

    Step F++. !onvert -ata

    1n this step -ata will be converted into .lsmw.conv file to make data is

    ready for populating into Session ob)ect.

    select , e8ecute , E8ecute , Sap *enerates a report as file is converted

    into !onv , !ome back , come back.

    Setp F+,"-isplay !onverted -ata

    select , E8ecute ,6pens an interface , !lick on continue, *enerates a

    report with *reen !olor , !ome back.

    Setp F+'"!reate +atch 1nput Session

    Select ,E8ecute , 6pens an interface , Select the checkbo8 , !lick on

    E8ecute , Prompts a message.

    Step F+"Run +atch 1nput Session

    6pens S;&K tcode to process +-! data.

    75

  • 7/25/2019 Complete Raeference to ABAP Basics

    76/83

    select , E8ecute , Select session ob)ect name , !lick on Process , !lick

    on continue , SAP trasnfers all file data into R& applications.

    RECORDING *ETOD: (SDB).

    +-! recording method is a SAP tool used to perform data migration. :sing

    this method7 a recording ob)ect is created for any one of the predefinedscreens $;;%7 ?B%7 and ?-%( the sample values entered in the screen

    input fields are taken to create a +-!-A"A structure. +ased on the structure

    created7 the source code is automatically generated by the system.1n this method we cannot use user,defined screens to populate the

    error records.

    N3i4ti!n$ t! pe%f!%m #t mi4%ti!n ;$in4 %ec!%#in4 met7!#.

    S-+, click on new recording push button from the application tool bar,

    opens an interface,name the recording ob)ect,specify "!6-E$ mm%( forwhich the recording is done$mm%( ,continue,opens specified screen

    $mm%( ,enter sample values V ;aterial no7 ;aterial type7 industrysector$matnr7mtart7mbrsh( ,click on select view pushbutton from the

    application tool bar,select basic data from interface,continue,opens

    second screen, enter description$makt8( and measurement$meins( , clickon save , opens an interface with +-!-A"A structure filled with the sample

    values , save the recording , comeback , select the recording ob)ect ,click on program pushbutton from the application tool bar , opens an

    interface , enter the program name , select transfer from recording radiobutton , continue , enter a short description , clickon source code pushbutton , opens SE&D editor with auto generated code.

    After the include statement7 specify the following code.

    M 1nclude bdcrec8.$include stmt(.

    -ata > begin of itab occurs %7 Str$#KK(7

    End of itab.-ata itab like mara occurs % with header line.

    After the start of selection event7 specify the following code.

    Start,of,selection.

    !all function WuploadX7

    76

  • 7/25/2019 Complete Raeference to ABAP Basics

    77/83

    E8portingFile name J Wc>Tmara.t8tX

    File type J WascX"ables

    -ataLtab J itab.

    3oop at itab.

    Split itab at W7X into itab,matnr itab,mtart itab,mbrsh itab,meins.

    Append itab.

    Endloop.

    After the perform open,group

    3oop at itab.

    Replace all the sample values for the fields with the internal table name.

    itab,matnritab,mtart

    itab,mbrsh

    itab,meinsendloop.

    Perform closeLgroup.

    Save it , activate , e8ecute.

    :sing recording method7 we can perform data migration in the following #ways.

    1. Session method.2. !all transaction method.

    @hen session method is selected7 specify session name , checkbo87keep

    batch input session , e8ecute.

    "o process the session7 go to sm&K and process.

    77

  • 7/25/2019 Complete Raeference to ABAP Basics

    78/83

    SAPSCRIPTS

    "his is a tool used to redirect SAP data to output devices. SEN is the "code

    to create SAPScript.

    !omponents of a SAPScript tool are>

    +" BASIC SETTINGS"

    Paragraph format7 character format.

    ," AD*INISTRATIVE SETTINGS"

    9ame of the form7 short description.

    3ayout is used to create a form in SAPScript. 3ayout is a collection of pages.Page is a collection of @indows.

    Type$ !f in#!$:. ;ain @indow , "his is a common window for all pages. "his is a default

    window.

    #. !onstant @indow , "his window is used to create footer space7 headerspace for a particular page.

    &. =ariable @indow , "his is a subwindow.2. *raphical @indow , "his is an optional window7 which is used to create

    logos or some other graphics for the page.

    NAVIGATIONS 8OR CREATING A SAPSCRIPT:

    SEN , Specify Form name starting with G or < $GSA+F6R;( , !lick on

    !reate , 6pens an interface , Enter short description , !lick on4Paragraph Format4 from Appn. toolbar , Specify Paragraph 9ame $P(,

    Press Enter , Enter short description , !lick on 4-efinitions4 pushbutton

    from application toolbar , Specify -efault Paragraph $P( created , !lickon 3ayout pushbutton from appn. toolbar , 6pens a layout with a default

    window 4;A194 , Right click on ;ain @indow , Select 4Edit "e8t4 , 6pens

    a 3ine Editor , Specify a statement , !ome back , Save , Activate theform , A SAPscript is created.

    "o invoke the form created7 we have to create a print program. !reate an

    E8ecutable Program and specify the following>

    78

  • 7/25/2019 Complete Raeference to ABAP Basics

    79/83

    !A33 F:9!"169 46PE9LF6R;4E?P6R"19*

    F6R; J 4GSA+F6R;4 3A9*:A*E J S

  • 7/25/2019 Complete Raeference to ABAP Basics

    80/83

    PASSING TABLE VALUES AS AN ARGU*ENT TO SAPSCRIPT:

    1n the line editor7 specify the table field arguments enclosed by 4/4 symbol asfollows>

    E E3E;E9"

    /B9A,B:99R/ 77 /B9A,9A;E/ 77 /B9A,3A9-/

    Save , Activate.

    1n the Print Program7 specify following code>

    "A+3ES B9A.

    !A33 F:9!"169 46PE9LF6R;4E?P6R"19*

    F6R; J 4GSA+F6R;4 3A9*:A*E J S

    E E3E;E9"

    /1"A+,B:99R/ /1"A+,9A;E/ /1"A+,3A9-/

    Save , Activate.

    1n Print Program7 specify following code>

    -A"A 1"A+ 31BE B9A 6!!:RS % @1" EA-ER 319E.

    80

  • 7/25/2019 Complete Raeference to ABAP Basics

    81/83

  • 7/25/2019 Complete Raeference to ABAP Basics

    82/83

    S*ART8OR*S

    ADVANTAGES O8 S*ART8OR*S:. Smartforms does not re5uire paragraph formats as a mandatory one.

    #. Smartforms does not duplicate the data.

    &. Smartforms are !lient,independent and language,independent.2. @e can apply styles for the te8ts using Smartforms.K. Print programs does not contain any function modules to call the form.

    S;AR"F6R;S is the "code to create smartforms in A+AP.Sm%tf!%m$ 7$ t7%ee c!mp!nent$>

    Gl!

    -A"A 9A;E$%( =A3:E 419-1A4.

    !A33 F:9!"169 4+!-@+SF%%%%%%2#4

    E?P6R"19*

    82

  • 7/25/2019 Complete Raeference to ABAP Basics

    83/83

    S"R J 9A;E., Save , Activate , E8ecute in the same way as Sapscript.

    N3i4ti!n$ t! p$$ inte%nl t

    1"A+ 31BE ;ARA.

    , E8pand Pages and @indows , Right click on ;ain @indow , !reate ,

    "able , !lick on -ata tab button , 1n the 366P section7 for the operandfields7 specify the following>

    1"A+ 19"6 1"A+.

    , Right click on ;ain Area , !reate , "able 3ine , 1n the 3ine "ype input

    field7 a line type called '3"

    /1"A+,;A"9R/77/1"A+,;"AR"/77/1"A+,;+RS/77/1"A+,;E19S/

    , !ome back , Save , Activate , E8ecute , !opy the autogenerated

    F;.

    1n SE&D program7 specify the following>

    -A"A 1"A+ 31BE ;ARA 6!!:RS % @1" EA-ER 319E

    83