SAP---ABAP

Sunday, July 8, 2007

Important ABAP FAQ's

1)What are dml statements in sap?

Ans: Insert, Update, Delete.

2)What is the difference between open sql & native sql?

Ans: Open SQL allows you to access all database tables known to the SAP system, regardless of the database manufacturer. Sometimes, however, we may want to use database-specific SQL statements called Native SQL in your ABAP/4 program.
To avoid incompatibilities between different database tables and also to make ABAP/4 programs independent of the database system in use, SAP has created a set of separate SQL statements called Open SQL. Open SQL contains a subset of standard SQL statements as well as some enhancements which are specific to SAP.
A database interface translates SAP's Open SQL statements into SQL commands specific to the database in use. Native SQL statements access the database directly

3)What is Primary key, foreign key ? what is primary index? secondary index?

Ans: Primary index: the primary index contains key fiels of a table and a pointer to non-key fields of the table. The primary index is created automatically when a table is created in database and moreover you can further define reference to the primary index which are known as Secondary index.

4)How many indexes can be created for a table?

Ans: 9.

5)What is data class?

Ans: The data class specifies in which table space the table is created in database.

6)Give few names of cluster tables in sap?

Ans:

7)Give few names of pooled tables in sap?

Ans: A pool table has many to one relation with the table in the database. For one table in the database there are many tables in the dictionary. Tha table in the database has a diff name than in the table in the data dict, it has diff no of fields and field names are different. A pooled table is stored in the pool at the database level. A table pool is a databse table with a special struct that enables the data of many R3 tables to be stored in it. It can hold only pooled tables.
Sorry I dont know table names.

8)Give few names of transparent tables?

Ans: A transparent table has a one to one relataionship in the database. The table in the dictionary has the same name, same no of fields, and the fields have the same name as in the R3 table defn. A transparent tabel has application data (Master and Transaction). sorry i dont know table names.

9)What is a buffer and how many types?

Ans: Buffer is othing but which stores data temporarily. there are two types of buffers.

They are Roll and Page areas.
Pages : it stores the application data.
Roll area: it stores the data of previous pages.Data areas of used programs are created in roll areas for each internal session.

10)What is table maintenance generator and how to create that? What is the transaction code?

Ans: Table maintanence generator is nothing but making a table available for adding records and deleting records.
The transaction code used is SM30.

11)How to add new fields to a standard sap table?

Ans: 1. Appended structures 2. Customizing tables

12)What are lock objects?

Ans: Lock objects are nothing but which holds a data for particular field value until you remove a lock..

13)Diff betwn inner & outer join?

Ans:

14)What is the use of start-of-selection event?

Ans: Start-of-selection is called implicity even it is not used in the program. start-of-selection is triggered after the standard selection screen has been displayed.

15)What is the difference between end-of-page and end-of-selection?

Ans: End-of-page : is footer of the page. End-of-selection: is triggered At the end of the processing block.

16)If you write a write statement after end-of-selection, will that be triggered?

Ans: Yes

17)How to create a button in selection screen?

Ans: Using parametres

18)How to add a gui status in a selection screen?

Ans:

19)How to create a check box/option button in a list?

Ans: Regarding Runtime creation of Check Boxes

20)Can you call a bdc program from a report? how?

Ans: Yes through Submit and return

21)Can you call a transaction from a report? how?

Ans: Yes Using Call transaction and leave to.

22)What are ALV reports? how they are different from normal reports?
Ans: these reports are used to find subtotals and totals in a report. If you want i'll give you an example program.

23)What are the main events that are used in an ALV report?
Ans:

24)What is the use of SLIS type pool in alv reports?

Ans: Slis type pool is a global defination of pooltypes of catalog structure, table and layout which we use in ALV reports.

25)Difference between top-of-page and top-of-page during at-line- selection?

Ans: Top-of-page is a header on primary list. Top-of-page during line-selection is a header on secondary lists.

26)In an interactive report, after going to 5th list, can you come back to 2nd list? how?

How many type of internal tables are there?

Ans: Standard, Hashed, Sorted tables

27)What is the difference between hashed & sorted internal tables?

Ans: Sorted internal table works on Binary Search and Hashed internal tables works on hashed alogorthim through indexes.

28)What is the difference between standard and sorted internal tables? (in performance wise)

Ans: Sorted table improve the performance in case of a huge table which has no: of records

29)What is the use of at new statement?

Ans:

30)When do you need to create an internal table with header line? and with out a header line? line?

Ans: If we don't want to use any explicit work area then its better to go for an internal table with header line.

31)What does it mean occurs 0 while creating an internal table?

Ans:

32)Which of these methods can be best used in background process?

Ans : Batch Input method.

33)What is direct input method?

What does an EXEC SQL stmt do in ABAP? What is the disadvantage of using it?

Ans: Exec Sql[Performing [Native sql statements]
endexec.
The above is the syntax for the native sql statements.

Disadvantages:

. Syntax check is not done to statements written inside the EXEC SQL statements.

34)What is the meaning of ABAP/4 editor integrated with ABAP/4 data dictionary?

What transactions do you use for data analysis?

ANs: Sorry i dont know but for runtime analysis we use transaction code : se30.

35)What are selection texts?

Ans: in the selection screen you can change the name of the field,title etc using selection texts. go to text--> text elemets---> selection texts in the menu bar to set selection texts.

36)What is the client concept in SAP? What is the meaning of client independent?

How to find the return code of a statement in ABAP programs?

Ans: Through functions.

37)What is performance tuning?

Ans: Performance tuning for Data Selection Statement

38)What are steps you follow to improve the performance of a report?

Ans: 1) USe select fields statements (not select *)
2) Use views rather than tables
3) Don't use nested Select.

39)What is the role of secondary index in performance?

Ans:

40)What is the role of ST05 in performance tuning?

Ans: SQL trace

41)What is the role of extended syntax check in performance tuning?

Ans:

42)Will join conditions in sql queries affect perfomance? how?

Ans : Yes

43)Will sorted internal tables help in performance?

Ans: Yes

44)Will where conditions in a sql query help improve performance?

Ans: No Not at all

45)Does select single *.. / select * .. affect performance? how?

Ans: Select single we use for first hit of the record. so obviously Select single will improve the performance.



ABAP Questions Commonly Asked 1


1) What is the difference betwen abap and sap memories?

Data sending between internal sessions is called abap memory using import and export parameters.
Data sending between main sessions using spa/gpa ie (set /get) parameters called sap memory.


2) What is nast?
nast is a message status database table.


3) How to upload logo in sapscripts?
1... create a logo using paint shop and save it as tifffile then using RSTXLDMC (is a program name) used to upload logo
2.....create a logo using paint shop and save it as bmpfile then using SE78 you can do this.


4) What are symbols explain?

Symbols are constants used to save un nessessary work used in documentation
1. system symbols : example: &date& &time& etc
2. text symbols: they are defined using control statements
protect...endprotect, if endif, etc
3. standard symbols : all the messages are stored in TTDTG table
4. program symbols : used in abap program example: &i_mara-matnr& &i_mara-ernam&


5) Difference b/w call transaction and session.

Call transaction

Session

1. synchronous updation optional

1.Only synchronous updation

2. errors can handle explicitely

2.Error log is created

3. faster

3.slower

4. less amount of data

4.more can transfer

5. updation takes place during program execution

5.updation takes place once the session being created


6. Difference b/w smartforms and scripts.


Script

Smartforms

Client dependant

Independant

Not possible

Multiple page formats are possible

compulsory

Without main window it can

Labels are used

Labels cannot

Not generated

Once session created function module


7. Errors hanling in call transaction

Two ways


1)... int table decalred having structure BDCMSGCOLL it is having certain variables not texts. ie msgtyp,megid, msgnr,
msgvar1, msgvar2, msgvar3, msgvar4 etc all the text messages are stored using T100 database table.


2)....int table decalred having structure BDCMSGCOLL it is having certain variables . ie msgtyp,megid, msgnr, msgvar1, msgvar2, msgvar3, msgvar4 etc by declaring function modules format_message or write_message you can handle.


8. Errors handling in session
In SM35 error log is created, there you can handle.


9. Difference b/w select-options, valueranges, parameters.
par----- singlevalue
select-options----range and itself implicitly creates internal table
value-ranges---- just for ranges


10. How to remove duplicate entries?

using COLLECT
or
DELECT DUPLICATE ENTRIES FROM TABLENAME>


11. What are standard texts?

These are predefined texts used for create change and display tcode SO10
Starting with INCLUDE
These are for TERMS AND CONDITIONS .


12. What is the use of select....for all entries?

Avoid nested select or inner joins
uses
fast processing
sorting
delete duplicate entries

13. What is the difference b/w exit and continue?

exit----if it is in the loop comes out of the loop.
----if it is in the subroutine comes out of the routine.
----if it is in the program comes out of the preogram.
continue-----unconditional jumping out of the loop.


14. What is the diffenrence b/w collect and append.

collect----- checks whether it is there or not. if there adds integer, packed, float otherwise remove
append-----just adding


15) What are barcodes?

For security purpose


16 )What is meant by "Matchcode"?

Matchcodes are defined in two stages in Abap/4 Dictionary:

1) The revelant table and fields are stipulated in matchcode object. A matchcode object describes the set of all possible search paths for a search item.

2) One or more matchcode ID can be defined for a matchcode object. A matchcode ID describes a special search path for a search term.The fields or combination of fields via which the search is to take place is defined in the matchcode ID.






ABAP Interview Questions

1. How data is stored in cluster table?
Each field of cluster table behaves as tables which contains the no. of entries.

2. What are client dependant objects in abap/sap?
SAP Script layout, text element, and some DDIC objects.

3. On which even we can validate the input fields in module progams?
In PAI (Write field statement on field you want to validate, if you want to validate group of fields put in chain and End chain statement.)

4. In selection screen I have three fields, plant mat no and material group. If I input plant how do I get the mat no and material group based on plant dynamically?
AT SELECTION-SCREEN ON VALUE-REQUEST FOR MATERIAL.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST' to get material and material group for the plant.

5. How do you get output from IDOC?
Data in IDOc is stored in segments, the output from Idoc is obtained by reading the data stored in its respective segments.

6. When top of the page event is triggered?
After excuteing first write statement in start-of-selection event.

7. Can we create field without data element and how?
In SE11 one option is available above the fields strip. Data element/ direct type.

8. How do we debug sapscript?
Go to SE71 give lay set name , go to utilities select debugger mode on.

9. Which transaction code can I used to analyze the performance of ABAP program.
TCode AL21.

10. How can I copy a standard table to make my own z_table.
Go to transaction SE11. Then there is one option to copy table. Press that button. Enter the name of the standard table and in the Target table enter Z table name and press enter.


11. What is the use of 'outerjoin'
Ans. With the use of outer join you can join the tables even there is no entry in all the tables used in the view.
In case of inner join there should be an entry in al the tables use in the view.

12. When to use logical database?
Ans. Advantage of Logical databases:
less coding s required to retrieve data compared to normal internel tables.
Tables used LDB are in hierarchial structure.

13. What is the use of 'table index'?
Ans .Index is used for faster access of data base tables.

14. What is the use of 'FOR ALL ENTRIES'?
Ans. To avoid nested select statements we use SELECT FOR ALL ENTRIES statement.
If there r more than 10000 records SELECT FOR ALL ENTRIES is used.
Performance wise SELECT FOR ALL ENTRIES is better to use.

15. Can you set up background processing using CALL TRANSACTION?
Yes,Using No Screen Mode.

16. What are table buffers?
Table buffers reside locally on each application server in the system. The data of buffered tables can thus be accessed
directly from the buffer of the application server. This avoids the time-consuming process of accessing the database.

Buffering is useful if table needs to be accessed more no. of times in a program.


17. How do I set a flag for a field in any table?
Create a char field of length 1. for example field STAS-LKENZ is Deletion Indicator. It means that if the value in the field is 'X' then that record has been deleted.

18. Can I execute user exits? If yes, how?
Yes you can. after finding the user exit, you need to use, goto CMOD add ur user-exit to your project. Then activate the FM which you require. Now go into that function module there will be a Include program wit name ZX* . Double click on it, it will ask to create an object, answer it Yes and then write your code in it.

19. How do I find the output type of a table or a program?
Table TNAPR / NAST




More than 100 ABAP questions



1. What is the typical structure of an ABAP/4 program?

ANS:- HEADER ,BODY,FOOTER.

2. What are field symbols and field groups.? Have you used "component idx of structure" clause with field groups?
ANS:-
Field symbols:-

Field groups :-

3. What should be the approach for writing a BDC program?
ANS:-
STEP 1: CONVERTING THE LEGACY SYSTEM DATA TO A FLAT FILE to internal table CALLED "CONVERSION".
STEP 2: TRANSFERING THE FLAT FILE INTO SAP SYSTEM CALLED "SAP DATA TRANSFER".
STEP 3: DEPENDING UPON THE BDC TYPE i)call transaction(Write the program explicity)
ii) create sessions (sessions are created and processed.if success data will transfer).

4. What is a batch input session?
ANS:-
BATCH INPUT SESSION is an intermediate step between internal table and database table.
Data along with the action is stored in session ie data for screen fields, to which screen it is passed,program name behind it, and how next screen is processed.

5. What is the alternative to batch input session?
ANS:- Call transaction.

6. A situation: An ABAP program creates a batch input session.
We need to submit the program and the batch session in back ground. How to do it?
ANS:-
go to SM36 and create background job by giving
job name,job class and job steps (JOB SCHEDULING)

8. What are the problems in processing batch input sessions?
How is batch input process different from processing online?
ANS:-
PROBLEMS:-
i) If the user forgets to opt for keep session then the session will be automatically removed from the session queue(log remains). However if session is processed we may delete it manually.
ii)if session processing fails data will not be transferred to SAP database table.

10. What are the different types of data dictionary objects?
ans:-
tables, structures, views, domains, data elements, lock objects, Matchcode objects.

11. How many types of tables exists and what are they in data dictionary?
ans :-
4 types of tables
i)Transparent tables - Exists with the same structure both in dictionary as well as in database exactly with the same data and fields. Both Opensql and Nativesql can be used.

ii)Pool tables & iii)Cluster tables -
These are logical tables that are arranged as records of transparent tables.one cannot use native sql on these tables
(only opensql).They are not managable directly using database system tools.

iv)Internal tables - .

12. What is the step by step process to create a table in data dictionary?
ans:-
step 1: creating domains(data type,field length,range).
step 2: creating data elements(properties and type for a table
field).
step 3: creating tables(SE11).

13. Can a transparent table exist in data dictionary but not in the data base physically?
ANS:- NO.
TRANSPARENT TABLE DO EXIST WITH THE SAME STRUCTURE BOTH IN THE DICTIONARY AS WELL AS IN THE DATABASE,EXACTLY WITH THE SAME DATA AND FIELDS.

14. What are the domains and data elements?
ANS:-
DOMAINS : FORMAL DEFINITION OF THE DATA TYPES.THEY SET ATTRIBUTES SUCH AS DATA TYPE,LENGTH,RANGE.
DATA ELEMENT : A FIELD IN R/3 SYSTEM IS A DATA ELEMENT.

15. Can you create a table with fields not referring to data elements?
ANS:-
YES. eg:- ITAB LIKE SPFLI.here we are referening to a data object(SPFLI) not data element.

16. What is the advantage of structures? How do you use them in the ABAP programs?
ANS:-
Adv:- GLOBAL EXISTANCE(these could be used by any other program without creating it again).

17. What does an extract statement do in the ABAP program?
ANS:-
Once you have declared the possible record types as field groups and defined their structure, you can fill the extract dataset using the following statements:
EXTRACT .

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

EXTRACT HEADER.

When you extract the data, the record is filled with the current values of the corresponding fields.

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

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

18. What is a collect statement? How is it different from append?
ANS:-
If an entry with the same key already exists, the COLLECT statement does not append a new line, but adds the contents of the numeric fields in the work area to the contents of the numeric fields in the existing entry.

19. What is open sql vs native sql?
Ans:
Open SQL , native SQL are the interfaces to create the database applicatons.
Open SQL is consistant across different types of existing Databases.
Native SQL is the database language specific to database.Its API is specific to the databse.
Open SQL API is consistent across all vendors

20. What does an EXEC SQL stmt do in ABAP? What is the disadvantage of using it?
ANS:-

Display Active Exits in a ABAP System

ZMS_ACTIVE_EXITS - This report shows displays the active exits in a ABAP system along with the corresponding SAP Enhancement (SMOD) and Customer Project (CMOD)

*&---------------------------------------------------------------------*
*& Report ZMS_ACTIVE_EXITS
*&---------------------------------------------------------------------*
*& This report displays all the active customer enhancements in the
*& system and also displays whether they are active or implemented
*&---------------------------------------------------------------------*
REPORT ZMS_ACTIVE_EXITS.
* Data decleration
types: begin of s_function,
fname like MOD0-FUNCNAME,
ftext like tftit-stext,
impl,
active,
example,
end of s_function.
TYPEs : BEGIN OF display_str,
project type modact-name,
enhancement type modact-member,
fm type modsap-member,
status type char20,
END OF display_str.
data : lt_member type table of modact-member,
ls_member like LINE OF lt_member,
lt_fm type table of modsap-member,
ls_fm like LINE OF lt_fm,
lt_modname type table of modact-name,
ls_modname like line of lt_modname,
lt_display type TABLE OF display_str,
ls_display like LINE OF lt_display,
ls_function type s_function,
field1(30).
START-OF-SELECTION.
* Select active customer enhancement.
select name from modattr into ls_modname
where status = 'A'.
append ls_modname to lt_modname.
CLEAR ls_modname.
ENDSELECT.
if lt_modname is INITIAL.
WRITE / 'no active enhancements'.
endif.
* Determine the details about the customer enhancement.
LOOP AT lt_modname INTO ls_modname.
CLEAR : ls_display.
SELECT member from modact into ls_member where name = ls_modname.
select member from modsap into ls_fm where name = ls_member and typ =
'E'.
ls_display-project = ls_modname.
ls_display-enhancement = ls_member.
ls_display-fm = ls_fm.
clear : ls_function.
ls_function-fname = ls_fm.
perform get_impl_status USING ls_function.
if ls_function-impl = 'X'.
ls_display-status = 'Implemented'.
ELSE.
ls_display-status = 'Active'.
endif.
APPEND ls_display to lt_display.
endselect.
ENDSELECT.
ENDLOOP.
* Displaying results
format color = 1.
write : 'Please double-click on the object for follow-on action'.
new-LINE. uline.
write : 'Customer Project', at 30 'SAP Enhancement', at 60 'Exit
Function Modul
e', at 100 'Active/Implemented'.
ULINE.
format color = 0.
loop at lt_display into ls_display.
new-LINE.
write : ls_display-project, at 30 ls_display-enhancement, at 60
ls_displayfm,
at 100 ls_display-status.
ENDLOOP.
* For calling transaction CMOD / SMOD / SE37.
at line-selection.
get cursor field field1.
CASE field1.
WHEN 'LS_DISPLAY-PROJECT'.
set parameter id 'MON_KUN' field sy-lisel(10).
call transaction 'CMOD' and skip first screen.
WHEN 'LS_DISPLAY-ENHANCEMENT'.
set parameter id 'MON' field sy-lisel+29(10).
call transaction 'SMOD' and skip first screen.
WHEN 'LS_DISPLAY-FM'.
set parameter id 'LIB' field sy-lisel+59(30).
call transaction 'SE37' and skip first screen.
WHEN OTHERS.
message 'Click on the right place.' TYPE 'I'.
ENDCASE.
*&---------------------------------------------------------------------*
*& Form get_impl_status
*&---------------------------------------------------------------------*
* This FORM checks whether an EXIT FM is implemented or not
*----------------------------------------------------------------------*
form get_impl_status using p_function type s_function.
data : l_mand LIKE tfdir-mand,
l_incl_names TYPE smod_names OCCURS 1 WITH HEADER LINE.
l_incl_names-itype = 'C'.
APPEND l_incl_names.
CLEAR l_mand.
SELECT SINGLE mand FROM tfdir INTO l_mand WHERE funcname =
p_function-fname.
IF sy-subrc = 0 AND l_mand(1) = 'C'.
p_function-active = 'X'.
* l_status-active = c_true.
ELSE.
p_function-active = ' '.
* l_status-inactive = c_true.
ENDIF.
CALL FUNCTION 'MOD_FUNCTION_INCLUDE'
EXPORTING
funcname = p_function-fname
TABLES
incl_names = l_incl_names
EXCEPTIONS
OTHERS = 4.
IF sy-subrc = 0.
LOOP AT l_incl_names.
SELECT SINGLE name FROM trdir INTO l_incl_names-iname
WHERE name = l_incl_names-iname.
IF sy-subrc = 0.
p_function-impl = 'X'.
ELSE.
p_function-impl = ' '.
ENDIF.
ENDLOOP.
ENDIF.
endform. "get_impl_status
List Of User Exit Related to VL01N

I need to some restriction in fields ( Actual GI Date, T-Code:Vl01n ).
How do you find out whcih user exits belongs to VL01n ?

Here is the list of user exit related to VL01N :

V02V0001 - Sales area determination for stock transport order
V02V0002 - User exit for storage location determination
V02V0003 - User exit for gate + matl staging area determination
V02V0004 - User Exit for Staging Area Determination (Item)
V50PSTAT - Delivery: Item Status Calculation
V50Q0001 - Delivery Monitor: User Exits for Filling Display Fields
V50R0001 - Collective processing for delivery creation
V50R0002 - Collective processing for delivery creation
V50R0004 - Calculation of Stock for POs for Shipping Due Date List
V50S0001 - User Exits for Delivery Processing
V53C0001 - Rough workload calculation in time per item
V53C0002 - W&S: RWE enhancement - shipping material type/time slot
V53W0001 - User exits for creating picking waves
VMDE0001 - Shipping Interface: Error Handling - Inbound IDoc
VMDE0002 - Shipping Interface: Message PICKSD (Picking, Outbound)
VMDE0003 - Shipping Interface: Message SDPICK (Picking, Inbound)
VMDE0004 - Shipping Interface: Message SDPACK (Packing, Inbound)

Difference Between BADI and User Exits

Business Add-Ins are a new SAP enhancement technique based on ABAP Objects. They can be inserted into the SAP System to accommodate user requirements too specific to be included in the standard delivery. Since specific industries often require special functions, SAP allows you to predefine these points in your software.

As with customer exits two different views are available:

In the definition view, an application programmer predefines exit points in a source that allow specific industry sectors, partners, and customers to attach additional software to standard SAP source code without having to modify the original object.

In the implementation view, the users of Business Add-Ins can customize the logic they need or use a standard logic if one is available.

In contrast to customer exits, Business Add-Ins no longer assume a two-level infrastructure (SAP and customer solutions), but instead allow for a multi-level system landscape (SAP, partner, and customer solutions, as well as country versions, industry solutions, and the like). Definitions and implementations of Business Add-Ins can be created at each level within such a system infrastructure.

SAP guarantees the upward compatibility of all Business Add-In interfaces. Release upgrades do not affect enhancement calls from within the standard software nor do they affect the validity of call interfaces. You do not have to register Business Add-Ins in SSCR.

The Business Add-In enhancement technique differentiates between enhancements that can only be implemented once and enhancements that can be used actively by any number of customers at the same time. In addition, Business Add-Ins can be defined according to filter values. This allows you to control add-in implementation and make it dependent on specific criteria (on a specific Country value, for example).

All ABAP sources, screens, GUIs, and table interfaces created using this enhancement technique are defined in a manner that allows customers to include their own enhancements in the standard. A single Business Add-In contains all of the interfaces necessary to implement a specific task.

The actual program code is enhanced using ABAP Objects. In order to better understand the programming techniques behind the Business Add-In enhancement concept, SAP recommends reading the section on ABAP Objects.

What is difference between badi and user-exists?
What is difference between enhancements and user-exists? and what is the full form of BADI?

I have another doubt in BDC IN BDC WE HAVE MSEGCALL (i did not remember the > correct name) where the error logs are stored, MSEGCALL is a table or structure.

What is the system landscape?

1) Difference between BADI and USER-EXIT.
i) BADI's can be used any number of times, where as USER-EXITS can be used only one time.
Ex:- if your assigning a USER-EXIT to a project in (CMOD), then you can not assign the same to other project.
ii) BADI's are oops based.

2) About 'BDCMSGCOLL' it is a structure. Used for finding error records.
3) Full form of BADI 'Business addins'.
3) System land scape will be depends on your project
Ex:- 'Development server'-->'Quality server'---> 'Production server'......

Finding the user-exits of a SAP transaction code
*
* Finding the user-exits of a SAP transaction code
*
* Enter the transaction code in which you are looking for the user-exit
* and it will list you the list of user-exits in the transaction code.
* Also a drill down is possible which will help you to branch to SMOD.
*
* Written by : SAP Basis, ABAP Programming and Other IMG Stuff
* http://www.sap-img.com
*

report zuserexit no standard page heading.
tables : tstc, tadir, modsapt, modact, trdir, tfdir, enlfdir.
tables : tstct.
data : jtab like tadir occurs 0 with header line.
data : field1(30).
data : v_devclass like tadir-devclass.
parameters : p_tcode like tstc-tcode obligatory.

select single * from tstc where tcode eq p_tcode.
if sy-subrc eq 0.
select single * from tadir where pgmid = 'R3TR'
and object = 'PROG'
and obj_name = tstc-pgmna.
move : tadir-devclass to v_devclass.
if sy-subrc ne 0.
select single * from trdir where name = tstc-pgmna.
if trdir-subc eq 'F'.
select single * from tfdir where pname = tstc-pgmna.
select single * from enlfdir where funcname =
tfdir-funcname.
select single * from tadir where pgmid = 'R3TR'
and object = 'FUGR'
and obj_name eq enlfdir-area.

move : tadir-devclass to v_devclass.
endif.
endif.
select * from tadir into table jtab
where pgmid = 'R3TR'
and object = 'SMOD'
and devclass = v_devclass.
select single * from tstct where sprsl eq sy-langu and
tcode eq p_tcode.
format color col_positive intensified off.
write:/(19) 'Transaction Code - ',
20(20) p_tcode,
45(50) tstct-ttext.
skip.
if not jtab[] is initial.
write:/(95) sy-uline.
format color col_heading intensified on.
write:/1 sy-vline,
2 'Exit Name',
21 sy-vline ,
22 'Description',
95 sy-vline.
write:/(95) sy-uline.
loop at jtab.
select single * from modsapt
where sprsl = sy-langu and
name = jtab-obj_name.
format color col_normal intensified off.
write:/1 sy-vline,
2 jtab-obj_name hotspot on,
21 sy-vline ,
22 modsapt-modtext,
95 sy-vline.
endloop.
write:/(95) sy-uline.
describe table jtab.
skip.
format color col_total intensified on.
write:/ 'No of Exits:' , sy-tfill.
else.
format color col_negative intensified on.
write:/(95) 'No User Exit exists'.
endif.
else.
format color col_negative intensified on.
write:/(95) 'Transaction Code Does Not Exist'.
endif.

at line-selection.
get cursor field field1.
check field1(4) eq 'JTAB'.
set parameter id 'MON' field sy-lisel+1(10).
call transaction 'SMOD' and skip first screen.

*---End of Program


Field exits (SMOD/CMOD) Questions and Answers

1. Field exit was created with CMOD, but is not processed when calling the screen.

- Since the field exit is not processed until PAI, an action must be triggered on the screen (Return, Save, ...).

- Set profile parameter abap/fieldexit to YES and restart the system.

- After activating the function module FIELD_EXIT... and the field exit, leave the transaction on whose screen the field exit is to be executed. The screen is not generated until the transaction is started.

- Do not work on different application servers since there may be some delay before the field exit is activated.

- The profile parameter must be set on all or none of the application servers.

- If the field exit is to only be active on specific screens, check whether you chose the correct program and the correct screen
number (take care with subscreens).

- Using SE51 -> Field list, check that the screen field does have a reference to a data element. In the name of the field exit use the name of the data element and not the field name.

- After transport, field exits are marked as active but will not be processed.
Tip: First try deactivating the field exit once more and then afterwards, activate it again.

2. How is performance affected by setting abap/fieldexit?

- If a screen is generated and the profile parameter is set, a check is run on 2 tables (TDDIR, TDDIRS) to see whether a field exit must be generated for the respective field. In practice, the screen load is not generated until the screen is selected after an
update. The user should not notice any difference because screen generation is very fast.

3. Can you read the contents of other screen fields in the field exit?

- In principle, every field exit can store its value in the global variables of the function group (TOP) and hence make them
available to other field exits. Note here that field exits are always called and not only if an entry is made in the field or if the field is empty. In addition, it is not possible to make any assumptions about the order in which the field exits will be called in the future.

4. How does the field exit behave on step loop fields ?

- After the user has entered data, the field exit is called in PAI as often as there are visible fields in the step loop. The system
variable SY-STEPL is incremented each time. If a new value is assigned to the field, it is displayed in the module between LOOP and ENDLOOP. This module is also called once for each visible step loop line.

5. Can field exits be debugged ?

- No. Field exits must be tested separately in the ABAP/4 Development Workbench. For errors which only occur in the screen environment, it is helpful to write interesting variable to the file system using TRANSFER... . These can then be analysed there.

6. What can you do if the field contents are no longer transported to to ABAP/4.

- Check whether a value is assigned to the field OUTPUT.

7. When is the field exit called if a conversion exit is attached to the
data element ?

- The field exit is called after the conversion exit. This means that the INPUT field receives the data in the same format as the
ABAP/4 program also receives it.

8. Although a global field exit is inactive, a function module is called which does not exist (for example FIELD_EXIT_PROGRAMM_@)

- This is an error in the kernel which no longer occurs as of 3.0C. As a temporary measure, it is useful to assign a program and a screen which do not exist to the field exit and then activate the field exit.

9. Field exit is not visible in CMOD, although created.

- If you want to create a field exit for a data element, a function module is proposed with the name FIELD_EXIT_. This
function module must exist for the field exit to work. If you do not create this function module, but do create one with a suffix,
the data element is not displayed in CMOD.

10. Field exit is not executed although it is active.

- Fields which do not have the 'Input field' attribute usually do not trigger a field exit. The field exit is designed to allow an
extended input check. It is therefore only called for input fields - even if they are not ready for input at runtime of the application by LOOP AT SCREEN.
This rule does not apply, however, if the field is located within a steploop. Here the field will be always activated, even if it is
invisible.

- Field exits can only be executed for fields that are directly related tothe dictionary. If the relation is indirect, i.e. via an ABAP declaration ( LIKE ), no field exit can be executed.

11. Field exits on check buttons do not work

- Field exits are only intended for input fields. As check buttons count as graphical elements, you cannot install field exits on
them.

12. Field exits do not work on selection screens

What is the difference between SMOD and CMOD?

CMOD is the Project Management of SAP Enhancements (i.e., SMOD Enhancements). SMOD contains the actual enhancements and CMOD is the grouping of those SMOD enhancements.

User exits (Function module exits) are exits developed by SAP. The exit is implementerd as a call to a function module. The code for the function module is written by the developer. You are not writing the code directly in the function module, but in the include that is implemented in the function module.

The naming standard of function modules for function module exits is:
EXIT_<3>

The call to a functionmodule exit is implemented as:
CALL CUSTOMER.-FUNCTION <3>

For Example:

The program for transaction VA01 Create salesorder is SAPMV45A

1. If you search for CALL CUSTOMER-FUNCTION program SAPMV45A you will find ( Among other user exits):

CALL CUSTOMER-FUNCTION '003'
exporting
xvbak = vbak
xvbuk = vbuk
xkomk = tkomk
importing
lvf_subrc = lvf_subrc
tables
xvbfa = xvbfa
xvbap = xvbap
xvbup = xvbup.

The exit calls function module EXIT_SAPMV45A_003

2. How to find user exits

Display the program where you are searching for and exit and search for CALL CUSTOMER-EXIT

If you know the Exit name, go to transaction CMOD. Choose menu Utillities->SAP Enhancements.

Enter the exit name and press enter.

You will now come to a screen that shows the function module exits for the exit.

or use this ABAP program to search for user exits :-

Finding the user-exits of a SAP transaction code

3. Using Project management of SAP Enhancements

You want to create a project to enhance transaction VA01

- Go to transaction CMOD
- Create a project called ZVA01
- Choose the Enhancement assign radio button and press the Change button
In the first column enter V45A0002 Predefine sold-to party in sales document . Note that an enhancement can only be used for 1 project. If the enhancement is allready in use, and error message will be displayed
- Press Save
- Press Components. You can now see that enhancement uses user exit EXIT_SAPMV45A_002.
- Double Click on the exit.
Now the function module is displayed. Double click on include ZXVVAU04 in the function module
Insert the following code into the include: E_KUNNR = '2155'.

Activate the include program. Go back to CMOD and activate the project.
Goto transaction VA01 and create a salesorder. Note that Sold-to-party now automatically is "2155"



What is User Exits and Customer Exits?

Difference between user exits & customer exits:

User exit - A user exit is a three character code that instructs the system to access a program during system processing.

SXX: S is for standard exits that are delivered by SAP. XX represents the 2-digit exit number.

UXX: U is for user exits that are defined by the user. XX represents the 2-digit exit number


Customer exit - The R/3 enhancement concept allows you to add your own functionality to SAP’s standard business applications without having to modify the original applications. SAP creates customer exits for specific programs, screens, and menus within standard R/3 applications. These exits do not contain any functionality. Instead, the customer exits act as hooks. You can hang your own add-on functionality onto these hooks.

The following document is about exits in SAP :-

The R/3 enhancement concept allows you to add your own functionality to SAP’s standard business applications without having to modify the original applications.

SAP creates user exits for specific programs, screens, and menus within standard R/3 applications. These exits do not contain any functionality. Instead, the customer exits act as hooks. You can hang your own add-on functionality onto these hooks.


Types of Exits
There are several different types of user exits. Each of these exits acts as hooks where you can attach or "hang" your own add-ons.


Menu Exits
Menu exits add items to the pulldown menus in standard SAP applications. You can use these menu items to call up your own screens or to trigger entire add-on applications.

SAP creates menu exits by defining special menu items in the Menu Painter. These special entries have function codes that begin with "+" (a plus sign). You specify the menu item’s text when activating the item in an add-on project.


Screen Exits
Screen exits add fields to screens in R/3 applications. SAP creates screen exits by placing special subscreen areas on a standard R/3 screen and calling a customer subscreen from the standard screen’s flow logic.


Function Module Exits
Function module exits add functions to R/3 applications. Function module exits play a role in both menu and screen exits.

When you add a new menu item to a standard pull down menu, you use a function module exit to define the actions that should take place once your menu is activated.

Function module exits also control the data flow between standard programs and screen exit fields. SAP application developers create function module exits by writing calls to customer functions into the source code of standard R/3 programs.

These calls have the following syntax:

CALL CUSTOMER-FUNCTION ‘001’.


Field Exits
Field exits allow you to create your own programming logic for any data element in the Dictionary. You can use this logic to carry out checks, conversions, or business-related processing for any screen field. Example: The data element BBBNR identifies a company’s international location number. You might want to set up your R/3 System so that all international location numbers are larger than 100.

The field exit concept lets you create a special function module that contains this logic.

You assign the special function module to the data element BBBNR. You then assign the module to any programs and screens in which users can add new international location numbers. When you activate your field exit, the system automatically triggers your special routine whenever a user enters a company location number.

In 4.6c, you can use "RSMODPRF" program to create field exits.


An example of a user exits :-

MODULE user_exit_0001 INPUT
CASE okcode.
WHEN 'BACK OR EXIT'.
CASE sy-dynnr.
WHEN '100'.
SET SCREEN 0.
LEAVE SCREEN.
WHEN '200'.
******************************************************************************
**** Note that you can write any code that satisfy your needs. ****
**** But in this case, this was wrote as a sample code for reference sake. ****
**** And you can test it. ****
******************************************************************************
SET SCREEN 100.
LEAVE SCREEN.
ENDCASE.
ENDCASE.

A Short Tutorial on User Exits

Content Author: Abhishek

User exits :

1. Introduction
2. How to find user exits
3. Using Project management of SAP Enhancements

1. Introduction:

User exits (Function module exits) are exits developed by SAP. The exit is implementerd as a call to a functionmodule. The code for the function module is writeen by the developer. You are not writing the code directly in the function module, but in the include that is implemented in the function module.

The naming standard of function modules for functionmodule exits is:
EXIT_<3>

The call to a functionmodule exit is implemented as:
CALL CUSTOMER.-FUNCTION <3>

Example:

The program for transaction VA01 Create salesorder is SAPMV45A

If you search for CALL CUSTOMER-FUNCTION i program
SAPMV45A you will find ( Among other user exits):

CALL CUSTOMER-FUNCTION '003'
exporting
xvbak = vbak
xvbuk = vbuk
xkomk = tkomk
importing
lvf_subrc = lvf_subrc
tables
xvbfa = xvbfa
xvbap = xvbap
xvbup = xvbup.

The exit calls function module EXIT_SAPMV45A_003

2. How to find user exits?

Display the program where you are searching for and exit and search for CALL CUSTOMER-EXIT

If you know the Exit name, go to transaction CMOD.

Choose menu Utillities->SAP Enhancements. Enter the exit name and press enter.

You will now come to a screen that shows the function module exits for the exit.

3. Using Project management of SAP Enhancements, we want to create a project to enahance trasnaction VA01 .

- Go to transaction CMOD
- Create a project called ZVA01
- Choose the Enhancement assign radio button and press the Change button

In the first column enter V45A0002 Predefine sold-to party in sales document.

Note that an enhancement can only be used in 1 project. If the enhancement is already in use, and error message will be displayed

Press Save

Press Components. You can now see that enhancement uses user exit EXIT_SAPMV45A_002. Double click on the exit.

Now the function module is displayed. Double click on include ZXVVAU04 in the function module

Insert the following code into the include: E_KUNNR = '2155'.

Activate the include program. Go back to CMOD and activate the project.

Goto transaction VA01 and craete a salesorder.

Note that Sold-to-party now automatically is "2155"

Create Push Buttons in Application Tool Bar

How to create pushbuttons in application tool bar in case of selection-screen?

REPORT zsiva_test
MESSAGE-ID zprecot.
TABLES : afru.

TYPES : BEGIN OF ty_test,
ism01 LIKE afru-ism01,
END OF ty_test.
TABLES sscrfields.

SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS : so_werks FOR afru-werks.
SELECTION-SCREEN PUSHBUTTON /79(10) charly USER-COMMAND abcd.
SELECTION-SCREEN END OF BLOCK b1.

INITIALIZATION.
MOVE 'Press' TO charly.

START-OF-SELECTION.

END-OF-SELECTION.

AT SELECTION-SCREEN.
IF sscrfields-ucomm = 'ABCD'.
MESSAGE i000 WITH so_werks-low 'Success' .
ENDIF.



ABAP Clipboard Utilities for Beautiful Commented Code

" Any fool can write code that a computer can understand.
Good programmers write code that humans can understand. "
--- Martin Fowler, Refactoring: Improving the Design of Existing Code


ABAP pretty printer is good for code but not supportive for data declarations.
As a result ABAP code often tends to need more labour to maintain.

I therefore wrote 3 Clipboard utilities

1. YClipJNC based on
http://sap.ionelburlacu.ro/abap/sap2/Beautify_Source_Code.html
but improved to include table~column half-line commenting.
Take any ABAP code (should have survived syntax check) including that "." DOT terminator.
Copy to Clipboard & F8 on YClipJNC will create the beautiful version in clipboard
ready for pasting back.

The big advantage is that you can send for beautification only portions of code
- this is vital in maintaining someone else's badly written code.

2. YClip2JNC is for Internal Table declarations only, with existing comments
Aligns everything nicely.

3. YClip3JNC is to create a Commented CALL FUNCTION Pattern.
Try with "CS_BOM_EXPL_MAT_V2"
The pattern is ready in clipboard for pasting appropriately.

These 3 utilities should give a big boost to good clean commented ABAP
code.

=========================================================================================

*&---------------------------------------------------------------------*
*& Beautify ABAP Code Via Clip
*
*&---------------------------------------------------------------------*

* based on ideas from
* http://sap.ionelburlacu.ro/abap/sap2/Beautify_Source_Code.html

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

*-----------------------------------------------------------------------
* This program takes ABAP code in ClipBoard, and does the following:
* - Attempts to move comments to the end of the line
* - Adds comments (table name) for the tables listed after a TABLES
* statement if the line has not been commented already.
* - Adds comments (field name) for data elements, parameters, and
* select-options that are defined using the LIKE or FOR statement
* - For ENDLOOP/ENDSELECT adds comment identify the LOOP/SELECT
* that is being closed
* - For FORM/ENDFORM adds comment identify the FORM that is being
* closed
* - Calls function PRETTY_PRINTER to do the SAP standard pretty print
* after the custom comments have been created
* Returns Modified Code Via ClipBoard
*-----------------------------------------------------------------------

REPORT yclipjnc. .

TABLES:
e071 , " Change & Transport System: Object Entries of
Requests/Tasks
tadir , " Directory of Repository Objects
trdir , " Generated Table for View TRDIR
dd02t . " R/3 DD: SAP table texts

DATA: BEGIN OF mtab_old_prog OCCURS 0,
line(172) TYPE c,
END OF mtab_old_prog.

DATA: BEGIN OF mtab_new_prog OCCURS 0,
line(172) TYPE c,
END OF mtab_new_prog.

DATA: BEGIN OF mtab_jnc_prog OCCURS 0,
line(172) TYPE c,
END OF mtab_jnc_prog.

DATA:
* Hold an entire statement, even if it spans multiple lines
BEGIN OF mtab_long_line OCCURS 0,
start TYPE i,
end TYPE i,
code(9999) TYPE c, "For type "C", a maximum length specification of 65535 is allowed.
END OF mtab_long_line.

DATA: BEGIN OF mtab_tabname OCCURS 0,
tabname LIKE dd02t-tabname, " Table name
tabdesc LIKE dd02t-ddtext, " Short text describing ABAP/4
Dictio
END OF mtab_tabname.

* Queue to hold list of internal table names for commenting the ENDLOOP
* line
DATA: BEGIN OF mtab_itab_names OCCURS 0,
tabname(40) TYPE c,
END OF mtab_itab_names.

* Queue to hold list of table names for commenting the ENDSELECT line
DATA: BEGIN OF mtab_tab_names OCCURS 0,
tabname(40) TYPE c,
END OF mtab_tab_names.

DATA: BEGIN OF mtab_form_names OCCURS 0,
tabname(40) TYPE c,
END OF mtab_form_names.

DATA: mylength TYPE i,
myrc TYPE i.

CONSTANTS: myhats(40) VALUE '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'.

* START of EXECUTION

* Read the program code in ClipBoard into an internal table
CALL METHOD cl_gui_frontend_services=>clipboard_import
IMPORTING
data = mtab_old_prog[]
length = mylength.

IF sy-subrc NE 0.
WRITE: / `Unable to read ClipBoard`.
WRITE: / `Exiting program`.
ENDIF.

PERFORM create_condensed_table TABLES mtab_old_prog mtab_long_line.

PERFORM format_program.

CALL FUNCTION `PRETTY_PRINTER`
EXPORTING
inctoo = space
TABLES
ntext = mtab_jnc_prog
otext = mtab_new_prog
EXCEPTIONS
enqueue_table_full = 1
include_enqueued = 2
include_readerror = 3
include_writeerror = 4
OTHERS = 5.

* Write the beautiful program code to ClipBoard from internal table
CALL METHOD cl_gui_frontend_services=>clipboard_export
IMPORTING
data = mtab_jnc_prog[]
CHANGING
rc = myrc.

LOOP AT mtab_jnc_prog.
IF mtab_jnc_prog = space.
SKIP 1.
ENDIF.
WRITE: / mtab_jnc_prog.
ENDLOOP. " LOOP AT MTAB_JNC_PROG


*---------------------------------------------------------------------*
* FORM CREATE_CONDENSED_TABLE *
*---------------------------------------------------------------------*
* Create a table that has all statements condensed onto 1 line *
*---------------------------------------------------------------------*
FORM create_condensed_table
TABLES ftab_old_prog STRUCTURE mtab_old_prog
ftab_long_line STRUCTURE mtab_long_line.

DATA:
* Structure to hold program code/comment
BEGIN OF fstr_line,
code(172) TYPE c, " Program Code
comment(172) TYPE c, " Inline comments
END OF fstr_line.

LOOP AT ftab_old_prog.

IF ftab_long_line-start = 0.
ftab_long_line-start = ftab_long_line-end + 1.
CLEAR ftab_long_line-end.
ENDIF.

* Strip off any inline comments so they do not get in the way
* If comments are not separated, then words in the comments could
* look like keywords, and cause problems
SPLIT ftab_old_prog-line AT `"` INTO fstr_line-code fstr_line-comment.

* Align all statements to be left justified
SHIFT fstr_line-code LEFT DELETING LEADING space.

* Put all lines that make up a single statement into one field
* This will make it easier to isolate key words. For example, if you
* want to process a TABLES statement, but exclude the TABLES part of a
* function call, or a subroutine call.
CONCATENATE ftab_long_line-code fstr_line-code
INTO ftab_long_line-code SEPARATED BY space.

IF fstr_line-code CA `.` OR " Period means end of statement
fstr_line-code(1) = `*` OR " Comment Line
fstr_line-code CO space. " Blank Line
* Keep track of the table index that the statement ends on
ftab_long_line-end = sy-tabix.
* Remove delimiter from concatenation of fields
SHIFT ftab_long_line-code LEFT BY 1 PLACES.

APPEND ftab_long_line.

CLEAR: ftab_long_line-code, ftab_long_line-start.

* Don`t clear out fstr_long_line-end yet. It is used to calc
* fstr_long_line-start.
ENDIF.

ENDLOOP. " LOOP AT FTAB_OLD_PROG
ENDFORM. " FORM CREATE_CONDENSED_TABLE

*---------------------------------------------------------------------*
* FORM FORMAT_PROGRAM *
*---------------------------------------------------------------------*
FORM format_program.

DATA: lstr_old_prog LIKE LINE OF mtab_old_prog.

LOOP AT mtab_long_line.

TRANSLATE mtab_long_line-code TO UPPER CASE.

IF mtab_long_line-code(1) EQ `*`. " Do not modify Comment Lines

LOOP AT mtab_old_prog FROM mtab_long_line-start
TO mtab_long_line-end.

mtab_new_prog-line = mtab_old_prog-line.

APPEND mtab_new_prog.

ENDLOOP. " LOOP AT MTAB_OLD_PROG

ELSEIF mtab_long_line-code(6) EQ `TABLES`.

* Reformat any TABLES statements. Will only reformat when TABLES
* is at the start of the statement. Will not try to get table
* descriptions for CALL FUNCTIONS or FORM/PERFORMs

* Get the table names from mstr_long_line.
PERFORM get_table_names_from_statement TABLES mtab_tabname
USING mtab_long_line-code.
* Find the descriptions for each table
PERFORM get_table_descriptions TABLES mtab_tabname.

* create the new statement
PERFORM build_new_tables_statement USING mtab_long_line.

ELSE. " All other modifications to the code handled here

LOOP AT mtab_old_prog FROM mtab_long_line-start
TO mtab_long_line-end.

* Remove extra spaces from line for comparisons
lstr_old_prog-line = mtab_old_prog-line.
CONDENSE lstr_old_prog-line.
TRANSLATE lstr_old_prog-line TO UPPER CASE.

IF lstr_old_prog-line CS `"`. " Comments
mtab_new_prog-line = mtab_old_prog-line.
ELSE.
IF lstr_old_prog-line CS ` LIKE ` OR
lstr_old_prog-line CS ` TYPE ` OR
lstr_old_prog-line CS ` FOR ` OR
lstr_old_prog-line CS `~`. "jnc OpenSQL
table~column


PERFORM get_for_like_comment USING mtab_old_prog
CHANGING mtab_new_prog.

ELSEIF lstr_old_prog-line(8) = 'LOOP AT'.

* save table name into a queue
PERFORM enqueue_itab_name USING mtab_long_line-code.
mtab_new_prog-line = mtab_old_prog-line.

ELSEIF lstr_old_prog-line(7) = `ENDLOOP`.

* get name off of queue and add it as a comment to the ENDLOOP line
PERFORM add_comment_to_endloop USING mtab_old_prog-line
CHANGING mtab_new_prog-line.

ELSEIF lstr_old_prog-line(7) EQ 'SELECT' AND
lstr_old_prog-line(13) NE 'SELECT SINGLE'.

* save table name into a queue
PERFORM enqueue_tab_name USING mtab_old_prog-line.
mtab_new_prog-line = mtab_old_prog-line.
ELSEIF lstr_old_prog-line(9) = `ENDSELECT`.

* get name off of queue and add it as a comment to the ENDSELECT
PERFORM add_comment_to_select USING mtab_old_prog-line
CHANGING mtab_new_prog-line.

ELSEIF lstr_old_prog-line(5) = 'FORM'.

* save form name into a queue
PERFORM enqueue_form_name USING mtab_old_prog-line.
mtab_new_prog-line = mtab_old_prog-line.

ELSEIF lstr_old_prog-line(7) = `ENDFORM`.

* get name off of queue and add it as a comment to the ENDFORM
PERFORM add_comment_to_endform USING mtab_old_prog-line
CHANGING mtab_new_prog-line.
ELSE. " Any other lines
mtab_new_prog-line = mtab_old_prog-line.
ENDIF.
ENDIF.

APPEND mtab_new_prog.

ENDLOOP. " LOOP AT MTAB_OLD_PROG
ENDIF.
ENDLOOP. " LOOP AT MTAB_LONG_LINE

ENDFORM. " FORM FORMAT_PROGRAM


*---------------------------------------------------------------------*
* FORM GET_TABLE_NAMES_FROM_STATEMENT *
*---------------------------------------------------------------------*
FORM get_table_names_from_statement TABLES ftab_tabname
STRUCTURE mtab_tabname
USING fc_statement.

CLEAR ftab_tabname.
REFRESH ftab_tabname.

REPLACE `TABLES` WITH space INTO fc_statement.
TRANSLATE fc_statement USING `. `. " Replace periods
TRANSLATE fc_statement USING `, `. " Replace commas
TRANSLATE fc_statement USING `: `. " Replace colons

CONDENSE fc_statement. " Remove all extra spaces

SPLIT fc_statement AT space INTO TABLE ftab_tabname.

ENDFORM. " FORM GET_TABLE_NAMES_FROM_STATEMENT


*---------------------------------------------------------------------*
* FORM GET_TABLE_DESCRIPTIONS *
*---------------------------------------------------------------------*
FORM get_table_descriptions TABLES ftab_tabname STRUCTURE mtab_tabname.

LOOP AT ftab_tabname.
SELECT SINGLE * FROM dd02t
WHERE tabname = ftab_tabname-tabname
AND ddlanguage = sy-langu.

IF sy-subrc = 0.
ftab_tabname-tabdesc = dd02t-ddtext.
MODIFY ftab_tabname.
ENDIF.

ENDLOOP. " LOOP AT FTAB_TABNAME
ENDFORM. " FORM GET_TABLE_DESCRIPTIONS


*---------------------------------------------------------------------*
* FORM BUILD_NEW_TABLES_STATEMENT *
*---------------------------------------------------------------------*
FORM build_new_tables_statement USING fstr_long_line LIKE
mtab_long_line.

DATA: lc_sep(1) TYPE c,
li_rows TYPE i,
wordlen TYPE i.

DESCRIBE TABLE mtab_tabname LINES li_rows.

mtab_new_prog-line = `TABLES:`.
APPEND mtab_new_prog.

LOOP AT mtab_tabname.
IF sy-tabix = li_rows.
lc_sep = `.`.
ELSE.
lc_sep = `,`.
ENDIF.

wordlen = STRLEN( mtab_tabname-tabname ).

IF wordlen < wordlen =" 12" wordlen =" 1." line =" f_old_prog." f_new_prog =" f_old_prog." f_new_prog =" lstr_old_prog-line." tabname =" `SY`." tabname =" `SYST`." tabname =" lstr_field-tabname" nametab =" ltab_nametab" internal_error =" 1" table_has_no_fields =" 2" table_not_activ =" 3" no_texts_found =" 4" others =" 5."> 0.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

READ TABLE ltab_nametab
WITH KEY tabname = lstr_field-tabname
fieldname = lstr_field-fldname.

IF sy-subrc = 0.

wordlen = STRLEN( lstr_old_prog-line ).

IF wordlen < wordlen =" 45" wordlen =" 1." f_new_prog =" lstr_old_prog-line." mtab_itab_names =" lc_itab." f_prog_line =" mtab_old_prog-line." mtab_tab_names =" lc_tab." f_prog_line =" mtab_old_prog-line." f_prog_line =" mtab_old_prog-line." mtab_form_names =" lc_tab." enqueue_form_name ="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="="" cl_gui_frontend_services="">clipboard_import
IMPORTING
data = mtab_old_prog[]
length = mylength.

IF sy-subrc NE 0.
WRITE: / `Unable to read ClipBoard`.
WRITE: / `Exiting program`.
ENDIF.

* SAP pads non-displayable characters in last few lines
LOOP AT mtab_old_prog.
MOVE sy-tabix TO saveix.

CONDENSE mtab_old_prog-line.
REPLACE ALL OCCURRENCES OF ' ,' IN mtab_old_prog-line WITH ','.

SPLIT mtab_old_prog-line AT space INTO TABLE i_words.

LOOP AT i_words.
wordlen = STRLEN( i_words-word ).
IF wordlen > 60
OR i_words-word+0(1) <> '~'.
DELETE mtab_old_prog INDEX saveix.
EXIT.
ENDIF.
ENDLOOP.
ENDLOOP.

LOOP AT mtab_old_prog.
CONDENSE mtab_old_prog-line.
REPLACE ALL OCCURRENCES OF ' ,' IN mtab_old_prog-line WITH ','.

SPLIT mtab_old_prog-line AT space INTO TABLE i_words.

MOVE 1 TO colnum.
LOOP AT i_words.
wordlen = STRLEN( i_words-word ).
CASE colnum.
WHEN 1.
IF wordlen > maxlen1.
MOVE wordlen TO maxlen1.
ENDIF.
WHEN 2.
IF wordlen > maxlen2.
MOVE wordlen TO maxlen2.
ENDIF.
WHEN 3.
IF wordlen > maxlen3.
MOVE wordlen TO maxlen3.
ENDIF.
ENDCASE.
ADD 1 TO colnum.
ENDLOOP.
ENDLOOP.


LOOP AT mtab_old_prog.
workline = mtab_old_prog-line.
CONDENSE workline.
REPLACE ALL OCCURRENCES OF ' ,' IN mtab_old_prog-line WITH ','.

SPLIT workline AT space INTO TABLE i_words.

LOOP AT i_words.
FIND i_words-word IN mtab_old_prog-line MATCH OFFSET wordoff.
EXIT.
ENDLOOP.
EXIT.
ENDLOOP.

LOOP AT mtab_old_prog.
CONDENSE mtab_old_prog-line.
REPLACE ALL OCCURRENCES OF ' ,' IN mtab_old_prog-line WITH ','.

SPLIT mtab_old_prog-line AT space INTO TABLE i_words.

MOVE 1 TO colnum.
LOOP AT i_words.
wordlen = STRLEN( i_words-word ).
CASE colnum.
WHEN 1.
PERFORM f_diff_calc USING maxlen1 wordlen
CHANGING diff.
CONCATENATE myhats+0(wordoff) i_words-word myhats+0(diff) INTO
mtab_new_prog-line.
WHEN 2.
PERFORM f_diff_calc USING maxlen2 wordlen
CHANGING diff.
CONCATENATE mtab_new_prog-line i_words-word myhats+0(diff) INTO
mtab_new_prog-line.
WHEN 3.
PERFORM f_diff_calc USING maxlen3 wordlen
CHANGING diff.
CONCATENATE mtab_new_prog-line i_words-word myhats+0(diff) INTO mtab_new_prog-line.
WHEN OTHERS.
CONCATENATE mtab_new_prog-line ` ` i_words-word INTO mtab_new_prog-line.
ENDCASE.
ADD 1 TO colnum.
ENDLOOP.
TRANSLATE mtab_new_prog-line USING `^ `.
APPEND mtab_new_prog.
ENDLOOP.

* Write the beautiful program code to ClipBoard from internal table
CALL METHOD cl_gui_frontend_services=>clipboard_export
IMPORTING
data = mtab_new_prog[]
CHANGING
rc = myrc.

LOOP AT mtab_new_prog.
IF mtab_new_prog = space.
SKIP 1.
ENDIF.
WRITE: / mtab_new_prog.
ENDLOOP. " LOOP AT MTAB_NEW_PROG

*&--------------------------------------------------------------------*
*& Form f_diff_calc
*&--------------------------------------------------------------------*
FORM f_diff_calc USING value(maxlen) TYPE i
value(wordlen) TYPE i
CHANGING diff TYPE i.

COMPUTE diff = maxlen - wordlen + 4.
IF diff > 40.
diff = 40.
ENDIF.
ENDFORM. "f_diff_calc


=========================================================================================

*&---------------------------------------------------------------------*
*& Beautiful Function Module Call via clipboard
*
*&---------------------------------------------------------------------*

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

*-----------------------------------------------------------------------
* This program takes a parameter as a Function Module Name
* and does a documented "pattern paste"
* Returns pattern Code Via ClipBoard
*-----------------------------------------------------------------------

PROGRAM yclip3jnc.

TYPE-POOLS : slis.

PARAMETERS: p_func LIKE fupararef-funcname. " Name of Function Module

DATA : BEGIN OF i_tab OCCURS 0,
funcname LIKE fupararef-funcname, " Name of Function Module
paramtype LIKE fupararef-paramtype, " Parameter type
pposition LIKE fupararef-pposition, " Internal Table, Current Line Index
optional LIKE fupararef-optional, " Optional parameters
parameter LIKE fupararef-parameter, " Parameter name
defaultval LIKE fupararef-defaultval, " Default value for import parameter
structure LIKE fupararef-structure, " Associated
Type of an Interface Parameter
stext LIKE funct-stext, " Short text
END OF i_tab.

DATA: BEGIN OF mtab_new_prog OCCURS 0,
line(172) TYPE c,
END OF mtab_new_prog.

DATA: funcdesc LIKE tftit-stext, " Short text for function module
mylen TYPE i,
myrc TYPE i.

CONSTANTS: myhats(40) VALUE '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'.

TRANSLATE p_func TO UPPER CASE.

SELECT SINGLE
tftit~stext " Short text for function module
INTO funcdesc
FROM tftit
WHERE tftit~funcname = p_func
AND tftit~spras = sy-langu.

TRANSLATE p_func TO LOWER CASE.

CONCATENATE `CALL FUNCTION ` p_func ` " ` funcdesc INTO mtab_new_prog-line.
APPEND mtab_new_prog.

TRANSLATE p_func TO UPPER CASE.

SELECT
fupararef~funcname " Name of Function Module
fupararef~paramtype " Parameter type
fupararef~pposition " Internal Table, Current Line Index
fupararef~optional " Optional parameters
fupararef~parameter " Parameter name
fupararef~defaultval " Default value for import parameter
fupararef~structure " Associated Type of an Interface
Parameter
funct~stext " Short text
INTO TABLE i_tab
FROM fupararef
INNER JOIN funct
ON fupararef~funcname = funct~funcname
AND fupararef~parameter = funct~parameter
AND funct~spras = sy-langu
WHERE fupararef~funcname = p_func
AND fupararef~r3state = 'A'
ORDER BY fupararef~paramtype
fupararef~pposition.


LOOP AT i_tab.
AT NEW paramtype.
CASE i_tab-paramtype.
WHEN 'C'.
MOVE ' CHANGING' TO mtab_new_prog-line.
WHEN 'E'.
MOVE ' IMPORTING' TO mtab_new_prog-line.
WHEN 'I'.
MOVE ' EXPORTING' TO mtab_new_prog-line.
WHEN 'T'.
MOVE ' TABLES' TO mtab_new_prog-line.
WHEN 'X'.
MOVE ' EXCEPTIONS' TO mtab_new_prog-line.
ENDCASE.
APPEND mtab_new_prog.
ENDAT.

IF i_tab-optional = 'X'.
mtab_new_prog-line = `*^^^`.
ELSE.
mtab_new_prog-line = `^^^^`.
ENDIF.

IF i_tab-paramtype = 'X'.
MOVE i_tab-pposition TO i_tab-defaultval.
CONDENSE i_tab-defaultval.
ELSE.
TRANSLATE i_tab-parameter TO LOWER CASE.
ENDIF.

CONCATENATE mtab_new_prog-line i_tab-parameter '^=^' INTO mtab_new_prog-line.

IF i_tab-defaultval IS NOT INITIAL.
CONCATENATE mtab_new_prog-line i_tab-defaultval INTO mtab_new_prog-line.
ENDIF.

mylen = STRLEN( mtab_new_prog-line ).

IF mylen < mylen =" 31" mylen =" STRLEN(" mylen =" 47" mtab_new_prog =" space." cl_gui_frontend_services="">clipboard_export
IMPORTING
data = mtab_new_prog[]
CHANGING
rc = myrc.


Recursion with Loop Checking in SAP

* This program can be a model for any ABAP recursion.
* This is often needed to navigate down hierarchical data.
* One example is BOM.

* Important point is to chack for stack overflow
* and give RIGHT MESSAGE so that corrective action can be taken.

*&---------------------------------------------------------------------*
* Sample Program Showing Recursion in ABAP
* Simple BOM Tree walking in ABAP
* Takes Care of Diagnostics as well - detects Loops
* Hence never experience Stack Overflow!
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
* http://www.sap-img.com/abap/reincarnation-of-reuse-alv-fieldcatalog-merge.htm
* has INCLUDE zjncinclude with FORM zjnc_dump_list
*&---------------------------------------------------------------------*

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

REPORT zjncrecursion.

INCLUDE zjncinclude. " From www.sap-img.com

TABLES: makt.

CONSTANTS: maxlevels TYPE i VALUE 10.

TYPES: BEGIN OF ty_usage,
parent TYPE makt-matnr,
child TYPE makt-matnr,
usage TYPE mseg-menge,
END OF ty_usage.

DATA: wa_usage TYPE ty_usage,
it_usage TYPE STANDARD TABLE OF ty_usage. " USAGE data

TYPES: BEGIN OF ty_stack,
level TYPE h_level,
matnr TYPE makt-matnr,
menge TYPE mseg-menge,
END OF ty_stack.

DATA: istackpos TYPE i,
wa_stack TYPE ty_stack,
it_stack TYPE STANDARD TABLE OF ty_stack. "BOM Stack

TYPES: BEGIN OF ty_reqd,
matnr TYPE makt-matnr,
menge TYPE mseg-menge,
END OF ty_reqd.

DATA: wa_reqd TYPE ty_reqd,
it_reqd TYPE STANDARD TABLE OF ty_reqd. "NET Requirement of
RAW Material

PARAMETERS: p_build TYPE makt-matnr, "Target to Build
p_menge TYPE mseg-menge. "Quantity to Build

INITIALIZATION.
PERFORM f_usage_data.


START-OF-SELECTION.

istackpos = 0.

MOVE istackpos TO wa_stack-level.
MOVE p_build TO wa_stack-matnr.
MOVE p_menge TO wa_stack-menge.
APPEND wa_stack TO it_stack. " 1st PUSH

PERFORM f_explode USING p_build.

SORT it_reqd BY matnr.

PERFORM zjnc_dump_list USING 'IT_REQD' 'WA_REQD' 'Net RAW
Requirement'.

*&--------------------------------------------------------------------*
*& Form f_Explode
*&--------------------------------------------------------------------*
FORM f_explode USING p_pmatnr.
DATA: icount TYPE i,
totalreq TYPE mseg-menge.

istackpos = istackpos + 1. " PUSH

IF istackpos GE maxlevels.
PERFORM f_dumpstack. " terminate
LEAVE PROGRAM.
ENDIF.

icount = 0.

LOOP AT it_usage INTO wa_usage WHERE parent = p_pmatnr.
icount = icount + 1.

MOVE istackpos TO wa_stack-level.
MOVE wa_usage-child TO wa_stack-matnr.
MOVE wa_usage-usage TO wa_stack-menge.
APPEND wa_stack TO it_stack. " PUSH

PERFORM f_explode USING wa_usage-child.

ENDLOOP.

IF icount = 0. " then LEAF
totalreq = '1.0'.
LOOP AT it_stack INTO wa_stack.
totalreq = totalreq * wa_stack-menge.
ENDLOOP.

MOVE p_pmatnr TO wa_reqd-matnr.
MOVE totalreq TO wa_reqd-menge.
COLLECT wa_reqd INTO it_reqd.

ENDIF.

DELETE it_stack INDEX istackpos. " POP

istackpos = istackpos - 1. " POP

ENDFORM. "f_Explode

*&--------------------------------------------------------------------*
*& Form f_dumpstack
*&--------------------------------------------------------------------*
FORM f_dumpstack.

PERFORM zjnc_dump_list USING 'IT_STACK' 'WA_STACK' 'LOOP in BOM
STACK'.

ENDFORM. "f_dumpstack

*&--------------------------------------------------------------------*
*& Form f_usage_data for Hungry Bengali ABAPer in Kolkata
*&--------------------------------------------------------------------*
FORM f_usage_data.
MOVE 'FISHCURRY' TO wa_usage-parent.
MOVE 'SPICES' TO wa_usage-child.
MOVE 10 TO wa_usage-usage.
APPEND wa_usage TO it_usage.

MOVE 'FISHCURRY' TO wa_usage-parent.
MOVE 'MIRCHI' TO wa_usage-child.
MOVE 5 TO wa_usage-usage.
APPEND wa_usage TO it_usage.

MOVE 'FISHCURRY' TO wa_usage-parent.
MOVE 'ALOO' TO wa_usage-child.
MOVE 8 TO wa_usage-usage.
APPEND wa_usage TO it_usage.

MOVE 'SPICES' TO wa_usage-parent.
MOVE 'MIRCHI' TO wa_usage-child.
MOVE 2 TO wa_usage-usage.
APPEND wa_usage TO it_usage.

MOVE 'SPICES' TO wa_usage-parent.
MOVE 'JEERA' TO wa_usage-child.
MOVE 3 TO wa_usage-usage.
APPEND wa_usage TO it_usage.

MOVE 'SPICES' TO wa_usage-parent.
MOVE 'HALUD' TO wa_usage-child.
MOVE 7 TO wa_usage-usage.
APPEND wa_usage TO it_usage.

ENDFORM. "f_usage_data