Wednesday, 24 December 2014

Delivery Class

You use the delivery class to control the transport of table data for an installation, upgrade, or client copy and transports between customer systems. The delivery class is also used in the extended table maintenance.

Features

There are the following development classes:
●  A- Application table (master and transaction data).
●  C- Customer table, data is only maintained by the customer.
●  L- Table for storing temporary data.
●  G- Customer table, SAP can insert new data records but cannot overwrite or delete existing ones. The customer namespace must be defined in table TRESC. To define the customer namespace use report RDDKOR54. You can start it directly from the table maintenance by choosing Maintain Customer Namespace on the Delivery and Maintenance tab.
●  E- System table with its own namespace for customer entries. The customer namespace must be defined in table TRESC. To define the customer namespace use report RDDKOR54. You can start it directly from the table maintenance by choosing Maintain Customer Namespace on the Delivery and Maintenance tab.
●  S- System table, data changes have the status of program changes.
●  W- System table (for example table of the development environment) whose data is transported with its own transport objects (such as R3TR PROG, R3TR TABL and so on).

Behavior During Client Copy

Only the data of client-dependent tables is copied.
●  Class C, G, E, S- The data records of the table are copied to the target client.
●  Class W, L- The data records of the table are not copied to the target client.
●  Class A- Data records are only copied to the target client if explicitly requested (parameter option). It is not sensible to transport such data, but this is supported nevertheless to allow the entire client environment to be copied.

Behavior During Installation, Upgrade and Language Import

The behavior of client-dependent tables differs from that of cross-client tables.
Client-Dependent Tables
●  Class A and C- Data is only imported into client 000. The system overwrites the existing data records.
●  Class E, S and W- Data is imported into all clients. The system overwrites the existing data records.
●  Class G- The system overwrites the existing data records in client 000. In all other clients, the system inserts new data records, but existing data records are not overwritten.
●  Class L- No data is imported.
Cross-Client Tables
●  Classes A, L and C- No data is imported.
●  Classes E, S, and W- Data is imported. The system overwrites the existing data records with the same key.
●  Class G- The system inserts non-existent data records, but does not overwrite existing data records.

Behavior During Transport Between Customer Systems

Data records of tables having delivery class L are not imported into the target system. Data records of tables having delivery classes A, C, E, G, S and W are imported into the target system (for client-dependent tables this is done for the target clients specified in the transport).

Use of the Delivery Class in the Extended Table Maintenance

The delivery class is also used in the Extended Table Maintenance (transaction code SM30). The maintenance interface generated for a table performs the following checks:
●  It is not possible to transport the entered data using the transport connection of the generated maintenance interface for tables having delivery classes W and L.
●  Data that is entered is checked to see if it violates the namespace defined in table TRESC. If the data violates the namespace, the system rejects the input.

How to create table maintenance generator?

Go to Se11, give the table name and click on change. Then Go to utilities--> Table maintenance generator.
In the table maintenance generator screen, we should give Authorization Group, Function Group name (Function Group name can be same as table name), Maintenance type can be one step or two step, usually we will create with one step. we should give maintenance screen number.
Authorization Group  used to group the logically related objects. It helps us to group dictionary tables for the purpose of authorization checking (Table TDDAT contains its list) . To create go to SE54, give the table name and choose authorization group and then click on create/change.
Function Group name is the name of the group to which the generated maintainence would belong.
Package if you want to assign it to a particular package.
After clicking on create button, a table maintenance generator will be created.
To check it go to SM30 . In SM30, we find display, Maintain options.
We can view the table contents by choosing Display and we can create table entries by choosing Maintain.

Single step and Two step in TMG

You can select either one step or two step. Assign Screen numbers (To assign Screen numbers click on the button 'Find Scr no'. It will propose screen no's)

Then Create. Save 

Single step: Only overview screen is created i.e. the Table Maintenance Program will have only one screen where you can add, delete or edit records. 
Two step: Two screens namely the overview screen and Single screen are created. The user can see the key fields in the first screen and can further go on to edit further details.

Tuesday, 23 December 2014

Extended Table Maintenance Events

Events allow you to change the generated table maintenance dialog at predefined positions, which cannot be reached by user modules in the screen flow logic.

The user routines are called dynamically at runtime. For this reason, the routines must be in a user include in the table/view maintenance dialog function group. All extended table maintenance global data is available. An interface is only required for events 22 and AF.
The events can be additions or replacements.
 

Additional events

Event 01 before saving the data in the database

Event 02 after saving the data in the database

Event 03 before deleting data in the display

Event 04 after deleting data in the display

Event 05 when inserting a new entry

Event 06 after completely performing the function 'Get original'

Event 07 before correcting the contents of a selected field

Event 08 after correcting the contents of a selected field

Event 09 after 'Get original' for one entry

Event 10 after creating the change request header entry  

Event 11 after changing a key entry in the change request  

Event 12 after changing the key entries in the change request

Event 13 end processing (leave main function module)

Event 14 after lock/unlock in main function module  

Event 15 before retrieving deleted entries  

Event 16 after retrieving deleted entries

Event 17 before printing entries  

Event 18 after the data change check  

Event 19 after initializing global variables, field symbols, etc.

Event 20 after input in date subscreen (time-dep.tables/views)

sapurl_link_0001_0020_0034

 Event 21 fill hidden fields  

Event 22 go to long text maintenance for other languages  

Event 23 before calling address maintenance screen

Event 25 at start of maintenance dialog

Event 26 before displayed data is output in a list  

Event 27 after filling a GUID field


Replacement events

Event AA instead of the standard data read routine

 Event AB instead of the standard database change routine

Event AC instead of the standard 'Get original' routine  

Event AD instead of the standard RO field read routine  

Event AE instead of the standard positioning code  

Event AF instead of reading texts in other languages

Event AG instead of 'Get original' for texts in other languages

Event AH instead of database changes for texts in other languages  

Event ST GUI menu main program name



Create table event

Validation on table maintenance

While creating the tables, sometimes we may need to update the table fields in the background. For example, if we create a table with 10 fields and in those 10 fields there are 2 fields which are User name and the Date, these 2 fields should update automatically when a record Inserted/Updated in the table. It also can be used when we want provide various validations on creating, changing or saving entries in a table.

Event Handling

When we provide event handling on table maintenance, table fields will be updated automatically when a new record inserted into the table or an existed record changes through the table maintenance generator.
To achieve the event handling in table maintenance, we need to create a table maintenance generator and then create events. Process is as follows:

Create a table ZTAB with the following fields:



Create a table maintenance generator for the table:

To create table maintenance generator go Utilities -> Table Maintenance Generator and provide following information:
Authorization Group: &NC&
Function group: Any suitable FC Eg: ZBC420XX
Maintenance type: Two Step
Maint. screen no: Overview screen 8005
                             Single screen    8006
Click on Create.

Create Events for table Maintenance:

To create events on table maintenance go to Environment -> Modification -> Events -> New Entries


List of events available:

Choose maintenance event 05-Creating New Entry and provide a name of the event (This will become perform/subroutine).
Click on Editor Button to provide event handling code.

A popup will be appear, It will ask to create an include program, in which we'll write the event handling code.
Click on continue.


Write the following code in include for this event.
FORM new_entry.
  DATA: v_nchar TYPE i.
  CONSTANTS: c_conlimit TYPE i VALUE 3.
  ztab-changed_by = sy-uname.         " current user
  ztab-create_date = sy-datum.        " current date
  ztab-create_time = sy-uzeit.        " current time
* Validation on Country Field
  v_nchar = STRLEN( ztab-country ).
  IF v_nchar NE c_conlimit.
    MESSAGE i536.
  ENDIF.
ENDFORM.                    "New_Entry

Create Transaction Code:

Create a transaction code to run the table maintenance generator.
Go to Tcode SE93
Transaction code: ZTAB
Short text: Test Table Maintenance Events
Start Object: Transaction with parameters (Parameter Transaction)

Transaction: SM30
Skip first Screen: Check ON
Default Values:
View Name      ZTAB
Update           X


Execute the transaction code:

Execute the transaction code ZTAB and click on New Entries button.


Now provide a valid value in country field and remain blank another fields.

Click Enter (NEW_ENTRY event will trigger) and current User, date and time will be automatically filled in respective fields.

Save the entry and check in table.

One more entry by table maintenance:
Write country code as US in place of USA and press Enter
Information message shown that entry was not saved.

Now provide USA as country code and save entry.

Monday, 22 December 2014

current execution is a batch job (background) or a dialog job(foreground)

SY-BATCH indicates if the current execution is a batch job (background) or a dialog job(foreground). If sy-batch is 'X', then the execution is in the background.

Suppose if you want to write logic for 2 diff. situations.

1. when program runs in foreground output shold be in excel

2.  when program runs in background output shold store in application server as a file.

To determine whether program is running forground or background we will can
use  SY-BATCH

IF SY-BATCH =  'X'.

  Background.

ELSE.

FOREground
ENDIF.

Different behviour in background processing from foreground processing

BDC for table control is totally depending upon the screen resolution.

if you try it on background it will show different behavior than foreground. It will also behave differently for different PC .

So my suggestion is go for BAPI.   

Many SAP transactions behave differently in online mode and in Batch mode and this mode is determined by the SY-BINPT variable that can be controlled using the OPTIONS command in addition to the CALL TRANSACTION.
 For example, the error message that usually comes in status bar while you are running the transaction online might appear in a popup window when you are running that in batch. This will make your fields disabled for input. This OPTIONS addition will remove this problem
The way to use the OPTIONS addition.
Declare a work area of type CTU_PARAMS
Fill the fields of CTU_PARAMS The field NOBINPT should be set to ‘X’.
This will set the SY-BINPT to space. So now the transaction which you will be calling will run in online mode.
Example.
clear X_OPTIONS.
X_OPTIONS-DISMODE = 'E'.
X_OPTIONS-UPDMODE = 'S'.
X_OPTIONS-CATTMODE = ' '.
X_OPTIONS-DEFSIZE = ' '.
X_OPTIONS-RACOMMIT = ' '.
X_OPTIONS-NOBINPT = 'X'.
X_OPTIONS-NOBIEND = ' '.
call transaction 'BP' using T_BDCDATA[] options from X_OPTIONS.
Note:
Do not use the MODE & UPDATE additions when you are using OPTIONS. The mode & update values are passed in the CTU_PARAMS structure.