Wednesday 11 July 2012

SAP BI support issues


SAP BI Production Support IssuesProduction Support Errors:

1) Invalid characters while loading:

 When you are loading data then you may get some special characters like @#$%...e.t.c.then BW will throw an error like Invalid characters then you need to go through this RSKC transaction and enter all the Invalid chars and execute. It will store this data in RSALLOWEDCHAR table. Then reload the data. You won't get any error because now these are eligible chars done by RSKC.

2) IDOC Or TRFC Error:

We can see the following error at “Status” Screen:Sending packages from OLTP to BW lead to errorsDiagnosisNo IDocs could be sent to the SAP BW using RFC.System responseThere are IDocs in the source system ALE outbox that did not arrive in the ALE inbox of the SAP BW.Further analysis:Check the TRFC log.You can get to this log using the wizard or the menu path "Environment -> Transact. RFC -> In source system".Removing errors:If the TRFC is incorrect, check whether the source system is completely connected to the SAP BW. Check especially the authorizations of the background user in the source system.Action to be taken:If Source System connection is OK Reload the Data.


3)PROCESSING IS OVERDUE FOR PROCESSED IDOCs:

Diagnosis IDocs were found in the ALE inbox for Source System that is not updated. Processing is overdue. Error correction: Attempt to process the IDocs manually. You can process the IDocs manually using the Wizard or by selecting the IDocs with incorrect status and processing them manually. Analysis:After looking at all the above error messages we find that the IDocs are found in the ALE inbox for Source System that are not Updated.Action to be taken:We can process the IDocs manually via RSMO -> Header Tab -> Click on Process manually.


4) LOCK NOT SET FOR LOADING MASTER DATA ( TEXT / ATTRIBUE / HIERARCHY ):

Diagnosis User ALEREMOTE is preventing you from loading texts to characteristic 0COSTCENTER . The lock was set by a master data loading process with therequest number. System response For reasons of consistency, the system cannot allow the update to continue, and it has terminated the process. Procedure Wait until the process that is causing the lock is complete. You can call transaction SM12 to display a list of the locks. If a process terminates, the locks that have been set by this process are reset automatically. Analysis:After looking at all the above error messages we find that the user is “Locked”. Action to be taken:Wait for sometime & try reloading the Master Data manually from Info-package at RSA1.


5) Flat File Loading ErrorDetail Error Message Diagnosis Data records were marked as incorrect in the PSA. System response The data package was not updated.Procedure Correct the incorrect data records in the data package (for example by manually editing them in PSA maintenance). You can find the error message for each record in the PSA by double-clicking on the record status.Analysis:After looking at all the above error messages we find that the PSA contains incorrect record.Action to be taken:To resolve this issue there are two methods:-i) We can rectify the data at the source system & then load the data.ii) We can correct the incorrect record in the PSA & then upload the data into the data target from here.


6) Object requested is currently locked by user ALEREMOTEDetail Error Message.DiagnosisAn error occurred in BI while processing the data. The error is documented in an error message.Object requested is currently locked by user ALEREMOTEProcedureLook in the lock table to establish which user or transaction is using the requested lock (Tools -> Administration -> Monitor -> Lock entries). Analysis:After looking at all the above error messages we find that the Object is “Locked. This must have happened since there might be some other back ground process runningAction to Be taken : Delete the error request. Wait for some time and Repeat the chain.


Idocs between R3 and BW while extraction 1)When BW executes an infopackage for data extraction the BW system sends a Request IDoc ( RSRQST ) to the ALE inbox of the source system.Information bundled in Request IDoc (RSRQST) is : Request Id ( REQUEST ) Request Date ( REQDATE ) Request Time (REQTIME) Info-source (ISOURCE) Update mode (UPDMODE )

2)The source system acknowledges the receipt of this IDoc by sending an Info IDoc (RSINFO) back to BW system.The status is 0 if it is ok or 5 for a failure.

3)Once the source system receives the request IDoc successfully, it processes it according to the information in the request. This request starts the extraction process in the source system (typically a batch job with a naming convention that begins with BI_REQ). The request IDoc status now becomes 53 (application document posted). This status means the system cannot process the IDoc further.

4)The source system confirms the start of the extraction job by the source system to BW by sending another info IDoc (RSINFO) with status = 1

5)Transactional Remote Function Calls (tRFCs) extract and transfer the data to BW in data packages. Another info IDoc (RSINFO) with status = 2 sends information to BW about the data package number and number of records transferred.

6)At the conclusion of the data extraction process (i.e., when all the data records are extracted and transferred to BW), an info IDoc (RSINFO) with status = 9 is sent to BW, which confirms the extraction process.When is reconstruction allowed?  1. When a request is deleted in a ODS/Cube, will it be available under reconstruction.Ans :Yes it will be available under reconstruction tab, only if the processing is through PSA Note: This function is particularly useful if you are loading deltas, that is, data that you cannot request again from the source system

2. Should the request be turned red before it is deleted from the target so as to enable reconstructionAns :To enable reconstruction you may not need to make the request red, but to enable repeat of last delta you have to make the request red before you delete it.
3. If the request is deleted with its status green, does the request get deleted from reconstruction tab tooAns :No, it wont get deleted from reconstruction tab

4. Does the behaviour of reconstruction and deletion differ when the target is differnet. ODS and CubeAns :Yes



How to Debugg Update and transfer Rules 1.Go to the Monitor. 2. Select 'Details' tab. 3. Click the 'Processing' 4. Right click any Data Package. 5. select 'simulate update' 6. Tick the check boxes ' Activate debugging in transfer rules' and 'Activate debugging in update rules'. 7. Click 'Perform simulation'.


Error loading master data - Data record 1 ('AB031005823') : Version 'AB031005823' is not valid:

ProblemCreated a flat file datasource for uploading master data.Data loaded fine upto PSA.Once the DTP which runs the transformation is scheduled, its ends up in error as below: SolutionAfter refering to many links on sdn, i found that since the data is from an external file,the data will not be matching the SAP internal format. So it shud be followed that we mark "External" format option in the datasource ( in this case for Material ) and apply the conversion routine MATN1 as shown in the picture below :Once the above changes are done, the load was successful.Knowledge from SDN forumsConversion takes place when converting the contents of a screen field from display format to SAP-internal format and vice versa and when outputting with the ABAP statement WRITE, depending on the data type of the field.


Check the Link: 

info:http://help.sap.com/saphelp_nw04/helpdata/en/2b/e9a20d3347b340946c32331c96a64e/content.htmhttp://help.sap.com/saphelp_nw04/helpdata/en/07/6de91f463a9b47b1fedb5be18699e7/content.htmThis fm ( MATN1) will add leading ZEROS to the material number because when u query on MAKT with MATNR as just 123 you wll not be getting any values, so u should use this conversion exit to add leading zeros.’




Function module to make yellow request to REDUse SE37, to execute the function module RSBM_GUI_CHANGE_USTATE.From the next screen, for I_REQUID enter that request ID and execute.From the next screen, select 'Status Erroneous' radiobutton and continue.This Function Module, change the status of request from Green / Yellow to RED.What will happend if a request in Green is deleted?Deleting green request is no harm. if you are loading via psa, you can go to tab 'reconstruction' and select the request and 'insert/reconstruct' to have them back.But,For example you will need to repeat this delta load from the source system. If you delete the green request then you will not get these delta records from the source system.Explanation :when the request is green, the source system gets the message that the data sent was loaded successfully, so the next time the load (delta) is triggered, new records are sent.If for some reason you need to repeat the same delta load from the source, then making the request red sends the message that the load was not successful, so do not discard these delta records.Delta queue in r/3 will keep until the next upload successfully performed in bw. The same records are then extracted into BW in the next requested delta load.Appearence of Values for charecterstic input help screen Which settings can I make for the input help and where can I maintain these settings?In general, the following settings are relevant and can be made for the input help for characteristics:Display: Determines the display of the characteristic values with the following options "Key", "Text", "Key and text" and "Text and key".Text type: If there are different text types (short, medium and long text), this determines which text type is to be used to display the text.Attributes: You can determine for the input help which attributes of the characteristic are displayed initially. When you have a large number of attributes for the characteristic, it makes sense to display only a selected number of attributes. You can also determine the display sequence of the attributes.F4 read mode: Determines in which mode the input help obtains its characteristic values. This includes the modes "Values from the master data table (M)", "Values from the InfoProvider (D)" and "Values from the Query Navigation (Q)". Note that you can set a read mode, on the one hand, for the input help for query execution (for example, in the BEx Analyzer or in the BEX Web) and, on the other hand, for the input help for the query definition (in the BEx Query Designer). You can make these settings in InfoObject maintenance using transaction RSD1 in the context of the characteristic itself, in the InfoProvider-specific characteristic settings using transaction RSDCUBE in the context of the characteristic within an InfoProvider or in the BEx Query Designer in the context of the characteristic within a query. Note that not all the settings can be maintained in all the contexts. The following table shows where certain settings can be made: Setting RSD1 RSDCUBE BExQueryDesigner Display X X X Text type X X X Attributes X - - Read mode - Query execution X X X - Query definition X - - Note that the respective input helps in the BEx Web as well as in the BEx Tools enable you to make these settings again after executing the input help.When do I use the settings from InfoObject maintenance (transaction RSD1) for the characteristic for the input help?

The settings that are made in InfoObject maintenance are active in the context of the characteristic and may be overwritten at higher levels if required. At present, the InfoProvider-specific settings and the BEx Query Designer belong to the higher levels. If the characteristic settings are not explicitly overwritten in the higher levels, the characteristic settings from InfoObject maintenance are active.When do I use the settings from the InfoProvider-specific characteristic settings (transaction RSDCUBE) for the input help?You can make InfoProvider-specific characteristic settings in transaction RSDCUBE -> context menu for a characteristic -> InfoProvider-specific properties.These settings for the characteristic are active in the context of the characteristic within an InfoProvider and may be overwritten in higher levels if required. At present, only the BEx Query Designer belongs to the higher levels. If the characteristic settings are not explicitly overwritten in the higher levels and settings are made in the InfoProvider-specific settings, these are then active. Note that the settings are thus overwritten in InfoObject maintenance.When do I use the settings in the BEx Query Designer for characteristics for the input help?In the BEx Query Designer, you can make the input help-relevant settings when you go to the tab pages "Display" and "Advanced" in the "Properties" area for the characteristic if this is selected.These settings for the characteristic are active in the context of the characteristic within a query and cannot be overwritten in higher levels at present. If the settings are not made explicitly, the settings that are made in the lower levels take effect.


The settings that are made in InfoObject maintenance are active in the context of the characteristic and may be overwritten at higher levels if required. At present, the InfoProvider-specific settings and the BEx Query Designer belong to the higher levels. If the characteristic settings are not explicitly overwritten in the higher levels, the characteristic settings from InfoObject maintenance are active.When do I use the settings from the InfoProvider-specific characteristic settings (transaction RSDCUBE) for the input help?You can make InfoProvider-specific characteristic settings in transaction RSDCUBE -> context menu for a characteristic -> InfoProvider-specific properties.These settings for the characteristic are active in the context of the characteristic within an InfoProvider and may be overwritten in higher levels if required. At present, only the BEx Query Designer belongs to the higher levels. If the characteristic settings are not explicitly overwritten in the higher levels and settings are made in the InfoProvider-specific settings, these are then active. Note that the settings are thus overwritten in InfoObject maintenance.When do I use the settings in the BEx Query Designer for characteristics for the input help?In the BEx Query Designer, you can make the input help-relevant settings when you go to the tab pages "Display" and "Advanced" in the "Properties" area for the characteristic if this is selected.These settings for the characteristic are active in the context of the characteristic within a query and cannot be overwritten in higher levels at present. If the settings are not made explicitly, the settings that are made in the lower levels take effect.

The settings that are made in InfoObject maintenance are active in the context of the characteristic and may be overwritten at higher levels if required. At present, the InfoProvider-specific settings and the BEx Query Designer belong to the higher levels. If the characteristic settings are not explicitly overwritten in the higher levels, the characteristic settings from InfoObject maintenance are active.When do I use the settings from the InfoProvider-specific characteristic settings (transaction RSDCUBE) for the input help?You can make InfoProvider-specific characteristic settings in transaction RSDCUBE -> context menu for a characteristic -> InfoProvider-specific properties.These settings for the characteristic are active in the context of the characteristic within an InfoProvider and may be overwritten in higher levels if required. At present, only the BEx Query Designer belongs to the higher levels. If the characteristic settings are not explicitly overwritten in the higher levels and settings are made in the InfoProvider-specific settings, these are then active. Note that the settings are thus overwritten in InfoObject maintenance.When do I use the settings in the BEx Query Designer for characteristics for the input help?In the BEx Query Designer, you can make the input help-relevant settings when you go to the tab pages "Display" and "Advanced" in the "Properties" area for the characteristic if this is selected.These settings for the characteristic are active in the context of the characteristic within a query and cannot be overwritten in higher levels at present. If the settings are not made explicitly, the settings that are made in the lower levels take effect.
The settings that are made in InfoObject maintenance are active in the context of the characteristic and may be overwritten at higher levels if required. At present, the InfoProvider-specific settings and the BEx Query Designer belong to the higher levels. If the characteristic settings are not explicitly overwritten in the higher levels, the characteristic settings from InfoObject maintenance are active.When do I use the settings from the InfoProvider-specific characteristic settings (transaction RSDCUBE) for the input help?You can make InfoProvider-specific characteristic settings in transaction RSDCUBE -> context menu for a characteristic -> InfoProvider-specific properties.These settings for the characteristic are active in the context of the characteristic within an InfoProvider and may be overwritten in higher levels if required. At present, only the BEx Query Designer belongs to the higher levels. If the characteristic settings are not explicitly overwritten in the higher levels and settings are made in the InfoProvider-specific settings, these are then active. Note that the settings are thus overwritten in InfoObject maintenance.When do I use the settings in the BEx Query Designer for characteristics for the input help?In the BEx Query Designer, you can make the input help-relevant settings when you go to the tab pages "Display" and "Advanced" in the "Properties" area for the characteristic if this is selected.These settings for the characteristic are active in the context of the characteristic within a query and cannot be overwritten in higher levels at present. If the settings are not made explicitly, the settings that are made in the lower levels take effect.How to supress messages generated by BW QueriesStandard Solution :
You might be aware of a standard solution. In transaction RSRT, select your query and click on the "message" button. Now you can determine which messages for the chosen query are not to be shown to the user in the front-end.

You might be aware of a standard solution. In transaction RSRT, select your query and click on the "message" button. Now you can determine which messages for the chosen query are not to be shown to the user in the front-end.
You might be aware of a standard solution. In transaction RSRT, select your query and click on the "message" button. Now you can determine which messages for the chosen query are not to be shown to the user in the front-end. You might be aware of a standard solution. In transaction RSRT, select your query and click on the "message" button. Now you can determine which messages for the chosen query are not to be shown to the user in the front-end.Custom Solution: Only selected messages can be suppressed using the standard solution. However, there's a clever way you can implement your own solution... and you don't need to modify the system for it!All messages are collected using function RRMS_MESSAGE_HANDLING. So all you have to do is implement an enhancement at the start of this function module. Now it's easy. Code your own logic to check the input parameters like the message class and number and skip the remainder of the processing logic if you don't want this message to show up in the front-end. FUNCTION rrms_message_handling. StartENHANCEMENT 1 Z_CHECK_BIA. * Filter BIA Message if i_class = 'RSD_TREX' and i_type = 'W' and i_number = '136'* just testing it.* exitend if. ENHANCEMENT End IMPORTING ------------ ---------- ---- EXCEPTIONS Dummy ..How can I display attributes for the characteristic in the input help? Attributes for the characteristic can be displayed in the respective filter dialogs in the BEx Java Web or in the BEx Tools using the settings dialogs for the characteristic. Refer to the related application documentation for more details.In addition, you can determine the initial visibility and the display sequence of the attributes in InfoObject maintenance on the tab page "Attributes" -> "Detail" -> column "Sequence F4". Attributes marked with "0" are not displayed initially in the input help.Why do the settings for the input help from the BEx Query Designer and from the InfoProvider-specific characteristic settings not take effect on the variable screen? On the variable screen, you use input helps for selecting characteristic values for variables that are based on characteristics. Since variables from different queries and from potentially different InfoProviders can be merged on the variable screen, you cannot clearly determine which settings should be used from the different queries or InfoProviders. For this reason, you can use only the settings on the variable screen that were made in InfoObject maintenance.Why do the read mode settings for the characteristic and the provider-specific read mode settings not take effect during the execution of a query in the BEx Analyzer? The query read mode settings always take effect in the BEx Analyzer during the execution of a query. If no setting was made in the BEx Query Designer, then default read mode Q (query) is used.How can I change settings for the input help on the variable screen in the BEx Java Web? In the BEx Java Web, at present, you can make settings for the input help only using InfoObject maintenance. You can no longer change these settings subsequently on the variable screen.Selective Deletion in Process Chain The standard procedure : Use Program RSDRD_DELETE_FACTS 1. Create a variant which is stored in the table RSDRBATCHPARA for the selection to be deleted from a data target. 2. Execute the generated program.Observations: The generated program executes will delete the data from data target based on the given selections. The program also removes the variant created for this selective deletion in the RSDRBATCHPARA table. So this generated program wont delete on the second execution. If we want to use this program for scheduling in the process chain we can comment the step where the program remove the deletion of the generated variant. Eg:REPORT ZSEL_DELETE_QM_C10 . TYPE-POOLS: RSDRD, RSDQ, RSSG. DATA: L_UID TYPE RSSG_UNI_IDC25, L_T_MSG TYPE RS_T_MSG, L_THX_SEL TYPE RSDRD_THX_SEL L_UID = 'D2OP7A6385IJRCKQCQP6W4CCW'. IMPORT I_THX_SEL TO L_THX_SEL FROM DATABASE RSDRBATCHPARA(DE) ID L_UID. * DELETE FROM DATABASE RSDRBATCHPARA(DE) ID L_UID.CALL FUNCTION 'RSDRD_SEL_DELETION' EXPORTING I_DATATARGET = '0QM_C10' I_THX_SEL = L_THX_SELI_AUTHORITY_CHECK = 'X' I_THRESHOLD = '1.0000E-01' I_MODE = 'C' I_NO_LOGGING = '' I_PARALLEL_DEGREE = 1 I_NO_COMMIT = '' I_WORK_ON_PARTITIONS = '' I_REBUILD_BIA = '' I_WRITE_APPLICATION_LOG = 'X' CHANGING C_T_MSG = L_T_MSG.export l_t_msg to memory id sy-repid. UPDATE RSDRBATCHREP SET DELETEABLE = 'X' WHERE REPID = 'ZSEL_DELETE_QM_C10'.ABAP program to find prev request in cube and delete There will be cases when we cannot use the SAP built-in settings to delete previous request..The logic to determine previous request may be so customised, a requirement.In such cases you can write a ABAP program which calculates previous request basing our own defined logic.Following are the tables used : RSICCONT ---(list of all requests in any particular cube)RSSELDONE ----- ( has got Reqnumb, source , target , selection infoobject , selections ..etc)Following is one example code. Logic is to select request based on selection conditions used in the infopackage:TCURF, TCURR and TCURX TCURF is always used in reference to Exchange rate.( in case of currency translation ).For example, Say we want to convert fig's from FROM curr to TO curr at Daily avg rate (M) and we have an exchange rate as 2,642.34. Factors for this currency combination for M in TCURF are say 100,000:1.Now the effective exchange rate becomes 0.02642.Question ( taken from sdn ):can't we have an exchange rate of 0.02642 and not at all use the factors from TCURF table?.I suppose we have to still maintain factors as 1:1 in TCURF table if we are using exchange rate as 0.02642. am I right?. But why is this so?. Can't I get rid off TCURF.What is the use of TCURF co-existing with TCURR.Answer :Normally it's used to allow you a greater precision in calaculationsie 0.00011 with no factors gives a different result to0.00111 with factor of 10:1So basing on the above answer, TCURF allows greater precision in calculations.Its factor shud be considered before considering exchange rate

.-------------------------------------------------------------------------------------TCURRTCURR table is generally used while we create currency conversion types.The currency conversion types will refer to the entries in TCURR defined against each currency ( with time reference) and get the exchange rate factor from source currency to target currency.

-------------------------------------------------------------------------------------
TCURXTCURX
table is used to exactly define the correct number of decimal places for any currency. It shows effect in the BEx report output.
-------------------------------------------------------------------------------------


.-------------------------------------------------------------------------------------TCURRTCURR table is generally used while we create currency conversion types.The currency conversion types will refer to the entries in TCURR defined against each currency ( with time reference) and get the exchange rate factor from source currency to target currency.
------------------------------------------------------------------------------------- TCURXTCURX table is used to exactly define the correct number of decimal places for any currency. It shows effect in the BEx report output. -------------------------------------------------------------------------------------

.-------------------------------------------------------------------------------------TCURRTCURR table is generally used while we create currency conversion types.The currency conversion types will refer to the entries in TCURR defined against each currency ( with time reference) and get the exchange rate factor from source currency to target currency. ------------------------------------------------------------------------------------- TCURXTCURX table is used to exactly define the correct number of decimal places for any currency. It shows effect in the BEx report output. -------------------------------------------------------------------------------------
.-------------------------------------------------------------------------------------TCURRTCURR table is generally used while we create currency conversion types.The currency conversion types will refer to the entries in TCURR defined against each currency ( with time reference) and get the exchange rate factor from source currency to target currency. ------------------------------------------------------------------------------------- TCURXTCURX table is used to exactly define the correct number of decimal places for any currency. It shows effect in the BEx report output. -------------------------------------------------------------------------------------How to define F4 Order Help for infoobject for reporting Open attributes tab of infoobject definition.In that you will observe column for F4 order help against each attribute of that infoobject like below : This field defines whether and where the attribute should appear in the value help.Valid values:• 00: The attribute does not appear in the value help.• 01: The attribute appears at the first position (to the left) in the value help.• 02: The attribute appears at the second position in the valuehelp.• 03: ......• Altogether, only 40 fields are permitted in the input help. In addition to the attributes, the characteristic itsel, its texts, and the compounded characteristics are also generated in the input help. The total number of these fields cannot exceed 40. So accordingly , the inofobjects are changed> Suppose if say for infobject 0vendor, if in case 0country ( which is an attribute of 0vendor) is not be shown in the F4 help of 0vendor , then mark 0 against the attribtue 0country in the infoobject definition of 0vendor.Dimension Size Vs Fact Size The current size of all dimensions can be monitored in relation to fact table by t-code se38 running report SAP_INFOCUBE_DESIGNS.Also,we can test the infocube design by RSRV tests.It gives out the dimension to fact ratio. The ratio of a dimension should be less than 10% of the fact table.In the report,Dimension table looks like /BI[C/O]/D[xxx] Fact table looks like /BI[C/0]/[E/F][xxx] Use T-CODE LISTSCHEMA to show the different tables associated with a cube. When a dimension grows very large in relation to the fact table, db optimizer can't choose efficient path to the data because the guideline of each dimension having less than 10 percent of the fact table's records has been violated. The condition of having large data growth in a dimension is called degenerative dimension.To fix, move the characteristics to different dimensions. But can only be done when no data in the InfoCube. Note : In case if you have requirement to include item level details in the cube, then may be the Dim to Fact size will obviously be more which you cant help it.But you can make the item charecterstic to be in a line item dimension in that case.Line item dimension is a dimension having only one charecterstic in it.In this case, Since there is only one charecterstic in the dimension, the fact table entry can directly link with the SID of the charecterstic without using any DIMid (Dimid in dimension table usually connects the SID of the charecterstic with the fact) .Since link happens by ignoring dimension table ( not in real sense ) , this will have faster query performance.BW Main tables Extractor related tables: ROOSOURCE - On source system R/3 server, filter by: OBJVERS = 'A' Data source / DS type / delta type/ extract method (table or function module) / etc RODELTAM - Delta type lookup table. ROIDOCPRMS - Control parameters for data transfer from the source system, result of "SBIW - General setting - Maintain Control Parameters for Data Transfer" on OLTP system. maxsize: Maximum size of a data packet in kilo bytes STATFRQU: Frequency with which status Idocs are sent MAXPROCS: Maximum number of parallel processes for data transfer MAXLINES: Maximum Number of Lines in a DataPacketMAXDPAKS: Maximum Number of Data Packages in a Delta RequestSLOGSYS: Source system.Query related tables: RSZELTDIR: filter by: OBJVERS = 'A', DEFTP: REP - query, CKF - Calculated key figureReporting component elements, query, variable, structure, formula, etc RSZELTTXT: Similar to RSZELTDIR. Texts of reporting component elementsTo get a list of query elements built on that cube:RSZELTXREF: filter by: OBJVERS = 'A', INFOCUBE= [cubename] To get all queries of a cube:RSRREPDIR: filter by: OBJVERS = 'A', INFOCUBE= [cubename]To get query change status (version, last changed by, owner) of a cube:RSZCOMPDIR: OBJVERS = 'A' .Workbooks related tables: RSRWBINDEX List of binary large objects (Excel workbooks) RSRWBINDEXT Titles of binary objects (Excel workbooks) RSRWBSTORE Storage for binary large objects (Excel workbooks) RSRWBTEMPLATE Assignment of Excel workbooks as personal templatesRSRWORKBOOK 'Where-used list' for reports in workbooks.Web templates tables: RSZWOBJ Storage of the Web Objects RSZWOBJTXT Texts for Templates/Items/Views RSZWOBJXREF Structure of the BW Objects in a TemplateRSZWTEMPLATE Header Table for BW HTML Templates.Data target loading/status tables:
rsreqdone, " Request-Data
rsseldone, " Selection for current Request
rsiccont, " Request posted to which InfoCube
rsdcube, " Directory of InfoCubes / InfoProvider
rsdcubet, " Texts for the InfoCubes
rsmonfact, " Fact table monitor
rsdodso, " Directory of all ODS Objects
rsdodsot, " Texts of ODS Objectssscrfields. " Fields on selection screens

rsreqdone, " Request-Data rsseldone, " Selection for current Request rsiccont, " Request posted to which InfoCube rsdcube, " Directory of InfoCubes / InfoProvider rsdcubet, " Texts for the InfoCubes rsmonfact, " Fact table monitor rsdodso, " Directory of all ODS Objects rsdodsot, " Texts of ODS Objectssscrfields. " Fields on selection screens
rsreqdone, " Request-Data rsseldone, " Selection for current Request rsiccont, " Request posted to which InfoCube rsdcube, " Directory of InfoCubes / InfoProvider rsdcubet, " Texts for the InfoCubes rsmonfact, " Fact table monitor rsdodso, " Directory of all ODS Objects rsdodsot, " Texts of ODS Objectssscrfields. " Fields on selection screens rsreqdone, " Request-Data rsseldone, " Selection for current Request rsiccont, " Request posted to which InfoCube rsdcube, " Directory of InfoCubes / InfoProvider rsdcubet, " Texts for the InfoCubes rsmonfact, " Fact table monitor rsdodso, " Directory of all ODS Objects rsdodsot, " Texts of ODS Objectssscrfields. " Fields on selection screensTables holding charactoristics: RSDCHABAS: fields OBJVERS -> A = active; M=modified; D=delivered (business content characteristics that have only D version and no A version means not activated yet)TXTTABFL -> = x -> has text ATTRIBFL -> = x -> has attribute RODCHABAS: with fields TXTSHFL,TXTMDFL,TXTLGFL,ATTRIBFL RSREQICODS. requests in ods RSMONICTAB: all requestsTransfer Structures live in PSAPODSD /BIC/B0000174000 Trannsfer Structure Master Data lives in PSAPSTABD /BIC/HXXXXXXX Hierarchy:XXXXXXXX /BIC/IXXXXXXX SID Structure of hierarchies: /BIC/JXXXXXXX Hierarchy intervals /BIC/KXXXXXXX Conversion of hierarchy nodes - SID: /BIC/PXXXXXXX Master data (time-independent): /BIC/SXXXXXXX Master data IDs: /BIC/TXXXXXXX Texts: Char./BIC/XXXXXXXX Attribute SID table:Master Data views /BIC/MXXXXXXX master data tables: /BIC/RXXXXXXX View SIDs and values: /BIC/ZXXXXXXX View hierarchy SIDs and nodes:InfoCube Names in PSAPDIMD /BIC/Dcube_name1 Dimension 1....../BIC/Dcube_nameA Dimension 10 /BIC/Dcube_nameB Dimension 11 /BIC/Dcube_nameC Dimension 12 /BIC/Dcube_nameD Dimension 13 /BIC/Dcube_nameP Data Packet /BIC/Dcube_nameT Time/BIC/Dcube_nameU Unit PSAPFACTD /BIC/Ecube_name Fact Table (inactive)/BIC/Fcube_name Fact table (active)ODS Table names (PSAPODSD) BW3.5/BIC/AXXXXXXX00 ODS object XXXXXXX : Actve records /BIC/AXXXXXXX40 ODS object XXXXXXX : New records /BIC/AXXXXXXX50 ODS object XXXXXXX : Change log Previously: /BIC/AXXXXXXX00 ODS object XXXXXXX : Actve records /BIC/AXXXXXXX10 ODS object XXXXXXX : New recordsT-code tables: tstc -- table of transaction code, text and program name tstct - t-code text .1What is tickets? And example? The typical tickets in a production Support work could be: 1. Loading any of the missing master data attributes/texts. 2. Create ADHOC hierarchies. 3. Validating the data in Cubes/ODS. 4. If any of the loads runs into errors then resolve it. 5. Add/remove fields in any of the master data/ODS/Cube. 6. Data source Enhancement. 7. Create ADHOC reports. 1. Loading any of the missing master data attributes/texts - This would be done by scheduling the info packages for the attributes/texts mentioned by the client. 2. Create ADHOC hierarchies. - Create hierarchies in RSA1 for the info-object. 3. Validating the data in Cubes/ODS. - By using the Validation reports or by comparing BW data with R/3. 4. If any of the loads runs into errors then resolve it. - Analyze the error and take suitable action. 5. Add/remove fields in any of the master data/ODS/Cube. - Depends upon the requirement 6. Data source Enhancement. 7. Create ADHOC reports. - Create some new reports based on the requirement of client. Tickets are the tracking tool by which the user will track the work which we do. It can be a change requests or data loads or whatever. They will of types critical or moderate. Critical can be (Need to solve in 1 day or half a day) depends on the client. After solving the ticket will be closed by informing the client that the issue is solved. Tickets are raised at the time of support project these may be any issues, problems.....etc. If the support person faces any issues then he will ask/request to operator to raise a ticket. Operator will raise a ticket and assign it to the respective person. Critical means it is most complicated issues ....depends how you measure this...hope it helps. The concept of Ticket varies from contract to contract in between companies. Generally Ticket raised by the client can be considered based on the priority. Like High Priority, Low priority and so on. If a ticket is of high priority it has to be resolved ASAP. If the ticket is of low priority it must be considered only after attending to high priority tickets. Checklists for a support project of BPS - To start the checklist: 1) Info Cubes / ODS / data targets 2) planning areas 3) planning levels 4) planning packages 5) planning functions 6) planning layouts 7) global planning sequences 8) profiles 9) list of reports 10) process chains 11) enhancements in update routines 12) any ABAP programs to be run and their logic 13) major bps dev issues 14) major bps production support issues and resolution .

2 What are the tools to download tickets from client? Are there any standard tools or it depends upon company or client...?Yes there are some tools for that. We use Hpopenview. Depends on client what they use. You are right. There are so many tools available and as you said some clients will develop their own tools using JAVA, ASP and other software. Some clients use just Lotus Notes. Generally 'Vantive' is used for tracking user requests and tickets. It has a vantive ticket ID, field for description of problem, severity for the business, priority for the user, group assigned etc. Different technical groups will have different group ID's. User talks to Level 1 helpdesk and they raise ticket. If they can solve issue for the issue, fine...else helpdesk assigns ticket to the Level 2 technical group. Ticket status keeps changing from open, working, resolved, on hold, back from hold, closed etc. The way we handle the tickets vary depending on the client. Some companies use SAP CS to handle the tickets; we have been using Vantage to handle the tickets. The ticket is handled with a change request, when you get the ticket you will have the priority level with which it is to be handled. It comes with a ticket id and all. It's totally a client specific tool. The common features here can be - A ticket Id, - Priority, - Consultant ID/Name, - User ID/Name, - Date of Post, - Resolving Time etc. There ideally is also a knowledge repository to search for a similar problem and solutions given if it had occurred earlier. You can also have training manuals (with screen shots) for simple transactions like viewing a query, saving a workbook etc so that such queried can be addressed by using them. When the problem is logged on to you as a consultant, you need to analyze the problem, check if you have a similar problem occurred earlier and use ready solutions, find out the exact server on which this has occurred etc. You have to solve the problem (assuming you will have access to the dev system) and post the solution and ask the user to test after the preliminary testing from your side. Get it transported to production once tested and posts it as closed i.e. the ticket has to be closed.3.What is User Authorizations in SAP BW? Authorizations are very important, for example you don't want the important financial report to all the users. so, you can have authorization in Object level if you want to keep the authorization for specific in object for this you have to check the Object as an authorization relevant in RSD1 and RSSM tcodes. Similarly you set up the authorization for certain users by giving that users certain auth. in PFCG tcode. Similarly you create a role and include the tcodes; BEx reports etc into the role and assign this role to the userid

Facts about SAP



This is about SAP:

Now... let's talk about a few other things....  You asked for best and easy. I'm hoping this was just an unfortunate word choice. Best is a matter of opinion: vanilla or chocolate. You need to educate yourself on the various career paths (programming, system administration, functional consulting, project management, etc) and the business subspecialties (components: SAP ERP, SAP CRM, SAP SRM, SAP SCM; modules - SAP ERP: FI, MM, PP, SD, etc) and then select for yourself the path and subspecialty which interests you most. The blog post on overview books is probably a good place to start.

As for "easy", you're in the wrong field. Nothing about SAP is "easy". SAP is the heart and soul of the companies in which it is installed. Folks take that seriously. There are deadlines and requirements and at no point does "easy" factor in to the equation. If you want a job that is mentally low stress, then get a job flipping burgers. If you want a job that is physically low stress, then SAP work probably fits the description; however, very few folks who work to support an SAP system lead low stress 9-to-5 type lives. Supporting a system means deadlines and often work on weekends and holidays. If you're just looking to punch a clock and collect a paycheck, then you should be looking to get a job as an end user, not as a support person.

Also, and I apologize for being a bit harsh, but SAP is a business system. You should strive to present yourself in a professional manner at all times. That means proper capitalization, punctuation, grammar, and spelling at all times. Your emphasis on easy and the general appearance and tone of your written communication leads me to believe that you may not have what it takes to be successful in an SAP career. In the blogs provided, you have a roadmap and all the tools necessary to succeed. If you read them and have questions, I and and many others stand ready to answer any questions you may have, but you have to do your homework first. I haven't seen any evidence yet that you have the ability to do the hard work necessary to even begin a career in SAP. I sincerely hope you have the drive and determination to prove me wrong. 

Best regards,
Ravi kiran.
bangalore.

Sunday 8 July 2012

SAP ABAP oops


Public attributes

Public attributes are defined in the PUBLIC section and can be viewed and changed from outside the class. There is direct access to public attributes. As a general rule, as few public attributes should be defined as possible.
PUBLIC SECTION.
DATA: Counter type i.
Private attributes
Private attributes are defined in the PRIVATE section. The can only be viewes and changed from within the class. There is no direct access from outside the class.
PRIVATE SECTION.
DATA: name(25) TYPE c,
planetype LIKE saplane-planetyp,
Instance attributes
There exist one instance attribute for each instance of the class, thus they exist seperately for each object. Instance attributes are declared with the DATA keyword.
Static attributes
Static attributes exist only once for each class. The data are the same for all instances of the class, and can be used e.g. for instance counters. Static attributes are defined with the keyword CLASS-DATA.
PRIVATE SECTION.
CLASS-DATA: counter type i,
Public methods
Can called from outside the class
PUBLIC SECTION.
METHODS: set_attributes IMPORTING p_name(25) TYPE c,
p_planetype LIKE saplane-planetyp,
Private methods
Can only be called from inside the class. They are placed in the PRIVATE section of the class.
Constructor method
Implicitly, each class has an instance constructor method with the reserved name constructor and a static constructor method with the reserved name class_constructor.
The instance constructor is executed each time you create an object (instance) with the CREATE OBJECT statement, while the class constructor is executed exactly once before you first access a class.
The constructors are always present. However, to implement a constructor you must declare it explicitly with the METHODS or CLASS-METHODS statements. An instance constructor can have IMPORTING parameters and exceptions. You must pass all non-optional parameters when creating an object. Static constructors have no parameters.
Static constructor
The static constructor is always called CLASS_CONSTRUCTER, and is called autmatically before the clas is first accessed, that is before any of the following actions are executed:
• Creating an instance using CREATE_OBJECT
• Adressing a static attribute using <classname>-><attrbute>
• Calling a ststic attribute using CALL METHOD
• Registering a static event handler
• Registering an evetm handler method for a static event
The static constructor cannot be called explicitly.
Protected components
When we are talking subclassing and enheritance there is one more component than Public and Private, the Protected component. Protected components can be used by the superclass and all of the subclasses. Note that Subclasses cannot access Private components.
Polymorphism
Polymorphism: When the same method is implemented differently in different classes. This can be done using enheritance, by redefining a method from the superclass in subclasses and implement it differently.
Template for making a class
Delete the parts that should not be used
******************************************
* Definition part
******************************************
CLASS xxx DEFINITION.
*------------------------------
* Public section
*------------------------------
PUBLIC SECTION.
TYPES:
DATA:
* Static data
CLASS-DATA:
* Methods
METHODS:
* Using the constructor to initialize parameters
constructor IMPORTING xxx type yyy,
* Method with parameters
mm1 IMPORTING iii TYPE ttt.
* Method without parameters
mm2.
* Static methods
CLASS-METHODS:
*---------------------------------------------------*
* Protected section. Also accessable by subclasses
*---------------------------------------------------
PROTECTED SECTION.
*---------------------------------------------------
* Private section. Not accessable by subclasses
*---------------------------------------------------
PRIVATE SECTION.
ENDCLASS.
******************************************
* Implementation part
******************************************
CLASS lcl_airplane IMPLEMENTATION.
METHOD constructor.
ENDMETHOD.
METHOD mm1.
ENDMETHOD.
METHOD mm2.
ENDMETHOD.
ENDCLASS.
Template for calling a class
* Create reference to class lcl_airplane
DATA: airplane1 TYPE REF TO lcl_airplane.
START-OF-SELECTION.
* Create instance using parameters in the cosntructor method
CREATE OBJECT airplane1 exporting im_name = 'Hansemand'
im_planetype = 'Boing 747'.
* Calling a method with parameters
CALL METHOD: airplane1->display_n_o_airplanes,
airplane1->display_attributes.
Subclass
CLASS xxx DEFINITION INHERITING FROM yyy.
Using af class as a parameter for a method
The class LCL_AIRPLANE is used as a parameter for method add_a_new_airplane:
METHODS:
add_a_new_airplane importing im_airplane TYPE REF to lcl_airplane.
Interfaces
In ABAP interfaces are implemented in addition to, and independently of classes. An interface only has a declaration part, and do not have visibillity sections. Components (Attributes, methods, constants, types) can be defined the same way as in classes.
• Interfaces are listed in the definition part lof the class, and must always be in the PUBLIC SECTION.
• Operations defined in the interface atre impemented as methods of the class. All methods of the interface must be present in the
• implementation part of the class.
• Attributes, events, constants and types defined in the interface are automatically available to the class carying out the implementation.
• Interface components are adresse in the class by <interface name>~<component name>
Example of how to implement an interface:
INTERFACE lif_document
DATA: author type ref to lcl_author.
METHODS: print,
display.
ENDINTERFACE.
CLASS lcl_text_document DEFINITION.
PUBLIC SECTION.
INTERFACES lif_document.
METHODS display.
ENDCLASS.
CLASS lcl_text_document IMPLEMENTTION.
METHOD lif_document~print.
ENDMETHOD.
METHOD lif_document~display
ENDMETHOD.
METHOD display.
ENDMETHOD.
ENDCLASS.
REPORT zzz.
DATA: text_doc TYPE REF TO lcl_document.
Start-of-selection.
CREATE OBJECT text_doc.
CALL METHOD text_doc->lif_document~print.
CALL METHOD text_doc->lif_document~display.
CALL METHOD text_doc->display.
Events
For events of controls, refer to How to use controls.
• Events can only have EXPORTING parameters
• When an event is triggerede, only those events handlers that have registred themselves using SET HANDLER by this point of runtime are
• executed. You can register an event using ACTIVATION 'X' and derigert it by using ACTIVATION 'SPACE'.
Defining events:
CLASS <classname> DEFINITION.
EVENTS: <event> EXPORTING VALUE (<ex_par>) TYPE type.
CLASS <classname> IMPLEMENTATION.
METHOD <m>:
RAISE EVENT <event> EXPORTING <ex_par> = <act_par>.
Handling events:
CLASS <classname> DEFINITION.
METHODS: <on_event> FOR <event> OF <classname> ! <interface> IMPORTING <imp_par1>...<imp_parN> SENDER.
Setting handler
SET HANDLER <ref_handle> <on_event> FOR <ref_sender> ! FOR ALL INSTANCES
[ACTIVATION <var>]
Define, implement and use simple class
***INCLUDE ZBC404_HF_LCL_AIRPLANE .
******************************************
* Definition part
******************************************
CLASS lcl_airplane DEFINITION.
*------------------------------
* Public section
*------------------------------
PUBLIC SECTION.
TYPES: t_name(25) TYPE c.
METHODS:
constructor,
set_attributes IMPORTING p_name TYPE t_name
p_planetype TYPE saplane-planetype,
display_attributes,
display_n_o_airplanes.
*------------------------------
* Private section
*------------------------------
PRIVATE SECTION.
* Private attributes
DATA: name(25) TYPE c,
planetype TYPE saplane-planetype.
* Private static attribute
CLASS-DATA n_o_airplanes TYPE i.
ENDCLASS.
******************************************
* Implementation part
******************************************
CLASS lcl_airplane IMPLEMENTATION.
METHOD constructor.
* Counts number of instances
n_o_airplanes = n_o_airplanes + 1.
ENDMETHOD.
METHOD set_attributes.
name = p_name.
planetype = p_planetype.
ENDMETHOD.
METHOD display_attributes.
WRITE:/ 'Name:', name, 'Planetype:', planetype.
ENDMETHOD.
METHOD display_n_o_airplanes.
WRITE: / 'No. planes:', n_o_airplanes.
ENDMETHOD.
ENDCLASS.
REPORT zbc404_hf_maintain_airplanes .
INCLUDE zbc404_hf_lcl_airplane.
* Create reference to class lcl_airplane
DATA: airplane1 TYPE REF TO lcl_airplane,
airplane2 TYPE REF TO lcl_airplane.
START-OF-SELECTION.
* Create instance
CREATE OBJECT airplane1.
CALL METHOD: airplane1->display_n_o_airplanes.
CREATE OBJECT airplane2.
* Setting attributes using a method with parameters
CALL METHOD airplane1->set_attributes EXPORTING p_name = 'Kurt'
p_planetype = 'MD80'.
END-OF-SELECTION.
* Using methods
CALL METHOD: airplane1->display_n_o_airplanes,
airplane1->display_attributes.
The resulting report:
Maintain airplanes
No. planes: 1
No. planes: 2
Name: Kurt Planetype: MD80
Use constructor to create an object with parameters
CLASS lcl_airplane DEFINITION.
PUBLIC SECTION.
TYPES: t_name(25) TYPE c.
METHODS:
constructor importing p2_name type t_name
p2_planetype TYPE saplane-planetype,
..... more code .......
CLASS lcl_airplane IMPLEMENTATION.
METHOD constructor.
name = p2_name.
planetype = p2_planetype.
..... more code .......
ST
ART-OF-SELECTION. CREATE OBJECT airplane1 exporting p2_name = 'Hansemand'
p2_planetype = 'Boing 747'.
Subclassing
This example uses a superclass LCL_AIRPLANE and subclasses it into LCL_PASSENGER_AIRPLANE and LCL_CARGO_PLANE.
LCL_AIRPLANE has a method display_n_o_airplanes that displays the number of object instances.
LCL_PASSENGER_AIRPLANE has the private instance attribute n_o_seats, and redefines the superclass method display_attributes, so it also displays n_o_seats.
LCL_CARGO_PLANE has the private instance attribute cargomax, and redefines the superclass method display_attributes, so it also displays cargomax.
All instance attributes are provided by the cunstructor method.
Superclass LCL_AIRPLANE
***INCLUDE ZBC404_HF_LCL_AIRPLANE .
******************************************
* Definition part
******************************************
CLASS lcl_airplane DEFINITION.
*------------------------------
* Public section
*------------------------------
PUBLIC SECTION.
TYPES: t_name(25) TYPE c.
METHODS:
constructor IMPORTING im_name TYPE t_name
im_planetype TYPE saplane-planetype,
display_attributes.
* Static methods
CLASS-METHODS:
display_n_o_airplanes.
*------------------------------
* Protected section
*------------------------------
PROTECTED SECTION.
* Private attributes
DATA: name(25) TYPE c,
planetype TYPE saplane-planetype.
* Private static attribute
CLASS-DATA n_o_airplanes TYPE i.
ENDCLASS.
******************************************
* Implementation part
******************************************
CLASS lcl_airplane IMPLEMENTATION.
METHOD constructor.
name = im_name.
planetype = im_planetype.
* Counts number of instances
n_o_airplanes = n_o_airplanes + 1.
ENDMETHOD.
METHOD display_attributes.
WRITE:/ 'Name:', name, 'Planetype:', planetype.
ENDMETHOD.
METHOD display_n_o_airplanes.
WRITE: / 'No. planes:', n_o_airplanes.
ENDMETHOD. ENDCLASS.
Sub class LCL_PASSENGER_AIRPLANE
***INCLUDE ZBC404_HF_LCL_PASSENGER_PLANE .
*******************************************************************
* This is a subclass of class lcl_airplane
******************************************************************* CLASS lcl_passenger_airplane DEFINITION INHERITING FROM lcl_airplane.
PUBLIC SECTION.
* The constructor contains the parameters from the superclass
* plus the parameters from the subclass
METHODS:
constructor IMPORTING im_name TYPE t_name
im_planetype TYPE saplane-planetype
im_n_o_seats TYPE sflight-seatsmax,
* Redefinition of superclass method display_attributes
display_attributes REDEFINITION.
PRIVATE SECTION.
DATA: n_o_seats TYPE sflight-seatsmax.
ENDCLASS. CLASS lcl_passenger_airplane IMPLEMENTATION.
METHOD constructor.
* The constructor method of the superclass MUST be called withing the
* construtor
CALL METHOD super->constructor
EXPORTING im_name = im_name
im_planetype = im_planetype.
n_o_seats = im_n_o_seats.
ENDMETHOD.
* The redefined display_attributes method
METHOD display_attributes.
CALL METHOD super->display_attributes.
WRITE: / 'No. seats:', n_o_seats.
ENDMETHOD. ENDCLASS.
Sub class LCL_CARGO_PLANE
***INCLUDE ZBC404_HF_LCL_CARGO_PLANE .
*******************************************************************
* This is a subclass of class lcl_airplane
*******************************************************************
CLASS lcl_cargo_plane DEFINITION INHERITING FROM lcl_airplane.
PUBLIC SECTION.
METHODS:
* The constructor contains the parameters from the superclass
* plus the parameters from the subclass
constructor IMPORTING im_name TYPE t_name
im_planetype TYPE saplane-planetype
im_cargomax type scplane-cargomax,
* Redefinition of superclass method display_attributes
display_attributes REDEFINITION.
PRIVATE SECTION.
DATA:cargomax TYPE scplane-cargomax.
ENDCLASS.
CLASS lcl_cargo_plane IMPLEMENTATION.
METHOD constructor.
* The constructor method of the superclass MUST be called withing the
* constructor
CALL METHOD super->constructor
EXPORTING im_name = im_name
im_planetype = im_planetype.
cargomax = im_cargomax.
ENDMETHOD.
METHOD display_attributes.
* The redefined display_attributes method
CALL METHOD super->display_attributes.
WRITE: / 'Cargo max:', cargomax.
ENDMETHOD.
ENDCLASS.
The Main program that uses the classes
REPORT zbc404_hf_main .
* Super class
INCLUDE zbc404_hf_lcl_airplane.
* Sub classes
INCLUDE zbc404_hf_lcl_passenger_plane.
INCLUDE zbc404_hf_lcl_cargo_plane.
DATA:
* Type ref to sub classes. Note: It is not necesssary to make typeref to the superclass
o_passenger_airplane TYPE REF TO lcl_passenger_airplane,
o_cargo_plane TYPE REF TO lcl_cargo_plane.
START-OF-SELECTION.
* Display initial number of instances = 0
CALL METHOD lcl_airplane=>display_n_o_airplanes.
* Create objects
CREATE OBJECT o_passenger_airplane
EXPORTING
im_name = 'LH505'
im_planetype = 'Boing 747'
im_n_o_seats = 350.
CREATE OBJECT o_cargo_plane
EXPORTING
im_name = 'AR13'
im_planetype = 'DC 3'
im_cargomax = 35.
* Display attributes
CALL METHOD o_passenger_airplane->display_attributes.
CALL METHOD o_cargo_plane->display_attributes.
* Call static method display_n_o_airplanes
* Note: The syntax for calling a superclass method, differs from the syntax when calling a subclass method.
* When calling a superclass => must be used instead of ->
CALL METHOD lcl_airplane=>display_n_o_airplanes.
Result:
No. planes: 0 Name: LH505 Planetype: Boing 747 No. seats: 350 Name: AR13 Planetype: DC 3 Cargo max: 35,0000 No. planes: 2
Polymorphism
Polymorphism: When the same method is implemented differently in different classes. This can be done using enheritance, by redefining a method from the superclass in subclasses and implement it differently.
Classes:
• lcl_airplane Superclass
• lcl_cargo_airplane Subclass
• lcl_passenger_airplane Subclass
The method estimate_fuel_consumption is implemented differently in the 3 classes, as it depends on the airplane type.
Object from different classes are stored in an internal table (plane_list) consisting of references to the superclass, and the processed
identically for all the classes.
What coding for the estimate_fuel_consumption method taht is actually executed, depends on the dynamic type of the plane reference variable,
that is, depends on which object plane points to.
DATA: cargo_plane TYPE REF to lcl_cargo_airplane,
passenger_plane TYPE REF to lcl_passenger_airplane,
plane_list TYPE TABLE OF REF TO lcl_airplane.
* Creating the list of references
CREATE OBJECT cargo_plane.
APPEND cargo_plane to plane_list.
CREATE OBJECT passenger_plane
APPEND passenger_plane to plane list.
* Generic method for calucalting required fuel
METHOD calculate required_fuel.
DATA: plane TYPE REF TO lcl_airplane.
LOOP AT plane_list INTO plane.
re_fuel = re_fuel + plane->estimate_fuel_consumption( distance ).
ENDLOOP.
ENDMETHOD.
Working example:
This example assumes that the classes lcl_airplane, lcl_passnger_airplane and lcl_cargo plane (Se Subcallsing) exists.
Create objects of type lcl_cargo_plane and lcl_passenger_airplane, adds them to a list in lcl_carrier, and displays the list.
*&---------------------------------------------------------------------*
*& Include ZBC404_HF_LCL_CARRIER *
*& *
*&---------------------------------------------------------------------*
* CLASS lcl_carrier DEFINITION *
*----------------------------------------------------------------------
* CLASS lcl_carrier DEFINITION.
PUBLIC SECTION.
TYPES: BEGIN OF flight_list_type,
connid TYPE sflight-connid,
fldate TYPE sflight-fldate,
airplane TYPE REF TO lcl_airplane,
seatsocc TYPE sflight-seatsocc,
cargo(5) TYPE p DECIMALS 3,
END OF flight_list_type.
METHODS: constructor IMPORTING im_name TYPE string,
get_name RETURNING value(ex_name) TYPE string,
add_a_new_airplane IMPORTING
im_airplane TYPE REF TO lcl_airplane,
create_a_new_flight importing
im_connid type sflight-connid
im_fldate type sflight-fldate
im_airplane type ref to lcl_airplane
im_seatsocc type sflight-seatsocc
optional
im_cargo type p optional,
display_airplanes.
PRIVATE SECTION.
DATA: name TYPE string,
list_of_airplanes TYPE TABLE OF REF TO lcl_airplane,
list_of_flights TYPE TABLE OF flight_list_type.
ENDCLASS.
*---------------------------------------------------------------------*
* CLASS lcl_carrier IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS lcl_carrier IMPLEMENTATION.
METHOD constructor.
name = im_name.
ENDMETHOD.
METHOD get_name.
ex_name = name.
ENDMETHOD.
METHOD create_a_new_flight.
DATA: wa_list_of_flights TYPE flight_list_type.
wa_list_of_flights-connid = im_connid.
wa_list_of_flights-fldate = im_fldate.
wa_list_of_flights-airplane = im_airplane.
IF im_seatsocc IS INITIAL.
wa_list_of_flights-cargo = im_cargo.
ELSE.
wa_list_of_flights-seatsocc = im_seatsocc.
ENDIF.
APPEND wa_list_of_flights TO list_of_flights.
ENDMETHOD.
METHOD add_a_new_airplane.
APPEND im_airplane TO list_of_airplanes.
ENDMETHOD.
METHOD display_airplanes.
DATA: l_airplane TYPE REF TO lcl_airplane.
LOOP AT list_of_airplanes INTO l_airplane.
CALL METHOD l_airplane->display_attributes.
ENDLOOP.
ENDMETH
OD.
ENDCLASS.
REPORT zbc404_hf_main .
*******************************************************************
* This reprort uses class LCL_AIRPLNAE and subclasses
* LCL_CARGO_PLANE and LCL_PASSENGER_AIRPLANE and class LCL_CARRIER
*******************************************************************
* Super class for airplanes
INCLUDE zbc404_hf_lcl_airplane.
* Sub classes for airplanes
INCLUDE zbc404_hf_lcl_passenger_plane.
INCLUDE zbc404_hf_lcl_cargo_plane.
* Carrier class
INCLUDE zbc404_hf_lcl_carrier.
DATA:
* Type ref to classes
o_passenger_airplane TYPE REF TO lcl_passenger_airplane,
o_passenger_airplane2 TYPE REF TO lcl_passenger_airplane,
o_cargo_plane TYPE REF TO lcl_cargo_plane,
o_cargo_plane2 TYPE REF TO lcl_cargo_plane,
o_carrier TYPE REF TO lcl_carrier.
START-OF-SELECTION.
* Create objects
CREATE OBJECT o_passenger_airplane
EXPORTING
im_name = 'LH505'
im_planetype = 'Boing 747'
im_n_o_seats = 350.
CREATE OBJECT o_passenger_airplane2
EXPORTING
im_name = 'SK333'
im_planetype = 'MD80'
im_n_o_seats = 110.
CREATE OBJECT o_cargo_plane
EXPORTING
im_name = 'AR13'
im_planetype = 'DC 3'
im_cargomax = 35.
CREATE OBJECT o_cargo_plane2
EXPORTING
im_name = 'AFL124'
im_planetype = 'Iljutsin 2'
im_cargomax = 35000.
CREATE OBJECT o_carrier
EXPORTING im_name = 'Spritisch Airways'.
* Add passenger and cargo planes to the list of airplanes
CALL METHOD o_carrier->add_a_new_airplane
EXPORTING im_airplane = o_passenger_airplane.
CALL METHOD o_carrier->add_a_new_airplane
EXPORTING im_airplane = o_passenger_airplane2.
CALL METHOD o_carrier->add_a_new_airplane
EXPORTING im_airplane = o_cargo_plane.
CALL METHOD o_carrier->add_a_new_airplane
EXPORTING im_airplane = o_cargo_plane2.
* Display list of airplanes
call method o_carrier->display_airplanes.
Result:
Name: LH505 Planetype: Boing 747
No. seats: 350
Name: SK333 Planetype: MD80
No. seats: 110
Name: AR13 Planetype: DC 3
Cargo max: 35,0000
Name: AFL124 Planetype: Iljutsin 2
Cargo max: 35.000,0000
Events
Below is a simple example of how to implement an event.
REPORT zbc404_hf_events_5.
*---------------------------------------------------------------------*
* CLASS lcl_dog DEFINITION
*------------------------
---------------------------------------------*
CLASS lcl_dog DEFINITION.
PUBLIC SECTION.
* Declare events
EVENTS:
dog_is_hungry
EXPORTING value(ex_time_since_last_meal) TYPE i.
METHODS:
constructor
IMPORTING im_name TYPE string,
set_time_since_last_meal
IMPORTING im_time TYPE i,
on_dog_is_hungry FOR EVENT dog_is_hungry OF lcl_dog
IMPORTING ex_time_since_last_meal.
ENDCLASS.
*---------------------------------------------------------------------*
* CLASS lcl_dog IMPLEMENTATION
*----------------------------
-----------------------------------------*
CLASS lcl_dog IMPLEMENTATION.
METHOD constructor.
WRITE: / 'I am a dog and my name is', im_name.
ENDMETHOD.
METHOD set_time_since_last_meal.
IF im_time < 4.
SKIP 1.
WRITE: / 'You fool, I am not hungry yet'.
ELSE.
* Subsrcribe for event:
* set handler <Event handler method>
* FOR <ref_sender>!FOR ALL INSTANCES [ACTIVATION <var>]
SET HANDLER on_dog_is_hungry FOR ALL INSTANCES ACTIVATION 'X'.
* Raise event
RAISE EVENT dog_is_hungry
EXPORTING ex_time_since_last_meal = im_time.
ENDIF.
ENDMETHOD.
METHOD on_dog_is_hungry.
* Event method, called when the event dog_is_hungry is raised
SKIP 1.
WRITE: / 'You son of a bitch. I have not eaten for more than',
ex_time_since_last_meal, ' hours'.
WRITE: / 'Give me something to eat NOW!'.
ENDMETHOD.
ENDCLASS.
*---------------------------------------------------------------------*
* R E P O R T
*---------------------------------------------------------------------*
DATA: o_dog1 TYPE REF TO lcl_dog.
START-OF-SELECTION.
CREATE OBJECT o_dog1 EXPORTING im_name = 'Beefeater'.
CALL METHOD o_dog1->set_time_since_last_meal
EXPORTING im_time = 2.
* This method call will raise the event dog_is_hungy
* because time > 3
CALL METHOD o_dog1->set_time_since_last_meal
EXPORTING im_time = 5.
Result:
I am a dog and my name is Beefeater You fool, I am not hungry yet You son of a bitch. I have not eaten for more than 5 hours Give me something to eat NOW!
1. Simple class
This example shows how to create a simple employee class. The constructor method is used to initialize number and name of thje employee when the object is created. A display_employee method can be called to show the attributes of the employee, and CLASS-METHOD dosplay_no_of_employees can be called to
show the total number of employees (Number of instances of the employee class).
REPORT zbc404_hf_events_1.
*********************************************************************
* L C L _ E M P L O Y E E
*********************************************************************
*---- LCL Employee - Definition
CLASS lcl_employee DEFINITION.
PUBLIC SECTION.
*--------------------------------------------------------------------
* The public section is accesible from outside
*--------------------------------------------------------------------
TYPES:
BEGIN OF t_employee,
no TYPE i,
name TYPE string,
END OF t_employee.
METHODS:
constructor
IMPORTING im_employee_no TYPE i
im_employee_name TYPE string,
display_employee.
* Class methods are global for all instances
CLASS-METHODS: display_no_of_employees.
PROTECTED SECTION.
*--------------------------------------------------------------------
* The protecetd section is accesible from the class and its subclasses
*--------------------------------------------------------------------
* Class data are global for all instances
CLASS-DATA: g_no_of_employees TYPE i.
PRIVATE SECTION.
*--------------------------------------------------------------------
* The private section is only accesible from within the classs
*--------------------------------------------------------------------
DATA: g_employee TYPE t_employee.
ENDCLASS.
*--- LCL Employee - Implementation
CLASS lcl_employee IMPLEMENTATION.
METHOD constructor.
g_employee-no = im_employee_no.
g_employee-name = im_employee_name.
g_no_of_employees = g_no_of_employees + 1.
ENDMETHOD.
METHOD display_employee.
WRITE:/ 'Employee', g_employee-no, g_employee-name.
ENDMETHOD.
METHOD display_no_of_employees.
WRITE: / 'Number of employees is:', g_no_of_employees.
ENDMETHOD.
ENDCLASS.
************************************************************************
* R E P O R T
*********************************************************************
DATA: g_employee1 TYPE REF TO lcl_employee,
g_employee2 TYPE REF TO lcl_employee.
START-OF-SELECTION.
CREATE OBJECT g_employee1
EXPORTING im_employee_no = 1
im_employee_name = 'John Jones'.
CREATE OBJECT g_employee2
EXPORTING im_employee_no = 2
im_employee_name = 'Sally Summer'.
CALL METHOD g_employee1->display_employee.
CALL METHOD g_employee2->display_employee.
CALL METHOD g_employee2->display_no_of_employees.
2. Inheritance and polymorphism
This example uses a superclass lcl_company_employees and two subclasses lcl_bluecollar_employee and lcl_whitecollar_employee to add employees to a list and then display a list of employees and there wages. The wages are calcukated in the method add_employee, but as the wages are calculated differently for blue collar employees and white collar emplyees, the superclass method add_employee is redeifined in the subclasses.
Principles:
Create super class LCL_CompanyEmployees.
The class has the methods:
• Constructor
• Add_Employee - Adds a new employee to the list of employees
• Display_Employee_List - Displays all employees and there wage
• Display_no_of_employees - Displays total number of employees
Note the use of CLASS-DATA to keep the list of employees and number of employees the same from instance to instance.
Create subclasses lcl_bluecollar_employee and lcl_whitecollar_employee. The calsses are identical, except for the redifinition of the add_employee method, where the caclculation of wage is different.
Methodes:
• Constructor. The constructor is used to initialize the attributes of the employee. Note that the constructor in the supclasss has to be called from within the constructor of the subclass.
• Add_Employee. This is a redinition of the same method in the superclass. In the redefined class the wage is calcuated, and the superclass method is called to add the employees to the emploee list.:
The program
REPORT zbc404_hf_events_2 .
*******************************************************
* Super class LCL_CompanyEmployees
*******************************************************
CLASS lcl_company_employees DEFINITION.
PUBLIC SECTION.
TYPES:
BEGIN OF t_employee,
no TYPE i,
name TYPE string,
wage TYPE i,
END OF t_employee.
METHODS:
constructor,
add_employee
IMPORTING im_no TYPE i
im_name TYPE string
im_wage TYPE i,
display_employee_list,
display_no_of_employees.
PRIVATE SECTION.
CLASS-DATA: i_employee_list TYPE TABLE OF t_employee,
no_of_employees TYPE i.
ENDCLASS.
*-- CLASS LCL_CompanyEmployees IMPLEMENTATI
ON
CLASS lcl_company_employees IMPLEMENTATION.
METHOD constructor.
no_of_employees = no_of_employees + 1.
ENDMETHOD.
METHOD add_employee.
* Adds a new employee to the list of employees
DATA: l_employee TYPE t_employee.
l_employee-no = im_no.
l_employee-name = im_name.
l_employee-wage = im_wage.
APPEND l_employee TO i_employee_list.
ENDMETHOD.
METHOD display_employee_list.
* Displays all employees and there wage
DATA: l_employee TYPE t_employee.
WRITE: / 'List of Employees'.
LOOP AT i_employee_list INTO l_employee.
WRITE: / l_employee-no, l_employee-name, l_employee-wage.
ENDLOOP.
ENDMETHOD.
METHOD display_no_of_employees.
* Displays total number of employees
SKIP 3.
WRITE: / 'Total number of employees:', no_of_employees.
ENDMETHOD.
ENDCLASS.
*******************************************************
* Sub class LCL_BlueCollar_Employee
*****************************************
**************
CLASS lcl_bluecollar_employee DEFINITION
INHERITING FROM lcl_company_employees.
PUBLIC SECTION.
METHODS:
constructor
IMPORTING im_no TYPE i
im_name TYPE string
im_hours TYPE i
im_hourly_payment TYPE i,
add_employee REDEFINITION.
PRIVATE SECTION.
DATA:no TYPE i,
name TYPE string,
hours TYPE i,
hourly_payment TYPE i.
ENDCLASS.
*---- CLASS LCL_BlueCollar_Employee IMPLEMENT
ATION
CLASS lcl_bluecollar_employee IMPLEMENTATION.
METHOD constructor.
* The superclass constructor method must be called from the subclass
* constructor method
CALL METHOD super->constructor.
no = im_no.
name = im_name.
hours = im_hours.
hourly_payment = im_hourly_payment.
ENDMETHOD.
METHOD add_employee.
* Calculate wage an call the superclass method add_employee to add
* the employee to the employee list
DATA: l_wage TYPE i.
l_wage = hours * hourly_payment.
CALL METHOD super->add_employee
EXPORTING im_no = no
im_name = name
im_wage = l_wage.
ENDMETHOD.
ENDCLASS.
*******************************************************
* Sub class LCL_WhiteCollar_Employee
******************************************
*************
CLASS lcl_whitecollar_employee DEFINITION
INHERITING FROM lcl_company_employees.
PUBLIC SECTION.
METHODS:
constructor
IMPORTING im_no TYPE i
im_name TYPE string
im_monthly_salary TYPE i
im_monthly_deductions TYPE i,
add_employee REDEFINITION.
PRIVATE SECTION.
DATA:
no TYPE i,
name TYPE string,
monthly_salary TYPE i,
monthly_deductions TYPE i.
ENDCLASS.
*---- CLASS LCL_WhiteCollar_Employee IMPLEMENTATION
CLASS lcl_whitecollar_employee IMPLEMENTATION.
METHOD constructor.
* The superclass constructor method must be called from the subclass
* constructor method
CALL METHOD super->constructor.
no = im_no.
name = im_name.
monthly_salary = im_monthly_salary.
monthly_deductions = im_monthly_deductions.
ENDMETHOD.
METHOD add_employee.
* Calculate wage an call the superclass method add_employee to add
* the employee to the employee list
DATA: l_wage TYPE i.
l_wage = monthly_salary - monthly_deductions.
CALL METHOD super->add_employee
EXPORTING im_no = no
im_name = name
im_wage = l_wage.
ENDMETHOD.
ENDCLASS.
*******************************************************
* R E P O R T
*******************************************************
DATA:
* Object references
o_bluecollar_employee1 TYPE REF TO lcl_bluecollar_employee,
o_whitecollar_employee1 TYPE REF TO lcl_whitecollar_employee.
START-OF-SELECTION.
* Create bluecollar employee obeject
CREATE OBJECT o_bluecollar_employee1
EXPORTING im_no = 1
im_name = 'Gylle Karen'
im_hours = 38
im_hourly_payment = 75.
* Add bluecollar employee to employee list
CALL METHOD o_bluecollar_employee1->add_employee
EXPORTING im_no = 1
im_name = 'Gylle Karen'
im_wage = 0.
* Create whitecollar employee obeject
CREATE OBJECT o_whitecollar_employee1
EXPORTING im_no = 2
im_name = 'John Dickens'
im_monthly_salary = 10000
im_monthly_deductions = 2500.
* Add bluecollar employee to employee list
CALL METHOD o_whitecollar_employee1->add_employee
EXPORTING im_no = 1
im_name = 'Karen Johnson'
im_wage = 0.
* Display employee list and number of employees. Note that the result
* will be the same when called from o_whitecollar_employee1 or
* o_bluecolarcollar_employee1, because the methods are defined
* as static (CLASS-METHODS)
CALL METHOD o_whitecollar_employee1->display_employee_list.
CALL METHOD o_whitecollar_employee1->display_no_of_employees.
The resulting report
List of Employees 1 Karen Johnson 2.850 2 John Dickens 7.500 Total number of employees: 2
3. Interfaces
This example is similiar to th eprevious example, however an interface is implemented with the method add_employee. Note that the interface is only implemented in the superclass ( The INTERFACE stament), but also used in the subclasses.
The interface in the example only contains a method, but an iterface can also contain attrbutes, constants, types and alias names.
The output from example 3 is similiar to the output in example 2.
All changes in the program compared to example 2 are marked with red.
REPORT zbc404_hf_events_3 .
*---------------------------------------------------------------------*
* INTERFACE lif_employee
*---------------------------------------------------------------------*
INTERFACE lif_employee.
METHODS:
add_employee
IMPORTING im_no TYPE i
im_name TYPE string
im_wage TYPE i.
ENDINTERFACE.
*******************************************************
* Super class LCL_CompanyEmployees
*******************************************************
CLASS lcl_company_employees DEFINITION.
PUBLIC SECTION.
INTERFACES lif_employee.
TYPES:
BEGIN OF t_employee,
no TYPE i,
name TYPE string,
wage TYPE i,
END OF t_employee.
METHODS:
constructor,
* add_employee "Removed
IMPORTING im_no TYPE i
im_name TYPE string
im_wage TYPE i,
display_employee_list,
display_no_of_employees.
PRIVATE SECTION.
CLASS-DATA: i_employee_list TYPE TABLE OF t_employee,
no_of_employees TYPE i.
ENDCLASS.
*-- CLASS LCL_CompanyEmployees IMPLEMENTATION
CLASS lcl_company_employees IMPLEMENTATION.
METHOD constructor.
no_of_employees = no_of_employees + 1.
ENDMETHOD.
METHOD lif_employee~add_employee.
* Adds a new employee to the list of employees
DATA: l_employee TYPE t_employee.
l_employee-no = im_no.
l_employee-name = im_name.
l_employee-wage = im_wage.
APPEND l_employee TO i_employee_list.
ENDMETHOD.
METHOD display_employee_list.
* Displays all employees and there wage
DATA: l_employee TYPE t_employee.
WRITE: / 'List of Employees'.
LOOP AT i_employee_list INTO l_employee.
WRITE: / l_employee-no, l_employee-name, l_employee-wage.
ENDLOOP.
ENDMETHOD.
METHOD display_no_of_employees.
* Displays total number of employees
SKIP 3.
WRITE: / 'Total number of employees:', no_of_employees.
ENDMETHOD.
ENDCLASS.
*******************************************************
* Sub class LCL_BlueCollar_Employee
*******************************************************
CLASS lcl_bluecollar_employee DEFINITION
INHERITING FROM lcl_company_employees.
PUBLIC SECTION.
METHODS:
constructor
IMPORTING im_no TYPE i
im_name TYPE string
im_hours TYPE i
im_hourly_payment TYPE i,
lif_employee~add_employee REDEFINITION..
PRIVATE SECTION.
DATA:no TYPE i,
name TYPE string,
hours TYPE i,
hourly_payment TYPE i. ENDCLASS.
*---- CLASS LCL_BlueCollar_Employee IMPLEMENTATION
CLASS lcl_bluecollar_employee IMPLEMENTATION.
METHOD constructor.
* The superclass constructor method must be called from the subclass
* constructor method
CALL METHOD super->constructor.
no = im_no.
name = im_name.
hours = im_hours.
hourly_payment = im_hourly_payment.
ENDMETHOD.
METHOD lif_employee~add_employee.
* Calculate wage an call the superclass method add_employee to add
* the employee to the employee list
DATA: l_wage TYPE i.
l_wage = hours * hourly_payment.
CALL METHOD super->lif_employee~add_employee
EXPORTING im_no = no
im_name = name
im_wage = l_wage.
ENDMETHOD.
ENDCLASS.
*******************************************************
* Sub class LCL_WhiteCollar_Employee
*******************************************************
CLASS lcl_whitecollar_employee DEFINITION
INHERITING FROM lcl_company_employees.
PUBLIC SECTION.
METHODS:
constructor
IMPORTING im_no TYPE i
im_name TYPE string
im_monthly_salary TYPE i
im_monthly_deductions TYPE i,
lif_employee~add_employee REDEFINITION.
PRIVATE SECTION.
DATA:
no TYPE i,
name TYPE string,
monthly_salary TYPE i,
monthly_deductions TYPE i.
ENDCLASS.
*---- CLASS LCL_WhiteCollar_Employee IMPLEMENTATION
CLASS lcl_whitecollar_employee IMPLEMENTATION.
METHOD constructor.
* The superclass constructor method must be called from the subclass
* constructor method
CALL METHOD super->constructor.
no = im_no.
name = im_name.
monthly_salary = im_monthly_salary.
monthly_deductions = im_monthly_deductions.
ENDMETHOD.
METHOD lif_employee~add_employee.
* Calculate wage an call the superclass method add_employee to add
* the employee to the employee list
DATA: l_wage TYPE i.
l_wage = monthly_salary - monthly_deductions.
CALL METHOD super->lif_employee~add_employee
EXPORTING im_no = no
im_name = name
im_wage = l_wage.
ENDMETH
OD.
ENDCLASS.
*******************************************************
* R E P O R T
*******************************************************
DATA:
* Object references
o_bluecollar_employee1 TYPE REF TO lcl_bluecollar_employee,
o_whitecollar_employee1 TYPE REF TO lcl_whitecollar_employee.
START-OF-SELECTION.
* Create bluecollar employee obeject
CREATE OBJECT o_bluecollar_employee1
EXPORTING im_no = 1
im_name = 'Gylle Karen'
im_hours = 38
im_hourly_payment = 75.
* Add bluecollar employee to employee list
CALL METHOD o_bluecollar_employee1->lif_employee~add_employee
EXPORTING im_no = 1
im_name = 'Karen Johnson'
im_wage = 0.
* Create whitecollar employee obeject
CREATE OBJECT o_whitecollar_employee1
EXPORTING im_no = 2
im_name = 'John Dickens'
im_monthly_salary = 10000
im_monthly_deductions = 2500.
* Add bluecollar employee to employee list
CALL METHOD o_whitecollar_employee1->lif_employee~add_employee
EXPORTING im_no = 1
im_name = 'Gylle Karen'
im_wage = 0.
* Display employee list and number of employees. Note that the result
* will be the same when called from o_whitecollar_employee1 or
* o_bluecolarcollar_employee1, because the methods are defined
* as static (CLASS-METHODS)
CALL METHOD o_whitecollar_employee1->display_employee_list.
CALL METHOD o_whitecollar_employee1->display_no_of_employees.
4. Events
This is the same example as example 4. All changes are marked with red. There have been no canges to the subclasses, only to the superclass and the report, sp the code for th esubclasses is not shown.
For a simple example refer to Events in Examples.
REPORT zbc404_hf_events_4 .
*---------------------------------------------------------------------*
* INTERFACE lif_employee
*---------------------------------------------------------------------*
INTERFACE lif_employee.
METHODS:
add_employee
IMPORTING im_no TYPE i
im_name TYPE string
im_wage TYPE i.
ENDINTERFACE.
*******************************************************
* Super class LCL_CompanyEmployees
*******************************************************
CLASS lcl_company_employees DEFINITION.
PUBLIC SECTION.
TYPES:
BEGIN OF t_employee,
no TYPE i,
name TYPE string,
wage TYPE i,
END OF t_employee.
* Declare event. Note that declaration could also be placed in the
* interface
EVENTS: employee_added_to_list
EXPORTING value(ex_employee_name) TYPE string.
* CLASS-EVENTS: Events can also be defined as class-events
INTERFACES lif_employee.
METHODS:
constructor,
display_employee_list,
display_no_of_employees,
* Declare event method
on_employee_added_to_list FOR EVENT employee_added_to_list OF lcl_company_employees
IMPORTING ex_employee_name sender.
PRIVATE SECTION.
CLASS-DATA:
i_employee_list TYPE TABLE OF t_employee,
no_
of_employees TYPE i.
ENDCLASS.
*-- CLASS LCL_CompanyEmployees IMPLEMENTATI
ON
CLASS lcl_company_employees IMPLEMENTATION.
METHOD constructor.
no_of_employees = no_of_employees + 1.
ENDMETHOD.
METHOD lif_employee~add_employee.
* Adds a new employee to the list of employees
DATA: l_employee TYPE t_employee.
l_employee-no = im_no.
l_employee-name = im_name.
l_employee-wage = im_wage.
APPEND l_employee TO i_employee_list.
* Raise event employee_added_to_list
RAISE EVENT employee_added_to_list
EXPORTING ex_employee_name = l_employee-name.
ENDMETHOD.
METHOD display_employee_list.
* Displays all employees and there wage
DATA: l_employee TYPE t_employee.
WRITE: / 'List of Employees'.
LOOP AT i_employee_list INTO l_employee.
WRITE: / l_employee-no, l_employee-name, l_employee-wage.
ENDLOOP.
ENDMETHOD.
METHOD display_no_of_employees.
* Displays total number of employees
SKIP 3.
WRITE: / 'Total number of employees:', no_of_employees.
ENDMETHOD.
METHOD on_employee_added_to_list.
* Event method
WRITE: / 'Employee added to list', ex_employee_name.
ENDMETH
OD.
ENDCLASS.
*******************************************************
* Sub class LCL_BlueCollar_Employee
*******************************************************
CLASS lcl_bluecollar_employee DEFINITION
INHERITING FROM lcl_company_employees.
See code in example 3...
ENDCLASS.
CLASS lcl_bluecollar_employee IMPLEMENTATION.
See code in example 3...
ENDCLASS.
*******************************************************
* Sub class LCL_WhiteCollar_Employee
*******************************************************
CLASS lcl_whitecollar_employee DEFINITION
See code in example 3...
ENDCLASS.
CLASS lcl_whitecollar_employee IMPLEMENTATION.
See code in example 3...
ENDCLASS.
*******************************************************
* R E P O R T
*******************************************************
DATA:
* Object references
o_bluecollar_employee1 TYPE REF TO lcl_bluecollar_employee,
o_whitecollar_employee1 TYPE REF TO lcl_whitecollar_employee.
START-OF-SELECTION.
* Create bluecollar employee obeject
CREATE OBJECT o_bluecollar_employee1
EXPORTING im_no = 1
im_name = 'Karen Johnson'
im_hours = 38
im_hourly_payment = 75.
* Register event for o_bluecollar_employee1
SET HANDLER o_bluecollar_employee1->on_employee_added_to_list
FOR o_bluecollar_employee1.
* Add bluecollar employee to employee list
CALL METHOD o_bluecollar_employee1->lif_employee~add_employee
EXPORTING im_no = 1
im_name = 'Gylle Karen'
im_wage = 0.
* Create whitecollar employee obeject
CREATE OBJECT o_whitecollar_employee1
EXPORTING im_no = 2
im_name = 'John Dickens'
im_monthly_salary = 10000
im_monthly_deductions = 2500.
* Register event for o_whitecollar_employee1
SET HANDLER o_whitecollar_employee1->on_employee_added_to_list
FOR o_whitecollar_employee1.´
* Add bluecollar employee to employee list
CALL METHOD o_whitecollar_employee1->lif_employee~add_employee
EXPORTING im_no = 1
im_name = 'Gylle Karen'
im_wage = 0.
* Display employee list and number of employees. Note that the result
* will be the same when called from o_whitecollar_employee1 or
* o_bluecolarcollar_employee1, because the methods are defined
* as static (CLASS-METHODS)
CALL METHOD o_whitecollar_employee1->display_employee_list.
CALL METHOD o_whitecollar_employee1->display_no_of_employees.
Result:
Employee added to list Karen Johnson Employee added to list John Dickens List of Employees 1 Karen Johnson 2.850 2 John Dickens 7.500 Total number of employees: 2
General
Control Framework and enheritance hierarchy
The control framework consists of 2 parts:
• CL_GUI_CFW contains methods that provide services for communication with the frontend, and can be used both by control wrapper calsses and by control progtrammers
• The CL_GUI_OBJECT encapsulates ActiveX or JavaBeans methods, while CL_GUI_CONTROL is responsible for displaying the control on the screen.
CL_GUI_OBJECT -> CL_GUI_CONTROL -> CL_GUI_* (Wrapper class)
These classes contains methods that are enherited by subsequent classes in the enheritance tree.
Synchronization/Flush
RFC calls is used to synchronize the front and backend. This synchronization takes palce at some predifined points in the program flow. However you should not rely entirely on automatic synchronization, but force synchronization with the Flush method when necessary.
Bear in mind that the synchronization/RFC calls represenmts a bottleneck, so you should keep the not use the Flush method to a minimum.
Syntax:
CALL METHOD cl_gui_cfw=>FLUSH
Set up event handling for controls
There are two types of events:
Application events. T
The flow logic of the screen is processed after the event (The PAI module is processed).
In the events table the event must be registred as an application event by setting then field appl_event to 'X':
wa_events-eventid = cl_gui_textedit=>event_double_click. wa_events-appl_event = 'X'. append wa_events to i_events.
Important: The dispatch method of cl_gui_cfw must be called in the PAI module:
CALL METHOD cl_gui_cfw=>dispatch.
System events.
For system events the flow-logic of the screen is not executed. That means that the PAI and PBO modules are not processed.
In the events table the the field appl_event must be set to SAPCE:
wa_events-eventid = cl_gui_textedit=>event_double_click. wa_events-appl_event = space. append wa_events to i_events.
The dispatch method of cl_gui_cfw must NOT be called.
Example
It is presumed that a SAP toolbar control named go_toolbar of class cl_gui_toolbar has been defined. To see a complete example of how to handle events, refer to The SAP toolbar control.
Data:
* 1. Define and instance of the eventhandler class.
* If the event handler class is defined after the data decalaration
* the class must be declared as DEFERRED in the top of the program: CLASS cls_event_handler DEFINITION DEFERRED.
go_event_handler TYPE REF TO cls_event_handler,
* 2. Define table for registration of events.
* Note that a TYPE REF to cls_event_handler must be created before you can
* reference types cntl_simple_events and cntl_simple_event
gi_events TYPE cntl_simple_events,
* Workspace for table gi_events
g_event TYPE cntl_simple_event.
* 3. Define and implement eventhandler class
CLASS cls_event_handler DEFINITION.
PUBLIC SECTION.
METHODS:
* Syntax:
* <method name> FOR EVENT <event of control - see the control documentation>
* OF <class of object> <importing parameters l - see the control documentation>
on_function_selected
FOR EVENT function_selected OF cl_gui_toolbar
IMPORTING fcode,
ENDCLASS.
CLASS cls_event_handler IMPLEMENTATION.
METHOD on_function_selected.
* Do something when the event is raised
ENDMETHOD.
ENDCLASS.
* 4. Append events to the events table
* The Event Id can be found in the control documentation. Note that The event below is registred as an application event
g_event-eventid = go_toolbar->m_id_function_selected.
g_event-appl_event = 'X'. "This is an application event
APPEND g_event TO gi_events.
.... append more events i necessary...
* 5. Use the events table to register events for the control
CALL METHOD go_toolbar->set_registered_events
EXPORTING
events = gi_events.
* 6. Create event handler
CREATE OBJECT go_event_handler.
* Syntax:
* SET HANDLER <event handler class> -> <Event handler method>
* FOR <control>
SET HANDLER go_event_handler->on_function_selected
FOR go_toolbar.
Declare a reference variable before the class has been defined
Scenario:
DATA: o_my_class TYPE REF TO lcl_myclass.
CLASS lcl_myclass..... ENDCLASS.
This will cause an error because the definition of class lcl_myclass is after the declaration.
Solution:
Define the class in the beginning of the program with DEFINITION DEFERRED:
CLASS lcl_myclass DEFINITION DEFERRED.
DATA: o_my_class TYPE REF TO lcl_myclass.
CLASS lcl_myclass..... ENDCLASS.
Set focus to a control
Set the focus to a control named go_grid:
CALL METHOD cl_gui_control=>set_focus
EXPORTING control = go_grid.
To Use BADI - Business Add In you need to Understand ABAP OO Interface Concept
Content Author: Jayanta Narayan Choudhuri Author Email: sss@cal.vsnl.net.in Author Website: http://www.geocities.com/ojnc
* For Rajat's OO ans BAdI Education
Report Z_CTRY.
* A Shape Interface "Like a shape" "Behaves like a Shape"
Adverb/Adjective
Interface IShape.
Methods: getArea Returning Value(area) Type F,
getCircumference Returning Value(circumference) Type F.
Endinterface.
* A Circle Class that behaves like a Shape
Class CCircle Definition.
Public Section.
Interfaces IShape.
Aliases: getArea For IShape~getArea,
getCircumference For IShape~getCircumference.
Methods: Constructor Importing pRadius Type F,
setRadius Importing pRadius Type F,
getRadius Returning Value(pRadius) Type F.
Private Section.
Data radius Type F.
Constants PI Type F Value '3.141592365359'.
EndClass.
Class CCircle Implementation.
Method Constructor.
radius = pRadius.
EndMethod.
Method setRadius.
radius = pRadius.
EndMethod.
Method getRadius.
pRadius = radius.
EndMethod.
Method IShape~getArea.
Compute area = 2 * PI * radius.
EndMethod.
Method IShape~getCircumference.
Compute circumference = PI * radius * radius.
EndMethod.
EndClass.
* A Square Class
Class CSquare Definition.
Public Section.
Interfaces IShape.
Aliases: getArea For IShape~getArea,
getCircumference For IShape~getCircumference.
Methods: Constructor Importing pSide Type F.
Private Section.
Data side Type F.
EndClass.
Class CSquare Implementation.
Method Constructor.
side = pSide.
EndMethod.
Method IShape~getArea.
Compute area = side * side.
EndMethod.
Method IShape~getCircumference.
Compute circumference = 4 * side.
EndMethod.
EndClass.
* A Rectangle Class
Class CRectangle Definition.
Public Section.
Interfaces IShape.
Aliases: getArea For IShape~getArea,
getCircumference For IShape~getCircumference.
Methods: Constructor Importing pHeight Type F
pLength Type F.
Private Section.
Data: height Type F,
length Type F.
EndClass.
Class CRectangle Implementation.
Method Constructor.
height = pHeight.
length = pLength.
EndMethod.
Method IShape~getArea.
Compute area = height * length.
EndMethod.
Method IShape~getCircumference.
Compute circumference = 2 * ( height + length ).
EndMethod.
EndClass.
* START of PROGRAM
* Array of Shapes
Data: OneShape Type Ref To IShape, " One Object with
Shape Behaviour
ShapeTable Type Table Of Ref To IShape. " Array of Objects
with Shape Behaviour
* Concrete Objects with IShape Behaviour!
Data: C1 Type Ref To CCircle,
S1 Type Ref To CSquare,
R1 Type Ref To CRectangle,
C2 Type Ref To CCircle,
S2 Type Ref To CSquare,
R2 Type Ref To CRectangle.
Data: descr_ref TYPE ref to CL_ABAP_TYPEDESCR,
ClassName Type String,
Serial Type I.
Data: myArea Type F,
myCircumference Type F.
START-OF-SELECTION.
Create Object C1 Exporting pRadius = '2.5'.
Create Object C2 Exporting pRadius = '5.0'.
Create Object S1 Exporting pSide = '3.5'.
Create Object S2 Exporting pSide = '6.0'.
Create Object R1 Exporting pHeight = '2.8' pLength = '3.4'.
Create Object R2 Exporting pHeight = '1.7' pLength = '6.3'.
* Append in any order!
Append S1 to ShapeTable.
Append R2 to ShapeTable.
Append R1 to ShapeTable.
Append C2 to ShapeTable.
Append C1 to ShapeTable.
Append S2 to ShapeTable.
Serial = 0.
Loop At ShapeTable into OneShape.
Call Method OneShape->getArea
Receiving area = myArea.
Call Method OneShape->getCircumference
Receiving circumference = myCircumference.
descr_ref = CL_ABAP_TYPEDESCR=>Describe_By_Object_Ref( OneShape
).
Call Method descr_ref->get_relative_name
Receiving P_RELATIVE_NAME = ClassName.
Add 1 to Serial.
Write: / Serial, ClassName.
Write: / 'Area ', myArea Decimals 4 Exponent
0.
Write: / 'Circumference ', myCircumference Decimals 4 Exponent
0.
Write: /.
EndLoop.
** Results
* 1 CSQUARE
* Area 12.2500
* Circumference 14.0000
*
* 2 CRECTANGLE
* Area 10.7100
* Circumference 16.0000
*
* 3 CRECTANGLE
* Area 9.5200
* Circumference 12.4000
*
* 4 CCIRCLE
* Area 31.4159
* Circumference 78.5398
*
* 5 CCIRCLE
* Area 15.7080
* Circumference 19.6350
*
* 6 CSQUARE
* Area 36.0000
* Circumference 24.0000
Example 1: Creating the TextEdit control
This is a simple example of how to implement a text edit control.
Steps
1. Create a report
2. In the start of selection event add: SET SCREEN '100'.
3. Create screen 100
4. Place a custom control on the screen by choosing the custom control icon which can be recognized by the letter 'C', and give it the name MYCONTAINER1.
5. To be able to exit the program, add a pushbutton with the function code EXIT.
6. In the elements list enter the name OK_CODE for the element of type OK.
The code
REPORT sapmz_hf_controls1 .
CONSTANTS:
line_length TYPE i VALUE 254.
DATA: ok_code LIKE sy-ucomm.
DATA:
* Create reference to the custom container
custom_container TYPE REF TO cl_gui_custom_container,
* Create reference to the TextEdit control
editor TYPE REF TO cl_gui_textedit,
repid LIKE sy-repid.
START-OF-SELECTION.
SET SCREEN '100'.
*---------------------------------------------------------------------*
* MODULE USER_COMMAND_0100 INPUT *
*---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'EXIT'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
* The TextEdit control shoul only be initialized the first time the
* PBO module executes
IF editor IS INITIAL.
repid = sy-repid.
* Create obejct for custom container
CREATE OBJECT custom_container
EXPORTING
container_name = 'MYCONTAINER1'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Create obejct for the TextEditor control
CREATE OBJECT editor
EXPORTING
wordwrap_mode =
cl_gui_textedit=>wordwrap_at_fixed_position
wordwrap_position = line_length
wordwrap_to_linebreak_mode = cl_gui_textedit=>true
parent = custom_container
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
gui_type_not_supported = 5
others = 6
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
The result
Example 2: Event handling - Application event
There are 2 types of events:
• System events. These events are triggerede irrespective of the screen flow-logic.
• Application events. The PAI module is processed after an event. The method CL_GUI_CFW=>DISPATCH must be called to initiate event handling
In this example an application event is added to the program in example 1. New code is marked with red.
Steps:
1. Create an input/output field on screen 100, where the event type can be output. Name it EVENT_TYPE
The code:
REPORT sapmz_hf_controls1 .
CONSTANTS:
line_length TYPE i VALUE 254.
DATA: ok_code LIKE sy-ucomm.
DATA:
* Create reference to the custom container
custom_container TYPE REF TO cl_gui_custom_container,
* Create reference to the TextEdit control
editor TYPE REF TO cl_gui_textedit,
repid LIKE sy-repid.
**********************************************************************
* Impmenting events
**********************************************************************
DATA:
event_type(20) TYPE c,
* Internal table for events that should be registred
i_events TYPE cntl_simple_events,
* Structure for oneline of the table
wa_events TYPE cntl_simple_event.
*---------------------------------------------------------------------*
* CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
catch_dblclick FOR EVENT dblclick
OF cl_gui_textedit IMPORTING sender.
ENDCLASS.
CLASS lcl_event_handler IMPLEMENTATION.
METHOD catch_dblclick.
event_type = 'Event DBLCLICK raised'.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
CLEAR wa_events. refresh i_events.
SET SCREEN '100'.
*---------------------------------------------------------------------*
* MODULE USER_COMMAND_0100 INPUT *
*---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'EXIT'.
LEAVE TO SCREEN 0.
WHEN OTHERS.
* Call the Dispacth method to initiate application event handling call method cl_gui_cfw=>Dispatch.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
* The TextEdit control shoul only be initialized the first time the
* PBO module executes
IF editor IS INITIAL.
repid = sy-repid.
* Create obejct for custom container
CREATE OBJECT custom_container
EXPORTING
container_name = 'MYCONTAINER1'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Create obejct for the TextEditor control
CREATE OBJECT editor
EXPORTING
wordwrap_mode =
cl_gui_textedit=>wordwrap_at_fixed_position
wordwrap_position = line_length
wordwrap_to_linebreak_mode = cl_gui_textedit=>true
parent = custom_container
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
gui_type_not_supported = 5
others = 6
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF. * Link the event handler method to the event and the
* TextEdit control
SET HANDLER lcl_event_handler=>catch_dblclick FOR
editor.
* Register the event in the internal table i_events
wa_events-eventid = cl_gui_textedit=>event_double_click.
wa_events-appl_event = 'X'. "This is an application event
append wa_events to i_events.
* Pass the table to the TextEdit control using method
* set_registred_events
call method editor->set_registered_events
exporting events = i_events.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
Result:
When you double click on the TextEdit control, the input/ouput field should show the text: Event DBLCLICK
Example 3: Event handling - System event
System events are passed irrespective of the flow-logic of the screen. To implement a system event change the code from example 2 as follows:
Code:
CLASS lcl_event_handler IMPLEMENTATION.
METHOD catch_dblclick.
*--- event_type = 'Event DBLCLICK raised'.
* Reacting to the system event
call method cl_gui_cfw=>set_new_ok_code
exporting new_code = 'SHOW'.
MODULE user_command_0100 INPUT.
CASE ok_code.
code.........
WHEN 'SHOW'.
event_type = 'System dblclick'.
WHEN OTHERS.
*---- call method cl_gui_cfw=>Dispatch.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
MODULE status_0100 OUTPUT.
Code ................
*--- wa_events-appl_event = 'X'. "This is an application event
wa_events-appl_event = space. "This is a system event
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
Result:
When you double clicks on the TextEdit control nothing happens, since the flow-logic of the screen an dthe fielde transport is ignore.
Example 4: Calling methods of the control
In this exercise a function that loads the texts of an internal table into the text window, is implemented.
Steps:
Define anoterh pushbutton on the screen, that activates the method that fills the TextEdit control. Give itname PUSHBUTTON_IMPORT and function code IMP.
Define a form CREATE_TEXTS that carries out the text import.
Only changes to the code in example 2 is show.
Code:
MODULE user_command_0100 INPUT.
CASE ok_code.
code.........
WHEN 'IMP'.
perform load_texts.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form load_texts
*&---------------------------------------------------------------------*
* This form creates an internal table with texts. The the contents of
* the table is instered into the TextEdit control using method
* set_text_as_r3table
*----------------------------------------------------------------------*
FORM load_texts.
TYPES:
BEGIN OF t_texttable,
line(line_length) TYPE c,
END OF t_texttable.
DATA
i_texttable TYPE TABLE OF t_texttable.
* Create internal table with texts
APPEND 'This a method that fills the TextEdit control' TO i_texttable.
APPEND 'with a text.' TO i_texttable.
DO 10 TIMES.
APPEND 'hallo world !' TO i_texttable.
ENDDO.
* Load TextEdit control with texts
CALL METHOD editor->set_text_as_r3table
EXPORTING table = i_texttable.
IF sy-subrc > 0.
* Display an error message
EXIT.
ENDIF.
* All methods that operates on controls are transferred to the frontend
* by a RFC calls. the method FLUSH is used to determine when this is done.
CALL METHOD cl_gui_cfw=>flush.
IF sy-subrc > 0.
* Display an error message
ENDIF.
ENDFORM. " create_texts
Example 5: Responding to an event
When you double click on a text line in the TextEdit control, you want it to be prefixed with a '*'.
The line number of the TextEdit control that is double clicked, is retreived using method GET_SELECTION_POS. The internal text table is reloaded froim the TextEdit control with method GET_TEXT_AS_R3TABLE. The position of the double click in the TextEdit control is used to find the entry in the table, and the entry is prefixed with '*' and loaded into the TextEdit control again.
The program should be changed so that the internal table i_texttable is global, and a global flag g_loaded added. The load of the table should be moved to the PBO module. The changes in thje code are marked with red. The whole program now looks like this:
Code
REPORT sapmz_hf_controls1 .
CONSTANTS:
line_length TYPE i VALUE 254.
DATA: ok_code LIKE sy-ucomm.
DATA:
* Create reference to the custom container
custom_container TYPE REF TO cl_gui_custom_container,
* Create reference to the TextEdit control
editor TYPE REF TO cl_gui_textedit,
repid LIKE sy-repid.
**********************************************************************
* Utillity table to load texts
**********************************************************************
TYPES:
BEGIN OF t_texttable,
line(line_length) TYPE c,
END OF t_texttable.
DATA:
i_texttable TYPE TABLE OF t_texttable,
g_loaded(1) TYPE c.
**********************************************************************
* Impmenting events
**********************************************************************
DATA:
event_type(20) TYPE c,
* Internal table for events that should be registred
i_events TYPE cntl_simple_events,
* Structure for oneline of the table
wa_events TYPE cntl_simple_event.
*---------------------------------------------------------------------*
* CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
catch_dblclick FOR EVENT dblclick
OF cl_gui_textedit IMPORTING sender.
ENDCLASS.
CLASS lcl_event_handler IMPLEMENTATION.
METHOD catch_dblclick.
DATA:
from_line TYPE i,
from_pos TYPE i,
to_line TYPE i,
to_pos TYPE i,
wa_texttable TYPE t_texttable.
* Used for the sytem event
call method cl_gui_cfw=>set_new_ok_code
exporting new_code = 'SHOW'.
* Read the position of the double click
CALL METHOD sender->get_selection_pos
IMPORTING
from_line = from_line
from_pos = from_pos
to_line = to_line
to_pos = to_pos.
* Texts in the TextEdit control can have been changed, so
* first reload text from the control into the internal
* table that contains text
IF NOT g_loaded IS INITIAL.
CALL METHOD sender->get_text_as_r3table
IMPORTING table = i_texttable.
* Read the line of the internal table that was clicked
READ TABLE i_texttable INDEX from_line INTO wa_texttable.
IF sy-subrc <> 0.
EXIT.
ENDIF.
IF wa_texttable+0(1) CS '*'.
SHIFT wa_texttable.
ELSEIF wa_texttable+0(1) NS '*'.
SHIFT wa_texttable RIGHT.
wa_texttable+0(1) = '*'.
ENDIF.
modify i_texttable from wa_texttable index from_line.
* Reload texts from h einternal table
perform load_texts.
ENDIF.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
CLEAR wa_events.
REFRESH: i_events.
SET SCREEN '100'.
*---------------------------------------------------------------------*
* MODULE USER_COMMAND_0100 INPUT *
*---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'EXIT'.
LEAVE TO SCREEN 0.
WHEN 'SHOW'.
event_type = 'System dblclick'.
WHEN 'IMP'.
PERFORM Load_texts.
WHEN OTHERS.
* CALL METHOD cl_gui_cfw=>dispatch. "Not used for system events
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
* The TextEdit control shoul only be initialized the first time the
* PBO module executes
IF editor IS INITIAL.
repid = sy-repid.
* Create object for custom container
CREATE OBJECT custom_container
EXPORTING
container_name = 'MYCONTAINER1'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Create obejct for the TextEditor control
CREATE OBJECT editor
EXPORTING
wordwrap_mode =
cl_gui_textedit=>wordwrap_at_fixed_position
wordwrap_position = line_length
wordwrap_to_linebreak_mode = cl_gui_textedit=>true
parent = custom_container
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
gui_type_not_supported = 5
others = 6
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Link the event handler method to the event and the
* TextEdit control
SET HANDLER lcl_event_handler=>catch_dblclick FOR editor.
* Register the event in the internal table i_events
wa_events-eventid = cl_gui_textedit=>event_double_click.
* wa_events-appl_event = 'X'. "This is an application event
wa_events-appl_event = space. "This is a system event
APPEND wa_events TO i_events.
* Pass the table to the TextEdit control uding method
* set_registred_events
CALL METHOD editor->set_registered_events
EXPORTING events = i_events.
* Create internal table with texts taht can be uploaded to
* the TextEdit control
APPEND 'This a method that fills the TextEdit control' TO i_texttable.
APPEND 'with a text.' TO i_texttable.
DO 10 TIMES.
APPEND 'hallo world !' TO i_texttable.
ENDDO.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Form Load_texts
*&---------------------------------------------------------------------*
* This form loads the lines of the internal table i_texttable into
* the TextEdit control
*----------------------------------------------------------------------*
FORM Load_texts.
* Load TextEdit control with texts
CALL METHOD editor->set_text_as_r3table
EXPORTING table = i_texttable.
IF sy-subrc > 0.
* Display an error message
EXIT.
ENDIF.
* All methods that operates on controls are transferred to the frontend
* by a RFC calls. the method FLUSH is used to determine when this is
* done.
CALL METHOD cl_gui_cfw=>flush.
IF sy-subrc > 0.
* Display an error message
ENDIF.
g_loaded = 'X'.
ENDFORM. " create_texts
Example 6: Protect a line in the TextEdit control and the importance of FLUSH
All methods that operates on controls are transfered to the fronend by RFC calls. The FLUSH method is used to synchronize control execution and the frontend. This is very important when working e.g. with export parameters from a method, as the parmeters will not be correct before the FLUSH method has been called.
The example below portects selected lines in the TextEdit and uses FLUSH to ensure that the correct parameters are returned from method GET_SELECTION_POS.
Note: Instead of using method PROTECT_LINES, the method PROTECT_SELECTION could be used. This method does not need line numbers or a FLUSH statement
Steps
• Add a new pushbutton to the screen with the function code PROTECT.
Code
Add the following code to the example:
* Global variables
DATA:
from_idx TYPE i,
to_idx TYPE i,
index TYPE i.
MODULE user_command_0100 INPUT.
CASE ok_code.
code.......................
WHEN 'PROTECT'.
PERFORM protect.
. .......................
ENDCASE.
*&---------------------------------------------------------------------*
*& Form protect
*&---------------------------------------------------------------------*
* Protects marked lines in a TextEdit control
*----------------------------------------------------------------------*
FORM protect.
* Determine the area selected by the user
CALL METHOD editor->get_selection_pos
IMPORTING
from_line = from_idx
to_line = to_idx
EXCEPTIONS
error_cntl_call_method = 1.
* Synchronize execution in the control with the ABAP program.
* Without this synchronization the variables from_idx and
* to_idx will have obsolutete values (The initial value for
* both, are 0)
CALL METHOD cl_gui_cfw=>flush.
IF sy-subrc > 0.
* Errormessage: Error in flush
ENDIF.
* Protect the selected lines
IF to_idx > from_idx.
to_idx = to_idx - 1.
ENDIF.
CALL METHOD editor->protect_lines
EXPORTING
from_line = from_idx
to_line = to_idx.
* The PROTECT_SELECTION method could be used instead, eliminating the
* need of line numbers and the last FLUSH
* call method editor->protect_selection.
* Flush again to protect immidiately
CALL METHOD cl_gui_cfw=>flush.
IF sy-subrc > 0.
* Errormessage: Error in flush
ENDIF.
ENDFORM. " protect
Example 7: Using multiple controls
In this example a second TextEdit control will be added to the screen. The new TextEdit control will be designed to act as a clipboard for short texts.
Steps:
• Add a new container to the screen and name it MYCONTAINER2.
Code:
Insert global datadeclaration:
**********************************************************************
* Implementing a second Scratch TextEdit control
**********************************************************************
DATA:
scratch TYPE REF TO cl_gui_textedit,
custom_container2 TYPE REF TO cl_gui_custom_container.
Insert the following code in the PBO module:
*------------------------------------------------------
* The SCRATCH TextEdit control
*------------------------------------------------------
IF scratch IS INITIAL.
* Create obejct for custom container2
CREATE OBJECT custom_container2
EXPORTING
container_name = 'MYCONTAINER2'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Create obejct for the SCRATCH TextEditor control
CREATE OBJECT scratch
EXPORTING
parent = custom_container2
wordwrap_mode =
cl_gui_textedit=>wordwrap_at_windowborder
wordwrap_to_linebreak_mode = cl_gui_textedit=>true.
* Remove the staus bar
CALL METHOD scratch->set_statusbar_mode
EXPORTING statusbar_mode = cl_gui_textedit=>false.
ENDIF.
Result:
1 REPORT sapmz_hf_controls1 .
2
3 CONSTANTS:
4 line_length TYPE i VALUE 254.
5
6 DATA: ok_code LIKE sy-ucomm.
7
8 DATA:
9 * Create reference to the custom container
10 custom_container TYPE REF TO cl_gui_custom_container,
11 * Create reference to the TextEdit control
12 editor TYPE REF TO cl_gui_textedit,
13 repid LIKE sy-repid.
14
15 **********************************************************************
16 * Utillity table to load texts
17 **********************************************************************
18 TYPES:
19 BEGIN OF t_texttable,
20 line(line_length) TYPE c,
21 END OF t_texttable.
22
23 DATA:
24 i_texttable TYPE TABLE OF t_texttable,
25 wa_texttable TYPE t_texttable,
26 g_loaded(1) TYPE c.
27
28 **********************************************************************
29 * Data for the protection example
30 **********************************************************************
31 DATA:
32 from_idx TYPE i,
33 to_idx TYPE i,
34 index TYPE i.
35
36 **********************************************************************
37 * Implementing a second Scratch TextEdit control
38 **********************************************************************
39 DATA:
40 scratch TYPE REF TO cl_gui_textedit,
41 custom_container2 TYPE REF TO cl_gui_custom_container.
42
43
44 **********************************************************************
45 * Implementing events
46 **********************************************************************
47 DATA:
48 event_type(20) TYPE c,
49 * Internal table for events that should be registred
50 i_events TYPE cntl_simple_events,
51 * Structure for oneline of the table
52 wa_events TYPE cntl_simple_event.
53
54 *---------------------------------------------------------------------*
55 * CLASS lcl_event_handler DEFINITION
56 *---------------------------------------------------------------------*
57 * ........ *
58 *---------------------------------------------------------------------*
59 CLASS lcl_event_handler DEFINITION.
60 PUBLIC SECTION.
61 CLASS-METHODS:
62 catch_dblclick FOR EVENT dblclick
63 OF cl_gui_textedit IMPORTING sender.
64
65 ENDCLASS.
66
67 *---------------------------------------------------------------------*
68 * CLASS lcl_event_handler IMPLEMENTATION
69 *---------------------------------------------------------------------*
70 * ........ *
71 *---------------------------------------------------------------------*
72 CLASS lcl_event_handler IMPLEMENTATION.
73 METHOD catch_dblclick.
74 DATA:
75 from_line TYPE i,
76 from_pos TYPE i,
77 to_line TYPE i,
78 to_pos TYPE i.
79
80
81 * Used for the sytem event
82 CALL METHOD cl_gui_cfw=>set_new_ok_code
83 EXPORTING new_code = 'SHOW'.
84
85
86 * Read the position of the double click
87 CALL METHOD sender->get_selection_pos
88 IMPORTING
89 from_line = from_line
90 from_pos = from_pos
91 to_line = to_line
92 to_pos = to_pos.
93
94 * Texts in the TextEdit control can have been changed, so
95 * first reload text from the control into the internal
96 * table that contains text
97 IF NOT g_loaded IS INITIAL.
98 CALL METHOD sender->get_text_as_r3table
99 IMPORTING table = i_texttable.
100 * Read the line of the internal table that was clicked
101 READ TABLE i_texttable INDEX from_line INTO wa_texttable.
102 IF sy-subrc <> 0.
103 EXIT.
104 ENDIF.
105
106 IF wa_texttable+0(1) CS '*'.
107 SHIFT wa_texttable.
108 ELSEIF wa_texttable+0(1) NS '*'.
109 SHIFT wa_texttable RIGHT.
110 wa_texttable+0(1) = '*'.
111 ENDIF.
112 MODIFY i_texttable FROM wa_texttable INDEX from_line.
113 * Reload texts from h einternal table
114 PERFORM load_texts.
115
116
117 ENDIF.
118
119
120 ENDMETHOD.
121 ENDCLASS.
122
123
124
125 START-OF-SELECTION.
126 CLEAR wa_events.
127 REFRESH: i_events.
128
129 SET SCREEN '100'.
130
131
132
133 *---------------------------------------------------------------------*
134 * MODULE USER_COMMAND_0100 INPUT *
135 *---------------------------------------------------------------------*
136 MODULE user_command_0100 INPUT.
137
138 CASE ok_code.
139 WHEN 'EXIT'.
140 LEAVE TO SCREEN 0.
141 WHEN 'SHOW'.
142 event_type = 'System dblclick'.
143 WHEN 'IMP'.
144 PERFORM load_texts.
145 WHEN 'PROTECT'.
146 PERFORM protect.
147
148 WHEN OTHERS.
149 * CALL METHOD cl_gui_cfw=>dispatch. "Not used for system events
150 ENDCASE.
151
152
153 ENDMODULE. " USER_COMMAND_0100 INPUT
154 *&---------------------------------------------------------------------*
155 *& Module STATUS_0100 OUTPUT
156 *&---------------------------------------------------------------------*
157 MODULE status_0100 OUTPUT.
158 * The TextEdit control shoul only be initialized the first time the
159 * PBO module executes
160 IF editor IS INITIAL.
161 repid = sy-repid.
162 * Create obejct for custom container
163 CREATE OBJECT custom_container
164 EXPORTING
165 container_name = 'MYCONTAINER1'
166 EXCEPTIONS
167 cntl_error = 1
168 cntl_system_error = 2
169 create_error = 3
170 lifetime_error = 4
171 lifetime_dynpro_dynpro_link = 5
172 others = 6
173 .
174 IF sy-subrc <> 0.
175 MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
176 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
177 ENDIF.
178
179 * Create obejct for the TextEditor control
180 CREATE OBJECT editor
181 EXPORTING
182
183 wordwrap_mode =
184 cl_gui_textedit=>wordwrap_at_fixed_position
185 wordwrap_position = line_length
186 wordwrap_to_linebreak_mode = cl_gui_textedit=>true
187 parent = custom_container
188 EXCEPTIONS
189 error_cntl_create = 1
190 error_cntl_init = 2
191 error_cntl_link = 3
192 error_dp_create = 4
193 gui_type_not_supported = 5
194 others = 6
195 .
196 IF sy-subrc <> 0.
197 MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
198 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
199 ENDIF.
200
201 * Link the event handler method to the event and the
202 * TextEdit control
203 SET HANDLER lcl_event_handler=>catch_dblclick FOR editor.
204
205 * Register the event in the internal table i_events
206 wa_events-eventid = cl_gui_textedit=>event_double_click.
207
208 * wa_events-appl_event = 'X'. "This is an application event
209 wa_events-appl_event = space. "This is a system event
210
211
212 APPEND wa_events TO i_events.
213 * Pass the table to the TextEdit control uding method
214 * set_registred_events
215 CALL METHOD editor->set_registered_events
216 EXPORTING events = i_events.
217
218 * Create internal table with texts taht can be uploaded to
219 * the TextEdit control
220 APPEND 'This a method that fills the TextEdit control' TO i_texttable.
221 APPEND 'with a text.' TO i_texttable.
222 DO 10 TIMES.
223 APPEND 'hallo world !' TO i_texttable.
224 ENDDO.
225 ENDIF.
226
227 *------------------------------------------------------
228 * The SCRATCH TextEdit control
229 *------------------------------------------------------
230 IF scratch IS INITIAL.
231 * Create obejct for custom container2
232 CREATE OBJECT custom_container2
233 EXPORTING
234 container_name = 'MYCONTAINER2'
235 EXCEPTIONS
236 cntl_error = 1
237 cntl_system_error = 2
238 create_error = 3
239 lifetime_error = 4
240 lifetime_dynpro_dynpro_link = 5
241 others = 6
242 .
243 IF sy-subrc <> 0.
244 MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
245 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
246 ENDIF.
247
248 * Create obejct for the SCRATCH TextEditor control
249 CREATE OBJECT scratch
250 EXPORTING
251 parent = custom_container2
252 wordwrap_mode =
253 cl_gui_textedit=>wordwrap_at_windowborder
254 wordwrap_to_linebreak_mode = cl_gui_textedit=>true.
255
256 * Remove the staus bar
257 CALL METHOD scratch->set_statusbar_mode
258 EXPORTING statusbar_mode = cl_gui_textedit=>false.
259
260 ENDIF.
261
262
263 ENDMODULE. " STATUS_0100 OUTPUT
264
265 *&---------------------------------------------------------------------*
266 *& Form Load_texts
267 *&---------------------------------------------------------------------*
268 * This form loads the lines of the internal table i_texttable into
269 * the TextEdit control
270 *----------------------------------------------------------------------*
271 FORM load_texts.
272
273 * Load TextEdit control with texts
274 CALL METHOD editor->set_text_as_r3table
275 EXPORTING table = i_texttable.
276 IF sy-subrc > 0.
277 * Display an error message
278 EXIT.
279 ENDIF.
280
281 * All methods that operates on controls are transferred to the frontend
282 * by a RFC calls. the method FLUSH is used to determine when this is
283 * done.
284 CALL METHOD cl_gui_cfw=>flush.
285 IF sy-subrc > 0.
286 * Display an error message
287 ENDIF.
288 g_loaded = 'X'.
289 ENDFORM. " create_texts
290 *&---------------------------------------------------------------------*
291 *& Form protect
292 *&---------------------------------------------------------------------*
293 * Protects marked lines in a TextEdit control
294 *----------------------------------------------------------------------*
295 FORM protect.
296 * Determine the area selected by the user
297 CALL METHOD editor->get_selection_pos
298 IMPORTING
299 from_line = from_idx
300 to_line = to_idx
301 EXCEPTIONS
302 error_cntl_call_method = 1.
303
304 * Synchronize execution in the control with the ABAP program.
305 * Without this synchronization the variables from_idx and
306 * to_idx will have obsolutete values (The initial value for
307 * both, are 0)
308 CALL METHOD cl_gui_cfw=>flush.
309 IF sy-subrc > 0.
310 * Errormessage: Error in flush
311 ENDIF.
312
313 * Protect the lines selected
314 IF to_idx > from_idx.
315 to_idx = to_idx - 1.
316 ENDIF.
317 CALL METHOD editor->protect_lines
318 EXPORTING
319 from_line = from_idx
320 to_line = to_idx.
321
322
323 * The PROTECT_SELECTION method could be used instead, eliminating the
324 * need of line numbers and the last FLUSH
325
326 * call method editor->protect_selection.
327
328
329 * Flush again to protect immidately
330 CALL METHOD cl_gui_cfw=>flush.
331 IF sy-subrc > 0.
332 * Errormessage: Error in flush
333 ENDIF.
334
335
336
337 ENDFORM. " protect