Sap Abap Ig Notes Part1

Embed Size (px)

Citation preview

  • 8/13/2019 Sap Abap Ig Notes Part1

    1/152

    SAPSYSTEMS, APPLICATIONS and PRODUCTS in data processingERP:E: Enterprise / Company Ex: Reddy Labs, Reliance, GE, GM, BMWR: Resources

    Man -> employeeMachines -> plants/manufacturing unitsMaterials -> items/products (raw, semi finished, finished)Money -> finance (profit/loss)

    P: Planning (effective plans for maximum profits with minimum resources)ERP Software:Software which is used to maintain the business activities of a company/enterprise is called ERP software.The business activities are

    How many customers/vendors/materialsHow many sales orders/delivery orders/invoice

    How much profits/lossHow many employees/leaves/provident funds/income taxHow many plants/stock available/stock damaged etc.The available softwares are,People SoftUsed by small companiesSupports less number of business applications/scenarios/programsSupports less number of business modulesLess cost softwareVery good at HR moduleOracleUsed by medium sized companies

  • 8/13/2019 Sap Abap Ig Notes Part1

    2/152

    Supports limited number of business applicationsSupports limited number of business modulesHigh cost softwareVery good at finance (FI) moduleSAPIt is an ERP software which is used by medium sized as well as top MNCsSAP supports every scenario or business applicationSAP supports almost every module in the business (around 45+ modules)Very high cost softwareIt is excellent at integration between all the SAP modules ***We cant do any black business in SAP (i.e., the information is stored in a secured way where you cant do any black business)ABAPADVANCED BUSINESS APLLICATION PROGRAMMINGIt is a 4thgeneration language i.e. ABAP/4, the entire ERP software is developed by using a single programming language which is called as ABAP.

    SAP ModulesSD : sales and distributionMM : material managementFI : financeCO : controllingHR : human resourcesCRM : customer relation managementSRM : supply relation management, etc.

  • 8/13/2019 Sap Abap Ig Notes Part1

    3/152

    Functional Consultants: A consultant who is responsible for configuring the real time business scenarios like how many plants, sales

    organizations, materials etc in SAP software is called as functional consultants.ABAP Consultants: A consultant who is responsible for developing new programs, screens, tables or modifying standard SAP programs is called

    as ABAP consultants.BASIS Consultants: A consultant responsible for installing the SAP software, configuring the servers, controlling network traffic, creating

    usernames and passwords etc are called as BASIS consultants.

    Roles and responsibilities of ABAP consultants:Receiving a ticket from TLAnalyze the business requirementEstimate the number of hours for business requirementDevelop the object

    Perform unit testing

    Release the developed object to testing serverPrepare technical document for objectSystem Landscape:

  • 8/13/2019 Sap Abap Ig Notes Part1

    4/152

    Development Server: A server where all the ABAP consultants will be developing the real time objects for a business requirement is called

    development server. Once the development is finished, we should do a sample testing called as unit testing.Quality Server: A server where all the functional consultants or testing consultants will be testing the developed objects is called a testing server.It is also called as quality server.Production Server: A server where all the developed objects will be used in the live business market to maintain the business is called production

    server. It contains the live business data of customers.ot : As an ABAP consultant, we will be working only at development sever, not the quality and production severs. ABAP consultants with more

    than 4 or 5 years of experience will have the access to quality sever but not production server. Sand Box Sever: It is a server where we do our R&D work is called a sand box sever. Everybody will have access to the sand box server.SAP R/3 Architecture: In software engineering there are 3 architecturesSingle tier architectureTwo tier architectureThree tier architectureSingle tier architecture: A system which is responsible for loading the program, compiling, interpreting, executing as well as storing the data in

    the same system is called single tier architecture. In simple words a system responsible for front end and back end operations is called single tier

    architecture.Ex: All Clanguage programs in olden days are written using single tier architecture.Two tier architecture: In this architecture we have two layers, server layer and client layer.2. a. Sever layer: In this layer we have a single system with very high configuration called as server. This sever is responsible for executing the

    programs as well as storing the data.2. b. Client layer: In this later we have multiple systems which are connected to a server. All the business users will be operating from client

    systems. The server will receive the request from the client system and gives back the response (i.e. result).Ex: SAP R/2, Oracle

  • 8/13/2019 Sap Abap Ig Notes Part1

    5/152

    Disadvantages of two tier architecture:As the number of client systems increases the load on the database server will increase and the response time will be delayedSince the response time is delayed the output will be very slow on the client system which is very big disadvantageTo overcome this problem we have a new architecture called as three tier architectureThree tier architecture: In this architecture we have three layers, they are database server layer, application server layer and presentation sever

    layer.3. a. Database server layer: A server which is responsible only for storing the data is called database server layer.3. b. Application sever layer: A server which is responsible for only executing the applications or programs is called application sever layer. 3. c. Presentation server layer: A server which is responsible for just presenting the output and taking the input is called as presentation sever

    layer.Ex: SAP R/3 architecture.

  • 8/13/2019 Sap Abap Ig Notes Part1

    6/152

    History of SAP:In 1972, five IBM employees started a company by name SAP AG (angelsko)

    Their objective was to develop a business or ERP softwareIn 1980 the company released the first ERP software by name SAP R/2, where R stands for real time and 2 stands for two tier architecture

    In 1990 the company released advanced version of SAP R/2 by name SAP R/3, where 3 stands for three tier architecture Even today also we are using SAP R/3

  • 8/13/2019 Sap Abap Ig Notes Part1

    7/152

    Chapter 01

  • 8/13/2019 Sap Abap Ig Notes Part1

    8/152

    Log into SAP:Double click on SAP GUI or SAP LOGON iconSelect development server name (ECC6)Click on LOGONProvide username: SAPUSER password: INDIA123Press enterSAP EASY ACCESS screen is displayedTransaction Code: It is a unique code or shortcut code to execute a specific program and its corresponding screen.Ex:

    SE11: Displays ABAP dictionarySE38: Displays ABAP editorSE37: Displays ABAP function builderSE21: Displays ABAP package builderSE80: Displays ABAP development work bench . Etc.

    Naming conventions:

    These objects will starts with any character

    Except Y and Z.

    The objects must start with either Y or Z.

    These objects cantbe modified directly. These objects can be changed however we

    want.

  • 8/13/2019 Sap Abap Ig Notes Part1

    9/152

    PACKAGE:It is a container of developed objectsEach project contains a single package (generally)Packages are created by BASIS consultants or team leads when the project is startedAll our objects must be stored in the package onlySE21 is the TCODE for creating a packageSteps to create a package:Go SE21Give the package name ZSAP_ABAPClick on create, provide short descriptionClick on create, save and enterPress enterClick on save, a package is createdTransport Request Number: A number which is used to transport an object from one server to another server within system landscape is called trans

    Ex:

    ECCK is the name of development server.

  • 8/13/2019 Sap Abap Ig Notes Part1

    10/152

    Package types:

    Steps to create a program:Go to SE38, give the program name

    zsample

    Click on create, provide descriptionSelect type = EXECUTABLEClick on saveProvide the package name and press enterClick on

    create request iconProvide short description and press enterA transport request number will be generated, just press enterThe ABAP editor is openedClick on save and activateWRITE: It is the statement which is used to print a text on the output screen.Ex:Write hello world.Syntax:

  • 8/13/2019 Sap Abap Ig Notes Part1

    11/152

    :Chain Operator: It is a statement which is used to display multiple texts which are separated by commas using a single write statement.Report zsample.Write hello world.Write

    welcome to sap abap

    Write / igrow soft.Write: / cno, cname, city.Write: / 3 cno, 15 cname, 25 city.Write: / 25(25) IBM Indialeft-justified color 1. (Displaying background color)Write: / 25(25) IBM Indiacentered color 2.Write: / 25(25) IBM Indiaright-justified color 3.Write: / 25(25) IBM Indiaright-justified color 6 inverse. (Displaying font color)

    System Variables:A variable which is defined by the system is called a system variable All system variables are automatically assigned with some valuesAll system variables will start with SYor SYSTAll system variables are stored in SYST structureEx:Write / sy-uline. (Displays horizontal line)Write / sy-datum. (Displays systems date as per date settings in SU3 Tcode)Write / sy-uzeit. (Displays systems time)Write / sy-uname. (Displays systems user name)Write / sy-repid. (Displays report name)Write / 25(25) sy-uline. (Horizontal line at specified position)Write / 25 sy-vline. (Vertical line of height 1line)

  • 8/13/2019 Sap Abap Ig Notes Part1

    12/152

    Ex to draw a box:Write / 25(25) sy-uline.Write / 25 sy-vline.Write 49 sy-vline.Write / 25(25) sy-uline.

    Develop a report to display customer details as below.

    What is a chain operator?What is a system variable and where they are stored?What are the roles and responsibilities of ABAP consultant?Explain the system landscape of your project?Explain 3 tier architecture?What are the modules you have worked on?What is your team size of your project?How many colors are there in sap abap?User defined variables: It is the keyword which is to declare a variable of certain data type and length. Syntax: (Data is keyword)Data: (length) TYPE value Ex:Data: v_fname(15) type c value ibm, v_lname(15) type c.V_lname = ibm india private limited.

  • 8/13/2019 Sap Abap Ig Notes Part1

    13/152

    Write: / v_fname, / v_lname.Data types in ABAP:

    Ex:Data: v_fname(15) type c,V_pincode(6) type n,V_dob type d,V_time type t,

    V_count type I,V_cost type p decimals 2,V_totalcost type p.V_fname = ibm india.V_pincode = 509001.V_dob = 19821231.V_time = 102030.V_count = 1.

  • 8/13/2019 Sap Abap Ig Notes Part1

    14/152

    V_cost = 1999.999.V_totalcost = 1999.999.Write: / v_fname,

    / v_pincode,/ v_dob,

    / v_time,/ v_count,/ v_cost,/ v_totalcost.Conditional statements:If ...Endif.If ..Else..Endif.If ..Elseif ..Elseif ..Else..Endif.Case .When value1..

  • 8/13/2019 Sap Abap Ig Notes Part1

    15/152

    When value2..When value3..When others..End case.Difference between if-elseif-endifand casestatements:

    The if-elseif-endif statement will compare each condition until the true statement is executed The case- end case statement will not compare each condition, instead it will directly jump to the true condition i.e. why always use case-end case statement instead of if-elseif-endif

    Parameters:It is a keyword which is used to create an input field on the selection screen. The selection screen is called input screen.Syntax:Parameters: (length) type

    The output screen is called as list screen, the input screen is called selection screenEx:(On if)Parameters: p_land1(3) type c.If p_land1 = .Write: / please enter a value.Endif.(On if-else)If p_land1 = in.Write: / we are calculating tax for Indian customers.Else.Write: / we are calculating tax for non Indian customers .

    dif

  • 8/13/2019 Sap Abap Ig Notes Part1

    16/152

    Endif.(On if-elseif-else-endif)If p_land1 = in.Write: / we are calculating tax for IN customers.Elseif p_land1 = us.Write: / we are calculating tax for US customers.Elseif p_land1 = uk.Write: / we are calculating tax for UK customers.Else.Write: / please enter a valid country code.(On caseend case)Case p_land1.When in.Write: / we are calculating tax for IN customers.When us.Write: / we are calculating tax for US customers.When uk.Write: / we are calculating tax for UK customers.When others.Write: / please enter a valid country code.End case.Loop statement:Do . EnddoWhile . EndwhileLoop at . Endloop

    L h hi h d dl d di di i fi d b f i

  • 8/13/2019 Sap Abap Ig Notes Part1

    17/152

    Loop statements are those statements which are executed repeatedly depending on a condition or fixed number of times.

    There are 3 types of loop statements.

    Do enddo:

    Syntax:Do times...Enddo.While endwhile:Syntax:While ...Endwhile.Ex:Data: v_count type i.V_count = 0.Do 10 times.V_count = v_count + 1.Write / v_count.Enddo.Data: v_count type i.V_count = 0.While v_count < 10.V_count = v_count + 1.Write / v_count.Endwhile.Using EXIT, CONTINUE statements:

    EXIT:It is a statement which is used to exit or terminate the loop.

    CONTINUE Thi t t t i d t ti th t it ti l b di th it ti

  • 8/13/2019 Sap Abap Ig Notes Part1

    18/152

    CONTINUE:This statement is used to continue the next iteration or cycle by ending the iteration.Ex:

    Data: v_count type i.V_count = 0.EXIT ex:Do 10 times.V_count = v_count + 1.If v_count =5.Exit.Endif.Write / v_count.Enddo.CONTINUE ex:Do 10 times.V_count = v_count + 1.If v_count = 5.Continue.Endif.Write / v_count.Enddo.SY-INDEX:***It is a system variable which stores the loop iteration or cycle or loop index number, to specify whether it is a first loop or second or third etc.Ex:Do 10 times.

    Write / sy index

  • 8/13/2019 Sap Abap Ig Notes Part1

    19/152

    Write / sy-index.Enddo.Write sy-uline.Do 10 times.If sy-index = 5.Exit.Endif.Write / sy-index.Enddo.Displaying date:

    ot : ***Always the date is stored in YYYYMMDD format, but it is displayed depending on user settings in SU3 Tcode.Ex:

    Data: v_date1 type d.Data: v_date2 type dats.V_date1 = 20110331.V_date1 = 20110330.Write: / v_date1,

    / d t 2

  • 8/13/2019 Sap Abap Ig Notes Part1

    20/152

    / v_date2.Output:

    3103201130.03.2011Changing user settings:Go to SU3 TcodeClick on defaults tabChange the date format to the required formatClick on saveLogout From SAP and re login into SAPThen only our changes will be effectedExecute the same program, below is the output0331201103/30/2011Using EDIT MASK:EDIT MASK is the statement which is used to change the date separators within the program, without changing at SU3 Tcode. Syntax:Write / v_date1 using edit mask __/__/____Ex:Data: v_date1 type dats.V_date1= 20111230.Write: / v_date1 using edit mask __.__.____.Write: / v_date1 using edit mask __/__/____.Write: / v_date1 using edit mask __-__-____.DEBUGGING:It is an SAP tool to check how each statement is executed in a programThere are two ways to start debuggingBreak point

    Using /H on selection screen

  • 8/13/2019 Sap Abap Ig Notes Part1

    21/152

    Using /H on selection screenBreak point:It is a point to break the execution of a program at a particular place is called break point. There are two types of break points1.a. Static break point:It is a break point which is fixed in a program and which cannot be deleted automatically is called static break point. It is

    set using keyword BREAK-POINT.1.b. Dynamic break point:It is a break point which is deleted automatically after some time is called dynamic break point. It is set by clicking on

    icon

    .Steps for debugging:Create a program as belowReport zdebug no standard page heading.Data: v_name(15) type c.Data: v_pincode(6) type n.V_name = ibm india.V_pincode = 500082.Write: / v_name, / v_pindcode.Put the cursor on any line and click on break point symbol

    Execute the program, the ABAP debugger will startsClick on debuggerSwitch to classic debuggerDouble click on v_name, v_pincodeClick on single step (F5) iconCheck the program execution line by lineThe output will be displayed

  • 8/13/2019 Sap Abap Ig Notes Part1

    22/152

    Chapter 02

    2 ABAP Dictionary

  • 8/13/2019 Sap Abap Ig Notes Part1

    23/152

    2. ABAP DictionaryIt is a central repository where we define and maintain the objects which are related to database. The objects are,

    Database table:It is an object which stores data in the form of rows and columns. Each row is called as record, and each column is called as

    field. So, to define a table we have to define the fields first.Defining a field:

    FIELD = DATAELEMENT + DOMAINDomain:It is an object which specifies technical information such as data type and lengthfor a field is called domain. It also specifiessign, lower

    case, conversion routine, fixed values, and value table.Data element:It is an object which specifies semantic information such as field description, field labels (short, medium, long and heading).Advantages of data element and domain:Reusability:The same data element and domain can be reused by multiple table fields, instead of creating again and again. These are also used in creating foreign key relationship, search help, ale-idocs.Key field:A field which is used to identify the record uniquely is called a key field. In a table there should be at least one key field. We can createnumber of key fields (max 16 key fields).Steps to create domain:

    Save check and activate

  • 8/13/2019 Sap Abap Ig Notes Part1

    24/152

    Save, check and activate

    Steps to create data element:Go to SE11Select data typeGive a name, ex zcnoCreate -> select data elementProvide short descriptionProvide domain name as zcnoPress enterClick on field label tab, specify short, medium, long and heading labelsSave, check and activateSteps to create a table:Go to SE11Provide the table name zcust_tableClick on createProvide descriptionSpecify delivery class as ASpecify display maintenance allowedClick on fields tabProvide the field name, data element name as below

    Click on saveClick on technical settings buttonProvide the details as data class -> APPL0, size category -> 0Click on save and click on backSave and activate the tableCreating records into the table:Go to SE11Give the table name and click on changeClick on utilities -> table contents -> create

    Provide the cno, cname, city

  • 8/13/2019 Sap Abap Ig Notes Part1

    25/152

    Provide the cno, cname, cityRepeat the same procedure and create the recordsDisplaying the table contents:Click on utilities -> table contents -> displayClick on execute buttonThe records will be displayed

    Create a table to store material data with below fieldsMaterial number, material type, material units, and material group.Components of table:

  • 8/13/2019 Sap Abap Ig Notes Part1

    26/152

    Delivery class Short text

    A

    C

    L

    G, E, S, W

    Application table (master and transaction data)

    Customizing table; maintenance only by customer; not SAP import

    Table for storing temporary data, delivery report

    System data

    Delivery class:It specifies the type of the data that stored in a table. The data can be business data or system data. Business data means

    application data (master and transaction data). The following options are available.Display maintenance: It specifies whether the data should be displayed as well as maintained. Data maintenance means creation, deletion, and

    changing. There are 3 options available.Display maintenance allowed: Data is displayed and maintained

  • 8/13/2019 Sap Abap Ig Notes Part1

    27/152

    Display maintenance not allowed: Data is not displayed and not maintainedDisplay maintenance allowed with restrictions: Data is displayed, but maintenance is given only for some users based restrictionsData class:It specifies the physical area of a table inside the database.

    Data Class Description

    APPL0

    APPL1

    APPL2

    Master data, transparent tables

    Transaction data, transparent tables

    Organization and customizing

    Depending on the table we are suppose to select the required option. The options available are,

    Master data:The data which never changes or which changes very rarely is called master data.Ex: cno, cname, city etc.Transaction data:The day to day business data or the data which changes every day is called transaction data.

    Ex: customer bank transaction dataOrganization data:The data which is related to organization or company like how many company codes, plants,

    sales organization etc, is called organization data.Size category:It specifies the maximum number of records that can be stored in a table. The possible options are available as below.

  • 8/13/2019 Sap Abap Ig Notes Part1

    28/152

    Size category Number of data records of table expected

    0

    1

    2

    3

    .

    .

    0 to 6,100

    6,100 to 24,000

    24,000 to 98,000

    98,000 to 390,000

    In the real time we always set size category as 0, because we have to use small amount of memory.

    Suppose if the memory is not sufficient the system will automatically increase the size.

    Buffer/cache memory:It is a temporary memory to store the data. It is mainly used to increase the system performance.

    The functionality of buffer is defined as below.

  • 8/13/2019 Sap Abap Ig Notes Part1

    29/152

    The system program/tables request for the dataThe system will check whether the data is available in cache/buffer memoryIf it is available the data will be immediately given back to the system program/table, thereby increasing the system performanceSuppose if the data is not available, the request will be sent to database, and the response will be given back to buffer or cache memory to store a

    copy for future referencesAfter the copy is stored then the data will be given back to the system program/tableBuffering options:Buffering not allowed:Data is not stored in bufferBuffering allowed but not switched off:Used by SAPBuffering switched on:Data is stored in buffer

    By default buffering not allowed will be selected. *** Buffering types:Single record buffer:Only first record will be stored in the bufferFully buffered:All the records will be stored in the bufferGeneric area:The key fields data is called generic area. Only generic area data will be stored in the bufferClient number:It is a unique number which is used to provide security to the data at the database level. The field name, data element, and domainfor client number is MANDT. In the real time we use the client number (100,120), (200,220), (300,320).

  • 8/13/2019 Sap Abap Ig Notes Part1

    30/152

    Client dependent table Client independent table

    i. If the first field is MANDT, then it is

    called as client dependent table

    ii. This table stores data in specific client

    only

    i. If the first field is not MANDT, then it is

    called client independent table

    ii. Data is stored in all clients without

    security

    Types of tables based on client number

    Client dependent table:

    Create a table by name zcust_table_dp with below fields.

    Create some records in the table and display then.Now login to 810 clientOpen the table and display the dataThe data will not be available, because it is a client dependent table

  • 8/13/2019 Sap Abap Ig Notes Part1

    31/152

    What are the roles and responsibilities of an ABAP consultant?What is a ticket?What is the client number you are using in the project? (100)What is the system landscape of your project?What is a data dictionary?What is the difference between data element and domain?What is a key field?Can we create a table without a key field? (no) How many key fields can be created in a table? (16)What is a client number?What is the difference between client dependent and independent table?

    Structure:

  • 8/13/2019 Sap Abap Ig Notes Part1

    32/152

    It is a container of reusable fieldsStructures are defined in data dictionaryOnce the structures are defined we must include them in tablesThere are two options for including the structures in tablesInclude structureAppend structureDifference between include structure and append structure:

    Include append

    1. This option is used only with custom

    tables

    2. These include structures are reusable by

    multiple tables

    3. Just give field name as .include and

    data element as structure name

    1. Used only with standard SAP tables

    2. Not reusable

    3. Click on append structure button to

    create structure and add to table

    Ex on include structure:Step 1:

    Create a structure by name zaddrwith fields city, country, postal codeGo to SE11, select data type, provide a name zaddrClick on create and provide the descriptionSpecify the fields and data elements

    Component

    (field type)

    Rtype

    (reference)

    Component name

    (DE name)

    City

    Country

    Pcode

    Zcity

    Zcountry

    zpcode

    Save and activateSteps 2:Include the structure in a table as belowOpen any tableProvide the field name as .include, data element as structure name (zaddr)Enter

    The fields will be automatically copied

  • 8/13/2019 Sap Abap Ig Notes Part1

    33/152

    Click on or to display the fieldsClick on or

    to compress the fieldsot : Sometimes we may get unpredictable errors in a table, due to adding or deleting the fields in a table. To solve the error follow the below

    steps.

    Go to SE14Provide the table nameClick on edit buttonClick on activate and adjust databasebuttonEx on append structure: Business requirement: Add a custom field mname(middle name) to the standard SAP table kna1(customer master

    table).Open the table kna1 in display modeClick on append structurebuttonA pop-up is displayed, click on create iconProvide the append name zapp1and press enterProvide the field name as mnameand data element as zmnameSave, activate and click on backCheck the table in the field, it will be available at the bottomCurrency and Quantity fields:For every currency and quantity field we have to specify the corresponding units also. CURR:It is the data type which is used to store the amount or price fields.CUKY:It is the data type which is used to store the corresponding units for the currency fields.QUAN:It is the data type which is used to specify the quantity for a material or stock.UNIT:It is the data type which is used to specify the units for the quantity fields.Steps for currency, quantity fields:First define a currency or quantity field using CURR or QUAN data types Then define the corresponding units using CUKY or UNIT data types Finally link the currency and quantity fields with the corresponding units by providing reference table name and reference field name

    Ex on currency quant ty e s:Open any table

  • 8/13/2019 Sap Abap Ig Notes Part1

    34/152

    Open any tableAdd the below fields

    Field Data element Data type Reference table Reference field

    Amount

    Amt_units

    Quantity

    Qua_units

    Zamount

    Zamt_units

    Zquantity

    Zqua_units

    Curr(5,2)

    Cuky(5)

    Quan(5,2)

    Unit(3)

    Yycust_table

    Yycust_table

    Amt_units

    Qua_units

    Save and activate the tableForeign key relation:The relation between two tables for validating the data is called foreign key relation. Validation means checking whether the v

    Check table:A master table which stores master data is called a check table.Foreign key table:A table which is linked with check table for validating the data is called foreign key table.

    Steps for foreign key relation:Step 1:Create a table by name

    zcustomers

    with field

    s customer number and customer name, also create some records.

    Step 2:Create another table by name zcustomers_bank with fields cno, bankid and bankname.

  • 8/13/2019 Sap Abap Ig Notes Part1

    35/152

    Step 3:Create the foreign key relation as belowOpen the table zcustomer_bankSelect cno fieldClick on foreign keys buttonProvide the check table name as zcustomerClick on generate proposalbuttonClick on copy buttonSave and activate

    Step 4:Unit testing

    Click on utilities -> table contents -> createEnter the invalid customer number and click on saveThe error message will be displayedReal time ex on foreign key relation:

    Domain with field values:It is used for validation at the domain levelWe have to maintain some fixed values at the domain, so that all the table fields will be referring to this domain will be checked against with the fiIf a wrong value is entered system will raise the error message

    This option is only used whenever the number of values are less than 10 or 15If h l h 15 f f i k l i

  • 8/13/2019 Sap Abap Ig Notes Part1

    36/152

    If the values are more than 15, we go for foreign key relationThe main advantage of domain with fixed values is reusabilitySteps:

    Open the table zcustomer_bankAdd an extra field by name genderwith data element and domain as zgenderNow go to the domain zgender, double click on itClick on value range tabMaintain the fixed values as below

    Fix.val Short text

    M

    F

    Male

    Female

    Save and activate the domain and the tableGo to unit testingEnter the invalid value for genderThe error will be displayedVALUE TABLE:***A table name defined at the domain level so that all the table fields will be referring to the domain will be checked or validated with a single table

    called as value table.The main advantage of value table is to automate the system for foreign key relation i.e. the system will automatically display check table name

    along with proposal.Steps for value table:Create a table zzcustomer with field cno and cname, also create some recordsMaintain the check table name at domain level called as value tableGo to the domain zcnoClick on value range tabProvide the value table as zzcustomerSave and activate, domain and tableCreate another table by name zzcustomer_bank with fields cno, bankid, banknameMaintain the foreign key relation as below

    Open zzcustomer_bank tableSelect cno field and click on foreign key buttonA pop-up displayed as below

  • 8/13/2019 Sap Abap Ig Notes Part1

    37/152

    If we click on yes, foreign key relation will be automatically displayedIf we click on no, it will not be displayedDifferences between check table and value table:

    Check table Value table

    It is defined at field level

    FK relation is not automatic, that means

    we must enter check table name

    It is defined at domain level

    FK relation is automatic, that means once

    we maintain value table, FK relation will

    be automatically displayed

    Domain properties:SIGN:It is used to store the sign of a number, whether it is positive sign or negative signLower Case:This option is used to store a value in the combination of capital and small letters ***By default SAP will convert the entire value into capital lettersIf we dont want capital letters, please select lower case optionConversion Routine:It is a sub-program or function module which is used to convert a value from internal format to external format and vice versa

    Conversion routine function modules:

    Go to any domain, ex: MATNRThe conversion routine will be displayed, ex: MATN1Double click on MATN1The function modules will be displayed as belowCONVERSION_EXIT_MATN1_INPUT:This function module is used to convert material number from external format to internal format.CONVERSION_EXIT_MATN1_OUTPUT:This function module is used to convert material number from internal format tot external format.

    Table Maintenance Generator (SM30):It i t d d SAP t d i th f f f ti d l t i t i t f d t M i t ti d l ti d

  • 8/13/2019 Sap Abap Ig Notes Part1

    38/152

    It is a standard SAP program created in the form of function modules to maintain mass amount of data. Maintenance means creation, deletion and

    modification. It is also used for validating the table data using the concept of events.***Steps for TMG:

    Create any table by name zcustwith mandt, cno, cname and land1Save and activate the tableClick on utilities -> select table maintenance generatorProvide the details as below

    Authorization group = &NC&Function group = zcust (table name)Maintenance type

    one stepClick on find screen number buttonA pop-up is displayed, just press enterThe screen number will be automatically proposed

    Click on create iconThe TMG will be created in the form of function modulesActivating TMG:Go to SE80Select function group from the listProvide function group name (table name) and press enterRight click on function group name and select activateUnit testing:Go to SM30Provide the table nameClick on maintainbuttonEnter customer number, name and countryClick on save, the data will be savedValidations with TMG:The validation are possible using the concept called eventsThere are around 39 events available

    For each event we need to provide a routine name (sub-program name)

    Inside the routine we have to write the ABAP code for validating the data

  • 8/13/2019 Sap Abap Ig Notes Part1

    39/152

    Events in TMG:Open the tableClick on utilities and select TMGClick on environment -> modification -> eventsA new screen will be displayedClick on new entriesbuttonClick on helpbutton on the first row, first columnThe 39 events will be displayed

    Main event Short text

    01

    02

    03

    04

    05

    ..

    ..

    Before saving the data in the database

    After saving the data in the database

    Before deleting the data displayed

    After deleting the data displayed

    Creating a new entry

    .

    .

    T (event name) Form routine (routine name)

    05 Znew_rec

    Provide the routine name for any event in the second column

    New sub-program which will be created for writing the logicEx on validation: Business Requirement: Raise an error message whenever a new record or customer is created without providing the country or

    land1.Create a table by name zkna1with kunnr, land1, name1 fieldsCreate a TMGClick on environment -> modifications -> eventsClick on new entriesbuttonSelect the event 05(creating a new record) and provide sub-routine name (sub-program name)

    Event name Form routine Editor

  • 8/13/2019 Sap Abap Ig Notes Part1

    40/152

    Event name Form routine Editor

    05

    ..

    ..

    Znew_rec

    ..

    ..

    .

    Click on editor iconPress enter 2 times (sub-program will be created automatically)Write the below ABAP codeForm znew_rec.If zkna1_land1 = .Message please enter countrytype E.Endif.Endform.Save and activateClick on back, saveClick on back, saveClick on saveAn information message will be displayed as function group cant be processedClick on back -> back -> backGo to SE80 and activate function groupGot SM30 and test it

    Create a table by name zlfa1with vendor number, name, date and user name. Create

    TMG and validate the TMG so that date and username automatically saved.

  • 8/13/2019 Sap Abap Ig Notes Part1

    41/152

    VIEWSA view is collection of fields from multiple tablesThe multiple tables must be joined to create a viewThere must be at least one common field to create a view View does not store any data, it fetches the data from multiple tables and displays the dataJOINSIt is a concept which is used to join or combine two or more tables to read the data. There are two types of joins.Inner joinOuter join or left outer joinInner join:

    In this type of join (inner) it will display or fetch only the matching records between two or multiple tables.Outer join: In this type of join it will display all the records from the left table or first table Then it will check whether there are any matching

  • 8/13/2019 Sap Abap Ig Notes Part1

    42/152

    Outer join:In this type of join, it will display all the records from the left table or first table. Then it will check whether there are any matching

    records. If the matching records are available, it will display the data, else it will display the value as blank.Types of views:There are 4 types of viewsDatabase viewProjection viewHelp viewMaintenance view

    Database view:A view created on two or more tables using inner join concept is called database view In this view we can only read the dataWe cannot maintain the dataWe can provide selections to read the dataEx on database view:Develop a database view on MARA and MAKT tables to display material number, material type, material units, language and description. Go to SE11Provide the view name zdb_viewClick on createSelect database viewProvide descriptionProvide the table names and joining condition

    Click on view fields tabClick on table fields buttonDouble click on MARA and select MATNR, MTART and MEINS

    Click on copy

  • 8/13/2019 Sap Abap Ig Notes Part1

    43/152

    Again click on table fields buttonDouble click on MAKT and select SPRAS, MAKTXClick on copyClick on condition tabProvide the condition as below

    Table Field name Operation Comparison value

    Makt Spras Eq E

    Save and activateClick on contents

    Click on execute, the data will be displayed

    Develop a database view on vbak and vbap tables to display vbeln, vkorg, vtweg, posnr, matnr and netwr. Develop a database view on ekko and ekpo tables to display ebeln, ekorg, ebelp and matnr. Projection view:A view created on single table is called projection view. Projection views are mainly used to minimize the database interface

    (number of fields) and improve the system performance. We can maintain the data in the projection views. We cannot provide any selections in

    the projection views.Ex on projection view:Go to SE11Provide the view name zproj_viewClick on create, provide descriptionProvide the basis table as maraClick on table fields buttonSelect matnr, mtart, mbrsh and meinsClick on copy buttonSave and activateClick on contents and display the view

    Maintaining the data:

  • 8/13/2019 Sap Abap Ig Notes Part1

    44/152

    g

    To maintain the data, we have to provide the key fields i.e. mandt, matnrGo to the view and add the first field as mandtClick on maintenance status tabSelect read and change radio buttonSelect display maintenance allowedSave, activate and display the data

    Help view:A view created on two or more tables using outer join concept is called help view. Help view are specially designed for search helps.We cannot execute help views directly, instead we have to include help views inside the search helps. We cannot maintain the data in help views. Ex on help views:Go to SE11Provide the view name zhelp_viewClick on create

    Provide descriptionProvide the table name as makt and click on relationships buttonSelect

    Click on copy, the join condition will be automatically displayedClick on view fields tabProvide the field names matnr, mtart, meins and maktx by clicking on table fields buttonProvide the selection condition if requiredSave and activateWe cannot test this help viewIf we want to test we should create a search helpMaintenance view:A view created on two or more tables using inner join concept is called maintenance viewsWe can maintain the data in maintenance viewsMaintenance view are used by SAP for internal purposeIn the real time we dont create any maintenance views because the data should be saved or modified in multiple tables which leads

    inconsistencyIf we want save or modify the data, we have to use standard SAP transactions or BAPI sSearch Helps (SH):

    Providing a help functionality or F4 functionality for an input field is called search help. There are two types of search help.Elementary search helpCollective search help

    Elementary search help:Providing a single search help for an input field is called elementary search help.Collective search help: Collection of elementary search helps for an input filed is called collective search help

  • 8/13/2019 Sap Abap Ig Notes Part1

    45/152

    Collective search help:Collection of elementary search helps for an input filed is called collective search help.Assigning search helps:Once search helps are created we have to assign themAt program-selection screen levelAt table-levelAt sap-screen levelSelection-screen:Input screen to a program or search is called selection screen.Parameters:It is a keyword to declare or create an input field on the selection screen.Ex:Parameters p_kunnr(10) type c.Parameters p_matnr(20) type c.Match code object:It is a keyword which is used to assign a search help to the input fields on the selection screen. By default standard SAP search

    help will be displayed. If we dont want standard search help then we use match code object to assign our own search help.Syntax:Parameters: (length) type match code object Parameters: type (field name) match code object Ex on elementary search help:Go to SE11Provide the search help name zel_shClick on create and provide descriptionProvide the selection method as maraProvide the search help parameter as below

    Search help parameter Imp Exp Lpos Spos Sids ..

    Matnr

    Mtart

    1

    2

    1

    2

    Save, activate and test it

    Assigning search help at program-selection screen level:Go to SE38Create a program by name zsh_progWrite the below code

  • 8/13/2019 Sap Abap Ig Notes Part1

    46/152

    Parameters: p_matnr1 type mara-matnr.Displays stands SHs

    Parameters: p_matnr2 type mara-matnr match code object zel_sh.Displays custom or our own SHs

    Assigning SHs at table level:Step 1:Create a table by name zcustomerswith cno, name and cityStep 2:Create a search help as belowGo to SE11Provide the SH name zsh_zcustomerClick on create and provide descriptionProvide the selection method as zcustomerProvide the search help parameters as below

    SHP Imp Exp Lpos Spos

    Cno

    Cname

    City

    1

    2

    3

    1

    2

    3

    Save, activate and test itStep 3:Let us assign the SH to the tableOpen the table zcustomerSelect the cno field and click on SH buttonThe proposal will be automatically generatedJust change the proposal as below

    SHP Table name Field name

    Cno

    Cname

    City

    Zcustomer Cno

    Press enterSave and activate the table

  • 8/13/2019 Sap Abap Ig Notes Part1

    47/152

    Save and activate the tableClick on contents iconClick on help button of customer number filedThe list of the values will be displayedCollective search help:A collection of elementary search helps is called collective search helps.Step 1:Create a elementary SH by name zel_sh1with selection method as mara and sh parameters matnr, mtart.Step 2:Create another elementary SH by name zel_she2with selection method as mara and sh parameters matnr, meins.Step 3:Create a collective search help as belowGo to SE11Provide the SH name zcoll_shClick on crate and provide descriptionProvide the SH parameters matnr, mtart and meins with import, export and data elementsClick on included search helps tabProvide the first search help name as zel_sh1and click on parameter assignment buttonClick on yes button the proposal will be generated automaticallyProvide the second search help name zel_sh2and click on parameter assignment buttonClick on yes button the proposal will be generated automatically

    Save, activate and test itFinally assign the SH at the program level or table levelComponents of SH:Selection method:It specifies the table name or the view name from where the values have to be selected. Provide the table name, if the values

    have to be selected from single table. Provide the view name (help view), if the values have to be selected from multiple tables.SPOS:It specifies the position of the field on the selection-screen.LPOS:It specifies the position of the field on the list-screen.Importing:If this check box is selected, the value will be imported from selection screen to the list screen and corresponding values will be

    displayed.Exporting:If this check box is selected, the value by the user will be exported from the list screen to the selection screen.

  • 8/13/2019 Sap Abap Ig Notes Part1

    48/152

    Dialog type:It specifies whether the value restriction screen should be disabled or not. There are 3 options available.Display values immediately:The values will be immediately displayed without value restriction screen.

    Dialog with value restriction:The value restriction screen will be displayed first and then output values are displayed.Dialog depends on set of values:If values are less than 500, then values will be displayed immediately else value restriction screen will be

    displayed.Search Help Exit:It is a function module exit where we design the custom search help by writing the ABAP statements inside the function

    module, which is not possible with the direct data dictionary SH. The function module must be of type F4IF_SHLP_EXIT_EXAMPLE ***.That means the function module exit should contain the same importing and exporting parameters of standard SAP function module.

    F4IF_SHLP_EXIT_EXAMPLE

    TYPE GROUP:(ABAP dictionary)It is an object which contains the reusable user defined types.Ex: SLISis a type group given by SAP for developing ALV reports.

  • 8/13/2019 Sap Abap Ig Notes Part1

    49/152

    What is the difference between table and structure?What is the difference between append structure and include structure?What is the difference between check table and value table? What do you mean by fixed values with domain?What is a conversion routine?How do you enter lower case letters on the screen?What is a selection screen?What is a view does the view stores any data?What are the different types of the views?What is a SH and its types?What is a collective SH?What is a match code object?What is a parameter?What is a TMG and its Tcode?Can you validate the table data using TMG, if yes what are the events available? What is a SH exit, SPOS, LPOS, importing and exporting?Types of Tables:There are 3 types of tables.Transparent tablesPooled tablesClustered tablesTransparent tables:These are used to store business data (master and transaction data). Whenever a transparent table is created in data dictionary

    the same table will be created in the database with the same name and the fields.

    That means transparent tables will have one to one relation between data dictionary table and database table. By default all the tables created by

    ABAP consultants are called as transparent tables.

  • 8/13/2019 Sap Abap Ig Notes Part1

    50/152

    p

    Pooled tables:These tables are used to store system data like screen sequence data, historical data and statistical data. All the pooled tables from

    data dictionary will be stored in a single table by name TABLE POOLin database.

    That means pooled tables will have many to one relationship between data dictionary tables and the database tables. The fields in the table pool

    are,TAB name stores name of the pooled tableVARKEY stores key fields of pooled tableDATALN stores length of the dataVARDATA stores the data of pooled table continuously like notepad filesClustered tables:These tables are also used to store system data such as screen sequence, historical data and statistical data. These tables also

    have many to one relationship.All the clustered tables from data dictionary will be stored in a single table by name TABLE CLUSTER.

    Cluster tables are same as pooled tables; the difference is cluster table stores the data in the form of pages with the time stamp (who created, whencreated and so on).

  • 8/13/2019 Sap Abap Ig Notes Part1

    51/152

  • 8/13/2019 Sap Abap Ig Notes Part1

    52/152

    Chapter 03

    3. INTERNAL TABLES

  • 8/13/2019 Sap Abap Ig Notes Part1

    53/152

    Internal table is a temporary memory location which can store the data from database table. By default the size of the internal table will be 8KBIt can store nnumber of recordsThe size of the internal table will increase dynamically

    Work Area (WA): It is also temporary memory location which can store only a single record. All the operations on internal table must be executed

    via WORK AREA.

    Syntax: (for internal table i.e. itab)Data type table of

    OrData type table of

    OrData type occurs 0 (obsolete statement)

    Syntax: (for work area i.e. wa)Data type

    OrData type

    Data type occurs 0 with header line (itab and wa will be created; obsolete statement)

  • 8/13/2019 Sap Abap Ig Notes Part1

    54/152

    a a wa a e ype da abase ab e occu s 0 w eade e ( ab a d wa w be c ea ed; obso e e s a e e )

    SELECT statement: It is the statement which is used to select data from database table into internal table (or) work area.Syntax:Select * (or) f1 f2 f3From Into table Where = And = . . . . . .LOOP. ENDLOOP: This statement is used to read each record from internal table into work area.Syntax:Loop at into ...Endloop .Ex Business Requirement: Develop a report to display customer details.Report zcustomer_report .Data i_kna1 type table of kna1 .Data wa_kna1 type kna1 .Select * from kna1 into table i_kna1 where land1 = us.Loop at i_kna1 into wa_kna1 .Write : / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1 .Endloop .

  • 8/13/2019 Sap Abap Ig Notes Part1

    55/152

    Develop a report display material details ( MARA)

    Develop a report to display vendor details (LFA1)User defined types: It is used to define our own TYPE with the fields required for the internal table. TYPESis the keyword to define a

    user defined type.Syntax:

    Types : begin of , f1 type , f2 type , .,End of .Ex on user defined types:Types: begin of ty_kna1,Kunnr type kna1-kunnr,Land1 type kna1-land1,

    Name1 type kna1-name1,Ort01 type kna1-ort01,End of ty_kna1.Data: i_kna1 type table of ty_kna1.Data: wa_kna1 type ty_kna1.Select kunnr land1 name1 ort01

    From kna1Into table i_kna1Where land1 = us.Loop at i_kna1 into wa_kna1.Write: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01.Endloop.

  • 8/13/2019 Sap Abap Ig Notes Part1

    56/152

    Select into corresponding fields: This statement is used whenever the selected fields and the internal table fields are miss matched, i.e. the

    source fields and the internal table fields are not in the proper order.Ex:Same program as above, do the change to select statement.Select *From kna1Into corresponding fields of table i_kna1Where land1 = us.ot : But itab (i_kan1) contains only 4 fields, so use select ., corresponding fields. This statement should never be used in the real time, because

    it puts unnecessary load on the select statement for comparing source and target fields.Operations on internal tables:AppendInsertSortDescribe tableRead table (with index and with key)Loop endloopModifyDeleteDelete adjacent duplicatesClearRefreshFreeAppend lines of

    Insert lines ofMove itab1 to itab2Collect

    Append: This statement is used to add a record from work area to internal table. The record is always added at the bottom.Syntax:

    Append to .

  • 8/13/2019 Sap Abap Ig Notes Part1

    57/152

    Ex:

    Wa_kna1-kunnr = 1011.Wa_kna1-name1 = aaa.Wa_kna1-land1 = us.Append wa_kna1 to i_kna1.Insert: This statement is used to insert a record from work area to internal table at the specified location.Syntax:

    Insert into index .Ex:

    Wa_kna1-kunnr = 1022.Wa_kna1_name1 = bbb.Wa_kna1-land1 = in.Insert wa_kna1 into i_kna1 index 5.Sort: This statement is used to sort the internal table data either in ascending order or descending order. By default it will sort in ascending order

    based on field1, field2, field3etc.Syntax:Sort by f1, f2, f3 .. Ascending / Descending.Ex:

    Sort i_kna1 by kunnr. (by default it is ascending order )Sort i_kna1 by land1 descending. (sorts in descending order)Sort i_kna1. (by default it sort in ascending order based on f1, f2, f3, . . . etc)Ex:Types: begin of ty_kna1 kunnr land1 name1 ort01

    End of ty_kna1.Data: i_kna1 type table of ty_kna1.Data: wa_kna1 type ty_kna1.

    Select kunnr land1 name1 ort01From kna1 into table i_kna1

  • 8/13/2019 Sap Abap Ig Notes Part1

    58/152

    Up to 10 rows.Wa_kna1-kunnr = 1011.Wa_kna1-land1 = us.Wa_kna1-name1 = aaa.Append wa_kna1 to i_kna1.Wa_kna1-kunnr = 1022.Wa_kna1-land1 = in.Wa_kna1-name1 = bbb.Insert wa_kna1 into i_kna1 index 5.*sort i_kna1 by kunnr.*sort i_kna1 by land1 descending.Sort i_kna1.Loop at i_kna1 into wa_kna1.Write: / wa_kna1-kunnr, wa_kna1-land1, wa_kna1-name1.Endloop.Describe table: This statement is used to find the total number of records in a internal table.Syntax: (data: v_index type i.)Describe table lines .Ex:Describe table i_kna1 lines v_lines.Write: / total customers are:, v_lines.

    Read table with index: This statement is used to read a single record from internal table into work area given by the index number.Syntax:R d bl i b i i d i d b

  • 8/13/2019 Sap Abap Ig Notes Part1

    59/152

    Read table into index .Ex:Read table i_kna1 into wa_kna1 index 5.Write: / wa_kna1-kunnr, wa_kna1-land1, wa_kna1-name1.Read table with key: This statement is used to read a single record from internal table into work area with field name and field value.Syntax:

    Read table into with key = =

    = Binary Search.

    Ex:Read table i_kna1 into wa_kna1 with key kunnr = 1011binary search.Write: / wa_kna1-kunnr, wa_kna1-land1, wa_kna1-name1.Binary Search:

    It is a search algorithm which is used to read the data very fastly from internal tableThe functionality of binary search is described belowThe entire internal table data will be divided into two halfsThe system will search for the record either in the first half or second half based on rough estimationSuppose if the system assumes the record to be available in the first half, the entire second half will be deleted, thereby reducing half of the

    burden on the systemNow the system will again divide the first half into two more halfsAgain the system will search for the record either in the first half or second halfSuppose if the record assume to be available in the second half, the entire first half will be deleted, thereby reducing 75% burden on the systemThe process will continue until it finds the exact record

  • 8/13/2019 Sap Abap Ig Notes Part1

    60/152

    ot : ***The prerequisite for binary search is the internal table should be sorted in ascending order.(Program continuation)Data: v_lines type i.Describe table i_kna1 lines v_lines.Write: / total customers are:, v_lines.Loop at i_kna1 into wa_kna1.Write: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01.Endloop.Write / sy-uline.Read table i_kna1 into wa_kna1 index 5.Write: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01.Write / sy-uline.Sort i_kna1 by kunnr.

    Read table i_kna1 into wa_kna1 with key kunnr = 1011binary search.Write: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01.

    Loop Endloop: This statement is used to read multiple records from internal table into work area serially one by one one by one

  • 8/13/2019 Sap Abap Ig Notes Part1

    61/152

    LoopEndloop: This statement is used to read multiple records from internal table into work area serially one by one, one by one.Syntax:Loop at into . Endloop.Loop at into where = and = and = . Endloop.Loop at into from to endloop.

    A real time example on loopendloop - Business requirement: Develop a customer master report to display customer details along with the bank

    details (kna1, knbk).Modify: This statement is used to modify a single record or multiple records based on the condition.Syntax:Modify from index transporting Modify from transporting .where .Transporting: This keyword specifies the list of the fields to be modified from work area to internal table.SY-TABIX: (SY: system, TAB: internal table, IX: index) this system variable automatically stores the index number of the internal table record

    which is currently processed in the work area.SY-INDEX: It is a system variable which stores the loop [ do-endo, while-endwhile ] iteration or cycle number.Ex1:Sort i_kna1 by kunnr.Read table i_kna1 into wa_kna1 with key kunnr = 1011binary search.Wa_kna1-land1 = usa.Modify i_kna1 from wa_kna1 index sy-tabix transporting land1.

  • 8/13/2019 Sap Abap Ig Notes Part1

    62/152

    Syntax:Delete adjacent duplicates from Comparing . (or) Comparing ALL fields.Ex:

  • 8/13/2019 Sap Abap Ig Notes Part1

    63/152

    Ex:Wa_kna1-kunnr = 1022.Wa_kna1-land1 = in.Wa_kna1-name1 = bbb.Insert wa_kna1 into index 5.Insert wa_kna1 into index 8.Insert wa_kna1 into index 3.Sort i_kna1 by kunnr.Delete adjacent duplicates from i_kna1 comparing all fields.Loop at i_kna1 into wa_kna1.Write: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1, wa_kna1-ort01.Endloop.Clear: This statement is used to clear or delete the data from work area. In the old version the clear statement was also used to clear the data from

    internal table also.Syntax:Clear .

    Clear [ ]. (body 8K of itab, i.e. old syntax)Ex:

    Append wa_kna1 to i_kna1.Clear wa_kna1.Refresh: This statement is used to delete the data from internal table only.Syntax:Refresh .

    Ex:Refresh i_kna1.Free: This statement is same as clear and refresh The difference is the free statement will delete the data as well as memory also But the

  • 8/13/2019 Sap Abap Ig Notes Part1

    64/152

    Free: This statement is same asclear andrefresh. The difference is, the free statement will delete the data as well as memory also. But the

    clear and refreshstatements will delete only data but not memory. Syntax:Free .Ex:Free i_kna1.Free wa_kna1.Append lines of: This statement is used to append multiple records from one internal table to another internal table.Syntax:Append lines of from to to .Ex:Data: i_kna1 type table of ty_kna1.Data: i_kna1_tmp type table of ty_kna1.Data: wa_kna1 type ty_kna1.Select kunnr name1 land1

    From kna1 into table i_kna1

    Up to 10 rows.Append lines of i_kna1 from 3 to 5 to i_kna1_tmp.Loop at i_kna1_tmp into wa_kna1.Write: / wa_kna1_tmp-kunnr, wa_kna1_tmp-name1, wa_kna1_tmp-land1.Endloop.Insert lines of: This statement is used to insert multiple records from one internal table to another internal table at a specified location.

    Syntax:Insert lines of from to into index .Ex:

  • 8/13/2019 Sap Abap Ig Notes Part1

    65/152

    Ex:

    Same program as above with below change.Insert lines of i_kna1 from 6 to 8 into i_kna1_tmp index 2.Move itab1 to itab2: This statement is used to move all the data of one internal table to the other internal table.Syntax:Itab2 [ ] = itab1 [ ].Ex:I_kna1_tmp [ ] = i_kna1 [ ].Loop at i_kna1_tmp into wa_kna1...Endloop.

    (Or)Loop at i_kna1 into wa_kna1.Append wa_kna1 to i_kna1_tmp.Endloop.Loop at i_kna1_tmp to wa_kna1.

    ..Endloop.

    What is the output of program?Loop at i_kna1 into wa_kna1.Append wa_kna1.

    Write: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-land1.Endloop.Collect:

  • 8/13/2019 Sap Abap Ig Notes Part1

    66/152

    Collect:

    Collect statement is same as append statement. The difference is, the append statement will append the record from work area to internal table

    without checkingWhereas the collect statement will check whether the work area record already exists in the internal table with the same key (C, N, D, T data

    types)If yes it will add the numerical fieldsIf no it will append record ***Syntax:Collect into .Ex:Types: begin of ty_kna1,

    Kunnr type kna1-kunnr,Name1 type kna1-name1,Amount type I,End of ty_kna1.

    Data: i_kna1 type table of ty_kna1.Data: wa_kna1 type ty_kna1.Wa kna1-kunnr = 1011

  • 8/13/2019 Sap Abap Ig Notes Part1

    67/152

    Wa_kna1 kunnr 1011 .Wa_kna1-name1 = reliance.Wa_kna1-amount = 100.Collect wa_kna1 into i_kna1.Wa_kna1-kunnr = 1022.Wa_kna1-name1 = hero motor corp.Wa_kna1-amount = 200.Collect wa_kna1 into i_kna1.Wa_kna1-kunnr = 1011.Wa_kna1-name1 = reliance.Wa_kna1-amount = 50.Collect wa_kna1 into i_kna1.Write: / wa_kna1-kunnr, wa_kna1-name1, wa_kna1-amount.Endloop.Types of internal tables: There are three types of internal tables.Standard internal table

    Sorted internal tableHashed internal table STANDARD ITAB SORTED ITAB HASHED ITAB

    1. These are the default itabs created

    by ABAP consultants

    2. We can read a record using index

    or key

    3. We can use either linear search or

    binary search for reading a record

    4. If we use linear search, then,

    response time number of records

    5. If we use binary search then ,

    response time(number of records)

    6. We can sort these internal tables

    wherever we want

    1. These are not default itabs, they

    are special type of itabs where the

    data is automatically sorted

    whenever you insert the data into

    the table

    2. The data is inserted using the

    insert statement, not the append

    statement (we cant use append

    here)

    3. It uses only binary search since

    the data is already sorted

    4. The response time is

    Response time= ( N)

    1. These are not default internal

    tables, these are also special type

    of itabs where we can use only

    key operations

    2. That means for reading a record

    we can use the key operation, we

    cantuse index operation

    3. The response time is always

    constant regardless of the number

    of records

    4. Hashed tables should be used only

    when we want to work with all

    the fields of database table and

    with all records, i.e. when

    working with mass amount of

    data

    5. The response time is constant

    because it will be using hashed

    algorithms

  • 8/13/2019 Sap Abap Ig Notes Part1

    68/152

  • 8/13/2019 Sap Abap Ig Notes Part1

    69/152

    What is an itab and wa?How much size will be allocated for itab and wa?What is the difference between append and insert, append and collect?How do you find total number of records in an internal table?What is binary search explain it?What is the prerequisite for binary search?What is transporting?What is the difference between sy-index and sy-tabix?***What is the difference between clear, refresh and free?***How do you move the data from one itab to another itab? How do you move limited records from one itab to another itab?What is occurs 0,header line?What are the different types of itabs?

    What is types statement?Do we use selectcorresponding fields, if no why?

  • 8/13/2019 Sap Abap Ig Notes Part1

    70/152

    Chapter 04

  • 8/13/2019 Sap Abap Ig Notes Part1

    71/152

    System variables used with open SQL:There are two system variables which get updated automatically whenever an open SQL statement isexecuted. SY-SUBRC:(System sub-operation return code) sy-subrcis a system variable which specifies whether the open SQL statement is successful

  • 8/13/2019 Sap Abap Ig Notes Part1

    72/152

    or not.Sy-subrc = 0, it is successful.Sy-subrc =0, it is unsuccessful.

    SY-DBCNT:(System database count) this system variable specifies how many records are successfully processed with an open SQL statement.Difference between modify, insert and update:Insert:It will insert the data into database table from itab or work area.Update:It will update the record, if the record already exists in the database table. If the record does not exist it does not update any record.Modify:

    Modify statement works as insert or update. If the record already exists it will work as update else it will work as insert.ot : When working with the open SQL statements the internal table should be declared directly referring to database tables not the user defined

    types.Ex:Data: i_kna1type table of ty_kna1.

    Data: i_kna1 type table of kna1.

  • 8/13/2019 Sap Abap Ig Notes Part1

    73/152

    Update:There are two types of updates.

    Syntax Syntax

    Update

    From .

    Update

    Set = = ..Where .

    Ex on open SQL(T001W Plant/Branches):Report zopen_sql.Data: i_t001w type table of t001w.Data: wa_t001w type t001w.Wa_t001w_werks = hyd1.Wa_t001w_name1 = hyd plant1.Append wa_t001w to i_t001w.Wa_t001w_werks = hyd2.Wa_t001w_name1 = hyd plant2.Append wa_t001w to i_t001w.Insert t001w from table i_t001w.Delete t001w from table i_t001w.Update t001w from table i_t001w.Update t001w set ort01 =

    panjagutta

    where werks =

    hyd1

    .

    Modify t001w from table i_t001w.If sy-subrc = 0.Write: / plants are successfully inserted / updated / modified:, sy-dbcnt.

  • 8/13/2019 Sap Abap Ig Notes Part1

    74/152

    Else.Write: / plants are not inserted / updated / modified.Endif.Select . With joins:

    This statement is used to fetch the data simultaneously from multiple database tablesThere should be at least onecommon fi eldbetween the tables to fetch the dataThe tables must be joined using inner join/outer joinIn the real time this is used only for two or three internal tablesIt should not be used for more than three tables because it puts heavy load on the databaseSyntax:Select t1~f1t1~f2t2~f1t2~f3t3~f1

    t3~f2Into table From as inner join/left outer join as on ~f1 = ~f1Inner join/left outer join as on ~f1 = ~f1Where .Ex: Business requirement: Develop a report to display material details and description details (mara, makt).Types: begin of ty_mara_makt,

    Matnr type mara-matnr,

    Mtart type mara-mtart,Meins type mara-meins,Spras type makt-spras,

  • 8/13/2019 Sap Abap Ig Notes Part1

    75/152

    Maktx type makt-maktx,End of ty_mara_makt.Data: i_mara_makt type table of ty_mara_makt.Data: wa_mara_makt type ty_mara_makt.Select a~matnr a~mtart a~meins b~spras b~maktxInto table i_mara_maktFrom mara as a inner join makt as b on a~matnr = b~matnr

    Where b~spras = en.Loop at i_mara_makt into wa_mara_makt.Write: / wa_mara_makt-matnr,

    wa_mara_makt-mtart,wa_mara_makt-meins,

    wa_mara_makt-spras,wa_mara_makt-maktx.Endloop.Select. For all entries:This statement is used to replace inner joinsThis statement can be used to fetch the data from more than three tables, that means select with joins must be used only for two or three tablesIf we want to fetch the data from more than three tables then use SELECTFOR ALL ENTRIESSyntax:Select .

  • 8/13/2019 Sap Abap Ig Notes Part1

    76/152

    Wa_mara-mtart = halb.Wa_mara-meins = st.Append wa_mara to i_mara.

  • 8/13/2019 Sap Abap Ig Notes Part1

    77/152

    Wa_mara-matnr = 100-120.Wa_mara-mtart = roh.Wa_mara-meins = st.Append wa_mara to i_mara.If i_mara is not initial.Select matnr spras maktx

    From makt into table i_maktFor all entries in i_maraWhere matnr = i_mara-matnr.Endif.*Loop at i_mara into wa_mara.*Loop at i_makt into wa_makt where matnr = wa_mara-matnr.*Write: / wa_mara-matnr, wa_mara-mtart, wa_mara-meins, wa_makt-spras, wa_makt-maktx.*Endloop.*Endloop.Sort i_mara by matnr.Sort i_makt by matnr.Loop at i_makt into wa_makt.Read table i_mara into wa_makt with key matnr = wa_makt-matnr binary search. Write: / wa_mara-matnr, wa_mara-mtart, wa_mara-meins, wa_makt-spras, wa_makt-maktx.Endloop.

    Ex2 on selectfor all entries:Types: begin of ty_final,Matnr type mara-matnr,

  • 8/13/2019 Sap Abap Ig Notes Part1

    78/152

    Mtart type mara-mtart,Meins type mara-meins,Spras type makt-spras,Maktx type makt-maktx,End of ty_final.Types: begin of ty_mara,Matnr type mara-matnr,Mtart type mara-mtart,Meins type mara-meins,End of ty_mara.Types: begin of ty_makt,

    Spras type makt-spras,Maktx type makt-maktx,

    End of ty_makt.Data: i_mara type table of ty_mara.Data: i_makt type table of ty_makt.Data: i_final type table of ty_final.Data: wa_mara type ty_mara.Data: wa_makt type ty_makt.Data: wa_final type ty_final.Parameters: p_mtart type mara-mtart.

    Select *From mara into table i_maraWhere mtart = p_mtart.S l *

  • 8/13/2019 Sap Abap Ig Notes Part1

    79/152

    Select *From makt into table i_maktFor all entries in i_maraWhere matnr = i_mara-matnr.Sort i_mara by matnr.Sort i_makt by matnr.Loop at i_makt into wa_makt.Read table i_mara into wa_mara with key matnr = wa_makt-matnr binary search.Wa_final-matnr= wa_mara-matnr.Wa_final-mtart = wa_mara-mtart.Wa_final-meins = wa_mara-meins.Wa_final-spras = wa_makt-spras.Wa_final-maktx = wa_makt-maktx.Append wa_final to i_final.Clear: wa_final, wa_mara, wa_makt.Endloop.Loop at i_final into wa_final.Write: / wa_final-matnr, wa_final-mtart, wa_final-meins, wa_final-spras, wa_final-maktx.Endloop.

  • 8/13/2019 Sap Abap Ig Notes Part1

    80/152

    Develop a customer master report to display master details and bank details (kna1, knbk)Develop a sales order report to display header details and item details (vbak, vbap)Develop a delivery report to display header details and item details (likp, lips)Develop a invoice/billing report to display header details and item details (vbrk, vbrp)

  • 8/13/2019 Sap Abap Ig Notes Part1

    81/152

    Chapter 05

    5. SD FLOW (SALES AND DISTRIBUTION)

  • 8/13/2019 Sap Abap Ig Notes Part1

    82/152

    Header data:The data related to organization or company or plant etc is called header data.Item data:The data which is related to item or products or materials is called item data.Select single/ up to 1 rows:

    Select single Select.up to 1 rows

    It is used to read exact record (single

    record) To read the exact record we need all key

    fields

    It is used for validation when all key

    fields are available

    It is faster, because all the key fields are

    available

    It is used to read appropriate record

    (single record) To read appropriate record we need some

    key fields, not all the key fields

    It is also used for validation when some

    key fields are available in program

    It is slow, because all the key fields are

    not available

    Syntax

    Select single * or ..

    From

    Into

    Where

    Syntax

    Select

    From

    Into

    Where

    End select.

    Ex:Report zopen_sql.Data: v_matnr type mara-matnr.Data: v prctr type cepc prctr

  • 8/13/2019 Sap Abap Ig Notes Part1

    83/152

    Data: v_prctr type cepc-prctr.Parameters: p_matnr type mara-matnr.Parameters: p_prctr type cepc-prctr.Select single matnrFrom mara

    Into v_matnrWhere matnr = p_matnr.If sy-subrc 0.Message invalid material numbertype E.Else.Write: / v_matnr color 5.Endif.Select prctr

    From cepcInto v_prctrWhere prctr = p_prctrEnd select.If sy-subrc 0.Message invalid profit center numbertype E.Else.Write: / v_prctr color 5.Endif.

    Select screen statements:Input screen to a program or report is called as selection screen.

  • 8/13/2019 Sap Abap Ig Notes Part1

    84/152

    Statement Description

    Parameters Used to create input field, check box, radio buttons

    Select-options Used to create two input fields for entering range of numbers

    Selection-screen

    commands

    Set of statements for designing selection screen beautifully

    Parameters:This statement is used to create a single input field check box, radio buttons.Syntax:Parameters: type .Parameters: type obligatory (means mandatory field)

  • 8/13/2019 Sap Abap Ig Notes Part1

    85/152

    Parameters: type obligatory. (means mandatory field)Parameters: as check box.Parameters: radio button group default X.ot : Whenever a check box or radio button is selected the value Xwill be stored in the corresponding parameter variable.

    Ex: (on parameters)Parameters: p_kunnr type kna1-kunnr obligatory.Parameters: p_land1 type kna1-land1.Parameters: p_dload as checkbox.Parameters: p_rb1 radiobutton group aaa.

    P_rb2 radiobutton group aaa default X.P_rb3 radiobutton group aaa.

    If p_dload = X.Write: / check box is selected.Else.Write: /

    check box is not selected

    .

    If p_rb1 = X.Write: / radio button 1 is selected.Elseif p_rb2 = X.Write: / radio button 2 is selected.Elseif p_rb3 = X.Write: / radio button 3 is selected.Endif.

    Select-options:This statement is used to create two input fields so that we can enter a range of values. In addition to that we can enter,Multiple single values (1, 7, 15, 17, 33, 99, ..)Multiple ranges (1-10, 25-29, 66-100, .)Exclude single values (4 14 33 )

  • 8/13/2019 Sap Abap Ig Notes Part1

    86/152

    Exclude single values (4, 14, 33, ..)Exclude ranges (22-56, 67-98, .)All the above options are only visible when you click on multiple selection or extension box.Syntax:Select-options: for .Select-options: for no intervals. (only lower input field is displayed)Select-options: for no-extension. (extension box is not displayed)Select-options: for no intervals no-extension.ot : Whenever we use select-options with the select statement, we have to use INoperator instead =operator in the where condition.

    Ex: (on select-options)Tables kna1.Data: i_kna1 type table of kna1.Data: wa_kna1type kna1.

    Select-options: s_kunnr1 for kna1-kunnr.Select-options: s_kunnr2 for kna1-kunnr no intervals.Select-options: s_kunnr3 for kna1-kunnr no-extension.Select-options: s_kunnr4 for kna1-kunnr no intervals no-extension.Select *

    From kna1Into table i_kna1Where kunnr in s_kunnr1.Loop at i_kna1into wa_kna1.

    Write: / wa_kna1-kunnr, wa_kna1-name1.Endloop.Select-options internal table:Whenever we declare select-options an internal table will be created automatically in the back end The fields of the internal table are

  • 8/13/2019 Sap Abap Ig Notes Part1

    87/152

    Whenever we declare select-options, an internal table will be created automatically in the back end. The fields of the internal table are,SignOptionLowHigh ***Sign:Stores I(inclusive) or E(exclusive)Imeans only specified values will be selectedEmeans only specified values will be excludedOption:Stores the option like BT, NB, EQ, NE, LT, LE, GT and GE. By default BT is stored.Low:Stores lower value entered on selection screen.High:Stores higher value entered on selection screen.Selection screen commands:These are used to design the selection screen beautifully.Selection-screen uline:Displays horizontal line on selection screen.Selection-screen skip:Displays blank line on selection screen.Selection-screen begin of block with frame title . ..... Selection-screen end of block. (displays a block for selection

    screen elements)Selection-screen begin of line. selection-screen end of line. (displays selection Screen elements in a horizontal line)Selection-screen comments pos(width) . (displays a field label/text for selection screen element)Selection-screen texts:It is used to provide our own labels or data dictionary field labels or meaningful texts for the selection screen input fieldsGo to SE38 -> open any programCreate a parameter statement ex:- p_kunnr type kna1-kunnr -> now click on goto-> text elements -> selection texts

    Click on save and test the program

    Variants: Saving the selection screen data into an object for future references is called a variant Enter the data on selection screen fields Click on save

  • 8/13/2019 Sap Abap Ig Notes Part1

    88/152

    Click on save Provide the variant name and description as test1 Click on save, the variant will be created

    Ex on selection-screen commands:Selection-screen begin of block b1 with frame title text-001.Select-options: s_kunnr for kna1-kunnr.Selection-screen uline.Parameters: p_land1 type kna1-land1.Selection-screen skip.Parameters: p_matnr type mara-matnr.Selection-screen end of block b1.Selection-screen begin of block b2 with frame title text-002.

    Selection-screen begin of line.Selection-screen comment 2(15) text-003.Parameters: p_lifnr type lfa1-lifnr.Selection-screen comment 30(10) text-004.Parameters: p_land2 type lfa1-land1.

    Selection-screen end of line.Selection-screen end of block b2.

  • 8/13/2019 Sap Abap Ig Notes Part1

    89/152

    Chapter 06

    6. MODULARIZATION IN ABAPDividing the main program into sub-programs for better readability and reusability is called modularization technique

  • 8/13/2019 Sap Abap Ig Notes Part1

    90/152

    Modularization is implemented in the form of,Include programsFunction modulesSub-routinesClasses and methodsMacros (used in HR ABAP)

    Include ProgramsIt is a sub-program which contains set of reusable statementsIt does not contain any parameter interface, i.e. no importing and no exporting parametersThese sub-programs cant be executed independently

  • 8/13/2019 Sap Abap Ig Notes Part1

    91/152

    p g p y

    To execute the sub-programs we must insert them inside the main program for executionSyntax:

    Include zxyz.

    Double click and create

    Ex:Report zmoudlarization.Include z_modularization_top.(Tables kna1.

    Data: i_mara type table of mara.Data: wa_mara type mara.)

    Selection-screen begin of block b1 with frame title text-001.Select-options: s_kunnr for kna1-kunnr.

    Parameters: p_land1 type kna1-land1.Selection-screen end of block b1.Include zmodularization_getdata.(Select * from mara

    Into table i_maraWhere kunnr in s_kunnr and land1 = p_land1.)

    Include zmodularization_dispdata.(Loop at i_kna1 into wa_kna1.Write: / . .Endloop.)

    Function Modules:It is also a sub-program which contains set of reusable statements for reusability

    Function modules are mainly used for reusabilityEx:

    GUI_UPLOAD:upload data into internal table from flat fileGUI_DOWNLOAD:download data into internal tableSPELL_AMOUNT:converts amount into words

    KD_FILENAME_GET_ON_F4: provides browse option for searching a fileFunction module contain parameter interface, i.e. importing and exporting parametersFunction modules can be executed independentlyTh l b t d f th i

  • 8/13/2019 Sap Abap Ig Notes Part1

    92/152

    They can also be executed from the main programFunction Group:It is a container or group of function modulesFirst we have to create function group then we should create the function modulesSE80 or SE37 are T-codes for function groupComponents of Function Module:

    Importing:Input parameters (variables or work areas) are called as importing parametersExporting:Output parameters (variables or work areas) are called as exporting parametersChanging:Parameters (variables or work areas) which act as importing or exporting are called as changingTables:Internal tables (8kb size) which act as importing or exporting are called as tables parametersExceptions:These are used to catch certain types of the errors in the function moduleSource Code:It contains the original logic or set of reusable statements for a specific taskSteps to create function group:Go to SE80Select function group from the listProvide a function group nameZfg1_funcgroup -> enter

    Provide the descriptionClick on save and activate

    Or

    Go to SE37Click on goto -> function group -> create groupProvide function group name, descriptionSave and activate

    Steps to create a function module: Business requirement:Develop a reusable function module to display customer details.Step 1:Create a function module in SE37 as belowGo to SE37, Provide function module name zget_cust_detailsClick on create

  • 8/13/2019 Sap Abap Ig Notes Part1

    93/152

    Provide the function group name, descriptionClick on saveProvide the importing parameter as belowIm_kunnr typekna1-kunnrProvide the exporting parameter as belowEx_kna1typekna1Provide the exception as below

    No_kunnrno_kunnrWrite the below source codeIf im_kunnr is initial.Raise no_kunnr.Else.Select single * from kna1Into ex_kna1Where kunnr = im_kunnr.Endif.Save, activate and test itot :Whenever an exception is raise from function module, it is caught or stored in SY-SUBRC system variable. ***

    Step 2:Calling the function module in main programClick on patternbuttonProvide the function module name and press enterThe code will be automatically generatedModify the code as belowData: wa_kna1 type kna1.Parameters: p_kunnr type kna1-kunnr.Call function zget_cust_detailsExporting

    Im_kunnr = p_kunnrImporting

    Ex_kna1 = wa_kna1

    Exceptions No_kunnr = 1Invalid_kunnr = 2Others = 3.

  • 8/13/2019 Sap Abap Ig Notes Part1

    94/152

    If sy-subrc = 0.Write: / wa_kna1-kunnr, wa_kna1-land1, wa_kna1-name1.Elseif sy-subrc = 1.Message please enter customer numbertype E.Elseif sy-subrc = 2.Message please enter valid customer numbertype E.Endif.DEBUGGING:Single step (F5):This button is used for line by line execution in the debugging.Execute (F6):This button is used to execute a sub-program (function module or sub-routine) at a single click.Return (F7):This button is used to return from sub-program to main program.Run to (F8):This button is used to run to the next break point available. If the break point is not available it will execute the entire program.Watch point:A point to watch for a particular value in a program is called watch point.Ex:Loop at i_kna1 into wa_kna1.Write: / wa_kna1-kunnr, wa_kna1-land1, wa_kna1-name1.Endloop.Execute the program in the debuggingDouble click on wa_kna1-kunnrPut the cursor on wa_kna1-kunnr and click on watch pointProvide the relational operator as =and comparison value as 6666Press enter, a watch point is createdNow click on F8, watch point will be immediately reached

    Develop a FM to display vendor details(lfa1)Import: im_lifnr -> type -> lfa1-lifnrException: no_lifnr.

    Invalid_lifnr.Source code: if i_lifnr is initial.Raise no_lifnr.Else.

  • 8/13/2019 Sap Abap Ig Notes Part1

    95/152

    Select single * from lfa1 into ex_lfa1 where lifnr = im_lifnr.Endif.If sy-subrc 0.Message please enter valid numbertype E.Endif.(Calling function module in program)Data: wa_lfa1 type lfa1.Parameters: p_lifnr type lfa1-lifnr.Call function zget_vendor_detailsExporting

    Im_lifnr = p_lifnrImporting

    Ex_lfa1 = wa_lfa1Exceptions

    No_lifnr = 1Invalid_lifnr = 2Others = 3.

    If sy-subrc = 0.Write: / wa_lfa1-lifnr, wa_lfa1-land1.Elseif sy-subrc = 1.Message please enter valuetype E.Elseif sy-subrc = 2.Message

    please enter valid number

    type

    E

    .

    Endif.Develop a FM to display material details (mara)Import: im_matnr -> type -> mara-matnr.Export: ex_mara -> type -> mara.Exception: no_matnr.

    Invalid_matnr.Source code: if im_matnr is initial.Raise no_matnr.Else.Select single * from mara into ex_mara where matnr = im_matnr.

    Endif.If sy-subrc 0.M l lid i l b E

  • 8/13/2019 Sap Abap Ig Notes Part1

    96/152

    Message please enter valid material numbertype E.Endif.(Calling function module)Data: wa_mara type mara.Parameters: p_matnr type mara-matnr.Call function zget_material_detailsExporting

    Im_matnr = p_matnrImporting

    Ex_mara = wa_maraExceptions

    No_matnr = 1Invalid_matnr = 2Others = 3.

    If sy-subrc = 0.Write: / wa_mara-matnr, wa_mara-meins, wa_mara-mtart.Elseif sy-subrc = 1.Message please enter numbertype E.Elseif sy-subrc = 2.Message please enter valid material numbertype E.Endif.Ex Using tables, changing parameters: Business requirement:Develop a reusable function module to display list of the customers for a given

    country codeGo to SE37

    Provide the function module name zget_cust_listClick on create, provide function group, name and descriptionProvide the parameters as belowIm_land1 -> type -> kna1-land1.(Tables): i_kna1 -> like -> kna1.(Changing): v_name -> type -> kna1-name1.

    Write the below source codeSelect * from kna1 into table i_kna1 where land1 = im_land1.If v_name = ibm.V_name = international business machines.

  • 8/13/2019 Sap Abap Ig Notes Part1

    97/152

    Elseif v_name = tcs.V_name = tata consultancy services.Endif.Endfunction.Save, activate and test it

    Calling the function in main program:Parameters: p_land1 type kna1-land1.Data: i_kna1 type table of kna1.Data: wa_kna1 type kna1.

  • 8/13/2019 Sap Abap Ig Notes Part1

    98/152

    Data: v_name type kna1-name1.V_name = ibm.Call function zget_cust_listExporting

    Im_land1 = p_land1Tables

    I_kna1 = i_kna1Changing

    V_name = v_name.Write: / sy-uline.Write: / v_name color 5.Write: / sy-uline.Loop at i_kna1 into wa_kna1.Write: / wa_kna1-kunnr, wa_kna1-name1.Endloop.

    Develop a reusable function module to display sales order items for a given sales order (vbap, vbak)Develop two reusable function module to display delivery details, invoice details for given delivery number , invoice number

    SUB ROUTINESSub routines:It is also a sub program which contains reusable statementsSubroutines are mainly used for readability of a program

  • 8/13/2019 Sap Abap Ig Notes Part1

    99/152

    Sometimes they can also be used for reusabilitySubroutines contains parameters interface i.e. import, exporting parametersSubroutines cant be executed independentlyWe cant handle exceptions in subroutinesSubroutines are called as local modularization, whereas function modules are called as global modularizationSyntax:This syntax is of two stepsSubroutine definition or declaration:Perform using

    Changing Actual ParametersTables .

    Form using Changing Formal ParametersTables .

    ..Endform.Components of subroutine:

    Using:It acts as importing parametersChanging:It acts as exporting parametersTables:Itabs acts as importing and exporting parameters

    Types of subroutines:There are two types of subroutinesInternal subroutines or local subroutinesExternal subroutines

  • 8/13/2019 Sap Abap Ig Notes Part1

    100/152

    Local sub-routines:If sub routine definition and implementation are available in the same program, it is called as local sub routines.External sub-routines:If sub routine definition and implementation are available in separate programs then it is called as external sub routines.Passing values between sub-routine definition and implementation:There are 3 ways to pass the values,Pass by reference (same memory)Pass by value (separate memory)Pass by value and return (separate memory)Pass by reference:In this step, the actual and formal parameters will be referring to same memory. Suppose if the formal parameter is changed,

    actual parameters will also be changed, since they are referring to same memory.Pass by reference is identified by key word USING.

    Perform abcd using a.

    Form abcd using f_a.

    ..

    ..Endform.Pass by value:In this step the actual and formal parameters will be referring to separate memory. Suppose if the formal parameter is changed, the

    t l t ill t b h d i th f i t t

  • 8/13/2019 Sap Abap Ig Notes Part1

    101/152

    actual parameter will not be changed, since they are referring to separate memory.

    Perform abcd using a.

    Form abcd using value(f_a).

    ....f_a = f_a + 10.....Endform.Pass by value is identified by the key word USING VALUE().Pass by value and return:In this step actual and formal parameters will be referring to separate memory. Suppose if the formal parameter is

    changed the actual parameter is also changed when the sub routine implementation is executed completely. Pass by value and return is identified by the key word CHANGING VALUE().

    Perform abcd changing a.