You are on page 1of 56

TRANSACTION CODE: ------------------------------------------------------------SE11 --> ABAP DICTIONARY SE21 --> PACKAGE BUILDER SE35 --> MAINTAIN MODULES SE36

OR SLDB --> CREATE LOGICAL DATABASE. SE37 --> FUNCTION BUILDER (FUNC. MODULE) SE38 --> ABAP EDITOR SE41 --> MENU PAINTER SE51 --> SCREEN PAINTER SE71 --> FORM PAINTER REQUEST (SAP SCRIPT) SE72 --> STYLE MAINTANENCE SE78 --> SAP SCRIPT GRAPHIC MANAGEMENT SE80 --> OBJECT NAVIGATOR SE85 --> OBJECT NAVIGATOR SE91 --> MESSSAGE MAINTANENCE SM35 --> SESSION OVERVIEW SO10 --> CREATE STANDARD TEXT MODULE SHDB --> TRANSACTION RECORDER (RECORDING OVERVIEW) LSMW --> LEGACY SYSTEM MIGRATION WORKBENCH MM01 --> MATERIAL MASTER CREATION. MM02 --> MATERIAL MASTER CHANGE MM03 --> MATERIAL MASTER DISPLAY XK01 --> VENDOR CREATION MARA - General Material Data. MARC - Plant Data for material. MAKT - Material Descriptions KNA1 - General Data in Customer Master KNB1 - Customer Master (Company Code) KNC1 - Customer Master (Transaction Figures) T001 - Company codes LFA1 - Vendor Master (General Section). LFB1 - Vendor Master (Company Code). LFC1 - Vendor MAster (Transaction Figures).

SUBROUTINES: -----------* It is one of the modularization technique in ABAP. * It is used to hold a piece of code that can be invoked either internally or externally. * Reduces code redundancy. syntax: -----FORM <sub_name>. ..attributes.. ENDFORM. To invoke the subroutine created, use PERFORM statement. SYNTAX: -----PERFORM <sub_name>. INVOKING SUBROUTINE INTERNALLY: ------------------------------Eg. code; --------REPORT Z_SUBROUTINES. PERFORM SUB. FORM SUB. DO 5 TIMES. WRITE :/ 'HELLO'. ENDDO. ENDFORM. INVOKING SUBROUTINE EXTERNALLY: ------------------------------Specify program name where the subroutine is created as follows: REPORT Z_SUBROUTINE_INVOKE. PERFORM SUB(Z_SUBROUTINES).

PARAMETER PASSING TECHNIQUES IN SUBROUTINE: ------------------------------------------PASS BY VALUE PASS BY REFERENCE 'USING' statement should be used along with the FORM and PERFORM statements to pass arguments to the subroutine. PASS BY REFERENCE: -----------------DATA: A TYPE I VALUE 100, B(10) VALUE 'CHENNAI'. PERFORM SUB USING A B. FORM SUB USING X Y. WRITE :/ X, Y. ENDFORM. PASS BY VALUE: -------------DATA: A TYPE I VALUE 100, B(10) VALUE 'CHENNAI'. PERFORM SUB USING A B. WRITE :/ A, B. FORM SUB USING VALUE(X) VALUE(Y). X = '1000'. Y = 'BANGALORE'. WRITE :/ X, Y. ENDFORM. 'VALUE' keyword should be used whenever we try to use PASS BY VALUE technique for the subroutine. USING CHANGING STATEMENT IN SUBROUTINE: -------------------------------------DATA : A TYPE I VALUE 10, B TYPE I VALUE 20, C TYPE I. PERFORM SUB USING A B CHANGING C.

FORM SUB USING X Y CHANGING Z. Z = X + Y. WRITE Z. ENDFORM. PASSING INTERNAL TABLE AS AN ARGUMENT TO SUBROUTINES: ----------------------------------------------------Eg. code: --------DATA ITAB LIKE KNA1 OCCURS 0 WITH HEADER LINE. SELECT * FROM KNA1 INTO TABLE ITAB. PERFORM DISPLAY TABLES ITAB. FORM DISPLAY TABLES ITAB STRUCTURE KNA1. LOOP AT ITAB. WRITE :/ ITAB-KUNNR, ITAB-NAME1, ITAB-LAND1, ITAB-ORT01. ENDLOOP. ENDFORM. Whenever internal table is passed as an argument, use 'TABLES' statement instead of 'USING'. The keyword 'STRUCTURE' in the FORM statement is used to refer to the database table structure for the internal table in FORM-ENDFORM statement. DISADVANTAGES OF SUBROUTINE: --------------------------1. Subroutine cannot be called from different clients. 2. There are no predefined subroutines in SAP. FUNCTION MODULES: ----------------* It is also a modularization technique. * Function modules can be called from different clients. * Using Function modules, we can also handle exceptions. A user-defined function module is saved under a container called as FUNCTION GROUP. Navigations to create a FUNCTION GROUP: --------------------------------------SE80 -> Select Function Group from the listbox -> Specify Function Group name starting with Z or Y -> Press Enter -> Click

on Yes to create object -> Opens an interface -> Enter short description -> Save under a package and Assign Request Number -> A Function Group is created. Navigations to Create a FUNCTION MODULE: ---------------------------------------SE37 -> Opens Function Builder Screen -> Specify FM name starting with Z or Y -> Click on Create -> Opens an interface -> Specify Function Group created earlier -> Enter short description -> Save -> Opens Function Module interface containing following components: 1. ATTRIBUTES - This is used to store general information about the Function group and function module. It also specifies the type of function module. 2. IMPORT - This component is used to receive arguments from the calling program. 3. EXPORT - This component is used to pass the return value to the calling program. 4. TABLES 5. CHANGING 6. EXCEPTIONS 7. SOURCE CODE-This component is a source code editor for the function module.Programmer will create source code in this area. TYPES OF FUNCTION MODULE: ------------------------1. NORMAL FUNCTION MODULE - Function module of this type can be called only from within the same client. 2. REMOTE-ENABLED FUNCTION MODULE - This FM can be called from different client as well as from the same client. USING IMPORT AND EXPORT TAB BUTTONS: -----------------------------------Create a FM -> In the IMPORT tab button, specify following: A TYPE I B TYPE I -> In the EXPORT tab button, specify following: C TYPE I -> Click on SOURCE CODE tab button -> Specify following code: C = A + B.

-> Save -> Activate. To invoke the FM from the executable program, use PATTERN pushbutton or CTRL+F6 shortcut key and specify following code: DATA: X TYPE I VALUE 10, Y TYPE I VALUE 20, Z TYPE I. CALL FUNCTION 'Z_TRAINING_FM' EXPORTING A = X B = Y IMPORTING C = Z. WRITE Z. CHANGING tab button can be used to return a value to the calling program. We can also pass string variables to the CHANGING parameter tab button. eg. code: --------In CHANGING tab button, specify following parameter: STR TYPE C. In SOURCE CODE, specify following string operation: TRANSLATE STR TO UPPER CASE. In the calling program, specify following: DATA B(10) VALUE 'chennai'. CALL FUNCTION 'Z_TRAINING_FM' CHANGING STR = B. WRITE B. PASSING INTERNAL TABLE AS AN ARGUMENT TO FUNCTION MODULE: ---------------------------------------------------------

TABLES tab button is used to specify INTERNAL TABLES as an argument for the Function module. In TABLES tab button, specify an internal table as follows: ITAB LIKE KNA1. In SOURCE CODE, specify the following: LOOP AT ITAB. WRITE :/ ITAB-KUNNR, ITAB-NAME1, ITAB-ORT01, ITAB-LAND1. ENDLOOP. In the invoking program, specify following code: DATA KTAB LIKE KNA1 OCCURS 0 WITH HEADER LINE. SELECT * FROM KNA1 INTO TABLE KTAB. CALL FUNCTION 'Z_TRAINING_FM' TABLES ITAB = KTAB. -> Save -> Activate -> Execute. HANDLING EXCEPTIONS USING FUNCTION MODULES: ------------------------------------------Using EXCEPTIONS tab button, we can create our own exceptions. For each exception we create, a SY-SUBRC value like 1,2,3,5,6. .. is generated and assigned by the system. RAISE statement is used to invoke the exceptions based on condition we specify. In the EXCEPTIONS tab button, specify following: ITAB_LESS_SIZE ITAB_MORE_SIZE In SOURCE CODE tab button, specify following: IF SY-TFILL < 100. RAISE ITAB_LESS_SIZE. ELSEIF SY-TFILL > 100. RAISE ITAB_MORE_SIZE. ENDIF.

-> Save -> ACtivate FM. In SE38 program, specify the following: DATA ITAB LIKE KNA1 OCCURS 0 WITH HEADER LINE. SELECT * FROM KNA1 INTO TABLE ITAB UP TO 100 ROWS. DESCRIBE TABLE ITAB. CALL FUNCTION 'Z_TRAINING_FM' EXCEPTIONS ITAB_LESS_SIZE =1 ITAB_MORE_SIZE =2 OTHERS = 3. IF SY-SUBRC = 1. WRITE :/ 'INTERNAL TABLE HAS LESS THAN 100 RECORDS'. ELSEIF SY-SUBRC = 2. WRITE :/ 'INTERNAL TABLE HAS MORE THAN 100 RECORDS'. ELSE. WRITE :/ 'CORRECT NUMBER OF RECORDS'. ENDIF.

VARIANTS: --------This component is used to hold the repetitive values that are needed to be inserted into the input fields in GUI Screen. This component is useful for the end users. eg. code: -------PARAMETERS : A(10), B(10), C(10), D(10), E(10). SELECTION-SCREEN PUSHBUTTON /10(10) LB1 USER-COMMAND PB1. SELECTION-SCREEN PUSHBUTTON 60(10) LB2 USER-COMMAND PB2. SELECTION-SCREEN PUSHBUTTON 40(10) LB3 USER-COMMAND PB3. INITIALIZATION. LB1 = 'PRINT'. LB2 = 'EXIT'. LB3 = 'CLEAR'.

AT SELECTION-SCREEN. CASE SY-UCOMM. WHEN 'PB1'. LEAVE TO LIST-PROCESSING. WRITE :/ A, B, C, D, E. WHEN 'PB2'. LEAVE PROGRAM. WHEN 'PB3'. A = ' '. B = ' '. C = ' '. D = ' '. E = ' '. ENDCASE. DATA DICTIONARY OBJECTS: ----------------------1. TABLES 2. VIEWS 3. DATA TYPES 4. DOMAINS 5. SEARCH HELP 6. TYPE GROUPS 7. LOCK OBJECTS TABLES: -------------PREDEFINED TABLES - 36675 TABLES. MARA - General Material Data. MARC - Plant Data for material. MAKT - Material Descriptions KNA1 - General Data in Customer Master KNB1 - Customer Master (Company Code) KNC1 - Customer Master (Transaction Figures) T001 - Company codes LFA1 - Vendor Master (General Section). LFB1 - Vendor Master (Company Code). LFC1 - Vendor MAster (Transaction Figures). Eg. code to fetch records from MARA table into LPS:

--------------------------------------------------------------------TABLES MARA. WRITE :/40(50) 'GENERAL MATERIAL DATA' COLOR 7 CENTERED. SKIP 2. WRITE :/ 'MATERIAL NUMBER', 'MATERIAL TYPE', 'INDUSTRY SECTOR', 'UNITS'. SKIP 1. SELECT * FROM MARA. WRITE :/ MARA-MATNR COLOR 3 , MARA-MTART COLOR 4, MARA-MBRSH COLOR 5 , MARA-MEINS COLOR 6. ENDSELECT. USING SELECT-OPTIONS STATEMENT: --------------------------------------------------------This statement is used to create a range for selection of table records. syntax: ---------SELECT-OPTIONS <variable> FOR <table_name>-<field_name>. eg. code: -----------TABLES KNA1. SELECT-OPTIONS CUSNUM FOR KNA1-KUNNR. SELECT * FROM KNA1 WHERE KUNNR IN CUSNUM. WRITE :/ KNA1-KUNNR, KNA1-NAME1, KNA1-ORT01, KNA1-LAND1. ENDSELECT. TABLES CLASSIFICATION BASED ON CLIENT: -------------------------------------------------------------------1. CLIENT-DEPENDENT TABLE - Table defined for one particular client cannot be accessed from cross clients. In these type of tables, the first field is MANDT which holds the client number (eg. 800). 2. CLIENT-INDEPENDENT TABLE - These type of tables can be accessed from any different clients. The first field is not MANDT for these type of tables. CREATING A USER-DEFINED TABLE IN SAP: ---------------------------------------------------------------In SAP, we can create a table in two types:

1. Built-in Type - The user has to specify the data type and length for each field of the table. 2. Using Data Element - The data type and length for fields is created once and implemented whenever necessary. COMPONENTS OF TABLE: -------------------------------------1. DELIVERY CLASS - Specifies what kind of data the table we create is going to hold. 2. MAINTENANCE -Specifies what screens should be made available to the user after the table is created & activated. 3. FIELDS - This section is used to create fields of the table. 4. TECHNICAL SETTINGS - DATA CLASS - Specifies the storage location of the table in database. - SIZE CATEGORY - Specifies initial size of the table in the form of number of records. Navigations to create table: ----------------------------------SE11 -> Select Database table radiobutton -> Specify table name starting with Z or Y -> Click on Create -> Opens an interface -> Enter short description -> Specify A (Application table) for DELIVERY CLASS -> Specify Display/Maintenance Allowed -> Click on Fields Tab button -> Specify Field names -> Select the first field as Primary key with Initial values -> Specify Data type and length for each field -> Click on Technical Settings pushbutton from Appn. Toolbar -> Save before leaving tool -> Save under a package -> Assign request number -> Opens an interface -> Specify Data Class as APPL0 -> Specify Initial Size Category as 0 -> Save -> Come back -> ACtivate the table. To create Entries -> Click on Utilities Menu -> Table Contents -> Create Entries -> Opens an interface with fields created -> Specify records -> SAve -> Come back. To Display Entries -> Select Display from the above menu path -> Opens an interface -> Execute. Eg. code to insert records into table using selection-screen: -------------------------------------------------------------------------TABLES YMY_TABLE. PARAMETERS : X LIKE YMY_TABLE-STUDID, Y LIKE YMY_TABLE-STUDNAME,

Z LIKE YMY_TABLE-COURSE. SELECTION-SCREEN PUSHBUTTON /10(10) LB1 USER-COMMAND PB1. SELECTION-SCREEN PUSHBUTTON 40(10) LB2 USER-COMMAND PB2. INITIALIZATION. LB1 = 'INSERT'. LB2 = 'EXIT'. AT SELECTION-SCREEN. CASE SY-UCOMM. WHEN 'PB1'. YMY_TABLE-STUDID = X. YMY_TABLE-STUDNAME = Y. YMY_TABLE-COURSE = Z. INSERT YMY_TABLE. IF SY-SUBRC = 0. MESSAGE S000(Z_MY_MESSAGE). ELSEIF SY-SUBRC = 4. MESSAGE E001(Z_MY_MESSAGE). ENDIF. WHEN 'PB2'. LEAVE PROGRAM. ENDCASE. In the above code, SY-SUBRC is the system variable used to handle exceptions. By default, 0 and 4 are values assigned to the system variable, where 0 specifies the specified action is successful. 4 specifies the specified action is failed. TABLES CLASSIFICATION BASED ON BUFFERING: -------------------------------------------------------------------------1. SINGLE-RECORD BUFFERING - If a table is created with this buffer type and whenever the user tries to access table records, a buffer area will be created in AS to hold only one record. 2. GENERIC BUFFERING - With this type, by default a buffer will be created to hold a single record. Depending upon the selection criteria, the

buffer size is increased or decreased dynamically. 3. FULLY BUFFERED - With this type, a buffer is created to hold all the records existing in the table. CREATING A TABLE USING DATA ELEMENTS: -------------------------------------------------------------------NAVIGATIONS TO CREATE A DOMAIN: ----------------------------------------------------------SE11 -> Select Domain radiobutton -> Specify domain name starting with Z or Y -> Click on create -> Opens an interface -> Enter short description -> Specify technical attributes (data type and length) for the field -> Save -> Activate -> Come back. NAVIGATIONS TO CREATE A DATA ELEMENT: -------------------------------------------------------------------SE11 -> Select Data Type radiobutton -> Specify name -> Click on create -> Opens an interface -> Select Data Element radiobutton -> Continue -> Opens another interface -> Enter short description -> Specify domain name created earlier -> Press enter -> Technical attributes are automatically called from the domain -> Save -> Activate -> Come back. Create a table -> Specify Delivery class, Display/Maintenance Allowed -> Specify Field names -> Specify Data Element name for each field -> Press Enter -> Specify Technical settings -> Save -> Activate -> Create Entries. PROVIDING F4 FUNCTIONALITY FOR THE INPUT FIELDS IN GUI: ---------------------------------------------------------------------------------------------SE11 -> Select Search Help radiobutton -> Specify name -> Click on Create -> Select Elementary Search Help -> Continue -> Opens interface -> Enter short description -> In SELECTION METHODS, specify table name -> In SEARCH HELP PARAMETERS, specify field names -> Check IMPORT and EXPORT checkboxes -> Specify values for LPOS and SPOS as 1 and 1 -> Save -> Activate. Use MATCHCODE OBJECT <Search_help> in PARAMETERS statement as follows: eg. PARAMETERS A(10) MATCHCODE OBJECT Z_MY_SEARCH.

LPOS and SPOS parameters are used to specify the positions of fields in the search help screen for the input field. VIEWS: ----------To fetch records from more than one database table, database view is used. NAVIGATIONS: ----------------------SE11 -> Select View Radiobutton -> Specify name -> Create -> Select Database View -> Continue -> Opens interface -> Enter short description -> Specify table names in TABLES area -> Click on Relationships pushbutton -> Opens an interface -> Select relationship based on primary key values (not based on MANDT field) -> A join condition is automatically generated -> To choose fields from different tables, click VIEW FIELDS tab button -> Click TABLE FIELDS pushbutton -> Select first table -> Click on Choose -> Select required fields -> Repeat same for other tables -> Save -> Activate -> Say NO to warning message. In SE38 editor, use the following code to access records using View: TABLES Y_MYVIEW. SELECT * FROM Y_MYVIEW. WRITE :/ Y_MYVIEW-MATNR, Y_MYVIEW-MTART, Y_MYVIEW-MBRSH, Y_MYVIEW-MEINS, Y_MYVIEW-WERKS, Y_MYVIEW-LVORM. ENDSELECT. Save -> Activate. INCLUDE PROGRAMS: ----------------These are Type I programs in SAP. These programs are not directly executable. This is used to contain certain lines of code, which can be reused in executable program whenever necessary.Include programs reduces code redundancy. In the Program Attributes screen, specify the program type as Include Program for creating TYPE I PROGRAMS. SYNTAX: -----INCLUDE <program_name>.

SUBMIT STATEMENT: ---------------This statement is used to invoke the output of another program. syntax: ------SUBMIT <program_name>. STRUCTURES: ---------SYNTAX: -----DATA : BEGIN OF <structure_name>, ..attributes.. END OF <structure_name>. EG. code to create structure in SE38 EDITOR using DATA statement: ----------------------------------------------------------------DATA : BEGIN OF STRUC_NAME, NAME(10), COURSE(10), END OF STRUC_NAME. STRUC_NAME-NAME = 'KARTHIK'. STRUC_NAME-COURSE = 'ABAP'. STRUC_NAME-NAME = 'XYZ'. STRUC_NAME-COURSE = 'ABAP'. STRUC_NAME-NAME = 'ABC'. STRUC_NAME-COURSE = 'SQL'. WRITE :/ STRUC_NAME-NAME, STRUC_NAME-COURSE. When this program is executed, it prints out only the latest record inserted. A structure can hold only a single record. To Make a structure hold multiple records, declare the structure as an internal table. INTERNAL TABLES: ---------------Internal table is a temporary work space area created by the user explicitly in the AS.

ADVANTAGES OF INTERNAL TABLES: -----------------------------1. It is used to hold database table records. 2. To make modifications or insertions to the database table records, internal tables are used. 3. It increases the system performance in accessing the underlying database. COMPONENTS OF INTERNAL TABLE: ----------------------------1. HEADER AREA. 2. BODY AREA. Internal table body area is used to hold records fetched from the database table. All the insertion and retrieval of datas from the internal table are done through header area which is called as HEADER LINE. TYPES OF INTERNAL TABLES: ------------------------1. INDEXED INTERNAL TABLE - STRUCTURED INTERNAL TABLE - STANDARD INTERNAL TABLE - SORTED INTERNAL TABLE 2. NON-INDEXED INTERNAL TABLE - HASHED INTERNAL TABLE Eg. code for structured internal table: --------------------------------------DATA : BEGIN OF STRUC_NAME OCCURS 0, NAME(10), COURSE(10), END OF STRUC_NAME. STRUC_NAME-NAME = 'KARTHIK'. STRUC_NAME-COURSE = 'ABAP'. APPEND STRUC_NAME. STRUC_NAME-NAME = 'XYZ'. STRUC_NAME-COURSE = 'ABAP'. APPEND STRUC_NAME.

STRUC_NAME-NAME = 'ABC'. STRUC_NAME-COURSE = 'SQL'. APPEND STRUC_NAME. LOOP AT STRUC_NAME. WRITE :/ STRUC_NAME-NAME, STRUC_NAME-COURSE. ENDLOOP. In the above code, OCCURS 0 statement is used to declare a structure as an internal table. Using this option, 8 KB size of memory is allocated for internal table body area in the AS dynamically. APPEND statement is used to insert records into the internal table body area. COLLECT statement is also used to insert records into body area, but it will check for the data we insert into internal table. If it already exists, it avoids data duplication inside the internal table body area. CREATING AN INTERNAL TABLE LIKE DATABASE TABLE STRUCTURE: --------------------------------------------------------SYNTAX: ------DATA <internal_table> LIKE <dbtable_name> OCCURS 0 WITH HEADER LINE. EG. CODE: --------TABLES MARA. DATA IT_MARA LIKE MARA OCCURS 0 WITH HEADER LINE. SELECT-OPTIONS MATNUM FOR MARA-MATNR. SELECT * FROM MARA INTO TABLE IT_MARA WHERE MATNR IN MATNUM. LOOP AT IT_MARA. WRITE :/ IT_MARA-MATNR, IT_MARA-MTART, IT_MARA-MBRSH, IT_MARAMEINS. ENDLOOP. Eg. code to fetch records from KNA1 and SORT THE INTERNAL TABLE: ---------------------------------------------------------------DATA IT_KNA1 LIKE KNA1 OCCURS 0 WITH HEADER LINE. SELECT * FROM KNA1 INTO TABLE IT_KNA1.

SORT IT_KNA1 BY ORT01 DESCENDING. LOOP AT IT_KNA1. WRITE :/ SY-TABIX COLOR 3, IT_KNA1-KUNNR, IT_KNA1-NAME1, IT_KNA1ORT01, IT_KNA1-LAND1. ENDLOOP. SORT statement is used to sort the internal table records based on the specified field. syntax: -----SORT <internal_table> BY <field_name> <ASCENDING/DESCENDING>. DESCRIBE statement is used to provide information about the internal table. Syntax: -----DESCRIBE TABLE <internal_table>. SY-TFILL system variable is used to return number of records existing in the internal table body area. SY-DBCNT system variable is used to return number of records processed from the specified database table. SY-TOCCU system variable is used to return the size of internal table created. eg. code: --------DATA IT_KNA1 LIKE KNA1 OCCURS 0 WITH HEADER LINE. SELECT * FROM KNA1 INTO TABLE IT_KNA1. WRITE :/ 'TOTAL NUMBER OF RECORDS PROCESSED FROM THE DATABASE TABLE IS' COLOR 5, SY-DBCNT COLOR 6. DESCRIBE TABLE IT_KNA1. WRITE :/ 'TOTAL NUMBER OF RECORDS IN INTERNAL TABLE IS' COLOR 5, SY-TFILL COLOR 4, SY-TOCCU COLOR 7. SKIP 2. SORT IT_KNA1 BY ORT01 DESCENDING.

LOOP AT IT_KNA1. WRITE :/ SY-TABIX COLOR 3, IT_KNA1-KUNNR, IT_KNA1-NAME1, IT_KNA1ORT01, IT_KNA1-LAND1. ENDLOOP. READ TABLE IT_KNA1 INDEX 356. SKIP 3 . WRITE :/ SY-TABIX COLOR 3, IT_KNA1-KUNNR, IT_KNA1-NAME1, IT_KNA1ORT01, IT_KNA1-LAND1. In the above code, READ TABLE statement is used to view a single record from the internal table based on the index value specified. syntax: ------READ TABLE <internal_table> INDEX <index>. Internal table uses BINARY SEARCH technique to fetch a single record using READ statement. STRUCTURED INTERNAL TABLE: -------------------------Any internal table created using BEGIN OF-END OF statements is called as STRUCTURED INTERNAL TABLE. STANDARD INTERNAL TABLE: -----------------------The internal table of this type performs linear searching technique to fetch a single record specified from the body area. SYNTAX: ------DATA <internal_table> LIKE STANDARD TABLE OF <dbtable_name> WITH NON-UNIQUE KEY <field_name> WITH HEADER LINE INITIAL SIZE <size>. Eg. code: --------DATA IT_KNA1 LIKE STANDARD TABLE OF KNA1 WITH NON-UNIQUE KEY ORT01 WITH HEADER LINE INITIAL SIZE 0.

SELECT * FROM KNA1 INTO TABLE IT_KNA1. LOOP AT IT_KNA1. WRITE :/ IT_KNA1-KUNNR, IT_KNA1-NAME1, IT_KNA1-ORT01, IT_KNA1LAND1. ENDLOOP. SORTED INTERNAL TABLE: ---------------------The internal table of this type, when declared, fetches and inserts database table records in a sorted manner itself. SYNTAX: ------DATA <internal_table> LIKE SORTED TABLE OF <dbtable_name> WITH NON-UNIQUE KEY <field_name> WITH HEADER LINE INITIAL SIZE <size>. Eg. code: -------DATA IT_KNA1 LIKE SORTED TABLE OF KNA1 WITH NON-UNIQUE KEY KUNNR WITH HEADER LINE INITIAL SIZE 0. SELECT * FROM KNA1 INTO TABLE IT_KNA1. LOOP AT IT_KNA1. WRITE :/ IT_KNA1-KUNNR, IT_KNA1-NAME1, IT_KNA1-ORT01, IT_KNA1LAND1. ENDLOOP. We cannot apply sorting technique for the SORTED kind of internal table. HASHED INTERNAL TABLE: ---------------------Syntax: ------DATA <internal_table> LIKE HASHED TABLE OF <dbtable_name> WITH UNIQUE KEY <field_name> WITH HEADER LINE INITIAL SIZE <size>. Eg. code:

--------DATA IT_KNA1 LIKE HASHED TABLE OF KNA1 WITH UNIQUE KEY KUNNR WITH HEADER LINE INITIAL SIZE 0. SELECT * FROM KNA1 INTO TABLE IT_KNA1. LOOP AT IT_KNA1. WRITE :/ IT_KNA1-KUNNR, IT_KNA1-NAME1, IT_KNA1-ORT01, IT_KNA1LAND1. ENDLOOP. INSERTING USER-DEFINED RECORDS INTO DATABASE TABLE USING INTERNAL TABLE: ----------------------------------------------------------------DATA IT_KNA1 LIKE KNA1 OCCURS 0 WITH HEADER LINE. IT_KNA1-KUNNR = 'TRAINING01'. IT_KNA1-NAME1 = 'KARTHIK'. IT_KNA1-ORT01 = 'CHENNAI'. IT_KNA1-LAND1 = 'IN'. APPEND IT_KNA1. IT_KNA1-KUNNR = 'TRAINING02'. IT_KNA1-NAME1 = 'LAKSHMAN'. IT_KNA1-ORT01 = 'BANGALORE'. IT_KNA1-LAND1 = 'IN'. APPEND IT_KNA1. IT_KNA1-KUNNR = 'TRAINING03'. IT_KNA1-NAME1 = 'RAM'. IT_KNA1-ORT01 = 'CHENNAI'. IT_KNA1-LAND1 = 'IN'. APPEND IT_KNA1. LOOP AT IT_KNA1. INSERT INTO KNA1 VALUES IT_KNA1. IF SY-SUBRC = 0. WRITE :/ 'RECORDS ARE INSERTED'. ELSE. WRITE :/ 'RECORDS ALREADY EXISTS'. ENDIF.

ENDLOOP. CREATING INTERNAL TABLE FOR SPECIFIC TABLE FIELDS: ------------------------------------------------Eg. code: --------DATA : BEGIN OF IT_KNA1 OCCURS 0, KUNNR LIKE KNA1-KUNNR, NAME1 LIKE KNA1-NAME1, ORT01 LIKE KNA1-ORT01, END OF IT_KNA1. IT_KNA1-KUNNR = 'TRAINING04'. IT_KNA1-NAME1 = 'KARTHIK'. IT_KNA1-ORT01 = 'CHENNAI'. APPEND IT_KNA1. IT_KNA1-KUNNR = 'TRAINING05'. IT_KNA1-NAME1 = 'LAKSHMAN'. IT_KNA1-ORT01 = 'BANGALORE'. APPEND IT_KNA1. IT_KNA1-KUNNR = 'TRAINING06'. IT_KNA1-NAME1 = 'RAM'. IT_KNA1-ORT01 = 'CHENNAI'. APPEND IT_KNA1. LOOP AT IT_KNA1. WRITE :/ IT_KNA1-KUNNR, IT_KNA1-NAME1, IT_KNA1-ORT01. ENDLOOP. TABLE RELATIONSHIP: ------------------CREATING A FOREIGN KEY RELATIONSHIP: ----------------------------------create a check table -> Create fields with data elements and domains -> SAve under a package -> ACtivate. Create a value table -> Specify fields with data elements and domains -> Save under a package -> Select a field for which a foreign key relationship should be specified -> Click on Foreign KEys pushbutton -> Opens an interface -> Enter short description -> Specify name of the check table -> Click

on Generate Proposal pushbutton -> A foreign key relationship is automatically generated -> Click on Copy -> Activate the table -> Create Entries. If a check table is specified for a particular field in the value table using foreign key relationship, make sure both the fields in check table and value table has same domain and data element. MENU PAINTER: ------------This tool is used to create user-defined menu bar, menu items, submenu items, pushbuttons in application toolbar (function keys) and function texts. SE41 is the Tcode to create user-defined menu items in the MENU PAINTER. NAVIGATIONS TO CREATE USER-DEFINED MENUS USING MENU PAINTER: ----------------------------------------------------------SE41 -> Opens Menu Painter -> Specify Program Name -> Specify Menu Painter Name in STATUS field -> Click on Create -> Opens an interface -> Enter short description -> Continue -> Opens Menu Painter interface -> Expand Menu Bar option -> Specify Menu name to be printed in the Menu Bar -> Double click on the name -> Opens 15 fields with CODE and TEXT to specify Menu Item name and Display Value. CODE -> Name of the Menu Item (Used to specify event functionality) TEXT -> Display Text To Create submenu item, just specify TEXT VALUE -> Double click -> Specify submenu item CODE and TEXT. -> Save the menu painter -> Activate. To implement user-defined menus created using MENU PAINTER, use PF-STATUS statement in SE38 as follows: SET PF-STATUS '<menupainter_name>'. AT USER-COMMAND event is used to specify event functionality for the menu items. Eg. code: --------WRITE :/ 'SELECT ONE FROM THE MENU BAR'.

SET PF-STATUS 'MYMENU'. *Double click on Status to access menu painter directly from SE38 AT USER-COMMAND. CASE SY-UCOMM. WHEN 'MENUITEM1'. MESSAGE S000(Z_MSG). WHEN 'MENUITEM2'. MESSAGE W001(Z_MSG). WHEN 'MENUITEM3'. LEAVE PROGRAM. WHEN 'SUBMENU1'. CALL TRANSACTION 'SE38'. WHEN 'SUBMENU2'. CALL TRANSACTION 'SE80'. WHEN 'PACKAGE'. CALL TRANSACTION 'SE21'. ENDCASE.

MODULE POOL PROGRAMMING (MPP): -------------------------------* These are type M programs in SAP. * These programs cannot be executed directly. * Transaction Codes (Tcodes) are used to execute MPP programs. * Graphical Screen PAinter is the tool used to create GUI in MPP (SE51). * MPP programs are created using the transaction code SE80. * MPP programs should start with the naming convention SAPMZ or SAPMY. EVENTS ASSOCIATED WITH SELECTION-SCREEN: ---------------------------------------INITIALIZATION AT SELECTION-SCREEN START-OF-SELECTION TOP-OF-PAGE

END-OF-PAGE END-OF-SELECTION. EVENTS ASSOCIATED WITH MPP: --------------------------1. PROCESS BEFORE OUTPUT (PBO) - Used to specify initial attributes for the screen. 2. PROCESS AFTER INPUT (PAI) - Used to specify event functionalities for the components of the screen. COMPONENTS OF MPP PROGRAM: -------------------------1. ATTRIBUTES - It holds description about the screen. 2. FLOW LOGIC - This is an editor for MPP programs to specify event functionality for the screen components. 3. ELEMENT LIST - This provides description about the components created in the screen. TYPES OF SCREEN IN MPP: ----------------------1. NORMAL SCREEN - A screen which has maximizing, minimizing and closing options is referred to as normal screen. 2. SUBSCREEN - A screen within a normal screen with either of above three options is referred to as subscreen. 3. MODAL DIALOG BOX - A screen with only closing option which is used to provide information to the end user is referred to as modal dialog box. NAVIGATIONS TO CREATE A SIMPLE MPP PROGRAM: ------------------------------------------SE80 -> Select Program from the dropdown list -> SPecify program name starting with SAPMZ or SAPMY (eg. SAPMYFIRSTMPP) -> Press Enter -> Click on Yes to Create object -> Opens another dialog box -> Click on Continue to create Top Include File for the program -> Opens another dialog box specifying TOP INCLUDE FILE name (MYFIRSTMPPTOP) -> Click on Continue -> Opens Program Attributes screen -> Enter short description -> The default program type is M -> Save under a package -> Assign Request number -> A folder with specified program name(SAPMYFIRSTMPP) is created with Top Include File.

To create a screen, right click on program name -> Create -> SCreen -> Opens dialog box -> Specify Screen number (100) -> Continue -> Opens an interface -> Enter short description -> Select Screen type as Normal -> Click on LAYOUT pushbutton from appn. toolbar -> Opens Graphical Screen painter -> Drag and drop two input fields, two pushbuttons and two text fields -> Double click on each component to specify attributes as follows: INPUT FIELDS: IO1, IO2 FIRST PUSHBUTTON : PB1, PRINT, PRINT SECOND PUSHBUTTON : PB2, EXIT, EXIT TEXT FIELDS : LB1 (ENTER NAME), LB2 (ENTER CITY) -> Save -> Click on Flowlogic Pushbutton from appn. toolbar -> Opens Flow Logic editor with two events (PAI and PBO). To specify event functionalities for screen components, decomment PAI Module name (USER_COMMAND_0100) -> Double click on module name -> Click on Yes to create object -> Opens an interface -> Select Program name from the list -> Continue -> Click on Yes to save the editor -> Opens PAI module and specify following code: CASE SY-UCOMM. WHEN 'PRINT'. LEAVE TO LIST-PROCESSING. WRITE :/ IO1, IO2. WHEN 'EXIT'. LEAVE PROGRAM. ENDCASE. In TOP INCLUDE FILE, declare input fields as follows: DATA : IO1(20), IO2(20). Save -> Activate -> Right click on Program name -> Activate (to activate all inactive objects). To execute MPP program, right click on program name -> Create -> Transaction -> Opens an interface -> Specify Tcode starting with Z or Y (zfirstmpp) -> Enter short description -> Continue -> Specify Main program name (SAPMYFIRSTMPP) and initial Screen number (100) -> Save under a package -> Assign a request number -> Execute.

TOP INCLUDE FILE is an area to declare variables for the program, and the variables declared here becomes globally accessed. SCREEN VALIDATION USING MPP: ---------------------------SCREEN is a predefined structure used to make MPP screen validations dynamically. SCREEN has following components: GROUP1 INVISIBLE REQUIRED INPUT OUTPUT INTENSIFIED IF SCREEN-INVISIBLE = 0 - Sets the input field values as visible. SCREEN-INVISIBLE = 1 - Sets the input field as password field. SCREEN-REQUIRED = 0 - Not a mandatory field. SCREEN-REQUIRED = 1 - Sets input field as mandatory one. Eg. code to perform validation dynamically for a login screen: ------------------------------------------------------------1. Create an MPP program. 2. Create a Normal Screen like initial login screen. 3. Assign IO1, IO2 to group GR1, IO3 to GR2. 4. In Top Include file, declare variables. 5. In PBO, specify following code: LOOP AT SCREEN. IF SCREEN-GROUP1 = 'GR1'. SCREEN-REQUIRED = '1'. ENDIF. IF SCREEN-GROUP1 = 'GR2'. SCREEN-INVISIBLE = '1'. ENDIF. MODIFY SCREEN. * to update the changes made to the predefined structure. ENDLOOP.

6. In PAI, specify following code: CASE SY-UCOMM. WHEN 'LOGIN'. CALL TRANSACTION 'SE38'. WHEN 'EXIT'. LEAVE PROGRAM. ENDCASE. 7. Create a Tcode -> Activate all -> Execute. INSERTING RECORDS FROM MPP SCREEN INTO DATABASE TABLE: -----------------------------------------------------1. Create an MPP program. 2. In Top Include File, declare an internal table as follows: DATA IT_KNA1 LIKE KNA1 OCCURS 0 WITH HEADER LINE. -> Save -> Activate. 3. Create a screen -> In Screen Painter, click DICTIONARY/PROGRAM FIELDS (F6) pushbutton from appn. toolbar -> Opens an interface -> Specify internal table name -> Click on GET FROM PROGRAM pushbutton -> Select required fields -> Continue -> Paste on Screen Painter -> Create two pushbuttons (INSERT, EXIT) -> Save -> Flow logic. 4. In PAI, specify following code: CASE SY-UCOMM. WHEN 'INSERT'. INSERT INTO KNA1 VALUES IT_KNA1. IF SY-SUBRC = 0. MESSAGE S000(ZMSG). ELSE. MESSAGE W001(ZMSG). ENDIF. WHEN 'EXIT'. *LEAVE PROGRAM. SET SCREEN 0.

ENDCASE. 5. Create a Tcode -> Activate all -> Execute. LIST OF VALUES: --------------Adding dropdown facility to the input fields is called as LIST OF VALUES. VRM is a predefined type group which has the following structure and internal table: VRM_VALUE is a structure with the components KEY and TEXT. VRM_VALUES is an internal table declared for the above structure without header line. The above type group is used to fetch values from the internal table declared with userdefined records and insert into the input field in the screen. 'VRM_SET_VALUES' is a function module used to carry the records from the internal table and populate in the input field. NAVIGATIONS TO CREATE DROPDOWN FACILITY FOR INPUT BOX: ------------------------------------------------------1. Create MPP program. 2. Create a screen. 3. Add a input box -> Double click -> Specify name (IO1) -> Select LISTBOX from the dropdown list -> A dropdown facility is added for the input field in the screen. 4. Create two pushbuttons (PRINT, EXIT). 5. In Top Include File, specify following code: TYPE-POOLS VRM. DATA IO1(20). DATA A TYPE I. DATA ITAB TYPE VRM_VALUES. * To create an internal table of an existing type DATA WA LIKE LINE OF ITAB. * To create a temporary structure of same line type of internal table. 6. In PBO, specify following code: IF A = 0. WA-KEY = 'ABAP'. WA-TEXT = 'ADVANCED PROGRAMMING'. APPEND WA TO ITAB. WA-KEY = 'BW'. WA-TEXT = 'BUSINESS WAREHOUSING'.

APPEND WA TO ITAB. WA-KEY = 'EP'. WA-TEXT = 'ENTERPRISE PORTAL'. APPEND WA TO ITAB. CALL FUNCTION 'VRM_SET_VALUES' EXPORTING ID = 'IO1' VALUES = ITAB. A = 1. ENDIF. 7. In PAI, specify following: CASE SY-UCOMM. WHEN 'PRINT'. LEAVE TO LIST-PROCESSING. WRITE :/ IO1. WHEN 'EXIT'. LEAVE PROGRAM. ENDCASE. 8. Create a Tcode -> Activate all -> Execute. CREATING TABSTRIPS IN MPP: -------------------------In a normal screen, we can add only maximum of 40 components. To make a screen hold more than 40 components, we can use tabstrip controls. NAVIGATIONS TO CREATE TABSTRIP CONTROL: --------------------------------------1. Create an MPP program. 2. Create a normal screen (100) -> Add Tabstrip Control component from toolbar -> By default, a tabstrip control is created with 2 tab buttons -> Double click on tabstrip control -> Specify name (TBSTR) in Attributes box -> Click on First tab button -> Add Subscreen Area from toolbar to first tab button -> Double click on subscreen area -> Specify name (SUB1) -> Click on Second tab button -> Repeat same process for adding subscreen area (SUB2) -> Double click on First tab button -> Specify attributes (TAB1,FIRST,TAB1) -> Double click on Second tab button -> Specify attributes (TAB2, SECOND, TAB2) -> SAve -> Flowlogic. 3. Create two subscreens (10, 20) -> Add required components in each subscreen.

4. In Top Include File, specify following code: DATA : IO1(10), IO2(10), IO3(10), IO4(10). CONTROLS TBSTR TYPE TABSTRIP. DATA A LIKE SY-DYNNR. 'CONTROLS' statement is used to allocate a memory area for the tabstrip created in the normal screen. 'TABSTRIP' itself is a data type for the tabstrip control. Whenever a tabstrip is created, SAP creates an object called 'ACTIVETAB' which is used to call the corresponding subscreens for each tab button in PAI. 5. In Flowlogic editor, write following code to initiate the subscreens to the corresponding subscreen areas of each tab button when the main screen is called: PROCESS BEFORE OUTPUT. MODULE STATUS_0100. CALL SUBSCREEN SUB1 INCLUDING 'SAPMZTABSTRIP' '10'. CALL SUBSCREEN SUB2 INCLUDING 'SAPMZTABSTRIP' '20'. PROCESS AFTER INPUT. MODULE USER_COMMAND_0100. CALL SUBSCREEN SUB1. CALL SUBSCREEN SUB2. 6. In PAI, specify following code for click events on each tab button: CASE SY-UCOMM. WHEN 'TAB1'. A = '10'. * calls specified subscreen during PAI TBSTR-ACTIVETAB = 'TAB1'. * makes entire tab button in active status WHEN 'TAB2'. A = '20'. TBSTR-ACTIVETAB = 'TAB2'. WHEN 'DISPLAY'. LEAVE TO LIST-PROCESSING. WRITE :/ IO1, IO2, IO3, IO4. WHEN 'EXIT'. LEAVE PROGRAM. ENDCASE. 7. Create a Tcode -> Activate all -> Execute.

TABLE CONTROLS: --------------Table Control component is used to view the internal table contents in the screen. Navigations to create Table control component: ---------------------------------------------1. Create an MPP program. 2. In Top include File, declare variables as follows: DATA ITAB LIKE KNA1 OCCURS 0 WITH HEADER LINE. DATA ITAB1 LIKE KNA1 OCCURS 0 WITH HEADER LINE. CONTROLS TBCL TYPE TABLEVIEW USING SCREEN 100. DATA CUR TYPE I VALUE 5. -> Save -> Activate. 3. Create a Screen (100) -> Select Table control component from toolbar -> Double Click and specify name (TBCL) -> Press F6 and specify internal table name (ITAB) -> Select required fields -> Paste on the Table control -> To separate the fields, use Separators option in Table control Attributes -> Specify labels if necessary -> Create pushbuttons (FETCH, MODIFY, PRINT, EXIT) -> Save -> Flowlogic. 4. In PAI module, specify following code: CASE SY-UCOMM. WHEN 'FETCH'. SELECT * FROM KNA1 INTO TABLE ITAB. TBCL-LINES = SY-DBCNT. * To create Vertical Scrollbar WHEN 'EXIT'. LEAVE PROGRAM. WHEN 'PRINT'. GET CURSOR LINE CUR. READ TABLE ITAB INDEX CUR. LEAVE TO LIST-PROCESSING. WRITE :/ ITAB-KUNNR, ITAB-NAME1, ITAB-ORT01, ITAB-LAND1. WHEN 'MODIFY'. LOOP AT ITAB1. MODIFY KNA1 FROM ITAB1. IF SY-SUBRC = 0. MESSAGE S002(ZMSG). ELSE.

MESSAGE E003(ZMSG). ENDIF. ENDLOOP. SELECT * FROM KNA1 INTO TABLE ITAB. TBCL-LINES = SY-DBCNT. ENDCASE. 5. In FlowLogic editor, specify following step loops: PROCESS BEFORE OUTPUT. MODULE STATUS_0100. LOOP AT ITAB CURSOR CUR WITH CONTROL TBCL. ENDLOOP. PROCESS AFTER INPUT. MODULE USER_COMMAND_0100. LOOP AT ITAB. MODULE NEW. * New module to move records from ITAB to ITAB1. Double click on Module Name (New) to create a new one. ENDLOOP. 6. Specify following code in the NEW module: MODULE NEW INPUT. APPEND ITAB TO ITAB1. ENDMODULE. 7. Create a Tcode -> Activate all -> Execute. USING TABLE CONTROL WIZARD: --------------------------This is a predefined SAP-specific component to create table control using predefined navigations. 1. Create an executable program (Z_TABLEWIZARD) in SE38 editor. Write the following code: CALL SCREEN 200. -> Save -> Activate. 2. Goto SE51 -> Specify program name created earlier (Z_TABLEWIZARD) -> Specify Screen number (200) -> Layout -> Select Table Control (Wizard) component from

toolbar -> Opens Table control Wizard -> Follow the navigations -> Save and Activate the table control. 3. Execute the program (Z_TABLEWIZARD).

REPORTS: -------There are five types of reports: 1. CLASSICAL REPORTS - CLASSICAL UNFORMATTED - CLASSICAL FORMATTED 2. ALV REPORTS 3. GROUP REPORTS 4. INTERACTIVE REPORTS 5. GRAPHICAL REPORTS. CLASSICAL REPORTS: -----------------Fetching records from one table or more than one table according to client's requirements is called as classical reporting. Classical Unformatted reporting: -------------------------------No colors, header, footer or outlines are drawn for the list. Classical Formatted reporting: -----------------------------A constant header, footer, colors are added to field values in the list. eg. code: ---------REPORT Z_REPORTS NO STANDARD PAGE HEADING LINE-COUNT 20(2) . DATA ITAB LIKE KNA1 OCCURS 0 WITH HEADER LINE. SELECT * FROM KNA1 INTO TABLE ITAB. LOOP AT ITAB. WRITE :/ ITAB-KUNNR, ITAB-NAME1, ITAB-LAND1, ITAB-ORT01. ENDLOOP.

TOP-OF-PAGE. list

* Event is used to create constant header

area for the

WRITE :/40(40) 'CUSTOMER MASTER DETAILS' COLOR 5. SKIP 1. END-OF-PAGE. list * Event is used to create constant footer area for the

WRITE :/50(40) 'THE CURRENT PAGE NUMBER IS' COLOR 6, SY-PAGNO COLOR 6. SELECTION-SCREEN EVENTS: -----------------------INITIALIZATION AT SELECTION-SCREEN START-OF-SELECTION TOP-OF-PAGE END-OF-PAGE END-OF-SELECTION STRING FUNCTIONS: ----------------1. STRLEN Eg. code: --------DATA STR(20) VALUE 'INDIA IS GREAT'. DATA LEN TYPE I. LEN = STRLEN( STR ). WRITE LEN. 2. SPLIT Eg. code: ---------DATA STR(20) VALUE 'INDIA IS GREAT'. DATA : S1(10), S2(10), S3(10). SPLIT STR AT ' ' INTO S1 S2 S3. WRITE :/ S1 COLOR 1, S2 COLOR 2 , S3 COLOR 3. 3. CONCATENATE Eg. code: --------DATA : S1(10) VALUE 'ABAP', S2(10) VALUE 'IN', S3(10) VALUE 'SAP'.

DATA STR(30). CONCATENATE S1 S2 S3 INTO STR SEPARATED BY ' '. WRITE STR. 4. SHIFT 5. SEARCH Eg. code: --------DATA STR(20) VALUE 'INDIA IS GREAT'. SEARCH STR FOR 'IS'. WRITE :/ SY-FDPOS. 6. REPLACE 7. CONDENSE 8. OVERLAY 9. TRANSLATE GROUP REPORTS: -------------In this type of report, control break statements are used. 1. ON CHANGE OF. ENDON. 2. AT FIRST. ENDAT. 3. AT LAST. ENDAT. 4. AT NEW. ENDAT. 5. AT END OF. ENDAT. 1. ON CHANGE OF - ENDON. ------------------------This is also called as processing block within the LOOP-ENDLOOP statements. Eg. code:

--------DATA IT_MARA LIKE MARA OCCURS 0 WITH HEADER LINE. SELECT * FROM MARA INTO TABLE IT_MARA. SORT IT_MARA BY MTART. LOOP AT IT_MARA. ON CHANGE OF IT_MARA-MTART. SKIP 1. WRITE :/ 'MATERIAL DETAILS BASED ON' COLOR 5, IT_MARA-MTART COLOR 5. SKIP 1. ENDON. WRITE :/ IT_MARA-MATNR, IT_MARA-MTART, IT_MARA-MBRSH, IT_MARAMEINS. ENDLOOP. The statement written within the processing block ON CHANGE OF-ENDON gets printed out in LPS whenever the internal table loop encounters change in the field value. 2. AT FIRST-ENDAT: ------------------Eg. code: --------DATA IT_MARA LIKE MARA OCCURS 0 WITH HEADER LINE. SELECT * FROM MARA INTO TABLE IT_MARA. SORT IT_MARA BY MTART. LOOP AT IT_MARA. AT FIRST. SKIP 1. WRITE :/40(50) 'MATERIAL MASTER DETAILS' CENTERED COLOR 7. SKIP 1. ENDAT. WRITE :/ IT_MARA-MATNR, IT_MARA-MTART, IT_MARA-MBRSH, IT_MARAMEINS.

ENDLOOP. The statement specified within AT FIRST-ENDAT gets printed out in LPS during the first pass of the loop iteration. 3. AT LAST-ENDAT: ----------------Eg. code: --------DATA IT_KNC1 LIKE KNC1 OCCURS 0 WITH HEADER LINE. SELECT * FROM KNC1 INTO TABLE IT_KNC1. LOOP AT IT_KNC1. WRITE :/ IT_KNC1-GJAHR, IT_KNC1-UM01U. AT LAST. SUM. SKIP 1. WRITE :/ 'GRAND TOTAL OF THE TRANSACTION IS' COLOR 4, IT_KNC1UM01U COLOR 4. ENDAT. ENDLOOP. 4. AT NEW-ENDAT: ---------------Eg. code: --------DATA : BEGIN OF IT_KNC1 OCCURS 0, GJAHR LIKE KNC1-GJAHR, UM01U LIKE KNC1-UM01U, END OF IT_KNC1. SELECT GJAHR UM01U FROM KNC1 INTO TABLE IT_KNC1. SORT IT_KNC1 BY GJAHR. LOOP AT IT_KNC1.

AT NEW GJAHR. SKIP 1. WRITE :/ 'TOTAL NUMBER OF TRANSACTIONS MADE DURING THE YEAR' COLOR 3, IT_KNC1-GJAHR COLOR 3. SKIP 1. ENDAT. WRITE :/ IT_KNC1-GJAHR, IT_KNC1-UM01U. ENDLOOP. 5. AT END OF - ENDAT: --------------------Eg. code: ---------DATA : BEGIN OF IT_KNC1 OCCURS 0, GJAHR LIKE KNC1-GJAHR, UM01U LIKE KNC1-UM01U, END OF IT_KNC1. SELECT GJAHR UM01U FROM KNC1 INTO TABLE IT_KNC1. SORT IT_KNC1 BY GJAHR. LOOP AT IT_KNC1. WRITE :/ IT_KNC1-GJAHR, IT_KNC1-UM01U. AT END OF GJAHR. SUM. SKIP 1. WRITE :/ 'GRAND TOTAL OF TRANSACTION FOR THE YEAR' COLOR 4, IT_KNC1-UM01U COLOR 4. SKIP 1. ENDAT. ENDLOOP. ALV REPORTS: -----------ALV stands for ABAP LIST VIEWER. Using this concept, we can generate two types of reports such as:

1. ALV LIST FORMAT 2. ALV GRID FORMAT Function Modules used in ALV reports: ------------------------------------REUSE_ALV_LIST_DISPLAY - Predefined FM to generate the report in LIST format. REUSE_ALV_GRID_DISPLAY - Predefined FM to generate the report in GRID format. Eg. code: --------DATA IT_KNA1 LIKE KNA1 OCCURS 0 WITH HEADER LINE. SELECT * FROM KNA1 INTO TABLE IT_KNA1. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' *'REUSE_ALV_LIST_DISPLAY' EXPORTING I_STRUCTURE_NAME = 'KNA1' TABLES T_OUTTAB = IT_KNA1. FIELD CATALOGUES: ----------------The field catalogues are used to specify required fields from the table for display using LIST or GRID formats. SLIS is a predefined type group used for this purpose. Eg. code to generate a report using FIELD CATALOGUES in GRID format: ------------------------------------------------------------TYPE-POOLS SLIS. DATA IT_KNA1 LIKE KNA1 OCCURS 0 WITH HEADER LINE. DATA: FIELDCAT TYPE SLIS_T_FIELDCAT_ALV OCCURS 0. WA_FIELD1 LIKE LINE OF FIELDCAT. SELECT * FROM KNA1 INTO TABLE IT_KNA1. PERFORM FIELDCATALOG. CREATE. FOUR SIMPLE STEPS TO

1. DECLARE INT TABLE AND FIELDCAT. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' 2. FETCH THE RECORDS AND PERFORM(SUBROUTINE) FIELDCAT.

EXPORTING GRID. IT_FIELDCAT SUBROUTINE. TABLES T_OUTTAB FORM FIELDCATALOG.

3. CALL FUNCTION ACC TO LIST OR = FIELDCAT = IT_KNA1. 4. COMPLETE THE

FIELD1-COL_POS = 1. FIELD1-FIELDNAME = 'KUNNR'. *FIELD1-TABNAME = 'CUSTOMER NUMBER'. FIELD1-SELTEXT_S = 'NUMBER'. APPEND FIELD1 TO FIELDCAT. FIELD1-COL_POS = 2. FIELD1-FIELDNAME = 'NAME1'. *FIELD1-TABNAME = 'CUSTOMER NAME'. FIELD1-SELTEXT_S = 'NAME'. APPEND FIELD1 TO FIELDCAT. FIELD1-COL_POS = 3. FIELD1-FIELDNAME = 'ORT01'. *FIELD1-TABNAME = 'CUSTOMER CITY'. FIELD1-SELTEXT_S = 'CITY'. APPEND FIELD1 TO FIELDCAT. FIELD1-COL_POS = 4. FIELD1-FIELDNAME = 'LAND1'. *FIELD1-TABNAME = 'CUSTOMER COUNTRY'. FIELD1-SELTEXT_S = 'COUNTRY'. APPEND FIELD1 TO FIELDCAT. ENDFORM.

INTERACTIVE REPORTS: -------------------Making lists to communicate with each other is called as interactive reporting. When the program is executed, the list we get initially is called as PRIMARY LIST. This list is assigned a default value 0.

We can create 20 secondary lists in LPS. The index number of the first secondary list starts with 1. The list index for secondary list range from 1-20. Totally, we can create 21 lists in LPS using interactive reports ranging from 0-20. SYSTEM VARIABLES USED IN INTERACTIVE REPORTING: -----------------------------------------------SY-LSIND - Returns list index value SY-LISEL - Stores the contents of the line selected from the SY-LILLI - Returns line number of the line selected from the Eg. code: --------DATA FLD(30). DATA IT_KNA1 LIKE KNA1 OCCURS 0 WITH HEADER LINE. SELECT * FROM KNA1 INTO TABLE IT_KNA1. WRITE :/ 'CURRENT LIST INDEX IS' COLOR 3, SY-LSIND COLOR 3. SKIP 2. LOOP AT IT_KNA1. WRITE :/ IT_KNA1-KUNNR HOTSPOT ON, IT_KNA1-NAME1, IT_KNA1-ORT01 HOTSPOT ON, IT_KNA1-LAND1. ENDLOOP. AT LINE-SELECTION. GET CURSOR FIELD FLD. IF FLD = 'IT_KNA1-ORT01'. WRITE :/ SY-LISEL. ENDIF. LOGICAL DATABASES: -----------------* Logical Databases are used to generate report. * It is a repository object, not a data dictionary object. * Under one logical database, a node is created first for the corresponding table in the database. * A logical database can have any number of related nodes in the hierarchical manner. * First node of the logical database is called as ROOT NODE. * SLDB or SE36 to create logical databases. Navigations to Create Logical Database:

list. list.

--------------------------------------SLDB -> Specify LDB name starting with Z or Y -> Click on Create -> Opens an interface -> Enter short description -> Create -> Save under a package and assign request number -> Opens an interface -> Specify Root Node name (MARA) -> Enter short description for the Root node -> Specify Database Table name (MARA) -> Create -> Opens an interface -> Select the Root Node (KNA1) -> Click on SELECTIONS pushbutton from Appn. Toolbar -> Click on Yes to generate Selection Screens from the Structure -> Click on No to Search Help -> Opens an Interface -> Select the checkboxes to create Field Selections and Free Selections -> TRansfer -> Opens an Include Program -> Decomment Select-Options statement and specify range variable as follows: SELECT-OPTIONS : MATNUM FOR MARA-MATNR. -> Save -> Activate -> Come back. Select the Node -> Click on SOURCE CODE pushbutton -> Click on Yes to generate source code from Structure and Selections -> Opens a report with two Include Files : include DBZLOGICAL_DATABASE1TOP . " header include DBZLOGICAL_DATABASE1NXXX . " all system routines -> Double click on Header File to declare global variables -> Specify Following code: TABLES : MARA * Autogenerated DATA IT_MARA LIKE MARA OCCURS 0 WITH HEADER LINE. -> Save -> Activate -> Come back -> Double click on System Routine file, where the fetching operations are done -> Opens an Include File with three subfiles as follows: include DBZLOGICAL_DATABASE1N001 . " Node MARA include DBZLOGICAL_DATABASE1FXXX . " init, PBO, PAI include DBZLOGICAL_DATABASE1SXXX . " search help -> Double click on the first file -> Specify SELECT operation statement as follows: select * from mara into table it_mara where matnr in MATNUM. PUT MARA. * AUTOGENERATED CODE

loop at it_mara. write :/ it_mara-matnr, it_mara-mtart, it_mara-mbrsh, it_mara-meins. endloop. -> Save -> Activate. To Access LDB node, create SE38 PROGRAM, Specify LDB name in ATTRIBUTES section -> Specify following code in SE38: NODES MARA. GET MARA. Save -> Activate -> Execute.

````SAP SCRIPTS``````````````````````````````` ------------------! ------------------! This is a predefined tool in SAP used to perform documentation purposes. Using SAPScript, we can create company-specific templates i.e., purchase orders, sales orders, requisition letters, etc. SE71 is the Tcode to create SAPSCRIPTS. FUNCTION MODULES USED IN SAPSCRIPT: ----------------------------------1. OPEN_FORM. 2. WRITE_FORM. 3. CLOSE_FORM. The above three function modules are used in PRINT PROGRAM, which is used to invoke the sapscript created using SE71 tcode. NAVIGATIONS TO CREATE A USER-DEFINED SAPSCRIPT: ----------------------------------------------SE71 -> Specify form name starting with Z or Y -> Create -> Opens an interface -> Enter short description -> Click on Paragraph Formats pushbutton -> Specify paragraph Name (P1) -> Press Enter -> Enter short description for the paragraph format -> Click on Definitions pushbutton -> Specify Default Paragraph Name (P1) in the Default Paragraph field -> Click on

Layout pushbutton from application toolbar -> Opens LAYOUT with a default page PAGE1 and default window with name MAIN (TYPE : MAIN). LAYOUT EDITOR is used to create text in the SAPSCRIPT form. To go to the LAYOUT EDITOR, Right click on MAIN window -> Select Edit Text -> Opens the editor. To go to the LINE EDITOR, click on GOTO menu -> Change Editor -> Opens LINE EDITOR -> Specify your own text -> In the TAG COLUMN, press F4 -> Select Text Element -> Specify Text element name (ELEMENT1). Eg. /E ELEMENT1 THIS IS MY FIRST SAPSCRIPT

-> Come back -> Save -> ACtivate the form. TO INVOKE THE SAPSCRIPT FROM SE38 editor, specify following PRINT PROGRAM: CALL FUNCTION 'OPEN_FORM' * to invoke the form EXPORTING FORM = 'Z_MY_SAPSCRIPT' LANGUAGE = SY-LANGU. CALL FUNCTION 'WRITE_FORM' * to specify which contents to be printed EXPORTING ELEMENT = 'ELEMENT1' WINDOW = 'MAIN'. CALL FUNCTION 'CLOSE_FORM'. * to save and call the form -> Save -> ACtivate -> Execute -> Opens an interface -> Specify the output device as LP01 -> Click on PRINT PREVIEW pushbutton -> Executes the form. USING SELECT-OPTIONS STATEMENT FOR SAPSCRIPT: --------------------------------------------TABLES KNA1. DATA ITAB LIKE KNA1 OCCURS 0 WITH HEADER LINE. SELECT-OPTIONS CUSNUM FOR KNA1-KUNNR.

SELECT * FROM KNA1 INTO TABLE ITAB WHERE KUNNR IN CUSNUM. CALL FUNCTION 'OPEN_FORM' EXPORTING FORM = 'Z_MY_TABLEFORM' LANGUAGE = SY-LANGU. LOOP AT ITAB. CALL FUNCTION 'WRITE_FORM' EXPORTING ELEMENT = 'TABLE' WINDOW = 'MAIN'. ENDLOOP. CALL FUNCTION 'WRITE_FORM' EXPORTING * ELEMENT ='' WINDOW = 'HEADER'. CALL FUNCTION 'CLOSE_FORM'. TO IMPORT USER-DEFINED GRAPHICS INTO SAPSCRIPT DIRECTORY: ---------------------------------------------------------Create a .bmp file -> SE78 Tcode -> Expand Graphics Folder -> Double click BMP image folder -> Click on IMPORT pushbutton from application toolbar -> Opens an interface -> Specify the path of file location -> Specify the color or black and white image -> Continue -> Displays message. To create the graphic window -> Right click on Layout -> Create Graphic -> Opens interface -> Press F4 from the NAME field -> Execute -> Opens SAPSCript Graphics Directory -> Choose the image -> Continue -> Execute the print program. 12:31 AM 12/30/2007REPORT zmara_pgm NO STANDARD PAGE HEADING LINE-SIZE 255. TYPE-POOLS: truxs. DATA: it TYPE truxs_t_text_data.

DATA : BEGIN OF it_error OCCURS 0, no LIKE rf02k-lifnr, error(255) TYPE c, END OF it_error. DATA: it_mess LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE. DATA : fname TYPE string. DATA : fname1 TYPE string. DATA : BEGIN OF i_str OCCURS 0, row TYPE string, END OF i_str.

DATA: BEGIN OF itab OCCURS 0, lifnr LIKE rf02k-lifnr, bukrs LIKE rf02k-bukrs, ekorg LIKE rf02k-ekorg, ktokk LIKE rf02k-ktokk, anred LIKE lfa1-anred, name1 LIKE lfa1-name1, sortl LIKE lfa1-sortl, stras LIKE lfa1-stras, ort01 LIKE lfa1-ort01, pstlz LIKE lfa1-pstlz, ort02 LIKE lfa1-ort02, land1 LIKE lfa1-land1, akont LIKE lfb1-akont, fdgrv LIKE lfb1-fdgrv, zterm LIKE lfb1-zterm, mahna LIKE lfb5-mahna, waers LIKE lfm1-waers, END OF itab.

INCLUDE bdcrecx1. PARAMETER: pc_file TYPE rlgrap-filename OBLIGATORY. AT SELECTION-SCREEN ON VALUE-REQUEST FOR pc_file. CALL FUNCTION 'F4_FILENAME' EXPORTING

program_name = syst-cprog dynpro_number = syst-dynnr field_name = 'X' IMPORTING file_name = pc_file. START-OF-SELECTION. CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP' EXPORTING * I_FIELD_SEPERATOR = * I_LINE_HEADER = i_tab_raw_data = it i_filename = pc_file TABLES i_tab_converted_data = itab. * EXCEPTIONS * CONVERSION_FAILED =1 * OTHERS =2 . IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. LOOP AT itab. WRITE:/ itab. ENDLOOP. DELETE itab INDEX 1. PERFORM open_group. LOOP AT itab. REFRESH bdcdata. PERFORM bdc_dynpro USING 'SAPMF02K' '0100'. PERFORM bdc_field USING 'BDC_CURSOR' 'RF02K-KTOKK'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'RF02K-LIFNR' itab-lifnr. PERFORM bdc_field USING 'RF02K-BUKRS' itab-bukrs. PERFORM bdc_field USING 'RF02K-EKORG'

itab-ekorg. PERFORM bdc_field USING 'RF02K-KTOKK' itab-ktokk. PERFORM bdc_dynpro USING 'SAPMF02K' '0110'. PERFORM bdc_field USING 'BDC_CURSOR' 'LFA1-SORTL'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'LFA1-ANRED' itab-anred. PERFORM bdc_field USING 'LFA1-NAME1' itab-name1. PERFORM bdc_field USING 'LFA1-SORTL' itab-sortl. PERFORM bdc_field USING 'LFA1-STRAS' itab-stras. PERFORM bdc_field USING 'LFA1-ORT01' itab-ort01. PERFORM bdc_field USING 'LFA1-PSTLZ' itab-pstlz. PERFORM bdc_field USING 'LFA1-ORT02' itab-ort02. PERFORM bdc_field USING 'LFA1-LAND1' itab-land1. PERFORM bdc_dynpro USING 'SAPMF02K' '0120'. PERFORM bdc_field USING 'BDC_CURSOR' 'LFA1-KUNNR'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_dynpro USING 'SAPMF02K' '0130'. PERFORM bdc_field USING 'BDC_CURSOR' 'LFBK-BANKS(01)'. PERFORM bdc_field USING 'BDC_OKCODE' '=ENTR'. PERFORM bdc_dynpro USING 'SAPMF02K' '0210'. PERFORM bdc_field USING 'BDC_CURSOR' 'LFB1-FDGRV'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'LFB1-AKONT' itab-akont. PERFORM bdc_field USING 'LFB1-FDGRV' itab-fdgrv. PERFORM bdc_dynpro USING 'SAPMF02K' '0215'. PERFORM bdc_field USING 'BDC_CURSOR' 'LFB1-ZTERM'.

PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'LFB1-ZTERM' itab-zterm. PERFORM bdc_dynpro USING 'SAPMF02K' '0220'. PERFORM bdc_field USING 'BDC_CURSOR' 'LFB5-MAHNA'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'LFB5-MAHNA' itab-mahna. PERFORM bdc_dynpro USING 'SAPMF02K' '0310'. PERFORM bdc_field USING 'BDC_CURSOR' 'LFM1-WAERS'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'LFM1-WAERS' itab-waers. PERFORM bdc_dynpro USING 'SAPMF02K' '0320'. PERFORM bdc_field USING 'BDC_CURSOR' 'RF02K-LIFNR'. PERFORM bdc_field USING 'BDC_OKCODE' '=UPDA'. PERFORM bdc_transaction USING 'XK01'. IF sy-subrc EQ 0. ENDIF. * ENDLOOP. PERFORM close_group. CALL TRANSACTION 'XK01' USING bdcdata MODE 'N' MESSAGES INTO it_mess. IF sy-subrc NE 0. fname = 'c:\INFO'. CONCATENATE fname sy-datum INTO fname. CONCATENATE fname sy-uzeit INTO fname. CONCATENATE fname '.TXT' INTO fname. * * MOVE itab-lifnr TO it_error-no. * PERFORM error. ENDIF. REFRESH bdcdata. ENDLOOP.

*&--------------------------------------------------------------------* *& Form error *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* FORM error. DATA msg(255) TYPE STRING. LOOP AT it_mess WHERE msgtyp EQ 'E'. CALL FUNCTION 'FORMAT_MESSAGE' EXPORTING id = it_mess-msgid lang = 'SY-LANGU' no = it_mess-msgnr v1 = it_mess-msgv1 v2 = it_mess-msgv2 v3 = it_mess-msgv3 v4 = it_mess-msgv4 IMPORTING msg = msg EXCEPTIONS not_found = 1 OTHERS = 2. IF sy-subrc EQ 0. MOVE msg TO it_error-NO. APPEND it_error.

ENDIF. ENDLOOP. fname1 = 'c:\ERROREE__'. CONCATENATE fname1 sy-datum INTO fname1. CONCATENATE fname1 sy-uzeit INTO fname1. CONCATENATE fname1 '.TXT' INTO fname1. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING * BIN_FILESIZE = filename = fname1 TABLES data_tab = it_ERROR.

* MOVE itab-lifnr TO it_error-no. * PERFORM error.

REFRESH it_mess. CLEAR it_mess. ENDFORM. "error *&--------------------------------------------------------------------*& Form MESSAGE_SUCCESS *&--------------------------------------------------------------------* text *---------------------------------------------------------------------* --> p1 text * <-- p2 text *----------------------------------------------------------------------

You might also like