Sie sind auf Seite 1von 216

Sample Test Questions on ABAP Programming

# 1 . What are the 2 boxes in your system for coding for Abap and their logins?
Development System & IDES/Sandbox
# 2. If I get a problem on a report in Production server how can I modify the report.
If the problem in production server we have to alter the program in Developemnt Client and transport it to
QA client Test it throughly and then Transport it to Production.
# 3. Tell me about Tokens.
Tokens are Issues sent by the Client to us.
#4 .How to Fix the bugs and where you will do those things.
It Actuall Depends what kind of bugs they asked about:
If it is a problem in Program, then we alter them in the SE38 (Develpment) and transport it after testing to
Prd Server.
#5. What is a sandboxes.
SAND BOX is nothing but a test client other than Develpment Client or QA.
#6.How to conncet the from ur office to clinet in US.
It will be configured by the BASIS guys..
In the sap logon pad they will enter the application server id and Routing String and the SERver type in the
Sytem Number....
with that we will connect
#7.Tell me about VPN and the connections.
Its a another way to connect to other PC. its a 3rd party utility....
#8. How to login ur system.
Thru SAP Logon enter the client number ,user id & password.
#9 .What is the purpose of SE14.
Database Utility to perform table maintenance such as deleting the table or adjusting the table when there is
a structure change.
#10 .What is the purpose of SM30.
SM30 is a table Maintanance for the Ztable Created by us.

#11.In Data dictionary in the table creation,What is the purpose of Technical settings.
To identify the Size of the Table Created and to Set whether buffering needs to be done for the table or not.
#12. What is the purpose of buffering in technical settings and for what type of tables are using
buffering.
It will reduce the Network tarffic but disadvantage is it will not update the Server back immediately.
#13. In reporting tell me all the events in a sequentail order.
- Initialization.
- At Selection-Screen
- Start-of-Selection.
- Top-of-Page.
- At Pfn.
- End-of-Page.
- End-of-Selection.
ABAP Self Test Q & A
1) Authorization Objects
( this question has more than 1 answer )
a) Stored in User Master
b) Defines fields for a complex authority check
c) Grouped together in profiles
d) Covers up to 10 fields
e) Consists of up to 10 authorization objects
2) Authorization Checking
( this question has more than 1 answer )
a) performed with SELECT statement
b) performed with AUTHORITY-CHECK
c) determines if user has authority in master record
d) always refers to authorization profile
e) system admin defines which authorization checks are executed
3) Authorization
( this question has more than 1 answer )
a) contains value for field of an authorization object
b) defines fields for a complex authorization object
c) can be grouped together in profiles
d) always refer to a particular authorization
e) authorizations and profiles are stored in user master record
4) Using SM35 in which case does the system check authorization:
( this question has more than 1 answer )
a) always
b) process / foreground
c) display errors only
d) process / background
e) system decides based on profile
5) Search Helps:
( this question has more than 1 answer )
a) called at POV
b) controls how fixed values are displayed when F4 is pressed
c) allow different views of info when help is required

d) object stored in data dictionary


e) field names starting with H_
6) Append Structures
( this question has more than 1 answer )
a) append to table without modifying table itself
b) can be assigned to several tables
c) same as substructure
d) use like any other structure
e) you must convert table once append is added
7) Check table
( this question has more than 1 answer )
a) value table assigned to a domain
b) internal table whose contents are used to check input values
c) table assigned to 1 or more fields if a FK (foreign key) table for checking input values
d) table for which a FK is defined
e) table to which a FK refers
8) Modify SAP objects:
( this question has more than 1 answer )
a) R/3 prevents modifications be user id DDIC and SAP*
b) Objects can be changed with registration
c) Register objects in OSS
d) Carry out modification without registration
e) Adjust modified object in upgrade
9) Activities required at upgrade when applying hot pack:
( this question has more than 1 answer )
a) adjust modified object
b) everything is automatic
c) release correction before update
d) abap dictionary tables, data elements and domains are adjusted during upgrade
e) abap dictionary objects not handled seperately
10) SELECT-OPTIONS COUNTRY FOR LFA1-LAND1:
What will internal table be?
a) LAND1
b) LFA1
c) COUNTRY
d) LFA1-LAND1
11) In program A function module F is called from function group G for the first time. Which one is
correct:
a) coding of entire function group G is loaded in the roll area
b) global data from A can be accessed in F
c) A and F have common work areas for dictionary table
d) Function module F is called in a separate internal session
e) Function module F can not call any sessions
12) from transaction A you call transaction B with LEAVE TO TRANSACTION B:
a) internal system session opened for B
b) LEAVE can be used to return from B to A
c) Data from A can be accessed in B
d) A can pass data to B with export
e) A can pass data using SET
13) What is a SAP LUW:
a) a modularised unit in ABAP programs
b) all the updates for 1 SAP transaction

c) a logical grouping of database updates that should all be performed at the same time
d) the section of program code from setting a lock until it is released
e) all actions between first and last database update in transaction
14) Why do update functions have attributes of either START NOW (v1) or START DELAYED(V2):
a) define whether update task triggered immediately
b) combine synchronous and asynchronous updates
c) assign different priorities
d) take different speed of servers into account
e) enable reaction to termination n V1
15) Relationship between SAP transactions and database transactions:
a) each SAP corresponds to one database
b) update requests of one SAP transaction are distributed amongst several database transactions
c) one database group change request of several SAP
d) database transaction is an internal system representation of SAP transactions
Answers:
1) b, c, d
2) b, d
3) a, c
4) b, c, d
5) a, c, d
6) a, d
7) a, c, e
8) b, c, e
9) a, c, d
10) c
11) a
12) a, d, e
13) c
14) c
15) b
ABAP Objective Questions
By: Rajendra Rai (raaz.rai.sap@gmail.com) SAP ABAP Consultant
1 Full Buffering would be appropriate for
A. Transaction Tables
B. Small Static tables
C. Internal Tables
D. Tables with generic Keys
2 What is the basic object of data Dictionary
A. Domains
B. Documentation
C. Data Models
D. Dynpro
3 Search help can not be attach to:
A. Domain
B. field of a table
C. check table
D. Type
4 Sub query usually more efficient because:
A. data is filtered in the database

B. data is filtered on the network


C. data is filtered in the sapgui
D. data is filtered at the application server
5 It is better to buffer a table when
A. When a table is read infrequently
B. When a table is linked to check tables
C. When a table is read frequently and the data seldom changes
D. When a single record is to be picked up
6 In Inner and outter join
A. buffers are always used
B. Choice of buffer can be made to use
C. buffers are always bypassed
D. None of above
7 What is invalid attribute of a domain
A. Type
B. Fixed values
C. Length
D. Header
8 Data element is an example of
A. Physical Definition
B. Business Object
C. Semantic Domain
D. Technical Domain
9 What is true
A. A view contains data
B. Views can be buffered
C. Views can not be buffered
D. None of above
10 Command flushes the database buffers
A. $TAB
B. $RESET
C. $INIT
D. $FREE
11 How many lists can exist in parallel in an interactive reporting?
A. An Interactive report can have 1 basic list and up to 20 Secondary lists.
B. An Interactive report can have 1 basic list and up to 19 Secondary lists.
C. An Interactive report can have 1 basic list and up to 19 Secondary lists.
D. An Interactive report can have 1 basic list and up to 21 Secondary lists.
12. What are the check tables and value tables? (Multiple Answer)
A. Check table will be at field level checking.
B. Value table will be at domain level checking
C Value table will be at field level checking
D. Check table will be at domain level checking.
13.What are presentation and application servers in SAP? (Multiple Answer)
A. Application server is actually a program named Sapgui.exe. It is usually installed On a users workstation.
B. Application server is a set of executables that collectively interpret the ABAP/4 Programs and manage the
input & output for them.
C. Presentation server is actually a program named Sapgui.exe. It is usually installed On a users
workstation.

D. Presentation server is a set of executables that collectively interpret the ABAP/4 Programs and manage
the input & output for them.
14.What is the difference between Synchronous and Asynchronous updates? (Multiple Answer)
A. In synchronous processing, the program waits: control returns to the program only when the task has
been completed.
B. In asynchronous processing, the program does not wait: the system returns control after merely logging
the request for execution.
C. In asynchronous processing, the program waits: control returns to the program only when the task has
been completed.
D. In synchronous processing, the program does not wait: the system returns control after merely logging
the request for execution.
15.What are the main events an interactive report have? (Multiple Answer)
A. Top-of-page during line selection.
B. At line-selection.
C. At user-command.
D. AT New
16.How many types of tables exist in data dictionary? (Multiple Answer)
A. Transparent tables
B. Internal Table
C. Pool tables
D. Hash Table
E. Cluster tables
F. Master Data Table
17. What is the difference between UPLOAD and WS_UPLOAD? (Multiple Answer)
A. WS_UPLOAD - File transfer with dialog from presentation server file to internal table. Data which is
available in a file on the presentation server is transferred in an internal table. ASCII & Binary files can be
transferred.
B. UPLOAD - To read data from the presentation server into an internal table without a user dialog, use the
function module WS_UPLOAD. The most important parameters are listed below.
C. UPLOAD - File transfer with dialog from presentation server file to internal table. Data which is available
in a file on the presentation server is transferred in an internal table. ASCII & Binary files can be transferred.
D.WS_UPLOAD - To read data from the presentation server into an internal table without a user dialog, use
the function module WS_UPLOAD. The most important parameters are listed below.
18.Is Session Method, Asynchronous or Synchronous?
A. Asynchronous
B. Synchronous
C. Synchronous and Asynchronous
D. None of above
19. What are the differences between SAP memory and ABAP memory? (Multiple Answer)
A. SAP Memory is a memory area in the internal session (roll area) of an ABAP program. Data within this
area is retained within a sequence of program calls, allowing you to pass data between programs that call
one another. It is also possible to pass data between sessions using SAP Memory.
B. ABAP Memory is a memory area to which all sessions within a SAPgui have access. You can use SAP
memory either to pass data from one program to another within a session (as with ABAP memory) or to pass
data from one session to another.
C.ABAP Memory is a memory area in the internal session (roll area) of an ABAP program. Data within this
area is retained within a sequence of program calls, allowing you to pass data between programs that call
one another. It is also possible to pass data between sessions using SAP Memory.
D.SAP Memory is a memory area to which all sessions within a SAPgui have access. You can use SAP
memory either to pass data from one program to another within a session (as with ABAP memory) or to pass
data from one session to another.

20. Which data type cannot be used to define parameters.


A. Type N
B. Type C
C. Type F
D. Type P

ANSWERS:1. B
2. A
3. D
4. A
5. C
6. C
7. D
8. C
9. B
10. A
11. A
12. A,B
13. C,B
14. A,B
15. A,B,C
16. A,C,E
17. C,D
18. B
19. C,D
20. C
ABAP Interview Questions
What is a 'Z' report?
Y or Z report refer to customized abap programs written for modules such as mm, sd, pp or fi/co etc.
Can we create an ABAP program without using Y or Z?
No, this is because all non Yor Z programs are standard SAP programs.
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.
Following are some of the answers which I gave upto my knowledge.
1. 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.
2. 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.
3. What is the use of 'table index'?
Ans .Index is used for faster access of data base tables.
4. 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.
5. Can you set up background processing using CALL TRANSACTION?
Yes,Using No Screen Mode.
6. 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.
With Compliments from: Pavan
1. 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.
2. 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.
3. How do I find the output type of a table or a program?
Table TNAPR / NAST
*-- Raj

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.
Answers to some ABAP Interview Questions
Questions which I have faced in an interview:
1) What is runtime analysis? Have you used this?
2) What is meant by performance analysis? Have done anything to improve the performance?
3) How to transfer the objects? Have to transferred any objects?
4) How did you test the developed objects?
5) What is the difference between SAP Memory and ABAP Memory?
6) In order to upload Purchase order details, how you handle multiple values for a single field?
Eg: Item field may contain no. of values for a record
7) What is the procedure you followed to upload the data?
8) How did you handle errors in Call Transaction?
9) Among the Call Transaction and Session Method, which is faster?
10) What are the difference between Interactive and Drill Down Reports?
11) How to pass the variables to forms?
12) How to create a link between modified form and modified print program?
13) What is the table, which contain the details of all the name of the programs and forms?
14) How did you test the form u developed? How did you taken print?
15) What are Standard Texts?
16) What is the difference between Clustered Tables and Pooled Tables?
17) What is pf-status?
18) Among "Move" and "Move Corresponding", which is efficient one?
19) What are the output type and Tcodes?
20) Where we use Chain and Endchain?
21) Do you use select statement in loop endloop, how will be the performance? To improve the
performance?
22) In select-options, how to get the default values as current month first date and last date by
default?
Eg: 1/12/2004 and 31/12/2004
Go thru these answers:
1) What is runtime analysis? Have you used this?
It's checks program execution time in microseconds. When you go to se30.if you give desired program
name in performance file. It will take you to below screen. You can get how much past is your program.
2) What is meant by performance analysis? Have done
3) How to transfer the objects? Have you transferred any objects?
4) How did you test the developed objects?
I was testing a developed object. There are two types of testing
- Negative testing
- Positive testing
In negative testing we will give negative data in input and we check any errors occurs.
In positive testing we will give positive data in input for checking errors.
8) How did you handle errors in Call Transaction?

We can create a internal table like 'bsgmcgcoll'. All the messages will go to internal table. We can get errors
in this internal table.
Below messages are go to internal table. when you run the call transaction.
- Message type
- Message id
- Message Number
- Variable1
- Variable2
- Variable3
9) Among the Call Transaction and Session Method, which is faster?
Call transaction is faster then session method. But usually we use session method in real time...because we
can transfer large amount of data from internal table to database and if any errors in a session. Process will
not complete until session get correct.
10) What are the difference between Interactive and
Drill Down Reports?
ABAP/4 provides some interactive events on lists such as AT LINE-SELECTION (double click) or AT USERCOMMAND (pressing a button). You can use these events to move through layers of information about
individual items in a list.
Drill down report is nothing but interactive report...drilldown means above paragraph only.
11) How to pass the variables to forms?
12) What is the table, which contain the details of all the name of the programs and forms?
Table contains vertical and horizontal lines. We can store the data in table as blocks. We can scroll depends
upon your wish. And these all are stored in database (data dictionary).
Which contain the details of all the name of the programs and forms? (I don't know).
13) How did you test the form u developed? How did you taken print?
14) What are Standard Texts?
16) What is the difference between Clustered Tables and Pooled Tables?
A pooled table is used to combine several logical tables in the ABAP/4 dictionary. Pooled tables are logical
tables that must be assigned to a table pool when they are defined.
Cluster table are logical tables that must be assigned to a table cluster when they are defined.
Cluster table can be used to store control data they can also used to store temporary data or text such as
documentation.
17) What is pf-status?
Pf status is used in interactive report for enhancing the functionality. If we go to se41, we can get menus,
items and different function keys, which we are using for secondary list in interactive report.

18) Among "Move" and "Move Corresponding", which is efficient one?


I guess, 'move corresponding' is very efficient then 'move' statement. Because usually we use this stamtent
for internal table fields only...so if we give move corresponding. Those fields only moving to other place
(what ever you want).
19) What are the output type and Tcodes?
20) Where we use Chain and End chain?
21) Do you use select statement in loop end loop, how will be the performance? To improve the
performance?
22) In select-options, how to get the default values as current month first date and last date by default?
Eg: 1/12/2004 and 31/12/2004
Prem Kumar
Q: How to compare the 2 tables between the 2 systems?
Ans: Which is using the transaction code is 'oy19'.
Q. What is the use of pick statement do?
Ans: The pick statement is used to it will capture the user action.
ex: if sy-ucomm = 'x'.
This statement is used to capture the user action.

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<subobject> ( ) and Remove<subobject> ( ) The BAPI Add<subobject> adds a subobject to an existing
object inst! ance and the BAPI and Remove<subobject> 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.
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
Ssession
1. synchronous updation
only synchronous updation
optional
2. errors can handled
error log is created
explicitely
3. faster
slower
4. less amount of data
more can transfer
5. updation takes place
updation takes place
during program execution 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
labels are used
not generated

without main window it can


labels cannot
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
Tips by : Ramana
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.
Important ABAP FAQ's
How to execute a program step by step on the abap editor?
This is known as Testing and Debugging ABAP Codes, Functions
What are dml statements in sap?
Ans: Insert, Update, Delete.
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
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.
How many indexes can be created for a table?
Ans: 9.
What is data class?
Ans: The data class specifies in which table space the table is created in database.
Give few names of cluster tables in sap?
Ans: sorry i dont know
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
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
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.
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.
How to add new fields to a standard sap table?
Ans: 1. Appended structures

2. Customizing tables

What are lock objects?


Ans: Lock objects are nothing but which holds a data for particular field value until you remove a lock..
Diff betwn inner & outer join?
Ans:
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.
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.
If you write a write statement after end-of-selection, will that be triggered?
Ans: Yes
How to create a button in selection screen?
Ans: Using parametres
How to add a gui status in a selection screen?
Ans: sorry i dont know i thik using set pf.
How to create a check box/option button in a list?
Ans: Regarding Runtime creation of Check Boxes

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


Ans: Yes through Submit and return
Can you call a transaction from a report? how?
Ans: Yes Using Call transaction and leave to.
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
What are the main events that are used in an ALV report?
Ans: sorry i dont know
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
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
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
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.
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
What is the use of at new statement?
Ans:sorry i dont know
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.
What does it mean occurs 0 while creating an internal table?
Ans: sorry i dont know
Which of these methods can be best used in background process?

Ans : Batch Input method.


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 <sql]
[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.
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.
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.
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.
What is performance tuning?
Ans: Performance tuning for Data Selection Statement
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.
What is the role of secondary index in performance?
Ans: sorry i dont know
What is the role of ST05 in performance tuning?
Ans: SQL trace
What is the role of extended syntax check in performance tuning?
Ans: sorry i dont know

Will join conditions in sql queries affect perfomance? how?


Ans : Yes
Will sorted internal tables help in performance?
Ans: Yes
Will where conditions in a sql query help improve performance?
Ans: No Not at all
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

Common Questions and Answers about ABAP/4 and Developments


1. What is the difference between external & internal subroutine?
2. Why do we use ALV?
3. Why do we use GET CURSOR and what is it?
4. Both the events AT SELECTION-SCREEN and AT USER-COMMAND are processed after user
input.
Then what is the difference between these and when we should use what?
Sudeshna
Answer 1:
1) Internal subroutines in the sense ..subroutines which are defined and used in a same program...external
in the sense if you create a sub routine in one program and you're calling this subroutine in another program
..then this is external subroutine.
2) ALV gives many advantages than a list like sorting summing getting graphics like that stuff
3) While generating a interactive report we will use get cursor..use is to get the value of the fiel under the
cursor..
4) At selection screen is used to validate the fields in a selection screen...and at user command is used to
modify the screen in a selection screen and in genarating secondary lists..
Sarath Reddy
Answer 2:
1. The name itself implies the internal subroutines defined by form /perform.. can be called within the same
prog in which they were declared.....external subroutines can be called outside the program.......
2. SAP LIST VIEWER is ALV . its main advantage is by using ALV technique we can find totals ,subtotals
,sort in any order etc there itself in the list output of course we need to write all those functionalities while
using ALV...also many functional modules are defined under ALV concept...

3. GETCURSOR is used to trace the position of the cursor in the list ..


suppose we want to double click on any filled in the list and want to trace data using that field we use
getcursor .....
4.AT SELECTION-SCREEN is used where you have a seperate selection screen using select-options or
parameters where as AT USER-COMMAND is used where no selection screen exists....at.user-command
is mainly used while setting pf-status which means creating our own menu with function codes etc...
Shiva
I had seen some of the standard abap that the table name had *, like *ekpo. What is the meaning?
What is the difference between with * and without * ?
It just lets you use the table a second time. For example:
select single * from ekpo where ebeln = '12345' and ebelp = '1'.
select single * from *ekpo where ebeln = '67890' and ebelp = '1'.
You now have two separate records, one in ekpo and one in *ekpo.
Another way to do this is to simply use the 'into' argument in the 'select' statement to read the second ekpo
record into some other field. The '*' format can be confusing, I think it may be left over from earlier releases,
like 2.2.
EKPO is database table and *EKPO is internal table.
Once you select into EKPO, you can use it the same way as *EKPO.

How do I use variables in the FORMAT command?


DATA COLORID TYPE I VALUE 4.
FORMAT INTENSIFIED ON COLOR = COLORID.

When using CALL 'SYSTEM' id 'COMMAND' field unix-command, how does one capture the results
of the command? For example, if the unix-command were the date?
You capture the results in the table e.g TABL, like this
DATA: BEGIN OF TABL OCCURS 0,
LINE(560),
END OF TABL.
REFRESH TABL.
CALL 'SYSTEM' ID 'COMMAND' FIELD PARCOM_LOC
ID 'TAB' FIELD TABL-*SYS*.

I am working on a program that needs to show number of days between 2 dates. When I scanned the
function library, I only found a function to give you the number of years between dates. I can
probably code this in ABAP but does anyone know if a function exists to do this.
I wrote this example for you. I think this is what you need.

DATA: DATE_1 LIKE SY-DATUM,


DATE_2 LIKE SY-DATUM.
DATA DAYS TYPE I.
DATE_1 = SY-DATUM.
DATE_2 = SY-DATUM + 65.
DAYS = DATE_2 - DATE_1.
WRITE:/ 'DATE_2=',DATE_2,'DATE_1=',DATE_1,'DAYS=',DAYS.
Run this code and then you will understand.

How do I concatenate two strings in Abap/4?


For all SAP Versions
STR_LENGTH = STRLEN( STRING1 ).
MOVE STRING1 TO STRING3.
WRITE STRING2 TO STRING3+STR_LENGTH.
For SAP Version 3.0 choose:
CONCATENATE STRING1 STRING2 INTO STRING3.
If you want a space between both fields:
CONCATENATE STRING1 STRING2 INTO STRING3 SEPARATED BY ' '.
For SAP Version 2.2 choose Functions:
STRING_CONCATENATE for 2 Strings and
STRING_CONCATENATE_3 for 3 Strings.

Has anyone been successful in suppressing the selection screen that is automatically displayed
when using logical data bases. I want to run a job in the background using a logical database and I
do not want the user prompted for the parameters. I want to pass the parameters in the program.
Try using the SUBMIT rep USING SELECTION-SET 'variant' WITH ....
command in the report to pass the variant thru the program

I would like to know how to execute from ABAP code an external Unix program and check for a
return code?
There are different ways to this:
(1) OPEN DATASET <file> FOR OUTPUT 'unix command'
CLOSE DATASET <file>
This command executes the unix command and writes the output into <file>
Look into OSS Note 9391.
(2) or try the following program but unfortunately the command CALL SYSTEM is
not supported by SAP. If you are on R/3 2.1 - 2.2x you can get some idea's from the program SAPMSOS0.
REPORT ZUNIXCOM .

DATA: U_COMMAND(200).
* Table for system messages
DATA: BEGIN OF RT OCCURS 100 ,
LINE(100) ,
END OF RT .
START-OF-SELECTION .
MOVE 'unix command' to U_COMMAND .
REFRESH RT.
CALL 'SYSTEM' ID 'COMMAND' FIELD U_COMMAND
ID 'TAB' FIELD RT-*SYS* .
LOOP AT RT.
WRITE : / RT-LINE .
ENDLOOP.
ABAP Frequently Asked Question
ABAP/4
Q: When we create a customer the information is updated in structure RF02D and the some tables like
KNA1 are updated. How can we find the tables for master data transactions?
A: Go to ABAP Workbench -> Overview -> application hierarchy - SAP -> follow the customizing based tree
for your application. Double click on a lowest hierarchy level to get for the correct marked development
class. Here you can find all the tables, views, logical databases etc. used for a system operation.

RFC
Q: We want to move a SAP table to an Access table using TABLE_EXPORT_TO_MSACCESS_RFC
Importing parameters are
DBNAME
DEST
FLG_APPEND
FLG_POPUP
LANGU
The table has three columns:
TABNAM
MANDT
SDATA
We have no Exporting parameters.
How shall we set the parameters?
A: Install the PS utilities, which are part of SAPGUI install CD. You may run report RIACCESS from SE38.
Go to SALE -> Communication -> Define RFC Destination. Setup two RFC destinations PS_ACCESS_1 and
PS_ACCESS_2 and will have to get them to point to wdpsastr.exe and wdpsatab.exe respectively. Then
execute RIACCESS and choose PS_ACCESS_1 to generate access tables. Please note that Access only
supports tables with up 255 fields.
Q: We want an RFC do the following transactions - MB1A, MB1C,>MB01 (goods receipt/issue).
A: Call the RFC INBOUND_IDOC_PROCESS with IDOC_CONTROL and IDOC_DATA. The structure in the
field sdata in the IDOC_DATA are e1mbxyh and e1mbxyi.

Transports

Q: In a Dev instance, we want to transport a modification to a layout set from one client to another. What is
the best way?
A: use transaction SE71. Choose Utilities->Copy from Client. Layout sets need not be transported between
clients , via transport requests DEVKxxxxxx.
Q: We need to keep track of the transports that need to flow through to other systems (ie, DEV, TST, TRN,
PRD etc). Is there a way do this?
A: SAPCRAFT enables you to control the CTS from DEV system. This keeps track of all transports at all
stages and enables you to allocate Import, export and Authorization functions to specific user.

E D I / IDOC
Q:1 We created an EDI Vendor and created all required output conditions. However no IDOC is generated
when PO is printed. Why?
A: Go to Header->output for the PO. The output type shall be '6'. The status shall be '1'. If the status is '0'
check the timing. If the status is '2' , go to 'GOTO->Processing Log' and the explanation for non-generation
of IDOC can be seen.
Q: How can we create / upload IDOC's from legacy system to SAP?
A: Third party tool Mercator may be used to convert Legacy files to Idoc format. Mercator provides an IDOC
tree import facility, SAP provides the export facility. You can transfer the Idoc layouts from SAP to Mercator
automatically and then map.
Q: We want to receive an outbound EDI 855 IDOC only if E2EDP20 -scheduling confirmation segment is
present. Else get an "error" status preventing triggering the EDI subsystem.
A: User exit logic has to be added in function IDOC_INPUT_ORDRSP.
# Set up a test flag and set it off when the IDOC header is read.
# Turn the flag ON when the EDP20 segment is read.
# Interrogate this flag when the next segment after EDP20 in the same IDOC comes in. If it is on ,you have
an EDP20 coming in.
# Issue an error status 51 with suitable message for whichever condition you don't want the IDOC to be
processed, This will stop the IDOC from posting.
Q: Where ever PO is sent to the vendor via EDI, we want an acknowledgement of the PO by vendor. Which
fields are updated and what should be my procedure?
A: Execute Program: IDOC_INPUT_ORDRSP
Process code: ORDR
Message type: ORDRSP
IDOC: ORDERS01
The confirmation process allows the supplier to return an acknowledgment. Only Dates and quantities can
be changed The information is stored in the PO and can be viewed via Item->Confirmation->Overview. The
PO can be flagged as 'confirmation required' so that Pos without acknowledgement receipt can be
monitored. Control keys and tolerances (days and quantities) have to be customized.

ALE
Q: Our IDOC remains in status 51 ( not posted) while testing ALE setup by passing DEBMAS02 Idocs. The
message 'Field KNA1-BRSCH is not an input field'. This is the Industry key. What are we missing?
A: Go to IMG - menu path IMG->LogisticsGeneral-> Logistics Basic Data: Business partners->Customers->
Control->Define Account groups and field selection for customer.
Select sold-to or ship-to. Select General Data. Select control and double click. Industry key is found here.
Change the option to 'Optional Entry'.
Check OSS 5599. You may have to update view V_T078D also.

Batch In-put/ Direct In-put


Q: We are calling transaction VL01 in batch input to create deliveries using a program for delivery due list.
How ever we are unable to create deliveries for transport stock orders. Why?
a: Batch-inputs can not be used to fill the "delivery due list" screen because it is not a dynpro. This is a
standard SAP report. A SAP report (check with "System -> Status") may be called using SUBMIT sentence
with the appropriate options . It is preferred to call a report than create a Batch-input program.
Q: What are some sample Direct input data transfer programs?
A: In MM for Material Master data - RMDATIND
FI - for Accounting Documents - RFBIBL00
PP - for Independent requirements - RM06IN00
CA - for Classification data - RCCLBI03

Handling Tables
Q: We specify the logical database. And we want a field that is not present in any of the tables defaulted in
logical database. How can we want to add this additional field from a different table?
A: . Presume you have a
logical database
table 1
table 2
table 3
Define the required field as additional field say fld of table 1, table 2 or table 3
and then in the code section define.
Perform get_f1d(zxxxxxxx) using f1d.
Form zxxxxxxx could be like;
Form get_f1d using f.
Select * from where 'conditions'
f = table4 - f1d.
Q: We need to download an internal table to the Presentation Server(local workstation). Whenever we run
the program, the same file has to be saved as a separate file in sequential order. Ex: 0001.txt, 0002.txt etc.
Where can we store the last file number?
A: SAP has a table TVARV for storing the variants.
A record may be created in TVARV for all the programs that require this kind of incremental records.
For Ex: the record could be 100Zmm10001 MM sequence rec where first part consists of client code and the
program being run. Client code is required because TVARV does not has a field for client code. The second
part is the description indicating the purpose what the record is created. This entire string may be posted in
the Name field (char - 30).
The Type field ( char- 1) may be populated with P or S (Parameter or Selection)
Low field (char- 45) may be populated with '0001' when run first time and increment it by one in your
program for downloading of the internal table.

Others
Q: How can we use CAD with SAP ?
A: Third party tools from Eigner + Partner provide interfaces to SAP. Another third party software - Fastlook
Plus from Kamel Software enables you to view all of the Autocad formats.

Q: How can I access SAP through Internet?


A: SAP has its own Internet transaction Server (ITS) . Other products include Haht, WebObjects,
NetDynamics etc. Each product has its' own architecture.
However to access the database, access paths SAP GUI or RFC Channel have to be used.
Q: How can we transport the standard text?
A: Refer note 3355 in OSS for a complete explanation. The SAPscript objects that should be transported
must be written in a transport request.
The entries are as follows:
R3TR FORM NAME (NAME = Name of the layout set)
R3TR STYL NAME (NAME = Name of the style)
R3TR TEXT OBJECT,NAME,ID,L
(OBJECT = Text object, NAME = Text name, ID = Text ID, L = Text language)
If you want to transport a number of texts, you can use report RSTXTRAN to insert the individual text keys
into a correction. The transport request must be entered and released via the transport system.
Q: How to find what transactions a particular user was running for a given period in the past (Eg: from 1st of
a month )
A: You may use the transaction - STAT.
Q: We want protect/lock a field so that only selected people can change the value while others can only
read. How to set the authorizations?
A: Create an authorization object for change mode. Loop at screen in the user exit and set input to 0. Check
the user based on sy-uname and the authorization. Decide whether input should be 0 or 1.
Q: How to lock an user defined transaction for some time during which no user can access the same?
A: Use transaction SM01. Scroll through the transactions and check against the transaction to be locked.
And after the maintenance is over, go back to SM01 and uncheck the same to unlock.
ABAP Tips and Tricks
Retrieving the deleted program
I recently deleted a custom program (which is already transported to production) accidentally and was
wondering if there is any method of retrieving the program back. After some research, I found a way of
getting back the program. Following are the steps in getting back the program:
1) Create a program with the same name as earlier (which is deleted)
2) Click on "Utilities" --> "Versions" --> "Version Management"
3) Select the version of your earlier program and click on display.
4) Your earlier program is displayed here. *-- Soumya Ray
Find out in what all Tables a specified field is available.
You can find out through transaction code SE15.
1) Give SE15 on command prompt.
2) Select ABAP Dictionary
3) Select "fields" folder
4) Click on table fields
5) Then you can enter the desired field name (In your case EKGRP)
6) Run OR press F8.
The system will list out all the tables which contain your desired field name.
or

1) using transactin Code SE11( ABAP Dictionary)


2) enter the Data table name where-in the respective field (EKGRP) is used eg; EKKO
3) Click the where -used list button
4) Check out the box(DB tables) Only .
There you can see entire list of tables containing the desired field.
Here the difficulty is that one should know at least the name of the one of the data tables which contain the
desired field.
With Compliment by: Manohar TS & Kotha
**********
Find the Table Name For a Field.
I know couple of ways to find the table name for a field.
like.
1. Part the cursor at the field and press F1 & F9.
2. se84 or se15
3. st05 (sql trace).
4. Setting Break point in ABAP.
If you will tell other methods it will be apreciate.
**********
*
* How to print Apostrophe using the write statement
* For e.g. You'll be there.
*
report zapostrophe message-id z1.
DATA: LINE(20).
CONCATENATE 'You''' 'll be there.' INTO LINE.
WRITE:/ LINE.
**********
Given a transaction code, how can I find the menu path?
In 4.6c, you can used tcode search_sap_menu to find the SAP MENU tcode.
Please note that there are no tcode available to find the path of the IMG transaction.
**********
How to un-encrypt SAP user password?
It is not possible to un-encrypt the SAP password, because a one-way encoding (with strong 1024 bit key) is
used for this. The result is stored and each time one has entered the password the encoding result is
checked.

**********
When you delete an entry from an internal table in ABAP, the system has to re-generate the index for all
entries after your delete, slowing the report if you have many records to eliminate.
It is much quicker to do an insert of the correct records into a second table than to delete entries from the
first. The reason for this is because the index is only generated for the newest element.
**********
If you want to protect a program against debugging, you just have to set the STATUS = S in the attributes
view of the main program.
**********
BDC.
When You use a call transaction ,and populate the BDCDATA table.
Make sure you pass the "DATE FIELDS" of any transaction by formatting it as "XX/XX/YYYY" cos if you
pick this data from database it will be of the format 20030505 or something like that. Make sure You pass
this value as character field.
Same is true for the "Rate Fields". Make sure you pass them as "Character Fields" by formatting them.
**********
If you need to find out the Okcodes for BDC sessions, look for program RSBDCCUA and run it for any
platform say 'WN' for windows or MC for Mac and it will generate list of function codes
**********
To save the contents of an internal table as a Microsoft Excel Worksheet when debugging code in SAP R/3
Enterprise:
1. Click on the "Table" button
2. Type in the name of your internal table in the "Internal table" field and hit Enter.
3. Hit CTRL + F11 or click on the "Save as Excel Worksheet" button.
4. Type in the record numbers that you want to save. (Ex. From Line: 1 To Line: 10) Hit Enter.
5. Save your file.
**********
Starts with a Z is homegrown program
You cannot be sure that anything which starts with a Z is a homegrown program.
SAP provide a number of correction programs, especially within the archiving area, which start with a Z.
For e.g. ZZSTOCKL from note 202345.
**********
Can line-size of abap report large than 255?
You can have line-size upto 1023.
Along with Report statement pass the line-size as 1023. Ex. Report xyz line-size 1023.
**********
How to find out the number of days between a given date, excluding Saturdays and Sundays and
public holidays?

Try functions,
=> DATE_CONVERT_TO_FACTORYDATE
=> HR_HK_DIFF_BT_2_DATES
Create Own Transaction Using SE93
What is SE93 and why we use this transaction?
By: Mrunalini
SE93 is to Maintain Transaction Codes.
If we develop some Module pool programs or Report Programs, to make these programs available to the
end users, we create transaction codes for these programes.
For performing any kind of task in the SAP R/3 ERP system, a transaction is used. SAP provides a standard
set of transactions to manipulate i.e insert, update, delete and display data in the system. But sometimes,
the need to create a customer specific transaction may arise due to the following reasons
--> Standard SAP may not support that task.
--> A particular transaction needs to be customized to suit the customer requirements.
A transaction is defined as a sequence of dynpros (sap term for screens) having input and output fields and
corresponding processing logic behind them to perform a particular task.
So we create a transaction in SE93.
We call an execution of an ABAP program using a transaction code a transaction . There are dialog , report,
parameter, variant, and - as of Release 6.10 - OO transactions. A transaction is started by entering the
transaction code in the input field on the standard toolbar or by means of the ABAP statements CALL
TRANSACTION or LEAVE TO TRANSACTION. Transaction codes can also be linked to screen elements or
menu entries. Selecting such an element will start the transaction.
How can we create TCODE for Table Maintenance Generator(TMG)?
Check following steps,
1. Transaction: SE93
2. Enter Short Text
3. Select Radio button "Transaction with Parameters (Parameter Transaction)"
4. Next screen, give transaction as SM30
5. Check "Skip Initial Screen"
6. Under Default Values tab give two rows
a. VIEWNAME for screen field and <your table name> for value
b. UPDATE for screen and 'X' as value
7. Save and Execute.
What The Differences Between ABAP and HR-ABAP
The ABAP HR is an integral part of ABAP. Generally in ABAP the following are done:
1)
2)
3)
4)

Table development
Date Processin
Reprt developing
BAPIs /RFC s

5)
6)
7)
8)
9)

Data base update


Screens development/enhancement
Scripts and smart forms.
Function Building
Java connectors etc.

This is basically done through the PROGRAMMING in ABAP builder by using ABAP 4th generation languge.
This may be related to any module of my SAP ERP 2004 like HR, FICO.SD,MM,CRM Etc.,
Now when it is said ABAP HR. It is the development of ABAP in the area of HR to meet the clients
requirements according to the functional specifications .They may be in any area of HR like in the areas of
time aspects ,pay aspects, OM aspects and Self Services like E-recruitment, ESS etc.,
One example of ABAP PROGRAMME related to HR is given below.
Report: ZP_POSTCODE: This report has been developed by the ABAPER in the area of SAP HR to Display
report of employees by postcode that includes current traveling allowances (i.e. parking, permit or transport
card etc.)
*:.....................................................................:
:
*: Use: Help encourage the use of car sharing and public
* transport wherever it appropriate (this is the functional requirement of the client or the functional
specification
* (which is given by the functional consultants)
:
*:.....................................................................:
REPORT zp_postcode.
type-pools: slis.

"ALV Declarations

NODES: pernr.
INFOTYPES: 0000, 0001, 0002, 0006, 0008, 0014, 0105, 0121.
SELECTION-SCREEN BEGIN OF BLOCK pcode WITH FRAME TITLE text-s01.
SELECT-OPTIONS: so_pcode FOR p0006-pstlz.
SELECTION-SCREEN END OF BLOCK pcode.
TYPES: BEGIN OF t_output,
pernr
TYPE p0001-pernr, "personnel name
anredtxt TYPE t522t-atext, "title (based on p0002-anred)
fname
TYPE p0002-vorna, "first name
lname
TYPE p0002-nachn, "last name
orgtx
TYPE t527x-orgtx, "dept
fte
TYPE p0008-bsgrd, "fte
parking(20) TYPE c,
payslip TYPE t526-sachn,
"payslip address
telno
TYPE p0105-usrid_long, "tel number(p0105-usrty = 0020)
email
TYPE p0105-usrid_long, "email (p0105-usrty = MAIL)
postcode type p0006-pstlz,
END OF t_output.
DATA: it_output TYPE STANDARD TABLE OF t_output INITIAL SIZE 0,
wa_output TYPE t_output.

*ALV data declarations


data: fieldcatalog type slis_t_fieldcat_alv with header line,
gd_tab_group type slis_t_sp_group_alv,
gd_layout
type slis_layout_alv,
gd_repid
like sy-repid,
gt_events
type slis_t_event,
gd_prntparams type slis_print_alv,
gd_count(6) type n,
gd_outtext(70) type c,
gd_lines
type i.
************************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.
clear: gd_count.
GET pernr.
* Infotype 0121 is used to store multiple contracts for personnel.
* Field p0121-hpern contains the personnel number for the main contract.
PROVIDE * from p0121 between pn-begda and pn-endda.
* Check if main contract
if p0121-pernr ne p0121-hpern.
reject.
endif.
ENDPROVIDE.
add 1 to gd_count.
concatenate 'Processing personnel data'(m10) gd_count into gd_outtext
separated by ' '.
* Display indicator for employee count
perform progress_indicator using gd_outtext.
* Retrieve datd from infotypes
rp_provide_from_last p0000 space pn-begda pn-endda.
rp_provide_from_last p0001 space pn-begda pn-endda.
rp_provide_from_last p0002 space pn-begda pn-endda.
rp_provide_from_last p0006 space pn-begda pn-endda.
rp_provide_from_last p0008 space pn-begda pn-endda.
rp_provide_from_last p0014 space pn-begda pn-endda.
* Check post code
CHECK p0006-pstlz IN so_pcode. "cp
* Post code
wa_output-postcode = p0006-pstlz.

* Personnel number
wa_output-pernr = pernr-pernr.
* Personnel title
SELECT SINGLE atext
FROM t522t
INTO wa_output-anredtxt
WHERE sprsl EQ sy-langu AND
anred EQ p0002-anred.
* First name
wa_output-fname = p0002-vorna.
* Last name
wa_output-lname = p0002-nachn.
* Organizational Unit text (dept)
SELECT SINGLE orgtx
FROM t527x
INTO wa_output-orgtx
WHERE sprsl EQ sy-langu AND
orgeh EQ p0001-orgeh AND
endda GE sy-datum.
* FTE
wa_output-fte = p0008-bsgrd.
* Parking / travel deducted?
CASE p0014-lgart.
WHEN '7180' OR '7181' OR '7182'.
wa_output-parking = text-002.
WHEN '7183'.
wa_output-parking = text-001.
WHEN '7171' OR '7172' or '7173' or '7174' or
'7175' or '7176' or '7177' or '7178'.
wa_output-parking = text-003.
ENDCASE.
* Payslip Address
SELECT SINGLE sachn
FROM t526
INTO wa_output-payslip
WHERE werks EQ p0001-werks AND
sachx EQ p0001-sacha.
PROVIDE * from p0105 between pn-begda and pn-endda.
* Telephone numbers
if p0105-usrty = '0020'.
wa_output-telno = p0105-usrid_long.
endif.

* Email address
if p0105-usrty = 'MAIL'.
wa_output-email = p0105-usrid_long.
endif.
ENDPROVIDE.
append wa_output to it_output.
clear: wa_output.

************************************************************************
*END-OF-SELECTION.
END-OF-SELECTION.
describe table it_output lines gd_lines.
if gd_lines gt 0.
perform build_fieldcatalog.
perform build_layout.
perform display_alv_report.
else.
message i003(zp) with 'No records found'.
endif.
*&---------------------------------------------------------------------*
*&
Form PROGRESS_INDICATOR
*&---------------------------------------------------------------------*
*
Displays progress indicator on SAP screen
*----------------------------------------------------------------------*
form progress_indicator using p_text.
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
*
PERCENTAGE = 0
text
= p_text.
endform.
" PROGRESS_INDICATOR
*&---------------------------------------------------------------------*
*&
Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*
Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
form build_fieldcatalog.
fieldcatalog-fieldname = 'PERNR'.
fieldcatalog-seltext_m = 'Personnel No.'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
* fieldcatalog-emphasize = 'X'.
* fieldcatalog-key
= 'X'.
* fieldcatalog-do_sum
= 'X'.
* fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'ANREDTXT'.
fieldcatalog-seltext_m = 'Title'.
fieldcatalog-col_pos = 1.

append fieldcatalog to fieldcatalog.


clear fieldcatalog.
fieldcatalog-fieldname = 'FNAME'.
fieldcatalog-seltext_m = 'First Name'.
fieldcatalog-col_pos = 2.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'LNAME'.
fieldcatalog-seltext_m = 'Last Name'.
fieldcatalog-col_pos = 3.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'ORGTX'.
fieldcatalog-seltext_m = 'Department'.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'FTE'.
fieldcatalog-seltext_m = 'FTE'.
fieldcatalog-col_pos = 5.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PARKING'.
fieldcatalog-seltext_m = 'Parking/Metrocard'.
fieldcatalog-col_pos = 6.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PAYSLIP'.
fieldcatalog-seltext_m = 'Payslip Add.'.
fieldcatalog-col_pos = 7.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'TELNO'.
fieldcatalog-seltext_m = 'Telephone'.
fieldcatalog-col_pos = 8.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'EMAIL'.
fieldcatalog-seltext_m = 'E-mail'.
fieldcatalog-col_pos = 9.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'POSTCODE'.
fieldcatalog-seltext_m = 'Post code'.
fieldcatalog-col_pos = 10.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
endform.
" BUILD_FIELDCATALOG

*&---------------------------------------------------------------------*
*&
Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
*
Build layout for ALV grid report
*----------------------------------------------------------------------*
form build_layout.
gd_layout-no_input
= 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text
= 'Totals'(201).
gd_layout-zebra
= 'X'.
endform.
" BUILD_LAYOUT
*&---------------------------------------------------------------------*
*&
Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*
Display report using ALV grid
*----------------------------------------------------------------------*
form display_alv_report.
gd_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program
= gd_repid
is_layout
= gd_layout
it_fieldcat
= fieldcatalog[]
i_save
= 'X'
tables
t_outtab
= it_output
exceptions
program_error
=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.
endform.

" DISPLAY_ALV_REPORT

To conclude the message its always advantage to have a HR consultant who knows ABAP that is why this
ABAP HR Consultant are in high demand.
SAPScript Transaction codes
SE71 - Form painter
SE72 - Style maintenance
SE78 - SapScript Graphics Management
SO10 - Create standard text module

SAPScript Important Programs


Here are some useful programs for SAPSCRIPT development/search ...

RSTXFCAT - Program to find out SAP Scirpt names (Search Program)


RSTXCDM1 - SAPscript: Sample Program for Form Printing
RSTXCNVR - Converting SAPscript standard text to RAW format (ASCII)
RSTXCPDF - Routines for Converting OTF Format to PDF Format
RSTXDBUG - Activate/Deactivate Form Debugger
RSTXFCAT - Find Forms
RSTXFCPY - Copy Forms Between Clients
RSTXFCOM - Comparison of Two Forms
RSTXFCON - SAPscript: Conversion of Page Format for Forms
RSTXFINF

- Comprehensive Information about a Specific Form

RSTXHTML - Conversion of SAPscript Texts (ITF) to HTML


RSTXICON - List of SAP icons and their names and SAP numbers <xxxxx>
RSTXSYMB - List of SAP symbols and their names as well as <xxxxx> SAP number
RSTXR3TR

- Transport Program For SAPscript Transport Objects

RSTXSCAT

- Find Styles

RSTXSF01

- TrueType font installation for SAPscript/SmartForms

RSTXTCAT

- Find Standard Texts

Reading Text in SAPScripts


If you only need to output the text, you don't need to used READ_TEXT like in an ABAP program,
just use the INCLUDE command in SAPScript.
It will read the text and output it to your form.
The Syntax is like this:
/: INCLUDE &T166K-TXNAM& OBJECT &T166K-TDOBJECT& ID &T166K-TDID& LANGUAGE &EKKOSPRAS&
SAP Scripts Boxes/Lines/Shading
Setting default parameters for a box:
You can use the POSITION and SIZE commands to set default parmeters for a box.
Instead of:
/: BOX XPOS '11.21' MM YPOS '5.31' MM HEIGHT '10' MM WIDTH '20' MM INTENSITY 10 FRAME 0 TW
You can write:

/: POSITION XORIGIN '11.21' YORIGIN '5.31' MM


/: SIZE HEIGHT '2' MM WIDTH '76' MM
/: BOX FRAME 10 TW INTENSITY 10
This can be usefull if you gave several boxes that share the same parameters.
If you want to set the position realtively to the window use POSITION WINDOW
to set the position to the top/left start of the window. Then use POSITION
to set the current position relatively to the start of the Window.
Note that you uses "+" or "-" in the ORIGIN position to the set the position relatively.
/: POSITION WINDOW
/: POSITION XORIGIN '+5' MM YORIGIN '+10' MM
the position is now 5 MM from the left and 10 MM from the top of the window
NOTE: After using the position command you can move the current position
realtively to the last used position
/: POSITION XORIGIN '+10' MM YORIGIN '+20' MM
Now the position will be X = 15 and Y = 30

Drawing a line. You can draw a line by setting the Height or Weidth to 0
and add a frane. E.g. a horizontal line:
/: SIZE HEIGHT '0' MM WIDTH '200' MM
/: BOX FRAME 10 TW XPOS '11.21' MM YPOS '14.81' MM INTENSITY 100

SAP Printer commands in SAPScripts


The command line in the editor must be as follows:
/: PRINT-CONTROL xxxxx
or
/: PRINT-CONTROL 'xxxxx'
where xxxxx stands for the five-character name of the print control.
Example:
/: PRINT-CONTROL ZM100
The complete printer command normally resides in the print control.
If characters belonging to the print command follow after the print control in the text (only useful for the HPL2
printer driver for PCL-5 printers), the text line following after the PRINT-CONTROL command should begin
with an equals sign (=) in the format column.

Example:
/: PRINT-CONTROL SESCP = *c5G
If you do not use the equals sign, a space character is inserted between the print control SESCP and the
character *c5G.
Different font on the same line
You can have different font on the same line by defining a character format.
For example B for bold text and U for Underline.
In your SAPScript apply like this :
<U>Underline Text</> <B>Bold Text</>
Print Footer notes only on the last page
Command to used in your sapscripts :/: IF &NEXTPAGE& EQ 0
whatever footer you want.
/: ENDIF
Orientations in SAPSCRIPT
-----Original Message----Subject: Orientations in SAPSCRIPT
From: Ashwini Jaokar
Hi,
I have 2 pages for a Form in SAPscript .
Can I have 2 different Orientations for 2 pages
Ie Can I assign Page1 as Portrait & page2 as Landscape ???
If so , How ????
Thanks in Advance.
Ashwini Jaokar.
-----Reply Message----Subject: Re: Orientations in SAPSCRIPT
From: jmersinger
Ashwini,
Not that I know of in the same layoutset...what you can do is create two layoutsets...one portrait, one
landscape...then in the print program call each one individually.
jjm

-----Reply Message----Subject: RE: Orientations in SAPSCRIPT


From: Ralph Klassen
Each form may only have a single orientation but you can create two forms and include them in the same
spool output.
In your ABAP program:
1. call function 'OPEN_FORM', don't pass a value in 'FORM'
2. call function 'START_FORM', include parameter 'FORM' passing the name of your first form
3. call function 'WRITE_FORM' as normal to output each element
4. call function 'END_FORM'
5. call function 'START_FORM', include parameter 'FORM' passing the name of your second form
6. call function 'WRITE_FORM' as normal to output each element
7. call function 'END_FORM'
8. call function 'CLOSE_FORM'
Repeat the 'START_FORM' ... 'END_FORM' sequence as required.
I have not tried using page numbers with this technique, I suspect that each form will restart at 1.
Regards,
Ralph Klassen Sylogist
-----End of Reply Message----Protect...Endprotect
-----Original Message----Subject: Protect...Endprotect
Hi,
Can anyone share what's a PROTECT...ENDPROTECT in
SAPScript form?
Thanks.
-----Reply Message----Subject: RE: Protect...Endprotect
hello!
While using Scripts, if u don't want to break a
paragraph text which aparts to another page
i.e. if u wanna display the paragraph with out

breaking in between two pages, u have to use


protect...endprotect.
all the best!
regards
-----End of Message-----

Retrieving data without modifying the original called program


*
* Retrieving data without modifying the original called program
*
* Put this script code in your sapscripts
* /: PERFORM GET_BARCODE IN PROGRAM ZSCRIPTPERFORM
* /: USING &PAGE&
* /: USING &NEXTPAGE&
* /: CHANGING &BARCODE&
* /: ENDPERFORM
* / &BARCODE&
*
* Submitted by : SAP Basis, ABAP Programming and Other IMG Stuff
*
http://www.sap-img.com
*
REPORT ZSCRIPTPERFORM.
FORM GET_BARCODE TABLES IN_PAR STRUCTURE ITCSY
OUT_PAR STRUCTURE ITCSY.
DATA: PAGNUM LIKE SY-TABIX, "page number
NEXTPAGE LIKE SY-TABIX. "number of next page
READ TABLE IN_PAR WITH KEY 'PAGE'.
CHECK SY-SUBRC = 0.
PAGNUM = IN_PAR-VALUE.
READ TABLE IN_PAR WITH KEY 'NEXTPAGE'.
CHECK SY-SUBRC = 0.
NEXTPAGE = IN_PAR-VALUE.
READ TABLE OUT_PAR WITH KEY 'BARCODE'.
CHECK SY-SUBRC = 0.
IF PAGNUM = 1.
OUT_PAR-VALUE = '|'. "First page
ELSE.
OUT_PAR-VALUE = '||'. "Next page
ENDIF.
IF NEXTPAGE = 0.
OUT_PAR-VALUE+2 = 'L'. "Flag: last page
ENDIF.
MODIFY OUT_PAR INDEX SY-TABIX.
ENDFORM.
*-- End of Program
SAPscripts How to calculate Totals and Subtotals

I have some doubs in BDC and SMART FORMS. I want to change the material number using the
transaction code MM02 through BDC.
In scripts and smartforms how to calculate totals and subtotals?
To calculate totals and sub totals in sap scripts you have to use subroutines.
Say if you have to add the unit price (KOMVD-KBERT) then in the main window whereever tat value is
picked write this routine
/: DEFINE &TOT_PRICE&
/: PERFORM F_GET_PRICE IN PROGRAM <subroutine prog name> /:USING &KOMVD-KBERT&
/:CHANGING &TOT_PRICE& /:ENDPERFORM
Then write the variable where ever you want it to be printed (mostly it will be in footer window)
Then create subroutine pool program and you have to write the code.
FORM F_GET_PRICE tables int_cond structure itcsy
outt_cond structure itcsy. data : value type kbert.
statics value1 type kbert.
Read int_cond table index 1.
value = int_cond-value.
value1 = value1 + value.
Read outt_cond table index 1.
outt_cond-value = value1.
Modify outt_cond index 1.
ENDFORM.
I have given a rough outline, please be aware of the variable conversions as Int_cond-value and outt_condvalue are characters.
SAPScripts - Developing SAPScript in different languages
Developing SAPScript in different languages
You can goto transaction SE63 and translate the scripts into different languages.
In SE63, click Translation -> Long Texts -> Sapscripts -> Forms
Those language you can convert to have already been pre-installed in the system.
SE63 is the best way to translate since it offers check options.
However, it does not mean that it is 100% full proof that everything is correct

How to convert Sapscript spools request to PDF?

SAP have created a standard program RSTXPDFT4 to convert your Sapscripts spools into a PDF format.
Specify the spool number and you will be able to download the sapscripts spool into your local harddisk.
It look exactly like what you see during a spool display.
Please note that it is not restricted to sapsciprts spool only. Any reports in the spool can be converted using
the program 'RSTXPDFT4'.

How to Upload graphics (IMAGE) to your Sapscript?


Command in your Sapscript
/: INCLUDE Z_YOUR_LOGO OBJECT TEXT ID ST LANGUAGE E
These are the steps to be followed for uploading graphics in R/3 system
1. First save the file as BMP
2. Open the BMP file in IMaging (Goto -> Programs -> Accessories -> Imaging) and
make it Zoom as 100% and save as *.TIFF
3. Open SE38 and execute program RSTXLDMC
4. Give your TIFF file path name
5. Select Bcol (for Color)
6. TEXT ID will be ZHEX-MACRO-*.
7. Inplace of * write your own logo name (ZCOMPANYLOGO)
8. Execute the program
9. Now Goto SE71 create your ZFORM
10. Create logo window
11. Goto text element of logo window
or
In 4.6x :1. Goto SE71 Change the mode to GRAPHICAL

2. Choose the Graph Tabstrips


3. Now type in some name for the LOGO WINDOW

4. Press the IMPORT BUTTON (third button from left) and then IMPORT the BMP file from your DESKTOP

5. The code will be written automatically. You just need to drag and drop wherever you want
the graphics to be.
/: INCLUDE Z_COMPANY_LOGO OBJECT GRAPHICS ID BMON LANGUAGE EN
Please note that in 4.6c onwards, you can also used Windows Bitmap file ( .BMP).
Import/Export SapScript form from PC file
How do you backup sapscript layout sets? Can you download and upload? How?
Use ABAP program: RSTXSCRP
It will download and upload your sapscripts as a text file in your local harddisk.
I want to copy SAP Script from one client (512) to client (500). How can I copy this SAP Script.
Login to Client (512)
Goto SE38 or SA38 and execute the abap program: RSTXSCRP
Mode : EXPORT
Login to Client (500)
Goto SE38 or SA38 and execute the abap program: RSTXSCRP
Mode : IMPORT
or
Login to Client (500)
Goto SE71 - Click Utilities - Copy from client

Is there a way that I can find where used list of a SAP Script?
I need to find the program that calls the particular form.
Solution:
Where used list for a sapscript would be difficult in cases where the script is called dynamically.
There is no way of finding the program name of SAP Script.
But you can get the program names from table TNAPR by passing the SAP Script name.
In cases where the script is configured via customising, then you can check it in TNAPR table by putting it in
FONAM field.
or
Also there is one more way of finding the Print Program Name for the specified Script.
Just Goto transaction SE71
--> Enter Form Name --> Display --> In Menu --> Form --> Check --> Texts --> Select Include Res --> Click
on click
This will give you the print program list for the specified SAP Script.
Also you can get the program name from NACE transaction.
Picture doesn't show in Print Preview
You have uploaded the picture as .TIF in Sap using ABAP RSTXLDMC and have also add the statement
/: INCLUDE ZHEX-SAMPLE-PICTURE OBJECT TEXT ID ST LANGUAGE EN
in your SapScript but the problem is that in print preview it's not displaying the picture.
It is normal that the picture doesn't show in print preview and you will be able to see the object only after
printing.
Don't let this bother you as long as the picture is shown on the hardcopy printout.
Delete Load program for SAPScript
Occassionally, when you make frequent changes to your SAPScript, the system can get out of sync.
When you view the form, the old data get display without your changes.

This can be fixed by deleting the SAPScript LOAD with program RSTXDELL.

Details information about SAP Barcodes


What I need to do to print a barcode in sapscript?
A barcode solution consists of the following:
- a barcode printer
- a barcode reader
- a mobile data collection application/program
A barcode label is a special symbology to represent human readable information such as a material number
or batch number
in machine readable format.
There are different symbologies for different applications and different industries. Luckily, you need not worry
to much about that as the logistics supply chain has mostly standardized on 3 of 9 and 128 barcode
symbologies - which all barcode readers support and which SAP support natively in it's printing protocols.
You can print barcodes from SAP by modifying an existing output form.
Behind every output form is a print program that collects all the data and then pass it to the form. The form
contains the layout as well as the font, line and paragraph formats. These forms are designed using
SAPScript (a very easy but frustratingly simplistic form format language) or SmartForms that is more of a
graphical form design tool.
Barcodes are nothing more than a font definition and is part of the style sheet associated with a particular
SAPScript form. The most important aspect is to place a parameter in the line of the form that points to the
data element that you want to represent as barcode on the form, i.e. material number. Next you need to set
the font for that parameter value to one of the supported barcode symbologies.
The next part of the equation can be a bit tricky as you will need to get a printer to print that barcode font.
Regular laser printers does not normally print barcode fonts, only specialized industrial printers that is
specifically designed to support that protocol and that uses specialized label media and heat transfer (resin)
ribbon to create the sharp image required for barcodes.
Not to fear though, there are two ways to get around this:
- You can have your IT department do some research most laser printers can accept a font cartridge/dimm chip (similar to computer memory), called a BarDIMM
that will allow a laser printer to support the printing of barcodes.
- Secondly, you can buy software that you can upload in your SAP print Server that will convert the
barcode symbology as an image that will print on a regular laser printer. I found that this option results in
less sharper barcodes. This option is really if you need to convert a large quantity of printers (>10) to support
barcodes.
- Thirdly, you can buy a third party software like Barcode.dll and install on your frontend PC connected
to the laser printer.
Now you have a barcode printed - what next?
Well there are two options, depending on your business requirements:
- You can use an existing SAP transaction on a regular workstation and get a barcode wedge reader to hook
up between the keyboard and the PC. These wedge readers comes in a wand or scanner format. There are
even wireless wedge scanners available that allows you to roam a few yards from the workstation to scan a
label. This approach is mostly used where you want to prevent human errors in typing in long material, batch
or serial numbers in receiving or issuing of material. The problem is that it's just replacing the keyboard input
and you are basically locked down in one location and have to bring all the material to that location to
process.
- Another solution is to use SAPConsole transactions

or write your own ABAP Dialog programs that will fit onto a barcode enabled wireless handheld terminal and
that will follow the business logic as executed on the shop floor.
These programs are highly complex exercises in industrial engineering and ergonomics because of the
limited screen sizes and limited ability to accept keyboard input. The user is instructed step-by-step and only
scan and push F-keys to interact with the SAP system. Scan, scan, beep, beep, enter - highly automated.
SapScript Question
1) How do you backup script layout sets?
2) What type of variables normally used in script to o/p data?
3) How do you use tabsets in layouts?
1) Use this Std program RSTXSCRP.
1) First Export to Presentation file(.doc).
2) Whenever you need that Export into SAP.
2) Normally we call them as Program symbols. Those are defined in Driver program. We can use in Script
as for exp. &itab-matnr&
Other variables ---System symbols : ex &page&
---Std symbols :
---Text symbols :We define them in script editor itself.
Ex : /: Define &mysymbol& = 'XX'
3) We can control the tab feed in a paragraph with tab positions. The tab stops us define in the paragraph
format replace the tab spacing we defined in the header data of the form. However, this depends on the
extent to which we have defined tab stops in the paragraph format. If there are fewer tabs in the paragraph
formats than in the header data, the tab stops of the header data are used for the rest of the line.
SAPscripts Tips by : Venkat O
Q: We get the total number of pages as expected by using 'SAPSCRIPT-FORMPAGES' in a duplex
layout. In our case duplex case is always 'Terms & Conditions'. We do not want the number of pages
as in duplex printing. What is the best possible solution?
A: On the Terms & Conditions page, Change the Page counter mode to 'HOLD' to keep the page counter
from incrementing when you print the Term & Conditions.
Q: Can I Print a logo on an Invoice?
A: Save a Logo using Paintshop Pro or Corel Draw as Tiff file. Use RSTXLDMC to convert the logo to
standard text in SapScript. When the program is executed, the path and file name have to be correctly
specified.
Process could be like the following:
Run RSTXLDMC
Enter file name C:\MAIL\COMPLOGO.TIF
Resolution for Tiff file
Absolute X-position
Absolute Y-position
Absolute positioning
Reserved height
Shift to right
UOM = CM
Text title
Line width for text = 132
Text name ZHEX-MACRO-COMPLOGO
Text ID ST

Text language = E
Postscript scaling
Width & Height according to PS scaling
Number of Tiff gray levels (2,4,9) 2
Then Create a new window 'COMP' with attributes;
Window COMP description Company Logo
Window type CONST
Left margin 7.00 CH window width 10.00 CH
Upper margin LN window height 8.00 LN
Finally in the text element , mention
/: INCLUDE 'ZHEX-MACRO-COMPLOGO' OBJECT TEXT ID ST LANGUAGE 'E'.
Please note that if object name is not indicated as 'ZHEX...', the logo may not be printed!
You will not be able to see the logo in a test print. The same will be printed in actual printout.
If you are using two logos in the same layout, the names of the logos should be unique. Say 'ZHEXMACRO-LOGO1' and 'ZHEX-MACRO-LOGO2'. Else all the information will be overwritten.
If the logo is not EXACTLY TIFF 6.0, the same will not be printed.
What is the difference between a script & a report ?
Script is a form which has a layout set as per the company standards and can be used for external use too.
Generally reports are designed for internal use for in house users
What are the components/elements/layout sets in sap script ?
Layout set and Print program and the layout set has windows in it.
Components of scripts:
Layout sets, SAPScripts text, ABAP print program, symbols, function module like open form, start form, write
form, etc....
Layout sets of scripts are:
Header data, paragraph formats, charcter formats, windows, page windows, pages.
Can you create a script with out a main window ?
No
How many main windows can be created for a script ?
99
How can we use tables in sap scripts?
We can access structures and the tables tat are updated during runtime. Else you have to pass the structure
values to the table in the print program.
How to print a logo in a sap script?
Upolad in the R3 using Se78 and use the Include statement in the script.
When we need to modify standard scripts (eg:medruck) given by sap?
When the client goes for customization of the form
What is the use of transaction code NACE in sap scripts?
You can track the form and the print program used for that form
What is the table name that will contain all the script form names and print program names?
TNAPR

Can you assign your own form to a standard print program? how?
Yes. thru NACE
What is the use of PROTECT & ENDPROTECT?
Keeps the block of text in the same page.
How to add extra functionality to a standard print program with out touching the print program?
Thru subroutine programs
What is sub routine pool in sap script? when it is used?
Its an Abap prog of type sub routine pool, it is used for calculating certain variables, eg DUE date for an
Invoice. You pass the values from the form thru ITCSY structure intot he prgram.
How to read text in sapscripts?
SO10
What is the difference between paragraph & character format?
Self explanatory definition
How to use a sapscript for multiple languages ?
(english, germany etc) Copy the script in each lang or you have an option to click 'TO all Languages'
How to download/upload sapscripts from & to your PC ?
SE78 or RSTXLDMC
What is the difference between scripts & smart forms?
Scripts are client-dependent but SF are client Independent
Sapscripts and abap programs are client dependent or not? Why?
Scripts are client dependent. / Reports are client Independent.
What is the transaction code for logo uploading?
SE78
What is the standard program used for uploading the logo to script?
RSTXLDMC FM to upload image in tiff format.
How can you send forms from one client to other?
SE71, Utilities -> Copy from client...
What does open_form, write_form, close_form do?
Again its self-explanatory
What is the diffrence between open_form and close_form?
open_form is used to open the form/initiate the form.
close_form is used to conclude the open_form.
How to convert a sapscript to smart form?
tcode SMARTFORMS, I think its menu Utilities you have an option.. Migrate Scripts to Smartforms.
How to send a smartform result through mail?
I think you have to configure the output type. Not sure..
How to select desired paper size in sapscript?
In Basic settings.

How to print the Page Nos in Forms. Every page I want to print 1 of 10 , 2 of 10 , 3 of 0 ...etc.
PAGE &PAGE& OF &SAPSCRIPT-FORMPAGES& *-- Nitin
How to debugg a script?
This can done in two ways:
In the form Utilities->debugger / RSTXDBUG FM for debugging script
The Procedure for debugging SAP script is:
Generally SAP script contains the Layout and corresponding print program.
First go to SE71 and enter ur script name. In the same screen go to Utilities->click on activate debugger
option.
Now go to SE 38 and enter ur Print Program name and execute the program.
Now you can debug the script Page wise and window wise.
Questions on PO SapScripts MEDRUCK
1. When do you modified MEDRUCK? ( IF I SAID I HAVE WORKED ON SCRIPTS).
Generally, we modify existing sap scripts provided by SAP rather than creating one. Unless you have to do
something new for your client like Labels or Packaging card, etc., MEDRUCK is the form for PO.
2. I want to know the procedure to create a purchase order using MEDRUCK.
You don't create a PO using MEDRUCK. MEDRUCK is the form used to print a PO that has been created.
3. What are the usual changes to be done on MEDRUCK?
Goto SE71, there is an option in Utilities as COPY ffrom Source client (000). Copy the from MEDRUCK into
a Zname form. The common changes wud b inserting a logo, using Std text for Terms and Conditions,
alignment of windows as per client requirement, get xtra data if client is asking for somethign more.
4. How can I access my data from DB to SCRIPTS?
There are structures used in Scripts which hold the data entered by the user. These structures are used to
get data from Database.
5. Please send me the one examples in full length.
Look at MEDRUCK form and it would have a print program. you can find in tcode NACE.
Create Scripts Of Your Own Using Standard Scripts
The folloiwng info may be useful for those who are new to SAP:
All Standard Scripts are in client '000'.
We have to copy them to '800'. (this is your own company define client no)
All Standard Scripts and their respective print programs are listed in table 'TNAPR'.
Ex: FORM MEDRUCK has the Driver Program SAPFM06P.
NOTE: Never make any changes to the Standard Driver Programs
STEP 1.
---------Goto Transaction Code <SE71> and
select from Menu UTILITIES ->Copy from Client.
Enter the Standard Form Name, It source Client 000 and the target Form Name that you want it to be saved
as on your client.

Say you are naming it as zmedruck1.


Click on EXECUTE.
STEP 2.
--------Converting form to English.
Open zmedruck1 in <SE71> With language DE.
Then goto UTILITIES -> Convert Original Language from DE to EN.
Then you can modify the layout for example, chaging the logo, or changing the headers, or adding any new
code to do some calculation etc.,
SAVE THE CHANGES AND ACTIVATE.
Then select from the menu FORM -> CHECK -> TEXT.
SELECT your driver program name from the list adn click on COPY.
If you don't see the program name in the list then click on
'APPEND PRINT PROGRAM' and add your program name and then select it from the list and click on
COPY.
STEP 3: Assigning our form to the standard print program.
----------Start Tr.Code <NACE>.
In our present case since we are working on 'Purchase order' we have to select EF and click on the button
Output Types.
Then on Right hand side, scroll down and select NEU - New P O Printout.
(This may change for different programs).
Then Double click on Processing Routines on Left hand side.
Change from Display -> Change Mode.
Give your form name (zmedruck1) for printoutput and SAVE.
STEP 4:
---------Start Tr.Code <ME22N> since you are working on Purchase order and click on print Preview to make sure
your layout etc., changes are OK. If not again you have to make the changes accordingly.
A Sample SAP Scripts Reports
Author: Mona
CALL FUNCTION 'OPEN_FORM'
* EXPORTING
* APPLICATION
= 'TX'
* ARCHIVE_INDEX
=
* ARCHIVE_PARAMS
=
* DEVICE
= 'PRINTER'
* DIALOG
= 'X'
* FORM
= 'ZSCRIPT1'
* LANGUAGE
= SY-LANGU
* OPTIONS
=
* MAIL_SENDER
=
* MAIL_RECIPIENT
=
* MAIL_APPL_OBJECT
=
* RAW_DATA_INTERFACE
= '*'
* SPONUMIV
=
* IMPORTING
* LANGUAGE
=
* NEW_ARCHIVE_PARAMS
=
* RESULT
=
EXCEPTIONS
CANCELED
=1
DEVICE
=2
FORM
=3
OPTIONS
=4

UNCLOSED
=5
MAIL_OPTIONS
=6
ARCHIVE_ERROR
=7
INVALID_FAX_NUMBER
=8
MORE_PARAMS_NEEDED_IN_BATCH
=9
SPOOL_ERROR
= 10
CODEPAGE
= 11
OTHERS
= 12
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'START_FORM'
EXPORTING
* ARCHIVE_INDEX
=
FORM
= 'ZFORM1'
* LANGUAGE
=''
* STARTPAGE
= 'X'
PROGRAM
= 'ZSCRIPT1'
* MAIL_APPL_OBJECT
=
* IMPORTING
* LANGUAGE
=
* EXCEPTIONS
* FORM
=1
* FORMAT
=2
* UNENDED
=3
* UNOPENED
=4
* UNUSED
=5
* SPOOL_ERROR
=6
* CODEPAGE
=7
* OTHERS
=8
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
* ELEMENT
=''
* FUNCTION
= 'SET'
* TYPE
= 'BODY'
WINDOW
= 'HEADER'
* IMPORTING
* PENDING_LINES
=
EXCEPTIONS
ELEMENT
=1
FUNCTION
=2
TYPE
=3
UNOPENED
=4
UNSTARTED
=5
WINDOW
=6
BAD_PAGEFORMAT_FOR_PRINT
=7
SPOOL_ERROR
=8
OTHERS
=9
.
IF SY-SUBRC <> 0.
write:/ 'ERROR IN HEADER'.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
* ELEMENT
=''
* FUNCTION
= 'SET'
* TYPE
= 'BODY'
WINDOW
= 'MAIN'
* IMPORTING
* PENDING_LINES
=
EXCEPTIONS
ELEMENT
=1
FUNCTION
=2
TYPE
=3
UNOPENED
=4
UNSTARTED
=5
WINDOW
=6
BAD_PAGEFORMAT_FOR_PRINT
SPOOL_ERROR
=8
OTHERS
=9
.
IF SY-SUBRC <> 0.
write:/ 'ERROR IN HEADER'.

=7

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO


*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
* ELEMENT
=''
* FUNCTION
= 'SET'
* TYPE
= 'BODY'
WINDOW
= 'FOOTER'
* IMPORTING
* PENDING_LINES
=
EXCEPTIONS
ELEMENT
=1
FUNCTION
=2
TYPE
=3
UNOPENED
=4
UNSTARTED
=5
WINDOW
=6
BAD_PAGEFORMAT_FOR_PRINT
=7
SPOOL_ERROR
=8
OTHERS
=9
.
IF SY-SUBRC <> 0.
write:/ 'ERROR IN HEADER'.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'END_FORM'
* IMPORTING
* RESULT
=
* EXCEPTIONS
* UNOPENED
=1
* BAD_PAGEFORMAT_FOR_PRINT
* SPOOL_ERROR
=3

=2

* CODEPAGE
* OTHERS
.

=4
=5

CALL FUNCTION 'CLOSE_FORM'


* IMPORTING
* RESULT
=
* RDI_RESULT
=
* TABLES
* OTFDATA
=
* EXCEPTIONS
* UNOPENED
=1
* BAD_PAGEFORMAT_FOR_PRINT
=2
* SEND_ERROR
=3
* SPOOL_ERROR
=4
* CODEPAGE
=5
* OTHERS
=6
.
Can you explain the difference between
1.open_form and Start form
2.end_form and Close_form.
whether all 4 modules are required in the driver pgm .
Open_form => It assign the form and printer, It should be first.
Start_form => It start Writing mode. You can use write_form in loop to write more than one lines befor
End_form.
End_form => It end writing mode of current page and will require to start again through Start_form.
Close_form=> it end the Form. After this you can not start again for created file.
Sample Sapscripts Label Printing Program
TABLES : ZPACK,ZTRN.
DATA: BEGIN OF ITAB OCCURS 0,
ZPKSLIP_NO LIKE ZTRN-ZPKSLIP_NO,
ZCARTON_NO LIKE ZPACK-ZCARTON_NO,
END OF ITAB.
DATA MVAR(12) TYPE C.
DATA MCTR(6) TYPE C.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: ZSLIP FOR ZTRN-ZPKSLIP_NO NO-EXTENSION NO INTERVALS
OBLIGATORY default 6.
SELECTION-SCREEN END OF BLOCK B1.
SELECT * FROM ZPACK INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE
ZPKSLIP_NO EQ ZSLIP-LOW .
CALL FUNCTION 'OPEN_FORM'
EXPORTING
FORM = 'ZTEST_RAJ'.
DO 4 TIMES.

MCTR = 100000 + SY-INDEX.


MCTR = MCTR+1(5).
CONCATENATE '55C/06/' MCTR INTO MVAR.
DO 80 TIMES.
ITAB-ZPKSLIP_NO = MVAR.
ITAB-ZCARTON_NO = SY-INDEX.
APPEND ITAB.
CLEAR ITAB.
ENDDO.
ENDDO.
SORT ITAB BY ZPKSLIP_NO ZCARTON_NO.
CALL FUNCTION 'START_FORM'
EXPORTING
FORM = 'ZTEST_RAJ'.
LOOP AT ITAB.
AT NEW ZPKSLIP_NO.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT = '101'
WINDOW = 'MAIN'.
ENDAT.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT = '102'
WINDOW = 'MAIN'.
AT END OF ZPKSLIP_NO.
CALL FUNCTION 'END_FORM'.
CALL FUNCTION 'START_FORM'
EXPORTING
FORM = 'ZTEST_RAJ'.
ENDAT.
ENDLOOP.
CALL FUNCTION 'END_FORM'.
CALL FUNCTION 'CLOSE_FORM'.

In sap script write :


/E 101
P1 ,,&ITAB-ZPKSLIP_NO(R)&
P1

/E 102
P1 ,,&ITAB-ZCARTON_NO(R)&
Introduction to SAP SmartForms
What is SAP Smart Forms?
SAP Smart Forms is introduced in SAP Basis Release 4.6C as the tool for creating and maintaining forms.
SAP Smart Forms allow you to execute simple modifications to the form and in the form logic by using
simple graphical tools; in 90% of all cases, this won't include any programming effort. Thus, a power user
without any programming knowledge can
configure forms with data from an SAP System for the relevant business processes.
To print a form, you need a program for data retrieval and a Smart Form that contains the entire from logic.
As data retrieval and form logic are separated, you must only adapt the Smart Form if changes to the form
logic are necessary. The application program passes the data via a function module interface to the
Smart Form. When activating the Smart Form, the system automatically generates a function module.
At runtime, the system processes this function module.
You can insert static and dynamic tables. This includes line feeds in individual table cells, triggering events
for table headings and subtotals, and sorting data before output.
You can check individual nodes as well as the entire form and find any existing errors in the tree structure.
The data flow analysis checks whether all fields (variables) have a defined value at the moment they are
displayed.
SAP Smart Forms allow you to include graphics, which you can display either as part of the form or as
background graphics. You use background graphics to copy the layout of an existing (scanned) form or to
lend forms a company-specific look. During printout, you can suppress the background graphic, if desired.
SAP Smart Forms also support postage optimizing.
Also read SAP Note No. 168368 - Smart Forms: New form tool in Release 4.6C
What Transaction to start SAP Smart Forms?
Execute transaction SMARTFORMS to start SAP Smart Forms.
Key Benefits of SAP Smart Forms:
SAP Smart Forms allows you to reduce considerably the implementation costs of mySAP.com solutions
since forms can be adjusted in minimum time.
You design a form using the graphical Form Painter and the graphical Table Painter. The form logic is
represented by a hierarchy structure (tree structure) that consists of individual nodes, such as nodes for
global settings, nodes for texts, nodes for output tables, or nodes for graphics.
To make changes, use Drag & Drop, Copy & Paste, and select different attributes.
These actions do not include writing of coding lines or using a Script language.
Using your form description maintained in the Form Builder, Smart Forms generates a function module that
encapsulates layout, content and form logic. So you do not need a group of function modules to print
a form, but only one.
For Web publishing, the system provides a generated XML output of the processed form.

Smart Forms provides a data stream called XML for Smart Forms (XSF) to allow the use of 3rd party printing
tools. XSF passes form content from R/3 to an external product without passing any layout information about
the Smart Form.
Advantages of SAP Smart Forms
SAP Smart Forms have the following advantages:
1. The adaption of forms is supported to a large extent by graphic tools for layout and logic, so that no
programming knowledge is necessary (at least 90% of all adjustments). Therefore, power user forms can
also make configurations for your business processes with data from an SAP system. Consultants are only
required in special cases.
2. Displaying table structures (dynamic framing of texts)
3. Output of background graphics, for form design in particular the use of templates which were scanned.
4. Colored output of texts
5. User-friendly and integrated Form Painter for the graphical design of forms
6. Graphical Table Painter for drawing tables
7. Reusing Font and paragraph formats in forms (Smart Styles)
8. Data interface in XML format (XML for Smart Forms, in short XSF)
9. Form translation is supported by standard translation tools
10. Flexible reuse of text modules
11. HTML output of forms (Basis release 6.10)
12. Interactive Web forms with input fields, pushbuttons, radio buttons, etc. (Basis-Release 6.10)
A Simple Smartform Tutorial
SAP Smartforms can be used for creating and maintaining forms for mass printing in SAP Systems. The
output medium for Smartforms support printer, fax, e-mail, or the Internet (by using the generated XML
output).
According to SAP, you need neither have any programming knowledge nor use a Script language to adapt
standard forms. However, basic ABAP programming skills are required only in special cases (for example, to
call a function module you created or for complex and extensive conditions).
1. Create a new smartforms
Transaction code SMARTFORMS
Create new smartforms call ZSMART
2. Define looping process for internal table
Pages and windows
First Page -> Header Window (Cursor at First Page then click Edit -> Node -> Create)
Here, you can specify your title and page numbering
&SFSY-PAGE& (Page 1) of &SFSY-FORMPAGES(Z4.0)& (Total Page)
Main windows -> TABLE -> DATA

In the Loop section, tick Internal table and fill in


ITAB1 (table in ABAP SMARTFORM calling function) INTO ITAB2

3. Define table in smartforms


Global settings :
Form interface
Variable name Type assignment Reference type
ITAB1
TYPE
Table Structure
Global definitions
Variable name Type assignment Reference type
ITAB2
TYPE
Table Structure
4. To display the data in the form
Make used of the Table Painter and declare the Line Type in Tabstrips Table
e.g. HD_GEN for printing header details,
IT_GEN for printing data details.
You have to specify the Line Type in your Text elements in the Tabstrips Output options.
Tick the New Line and specify the Line Type for outputting the data.
Declare your output fields in Text elements
Tabstrips - Output Options
For different fonts use this Style : IDWTCERTSTYLE
For Quantity or Amout you can used this variable &GS_ITAB-AMOUNT(12.2)&
5. Calling SMARTFORMS from your ABAP program
REPORT ZSMARTFORM.
* Calling SMARTFORMS from your ABAP program.
* Collecting all the table data in your program, and pass once to SMARTFORMS
* SMARTFORMS
* Declare your table type in :* Global Settings -> Form Interface
* Global Definintions -> Global Data
* Main Window -> Table -> DATA
*
* Written by : SAP Hints and Tips on Configuration and ABAP/4 Programming
*
http://sapr3.tripod.com
*
TABLES: MKPF.
DATA: FM_NAME TYPE RS38L_FNAM.
DATA: BEGIN OF INT_MKPF OCCURS 0.
INCLUDE STRUCTURE MKPF.
DATA: END OF INT_MKPF.
SELECT-OPTIONS S_MBLNR FOR MKPF-MBLNR MEMORY ID 001.
SELECT * FROM MKPF WHERE MBLNR IN S_MBLNR.
MOVE-CORRESPONDING MKPF TO INT_MKPF.
APPEND INT_MKPF.
ENDSELECT.

* At the end of your program.


* Passing data to SMARTFORMS
call function 'SSF_FUNCTION_MODULE_NAME'
exporting
formname
= 'ZSMARTFORM'
* VARIANT
=''
* DIRECT_CALL
=''
IMPORTING
FM_NAME
= FM_NAME
EXCEPTIONS
NO_FORM
=1
NO_FUNCTION_MODULE
=2
OTHERS
= 3.
if sy-subrc <> 0.
WRITE: / 'ERROR 1'.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
call function FM_NAME
* EXPORTING
* ARCHIVE_INDEX
=
* ARCHIVE_INDEX_TAB
=
* ARCHIVE_PARAMETERS
=
* CONTROL_PARAMETERS
=
* MAIL_APPL_OBJ
=
* MAIL_RECIPIENT
=
* MAIL_SENDER
=
* OUTPUT_OPTIONS
=
* USER_SETTINGS
= 'X'
* IMPORTING
* DOCUMENT_OUTPUT_INFO
=
* JOB_OUTPUT_INFO
=
* JOB_OUTPUT_OPTIONS
=
TABLES
GS_MKPF
= INT_MKPF
EXCEPTIONS
FORMATTING_ERROR
=1
INTERNAL_ERROR
=2
SEND_ERROR
=3
USER_CANCELED
=4
OTHERS
= 5.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.

Additional Fonts for your SMARTFORMS


You can create additional fonts and style with transaction SMARTSTYLES
This can then be define in the paragraph and character formats, which you can then be assign to texts and
fields in the Smart Form.
The character formats includes effects such as superscript, subscript, barcode and font attributes.

Difference with SMARTFORMS vs. SapScript (SE71)


The Following are the differences :a) Multiple page formats are possible in smartforms which is not the case in SAPScripts
b) It is possible to have a smartform without a main window .
c) Labels cannot be created in smartforms.
d) Routines can be written in smartforms tool.
e) Smartforms generates a function module when activated.
Contributed by : SAP ABAP/4 Programming, Basis Administration, Configuration Hints and Tips

f) Unlike sapscripts (RSTXSCRP), you cannot upload/download Smartform to your local harddisk.
It was said that it was provided in CRM 3.0 version, but not available in R/3. You can download smartforms
into Local PC in a XML format. In the same way you can upload this XML format into Smartform. From the
smartform editor itself you can call download option, if you are working in CRM 3.0 environment.
In R3 also, you can download into XML format. However, it's not sure about uploading. Refer to the program
'SF_XSF_DEMO'.
In 4.7 Enterprise, other have seen this utlity which is completey missing in 4.6c. There is functionality to
downlaod a complete form or only a particular node. (Utilities -> Download form). It will create a XML file
and save it in the hard disk.
For others, if you want to download/upload the Smartforms source, you will need the help from the
Basis people. What you can do is to create a Transport and then FTP down to your local harddisk.
When you need the Smartform source in another system, you have FTP up the Smartforms file back
to the SAP server. Finally, the Basis team, will tp it into your system.
g) The protect and endprotect command in sapscript doesn't work with smartforms. For example on a
invoice: First data of position no 80. is printed on page one, other data of position no 80 is printed on page 2.
And there's nothing you can do about it. Actually, there is something you can do about it. By using a folder
node and checking the 'protect' checkbox, everything in that folder will be page protected.
i) The main difference is that SAP script is client-dependant, while smartform is independent. Also there are
some advanced and intreractive features available in smartforms.
You can use an External subroutine-call in sapscript editor like:
/: perform <form_name> in program <program_name>
/: using <var1>
/: using <var2>
.
.
/: changing <return1>
/: changing <return2>
/:endperform \

FAQ on Migrating SAPscript to SmartForms


Is it possible to migrate a SAPscript form to a Smart Form?
Smart Forms provides a migration tool for this purpose which migrates layout and texts of a SAPscript form
to a Smart Form. It does not migrate SAPscript form logic of the print program. Using Smart Forms, this logic
is described by the tree structure of the Form Builder. The effort involved in migrating it depends on the
complexity of the print program.
Which Basis Release do I need to use SAP Smart Forms?
SAP Smart Forms is available as of R/3 Basis Release 4.6C.
I have heard that Smart Forms replaces SAPscript. What does "replace" mean?
It does not mean that SAPscript is removed from the Basis shipment. Even as of Basis Release 4.6C,
SAPscript remains part of the SAP standard and there are no plans to remove it. Since Smart Forms is
currently, and will continue to be, the tool for form maintenance for mySAP.com solutions, our further
development efforts will focus on Smart Forms, not on SAPscript.
Do we have to migrate all SAPscript forms to Smart Forms?
There is no point in migrating all SAPscript forms already in use. Since SAPscript can still be used and will
be available in the future, there is no need to. If you plan to migrate a SAPscript form, it is recommended
that you check whether benefit is worth the effort involved.
Conversion of SAPSCRIPT to SMARTFORMS
SAP provides a conversion for SAPscript documents to SMARTforms.
This is basically a function module, called FB_MIGRATE_FORM. You can start this function module by
hand (via SE37), or create a small ABAP which migrates all SAPscript forms automatically.
You can also do this one-by-one in transaction SMARTFORMS, under
Utilities -> Migrate SAPscript form.
You could also write a small batch program calling transaction SMARTFORMS and running the migration
tool.
SmartForms System Fields
Within a form you can use the field string SFSY with its system fields. During form processing the system
replaces these fields with the corresponding values. The field values come from the SAP System or are
results of the processing.
System fields of Smart Forms
&SFSY-DATE&
Displays the date. You determine the display format in the user master record.
&SFSY-TIME&
Displays the time of day in the form HH:MM:SS.

&SFSY-PAGE&
Inserts the number of the current print page into the text. You determine the format of the page number (for
example, Arabic, numeric) in the page node.
&SFSY-FORMPAGES&
Displays the total number of pages for the currently processed form. This allows you to include texts such
as'Page x of y' into your output.
&SFSY-JOBPAGES&
Contains the total page number of all forms in the currently processed print request.
&SFSY-WINDOWNAME&
Contains the name of the current window (string in the Window field)
&SFSY-PAGENAME&
Contains the name of the current page (string in the Page field)
&SFSY-PAGEBREAK&
Is set to 'X' after a page break (either automatic [Page 7] or command-controlled [Page 46])
&SFSY-MAINEND&
Is set as soon as processing of the main window on the current page ends
&SFSY-EXCEPTION&
Contains the name of the raised exception. You must trigger your own exceptions, which you defined in the
form interface, using the user_exception macro (syntax: user_exception <exception name >).
Example Forms Available in Standard SAP R/3
SF_EXAMPLE_01
Simple example; invoice with table output of flight booking for one customer
SF_EXAMPLE_02
Similar to SF_EXAMPLE_01 but with subtotals
SF_EXAMPLE_03
Similar to SF_EXAMPLE_02, whereby several customers are selected in the application program; the form
is called for each customer and all form outputs are included in an output request
A Sample Program Calling Smartforms
With Compliments by: Ambekar, Abhijeet
You should use 'SSF_FUNCTION_MODULE_NAME' & call function fm_name in your program & not others.
*&---------------------------------------------------------------------*
*& Report ZTACA_DRIVER_SMARTFORM
*&
*
*&---------------------------------------------------------------------*
*&
*
*&
*
*&---------------------------------------------------------------------*
REPORT ZTACA_DRIVER_SMARTFORM
Tables : sflight.
Data : fm_name TYPE rs38l_fnam.

*data : Begin of it_flttab occurs 0,


*
carrid type sflight-carrid,
*
connid type sflight-connid,
*
fldate type sflight-fldate,
*
seatsmax type sflight-seatsmax,
*
seatsocc type sflight-seatsocc,
*
End of it_flttab.
data : it_flttab like table of sflight.
Data : g_salary type i .
*
it_flttab type standard table of ty_flt.
g_salary = 1000.
select carrid connid fldate seatsmax seatsocc from sflight into
corresponding fields of table it_flttab.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname
= 'ZTACA_SMFORM2'
* VARIANT
=''
* DIRECT_CALL
=''
IMPORTING
FM_NAME
= fm_name
EXCEPTIONS
NO_FORM
=1
NO_FUNCTION_MODULE
=2
OTHERS
=3
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
call function fm_name
Exporting
salary = g_salary
TABLES
it_flttab = it_flttab
EXCEPTIONS
FORMATTING_ERROR
=1
INTERNAL_ERROR
=2
SEND_ERROR
=3
USER_CANCELED
=4
OTHERS
=5
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Search For Standard or Customise Smartform
*&---------------------------------------------------------------------*
*& Report
: ZTEST_SEARCH_FORMNAME
*
*& Created by : SHYAM BABU SAH.
*& date
: 17.01 2007.
*
*&---------------------------------------------------------------------*
*& This program will help you to search the SMARTFORM either Standard
* Or Customer created in your compatiable language.
*
*

*&---------------------------------------------------------------------*
REPORT ZTEST_SEARCH_FORMNAME .
TYPE-POOLS: SLIS.
TABLES: STXFADM, STXFADMT.
DATA: BEGIN OF ITAB OCCURS 0,
FORMNAME LIKE STXFADM-FORMNAME,
MASTERLANG LIKE STXFADM-MASTERLANG,
DEVCLASS LIKE STXFADM-DEVCLASS,
VERSION
LIKE STXFADM-VERSION,
FIRSTUSER LIKE STXFADM-FIRSTUSER,
FIRSTDATE LIKE STXFADM-FIRSTDATE,
FIRSTTIME LIKE STXFADM-FIRSTTIME,
LASTUSER LIKE STXFADM-LASTUSER,
LASTDATE LIKE STXFADM-LASTDATE,
FORMTYPE LIKE STXFADM-FORMTYPE,
CAPTION
LIKE STXFADMT-CAPTION,
END OF ITAB.
DATA: IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_DEV FOR STXFADM-DEVCLASS NO INTERVALS.
SELECT-OPTIONS: S_FORM FOR STXFADM-FORMNAME NO INTERVALS.
SELECTION-SCREEN SKIP 1.
PARAMETERS: P_LANG LIKE T002-SPRAS DEFAULT 'EN'.
SELECTION-SCREEN END OF BLOCK B1.
PERFORM F_SELECT_DATA.
PERFORM F_LAYOUT.
PERFORM F_FIELDCAT.
PERFORM DISPLAY.
*&---------------------------------------------------------------------*
*&
Form f_select_data
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM F_SELECT_DATA .
SELECT
A~FORMNAME
A~MASTERLANG
A~DEVCLASS
A~VERSION
A~FIRSTUSER
A~FIRSTDATE
A~FIRSTTIME
A~LASTUSER
A~LASTDATE
A~FORMTYPE
B~CAPTION
FROM STXFADM AS A INNER JOIN STXFADMT AS B ON
A~FORMNAME = B~FORMNAME INTO TABLE ITAB WHERE
A~DEVCLASS IN S_DEV AND
A~FORMNAME IN S_FORM AND
B~LANGU = P_LANG.
IF SY-SUBRC = 0.
SORT ITAB BY FORMNAME.
ELSE.

MESSAGE I398(00) WITH 'No Form Exits for this selection criteria'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM.
" f_select_data
*&---------------------------------------------------------------------*
*&
Form display
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM DISPLAY .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SYST-CPROG
IS_LAYOUT
= WA_LAYOUT
IT_FIELDCAT
= IT_FIELDCAT
TABLES
T_OUTTAB
= ITAB.
IF SY-SUBRC <> 0.
ENDIF.
ENDFORM.
" display
*&---------------------------------------------------------------------*
*&
Form f_fieldcat
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM F_FIELDCAT .
DATA: WA_COL TYPE I VALUE 1.
WA_FIELDCAT-COL_POS = WA_COL + 1.
WA_FIELDCAT-SELTEXT_L = TEXT-003. " Form Name
WA_FIELDCAT-FIELDNAME = 'FORMNAME'.
WA_FIELDCAT-TABNAME = 'ITAB'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-COL_POS = WA_COL + 1.
WA_FIELDCAT-SELTEXT_L = TEXT-004. " Smart form Text
WA_FIELDCAT-FIELDNAME = 'CAPTION'.
WA_FIELDCAT-TABNAME = 'ITAB'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-COL_POS = WA_COL + 1.
WA_FIELDCAT-SELTEXT_L = TEXT-005. "Package
WA_FIELDCAT-FIELDNAME = 'DEVCLASS'.
WA_FIELDCAT-TABNAME = 'ITAB'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-COL_POS = WA_COL + 1.
WA_FIELDCAT-SELTEXT_L = TEXT-006. "First User
WA_FIELDCAT-FIELDNAME = 'FIRSTUSER'.
WA_FIELDCAT-TABNAME = 'ITAB'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.


CLEAR WA_FIELDCAT.
WA_FIELDCAT-COL_POS = WA_COL + 1.
WA_FIELDCAT-SELTEXT_L = TEXT-007. "First Date
WA_FIELDCAT-FIELDNAME = 'FIRSTDATE'.
WA_FIELDCAT-TABNAME = 'ITAB'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-COL_POS = WA_COL + 1.
WA_FIELDCAT-SELTEXT_L = TEXT-008. "Version
WA_FIELDCAT-FIELDNAME = 'VERSION'.
WA_FIELDCAT-TABNAME = 'ITAB'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-COL_POS = WA_COL + 1.
WA_FIELDCAT-SELTEXT_L = TEXT-009. "Master Language
WA_FIELDCAT-FIELDNAME = 'MASTERLANG'.
WA_FIELDCAT-TABNAME = 'ITAB'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-COL_POS = WA_COL + 1.
WA_FIELDCAT-SELTEXT_L = TEXT-010. "Last User
WA_FIELDCAT-FIELDNAME = 'LASTUSER'.
WA_FIELDCAT-TABNAME = 'ITAB'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
ENDFORM.
" f_fieldcat
*&---------------------------------------------------------------------*
*&
Form f_layout
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM F_LAYOUT .
WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
ENDFORM.
" f_layout
Smart forms Frequently Asked Questions
Forcing a page break within table loop
Create a loop around the table. Put a Command node before the table in the loop that forces a NEWPAGE
on whatever condition you want. Then only loop through a subset of the internal table (based on the
conditions in the Command node) of the elements in the Table node.
Font style and Font size
Goto Transaction SMARTSTYLES.
There you can create Paragraph formats etc just like in sapscript.

Then in your window under OUTPUT OPTIONS you include this SMARTSTYLE and use the Paragraph and
character formats.
Line in Smartform
Either you can use a window that takes up the width of your page and only has a height of 1 mm.
Then you put a frame around it (in window output options).
Thus you have drawn a box but it looks like a line.
Or you can just draw "__" accross the page and play with the fonts so that it joins each UNDER_SCORE.
Difference between 'forminterface' and 'global definitions' in global settings of smart forms
The Difference is as follows.
To put it very simply:
Form Interface is where you declare what must be passed in and out of the smartform (in from the print
program to the smartform and out from the smartform to the print program).
Global defs. is where you declare data to be used within the smartform on a global scope.
ie: anything you declare here can be used in any other node in the form.
Smartforms function module name
Once you have activated the smartform, go to the environment -> function module name. There you can get
the name of funtion module name.
The key thing is the program that calls it. for instance, the invoice SMARTFORM LB_BIL_INVOICE is ran by
the program RLB_INVOICE.
This program uses another FM to determine the name of the FM to use itself. The key thing is that when it
calls this FM (using a variable to store the actual name), that the parameters match the paramters in your
smartform.
Another thing to note is that the FM name will change wherever the SF is transported to.
So you need to use the FM to determine the name of the SF.
Here is the code that can be use to determine the internal name of the function module:
Code:
if sf_label(1) <> '/'. " need to resolve by name
move sf_label to externalname.
call function 'SSF_FUNCTION_MODULE_NAME'
exporting
formname
= externalname
importing
fm_name
= internalname
exceptions
no_form
=1
no_function_module = 2
others
= 3.
if sy-subrc <> 0.

message 'e427'.
endif.
move internalname to sf_label.
endif.
It checks to see if the sf_label starts with a '/', which is how the internal names start. if it does, the name has
already been converted. If not, it calls the FM and converts the name.
You would then CALL FUNCTION sf_label.
Smartforms FAQ Part Two
Smartforms output difference
Problem with Smartforms: in a certain form for two differently configured printers, there seem to be
a difference in the output of characters per inch (the distance between characters which gives a
layout problem - text in two lines instead of one.
It happens when the two printers having different Printer Controls' if you go to SPAD Menu (Spool
Administrator Menu) you can see the difference in the Printer Control and if you make the Printer control
setting for both the printers as same. then it will be ok. and also u have to check what is the device type
used for both the output devices.

SmartForms Output to PDF


There is a way to download smartform in PDF format.
Please do the following:
1. Print the smartform to the spool.
2. Note the spool number.
3. Download a PDF file (Acrobat Reader) version of the spool by running Program RSTXPDFT4 and
entering the
noted spool number.

SmartForm Doublesided printing question


Your customer wants your PO SmartForm to be able to print "Terms and Conditinos" on the back
side of each page. They don't want to purchase pre-printed forms with the company's logo on the
front and terms & conditions on the back. Now this presents an interesting problem.
Has anyone else ever had a request like this? If for example there was a 3 page PO to be printed,
they want 3 pieces of paper, the front side of each to containe the PO information (page 1, 2, and 3)
and the back side of each piece of paper to containg the static "Terms & Conditions" information.
Anyone have a clue how to force this out?
Easy - page FRONT lists page CONTACTS as next page and CONTACTS lists FRONT as next page. Since
CONTACTS does not contain a MAIN window, it will print the contacts info and then continue on to FRONT
for the rest of the main items. Additionally, set print mode on FRONT to D (duplex) and set CONTACTS to
'blank' (for both resource name and print mode - this is the only way to get to the back of the page).

Transport Smart Forms


How does one transport SMARTFORM? SE01?
How do you make sure that both, the SMARTFORM & it's function module gets transported? Or does
the FM with same name gets generated automatically in the transported client?
A smartform is transported no differently than any other object. if it is assigned to a development class that is
atteched to a transport layer, it will be transported.
The definition is transported, and when called, the function module is regenerated.
This leads to an interetsing situation. On the new machine, it is very likely the function module name will be
different than the name on the source system. Make sure, before you call the function module, you resolve
the external name to the internal name using the 'SSF_FUNCTION_MODULE_NAME' function module.

Typically, generate the SF, then use the pattern to being in the interface. Then change the call function to
use the name you get back from the above function module.

Smartforms: protect lines in main window.


How to protect lines in the main window from splitting between pages?
It was easy with SAPscript, but how to do it with SF's. For 4.7 version if you are using tables, there are two
options for protection against line break:
- You can protect a line type against page break.
- You can protect several table lines against page break for output in the main area.
Protection against page break for line types
- Double-click on your table node and choose the Table tab page.
- Switch to the detail view by choosing the Details pushbutton.
- Set the Protection against page break checkbox in the table for the relevant line type. Table lines that use
this line type are output on one page.
Protection against page break for several table lines
- Expand the main area of your table node in the navigation tree.
- Insert a file node for the table lines to be protected in the main area.
- If you have already created table lines in the main area, you can put the lines that you want to protect
again page break under the file using Drag&Drop. Otherwise, create the table lines as subnodes of the file.
- Choose the Output Options tab page of the file node and set the Page Protection option. All table lines
that are in the file with the Page Protection option set are output on one page.
In 4.6, Alternatively in a paragraph format use the Page protection attribute to determine whether or not to
display a paragraph completely on one page. Mark it if you want to avoid that a paragraph is split up by a
page break. If on the current page (only in the main window) there is not enough space left for the
paragraph, the entire paragraph appears on the next page.

Display a contents of a table on SmartForm with LOOP


There's a DDIC Table called "Ugyfel" containing 5 rows. I'd like simply to display all the rows on a
SF's Main window.
Please follow this process to display the value from your table "Ugyfel"
1. Go with a transaction code : smartforms
2. Enter the form name like : ysmart_forms1
3. Create
4. Enter the Description for the form
5. From the left side window there will be a form interface to provide table .....
6. Go for tables option
7. ugyfel like ugyfel(ref.type)
8. Pages and window---> page1---> main window
9. Go to the form painter adjust the main window.
10. Select main window and right click --> go for create loop
11. Name: loop1, desc: display loop.
12. Internal table ktab into ktab.
13. select loop right click -> create a text
14. name : text1, desc: display text.
15. Go to change editor.
16. Write the mater what ever you want and if you want to display data from the table write the table fields as
follows:
&ktab-<field1>&

&ktab-<field2>&

save & activate then execute ,, scripts will generate a function module like : '/ibcdw/sf0000031' copy this
function module and call in executable program...
For that
1. go with abap editor se38.
2. table: ugyfel.
3. parameters: test like ugyfel-<field1>.
4. data itab like ugyfel occurs 0 with header line.
5. select * from ugyfel into table itab where field1 = test1.
6. call function '/ibcdw/sf0000031'
7. tables
ktab = itab.
Save and activate the program ( ^f 3).
Now run the program ( f 8)
Internal Table in Smartform
Here is a sample program in which used two internal tables:
REPORT YPRINTPRG_SMARTFORM1 .
DATA : ITKNA1 LIKE KNA1,
ITVBAK LIKE VBAK OCCURS 0 WITH HEADER LINE.
PARAMETERS : PKUNNR LIKE KNA1-KUNNR.
SELECT * FROM KNA1 INTO ITKNA1
WHERE KUNNR = PKUNNR.
ENDSELECT.
SELECT * FROM VBAK
INTO TABLE ITVBAK
WHERE KUNNR = PKUNNR.
CALL FUNCTION '/1BCDWB/SF00000011' THIS FUNCTION MODULE CALLS THE
SMART FORM WE WILL GET THIS AT MENU ENVIRONEMENT
EXPORTING
ITKNA1
= ITKNA1
TABLES
ITVBAK
= ITVBAK.
IN SMART FORM
FORM INERFACE---------IMPORT (TAB)
Parameter name
Type assignment Reference type
ITKNA1
LIKE
KNA1

Default value

FORM INERFACE---------TABLES (TAB)


ITVBAK
LIKE
VBAK
PAGES & WINDOWS----- MAIN WINDOW-----LOOP 1----DATA(TAB)
ITVBAK
INTO
ITVBAK
PAGES & WINDOWS-------MAIN WINDOW------LOOP 1-----TEXT 3(EDITOR)
&ITVBAK-VBELN& &ITVBAK-ERDAT& &ITVBAK-ERNAM& &ITVBAK-NETWR&
PAGES & WINDOWS-------HEADER WINDOW-----TEXT 2(EDITOR)
Customer No. &itkna1-kunnr&
CustomerName :&itkna1-name1& Questions for Bar Code Printing in
SAP

1. Can we print bar codes in SAP only from ZEBRA printers ?


2. I had read that bar code printing is enabled in SAP and only needs to configure device/printer for
that. Does this mean that we can use our existing HP 2300 or like printers to print bar codes without
any ZEBRA like printers and the printed bar codes are readable through any reader ?
3. Are there any specific steps to print bar codes from SAP (from within Smartforms) including data
fetch and printer configurations.
4. What is the process or method for reading data in bar code form into sap ( as far as I think that we
can upload the txt file created from reader and upload it to SAP ). Can we do this without uploading
TXT file i.e. directly reading from bar code reader into SAP. In other means what are the normal ways
to read bar codes data into SAP.
Furthermore, we have taken a zebra Z4M plus printer from one of vendor on trial basis but even after
following the recommended steps as mentioned in the config. manual we are unable to print any
thing on bar code printer from within SAP.
I do agree that we can print bar codes from excel or from outside SAP but we wanted to print it out
from within SAP and we think SMARTFORM is an easier way as compare to SAPSCRIPT (although
we don't have any idea of printing bar codes from SAPSCRIPTs).
About reading from bar code reader .... yes we know that we have to read the bar codes into a ASCII
or text file but in that case we need to write a ABAP program to upload that information into SAP to
do MIGO (in our case) and for that we also need to fill in certain other information into that text file
after reading bar codes ....?? is there any other simpler way of doing this ???
We are able to print barcodes from smartforms. Doing this way, we print barcodes on laser printers.
We are also printing from sap to zebra printers using two ways:
1. Download the data to an excel sheet, then creating a macro that opens the printer port and sending the
commands to the printer through this "file". All this is done via vb script provided with excel)..
2. The second way is creating a vbscript (an ascii file from sap) with the printer commands and then runing
it using ws_execute.
You need a barcode reader to read the barcodes, and this scanner acts like a keyboard, it sends the data
scanned to the active field on screen. (which might be a notepad, word, excel or an input field or ... ).
Back to your problem:
1. We're using Zebra 2746-e (Eltron) to print labels that have some barcodes in their design. There are
several approaches to solve this problem. We've decided to work with the programming language of the
printer (EPL-2), because we use the zebra printers from SAP or from other windows applications.
Our solution was to develope function module that creates an ascii file (a vbscript file) and then use the
ws_execute to run wscript with this file. The vbscript just opens the port for output and sends a sequence of
writeline, each of them with a command to the printer. After all the commands were sent to the printer, we
close the port . Just note that the port acts the same as a file.
This is an EXAMPLE of the visual basic script code;
Set fs=CreateObject("Scripting.FileSystemObject")
Rem send the output to COM1 port.
Set a = fs.CreateTextFile("COM1:",True)
Comilla = Chr(34)
a.writeline "O"
a.writeline "ZB"
a.writeline ""
a.writeline ""

a.writeline ""
a.writeline "N"
a.writeline ""
a.writeline ""
a.writeline "q800"
a.writeline "Q635,24+0"
a.writeline "R32,24"
a.writeline "S3"
a.writeline "D8"
a.writeline "ZT"
a.writeline ""
rem this is an example of barcode ean128-ucc
a.writeline "B126,429,0,1E,3,3,61,B,""011234567890123410051215"""
rem this is an example of barcode 3 of 9 rotated
a.writeline "B10,495,3,1,3,3,49,B,""01234567"""
a.writeline ""
a.writeline ""
a.writeline "P1"
a.writeline ""
a.Close
We've send this code to an ascii file or as part of a macro to be run within an excel sheet. We have succeed
in both cases.
The zebra printer is created as local to the computer running the vbscript. We haven't been able to share
the zebra printer so other people in the network can use it. And the zebra printer isn't installed as a SAP
printer (we aren't using sap spooler to send jobs to the zebra). Another Note: zebra 2746 comes with a
software bar-one (or something like that) that allows you to design the barcode label in a wysiwyg way
If my memory isn't failing, I think that I've read something about controlling zebra printers from smartforms in
service.sap.com, but I haven't explored this possibility.
2. From 4.6c on, you can use smartforms to print barcodes without buying any barcode.dll software
nor hardware extention like Bardimm on any laser/inkjet printer (Please Note that I haven't
mentioned Zebra printers here!). To do this, you have to create a smartstyle -> character format with
the desired barcode font (defined within sap). Then in the smartform, create a window, put the field and
associate it the character format. That's all (I mean, that's all we do at least :-). I think, you have to consider
the barcode specifications before sending the barcode value to the smartform (Just an example, if you're
using 3 of 9, the code should start and end with an asterisk - '*' -) We're printing an interleaved 2 out of 5
barcode in our invoices due to a legal requirement, and we did it this way.
3. If you have a barcode scanner, then you should not need reading the barcode into an ascii file to get the
data read in an standard or custom screen field. You can read it directly to the field you want. (unless... you
have complex data coded in the barcode - for example if you're using an ean-ucc 128 compliant code and
you're sending several fields in a single code ... In this case, an interface is almost mandatory because you
must interpret the data fields according to the ucc standard, split the code into several fields .... and .... pure
programming logic ).
To put it clear: if you have to read, for example, a barcode that holds the legal number of an invoice using a
barcode scanner and this number should be sent to migo-> bktxt then you don't need an interface. The
scanner itself acts like a fast operator entering the characters using a keyboard and filling in the field.
We're reading barcodes in several places (when we finish each pallet, when we receive an invoice, and so
on. Each case is a different screen. We arent using an ascii file to read these barcodes. Furthermore, we
read the invoice legal number into migo bktxt field (Head Text).
BAPI Programming Tips and Tricks
SAP created the Business Framework to allow the technical integration and exchange of business data
among SAP components and between SAP and non-SAP components. Important components of the
Business Framework are the Business Application Programming Interfaces (BAPIs), which represent visible
interfaces at the component boundaries and whose properties serve to integrate these components.

The integration can include both components within a local network and components that are connected
with one another through the Internet.
BAPIs allow integration at the business level, not the technical level. This provides for greater stability in the
link, and independence from the underlying communication technology.
You can get all the standard SAP BAPI functions with the transactions code 'BAPI'.
BAPI Conventions
Methods
Parameters
Standardized BAPIs
Standardized Parameters
Important things to remember..
BAPI/ALE Integration
Methods

If the BAPI to be implemented is a standardized BAPI, use the generic names, for example,
GetList, GetDetail.
The method name must be in English (maximum 30 characters).
The individual components of a BAPI name are separated by the use of upper and lower
case.Example: GetList
Underscores ("_") are not allowed in BAPI names.
Each BAPI has a return parameter that is either an export parameter or an export table.
So that customers can enhance BAPIs, each BAPI must have an ExtensionIn and an ExtensionOut
parameter.

Parameters

If standardized parameters are used, you have to use the names specified for standardized
parameters.
BAPI parameter names should be as meaningful as possible. Poorly chosen names include
abbreviations and technical names (e.g. "flag", table names, etc.).
The parameter and field names must be in English with a maximum of 30 characters.
The components of a parameter name in the BOR are separated by upper and lower case letters to
make them easier to read. Example: CompanyCodeDetail
Values that belong to each other semantically should be grouped together in one structured
parameter, instead of using several scalar parameters.
For ISO-relevant fields (country, language, unit of measure, currency), additional fields for ISO
codes are provided.
Unit of measure fields must accompany all quantity fields and currency identifiers must accompany
currency amount fields.

Standardized BAPIs
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<subobject> ( ) and
Remove<subobject> ( )

The BAPI Add<subobject> adds a subobject to an existing object instance


and the BAPI and Remove<subobject> removes a subobject from an object
instance. These BAPIs are instance methods.

BAPIs for Mass Data Processing


The BAPIs listed above for creating and changing data can also be used for mass processing. For more
information see BAPIs for Mass Data Transfer [Extern]
BAPIs for Replicating Business Object Instances

Replicate( ) and
SaveReplica( )

The BAPIs Replicate() and SaveReplica() are implemented as methods of replicable


business object types. They enable specific instances of an object type to be copied to
one or more different systems. These BAPIs are used mainly to transfer data between

distributed systems within the context of Application Link Enabling (ALE). These BAPIs
are class methods.
Other Less Used Standardized BAPIs

Programming GetStatus() BAPIs [Extern]


Programming ExistenceCheck() BAPIs [Extern]

Standardized Parameters
There are some parameters that can be created for various BAPIs because they contain the same or the
equivalent data in all BAPIs. They should be implemented the same in all BAPIs.

Address
parameters

Specific reference structures are defined for address parameters in BAPIs. You should
copy these structures to use in your BAPI, especially if the underlying object type uses the
central address management (CAM).

Change
Parameters

In BAPIs that cause database changes (for example, Change() and Create() BAPIs) you
must be able to distinguish between parameter fields that contain modified values and
parameter fields that have not been modified. This distinction is made through the use of
standardized parameters.

Extension
parameters

The parameters ExtensionIn and ExtensionOut provides customers with a mechanism that
enables BAPIs to be enhanced without modifications.

Return
Parameters

Each BAPI must have an export return parameter for returning messages to the calling
application. To provide application programmers with a consistent error handling process
for BAPI calls, all return parameters must be implemented in the same, standardized way.

Selection
Parameters

Standardized selection parameters are used in BAPIs that can be used to search for
specific instances of a business object type (e.g. in GetList() ). These parameters enable
the BAPI caller to specify the relevant selection criteria.

Test Run
Parameters

The parameter TestRun is used in write BAPIs (Create() and Change() ), to check the
entries for the object instance in the database before actually creating the object instance.
The creation of the object instance is only simulated and data is not updated.

Text Transfer
Parameters

To transfer BAPI documentation texts (e.g. the documentation of a business object type),
you have to create standardized text transfer parameters.

Important things to remember..


It is important to follow the guidelines below when develop9ng BAPIs:
BAPIs must not contain CALL TRANSACTIO or SUBMIT REPORT
BAPIs must not invoke a COMMIT WORK. instead use the BAPI TransactionCommit to execute the
commit after the BAPI has executed.
BAPI structures must not use includes.
There should be no functional dependecies between two BAPIs
BAPIs must perform there own authorization check
BAPIs should not use dialogs
BAPIs must not cause the program to abort or terminate. re4levant messages must be
communicated through the return parameter.

BAPI/ALE Integration
When you use the BAPIs for asynchronous messagning, the application in the sendig systen calls the
generated ALE IDoc interface isntead of the BAPI.
Asynchronous BAPIs use the ALE interface this way:

Creates an IDOC from the BAPI data


Sends the IDOC to the target system
Receives the IDOC in trhe target system, crreates the BAPI data from the IDoc and calls the BAPI

An ALE interface for a BAPi is created in transaction BDBG.

What is the different between ALE, IDOC and BAPI?


ALE
ALE is SAP proprietary technology that enables data communications between two or more SAP R/3
systems and/or R/3 and external systems. When a new enterprise resource planning (ERP) solution such as
R/3 is implemented, companies have to interface the ERP system with legacy systems or other ERP
systems.
ALE provides intelligent mechanisms where by clients can achieve integration as well as distribution of
applications and data.
ALE technology facilitates rapid application prototyping and application interface development, thus reducing
implementation time.
The ALE components are inherently integrated with SAP applications and are robust, leading to a highly
reliable system.
ALE comes with application distribution/integration scenarios as well as a set of tools, programs, data
definitions, and methodologies that you can easily configure to get an interface up and running.
BAPI
BAPIs provide a stable, standardized method for third-party applications and components to integrate into
the Business Framework. These interfaces are being specified as part of SAP's initiative with customers,
partners and leading standards organizations. Also, SAP has implemented the emerging Object Application
Group (OAG) specifications with BAPIs.
Pros and Cons for both BAPI and Call Transaction
BAPI
One of the big plusses for BAPIs is that the interface and function are not supposed to change. This is a big
plus when you do upgrades or hot packs because the transaction can change (format, required inputs etc)
which means you then need to update the call transaction.
Some of the BAPIs are better documented and easier to use than others.
You usually need to perform the BAPI that actually does the COMMIT after you call your BAPI.

The Program coding for calling a BAPI is usually cleaner than setting up the screen flow etc for the Call
Transaction.
You don't need to worry about special data circumstances interrupting the normal data flow of the screens
and causing errors because of that.
BAPIs probably have better performance since they don't do the screen flow processing.
In general if the BAPI exists for the transaction you want to perform and you can figure out how to use it the
BAPI is probably the best way to go.
This is just from my experience working with both BAPI and Call Transaction. I have had some very good
successes with BAPIs, but very occasionally found that I could not get the BAPI to perform the update I
needed.
The interface concept of the classic R/3 is based on two different strategies: Remote Function Calls (RFC)
and data exchange through IDoc message documents. RFC makes direct and synchronous calls of a
program in the remote system. If the caller is an external program it will call an RFC-enabled function in R/3
and if the calling program is the R/3 system it will call an
RFC-function in another R/3-system or it will call a non-R/3 program through a gateway-proxy (usually
rfcexec.exe). BAPIs are a subset of the RFC-enabled function modules, especially designed as Application
Programming Interface (API) to the SAP business object, or in other words: are function modules officially
released by SAP to be called from external programs.
IDocs are text encoded documents with a rigid structure that are used to exchange data between R/3 and a
foreign system. Instead of calling a program in the destination system directly, the data is first packed into an
IDoc and then sent to the receiving system, where it is analyzed and properly processed. Therefore an
IDoc data exchange is always an
asynchronous process. The significant difference between simple RFC-calls and IDoc data exchange is the
fact, that every action performed on IDocs are protocolled by R/3 and IDocs can be reprocessed if an error
occurred in one of the message steps.
While IDocs have to be understood as a data exchange protocol, EDI and ALE are typical use cases for
IDocs. R/3 uses IDocs for both EDI and ALE to deliver data to the receiving system. ALE is basically the
scheduling mechanism that defines when and between which partners and what kind of data will be
exchanged on a regular or event triggered basis. Such a set-up is called an ALE-scenario.
The philosophical difference between EDI and ALE can be pinned as follows: If we send data to an external
partner, we generally speak of EDI, while ALE is a mechanism to reliable replicate data between trusting
systems to store a redundant copy of the IDoc data. The difference is made clear, when we think of a
purchase order that is sent as an IDoc. If we send the purchase order to a supplier then the supplier will
store the purchase order as a sales order. However, if we send the purchase order via ALE to another R/3
system, then the receiving system will store the purchase order also as a purchase order.

Difference and/or similarities between BAPI and IDOC's


-----Original Message----Subject: Difference and/or simmelarities between BAPI and IDOC's
Hello,
Can someone explain to me the difference and/or similarities between
BAPI and IDOC's?

With regards,
-----Reply Message----Subject: RE: Difference and/or simmelarities between BAPI and IDOC's
There are many differences between IDOCs and BAPIs.
BAPIs in 3.1 are synchronous; in 4.+ they can be asynchronous (and I
believe they then drive certain ALE/IDOCs).
BAPIs are called from the outside-in. That is, an external program
invokes a BAPI that gets data from SAP to display or updates data in
SAP. The BAPI concept does not include an event concept -- you cannot
tell SAP that when certain events happen to a "business object", to fire
a message or a file to an external system.
BAPIs are invokable from Java or C/C++ or Visual Basic (and I think some
people are using Delphi).
In 3.1x there are very few BAPIs to use. In 4.+ SAP has added a large
number.
BAPIs are not totally immune to upgrades but if they are to be retired
you supposedly will have them supported for two releases. Whether those
are point or letter releases, I don't know. I believe that IDOCs may
be more changable from release to release.
BAPIs are reasonably well documented and there is a common place to look
to see what is available. IDOCs -- I have heard -- are poorly
documented in terms of finding them, and IDOCs were done differently by
different groups in SAP.
BTW, you can also use Java, C/C++, Visual Basic, ... to invoke RFCs in
SAP and get or update data. That's how the BAPIs work since they
utimately are sets of RFC calls (written to a design spec for BAPIs).
Hope I haven't misstated any of the details.
BAPI vs Call transaction
-----Original Message----Subject: BAPI vs Call transaction
Hi all!
Could you explain me why a BAPI is faster than a call transaction?.
E.g. If i have the BAPI: create_sales_document and I could also do a call transaction to
va01. Wich one is better?. Why?.
Thanks in advance...
-----Reply Message----Subject: RE: BAPI vs Call transaction

Hi, As of I know BAPI's R internally they RFC functions and they were implemented
with Objects... ..May be because of this reason they R faqster..if it is wrong ..please
don't mind...Regards...
-----Reply Message----Subject: RE: BAPI vs Call transaction
A BAPI is faster because it is updating the DB "directly" through ABAP code. A BDC with call
transaction goes through the whole screen sequence like any user would do, simply put, it
is filling screens.
Use BAPIs whenever possible.
-----Reply Message----Subject: RE: BAPI vs Call transaction
you use a special BAPI, cause this one uses CALL TRANSACTION to create a sales order.
A lot of BAPIS and IDOC - input FM use DIRECT INPUT instead of CALL TA. Much faster. And
you can do a lot with them, you can't do as easy in CALL TA.
But the best reason for BAPIs is, that they are farely safe on release change or support
package change.
Bye
-----Reply Message----Subject: RE: BAPI vs Call transaction
Thanks for your answers... They have been very useful...
COMMIT WORK and BAPI_TRANSACTION_COMMIT
-----Original Message----Subject: COMMIT WORK and BAPI_TRANSACTION_COMMIT
Does anybody know what's the difference between the two?
-----Reply Message----Subject: RE: COMMIT WORK and BAPI_TRANSACTION_COMMIT
Hi,
Commit work is used when you code directly in ABAP and make changes in the database and
want to commit the database.
BAPI_TRANSACTION_COMMIT is used when you make changes to the SAP database by calling
a BAPI from outside SAP and want to commit the database. When you use a BAPI, you can not
directly use commit work, instead you are allowed to use only
BAPI_TRANSACTION_COMMIT.
Regards,
-----Reply Message----Subject: RE: COMMIT WORK and BAPI_TRANSACTION_COMMIT
I would sasy the diff lies more in the way u want to call Commit Work.
With BAPI_TRANSACTION_COMMIT ..the external systems have a way of deciding on whether to
Commit or to Roll back Changes.

But with Commit Work u have to code it inside ure BAPI and the outside systems then have no chance or
have
any hold over the commit...
so i guess the diff lies more in the way how u want to call commit ,either from outside or from within ure
BAPI.
u can use both...
SAP though recommends using BAPI_Transaction_Commit and not using Commit_work in the BAPI...
but its upto u and ure middleware guy to decide how u want to do it..
Exponential form to general
-----Original Message----Subject: Exponential form to general
hi,
can anyone help me in BAPI
1)In BAPI_BILLINGDOC_CANCEL1
i am not able to under TESTRUN.how can we test it
2)BAPI_SALESORDER_CHANGE
3)BAPI_TRANSACTION_COMMIT
can anyone help me out on these.i dont know BAPI.Can any one advice me where can i read
it?
-----Reply Message----Subject: RE: Exponential form to general
Hi,
You can test the bapi's by passing the required parameters, Actually you can use the
BAPI_SALESORDER_CHANGE when you want to change the existing sales order.
BAPI_TRANSACTION_COMMIT is necessary to commit the changes, if you won't call the
BAPI_TRANSACTION_COMMIT the values won't store in database.
The doucmentation is not available in English version, if yo want to see the similar once check
SD_SALESDOCUMENT_CHANGE function module, both will do same work. You can get the
documentation
for this function module in GOTO-->DOCUMENTAION.
regards
Persistent key
-----Original Message----Subject: persistent key

Hi all,
i'm new in bapi programming, i'm trying to call GetList method from
GeneralLedgerAccount Business Object, and got this error message 'The
persistent key for an bussiness object instance of type GeneralLedgerAccount
has not been set. Cannot invoke method GetList'.
How can i set the persistent key, and what is the persistent key exactly ?
How can i check the persistent key in the BOR ?
I'm using SAP R/3 version 3.1g and VB version 6.0
-----Reply Message----Subject: RE: persistent key
Although we are currently using SAP 4.0B, the GeneralLedgerAccount BAPI has not changed
significantly (if at all). I have had this error message many times working with HR BAPI's and it
took a lot of research to finally puzzle out what SAP actually wants in these situations. On the
other hand, I took a look at the GetList method for this BAPI and I cannot see why you would
be getting this error! There are three kinds of BAPI's I have encountered so far - those that
return actual tables of data based on key fields you fill in (ie. Employee.GetList), those
that return tables of keys that point to the actual data within SAP (think of C pointers! ie.
EmployeePersonalData.GetList), and BAPI's that have no input parameters at all but can retrieve
extra information directly related to a particular 'instance' of a business object that you have
previously 'instantiated' (translation - the last 'record' you 'read' from the table! ie.
EmployeePersonalData.GetDetail). GeneralLedgerAccount is of the first type, while the error you get
is related to BAPI's of the third type. It is usually caused by calling a GetDetail method without
calling GetSAPObject with a complete, unique key value first. The following code fragment
shows how I read Employee.GetList - this may shed some light on what you might be missing. The
second fragment shows how to 'instantiate' a 'persistant' object (don't we just love this
terminology?) before calling a GetDetail BAPI. Hope this helps you out!
===================================================
Dim oBapiControl As Object
Dim oConnection As Object
Dim oEmployee As Object
Dim oReturn As Object
Dim otabPersonalData As Object
Dim otabOrgAssignment As Object
Dim oRow As Object
oBapiControl = CreateObject("SAP.BAPI.1")
Set oConnection = oBapiControl.Connection
'SET UP ALL oConnection PARAMETERS HERE AND CALL oConnection.Logon(0, True)
Set oEmployee = oBapiControl.GetSAPObject("Employee")
oEmployee.Getlist Lastname:="*", _
Return:=oReturn, _
PersonalData:=otabPersonalData, _
OrgAssignment:=otabOrgAssignment
For Each oRow In otabPersonalData.Rows
Print "Personnel Number = " + oRow.Value("PERNO")
...
Next oRow
- Substitute the word 'GeneralLedgerAccount' for 'Employee' and this should work for you!
===================================================
Private Sub LoadFamily(sPerno As String)
Dim cSep
As String * 1
Dim sToday
As Date
Dim oCol
As Object
Dim oDelRow
As Object
Dim oReturn
As Object

Dim oFReturn
As Object
Dim otabFKeyList As Object
Dim oFamilyKey As Object
Dim oFamilyMem As Object
Dim sFirstName As String
Dim sSecondName As String
Dim sLastName
As String
Dim sGender
As String
Dim sBirthdate As Date
cSep = Chr(9)
sToday = Date
' RETRIEVE ALL FAMILY MEMBERS FOR A GIVEN PERSONNEL NUMBER.
' NOTE THAT THE BAPI RETURNS A TABLE OF KEYS (Familykey) AND
' NOT THE ACTUAL DATA!
Set otabFKeyList = Nothing
oFamilyMembers.Getlist EmployeeNumber:=sPerno, _
Subtype:="", _
Timeintervallow:=sToday, _
Timeintervalhigh:=sToday, _
Return:=oFReturn, _
Familykey:=otabFKeyList
If oFReturn.Value("TYPE") <> "E" Then
'IF THE CALL SUCCEEDED,
For Each oFamilyKey In otabFKeyList.Rows
THEN FOR EACH KEY IN THE TABLE...
On Error Resume Next
' INSTANTIATE A PERSISTANT LOCAL BUSINESS OBJECT HERE USING THE
' FULL KEY VALUE
Set oFamilyMem = oBapiControl.GetSAPObject("EmployeeFamilyMember", _
oFamilyKey.Value("EMPLOYEENO"), _
oFamilyKey.Value("SUBTYPE"), _
oFamilyKey.Value("OBJECTID"), _
oFamilyKey.Value("LOCKINDIC"), _
oFamilyKey.Value("VALIDEND"), _
oFamilyKey.Value("VALIDBEGIN"), _
oFamilyKey.Value("RECORDNR"))
If Err.Number = 0 Then
' AND IF THAT WORKED, THEN FINALLY
' WE CAN GET THE INFORMATION WE WANT BY CALLING GETDETAIL. THIS BAPI
' USES THE KEY INFORMATION IN THE FamilyMem OBJECT TO IDENTIFY THE SAP
' DATA THAT SHOULD BE RETURNED....VERY COMPLEX!!!
oFamilyMem.GetDetail Return:=oReturn, _
Firstname:=sFirstName, _
Initials:=sSecondName, _
Lastname:=sLastName, _
Gender:=sGender, _
Dateofbirth:=sBirthdate
If oReturn.Type <> "E" Then
Print #2, sPerno; cSep; _
sFirstName; cSep; _
sSecondName; cSep; _
sLastName; cSep; _
sGender; cSep; _
sBirthdate; cSep; _
""
End If
Else
Err.Clear
End If
Next oFamilyKey
End If

End Sub
===================================================
-----End of Message----Read function module definition
-----Original Message----Subject: read function module definition
hi,
did someone know, where the import, export, tables, exception definition
of a function module is storeed?
I try to write a RFC call to read the interface of a function module (or
BAPI) to generate a C++ interface.
Therefore I write a function in Abap, which could be called via RFC.
Thx
-----Reply Message----Subject: RE: read function module definition
Try RFC_GET_FUNCTION_INTERFACE
-----End of Message----Difference Between BAPI and RFC
What is the main difference between BAPI and RFC and difference between BAPI and BDC?
BAPI is used only when it is available for the particular transaction like Delivery Sales order. but BDC can
be used for any
transaction which have screen and fields.
BAPI is directly updated the database instead BDC run through the screen flow.
So BAPI can't handle all the flow logic checking and enhancement put by programmer to faciliate the user
requirement.

Difference between BAPI and BDC:


BAPI is a higher end usage for tranfering the data from SAP to non-SAP and vice-versa. for ex: if we are
using VB application,where in that we want to connect to SAP and retireve the data,and then change and
update the data in SAP for that purpose we can use that.
Apart from that, we can also use it for Uploading/Downloading the data from SAP to Non-SAP like BDC,
provided we have an existing BAPI for that.
BAPI function modules will also do all the checks required for data integrity like Transactions for BDC.
There is one more advantage using BAPI instead of BDC. When we go for upgradation, there might be
pozzibility to change the screen elements for transactions depending on the requirement. In that case,our
BDC pgm may or may not work (depending on the screen changes they have made). Unless and until we

prepare new BDC we cant use the old BDC pgm. But in BAPI, SAP promises that they are going to keep the
old BAPI and for new functionality they will provide an upgraded BAPI. Until we write a new BAPI pgm, we
can use the exisitng BAPI pgm.
BAPI ActiveX Control
-----Original Message----Subject: BAPI ActiveX Control
Hi!
Where can I find the BAPI ActiveX Control ?
Thanks in advance
-----Reply Message----Subject: RE: BAPI ActiveX Control
Hi!
All necessary files for using BAPI are installed together with the SAP
GUI on your PC (from 3.1H on).
If it does not work or you can not find any SAP ActiveX Control you have to
install the SAP GUI again.
The BAPI ActiveX Control might be the file "wdobapi.ocx ".
ODBC and MsAccess
-----Original Message---Subject: ODBC and MsAccess
Hello All,
We are building an interface between R/3 and an application a company build
for us in Ms. Access. Since they build the application for us we want to
subcontract this interface to this company. The consultant came to with the
idea of using ODBC to read/write directly to the Oracle database.
Can this be done ???? (I thought not !)
anybody has experience with Access/R/3
Thanks !
-----Reply Message---Subject: RE: ODBC and MsAccess
Hello!
Dont write directly to the SAP database because you can get inconsistent
information in your system. Always use the standard functionality with its
checks. For this reason you can use the BAPI-method.
-----End of Message-----

BAPI C++ Library


-----Original Message----Subject: BAPI C++ Library
Hi,
I've just subscribed to this list in the hopes of getting an answer to a
problem which I'm having. I'm trying to statically link to the BAPI C++
class library. In MSVC++ 5.0 I'm getting undefined external symbol errors
from the linker on all the CBO references, which I didn't get in a previous
iteration, using just the RFC class library and its C++ objects. My project
currently includes the lib file, RFCClass.lib, which I gather from the
linker errors doesn't resolve the CBO calls. I'm wondering if anyone knows
what the name of the CBO lib file is, and where in the Automation Kit I can
find it. Thanks in advance for any assistance.
Regards,
-----Reply Message----Subject: RE: BAPI C++ Library
Hi,
The lib file is named "cbo.lib" and you'll find it in the SAP Automation
Kit in the directory: ..\Bapi Class\lib\ (in version 4.0b or 4.0a).
Further information you'll find in the ..\Bapi Class\Help directory.
-----End of Message-----

Questions on BAPI and RFC Programming


One BAPI to get status back of the delivery no ! >> RFC programming
1) I am creating purchase order(PO) and creating inbound delivery for that purchase order(PO) which will
be distibuted to NONSAP((warehouse management) .
> -----------------------------Then NONSAP((ware house management) sends back the confirmation (after updating its Data base of that
inbound delivery ) to SAP through IDoc which uses delivery number. I am sending delivery no(in IDoc) from
Non Sap(ware house management) to Sap through JCO.
If you use Jco, which is the Java Connector, you know how to program
Java or you have a resource available that knows how to program java.

Then in SAP [after getting back that IDoc from NON-SAP((ware house management) ], the status of that
delivery number will changes to "Confirmed". We can see that in SAP through transaction code : vl33n.
> -----------------------------I am not so familiar with VL33N, so I could not find this status change. Am I right to think that this status is
stored in table LIKP field VLSTK ( Distribution Status (Decentralized Warehouse
Processing) ).

NOW , I need one BAPI which I can use from NON-SAP, to get back the status of that delivery number. My
idoc sending from NON-SAP, since it is through idoc , it is not returning back the delivery number's status
from SAP, I need to use one BAPI from nonsap (java prg) which takes input as delivery number and gives

back the status of that delivery number from SAP.


> -----------------------------You need either a BAPI ( there is non that does what you want ), or you need an RFC.

2) What is RFC sever programming ? In which language is it in? I am an ABAP programmer. How can I deal
that issue please guide me .
> -----------------------------Ahah. RFC ! So, RFC's are actually function modules, but in the Attributes tab you enable 'Remote-enabled
module' and you enable 'Start Immediately'. RFC's are created with SE37, you can also create them with
SE80.
In the import section you would create a p_vbeln like likp-vbeln, in the export section you would create a
p_status like likp-vlstk.
In the source code you would have something like
select single vlstk
into p_status
from likp
where vbeln eq p_vbeln.
And then in JCO you call this Function Module/RFC. The java person should know how to do this.
How to Find Bapi for Particular Transaction in SAP
How to find function module or Bapi for particular transaction in sap?
If you mean that you need to know what BAPI's a particular tranx uses, which I can only assume that's what
you mean, then you should access the code behind the transaction and search for 'CALL'. That normally is
the standard method that think that most people use.
Suppose you want to find the bapi for creating a sales order, you usually use transaction VA01 for this.
1. Find out the package of the transaction.
Start Va01 go to system --> status.
Double click on transaction
Package is VA
Open this package in SE80
Open business engineering-->Business object types
Find the BO which sounds the most appropriate
I would suggest BUS2032 Sales Order
Double click.
Open methods.
Find the released method with from data or something similar in the name
, Createfromdat2
Position the cursor in it and click the program button
Scroll down to find the bapi used in this method
With this way you can also find out programs and FM's
2. Start va01 go to system-->status
Double click transaction VA01
Double click on package
Read the application component. (this is SD-SLS Sales)
Then open the transaction BAPI
Sales and distribution-->Sales-->sales order
createfromdat2

BAPI Step by step Guidance


BAPI stands for Business Application Programming Interface.
There are 5 different steps in BAPI.
- Create BAPI Structure
- Create BAPI Function Module or API Method.
- Create BAPI object
- Release BAPI Function Module.
- Release BAPI object.
Step1. Creating BAPI Structure:
- Go to <SE11>.
- Select Data Type & Enter a name.
- Click on Create.
- Note: Always BAPI should be in a development class with request number (Not Local Object).
- Select Structure & hit ENTER.
- Enter the fields from your database. Make sure that the first field is the Primary Key Field.
- Then SAVE & ACTIVATE.
Step 2. Creating BAPI module:
- Enter TR.CODE <SE37>.
- Before entering any thing, from the present screen that you are in, select the menu
Goto -> Function Groups -> Create Group.
Enter a name (Note: This name Must start with ZBAPI)
Let this screen be as it is and open another window and there, enter TR.CODE <SE80).
Click on the Third ICON that says Inactive Objects.
Select the group that you just created and click on Activate.
Notice that the group you created will disappear from the list of inactive objects.
- Go back to <SE37> screen and enter a name and hit <ENTER>. Then enter the group name that you just
created and activated.
NOTE: When you release a function module the respective group will be attached to that particular
application. It cannot be used for any other application. NEVER include an already existing group that is
attached to another module.
Now click on the first Tab that says [ATTRIBUTES] and select the radio button that says remote-enabled
module since we will be accessing this from any external system.
Then click on the second tab that says [IMPORT].
Enter a PARAMETER NAME, TYPE and the structure you created in the first step. Also select the check box
Pa. All remotely enabled functional modules MUST be Pa enabled, where Pa means Passed by Value and
if you dont select Pa, then that means it will be passed by reference..
Then click on tab that says [EXPORT].
Enter the following as is in the first three fields
RETURN
TYPE
BAPIRETURN (These 3 field values are always same)
Here also select Pa meaning Pass by value.
Note: BAPIRETURN contains structure with message fields.
Then SAVE and ACTIVATE.
Step 3. Creating BAPI object:
- Enter Tr.Code <SWO1> (Note. It is letter O and not Zero).
- Enter a name and then click on create. Enter details.
NOTE: Make sure that that Object Type and Program name are SAME.
- Enter Application M, if you are using standard table Mara. If you are using your own database then select
Z at the bottom.

- Then hit <ENTER>.


- Now we have to add Methods. High light METHODS and then select the following from the menu:
Goto Utilities -> API Methods -> Add Methods.
- Enter function Module name and hit <ENTER>.
- Select the second FORWARD ARROW button (>)to go to next step.
- Check if every thing looks ok and again click on FORWARD ARROW button (>).
- Then select YES and click on <SAVE>.
- Now on a different screen goto TR.CODE <SE37>. Enter Function Module name and select from the top
menu Function Module -> Release -> Release.
- Goback to TR.CODE <SWO1>.
Here select the menu combination shown below in the same order.
- Edit -> Change Release Status -> Object Type Component -> To Implemented.
- Edit -> Change Release Status -> Object Type Component -> To Released.
- Edit -> Change Release Status -> Object Type -> To Implemented.
- Edit -> Change Release Status -> Object Type -> To Released.
- Then click on <SAVE>.
- Then click on Generate Button (4th button from left hand side looks like spinning wheel).
- Then Click on the button that says PROGRAM to see the source code.
To check if this is present in work flow goto TR.CODE <BAPI>.
Here it shows business object repository.
- First click on the middle button and then select ALL and hit ENTER.
- Goto tab [ALPHABETICAL] and look for the object that you created. This shows that the BAPI object has
been created successfully.
BAPI_EMPLOYEE_CHECKPASSWORD
-----Original Message----Subject: BAPI_EMPLOYEE_CHECKPASSWORD
All
Is the Password parameter in BAPI_EMPLOYEE_CHECKPASSWORD a structure?
Also, Do you have some sample code on how to use this?
Thanks for your help.
-----Reply Message----Subject: RE: BAPI_EMPLOYEE_CHECKPASSWORD
Hi,
It's a simple parameter. If you go into transaction "se37" and type in
the RFC name (e.g. BAPI_EMPLOYEE_CHECKPASSWORD), select the
Import/Export radio button and then click the Display button. You'll
see the PASSWORD parameter listed. If you look under the "Reference
Type" column you see that is BAPIUID-PASSWORD, which indicates that is
the PASSWORD field of the BAPIUID structure. If you double-click on
this column you'll see the whole structure and the line will be
positioned to this field.
-----End of Message----HR-TM Object

-----Original Message----Subject: HR-TM Object


My question will be more applicable for those people working with
the HR Time Management module.
I want to ask is there a way to populate the Time Clocking data for
employee using the BAPI/RFC. Though there are many partners solution
available in the market, we are unable to do so due to some legal
contract issue.
Presently, we have a non SAP certified system to capture the
employee clocking data. This system will then download a ASCII file
to interface to the SAP system before running the time evaluation
program.
Any advise from someone out there? Thanks.
-----Reply Message----Subject: RE: HR-TM Object
The way we handled it was to create an RFC that can be invoked by the
UNIX startrfc command. This is triggered by the transport process we
use to fetch and move files. This RFC is modeled after the channel 1
(CC1) import provided by SAP. The ASCII file seems to be the
smoothest solution at this time. I am told there are timeclocks out
there that have direct connectivity to SAP but I have not seen one at
this time.
-----Reply Message----Subject: RE: HR-TM Object
We have a similar need. It looks like the TimeMgtConfirmation.Post
BAPI will do this. Take a look at it. I haven't used it yet, but
it appears to be what we need. We plan to build a web application
to report time that would use this (or similar) BAPI.
-----Reply Message----Subject: RE: HR-TM Object
We have found that response time of BAPI's is too ong for mass input.
I have approx 1 million punches a week coming into the system. This
would take tooooooooo long via a BAPI. Using the channel which is
SAP supplied, I can import 25,000 punches in 4 minutes. The only
reason I am using my own RFC is to remove some of the validation
checks being done by SAP (I have pre checked the data before the
import step) to speed things up.
I still do not trust HR BAPI's to work as advertised. They do NOT.
If your WEB application is using the BAPI directly (as the user
types) then the response time issue is probably not as important.
People can olnly type so fast. You may want to watch out for
licesnse issues with this though. The license is very expensive if
you have a large number of people using them. One license per person
is required!
-----End of Message-----

BAPI_GOODSMVT_CREATE to post Goods Movement


The following is an abap program making used of the BAPI function BAPI_GOODSMVT_CREATE to do
Goods Receipts for Purchase Order after importing the data from an external system.
*
* BAPI TO Upload Inventory Data
*
* GMCODE Table T158G - 01 - MB01 - Goods Receipts for Purchase Order
*
02 - MB31 - Goods Receipts for Prod Order
*
03 - MB1A - Goods Issue
*
04 - MB1B - Transfer Posting
*
05 - MB1C - Enter Other Goods Receipt
*
06 - MB11
*
* Domain: KZBEW - Movement Indicator
*
Goods movement w/o reference
* B - Goods movement for purchase order
* F - Goods movement for production order
* L - Goods movement for delivery note
* K - Goods movement for kanban requirement (WM - internal only)
* O - Subsequent adjustment of "material-provided" consumption
* W - Subsequent adjustment of proportion/product unit material
*
report zbapi_goodsmovement.
parameters: p-file like rlgrap-filename default
'c:\sapdata\TEST.txt'.
parameters: e-file like rlgrap-filename default
'c:\sapdata\gdsmvterror.txt'.
parameters: xpost like sy-datum default sy-datum.
data: begin of gmhead.
include structure bapi2017_gm_head_01.
data: end of gmhead.
data: begin of gmcode.
include structure bapi2017_gm_code.
data: end of gmcode.
data: begin of mthead.
include structure bapi2017_gm_head_ret.
data: end of mthead.
data: begin of itab occurs 100.
include structure bapi2017_gm_item_create.
data: end of itab.
data: begin of errmsg occurs 10.
include structure bapiret2.
data: end of errmsg.
data: wmenge like iseg-menge,
errflag.
data: begin of pcitab occurs 100,
ext_doc(10),
"External Document Number
mvt_type(3),
"Movement Type
doc_date(8),
"Document Date
post_date(8),
"Posting Date

plant(4),
"Plant
material(18),
"Material Number
qty(13),
"Quantity
recv_loc(4),
"Receiving Location
issue_loc(4),
"Issuing Location
pur_doc(10),
"Purchase Document No
po_item(3),
"Purchase Document Item No
del_no(10),
"Delivery Purchase Order Number
del_item(3),
"Delivery Item
prod_doc(10),
"Production Document No
scrap_reason(10),
"Scrap Reason
upd_sta(1),
"Update Status
end of pcitab.
call function 'WS_UPLOAD'
exporting
filename
= p-file
filetype
= 'DAT'
* IMPORTING
* FILELENGTH
=
tables
data_tab
= pcitab
* EXCEPTIONS
* FILE_OPEN_ERROR
=1
* FILE_READ_ERROR
=2
* NO_BATCH
=3
* GUI_REFUSE_FILETRANSFER
=4
* INVALID_TYPE
=5
* OTHERS
=6
.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
exit.
endif.
gmhead-pstng_date = sy-datum.
gmhead-doc_date = sy-datum.
gmhead-pr_uname = sy-uname.
gmcode-gm_code = '01'. "01 - MB01 - Goods Receipts for Purchase Order
loop at pcitab.
itab-move_type = pcitab-mvt_type.
itab-mvt_ind = 'B'.
itab-plant
= pcitab-plant.
itab-material = pcitab-material.
itab-entry_qnt = pcitab-qty.
itab-move_stloc = pcitab-recv_loc.
itab-stge_loc = pcitab-issue_loc.
itab-po_number = pcitab-pur_doc.
itab-po_item = pcitab-po_item.
concatenate pcitab-del_no pcitab-del_item into itab-item_text.
itab-move_reas = pcitab-scrap_reason.
append itab.
endloop.
loop at itab.
write:/ itab-material, itab-plant, itab-stge_loc,
itab-move_type, itab-entry_qnt, itab-entry_uom,
itab-entry_uom_iso, itab-po_number, itab-po_item,
pcitab-ext_doc.

endloop.
call function 'BAPI_GOODSMVT_CREATE'
exporting
goodsmvt_header
= gmhead
goodsmvt_code
= gmcode
* TESTRUN
=''
* IMPORTING
goodsmvt_headret
= mthead
* MATERIALDOCUMENT
=
* MATDOCUMENTYEAR
=
tables
goodsmvt_item
= itab
* GOODSMVT_SERIALNUMBER
=
return
= errmsg
.
clear errflag.
loop at errmsg.
if errmsg-type eq 'E'.
write:/'Error in function', errmsg-message.
errflag = 'X'.
else.
write:/ errmsg-message.
endif.
endloop.
if errflag is initial.
commit work and wait.
if sy-subrc ne 0.
write:/ 'Error in updating'.
exit.
else.
write:/ mthead-mat_doc, mthead-doc_year.
perform upd_sta.
endif.
endif.
*---------------------------------------------------------------------*
*
FORM UPD_STA
*
*---------------------------------------------------------------------*
*
........
*
*---------------------------------------------------------------------*
form upd_sta.
loop at pcitab.
pcitab-upd_sta = 'X'.
modify pcitab.
endloop.
call function 'WS_DOWNLOAD'
exporting
filename
= p-file
filetype
= 'DAT'
* IMPORTING
* FILELENGTH
=
tables
data_tab
= pcitab
* EXCEPTIONS
* FILE_OPEN_ERROR
=1
* FILE_READ_ERROR
=2
* NO_BATCH
=3
* GUI_REFUSE_FILETRANSFER
* INVALID_TYPE
=5

=4

* OTHERS
.

=6

endform.
*--- End of Program

BAPI to Copy Materials from one Plant to Another


*
* Copy Materials from one Plant to Another
* First run GETDATA AS CHECKBOX, "Tick to download materials data to local harddisk
* Second run UPDDATA AS CHECKBOX. "Tick to update date to Materials Master
* Check data in Excel before Second run
*
REPORT ZBAPIMM01 LINE-SIZE 255 NO STANDARD PAGE HEADING
LINE-COUNT 065(001).
TABLES: T001L, "Storage Locations
MARA, "General Material Data
MAKT, "Material Descriptions
MBEW, "Material Valuation
MARC. "Plant Data for Material
DATA: BAPI_HEAD LIKE BAPIMATHEAD,
BAPI_MAKT LIKE BAPI_MAKT, "Material Description
BAPI_MARA1 LIKE BAPI_MARA, "Client Data
BAPI_MARAX LIKE BAPI_MARAX,
BAPI_MARC1 LIKE BAPI_MARC, "Plant View
BAPI_MARCX LIKE BAPI_MARCX,
BAPI_MBEW1 LIKE BAPI_MBEW, "Accounting View
BAPI_MBEWX LIKE BAPI_MBEWX,
BAPI_RETURN LIKE BAPIRET2.
DATA: BEGIN OF INT_MAKT OCCURS 100.
INCLUDE STRUCTURE BAPI_MAKT.
DATA: END OF INT_MAKT.
DATA: BEGIN OF INT_MAT OCCURS 100,
WERKS(4), "Plant
MTART(4), "Material type
MATNR(18), "Material number
MATKL(9) , "Material group
MBRSH(1), "Industry sector
MEINS(3), "Base unit of measure
GEWEI(3), "Weight Unit
SPART(2), "Division
EKGRP(3), "Purchasing group
VPRSV(1), "Price control indicator
STPRS(12), "Standard price
PEINH(3), "Price unit
SPRAS(2), "Language key
MAKTX(40), "Material description
END OF INT_MAT.
SELECT-OPTIONS:

PLANT FOR MARC-WERKS OBLIGATORY MEMORY ID PLT,


MATERIAL FOR MARA-MATNR MEMORY ID MAT,
MATLTYPE FOR MARA-MTART MEMORY ID MTY,
DIVISION FOR MARA-SPART MEMORY ID DIV.
PARAMETERS: F_FILE LIKE RLGRAP-FILENAME
DEFAULT 'C:\DATA\ZMATERIAL.XLS' MEMORY ID F_FILE,
GETDATA AS CHECKBOX, "Tick to download materials data to local harddisk
UPDDATA AS CHECKBOX. "Tick to update date to Materials Master
IF GETDATA = 'X'.
PERFORM DOWNLOAD_DATA.
PERFORM DOWNLOAD_FILE.
ENDIF.
IF UPDDATA = 'X'.
PERFORM UPLOAD_FILE.
PERFORM UPDATE_MM.
ENDIF.
FORM DOWNLOAD_DATA.
SELECT * FROM MARC WHERE LVORM EQ ' '
AND WERKS IN PLANT
AND MATNR IN MATERIAL.
CLEAR MARA.
SELECT SINGLE * FROM MARA WHERE MATNR = MARC-MATNR.
CHECK MATLTYPE.
CHECK DIVISION.
CLEAR MBEW.
SELECT SINGLE * FROM MBEW WHERE MATNR = MARC-MATNR
AND BWKEY = MARC-WERKS.
CLEAR MAKT.
SELECT SINGLE * FROM MAKT WHERE SPRAS = 'EN'
AND MATNR = MARC-MATNR.
WRITE:/ MARC-WERKS, "Plant
MARA-MTART, "Material type
MARA-MATNR, "Material number
MARA-MATKL, "Material group
MARA-MBRSH, "Industry sector
MARA-MEINS, "Base unit of measure
MARA-GEWEI, "Weight Unit
MARA-SPART, "Division
MARC-EKGRP, "Purchasing group
MBEW-VPRSV, "Price control indicator
MBEW-STPRS, "Standard price
MBEW-PEINH, "Price unit
MAKT-SPRAS, "Language key
MAKT-MAKTX. "Material description
INT_MAT-WERKS = MARC-WERKS. "Plant
INT_MAT-MTART = MARA-MTART. "Material type
INT_MAT-MATNR = MARA-MATNR. "Material number
INT_MAT-MATKL = MARA-MATKL. "Material group
INT_MAT-MBRSH = MARA-MBRSH. "Industry sector
INT_MAT-MEINS = MARA-MEINS. "Base unit of measure
INT_MAT-GEWEI = MARA-GEWEI. "Weight Unit
INT_MAT-SPART = MARA-SPART. "Division
INT_MAT-EKGRP = MARC-EKGRP. "Purchasing group
INT_MAT-VPRSV = MBEW-VPRSV. "Price control indicator
INT_MAT-STPRS = MBEW-STPRS. "Standard price
INT_MAT-PEINH = MBEW-PEINH. "Price unit

INT_MAT-SPRAS = MAKT-SPRAS.
INT_MAT-MAKTX = MAKT-MAKTX.

"Language key
"Material description

APPEND INT_MAT.
CLEAR INT_MAT.
ENDSELECT.
ENDFORM.
FORM DOWNLOAD_FILE.
call function 'WS_DOWNLOAD'
EXPORTING
FILENAME
= F_FILE
FILETYPE
= 'DAT'
* FILETYPE
= 'WK1'
tables
data_tab
= INT_MAT
EXCEPTIONS
FILE_OPEN_ERROR
=1
FILE_WRITE_ERROR
=2
INVALID_FILESIZE
=3
INVALID_TYPE
=4
NO_BATCH
=5
UNKNOWN_ERROR
=6
INVALID_TABLE_WIDTH
=7
GUI_REFUSE_FILETRANSFER
=8
CUSTOMER_ERROR
=9
OTHERS
= 10.
IF SY-SUBRC = 0.
FORMAT COLOR COL_GROUP.
WRITE:/ 'Data Download Successfully to your local harddisk'.
SKIP.
ENDIF.
ENDFORM.
FORM UPLOAD_FILE.
call function 'WS_UPLOAD'
EXPORTING
FILENAME
= F_FILE
FILETYPE
= 'DAT'
* FILETYPE
= 'WK1'
tables
data_tab
= INT_MAT
EXCEPTIONS
FILE_OPEN_ERROR
=1
FILE_WRITE_ERROR
=2
INVALID_FILESIZE
=3
INVALID_TYPE
=4
NO_BATCH
=5
UNKNOWN_ERROR
=6
INVALID_TABLE_WIDTH
=7
GUI_REFUSE_FILETRANSFER
=8
CUSTOMER_ERROR
=9
OTHERS
= 10.
IF SY-SUBRC = 0.
FORMAT COLOR COL_GROUP.
WRITE:/ 'Data Upload Successfully from your local harddisk'.
SKIP.
ENDIF.
ENDFORM.

FORM UPDATE_MM.
LOOP AT INT_MAT.
* Header
BAPI_HEAD-MATERIAL
= INT_MAT-MATNR.
BAPI_HEAD-IND_SECTOR
= INT_MAT-MBRSH.
BAPI_HEAD-MATL_TYPE
= INT_MAT-MTART.
BAPI_HEAD-BASIC_VIEW
= 'X'.
BAPI_HEAD-PURCHASE_VIEW = 'X'.
BAPI_HEAD-ACCOUNT_VIEW = 'X'.
* Material Description
REFRESH INT_MAKT.
INT_MAKT-LANGU
= INT_MAT-SPRAS.
INT_MAKT-MATL_DESC
= INT_MAT-MAKTX.
APPEND INT_MAKT.
* Client Data - Basic
BAPI_MARA1-MATL_GROUP = INT_MAT-MATKL.
BAPI_MARA1-BASE_UOM
= INT_MAT-MEINS.
BAPI_MARA1-UNIT_OF_WT = INT_MAT-GEWEI.
BAPI_MARA1-DIVISION
= INT_MAT-SPART.
BAPI_MARAX-MATL_GROUP = 'X'.
BAPI_MARAX-BASE_UOM = 'X'.
BAPI_MARAX-UNIT_OF_WT = 'X'.
BAPI_MARAX-DIVISION = 'X'.
* Plant - Purchasing
BAPI_MARC1-PLANT
= INT_MAT-WERKS.
BAPI_MARC1-PUR_GROUP = INT_MAT-EKGRP.
BAPI_MARCX-PLANT
= INT_MAT-WERKS.
BAPI_MARCX-PUR_GROUP = 'X'.
* Accounting
BAPI_MBEW1-VAL_AREA = INT_MAT-WERKS.
BAPI_MBEW1-PRICE_CTRL = INT_MAT-VPRSV.
BAPI_MBEW1-STD_PRICE = INT_MAT-STPRS.
BAPI_MBEW1-PRICE_UNIT = INT_MAT-PEINH.
BAPI_MBEWX-VAL_AREA = INT_MAT-WERKS.
BAPI_MBEWX-PRICE_CTRL = 'X'.
BAPI_MBEWX-STD_PRICE = 'X'.
BAPI_MBEWX-PRICE_UNIT = 'X'.
WRITE:/ BAPI_HEAD, BAPI_MARC1.

*
*
*
*
*
*
*
*
*
*

call function 'BAPI_MATERIAL_SAVEDATA'


exporting
HEADDATA
= BAPI_HEAD
CLIENTDATA
= BAPI_MARA1
CLIENTDATAX
= BAPI_MARAX
PLANTDATA
= BAPI_MARC1
PLANTDATAX
= BAPI_MARCX
FORECASTPARAMETERS
=
FORECASTPARAMETERSX
=
PLANNINGDATA
=
PLANNINGDATAX
=
STORAGELOCATIONDATA
=
STORAGELOCATIONDATAX
=
VALUATIONDATA
= BAPI_MBEW1
VALUATIONDATAX
= BAPI_MBEWX
WAREHOUSENUMBERDATA
=
WAREHOUSENUMBERDATAX
=
SALESDATA
= BAPI_MVKE1
SALESDATAX
= BAPI_MVKEX

*
*

*
*
*
*
*
*
*
*
*
*

STORAGETYPEDATA
=
STORAGETYPEDATAX
=
IMPORTING
RETURN
= BAPI_RETURN
TABLES
MATERIALDESCRIPTION
= INT_MAKT
UNITSOFMEASURE
=
UNITSOFMEASUREX
=
INTERNATIONALARTNOS
=
MATERIALLONGTEXT
=
TAXCLASSIFICATIONS
=
RETURNMESSAGES
=
PRTDATA
=
PRTDATAX
=
EXTENSIONIN
=
EXTENSIONINX
=
.

IF BAPI_RETURN-TYPE = 'E'.
WRITE:/ 'Error Message ', BAPI_RETURN.
ENDIF.
ENDLOOP.
ENDFORM.
*---End of Program
BAPI_MATERIAL_MAINTAINDATA_RT
-----Original Message----Subject: BAPI_MATERIAL_MAINTAINDATA_RT
I'm attempting to use the 'BAPI_MATERIAL_MAINTAINDATA_RT' BAPI function.
Does anyone know what goes in the 'Function' field of the main import table. The same field also appears in
the parameter
tables.
Any idea, anyone.
-----Reply Message----Subject: RE: BAPI_MATERIAL_MAINTAINDATA_RT
check out transaction WE60 basic type ARTMAS01. This will give you documentation related to the idoc
basic type for this
function.
The segment documentation will give you the required values.
Regards,
-----End of Message----Material Master creation/change
-----Original Message----Subject: Material Master creation/change
Hi,

I would like to know if there is any BAPI in 4.5B for Material Master creation/change. i would really
appreciate if anyone
could help me out on this.
Thanks
-----Reply Message----Subject: RE: Material Master creation/change
BAPI_MATERIAL_SAVEDATA
-----End of Message---Material Master
-----Original Message----Subject: Material Master
Hi
I am trying to retrieve all material in the SAP system,
but the only Business object I have found (Material)
requires a key (Material Number)
I can not force it to retrieve all materials
Is there is a way I can use to retrieve all materials
If yes can you provide me with an example
Thankx in advance
-----Reply Message----Subject: RE: Material Master
Hi!
you have to use the Method MATERIAL.GETLIST. It gives you the material numbers
of all your material. Then you have to get the detail material data with
MATERIAL.GETDETAIL(material number).
MATERIAL ( BUS1001 ) is a Business Object in the BOR.
-----End of Message----Sample Abap code on BAPI_PO_CHANGE
DELETING PURCHASE ORDERS
*&---------------------------------------------------------------------*
*& Report ZMMR_DELETEPO
*
*&---------------------------------------------------------------------*
*& Author
: Bikash Agarwal
*& Description
: VTLS PO Change
*& Program Objective
: Places a DELETION indicator for the PO
*&
items given in the VTLS data
*& Remarks
: NA
*&---------------------------------------------------------------------*

REPORT ZMMR_DELETEPO NO STANDARD PAGE HEADING MESSAGE-ID zisb.


tables : zvtls_sap.
*C-- Types Declarations
TYPES : BEGIN OF tp_flatfile_vtls,
ebeln(10),
ebelp type ekpo-ebelp,
END OF tp_flatfile_vtls.
*=====================================================================
*
INTERNAL TABLES DECLARATION
*=====================================================================
DATA: t_flatfile_vtls TYPE tp_flatfile_vtls OCCURS 0 WITH HEADER LINE.
data : begin of t_sapdata occurs 0,
po like zvtls_sap-posap,
item like zvtls_sap-itemsap,
end of t_sapdata.
data : begin of t_flatfile_vtls1 occurs 0,
po(10),
item like zvtls_sap-itemsap,
end of t_flatfile_vtls1.
data : begin of t_update occurs 0,
mandt like zvtls_sap-mandt,
povtls like zvtls_sap-povtls,
itemvtls like zvtls_sap-itemvtls,
posap like zvtls_sap-posap,
itemsap like zvtls_sap-itemsap,
aedat like zvtls_sap-aedat,
paedt like zvtls_sap-paedt,
loekz like zvtls_sap-loekz,
end of t_update.
data : begin of t_poheader occurs 0,
po like zvtls_sap-posap,
end of t_poheader.
data : begin of t_poitem occurs 0,
po like zvtls_sap-posap,
item like zvtls_sap-itemsap,
end of t_poitem.
DATA : BEGIN OF T_MESSAGE OCCURS 0,
MSGTY,
MSGID(2),
MSGNO(3),
MSGTX(100),
PO like zvtls_sap-povtls,
item like zvtls_sap-itemvtls,
END OF T_MESSAGE.
DATA : BEGIN OF t_bapi_poheader OCCURS 0.
INCLUDE STRUCTURE bapimepoheader.
DATA : END OF t_bapi_poheader.
DATA : BEGIN OF t_bapi_poheaderx OCCURS 0.
INCLUDE STRUCTURE bapimepoheaderx.

DATA : END OF t_bapi_poheaderx.


DATA : BEGIN OF t_bapi_poitem OCCURS 0.
INCLUDE STRUCTURE bapimepoitem.
DATA : END OF t_bapi_poitem.
DATA : BEGIN OF t_bapi_poitemx OCCURS 0.
INCLUDE STRUCTURE bapimepoitemx.
DATA : END OF t_bapi_poitemx.
DATA : BEGIN OF t_bapireturn OCCURS 0.
INCLUDE STRUCTURE bapiret2.
DATA : END OF t_bapireturn.
*=====================================================================
*
V AR I AB LE S
*=====================================================================
DATA: w_success(6) TYPE n,
w_bklas like t023-bklas,
w_curryear(4),
w_begda like sy-datum,
w_endda like sy-datum,
w_begyr(4),
w_endyr(4),
w_currmon(2),
w_assetclass like ankt-anlkl,
w_price type p,
w_recordsap type i,
w_povtls(10),
w_count type i.
DATA: w_filepath TYPE rlgrap-filename,
w_rc TYPE sy-subrc,
w_sscrfields_ucomm1 TYPE sscrfields-ucomm,
w_file1 TYPE string,
w_file2 TYPE FILENAME-FILEINTERN.
*=====================================================================
*
C O N S TAN TS
*=====================================================================
CONSTANTS: c_x
TYPE c
VALUE 'X',
c_hyp
TYPE c
VALUE '-',
c_err
TYPE bdc_mart VALUE 'E'.
CONSTANTS: c_slash(1)
TYPE c VALUE '/',
c_hash(1)
TYPE c VALUE '#',
c_pipe
TYPE c VALUE '|',
c_1
TYPE i VALUE 1,
c_zero
TYPE n VALUE '0',
c_rg1(3)
TYPE c VALUE 'rg1',
c_gr3(3)
TYPE c VALUE 'GR3',
c_gr2(3)
TYPE c VALUE 'GR2',
c_e(1)
TYPE c VALUE 'E',
c_filepath(8)
TYPE c VALUE '/interf/',
c_filetype(10)
TYPE c VALUE 'ASC'.
CONSTANTS : c_bapimepoheaderx TYPE x030l-tabname
VALUE 'bapimepoheaderx',
c_bapimepoitem
TYPE x030l-tabname
VALUE 'bapimepoitem',

c_bapimepoaccount TYPE x030l-tabname


VALUE 'bapimepoaccount',
c_t_bapi_poheader(15)
TYPE c
VALUE 't_bapi_poheader',
c_t_bapi_poitem(13)
TYPE c
VALUE 't_bapi_poitem',
c_t_bapi_poitemx(14)
TYPE c
VALUE 't_bapi_poitemx',
c_t_bapi_poheaderx(16)
TYPE c
VALUE 't_bapi_poheaderx'.
CLASS cl_abap_char_utilities DEFINITION LOAD.
CONSTANTS:con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
*======================================================================
*
SELECTION SCREEN
*======================================================================
SELECTION-SCREEN BEGIN OF BLOCK inputpath WITH FRAME TITLE text-001.
SELECTION-SCREEN : BEGIN OF BLOCK blk2 WITH FRAME TITLE text-002.
PARAMETERS : p_fore RADIOBUTTON GROUP rg1
USER-COMMAND pc,
p_back RADIOBUTTON GROUP rg1 DEFAULT 'X'.
SELECTION-SCREEN : END OF BLOCK blk2.
SELECTION-SCREEN : BEGIN OF BLOCK blk1 WITH FRAME TITLE text-003.
PARAMETERS : p_file1 LIKE rlgrap-filename OBLIGATORY MODIF ID gr2.
PARAMETERS : p_afile1 LIKE rlgrap-filename OBLIGATORY MODIF ID gr3.
SELECTION-SCREEN : END OF BLOCK blk1.
SELECTION-SCREEN END OF BLOCK inputpath.
*C-- Initialization Event
INITIALIZATION.
CLEAR w_filepath.
CONCATENATE c_filepath sy-sysid c_slash sy-mandt c_slash INTO
w_filepath.
CONDENSE w_filepath NO-GAPS.
p_file1 = text-008.
p_afile1 = text-009.
*======================================================================
*
SELECTION SCREEN EVENTS
*======================================================================
*C-- Selection Screen Output
AT SELECTION-SCREEN OUTPUT.
IF p_fore = c_x.
w_sscrfields_ucomm1 = space.
ELSE.
w_sscrfields_ucomm1 = c_rg1.
ENDIF.
LOOP AT SCREEN.

*C--Modify selection screen if presentation


*C--or application server radio button is chosen
IF w_sscrfields_ucomm1 = space.
IF screen-group1 = c_gr3.
screen-active = c_zero.
ENDIF.
ELSE.
IF screen-group1 = c_gr2.
screen-active = c_zero.
ENDIF.
ENDIF.
if screen-name = 'P_AFILE1'.
screen-input = 0.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
*C-- Selection Screen VALUE-REQUEST FOR File path
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file1.
IF p_fore EQ c_x.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
IMPORTING
file_name = p_file1.
ENDIF.
*C-- At Start of the Selection Process
START-OF-SELECTION.
IF p_fore EQ c_x.
w_file1 = p_file1.
ELSE.
w_file2 = p_afile1.
ENDIF.
IF p_fore EQ c_x. " Presentaion Server
*C--Validations for the input files
PERFORM validate_pre_file USING p_file1.
*C-- Load the contents of the input file into the internal table
PERFORM upload_file TABLES t_flatfile_vtls
USING w_file1
CHANGING w_rc.
IF w_rc <> 0.
MESSAGE s006 DISPLAY LIKE c_e.
ENDIF.
ELSE. " Application Server

*C--Validations for the input files


PERFORM validate_app_file USING w_file2.
*C-- Load the contents of the input file into the internal table
PERFORM upload_file_app TABLES t_flatfile_vtls
USING w_file2
CHANGING w_rc.
ENDIF.
loop at t_flatfile_vtls.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = t_flatfile_vtls-ebeln
IMPORTING
output = t_flatfile_vtls1-po.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = t_flatfile_vtls-ebelp
IMPORTING
output = t_flatfile_vtls1-item.
append t_flatfile_vtls1.
clear t_flatfile_vtls1.
endloop.
perform get_podata.
loop at t_poheader.
perform move_to_bapi.
perform call_bapi.
endloop.
PERFORM STORE_MESSAGES TABLES T_MESSAGE.
*&--------------------------------------------------------------------*
*&
Form validate_pre_file
*&--------------------------------------------------------------------*
* Routine to validate presentation server file path.
*---------------------------------------------------------------------*
*
-->fp_name text
*---------------------------------------------------------------------*
FORM validate_pre_file USING fp_name TYPE rlgrap-filename.
DATA : l_result,
l_filename TYPE string.
l_filename = fp_name.
CLEAR l_result.
CALL METHOD cl_gui_frontend_services=>file_exist

EXPORTING
file
= l_filename
RECEIVING
result
= l_result
EXCEPTIONS
cntl_error
=1
error_no_gui
=2
wrong_parameter
=3
not_supported_by_gui = 4
OTHERS
= 5.
IF sy-subrc <> 0.
MESSAGE s007 DISPLAY LIKE c_e.
LEAVE LIST-PROCESSING.
ELSEIF l_result IS INITIAL.
MESSAGE s008 DISPLAY LIKE c_e.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM.

" validate_pre_file_hdr

*&--------------------------------------------------------------------*
*&
Form validate_app_file
*&--------------------------------------------------------------------*
*
text - Checks if the path entered and filename is correct
*---------------------------------------------------------------------*
FORM validate_app_file USING fp_file TYPE FILENAME-FILEINTERN.
data : l_fname(60).
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
LOGICAL_FILENAME = FP_FILE
OPERATING_SYSTEM = SY-OPSYS
IMPORTING
FILE_NAME
= L_FNAME
EXCEPTIONS
FILE_NOT_FOUND = 1
OTHERS
= 2.
IF SY-SUBRC = '0'.
OPEN DATASET L_FNAME FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
MESSAGE s007 DISPLAY LIKE c_e.
ELSE.
CLOSE DATASET l_fname.
ENDIF.
ENDIF.
ENDFORM.

" validate_app_file

*&--------------------------------------------------------------------*
*&
Form upload_file
*&--------------------------------------------------------------------*
*
Routine to upload data from file to tables.
*---------------------------------------------------------------------*
*
-->P_fp_flatfile

*
-->P_fp_file
*
<--P_fp_rc
*---------------------------------------------------------------------*
FORM upload_file TABLES fp_flatfile
USING fp_file TYPE string
CHANGING fp_rc TYPE sy-subrc.
IF fp_flatfile[] IS INITIAL.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename
= fp_file
filetype
= c_filetype
has_field_separator = c_x
TABLES
data_tab
= fp_flatfile
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.
MOVE sy-subrc TO fp_rc.
ENDIF.
ENDFORM. " upload_file
*&--------------------------------------------------------------------*
*&
Form upload_file_app
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
*
-->FP_FLATFILEtext
*
-->FP_FILE text
*
-->FP_RC
text
*---------------------------------------------------------------------*
FORM upload_file_app TABLES fp_flatfile
USING fp_file TYPE FILENAME-FILEINTERN
CHANGING fp_rc TYPE sy-subrc.
DATA: l_string TYPE tedata-data.
DATA: wa_data_file TYPE tp_flatfile_vtls,
l_wllength TYPE i,
FNAME(60).
CALL FUNCTION 'FILE_GET_NAME'

EXPORTING
LOGICAL_FILENAME = FP_FILE
OPERATING_SYSTEM = SY-OPSYS
IMPORTING
FILE_NAME
= FNAME
EXCEPTIONS
FILE_NOT_FOUND = 1
OTHERS
= 2.
IF SY-SUBRC = 0.
OPEN DATASET FNAME FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
* *C-- commented by Bikash
*
MESSAGE s107(yaero_ps) DISPLAY LIKE c_e.
message e008.
ELSE.
DO.
CLEAR: l_string.
READ DATASET FNAME INTO l_string LENGTH l_wllength.
IF sy-subrc NE 0.
EXIT.
ELSE.
SPLIT l_string AT con_tab INTO wa_data_file-ebeln
wa_data_file-ebelp.
APPEND wa_data_file TO fp_flatfile.
ENDIF.
ENDDO.
CLOSE DATASET FNAME.
ENDIF.
ENDIF.
ENDFORM. " upload_file_app
*&--------------------------------------------------------------------*
*&
Form get_podata
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
form get_podata.
select *
into table t_update
from zvtls_sap
for all entries in t_flatfile_vtls1
where itemvtls = t_flatfile_vtls1-item
and povtls = t_flatfile_vtls1-po.
sort t_update by posap itemsap.
loop at t_update.
at new posap.
t_poheader-po = t_update-posap.
append t_poheader.
clear t_poheader.

endat.
t_poitem-po = t_update-posap.
t_poitem-item = t_update-itemsap.
append t_poitem.
clear t_poitem.
t_update-paedt = sy-datum.
t_update-loekz = 'X'.
modify t_update.
endloop.
modify zvtls_sap from table t_update.
endform.

"get_podata

*&--------------------------------------------------------------------*
*&
Form move_to_bapi
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
form move_to_bapi.
t_bapi_poheader-po_number = t_poheader-po.
CLEAR t_bapi_poheaderx.
PERFORM fill_check_structure USING c_bapimepoheaderx
c_t_bapi_poheader
c_t_bapi_poheaderx
c_x.
refresh : t_bapi_poitem,t_bapi_poitemx.
loop at t_poitem where po = t_poheader-po.
clear t_bapi_poitem.
t_bapi_poitem-po_item = t_poitem-item.
t_bapi_poitem-delete_ind = 'X'.
CLEAR t_bapi_poitemx.
PERFORM fill_check_structure USING c_bapimepoitem
c_t_bapi_poitem
c_t_bapi_poitemx
c_x.
t_bapi_poitemx-po_item = t_poitem-item.
t_bapi_poitemx-po_itemx = c_x.
APPEND t_bapi_poitem.
APPEND t_bapi_poitemx.
clear t_bapi_poitem.
clear t_bapi_poitemx.
endloop.
endform.

"move_to_bapi

*&--------------------------------------------------------------------*
*&
Form call_bapi
*&--------------------------------------------------------------------*

*
This form Routine is used to commit the data records
*----------------------------------------------------------------------*
FORM call_bapi .
DATA : l_msgty
TYPE c,
l_msgid(2) TYPE c,
l_msgno(3) TYPE c,
l_msgtx(100) TYPE c,
l_errflag TYPE c.
CLEAR: t_bapireturn.
REFRESH: t_bapireturn.
CALL FUNCTION 'BAPI_PO_CHANGE'
EXPORTING
PURCHASEORDER = T_POHEADER-PO
POHEADER
= T_BAPI_POHEADER
POHEADERX = T_BAPI_POHEADERX
TABLES
RETURN
= T_BAPIRETURN
POITEM
= T_BAPI_POITEM
POITEMX
= T_BAPI_POITEMX.
READ TABLE t_bapireturn WITH KEY type = c_err TRANSPORTING NO FIELDS.
IF sy-subrc NE 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = c_x.
ENDIF.
*C-- Write messages
WRITE: / 'PO Number', t_poheader-po.
clear : t_update,w_povtls.
read table t_update with key posap = t_poheader-po.
w_povtls = t_update-povtls.
CLEAR l_errflag.
LOOP AT t_bapireturn.
CLEAR: l_msgty, l_msgid, l_msgno, l_msgtx.
l_msgty = t_bapireturn-type.
l_msgid = t_bapireturn-id.
l_msgno = t_bapireturn-number.
l_msgtx = t_bapireturn-message.
WRITE: / l_msgty, l_msgid, l_msgno, l_msgtx.
if l_msgtx cs t_poheader-po.
w_count = w_count + 1.
loop at t_update.
if sy-tabix = w_count.
t_message-item = t_update-itemvtls.
endif.
endloop.
endif.
t_message-msgty = l_msgty.
t_message-msgid = l_msgid.

t_message-msgno = l_msgno.
t_message-msgtx = l_msgtx.
t_message-po = w_povtls.
append t_message.
clear t_message.
IF l_msgty EQ c_err.
l_errflag = c_x.
ENDIF. " l_msgty EQ 'E'
ENDLOOP.
ULINE.
IF l_errflag NE c_x.
w_success = w_success + 1.
ENDIF. " l_errflag NE C_X
endform.

"call_bapi

*&--------------------------------------------------------------------*
*&
Form fill_check_structure
*&--------------------------------------------------------------------*
*
This form Routine will check whether the specified structure
*
exist/active
*---------------------------------------------------------------------*
FORM fill_check_structure USING fp_tabname TYPE any
fp_orgtabname TYPE any
fp_chktabname TYPE any
fp_check TYPE c.
FIELD-SYMBOLS : <fs_chk>, <fs_org>.
DATA: l_char1(61) TYPE c,
l_char2(61) TYPE c.
DATA: BEGIN OF tl_nametab OCCURS 60.
INCLUDE STRUCTURE x031l.
DATA: END OF tl_nametab.
REFRESH tl_nametab.
CALL FUNCTION 'RFC_GET_NAMETAB'
EXPORTING
tabname
= fp_tabname
TABLES
nametab
= tl_nametab
EXCEPTIONS
table_not_active = 1
OTHERS
= 2.
IF sy-subrc <> 0.
CLEAR tl_nametab.
ENDIF.
LOOP AT tl_nametab.
CLEAR: l_char1, l_char2.
CONCATENATE fp_chktabname c_hyp tl_nametab-fieldname INTO l_char1.
ASSIGN (l_char1) TO <fs_chk>.
CONCATENATE fp_orgtabname c_hyp tl_nametab-fieldname INTO l_char2.
ASSIGN (l_char2) TO <fs_org>.
IF <fs_org> IS NOT INITIAL.

<fs_chk> = fp_check.
ENDIF.
ENDLOOP.
ENDFORM.

" fill_check_structure

*&--------------------------------------------------------------------*
*&
Form STORE_MESSAGES
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
*
-->FP_MESSAGEStext
*---------------------------------------------------------------------*
FORM STORE_MESSAGES TABLES FP_MESSAGES STRUCTURE T_MESSAGE.
DATA: wl_output_data LIKE t_MESSAGE.
DATA: l_catstr TYPE string.
DATA: l_fieldvalue TYPE string.
DATA: l_index TYPE i VALUE 1.
DATA: L_FNAME(60).
FIELD-SYMBOLS <fs>.
CLEAR l_catstr.
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
LOGICAL_FILENAME = '/USR/SAP/VTLS/POCHANGE/LOG'
OPERATING_SYSTEM = SY-OPSYS
IMPORTING
FILE_NAME
= L_FNAME
EXCEPTIONS
FILE_NOT_FOUND = 1
OTHERS
= 2.
IF SY-SUBRC = '0'.
IF fp_messages[] IS NOT INITIAL.
OPEN DATASET L_FNAME FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
LEAVE LIST-PROCESSING.
ELSE.
LOOP AT fp_messages INTO wl_output_data.
DO.
ASSIGN COMPONENT l_index OF STRUCTURE wl_output_data TO <fs>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
MOVE <fs> TO l_fieldvalue.
IF l_catstr IS NOT INITIAL.

CONCATENATE l_catstr l_fieldvalue INTO l_catstr SEPARATED


BY con_tab.
ELSE.
MOVE l_fieldvalue TO l_catstr.
ENDIF.
l_index = l_index + c_1.
CLEAR l_fieldvalue.
CLEAR <fs>.
ENDDO.
l_index = c_1.
TRANSFER l_catstr TO L_FNAME .
CLEAR wl_output_data.
CLEAR l_catstr.
ENDLOOP.
CLOSE DATASET L_FNAME.
ENDIF.
ENDIF.
ENDIF.

ENDFORM.

"STORE_MESSAGES

BAPI_ALM_NOTIF_CREATE - Maintenance Notification


I am trying to use BAPI "BAPI_ALM_NOTIF_CREATE" to create Maintenance Notification. I am
working on SAP ECC 5.0 Version. When I try to create the same using IW21 transaction, by just
passing Notificaiton type, Equiment Number and short text, I am able to create the notification.
If I try to pass the same value to BAPI, I am not getting the notification created, but also it is not
giving back any message to return table.
To create items, causes, tasks, or actions, the sort field must be filled.
When you create a cause, the sort field of the item must also be filled.
When you create a long text, the fields OBJTYP and OBJKEY must be filled. OBJTYP can have the
following values:
1. QMEL - Notification header
2. QMFE - Notification item
3. QMUR - Notification cause

4. QMSM - Notification task


5. QMMA - Notification action
OBJKEY must have the corresponding sort field for the values named above. The combination of sort field
of item/cause, item/task and item/action must be unique within a notification. If you leave the sort field empty
and the OBJTYP = QME, then a long text is created for the notification header.
In the field REFOBJECTKEY an external reference can be transferred. The link between external reference
keys and R/3 keys is transferred in the export table KEY_RELATIONSHIP. If the fields SENDER,
REFOBJECTTYPE and REFRELTYPE are filled, then an object link can be created at notification header
level
BAPI to create Sales Order with reference
-----Original Message----Subject: BAPI to create Sales Order with reference
Hello,
I am trying to create Sales Order with reference to Scheduling Agreement, but although the
order gets created, it does not contain reference document information.
The BAPI I am using is BAPI_SALESORDER_CREATEFROMDAT2.
Would someone know which parameters I have to papulate,or have any other suggestion
how to accomplish my task?
Thank you so much,
-----Reply Message----Subject: RE: BAPI to create Sales Order with reference
Try using
ORDER_HEADER_IN-REFDOCTYPE = Your Sch. Agreement No. (Please Check) and
ORDER_HEADER_IN-SD_DOC_CAT = 'E'.
-----Reply Message----Subject: RE: BAPI to create Sales Order with reference
Thank you so much for your quick responce.
Here are the parameters I am populating (including the once you have mentioned).
Unfortunately, the order gets created with out Scheduling Agreement reference.
Any idea why?
Thank you,
************** CODE **************************************
* local data
DATA: HEADER LIKE BAPISDHD1.
DATA: I_PARTNERS LIKE BAPIPARNR OCCURS 1 WITH HEADER LINE.
DATA: I_ITEM LIKE BAPISDITM OCCURS 10 WITH HEADER LINE.
DATA: I_SCHEDULE LIKE BAPISCHDL OCCURS 10 WITH HEADER LINE.
DATA: RETURN LIKE BAPIRET2 OCCURS 1 WITH HEADER LINE.

* order header values


HEADER-DOC_TYPE = 'ZSED'.
HEADER-SALES_ORG = ZCONSGAGRMWK-VKORG.
HEADER-DISTR_CHAN = ZCONSGAGRMWK-VTWEG.
HEADER-DIVISION = ZCONSGAGRMWK-SPART.
HEADER-PURCH_DATE = ZCONSGACTVSV-TRNACTDAT.
HEADER-PURCH_NO_C = ZCONSGACTVWK-PONUM.
HEADER-REF_DOC = ZCONSGAGRMSV-SCHDAGRM.
HEADER-REFDOC_CAT = 'E'.
HEADER-ASS_NUMBER = ZCONSGACTVSV-HUBREFNUM.
* order item level data
I_ITEM-ITM_NUMBER = '000010'.
I_ITEM-MATERIAL = ZCONSGACTVSV-MLXPART.
I_ITEM-ROUTE = CON-ROUTE.
IF NOT ZCONSGAGRMSV-CHARG IS INITIAL.
I_ITEM-BATCH = ZCONSGAGRMSV-CHARG.
ELSE.
I_ITEM-BATCH = '1'.
ENDIF.
I_SCHEDULE-ITM_NUMBER = '000010'.
I_SCHEDULE-REQ_QTY = ZCONSGACTVWK-QTY.
I_PARTNERS-PARTN_ROLE = 'AG'. " Soldto
I_PARTNERS-PARTN_NUMB = ZCONSGAGRMSV-SOLDTO.
APPEND: I_ITEM,
I_SCHEDULE,
I_PARTNERS.
CLEAR: I_ITEM,
I_SCHEDULE,
I_PARTNERS.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
* SALESDOCUMENTIN =
ORDER_HEADER_IN = HEADER
* ORDER_HEADER_INX =
* SENDER =
* BINARY_RELATIONSHIPTYPE =
* INT_NUMBER_ASSIGNMENT =
* BEHAVE_WHEN_ERROR =
* LOGIC_SWITCH =
* TESTRUN =
* CONVERT = ' '
IMPORTING
SALESDOCUMENT = ORDER
TABLES
RETURN = RETURN
ORDER_ITEMS_IN = I_ITEM
* ORDER_ITEMS_INX =
ORDER_PARTNERS = I_PARTNERS
ORDER_SCHEDULES_IN = I_SCHEDULE
* ORDER_SCHEDULES_INX =
* ORDER_CONDITIONS_IN =
* ORDER_CFGS_REF =
* ORDER_CFGS_INST =

* ORDER_CFGS_PART_OF =
* ORDER_CFGS_VALUE =
* ORDER_CFGS_BLOB =
* ORDER_CFGS_VK =
* ORDER_CFGS_REFINST =
* ORDER_CCARD =
* ORDER_TEXT =
* ORDER_KEYS =
* EXTENSIONIN =
* PARTNERADDRESSES =
.
-----Reply Message----Subject: RE: BAPI to create Sales Order with reference
FM BAPI_SALESDOCUMENT_COPY is what you are looking for. Don't know when SAP
released this one, but its not there in 4.0B and is available in rel 4.6C
-----End of Message----BAPI_SALESORDER_CREATEFROMDAT2 - Sales Order Create
Please help with an exact code which this BAPI is used for creating Sales order so that I can refer.
*&---------------------------------------------------------------------*
*& Report ZBAPI_SALESORDER_CREATE
*&
*&---------------------------------------------------------------------*
*&
*& Author : Karthik
*&---------------------------------------------------------------------*
REPORT ZBAPI_SALESORDER_CREATE.
data : ORDER_HEADER_IN like BAPISDHD1.
data : ORDER_ITEMS_IN like BAPISDITM occurs 0 with
header line.
data : RETURN like BAPIRET2 occurs 0 with header line.
data : ORDER_PARTNERS like BAPIPARNR occurs 0 with
header line.
DATA : ORDER_KEYS LIKE BAPISDKEY OCCURS 0 WITH HEADER
LINE.
data : ORDER_SCHEDULES_IN like BAPISCHDL occurs 0 with
header line.
data : BEGIN OF TAB OCCURS 0,
SRNO(4),
DOC_TYPE like ORDER_HEADER_IN-dOC_TYPE,
SALES_ORG LIKE ORDER_HEADER_IN-SALES_ORG,
DISTR_CHAN LIKE ORDER_HEADER_IN-DISTR_CHAN,
DIVISION like ORDER_HEADER_IN-DIVISION,
*
REQ_DATE_H(10),
PURCH_DATE(10),
PMNTTRMS LIKE ORDER_HEADER_IN-PMNTTRMS,
PURCH_NO_C LIKE ORDER_HEADER_IN-PURCH_NO_C,
ITM_NUMBER like BAPISDITM-ITM_NUMBER,
CUST_MAT22 LIKE ORDER_ITEMS_IN-CUST_MAT22,
PLANT LIKE ORDER_ITEMS_IN-PLANT,
TARGET_QTY LIKE ORDER_ITEMS_IN-TARGET_QTY,
PARTN_ROLE LIKE ORDER_PARTNERS-PARTN_ROLE,
PARTN_NUMB LIKE ORDER_PARTNERS-PARTN_NUMB,

END OF TAB.
data: itab1 like alsmex_tabline occurs 0 with header
line.
DATA: gd_currentrow type i.
data : PURCHASEORDER like ekko-ebeln.
Data: tot_rec type i, "Total Records
gd_update type i, "Main Table Increement Counter
gd_lines type i, "Success Table increement Counter
w_textout like t100-text. "VARIABLE TO GET ERRORLOG
data : begin of it_success occurs 0,
SALESDOCUMENT LIKE BAPIVBELN-VBELN, "PROJECT
end of it_success.
data : begin of it_error occurs 0,
srno(4),
err_msg(73) TYPE c, "TO RETREIVE ERROR MESSAGES
end of it_error.
data : srno(4).
DATA : SALESDOCUMENT LIKE BAPIVBELN-VBELN.
selection-screen begin of block b1 with frame.
skip 3.
parameter:p_infile like rlgrap-filename obligatory.
skip 3.
selection-screen end of block b1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_infile.
PERFORM value_help.
start-of-selection.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename
= p_infile
i_begin_col
= '1'
i_begin_row
= '2' "Do not require
headings
i_end_col
= '22'
i_end_row
= '10000'
TABLES
intern
= itab1
EXCEPTIONS
inconsistent_parameters = 1
upload_ole
=2
others
= 3.
if sy-subrc <> 0.
message e010(zz) with text-001. "Problem uploading
Excel Spreadsheet
endif.
*perform open_group.
sort itab1 by row col.
* Get first row retrieved
read table itab1 index 1.
* Set first row retrieved to current row
gd_currentrow = itab1-row.
loop at itab1.

* Reset values for next row


if itab1-row ne gd_currentrow.
append tab .
clear tab.
gd_currentrow = itab1-row.
endif.
SHIFT ITAB1-VALUE LEFT DELETING LEADING SPACE.
case itab1-col.
when '0001'.
TAB-SRNO = itab1-value.
when '0002'.
TAB-DOC_TYPE = itab1-value.
when '0003'.
TAB-SALES_ORG = itab1-value.
when '0004'.
TAB-DISTR_CHAN = itab1-value.
when '0005'.
TAB-DIVISION = itab1-value.
*
when '0006'.
*
TAB-REQ_DATE_H = itab1-value.
when '0006'.
TAB-PURCH_DATE = itab1-value.
when '0007'.
TAB-PMNTTRMS = itab1-value.
when '0008'.
TAB-PURCH_NO_C = itab1-value.
when '0009'.
TAB-ITM_NUMBER = itab1-value.
when '0010'.
TAB-CUST_MAT22 = itab1-value.
when '0011'.
TAB-PLANT = itab1-value.
when '0012'.
TAB-TARGET_QTY = itab1-value.
when '0013'.
TAB-PARTN_ROLE = itab1-value.
when '0014'.
TAB-PARTN_NUMB = itab1-value.
endcase.
endloop.
append tab.
clear tab.
sort tab by SRNO.
LOOP AT TAB.
* concatenate tab-REQ_DATE_H+4(4)
tab-REQ_DATE_H+2(2) tab-REQ_DATE_H+0(2) into
tab-REQ_DATE_H.
concatenate tab-PURCH_DATE+4(4)
tab-PURCH_DATE+2(2) tab-PURCH_DATE+0(2) into
tab-PURCH_DATE.
SRNO = TAB-SRNO.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = tab-PARTN_NUMB
IMPORTING
OUTPUT = tab-PARTN_NUMB.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'


EXPORTING
INPUT = tab-CUST_MAT22
IMPORTING
OUTPUT = tab-CUST_MAT22.
IF TAB-SRNO = SRNO.
ORDER_HEADER_IN-DOC_TYPE = TAB-DOC_TYPE.
ORDER_HEADER_IN-SALES_ORG = TAB-SALES_ORG.
ORDER_HEADER_IN-DISTR_CHAN = TAB-DISTR_CHAN.
*
ORDER_HEADER_IN-REQ_DATE_H = TAB-REQ_DATE_H.
ORDER_HEADER_IN-PURCH_DATE = TAB-PURCH_DATE.
ORDER_HEADER_IN-PMNTTRMS = TAB-PMNTTRMS.
ORDER_HEADER_IN-PURCH_NO_C = TAB-PURCH_NO_C.
ORDER_HEADER_IN-DIVISION = tab-DIVISION.
ORDER_ITEMS_IN-ITM_NUMBER = tab-ITM_NUMBER.
ORDER_ITEMS_IN-material = TAB-CUST_MAT22.
ORDER_ITEMS_IN-PLANT
= TAB-PLANT.
APPEND ORDER_ITEMS_IN.
ORDER_PARTNERS-PARTN_ROLE = TAB-PARTN_ROLE.
ORDER_PARTNERS-PARTN_NUMB = TAB-PARTN_NUMB.
APPEND ORDER_PARTNERS.
ORDER_SCHEDULES_IN-ITM_NUMBER = tab-ITM_NUMBER.
ORDER_SCHEDULES_IN-REQ_QTY = tab-TARGET_QTY.
append ORDER_SCHEDULES_IN.
ENDIF.

*
*
*
*
*
*
*
*
*

*
*
*
*
*
*
*
*
*
*
*
*
*

AT END OF SRNO.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
SALESDOCUMENTIN
=
ORDER_HEADER_IN
= ORDER_HEADER_IN
ORDER_HEADER_INX
=
SENDER
=
BINARY_RELATIONSHIPTYPE
=
INT_NUMBER_ASSIGNMENT
=
BEHAVE_WHEN_ERROR
=
LOGIC_SWITCH
=
TESTRUN
=
CONVERT
=''
IMPORTING
SALESDOCUMENT
= SALESDOCUMENT
TABLES
RETURN
= RETURN
ORDER_ITEMS_IN
= ORDER_ITEMS_IN
ORDER_ITEMS_INX
=
ORDER_PARTNERS
= ORDER_PARTNERS
ORDER_SCHEDULES_IN
= ORDER_SCHEDULES_IN
ORDER_SCHEDULES_INX
=
ORDER_CONDITIONS_IN
=
ORDER_CONDITIONS_INX
=
ORDER_CFGS_REF
=
ORDER_CFGS_INST
=
ORDER_CFGS_PART_OF
=
ORDER_CFGS_VALUE
=
ORDER_CFGS_BLOB
=
ORDER_CFGS_VK
=
ORDER_CFGS_REFINST
=
ORDER_CCARD
=
ORDER_TEXT
=

*
*

ORDER_KEYS
= ORDER_KEYS
EXTENSIONIN
=
PARTNERADDRESSES
=
.

IF SALESDOCUMENT <> SPACE.


commit work.
ADD 1 TO gd_update.
it_success-SALESDOCUMENT = SALESDOCUMENT.
append it_success.
CLEAR :SALESDOCUMENT,ORDER_HEADER_IN.
REFRESH : RETURN,ORDER_ITEMS_IN,ORDER_PARTNERS.
ELSE.
loop at return.
it_error-SRNO = tab-SRNO.
it_error-err_msg = return-MESSAGE .
Append it_error.
ENDLOOP.
CLEAR :SALESDOCUMENT,ORDER_HEADER_IN.
REFRESH : RETURN,ORDER_ITEMS_IN,ORDER_PARTNERS.
ENDIF.
endat.
endloop.
DESCRIBE TABLE it_success LINES gd_lines.
IF gd_lines GT 0.
* Display result report column headings
PERFORM display_column_headings.
* Display result report
PERFORM DISPLAY_SUCESS.
ENDIF.
* IF SUCESS FAILS Display Error Report
DESCRIBE TABLE it_error LINES gd_lines.
IF gd_lines GT 0.
PERFORM errorheadings.
PERFORM errorreport.
ENDIF.
*&---------------------------------------------------------------------*
*&
Form display_column_headings
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM display_column_headings.
WRITE:2 ' Success Report '(014) COLOR COL_POSITIVE.
SKIP.
WRITE:2 'The following records inserted
successfully:'(013).
WRITE:/ sy-uline(15).
FORMAT COLOR COL_HEADING.
WRITE:/
sy-vline,
(10) 'Sales order'(004), sy-vline.
WRITE:/ sy-uline(15).
ENDFORM.
"display_column_headings
*Subroutine to display SUCESS REPORT
FORM DISPLAY_SUCESS.
FORMAT COLOR COL_NORMAL.
LOOP AT it_success.
WRITE:/
sy-vline,
(10) it_success-SALESDOCUMENT, sy-vline.

CLEAR it_success.
ENDLOOP.
WRITE:/ sy-uline(15).
REFRESH: it_success.
FORMAT COLOR COL_BACKGROUND.
ENDFORM.
"
DISPLAY_REPORT
*&---------------------------------------------------------------------*
*&
Form errorreport
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM errorreport.
LOOP AT it_error.
WRITE:/
sy-vline,
(10) it_error-SRNO, sy-vline,
(40) it_error-err_msg, sy-vline.
ENDLOOP.
WRITE:/ sy-uline(104).
REFRESH: it_error.
endform.

"errorreport

*&---------------------------------------------------------------------*
*&
Form ERRORHEADINGS
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM ERRORHEADINGS.
SKIP.
WRITE:2 ' Error Report '(007) COLOR COL_NEGATIVE.
SKIP.
WRITE:2 'The following records failed during
update:'(008).
WRITE:/ sy-uline(104).
FORMAT COLOR COL_HEADING.
WRITE:/
sy-vline,
(10) 'ERROR.'(009), sy-vline.
WRITE:/ sy-uline(104).
FORMAT COLOR COL_NORMAL.
ENDFORM.
"ERRORHEADINGS
**&--------------------------------------------------------------------**
**&
Form value_help
**&--------------------------------------------------------------------**
**
text
**---------------------------------------------------------------------**
** --> p1
text
** <-- p2
text
**---------------------------------------------------------------------**
FORM value_help .
CALL FUNCTION 'DSVAS_DOC_WS_FILENAME_GET_50'
EXPORTING
DEF_FILENAME = ' '
DEF_PATH
=''
MASK
= ',*.*,*.*.'
MODE
= 'O'

TITLE
=''
IMPORTING
FILENAME
= p_infile
EXCEPTIONS
INV_WINSYS
=1
NO_BATCH
=2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS
= 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endform.

"value_help

BAPI_CUSTMATINFO_GETLIST - Customer Material Info


This is a sample program using BAPI to get the customer material information.
*&---------------------------------------------------------------------*
*& Report ZBAPITEST
*&
*&---------------------------------------------------------------------*
REPORT ZBAPITEST.
tables: knmt.
data: i_salesorgrange type standard table of bapi_rangesvkorg with header line,
i_distrchanrange type standard table of bapi_rangesvtweg with header line,
i_customerrange type standard table of bapi_rangeskunnr with header line,
i_materialrange type standard table of bapi_rangesmatnr with header line,
i_customermaterialinfo type standard table of bapi_bus3033_boid with header line,
i_customermaterialinfodetail type standard table of bapi_bus3033_knmt_disp with header line,
i_return type standard table of bapiret2 with header line.
selection-screen begin of block b1 with frame title text-001.
select-options: p_sorg for knmt-vkorg,
p_dcha for knmt-vtweg,
p_cust for knmt-kunnr.
selection-screen end of block b1.
start-of-selection.
move p_sorg[] to i_salesorgrange[].
move p_dcha[] to i_distrchanrange[].
move p_cust[] to i_customerrange[].
call function 'BAPI_CUSTMATINFO_GETLIST'
tables
salesorgrange
= i_salesorgrange[]
distrchanrange
= i_distrchanrange[]
customerrange
= i_customerrange[]
customermaterialinfo
= i_customermaterialinfo[]
customermaterialinfodetail
= i_customermaterialinfodetail[]

return

= i_return[].

loop at i_customermaterialinfodetail.
write:/ i_customermaterialinfodetail-customer,' - ',i_customermaterialinfodetail-material,' - ',
i_customermaterialinfodetail-mat_nr_cus.
endloop.
end-of-selection.

BAPI and JAVA Program to Interface Two System


I am working with a client, who wish to use both SAP and P3e. The data from SAP will be send back
to P3e. With respect to this I am working on field mapping betweem the 2 systems.
Develope Z Bapi using the standard BAPI and use jave program to interface these two system. We are also
working on the same and for your help, please find attached the ZBAPI developed. *-- Waris

FUNCTION zbapi_project_maintain.
*"---------------------------------------------------------------------*"*"Local interface:
*" IMPORTING
*" VALUE(WBS_ELEMENT) LIKE BAPI_WBS_ELEMENT-WBS_ELEMENT
*" VALUE(WBS_ELEMENT_DESCRIPTION) LIKE
*"
BAPI_PROJECT_DEFINITION-DESCRIPTION
*" VALUE(WBS_ELEMENT1) LIKE BAPI_WBS_ELEMENT-WBS_ELEMENT
*" VALUE(PROJECT_DEFINITION) LIKE
*"
BAPI_WBS_ELEMENT-PROJECT_DEFINITION
*" VALUE(DESCRIPTION) LIKE BAPI_PROJECT_DEFINITION-DESCRIPTION
*" VALUE(NETWORK) LIKE BAPI_NETWORK-NETWORK
*" VALUE(NETWORK1) LIKE BAPI_NETWORK-NETWORK
*" VALUE(NETWORK_TYPE) LIKE BAPI_NETWORK-NETWORK_TYPE
*" VALUE(PROFILE) LIKE BAPI_NETWORK-PROFILE
*" VALUE(ACTIVITY) LIKE BAPI_NETWORK_ACTIVITY-ACTIVITY
*" VALUE(CONTROL_KEY) LIKE BAPI_NETWORK_ACTIVITY-CONTROL_KEY
*" VALUE(ACT_DESC) LIKE BAPI_NETWORK_ACTIVITY-DESCRIPTION
*" VALUE(NETWORK_PREDECESSOR) LIKE
*"
BAPI_NETWORK_RELATION-NETWORK_PREDECESSOR
*" VALUE(ACTIVITY_PREDECESSOR) LIKE
*"
BAPI_NETWORK_RELATION-ACTIVITY_PREDECESSOR
*" VALUE(NETWORK_SUCCESSOR) LIKE
*"
BAPI_NETWORK_RELATION-NETWORK_SUCCESSOR
*" VALUE(ACTIVITY_SUCCESSOR) LIKE
*"
BAPI_NETWORK_RELATION-ACTIVITY_SUCCESSOR
*" VALUE(RELATION_TYPE) LIKE BAPI_NETWORK_RELATION-RELATION_TYPE
*" VALUE(ELEMENT) LIKE BAPI_ACT_ELEMENT-ELEMENT
*" VALUE(UP) LIKE BAPI_WBS_HIERARCHIE-UP
*" VALUE(DOWN) LIKE BAPI_WBS_HIERARCHIE-DOWN
*" VALUE(LEFT) LIKE BAPI_WBS_HIERARCHIE-LEFT
*" VALUE(RIGHT) LIKE BAPI_WBS_HIERARCHIE-RIGHT
*" VALUE(UP1) LIKE BAPI_WBS_HIERARCHIE-UP
*" VALUE(DOWN1) LIKE BAPI_WBS_HIERARCHIE-DOWN
*" VALUE(LEFT1) LIKE BAPI_WBS_HIERARCHIE-LEFT
*" VALUE(RIGHT1) LIKE BAPI_WBS_HIERARCHIE-RIGHT
*" VALUE(VPLANT) LIKE BAPI_NETWORK-PLANT
*" VALUE(VPROJ_TYPE) LIKE BAPI_WBS_ELEMENT-PROJ_TYPE
*" TABLES
*"
WBS_CREATE_ERROR STRUCTURE BAPI_METH_MESSAGE OPTIONAL

*"
NETWORK_CREATE_ERROR STRUCTURE BAPI_METH_MESSAGE OPTIONAL
*"
WBS_HIERARCHY_ERROR STRUCTURE BAPI_METH_MESSAGE OPTIONAL
*"
ACTIVITY_CREATE_ERROR STRUCTURE BAPI_METH_MESSAGE OPTIONAL
*"
ACTIVITY_RELATION_ERROR STRUCTURE BAPI_METH_MESSAGE OPTIONAL
*"---------------------------------------------------------------------DATA : BEGIN OF itproj OCCURS 0.
INCLUDE STRUCTURE bapi_project_definition.
DATA :END OF itproj.
DATA : BEGIN OF itprojupd OCCURS 0.
INCLUDE STRUCTURE bapi_project_definition_up.
DATA :END OF itprojupd.
DATA : BEGIN OF itwbsmethod OCCURS 0.
INCLUDE STRUCTURE bapi_method_project.
DATA :END OF itwbsmethod.
DATA : BEGIN OF itwbs OCCURS 0.
INCLUDE STRUCTURE bapi_wbs_element.
DATA :END OF itwbs.
DATA : BEGIN OF itnetmethod OCCURS 0.
INCLUDE STRUCTURE bapi_method_project.
DATA :END OF itnetmethod.
DATA : BEGIN OF itnetwork OCCURS 0.
INCLUDE STRUCTURE bapi_network.
DATA :END OF itnetwork.
DATA : BEGIN OF itwbshierarchy OCCURS 0.
INCLUDE STRUCTURE bapi_wbs_hierarchie.
DATA :END OF itwbshierarchy.
DATA : BEGIN OF iterr OCCURS 0.
INCLUDE STRUCTURE bapi_meth_message .
DATA :END OF iterr.
DATA : iterr1 LIKE bapi_meth_message OCCURS 0 WITH HEADER LINE.
DATA : itemsg LIKE bapi_meth_message OCCURS 0 WITH HEADER LINE.
DATA : itemsg1 LIKE bapi_meth_message OCCURS 0 WITH HEADER LINE.
DATA : itemsg2 LIKE bapi_meth_message OCCURS 0 WITH HEADER LINE.
DATA : BEGIN OF itactivity OCCURS 0.
INCLUDE STRUCTURE bapi_network_activity.
DATA :END OF itactivity.
DATA : BEGIN OF itactmethod OCCURS 0.
INCLUDE STRUCTURE bapi_network_activity_up.
DATA :END OF itactmethod.
DATA :BEGIN OF itrelation OCCURS 0.
INCLUDE STRUCTURE bapi_network_relation.
DATA :END OF itrelation.
DATA : v_str(100) TYPE c.
DATA : v_str1(34) TYPE c.
IF NOT wbs_element IS INITIAL AND
NOT project_definition IS INITIAL.
* AND NOT description IS INITIAL.

MOVE wbs_element TO itwbs-wbs_element.


MOVE project_definition TO itwbs-project_definition.
* MOVE vproj_type TO itwbs-proj_type.
MOVE WBS_ELEMENT_DESCRIPTION TO itwbs-description.
IF NOT wbs_element1 IS INITIAL.
MOVE vproj_type TO itwbs-proj_type.
ELSE.
MOVE ' ' TO itwbs-proj_type.
ENDIF.
APPEND itwbs.
MOVE project_definition TO itproj-project_definition.
MOVE description to itproj-description.
APPEND itproj.
MOVE '000010' TO itwbsmethod-refnumber.
MOVE 'WBS-ELEMENT' TO itwbsmethod-objecttype.
MOVE 'CREATE' TO itwbsmethod-method.
MOVE wbs_element TO itwbsmethod-objectkey.
APPEND itwbsmethod.
MOVE '000000' TO itwbsmethod-refnumber.
MOVE ' ' TO itwbsmethod-objecttype.
MOVE 'SAVE' TO itwbsmethod-method.
MOVE ' ' TO itwbsmethod-objectkey.
APPEND itwbsmethod.
************ create WBS Elements******************
REFRESH iterr.

*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*

CALL FUNCTION 'BAPI_PROJECT_MAINTAIN'


EXPORTING
i_project_definition
= itproj
i_project_definition_upd = itprojupd
IMPORTING
RETURN
=
TABLES
i_method_project
= itwbsmethod
I_WBS_ELEMENT_TABLE_UPDATE =
i_wbs_element_table
= itwbs
I_WBS_MILESTONE_TABLE
=
I_WBS_MILESTONE_TABLE_UPDATE =
I_WBS_HIERARCHIE_TABLE
= itwbshierarchy
i_network
= itnetwork
I_NETWORK_UPDATE
=
i_activity
= itactivity
i_activity_update
= itactmethod
I_RELATION
=
I_RELATION_UPDATE
=
e_message_table
= iterr.
I_ACTIVITY_ELEMENT
=
I_ACTIVITY_ELEMENT_UPDATE =
I_ACTIVITY_MILESTONE
=
I_ACTIVITY_MILESTONE_UPDATE =
IF sy-subrc = 0.

ENDIF.
LOOP AT iterr.
MOVE : iterr-method to wbs_create_error-method,
iterr-object_type to wbs_create_error-OBJECT_TYPE,
iterr-internal_object_id to
wbs_create_error-INTERNAL_OBJECT_ID,
iterr-external_object_id to
wbs_create_error-EXTERNAL_OBJECT_ID,
iterr-message_id to wbs_create_error-MESSAGE_ID,
iterr-message_number to wbs_create_error-MESSAGE_NUMBER,
iterr-message_type to wbs_create_error-MESSAGE_TYPE,
iterr-message_text to wbs_create_error-MESSAGE_TEXT.
append wbs_create_error.
clear iterr.
endloop.
COMMIT WORK .
WAIT UP TO 1 SECONDS.
ENDIF. " if not wbs_element initial
************ create network ***********
if not network is initial.
MOVE '000001' TO itnetmethod-refnumber.
MOVE 'NETWORK' TO itnetmethod-objecttype.
MOVE 'CREATE' TO itnetmethod-method.
MOVE network TO itnetmethod-objectkey.
APPEND itnetmethod.
MOVE '000000' TO itnetmethod-refnumber.
MOVE ' ' TO itnetmethod-objecttype.
MOVE 'SAVE' TO itnetmethod-method.
MOVE ' ' TO itnetmethod-objectkey.
APPEND itnetmethod.
MOVE network TO itnetwork-network.
MOVE network_type TO itnetwork-network_type.
MOVE vplant TO itnetwork-plant.
MOVE 'NEW NETWORK' TO itnetwork-short_text.
MOVE wbs_element TO itnetwork-wbs_element.
MOVE '001' TO itnetwork-mrp_controller.
MOVE project_definition TO itnetwork-project_definition.
MOVE profile TO itnetwork-profile.
APPEND itnetwork.
REFRESH itemsg.
*
*

*
*
*

CALL FUNCTION 'BAPI_NETWORK_MAINTAIN'


IMPORTING
RETURN
=
TABLES
i_method_project
= itnetmethod
i_network
= itnetwork
I_NETWORK_UPDATE
=
I_ACTIVITY
=
I_ACTIVITY_UPDATE
=

*
*
*
*
*
*

I_RELATION
=
I_RELATION_UPDATE
=
e_message_table
= itemsg.
I_ACTIVITY_ELEMENT
=
I_ACTIVITY_ELEMENT_UPDATE =
I_ACTIVITY_MILESTONE
=
I_ACTIVITY_MILESTONE_UPDATE =
IF sy-subrc = 0.
ENDIF.
LOOP AT itemsg.
MOVE : itemsg-method to network_create_error-method,
itemsg-object_type to network_create_error-OBJECT_TYPE,
itemsg-internal_object_id to
network_create_error-INTERNAL_OBJECT_ID,
itemsg-external_object_id to
network_create_error-EXTERNAL_OBJECT_ID,
itemsg-message_id to network_create_error-MESSAGE_ID,
itemsg-message_number to
network_create_error-MESSAGE_NUMBER,
itemsg-message_type to network_create_error-MESSAGE_TYPE,
itemsg-message_text to network_create_error-MESSAGE_TEXT.
append network_create_error.
clear itemsg.
endloop.
COMMIT WORK .
WAIT UP TO 1 SECONDS.
endif. "if not network is initial.

********* this method will decide hierarchy of WBS *******


IF NOT wbs_element1 IS INITIAL.
"AND NOT wbs_element_parent IS INITIAL.
CLEAR:itwbsmethod,itwbshierarchy,itwbs,iterr1.
REFRESH:itwbsmethod,itwbshierarchy,itwbs,iterr1.
*********MAINTAIN HIERARCHY*************************************
******* New WBS along with position w.r.t parent********
*
MOVE wbs_element_parent TO itwbshierarchy-wbs_element.
MOVE wbs_element TO itwbshierarchy-wbs_element.
MOVE project_definition TO itwbshierarchy-project_definition.
MOVE up TO itwbshierarchy-up.
MOVE down TO itwbshierarchy-down.
MOVE left TO itwbshierarchy-left.
MOVE right TO itwbshierarchy-right.
APPEND itwbshierarchy.
CLEAR itwbshierarchy.
********Pass WBS elements parent with position w.r.t child***
MOVE wbs_element1 TO itwbshierarchy-wbs_element.

MOVE project_definition TO itwbshierarchy-project_definition.


MOVE up1 TO itwbshierarchy-up.
MOVE down1 TO itwbshierarchy-down.
MOVE left1 TO itwbshierarchy-left.
MOVE right1 TO itwbshierarchy-right.
APPEND itwbshierarchy.
CLEAR itwbshierarchy.
******** Method for saving and creating WBS**********
MOVE 'WBS-HIERARCHY' TO itwbsmethod-objecttype.
MOVE 'CREATE' TO itwbsmethod-method.
APPEND itwbsmethod.
CLEAR itwbsmethod.
MOVE 'SAVE' TO itwbsmethod-method.
APPEND itwbsmethod.
CLEAR itwbsmethod.
***********end method ****************
***** WBS updating it with proj_type***
*
MOVE wbs_element_parent TO itwbs-wbs_element.
MOVE wbs_element TO itwbs-wbs_element.
MOVE project_definition TO itwbs-project_definition.
MOVE WBS_ELEMENT_DESCRIPTION TO itwbs-description.
MOVE vproj_type TO itwbs-proj_type.
APPEND itwbs.
***** WBS updating it with proj_type***

*
*
*
*
*
*
*
*
*
*
*
*
*
*
*

CALL FUNCTION 'BAPI_PROJECT_MAINTAIN'


EXPORTING
i_project_definition
= itproj
i_project_definition_upd = itprojupd
IMPORTING
RETURN
=
TABLES
i_method_project
= itwbsmethod
I_WBS_ELEMENT_TABLE_UPDATE =
i_wbs_element_table
= itwbs
I_WBS_MILESTONE_TABLE
=
I_WBS_MILESTONE_TABLE_UPDATE =
i_wbs_hierarchie_table
= itwbshierarchy
I_NETWORK
= itnetwork
I_NETWORK_UPDATE
=
I_ACTIVITY
= itactivity
I_ACTIVITY_UPDATE
= itactmethod
I_RELATION
=
I_RELATION_UPDATE
=
e_message_table
= iterr1.
I_ACTIVITY_ELEMENT
=
I_ACTIVITY_ELEMENT_UPDATE =
I_ACTIVITY_MILESTONE
=
I_ACTIVITY_MILESTONE_UPDATE =
IF sy-subrc = 0.
ENDIF.
LOOP AT iterr1.

MOVE : iterr1-method to wbs_hierarchy_error-method,


iterr1-object_type to wbs_hierarchy_error-OBJECT_TYPE,
iterr1-internal_object_id to
wbs_hierarchy_error-INTERNAL_OBJECT_ID,
iterr1-external_object_id to
wbs_hierarchy_error-EXTERNAL_OBJECT_ID,
iterr1-message_id to wbs_hierarchy_error-MESSAGE_ID,
iterr1-message_number to wbs_hierarchy_error-MESSAGE_NUMBER,
iterr1-message_type to wbs_hierarchy_error-MESSAGE_TYPE,
iterr1-message_text to wbs_hierarchy_error-MESSAGE_TEXT.
append wbs_hierarchy_error.
clear iterr1.
endloop.
COMMIT WORK .
WAIT UP TO 1 SECONDS.

ENDIF." if not wbs_element1 initial


**************** create activity in network************
CLEAR : itactivity,itnetmethod,itemsg1,itnetwork.
REFRESH :itactivity,itnetmethod,itemsg1,itnetwork.
IF NOT network IS INITIAL.
CONCATENATE itemsg-internal_object_id activity INTO v_str.
MOVE itemsg-internal_object_id+0(12) TO itactivity-network.
ELSE.
CONCATENATE network1 activity INTO v_str.
MOVE network1 TO itactivity-network.
ENDIF.
MOVE activity TO itactivity-activity.
MOVE act_desc TO itactivity-description.
MOVE 'PS01' TO itactivity-control_key.
MOVE project_definition TO itactivity-project_definition.
MOVE wbs_element TO itactivity-wbs_element.
MOVE 'W7' TO itactivity-factory_calendar.
APPEND itactivity.
MOVE '000001' TO itnetmethod-refnumber.
MOVE 'NETWORKACTIVITY' TO itnetmethod-objecttype.
MOVE 'CREATE' TO itnetmethod-method.
MOVE v_str TO itnetmethod-objectkey.
APPEND itnetmethod.
CLEAR itnetmethod.
MOVE 'SAVE' TO itnetmethod-method.
APPEND itnetmethod.
CLEAR itnetmethod.

MOVE network1 TO itnetwork-network.


MOVE '001' TO itnetwork-mrp_controller.
APPEND itnetwork.

*
*

*
*
*
*
*
*
*
*

CALL FUNCTION 'BAPI_NETWORK_MAINTAIN'


IMPORTING
RETURN
=
TABLES
i_method_project
= itnetmethod
i_network
= itnetwork
I_NETWORK_UPDATE
=
i_activity
= itactivity
I_ACTIVITY_UPDATE
=
I_RELATION
=
I_RELATION_UPDATE
=
e_message_table
= itemsg1.
I_ACTIVITY_ELEMENT
=
I_ACTIVITY_ELEMENT_UPDATE =
I_ACTIVITY_MILESTONE
=
I_ACTIVITY_MILESTONE_UPDATE =
IF sy-subrc = 0.
ENDIF.
LOOP AT itemsg1.
MOVE : itemsg1-method to activity_create_error-method,
itemsg1-object_type to activity_create_error-OBJECT_TYPE,
itemsg1-internal_object_id to
activity_create_error-INTERNAL_OBJECT_ID,
itemsg1-external_object_id to
activity_create_error-EXTERNAL_OBJECT_ID,
itemsg1-message_id to activity_create_error-MESSAGE_ID,
itemsg1-message_number to
activity_create_error-MESSAGE_NUMBER,
itemsg1-message_type to activity_create_error-MESSAGE_TYPE,
itemsg1-message_text to activity_create_error-MESSAGE_TEXT.
append activity_create_error.
clear itemsg1.
endloop.

COMMIT WORK .
WAIT UP TO 1 SECONDS.
*********************** create network relationship*********************
CLEAR : itnetmethod,itemsg2,itnetwork,itrelation.
REFRESH :itnetmethod,itemsg2,itnetwork,itrelation.
MOVE '000001' TO itnetmethod-refnumber.
MOVE 'NETWORKRELATION' TO itnetmethod-objecttype.
MOVE 'CREATE' TO itnetmethod-method.
CONCATENATE relation_type network_predecessor activity_predecessor
network_successor activity_successor INTO v_str1.
MOVE v_str1 TO itnetmethod-objectkey.

APPEND itnetmethod.
CLEAR itnetmethod.
MOVE 'SAVE' TO itnetmethod-method.
APPEND itnetmethod.
CLEAR itnetmethod.
MOVE network1 TO itnetwork-network.
APPEND itnetwork.
CLEAR itnetwork.
MOVE network_predecessor TO itrelation-network_predecessor.
MOVE activity_predecessor TO itrelation-activity_predecessor.
MOVE network_successor TO itrelation-network_successor.
MOVE activity_successor TO itrelation-activity_successor.
MOVE relation_type TO itrelation-relation_type.
APPEND itrelation.
CLEAR itrelation.
*
*

*
*
*
*
*
*
*
*

CALL FUNCTION 'BAPI_NETWORK_MAINTAIN'


IMPORTING
RETURN
=
TABLES
i_method_project
= itnetmethod
i_network
= itnetwork
I_NETWORK_UPDATE
=
I_ACTIVITY
= itactivity
I_ACTIVITY_UPDATE
=
i_relation
= itrelation
I_RELATION_UPDATE
=
e_message_table
= itemsg2.
I_ACTIVITY_ELEMENT
=
I_ACTIVITY_ELEMENT_UPDATE =
I_ACTIVITY_MILESTONE
=
I_ACTIVITY_MILESTONE_UPDATE =
IF sy-subrc = 0.
ENDIF.
LOOP AT itemsg2.
MOVE : itemsg2-method to activity_relation_error-method,
itemsg2-object_type to activity_relation_error-OBJECT_TYPE,
itemsg2-internal_object_id to
activity_relation_error-INTERNAL_OBJECT_ID,
itemsg2-external_object_id to
activity_relation_error-EXTERNAL_OBJECT_ID,
itemsg2-message_id to activity_relation_error-MESSAGE_ID,
itemsg2-message_number to
activity_relation_error-MESSAGE_NUMBER,
itemsg2-message_type to
activity_relation_error-MESSAGE_TYPE,
itemsg2-message_text to
activity_relation_error-MESSAGE_TEXT.

append activity_relation_error.
clear itemsg2.
endloop.
.
COMMIT WORK .
WAIT UP TO 1 SECONDS.

ENDFUNCTION.
Loading Purchase Orders Using BAPI_PO_CREATE
Pls check if this code. I used this to upload po.
*&---------------------------------------------------------------------*
*& Report ZBAPI_PO_CRATE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZBAPI_PO_CRATE.
data : PO_HEADER like BAPIEKKOC.
data : PO_HEADER_ADD_DATA like BAPIEKKOA.
data : PO_ITEMS like BAPIEKPOC occurs 0 with header
line.
data : PO_ITEM_SCHEDULES like BAPIEKET occurs 0 with
header line.
data : RETURN like BAPIRETURN occurs 0 with header
line.
DATA : BEGIN OF TAB OCCURS 0,
PO_NUMBER like BAPIEKKOC-PO_NUMBER,
DOC_DATE(10),
DOC_TYPE like BAPIEKKOC-DOC_TYPE,
CO_CODE like BAPIEKKOC-CO_CODE,
PURCH_ORG like BAPIEKKOC-PURCH_ORG,
PUR_GROUP like BAPIEKKOC-PUR_GROUP,
VENDOR like BAPIEKKOC-VENDOR,
PMNTTRMS like BAPIEKKOA-PMNTTRMS,
INCOTERMS1 like BAPIEKKOA-INCOTERMS1,
INCOTERMS2 like BAPIEKKOA-INCOTERMS2,
PO_ITEM like BAPIEKPOC-PO_ITEM,
MATERIAL like BAPIEKPOC-MATERIAL,
PUR_MAT like BAPIEKPOC-PUR_MAT,
ITEM_CAT like BAPIEKPOC-ITEM_CAT,
PLANT like BAPIEKPOC-PLANT,
NET_PRICE like BAPIEKPOC-NET_PRICE,
TAX_CODE like BAPIEKPOC-TAX_CODE,
DELIV_DATE(10),
QUANTITY like BAPIEKET-QUANTITY,
end of tab.
data: itab1 like alsmex_tabline occurs 0 with header
line.
DATA: gd_currentrow type i.
data : PURCHASEORDER like ekko-ebeln.
Data: tot_rec type i, "Total Records
gd_update type i, "Main Table Increement

Counter
gd_lines type i, "Success Table increement
Counter
w_textout like t100-text. "VARIABLE TO GET ERROR
LOG
data : begin of it_success occurs 0,
PURCHASEORDER LIKE ekko-ebeln, "PROJECT
end of it_success.
data : begin of it_error occurs 0,
pono like ekko-ebeln,
err_msg(73) TYPE c, "TO RETREIVE ERROR
MESSAGES
end of it_error.
data : pono like ekko-ebeln.
selection-screen begin of block b1 with frame.
skip 3.
parameter:p_infile like rlgrap-filename obligatory.
skip 3.
selection-screen end of block b1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_infile.
PERFORM value_help.
start-of-selection.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename
= p_infile
i_begin_col
= '1'
i_begin_row
= '2' "Do not require
headings
i_end_col
= '22'
i_end_row
= '10000'
TABLES
intern
= itab1
EXCEPTIONS
inconsistent_parameters = 1
upload_ole
=2
others
= 3.
if sy-subrc <> 0.
message e010(zz) with text-001. "Problem uploading
Excel Spreadsheet
endif.
*perform open_group.
sort itab1 by row col.
* Get first row retrieved
read table itab1 index 1.
* Set first row retrieved to current row
gd_currentrow = itab1-row.
loop at itab1.
* Reset values for next row
if itab1-row ne gd_currentrow.
append tab .

clear tab.
gd_currentrow = itab1-row.
endif.
case itab1-col.
when '0001'. "PGNAM
TAB-PO_NUMBER = itab1-value.
when '0002'. "RONAM
TAB-DOC_DATE = itab1-value.
when '0003'. "JVLEVEL
TAB-DOC_TYPE = itab1-value.
when '0004'. "FTTYPE
TAB-CO_CODE = itab1-value.
when '0005'. "LANG
TAB-PURCH_ORG = itab1-value.
when '0006'. "LTEXT
TAB-PUR_GROUP = itab1-value.
when '0007'. "LTEXT
TAB-VENDOR = itab1-value.
when '0008'. "LTEXT
TAB-PMNTTRMS = itab1-value.
when '0009'. "LTEXT
TAB-INCOTERMS1 = itab1-value.
when '0010'. "FTTYPE
TAB-INCOTERMS2 = itab1-value.
when '0011'. "FTTYPE
TAB-PO_ITEM = itab1-value.
when '0012'. "FTTYPE
TAB-MATERIAL = itab1-value.
when '0013'. "FTTYPE
TAB-PUR_MAT = itab1-value.
when '0014'. "FTTYPE
TAB-ITEM_CAT = itab1-value.
when '0015'. "FTTYPE
shift itab1-value left deleting leading space.
TAB-PLANT = itab1-value.
when '0016'. "FTTYPE
TAB-NET_PRICE = itab1-value.
when '0017'. "FTTYPE
TAB-TAX_CODE = itab1-value.
when '0018'. "FTTYPE
TAB-DELIV_DATE = itab1-value.
when '0019'. "FTTYPE
TAB-QUANTITY = itab1-value.
endcase.
endloop.
append tab.
clear tab.
sort tab by PO_NUMBER.
DELETE TAB WHERE PO_NUMBER = SPACE.
loop at tab.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = tab-material
IMPORTING
OUTPUT = tab-material.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = tab-PUR_MAT

IMPORTING
OUTPUT = tab-PUR_MAT.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = tab-vendor
IMPORTING
OUTPUT = tab-vendor.
concatenate tab-doc_DATE+4(4) tab-doc_DATE+2(2)
tab-doc_DATE+0(2)
into tab-doc_DATE.
concatenate tab-DELIV_DATE+4(4)
tab-DELIV_DATE+2(2)
tab-DELIV_DATE+0(2) into tab-DELIV_DATE.
pono = tab-PO_NUMBER.
if tab-po_number = pono.
PO_HEADER-DOC_DATE = tab-DOC_DATE.
PO_HEADER-DOC_TYPE = tab-DOC_TYPE.
PO_HEADER-CO_CODE = tab-CO_CODE.
PO_HEADER-PURCH_ORG = tab-PURCH_ORG.
PO_HEADER-PUR_GROUP = tab-PUR_GROUP.
PO_HEADER-VENDOR = tab-VENDOR.
PO_HEADER-PO_NUMBER = tab-PO_NUMBER.
PO_HEADER_ADD_DATA-PMNTTRMS = tab-PMNTTRMS.
PO_HEADER_ADD_DATA-INCOTERMS1 = tab-INCOTERMS1.
PO_HEADER_ADD_DATA-INCOTERMS2 = tab-INCOTERMS2.
PO_ITEMS-PO_ITEM = tab-PO_ITEM.
PO_ITEMS-MATERIAL = tab-MATERIAL.
PO_ITEMS-PUR_MAT = tab-PUR_MAT.
PO_ITEMS-ITEM_CAT = tab-ITEM_CAT.
PO_ITEMS-PLANT = tab-PLANT.
PO_ITEMS-NET_PRICE = tab-NET_PRICE.
PO_ITEMS-TAX_CODE = tab-TAX_CODE.
append po_items.
PO_ITEM_SCHEDULES-PO_ITEM = tab-PO_ITEM.
PO_ITEM_SCHEDULES-DELIV_DATE = tab-DELIV_DATE.
PO_ITEM_SCHEDULES-QUANTITY = tab-QUANTITY.
append PO_ITEM_SCHEDULES.
endif.
at end of PO_NUMBER.
CALL FUNCTION 'BAPI_PO_CREATE'
EXPORTING
PO_HEADER
= PO_HEADER
PO_HEADER_ADD_DATA
=
PO_HEADER_ADD_DATA
*
HEADER_ADD_DATA_RELEVANT
=
*
PO_ADDRESS
=
*
SKIP_ITEMS_WITH_ERROR
= 'X'
*
ITEM_ADD_DATA_RELEVANT
=
*
HEADER_TECH_FIELDS
=
IMPORTING
PURCHASEORDER
=
PURCHASEORDER
TABLES
PO_ITEMS
= PO_ITEMS

PO_ITEM_ADD_DATA
=
PO_ITEM_SCHEDULES
=
PO_ITEM_SCHEDULES
*
PO_ITEM_ACCOUNT_ASSIGNMENT
*
PO_ITEM_TEXT
=
RETURN
= RETURN
*
PO_LIMITS
=
*
PO_CONTRACT_LIMITS
=
*
PO_SERVICES
=
*
PO_SRV_ACCASS_VALUES
=
*
PO_SERVICES_TEXT
=
*
PO_BUSINESS_PARTNER
=
*
EXTENSIONIN
=
*
POADDRDELIVERY
=
.

if PURCHASEORDER <> space.


.
commit work.
ADD 1 TO gd_update.
it_success-PURCHASEORDER = PURCHASEORDER.
append it_success.
clear:PO_HEADER,PO_HEADER_ADD_DATA,PURCHASEORDER.
refresh : PO_ITEMS,PO_ITEM_SCHEDULES,RETURN.
ELSE.
loop at return.
it_error-pono = tab-PO_NUMBER.
it_error-err_msg = return-MESSAGE .
Append it_error.
ENDLOOP.
clear:PO_HEADER,PO_HEADER_ADD_DATA,PURCHASEORDER.
refresh : PO_ITEMS,PO_ITEM_SCHEDULES,RETURN.
endif.
endat.
endloop.
DESCRIBE TABLE it_success LINES gd_lines.
IF gd_lines GT 0.
* Display result report column headings
PERFORM display_column_headings.
* Display result report
PERFORM DISPLAY_SUCESS.
ENDIF.
* IF SUCESS FAILS Display Error Report
DESCRIBE TABLE it_error LINES gd_lines.
IF gd_lines GT 0.
PERFORM errorheadings.
PERFORM errorreport.
ENDIF.
*&---------------------------------------------------------------------*
*&
Form display_column_headings
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM display_column_headings.
WRITE:2 ' Success Report '(014) COLOR COL_POSITIVE.
SKIP.
WRITE:2 'The following records inserted
successfully:'(013).
WRITE:/ sy-uline(15).

FORMAT COLOR COL_HEADING.


WRITE:/
sy-vline,
(10) 'Purchase order'(004), sy-vline.
WRITE:/ sy-uline(15).
ENDFORM.
"display_column_headings
*Subroutine to display SUCESS REPORT
FORM DISPLAY_SUCESS.
FORMAT COLOR COL_NORMAL.
LOOP AT it_success.
WRITE:/
sy-vline,
(10) it_success-PURCHASEORDER, sy-vline.
CLEAR it_success.
ENDLOOP.
WRITE:/ sy-uline(15).
REFRESH: it_success.
FORMAT COLOR COL_BACKGROUND.
ENDFORM.
"
DISPLAY_REPORT
*&---------------------------------------------------------------------*
*&
Form errorreport
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM errorreport.
LOOP AT it_error.
WRITE:/
sy-vline,
(10) it_error-pono, sy-vline,
(40) it_error-err_msg, sy-vline.
ENDLOOP.
WRITE:/ sy-uline(104).
REFRESH: it_error.
endform.

"errorreport

*&---------------------------------------------------------------------*
*&
Form ERRORHEADINGS
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM ERRORHEADINGS.
SKIP.
WRITE:2 ' Error Report '(007) COLOR COL_NEGATIVE.
SKIP.
WRITE:2 'The following records failed during
update:'(008).
WRITE:/ sy-uline(104).
FORMAT COLOR COL_HEADING.
WRITE:/
sy-vline,
(10) 'ERROR.'(009), sy-vline.
WRITE:/ sy-uline(104).
FORMAT COLOR COL_NORMAL.
ENDFORM.
"ERRORHEADINGS
**&--------------------------------------------------------------------**
**&
Form value_help
**&--------------------------------------------------------------------**

**
text
**---------------------------------------------------------------------**
** --> p1
text
** <-- p2
text
**---------------------------------------------------------------------**
FORM value_help .
CALL FUNCTION 'DSVAS_DOC_WS_FILENAME_GET_50'
EXPORTING
DEF_FILENAME = ' '
DEF_PATH
=''
MASK
= ',*.*,*.*.'
MODE
= 'O'
TITLE
=''
IMPORTING
FILENAME
= p_infile
EXCEPTIONS
INV_WINSYS
=1
NO_BATCH
=2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS
= 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endform.

"value_help

What is BDC?
Batch Data Communication or BDC is a batch interfacing technique that SAP developed. It is mainly used
for uploading data into the SAP R/3 system. BDC works by simulating the user input from transactional
screen via an ABAP program.
The data input data file will come in the form of a flat file which the user save as file type txt file or prn file
from the Microsoft Excel program. An Abaper will create a program to read the text file and upload into the
SAP system.
Normally, the tcode SHDB will be used to record the transaction code the user used. After, the simulation,
the Abaper can generate a sample program and modify from there. It makes the programming easier and
faster.
Learning BDC Programming
I want to learn how to upload data using BDC. If I have a excel data file how will upload it using BDC.
I don't know the full process of doing it, if someone help me in this. I want it using BDC session
process and processing that session. I was trying to upload material master other day. But could not
follow the process of uploading using BDC though I know LSMW. Please explain me the BDC
process in details with examples.
For a BDC upload you need to write a program which created BDC sessions.
Steps:
1. Work out the transaction you would use to create the data manually.
2. Use transaction SHDB to record the creation of one material master data.
Click the New recording button or the Menu - Recording - Create

3. Save the recording, and then go back a screen and go to the overview.
4. Select the recording and click on Edit - Create Program. Give the program a Z name, and select transfer
from recording.
5. Edit the program. You will see that all the data you entered is hard-coded into the program. You need to
make the following changes:
5.1 After the start-of-selection, Call ws_upload to upload the file (the excel file needs to be saved as TAB
separated).
5.2 After the open-group, Loop on the uploaded data. For each line, perform validation checks on the data,
then modify the perform bdc_field commands to use the file data.
5.3. After perform bdc_transaction, add the endloop.
Execute the program. It will have options to create a batch session or to process directly.
These are all my finds . Might be it will be useful to you.
Direct call of transactions, session handling:
/nxxxx This terminates the current transaction, and starts transaction xxxx
/n This terminates the transaction. This generally corresponds to pressing F15 to go back.
/nend This termiantes all separate sessions and logs off (corresponds to System - Logoff).
/nex This terminates all separate sessions and logs off immediately (without any warning!).
/oxxxx This opens a new session and starts transaction xxxx in This session.
/o This lists existing sessions and allows deletion or opening of a new session.
/i This terminates the current session (corresponds to System End
/i1, /i2,... This terminates the session with the number given.
.xyzw Fast path: 'xyzw' refers to the underlined letters in the menus. This type of navigation is uncommon
and is provided more for emergencies (such as a defective mouse).
Batch
The following commands can be entered in correction mode ('Process in foreground' or 'Display errors only')
when processing a batch input session:
/n This terminates the current batch input transaction and characterizes it as
/bdel This deletes the current batch input transaction.
/bend This terminates batch input processing and sets the session to Failed
/bda This switches from Display errors only to Process in foreground
/bde This switches from Process in foreground to Display errors only
ABAP/4
/h This switches into debugging mode.
/hs This switches into debugging mode and activates the debugging of system functions.

Buffer
WARNING: Resetting buffers can significantly change the performance of the entire system for a long time.
It should therefore only be used where there is a good reason tdso. As of release 3.0B system administator
authorization is required (authorization object (S_ADMI_FCD). The action is noted in the system log.
/$SYNC This resets all buffers of the application server
/$CUA This resets the CUA buffer of the application server
/$TAB This resets the TABLE buffers of the application server
/$NAM This resets the nametab buffer of the application server
/$DYNP This resets the screen buffer of the application server
What is recording?
As the word record implies, it mean recording the keystroke of the user input of a SAP transaction screen.
Why it is used?
It is normally used for mass update or uploading of data to the system.
What is its need?
It help to save time for the users who need to mass change the system data. For e.g. tax rate change
announce by the country government.
How it is related with bdc?
It is related to bdc because bdc programming allows recording of user inputs
Question About BDC Program
What is bdc_okcode?
It is the user command that was executed. eg. '/00' means Enter command.
The user command can varies during a bdc program. Therefore, we need to used tcode shdb to check what
it actually contains.
What is the function key values of BDC_OKCODE ie '/00' what this is for?
How will we handle the errors in call transaction method?
'/00' is generally the BDC_OKCODE for the ENTER key.
You don't need to know the list of the BDC_OKCODE s.
You go to the transaction SHDB.
You can execute any transaction here.
Then you can replay the execution of the trasaction afterwards.
Select 'display all screens' mode.
BDC_OKCODEs for each one functions you use is displayed on the screen.
Now, regarding the error handling in call transaction.
The BDCMSGCOLL does not have the messages text. It has only the message type, number and message
parameters.
You have to read the message text. (recall that the database table T100 stores all the messages.)
There are more than one method of doing this.
Following is the psuedocode for one of the methods.
LOOP for the internal table IT1 which has data value from flat file.

call transcation using....


if SY-SUBRC <> 0.
Read the dictionary table T100 FOR ALL ENTRIES in BDCMSGCOLL.
(also use the condition T100-SPRAS = SY-LANGU (the log on language. This is because you need only
the message texts in English if the user is logged in English language)
IF message type is E , then, transfer the contents of this particular error record to file x. (TRANSFER......)
( Ignore all other messages. Only consider type 'E' messages. Ignore other types of messages.)
(You can also store the message text from T100 and the error record in another internal table IT2)
.....
....
ENDLOOP.
Please note that the client might ask you for a file of records which could not be uploaded.
Give him the file created in the above psuedocode. (most often you will have to do this).
Otherwise just display the error messages and the error records in the internal table IT2 in the form of a list.
Thats it.
Alternatively,
Instead of
" Read the dictionary table T100 FOR ALL ENTRIES in BDCMSGCOLL."
you can use the function module
WRITE_MESSAGES to read the messages.
Please refer to the function module for the list of parameters.
Also refer FORMAT_MESSAGES function module.
As, I said, there are more than one method of doing this.
ABAP Tips by: Satheesh, Jinna
1) How to handle error in bdc call transaction method...without using structure BDCMSGCOLL.
Use Std Function module 'FORMAT_MESSAGE'
2) How to load images from application server in bdc
Solution: I don't think so.
3) How to insert data in table control through bdc ....problem is every system displays different no of
rows in the table control when you enter the application....for ex .. purchase order, pur req, bom....
Solution: Use CALL TRANSACTION 'ME21N' OPTIONS FROM w_ctu_params.( type CTU_PARAMS)
This structure contains the follwing.
DISMODE : Display mode (like the MODE addition)
UPDMODE: Update mode (like the UPDATE addition)
CATTMODE: CATT mode (controls a CATT)
CATT mode can have the following values:
' ' No CATT active

'N' CATT without single-screen control


'A' CATT with single-screen control
DEFSIZE : Use default window size (Here we are handling those transaction by giving default window size)
RACOMMIT: Do not end transaction at COMMIT WORK
NOBINPT : No batch input mode (that is, SY-BINPT = SPACE)
NOBIEND : No batch input mode after the end of BDC data.
The components DEFSIZE , RACOMMIT, NOBINPT, and NOBIEND always take the following values:
'X' Yes
4) Can you give me one example where we should use only bdc call transaction method:
Solution: With CALL TRANSACTION USING, the system processes the data more quickly than with batch
input sessions. Unlike batch input sessions, CALL TRANSACTION USING does not automatically support
interactive correction or logging functions
5) In the reports when you press f4 to get list is it possible to pass default value in that value...i.e
suppose i have created select option on company code when the user press f4 automatically he
should get the default value.
Solution: Ya, It is possible.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_BUKRS.
P_BUKRS-LOW = 2000.
With Compliment by: Venkat .O.
I want to learn BDC ....how should I go about it so that I make it my strong area......please help.
BDC is Batch Data Communication where data is transferred from legacy system to SAP system. Different
methods of BDC are
1. Call Transaction Method.
2. Session Method
3. Direct Input method.
In all the above methods you have to prepare a flat file containing the data in the required format to be
uploaded to the SAP system. You need to call the function ' UPLOAD' to do this. Then the contents of the flat
file have to copied to your internal table and then u need to call the transaction through which you want to
update the database. You internal table should also have the information relating to the structure BDCDATA
which is having the details like the module pool program name, screen no. The basic concept of updating
the database is same in all the 3 methods but only the method differs.
In session method after the data transfer program is coded, in order to process that particular session you
have to go to TC: SM 35 to process the session.
Direct input method have some standard programs that have to executed.....
Well, to be strong you got to try it out.......and check if it works!!!
Smitha
Q: Our ABAP program is working properly in Foreground. Can I schedule it for background
processing on the weekend?

A: SAP standard program RSBDCSUB helps you to schedule the job. Create a variant for RSBDCSUB with
the BDC session name.
Q: How can we send a mail to the user intimating him that his report/BDC is completed in
background?
A: You can use FUNCTION RS_SEND_MAIL_FOR_SPOOLLIST
If UNIX is being used, you may send a report to any internet mail with the following:
REPORT ZSNDMAIL.
DATA: COMND (200) type c.
DATA: RESULT (200) type c occurs 100 with header line.
PARAMETERS: FILE (60) type c lower case default '/sapdata/sd_outbound/testmail.dat'.
PARAMETERS: SUBJECT (60) type c lower case.
PARAMETERS: EMAIL (60) type c lower case.
INITIALIZATION.
TRANSLATE EMAIL TO LOWER CASE.
START-OF-SELECTION.
TRANSLATE EMAIL TO LOWER CASE.
CONCATENATE 'cat' FILE '| elm -s "' subject '"' email into comnd seperated by space.
CALL 'SYSTEM' ID 'COMMAND' FIELD comnd 'TAB' FIELD UNIX_RESULTS-*SYS*.
Loop at Results.
write: /1 results.
endloop
end-of-selection.
Interview Question on BDC
What is BDC- its use, and how to use it?
It is Batch Data conversion used for transferring some data other than sap into sap ... this is also a work of
an ABAPer.
What is "UTS" Or may be it is "UST", something called Unit test?
Use: After developing any object we should write a test case proving that the object is working properly or
not. This is done by the ABAPer. This is UNIT TEST CASE.
In BDC how can we handle Table Controls?
When you do your recording you will have a tab for Next line or Insert. You have to capture that in your
recording. If your transaction code doesn't have that in the recording then you have to set up a page down
(=P+) and loop it based on the line entries u c on teh screen.
Suppose we are transfer data through BDC from leagacy to SAP and their is some duplicate data in
legacy system but we don't want this in SAP system .So how can we check that this data is already
exist?
In BDC you would have all your legacy data in an internal table. Use Delete Adjacent dulpicates syntax to
delete duplicate entries.
Can we use two transaction code in one BDC like XK01 & XD01 if yes how?
Yes, we can do that by combining the two bdc program codes together. Then you perform the program
routine accordingly. However, it will make your BDC program very long and complex.
How can we handle errors in Function Module?

Exceptions is used to handle errors.


Can we use Session method & Call transaction both in one BDC if yes please give me example and
scenerio where we use this?
You start your dataload using Call Transaction and if any errors occur push all those errors in a session so
that your dataload takes place uninterrupted and you can processs ur errors later.
Difference Between Batch Input and Call Transaction in BDC
What is the difference between batch input and call transaction in BDC?
Session method.
1) synchronous processing.
2) can tranfer large amount of data.
3) processing is slower.
4) error log is created
5) data is not updated until session is processed.
Call transaction.
1) asynchronous processing
2) can transfer small amount of data
3) processing is faster.
4) errors need to be handled explicitly
5) data is updated automatically
ABAP Tips by : Nagaraj Muniyappa
Batch Data Communication (BDC) is the oldest batch interfacing technique that SAP provided since the
early versions of R/3. BDC is not a typical integration tool, in the sense that, it can be only be used for
uploading data into R/3 and so it is
not bi-directional.
BDC works on the principle of simulating user input for transactional screen, via an ABAP program.
Typically the input comes in the form of a flat file. The ABAP program reads this file and formats the input
data screen by screen into an internal table (BDCDATA). The transaction is then started using this internal
table as the input and executed in the background.
In Call Transaction, the transactions are triggered at the time of processing itself and so the ABAP program
must do the error handling. It can also be used for real-time interfaces and custom error handling & logging
features. Whereas in
Batch Input Sessions, the ABAP program creates a session with all the transactional data, and this session
can be viewed, scheduled and processed (using Transaction SM35) at a later time. The latter technique has
a built-in error processing mechanism too.
Batch Input (BI) programs still use the classical BDC approach but doesnt require an ABAP program to be
written to format the BDCDATA. The user has to format the data using predefined structures and store it in a
flat file. The BI program then reads this and invokes the transaction mentioned in the header record of the
file.
Direct Input (DI) programs work exactly similar to BI programs. But the only difference is, instead of
processing screens they validate fields and directly load the data into tables using standard function
modules. For this reason, DI programs are much faster (RMDATIND - Material Master DI program works at
least 5 times faster) than the BDC counterpart and so ideally suited for loading large volume data. DI
programs are not available for all application areas.

Differences between bdc session method and call transaction method.


The most important aspects of the batch session interface are: - Asynchronous processing - Transfers data
for multiple transactions - Synchronous database update During processing, no transaction is started until
the previous transaction has been written to the database. - A batch input processing log is generated for
each session - Sessions cannot be generated in parallel
The most important aspects of the CALL TRANSACTION USING interface are: - Synchronous processing Transfers data for a single transaction - Synchronous and asynchronous database updating both possible
The program specifies which kind of updating is desired. - Separate LUW for the transaction The system
performs a database commit immediately before and after the CALL TRANSACTION USING statement. No batch input processing log is generated.
Explain in detail with example what is batch input session?
Batch Input Session:
- It is a sequence of transactions, which is generated when user run a particular program.
- It contains the accounting documents that are to be created. The SAP system stores these transactions
until you decide to process them online.
- It does not update transaction figures until the session has been processed. Using this technique, you can
transfer large amounts of data to the SAP system in a short time.
Three processing modes of executing Batch Input Session :(1) Run Visibly : You can correct faulty transactions online & work step-by-step through the transactions not
yet executed.
(2) Display Errors only : You can correct faulty transactions online. Transactions not yet executed, but
without error, run in the background.
(3) Run in Background : Recommended by SAPDelimiter for BDC Program
I use (tab and ,) delimeter for bdc but I could not upload data from note pad to sap.
As you mentioned that you have used ( tab & , ) this is wrong you have to use TAB OR , (comma) .
Use , (comma). While executing bdc you have to mention delimiter factor at bdc screen.
Nitin

Can anybody tell me, if we are using excel sheet as a data provider for BDC Program, then how to
define a delimiter so that my BDC programe should automatically split the field.
You either save the excel sheet as Tab delimited file or .csv file. and declare your internal table to get the
corresponding the contents from the file. Then when its tab delimited or .csv, SPLIT the contents into
respective fields.
Here is a sample for CSV file :
*declaration of internal tables.
DATA : BEGIN OF IT_DUMMY OCCURS 0,
TEXT(500),
END OF IT_DUMMY.
DATA : BEGIN OF IT_MAIN OCCURS 0,
MATNR LIKE RMMG1-MATNR,
"material selection to change
DISLS LIKE MARC-DISLS,
"lot size key
END OF IT_MAIN.

*uploading the input file***********************************************


CALL FUNCTION 'UPLOAD'
EXPORTING
FILENAME
= INPUT
TABLES
DATA_TAB
= IT_DUMMY
EXCEPTIONS
CONVERSION_ERROR = 1
INVALID_TABLE_WIDTH = 2
INVALID_TYPE
=3
NO_BATCH
=4
UNKNOWN_ERROR
=5
OTHERS
= 6.
*appending it_main by splitting the uploaded file
LOOP AT IT_DUMMY.
SPLIT IT_DUMMY AT ',' INTO IT_MAIN-MATNR IT_MAIN-DISLS.
APPEND IT_MAIN.
ENDLOOP.
BDC to Check the Views Maintained For A Material Master
You want to run a BDC programme to update your material master for selected views. Now every
master depending on its creation has got different views maintained, and you want to select only
two views i.e. PURCHASING and MRP 1 every time for each material code. If you go statically by
giving the index for the views selection screen, then the selection of the views go wrong every time
there is a change in the total maintained views for a material.
For example:
Check field MARA-VPSTA. Updated with a character for a specific view.
Think it is like this:
'A'.
" Work scheduling
'B'.
" Accounting
'C'.
" Classification
'D'.
" MRP 1 / 2 / 3 / 4
'E'.
" Purchasing/Foreign trade import
'F'.
" Production resources / tools
'G'.
" Costing
'K'.
" Basic Data
'L'.
" Plant data - Storage 1 / 2
'P'.
" Forecasting
'Q'.
" Quality Management
'S'.
" Warehouse Management
'V'.
" Sales
'X'.
" Plant stocks
'Z'.
" Storage location stocks
Answer:
Many Abaper have this problem. When you record your BDC transaction select the basic data view only.
Then navigate to the views you want using the tabs. (don't select and use enter). You will get values like
"SP06". These will take you directly to the screen.
ABAP - Execute BDC immediately by replacing the include BDCRECX1
When you generate the BDC (Batch Data Communication options define the processing mode for a batch
input session) program with SHDB, you can remove a lot of unwanted fields by copying this customize abap
include program. It allows you to execute the BDC program immediately without filling up those SAP
generate fields. To run background, just run it as a background job.

* Execute BDC immediately by replacing the include BDCRECX1


*
* Written by : SAP Basis, ABAP Programming and Other IMG Stuff
*
http://www.sap-img.com
*
***INCLUDE ZBDCRECX1.
* When you generate the program using SHDB, you can replace it
* with this if you want to execute it immediately without having
* to process it using SM35.
*
* During testing you can used the original include.
*
* For example,
* include zbdcrecx1. "After test
* include bdcrecx. "Before test
* ------------------------------------* Declare your internal table as RECORD
* ------------------------------------* for programs doing a data transfer by creating a batch-input session
* and
* for programs doing a data transfer by CALL TRANSACTION USING
*SELECTION-SCREEN BEGIN OF LINE.
* PARAMETERS SESSION RADIOBUTTON GROUP CTU. "create session
* SELECTION-SCREEN COMMENT 3(20) TEXT-S07 FOR FIELD SESSION.
* selection-screen position 45.
* PARAMETERS CTU RADIOBUTTON GROUP CTU DEFAULT 'X'. "call transaction
* SELECTION-SCREEN COMMENT 48(20) TEXT-S08 FOR FIELD CTU.
*SELECTION-SCREEN END OF LINE.
PARAMETERS: SESSION NO-DISPLAY,
CTU NO-DISPLAY DEFAULT 'X'.
*SELECTION-SCREEN BEGIN OF LINE.
* SELECTION-SCREEN COMMENT 3(20) TEXT-S01 FOR FIELD GROUP.
* selection-screen position 25.
* PARAMETERS GROUP(12).
"group name of session
* SELECTION-SCREEN COMMENT 48(20) TEXT-S05 FOR FIELD CTUMODE.
* selection-screen position 70.
* PARAMETERS CTUMODE LIKE CTU_PARAMS-DISMODE DEFAULT 'N'.
*
"A: show all dynpros
*
"E: show dynpro on error only
*
"N: do not display dynpro
*SELECTION-SCREEN END OF LINE.
PARAMETERS: GROUP(12) NO-DISPLAY,
CTUMODE NO-DISPLAY DEFAULT 'N'.
*SELECTION-SCREEN BEGIN OF LINE.
* SELECTION-SCREEN COMMENT 3(20) TEXT-S02 FOR FIELD USER.
* selection-screen position 25.
* PARAMETERS: USER(12) DEFAULT SY-UNAME. "user for session in batch
* SELECTION-SCREEN COMMENT 48(20) TEXT-S06 FOR FIELD CUPDATE.
* selection-screen position 70.
* PARAMETERS CUPDATE LIKE CTU_PARAMS-UPDMODE DEFAULT 'L'.
*
"S: synchronously
*
"A: asynchronously
*
"L: local
*SELECTION-SCREEN END OF LINE.
PARAMETERS: USER(12) NO-DISPLAY DEFAULT SY-UNAME,
CUPDATE LIKE CTU_PARAMS-UPDMODE DEFAULT 'L' NO-DISPLAY.

*SELECTION-SCREEN BEGIN OF LINE.


* SELECTION-SCREEN COMMENT 3(20) TEXT-S03 FOR FIELD KEEP.
* selection-screen position 25.
* PARAMETERS: KEEP AS CHECKBOX.
"' ' = delete session if finished
*
"'X' = keep session if finished
* SELECTION-SCREEN COMMENT 48(20) TEXT-S09 FOR FIELD E_GROUP.
* selection-screen position 70.
* parameters E_GROUP(12).
"group name of error-session
*SELECTION-SCREEN END OF LINE.
PARAMETERS: KEEP
NO-DISPLAY,
E_GROUP(12) NO-DISPLAY.
*SELECTION-SCREEN BEGIN OF LINE.
* SELECTION-SCREEN COMMENT 3(20) TEXT-S04 FOR FIELD HOLDDATE.
* selection-screen position 25.
* PARAMETERS: HOLDDATE LIKE SY-DATUM.
* SELECTION-SCREEN COMMENT 51(17) TEXT-S02 FOR FIELD E_USER.
* selection-screen position 70.
* PARAMETERS: E_USER(12) DEFAULT SY-UNAME. "user for error-session
*SELECTION-SCREEN END OF LINE.
PARAMETERS: HOLDDATE LIKE SY-DATUM NO-DISPLAY,
E_USER(12) DEFAULT SY-UNAME NO-DISPLAY.
*SELECTION-SCREEN BEGIN OF LINE.
* SELECTION-SCREEN COMMENT 51(17) TEXT-S03 FOR FIELD E_KEEP.
* selection-screen position 70.
* PARAMETERS: E_KEEP AS CHECKBOX. "' ' = delete session if finished
*
"'X' = keep session if finished
*SELECTION-SCREEN END OF LINE.
PARAMETERS: E_KEEP NO-DISPLAY.
*SELECTION-SCREEN BEGIN OF LINE.
* SELECTION-SCREEN COMMENT 51(17) TEXT-S04 FOR FIELD E_HDATE.
* selection-screen position 70.
* PARAMETERS: E_HDATE LIKE SY-DATUM.
*SELECTION-SCREEN END OF LINE.
*
*SELECTION-SCREEN SKIP.
PARAMETERS: E_HDATE LIKE SY-DATUM NO-DISPLAY.
*SELECTION-SCREEN BEGIN OF LINE.
* SELECTION-SCREEN COMMENT 1(33) TEXT-S10 FOR FIELD NODATA.
* PARAMETERS: NODATA DEFAULT '/' LOWER CASE.
"nodata
*SELECTION-SCREEN END OF LINE.
PARAMETERS: NODATA DEFAULT '/' LOWER CASE NO-DISPLAY.
*SELECTION-SCREEN BEGIN OF LINE.
* SELECTION-SCREEN COMMENT 1(33) FOR FIELD SMALLLOG.
* PARAMETERS: SMALLLOG as checkbox. "' ' = log all transactions
*
"'X' = no transaction logging
*SELECTION-SCREEN END OF LINE.
PARAMETERS: SMALLLOG NO-DISPLAY.
*----------------------------------------------------------------------*
* data definition
*----------------------------------------------------------------------*
*
Batchinputdata of single transaction
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
*
messages of call transaction
DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

*
error session opened (' ' or 'X')
DATA: E_GROUP_OPENED.
*
message texts
TABLES: T100.

*----------------------------------------------------------------------*
* at selection screen
*
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
* group and user must be filled for create session
IF SESSION = 'X' AND
GROUP = SPACE OR USER = SPACE.
MESSAGE E613(MS).
ENDIF.
*----------------------------------------------------------------------*
* open dataset
*
*----------------------------------------------------------------------*
FORM OPEN_DATASET USING P_DATASET.
OPEN DATASET P_DATASET IN TEXT MODE.
IF SY-SUBRC <> 0.
WRITE: / TEXT-E00, SY-SUBRC.
STOP.
ENDIF.
ENDFORM.
*----------------------------------------------------------------------*
* close dataset
*
*----------------------------------------------------------------------*
FORM CLOSE_DATASET USING P_DATASET.
CLOSE DATASET P_DATASET.
ENDFORM.
*----------------------------------------------------------------------*
* create batchinput session
*
* (not for call transaction using...)
*
*----------------------------------------------------------------------*
FORM OPEN_GROUP.
IF SESSION = 'X'.
SKIP.
WRITE: /(20) 'Create group'(I01), GROUP.
SKIP.
* open batchinput group
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING CLIENT = SY-MANDT
GROUP = GROUP
USER = USER
KEEP = KEEP
HOLDDATE = HOLDDATE.
WRITE: /(30) 'BDC_OPEN_GROUP'(I02),
(12) 'returncode:'(I05),
SY-SUBRC.
ENDIF.
ENDFORM.
*----------------------------------------------------------------------*
* end batchinput session
*
* (call transaction using...: error session)
*
*----------------------------------------------------------------------*

FORM CLOSE_GROUP.
IF SESSION = 'X'.
* close batchinput group
CALL FUNCTION 'BDC_CLOSE_GROUP'.
WRITE: /(30) 'BDC_CLOSE_GROUP'(I04),
(12) 'returncode:'(I05),
SY-SUBRC.
ELSE.
IF E_GROUP_OPENED = 'X'.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
WRITE: /.
WRITE: /(30) 'Fehlermappe wurde erzeugt'(I06).
ENDIF.
ENDIF.
ENDFORM.
*----------------------------------------------------------------------*
*
Start new transaction according to parameters
*
*----------------------------------------------------------------------*
FORM BDC_TRANSACTION USING TCODE.
DATA: L_MSTRING(480).
DATA: L_SUBRC LIKE SY-SUBRC.
* batch input session
IF SESSION = 'X'.
CALL FUNCTION 'BDC_INSERT'
EXPORTING TCODE = TCODE
TABLES DYNPROTAB = BDCDATA.
IF SMALLLOG <> 'X'.
WRITE: / 'BDC_INSERT'(I03),
TCODE,
'returncode:'(I05),
SY-SUBRC,
'RECORD:',
SY-INDEX.
ENDIF.
* call transaction using
ELSE.
REFRESH MESSTAB.
CALL TRANSACTION TCODE USING BDCDATA
MODE CTUMODE
UPDATE CUPDATE
MESSAGES INTO MESSTAB.
L_SUBRC = SY-SUBRC.
IF SMALLLOG <> 'X'.
*
WRITE: / 'CALL_TRANSACTION',
*
TCODE,
*
'returncode:'(I05),
*
L_SUBRC,
*
'RECORD:',
*
SY-INDEX.
IF SY-SUBRC = 0.
FORMAT COLOR OFF.
WRITE:/ 'Successfully Process ', MESSTAB, RECORD.
ELSE.
FORMAT COLOR COL_NEGATIVE.
WRITE:/ 'Failed Process ', MESSTAB, RECORD.
ENDIF.
LOOP AT MESSTAB.
SELECT SINGLE * FROM T100 WHERE SPRSL = MESSTAB-MSGSPRA
AND ARBGB = MESSTAB-MSGID
AND MSGNR = MESSTAB-MSGNR.
IF SY-SUBRC = 0.

L_MSTRING = T100-TEXT.
IF L_MSTRING CS '&1'.
REPLACE '&1' WITH MESSTAB-MSGV1 INTO L_MSTRING.
REPLACE '&2' WITH MESSTAB-MSGV2 INTO L_MSTRING.
REPLACE '&3' WITH MESSTAB-MSGV3 INTO L_MSTRING.
REPLACE '&4' WITH MESSTAB-MSGV4 INTO L_MSTRING.
ELSE.
REPLACE '&' WITH MESSTAB-MSGV1 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV2 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV3 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV4 INTO L_MSTRING.
ENDIF.
CONDENSE L_MSTRING.
WRITE: / MESSTAB-MSGTYP, L_MSTRING(250).
ELSE.
WRITE: / MESSTAB.
ENDIF.
ENDLOOP.
SKIP.
ENDIF.
** Erzeugen fehlermappe ************************************************
IF L_SUBRC <> 0 AND E_GROUP <> SPACE.
IF E_GROUP_OPENED = ' '.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING CLIENT = SY-MANDT
GROUP = E_GROUP
USER = E_USER
KEEP = E_KEEP
HOLDDATE = E_HDATE.
E_GROUP_OPENED = 'X'.
ENDIF.
CALL FUNCTION 'BDC_INSERT'
EXPORTING TCODE = TCODE
TABLES DYNPROTAB = BDCDATA.
ENDIF.
ENDIF.
REFRESH BDCDATA.
ENDFORM.
*----------------------------------------------------------------------*
*
Start new screen
*
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM.
*----------------------------------------------------------------------*
*
Insert field
*
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL <> NODATA.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM.

--- End of ABAP Program


Retreive Error Message from BDC
While doing call transaction, if an error occurs in updation, we declare bdcmsgcoll and store our
messages in it, but how to retreive error message from it
Using function module 'FORMAT_MESSAGE' you can capture the messages.
Here is a sample of the program code for that:
LOOP AT it_messtab.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = it_messtab-msgid
lang = it_messtab-msgspra
no = it_messtab-msgnr
v1 = it_messtab-msgv1
v2 = it_messtab-msgv2
IMPORTING
msg = g_msg
EXCEPTIONS
OTHERS = 0.
IF it_messtab-msgtyp = 'S'.
it_sucess-sucess_rec = g_msg.
it_sucess-lifnr = it_header-lifnr." Based on your field
it_sucess-tabix = v_lines.
APPEND it_sucess.
ELSEIF it_messtab-msgtyp = 'E'.
it_error-error_rec = g_msg.
it_error-lifnr = it_header-lifnr.
it_error-tabix = v_lines.
APPEND it_error.
ELSE.
it_info-info_rec = g_msg.
it_info-lifnr = it_header-lifnr.
it_info-tabix = v_lines.
APPEND it_info.
ENDIF.
ENDLOOP.
System Crash During BDC Update
While uploading a flat file through BDC Call Transaction, the system suddenly get CRASHED. How
do I know many records have been updated?
Most ABAPers would not have faced this problem.
We faced it on 3 or 4 occasions during our Project.
There are two ways to tackle this issue.
Method..1
Thru se16 check the table(s) being updated, preferably the last table as per your code. If you have say 1600
records in the flat file check for the upload of the 1600 th record.. If not ok, check for the upload of the 800 th
record(N-N/2), if OK go & check

N+(N/2) th record if not ok goto N-(N/2) th record where N is the curent record number in the flat file . In
about 4 or five checks you will converge on the last uploaded record.
Now from the flat file, remove the lines till the upload is ok & then re-run BDC.
Even here a record may be uploaded partially which has to be manually edited thru se16.
Method..2
Have a zee table for uploads. Just after uploading a record into the sap table, fill this zeetable with few fields
of each the records. In an abort situation this table will tell the story of the update status. Take care to empty
this table occasionally.
What Are RSBDCBTC_SUB and RSBDCSUB Use For
By: Mike
Explain briefly about RSBDCSUB and it uses.
Program rsbdcsub is to execute the session method in background and in foreground, for this you need to
create a session in sm35.
To carry out postings, you can have the system run the batch input sessions automatically. To do this, use
report RSBDCSUB.
To process batch input sessions manually, proceed as follows:
- Choose System -> Services -> Batch input -> Sessions.
The system displays a list of those batch input sessions that meet your selection criteria. Enter the relevant
data for selecting the session.
- Select the session you require and choose Session -> Process.
The system displays a dialog box where you can specify how the session is to be processed. You generally
select the Display errors field in order to have the system display any errors in the session.
- Save your entries.
The system posts the documents. You can call up a log of the batch input session by choosing Goto -> Log.
How to run Batch Input Session from a report in Online?
I have created a Batch Input Session through report program. When the report was executed and
once the Batch Input is created, I want the Batch Input which is created by the report program has to
be processed online. How this can be achieved.
Debugging program RSBDCSUB lead me to find out another program called RSBDCBTC_SUB which just
takes the Queue ID of the Batch session and process it in the No screen mode. I copied this standard
program, made changes so that it always pass the mode as 'A' (All Screens) and used it in my program. I
already had the Queue ID and that's all I want to execute ZRSBDCBTC_SUB.
Variant in Job Log
In a job log, TCode SM37, the program name is given as RSBDCBTC_SUB and the variant is given as
&0000000003325.
1) When I go to the program in SE38 and execute the program, on the selection screen no variant is
maintained. Then from where is it picking up this variant? And where can I see, what are the values
in this variant?

2) Every time the job runs, it picks up a new variant. From where is it picking up these new variants
everyday?
When you run the report at SE38 using execute background ,system will take default variant.
In your case someone is running the program(se38) in background, he fill the values in selection screen and
run on background.
In this case variant is not requeired.
Difference between RSBDCSUB and RSBDCBTC :
RSBDCSUB - You can start the processing of the sessions using this.
RSBDCBTC - This has something to do with the Queues of the batch input sessions, you cannot start any
session using this.
RSBDCSUB is used for executing BDC sessions, e.g. you create BDC sessions in a user exit and want to
execute them once every day. You can schedule RSBDCSUB to execute you BDC sessions at a particular
time.
When the program is processed and waiting for the session to be released, if we use RSBDCSUB then the
Whole sessions created for the program are released at a single go, Whereas if we use RSBDCBTC, each
session is given a Unique Session ID and it can be released automatically regardless of the program name.
RSBDCSUB - Processing Sessions Automatically
In most cases, batch input sessions can be processed automatically. It is not necessary for a session to wait
until a system administrator explicitly starts the processing of the session.
The ABAP program RSBDCSUB must be scheduled as a periodic job in the R/3 background processing
system. RSBDCSUB checks for and starts any batch input sessions that have not yet been run. It schedules
such sessions for immediate execution in the background processing system.
Schedule RSBDCSUB to run periodically in one or more background jobs.
If you have regularly scheduled batch input runs, you can schedule separate jobs for each of the scheduled
data transfers. The start time for the RSBDCSUB job can be set according to the batch input schedule. And
you can use a variant to restrict RSBDCSUB only to the batch input sessions that you expect.
With RSBDCSUB, you can use all of the selection criteria offered on the batch input main menu to select
sessions to run:
- session name
- date and time of generation
- status: ready to run or held in the queue because of errors
Batch input sessions are started automatically rather than by hand. The RSBDCSUB program can be set up
to start all sessions that arrive in an R/3 System, or it can be fine-tuned to start only batch input sessions
that you expect.
ABAP syntax - submit BDC - help
I am using the SAP program RSBDCBTC to submit a BDC session from within my program that is running in
the foreground. So I am submitting the program with following syntax:

SUBMIT rsbdcbtc WITH queue-id = qid AND RETURN.


This SUBMIT works fine. That is, the BDC session is executed BUT the problem I have is that the program
control DOES NOT return back to my calling program after the session is submitted/executed. I get the popup window "processing of batch input session completed" and when I click on either of the buttons "Session
Overview" or "Exit batch input", the program ends. I need to get back to my calling program. Granted if I ran
this program in the background, this informational pop-up screen would be ignored but I need to run my
program in the foreground ...
Anyways so I thought I would modify/write my own version of RSBDCBTC but I came across a CALL that I
am unfamiliar with. That is, the syntax makes no sense to me. In RSBDCBTC there is the following call:
CALL 'BDC_START_GROUP' ID 'GROUP' FIELD WA_MTAB-GROUPID
ID 'QUID' FIELD WA_MTAB-QID
ID 'DISPLAY' FIELD MODUS
ID 'LOG' FIELD LOGALL. "all message
But I cant find the code behind 'BDC_START_GROUP' ! What is it ??? It's not a function or a form or a
report ... what is it ?? Where can I find the code behind BDC_START_GROUP ?
As a side note, if someone can tell me how to get back to my calling program after I submit RSBDCBTC,
that would be good to.
--CALL 'BDC_START_GROUP' is a C-routine and you cannot find the code behind it as it is C-code.
I have already used this and when you are giving the option Return, it should return to the calling program.
--Submit with RSBDCSUB like follows,
submit rsbdcsub using selection-set selection_set and return.
You should have to create a variant on RSBDCSUB with the session name.
--You can use this piece of code:
DATA SUBREPORT(12) TYPE C VALUE 'RSBDCBTC_SUB'. " Submit Batch
move groupid to jname.
CALL FUNCTION 'JOB_OPEN'
EXPORTING
JOBGROUP = BI
JOBNAME = JNAME
IMPORTING
JOBCOUNT = JNUMB

EXCEPTIONS
CANT_CREATE_JOB = 1
INVALID_JOB_DATA = 2
JOBNAME_MISSING = 3
OTHERS = 99.
*
IF SY-SUBRC EQ 0. "Job_open OK
*
SUBMIT (SUBREPORT)
USER SY-UNAME
VIA JOB JNAME
NUMBER JNUMB
WITH QUEUE_ID EQ QID
WITH MAPPE EQ GROUPID
WITH MODUS EQ 'N'
WITH LOGALL EQ LMODUS
AND RETURN.
*
IF SY-SUBRC EQ 0. "submit OK
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
JOBCOUNT = JNUMB
JOBNAME = JNAME
STRTIMMED = X
IMPORTING
JOB_WAS_RELEASED = JOBRELE
EXCEPTIONS
CANT_START_IMMEDIATE = 1
INVALID_STARTDATE = 2
JOBNAME_MISSING = 3
JOB_CLOSE_FAILED = 4
JOB_NOSTEPS = 5
JOB_NOTEX = 6
LOCK_FAILED = 7
OTHERS = 99.
IF SY-SUBRC EQ 0. "Job_close is OK
IF JOBRELE EQ X. "job is release/
ENDIF.
ENDIF.
ENDIF.
ENDIF

What is ALV Programming?


Content Author: Nimesh Jhanwar
What is ALV programming in ABAP? When is this grid used in ABAP?
ALV is Application List viewer.
Sap provides a set of ALV (ABAP LIST VIEWER) function modules which can be put into use to embellish
the output of a report. This set of ALV functions is used to enhance the readability and functionality of any
report output. Cases arise in sap when the output of a report contains columns extending more than 255
characters in length.
In such cases, this set of ALV functions can help choose selected columns and arrange the different
columns from a report output and also save different variants for report display. This is a very efficient tool
for dynamically sorting and arranging the columns from a report output.
The report output can contain up to 90 columns in the display with the wide array of display options.
The commonly used ALV functions used for this purpose are;
1. REUSE_ALV_VARIANT_DEFAULT_GET
2. REUSE_ALV_VARIANT_F4
3. REUSE_ALV_VARIANT_EXISTENCE
4. REUSE_ALV_EVENTS_GET
5. REUSE_ALV_COMMENTARY_WRITE
6. REUSE_ALV_FIELDCATALOG_MERGE
7. REUSE_ALV_LIST_DISPLAY
8. REUSE_ALV_GRID_DISPLAY
9. REUSE_ALV_POPUP_TO_SELECT
Purpose of the above Functions are differ not all the functions are required in all the ALV Report.
But either no.7 or No.8 is there in the Program.
How you call this function in your report?
After completion of all the data fetching from the database and append this data into an Internal Table. say
I_ITAB.
Then use follwing function module.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM
= 'Prog.name'
I_STRUCTURE_NAME
= 'I_ITAB'
I_DEFAULT
= 'X'
I_SAVE
= 'A'
TABLES
T_OUTTAB
= I_ITAB.
IF SY-SUBRC <> 0.
WRITE: 'SY-SUBRC: ', SY-SUBRC .
ENDIF.
ENDFORM.
" GET_FINAL_DATA

What is SLIS in ALV


SLIS is the type library for ALV grid.
If you'll use the ALV you have to add TYPE-POOLS : SLIS. command at the beginning of your code.
Consider these :
slis_t_fieldcat_alv is containing "_t_"
It means that it is an internal table and slis_fieldcat_alv is header line of that.
Here is a practical example for alv grid :
Just think that you have an internal table named 'ITAB' to show.
Step1 : First add these lines to your code :
TYPE-POOLS : SLIS.
DATA ALV_PROG_NAME LIKE SY-REPID.
ALV_PROG_NAME = SY-REPID.
DATA : ALV_ITAB_NAME(30),
L_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
ALV_ITAB_NAME = 'ITAB'. "!!Write here the name of your internal table
Step 2 : Add these two function :
The first function is filling the fieldcat L_FIELDCAT that you described, second is showing it on the screen.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = ALV_PROG_NAME
I_INTERNAL_TABNAME = ALV_ITAB_NAME
* I_STRUCTURE_NAME =
* I_CLIENT_NEVER_DISPLAY = 'X'
I_INCLNAME = ALV_PROG_NAME
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
CHANGING
CT_FIELDCAT = L_FIELDCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = ALV_PROG_NAME
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =

* I_GRID_SETTINGS =
* IS_LAYOUT =
IT_FIELDCAT = L_FIELDCAT
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IT_ALV_GRAPHICS =
* IT_ADD_FIELDCAT =
* IT_HYPERLINK =
* I_HTML_HEIGHT_TOP =
* I_HTML_HEIGHT_END =
* IT_EXCEPT_QINFO =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = ITAB[] "Write here the name of your internal table + []
* EXCEPTIONS
* PROGRAM_ERROR = 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.
*-- Bulent
Upload Logo for REUSE_ALV_COMMENTARY_WRITE
For those who wish to upload and use a picture in your ALV abap reports.
Steps for uploading Logo :-:
1. Goto the transaction OAER
2. Enter the class name as 'PICTURES'
3. Enter the class type as 'OT'
4. Enter the object key as the name of the logo you wish to give
5. Execute
6. Then in the new screen select Standard doc. types in bottom window
Click on the Screen icon
Now, it will ask for the file path where you have to upload the logo
7. Now you can use this logo in REUSE_ALV_COMMENTARY_WRITE
or
Import Logo and Background Picture for Reporting
In this step, you can import a customer-specific logo and a background picture into the R/3 System. These
will be displayed in the header area of reports in HR Funds and Position Management.

From the SPRO:


HR Funds and Position Management --> Dialog Control --> Customize Reporting Interface --> Import Logo
and Background Picture for Reporting.
Activities
1. Enter the Name of your logo/background picture as an object key in the initial screen.
2. Make sure that the class name is PICTURES, and the class type is OT.
3. Choose Execute.
4. Double-click the document type Picture on the Create tab page. A dialog box will appear in which you can
enter the path in which the logo/background picture can be found.
5. Enter the path and choose Open. The logo will be uploaded into the current R/3 System. If the
logo/background picture is to be transported into other systems as well, choose Transport.
6. Return to the initial screen and repeat the procedure after having entered the Name of your background
picture as an object key.
Please note that the logo/background picture can only be displayed in ALV-based reports with an HTML
header. Manually programmed reports such as business distribution plans are not based on the ALV.
If you have selected several initial objects, ALV-based reports in HR Funds and Position Management will
automatically use a hiearchical-sequential display. A logo is not displayed here either. Note also that the logo
cannot be printed (see print preview in program).
Make sure that the logo does not exceed a height of 100 pixels because it would mean that the header of
the report will be scrollable
How can I insert my company logo in the standard report?
It is not possible to print logo in the ordinary report, but it can done through ALV.
Write the code in Top-of-page event in ALV.
The following is the code for inserting the logo in ALV.
FORM TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
I_LOGO
= 'ENJOYSAP_LOGO'
IT_LIST_COMMENTARY = GT_LIST_TOP_OF_PAGE.
ENDFORM.
How to Refresh ALV List/Grid once it is displayed?
This mean to say that if you have a 'refresh' push button in your gui status, every time you press the
button, the list should get refreshed.
In ALV, to refresh the table you have to call the method "refresh_table_display".
It has the syntax very similar to creating the table.
It has two parameters. In the first one, you can mention if you want to refresh only the data (the icons are not
refreshed)
or

if you want to refresh only the icons around the grid (the data is not refreshed - this option is mostly not used
in day to day applications).
the synatx is :call method grid (name of grid )->refresh_table_display
exporting
IS_STABLE = <STRUCT OF TYPE LVC_S_STBL> (THIS IS FOR DATA REFRESHING)
I_SOFT_REFRESH = <VARIABLE OF CHAR 01> (THIS IS FOR ICON REFRESHING).
Sample programs on ALV Grid
report zbnstest.
************************************************************************
* TABLES AND DATA DECLARATION.
************************************************************************
*TABLES: mara,makt.",marc.
data syrepid like sy-repid.
data sydatum(10). " LIKE sy-datum.
data sypagno(3) type n.

* WHEN USING MORE THAN ONE TABLE IN ALV WE NEEED TO DECLARE THE TYPE
* GROUP (TYPE-POOLS--------->SLIS)
type-pools : slis.

************************************************************************
* INTERNAL TABLE DECLARATION.
************************************************************************
* INTERNAL TABLE TO HOLD THE VALUES FROM THE MARA TABLE
data: begin of t_mara occurs 0,
matnr like mara-matnr,
meins like mara-meins,
mtart like mara-mtart,
matkl like mara-matkl,
end of t_mara.
* INTERNAL TABLE TO HOLD THE CONTENTS FROM THE EKKO TABLE
data : begin of t_marc occurs 0,
matnr like mara-matnr,
werks like marc-werks,
minbe like marc-minbe.
data: end of t_marc.
* INTERNAL TABLE TO HOLD THE VALUES FROM MAKT TABLE.
data : begin of t_makt occurs 0,
matnr like mara-matnr,
maktx like makt-maktx,
spras like makt-spras,
end of t_makt.
* INTERNAL TABLE WHICH ACTUALLY MERGES ALL THE OTHER INTERNAL TABLES.
data: begin of itab1 occurs 0,

matnr like mara-matnr,


meins like mara-meins,
maktx like makt-maktx,
spras like makt-spras,
werks like marc-werks,
minbe like marc-minbe,
end of itab1.

* THE FOLLOWING DECLARATION IS USED FOR DEFINING THE FIELDCAT


* AND THE LAYOUT FOR THE ALV.
* HERE AS slis_t_fieldcat_alv IS A INTERNAL TABLE WITHOUT A HEADER LINE
* WE EXPLICITELY DEFINE AN INTERNAL TABLE OF THE SAME STRUCTURE AS THAT
* OF slis_t_fieldcat_alv BUT WITH A HEADER LINE IN THE DEFINITION.
* THIS IS DONE TO MAKE THE CODE SIMPLER.
* OTHERWISE WE MAY HAVE TO DEFINE THE STRUCTURE AS IN THE NORMAL SAP
* PROGRAMS.
* IN THE FIELDCATALOG TABLE WE ACTUALLY PASS THE FIELDS FROM ONE OR
* MORE TABLES AND CREATE A STRUCTURE
* IN THE LAYOUT STRUCTURE WE BASICALLY DEFINE THE FORMATTING OPTIONS
* LIKE DISPLAY IN THE ZEBRA PATTERN ,THE HOTSPOT OPTIONS ETC.
data: fieldcatalog type slis_t_fieldcat_alv with header line,
fieldlayout type slis_layout_alv.

* DECLARING THE EVENTTABLE INTERNL TABLE FOR USING EVENTS LIKE


* TOP-OF-PAGE ETC.
data : eventstab type slis_t_event with header line.
* DECLARING AN INTERNAL TABLE TO HOLD THE DATA FOR THE TOP-OF-PAGE
data : heading type slis_t_listheader with header line.
data : heading1 type slis_t_listheader with header line.
data : heading2 type slis_t_listheader with header line.
data : heading3 type slis_t_listheader with header line.
data : heading4 type slis_t_listheader with header line.
data : heading5 type slis_t_listheader with header line.
data : heading6 type slis_t_listheader with header line.
data : heading7 type slis_t_listheader with header line.
data : heading8 type slis_t_listheader with header line.

* STRUCTURE TO PASS THE COLOR ATTRIBUTES FOR DISPLAY.


data : colorstruct type slis_coltypes.
************************************************************************
* INITIALIZATION. *
************************************************************************
initialization.
syrepid = sy-repid.
sypagno = sy-pagno.
clear fieldcatalog.

************************************************************************
* START-OF-SELECTION. *
************************************************************************
start-of-selection.
* SUBROUTINE TO POPULATE THE COLORSTRUCT
perform fill_colorstruct using colorstruct.
* SUBROUTINE TO POPULATE THE FIELDS OF THE FIELD CATALOGUE
perform populate_fieldcatalog.

* SUBROUTINE TO SELECT DATA FROM VARIOUS TABLES AND POPULATE IT IN THE


* INTERNAL TABLE.
perform selectdata_and_sort.
* SUBROUTINE TO POPULATE THE LAYOUT STRUCTURE.
perform populate_layout using fieldlayout.
* SUBROUTINE TO CALL THE FUNCTION MERGE TO ENSURE PROPER DISPLAY.
perform merge_fieldcatalog.
* SUBROUTINE TO POPULATE THE EVENTSTAB.
perform fill_eventstab tables eventstab.
* SUBROUTINE TO POPULATE THE HEADING TABLES.
perform fill_headingtable tables heading using 'HEADING'.
perform fill_headingtable tables heading1 using 'HEADING1'.
perform fill_headingtable tables heading2 using 'HEADING2'.
perform fill_headingtable tables heading3 using 'HEADING3'.
perform fill_headingtable tables heading4 using 'HEADING4'.
perform fill_headingtable tables heading5 using 'HEADING5'.
perform fill_headingtable tables heading6 using 'HEADING6'.
perform fill_headingtable tables heading7 using 'HEADING7'.
perform fill_headingtable tables heading8 using 'HEADING8'.
* SUBROUTINE TO DISPLAY THE LIST.
perform display_alv_list.

************************************************************************
* FORMS
************************************************************************
* IN THIS SUBROUTINE WE POPULATE THE FIELDCATALOG TABLE WITH THE NAMES
* OF THE TABLE,FIELDNAME,WHETHER IT IS KEY FIELD OR NOT,HEADING AND
* COLUMN JUSTIFICATION.
form populate_fieldcatalog.
perform fill_fields_of_fieldcatalog tables fieldcatalog
using 'ITAB1' 'MATNR' 'X' .
perform fill_fields_of_fieldcatalog tables fieldcatalog
using 'ITAB1' 'MEINS' ' '.
perform fill_fields_of_fieldcatalog tables fieldcatalog
using 'ITAB1' 'MAKTX' ' ' .
perform fill_fields_of_fieldcatalog tables fieldcatalog
using 'ITAB1' 'MTART' ' ' .
perform fill_fields_of_fieldcatalog tables fieldcatalog
using 'ITAB1' 'MATKL' ' ' .
perform fill_fields_of_fieldcatalog tables fieldcatalog
using 'ITAB1' 'SPRAS' ' ' .
perform fill_fields_of_fieldcatalog tables fieldcatalog
using 'ITAB1' 'WERKS' ' ' .
perform fill_fields_of_fieldcatalog tables fieldcatalog
using 'ITAB1' 'MINBE' ' ' .
endform. " POPULATE_FIELDCATALOG

*---------------------------------------------------------------------*
* FORM FILL_FIELDS_OF_FIELDCATALOG *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> FIELDCATALOG *
* --> P_TABNAME *
* --> P_FIELDNAME *
* --> P_KEY *
* --> P_KEY *

*---------------------------------------------------------------------*
form fill_fields_of_fieldcatalog tables fieldcatalog
structure fieldcatalog
using p_tabname
p_fieldname
p_key.
* p_no_out.
fieldcatalog-tabname = p_tabname.
fieldcatalog-fieldname = p_fieldname.
fieldcatalog-key = p_key.
fieldcatalog-emphasize = '1234'.
*fieldcatalog-no_out = p_no_out.
append fieldcatalog.
endform. " FILL_FIELDSOFFIELDCATALOG

*---------------------------------------------------------------------*
* FORM POPULATE_LAYOUT *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> FIELDLAYOUT *
*---------------------------------------------------------------------*
form populate_layout using fieldlayout type slis_layout_alv.
fieldlayout-f2code = '&ETA' .
fieldlayout-zebra = 'X'.
* FOR THE WINDOW TITLE.
fieldlayout-window_titlebar = 'ALV with Events'.
fieldlayout-colwidth_optimize = 'X'.
fieldlayout-no_vline = ' '.
*fieldlayout-no_input = 'X'.
fieldlayout-confirmation_prompt = ''.
fieldlayout-key_hotspot = 'X'.
* This removes the column headings if the flag is set to 'X'
fieldlayout-no_colhead = ' '.
*fieldlayout-hotspot_fieldname = 'MAKTX'.
fieldlayout-detail_popup = 'X'.
* fieldlayout-coltab_fieldname = 'X'.
endform. " POPULATE_LAYOUT
*---------------------------------------------------------------------*
* FORM SELECTDATA_AND_SORT *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form selectdata_and_sort.
select matnr meins mtart matkl from mara
into corresponding fields of t_mara
up to 500 rows .
select matnr maktx spras from makt
into corresponding fields of t_makt
where matnr = t_mara-matnr and
spras = sy-langu.
select matnr werks minbe from marc
into corresponding fields of t_marc
where matnr = t_mara-matnr.
append t_marc.

endselect.
append t_makt.
endselect.
append t_mara.
endselect.
perform populate_itab1.
sort itab1 by matnr.
endform. " SELECTDATA_AND_SORT
*---------------------------------------------------------------------*
* FORM MERGE_FIELDCATALOG *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form merge_fieldcatalog.
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name = syrepid
i_internal_tabname = 'ITAB1'
* i_structure_name = 'COLORSTRUCT'
* I_CLIENT_NEVER_DISPLAY = 'X'
i_inclname = syrepid
changing
ct_fieldcat = fieldcatalog[]
exceptions
inconsistent_interface = 1
program_error = 2
others = 3.
endform. " MERGE_FIELDCATALOG

* IN THIS FUNCTION THE MINIMUM PARAMETERS THAT WE NEED TO PASS IS AS


* FOLLOWS:* i_callback_program --> CALLING PROGRAM NAME
* i_structure_name --> STRUCTURE NAME.
* is_layout --> LAYOUT NAME.
* it_fieldcat ---> BODY OF THE FIELD CATALOGUE INTERNAL TABLE
form display_alv_list.
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
* I_INTERFACE_CHECK = ' '
i_callback_program = syrepid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
i_structure_name = 'ITAB1'
is_layout = fieldlayout
it_fieldcat = fieldcatalog[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* THE FOLLOWING PARAMETER IS SET AS 'A' INORDER TO DISPLAY THE STANDARD
* TOOL BAR
i_save = 'A'
* IS_VARIANT = ' '
it_events = eventstab[]
* IT_EVENT_EXIT =
* IS_PRINT =
* I_SCREEN_START_COLUMN = 0

* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
tables
t_outtab = itab1
exceptions
program_error = 1
others = 2.
endform. " DISPLAY_ALV_LIST
*&---------------------------------------------------------------------*
*& Form POPULATE_ITAB1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form populate_itab1.
loop at t_mara.
loop at t_makt where matnr = t_mara-matnr.
loop at t_marc where matnr = t_mara-matnr.
move-corresponding t_mara to itab1.
move-corresponding t_makt to itab1.
move-corresponding t_marc to itab1.
append itab1.
endloop.
endloop.
endloop.
endform. " POPULATE_ITAB1
*&---------------------------------------------------------------------*
*& Form FILL_EVENTSTAB
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_EVENTSTAB text *
*----------------------------------------------------------------------*
form fill_eventstab tables p_eventstab structure eventstab.
* WHEN THE FOLLOWING FUNCTION IS CALLED THE SYSTEM POPULATES THE
* INTERNAL TABLE EVENTSTAB WITH A LIST OF EVENTS NAME.
* AS SHOWN BELOW WHEN USING I_LIST_TYPE = 0 THE FUNCTION RETURNS 14
* EVENTS NAME.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = p_eventstab[]
exceptions
list_type_wrong = 1
others = 2.
* BY CALLING THE ABOVE FUNCTION WE FIRST POPULATE THE EVENTSTAB WITH
* THE PREDEFINED EVENTS AND THEN WE MOVE THE FORM NAME AS SHOWN BELOW.
* WE ASSIGN A FORM NAME TO THE EVENT AS REQUIRED BY THE USER.
* FORM NAME CAN BE ANYTHING.THE PERFORM STATEMENT FOR THIS FORM
* IS DYNAMICALY CALLED.
read table p_eventstab with key name = slis_ev_top_of_page.
if sy-subrc = 0 .

move 'TOP_OF_PAGE' to p_eventstab-form.


append p_eventstab.
endif.
read table p_eventstab with key name = slis_ev_top_of_coverpage.
if sy-subrc = 0 .
move 'TOP_OF_COVERPAGE' to p_eventstab-form.
append p_eventstab.
endif.
read table p_eventstab with key name = slis_ev_end_of_coverpage .
if sy-subrc = 0 .
move 'END_OF_COVERPAGE' to p_eventstab-form.
append p_eventstab.
endif.
read table p_eventstab with key name = slis_ev_foreign_top_of_page.
if sy-subrc = 0 .
move 'FOREIGN_TOP_OF_PAGE' to p_eventstab-form.
append p_eventstab.
endif.
read table p_eventstab with key name = slis_ev_foreign_end_of_page.
if sy-subrc = 0 .
move 'FOREIGN_END_OF_PAGE' to p_eventstab-form.
append p_eventstab.
endif.
read table p_eventstab with key name = slis_ev_list_modify.
if sy-subrc = 0 .
move 'LIST_MODIFY' to p_eventstab-form.
append p_eventstab.
endif.
read table p_eventstab with key name = slis_ev_top_of_list.
if sy-subrc = 0 .
move 'TOP_OF_LIST' to p_eventstab-form.
append p_eventstab.
endif.
read table p_eventstab with key name = slis_ev_end_of_page.
if sy-subrc = 0 .
move 'END_OF_PAGE' to p_eventstab-form.
append p_eventstab.
endif.
read table p_eventstab with key name = slis_ev_end_of_list .
if sy-subrc = 0 .
move 'END_OF_LIST' to p_eventstab-form.
append p_eventstab.
endif.
endform. " FILL_EVENTSTAB
*&---------------------------------------------------------------------*
*& Form FILL_HEADINGTABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_HEADING text *
*----------------------------------------------------------------------*

form fill_headingtable tables p_heading structure heading


using tablename.
case tablename.
when 'HEADING'.
p_heading-typ = 'H'.
concatenate
' REPORT NAME:-' syrepid
' ABB Industry Pte Ltd' into p_heading-info.
append p_heading.
write sy-datum using edit mask '__/__/____' to sydatum.
concatenate
' DATE:-' sydatum ' USER: ' sy-uname 'PAGE NO:' sypagno
into p_heading-info.
append p_heading.
when 'HEADING1'.
p_heading-typ = 'H'.
p_heading-info = 'TOP-OF-COVER-PAGE'.
append p_heading.
when 'HEADING2'.
p_heading-typ = 'H'.
p_heading-info = 'END-OF-COVER-PAGE'.
append p_heading.
when 'HEADING3'.
p_heading-typ = 'H'.
p_heading-info = 'FOREIGN-TOP-OF-PAGE'.
append p_heading.
when 'HEADING4'.
p_heading-typ = 'H'.
p_heading-info = 'FOREIGN-END-OF-PAGE'.
append p_heading.
* WHEN 'HEADING5'.
* P_HEADING-TYP = 'H'.
* P_HEADING-INFO = 'LIST-MODIFY'.
* APPEND P_HEADING.
when 'HEADING6'.
p_heading-typ = 'H'.
p_heading-info = 'END-OF-PAGE'.
append p_heading.
when 'HEADING7'.
p_heading-typ = 'H'.
p_heading-info = 'END-OF-LIST'.
append p_heading.
when 'HEADING8'.
p_heading-typ = 'H'.
p_heading-info = 'TOP-OF-LIST'.
append p_heading.
endcase.
endform. " FILL_HEADINGTABLE
*---------------------------------------------------------------------*
* FORM TOP_OF_PAGE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form top_of_page.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = heading[]
exceptions
others = 1.

endform.
*&---------------------------------------------------------------------*
*& Form FILL_COLORSTRUCT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_COLORSTRUCT text *
*----------------------------------------------------------------------*
form fill_colorstruct using p_colorstruct type slis_coltypes .
p_colorstruct-heacolfir-col = 6.
p_colorstruct-heacolfir-int = 1.
p_colorstruct-heacolfir-inv = 1.
endform. " FILL_COLORSTRUCT
*---------------------------------------------------------------------*
* FORM TOP_OF_COVERPAGE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form top_of_coverpage.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = heading1[]
exceptions
others = 1.
endform.
*---------------------------------------------------------------------*
* FORM END_OF_COVERPAGE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form end_of_coverpage.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = heading2[]
exceptions
others = 1.
endform.
*---------------------------------------------------------------------*
* FORM FOREIGN_TOP_OF_PAGE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form foreign_top_of_page.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = heading3[]
exceptions
others = 1.
endform.
*---------------------------------------------------------------------*
* FORM FOREIGN_END_OF_PAGE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form foreign_end_of_page.

call function 'REUSE_ALV_COMMENTARY_WRITE'


exporting
it_list_commentary = heading4[]
exceptions
others = 1.
endform.
*---------------------------------------------------------------------*
* FORM LIST_MODIFY *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
*FORM LIST_MODIFY.
* CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
* EXPORTING
* IT_LIST_COMMENTARY = HEADING5[]
* EXCEPTIONS
* OTHERS = 1.
*ENDFORM.
*---------------------------------------------------------------------*
* FORM END_OF_PAGE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form end_of_page.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = heading6[]
exceptions
others = 1.
endform.
*---------------------------------------------------------------------*
* FORM END_OF_LIST *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form end_of_list.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = heading7[]
exceptions
others = 1.
endform.
*---------------------------------------------------------------------*
* FORM TOP_OF_LIST *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form top_of_list.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = heading8[]
exceptions
others = 1.
endform.
*--- End of Program

REUSE_ALV_GRID_DISPLAY Functions Example


I am using "REUSE_ALV_GRID_DISPLAY" to display Report in ALV.
I have to show System Date and Time at the end of Report so I caught Event "END_OF_PAGE" in
IT_EVENTS and modified IT_EVENTS field FORM with "F100_TOP_OF_PAGE", but I am not able to
see the Date and Time in the END OF PAGE
I wrote follwoing ocde so please suggest me necessary changes
*&---------------------------------------------------------------------*
*& Form f100-end_of_page
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f100-end_of_page.
clear: wa_listheader, it_end_listheader, it_end_listheader[].
concatenate 'Date' sy-datum into w_date separated by space.
wa_listheader-key = ''.
wa_listheader-typ = 'S'.
wa_listheader-info = 'Date'.
append wa_listheader to it_end_listheader.
clear: wa_listheader.
concatenate 'Time' sy-uzeit into w_date separated by space.
wa_listheader-key = ''.
wa_listheader-typ = 'S'.
wa_listheader-info = 'Time'.
append wa_listheader to it_end_listheader.
clear: wa_listheader.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = it_end_listheader[]
* I_LOGO =
* I_END_OF_LIST_GRID =
.
ENDFORM. " f100-end_of_page
----------------------------------In grid display there will be no end_of_page and no end_of_list.
You have show in top_of_page itself.
Otherwise use list display instead of grid.
Suresh Avutu

----------------------------------These steps have to be carried out...


DATA: gc_formname_top_of_page TYPE slis_formname
VALUE 'TOP_OF_PAGE'.
DATA: gc_formname_end_of_page TYPE slis_formname
VALUE 'END_OF_PAGE'.
DATA: gt_list_top_of_page TYPE slis_t_listheader.
DATA: gt_list_end_of_page TYPE slis_t_listheader.
-----------------PERFORM e03_eventtab_build USING gt_event[].
PERFORM e04_comment_build USING
gt_list_top_of_page[].
PERFORM e06_comment_build USING
gt_list_end_of_page[].
PERFORM list_alv_display.
------------------------FORM list_alv_display .
gt_event-name = slis_ev_top_of_list.
gt_event-form = 'TOP_OF_PAGE'.
APPEND gt_event.
gt_event-name = slis_ev_end_of_list.
gt_event-form = 'END_OF_PAGE'.
APPEND gt_event.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
* I_INTERFACE_CHECK
=''
i_bypassing_buffer
= 'X'
i_buffer_active
=''
i_callback_program
= ....
--------------------------------------FORM end_of_page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
i_logo
= ''
it_list_commentary = gt_list_end_of_page
I_END_OF_LIST_GRID = 1.
ENDFORM.
"END_OF_PAGE
-----------------------------------------FORM e06_comment_build
USING e06_lt_end_of_page TYPE slis_t_listheader.
DATA: ls_line TYPE slis_listheader.
DATA: yl_uname(60).
< here u can concatenate system date and time to
yl_uname>
CLEAR ls_line.
ls_line-typ = 'S'.
ls_line-info = yl_uname.
APPEND ls_line TO e06_lt_end_of_page.

endform.

"e06_comment_build

Suman Tyagi

An Example:
REPORT ZALV_GRID.
TABLES :vbap.
type-pools : slis.
data i_events TYPE slis_t_event.
DATA : my_alv TYPE REF TO cl_gui_alv_grid.
TYPES : BEGIN OF itab,
vbeln LIKE vbap-vbeln,
arktx LIKE vbap-arktx,
END OF itab.
TYPES : itab1 TYPE TABLE OF itab.
DATA : display TYPE itab1.
DATA : fcat TYPE SLIS_T_FIELDCAT_ALV.
DATA : wa LIKE LINE OF FCAT.
DATA WA1 LIKE VBAP.
DATA: container TYPE REF TO cl_gui_custom_container.
data report_id like sy-repid.
SELECT-OPTIONS s_vbeln FOR vbap-vbeln.
report_id = sy-repid.
SELECT * FROM vbap INTO CORRESPONDING FIELDS OF TABLE display WHERE
vbeln IN s_vbeln.
wa-fieldname = 'VBELN'.
wa-tabname = 'VBAP'.
wa-key = 'X'.
WA-HOTSPOT = 'X'.
wa-text_fieldname = 'Doc no.'.
APPEND wa TO fcat.
CLEAR wa.
wa-fieldname = 'ARKTX'.
wa-tabname = 'VBAP'.
wa-text_fieldname = 'Item Text'.
APPEND wa TO fcat.
PERFORM f0650_build_event USING 'USER_COMMAND'
'F0750_USER_COMMAND'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY '
EXPORTING
I_CALLBACK_PROGRAM = report_id
IT_FIELDCAT = FCAT
IT_EVENTS = i_events
TABLES
t_outtab = DISPLAY
.

FORM f0650_build_event USING value(w_c_event_name)


value(w_c_event_form).
DATA: f0650_wa_event TYPE slis_alv_event.
CLEAR f0650_wa_event.
f0650_wa_event-name = w_c_event_name.
f0650_wa_event-form = w_c_event_form.
APPEND f0650_wa_event TO i_events.
ENDFORM.
FORM f0750_user_command USING w_ucomm TYPE sy-ucomm
w_selfield TYPE slis_selfield.
CASE w_ucomm.
WHEN '&IC1'.
READ TABLE DISPLAY INTO WA1 INDEX w_selfield-tabindex.
* MESSAGE E000 WITH
* ' You have no authorization to view the report'.
call transaction 'SE11'.
ENDCASE.
ENDFORM.
function REUSE_ALV_FIELDCATALOG_MERGE
An example :Please note that structure ZSTOCK is a custom table and iline looks as follow :data: iline type table of zstock with header line.
data: gt_fieldcat
type slis_t_fieldcat_alv.
perform setup-fieldcatalog using gt_fieldcat[].
form setup-fieldcatalog using _fieldcat type slis_t_fieldcat_alv.
data: ls_fieldcat type slis_fieldcat_alv.
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_internal_tabname = 'ILINE'
i_structure_name = 'ZSTOCK'
changing
ct_fieldcat
= _fieldcat.
loop at _fieldcat into ls_fieldcat.
case ls_fieldcat-fieldname.
when 'DEPT'.
ls_fieldcat-no_out = 'X'.
when 'DESCR'.
ls_fieldcat-no_out = 'X'.
when 'GOOD_PRD'.
ls_fieldcat-do_sum = 'X'.
endcase.

modify _fieldcat from ls_fieldcat.


endloop.
endform.

" FIELDCATALOG

ALV 'Classic' Creating User/Global Layout Variants


You are working with the ALV "Classic" function module REUSE_ALV_LIST_DISPLAY.
Reading the documentation for the function module, it seems there is a way to save an ALV layout variant as
"user-specific" and/or "global". But unfortunately, you either can only save "globals" (with the '/' as first
character of the layout name) or "user-specific".
You have tried the I_SAVE parameter as 'U' and can only save "user-specific". You tried I_SAVE as 'X' and
can only save "global". You tried I_SAVE as 'A', but only can only save as "user-specific". The odd thing is,
on the Save Layout pop-up dialog the User-Specific checkbox is always "greyed-out", but has a check (for
'U' and 'A') or is checkless (for 'X').
Can "user" and "global" layout variants be saved together from same program with I_SAVE as 'A'?
Why is the User-Specific checkbox on the Save Layout pop-up always "greyed-out"?
You have the following EXPORTING parameters in my function module:
I_DEFAULT = 'X'
I_SAVE = 'A' "<=== this is to be global & user IS_VARIANT = VARIANT
VARIANT has the program's name in the REPORT field.

The "user-specific saving" needs a special authorization:


Authority-check object 'S_ALV_LAYO' id 'ACTVT' field '23', you can
avoid this authorization with IS_LAYOUT-NO_AUTHOR = 'X'.

How to use ALV for Hierarchical Lists


Can anyone tell me how to use ALV for hierarchical lists using the function code
REUSE_ALV_HIERSEQ_LIST_DISPLAY?
Swarna
Hello, there are some nice examples in SAP which use this function module, so you might want to check
them out ( where used etc. )
In essence, this is a call in one of my ABAPs

CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'


EXPORTING
i_interface_check
= 'I'
i_callback_program
= gv_repid
*
i_callback_pf_status_set
= 'STATUS_DATA'
i_callback_user_command
= 'COMMAND_DATA'
*
is_layout
= gs_layout

it_fieldcat
= gt_fieldcat
i_default
=''
i_save
= 'A'
i_tabname_header
= v_headers_itable
i_tabname_item
= v_items_itable
i_structure_name_header
= v_headers_table
i_structure_name_item
= v_items_table
is_keyinfo
= gs_keyinfo
i_bypassing_buffer
= 'X'
TABLES
t_outtab_header
= i_headers
*
t_outtab_item
= i_result
t_outtab_item
= i_report
EXCEPTIONS
program_error
=1
OTHERS
= 2.
The field cat creation worked like this :
FORM fieldcat.
DATA: ls_fieldcat TYPE slis_fieldcat_alv.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_internal_tabname = v_items_itable
i_structure_name = v_items_table
CHANGING
ct_fieldcat
= gt_fieldcat.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_internal_tabname = v_headers_itable
i_structure_name = v_headers_table
CHANGING
ct_fieldcat
= gt_fieldcat.
ENDFORM.
and of course you need to tell the thing what is key and item
gs_keyinfo-header01 = 'PA'.
gs_keyinfo-item01 = 'PA'.
gs_keyinfo-item02 = 'SAPDOC'.
PERFORM fieldcat.
I hope this helps you and not confuse you,
Cheers.
Display a Secondary List using ALV Grid
To display a secondary list when you click on one of the row items in an alv grid. The secondary list should
also be an alv.
Try out this code. You will have to make a structure ZSTR same as the output internal table.

REPORT ZTEST_REP1 .

TABLES : MARA,
BHDGD,
zstr.
TYPES:

BEGIN OF T_MARA,
MATNR LIKE MARA-MATNR,
ERNAM LIKE MARA-ERNAM,
END OF T_MARA.

CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED.


*Constants for ALV Implementation
CONSTANTS: C_SET
VALUE 'X',
C_RESET
VALUE '0',
C_SAVE
VALUE 'A',
C_EXIT(4)
VALUE 'EXIT',
C_BACK(4)
VALUE 'BACK',
C_CANC(4)
VALUE 'CANC',
C_PGTOP(5)
VALUE 'PGTOP',
C_PGUP(4)
VALUE 'PGUP',
C_PGDN(4)
VALUE 'PGDN',
C_PGEND(5)
VALUE 'PGEND'.

DATA : I_MARA TYPE STANDARD TABLE OF T_MARA WITH HEADER LINE,


*
*
*

Internal table for fields catalouge


I_FIELDCAT TYPE LVC_T_FCAT WITH HEADER LINE,
i_fieldcat2 type lvc_t_fcat with header line,
Internal table for cursor position
I_GT_SELROWS TYPE LVC_T_ROW .

DATA : WA_MARA LIKE I_MARA,


WA_GRIDROW LIKE LVC_S_ROW,
WA_GRIDCOL LIKE LVC_S_COL.
*Data for ALV Implementation.
DATA: OK_CODE
LIKE SY-UCOMM,
W_OK_CODE LIKE SY-UCOMM,
W_CALL
TYPE I VALUE 1,
W_TAB
LIKE SY-UCOMM VALUE 'TAB1',
W_SAVE,
"For Parameter I_SAVE
W_VARIANT TYPE DISVARIANT,
"For parameter IS_VARIANT
W_GRID
TYPE REF TO CL_GUI_ALV_GRID,
*
w_grid1
type ref to cl_gui_alv_grid,
W_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
*

w_container1 type ref to cl_gui_custom_container,


W_REPID
LIKE SY-REPID,
W_GS_PRINT TYPE LVC_S_PRNT,
W_GS_LAYOUT TYPE LVC_S_LAYO,
W_EVENT_REC TYPE REF TO LCL_EVENT_RECEIVER,
W_CONT_MAIN TYPE SCRFNAME VALUE 'CCCONTAINER',
W_LN
TYPE I,
"line number
W_INDEX
LIKE SY-TABIX,

W_FLAG,
W_TEMP_VAL

TYPE I.

*---------------------------------------------------------------------*
* Definition:
*---------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER DEFINITION.
PUBLIC SECTION.
METHODS:
HANDLE_TOP_OF_PAGE
FOR EVENT PRINT_TOP_OF_PAGE OF CL_GUI_ALV_GRID,
HANDLE_DOUBLE_CLICK
FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW E_COLUMN.
ENDCLASS.

*---------------------------------------------------------------------*
* CLASS LCL_EVENT_RECEIVER IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
METHOD HANDLE_TOP_OF_PAGE.
PERFORM F_GET_HEADER.
ENDMETHOD.
"handle_top_of_page
METHOD HANDLE_DOUBLE_CLICK.
* The event DOUBLE_CLICK provides parameters for row and column
* of the click. We use row parameter to select a line of the
* corresponding internal table.
* read selected row from internal table
READ TABLE I_MARA INDEX E_ROW-INDEX INTO WA_MARA.
IF SY-SUBRC <> 0.
*
message i001. " Cursor position not correct.
ELSE.
*
call dialog screen and display the details
call screen 200 starting at 10 5.
ENDIF.

ENDMETHOD.

"handle_double_click

ENDCLASS.
*----------------------------------------------------------------------* start-of-selection.
*----------------------------------------------------------------------START-OF-SELECTION.
SELECT MATNR ERNAM FROM MARA INTO TABLE I_MARA.
*---------------------------------------------------------------------* End-of-Selection.
*---------------------------------------------------------------------END-OF-SELECTION.

* Start of ALV part.


W_REPID = SY-REPID.
W_VARIANT-REPORT = W_REPID.
W_SAVE = C_SAVE.
W_CONT_MAIN = W_CONT_MAIN.
W_GS_LAYOUT = W_GS_LAYOUT.
W_GS_PRINT = W_GS_PRINT.
I_FIELDCAT = I_FIELDCAT.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*&
Form f_get_header
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM F_GET_HEADER.
DATA: L_LINE1 LIKE BHDGD-LINE1,
L_LINE2 LIKE BHDGD-LINE2.
CONSTANTS LC_SPACE VALUE ' '.
DATA: L_F1(7), L_F2(11), L_F3(9), L_F4(6), L_F5(11), L_F6(4), L_F7(8),
L_F8(4),L_F9(10), L_F11(11), L_F12(24), L_F13(4),
L_F14(3).
* take the values of line1 and line2 into two new variables, otherwise
* after coming back to the first screen from the print preview, the
* header shows the condensed lines
L_LINE1 = BHDGD-LINE1.
L_LINE2 = BHDGD-LINE2.
CONDENSE L_LINE1.
CONDENSE L_LINE2.
*split the lines to display the whole lines within the
*stipulated report-width
SPLIT L_LINE1 AT LC_SPACE INTO L_F1 L_F2 L_F3 L_F4 L_F5 L_F6 L_F7 L_F8
L_F9 .
SPLIT L_LINE2 AT LC_SPACE INTO L_F11 L_F12 L_F13 L_F14.
L_F14 = SY-PAGNO.
WRITE:/1 L_F1, 9 L_F2, 40 L_F3, 50 L_F4, 57 L_F5, 88 L_F6, 93 L_F7 ,
103 L_F8 , 108 L_F9 .
WRITE:/1 L_F11, 40 TEXT-012, 78 L_F12, 103 L_F13, 108 L_F14.

ENDFORM.
" f_get_header
*&---------------------------------------------------------------------*
*&
Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'STAT'.
SET TITLEBAR 'TITL'.

ENDMODULE.
" STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM .
WHEN C_EXIT OR C_BACK OR C_CANC.
IF NOT W_CONTAINER IS INITIAL.
CALL METHOD W_CONTAINER->FREE.
ENDIF.
LEAVE TO SCREEN 0.
WHEN C_PGTOP.
WA_GRIDROW-INDEX = 1.
WHEN C_PGUP.
IF WA_GRIDROW-INDEX <= 15.
WA_GRIDROW-INDEX = 1.
ELSE.
WA_GRIDROW-INDEX = WA_GRIDROW-INDEX - 15.
ENDIF.
WHEN C_PGDN.
PERFORM F_GET_NO_ROWS.
W_TEMP_VAL = W_LN - WA_GRIDROW-INDEX.
IF W_TEMP_VAL < 15.
WA_GRIDROW-INDEX = W_LN.
ELSE.
WA_GRIDROW-INDEX = WA_GRIDROW-INDEX + 15.
ENDIF.
WHEN C_PGEND.
PERFORM F_GET_NO_ROWS.
WA_GRIDROW-INDEX = W_LN.
ENDCASE.

ENDMODULE.
" USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*&
Form f_get_no_rows
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM F_GET_NO_ROWS.
DESCRIBE TABLE I_MARA LINES W_LN.
ENDFORM.
" f_get_no_rows
*&---------------------------------------------------------------------*
*&
Module DISPLAY_0100 OUTPUT
*&---------------------------------------------------------------------*
*
text

*----------------------------------------------------------------------*
MODULE DISPLAY_0100 OUTPUT.
IF NOT WA_GRIDROW IS INITIAL
AND NOT WA_GRIDCOL IS INITIAL.
CALL METHOD W_GRID->SET_SCROLL_INFO_VIA_ID
EXPORTING
IS_ROW_INFO = WA_GRIDROW
IS_COL_INFO = WA_GRIDCOL .
CALL METHOD W_GRID->SET_CURRENT_CELL_VIA_ID
EXPORTING
IS_ROW_ID = WA_GRIDROW
IS_COLUMN_ID = WA_GRIDCOL .
ENDIF.
CALL METHOD W_GRID->GET_SCROLL_INFO_VIA_ID
IMPORTING
ES_ROW_INFO = WA_GRIDROW
ES_COL_INFO = WA_GRIDCOL .
CALL METHOD W_GRID->GET_SELECTED_ROWS
IMPORTING
ET_INDEX_ROWS = I_GT_SELROWS[].
* Build the fieldcat according to structure
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'ZSTR'
CHANGING
CT_FIELDCAT
= I_FIELDCAT[].
LOOP AT I_FIELDCAT.
W_INDEX = SY-TABIX.
CASE I_FIELDCAT-FIELDNAME.
WHEN 'MATNR'.
I_FIELDCAT-SCRTEXT_S = 'MATNR'.
I_FIELDCAT-KEY
= ' '.
I_FIELDCAT-COL_POS = '1'.
WHEN 'ERNAM'.
I_FIELDCAT-SCRTEXT_S = 'ERDAT'.
I_FIELDCAT-OUTPUTLEN = '18'.
I_FIELDCAT-COL_POS = '2'.

ENDCASE.
MODIFY I_FIELDCAT INDEX W_INDEX.
ENDLOOP.
READ TABLE I_FIELDCAT INDEX 1 .

IF W_CALL = 1.
PERFORM F_STD_HEADER.
CALL METHOD W_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_VARIANT
= W_VARIANT
I_SAVE
= W_SAVE
CHANGING
IT_OUTTAB
= I_MARA[]
IT_FIELDCATALOG
= I_FIELDCAT[]
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR
=2
OTHERS
= 3.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
EXIT.
ENDIF.
CREATE OBJECT W_EVENT_REC.
SET HANDLER W_EVENT_REC->HANDLE_TOP_OF_PAGE FOR W_GRID.
CREATE OBJECT W_EVENT_REC.
SET HANDLER W_EVENT_REC->HANDLE_DOUBLE_CLICK FOR W_GRID.
W_FLAG = C_RESET.

CALL METHOD CL_GUI_CONTROL=>SET_FOCUS EXPORTING CONTROL = W_GRID.


W_CALL = 0.
ENDIF.

ENDMODULE.
" DISPLAY_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
Form f_std_header
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM F_STD_HEADER.
ENDFORM.
" f_std_header
*&---------------------------------------------------------------------*
*&
Module DYNPRONR_CHECK_500 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE DYNPRONR_CHECK_500 OUTPUT.
* if w_dynpronr is initial.
* w_dynpronr = '0100'.
* endif.
ENDMODULE.
" DYNPRONR_CHECK_500 OUTPUT
*&---------------------------------------------------------------------*
*&
Module create_objects_0100 OUTPUT

*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE create_objects_0100 OUTPUT.
check w_container is initial .
create object w_container
exporting
container_name = 'CC'.
create object w_grid
exporting
i_parent = w_container.
w_flag = c_set.
w_flag = w_flag.
ENDMODULE.
" create_objects_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
Module STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE STATUS_0200 OUTPUT.
SET PF-STATUS 'ST20'.
SET TITLEBAR '200'.
zstr-matnr = wa_mara-matnr.
zstr-ernam = wa_mara-ernam.
ENDMODULE.
" STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_0200 INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0200 INPUT.
move ok_code to w_ok_code.
clear ok_code.
case w_ok_code.
when c_back or c_exit or c_canc.
leave to screen 0.
endcase.
clear w_ok_code.
ENDMODULE.
" USER_COMMAND_0200 INPUT
*-- End of Program
Download a report to excel with format (border, color cell, etc)
Try this program...it may help you to change the font ..etc.
Code:
REPORT ZSIRI NO STANDARD PAGE HEADING.
* this report demonstrates how to send some ABAP data to an
* EXCEL sheet using OLE automation.
INCLUDE OLE2INCL.
* handles for OLE objects
DATA: H_EXCEL TYPE OLE2_OBJECT,
" Excel object
H_MAPL TYPE OLE2_OBJECT,
" list of workbooks
H_MAP TYPE OLE2_OBJECT,
" workbook
H_ZL TYPE OLE2_OBJECT,
" cell
H_F TYPE OLE2_OBJECT.
" font
TABLES: SPFLI.
DATA H TYPE I.
* table of flights
DATA: IT_SPFLI LIKE SPFLI OCCURS 10 WITH HEADER LINE.

*&---------------------------------------------------------------------*
*& Event START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
* read flights
SELECT * FROM SPFLI INTO TABLE IT_SPFLI UP TO 10 ROWS.
* display header
ULINE (61).
WRITE: / SY-VLINE NO-GAP,
(3) 'Flg'(001) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
(4) 'Nr'(002) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
(20) 'Von'(003) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
(20) 'Nach'(004) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
(8) 'Zeit'(005) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP.
ULINE /(61).
* display flights
LOOP AT IT_SPFLI.
WRITE: / SY-VLINE NO-GAP,
IT_SPFLI-CARRID COLOR COL_KEY NO-GAP, SY-VLINE NO-GAP,
IT_SPFLI-CONNID COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
IT_SPFLI-CITYFROM COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
IT_SPFLI-CITYTO COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
IT_SPFLI-DEPTIME COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP.
ENDLOOP.
ULINE /(61).
* tell user what is going on
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
*
PERCENTAGE = 0
TEXT
= TEXT-007
EXCEPTIONS
OTHERS = 1.
* start Excel
CREATE OBJECT H_EXCEL 'EXCEL.APPLICATION'.
* PERFORM ERR_HDL.
SET PROPERTY OF H_EXCEL 'Visible' = 1.
* CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING #1 = 'c:\kis_excel.xls'
.
* PERFORM ERR_HDL.
* tell user what is going on
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
*
PERCENTAGE = 0
TEXT
= TEXT-008
EXCEPTIONS
OTHERS = 1.
* get list of workbooks, initially empty
CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
PERFORM ERR_HDL.
* add a new workbook
CALL METHOD OF H_MAPL 'Add' = H_MAP.
PERFORM ERR_HDL.
* tell user what is going on
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
*
PERCENTAGE = 0

TEXT
= TEXT-009
EXCEPTIONS
OTHERS = 1.
* output column headings to active Excel sheet
PERFORM FILL_CELL USING 1 1 1 'Flug'(001).
PERFORM FILL_CELL USING 1 2 0 'Nr'(002).
PERFORM FILL_CELL USING 1 3 1 'Von'(003).
PERFORM FILL_CELL USING 1 4 1 'Nach'(004).
PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).
LOOP AT IT_SPFLI.
* copy flights to active EXCEL sheet
H = SY-TABIX + 1.
PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
ENDLOOP.
* changes by Kishore - start
* CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
CALL METHOD OF H_EXCEL 'Worksheets' = H_MAPL." EXPORTING #1 = 2.
PERFORM ERR_HDL.
* add a new workbook
CALL METHOD OF H_MAPL 'Add' = H_MAP EXPORTING #1 = 2.
PERFORM ERR_HDL.
* tell user what is going on
SET PROPERTY OF H_MAP 'NAME' = 'COPY'.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
*
PERCENTAGE = 0
TEXT
= TEXT-009
EXCEPTIONS
OTHERS = 1.
* output column headings to active Excel sheet
PERFORM FILL_CELL USING 1 1 1 'Flug'(001).
PERFORM FILL_CELL USING 1 2 0 'Nr'(002).
PERFORM FILL_CELL USING 1 3 1 'Von'(003).
PERFORM FILL_CELL USING 1 4 1 'Nach'(004).
PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).
LOOP AT IT_SPFLI.
* copy flights to active EXCEL sheet
H = SY-TABIX + 1.
PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
ENDLOOP.
* changes by Kishore - end
* disconnect from Excel
*
CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING #1 = 'C:\SKV.XLS'.
FREE OBJECT H_EXCEL.
PERFORM ERR_HDL.
*---------------------------------------------------------------------*
*
FORM FILL_CELL
*
*---------------------------------------------------------------------*
*
sets cell at coordinates i,j to value val boldtype bold
*---------------------------------------------------------------------*
FORM FILL_CELL USING I J BOLD VAL.

CALL METHOD OF H_EXCEL 'Cells' = H_ZL EXPORTING #1 = I #2 = J.


PERFORM ERR_HDL.
SET PROPERTY OF H_ZL 'Value' = VAL .
PERFORM ERR_HDL.
GET PROPERTY OF H_ZL 'Font' = H_F.
PERFORM ERR_HDL.
SET PROPERTY OF H_F 'Bold' = BOLD .
PERFORM ERR_HDL.
ENDFORM.
*&---------------------------------------------------------------------*
*&
Form ERR_HDL
*&---------------------------------------------------------------------*
*
outputs OLE error if any
*
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM ERR_HDL.
IF SY-SUBRC <> 0.
WRITE: / 'Fehler bei OLE-Automation:'(010), SY-SUBRC.
STOP.
ENDIF.
ENDFORM.
" ERR_HDL
Please note that this example maybe slow at filling the excel table
(perhaps four fields per second on a 900 MHz machine - almost 30 seconds
for a short example).
To get the data on properties and methods - there is a bit of smoke and mirrors
going on here; they are EXCEL properties and methods, not sap ones - so you need
to look at excel help to determine how a particular function is structured. then
build the block in sap, as shown in the example.
If you only want to transfer the data to Excel like when you transfer the data from
ALV to Excel simply use the Function Modules:
XXL_SIMPLE_API
If you want more modifications when you transfer it to Excel use:
XXL_FULL_API
Line Color in ALV Example
An example of using linecolor (ALV).
Here you have a good example of coloring rows, columns and specific cells in alvs. It comes in an example
of how to use hashed tables.
For coloured rows and cols check gp_bymat
for coloured specific rows uncheck gp_bymat.
HTH.
Horacio
ps: code:
report zuseofhashedtables.
************************************************************************
** Program: ZUseOfHashedTables
**
************************************************************************
** Author: Horacio Zapettini
**
**
**
** Versions: 4.6b - 4.6c
**

************************************************************************
** Notes:
**
** this program shows how we can use hashed tables to improve **
** the responce time.
**
** It shows,
**
**
1. how to declare hashed tables
**
**
2. a cache-like technique to improve access to master data **
**
3. how to collect data using hashed tables
**
**
4. how to avoid deletions of unwanted data
**
************************************************************************
** Results: the test we run read about 31000 rows from mkpf, 150000 **
**
rows from mseg, 500 rows from makt and 400 from lfa1. **
**
it filled ht_lst with 24500 rows and displayed them in **
**
alv grid format.
**
**
**
**
It took about 65 secodns to perform this task (first time **
**
we run it when all the db buffers are empty.
**
**
**
**
The same program with standard tables needed 140 seconds **
**
to run with the same recordset and with buffers filled in **
**
**
**
A simmilar test over more than a million rows
************************************************************************
** Objetive: show a list that consists of all the material movements **
**
'101' - '901' for a certain range of dates in mkpf-budat. **
** the columns to be displayed are:
**
**
mkpf-budat,
**
**
mkpf-mblnr,
**
**
mseg-lifnr,
**
**
lfa1-name1,
**
**
mkpf-xblnr,
**
**
mseg-zeile
**
**
mseg-charg,
**
**
mseg-matnr,
**
**
makt-maktx,
**
**
mseg-erfmg,
**
**
mseg-erfme.
**
** or show a sumary list by matnr - menge
**
**
**
** You'll have to create a pf-status called vista **
** See form set_pf_status for details
**
************************************************************************
** tables used tables: mkpf,
mseg,
lfa1,
makt.
** global hashed tables used
*
data: begin of wa_mkpf, "header
mblnr like mkpf-mblnr,
mjahr like mkpf-mjahr,
budat like mkpf-budat,
xblnr like mkpf-xblnr,
end of wa_mkpf.
data: ht_mkpf like hashed table of wa_mkpf
with unique key mblnr mjahr
with header line.
data: st_mkpf like standard table of wa_mkpf
with header line.

*
data: begin of wa_mseg, " line items
mblnr like mseg-mblnr,
mjahr like mseg-mjahr,
zeile like mseg-zeile,
bwart like mseg-bwart,
charg like mseg-charg,
matnr like mseg-matnr,
lifnr like mseg-lifnr,
erfmg like mseg-erfmg,
erfme like mseg-erfme,
end of wa_mseg.
data ht_mseg like hashed table of wa_mseg
with unique key mblnr mjahr zeile
with header line.
data st_mseg like standard table of wa_mseg
with header line.
** cache structure for lfa1 records
data: begin of wa_lfa1,
lifnr like lfa1-lifnr,
name1 like lfa1-name1,
end of wa_lfa1.
data ht_lfa1 like hashed table of wa_lfa1
with unique key lifnr
with header line.
** cache structure for material related data
data: begin of wa_material,
matnr like makt-matnr,
maktx like makt-maktx,
end of wa_material.
data: ht_material like hashed table of wa_material
with unique key matnr
with header line.
** result table
data: begin of wa_lst, "
budat like mkpf-budat,
mblnr like mseg-mblnr,
lifnr like mseg-lifnr,
name1 like lfa1-name1,
xblnr like mkpf-xblnr,
zeile like mseg-zeile,
charg like mseg-charg,
matnr like mseg-matnr,
maktx like makt-maktx,
erfmg like mseg-erfmg,
erfme like mseg-erfme,
mjahr like mseg-mjahr,
end of wa_lst.
data: ht_lst like hashed table of wa_lst
with unique key mblnr mjahr zeile
with header line.
data: begin of wa_lst1, " sumary by material
matnr like mseg-matnr,
maktx like makt-maktx,
erfmg like mseg-erfmg,

erfme like mseg-erfme,


color_line(4) TYPE c,
" Line color
color_cell TYPE lvc_t_scol, " Cell color
celltab type LVC_T_STYL,
end of wa_lst1.
data: ht_lst1 like hashed table of wa_lst1
with unique key matnr
with header line.
** structures for alv grid display.
** itabs
type-pools: slis.
data: it_lst
like standard table of wa_lst with header line,
it_fieldcat_lst type slis_t_fieldcat_alv with header line,
it_sort_lst
type slis_t_sortinfo_alv,
it_lst1
like standard table of wa_lst1 with header line,
it_fieldcat_lst1 type slis_t_fieldcat_alv with header line,
it_sort_lst1
type slis_t_sortinfo_alv.
** structures
data: wa_sort
type slis_sortinfo_alv,
ls_layout
type slis_layout_alv.
** color management.
DATA : wa_color TYPE lvc_s_scol.
* Internal table for color management.
DATA : it_color TYPE TABLE
OF lvc_s_scol.
* itab for input enabling.
DATA: lt_celltab TYPE lvc_t_styl. "
** global varialbes
data: g_lines type i.
data: g_repid like sy-repid,
ok_code
like sy-ucomm.
** selection-screen
"text: Dates:
select-options: so_budat for mkpf-budat default sy-datum.
"text: Material numbers.
select-options: so_matnr for mseg-matnr.
selection-screen uline.
selection-screen skip 1.
"Text: show summary by material.
parameters: gp_bymat as checkbox default ''.
parameters: gp_hier as checkbox default 'X'.
start-of-selection.
perform get_data.
perform show_data.
end-of-selection.
*---------------------------------------------------------------------*
*
FORM get_data
*
*---------------------------------------------------------------------*
*
........
*
*---------------------------------------------------------------------*

form get_data.
select mblnr mjahr budat xblnr
into table ht_mkpf
from mkpf
where budat in so_budat. " make use of std index.
** have we retrieved data from mkpf?
describe table ht_mkpf lines g_lines.
if g_lines > 0.
** if true then retrieve all related records from mseg.
** Doing this way we make sure that the access is by primary key
** of mseg.
** The reason is that is faster to filter them in memory
** than to allow the db server to do it.
select mblnr mjahr zeile bwart charg
matnr lifnr erfmg erfme
into table ht_mseg
from mseg
for all entries in ht_mkpf
where mblnr = ht_mkpf-mblnr
and mjahr = ht_mkpf-mjahr.
endif.
** fill t_lst or t_lst1 according to user's choice.
if gp_bymat = ' '.
perform fill_ht_lst.
else.
perform fill_ht_lst1.
endif.
endform.
form fill_ht_lst.
refresh ht_lst.
** Example: how to discard unwanted data in an efficient way.
loop at ht_mseg.
* filter unwanted data
check ht_mseg-bwart = '101' or ht_mseg-bwart = '901'.
check ht_mseg-matnr in so_matnr.
* read header line.
read table ht_mkpf with table key mblnr = ht_mseg-mblnr
mjahr = ht_mseg-mjahr.
clear ht_lst.
* * note : this may be faster if you specify field by field.
move-corresponding ht_mkpf to ht_lst.
move-corresponding ht_mseg to ht_lst.
perform read_lfa1 using ht_mseg-lifnr changing ht_lst-name1.
perform read_material using ht_mseg-matnr changing ht_lst-maktx.
insert table ht_lst.
endloop.
endform.
form fill_ht_lst1.
data: colorear.
refresh ht_lst1.
** Example: how to discard unwanted data in an efficient way.
**
hot to simulate a collect in a faster way
loop at ht_mseg.
* filter unwanted data
check ht_mseg-bwart = '101' or ht_mseg-bwart = '901'.
check ht_mseg-matnr in so_matnr.
* * note : this may be faster if you specify field by field.

read table ht_lst1 with table key matnr = ht_mseg-matnr


transporting erfmg.
if sy-subrc <> 0. " if matnr doesn't exist in sumary table
" insert a new record
clear ht_lst1.
ht_lst1-matnr = ht_mseg-matnr.
perform read_material using ht_mseg-matnr changing ht_lst1-maktx.
ht_lst1-erfmg = ht_mseg-erfmg.
ht_lst1-erfme = ht_mseg-erfme.
if colorear = ''.
colorear = 'X'.
refresh it_color.
ht_lst1-color_cell[] = it_color[].
MOVE 'C410' TO ht_lst1-color_line.
else.
colorear = ' '.
refresh it_color. clear it_color.
MOVE 'MATNR' TO wa_color-fname.
MOVE '6'
TO wa_color-color-col.
MOVE '1'
TO wa_color-color-int.
MOVE '1'
TO wa_color-color-inv.
APPEND wa_color TO it_color.
MOVE 'MAKTX' TO wa_color-fname.
MOVE '3'
TO wa_color-color-col.
MOVE '1'
TO wa_color-color-int.
MOVE '1'
TO wa_color-color-inv.
APPEND wa_color TO it_color.
MOVE 'ERFMG' TO wa_color-fname.
MOVE '5'
TO wa_color-color-col.
MOVE '1'
TO wa_color-color-int.
MOVE '1'
TO wa_color-color-inv.
APPEND wa_color TO it_color.
ht_lst1-color_cell[] = it_color[].
clear ht_lst1-color_line.
endif.
insert table ht_lst1.
else." a record was found.
" collect erfmg. To do so, fill in the unique key and add
" the numeric fields.
ht_lst1-matnr = ht_mseg-matnr.
add ht_mseg-erfmg to ht_lst1-erfmg.
modify table ht_lst1 transporting erfmg.
endif.
endloop.
endform.
** implementation of cache for lfa1.
form read_lfa1 using p_lifnr changing p_name1.
read table ht_lfa1 with table key lifnr = p_lifnr
transporting name1.
if sy-subrc <> 0.
clear ht_lfa1.
ht_lfa1-lifnr = p_lifnr.
select single name1
into ht_lfa1-name1
from lfa1
where lifnr = p_lifnr.

if sy-subrc <> 0. ht_lfa1-name1 = 'n/a in lfa1'. endif.


insert table ht_lfa1.
endif.
p_name1 = ht_lfa1-name1.
endform.
** implementation of cache for material data
form read_material using p_matnr changing p_maktx.
read table ht_material with table key matnr = p_matnr
transporting maktx.
if sy-subrc <> 0.
ht_material-matnr = p_matnr.
select single maktx into ht_material-maktx
from makt
where spras = sy-langu
and matnr = p_matnr.
if sy-subrc <> 0. ht_material-maktx = 'n/a in makt'. endif.
insert table ht_material.
endif.
p_maktx = ht_material-maktx.
endform.
form show_data.
if gp_hier = 'X'. "no anda.
* perform show_hierarchicalALV.
else.
if gp_bymat = ' '.
perform show_ht_lst.
else.
perform show_ht_lst1.
endif.
endif.
endform.
form show_hierarchicalALV.
st_mkpf[] = ht_mkpf[].
st_mseg[] = ht_mseg[].
call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
* exporting
* I_INTERFACE_CHECK
=''
* I_CALLBACK_PROGRAM
=
* I_CALLBACK_PF_STATUS_SET
=''
* I_CALLBACK_USER_COMMAND
=''
* IS_LAYOUT
=
* IT_FIELDCAT
=
* IT_EXCLUDING
=
* IT_SPECIAL_GROUPS
=
* IT_SORT
=
* IT_FILTER
=
* IS_SEL_HIDE
=
* I_SCREEN_START_COLUMN
=0
* I_SCREEN_START_LINE
=0
* I_SCREEN_END_COLUMN
=0
* I_SCREEN_END_LINE
=0
* I_DEFAULT
= 'X'
* I_SAVE
=''
* IS_VARIANT
=
* IT_EVENTS
=
* IT_EVENT_EXIT
=
* i_tabname_header
=
* i_tabname_item
=
* I_STRUCTURE_NAME_HEADER
=
* I_STRUCTURE_NAME_ITEM
=
* is_keyinfo
=

* IS_PRINT
=
* IS_REPREP_ID
=
* I_BUFFER_ACTIVE
=
* I_BYPASSING_BUFFER
=
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER
=
* ES_EXIT_CAUSED_BY_USER
=
tables
t_outtab_header
= st_mkpf
t_outtab_item
= st_mseg
* EXCEPTIONS
* PROGRAM_ERROR
=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.
endform.
form show_ht_lst.
"needed because the FM can't use a hashed table.
it_lst[] = ht_lst[].
perform fill_layout using 'full display'
changing ls_layout.
perform fill_columns_lst.
* perform sort_lst.
g_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program
= g_repid
i_callback_pf_status_set = 'SET_PF_STATUS'
is_layout
= ls_layout
it_fieldcat
= it_fieldcat_lst[]
*
it_sort
= it_sort_lst
tables
t_outtab
= it_lst
exceptions
program_error
=1
others
= 2.
endform.
form show_ht_lst1.
"needed because the FM can't use a hashed table.
it_lst1[] = ht_lst1[].
perform fill_layout using 'Sumary by matnr'
changing ls_layout.
perform fill_columns_lst1.
* perform sort_lst.
g_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program
= g_repid
i_callback_pf_status_set = 'SET_PF_STATUS'
is_layout
= ls_layout
it_fieldcat
= it_fieldcat_lst1[]
*
it_sort
= it_sort_lst
tables

t_outtab
exceptions
program_error
others

= it_lst1
=1
= 2.

endform.
form fill_layout using p_window_titlebar
changing cs_layo type slis_layout_alv.
clear cs_layo.
cs_layo-window_titlebar
= p_window_titlebar.
cs_layo-edit
= 'X'.
cs_layo-edit_mode
= space.
MOVE 'COLOR_LINE' TO cs_layo-info_fieldname.
* Field that identify cell color in inetrnal table
MOVE 'COLOR_CELL' TO cs_layo-coltab_fieldname.
* move 'CELLTAB' TO cs_layo-stylefname.
endform.

" armar_layout_stock

form set_pf_status using rt_extab type slis_t_extab.


** create a new status
** and then select extras -> adjust template -> listviewer
set pf-status 'VISTA'.
endform.
"set_pf_status
define add_lst.
clear it_fieldcat_lst.
it_fieldcat_lst-fieldname = &1.
it_fieldcat_lst-outputlen = &2.
it_fieldcat_lst-ddictxt
= 'L'.
it_fieldcat_lst-seltext_l
= &1.
it_fieldcat_lst-seltext_m
= &1.
it_fieldcat_lst-seltext_m
= &1.
if &1 = 'MATNR'.
it_fieldcat_lst-emphasize = 'C111'.
endif.
append it_fieldcat_lst.
end-of-definition.
define add_lst1.
clear it_fieldcat_lst.
it_fieldcat_lst1-fieldname = &1.
it_fieldcat_lst1-outputlen = &2.
it_fieldcat_lst1-ddictxt
= 'L'.
it_fieldcat_lst1-seltext_l
= &1.
it_fieldcat_lst1-seltext_m
= &1.
it_fieldcat_lst1-seltext_m
= &1.
append it_fieldcat_lst1.
end-of-definition.
form fill_columns_lst.
* set columns for output.
refresh it_fieldcat_lst.
*
add_lst 'BUDAT' 10.
add_lst 'MBLNR' 10.
add_lst 'LIFNR' 10.
add_lst 'NAME1' 35.
add_lst 'XBLNR' 15.
add_lst 'ZEILE' 5.

add_lst 'CHARG' 10.


add_lst 'MATNR' 18.
add_lst 'MAKTX' 30.
add_lst 'ERFMG' 17.
add_lst 'ERFME' 5.
add_lst 'MJAHR' 4.
endform.
form fill_columns_lst1.
* set columns for output.
refresh it_fieldcat_lst1.
add_lst1 'MATNR' 18.
add_lst1 'MAKTX' 30.
add_lst1 'ERFMG' 17.
add_lst1 'ERFME' 5..
endform.
Horacio Zapettini
-------------------------------Program to Calculate FI Opening Balance
How to find the Opening balance for a given period in FI Module for a Particular GL A/c.
I was calculated opening balance, code is below maybe it will be helpful.
*find period.
CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
EXPORTING
i_date
= s_budat-low
i_periv
= i_tab-periv
"'K4'
IMPORTING
e_buper
= v_donem
e_gjahr
= v_gjahr
EXCEPTIONS
input_false = 1
t009_notfound = 2
t009b_notfound = 3
OTHERS
= 4.
*calc opening balance hesab
SELECT * FROM knc1 WHERE kunnr = i_tab-kunnr
AND bukrs = i_tab-bukrs " s_bukrs
AND gjahr EQ v_gjahr.
v_dnm = v_donem.
* opening balance first calc > old year ,
WHILE v_dnm > 1.
v_dnm = v_dnm - 1.
CONCATENATE 'knc1-um' v_dnm 's' INTO v_field_name_borc.
CONCATENATE 'knc1-um' v_dnm 'h' INTO v_field_name_alacak.
ASSIGN (v_field_name_borc) TO <fs1> .
ASSIGN (v_field_name_alacak) TO <fs2> .
i_tab-dmbtr_s = i_tab-dmbtr_s + ( <fs1> ). " borc
i_tab-dmbtr_h = i_tab-dmbtr_h + ( <fs2> ). " borc
ENDWHILE.
*opening balance last calc> old
* add days which is from selected date-low month
IF v_donem > 1.
v_dnm = v_donem - 1.

ELSE.
v_dnm = v_donem.
ENDIF.
SELECT SINGLE * FROM t009b WHERE periv = i_tab-periv
AND bdatj = s_budat-low+0(4)
AND poper = v_dnm.

"'K4'

t009b-butag = t009b-butag + 1.
IF s_budat-low+6(2) NE t009b-butag.
v_date_high = s_budat-low - 1.
IF v_donem = 1.
v_date_low = s_budat-low.
v_date_low+4(4) = '0101'.
ELSE.
CONCATENATE t009b-bdatj t009b-bumon t009b-butag INTO
v_date_low.
ENDIF.
SELECT * FROM bsad WHERE bukrs EQ i_tab-bukrs "IN s_bukrs
AND kunnr = i_tab-kunnr
AND budat BETWEEN v_date_low AND
v_date_high
AND umskz = space
AND blart IN s_blart.
IF bsad-shkzg = 'S'.
i_tab-dmbtr_s = i_tab-dmbtr_s + ( bsad-dmbtr ).
ELSEIF bsad-shkzg = 'H'.
i_tab-dmbtr_h = i_tab-dmbtr_h + ( bsad-dmbtr ).
ENDIF.
ENDSELECT.
SELECT * FROM bsid WHERE bukrs EQ i_tab-bukrs "IN s_bukrs
AND kunnr = i_tab-kunnr
AND budat BETWEEN v_date_low AND
v_date_high
AND umskz = space
AND blart IN s_blart.
*
AND gsber IN gsber.
IF bsid-shkzg = 'S'.
i_tab-dmbtr_s = i_tab-dmbtr_s + ( bsid-dmbtr ).
ELSEIF bsid-shkzg = 'H'.
i_tab-dmbtr_h = i_tab-dmbtr_h + ( bsid-dmbtr ).
ENDIF.
ENDSELECT.
ENDIF.
"opening balance ( irket bazl )z1 degeri
i_tab-z1 = i_tab-z1 + ( knc1-umsav + i_tab-dmbtr_s - i_tab-dmbtr_h ).
* for israel
i_tab-dmbtril_s = i_tab-dmbtr_s .
i_tab-dmbtril_h = i_tab-dmbtr_h .
ENDSELECT.

How to make ALV header like this?


Header long text 1 Header long text 2 Header long text 3
Col_1 Col_2 Col_3 Col_4 Col_5 Col_6 Col_7 Col_8 Col_9
----------------------- Cell conents ----------------------------------------------------- Cell conents ----------------------------------------------------- Cell conents -------------------------------

----------------------- Cell conents ----------------------------------------------------- Cell conents ------------------------------You could try:


data: gt_list_top_of_page type slis_t_listheader. " Top of page text.
Initialization.
perform comment_build using gt_list_top_of_page[].
form top_of_page.
* Note to self: the gif must be loaded into transaction OAOR with
* classname 'PICTURES' AND TYPE 'OT' to work with ALV GRID Functions.
* I Loaded NOVALOGO2 into system.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
* I_LOGO = 'NOVALOGO2'
* i_logo = 'ENJOYSAP_LOGO'
it_list_commentary = gt_list_top_of_page.
endform. " TOP_OF_PAGE
form comment_build using e04_lt_top_of_page type slis_t_listheader.
data: ls_line type slis_listheader.
clear ls_line.
ls_line-typ = 'A'.
ls_line-info = 'Special'(001).
fgrant = xgrant.
concatenate ls_line-info fgrant
'Stock Option Report to the board'(002)
into ls_line-info separated by space.
condense ls_line-info.
append ls_line to e04_lt_top_of_page.
endform. " COMMENT_BUILD
How to implement a footer in alv grid programming? What is the procedure and the code regarding
to create a footer?
Use following syntex for footer print in alv:
* For End of Page
form END_OF_PAGE.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10)

type c.

write: sy-uline(50).
skip.
write:/40 'Page:', sy-pagno .
endform.

* For End of Report


form END_OF_LIST.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
skip.
write:/40 'Page:', sy-pagno .
endform.
Sample ALV: Heading in ALV
With Compliments by: Ulhas Sonawane
report zus_alv_demo_grid .
tables: ekko.
type-pools: slis.
types: begin of t_ekko,
ebeln type ekpo-ebeln,
ebelp type ekpo-ebelp,
statu type ekpo-statu,
aedat type ekpo-aedat,
matnr type ekpo-matnr,
menge type ekpo-menge,
meins type ekpo-meins,
netpr type ekpo-netpr,
peinh type ekpo-peinh,
line_color(4) type c, "Used to store row color
end of t_ekko.
data: it_ekko type standard table of t_ekko initial size 0,
wa_ekko type t_ekko.
*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
gd_tab_group type slis_t_sp_group_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid.
* Data declaration for EVENT and PRINT PARAMETER.
data: gt_events type slis_t_event,
gd_prntparams type slis_print_alv.
* data declaration for sorting.
data : it_sortcat type slis_sortinfo_alv occurs 1,
wa_sort like line of it_sortcat.
data : i_list_comments type slis_t_listheader.
start-of-selection.
perform data_retrieval.
* perform user_command.
perform build_fieldcatalog.
perform build_layout.
perform build_events.

perform build_print_params.
perform build_sortcat.
perform display_alv_report.
end-of-selection.
*TOP-OF-PAGE.
* PERFORM top-of-page.
end-of-page.
*&---------------------------------------------------------*&
Form build_fieldcatalog
*&---------------------------------------------------------*
text
*----------------------------------------------------------* --> p1
text
* <-- p2
text
*----------------------------------------------------------form build_fieldcatalog.
fieldcatalog-fieldname = 'EBELN'.
fieldcatalog-seltext_m = 'Purchase Order'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'EBELP'.
fieldcatalog-seltext_m = 'PO Item'.
fieldcatalog-col_pos = 1.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'STATU'.
fieldcatalog-seltext_m = 'Status'.
fieldcatalog-col_pos = 2.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'AEDAT'.
fieldcatalog-seltext_m = 'Item change date'.
fieldcatalog-col_pos = 3.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Material Number'.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MENGE'.
fieldcatalog-seltext_m = 'PO quantity'.
fieldcatalog-col_pos = 5.
fieldcatalog-do_sum = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MEINS'.

fieldcatalog-seltext_m = 'Order Unit'.


fieldcatalog-col_pos = 6.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'NETPR'.
fieldcatalog-seltext_m = 'Net Price'.
fieldcatalog-col_pos = 7.
fieldcatalog-outputlen = 15.
fieldcatalog-datatype = 'CURR'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PEINH'.
fieldcatalog-seltext_m = 'Price Unit'.
fieldcatalog-col_pos = 8.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
endform.
" build_fieldcatalog
*&---------------------------------------------------------*&
Form build_layout
*&---------------------------------------------------------*
text
*----------------------------------------------------------* --> p1
text
* <-- p2
text
*----------------------------------------------------------form build_layout.
gd_layout-no_input
= 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text
= 'Totals'(201).
* Set layout field for row attributes(i.e. color)
gd_layout-info_fieldname =
'LINE_COLOR'.
* gd_layout-totals_only
= 'X'.
* gd_layout-f2code
= 'DISP'. "Sets fcode for
*when double
*
"click(press f2)*
* gd_layout-group_change_edit = 'X'.
* gd_layout-header_text
= 'helllllo'.
endform.
" build_layout
*&---------------------------------------------------------*&
Form data_retrieval
*&---------------------------------------------------------*
text
*----------------------------------------------------------* --> p1
text
* <-- p2
text
*----------------------------------------------------------form data_retrieval.
data: ld_color(1) type c.
select ebeln ebelp statu aedat matnr menge meins netpr
peinh from ekpo into table it_ekko.
*Populate field with color attributes
loop at it_ekko into wa_ekko.
* Populate color variable with colour properties
* Char 1 = C (This is a color property)
* Char 2 = 3 (Color codes: 1 - 7)
* Char 3 = Intensified on/off ( 1 or 0 )

* Char 4 = Inverse display on/off ( 1 or 0 )


*
i.e. wa_ekko-line_color = 'C410'
ld_color = ld_color + 1.
* Only 7 colours so need to reset color value
if ld_color = 8.
ld_color = 1.
endif.
concatenate 'C' ld_color '10' into wa_ekko-line_color.
* wa_ekko-line_color = 'C410'.
modify it_ekko from wa_ekko.
endloop.
endform.
" data_retrieval
*&---------------------------------------------------------*&
Form display_alv_report
*&---------------------------------------------------------*
text
*----------------------------------------------------------* --> p1
text
* <-- p2
text
*----------------------------------------------------------form display_alv_report.
gd_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program
= gd_repid
is_layout
= gd_layout
i_callback_top_of_page = 'TOP-OF-PAGE'
i_callback_user_command = 'USER_COMMAND'
i_callback_pf_status_set = 'SET_PF_STATUS'
it_event
= gt_events
is_print
= gd_prntparams
it_fieldcat
= fieldcatalog[]
it_sort
= it_sortcat
i_save
= 'X'
tables
t_outtab
= it_ekko
exceptions
program_error
=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.
endform.
" DISPLAY_ALV_REPORT
*&---------------------------------------------------------*&
Form user_command
*&---------------------------------------------------------*
text
*----------------------------------------------------------* --> p1
text
* <-- p2
text
*----------------------------------------------------------*&---------------------------------------------------------*&
Form top-of-page
*&---------------------------------------------------------*
text
*----------------------------------------------------------* --> p1
text
* <-- p2
text
*----------------------------------------------------------form top-of-page.

*ALV Header declarations


data: t_header type slis_t_listheader,
wa_header type slis_listheader,
t_line like wa_header-info,
ld_lines type i,
ld_linesc(10) type c.
* Title
wa_header-typ = 'H'.
wa_header-info = 'EKKO Table Report'.
append wa_header to t_header.
clear wa_header.
* Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
concatenate sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) into wa_header-info."todays date
append wa_header to t_header.
clear: wa_header.
* Total No. of Records Selected
describe table it_ekko lines ld_lines.
ld_linesc = ld_lines.
concatenate 'Total No. of Records Selected: ' ld_linesc
into t_line separated by space.
wa_header-typ = 'A'.
wa_header-info = t_line.
append wa_header to t_header.
clear: wa_header, t_line.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = t_header
i_logo
= 'GANESH_LOGO'.

endform.

" top-of-page

*---------------------------------------------------------------------*
*
FORM user_command
*
*---------------------------------------------------------------------*
*
........
*
*---------------------------------------------------------------------*
* --> R_UCOMM
*
* --> RS_SELFIELD
*
*---------------------------------------------------------------------*
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
case r_ucomm.
when '&IC1'.
if rs_selfield-fieldname = 'EBELN'.
read table it_ekko into wa_ekko index rs_selfield-tabindex.
set parameter id 'BES' field wa_ekko-ebeln.
call transaction 'ME23N' and skip first screen.
endif.
when 'ULHAS'.

if rs_selfield-fieldname = 'EBELN'.
read table it_ekko into wa_ekko index rs_selfield-tabindex.
set parameter id 'BES' field wa_ekko-ebeln.
call transaction 'ME23N' and skip first screen.
endif.
endcase.
endform.
*---------------------------------------------------------------------*
*
FORM set_pf_status
*
*---------------------------------------------------------------------*
*
........
*
*---------------------------------------------------------------------*
* --> RT_EXTAB
*
*---------------------------------------------------------------------*
form set_pf_status using rt_extab type slis_t_extab.
set pf-status 'ZNEWSTATUS'.
endform.
*&---------------------------------------------------------------------*
*&
Form build_events
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form build_events.
data: ls_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type
=0
importing
et_events
= gt_events[]
* EXCEPTIONS
* LIST_TYPE_WRONG
=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.
read table gt_events with key name = slis_ev_end_of_page
into ls_event.
if sy-subrc = 0.
move 'END_OF_PAGE' to ls_event-form.
append ls_event to gt_events.
endif.
read table gt_events with key name = slis_ev_end_of_list
into ls_event.
if sy-subrc = 0.
move 'END_OF_LIST' to ls_event-form.
append ls_event to gt_events.
endif.
endform.
" build_events
*&---------------------------------------------------------------------*
*&
Form build_print_params
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*

* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form build_print_params.
gd_prntparams-reserve_lines = '3'. "Lines reserved for footer
gd_prntparams-no_coverpage = 'X'.
endform.
" build_print_params
*---------------------------------------------------------------------*
*
FORM END_OF_PAGE
*---------------------------------------------------------------------*
*
........
*
*---------------------------------------------------------------------*
form end_of_page.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
write: sy-uline(50).
skip. write:/40 'Page:', sy-pagno .
endform.

*---------------------------------------------------------------------*
*
FORM END_OF_LIST
*
*---------------------------------------------------------------------*
*
........
*
*---------------------------------------------------------------------*
form end_of_list.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
skip. write:/40 'Page:', sy-pagno .
endform.
*&---------------------------------------------------------------------*
*&
Form build_sortcat
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form build_sortcat.
wa_sort-spos
= 1.
wa_sort-fieldname = 'EBELN'.
append wa_sort to it_sortcat.
wa_sort-spos
= 2.
wa_sort-fieldname = 'EBELP'.
append wa_sort to it_sortcat.
endform.
" build_sortcat
Test ALV Display With Header & Footer
*Program to Test ALV Display With Header & Footer.
*&---------------------------------------------------------------------*
*& Report ZRJR02
*
*&---------------------------------------------------------------------*
REPORT ZRJR02
.
*Table declaration.
TABLES:ZEMP_MST,ZDEPT_MST,ZDESG_MST,ZSL_TXN.
*Varriable declaration.
TYPE-POOLS SLIS.

DATA : POS TYPE I.


DATA REPID LIKE SY-REPID.
DATA : F1 TYPE SLIS_T_FIELDCAT_ALV,
F2 TYPE SLIS_FIELDCAT_ALV,
L_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA L_POS TYPE I VALUE 1.
"position of the column
DATA GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
*DATA GT_SORT TYPE SLIS_T_SORTINFO_ALV.
data: GT_EVENTS TYPE SLIS_T_EVENT,
FS_EVENTCAT LIKE LINE OF GT_EVENTs.
*Internal table declaration.
*DATA BEGIN OF IT_SORT OCCURS 5.
*
INCLUDE TYPE SLIS_SORTINFO_ALV.
*DATA END OF IT_SORT.
DATA:BEGIN OF ITAB OCCURS 0,
ZEMPNO LIKE ZEMP_MST-ZEMPNO,
ZEMPNAME LIKE ZEMP_MST-ZEMPNAME,
ZDEPTCD LIKE ZEMP_MST-ZDEPTCD,
ZDEPTNAME LIKE ZDEPT_MST-ZDEPTNAME,
ZDESGCD LIKE ZEMP_MST-ZDESGCD,
ZDESGNAME LIKE ZDESG_MST-ZDESGNAME,
END OF ITAB.
REFRESH ITAB.CLEAR ITAB.
START-OF-SELECTION.
SELECT A~ZEMPNO A~ZEMPNAME A~ZDEPTCD B~ZDEPTNAME A~ZDESGCD C~ZDESGNAME
FROM ZEMP_MST AS A
INNER JOIN ZDEPT_MST AS B
ON A~ZDEPTCD EQ B~ZDEPTCD
INNER JOIN ZDESG_MST AS C
ON A~ZDESGCD EQ C~ZDESGCD
INTO CORRESPONDING FIELDS OF TABLE ITAB.
IF SY-SUBRC <> 0.
MESSAGE E899(M3) WITH 'No records'.
ENDIF.
perform f_build_eventcat.
PERFORM LAYOUT.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&
Form LAYOUT
*&---------------------------------------------------------------------*
FORM LAYOUT .
PERFORM FCAT USING 'ZEMPNO' 'ITAB' '' 'Emp.No.' 'ZEMPNO' 'ZEMP_MST' ''.
PERFORM FCAT USING 'ZEMPNAME' 'ITAB' '' 'Emp. Name' 'ZEMPNAME' 'ZEMP_MST' ''.
PERFORM FCAT USING 'ZDEPTCD' 'ITAB' '' 'Dept.Code' 'ZDEPTCD' 'ZEMP_MST' ''.
PERFORM FCAT USING 'ZDEPTNAME' 'ITAB' '' 'Dept.Name' 'ZDEPTNAME' 'ZDEPT_MST' ''.
PERFORM FCAT USING 'ZDESGCD' 'ITAB' '' 'Desg.Code' 'ZDESGCD' 'ZEMP_MST' ''.
PERFORM FCAT USING 'ZDESGNAME' 'ITAB' '' 'Desg.Name' 'ZDESGNAME' 'ZDESG_MST' ''.
* PERFORM LSORT USING 'ZEMPNO' 'IDATA' ''.
* PERFORM LSORT USING 'ZEMPNAME' 'IDATA' ''.
* MOVE IT_SORT[] TO GT_SORT[].

REPID = SY-REPID.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM
= REPID
IT_FIELDCAT
= F1
*
IT_SORT
= GT_SORT
I_SAVE
= 'X'
IT_EVENTS
= GT_EVENTS[]
TABLES
T_OUTTAB
= ITAB.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM.
" LAYOUT
*&---------------------------------------------------------------------*
*&
Form FCAT
*&---------------------------------------------------------------------*
FORM FCAT USING P_FIELD P_TABLE P_SUM P_TEXT P_RFIELD P_RTABLE P_DISP.
ADD 1 TO POS.
F2-COL_POS
= POS.
F2-FIELDNAME = P_FIELD.
F2-TABNAME
= P_TABLE.
F2-SELTEXT_L = P_TEXT.
F2-REF_FIELDNAME = P_RFIELD.
F2-REF_TABNAME = P_RTABLE.
F2-DO_SUM
= P_SUM.
F2-NO_OUT
= P_DISP.
APPEND F2 TO F1.
CLEAR F2.
ENDFORM.
" FCAT
*&---------------------------------------------------------------------*
*&
Form LSORT
*&---------------------------------------------------------------------*
*FORM LSORT USING P_FIELD P_TABLE P_UP.
* ADD 1 TO L_POS.
* IT_SORT-SPOS
= L_POS.
* IT_SORT-FIELDNAME = P_FIELD.
* IT_SORT-TABNAME = P_TABLE.
* IT_SORT-UP
= P_UP.
* APPEND IT_SORT.
*ENDFORM.
" LSORT
*------------FORM F_BUILD_EVENTCAT .
CLEAR: GT_EVENTS. REFRESH: GT_EVENTS.
CLEAR: FS_EVENTCAT.
FS_EVENTCAT-NAME = 'TOP_OF_PAGE'.
FS_EVENTCAT-FORM = 'F_REPORT_HEADER_ALV'.
APPEND FS_EVENTCAT TO GT_EVENTS.
CLEAR: FS_EVENTCAT.
FS_EVENTCAT-NAME = 'END_OF_LIST'.
FS_EVENTCAT-FORM = 'F_WRITE_SUMMARY'.
APPEND FS_EVENTCAT TO GT_EVENTS.
ENDFORM.

" F_BUILD_EVENTCAT

FORM F_REPORT_HEADER_ALV.
CALL FUNCTION 'Z_YHEAD_PRINT'
EXPORTING
TITLE1
= 'XYZ Limited'
TITLE2
= 'Employee Master'
TITLE3
= 'Created on '
COLOR
= 'X'
.
ENDFORM.
*&---------------------------------------------------------------------*
*&
Form F_WRITE_SUMMARY
*&---------------------------------------------------------------------*
*
Write summary before exit
*----------------------------------------------------------------------*
FORM F_WRITE_SUMMARY .
write:/ 'Welcome to XYZ Limited'.
write:/ 'This is a test program to display Report in ALV Format'.
Use Simple ALV Functions to Make Reporting Easy
*&---------------------------------------------------------------------*
*& Report ZBC_ALV_EXAMPLE
*
*&
*
*&---------------------------------------------------------------------*
* This program explains how we can use simple ALV functions to make *
* reporting easy and looks pretty
************************************************************************
* Programmer
: Venkat Reddy
ETA
*
* Date
: 10/02/04
*
************************************************************************
* Maintenance Log
*
*----------------------------------------------------------------------*
* Changed By
Date
Transport# Description
*
*------------ ---------------------------------------------------------*
* Venkat Reddy 10/02/04 EGD913575 Changed program to avoid *
*----------------------------------------------------------------------*
REPORT ZBC_ALV_EXAMPLE.
************************************************************************
*
D-A-T-A D-E-C-L-A-R-A-T-I-O-N-S
*
************************************************************************
tables: sflight.
**-- TYPE-POOLS Definition
**Includes the types and constants of a type group. Since the types and
*constants specified in a type group have global validity, you cannot
*use the statement within a FORM or FUNCTION.
type-pools: slis.
PARAMETERS: P_VARI LIKE DISVARIANT-VARIANT.
**-- ALV variables
*****- Field Catalog structure
data: ls_fieldcat type slis_fieldcat_alv,

"Field Catalog list

**--- Field Catalog table


gt_fieldcat type slis_t_fieldcat_alv, "Field Catalog
**--- Layout ( How you would like to see the output )
gs_layout
type slis_layout_alv,
"List Layout

**-- Report name


g_repid
like sy-repid,
g_save(1)
type c,
g_exit(1)
type c,
g_variant
like disvariant,
gx_variant
like disvariant.
**-- Flight Info Internal table
data: lt_sflight like sflight occurs 0 with header line.
************************************************************************
*
C-O-N-S-T-A-N-T-S
*
************************************************************************
************************************************************************
*
S-E-L-E-C-T-I-O-N S-C-R-E-E-N
*
************************************************************************
selection-screen begin of block a with frame title text-100.
select-options: s_carrid for sflight-carrid,
s_connid for sflight-connid,
s_fldate for sflight-fldate default sy-datum.
selection-screen end of block a .
************************************************************************
*
I-N-I-T-I-A-L-I-Z-A-T-I-O-N
*
************************************************************************
initialization.
g_repid = sy-repid.
**-- Fill ALV field catalog
perform initialize_fieldcat using gt_fieldcat[].
***-- Build Events
* perform build_eventtab using gt_events[].
*
**-- Read the default variant
perform initialize_variant.
************************************************************************
*
A-T S-E-L-E-C-T-I-O-N S-C-R-E-E-N
*
************************************************************************
at selection-screen on value-request for p_vari.
**-- Display all existing variants
call function 'REUSE_ALV_VARIANT_F4'
exporting
is_variant = g_variant
i_save = g_save
importing
e_exit = g_exit
es_variant = gx_variant
exceptions
not_found = 2.
if sy-subrc = 2.
message id sy-msgid type 'S'
number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
else.
if g_exit = space.
p_vari = gx_variant-variant.

endif.
endif.
************************************************************************
*
S-T-A-R-T O-F S-E-L-E-C-T-I-O-N
*
************************************************************************
start-of-selection.
**-- Read Flight information.
perform read_flight_info.
**-- Fill ALV field catalog and display report.
if not lt_sflight[] is initial.
perform dislay_alv_report.
endif.
*======================================================================*
*
FORMS / SUB ROUTINES
*
*======================================================================
*&---------------------------------------------------------------------*
*&
Form initialize_fieldcat
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_GT_FIELDCAT[] text
*----------------------------------------------------------------------*
form initialize_fieldcat using l_fieldcat type slis_t_fieldcat_alv.
clear ls_fieldcat.
* Air line
ls_fieldcat-fieldname = 'CARRID'.
ls_fieldcat-key
= 'X'.
ls_fieldcat-col_pos = 1.
ls_fieldcat-seltext_s = 'Airline'.
ls_fieldcat-seltext_l = 'Airline'.
append ls_fieldcat to l_fieldcat.
clear ls_fieldcat.
* Flight Number
ls_fieldcat-fieldname = 'CONNID'.
ls_fieldcat-key
= 'X'.
ls_fieldcat-col_pos = 2.
ls_fieldcat-seltext_s = 'Flight Number'.
ls_fieldcat-seltext_l = 'Flight Number'.
append ls_fieldcat to l_fieldcat.
clear ls_fieldcat.
* Flight date
ls_fieldcat-fieldname = 'FLDATE'.
ls_fieldcat-key
= 'X'.
ls_fieldcat-col_pos = 3.
ls_fieldcat-seltext_s = 'Flight date'.
ls_fieldcat-seltext_l = 'Flight date'.
append ls_fieldcat to l_fieldcat.
clear ls_fieldcat.
* Airfare
ls_fieldcat-fieldname = 'PRICE'.
ls_fieldcat-col_pos = 4.

ls_fieldcat-do_sum
= 'X'.
ls_fieldcat-seltext_s = 'Airfare'.
ls_fieldcat-seltext_l = 'Airfare'.
append ls_fieldcat to l_fieldcat.
clear ls_fieldcat.
* Local Currency
ls_fieldcat-fieldname = 'CURRENCY'.
ls_fieldcat-col_pos = 5.
ls_fieldcat-seltext_s = 'Local Currency'.
ls_fieldcat-seltext_l = 'Local Currency'.
append ls_fieldcat to l_fieldcat.
clear ls_fieldcat.
* Plane Type
ls_fieldcat-fieldname = 'PLANETYPE'.
ls_fieldcat-col_pos = 6.
ls_fieldcat-seltext_s = 'Plane type'.
ls_fieldcat-seltext_l = 'Plane type'.
append ls_fieldcat to l_fieldcat.
clear ls_fieldcat.
* Maximum capacity
ls_fieldcat-fieldname = 'SEATSMAX'.
ls_fieldcat-col_pos = 7.
ls_fieldcat-seltext_s = 'Max. seats'.
ls_fieldcat-seltext_l = 'Max. seats'.
append ls_fieldcat to l_fieldcat.
clear ls_fieldcat.
* Occupied seats
ls_fieldcat-fieldname = 'SEATSOCC'.
ls_fieldcat-col_pos = 8.
ls_fieldcat-seltext_s = 'Seats occupied'.
ls_fieldcat-seltext_l = 'Seats occupied'.
append ls_fieldcat to l_fieldcat.
clear ls_fieldcat.
* Total
ls_fieldcat-fieldname = 'PAYMENTSUM'.
ls_fieldcat-col_pos = 9.
ls_fieldcat-do_sum = 'X'.
ls_fieldcat-seltext_s = 'Total amount'.
ls_fieldcat-seltext_l = 'Total amount'.
append ls_fieldcat to l_fieldcat.
clear ls_fieldcat.
* Total
ls_fieldcat-fieldname = 'PAYMENTSUM'.
ls_fieldcat-col_pos = 9.
ls_fieldcat-do_sum = 'X'.
ls_fieldcat-seltext_s = 'Total amount'.
ls_fieldcat-seltext_l = 'Total amount'.
append ls_fieldcat to l_fieldcat.
clear ls_fieldcat.
* Max. Capacity, Buss. Class
ls_fieldcat-fieldname = 'SEATSMAX_B'.
ls_fieldcat-col_pos = 10.
ls_fieldcat-seltext_s = 'Max.Buss.class cap.'.
ls_fieldcat-seltext_l = 'Max.Buss.class cap.'.

append ls_fieldcat to l_fieldcat.


clear ls_fieldcat.
* Max. occupancy, Buss. Class
ls_fieldcat-fieldname = 'SEATSOCC_B'.
ls_fieldcat-col_pos = 11.
ls_fieldcat-seltext_s = 'Max.Bus.CL.occupied'.
ls_fieldcat-seltext_l = 'Max.Bus.CL.occupied'.
append ls_fieldcat to l_fieldcat.
clear ls_fieldcat.
* Max. Capacity, First. Class
ls_fieldcat-fieldname = 'SEATSMAX_F'.
ls_fieldcat-col_pos = 12.
ls_fieldcat-seltext_s = 'Max.Buss.class cap.'.
ls_fieldcat-seltext_l = 'Max.Buss.class cap.'.
append ls_fieldcat to l_fieldcat.
clear ls_fieldcat.
* Max. occupancy, First. Class
ls_fieldcat-fieldname = 'SEATSOCC_F'.
ls_fieldcat-col_pos = 13.
ls_fieldcat-seltext_s = 'Max.Bus.CL.occupied'.
ls_fieldcat-seltext_l = 'Max.Bus.CL.occupied'.
append ls_fieldcat to l_fieldcat.
clear ls_fieldcat.
ENDFORM.
" initialize_fieldcat
*&---------------------------------------------------------------------*
*&
Form read_flight_info
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM read_flight_info .
refresh lt_sflight.
clear lt_sflight.
**-- Read data from SFLIGHT table
select *
from SFLIGHT
into table lt_sflight
where carrid in s_carrid
and connid in s_connid
and fldate in s_fldate.
if sy-subrc <> 0.
message e208(00) with text-101.
endif.
ENDFORM.
" read_flight_info
*&---------------------------------------------------------------------*
*&
Form dislay_alv_report
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*

FORM dislay_alv_report .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK
=''
* I_BYPASSING_BUFFER
=
* I_BUFFER_ACTIVE
=''
I_CALLBACK_PROGRAM
= g_repid
* I_CALLBACK_PF_STATUS_SET
=''
* I_CALLBACK_USER_COMMAND
=''
I_STRUCTURE_NAME
= 'sflight'
* IS_LAYOUT
=
IT_FIELDCAT
= gt_fieldcat
* IT_EXCLUDING
=
* IT_SPECIAL_GROUPS
=
* IT_SORT
=
* IT_FILTER
=
* IS_SEL_HIDE
=
I_DEFAULT
= 'X'
I_SAVE
= 'A'
IS_VARIANT
= GX_VARIANT
* IT_EVENTS
=
* IT_EVENT_EXIT
=
* IS_PRINT
=
* IS_REPREP_ID
=
* I_SCREEN_START_COLUMN
=0
* I_SCREEN_START_LINE
=0
* I_SCREEN_END_COLUMN
=0
* I_SCREEN_END_LINE
=0
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER
=
* ES_EXIT_CAUSED_BY_USER
=
TABLES
T_OUTTAB
= lt_sflight
EXCEPTIONS
PROGRAM_ERROR
=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.
ENDFORM.
" dislay_alv_report
*&---------------------------------------------------------------------*
*&
Form initialize_variant
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM initialize_variant .
g_save = 'A'.
clear g_variant.
g_variant-report = g_repid.
gx_variant = g_variant.
call function 'REUSE_ALV_VARIANT_DEFAULT_GET'
exporting
i_save = g_save
changing
cs_variant = gx_variant

exceptions
not_found = 2.
if sy-subrc = 0.
p_vari = gx_variant-variant.
endif.
ENDFORM.

" initialize_variant

Creation Of Active Icon


By : Kartikeya Bommuluri - kari_003@rediffmail.com
REPORT CREATION_OF_ACTIVE_ICON.
INITIALIZATION.
IMPORT mytab-activetab FROM MEMORY ID 'TABSTRIP'.
CASE mytab-activetab.
WHEN 'UCOMM1'. mytab-dynnr = 100.
WHEN 'UCOMM2'. mytab-dynnr = 200.
WHEN 'UCOMM3'. mytab-dynnr = 300.
WHEN OTHERS.
tabb1-dynnr = 100.
ENDCASE.
START-OF-SELECTION.
EXPORT: tabb1-activetab TO MEMORY ID 'TABSTRIP'.
SHORT VERSION.
INITIALIZATION.
IMPORT mytab FROM MEMORY ID 'TABSTRIP'.
START-OF-SELECTION.
EXPORT: mytab TO MEMORY ID 'TABSTRIP'.
SYNTAX FOR CREATING THE EXISTING CONTEXT MENU.::
FORM on_ctmenu_text USING menu TYPE REF TO cl_ctmenu.
CALL METHOD menu->load_gui_status
EXPORTING program = prog
status = 'CON_MENU'
menu = menu .
CALL METHOD menu->set_default_function
EXPORTING fcode = 'list'.
ENDFORM.
CREATING A NEW CONTEXT MENU::
FORM on_ctmenu_text USING menu TYPE REF TO cl_ctmenu.
DATA new_menu TYPE REF TO cl_ctmenu.
CREATE OBJECT new_menu.
CALL METHOD new_menu->add_function
EXPORTING fcode = 'list'
text = text-001.
CALL METHOD new_menu->add_function
EXPORTING fcode = 'add'
text = text-002. CALL METHOD

new_menu->add_function
EXPORTING fcode = 'delete'
text = text-003.
CALL METHOD new_menu->add_submenu
EXPORTING menu = new_menu
text = text-005.
ENDFORM
SYNTAX FOR STATUS ICON:
CALL FUNCTION 'ICON_CREATE'
EXPORTING
NAME = 'icon name'
TEXT = 'text to be displayed'
INFO = 'tooltip text'
Use SAP code to list how many documents in the folder on your PC
PC Folder List with ABAP
Use function module TMP_GUI_DIRECTORY_LIST_FILES to get a list of files on any given path on the
presentation server.
Sample Code:
data : file_table like table of SDOKPATH.
data : dir_table like table of SDOKPATH.
CALL FUNCTION 'TMP_GUI_DIRECTORY_LIST_FILES'
EXPORTING
DIRECTORY = 'C:\export\'
FILTER = '*.TXT'
* IMPORTING
* FILE_COUNT =
* DIR_COUNT =
TABLES
FILE_TABLE = file_table
DIR_TABLE = dir_table
* EXCEPTIONS
* CNTL_ERROR = 1
* OTHERS = 2.

Das könnte Ihnen auch gefallen