0% found this document useful (0 votes)
36 views29 pages

Study at NTG

Table maintenance generator

Uploaded by

Mostafa Hassanin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views29 pages

Study at NTG

Table maintenance generator

Uploaded by

Mostafa Hassanin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Using selection-screen in Table

Maintenance Generator
Business Requirement:
Filtering data in Table Maintenance Generator(TMG) is cumbersome and definitely has
a very limited functionality.

You can also filter the data from the Overview screen, but that too is not very

flexible
Sometimes users might want to have more flexible functionality to select the data from
the view/table viz., a selection-screen to select the data.

Add selection-screen to TMG of a table/view:


We all agree to the fact that the TMG function group should never be manually altered &
any modifications should be handled via TMG events. In this particular case we need to
modify the way standard SAP reads the data from the underlying table/view into the
TMG screen. We can therefore make use of the Event AA: Instead of the Standard Data
Read Routine.

For demonstration purpose, i've created a custom maintenance view ZVSFLIGHT for
the
table SFLIGHT.
The TMG is defined for the maintenance view and the callback routine for the Event 'AA'
is
defined.

For the sake of simplicity, I've created a selection-screen with 2 elements: A parameter
for Airline ID & and Select-option for the flight date.

*----------------------------------------------------------------------*
***INCLUDE LZVSFLIGHTF01 .
*----------------------------------------------------------------------*
DATA: gv_fldate TYPE s_date.
*--------------------------------------------------------------------*
* Custom Selection-Screen
*--------------------------------------------------------------------*
SELECTION-SCREEN: BEGIN OF SCREEN 100 TITLE text-s01.
PARAMETERS: p_carrid TYPE s_carr_id.
SELECT-OPTIONS: s_fldate FOR gv_fldate.
SELECTION-SCREEN: END OF SCREEN 100.

*&---------------------------------------------------------------------*
*& Form sub_zvsflight_read_data
*&---------------------------------------------------------------------*
* Read the Flight data
*----------------------------------------------------------------------*
FORM sub_zvsflight_read_data.

* Read the SAP documentation on Event AA: Instead of the Standard Data Read
Routine
*
http://help.sap.com/saphelp_nw04s/helpdata/en/91/ca9f56a9d111d1a5690000e82deaa
a/content.htm

DATA: ls_temp_data TYPE zvsflight.

* Call the user defined selection-screen


CALL SELECTION-SCREEN 100 STARTING AT 25 10.

* Read the data into int. table TOTAL


PERFORM get_data_zvsflight.

* Filter the data from TOTAL


LOOP AT total.
MOVE <vim_total_struc> TO ls_temp_data.
* Check if the record satisfies the input criteria
IF ls_temp_data-carrid <> p_carrid OR
ls_temp_data-fldate NOT IN s_fldate.
DELETE total. "Doesn't satisfy condition, delete it!!!
ENDIF.
ENDLOOP.

ENDFORM. "SUB_ZVSFLIGHT_READ_DATA

Please note that the data can be loaded into the internal table TOTAL using the subroutines:

 TABLE_GET_DATA --> TMG of a table

 GET_DATA_VIEWNAME --> TMG of a view

You can read the data from the underlying table using Open SQL statements, but i prefer to use
these subroutines.

Voila!
When the user tries to maintain the data using this view, he/she will be presented with a
selection-screen pop-
up.
The data input will be used to filter the data which is displayed in the TMG overview screen.

//////////////////////////////////////////////////////////////////////////////////////////////

Update and Create Events in Table Maintenance Generator

INTRODUCTION:
I got the requirement to capture the Created by Created on and
Updated by Updated on logs for the custom table using Table
Maintenance Generator events.
Here is the step by step process to capture the table change logs.
Step 1:
Create a custom table.

Step 2:
Click on utilities, go to table maintenance generator.
Step 3:
Enter the details of the function group, propose screen numbers
and click on save, we will provide the package name.
There are two different maintenance screen types

1. one step and

2. Two step
one step

 In one step we will have only overview screen.

 Will able to see and maintain only through the overview


screen.

Two step

 We will have two screens. overview screen and


Single/Detail screen.

 overview screen will contain key fields and Single screen


will contain all the other fields.
Step 4:
For TMG events, in the menu Click on Environment--
>Modifications-->Events
Following screen will be displayed. From the below list i have
used Update and Create Events.
Update Event
Select the Update event and press enter, the following screen
will appear.
Source Code

----------------------------------------------------------------
------
***INCLUDE LZTEMP_DTLSF01.
----------------------------------------------------------------
------
FORM update.
** -- Data Declarations
DATA: lv_timestamp TYPE tzonref-tstamps.
*-- Time stamp conversion
CALL FUNCTION 'ABI_TIMESTAMP_CONVERT_INTO'
EXPORTING
iv_date = sy-datum
iv_time = sy-uzeit
IMPORTING
ev_timestamp = lv_timestamp
EXCEPTIONS
conversion_error = 1
OTHERS = 2.
FIELD-SYMBOLS: <fs_field> TYPE any .
LOOP AT total.
CHECK <action> EQ aendern.
** -- Updated By
ASSIGN COMPONENT 'UPDTD_BY' OF STRUCTURE <vim_total_struc> TO
<fs_field>.
IF sy-subrc EQ 0.
<fs_field> = sy-uname.
ENDIF.
** -- Updated On
ASSIGN COMPONENT 'UPDTD_ON' OF STRUCTURE <vim_total_struc> TO
<fs_field>.
IF sy-subrc EQ 0.
<fs_field> = lv_timestamp.
ENDIF.
READ TABLE extract WITH KEY <vim_xtotal_key>.
IF sy-subrc EQ 0.
extract = total.
MODIFY extract INDEX sy-tabix.
ENDIF.
IF total IS NOT INITIAL.
MODIFY total.
ENDIF.
ENDLOOP.
ENDFORM.

Once the code is completed then we need check and activate the
include.Here we need to activate the below two objects.
Create Event
Select the Create event and press enter, the following screen will
appear.
Same process we have to go for the Create event.
Source Code

----------------------------------------------------------------
------
***INCLUDE LZTEMP_DTLSF02.
----------------------------------------------------------------
------
FORM create.
** -- Data Declarations
DATA: lv_timestamp TYPE tzonref-tstamps.
*-- Time stamp conversion
CALL FUNCTION 'ABI_TIMESTAMP_CONVERT_INTO'
EXPORTING
iv_date = sy-datum
iv_time = sy-uzeit
IMPORTING
ev_timestamp = lv_timestamp
EXCEPTIONS
conversion_error = 1
OTHERS = 2.
** -- Created On & Created By
ztemp_dtls-crtd_by = sy-uname.
ztemp_dtls-crtd_on = lv_timestamp.
ENDFORM.

Check and activate it.


Step 5:

Now To test the Update and Create events Go to Table


maintenance generator ( SM30 Tcode) and Click on maintain
button as per shown below.
Next, Create the data by clicking on new entries and click on
save then we will able to see the Create logs.
Update the existing data then click on save, then we will able to
see the Update logs.
Conclusion:

Following the above steps, we can see the table create and
update logs for a custom table, which contains the fields "Date
on which record was created" and "Name of the person who
created the object".

////////////////////////////////////////////////////////////////////////////////////////////////

ABAP – Function module


HR_INFOTYPE_OPERATION
June 12, 2015 at 3:21 pm (ABAP, ABAP HR, SAP)
Tags: ABAP, SAP

ABAP – Function module HR_INFOTYPE_OPERATION

objectid – object id from infotype

number – Personnel number

validityend – validity end date

validitybegin – validity begin date

record – infotype record values to be updated, inserted etc (will be structure of infortyoe you are

updating)
recordnumber – sequence nunber from infotype record you are updating

Operation – describes what operation is to be performed

COP = Copy

DEL = Delete

DIS = Display

EDQ = Lock/unlock

INS = Create

LIS9 = Delimit

MOD = Change

INSS = Create for Actions is not converted to Change

nocommit – commit yes(‘X’) / no(‘ ‘)

dialog_mode – dialog mode or not, default is ‘0’

Example coding for MOD operation

CONSTANTS: change TYPE pspar-actio VALUE ‘MOD’.

“This code is required and locks the record ready for modification

CALL FUNCTION ‘HR_EMPLOYEE_ENQUEUE’

EXPORTING

number = p_pernr.

“loop at p0071 into p_p0071. “added to put code in context

validitybegin = p_record-begda.

validityend = p_record-endda.

p_record-endda = pn-begda – 1.

CALL FUNCTION ‘HR_INFOTYPE_OPERATION’

EXPORTING

infty = ‘0071’

subtype = p_record-subty

objectid = P_record-objps

number = p_record-pernr “employeenumber

validityend = validityend

validitybegin = validitybegin
record = p_record

recordnumber = p_record-SEQNR

operation = change

nocommit = nocommit

dialog_mode = ‘0’

IMPORTING

return = return_struct

key = personaldatakey

EXCEPTIONS

OTHERS = 0.

“endloop.

“unlock record after modification

CALL FUNCTION ‘HR_EMPLOYEE_DEQUEUE’

EXPORTING

number = p_pernr.

Example coding for INS operation

CONSTANTS: insert TYPE pspar-actio VALUE ‘INS’.

“This code is required and locks the record ready for modification

CALL FUNCTION ‘HR_EMPLOYEE_ENQUEUE’

EXPORTING
number = p_pernr.

validitybegin = p_record-begda.

validityend = p_record-endda.

p_record-pernr = p_pernr

p_record-begda = pn-begda.

p_record-endda = validityend.

p_record-subty = p_SUBTY. “subtype of new entry

p_record-SCREF = p_SUBTY. “subtype of new entry

“plus populate any other fields you need to update


CALL FUNCTION ‘HR_INFOTYPE_OPERATION’

EXPORTING

infty = ‘0071’

subtype = p_record-subty

number = p_record-pernr “employeenumber

validityend = validityend

validitybegin = validitybegin

record = p_record

operation = insert

nocommit = nocommit

dialog_mode = ‘0’
IMPORTING

return = return_struct

key = personaldatakey

EXCEPTIONS

OTHERS = 0.

“unlock record after modification

CALL FUNCTION ‘HR_EMPLOYEE_DEQUEUE’

EXPORTING

number = p_pernr.

ABAP - Infotype record creation -


HR_INFOTYPE_OPERATION
Function Module HR_INFOTYPE_OPERATION
This function module enables you to maintain master data for employees. You can transfer one
data record. All validation checks take place that would take place in the individual maintenance
screens in the dialog.

Infotype Operation Types:


This operation defines which editing mode should be used to process the infotype in an action.

Operatio Description
n
COP Copy

DEL Delete

DIS Display

EDQ Lock/unlock

INS Create

LIS9 Delimit

MOD Change

INSS Create for Actions is not converted to


Change

Insert Infotype Record


When you create infotype records while processing actions, the system checks if an infotype
with the same subtype already exists. If it does, the system switches from "Create" to "Change".
It only makes sense to use the Create (INS) operation for the initial entry action.

REPORT ztest_notepad .
DATA:p0015 TYPE p0015.
DATA:RETURN LIKE bapireturn1.

p0015-pernr = '00909089'.
p0015-subty = '1500'.
p0015-endda = '99991231'.
p0015-begda = sy-datum.
p0015-lgart = '1500'.
p0015-betrg = '100.00'.

CALL FUNCTION 'HR_EMPLOYEE_ENQUEUE'


EXPORTING
NUMBER = '00909089'.
CALL FUNCTION 'HR_INFOTYPE_OPERATION'
EXPORTING
infty = '0015'
NUMBER = '00909089'
subtype = '1500'
validityend = '99991231'
validitybegin = sy-datum
record = p0015
operation = 'INS'
tclas = 'A'
IMPORTING
RETURN = RETURN.
WRITE RETURN.

CALL FUNCTION 'HR_EMPLOYEE_DEQUEUE'


EXPORTING
NUMBER = '00909089'.

Modify Infotype Record


Read existing record before you modify record. Use operation MOD.

CALL FUNCTION 'HR_INFOTYPE_GETDETAIL'


EXPORTING
infty = '0006'
NUMBER = employeenumber
subtype = subtype
objectid = objectid
lockindicator = lockindicator
validityend = validityend
validitybegin = validitybegin
recordnumber = recordnumber
tclas = 'A'
IMPORTING
RETURN = RETURN
record = p0006
EXCEPTIONS
OTHERS = 0.
IF NOT RETURN IS INITIAL.
EXIT.
ENDIF.

p0006-pernr = employeenumber.
p0006-subty = subtype.
p0006-infty = '0006'.
p0006-objps = objectid.
p0006-sprps = lockindicator.
p0006-begda = validitybegin.
p0006-endda = validityend.
p0006-seqnr = recordnumber.
p0006-anssa = subtype.
p0006-name2 = coname.
p0006-stras = streetandhouseno.
p0006-ort01 = city.
p0006-ort02 = district.
p0006-pstlz = postalcodecity.
p0006-STATE = STATE.
p0006-land1 = COUNTRY.
p0006-telnr = telephonenumber.
p0006-entkm = distanceinkm.
p0006-entk2 = distanceinkm1.
p0006-wkwng = companyownedapt.
p0006-busrt = busroute.
p0006-com01 = commtype1.
p0006-num01 = commnumber1.
p0006-com02 = commtype2.
p0006-num02 = commnumber2.
p0006-com03 = commtype3.
p0006-num03 = commnumber3.

CALL FUNCTION 'HR_INFOTYPE_OPERATION'


EXPORTING
infty = '0006'
NUMBER = employeenumber
subtype = subtype
objectid = objectid
lockindicator = lockindicator
validityend = validityend
validitybegin = validitybegin
recordnumber = recordnumber
record = p0006
operation = 'MOD'
nocommit = space
IMPORTING
RETURN = RETURN
EXCEPTIONS
OTHERS = 0.

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

1) All wage types are stored in T512W and T512T for Wage Type Texts

2) /561 gets populated once value is stored in DDNTK.

3) The earl retroactive acting period is stored on PA03.

You might also like