Thursday, May 8, 2008

Object oriented programming (OOP) All Steps

Place the mouse cursor in DEPOSIT and hit the Parameters button.



Write the parameters imported / exported for DEPOSIT method.


Similarly for SET_BALANCE




And WITHDRAW

For withdraw we define an exception.


We can see

the attributes and methods by pressing “Display object list” button on top.


Now we IMPLEMENT the 3 methods.
Double click the method
DEPOSIT.
Write the required code.
Similarly for SET_BALANCE



Write the required code.

Similarly for
WITHDRAW.

Now we are almost done creating the object.

Press CTRL + F3 to activate or hit the Matchstick.

We will see this in the status

Now we are done building the global class we can test it.

Press F8.

Click SET_BALANCE.
Write the NEW_BALANCE and
Press ENTER.



We come back to Initial Screen.
Now click DEPOSIT.

We see the return Values now.


Now let’s WITHDRAW 4000


Now the BALANCE is 2000

Lets try withdrawing 3000 now.


We get an exception.

Given below is an example code for using the global class we defined.

REPORT ZGB_OOPS_BANK .

DATA: acct1 type ref to zaccountaa.

DATA: bal type i.

create object: acct1.

selection-screen begin of block a.
parameters: p_amnt type dmbtr,
p_dpst type dmbtr,
p_wdrw type dmbtr.

selection-screen end of block a.

start-of-selection.


call method acct1->set_balance( p_amnt ).
write:/ 'Set balance to ', p_amnt.


bal = acct1->deposit( p_dpst ).
write:/ 'Deposited ', p_dpst ,' bucks making balance to ', bal.


bal = acct1->withdraw( p_wdrw ).
write:/ 'Withdrew ', p_wdrw ,' bucks making balance to ', bal.


This is the output.

Object oriented programming (OOP) Step2

DEPOSIT,

SET_BALANCE

and

WITHDRAW.

Object oriented programming (OOP) Step-by-step

approach with screen-shots

Go to SE24 (Class builder)

Type in ZACCOUNTAA as the name of the class and press Create.



Object oriented programming (OOP) explained with an example

Create a class that keeps track of a bank account balance. Then write a program to use this class.


Steps involved:


· Run the class builder utility (SE24).

· Create a class called ZACCOUNTxx, where xx is the last two digits of your logon ID.

· Declare a PRIVATE attribute BALANCE of type DMBTR to store the account balance.



Create the following PUBLIC methods:

o SET_BALANCE (Sets the balance to a new value)

§ IMPORTING NEW_BALANCE TYPE DMBTR


o DEPOSIT (Adds a deposit amount to the balance and returns the new balance)

§ IMPORTING AMOUNT TYPE DMBTR

§ RETURNING NEW_BALANCE TYPE DMBTR


o WITHDRAW (Subtracts a deposit amount from the balance and returns the new balance.)

§ IMPORTING AMOUNT TYPE DMBTR

§ RETURNING NEW_BALANCE TYPE DMBTR

§ EXCEPTIONS INSUFFICIENT_FUNDS


· Activate all elements of your class.


· Write a program called Z_USE_ACCOUNT_xx, where xx is the last two digits of your logon ID.


This program should do the following:


o Instantiate an instance of the Account class.

o Set the account balance to some initial value.

o Make several deposits and withdrawals, printing the new balance each time. Do not allow the balance to become less than zero. (Use the exception to detect this.)

· Test and debug your program.


"Extra Credit": If you have extra time, try any of the following:


· Replace the SET_BALANCE method with a constructor. Pass the opening balance when you instantiate the account object.

· Create a static attribute and methods to set and get the name of the bank that holds the accounts.

Wednesday, May 7, 2008

Interview Question on BAPI, RFC, ABAP Objects, Tables

1) What is the difference between RFC and BAPI ?
What are subclasses and super classes in BAPI and also what are the methods in BAPI ?
2) Is it possible to connect SAP to Non-SAP systems to retrieve data using RFC alone with out using BAPI ?
3) What is the difference between Function module and BAPI ?
4) What are the types of tables?
5) What are pooled table ?
6) What are Hashed Tables ?
7) What are advantages of using ABAP objects?
8) What is the advantage of using ABAP objects in Reports ?

1) BAPI are RFC enabled function modules. the difference between RFc and BAPI are business objects. You create business objects and those are then registered in your BOR (Business Object Repository) which can be accessed outside the SAP system by using some other applications (Non-SAP) such as VB or JAVA. in this case u only specify the business object and its method from external system in BAPI there is no direct system call. while RFC are direct system call Some BAPIs provide basic functions and can be used for most SAP business object types. These BAPIs should be implemented the same for all business object types. Standardized BAPIs are easier to use and prevent users having to deal with a number of different BAPIs. Whenever possible, a standardized BAPI must be used in preference to an individual BAPI.

The following standardized BAPIs are provided:
Reading instances of SAP business objects
GetList ( ) With the BAPI GetList you can select a range of object key values, for example, company codes and material numbers.

The BAPI GetList() is a class method.
GetDetail() With the BAPI GetDetail() the details of an instance of a business object type are retrieved and returned to the calling program. The instance is identified via its key. The BAPI GetDetail() is an instance method. BAPIs that can create, change or delete instances of a business object type

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

Create( ) and CreateFromData! ( )
The BAPIs Create() and CreateFromData() create an instance of an SAP business object type, for example, a purchase order. These BAPIs are class methods.

Change( )
The BAPI Change() changes an existing instance of an SAP business object type, for example, a purchase order. The BAPI Change () is an instance method.

Delete( ) and Undelete( ) The BAPI Delete() deletes an instance of an SAP business object type from the database or sets a deletion flag.

The BAPI Undelete() removes a deletion flag. These BAPIs are instance methods.

Cancel ( ) Unlike the BAPI Delete(), the BAPI Cancel() cancels an instance of a business object type. The instance to be cancelled remains in the database and an additional instance is created and this is the one that is actually canceled. The Cancel() BAPI is an instance method.

Add ( ) and Remove ( ) The BAPI Add adds a subobject to an existing object inst! ance and the BAPI and Remove removes a subobject from an object instance. These BAPIs are instance methods.

2) No it is not possible to connect SAP to Non-SAP systems to retrieve data using RFC alone. RFC can acces the SAP from outside only through BAPI and same is for vice versa access.

3) Each Bapi Object has Interface, Key Fields, Attributes,Methods and Events.
Bapi Function Modules can be attached to these Bapi objects .Function module has a single bound functionality while a BAPI object can contain many functionalities

4) Transparent table, Pool table and cluster table are data dictionary table objects sorted table, indexed table and hash table are internal tables.

5)Table pools (pools) and table clusters (clusters) are special table types in the ABAP Dictionary. The data from several different tables can be stored together in a table pool or table cluster. Tables assigned to a table pool or table cluster are referred to as pooled tables or cluster tables.

A table in the database in which all records from the pooled tables assigned to the table pool are stored corresponds to a table pool.

The definition of a pool consists essentially of two key fields (Tabname and Varkey) and a long argument field (Vardata).
Table Clusters Several logical data records from different cluster tables can be stored together in one physical
record in a table cluster.

A cluster key consists of a series of freely definable key fields and a field (Pageno) for distinguishing continuation records. A cluster also contains a long field (Vardata) that contains the contents of the data fields of the cluster tables for this key. If the data does not fit into the long field, continuation records are created. Control information on the structure of the data string is still written at the beginning of the Vardata field.

6) Hashed tables
This is the most appropriate type for any table where the main operation is key access. You cannot access a hashed table using its index. The response time for key access remains constant, regardless of the number of table entries. Like database tables, hashed tables always have a unique key. Hashed tables are useful if you want to construct and use an internal table which resembles a database table or for processing large amounts of data.

Sample Prog: This does nothing.
REPORT Z_1 .
tables: mara.
data: i type hashed table of mara with unique key matnr

7) and 8) ABAP objects are root for your program and reports.

RFC Vs BAPI

BAPI are RFC enabled function modules. the difference between RFc and BAPI are business objects. You create business objects and those are then registered in your BOR (Business Object Repository) which can be accessed outside the SAP system by using some other applications (Non-SAP) such as VB or JAVA.

In this case you only specify the business object and its method from external system in BAPI there is no direct system call. while RFC are direct system call Some BAPIs provide basic functions and can be used for most SAP business object types. These BAPIs should be implemented the same for all business object types. Standardized BAPIs are easier to use and prevent users having to deal with a number of different BAPIs. Whenever possible, a standardized BAPI must be used in preference to an individual BAPI. It is not possible to connect SAP to Non-SAP systems to retrieve data using RFC alone. RFC can acces the SAP from outside only through BAPI and same is for vice versa access.

RFC is the protocol used by SAP for remote communication, that is, for communications between remote (independent) systems. RFC is used for communications between two independent SAP systems, or for communications between an SAP system and a non-SAP system, such as an external application. It can also be used for communications between modules on the same system. Using the RFC interfaces you can extend the functionality of R/3 applications from an external program.

What is the different btween clear and refresh?

There are 2 types of clear statements we can use:
Clear ITAB : This Statement will clear the Internal Table Header content.
To clear the Intertal Table Hearder as well Body we can use Clear ITAB [ ] statement.

Refresh will deletes the Internal Table content but still memory is not freed.

What is the pick statment do?

Pick Statemnt will captures the UserAction.
Eg: if SY-UCOMM = 'X'.
This type of user actions can be captured thru PICK Statement only.

What is the different between sesstion method and call transaction method and suppose I used one method to transform the data next time suppose I want transform the data which method I can use.

There are many difference between Session method and Call Transaction.
Which method we have to use will be found based on Volume Of data and Accuracy of data given. Mainly Call Transaction used for small sets of data because in Call Transaction we have to Handle the Processing errors explicitly. We can do this by BDCMSGCOLL structure.
In Session method seperate session will crate for errors. Calll Transaction will update the Database fastly compare with Session Method.

What is single and upto one row different?

The Major difference between Select Single and Select UPTO 1 rows is The Usage Of Buffer for each.
Select Single will search for all the satisfied data and bring all that data into Buffer and later it will give to that data to the program.
Select UPTO 1 Rows will end the search after getting the 1st satisfied record and gives that record to the program.
Thus Select Single will take much processing time when compare with Select UPTO 1 rows.

What is the differences between selection screen and selection screen out?

The difference between Selection Screen and Selection Screen Output is we use the Selection Screen Output Event before the Selection Screen will displayed. Eg: Suppose if we want to disable some fields and enable some fields in the Selection Screen then we can code that in Section-Screen Output event.
Selection-Screen Event will trigger after section-screen is displayed and user action takes place on that.

The Other 50 ABAP Interview Faq's

51. What are the techniques involved in using SAP supplied programs?
Do you prefer to write your own programs to load master data? Why?

52. What are logical databases? What are the advantages/disadvantages of logical databases?
ANS:-
To read data from a database tables we use logical database.
A logical database provides read-only access to a group of related tables to an ABAP/4 program.

adv:-
The programmer need not worry about the primary key for each table.Because Logical database knows how the different tables relate to each other,and can issue the SELECT command with proper where clause to retrieve the data.
i)An easy-to-use standard user interface.
ii)check functions which check that user input is complete,correct,and plausible.
iii)meaningful data selection.
iv)central authorization checks for database accesses.
v)good read access performance while retaining the hierarchical data view determined by the application logic.

disadv:-
i)If you donot specify a logical database in the program attributes,the GET events never occur.
ii)There is no ENDGET command,so the code block associated with an event ends with the next event
statement (such as another GET or an END-OF-SELECTION).

53. What specific statements do you using when writing a drill down report?
ans:-
AT LINE-SELECTION,AT USER-COMMAND,AT PF.

54. What are different tools to report data in SAP? What all have you used?
ans:-

55. What are the advantages and disadvantages of ABAP/4 query tool?

56. What are the functional areas? User groups? and how does ABAP/4 query work in relation to these?

57. Is a logical database a requirement/must to write an ABAP/4 query?

59. What are Change header/detail tables? Have you used them?

60. What do you do when the system crashes in the middle of a BDC batch session?
ans:-
we will look into the error log file (SM35).

61. What do you do with errors in BDC batch sessions?
ANS:-
We look into the list of incorrect session and process it again. To correct incorrect session we analyize the session to determine which screen and value produced the error.For small errors in data we correct them interactively otherwise
modify batch input program that has generated the session or many times even the datafile.

62. How do you set up background jobs in SAP? What are the steps? What are the event driven batch jobs?
ans:-
go to SM36 and create background job by giving job name,job class and job steps(JOB SCHEDULING)

63. Is it possible to run host command from SAP environment? How do you run?

64. What kind of financial periods exist in SAP? What is the relavent table for that?

65. Does SAP handle multiple currencies? Multiple languages?
ans:-
Yes.

66. What is a currency factoring technique?

67. How do you document ABAP/4 programs? Do you use program documentation menu option?

68. What is SAPscript and layout set?
ans:-
The tool which is used to create layout set is called SAPscript. Layout set is a design document.

69. What are the ABAP/4 commands that link to a layout set?
ans:-
control commands,system commands,

70. What is output determination?

71. What are IDOCs?
ans:-
IDOCs are intermediate documents to hold the messages as a container.

72. What are screen painter? menu painter? Gui status? ..etc.
ans:-
dynpro - flow logic + screens.
menu painter -
GUI Status - It is subset of the interface elements(title bar,menu bar,standard tool bar,push buttons) used for a certain screen.
The status comprises those elements that are currently needed by the transaction.

73. What is screen flow logic? What are the sections in it? Explain PAI and PBO.
ans:-
The control statements that control the screen flow.
PBO - This event is triggered before the screen is displayed.
PAI - This event is responsible for processing of screen after the user enters the data and clicks the pushbutton.

74. Overall how do you write transaction programs in SAP?
ans:-
Create program-SE93-create transcode-Run it from command field.

75. Does SAP has a GUI screen painter or not? If yes what operating systems is it available on? What is the other type of screen painter called?

76. What are step loops? How do you program pagedown pageup in step loops?
ans:-
step loops are repeated blocks of field in a screen.

77. Is ABAP a GUI language?
ANS:-
Yes.
ABAP IS AN EVENT DRIVEN LANGUAGE.

78. Normally how many and what files get created when a transaction program is written?
What is the XXXXXTOP program?
ans:-
ABAP/4 program.
DYNPRO

79. What are the include programs?
ANS:-
When the same sequence of statements in several programs are to be written repeadly they are coded in include programs (External programs) and are included in ABAP/4 programs.

80. Can you call a subroutine of one program from another program?
ans:- Yes- only external subroutines Using 'SUBMIT' statement.

81. What are user exits? What is involved in writing them? What precations are needed?

82. What are RFCs? How do you write RFCs on SAP side?

83. What are the general naming conventions of ABAP programs?
ANS:-
Should start with Y or Z.

84. How do you find if a logical database exists for your program requrements?
ans:-
SLDB-F4.

85. How do you find the tables to report from when the user just tell you the transaction he uses? And all the underlying data is from SAP structures?
ans:-
Transcode is entered in command field to open the table.Utilities-Table contents-display.

86. How do you find the menu path for a given transaction in SAP?
ans:-

87. What are the different modules of SAP?
ans:-
FI,CO,SD,MM,PP,HR.

89. How do you get help in ABAP?
ans:-
HELP-SAP LIBRARY,by pressing F1 on a keyword.

90. What are different ABAP/4 editors? What are the differences?
ans:-

91. What are the different elements in layout sets?
ans:-
PAGES,Page windows,Header,Paragraph,Character String,Windows.

92. Can you use if then else, perform ..etc statements in sap script?
ans:-
yes.

93. What type of variables normally used in sap script to output data?

94. How do you number pages in sapscript layout outputs?

95. What takes most time in SAP script programming?
ANS:-
LAYOUT DESIGN AND LOGO INSERTION.

96. How do you use tab sets in layout sets?

97. How do you backup sapscript layout sets? Can you download and upload? How?

98. What are presentation and application servers in SAP?
ANS:-
The application layer of an R/3 System is made up of the application servers and the message server. Application programs in an R/3 System are run on application servers. The application servers communicate with the presentation components, the database, and also with each other, using the message server.

99. In an ABAP/4 program how do you access data that exists on a presentation server vs on an application server?
ans:-
i)using loop statements.
ii)flat

100. What are different data types in ABAP/4?
ans:-
Elementary -
predefined C,D,F,I,N,P,T,X.
userdefined TYPES.
ex: see in intel book page no 35/65

Structured -
predefined TABLES.
userdefined Field Strings and internal tables.

101. What is difference between session method and Call Transaction?
ans:-

102. Setting up a BDC program where you find information from?
ans:-

103. What has to be done to the packed fields before submitting to a BDC session.
ans:-
fields converted into character type.

104. What is the structure of a BDC sessions.
ans:-
BDCDATA (standard structure).

105. What are the fields in a BDC_Tab Table.
ans:-
program,dynpro,dynbegin,fnam,fval.

106. What do you define in the domain and data element.
Technical details like

107. What is the difference between a pool table and a transparent table and how they are stored at the database level.
ans:-
ii)Pool tables is a logical representation of transparent tables .Hence no existence at database level. Where as transparent tables are physical tables and exist at database level.

108. What is cardinality?
For cardinality one out of two (domain or data element) should be the same for Ztest1 and Ztest2 tables. M:N
Cardinality specifies the number of dependent(Target) and independent (source) entities which can be in a relationship

More than 100 ABAP Interview Faq's

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 :-

Can any body explain me what is field group?

Field groups are groups similar fields together into one name. Field group works in conjuction with

INSERT f1 f2 INTO fg
EXTRACT fg
SORT BY fg
LOOP ... ENDLOOP

INSERT f1 f2 INTO fg
---------------------

The insert statement is used to create a field group dynamically by inserting the field into it. Only global data fields can be inserted and not local data fields eg : in form modules.

EXTRACT fg
----------

This will combine all the fields in the fieldgroup and write them to a sequential dataset as a single record.

SORT BY fg
----------

Sorting of sequential dataset by field group.

LOOP AND ENDLOOP
---------------

LOOP.
AT ***
......
....
ENDAT.
AT ***
.....
....
ENDAT.
ENDLOOP. *-- Chinmaya

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:- by Madhukar
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:-

21. What is the meaning of ABAP/4 editor integrated with ABAP/4 data dictionary?
ANS:-

22. What are the events in ABAP/4 language?
ANS:-
Initialization, At selection-screen,Start-of-selection,end-of-selection,top-of-page,end-of-page, At line-selection,At user-command,At PF,Get,At New,At LAST,AT END, AT FIRST.

23. What is an interactive report?
What is the obvious diff of such report compared with classical type reports?
ANS:-
An Interactive report is a dynamic drill down report that produces the list on users choice.
diff:-
a) THE LIST PRODUCED BY CLASSICAL REPORT DOESN'T allow user to interact with the system
the list produced by interactive report allows the user to interact with the system.
b) ONCE A CLASSICAL REPORT EXECUTED USER LOOSES CONTROL.IR USER HAS CONTROL.
c) IN CLASSICAL REPORT DRILLING IS NOT POSSIBLE.IN INTERACTIVE DRILLING IS POSSIBLE.

24. What is a drill down report?
ANS:-
Its an Interactive report where in the user can get more relavent data by selecting explicitly.

25. How do you write a function module in SAP? describe.
ANS:-
creating function module:-
called program - se37-creating funcgrp,funcmodule by assigning attributes,importing,exporting,tables,exceptions.
calling program - SE38-in pgm click pattern and write function name- provide export,import,tables,exception values.

26. What are the exceptions in function module?
ANS:-
COMMUNICATION_FAILURE
SYSTEM_FAILURE

27. What is a function group?
ANS:-
GROUP OF ALL RELATED FUNCTIONS.

28. How are the date and time field values stored in SAP?
ANS:-
DD.MM.YYYY. HH:MM:SS

30. Name a few data dictionary objects? //rep//
ANS:-
TABLES,VIEWS,STRUCTURES,LOCK OBJECTS,MATCHCODE OBJECTS.

31. What happens when a table is activated in DD?
ANS:-
It is available for any insertion,modification and updation of records by any user.

32. What is a check table and what is a value table?
Check table will be at field level checking.
Value table will be at domain level checking ex: scarr table is check table for carrid.

33. What are match codes? describe?
ans:-
It is a similar to table index that gives list of possible values for either primary keys or non-primary keys.

34. What transactions do you use for data analysis?
ANS:-

35. What is table maintenance generator?
ANS:-

36. What are ranges? What are number ranges?
ANS:-
max,min values provided in selection screens.

37. What are select options and what is the diff from parameters?
ANS:-
select options provide ranges where as parameters do not.

SELECT-OPTIONS declares an internal table which is automatically filled with values or ranges
of values entered by the end user. For each SELECT-OPTIONS , the system creates a selection table.

SELECT-OPTIONS FOR .

A selection table is an internal table with fields SIGN, OPTION, LOW and HIGH.
The type of LOW and HIGH is the same as that of .
The SIGN field can take the following values: I Inclusive (should apply) E Exclusive (should not apply)
The OPTION field can take the following values: EQ Equal GT Greater than NE Not equal BT Between LE Less
than or equal NB Not between LT Less than CP Contains pattern GE Greater than or equal NP No pattern.
diff:-
PARAMETERS allow users to enter a single value into an internal field within a report.
SELECT-OPTIONS allow users to fill an internal table with a range of values.

For each PARAMETERS or SELECT-OPTIONS statement you should define text elements by choosing
Goto - Text elements - Selection texts - Change.

Eg:- Parameters name(30).
when the user executes the ABAP/4 program,an input field for 'name' will appear on the selection screen.You can change the comments on the left side of the input fields by using text elements as described in Selection Texts.

38. How do you validate the selection criteria of a report?
And how do you display initial values in a selection screen?
ANS:-
validate :- by using match code objects.
display :- Parameters default 'xxx'.
select-options for spfli-carrid.

39. What are selection texts?
ANS:-

40. What is CTS and what do you know about it?
ANS:-

The Change and Transport System (CTS) is a tool that helps you to organize development projects in the ABAP Workbench and in Customizing, and then transport the changes between the SAP Systems and clients in your system landscape.
This documentation provides you with an overview of how to manage changes with the CTS and essential information on setting up your system and client landscape and deciding on a transport strategy. Read and follow this documentation when planning your development project.
For practical information on working with the Change and Transport System, see Change and Transport Organizer and Transport Management System.

41. When a program is created and need to be transported to prodn does selection texts always go with it? if not how do you make sure? Can you change the CTS entries? How do you do it?
ANS:-

42. What is the client concept in SAP? What is the meaning of client independent?
ANS:-

43. Are programs client dependent?
ANS:-
Yes.Group of users can access these programs with a client no.

44. Name a few system global variables you can use in ABAP programs?
ANS:-
SY-SUBRC,SY-DBCNT,SY-LILLI,SY-DATUM,SY-UZEIT,SY-UCOMM,SY-TABIX.....
SY-LILLI IS ABSOLUTE NO OF LINES FROM WHICH THE EVENT WAS TRIGGERED.

45. What are internal tables? How do you get the number of lines in an internal table?
How to use a specific number occurs statement?
ANS:-
i)It is a standard data type object which exists only during the runtime of the program.
They are used to perform table calculations on subsets of database tables and for re-organising the contents of database tables according to users need.
ii)using SY-DBCNT.
iii)The number of memory allocations the system need to allocate for the next record population.

46. How do you take care of performance issues in your ABAP programs?
Performance of ABAPs can be improved by minimizing the amount of data to be transferred.
The data set must be transferred through the network to the applications, so reducing the amount OF time and also reduces the network traffic.

Some measures that can be taken are:

- Use views defined in the ABAP/4 DDIC (also has the advantage of better reusability).
- Use field list (SELECT clause) rather than SELECT *.
- Range tables should be avoided (IN operator)
- Avoid nested SELECTS.

i)system tools

ii)field symbols and field groups.
ans:-
Field Symbols : Field symbols are placeholders for existing fields. A Field Symbol does not physically reserve space for a field,but points to a field which is not known until runtime of the program.
eg:- FIELD-SYMBOL [].

Field groups : A field group combines several fields under one name.At runtime,the INSERT command is used to define which data fields are assigned to which field group.
There should always be a HEADER field group that defines how the extracted data will be sorted,the data is sorted by the fields grouped under the HEADER field group.

47. What are datasets?
ANS:-
The sequential files(ON APPLICATION SERVER) are called datasets. They are used for file handling in SAP.

48. How to find the return code of a statement in ABAP programs?
ANS:-
Using function modules.

49. What are interface/conversion programs in SAP?
ANS :
CONVERSION : LEGACY SYSTEM TO FLAT FILE.
INTERFACE : FLAT FILE TO SAP SYSTEM.

Events in Report

An event is a tag that identifies a section of code. The section of code associated with an event name and ends when a next name is encountered.

Some of the events are:

1. Initialization.
2. At Selection-Screen.
3. Start-of-Selection.
4. Top-of-Page.
5. end-of-Page.
6. End-of-Selection.
7. At line Selection
8. At PFn.
9. At User-command.

SAP has a inbuilt program called Driver Program which controls another program in the R/3 System.

DRIVER EVENTS:

Initialization.
At Selection-Screen.
Start-of-selection.
End-of Selection.
USER EVENTS:
At line-Selection
At PFn.

At User-Command.

PROGRAM EVENTS:
Top-of-Page.
End-of-Page.

Example: The IDoc Type ORDERS01

To allow an interference, here is a sample of IDoc type ORDERS01 which is used for purchase
orders and sales orders.

Purchasing and sales orders naturally share the same IDoc type because what is a
purchase order on the sender side will become a sales order on the receiver side.
Other than MATMAS01, the IDoc type ORDERS01 does not reflect the structure of
the underlying RDB entity, neither the one of SD (VA01) nor the one of MM
(ME21). The structure is rather derived from the EDI standards used in the
automobile industry. Unfortunately, this does not make it easier to read.
Note: With transaction WE05 you can monitor, if there are already any IDocs in
your system.

You can call transaction WE30 to display the structure of the IDoc type of the found
IDoc
If this IDoc would have been written to a file, the file content would have looked
similar to this:

ORDERS01 DEVCLNT100 INTERNAL...
...E1EDKA1 ....and here the data
...E1EDKA2 ....and here the data
...E1EDP19 ....and here the data

Program for Outbound IDOC

All IDoc data records are exchanged in a fixed format, regardless of the segment type. The
segment’s true structure is stored in R/3’s repository as a DDic structure of the same name.
The segment info tells the IDoc processor how the current segment data is structured
and should be interpreted. The information, which is usually the only interest, is the
name of the segment EDID4-SEGNAM.

The segment name corresponds to a data dictionary structure with the same name,
which has been created automatically when defining the IDoc segment definition
with transaction WE31 .

For most applications, the remaining information in the segment info can be ignored
as being redundant. Some older, non-SAP-compliant partners may require it. E.g.
the IDoc segment info will also store the unique segment number for systems, which
require numeric segment identification.

To have the segment made up for processing in an ABAP, it is usually wise to move
the segment data into a structure, which matches the segment definition.
For a segment of type e1maram the following coding is commonly used:


TABLES: e1maram.
. . .
MOVE edidd-sdata TO e1maram.


Then you can access the fields of the IDoc segment EDIDD-SDATA as fields of the
structure e1maram .


WRITE: e1maram-matnr.


The following coding sample, shows how you may read a MATMAS IDoc and
extract the data for the MARA and MARC segments to some internal variables and
tables.


DATA: xmara LIKE e1maram.
DATA: tmarc AS STANDARD TABLE OF e1marcm
WITH HEADER LINE.
LOOP AT edidd.
CASE edidd-segnam.
WHEN 'E1MARAM'.
MOVE edidd-sdata TO xmara.
WHEN 'E1MARCM'.
MOVE edidd-sdata TO tmarc.
APPEND tmarc.
ENDCASE.
ENDLOOP.
now do something with xmara and tmarc.

Basic Configuration in IDOC

Define a new internal RFC destination INTERNAL
Explore both the transactions WEDI and SALE and adjust the settings as necessary
Use transaction BALE to generate an arbitrary IDoc


You can access most of the transactions used in the example below in the menu
WEDI and SALE.

We will assume, that we want to send material master data from the current system
to a remote system. To simulate this scenario we do not need to have a second
system. With a little trick, we can set up the system to send an IDoc back to the
sending client.

We will set up the system to use an RFC call to itself. Therefore we need to define
an RFC remote destination, which points back to our own client. There is a virtual
RFC destination called NONE which always refers to the calling client.
RFC destinations are installed with the transaction SM59. Create a new R/3
destination of type "L" (Logical destination) with the name INTERNAL and the
destination NONE.

Note: Do not use RFC type internal. Although you could create them manually, they
are reserved for being automatically generated. However, there is the internal
connection "NONE" or "BACK" which would do the same job as the destination we
are creating now.

The next step is defining a data port, which is referenced by the IDoc sending
mechanism to send the IDoc through. Declaring the port is done by transaction
WE21.
We will now declare an ALE connection from our client to the partner INTERNAL.
ALE uses IDocs to send data to a remote system. There is a convenient transaction
to send material master data as IDocs via the ALE.

The set up is done in transaction SALE. You first create a new ALE model, to avoid
interfering with eventual existing definitions. Then you simply add the IDoc
message MATMAS as a valid path from your client to INTERNAL.
In order to send the IDoc, you call the transaction BALE and choose the distribution
of material master data (BD10). Choose a material, enter INTERNAL as receiver
and go.

To see, which IDocs have been sent, you can use the transaction WE05. If you did
everything as described above, you will find the IDocs with an error status of 29,
meaning that there is no valid partner profile. This is true, because we have not
defined one yet.

Tuesday, May 6, 2008

Sample ABAP Program to Upload table using new function GUI_UPLOAD

*& Report ZUPLOAD *
*& *
*&---------------------------------------------------------------------*
*& This program uses the new function GUI_UPLOAD *
*& Input must be TAB delimited with a blank column at the start *
*& to allow for MANDT. *
*& To use this program for any Database Table replace ZTEST with *
*& new table name. *
*&---------------------------------------------------------------------*
*& AUTHOR: Sheila Titchener - abap at iconet-ltd.co.uk *
*& Date: February 2004 *
*&---------------------------------------------------------------------*

REPORT zupload MESSAGE-ID bd.

DATA: w_tab TYPE ZTEST.
DATA: i_tab TYPE STANDARD TABLE OF ZTEST.

DATA: v_subrc(2),
v_recswritten(6).

PARAMETERS: p_file(80)
DEFAULT 'C:\Temp\ZTEST.TXT'.

DATA: filename TYPE string,
w_ans(1) TYPE c.

filename = p_file.


CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = 'Upload Confirmation'
* DIAGNOSE_OBJECT = ' '
text_question = p_file
text_button_1 = 'Yes'(001)
* ICON_BUTTON_1 = ' '
text_button_2 = 'No'(002)
* ICON_BUTTON_2 = ' '
default_button = '2'
* DISPLAY_CANCEL_BUTTON = 'X'
* USERDEFINED_F1_HELP = ' '
* START_COLUMN = 25
* START_ROW = 6
* POPUP_TYPE =
* IV_QUICKINFO_BUTTON_1 = ' '
* IV_QUICKINFO_BUTTON_2 = ' '
IMPORTING
answer = w_ans
* TABLES
* PARAMETER =
* EXCEPTIONS
* TEXT_NOT_FOUND = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


CHECK w_ans = 1.


CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = filename
* FILETYPE = 'ASC
has_field_separator = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
data_tab = i_tab
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.

* SYST FIELDS ARE NOT SET BY THIS FUNCTION SO DISPLAY THE ERROR CODE *

IF sy-subrc <> 0.
v_subrc = sy-subrc.
MESSAGE e899 WITH 'File Open Error' v_subrc.
ENDIF.


INSERT ZTEST FROM TABLE i_tab.

COMMIT WORK AND WAIT.

MESSAGE i899 WITH sy-dbcnt 'Records Written to ZTEST'.

Sample ABAP Program for Submitting report with selection table

REPORT submit_with_selection_table.
TABLES QMSM.
* Work area for internal table IQMSM
DATA: BEGIN OF WQMSM,
QMNUM LIKE QMSM-QMNUM,
MNGRP LIKE QMSM-MNGRP,
MNCOD LIKE QMSM-MNCOD,
ZZSTAT LIKE QMSM-ZZSTAT,
END OF WQMSM.

* WORK Area for internal table iseltab.
DATA: WSELTAB LIKE RSPARAMS.
*----------------------------------------------------------------------*
* Internal tables
*----------------------------------------------------------------------*
* selection table to pass to RIQMEL30
DATA: ISELTAB LIKE TABLE OF WSELTAB.
* Table of notification numbers selected - will be passed to riqmel30
DATA: IQMSM LIKE TABLE OF WQMSM.
*----------------------------------------------------------------------*
START-OF-SELECTION.
*----------------------------------------------------------------------*
REFRESH IQMSM.
SELECT QMNUM MNGRP MNCOD ZZSTAT
FROM QMSM INTO CORRESPONDING FIELDS OF TABLE IQMSM
WHERE MNGRP = 'ACTION'
AND MNCOD = 'CALL'
and ( zzqmart = 'ZE' or zzqmart = 'ZI' )
AND ZZSTAT = ' '.

* create selection table entries for field QMART

WSELTAB-SELNAME = 'QMART'.
WSELTAB-KIND = 'S'.
WSELTAB-SIGN = 'I'.
WSELTAB-OPTION = 'EQ'.
WSELTAB-LOW = 'ZE'.
APPEND WSELTAB TO ISELTAB.
WSELTAB-LOW = 'ZI'.
APPEND WSELTAB TO ISELTAB.

* Create selection table entries for QMNUM

CLEAR WSELTAB.
WSELTAB-SELNAME = 'QMNUM'.
WSELTAB-KIND = 'S'.
WSELTAB-SIGN = 'I'.
WSELTAB-OPTION = 'EQ'.
LOOP AT IQMSM INTO WQMSM.
WSELTAB-LOW = WQMSM-QMNUM.
APPEND WSELTAB TO ISELTAB.
ENDLOOP
*
* SUBMIT program with parameters passed in table ISELTAB
* Other parameters passed explicitly

SUBMIT RIQMEL30 WITH SELECTION-TABLE ISELTAB
WITH MNGRP = 'ACTION'
WITH MNCOD = 'CALL'
WITH DATUV = '00000000'
WITH DATUB = '99991231'
WITH STAI1 = 'TSRL'.

Sample ABAP Program for Submitting report with selection table

REPORT submit_with_selection_table.
TABLES QMSM.
* Work area for internal table IQMSM
DATA: BEGIN OF WQMSM,
QMNUM LIKE QMSM-QMNUM,
MNGRP LIKE QMSM-MNGRP,
MNCOD LIKE QMSM-MNCOD,
ZZSTAT LIKE QMSM-ZZSTAT,
END OF WQMSM.

* WORK Area for internal table iseltab.
DATA: WSELTAB LIKE RSPARAMS.
*----------------------------------------------------------------------*
* Internal tables
*----------------------------------------------------------------------*
* selection table to pass to RIQMEL30
DATA: ISELTAB LIKE TABLE OF WSELTAB.
* Table of notification numbers selected - will be passed to riqmel30
DATA: IQMSM LIKE TABLE OF WQMSM.
*----------------------------------------------------------------------*
START-OF-SELECTION.
*----------------------------------------------------------------------*
REFRESH IQMSM.
SELECT QMNUM MNGRP MNCOD ZZSTAT
FROM QMSM INTO CORRESPONDING FIELDS OF TABLE IQMSM
WHERE MNGRP = 'ACTION'
AND MNCOD = 'CALL'
and ( zzqmart = 'ZE' or zzqmart = 'ZI' )
AND ZZSTAT = ' '.

* create selection table entries for field QMART

WSELTAB-SELNAME = 'QMART'.
WSELTAB-KIND = 'S'.
WSELTAB-SIGN = 'I'.
WSELTAB-OPTION = 'EQ'.
WSELTAB-LOW = 'ZE'.
APPEND WSELTAB TO ISELTAB.
WSELTAB-LOW = 'ZI'.
APPEND WSELTAB TO ISELTAB.

* Create selection table entries for QMNUM

CLEAR WSELTAB.
WSELTAB-SELNAME = 'QMNUM'.
WSELTAB-KIND = 'S'.
WSELTAB-SIGN = 'I'.
WSELTAB-OPTION = 'EQ'.
LOOP AT IQMSM INTO WQMSM.
WSELTAB-LOW = WQMSM-QMNUM.
APPEND WSELTAB TO ISELTAB.
ENDLOOP
*
* SUBMIT program with parameters passed in table ISELTAB
* Other parameters passed explicitly

SUBMIT RIQMEL30 WITH SELECTION-TABLE ISELTAB
WITH MNGRP = 'ACTION'
WITH MNCOD = 'CALL'
WITH DATUV = '00000000'
WITH DATUB = '99991231'
WITH STAI1 = 'TSRL'.

Sample ABAP Program for Sending SAP Mail

*&---------------------------------------------------------------------*
*& Form SEND_MAIL
*&---------------------------------------------------------------------*
* send email to current user *
*----------------------------------------------------------------------*
FORM SEND_MAIL.

* PARAMETERS FOR SO_NEW_DOCUMENT_SEND_API1
DATA: W_OBJECT_ID LIKE SOODK,
W_SONV_FLAG LIKE SONV-FLAG.
DATA: T_RECEIVERS LIKE SOMLRECI1 OCCURS 1 WITH HEADER LINE,
W_OBJECT_CONTENT LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE,
W_DOC_DATA LIKE SODOCCHGI1 OCCURS 0 WITH HEADER LINE.
*
DATA: W_DATE(10).
CLEAR T_RECEIVERS.
T_RECEIVERS-RECEIVER = SY-UNAME.
T_RECEIVERS-REC_TYPE = 'B'.
T_RECEIVERS-EXPRESS = ' '.
APPEND T_RECEIVERS.

W_DOC_DATA-OBJ_DESCR = 'Change Expiry date'.


* Delivery NO
CONCATENATE 'Delivery No' M_VMVMA-VBELN INTO W_OBJECT_CONTENT
SEPARATED BY ' '.
APPEND W_OBJECT_CONTENT.
* material Batch
CONCATENATE 'Material' ZGREC-MATNR 'Batch' ZGREC-CHARG
INTO W_OBJECT_CONTENT SEPARATED BY ' '.
APPEND W_OBJECT_CONTENT.
* Expiry date
WRITE B_VFDAT TO W_DATE DD/MM/YYYY.
CONCATENATE 'Change expiry date to' W_DATE
INTO W_OBJECT_CONTENT SEPARATED BY ' '.
APPEND W_OBJECT_CONTENT.
*
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = W_DOC_DATA
PUT_IN_OUTBOX = ' '
TABLES
OBJECT_CONTENT = W_OBJECT_CONTENT
RECEIVERS = T_RECEIVERS
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
DOCUMENT_TYPE_NOT_EXIST = 3
OPERATION_NO_AUTHORIZATION = 4
PARAMETER_ERROR = 5
X_ERROR = 6
ENQUEUE_ERROR = 7
OTHERS = 8.
ENDFORM. " SEND_MAIL

Sample ABAP Program for Search Layout sets for given String

REPORT Ysearchl LINE-SIZE 132.

************************************************************************
*
* Program : Ysearchl
* Authors : Chris Harrop (chris.harrop@bigfoot.com)
* Date : March 1999
* Purpose : Searches all Y and Z layout sets for a given string
*
************************************************************************
*
* maintenance history
*
* date author purpose
*
************************************************************************

TABLES: STXL.

PARAMETERS:
STRING(128).

DATA: BEGIN OF TLINETAB OCCURS 0.
INCLUDE STRUCTURE TLINE.
DATA: END OF TLINETAB,
SUBRC LIKE SY-SUBRC.

SELECT TDNAME FROM STXL INTO (STXL-TDNAME)
WHERE TDOBJECT = 'FORM' AND ( TDNAME LIKE 'Y%' OR TDNAME LIKE 'Z%' )
AND TDID = 'TXT'.

PERFORM DISPLAY_STATUS_TEXT USING STXL-TDNAME.

REFRESH TLINETAB.
PERFORM GET_TEXT_TABLE
TABLES TLINETAB
USING 'FORM' 'TXT' STXL-TDNAME
CHANGING SUBRC.
LOOP AT TLINETAB.
IF TLINETAB-TDLINE CS STRING.
WRITE : / STXL-TDNAME, TLINETAB-TDLINE.
ENDIF.
ENDLOOP.
ENDSELECT.


* Display a message on the status bar
FORM DISPLAY_STATUS_TEXT USING VALUE(TEXT) TYPE C.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
TEXT = TEXT.
ENDFORM.
*
* Get the long texts for the object
*
FORM GET_TEXT_TABLE TABLES TLINETAB
USING VALUE(TDOBJECT) LIKE THEAD-TDOBJECT
VALUE(ID) LIKE THEAD-TDID
VALUE(TDNAME) LIKE THEAD-TDNAME
CHANGING SUBRC LIKE SY-SUBRC.

DATA: BEGIN OF XTHEAD OCCURS 0.
INCLUDE STRUCTURE THEAD.
DATA: END OF XTHEAD.

DATA: EINTRAEGE LIKE SY-TFILL.

DATA XTDNAME LIKE THEAD-TDNAME.
REFRESH XTHEAD.
CLEAR XTDNAME.
XTDNAME = TDNAME.

CALL FUNCTION 'SELECT_TEXT'
EXPORTING
ID = ID
LANGUAGE = SY-LANGU
NAME = TDNAME
OBJECT = TDOBJECT
IMPORTING
ENTRIES = EINTRAEGE
TABLES
SELECTIONS = XTHEAD.

REFRESH TLINETAB.

CALL FUNCTION 'READ_TEXT'
EXPORTING
ID = ID
LANGUAGE = SY-LANGU
NAME = TDNAME
OBJECT = TDOBJECT
IMPORTING
HEADER = XTHEAD
TABLES
LINES = TLINETAB
EXCEPTIONS
ID = 01
LANGUAGE = 02
NAME = 03
NOT_FOUND = 04
OBJECT = 05
REFERENCE_CHECK = 06.
SUBRC = SY-SUBRC.
ENDFORM. " FILL_ITEM_TEXT

Sample ABAP Program for Sapscript PerForm Module

REPORT YLSD999A.
DATA W_LENGTH TYPE I.
* GENERAL PURPOSE SUBROUTINES FOR CALLING FROM SAPSCRIPTS
*-----------------------------------------------------------------------
*----------------------------------------------------------------------
FORM DISPLAY_POUND TABLES IN_TAB STRUCTURE ITCSY
OUT_TAB STRUCTURE ITCSY.
DATA: COUNT TYPE P VALUE 16.
DATA: W_VALUE(17) TYPE C. "defined as 7 chars to remove pence
DATA: W_CHAR TYPE C.
DATA: W_DUMMY TYPE C.
DATA: W_CURR(3) TYPE C.
* Get first parameter in input table.
READ TABLE IN_TAB INDEX 1.
WRITE IN_TAB-VALUE TO W_VALUE .
* get second parameter in input table
READ TABLE IN_TAB INDEX 2.
MOVE IN_TAB-VALUE TO W_CURR.
IF W_CURR = 'GBP'.
W_CURR = '£'.
ENDIF.
W_LENGTH = STRLEN( W_CURR ).
* look for first space starting at right.
WHILE COUNT > -1.
W_CHAR = W_VALUE+COUNT(1).
* W_CHAR = IN_TAB-VALUE+COUNT(1).
IF W_CHAR = ' '.
COUNT = COUNT - W_LENGTH + 1.
W_VALUE+COUNT(W_LENGTH) = W_CURR.
COUNT = -1.
ELSE.
* W_VALUE+COUNT(1) = W_CHAR.
COUNT = COUNT - 1.
ENDIF.
ENDWHILE.
* read only parameter in output table
READ TABLE OUT_TAB INDEX 1.
OUT_TAB-VALUE = W_VALUE.
MODIFY OUT_TAB INDEX SY-TABIX.
ENDFORM.

Sample ABAP Program for Create IDOC

FUNCTION Y_ISSUE_ROCO_IDOC.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(I_MODE) LIKE Z1ROCO-ZMODE
*" VALUE(I_ROUTE) LIKE Z1ROCO-ROUTE
*" VALUE(I_CUT_OFF) LIKE Z1ROCO-CUT_OFF OPTIONAL
*" VALUE(I_BEZEI) LIKE Z1ROCO-BEZEI OPTIONAL
*" VALUE(I_TROUTE_MON) LIKE Z1ROCO-TROUTE_MON OPTIONAL
*" VALUE(I_TROUTE_TUE) LIKE Z1ROCO-TROUTE_TUE OPTIONAL
*" VALUE(I_TROUTE_WED) LIKE Z1ROCO-TROUTE_WED OPTIONAL
*" VALUE(I_TROUTE_THU) LIKE Z1ROCO-TROUTE_THU OPTIONAL
*" VALUE(I_TROUTE_FRI) LIKE Z1ROCO-TROUTE_FRI OPTIONAL
*" VALUE(I_TROUTE_SAT) LIKE Z1ROCO-TROUTE_SAT OPTIONAL
*" VALUE(I_TROUTE_SUN) LIKE Z1ROCO-TROUTE_SUN OPTIONAL
*" VALUE(I_PGI_IND) LIKE Z1ROCO-PGI_IND OPTIONAL
*"----------------------------------------------------------------------

DATA: W_EDIDC LIKE EDIDC OCCURS 5 WITH HEADER LINE,
W_Z1ROCO LIKE EDIDC,
L_EDIDC LIKE EDIDC,
L_SEND_FLAG,
W_SDATA LIKE EDIDD-SDATA.
DATA: T_BDI_MODEL LIKE BDI_MODEL OCCURS 0 WITH HEADER LINE.
DATA: T_EDIDC LIKE EDIDC OCCURS 0 WITH HEADER LINE.
DATA: T_EDIDD LIKE EDIDD OCCURS 0 WITH HEADER LINE.

*- Call function module to determine if message is to be distributed

CALL FUNCTION 'ALE_MODEL_DETERMINE_IF_TO_SEND'
EXPORTING
MESSAGE_TYPE = 'ZZROCO'
IMPORTING
IDOC_MUST_BE_SENT = L_SEND_FLAG
EXCEPTIONS
OWN_SYSTEM_NOT_DEFINED = 1
OTHERS = 2.

*- Determine recipient systems

CALL FUNCTION 'ALE_MODEL_INFO_GET'
EXPORTING
MESSAGE_TYPE = 'ZZROCO'
* RECEIVING_SYSTEM = ' '
* SENDING_SYSTEM = ' '
* VALIDDATE = SY-DATUM
TABLES
MODEL_DATA = T_BDI_MODEL
EXCEPTIONS
NO_MODEL_INFO_FOUND = 1
OWN_SYSTEM_NOT_DEFINED = 2
OTHERS = 3.

* 3.2
*Call function 'L_IDOC_HEADER_CREATE'
* exporting
* i_mestyp = 'ZZROCO'
* i_mescod = ' '
* i_idoctp = 'ZSDROCO'
* i_rcvprn = 'Z_WMS'
* exceptions
* others = 1.
* 3.3
MOVE I_MODE TO Z1ROCO-ZMODE.
MOVE I_ROUTE TO Z1ROCO-ROUTE.
MOVE I_CUT_OFF TO Z1ROCO-CUT_OFF.
MOVE I_BEZEI TO Z1ROCO-BEZEI.
MOVE I_TROUTE_MON TO Z1ROCO-TROUTE_MON.
MOVE I_TROUTE_TUE TO Z1ROCO-TROUTE_TUE.
MOVE I_TROUTE_WED TO Z1ROCO-TROUTE_WED.
MOVE I_TROUTE_THU TO Z1ROCO-TROUTE_THU.
MOVE I_TROUTE_FRI TO Z1ROCO-TROUTE_FRI.
MOVE I_TROUTE_SAT TO Z1ROCO-TROUTE_SAT.
MOVE I_TROUTE_SUN TO Z1ROCO-TROUTE_SUN.
MOVE I_PGI_IND TO Z1ROCO-PGI_IND.

MOVE Z1ROCO TO: W_SDATA, T_EDIDD-SDATA.
MOVE 'Z1ROCO' TO T_EDIDD-SEGNAM.
APPEND T_EDIDD.

*call function 'L_IDOC_SEGMENT_CREATE'
* exporting
* i_segnam = 'Z1ROCO'
* i_sdata = w_sdata
* exceptions
* others = 1.

*call function 'L_IDOC_SEND'
* tables
* t_comm_idoc = w_edidc
* exceptions
* error_distribute_idoc = 1
* others = 2.

READ TABLE T_BDI_MODEL INDEX 1. " maximum 1 recipient
MOVE 'ZZROCO' TO L_EDIDC-MESTYP.
MOVE 'ZSDROCO' TO L_EDIDC-IDOCTP.
MOVE 'LS' TO L_EDIDC-RCVPRT.
MOVE T_BDI_MODEL-RCVSYSTEM TO L_EDIDC-RCVPRN.

*- Distribute the iDoc

CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE' IN UPDATE TASK
EXPORTING
MASTER_IDOC_CONTROL = L_EDIDC
TABLES
COMMUNICATION_IDOC_CONTROL = W_EDIDC
MASTER_IDOC_DATA = T_EDIDD
EXCEPTIONS
ERROR_IN_IDOC_CONTROL = 01
ERROR_WRITING_IDOC_STATUS = 02
ERROR_IN_IDOC_DATA = 03
SENDING_LOGICAL_SYSTEM_UNKNOWN = 04.

COMMIT WORK.
*E_RESPONSE = SY-SUBRC.
ENDFUNCTION.

Sample ABAP Program for Output file to application server then send mail with Download details

*&---------------------------------------------------------------------*
*& Form download_to_application
*& download to application server, attach to mail and send to user
*&---------------------------------------------------------------------*
FORM download_to_application.

data: l_title type SO_OBJ_DES.

l_title = sy-repid.

CALL FUNCTION 'ZSEND_REPORT_MAIL'
EXPORTING
i_title = l_title
tables
it_text_data = it_download
EXCEPTIONS
INVALID_USER = 1
MAIL_SEND_ERROR = 2
OPEN_FILE = 3
FILE_GET_NAME = 4
OTHERS = 5
.
IF sy-subrc <> 0.
MESSAGE e368(00) with 'ZSEND_REPORT_MAIL fail -'
sy-subrc.
ENDIF.

ENDFORM. " download_to_application
===============================================================================

FUNCTION Zsend_report_mail.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(I_UNAME) TYPE SYUNAME DEFAULT SY-UNAME
*" REFERENCE(I_TITLE) TYPE SO_OBJ_DES
*" TABLES
*" IT_TEXT_DATA
*" EXCEPTIONS
*" INVALID_USER
*" MAIL_SEND_ERROR
*" OPEN_FILE
*" FILE_GET_NAME
*"----------------------------------------------------------------------

* This function is used to store a file (report result) on the file
* system of the application server and to send an "active" SAP mail
* to the user.
* The "active" SAP mail calls function ZMAIL_DOWNLOAD to
* download the file to the presentation server.

DATA: ls_document_data LIKE sodocchgi1.
DATA: lt_object_para LIKE soparai1 OCCURS 5 WITH HEADER LINE.
DATA: lt_object_parb LIKE soparbi1 OCCURS 0 WITH HEADER LINE.
DATA: lt_object_cont LIKE solisti1 OCCURS 0 WITH HEADER LINE.
DATA: lt_reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE.

DATA: l_filename(200) TYPE c.

CHECK NOT it_text_data[] IS INITIAL.

* terminate if name not suitable.
IF i_uname IS INITIAL OR
i_uname = 'WF-BATCH' OR
i_uname = 'DDIC' OR
i_uname = 'SAP*'.
RAISE invalid_user.
ENDIF.

* get physical file from logical filename( optional)

CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
logical_filename = 'MAILFILE'
parameter_1 = sy-uname
parameter_2 = sy-datum
parameter_3 = sy-uzeit
* USE_PRESENTATION_SERVER = ' '
* WITH_FILE_EXTENSION = ' '
* USE_BUFFER = ' '
* ELEMINATE_BLANKS = 'X'
IMPORTING
* EMERGENCY_FLAG =
* FILE_FORMAT =
file_name = l_filename
EXCEPTIONS
file_not_found = 1
OTHERS = 2.
IF sy-subrc NE 0.
RAISE file_get_name.
ENDIF.

* save file
OPEN DATASET l_filename FOR OUTPUT IN TEXT MODE.
IF sy-subrc NE 0.
RAISE open_file.
ENDIF.
LOOP AT it_text_data. " into l_text_data.
TRANSFER it_text_data TO l_filename.
ENDLOOP.
CLOSE DATASET l_filename.

* SAP mail header (execute function)
CLEAR: ls_document_data.
ls_document_data-obj_descr = i_title.
ls_document_data-proc_type = 'F'. " function call
ls_document_data-proc_name = 'ZMAIL_DOWNLOAD'.
ls_document_data-no_change = 'X'.
* SAP mail receiver
REFRESH lt_reclist.
CLEAR lt_reclist.
lt_reclist-receiver = i_uname.
lt_reclist-rec_type = 'B'.
* gt_reclist-express = 'X'.
APPEND lt_reclist.
* message text
REFRESH lt_object_cont.
CLEAR lt_object_cont.
lt_object_cont-line =
'The result of the following report has been saved.'.
APPEND lt_object_cont.
* report name
lt_object_cont-line = 'Report:'.
lt_object_cont-line+15 = sy-cprog.
CONDENSE lt_object_cont-line.
APPEND lt_object_cont.
* date & time
lt_object_cont-line = 'Date/Time:'.
WRITE sy-datum TO lt_object_cont-line+15.
WRITE sy-uzeit TO lt_object_cont-line+27.
CONDENSE lt_object_cont-line.
APPEND lt_object_cont.
*
lt_object_cont-line =
'Please execute (Ctrl-F6) this mail to download the result.'.
APPEND lt_object_cont.

* mail parameters
REFRESH lt_object_parb.
CLEAR lt_object_parb.
lt_object_parb-name = 'FUNCTION'. " mail identifier
lt_object_parb-value = 'FILE_DOWNLOAD'. " mail identifier
APPEND lt_object_parb.
lt_object_parb-name = 'FILENAME'.
lt_object_parb-value = l_filename.
APPEND lt_object_parb.

*call SAPOffice API
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = ls_document_data
TABLES
object_content = lt_object_cont
object_para = lt_object_para
object_parb = lt_object_parb
receivers = lt_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
IF sy-subrc NE 0.
RAISE mail_send_error.
ENDIF.

ENDFUNCTION.
===========================================================================
FUNCTION zmail_download.
*"----------------------------------------------------------------------
*"*"Local interface:
*" TABLES
*" MSGDIAL STRUCTURE SOPARBI1
*"----------------------------------------------------------------------
* This function is called in a SAP mail to download a file from the
* application server file system.
* Function ZSEND_REPORT_MAIL is used to save report result
* on application server file system and to send SAP mail to user.
* Based on UK COM solution by Damian Norton.

DATA: ls_msgdial TYPE soparbi1.
DATA: l_filename TYPE filep.
* DATA: l_filename_local TYPE filep.
DATA: l_operation(30) TYPE c.
DATA: BEGIN OF lt_text_data OCCURS 10,
line(2000),
END OF lt_text_data.

* read parameters
LOOP AT msgdial INTO ls_msgdial.
CASE ls_msgdial-name.
WHEN 'FUNCTION'.
l_operation = ls_msgdial-value.
WHEN 'FILENAME'.
l_filename = ls_msgdial-value.
WHEN OTHERS.
MESSAGE e368(00) WITH 'Invalid parameter' ls_msgdial-name.
ENDCASE. " ls_msgdial-name
ENDLOOP. " msgdial

IF l_operation = 'FILE_DOWNLOAD'.
* check, whether file exists on presentation server
REFRESH lt_text_data.
OPEN DATASET l_filename FOR INPUT IN TEXT MODE.
IF sy-subrc = 0.
DO.
READ DATASET l_filename INTO lt_text_data-line.
IF sy-subrc = 0.
APPEND lt_text_data.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET l_filename.
* request filename on presentation server - or GUI_DOWNLOAD??
CALL FUNCTION 'DOWNLOAD'
TABLES
data_tab = lt_text_data
EXCEPTIONS
invalid_filesize = 1
invalid_table_width = 2
invalid_type = 3
no_batch = 4
unknown_error = 5
gui_refuse_filetransfer = 6
customer_error = 7
OTHERS = 8.
IF sy-subrc NE 0.
MESSAGE e688(00) WITH 'File download error' sy-subrc.
ENDIF.
ELSE.
MESSAGE e398(00) WITH 'File open error' l_filename.
ENDIF. " sy-subrc = 0 (OPEN DATASET)
ENDIF. " l_operation = 'FILE_DOWNLOAD'

ENDFUNCTION.

Blog Archive