SAP---ABAP

Friday, September 21, 2007

BAPI-1

BAPI Conventions

Methods

  • If the BAPI to be implemented is a standardized BAPI, use the generic names, for example, GetList, GetDetail.
  • The method name must be in English (maximum 30 characters).
  • The individual components of a BAPI name are separated by the use of upper and lower case.Example: GetList
    Underscores ("_") are not allowed in BAPI names.
  • Each BAPI has a return parameter that is either an export parameter or an export table.
  • So that customers can enhance BAPIs, each BAPI must have an ExtensionIn and an ExtensionOut parameter.

Parameters

  • If standardized parameters are used, you have to use the names specified for standardized parameters.
  • BAPI parameter names should be as meaningful as possible. Poorly chosen names include abbreviations and technical names (e.g. "flag", table names, etc.).
    The parameter and field names must be in English with a maximum of 30 characters.
  • The components of a parameter name in the BOR are separated by upper and lower case letters to make them easier to read. Example: CompanyCodeDetail
  • Values that belong to each other semantically should be grouped together in one structured parameter, instead of using several scalar parameters.
  • For ISO-relevant fields (country, language, unit of measure, currency), additional fields for ISO codes are provided.
  • Unit of measure fields must accompany all quantity fields and currency identifiers must accompany currency amount fields.

Standardized BAPIs

Some BAPIs provide basic functions and can be used for most SAP business object types. These BAPIs should be implemented the same for all business object types. Standardized BAPIs are easier to use and prevent users having to deal with a number of different BAPIs. Whenever possible, a standardized BAPI must be used in preference to an individual BAPI.

The following standardized BAPIs are provided:

Reading instances of SAP business objects



GetList ( ) With the BAPI GetList you can select a range of object key values, for example, company codes and material numbers.
The BAPI GetList() is a class method.
GetDetail() With the BAPI GetDetail() the details of an instance of a business object type are retrieved and returned to the calling program. The instance is identified via its key. The BAPI GetDetail() is an instance method.

BAPIs that can create, change or delete instances of a business object type

The following BAPIs of the same object type have to be programmed so that they can be called several times within one transaction. For example, if, after sales order 1 has been created, a second sales order 2 is created in the same transaction, the second BAPI call must not affect the consistency of the sales order 2. After completing the transaction with a COMMIT WORK, both the orders are saved consistently in the database.




Create( ) and
CreateFromData( )
The BAPIs Create() and CreateFromData() create an instance of an SAP business object type, for example, a purchase order. These BAPIs are class methods.
Change( ) The BAPI Change() changes an existing instance of an SAP business object type, for example, a purchase order. The BAPI Change () is an instance method.
Delete( ) and Undelete( ) The BAPI Delete() deletes an instance of an SAP business object type from the database or sets a deletion flag.
The BAPI Undelete() removes a deletion flag. These BAPIs are instance methods.
Cancel ( ) Unlike the BAPI Delete(), the BAPI Cancel() cancels an instance of a business object type. The instance to be cancelled remains in the database and an additional instance is created and this is the one that is actually canceled. The Cancel() BAPI is an instance method.
Add ( ) and Remove ( ) The BAPI Add adds a subobject to an existing object instance and the BAPI and Remove removes a subobject from an object instance. These BAPIs are instance methods.

BAPIs for Mass Data Processing

The BAPIs listed above for creating and changing data can also be used for mass processing. For more information see BAPIs for Mass Data Transfer [Extern]

BAPIs for Replicating Business Object Instances



Replicate( ) and SaveReplica( ) The BAPIs Replicate() and SaveReplica() are implemented as methods of replicable business object types. They enable specific instances of an object type to be copied to one or more different systems. These BAPIs are used mainly to transfer data between distributed systems within the context of Application Link Enabling (ALE). These BAPIs are class methods.

Other Less Used Standardized BAPIs

  • Programming GetStatus() BAPIs [Extern]
  • Programming ExistenceCheck() BAPIs [Extern]

Standardized Parameters

There are some parameters that can be created for various BAPIs because they contain the same or the equivalent data in all BAPIs. They should be implemented the same in all BAPIs.




Address parameters Specific reference structures are defined for address parameters in BAPIs. You should copy these structures to use in your BAPI, especially if the underlying object type uses the central address management (CAM).
Change Parameters In BAPIs that cause database changes (for example, Change() and Create() BAPIs) you must be able to distinguish between parameter fields that contain modified values and parameter fields that have not been modified. This distinction is made through the use of standardized parameters.
Extension parameters The parameters ExtensionIn and ExtensionOut provides customers with a mechanism that enables BAPIs to be enhanced without modifications.
Return Parameters Each BAPI must have an export return parameter for returning messages to the calling application. To provide application programmers with a consistent error handling process for BAPI calls, all return parameters must be implemented in the same, standardized way.
Selection Parameters Standardized selection parameters are used in BAPIs that can be used to search for specific instances of a business object type (e.g. in GetList() ). These parameters enable the BAPI caller to specify the relevant selection criteria.
Test Run Parameters The parameter TestRun is used in write BAPIs (Create() and Change() ), to check the entries for the object instance in the database before actually creating the object instance. The creation of the object instance is only simulated and data is not updated.
Text Transfer Parameters To transfer BAPI documentation texts (e.g. the documentation of a business object type), you have to create standardized text transfer parameters.

Important things to remember..

It is important to follow the guidelines below when develop9ng BAPIs:
  • BAPIs must not contain CALL TRANSACTIO or SUBMIT REPORT
  • BAPIs must not invoke a COMMIT WORK. instead use the BAPI TransactionCommit to execute the commit after the BAPI has executed.
  • BAPI structures must not use includes.
  • There should be no functional dependecies between two BAPIs
  • BAPIs must perform there own authorization check
  • BAPIs should not use dialogs
  • BAPIs must not cause the program to abort or terminate. re4levant messages must be communicated through the return parameter.

BAPI/ALE Integration

When you use the BAPIs for asynchronous messagning, the application in the sendig systen calls the generated ALE IDoc interface isntead of the BAPI.

Asynchronous BAPIs use the ALE interface this way:

  • Creates an IDOC from the BAPI data
  • Sends the IDOC to the target system
  • Receives the IDOC in trhe target system, crreates the BAPI data from the IDoc and calls the BAPI
An ALE interface for a BAPi is created in transaction BDBG.

Tuesday, September 18, 2007

Object-2



Splash Screen in ABAP using OO



SAP being a serious Businesss Software you cannot have too many
JPGs floating around! One or two is fun.

In Function group uou need two screens 0806 & 2009 which are
essentially blank.

I put 2 title Bars - 0806 "SAP - JOB in Progress"; 2009 - "SAP - JOB
OVER!!"

Code listing for function: ZJNC_START_SPLASH
Description: Show Splash at Start
--------------------------------------------------------------------------------

FUNCTION zjnc_start_splash.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(IMAGEFILE) TYPE C DEFAULT 'THANKS.JPG'
*" REFERENCE(WIDTH) TYPE I DEFAULT 415
*" REFERENCE(HEIGHT) TYPE I DEFAULT 274
*" REFERENCE(TIMEOUT) TYPE I DEFAULT 3
*" REFERENCE(CALLBACK) TYPE C
*"----------------------------------------------------------------------

* Global data declarations
MOVE imagefile TO g_name.
MOVE width TO picwidth.
MOVE height TO picheight.
MOVE timeout TO pictimeout.
MOVE callback TO piccallback.
TRANSLATE piccallback TO UPPER CASE.

PERFORM getpicurl.

CALL SCREEN 0806.

ENDFUNCTION.


Code listing for function: ZJNC_END_SPLASH
Description: Show Splash at End
--------------------------------------------------------------------------------

FUNCTION ZJNC_END_SPLASH.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(IMAGEFILE) TYPE C DEFAULT 'THANKS.JPG'
*" REFERENCE(WIDTH) TYPE I DEFAULT 415
*" REFERENCE(HEIGHT) TYPE I DEFAULT 274
*" REFERENCE(TIMEOUT) TYPE I DEFAULT 3
*"----------------------------------------------------------------------

* Global data declarations
MOVE imagefile TO g_name.
MOVE width TO picwidth.
MOVE height TO picheight.
MOVE timeout TO pictimeout.

PERFORM getpicurl.

CALL SCREEN 2009.

ENDFUNCTION.


Code listing for: LZUTILTOP

* TOP level Include of Function Group ZUTIL

* Author Jayanta Narayan Choudhuri
* Flat 302
* 395 Jodhpur Park
* Kolkata 700 068
* Email sss@cal.vsnl.net.in
* URL: http://www.geocities.com/ojnc

FUNCTION-POOL zutil. "MESSAGE-ID ..

TYPE-POOLS: abap.

DATA: graphic_url(255),
g_result TYPE i,
g_linesz TYPE i,
g_filesz TYPE i,
g_name(100).

TYPES: t_graphic_line(256) TYPE x.

DATA: graphic_line TYPE t_graphic_line,
graphic_table TYPE TABLE OF t_graphic_line.

DATA: picwidth TYPE i,
picheight TYPE i,
pictimeout TYPE i,
piccallback(60) TYPE c,
first TYPE boolean.


*---------------------------------------------------------------------*
* CLASS ZCL_ES_SPLASH_SCREEN DEFINITION
*---------------------------------------------------------------------*
CLASS zcl_es_splash_screen DEFINITION.

PUBLIC SECTION.
EVENTS on_close.

METHODS constructor
IMPORTING
!i_num_secs TYPE i DEFAULT 5
!i_url TYPE c
!i_width TYPE i
!i_height TYPE i.

PROTECTED SECTION.

METHODS handle_end_of_timer
FOR EVENT finished OF cl_gui_timer.
PRIVATE SECTION.

DATA container TYPE REF TO cl_gui_dialogbox_container.
DATA image TYPE REF TO cl_gui_picture.
DATA timer TYPE REF TO cl_gui_timer.

ENDCLASS. "ZCL_ES_SPLASH_SCREEN DEFINITION

*---------------------------------------------------------------------*
* CLASS ZCL_ES_SPLASH_SCREEN IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS zcl_es_splash_screen IMPLEMENTATION.
METHOD constructor.

DATA: image_width TYPE i,
image_height TYPE i.

COMPUTE image_width = i_width + 30.
COMPUTE image_height = i_height + 50.

CREATE OBJECT container
EXPORTING
width = 10
height = 10
top = 10
left = 10
name = 'DialogSplash'.


CALL METHOD container->set_caption
EXPORTING
caption = g_name.

CREATE OBJECT image
EXPORTING
parent = container.

CALL METHOD image->load_picture_from_url
EXPORTING
url = i_url.

image->set_display_mode( image->display_mode_normal_center ).

cl_gui_cfw=>flush( ).

container->set_metric( EXPORTING metric = image->metric_pixel ).

DATA: myleft TYPE i,
mytop TYPE i.

COMPUTE myleft = ( 800 - image_width ) / 2.
COMPUTE mytop = ( 600 - image_height ) / 2.

IF myleft < 0.
MOVE 0 TO myleft.
ENDIF.
IF mytop < 0.
MOVE 0 TO mytop.
ENDIF.
container->set_position(
EXPORTING
height = image_height
left = myleft
top = mytop
width = image_width ).

cl_gui_cfw=>update_view( ).

CREATE OBJECT timer.
timer->interval = i_num_secs.

SET HANDLER me->handle_end_of_timer FOR timer.
timer->run( ).
cl_gui_cfw=>flush( ).

ENDMETHOD. "constructor

METHOD handle_end_of_timer.

* I wanted NAMASTE to remain until JOB was complete.
* IF container IS NOT INITIAL.
* container->free( ).
* CLEAR container.
* FREE container.
* ENDIF.
*
* IF timer IS NOT INITIAL.
* timer->free( ).
* CLEAR timer.
* FREE timer.
* ENDIF.
*
* cl_gui_cfw=>flush( ).

RAISE EVENT on_close.

ENDMETHOD. "handle_end_of_timer
ENDCLASS. "ZCL_ES_SPLASH_SCREEN IMPLEMENTATION

*---------------------------------------------------------------------*
* CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.

PUBLIC SECTION.
CLASS-METHODS: on_close FOR EVENT on_close OF zcl_es_splash_screen.
ENDCLASS. "lcl_event_handler DEFINITION

*---------------------------------------------------------------------*
* CLASS lcl_event_handler IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
METHOD on_close.
IF sy-dynnr = 2009.
LEAVE PROGRAM.
ELSE.
MOVE abap_false TO first.
PERFORM (piccallback) IN PROGRAM (sy-cprog).
ENDIF.
ENDMETHOD. "on_close
ENDCLASS. "lcl_event_handler IMPLEMENTATION

DATA: splash TYPE REF TO zcl_es_splash_screen.

*&---------------------------------------------------------------------*
*& Module STATUS_0806 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0806 OUTPUT.
IF first IS INITIAL.
first = abap_true.

SET TITLEBAR 'TITLE0806'.

CREATE OBJECT splash
EXPORTING
i_num_secs = pictimeout
i_url = graphic_url
i_width = picwidth
i_height = picheight.

SET HANDLER lcl_event_handler=>on_close FOR splash.

ENDIF.
ENDMODULE. " STATUS_0806 OUTPUT

*&---------------------------------------------------------------------*
*& Module STATUS_2009 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_2009 OUTPUT.
IF first IS INITIAL.
first = abap_true.

SET TITLEBAR 'TITLE2009'.

CREATE OBJECT splash
EXPORTING
i_num_secs = pictimeout
i_url = graphic_url
i_width = picwidth
i_height = picheight.

SET HANDLER lcl_event_handler=>on_close FOR splash.

ENDIF.
ENDMODULE. " STATUS_2009 OUTPUT

*&---------------------------------------------------------------------*
*& Form getpicurl
*&---------------------------------------------------------------------*
FORM getpicurl.

OPEN DATASET g_name FOR INPUT IN BINARY MODE.

REFRESH graphic_table.
CLEAR g_filesz.

DO.
CLEAR graphic_line.
READ DATASET g_name INTO graphic_line ACTUAL LENGTH g_linesz.

ADD g_linesz TO g_filesz.

APPEND graphic_line TO graphic_table.
IF sy-subrc <> 0.
EXIT.
ENDIF.

ENDDO.

CLOSE DATASET g_name.

CLEAR graphic_url.

CALL FUNCTION 'DP_CREATE_URL'
EXPORTING
type = 'IMAGE'
subtype = 'GIF'
TABLES
data = graphic_table
CHANGING
url = graphic_url
EXCEPTIONS
dp_invalid_parameter = 1
dp_error_put_table = 2
dp_error_general = 3
OTHERS = 4.


IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ENDIF.

ENDFORM. "getpicurl

Object-1



What are ABAP Objects?

ABAP Objects is a new concept in R/3 Release 4.0. The term has two meanings. On the one hand, it stands for the entire ABAP runtime environment. On the other hand, it represents the object-oriented extension of the ABAP language.

The following is a simple example shows the object-oriented aspect of function groups in the simple case of a counter.

Suppose we have a function group called COUNTER:


Create an abap program with this code :-

FUNCTION-POOL COUNTER.

DATA COUNT TYPE I.

FUNCTION SET_COUNTER.

* Local Interface IMPORTING VALUE(SET_VALUE)

COUNT = SET_VALUE.
ENDFUNCTION.

FUNCTION INCREMENT_COUNTER.
ADD 1 TO COUNT.
ENDFUNCTION.

FUNCTION GET_COUNTER.

* Local Interface: EXPORTING VALUE(GET_VALUE)

GET_VALUE = COUNT.
ENDFUNCTION.

* End of program code

The function group has a global integer field COUNT, and three function modules,
- SET_COUNTER,
- INCREMENT_COUNTER, and
- GET_COUNTER, that work with the field.

Two of the function modules have input and output parameters. These form the data interface of the function group.

Any ABAP program can then work with this function group. For example:

REPORT ZABAPOO.

DATA NUMBER TYPE I VALUE 5.

CALL FUNCTION 'SET_COUNTER' EXPORTING SET_VALUE = NUMBER.

DO 3 TIMES.
CALL FUNCTION 'INCREMENT_COUNTER'.
ENDDO.

CALL FUNCTION 'GET_COUNTER' IMPORTING GET_VALUE = NUMBER.

WRITE: / 'After processing NUMBER is :- ', NUMBER.


* End of program code

After this section of the program has been processed, the program variable NUMBER will have the value 8.

The program itself cannot access the COUNT field in the function group. Operations on this field are fully encapsulated in the function module. The program can only communicate with the function group by calling its function modules.

Monday, September 17, 2007

TABLE-18



Easy Way To Remember Table In SAP

The easiest way to remember the table in sap is:

Just try to remember the sap terminology of representing the business or buisness objects... such as

all vendor tables start with L such as lfa1, etc..

all customer tables start with K ... Kna1, konv...

all sales tables start with V... vbak vbap

all master data tables start with T... T001, t001w

all bank tables start with B.. Bknf, bkpf....

all purchasing tables start with E.. ekko, ekpo etc..

all material tables start with M... mara, makt, marc...


And


in sales, delivery, billing, purchasing...

if the tables name contains K init it is Header data
such as vbak, likp, vbrk, ekko...

if the tables name contains P init it is Item data
such as vbap, lips, vbrp, ekpo ....

Coming to FI tables... there are only 6 important tables in whole Finance module which are mostly used by abapers.


They can be remember by:

.if the table name contains I, that is open item

if the table name contains A, that is closed item

if the table name ends with S, that is GL account

exp BSIS- GL master open items
BSAS- GL master closed items
like wise...

if the table name ends with D, that is customer

if the table name ends with K, that is vendor

Finally, table TSTC contains the list of all transaction codes.

TABLE-17



How Loop Works in Internal Tables


How loop works in internal tables with example using any SD table? What is the effect on INTERNAL TABLE ITAB using CLEAR ITAB, REFRESH ITAB?


Internal table is a temporary storage location which is only available at runtime.

Now we are defining one internal table IT_KNA1 using the database table KNA1.

DATA : BEGIN OF IT_KNA1 OCCURS 0,
CUST_NO LIKE KNA1-KUNNR,
NAME LIKE KNA1-NAME1,
CNTRY LIKE KNA1-LAND1,
END OF IT_KNA1.

With the above statement internal table is created with body and work area.

Now we have populated the IT_KNA1 using select statement.

Select ... from KNA1 into IT_KNA1 where.....
append IT_KNA1.
Endselect.

(or)

select... from KNA1 into table IT_KNA1 where.....

The total number of records statisfying the where condition will enter into the internal table. First one record enters work-area of the internal table then it gets appended into the body of the internal table, same procedure repeats for all the records.

For displaying the data which is in the internal table.

Loop at IT_KNA1.
WRITE :/IT_KNA1-CUST_NO, IT_KNA1-NAME, IT_KNA1-CNTRY.
ENDLOOP.

Similarly as mentioned above for entering data, for displaying also. The first record from the body of the internal table is fetched into the work-area and then output is displayed, and procedure repeats for all the records in the internal table.

TABLE-16



What is the Different Types and Usage of Views



The followings are different types of views:


- Database View (SE11)

Database views are implement an inner join, that is, only records of the primary table (selected via the join operation) for which the corresponding records of the secondary tables also exist are fetched. Inconsistencies between primary and secondary table could, therefore, lead to a reduced selection set.

In database views, the join conditions can be formulated using equality relationships between any base fields. In the other types of view, they must be taken from existing foreign keys. That is, tables can only be collected in a maintenance or help view if they are linked to one another via foreign keys.


- Help View ( SE54)

Help views are used to output additional information when the online help system is called.

When the F4 button is pressed for a screen field, a check is first made on whether a matchcode is defined for this field. If this is not the case, the help view is displayed in which the check table of the field is the primary table. Thus, for each table no more than one help view can be created, that is, a table can only be primary table in at most one help view.


- Projection View

Projection views are used to suppress or mask certain fields in a table (projection), thus minimizing the number of interfaces. This means that only the data that is actually required is exchanged when the database is accessed.

A projection view can draw upon only one table. Selection conditions cannot be specified for projection views.


- Maintenance View ( SE54 )

Maintenance views enable a business-oriented approach to looking at data, while at the same time, making it possible to maintain the data involved. Data from several tables can be summarized in a maintenance view and maintained collectively via this view. That is, the data is entered via the view and then distributed to the underlying tables by the system.

TABLE-15



What Are Different Types Of Internal Tables and Their Usage


Standard Internal Tables

Standard tables have a linear index. You can access them using either the index or the key. If you use the key, the response time is in linear relationship to the number of table entries. The key of a standard table is always non-unique, and you may not include any specification for the uniqueness in the table definition.

This table type is particularly appropriate if you want to address individual table entries using the index. This is the quickest way to access table entries. To fill a standard table, append lines using the (APPEND) statement. You should read, modify and delete lines by referring to the index (INDEX option with the relevant ABAP command). The response time for accessing a standard table is in linear relation to the number of table entries. If you need to use key access, standard tables are appropriate if you can fill and process the table in separate steps. For example, you can fill a standard table by appending records and then sort it. If you then use key access with the binary search option (BINARY), the response time is in logarithmic relation to
the number of table entries.


Sorted Internal Tables

Sorted tables are always saved correctly sorted by key. They also have a linear key, and, like standard tables, you can access them using either the table index or the key. When you use the key, the response time is in logarithmic relationship to the number of table entries, since the system uses a binary search. The key of a sorted table can be either unique, or non-unique, and you must specify either UNIQUE or NON-UNIQUE in the table definition. Standard tables and sorted tables both belong to the generic group index tables.

This table type is particularly suitable if you want the table to be sorted while you are still adding entries to it. You fill the table using the (INSERT) statement, according to the sort sequence defined in the table key. Table entries that do not fit are recognised before they are inserted. The response time for access using the key is in logarithmic relation to the number of
table entries, since the system automatically uses a binary search. Sorted tables are appropriate for partially sequential processing in a LOOP, as long as the WHERE condition contains the beginning of the table key.


Hashed Internal Tables

Hashes tables have no internal linear index. You can only access hashed tables by specifying the key. The response time is constant, regardless of the number of table entries, since the search uses a hash algorithm. The key of a hashed table must be unique, and you must specify UNIQUE in the table definition.

This table type is particularly suitable if you want mainly to use key access for table entries. You cannot access hashed tables using the index. When you use key access, the response time remains constant, regardless of the number of table entries. As with database tables, the key of a hashed table is always unique. Hashed tables are therefore a useful way of constructing and
using internal tables that are similar to database tables.


Index Tables

Index table is only used to specify the type of generic parameters in a FORM or FUNCTION. That means that you can't create a table of type INDEX.

Internal tables are not DB tables. Standard and Sorted tables in combined are basically called as Index tables and there nothing else. Here is the hierarchy


ANY TABLE
|
------------------------------------
| |
Index Tables Hashed Table
|
------------------------------------
| |
Standard Table Sorted Table

TABLE-14


Difference between extract and collect statements


What is the difference between 'extract' and 'collect' statements?

Once you have declared the possible record types as field groups and defined their structure, you can fill the extract dataset using the following statements:

EXTRACT .

When the first EXTRACT statement occurs in a program, the system creates the extract dataset and adds the first extract record to it. In each subsequent EXTRACT statement, the new extract record is added to the dataset.

Each extract record contains exactly those fields that are contained in the field group , plus the fields of the field group HEADER (if one exists). The fields from HEADER occur as a sort key at the beginning of the record. If you do not explicitly specify a field group , the EXTRACT statement is a shortened form of the statement extracts used in field groups (version 2.x - obsolete these days as noone uses field groups anymore), and collect is used to accumulate the contents of a field if X no. of keys are the same.

EXTRACT HEADER.

When you extract the data, the record is filled with the current values of the corresponding fields. As soon as the system has processed the first EXTRACT statement for a field group , the structure of the corresponding extract record in the extract dataset is fixed. You can no longer insert new fields into the field groups and HEADER. If you try to modify one of the field groups afterwards and use it in another EXTRACT statement, a runtime error occurs.

By processing EXTRACT statements several times using different field groups, you fill the extract dataset with records of different length and structure. Since you can modify field groups dynamically up to their first usage in an EXTRACT statement, extract datasets provide the advantage that you need not determine the structure at the beginning of the program.

Collect:

When the line is inserted, the system checks whether there is already a table entry that matches the key. If there is no corresponding entry already in the table, the COLLECT statement has the same effect as inserting the new line. If an entry with the same key already exists, the COLLECT statement does not append a new line, but adds the contents of the numeric fields in the work area to the contents of the numeric fields in the existing entry.

You should only use the COLLECT statement if you want to create summarized tables. If you use other statements to insert table entries, you may end up with duplicate entries.

TABLE-13


Create a table maintance program for a z table

In transaction SE11, in the attribute tab of your z table check table maintenance check box. Go to SM30 transaction, enter the ztable name and click on maintain button. Here you can enter new entries into the ztable .

Or

You can create a PARAMETER TRANSACTION for the transaction for SM30 .


Follow these steps :

1. go to transaction SE93 , give your own transaction code say ztran_tab, for maintaining your ztable.


2. Click on create button and check the radio button Transaction with parameters (PARAMETER TRANSACTION) and click on the tick button.


3. In the next screen enter default values:
transaction : SM30
check the check box skip initial screen


4. Scroll down you will find a table control for default values

--------------------------------------------------------------------------------

Name of the screen field | value

--------------------------------------------------------------------------------

VIEWNAME | your ztable name
SHOW | X


Save your work.


Now as you have created a custom transaction for maintaining your ztable this transaction can be called from any program with CALL transaction 'XXX'.

TABLE-12



Trace when a variant of a report was created


To find out the Date and Time of the user saving a Variant.


Use SE16 and browse table VARID.


Look for the fields :-


ENAME -> User Name

EDAT -> Date of saving the variant

ETIME -> Time of saving the variant

TABLE-11



Output Table Fields to a List

When you're looking at the structure of a table, SAP will let you print the structure, but it
won't let you save the structure. This can be annoying. This report outputs the table structure
to a list. At this point the user can use the System->List->Save->Local file command to save
the list to a file.


Output Table Fields to a List


*&---------------------------------------------------------------------*
*& Report YTABFLDS *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*


REPORT YTABFLDS .

TABLES: DD02L, DD03L, DD04T.


PARAMETERS THETABLE LIKE DD02L-TABNAME OBLIGATORY.

DATA: BEGIN OF MYTABLE,

TABNAME LIKE DD02L-TABNAME,

AS4LOCAL LIKE DD02L-AS4LOCAL,

AS4VERS LIKE DD02L-AS4VERS,

END OF MYTABLE.


SELECT SINGLE TABNAME AS4LOCAL AS4VERS INTO MYTABLE FROM DD03L

WHERE TABNAME = THETABLE.

WRITE: / MYTABLE-TABNAME, 11 MYTABLE-AS4LOCAL, 13 MYTABLE-AS4VERS.

SELECT * FROM DD03L

WHERE TABNAME = MYTABLE-TABNAME AND

AS4LOCAL = MYTABLE-AS4LOCAL AND AS4VERS = MYTABLE-AS4VERS.

WRITE: / DD03L-FIELDNAME, 11 DD03L-KEYFLAG, 13 DD03L-ROLLNAME,

24 DD03L-CHECKTABLE, 35 DD03L-INTTYPE, 37 DD03L-REFTABLE,

48 DD03L-DATATYPE.

SELECT SINGLE * FROM DD04T

WHERE ROLLNAME = DD03L-ROLLNAME AND

AS4LOCAL = MYTABLE-AS4LOCAL AND AS4VERS = MYTABLE-AS4VERS AND

DDLANGUAGE = 'E'.

WRITE: 53 DD04T-DDTEXT.

ENDSELECT.

TABLE-10



Which table is the developer key stored in?


If you would like to look up at your developer key and save it and have it available for the next system refresh.


The table name is DEVACCESS and can be viewed with SE16 and SE11.


For new ABAP developer, you will be prompt for the developer if you are trying to create a program using the standard SAP naming convention.


Customer own created program should all start with a "Y" or "Z".

TABLE-9



How to create a Dynamic Internal Table or Array?


Can you create an internal table dynamically? (at run time)


Yes , you can create a Dynamic Internal table .Just chek out this program .


type-pools : abap.
field-symbols: type standard table,
,
.
data: dy_table type ref to data,
dy_line type ref to data,
xfc type lvc_s_fcat,
ifc type lvc_t_fcat.
selection-screen begin of block b1 with frame.
parameters: p_table(30) type c default 'T001'.
selection-screen end of block b1.
start-of-selection.
perform get_structure.
perform create_dynamic_itab. **********Creates a dyanamic internal table**********
perform get_data.
perform write_out.
form get_structure.
data : idetails type abap_compdescr_tab,
xdetails type abap_compdescr.
data : ref_table_des type ref to cl_abap_structdescr.
* Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( p_table ).
idetails[] = ref_table_des->components[].
loop at idetails into xdetails.
clear xfc.
xfc-fieldname = xdetails-name .
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
append xfc to ifc.
endloop.
endform.
form create_dynamic_itab.
* Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = ifc
importing
ep_table = dy_table.
assign dy_table->* to .
* Create dynamic work area and assign to FS
create data dy_line like line of .
assign dy_line->* to .
endform.

form get_data.
* Select Data from table.
select * into table
from (p_table).
endform.
Write out data from table.
loop at into .
do.
assign component sy-index
of structure to .
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
write:/ .
else.
write: .
endif.
enddo.
endloop.

.......................................................................................................................................


REPORT ZCLUST1 .
*
* Example: how to create a dynamic internal table
*
* The dynamic internal table stucture
DATA: BEGIN OF STRUCT OCCURS 10,
FILDNAME(8) TYPE C,
ABPTYPE TYPE C,
LENGTH TYPE I,
END OF STRUCT.

* The dynamic program source table
DATA: BEGIN OF INCTABL OCCURS 10,
LINE(72),
END OF INCTABL.

DATA: LNG TYPE I, TYPESRTING(6).

* Sample dynamic internal table stucture
STRUCT-FILDNAME = 'field1'. STRUCT-ABPTYPE = 'c'. STRUCT-LENGTH = '6'.
APPEND STRUCT. CLEAR STRUCT.

STRUCT-FILDNAME = 'field2'. STRUCT-ABPTYPE = 'd'.
APPEND STRUCT. CLEAR STRUCT.

STRUCT-FILDNAME = 'field3'. STRUCT-ABPTYPE = 'i'.
APPEND STRUCT. CLEAR STRUCT.

* Create the dynamic internal table definition in the dyn. program
INCTABL-LINE = 'program zdynpro.'. APPEND INCTABL.
INCTABL-LINE = 'data: begin of dyntab occurs 10,'. APPEND INCTABL.

LOOP AT STRUCT.
INCTABL-LINE = STRUCT-FILDNAME.
LNG = STRLEN( STRUCT-FILDNAME ).

IF NOT STRUCT-LENGTH IS INITIAL .
TYPESRTING(1) = '('.
TYPESRTING+1 = STRUCT-LENGTH.
TYPESRTING+5 = ')'.
CONDENSE TYPESRTING NO-GAPS.
INCTABL-LINE+LNG = TYPESRTING.
ENDIF.

INCTABL-LINE+15 = 'type '.
INCTABL-LINE+21 = STRUCT-ABPTYPE.
INCTABL-LINE+22 = ','.
APPEND INCTABL.
ENDLOOP.
INCTABL-LINE = 'end of dyntab. '.
APPEND INCTABL.

* Create the code processes the dynamic internal table
INCTABL-LINE = ' '. APPEND INCTABL.
INCTABL-LINE = 'dyntab-field1 = ''aaaaaa''.'. APPEND INCTABL.
INCTABL-LINE = 'dyntab-field1 = ''19970814''.'. APPEND INCTABL.
INCTABL-LINE = 'dyntab-field1 = 1.'. APPEND INCTABL.
INCTABL-LINE = 'append dyntab.'. APPEND INCTABL.
INCTABL-LINE = ' '. APPEND INCTABL.
INCTABL-LINE = 'loop at dyntab.'. APPEND INCTABL.
INCTABL-LINE = 'write: / dyntab.'. APPEND INCTABL.
INCTABL-LINE = 'endloop.'. APPEND INCTABL.

* Create and run the dynamic program
INSERT REPORT 'zdynpro'(001) FROM INCTABL.
SUBMIT ZDYNPRO.


.......................................................................................................................................


or Just try out this simpler dynamic internal tables

DATA: itab TYPE STANDARD TABLE OF spfli,
wa LIKE LINE OF itab.

DATA: line(72) TYPE c,
list LIKE TABLE OF line(72).

START-OF-SELECTION.
*line = ' CITYFROM CITYTO '.
line = ' AIRPTO '.
APPEND line TO list.

SELECT DISTINCT (list)
INTO CORRESPONDING FIELDS OF TABLE itab
FROM spfli.

IF sy-subrc EQ 0.
LOOP AT itab INTO wa.
* WRITE: / wa-cityfrom, wa-cityto.
WRITE :/ wa-airpto.
ENDLOOP.
ENDIF.






TABLE-8



What is use of using HASHED TABLE?


Hashed table is useful when your have to work with very big internal table and to read it with
"READ TABLE WITH KEY ..."

The time access is constant !


Definition of a Hashed Table:


"Defines the table as one that is managed with an internal hash procedure. You can imagine a hashed table as a set, whose elements you can address using their unique key. Unlike standard and sorted tables, you cannot access hash tables using an index. All entries in the table must have a unique key.


Access time using the key is constant, regardless of the number of table entries.


You can only access a hashed table using the generic key operations or other generic operations (SORT, LOOP, and so on). Explicit or implicit index operations (such as LOOP ... FROM to INSERT itab within a LOOP) are not allowed."

As long as your records has unique key(s), using hash table will give you a huge performance gain when dealing with large dataset. assuming in your case, 10000 record , and if the key is unique, use hash table. The main use of hash tables is for looking up fixed information from a key. So if you have a report that has personnel number and you want to display their name, you could use a hash table.


Thus:
Code:

types: begin of typ_pernr,
pernr like pa0001-pernr,
ename like pa0001-ename,
end of typ_pernr.
data: ls_pernr type typ_pernr,
lt_pernr type hashed table of typ_pernr with unique key pernr.
...
select pernr ename into table lt_pernr from pa0001.
...
loop at itab.
read table lt_pernr with table key pernr = itab-pernr
into ls_pernr.
write: ls_pernr-ename, itab-data.
endloop.

TABLE-7



How to get the field descriptions of a table?


I need to get the associated data element descriptions of all the fields in a table. I think there's a way to do that using the SELECT statement.

Can you please give me in detail, the various steps and methods to find the corresponding SAP tables and fields for a particular transaction code, for example (CS03).


Do the following 2 steps. Then create your ABAP program accordingly with the SELECT statement.

1. From table DD03L, give your tablename and get all of its field names and corresponding data element names.

2. From table DD03T, get the description of each data element you have got in step 1.

Then Use Function Module DDIF_FIELDINFO_GET


The sample program will look like this:


REPORT ZTABLEFIELDNAME.

TABLES: DFIES,
X030L.

DATA: BEGIN OF INTTAB OCCURS 100.
INCLUDE STRUCTURE DFIES.
DATA: END OF INTTAB.

PARAMETERS: TABLENM TYPE DDOBJNAME DEFAULT 'MSEG',
FIELDNM TYPE DFIES-FIELDNAME DEFAULT 'MENGE'.

call function 'DDIF_FIELDINFO_GET'
exporting
tabname = TABLENM
FIELDNAME = FIELDNM
LANGU = SY-LANGU
* LFIELDNAME = ' '
* ALL_TYPES = ' '
* IMPORTING
* X030L_WA = WATAB
* DDOBJTYPE =
* DFIES_WA =
* LINES_DESCR =
TABLES
DFIES_TAB = INTTAB
* FIXED_VALUES =
EXCEPTIONS
NOT_FOUND = 1
INTERNAL_ERROR = 2
OTHERS = 3.

if sy-subrc <> 0.
WRITE:/ 'Field name not found'.
endif.

LOOP AT INTTAB.
WRITE:/ INTTAB-TABNAME, INTTAB-FIELDNAME, INTTAB-FIELDTEXT.
ENDLOOP.

*** End of Program

OR

Step 1.


Run the transaction and click on System -> Status. Note the program name shown under the transaction code.

Step 2.

Run SE49 and enter the program name you identified in step 1 (SAPLCSDI) and then press enter.

This will identify the tables used, however, as you want to know the fields used as well then you may have to resort to looking at the actual code (get a developer involved if you're not one) using transaction SE80.

In this case the transaction CS03 is assigned to a screen with a function group so it's a slightly tricker process, hence the need for a developers service.

For all the tables, descriptions and fields you can refer to these tables:
DD02L : ALL SAP TABLE NAMES
DD02T : DESCRIPTION OF TABLE NAMES
DD03L : FIELDS IN A TABLE.

TABLE-6



Quick Note on Design of secondary database indexes and logical databases

Secondary Database

First it must be stated that table design is a more logical work while index design is rather technical. In table design it might make sense to place certain fields (client, company code, ...) in the beginning. In index design, this is not advisable. Very important for an index is that it contains very selective fields in the beginning. Those are fields like object numbers. Not selective are client, company code, ...

Indexes should be small (few fields). The Database optimizer can combine two or more indexes to execute a query.

Indexes of one table should be disjoint (have few common fields), in order not to confuse the optimizer which index to use.

Note that each index slows the inserts into the table down. Updates are only slowed down if indexed fields are updated. In general, heavy inserted tables should have only few indexes while heavy selected tables might have more.


Logical Database

Using logical databases is a good method to write reports. Logical databases can be optimized centrally. But ensure that the structure of the logical database fits well to your report. Otherwise the effect can be the opposite.


Please clarify my doubts:


1. What is meant by secondary index?
2. What is the purpose of cursor?


If you cannot use the primary index to determine the result set because, for example, none of the fields primary index occur in the WHERE or HAVING clause, the system searches through the entire table (full table scan). For this case, you can create secondary indexes, which can restrict the number of table entries searched to form the result set.

You should only create secondary indexes, for database tables from which you mainly read, since indexes have to be updated each time the database table is changed. secondary indexes should contain columns that you use frequently in a selection, and that are as highly selective as possible to improve performance..

Cursor is used to read the data:-----

When you use a cursor to read data, you decouple the process from the SELECT statement. To do this, you must open a cursor for a SELECT statement. Afterwards, you can place the lines from the selection into a flat target area. An open cursor points to an internal handler, similarly to a reference variable pointing to an object.

Cursor is used for one more purpose that is ,You can set the cursor on the current list dynamically from within your program. You can do this to support the user with entering values into input fields or selecting fields or lines. To set the cursor we use SET CURSOR command.

SET cursor .

This statement sets the cursor to column of line of the output window.

TABLE-5



Difference between a check table and a value table


Value Table

This is maintained at Domain Level.

When ever you create a domain , you can entered allowed values. For example you go to Domain SHKZG - Debit/credit indicator. Here only allowed values is H or S.

When ever you use this Domain, the system will forces you to enter only these values.

This is a sort of master check . To be maintained as a customization object. This mean that if you want to enter values to this table you have to create a development request & transport the same.


Check table

For example you have Employee master table & Employee Transaction table.

When ever an employee Transacts we need to check whether that employee exists , so we can refer to the employee master table.

This is nothing but a Parent & Child relationship . Here data can be maintained at client level , no development involved.

As per DBMS what we call foregin key table, is called as check table in SAP.


There is 1 more important Difference in Value Table and Check Table is that:

1. The contents of the check will be used as an input help(F4 Help) for a particular field on which a check table is assigned. But the contents of Value Table are never used in Input Help.

The Heirarchy which decides from where to used the Input Help is:

1. Input help defined explicitly in ABAP Program or Dialog Module.

2. Input Help Attached to the referenced Database Table field.

3. Using the contents of Check Table as an input help if neither (1) or (2) help are there.

4. Input help from Fixed value or Value range given in Domain.

TABLE-4



The Different Types of SAP Tables


What is transparent, cluster and pool table? Where and when we use these tables?


Transparent Table :
Exists with the same structure both in dictionary as well as in database exactly with the same data and fields.

Pooled Table : Pooled tables are logical tables that must be assigned to a table pool when they are defined. Pooled tables are used to store control data. Several pooled tables can be cominied in a table pool. The data of these pooled tables are then sorted in a common table in the database.

Cluster Table : Cluster tables are logical tables that must be assigned to a table cluster when they are defined. Cluster tables can be used to strore control data. They can also be used to store temporary data or texts, such as documentation.


Could anyone tell me what is the major difference between Standard tables, Pooled tables and Clusterd Tables?

A transparent table is a table that stores data directly. You can read these tables directly on the database from outside SAP with for instance an SQL statement.

Transparent table is a one to one relation table i.e. when you create one transparent table then exactly same table will create in data base and if is basically used to store transaction data.

A clustered and a pooled table cannot be read from outside SAP because certain data are clustered and pooled in one field.

One of the possible reasons is for instance that their content can be variable in length and build up. Database manipulations in Abap are limited as well.

But pool and cluster table is a many to one relationship table. This means many pool table store in a database table which is know as table pool.

All the pool table stored table in table pool does not need to have any foreign key relationship but in the case of cluster table it is must. And pool and cluster table is basically use to store application data.

Table pool can contain 10 to 1000 small pool table which has 10 to 100 records. But cluster table can contain very big but few (1 to 10) cluster table.

For pool and cluster table you can create secondary index and you can use select distinct, group for pool and cluster table. You can use native SQL statement for pool and cluster table.

A structure is a table without data. It is only filled by program logic at the moment it is needed starting from tables.

A view is a way of looking at the contents of tables. It only contains the combination of the tables at the basis and the way the data needs to be represented. You actually call directly upon the underlying tables.

TABLE-3



Difference between Work Area and Header Line


While adding or retrieving records to / from internal table we have to keep the record temporarily.

The area where this record is kept is called as work area for the internal table. The area must have the same structure as that of internal table. An internal table consists of a body and an optional header line.

Header line is a implicit work area for the internal table. It depends on how the internal table is declared that the itab will have the header line or not.


E.g.

data: begin of itab occurs 10,
ab type c,
cd type i,
end of itab. " this table will have the header line.

data: wa_itab like itab. " explicit work area for itab

data: itab1 like itab occurs 10. " table is without header line.


The header line is a field string with the same structure as a row of the body, but it can only hold a single row.


It is a buffer used to hold each record before it is added or each record as it is retrieved from the internal table. It is the default work area for the internal table.

TABLE-2



Function to Display All the Columns of any Table Work Area


Advantage :-

This function can be used as a quick write report with very less coding to any passed internal table.

use & enjoy.


Note:-


1. Created quick ALV function to display alv for any internal table passed.
2. Developed dynamic program generation ( we can execute program dynamically without passing request to the production server)
3. Created a dynamic program to display any FOXPRO table into ABAP ALV.

Feel free to contact for your doubts.

Thanks

Calling the function :-

CALL FUNCTION 'ZPREM_QLINE' TABLES zf = internal_table .

**********

create a function & define ZF in the tables parameter name without Type spec.

************source code

FUNCTION ZPREM_QLINE.
FIELD-SYMBOLS: .
DO.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE ZF TO .
IF SY-SUBRC <> 0. EXIT. ENDIF.
if sy-index = 1. write / ' '. endif.
if sy-index = 25. exit. endif.
WRITE : , sy-vline.
ENDDO.
ENDFUNCTION.

TABLE-1



Steps to Creating domains, Data Elements, Tables


To give you the steps for creating table:.

There are two approach in creating a table.

1. Bottom-up approach
2. Top-down approach.

Both are valid and you can choose which approach is suitable for you. I always use the bottom-up approach. Here are the steps to create the tables with this approach.

1. SE11 will take you to the DDIC and enter the name of the new table to be created. Let us say Zname. Click create.

2. Enter the short discription of the table and enter the field of the table. If it is primary key and you have to check the box.

3. Enter the data element and double click it, you will be asked to save and will take you to data element discription page. Enter the short discription of the data element and enter the information of domain like the length of field and type of field.

4. If you wanted to use the existing domain then its fine, or else, you have to create one. Enter the domain name in the data element page and double click it. Page will ask to save and jump to domain creation page.

5. In the domain page, you have to save the information which you have already given in the data elements page and check it. Before going to data element page, you have to activate the domain.

6. Go to data element page and save, check and activate.

7. Go to main table page and save, check, and activate.

8. Also, you have to save the technical settings of the table.

The table is now ready for operation. You can use it in your program or you can use it to enter information.

Check table: It is the table which will have all the information about the Foreign keys which are the primary keys in the check table.

It can be created by creating the foreign key from the main table. Click foreign key in the main table and it will take you to a page which will ask for table name and field to which foreign key relation has to be associated. Enter the information and you can create the check table automatically.

SM30 is used for maintenance of the table, that is to realease the errors occured during the creation of the table.