Download Android App of sapabap-vamsi

sapabap-vamsi : Download Android App for Mobiles

Friday, September 16, 2011

Create ABAP dialog screen dynpro Table Control within SAP


·        Step 1 (Create new structure for table control)
Type is name of structure (ZTC_EKKO) and press create



Enter the fields that you want to display in the table control. Example uses fields from EKKO.

Now save and activate it!
 


·        Step 2 (Create Program)
Goto transaction SE80(Object Navigator) -> Repository Browser -> Program.
Enter your program name, please ensure that is begins with SAPMZ…… as this is a module pool (dialog program).
Press enter to create, and press yes!

 
Ensure that you create a top include, and press Enter.


Accept the name created for the top include.
Press Enter.    

Press Save

·        Step 3 (Create TOP include)
Double click on the top include and enter following ABAP code:

Tables: ZTC_EKKO.
controls: tc100 type tableview using screen 100.

dataok_code type sy-ucomm.
datait_ekko type standard
           table of ZTC_EKKO initial size 0,
        wa_ekko type ZTC_EKKO.


         Press Save and Activate

·        Step 4 (Create screen)
Right click the program to create a screen 100 for the dialog. Enter Short description, set screen type to Normal and enter 0 or blank into Next screen. Then move toElement List tab and enter the OK code as OK_CODE (i.e. the same as what you declared in the top include with data: ok_code type sy-ucomm).



 

·        Step 5 (Create table control)

Press the Layout button to bring up the screen painter editor.


Press table control button and drag it on to the screen, enter the name of table control created in TOP include (TC100). Now press the yellow button for attributes and set the table control as below options


·        Step 6 (Populate table control )
Press the orange button (Fields). On the next screen enter ZTC_EKKO and press the ‘Get from Dict’ button. Select the fields you want (all) and press enter. Now drag them onto your Table Control.


Below is the result, there will been syntax errors if we check now! So Save and go back into the flow logic tab.

 

·        Step 7 (Create flow control )
Within the flow logic of screen 100 and create two modules, one to select the data from the database and the other to move the selected fields into the table control. Also insert the two loop statements to populate and retrieve the lines of the table control.

PROCESS BEFORE OUTPUT.
* MODULE STATUS_0100.
  module data_retrieval.
  loop at it_ekko into wa_ekko with control TC100.
    module populate_screen.
  endloop.
*
PROCESS AFTER INPUT.
  loop at it_ekko.
  endloop.
* MODULE USER_COMMAND_0100.


Double click the module data_retrieval to create and click yes to get past the popup. Ensure that a new include is created to hold all the PBO modules (default). Press enter.

Select 10 rows of data from the EKKO table and load into the internal table it_ekko. Go back to the flow logic to load this data into the Table Control.
*----------------------------------------------------------------------*
***INCLUDE MZ_TCONTROL_DATA_RETRIEVALO01 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  data_retrieval  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE data_retrieval OUTPUT.
* select data from ekko table
  SELECT ebeln bukrs bstyp bsart
         bsakz loekz statu aedat
   UP TO 10 ROWS
    FROM ekko
    INTO CORRESPONDING FIELDS OF TABLE it_ekko.
ENDMODULE.                 data_retrieval  OUTPUT


Double click the module populate_screen to create. Now move the values in this loop from the wa_ekko into the Table Control with the move-corresponding statement.

MODULE populate_screen OUTPUT.
    DATA: ld_line TYPE i.

*   Set which line of table is a top of displayed table control
    IF sy-stepl = 1.
      tc100-lines =
        tc100-top_line + sy-loopc - 1.
    ENDIF.

*   move fields from work area to scrren fields
    MOVE-CORRESPONDING wa_ekko TO ztc_ekko.

  ENDMODULE.                 populate_screen  OUTPUT


·        Step 8 (Create transaction )
Now create a transaction to test the table control program. Right click the Program and select create-> transaction.



            


·        Step 9 (Execute transaction )
Execute transaction ZTC 

SAP ABAP dynpro programs, dialog screen programs with input fields, buttons, OO ALV grids etc..

An SAP dialog program is an ABAP development which consists of many screens which when linked together make up an application which allows the user to perform a specific piece of functionality such as creating a purchase order (ME21). These screens are referred too as dynpros (DYnamic PROgrams) and are made up of the actual user screen and its associated flow logic which are all stored within an SAP module pool. It is the flow logic via the use of the PBO and PAI that controls the process and functionality of the screen and depending on the user actions the appropriate event or relevant next dynpro is called.

The PBO module controls all events and functionality that needs to be performed before a screen is displayed to the user. i.e. populating default fields, hiding fields based on certain criteria.

The PAI module controls all the events and functionality which needs to be performed after the user performs an action. This includes things like field validation, checking the ok code to see what action the selected and performing the associated functionality etc etc...

Thursday, September 15, 2011

Internal table declaration - various ABAP code to implement an internal table


Declaring internal tables is an essential part of writing ABAP code as this is where most of the data retrieved from database tables will be stored. During the selectstatement you retrieve data from a database table into an internal table (multiple rows) or a work area or header line (single row).

*&-------------------------------------------------------------*
*& Report  ZTYPES                                              *
*&                                                             *
*&-------------------------------------------------------------*
REPORT  ZTYPES .

* Table declaration (old method)
DATA: BEGIN OF tab_ekpo OCCURS 0,             "itab with header line
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
 END OF tab_ekpo.

*Table declaration (new method)     "USE THIS WAY!!!
TYPES: BEGIN OF t_ekpo,
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
 END OF t_ekpo.
DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,      "itab
      wa_ekpo TYPE t_ekpo.                    "work area (header line)

* Build internal table and work area from existing internal table
DATA: it_datatab LIKE tab_ekpo OCCURS 0,      "old method
      wa_datatab LIKE LINE OF tab_ekpo.

* Build internal table and work area from existing internal table,
* adding additional fields
TYPES: BEGIN OF t_repdata.
        INCLUDE STRUCTURE tab_ekpo.  "could include EKKO table itself!!
TYPES: bukrs  TYPE ekpo-werks,
       bstyp  TYPE ekpo-bukrs.
TYPES: END OF t_repdata.
DATA: it_repdata TYPE STANDARD TABLE OF t_repdata INITIAL SIZE 0,   "itab
      wa_repdata TYPE t_repdata.                 "work area (header line)

Friday, September 9, 2011

Reports - I

Classic Reports


1. Load Of Program : will get triggered initially. This event cant be handled.
                                  The Classic event which initially gets triggered is "Load Of Program".

2. Initialize Event : For default values to be popped up at selection screen need to go with Initialize Event.
                             This event can be handled.

3. At Selection Screen : This event is used to select the fields.

4. Top - Of - Page : To maintain list headings.

5. Start - Of -Selection : Based on inputs start of selection will trigger.

6. End - Of - Page : To maintain Footer of the page.

7. At PF 'N' : Event triggered at Predefined Function.

8. At User Command : User Commands is nothing but User Codes.
                                    The event that is triggered when a button is clicked.
                                     Need to maintain Function Codes for this event and need to maintain those  
                                     Function Codes in Upper case.               

Example for creating Global Class



 Navigate to Transaction SE11.































Select Structure Radio Button









For Currency/quantity fields Reference table and Ref. field should be specified.
Maintain Enhancement Category Settings.
























Select Can be enhanced (Character-type or numeric) option. 
Save, Check and Activate.

Now Creating a Row Type.

Select Table Type.



Specify the line type name in the given field.


















Save, Check and Activate.
Now creating a Type Group.
























Navigate to SE24.



Mention the Type group name  in the Type Group / Object Type field created for using Types.

















In the Attributes tab mention the parameters required as input fields.


















In the Methods tab specify the methods for this class.
Constructor is the default method for any global class.



Select the constructor field and click on Methods button.


Navigate back .
Double Click on constructor and follow the screen below.



















Go Back.
Double Click on Get_Data.



method GET_DATA.
  SELECT lfa1~lifnr lfa1~name1 ekko~ebeln ekpo~matnr ekpo~txz01 ekpo~netwr
    FROM lfa1
    INNER JOIN ekko on lfa1~lifnr eq ekko~lifnr
    inner join ekpo on ekko~ebeln eq ekpo~ebeln
    into table itab
    where ekko~ebeln between p_low and p_high.
endmethod.


Go Back.
Double Cilck on Show_Data.

















method SHOW_DATA.
  LOOP AT  itab into wa.
write : / wa-lifnr,wa-name1,wa-ebeln,wa-matnr,wa-txz01,wa-netwr.
  ENDLOOP.
endmethod.


Go Back.
Save, Check and Activate.
Execute/Test.


 Enter Parameters Value and click on Instance.

















Click on Get_data.

Click on Show_Data.



 Back to the main screen.
Navigate to SE38.





 Create a Program to use the Global Class.


















*&---------------------------------------------------------------------*
*& Report  ZGLOBAL_CALL
*& Created By : Vamsi Vitta
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZGLOBAL_CALL line-SIZE 200.

TYPE-POOLs : zpord.

DATA : d_ebeln TYPE zpord_wa-ebeln.

SELECT-OPTIONS : s_ebeln FOR d_ebeln.

DATA : objkt TYPE REF TO zpurchase_class.

CREATE OBJECT OBJKT
  EXPORTING
    C_LOW  = s_ebeln-low
    C_HIGH = s_ebeln-high
    .
CALL METHOD OBJKT->GET_DATA
    .

CALL METHOD OBJKT->SHOW_DATA
    .


Save, Check and Activate.

Execute.

Enter the values and execute to get the output.

























It's done.
Appreciate Thanks.

Tuesday, September 6, 2011

SAP ABAP Query


Why ABAP/4 Queries?
Many times a need arises for SAP Users and Functional Consultants to generate quick reports without getting any ABAP coding done – time taken to complete the coding in development, transport and test it in QA system and then transport to production – is sometimes too long. In such cases, ABAP/4 query is a tool provided by SAP for generating these kind of reports.
And also ABAP/4 Query is a powerful tool to generate simple reports without any coding. ABAP/4 Query can generate the following 3 simple reports: Basic List: It is the simple reports. Statistics: Reports with statistical functions like Average, Percentages. Ranked Lists: For analytical reports. - For creating a ABAP/4 Query, programmer has to create user group and a functional group. Functional group can be created using with or without logical database table. Finally, assign user group to functional group. Finally, create a query on the functional group generated.
Note: The output is always seen in the order of Basic List, then Statistics and then Ranked List if any. One ABAP query can have one basic list, maximum of 9 statistics and maximum of 9 ranked lists.
An ABAP/4 query can be designed in four steps:
  • Creation of a user group
  • Creation of functional area
  • Assignment of user group to functional area
  • Creation of the query based on functional area
Main transaction codes used here are:
SQ01: ABAP/4 Query
SQ02: Functional Area
SQ03: User Group

First Step: Creating Functional Areas
In the section functional area, we have to indicate from which part of the SAP database the data is going to be retrieved and how the data is to be retrieved by the query. A functional area can be created with or without a logical database.
To create a functional area with a logical database, you have to mention the name of the database and then select the fields from the tables that form the logical database.
Steps to create the functional area with a logical database :
Tools --> ABAP/4 Workbench --> Utilities --> Query --> Functional Areas.
● Give the functional area name and click on Create button
● In the next screen give a brief description of the functional area
● Specify the name of the logical database, for e.g. Database FI, Application S. This will be the definition for the flight database
● Click on the button Functional Group present on the application toolbar, in order to create the functional group for the required fields from the logical database tables
● In the functional group box mention the number of the functional group and the description for the functional group
● The tables from the logical database are shown in Tables Of Logical Database/Joins while the fields are displayed in the Fields Box
● Double click on the table name in order to change the list
● Every field that has to be selected in the query should be assigned a functional group number against it
● Sometimes the list of fields in the Fields box will not be completely visible. To have a wider display of the list place the cursor in the fields box area and click on Settings --> Full Screen from the SAP menu bar
● To see the fields from different tables select the table and double click on it.
● Once the required fields are selected, save the functional Area by clicking on the SAVE icon on the toolbar, and then Generate the Functional Area by clicking the Generate icon on the toolbar
● To add user defined fields to the ABAP query use the menu bar option GOTO => Additional Field
● Give the field name and the table name from the logical database to which the field needs to be included. Click the ENTER button.
● On the next screen give the Sequence, description, title and the technical attributes for the field (field type, length). Here you can also specify the formula for the field. Click on the SAVE button to register the data to the database.
● Remember that the sequence of the field matters – if the second field uses the first field in its code then the second field should have a higher sequence than the first. Tables can also be included – to do this use the menu option Goto --> Additional Tables
● You can include your own selection criteria and parameters to control the data to be selected from the database. For these additions to get activated, code needs to be written for taking care of the additional fields.
● To display something before the execution of the actual query, go to the start of selection event via the menu path Goto --> Code --> Start-of-selection.
● To display something just before or after the output of the query, go to the end of selection event via the menu path Goto --> Code --> End-of-selection.
● To display something at the beginning of the page, go to the top of page event via the menu path Goto --> Code --> Top-of-page.
After finishing everything save and generate the functional area and click on the BACK icon to come out.
Steps to create the functional are without a logical database:
One of the following can be selected
● Based on a single table
● Using an ABAP/4 program
● Using Table Joins
● Using Sequential Dataset
The steps to be followed for creating the functional area are as follows
● Tools --> ABAP/4 Workbench --> Utilities --> ABAP/4 query --> Functional Areas.
● Give the functional area name and click on Create button
● In the next screen give a brief description of the functional area
In the ‘Without a logical database area’ give the base table on which to form the ABAP query”
● To form the query with two or three tables, we need to create a join. For this check the Table Join Check Box and click on the Table Join button.
IMP: The tables to be used in the join should have at least one field in common i.e. it should have the same name, domain or data element.
Mention the tables that you want to include in the join condition in the Joined Tables area and press ENTER.
A checkbox will appear against the table names on the left side, and three radio buttons will appear against the tables on the right side specifying the join type.
● Base table name remains grayed out. Select the two tables to be involved in the join by clicking the check boxes against them. Use menu path Edit => Join => Define condition to create the join.
A mapping between the tables will be displayed on the right hand side. Click on the button provided (with + and down arrow symbol) to specify the join.
● Click YES on the Proposal Requested message that gets displayed.
● If the join tables have a foreign key relationship then the common fields in the tables will be marked with 00 to indicate that the join has been created. User can create the join by specifying 00, 01 etc. against the fields that qualify for the join.
● Complete the join condition by adding more tables if necessary.
Remaining concepts for creating the functional area without a logical database are same as the concepts for creating the functional area with a logical database.
After finishing everything save and generate the functional area and click on the BACK icon to come out.
Second Step Creating User Group:
Here you specify the users who should be authorized to run the query. A user group is always associated with a Functional Area.
● Go to the menu path Environment => User Group. Give a user group name in the screen that comes next.
● Specify the sap logins of the users whom you want to authorize for using the functional area and click on the Create button.
● Use the menu path Assign Functional Area to assign the functional area to the user group.
● Save the user group and back out of the screen by clicking the Back button.
Note: One user group can be assigned to any number of functional areas with logical database or without logical database.
The final step is to create the actual query.
Third Step Creating The Query:
● In order to create the query use the menu path Environment => Queries
● Give a name to the query and click on the Create button
● Give the description of the query in the next screen. Specify the output length and select the processing option from the Further Processing Options box. The data can be displayed in various formats such as table, download to a file, and display in Word etc.
● Click on the Next screen icon. Select the functional group screen. All the functional groups created in the functional area are displayed. Select the groups that you desire – fields from only these groups will be displayed in the output. Click on the respective check boxes and click on the Next Screen icon.
● The Select Field screen gets displayed. Select all the fields from the user group that you need to display on the output of the query. If required, specify the short names for the fields using the menu path Edit => Short Names => Switch On/Off or you can also change the selection text contains in the order you want to appear on the selection screen. You can also maintain column headers for the
fields by using the menu path Edit => Column Header => Maintain.
● Click on the Next Screen icon to get the Selections Screen. Here you can check against the fields that you require to be shown on the selection screen.
● Now we need to specify the output type for the query as Basic List, Statistics or Ranked List. Choose the option Basic List.
● On the Basic List line structure screen the following things can be done
- Specify the report layout in detail – lines on which the fields will appear.
- Order in which the fields will appear in the output
- Sort order for the fields – this is optional.
- For the numeric fields you can check against the fields for which you require totals in the output.
- Beautify the output according to the options provided.
● Click on the next screen icon, to specify the control levels as mentioned below
- Specify the sort order. The default sort order is ascending and can be changed to
descending if required.
- Totals for each field selected for sorting can be displayed
- To display the output of a field in a box click on the check box against box. To display a line after the output of a field, click on the check box against BlnkLn
- To display the output of a field on a new page click on the check box against New Page
● Click on the next screen icon to get the List Line options Screen. Here you can specify the background color for displaying the output.
● Click on the next screen icon to get the Field Output Option screen. In this you can specify the following:
- Change the output length or the display positions of the fields
- Specify the display position of the unit for quantity or currency fields. Click left radio button to display it before the figure, middle radio button to display it after the figure while last radio button to hide the unit altogether.
- Specify color for the column of every field under the Format option.
- Specify the label against the output of sort fields.
● Click on the Next screen option to go to the Basic List Header screen. Here you can specify
- Give page header and page footer for the output
- Include user name and date by specifying &N and &D respectively.
After providing all the above options you can save the query and execute it by clicking the Execute button twice.
Retrieving Data Using Program:
Sometimes a situation arises when an ABAP query’s automatic data retrieval facility is not enough to get the desired results. In that case, the steps up to creating the functional area are the same. Only difference is that on the Title and Database screen specify a structure in the field Table and select the field Data Retrieval Using
Program.
The default report name given by the system can be overwritten.
This report needs to be defined before hand – because it is used as a model while generating the query report.
Thus the report itself remains unchanged but based on that another one is created.
General Format of the Report
A typical report of this type will have the following format:
Report <report name>.
Tables: <list of dictionary structures to be used>.
Parameters: <name of parameters>.
Select-options: <name of select options>.
Data: < all internal tables>.
*<query head> This comment should always be after data declarations.
Beginning of a loop to retrieve each record and place it in the field string tab.
Select, do-enddo, loop, etc.
<code to format the data>.
*<query body> This comment should always be the last statement in the loop.
At this stage the data will come into the field string.
Endselect, enddo, endloop.