Professional Documents
Culture Documents
ABAP Tutorials For Beginners
ABAP Tutorials For Beginners
Dictionary
Reports
PDF Viewer
Convert internal table data into HTML with out using Function Modules
Convert internal table data into HTML using Function Modules
Adding custom context menu in classical list
Dynamic Selection Screen (Drop downs, pushbuttons, radio buttons, icons))
Creating Dynamic variant using table TVARV
Display images (like company logo) on the selection-screen
Custom Parameter-id Creation
Creating Dynamic Patterns
Scheduling a background job by triggering an event
Performance Tuning using Parallel Cursor
Creating a Transaction Variant
E-mailing the background jobs
ABAP Programming standards
ABAP Performance Tuning Checklist
Understanding SQL Trace
Changing the text "Sales Order" to "Billing Request" in the transactions VA01,
VA02 and VA03
Creation of a web service in SAP
Calling a web service in ABAP that validates an email id
Handling favorites in ABAP Workbench
Implementing events in Table Maintenance
Using Sorted table and Index while processing internal tables
Displaying Graphics using ABAP Program
The Features of ABAPTM New Editor - Part 2
The Features of ABAPTM New Editor - Part 1
Working with Menu Painter
Dynamic Variant in a report
Creating F1 helps with ease
Object oriented programming (OOP) explained with an example
Calling an RFC function module from one system to another
Updating Material Master long text (BASIC DATA TEXT, INSPECTION TEXT and
INTERNAL COMMENT)
System debugging - Explained in detail
MESSAGE XXXX RAISING XXXX. What is this?
Dialog Programming
BDC Programming
2. Enter the description, Delivery class and check on table maintenance allowed. Then click on the
tab Fields.
3. Enter the ZCHAR in fields tab and ZCHAR_DE in field type tab.
4. Double click on ZCHAR_DE. Then it will ask for Save. Press YES.
6. Now it will ask for the creation of the data element. Press Yes.
7. Click on the Field label tab and enter the lengths and descriptions accordingly.
9. Double click on that zchar_d to create domain, then it will ask for save before going next screen.
Press Yes.
12. Give short description for that domain which you are creating. And mention the data type in data
type field and length in no. characters field an press ENTER.
13. Then press Ctrl+F3. It will ask for save before activation. Save it as a local Object.
16. Press Ctrl+F3. You will get the following screen. Press Back button.
18. Create one more field ZNUM and give data element name as ZNUM_DE. And double click on
ZNUM_DE
20. Now it will ask for the data element creation. Press Yes.
21. Give short description of the data element. And give the lengths and field labels accordingly in
Field label tab.
22. Press on Definition tab and give the domain name in Domain field. Double click on ZNUM_D.
26. Give short description in short text field. Enter the data type and no. characters, Press Enter.
Then Press on Activate button or Press Ctrl+F3.
29. Now you will get the following screen. Press Back button.
30. Activate the data element By pressing Activate button or Pressing Ctrl+F3.
33. Now we created two fields. And Data elements and Domain for these two fields.
Now we have to maintain the technical settings. Press on Technical settings button.
34. Give the data class and size category of the table as per the requirement.
And press the back button.
35. Now
activate
the
table
by
pressing
the
activate
button
or
CTRL+F3.
38. Now enter the data into table. Go to Utilities Table contents Create Entries.
39. Now enter the data in the fields and Save it.
40. You will get the following screen after clicking the Reset Button.
41. Enter the data for the second entry into the table.
42. Save it and press reset.
44.
45.
46.
47. To see the table contents go to Utilities Table contents Display. Or press Ctrl+Shift+F10.
49. Press on run button or press F8. Now it will display the table contents.
Go to transaction SE11 and select the radio button Data type. Enter a structure name starting with Y or
Z.
Go To SE11 T-code.
Press Enter.
Provide the short description, the selection method.
Provide the fields.
We can see the screen like this, and then press F4 in this page.
exchange of values between the screen template and selection method is implemented
(interface of the search help) and how the online input help should be defined (online
behavior of the search help).
2) Collective search helps combine several elementary search helps. Collective search
help thus can offer several alternative search paths.
3) An elementary search help defines the standard flow of an input help.
4) A collective search help combines several elementary search helps. The user can thus
choose one of several alternative search paths with collective search help.
5) A collective search help comprises several elementary search helps. It combines all
the search paths that are meaningful for a field.
6) Both elementary search helps and other search helps can be included in a collective
search help. If other collective search helps are contained in collective search help, they
are expanded to the level of the elementary search helps when the input help is called.
There are two types of indexes: Primary index and secondary index. Primary index is automatically
created using the primary keys defined.
Secondary index could be created as per the user requirement. This article discusses about
creating a secondary index.
Go to transaction SE11.
From the above screenshot, it is evident that there are no secondary indexes already created.
Click on Create Create Index
Fill in the details Short description and the fields in the index.
Secondary Indexes
Consider the following example:
SELECT * FROM SPFLI
%_HINTS ORACLE 'INDEX("SPFLI" "SPFLI~001")'
.......
ENDSELECT.
In the above example, 001 is the secondary index of the table SPFLI. It's a well-known fact that the efficient
way of retrieving data from the database tables is by using secondary indexes. Many database vendors provide
the optimizer hints for the same. From SAP v4.5, optimizer hints can be provided by the %_HINTS parameter.
This is dependent on the database systems that support optimizer hints. The point to be noted here is these
optimizer hints are not standardized by the SQL standards. Each database vendor is free to provide the
optimizer hints.
Now to know which index to use for our table:
1. Go to SE11 and there specify the table name
2. Now from the menu, goto --> indexes
3. select the required index.
Now suppose that the identifier 001 represents a non-unique secondary index comprising of the columns
CITYFROM and CITYTO. The index name should be defined as:
<tablename>~<Index Identifier>
like SPFLI~001 in the above example.
The sequence of fields in the WHERE condition is of no relevance in using this optimizers index. If you specify
hints incorrectly, ABAPTM ignores them but doesn't return a syntax error or runtime error.
The code was written in R/3 4.6C.
Code
Consider the following example:
REPORT Suresh_test.
TABLES: spfli.
DATA : t_spfli LIKE spfli OCCURS 0 WITH HEADER LINE.
SELECT * FROM spfli
INTO TABLE t_spfli
%_HINTS ORACLE 'INDEX("SPFLI" "SPFLI~001")'.
LOOP AT t_spfli.
WRITE :/ t_spfli.
ENDLOOP.
Go to SE11 and enter the Z table name for which the table maintenance generator has to be generated.
Click on Change.
If we are using Logical Database for HR purpose, we should check the check Box Info types (HR only).
Press CREATE Button as shown above.
It would prompt for package name and workbench request .
On pressing Save button, following screen appears, prompting for the details of the root node.
Now enter the details of all the tables under LFA1 (as shown below).
The above screen displays the LDB structure as per our requirements.
We can maintain search help for the fields for the tables defined in structure.
Click on save.
Now you can create the table entries through the transaction created above.
For our demo purposes, let us provide search help for MATNR and WERKS.
Let us use the standard search help available for MATNR and WERKS.
Here we can design our own selection screen as per the requirements.
Here by using above marked statement we can create Dynamic selection screen for different tables as
per the requirements.
Database program (with some includes) are automatically created upon the creation of logical database:
Click on Display.
View Cluster
A view cluster is the set of objects, such as views, reports or tables, which belong to one business
function. The data can be arranged either hierarchically or non-hierarchically in view cluster. A viewcluster transaction edits the complex cross-table data in a view cluster. The transaction navigation box
shows the complex business object with its components or sub objects.
Example:
Let us create a View Cluster on Material Details. The view cluster would include three tables namely,
MARA, MARC and MARD. We need to create maintenance views for each of these tables.
Maintenance view for Table MARA
To create maintenance view for the table MARA follow the procedure below. Go to transaction SE11. Give
a view name say ZMM_V_MARA and click on Create. Give a short description, enter the table name as
MARA and click on the tab View fields.
By default all the key fields would be added. We can add more fields by clicking on the button Table fields.
This is because the fields MANDT and MATNR would be filled in the view for MARA and thus they act as
subsets and appear as header data when we create entries in view cluster.
Maintenance view for Table MARD
Follow the same procedure as above. In the Tab View fields, give S in the column P for the fields
MANDT, MATNR and WERKS as shown in the screen shot below:
This is because the fields MANDT, MATNR and WERKS would be filled in the view for MARC and thus
they act as subsets and appear as header data when we create entries in view cluster.
Table Maintenance Generator for ZMM_V_MARA
Now, for each view we need to create a table maintenance generator, which has to be done as follows:
The table maintenance screen appears. Here give the details as in the screen shot below. This table
maintenance is for the view ZMM_V_ MARA.
Before creating a table maintenance generator, create a function group say ZFG_MATERIAL from the
transaction SE80. After the function group is successfully created, enter the function group name as
shown in the screen shot. Also select Maintenance type as One Step and give the Maintenance Screen
no. as 1 in the Overview screen and click on the button Create.
Similarly, create the Table maintenance Generators for the views ZMM_V_MARC and ZMM_V_MARD.
The screen shots for these views would be as follows:
Table Maintenance Generators for ZMM_V_MARC and ZMM_V_MARD
Note that the Overview screen numbers would change for each view. It would be 2 for the view
ZMM_V_MARC and it would be 3 for the view ZMM_V_MARD.
Creating view cluster
The pre-requisites for creating the View Cluster are now ready. Go to transaction SE54 and select the
button Edit View Cluster. Enter the view cluster name as say ZMM_VC_MATERIAL and click on
Create.
Continue by pressing Enter. The following screen appears. Give a short description and click on Object
Structure as shown in the screen shot below:
On Clicking the Object Structure the following screen appears. Select the New Entries button to enter
the maintenance views created to form a cluster.
The entries would be entered in a hierarchical manner. The short text is the description of the view. The
Predecess column specifies the predecessor of that view. So in this case, the predecessor of
ZMM_V_MARA is ZMM_V_MARA itself. The predecessor of ZMM_V_MARC is ZMM_V_MARA and the
predecessor of ZMM_V_MARD is ZMM_V_MARC. The DEP column explains whether the entry is a
Header entry or a Dependent entry. It is R for the view ZMM_V_MARA, because it is a header entry and
does not depend on any other view. Whereas, it is S for ZMM_V_MARC and ZMM_V_MARD, because
ZMM_V_MARC is dependent on ZMM_V_MARA and ZMM_V_MARD is dependent on ZMM_V_MARC.
The column POS specifies the sequence of the views. In the column Start select the radio button
against the entry for ZMM_V_MARA as it comes first in the hierarchy.
After entering the above entries, press Enter. Three pop-ups for each view would appear as shown
below. Proceed further by clicking on Enter key.
Now select each line and click on Field-dependence button. A pop-up appears saying Field
dependencies successfully generated.
Generate the field dependence for the views ZMM_V_MARC and ZMM_V_MARD in the same way. Now,
save the entries and go back to Header Entry folder. Activate the view cluster. A pop-up appears as
shown below. Click on Yes.
The view cluster can be created on the tables whose data has to be stored in a hierarchical
manner.
2.
One has to check whether proper foreign key relationships are maintained between the tables
appearing in the cluster. Sometimes while generating the Field-dependencies, errors may occur if
the foreign keys are not maintained properly.
Since we have created the view cluster on standard tables MARA, MARC and MARD we observe that all
the existing entries would appear. The screen shot below shows all the existing entries of the table
MARA. In order to see the corresponding Plant details for the material, just select an entry and double
click on Plant details as shown below.
The plant details would appear. In the same way for the corresponding storage location details, select an entry
and double click on Storage details as shown below.
In the above screen shot the material selected in the Material details view would appear as a header
entry. The storage location details are as follows:
In the above screen shot the material selected in the Material details view and the plant selected in the
Plant details view would appear as header entry.
2.
Create
table
ZTEST_SHUKS3.
We will make single screen maintenance for this table. Save it. So finally we have table maintenance
code automatically generated in function group ZTEST_SHUKS3.
3.
Now save and activate the Lock object. SAP creates two function modules corresponding to lock object
for enqueue and dequeue of the table.
4.
Now create a report ZREP_SHUKS3 and transaction code ZTEST_SHUKS3 to call this report. This
tcode will call table maintenance generator of table ZTEST_SHUKS3 .
5.
Normally if a person opens table maintenance generator and tries to maintain the table, no one else
can maintain table at the same time. This is because of table level lock by default in SAP. Only one
user can maintain any table at a time. In report ZREP_SHUKS3 we will delete the table level lock and
put row level lock so that multiple users can maintain table at same time. Rows locked by one user
will not be editable by other user. Check the report and comments given below.
*&---------------------------------------------------------------------*
*& Report ZREP_SHUKS3
*&
*&--------------------------------------------------------------------*& Author : Swetabh Shukla
*& Date : 05/22/2009
*& Description : To delete table level lock from table.
*&---------------------------------------------------------------------*
REPORT zrep_shuks3.
**Selection range for view maintenance
DATA:
BEGIN OF selekttab OCCURS 1.
"Selektionsbereich
INCLUDE STRUCTURE vimsellist.
DATA: END OF selekttab,
**Table of inactive CUA functions for view maintenance
BEGIN OF excl_cua_funct OCCURS 1. "inaktive CUA-Fkt bei View-Pflege
INCLUDE STRUCTURE vimexclfun.
DATA: END OF excl_cua_funct.
DATA: lt_enq_del TYPE STANDARD TABLE OF seqg3,
lt_enq_read TYPE STANDARD TABLE OF seqg7,
lw_enq_read TYPE seqg7,
lw_enq_del TYPE seqg3,
lv_subrc TYPE sy-subrc.
*Read all the lock details in system
CALL FUNCTION 'ENQUE_READ2'
EXPORTING
gclient = sy-mandt
gname = ' '
guname = '*'
TABLES
enq = lt_enq_read.
*We will search entry for table level lock for our table
LOOP AT lt_enq_read INTO lw_enq_read
WHERE gname EQ 'RSTABLE'
AND garg CS 'ZTEST_SHUKS3'.
MOVE-CORRESPONDING lw_enq_read TO lw_enq_del.
APPEND lw_enq_del TO lt_enq_del.
ENDLOOP.
*Delete table level lock entry for our table
CALL FUNCTION 'ENQUE_DELETE'
EXPORTING
check_upd_requests = 1
IMPORTING
subrc
= lv_subrc
TABLES
enq
= lt_enq_del.
Just one more change in table maintenance screen. Now open table maintenance function
group(ZTEST_SHUKS3) in SE80.We know for table maintenance SAP automatically creates code in
the function group. Now we will make some modification in that existing code to change the behavior.
Open the screen you created through table maintenance and add one module.
Open the screen 0001 and add one module in PBO of the screen as shown in figure below.
Now we are ready for testing. Call the transaction once and make some entries in table. In below
screenshot I have entered some random values. Since we have not maintained any check tables etc,
so values may be invalid. That can be taken care in real scenario.
Save data.
Lets call two sessions of the transaction ZTEST_SHUKS3.
Session 1
In first session we will call the transaction ZTEST_SHUKS3 and try to open some existing values for table
maintenance.
Session 2
Open transaction ZTEST_SHUKS3
So we can see that our transaction is able to achieve a row level locking and has removed table level
locking.
In this Tutorial, we create a Table pool first and then create/ (add a table to Table pool) a Pooled Table.
Step 1:
Go to transaction SE11. Go to Utilities Other Dictionary Objects
Step 2:
Select Radio button Table pool/Cluster Give table Pool Name: ZTBL_POOL.
Then press F5 or choose Create.
Step 3:
Then Select Radio button Table Pool. Press Enter.
Step 4:
Step 5:
Then go to Technical settings.
Step 6:
In the Maintain technical Settings screen Provide Size category.
Step 8:
Maintain Delivery and Maintenance attributes for the Z table.
Step 9:
Then Go to Extras Change table category
Step 10:
Choose Table type.
In our Example it is Pooled table.
Step 11:
Go back to Delivery and Maintenance tab and provide Pool/Cluster value.
PDF Viewer
By Sai Kumar B, Enteg
This Program helps you to view any output in PDF viewer as shown below. Its very simple to understand.
Just convert OFT data into PDF as below.
*&---------------------------------------------------------------------*
*& Report ZSAP_PDF_VIEWER_DEMO_2
*&
*&---------------------------------------------------------------------*
REPORT
ZSAP_PDF_VIEWER.
VBELN_VL.
INITIALIZATION.
LS_CONTROL_PARAM-GETOTF = 'X'.
LS_CONTROL_PARAM-NO_DIALOG = 'X'.
START-OF-SELECTION.
CALL FUNCTION '/1BCDWB/SF00000034'
EXPORTING
*
ARCHIVE_INDEX
=
*
ARCHIVE_INDEX_TAB
=
*
ARCHIVE_PARAMETERS
=
CONTROL_PARAMETERS
= LS_CONTROL_PARAM
P_VBELN
= P_VBELN
*
MAIL_APPL_OBJ
=
*
MAIL_RECIPIENT
=
*
MAIL_SENDER
=
*
OUTPUT_OPTIONS
=
*
USER_SETTINGS
= 'X'
IMPORTING
*
DOCUMENT_OUTPUT_INFO = L_DOCUMENT_OUTPUT_INFO
JOB_OUTPUT_INFO
= L_JOB_OUTPUT_INFO
*
JOB_OUTPUT_OPTIONS
= L_JOB_ OUTPUT_OPTIONS
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.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT
=
IMPORTING
BIN_FILESIZE
=
TABLES
OTF
=
LINES
=
EXCEPTIONS
ERR_MAX_LINEWIDTH
=
ERR_FORMAT
=
ERR_CONV_NOT_POSSIBLE =
OTHERS
=
'PDF'
PDF_FSIZE
L_JOB_OUTPUT_INFO-OTFDATA
LT_PDF
1
2
3
4.
*&---------------------------------------------------------------------*
*&
Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.
CREATE OBJECT G_HTML_CONTAINER
EXPORTING
CONTAINER_NAME = 'PDF'.
CREATE OBJECT G_HTML_CONTROL
EXPORTING
PARENT = G_HTML_CONTAINER.
* Convert xstring to binary table to pass to the LOAD_DATA method
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER
= LV_CONTENT
TABLES
BINARY_TAB = LT_DATA.
* Load the HTML
CALL METHOD G_HTML_CONTROL->LOAD_DATA(
EXPORTING
TYPE
= 'application'
SUBTYPE
= 'pdf'
IMPORTING
ASSIGNED_URL
= LV_URL
CHANGING
DATA_TABLE
= LT_DATA
EXCEPTIONS
DP_INVALID_PARAMETER = 1
DP_ERROR_GENERAL
= 2
CNTL_ERROR
= 3
OTHERS
= 4 ).
* Show it
CALL METHOD G_HTML_CONTROL->SHOW_URL( URL = LV_URL
IN_PLACE = 'X' ).
ENDMODULE.
" STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
ENDMODULE.
" USER_COMMAND_0100
INPUT
Convert internal table data into HTML format without using Function
Modules
By Suman Kumar Chinnam
The output of this Tutorial is same as previous one but in this we are not using any function modules to
convert internal table data to HTML table.
*&----------------------------------------------------------------*
*& Report YTEST_TABLE_HTML1
*&
*&----------------------------------------------------------------*
REPORT ytest_table_html1.
*----------------------------------------------------------------*
*
D A T A
D E C L A R A T I O N
*----------------------------------------------------------------*
*-HTML Table
DATA:
t_html TYPE STANDARD TABLE OF w3html WITH HEADER LINE,
" Html Table
*- Declare Internal table and Fieldcatalog
it_flight TYPE STANDARD TABLE OF sflight WITH HEADER LINE,
" Flights Details
it_fcat TYPE lvc_t_fcat WITH HEADER LINE.
" Fieldcatalog
*-Variables
DATA:
v_lines TYPE i,
v_field(40).
*-Fieldsymbols
FIELD-SYMBOLS: <fs> TYPE ANY.
*----------------------------------------------------------------*
*
S T A R T - O F - S E L E C T I O N
*----------------------------------------------------------------*
START-OF-SELECTION.
SELECT *
FROM sflight
INTO TABLE it_flight
UP TO 20 ROWS.
*----------------------------------------------------------------*
*
E N D - O F - S E L E C T I O N
*----------------------------------------------------------------*
END-OF-SELECTION.
*-Fill the Column headings and Properties
* Field catalog is used to populate the Headings and Values of
* The table cells dynamically
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name
= 'SFLIGHT'
CHANGING
ct_fieldcat
= it_fcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error
= 2.
DELETE it_fcat WHERE fieldname = 'MANDT'.
t_html-line = '<html>'.
APPEND t_html.
CLEAR t_html.
t_html-line = '<thead>'.
APPEND t_html.
CLEAR t_html.
t_html-line = '<tr>'.
APPEND t_html.
CLEAR t_html.
t_html-line = '<td><h1>Flights Details</h1></td>'.
APPEND t_html.
CLEAR t_html.
t_html-line = '</tr>'.
APPEND t_html.
CLEAR t_html.
t_html-line = '</thead>'.
APPEND t_html.
CLEAR t_html.
t_html-line = '<table border = "1">'.
APPEND t_html.
CLEAR t_html.
t_html-line = '<tr>'.
APPEND t_html.
CLEAR t_html.
*-Populate HTML columns from Filedcatalog
LOOP AT it_fcat.
CONCATENATE '<th bgcolor = "green" fgcolor = "black">'
it_fcat-scrtext_l
'</th>' INTO t_html-line.
APPEND t_html.
CLEAR t_html.
ENDLOOP.
t_html-line = '</tr>'.
APPEND t_html.
CLEAR t_html.
DESCRIBE TABLE it_fcat LINES v_lines.
*-Populate HTML table from Internal table data
LOOP AT it_flight.
t_html-line = '<tr>'.
APPEND t_html.
CLEAR t_html.
*-Populate entire row of HTML table Dynamically
*-With the Help of Fieldcatalog.
DO v_lines TIMES.
READ TABLE it_fcat INDEX sy-index.
CONCATENATE 'IT_FLIGHT-' it_fcat-fieldname INTO v_field.
ASSIGN (v_field) TO <fs>.
t_html-line = '<td>'.
APPEND t_html.
CLEAR t_html.
t_html-line = <fs>.
APPEND t_html.
CLEAR t_html.
t_html-line = '</td>'.
APPEND t_html.
CLEAR t_html.
CLEAR v_field.
UNASSIGN <fs>.
ENDDO.
t_html-line = '</tr>'.
APPEND t_html.
CLEAR t_html.
ENDLOOP.
t_html-line = '</table>'.
APPEND t_html.
CLEAR t_html.
*-Download the HTML into frontend
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename
= 'C:\Flights.htm'
TABLES
data_tab
= t_html
EXCEPTIONS
file_write_error
= 1
no_batch
= 2
gui_refuse_filetransfer = 3
invalid_type
= 4
no_authority
= 5
unknown_error
= 6
header_not_allowed
= 7
separator_not_allowed
= 8
filesize_not_allowed
= 9
header_too_long
= 10
dp_error_create
= 11
dp_error_send
= 12
dp_error_write
= 13
unknown_dp_error
= 14
access_denied
= 15
dp_out_of_memory
= 16
disk_full
= 17
dp_timeout
= 18
file_not_found
= 19
dataprovider_exception = 20
control_flush_error
= 21
OTHERS
= 22.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*-Display the HTML file
CALL METHOD cl_gui_frontend_services=>execute
EXPORTING
document
= 'C:\Flights.htm'
operation
= 'OPEN'
EXCEPTIONS
cntl_error
= 1
error_no_gui
= 2
bad_parameter
= 3
file_not_found
= 4
path_not_found
= 5
file_extension_unknown = 6
error_execute_failed
= 7
synchronous_failed
= 8
not_supported_by_gui
= 9
OTHERS
= 10.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Result:
Convert internal table data into HTML format using Function Modules
By Suman Kumar Chinnam
Following Function Modules are used to convert internal table data to HTML Table.
1. WWW_ITAB_TO_HTML_HEADERS is used to populate column headings.
2. WWW_ITAB_TO_HTML_LAYOUT is used to populate column cell properties.
*&
*&---------------------------------------------------------------------*
REPORT ytest_table_html.
*---------------------------------------------------------------------*
*
T Y P E S D E C L A R A T I O N
*---------------------------------------------------------------------*
TYPES:BEGIN OF ty_sflight,
carrid TYPE s_carr_id,
" Airline Code
connid TYPE s_conn_id,
" Connection Number
fldate TYPE s_date,
" Flight Date
price TYPE s_price,
" AirFare
currency TYPE s_currcode,
" Currency
END OF ty_sflight.
*-ALL related Declarations
DATA:
t_header TYPE STANDARD TABLE OF w3head WITH HEADER LINE,
"Header
t_fields TYPE STANDARD TABLE OF w3fields WITH HEADER LINE, "Fields
t_html TYPE STANDARD TABLE OF w3html,
"Html
wa_header TYPE w3head,
w_head TYPE w3head.
DATA:
it_sflight TYPE TABLE OF ty_sflight,
" Flights Details
it_fcat TYPE lvc_t_fcat WITH HEADER LINE. " Fieldcatalog
*---------------------------------------------------------------------*
*
S T A R T - O F - S E L E C T I O N
*---------------------------------------------------------------------*
START-OF-SELECTION.
SELECT * FROM
sflight
INTO CORRESPONDING FIELDS OF TABLE it_sflight
UP TO 20 ROWS.
*---------------------------------------------------------------------*
*
E N D - O F - S E L E C T I O N
*---------------------------------------------------------------------*
END-OF-SELECTION.
*-Populate Fieldcatalog
it_fcat-coltext = 'Airline Code'.
APPEND it_fcat.
it_fcat-coltext = 'Connection Number'.
APPEND it_fcat.
it_fcat-coltext = 'Flight date'.
APPEND it_fcat.
it_fcat-coltext = 'Airfare'.
APPEND it_fcat.
it_fcat-coltext = 'Currency'.
APPEND it_fcat.
*-Fill the Column headings and Properties
LOOP AT it_fcat.
w_head-text = it_fcat-coltext.
*-Populate the Column Headings
CALL FUNCTION 'WWW_ITAB_TO_HTML_HEADERS'
EXPORTING
field_nr = sy-tabix
text
= w_head-text
fgcolor = 'black'
bgcolor = 'green'
TABLES
header
= t_header.
*-Populate Column Properties
CALL FUNCTION 'WWW_ITAB_TO_HTML_LAYOUT'
EXPORTING
field_nr = sy-tabix
fgcolor = 'black'
size
= '3'
TABLES
fields
= t_fields.
ENDLOOP.
*-Title of the Display
wa_header-text = 'Flights Details' .
wa_header-font = 'Arial'.
wa_header-size = '2'.
*-Preparing the HTML from Intenal Table
REFRESH t_html.
CALL FUNCTION 'WWW_ITAB_TO_HTML'
EXPORTING
table_header = wa_header
TABLES
html
= t_html
fields
= t_fields
row_header
= t_header
itable
= it_sflight.
*-Download the HTML into frontend
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename
= 'C:\Flights.htm'
TABLES
data_tab
= t_html
EXCEPTIONS
file_write_error
= 1
no_batch
= 2
gui_refuse_filetransfer = 3
invalid_type
= 4
no_authority
= 5
unknown_error
= 6
header_not_allowed
= 7
separator_not_allowed
= 8
filesize_not_allowed
= 9
header_too_long
= 10
dp_error_create
= 11
dp_error_send
= 12
dp_error_write
= 13
unknown_dp_error
= 14
access_denied
= 15
dp_out_of_memory
= 16
disk_full
= 17
dp_timeout
= 18
file_not_found
= 19
dataprovider_exception = 20
control_flush_error
= 21
OTHERS
= 22.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Result:
*&---------------------------------------------------------------*
*& Report Z_CONTEXT_MENU_DEMO
*&
*&---------------------------------------------------------------*
*& published at SAPTechnical.COM
*&
*&---------------------------------------------------------------*
REPORT z_context_menu_demo.
* Table declaration
DATA: i_vbak TYPE STANDARD TABLE OF vbak INITIAL SIZE 0,
i_vbap TYPE STANDARD TABLE OF vbap INITIAL SIZE 0.
* Workarea declaration
DATA: w_vbak TYPE vbak,
w_vbap TYPE vbap.
START-OF-SELECTION.
* Set custom status
SET PF-STATUS 'BASIC'.
* Fetch header data
SELECT * FROM vbak
INTO TABLE i_vbak
UP TO 50 ROWS.
IF sy-subrc = 0.
*
Fetch line item data
SELECT * FROM vbap
INTO TABLE i_vbap
FOR ALL ENTRIES IN i_vbap
WHERE vbeln = i_vbap-vbeln.
CHECK sy-subrc = 0.
*
Display basic list
LOOP AT i_vbak INTO w_vbak.
FORMAT COLOR COL_HEADING.
WRITE : /10 w_vbak-vbeln,
20 w_vbak-erdat,
35 w_vbak-erzet,
55 w_vbak-ernam.
HIDE: w_vbak-vbeln.
ENDLOOP.
ENDIF.
AT USER-COMMAND.
* Handle user command
CASE sy-ucomm.
WHEN 'DETAIL'.
CHECK NOT w_vbak IS INITIAL.
*
Display detail list
LOOP AT i_vbap INTO w_vbap WHERE vbeln =
w_vbak-vbeln.
FORMAT COLOR COL_HEADING.
WRITE : /10 w_vbap-vbeln,
25 w_vbap-posnr,
35 w_vbap-matnr,
55 w_vbap-matwa.
ENDLOOP.
WINDOW STARTING AT 20 20
ENDING AT 120 110.
ENDCASE.
*&---------------------------------------------------------------*
*&
Form on_ctmenu_request
*&---------------------------------------------------------------*
*
Creation of custom context menu- It is called dynamically
*
by ABAP runtime
*----------------------------------------------------------------*
*
-->L_MENU
Handle for context menu
*----------------------------------------------------------------*
FORM on_ctmenu_request USING l_menu TYPE REF TO cl_ctmenu.
DATA lin TYPE i.
GET CURSOR LINE lin.
IF lin > 2 AND sy-lsind = 0.
*
Add menu
CALL METHOD l_menu->add_function
EXPORTING
fcode = 'DETAIL'
text = text-001.
ENDIF.
*
Add menu
CALL METHOD l_menu->add_function
EXPORTING
fcode = 'BACK'
text = text-002.
ENDFORM.
"on_ctmenu_request
How SAP calls the routine ON_CTMENU_REQUEST:
Whenever user presses right mouse button or shift + F10 key combinations sap triggers system event
and calls the method DISPATCH_SYSTEM_EVENTS of class CL_GUI_CFW. Within it, it calls the method
DISPATCH of class LCL_DYNPRO_PROXY (defined within the class pool of CL_GUI_CFW).
From this method (DISPATCH) it calls the routine ON_CTMENU_REQUEST which is defined in our
program.
Output:
Basic list:
Detail list:
*&----------------------------------------------------------------*
*& Report Z_sscr
*
* Published at SAPTechnical.COM
*&
*
*&----------------------------------------------------------------*
*&DYNAMIC Selection screen based on user clicks on the radiobutton*
*&
*
*&----------------------------------------------------------------*
REPORT zsscr.
*TYPE POOLS DECLARATIONS FOR VALUE REQUEST MANAGER AND ICONS
TYPE-POOLS : vrm,
icon.
*SELECTION SCREEN FIELDS
TABLES : sscrfields.
*GLOBAL DECLARATIONS
DATA : flag TYPE c,
tablename(10),
mmtable LIKE dd02l-tabname,
sdtable LIKE dd02l-tabname,
hrtable LIKE dd02l-tabname.
*DECLARATIONS FOR SELECTION SCREEN STATUS
DATA it_ucomm TYPE TABLE OF sy-ucomm.
***********SELECTION-SCREENS**********************
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME.
*FOR DYNAMIC DISPLAY OF MODULES
PARAMETERS : pa RADIOBUTTON GROUP rad USER-COMMAND com MODIF ID mod,
pb RADIOBUTTON GROUP rad MODIF ID rad,
pc RADIOBUTTON GROUP rad MODIF ID cad.
SELECTION-SCREEN SKIP.
**TO INCLUDE DYNAMIC ICONS
screen-active = 0.
screen-display_3d = '0'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDIF.
*CLICK OF THIRD RADIO
IF pc = 'X'.
sscrfields-functxt_03 = 'Human Resources'.
WRITE icon_new_employee AS ICON TO text_001.
LOOP AT SCREEN.
IF screen-group1 = 'RAD'.
screen-intensified = '0'.
screen-active = 0.
screen-display_3d = '0'.
MODIFY SCREEN.
ENDIF.
IF screen-group1 = 'MOD'.
screen-intensified = '0'.
screen-active = 0.
screen-display_3d = '0'.
MODIFY SCREEN.
ENDIF.
IF screen-group1 = 'CAD'.
screen-intensified = '1'.
screen-active = 1.
screen-display_3d = '1'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDIF.
*CUSTOMISING THE TOOLBARS OF THE SELECTION SCREEN
*WITH F8 BUTTON DISABLED
APPEND : 'PRIN' TO it_ucomm,
'SPOS' TO it_ucomm,
'ONLI' TO it_ucomm.
CALL FUNCTION 'RS_SET_SELSCREEN_STATUS'
EXPORTING
p_status = sy-pfkey
TABLES
p_exclude = it_ucomm.
**EVENT ON THE SELECTION
AT SELECTION-SCREEN.
* LIST BOX ONE VALUES
CASE one.
WHEN '1'.
mmtable = 'MARC'.
WHEN '2'.
mmtable = 'MARA'.
WHEN '3'.
mmtable = 'MARD'.
WHEN '4'.
mmtable = 'MARM'.
ENDCASE.
* LIST BOX TWO VALUES
CASE two.
WHEN '1'.
sdtable = 'VBAK'.
WHEN '2'.
sdtable = 'VBAP'.
WHEN '3'.
sdtable = 'VBUK'.
WHEN '4'.
sdtable = 'VBUP'.
ENDCASE.
* LIST BOX THREE VALUES
CASE three.
WHEN '1'.
hrtable = 'PA0001'.
WHEN '2'.
hrtable = 'PA0006'.
WHEN '3'.
hrtable = 'PA0022'.
WHEN '4'.
hrtable = 'PA0008'.
ENDCASE.
*VALUES FOR CLICK OF THE PUSHBUTTON ON APP TOOLBAR
*AND ENABLING THE BUTTONS TO PERFORM F8
CASE sscrfields-ucomm.
WHEN 'FC01'.
tablename = mmtable.
sscrfields-ucomm = 'ONLI'.
WHEN 'FC02'.
tablename = sdtable.
sscrfields-ucomm = 'ONLI'.
WHEN 'FC03'.
tablename = hrtable.
sscrfields-ucomm = 'ONLI'.
ENDCASE.
*INITIALIZATION EVENT
INITIALIZATION.
*VALUES ASSIGNED TO DROPDOWNLISTS IN THE SUBROUTINES
PERFORM f4_value_request_pa.
PERFORM f4_value_request_pb.
PERFORM f4_value_request_pc.
*START OF SELECTION EVENT
START-OF-SELECTION.
*SUBROUTINE FOR OUTPUT
PERFORM output.
*&----------------------------------------------------------------*
*&
Form f4_value_request_PA
*&----------------------------------------------------------------*
*
text
*-----------------------------------------------------------------*
*SUBROUTINE TO PROVIDE DROPDOWN VALUES TO LIST1
FORM f4_value_request_pa.
DATA: l_name TYPE vrm_id,
li_list TYPE vrm_values,
l_value LIKE LINE OF li_list.
l_value-key = '1'.
l_value-text = 'Plant Data for Material'.
APPEND l_value TO li_list.
CLEAR l_value.
l_value-key = '2'.
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. " f4_value_request_PB
*&----------------------------------------------------------------*
*&
Form f4_value_request_PC
*&----------------------------------------------------------------*
*
text
*-----------------------------------------------------------------*
*SUBROUTINE TO PROVIDE DROPDOWN VALUES TO LIST3
FORM f4_value_request_pc.
DATA: l_name TYPE vrm_id,
li_list TYPE vrm_values,
l_value LIKE LINE OF li_list.
l_value-key = '1'.
l_value-text = 'HR Master :Infotype 0001 (Org. Assignment)'.
APPEND l_value TO li_list.
CLEAR l_value.
l_value-key = '2'.
l_value-text = 'Address Infotype 0006'.
APPEND l_value TO li_list.
CLEAR l_value.
l_value-key = '3'.
l_value-text = 'Education Infotype 0022'.
APPEND l_value TO li_list.
CLEAR l_value.
l_value-key = '4'.
l_value-text = 'Basic Pay Infotype 0008'.
APPEND l_value TO li_list.
CLEAR l_value.
l_name = 'THREE'.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id
= l_name
values
= li_list
EXCEPTIONS
id_illegal_name = 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. " f4_value_request_PC
*&----------------------------------------------------------------*
*&
Form OUTPUT
*&----------------------------------------------------------------*
*
text
*-----------------------------------------------------------------*
*
-->P_TABLENAME text
*-----------------------------------------------------------------*
*fINAL OUTPUT
FORM output.
DATA p_table(10).
p_table = tablename.
*popup to display teh selected table and
On click of the Button in the Application toolbar, here Sales and Distribution, we get
Let us say for the given selection screen we need to create a dynamic variant.
Step 1. First maintain a variable with values in table TVARV. This can be done from transaction STVARV.
Later this variable needs to be assigned to the variant.
Step 2. Next create the dynamic variant by pressing the SAVE button on the selection screen.
In the next screen (ABAP: Save as Variant) enter Variant name, description, set the Selection variable
(L) radio button and press Selection variable push button.
In the next screen check that green traffic light is on under column T (T: Table variable from TVARV). Then
click on the
button.
Now from the popup select the variable name created in Step1 and save the variant.
It will populate Airline select-option with the values maintained in TVARV table against variable
ZAIRLINE_CODE.
Press
Press the Create button
REFRESH query_table.
query_table-name = '_OBJECT_ID'.
*CHANGE IMAGE NAME BELOW UPLOADED IN SWO0******************
query_table-value = 'BIKER'.
APPEND query_table.
CALL FUNCTION 'WWW_GET_MIME_OBJECT'
TABLES
query_string
= query_table
html
= html_table
mime
= pic_data
CHANGING
return_code
= return_code
content_type
= content_type
content_length
= content_length
EXCEPTIONS
object_not_found
= 1
parameter_not_found = 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 'DP_CREATE_URL'
EXPORTING
type
= 'image'
subtype = cndp_sap_tab_unknown
size
= pic_size
lifetime = cndp_lifetime_transaction
TABLES
data
= pic_data
CHANGING
url
= url
EXCEPTIONS
OTHERS
= 1.
ENDIF.
CALL METHOD picture_control_1->load_picture_from_url
EXPORTING
url = url.
*Syntax for URL
*url = 'file://D:\corp-gbanerji\pickut\cartoon_184.gif'.
*url = 'http://l.yimg.com/a/i/ww/beta/y3.gif'.
ENDFORM.
"show_pic
Make changes in the report accordingly.
Go to the table maintenance generator of the table TPARA and go to the Maintain button through
the transaction SM30.
Enter the table view name TPARA.
Click on the maintain button. The following information will appear. Click on the Tick button or the
ENTER button to go to the next screen.
Enter the Set/Get parameter id as the parameter ID you want to create. Here, I will be creating
the parameter Id as ZNAME_DATA1. Click on ENTER button.
It will ask for the text of the parameter Id. Enter the text of the parameter ID and click on the Save
button.
Activate the data element and use it with the program. It will act the same good as a standard one.
Step1. Create a pattern with only one line that contains *$&$EXIT.
Step2. Now from CMOD create a project and include enhancement SEUED001 in it.
Now select the user exit EXIT_SAPLLOCAL_EDT1_001 and create the include program in it.
Now insert the following code block in the include program and activate it.
*&---------------------------------------------------------------------*
*& Include
ZXSEUU26
*
*&---------------------------------------------------------------------*
DATA: w_buffer TYPE string.
CASE keyword.
WHEN 'DYNAMIC_PATTERN'.
w_buffer =
'*********************************************************************'.
APPEND w_buffer TO buffer.
w_buffer = '*& Program
:'.
APPEND w_buffer TO buffer.
w_buffer = '*& Module
:'.
APPEND w_buffer TO buffer.
w_buffer = '*& Sub-Module
:'.
APPEND w_buffer TO buffer.
w_buffer = '*& Functional Contact:'.
APPEND w_buffer TO buffer.
w_buffer = '*& Funct. Spec. Ref. :'.
APPEND w_buffer TO buffer.
w_buffer = '*& Developer(Company):'.
APPEND w_buffer TO buffer.
w_buffer = '*& Create Date
:'.
APPEND w_buffer TO buffer.
w_buffer = '*& Program Type
:'.
APPEND w_buffer TO buffer.
w_buffer = '*& Project Phase
:'.
APPEND w_buffer TO buffer.
w_buffer = '*& Description
:'.
APPEND w_buffer TO buffer.
w_buffer =
'*********************************************************************'.
Step2: Create a program that triggers this event by calling the FM BP_EVENT_RAISE.
*&---------------------------------------------------------------------*
In the popup screen press After event button and give the event name and then press save
button.
Provide program and variant name and after providing all the values press save button.
Step4: Now execute the program to trigger the event and as well check the background job.
Nested Loops This is one of the fear factors for all the ABAP developers as this consumes lot of
program execution time. If the number of entries in the internal tables is huge, then the situation would be
too worse. The solution for this is to use parallel cursor method whenever there is a need for Nested
Loop.
Program using Normal Nested Loop:
REPORT
TABLES:
likp,
ZNORMAL_NESTEDLOOP.
lips.
Data:
t_likp
t_lips
data:
W_RUNTIME1 TYPE I,
W_RUNTIME2 TYPE I.
START-OF-SELECTION.
select *
from likp
into table t_likp.
select *
from lips
into table t_lips.
get RUN TIME FIELD w_runtime1.
loop at t_likp into likp.
loop at t_lips into lips where vbeln eq likp-vbeln.
endloop.
endloop.
get RUN TIME FIELD w_runtime2.
w_runtime2 = w_runtime2 - w_runtime1.
write w_runtime2.
Nested Loop using Parallel Cursor:
REPORT
zparallel_cursor2.
TABLES:
likp,
lips.
DATA:
t_likp
t_lips
DATA:
w_runtime1 TYPE i,
w_runtime2 TYPE i,
w_index LIKE sy-index.
START-OF-SELECTION.
SELECT *
FROM likp
INTO TABLE t_likp.
SELECT *
FROM lips
1
2
3
34,796,147
38,534,583
34,103,426
In this tutorial, we would discuss about creating a transaction variant for the transaction MM01. Our
transaction variant should default to a value for Industry sector and material type and should not allow the
end user to change those values (output only).
Go to transaction SHD0.
Select the required Industry sector and Material Type and press ENTER. Following popup would appear:
Enter the values as shown above. Click on Enter. The following SE93 transaction would appear:
The name of the Transaction Variant is automatically proposed. Save your entries.
Now go to Transaction ZMM01 and check your transaction variant:
You can observe that the field Industry sector and Material type default to the value we have given earlier
and are output enabled only.
This tutorial deals about the procedure in automatic e-mailing of the background jobs. The output of the
background job is sent to the recipient as an email.
We would schedule the above program as a background job and send the output of the same as an
email.
Go to Transaction SM36.
Enter the job name.
Save your job. Only after you save, the job would be set to status Released.
In the above screenshot, you can observe an email related to the job we created earlier. Open the
attachment to see the output of the background job:
* Modification history:
*
--------------------------------------------------------------------------------------------------------* DATE
|User ID
|TS Ver | Transport Request | Description
*
--------------------------------------------------------------------------------------------------------*
************************************************************************
Naming conventions to be followed:
Other Objects
Application area corresponds to the application area you are working like
B - Basis
C - CO
S SD / SAM
F- FI
W - PM
M MM/Supply
Description
Run Extended syntax checks with character literals checkbox
switched on & Code Inspector to rectify all relevant errors and
warning (e.g. Use the results of the above checks to remove all
variables/constants etc that are declared but are not used)
Transaction SE30 (ABAP Runtime Analysis) must be checked to
Result (Y, N
or N/A)
Comments
Sort internal table by fields in the correct order, which are used in a
READ TABLE statement using BINARY SEARCH. If the order of
sorting is invalid the BINARY SEARCH will never work
For large internal tables where only some rows are to be
processed, use SORT and then the READ TABLE command is
used to set index to first relevant row before looping from that
index. Use CHECK or IFEXITENDIF as appropriate to exit
from the loop
Sort fields and Sort Order on the SORT statement should be
mentioned explicitly (e.g. SORT ITAB BY FLD1 FLD2
ASCENDING)
Hashed table is used for processing large amount of data
(provided that you access single records only, and all with a fully
specified key)
DELETE or SORT is not used on a hashed table since it increases
memory consumption
Sorted table is used for range accesses involving table key or
index accesses
Fields specified in the WHERE condition with the critical operators
NOT and <> (negative SQL statements) cannot be used for a
search using database indexes. Whenever possible formulate SQL
statements positively
When coding IF or CASE, testing conditions are nested so that the
most frequently true conditions are processed first. Also CASE is
used instead of IF when testing multiple fields equal to something
LOOP AT ITAB INTO WORKAREA WHERE K = XXX should be
used instead of LOOP AT ITAB INTO WORKAREA / CHECK ITABK = XXX.
Also READ TABLE INTO WORKAREA should be used instead of
only READ TABLE.
After the APPEND statement inside a loop, the work area that has
been appended is cleared
Internal tables, Work areas & Global Variables are freed when no
longer needed (e.g. using the FREE / REFRESH command),
especially when the tables are large or the program is a batch
program
Do not delete the records of internal table inside the Loop End
loop.
Do not use: LOOP AT ITAB WHERE EQUNR = 00001011.
DELETE ITAB.
ENDLOOP.
Use: DELETE ITAB WHERE EQUNR = 00001011.
Use the MODIFY ITAB ... TRANSPORTING f1 f2 ... for single line,
and MODIFY ITAB ... TRANSPORTING f1 f2 ... WHERE condition
for a set of line, to accelerate the updating of internal table
If possible, Update/Insert statement is used instead of Modify
1. Access transaction ST05. From the initial screen, click the check box for SQL trace,
under the trace requests, click Trace on.
2. Run the program containing the SQL query that needs to be analyzed in the SE38 editor.
3. Come back to ST05 screen, under Trace requests, click Trace off.
4. Click List trace to view the trace of the current statement.
Screen shot of the initial ST05 screen
The basic list trace shows the sequence of database operations that are taking place while a query is
processed, it includes prepare, fetch, open, reopen, execute. In addition the basic list trace also gives the
duration execution for each of the operations with color legend.
Summarizing the basic trace list (menu path: Goto Summary)
A basic trace list can be summarized to see the summation of execution times of similar database
operations. Use menu path: GotoSummary. The above screen shot depicts the summed up execution
time. The summary option lists the summed up execution time of all the queries that the SQL trace has
captured at its runtime, but the identification of a particular query can be done using the PID Process ID
which is displayed as the first column of the above screen shot. For example, 896 is the process ID for
one of the SQL statements.
Summary of a particular trace
To get the total execution time, specifically for a particular SQL Statement, select all the PID
corresponding to it and click summarize in the application toolbar. This leads to a compressed data of
SQL trace as above.
Color legends indicating the processes in a trace 1
Use the menu path: Goto -> Show color legend to know about the color specification in the trace.
Color legends indicating the processes in a trace 2
The above screen shot indicates that the query execution time has exceeded its threshold with the link
pink color. A change in object name is indicated with the change in color to yellow. These colors thereby
indicate whether the query is well written and also the current status of the database server.
Extended list
(From basic trace list: click extended list button in application toolbar to view the extended list). The
extended list shows the cursor id declared for the SQL statement, the connection type also.
Cursors: A cursor is a handle or name for an area in memory in which a parsed statement and other
information for processing the statement are kept; such an area is also called a private SQL area.
Although most Oracle users rely on the automatic cursor handling of the Oracle utilities, the programmatic
interfaces offer application designers more control over cursors. In application development, a cursor is a
named resource available to a program and can be used specifically for the parsing of SQL statements
embedded within the application.
Identical select statements
Use the menu path: Goto Identical Selects to view a comprehensive list of identical select statements
executed during the trace and the number of times they were executed. Identical select statements are
grouped based on the where clause.
Note that identical select statements have similar execution plan used for their processing thereby
saving time of execution and provide increased performance, too.
Identical select statements displayed
The above screen shot shows the list of identical select statements and the number of time they got
executed.
Database Operations Measured by SQL Trace
The SQL Trace analysis helps in measuring the execution time of the following data base operations that
are performed when executing an SQL statement.
1) DECLARE: This operation declares a new cursor and assigns the SQL statement to that cursor
created.
2) PREPARE: This operation converts the SQL statement into native SQL and frames out an execution
plan for that statement.
3) OPEN: This operation opens the declared cursor and passes the parameters for database access.
4) FETCH: This operation passes one or more data records fetched to the database interface of the R/3
system.
5) REOPEN: Once a new select statement is brought in then this operation opens the cursor previously
declared for previous select statement and performs new parameter passing to the database.
6) EXEC: Passes the parameters for the database statement, and executes the statements that change
data in the database (such as UPDATE, DELETE, or INSERT).
Scenario:
The below steps to be followed for Changing the text Sales Order to Billing Request in VA01, VA02, VA03
Transactions.
Go to transaction VA01
Click on Enhance
(Shift+F4)
Click on Edit > Enhancement Operations > Show Implicit Enhancement Options
Enter the Enhancement Implementation, Short text and Click on Create Composite Implementation.
Enter the name for Composite enhancement implementation and Short Text.
Then Click on Creation of Enhancement (Enter)
Click on Yes.
Enter the Title of the created program and Assign Type as Module Pool.
Click on Save.
Save it in Package.
Go to VA02.
Go to VA03.
In this Scenario, I would like to explain about creating a Web Service with a simple scenario.
Creating a Web Service
In the function library (SE37), display the function module.
Open the function Module
: ME_GET_CURRENT_USER_ID
Choose Utilities -> More Utilities -> Creating a Web Service -> From Function Module.
In the following screen, enter the required data and select the checkbox Name Mapping. If the checkbox Name
Mapping is ticked, the wizard accepts the existing names for the end point.
Choose Continue.
In the following screen, enter the required data and select the checkbox Release Service for runtime.
Choose Continue.
Choose Complete.
Select the Web service definition you have created under SOAP Application for RFC-Compliant FMs
Select and expand the ZWEB_GET_CURRENT_USER and select the Web Service as shown in
screen.
You have entered the address of the application server on which the J2EE Engine is running in
transaction WSADMIN under Goto -> Administration Settings.
Fill in values for the method parameters underneath the heading Request if required. Choose Send.
The required values are displayed under the Response heading. The Web service has not been tested
successfully.
In this tutorial, we would use a free web service in an ABAP program which validates an emailid. For more details regarding this web service, click here.
Create a program and use the following code:
REPORT zvalidate_email.
PARAMETERS: p_mail(100) LOWER CASE.
" E-Mail id to be verified
DATA: http_client TYPE REF TO if_http_client .
DATA: w_string TYPE string ,
w_result TYPE string ,
r_str
TYPE string .
DATA: result_tab TYPE TABLE OF string.
START-OF-SELECTION .
CLEAR w_string .
CONCATENATE
'http://www.webservicex.net/ValidateEmail.asmx/IsValidEmail?Email=' p_mail
INTO
w_string .
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url
= w_string
IMPORTING
client
= http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error
= 3
OTHERS
= 4.
CALL METHOD http_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state
= 2.
CALL METHOD http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state
= 2
http_processing_failed
= 3.
CLEAR w_result .
w_result = http_client->response->get_cdata( ).
REFRESH result_tab .
SPLIT w_result AT cl_abap_char_utilities=>cr_lf INTO TABLE result_tab .
READ TABLE result_tab INTO r_str INDEX 2.
IF r_str+44(1) = 't'.
WRITE:/ 'Valid email address'.
ELSE.
WRITE:/ 'Invalid email address'.
ENDIF.
Output:
This document details the procedure in handling the favorites in the ABAP Workbench. I would always
want to add my frequently used objects in the favorites. For our learning purpose, let us add the package
SWDP_DEMO_TUTORIALS (Demo tutorials for Web Dynpro ABAP) to the favorite list.
Go to Transaction SE80 and select Package from the list box. Enter the package name
SWDP_DEMO_TUTORIALS as shown below:
This way, we can add the recently used objects in the favorites list.
To download/Upload favorites from one system to another:
In the favorites, click on Edit as shown below:
Using the Download/Upload buttons, we can either download/upload the favorites from one system to
another.
Here you can observe that there are different types of events available like before saving the data, after
saving the data, before deleting, after deleting and others. Let us go with Creating a new entry.
Click on the button in the Editor column and enter the following code: (Please note that you should also
code FORM and ENDFORM as well).
Check your entries in the database table. You can observe that the date and user name are automatically
filled-in. See the screenshot below:
There would have been many instances where we would have to process large entries in an internal table
with a WHERE condition. This article is intended to demonstrate the comparison between three different
methods in handling this situation.
First Method: The normal method used by most of us. Standard internal table processing using WHERE
condition
Second Method: Same as above, but here we would be using the Sorted table
Third Method: Sorted table and using the Index
Following is the demo program illustrating the above three methods:
REPORT ZINTERNAL_TABLE_OPERATIONS.
* Program to find the best method in reading the internal tables
* Author: Suresh Kumar Parvathaneni
* Type declaration
TYPES:
BEGIN OF TY_MARA,
MATNR LIKE MARA-MATNR,
MTART LIKE MARA-MTART,
END OF TY_MARA.
* Internal table declaration
DATA:
T_MARA TYPE STANDARD TABLE OF TY_MARA,
T_MARA1 TYPE SORTED TABLE OF TY_MARA
WITH NON-UNIQUE KEY MTART.
* Variable declaration
DATA:
W_COUNTER TYPE I,
W_RUNTIME1 TYPE I,
W_RUNTIME2 TYPE I,
W_TABIX LIKE SY-TABIX.
* Table workarea definition
DATA:
WA_MARA TYPE TY_MARA.
SELECT MATNR
" Material Number
MTART
" Material Type
FROM MARA
INTO TABLE T_MARA.
T_MARA1[] = T_MARA[].
* CASE 1: Processing internal table using LOOP..WHERE Condition
GET RUN TIME FIELD W_RUNTIME1.
Records: 132,693
Iteration Using Normal LOOP & Using Sorted table LOOP
No
WHERE
& WHERE
1
34239
35774
2
34271
38250
3
4
34492
34198
36534
35695
3554
3584
Sorted table might have given a better performance here if the field in the WHERE condition is the first
field in the internal table. However, from the above statistics, we can say that method 3 is better than the
other 2 methods. In production environment, the data would be huge and the performance could be much
improved with this simple technique.
I would like to explain about a simple report program to display graphics. The SAP Graphics can be used
for various business purposes.
In this article I am explaining about a simple Sales analysis on a yearly basis.
*&---------------------------------------------------------------------*
*& Report ZGRAPH_TEST
*&
*&---------------------------------------------------------------------*
REPORT ZGRAPH_TEST.
DATA: BEGIN OF TAB OCCURS 5,
CLASS(5) TYPE C,
VAL1(2) TYPE I,
VAL2(2) TYPE I,
VAL3(2) TYPE I,
END OF TAB.
DATA: BEGIN OF OPTTAB OCCURS 1,
C(20),
END OF OPTTAB.
MOVE: 'fan' TO TAB-CLASS,
12 TO TAB-VAL1, 8 TO TAB-VAL2, 15 TO TAB-VAL3.
APPEND TAB.
CLEAR TAB.
MOVE: 'cool' TO TAB-CLASS,
15 TO TAB-VAL1, 10 TO TAB-VAL2, 18 TO TAB-VAL3.
APPEND TAB.
CLEAR TAB.
MOVE: 'DA' TO TAB-CLASS,
17 TO TAB-VAL1, 11 TO TAB-VAL2, 20 TO TAB-VAL3.
APPEND TAB.
CLEAR TAB.
OPTTAB = 'FIFRST = 3D'.
APPEND OPTTAB.
"// Grafik-Typ
OPTTAB = 'P3TYPE = TO'.
APPEND OPTTAB.
"// Objektart
OPTTAB = 'P3CTYP = RO'.
APPEND OPTTAB.
"// Farben der Objekte
OPTTAB = 'TISIZE = 2'.
APPEND OPTTAB.
"// Haupttitelgre
OPTTAB = 'CLBACK = X'.
APPEND OPTTAB.
"// Background Color
CALL FUNCTION 'GRAPH_MATRIX_3D'
EXPORTING
COL1
= '1997'
COL2
= '1998'
COL3
= '1999'
DIM2
= 'Products'
DIM1
TITL
TABLES
DATA
OPTS
EXCEPTIONS
OTHERS
LEAVE PROGRAM.
= 'Years'
= 'Sales In Rs. Crores'
= TAB
= OPTTAB
= 1.
Results :
Execute the report program for an output shown below.
SE38
SE37
SE24
SE37
Go to Utilities Settings
Click on Front-end Editor (New) as shown below
Click
Display Features
Following are some of the features that could be observed while writing the code:
Line Numbers
As observed in the above screenshot, the new ABAP TM editor displays the line numbers for easy navigation
through the code.
Changed line indicators
The changed lines in the current session are marked with
These indicators would vanish once you come out of the program.
Bookmarks
Bookmarks allow in navigating and code editing. There are 9 numbered bookmarks provided by SAP and
unlimited unnumbered bookmarks. Bookmarks could be accessed by the right click of the mouse in the
Indicator Margin (The complete left portion of the ABAP TM editor).
To set a bookmark, right click on the Indicative Margin, click on Bookmarks --> Bookmark 0 (Bookmarks are
numbered 0 to 9). A Blue flag with the bookmark number would appear on the Indicative Margin.
To navigate to any bookmark marked earlier, right click on the Indicative Margin, Go to Bookmark --> Bookmark
0.
Code Hints
Code hints appear as you type in ABAP TM editor. For example, if you start typing for Parameters, following
occurs:
Window Splitter
The window splitter allows you to work on different parts of the code simultaneously.
The window could be set to splitter mode by double clicking the splitter line above the
vertical scrollbar (shown below).
Using this, you can design how the screen should look like, For example, you can dictate how the
comments should appear (like Font, size, foreground color and background color). Let us take the same
comments section for our scenario here.
Comments are currently displayed as shown below:
Now click on the options button and select Fonts and Colors. Select Comments from the list box:
Now change the way you would like the options to appear in this section:
You would observe the code templates available for use with the editor. Click on any code template to
understand further.
Above screenshot is for DO. We would use this for our demo purpose to better understand the code
template.
Write some sample code in your editor.
Now select your program code and click the right button of the mouse. Select -> Format -> Surround by
template -> Do () (as shown in the following screenshot)
Select your code and click on right button. Select Format -> Extract template
Click on OK.
Now we need to define the position where the selected text (surrounded text) to appear.
Click
on
the
empty
line
between
form
and
endform
and
click
on
Insert
tag
Now just enter the form name to complete your subroutine definition.
Setting Break-points:
Open the new ABAP editor and write some sample code in it.
Enter the Title of the Program And Select the Type as Executable Program.
And click on save. Save it in a Relevant Package.
Go to T-code SE41
Enter the Program name and Status name.
Click on create
Click
on
Menu
Bar.
Click on Continue.
Created
Title
Displayed.
Click on Save.
*&---------------------------------------------------------------------*
*& Report ZMENU_PAINTER
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZMENU_PAINTER.
TABLES: MARA.
DATA: MATNR TYPE MARA-MATNR,
ERSDA TYPE MARA-ERSDA,
ERNAM TYPE MARA-ERNAM,
DISPLAY TYPE C,
SAVE TYPE C,
DELETE TYPE C,
CLEAR TYPE C,
EXIT TYPE C,
OK_CODE LIKE SY-UCOMM.
CALL SCREEN 101.
*&---------------------------------------------------------------------*
*&
Module STATUS_0101 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE STATUS_0101 OUTPUT.
SET PF-STATUS 'ZMENU'.
SET TITLEBAR 'ZMENU_PAINTER'.
CASE SY-UCOMM.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'BACK'.
LEAVE PROGRAM.
WHEN 'DISPLAY'.
SELECT SINGLE ERSDA ERNAM FROM MARA INTO (MARA-ERSDA, MARA-ERNAM) WHERE MATNR
= MARA-MATNR.
WHEN 'CLEAR'.
CLEAR MARA.
ENDCASE.
ENDMODULE.
" STATUS_0101 OUTPUT
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_0101 INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0101 INPUT.
ENDMODULE.
" USER_COMMAND_0101 INPUT
Enter MARA in the Table/Fieldname Text Box Then click on Get From Dictionary.
Output:
Enter the Material number and Press Display.
Click on Display.
F5 Clear
F6 Display
F7 Exit.
Scenario: This blog is to explain the creation of Dynamic Variant for report selection screen.
Let us understand What is Dynamic Variant? Dynamic Variant consists of selection variable for a selection
screen item where in a formula can be defined. For example: On the selection screen of a report, take a Date
field, which needs to be dynamic. From Date should be Current date 15 and To Date should be Current
Date. In this way the report when run with this variant, it would be possible to retrieve all those records which
are past 15 days entries from now.
Step 1: Go to transaction SE38 to specify the Program name and select Variant radio button and
Display.
Then it will lead you to next screen ABAP:Variants Initial Screen as shown below: Specify the variant
which needs to be created or changed.
Step2: Specify all those values which are static on the selection screen in this step. Then click Variant
Attributes to define selection variable for Date Created on the selection screen.
Step 3: In this step, provide suitable meaning for the variant. As we need to define selection variable for
Date created item on selection screen, check the box under L as shown in the selection screen below:
Step 4: In the previous step, select Selection Variables on the menu. It leads to the next screen as
shown below. As we have decided to create selection variable for Date created item only, in this screen
you get to see the variable as Date created. Here you are provided with three options.
T: Table variable from TVARV
D: Dynamic Date Calculation
B: User defined Variables.
From the provided options as per our requirement select D option. This can be done by clicking the
Traffic lights under Das shown below to know that the particular option is selected.
Now click the black arrow as shown in the screenshot below and you will be prompted with search help of
different formulas for the selection variable.
Step 5: Find the suitable formula as Current date xxx, current date + yyy and select it. This will lead
you to the next screen to enter the values for xxx and yyy. So, provide values as 15 for xxx and 0 for yyy.
Save the variant and this will conclude the creation of dynamic variant with the help of selection variable.
This variant can also be used in the background jobs.
Go to SE61 and create a general text TX like the one shown below.
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZGB_TEST_SEARCH_HELP
.
* INTERNAL TABLE FOR STORING NAMES IN SELECTION LIST
data: begin of t_itab occurs 0,
name(10) type c,
end of t_itab.
*FIELDNAME AND TAB NAME FOR THE SELECTION
DATA :field_tab LIKE dfies OCCURS 0 WITH HEADER LINE.
*THE TABLE FOR RETURNING THE NAME OF THE SELECTED ITEM
DATA : return_tab LIKE ddshretval OCCURS 0 WITH HEADER LINE.
*START THE SELECTION SCREEN BLOCK
selection-screen begin of block ss1 with frame.
parameters: p_name1(10) type c.
selection-screen end of block ss1.
*&---------------------------------------------------------------------*
*&
*
*& F4 Help for p_name1
*
*&---------------------------------------------------------------------*
at selection-screen on value-request for p_name1.
*CLEAR ALL EXISTING DATA
*TO BE DONE EVERYTIME F4 HELP IS REQUESTED
REFRESH t_itab.
REFRESH field_tab.
field_tab-fieldname = 'ERNAM'.
field_tab-tabname = 'VBAK'.
APPEND field_tab.
t_itab-name = 'Andrews'.
append t_itab.
t_itab-name = 'Jennie'.
append t_itab.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
*
DDIC_STRUCTURE
= ' '
retfield
= field_tab-fieldname
*
PVALKEY
= ' '
*
DYNPPROG
= ' '
*
DYNPNR
= ' '
*
DYNPROFIELD
= ' '
*
STEPL
= 0
WINDOW_TITLE
= 'Select name'
*
VALUE
= ' '
*
VALUE_ORG
= 'C'
*
MULTIPLE_CHOICE
= ' '
*
DISPLAY
= ' '
*
CALLBACK_PROGRAM
= ' '
*
CALLBACK_FORM
= ' '
*
MARK_TAB
=
* IMPORTING
*
USER_RESET
=
tables
value_tab
= t_itab
*
*
*
FIELD_TAB
= field_tab
RETURN_TAB
= return_tab
*
DYNPFLD_MAPPING
=
EXCEPTIONS
PARAMETER_ERROR
= 1
NO_VALUES_FOUND
= 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.
else.
p_name1 = return_tab-fieldval.
ENDIF.
*&---------------------------------------------------------------------*
*&
*
*& F1 Help for p_name1
*
*&---------------------------------------------------------------------*
at selection-screen on help-request for p_name1.
CALL FUNCTION 'DSYS_SHOW_FOR_F1HELP'
EXPORTING
*
APPLICATION
= 'SO70'
dokclass
= 'TX'
DOKLANGU
= SY-LANGU
dokname
= 'Z_GAURAB_DEMO'
*
DOKTITLE
= 'This appears as bold title'
*
HOMETEXT
= ' '
*
OUTLINE
= ' '
*
VIEWNAME
= 'STANDARD'
*
Z_ORIGINAL_OUTLINE
= ' '
*
CALLED_FROM_SO70
= ' '
*
SHORT_TEXT
= ' '
*
APPENDIX
= ' '
* IMPORTING
*
APPL
=
*
PF03
=
*
PF15
=
*
PF12
=
EXCEPTIONS
CLASS_UNKNOWN
= 1
OBJECT_NOT_FOUND
= 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.
2.
HELP_OBJECT_SHOW_FOR_FIELD
HELP_OBJECT_SHOW
Create a class that keeps track of a bank account balance. Then write a program to use this class.
Steps involved:
Declare a PRIVATE attribute BALANCE of type DMBTR to store the account balance.
DEPOSIT (Adds a deposit amount to the balance and returns the new balance)
WITHDRAW (Subtracts a deposit amount from the balance and returns the
new balance.)
EXCEPTIONS INSUFFICIENT_FUNDS
Write a program called Z_USE_ACCOUNT_xx, where xx is the last two digits of your
logon ID. This program should do the following:
o
"Extra Credit": If you have extra time, try any of the following:
Replace the SET_BALANCE method with a constructor. Pass the opening balance when you
instantiate the account object.
Create a static attribute and methods to set and get the name of the bank that holds the
accounts.
Place the mouse cursor in DEPOSIT and hit the Parameters button.
And WITHDRAW
We can see the attributes and methods by pressing Display object list button on top.
Now we are almost done creating the object. Press CTRL + F3 to activate or hit the Matchstick.
We will see this in the status
Now we are done building the global class we can test it. Press F8.
We get an exception.
Given below is an example code for using the global class we defined.
REPORT ZGB_OOPS_BANK
begin
p_amnt
p_dpst
p_wdrw
of
block
type
type
type
a.
dmbtr,
dmbtr,
dmbtr.
acct1->set_balance(
p_amnt
).
bal
=
acct1->deposit(
write:/ 'Deposited ', p_dpst ,' bucks making balance to ', bal.
p_dpst
).
bal
=
acct1->withdraw(
write:/ 'Withdrew ', p_wdrw ,' bucks making balance to ', bal.
p_wdrw
).
Under
IMPORT
Tab,
define
the
following
variables
In
the
Source
Now set the function module as Remote-enabled module in the attributes tab.
Code
The
Technical
Settings
Tab,
enter
the
system
details
However establishing a connection will not ensure logging on to the target system. For that we have to
test REMOTE LOGON.
Press the REMOTE LOGON button
If we can see this
And this
However if we see the screen as shown below then there is an authentication failure (user-id or password
is wrong).
The new connection will become visible in the SM59 list like this.
After establishing the connection, let us create a program, which would trigger the RFC in D05 system.
Go to SE38 and create a program ZGB_RFC
Write the following code
Material number
Identification
Long text
LINE.
FILETYPE
= 'DAT'
ITEM
= ' '
FILEMASK_MASK
= ' '
FILEMASK_TEXT
= ' '
FILETYPE_NO_CHANGE
= ' '
FILEMASK_ALL
= ' '
FILETYPE_NO_SHOW
= ' '
LINE_EXIT
= ' '
USER_FORM
= ' '
USER_PROG
= ' '
SILENT
= 'S'
IMPORTING
FILESIZE
=
CANCEL
=
ACT_FILENAME
=
ACT_FILETYPE
=
TABLES
DATA_TAB
= T_UPLOAD
EXCEPTIONS
CONVERSION_ERROR
= 1
INVALID_TABLE_WIDTH
= 2
INVALID_TYPE
= 3
NO_BATCH
= 4
UNKNOWN_ERROR
= 5
GUI_REFUSE_FILETRANSFER
= 6
OTHERS
= 7
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
SORT T_UPLOAD BY MATNR ID.
ENDFORM.
" upload_file
*&---------------------------------------------------------------------*
*&
Form place_longtext
*&---------------------------------------------------------------------*
* This routine places the text in MM02 transaction
*----------------------------------------------------------------------*
* No interface parameters are passed
*----------------------------------------------------------------------*
FORM PLACE_LONGTEXT .
LOOP AT T_UPLOAD.
T_LINE-TDFORMAT = 'ST'.
T_LINE-TDLINE = T_UPLOAD-LTEXT.
APPEND T_LINE.
IF T_UPLOAD-ID EQ 'BT'.
MOVE T_UPLOAD-MATNR TO LV_VALUE.
MOVE 'GRUN' TO W_GRUN.
"Test ID for Basic data text
PERFORM CREATE_TEXT USING W_GRUN LV_VALUE.
ENDIF.
IF T_UPLOAD-ID EQ 'IT'.
CLEAR W_GRUN.
MOVE T_UPLOAD-MATNR TO LV_VALUE.
MOVE 'PRUE' TO W_GRUN.
"Test ID for Inspection text
PERFORM CREATE_TEXT USING W_GRUN LV_VALUE.
ENDIF.
IF T_UPLOAD-ID EQ 'IC'.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
CLEAR W_GRUN.
MOVE : T_UPLOAD-MATNR TO LV_VALUE,
'IVER' TO W_GRUN.
comment
PERFORM CREATE_TEXT USING W_GRUN LV_VALUE.
ENDIF.
ENDLOOP.
ENDFORM.
" place_longtext
System Debugging
By Selvamani
Consider the following program, which contains a simple call to the function module
ICON_SHOW.
Set a breakpoint at the CALL FUNCTION statement and now execute the program.
Ensure that the system debugging is switched off, by selecting Settings system debugging.
On pressing F5, instead of going into the code of the function module, the function module is
executed and the following pop-up is shown:
Select a record and press CONTINUE, the program is executed without going into the debug
mode of the function module. Reason?
Now go to the function module ICON_SHOW. Select Goto Main Program.
From the above screenshot, it is understood that the program status is S (System program). In
order to debug the system program, we need to set the system debugging ON. Now repeat the
above debugging by setting system debugging ON. This time, we should be able to debug the
function module.
Now try debugging the program with system debugging off. This time, the debug point will not
even reach the CALL FUNCTION statement. Once you turn the system debugging ON, both our
program and the standard function module could be debugged.
If the call to the function module does not handle EXCEPTIONS, then the message
is issued (in this case the error message is issued)
If the calling program handles the exception, then no message is issued. The
calling program would have the message details in the standard message variables
SY-MSGID, SY-MSGV1 and others. So in our case, the calling program would have
the information about the material and plant combination that triggered the
exception.
LSMW is basicaly designed for a fuctional consultant who do not do much coding but
need to explore the fuctionality while BDC is designed for a technical consultant.
LSMW offers different techinque for migrating data: Direct input ,BAPI,Idoc,Batch input
LSMW is basically for standard SAP application while bdc basically for customized
application.
Following are the performance standards need to be following in writing ABAP programs:
1.
Unused/Dead code
Avoid leaving unused code in the program. Either comment out or
delete the unused situation. Use program --> check --> extended
program to check for the variables, which are not used statically.
2.
Subroutine Usage
For good modularization, the decision of whether or not to execute a
subroutine should be made before the subroutine is called. For
example:
This is better:
IF f1 NE 0.
PERFORM sub1.
ENDIF.
FORM sub1.
...
ENDFORM.
Than this:
PERFORM sub1.
FORM sub1.
IF f1 NE 0.
...
ENDIF.
ENDFORM.
3.
Usage of IF statements
When coding IF tests, nest the testing conditions so that the outer
conditions are those which are most likely to fail. For logical
expressions with AND , place the mostly likely false first and for the
OR, place the mostly likely true first.
Example - nested IF's:
IF (least likely to be true).
IF (less likely to be true).
IF (most likely to be true).
ENDIF.
ENDIF.
ENDIF.
Example - IF...ELSEIF...ENDIF :
IF (most likely to be true).
ELSEIF (less likely to be true).
ELSEIF (least likely to be true).
ENDIF.
Example - AND:
IF (least likely to be true) AND
(most likely to be true).
ENDIF.
Example - OR:
IF (most likely to be true) OR
(least likely to be true).
4.
5.
MOVE statements
When records a and b have the exact same structure, it is more efficient to MOVE a TO b
than to MOVE-CORRESPONDING a TO b.
7.
8.
Use the SELECT into <itab> to buffer the necessary rows in an internal table, then
use a READ TABLE WITH KEY ... BINARY SEARCH in place of the SELECT
SINGLE command. Note that this only make sense when the table you are
buffering is not too large (this decision must be made on a case by case basis).
9.
use READ TABLE WITH KEY BINARY SEARCH for better performance.
There are a few cases where one command is better than two. For example:
Use:
append <tab_wa> to <tab>.
Instead of:
<tab> = <tab_wa>.
append <tab> (modify <tab>).
And also, use:
if not <tab>[] is initial.
Instead of:
describe table <tab> lines <line_counter>.
if <line_counter> > 0.
ENDIF.
ENDIF.
* At selection screen
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
* Start of selection
START-OF-SELECTION.
PERFORM f_table_definition USING p_table.
PERFORM f_upload_data USING p_file.
PERFORM f_prepare_table USING p_table.
PERFORM f_process_data.
IF p_nodb IS INITIAL.
PERFORM f_modify_table.
ENDIF.
IF p_list = 'X'.
PERFORM f_list_records.
ENDIF.
* End of selection
END-OF-SELECTION.
*---------------------------------------------------------------------*
* FORM f_table_definition *
*---------------------------------------------------------------------*
* --> VALUE(IN_TABLE) *
*---------------------------------------------------------------------*
FORM f_table_definition USING value(in_table).
DATA: l_tname TYPE tabname,
l_state TYPE ddgotstate,
l_dd02v TYPE dd02v.
l_tname = in_table.
CALL FUNCTION 'DDIF_TABL_GET'
EXPORTING
name = l_tname
IMPORTING
gotstate = l_state
dd02v_wa = l_dd02v
TABLES
dd03p_tab = it_dd03p
EXCEPTIONS
illegal_input = 1
OTHERS = 2.
IF l_state NE 'A'.
write_error 'does not exist or is not active' space.
ENDIF.
IF l_dd02v-tabclass NE 'TRANSP' AND
l_dd02v-tabclass NE 'CLUSTER'.
write_error 'is type' l_dd02v-tabclass.
ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
* FORM f_prepare_table *
*---------------------------------------------------------------------*
* --> VALUE(IN_TABLE) *
*---------------------------------------------------------------------*
FORM f_prepare_table USING value(in_table).
DATA: l_tname TYPE tabname,
lt_ftab TYPE lvc_t_fcat.
l_tname = in_table.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = l_tname
CHANGING
ct_fieldcat = lt_ftab
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
WRITE: / 'Error while building field catalog'.
STOP.
ENDIF.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_ftab
IMPORTING
ep_table = it_file.
ASSIGN it_file->* TO <table>.
CREATE DATA is_file LIKE LINE OF <table>.
ASSIGN is_file->* TO <data>.
ENDFORM.
*---------------------------------------------------------------------*
* FORM f_upload_data *
*---------------------------------------------------------------------*
* --> VALUE(IN_FILE) *
*---------------------------------------------------------------------*
FORM f_upload_data USING value(in_file).
DATA: l_file TYPE string,
l_ltext TYPE string.
WRITE: 'ok'.
FORMAT RESET.
ELSEIF is_dd03p-datatype NE 'CLNT'.
FORMAT COLOR COL_NEGATIVE.
WRITE: 'error'.
FORMAT RESET.
l_missk = 'X'.
ENDIF.
ENDLOOP.
* Log other fields
SKIP.
FORMAT COLOR COL_HEADING.
WRITE: /3 'Other fields'.
FORMAT RESET.
LOOP AT it_dd03p INTO is_dd03p WHERE keyflag IS initial.
WRITE: /3 is_dd03p-fieldname.
READ TABLE it_fields WITH KEY table_line = is_dd03p-fieldname
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
WRITE: 'X'.
ENDIF.
ENDLOOP.
* Missing key field
IF l_missk = 'X'.
SKIP.
WRITE: /3 'Missing key fields - no further processing'.
STOP.
ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
* FORM f_process_data *
*---------------------------------------------------------------------*
FORM f_process_data.
DATA: l_ltext TYPE string,
l_stext TYPE text40,
l_field TYPE fieldname,
l_datat TYPE c.
LOOP AT it_rdata INTO is_rdata FROM 2.
l_ltext = is_rdata.
LOOP AT it_fields INTO l_field.
ASSIGN COMPONENT l_field OF STRUCTURE <data> TO <fs>.
IF sy-subrc = 0.
* Field value comes from file, determine conversion
DESCRIBE FIELD <fs> TYPE l_datat.
CASE l_datat.
WHEN 'N'.
SPLIT l_ltext AT p_separ INTO l_stext l_ltext.
WRITE l_stext TO <fs> RIGHT-JUSTIFIED.
OVERLAY <fs> WITH '0000000000000000'. "max 16
WHEN 'P'.
ENDIF.
IF is_dd03p-rollname = 'AEDAT'.
ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE <data>
TO <fs>.
<fs> = sy-datum.
ENDIF.
IF is_dd03p-rollname = 'AETIM'.
ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE <data>
TO <fs>.
<fs> = sy-uzeit.
ENDIF.
IF is_dd03p-rollname = 'AENAM'.
ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE <data>
TO <fs>.
<fs> = sy-uname.
ENDIF.
APPEND <data> TO <table>.
ENDIF.
ENDLOOP.
ENDFORM.
*---------------------------------------------------------------------*
* FORM f_modify_table *
*---------------------------------------------------------------------*
FORM f_modify_table.
SKIP.
IF p_save = 'X'.
MODIFY (p_table) FROM TABLE <table>.
ELSEIF p_dele = 'X'.
DELETE (p_table) FROM TABLE <table>.
ELSE.
EXIT.
ENDIF.
IF sy-subrc EQ 0.
FORMAT COLOR COL_POSITIVE.
IF p_save = 'X'.
WRITE: /3 'Modify table OK'.
ELSE.
WRITE: /3 'Delete table OK'.
ENDIF.
FORMAT RESET.
IF p_test IS INITIAL.
COMMIT WORK.
ELSE.
ROLLBACK WORK.
WRITE: '- test only, no update'.
ENDIF.
ELSE.
FORMAT COLOR COL_NEGATIVE.
WRITE: /3 'Error while modifying table'.
FORMAT RESET.
ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
* FORM f_list_records *
*---------------------------------------------------------------------*
FORM f_list_records.
DATA: l_tleng TYPE i,
l_lasti TYPE i,
l_offst TYPE i.
* Output width
l_tleng = 1.
LOOP AT it_dd03p INTO is_dd03p.
l_tleng = l_tleng + is_dd03p-outputlen.
IF l_tleng LT sy-linsz.
l_lasti = sy-tabix.
l_tleng = l_tleng + 1.
ELSE.
l_tleng = l_tleng - is_dd03p-outputlen.
EXIT.
ENDIF.
ENDLOOP.
* Output header
SKIP.
FORMAT COLOR COL_HEADING.
WRITE: /3 'Contents'.
FORMAT RESET.
ULINE AT /3(l_tleng).
* Output records
LOOP AT <table> ASSIGNING <data>.
LOOP AT it_dd03p INTO is_dd03p FROM 1 TO l_lasti.
IF is_dd03p-position = 1.
WRITE: /3 sy-vline.
l_offst = 3.
ENDIF.
ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE <data> TO <fs>.
l_offst = l_offst + 1.
IF is_dd03p-decimals LE 2.
WRITE: AT l_offst <fs>.
ELSE.
WRITE: AT l_offst <fs> DECIMALS 3.
ENDIF.
l_offst = l_offst + is_dd03p-outputlen.
WRITE: AT l_offst sy-vline.
ENDLOOP.
ENDLOOP.
* Output end
ULINE AT /3(l_tleng).
ENDFORM.
2.
3.
Warning% Assume that an interval is defined from 1 to 1000. If you want to issue a warning
at the number 900, enter 10 (%) here.
4.
5.
6.
7.
8.
9.
10. Click Insert and then SAVE. The number range object is generated.
Testing the Number Range Object:
We can use the function module, NUMBER_GET_NEXT, to get the next number of
any number range object.
Following is a test program to get the next available number of the object created
above:
REPORT zsnro_test.
DATA:
NUMBER TYPE I.
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
nr_range_nr = '01'
object = 'ZDEMO'
IMPORTING
NUMBER = NUMBER
EXCEPTIONS
INTERVAL_NOT_FOUND = 1
NUMBER_RANGE_NOT_INTERN = 2
OBJECT_NOT_FOUND = 3
QUANTITY_IS_0 = 4
QUANTITY_IS_NOT_1 = 5
INTERVAL_OVERFLOW = 6
BUFFER_OVERFLOW = 7
OTHERS = 8
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
= <t_itab>.
ep_table
= t_newtable.
fieldvalue NO-GAPS.
= <t_dyntable>.
Infotype creation
Custom Infotype can be created by following these steps:
1. Go to transaction PM01.
2. Provide the Infotype number. The number should be from 9000 to 9999.
Avoid providing the Infotype
number that already exists.
3. See to it that the Employee Infotype and PS structure radio buttons have
been selected.
All Push button
4. Select the All Push button as shown in above figure. The following below
shown screen is
displayed.
5. Maintain the structure (Provide fields) which will be included in our current
custom Infotype. The
PAKEY/PBKEY and PSHD1 structures are not required to be provided while
creating the custom
Infotype. They are included in the custom Infotype by default.
6. Save and activate the structure. Go to the initial screen of PM01
transaction.
Infotype characteristics
Push button
Technical Attributes
Push button
7. Select the Infotype characteristics push button shown in the above
figure. The below screen is
displayed.
New Entries Push button
8. Select the New Entries push button shown in the above figure. The below
shown screen is
displayed.
9. Provide the Current custom Infotype number (9002) and description for
the Infotype. Also provide the
Time constraint based on the requirement, 2000 as the single screen and
3000 as the list screen.
10. The Subtype Obligatory check box needs to be selected if we intend to
make the subtype as mandatory
field. This step is useful when we come through the step 11 (Subtype
maintenance).This step can be
skipped if we dont want the subtype for an Infotype.
11. Save the Infotype details and go back to the initial screen of PM01
transaction.
Additional steps
If a subtype needs to be maintained for the Infotype then some additional
steps also needs to be performed
before providing Infotype characteristics (step number 7).
12. Select the Technical attributes (Figure shown in step 6) from the initial
screen of PM01 transaction .The
below shown figure is displayed.
13. Select the change button on application tool bar. The dialog module in
the above screen then becomes
editable.
14. Select the Infotype 9002 and select the details button as shown in the
above figure (In change mode).
The below shown figure is displayed.
Display/Change button Details
15. Provide the Subtype field of the Infotype, Subtype table as T591A and
Subty.text table as T591S.
16. Save and go back to the initial PM01 screen.
17. The subtypes for an Infotype can be entered via the maintenance view
V_T591A.
18. Continue with step 7 as required.
BEGIN OF T_CRMEMO,
VBELN TYPE VBAK-VBELN,
POSNR TYPE VBAP-POSNR,
ERDAT TYPE VBAK-ERDAT,
AUART TYPE VBAK-AUART,
AUGRU TYPE VBAK-AUGRU,
WAERK TYPE VBAK-WAERK,
VKORG TYPE VBAK-VKORG,
VTWEG TYPE VBAK-VTWEG,
SPART TYPE VBAK-SPART,
VDATU TYPE VBAK-VDATU,
BSTNK TYPE VBAK-BSTNK,
BSARK TYPE VBAK-BSARK,
BSTDK TYPE VBAK-BSTDK,
AEDAT TYPE VBAK-AEDAT,
BUKRS_VF TYPE VBAK-BUKRS_VF,
MATNR TYPE VBAP-MATNR,
ZMENG TYPE VBAP-ZMENG,
ZIEME TYPE VBAP-ZIEME,
END OF T_CRMEMO,
BEGIN OF T_CRMEMO_CHANGE,
VBELN(90) TYPE C,
POSNR TYPE VBAP-POSNR,
ERDAT TYPE VBAK-ERDAT,
AUART TYPE VBAK-AUART,
AUGRU TYPE VBAK-AUGRU,
WAERK TYPE VBAK-WAERK,
VKORG TYPE VBAK-VKORG,
VTWEG TYPE VBAK-VTWEG,
SPART TYPE VBAK-SPART,
VDATU TYPE VBAK-VDATU,
BSTNK TYPE VBAK-BSTNK,
BSARK TYPE VBAK-BSARK,
BSTDK TYPE VBAK-BSTDK,
AEDAT TYPE VBAK-AEDAT,
BUKRS_VF TYPE VBAK-BUKRS_VF,
MATNR TYPE VBAP-MATNR,
ZMENG TYPE VBAP-ZMENG,
ZIEME TYPE VBAP-ZIEME,
END OF T_CRMEMO_CHANGE,
BEGIN OF T_MVKE,
MATNR TYPE MVKE-MATNR,
VKORG TYPE MVKE-VKORG,
VTWEG TYPE MVKE-VTWEG,
MTPOS TYPE MVKE-MTPOS,
END OF T_MVKE,
BEGIN OF T_ORDERS,
VBELV
TYPE VBFA-VBELV,
POSNV
TYPE VBFA-POSNV,
VBELN
TYPE VBFA-VBELN,
POSNN
TYPE VBFA-POSNN,
VBTYP_N TYPE VBFA-VBTYP_N,
END OF T_ORDERS,
BEGIN OF T_EKPO,
EBELN
TYPE EKKO-EBELN,
EBELP
TYPE EKPO-EBELP,
WAERS
TYPE EKKO-WAERS,
MENGE
TYPE EKPO-MENGE,
MEINS
TYPE EKPO-MEINS,
NETPR
TYPE EKPO-NETPR,
PEINH
TYPE EKPO-PEINH,
mwskz
TYPE EKPO-mwskz,
TXJCD
TYPE EKPO-TXJCD,
END OF T_EKPO,
BEGIN OF T_EKBE,
EBELN
TYPE EKBE-EBELN,
EBELP
TYPE EKBE-EBELP,
ZEKKN
TYPE EKBE-ZEKKN,
VGABE
TYPE EKBE-VGABE,
GJAHR
TYPE EKBE-GJAHR,
BELNR
TYPE EKBE-BELNR,
BUZEI
TYPE EKBE-BUZEI,
END OF T_EKBE,
BEGIN OF T_RBKP,
BELNR
TYPE RBKP-BELNR,
GJAHR
TYPE RBKP-GJAHR,
BLDAT
TYPE RBKP-BLDAT,
BUDAT
TYPE RBKP-BUDAT,
XBLNR
TYPE RBKP-XBLNR,
LIFNR
TYPE RBKP-LIFNR,
RMWWR
TYPE RBKP-RMWWR,
WMWST1 TYPE RBKP-WMWST1,
XRECH
TYPE RBKP-XRECH,
STBLG
TYPE RBKP-STBLG,
END OF T_RBKP,
BEGIN OF T_CDHDR,
OBJECTCLAS TYPE
OBJECTID
TYPE
CHANGENR
TYPE
UDATE
TYPE
UTIME
TYPE
END OF T_CDHDR,
CDHDR-OBJECTCLAS,
CDHDR-OBJECTID,
CDHDR-CHANGENR,
CDHDR-UDATE,
CDHDR-UTIME,
BEGIN OF T_CDPOS,
OBJECTCLAS TYPE
OBJECTID
TYPE
CHANGENR
TYPE
TABNAME
TYPE
TABKEY
TYPE
FNAME
TYPE
CHNGIND
TYPE
VALUE_NEW TYPE
VALUE_OLD TYPE
END OF T_CDPOS,
CDHDR-OBJECTCLAS,
CDHDR-OBJECTID,
CDHDR-CHANGENR,
CDPOS-TABNAME,
CDPOS-TABKEY,
CDPOS-FNAME,
CDPOS-CHNGIND,
CDPOS-VALUE_NEW,
CDPOS-VALUE_OLD,
BEGIN OF T_CHANGE_DOCS,
OBJECTCLAS TYPE CDHDR-OBJECTCLAS,
OBJECTID
TYPE CDHDR-OBJECTID,
CHANGENR
TYPE CDHDR-CHANGENR,
UDATE
TYPE CDHDR-UDATE,
UTIME
TYPE CDHDR-UTIME,
TABNAME
TYPE CDPOS-TABNAME,
TABKEY
TYPE CDPOS-TABKEY,
FNAME
TYPE CDPOS-FNAME,
CHNGIND
TYPE CDPOS-CHNGIND,
VALUE_NEW TYPE CDPOS-VALUE_NEW,
VALUE_OLD TYPE CDPOS-VALUE_OLD,
END OF T_CHANGE_DOCS,
BEGIN OF T_SUCCESS,
crmemo
TYPE VBAK-vbeln,
cmemo
TYPE VBAK-vbeln,
orders
TYPE VBAK-vbeln,
po
TYPE VBAK-vbeln,
miro_no
TYPE VBAK-vbeln,
text(20) TYPE C,
END OF T_SUCCESS,
BEGIN OF T_ERROR,
crmemo TYPE VBAK-vbeln,
cmemo
TYPE VBAK-vbeln,
orders
TYPE VBAK-vbeln,
po
TYPE VBAK-vbeln,
miro_no
TYPE VBAK-vbeln,
text(100) TYPE C,
END OF T_ERROR.
*----------------------------------------------------------------------*
*
WORKAREA DECLARATION
*----------------------------------------------------------------------*
DATA:
WA_CRMEMO TYPE T_CRMEMO,
WA_CRMEMO_CHANGE TYPE T_CRMEMO_CHANGE,
WA_MVKE
TYPE T_MVKE,
WA_ORDERS TYPE T_ORDERS,
WA_CMEMO
TYPE T_ORDERS,
WA_PO
TYPE T_ORDERS,
WA_EKPO
TYPE T_EKPO,
WA_EKBE
TYPE T_EKBE,
WA_EKBE_TEMP TYPE T_EKBE,
WA_RBKP
TYPE T_RBKP,
WA_RBKP_TMP TYPE T_RBKP,
WA_CDHDR
TYPE T_CDHDR,
WA_CDPOS
TYPE T_CDPOS,
WA_CHANGE_DOCS TYPE T_CHANGE_DOCS,
WA_CRMEMO_MR8M TYPE T_CRMEMO,
WA_SUCCESS TYPE T_SUCCESS,
WA_ERROR
TYPE T_ERROR,
WA_SUCCESS_MR8M TYPE T_SUCCESS,
WA_ERROR_MR8M
TYPE T_ERROR.
*--Work area for all the internal tables used for Sending Mail
DATA :
WA_OBJPACK TYPE SOPCKLSTI1,
v_tabix
format
type sy-tabix.
*----------------------------------------------------------------------*
* CONSTANTS
*
*----------------------------------------------------------------------*
CONSTANTS:
C_X(1)
TYPE C
VALUE 'X',
" Constant X or Flag
C_E(1)
TYPE C
VALUE 'E',
" For Error check
c_v(1)
TYPE C
VALUE 'V',
" For PO Docs
c_o(1)
TYPE C
VALUE 'O',
" For Order Docs
c_c(1)
TYPE C
VALUE 'C',
" For Credit Memo Docs
c_k(1)
TYPE C
VALUE 'K',
" For CR Memo Docs
c_u(1)
TYPE C
VALUE 'U',
" For Change tables
Update
c_ali(3)
TYPE C
VALUE 'ALI',
" For ALI Format
c_vbak(4)
TYPE C
VALUE 'VBAK',
" For Change docs table
C_01(2)
TYPE C
VALUE '01',
" For Serial No. &
Reversal Reason
C_02(2)
TYPE C
VALUE '02',
" For Reversal Reason
c_blart
TYPE bkpf-blart VALUE 'RE',
" Document type
C_MTPOS
TYPE MVKE-MTPOS VALUE 'BANS',
" Item Category group
C_AUGRU(5)
TYPE C
VALUE 'AUGRU',
" Reason Code
C_0000500205(10) TYPE C
VALUE '0000500205', " GL Account #
C_VERKBELEG(9)
TYPE C
VALUE 'VERKBELEG'. " For Object Class
*-- Horizontal tab & line feed constants
CLASS CL_ABAP_CHAR_UTILITIES DEFINITION LOAD.
CONSTANTS:
C_TAB TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,
C_CR_LF TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF .
*----------------------------------------------------------------------*
* SELECTION SCREEN
*----------------------------------------------------------------------*
*-- Select Optons
SELECTION-SCREEN: BEGIN OF BLOCK B01 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_AUART FOR VBAK-AUART OBLIGATORY NO INTERVALS,
" Sales Document Type
S_AUGRU FOR VBAK-AUGRU OBLIGATORY NO INTERVALS,
" Order reason
S_ERDAT FOR VBAK-ERDAT OBLIGATORY.
" Date on which the record was created
SELECTION-SCREEN: END OF BLOCK B01.
*-- Mail Sending Options
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-004.
PARAMETERS:P_EMAIL AS CHECKBOX DEFAULT SPACE USER-COMMAND V_COM .
PARAMETERS : P_MODE TYPE SO_ESCAPE
default 'U' MODIF ID US1.
SELECT-OPTIONS: S_EMAIL FOR ADR6-SMTP_ADDR
NO INTERVALS MODIF ID US2.
* SELECT-OPTIONS: S_EMAIL FOR TRDYSE01CM-USERNAME
*
NO INTERVALS MODIF ID US2.
SELECTION-SCREEN: BEGIN OF LINE.
SELECTION-SCREEN: COMMENT 55(40) TEXT-019 MODIF ID US2.
SELECTION-SCREEN: END OF LINE.
*
A Form routine to modify the screen
*----------------------------------------------------------------------*
FORM F_MODIFY_SCREEN .
*-- To Modify Mail Sending Options
LOOP AT SCREEN.
IF P_EMAIL = C_X.
IF SCREEN-GROUP1 = 'US1' .
SCREEN-INVISIBLE = 0.
SCREEN-ACTIVE = 1.
SCREEN-INPUT = 0.
MODIFY SCREEN.
ENDIF.
IF SCREEN-GROUP2 = 'US2' .
SCREEN-INVISIBLE = 0.
SCREEN-ACTIVE = 1.
MODIFY SCREEN.
ENDIF.
ELSEIF P_EMAIL = SPACE.
IF SCREEN-GROUP1 = 'US1' .
SCREEN-INVISIBLE = 1.
SCREEN-ACTIVE = 0.
MODIFY SCREEN.
ENDIF.
IF SCREEN-GROUP1 = 'US2' .
SCREEN-INVISIBLE = 1.
SCREEN-ACTIVE = 0.
MODIFY SCREEN.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM.
" F_MODIFY_SCREEN
*&---------------------------------------------------------------------*
*&
Form f_validate
*&---------------------------------------------------------------------*
*
Validation of Selection-Screen Inputs
*----------------------------------------------------------------------*
FORM f_validate .
*-- Validate Sales Document Type
if not s_AUART[] is initial.
select AUART
into s_AUART-low
from TVAK up to 1 rows
where AUART in s_AUART.
endselect.
if sy-subrc <> 0.
message E000 with 'Invalid Sales Document Type'(e01) .
endif.
ENDIF.
*-- Validate Order reason (reason for the business transaction)
if not s_AUGRU[] is initial.
select AUGRU
into s_AUGRU-low
" F_GET_CREDIT_MEMO_REQUEST
*&---------------------------------------------------------------------*
*&
Form F_GET_MVKE_DOCS
*&---------------------------------------------------------------------*
*
Fetch Sales Data for Material
*----------------------------------------------------------------------*
FORM F_GET_MVKE_DOCS .
ENDFORM.
" F_GET_MVKE_DOCS
*&---------------------------------------------------------------------*
*&
Form F_GET_SO_PO_DOCS
*&---------------------------------------------------------------------*
*
Fetch the Sales Order documents, PO documents, & Credit Memo
*----------------------------------------------------------------------*
FORM F_GET_SO_PO_DOCS.
*-- Fetch Preceding sales orders based on the credit memo request
SELECT VBELV
POSNV
VBELN
POSNN
VBTYP_N
FROM VBFA
INTO TABLE IT_ORDERS
FOR ALL ENTRIES IN IT_CRMEMO
WHERE VBELN = IT_CRMEMO-VBELN
AND POSNN = IT_CRMEMO-POSNR
AND VBTYP_N = C_K
AND VBTYP_V = C_C.
IF SY-SUBRC = 0.
SORT IT_ORDERS BY VBELV POSNV.
*-- Fetch Subsequent PO documents & Credit Memo based on the sales orders
SELECT VBELV
POSNV
VBELN
POSNN
VBTYP_N
FROM VBFA
INTO TABLE IT_PO
FOR ALL ENTRIES IN IT_ORDERS
WHERE VBELV = IT_ORDERS-VBELV
AND POSNV = IT_ORDERS-POSNV
AND VBTYP_N IN (C_V,C_O)
AND VBTYP_V = C_C.
IF SY-SUBRC = 0.
SORT IT_PO BY VBTYP_N.
*-- Copy the IT_PO internal table contents to IT_CMEMO internal table
IT_CMEMO[] = IT_PO[].
*-- Delete PO documents from IT_CMEMO internal table
DELETE IT_CMEMO WHERE VBTYP_N = C_V.
SORT IT_CMEMO BY VBELN POSNN.
IF IT_CMEMO[] IS INITIAL.
MESSAGE I000 WITH 'No Credit Memo are available for CM Request'(003).
*
v_flag = c_x.
*
stop.
ENDIF.
*-- Delete Credit Memo documents from IT_PO internal table
DELETE IT_PO WHERE VBTYP_N = C_O.
SORT IT_PO BY VBELN POSNN.
ENDIF.
ENDIF.
ENDFORM.
" F_GET_SO_PO_DOCS
*&---------------------------------------------------------------------*
*&
Form F_GET_CHANGED_DOCS
*&---------------------------------------------------------------------*
*
Fetch Change Documents for CR Memos from CDHDR and CDPOS tables
*----------------------------------------------------------------------*
FORM F_GET_CHANGED_DOCS .
*-- Fetch Change Documents for CR Memos from CDHDR
SELECT OBJECTCLAS
OBJECTID
CHANGENR
UDATE
UTIME
FROM CDHDR
INTO TABLE IT_CDHDR
FOR ALL ENTRIES IN IT_CRMEMO_CHANGE
WHERE OBJECTCLAS = C_VERKBELEG
AND OBJECTID
= IT_CRMEMO_CHANGE-VBELN
*
AND UDATE
= IT_CRMEMO_CHANGE-AEDAT
.
IF SY-SUBRC = 0.
SORT IT_CDHDR BY OBJECTCLAS OBJECTID CHANGENR.
*-- Fetch Change Documents for CR Memos from CDPOS
SELECT OBJECTCLAS
OBJECTID
CHANGENR
TABNAME
TABKEY
FNAME
CHNGIND
VALUE_NEW
VALUE_OLD
FROM CDPOS
INTO TABLE IT_CDPOS
FOR ALL ENTRIES IN IT_CDHDR
WHERE OBJECTCLAS = C_VERKBELEG
AND OBJECTID
= IT_CDHDR-OBJECTID
AND CHANGENR
= IT_CDHDR-CHANGENR
AND TABNAME
= C_VBAK
AND FNAME
= C_AUGRU
AND CHNGIND
= C_U.
IF SY-SUBRC = 0.
SORT IT_CDPOS BY OBJECTCLAS OBJECTID CHANGENR.
ENDIF.
ENDIF.
ENDFORM.
" F_GET_CHANGED_DOCS
*&---------------------------------------------------------------------*
*&
Form F_GET_EKPO
*&---------------------------------------------------------------------*
*
Fetch Purchasing Document Item Details
*----------------------------------------------------------------------*
FORM F_GET_EKPO .
*-- Fetch Purchasing Document Item Details
SELECT A~EBELN
B~EBELP
A~WAERS
B~MENGE
B~MEINS
B~NETPR
B~PEINH
B~mwskz
B~TXJCD
INTO TABLE IT_EKPO
FROM ( EKKO AS A
INNER JOIN EKPO AS B ON A~EBELN = B~EBELN )
FOR ALL ENTRIES IN IT_PO
WHERE A~EBELN = IT_PO-VBELN
AND B~EBELP = IT_PO-POSNN+1(5).
IF SY-SUBRC = 0.
SORT IT_EKPO BY EBELN EBELP.
ENDIF.
ENDFORM.
" F_GET_EKPO
*&---------------------------------------------------------------------*
*&
Form F_GET_VENDOR
*&---------------------------------------------------------------------*
*
Fetch MIRO Vendor details based on the PO Details
*----------------------------------------------------------------------*
FORM F_GET_VENDOR .
DATA: LV_TABIX TYPE SY-TABIX.
*-- Fetch History per Purchasing Document records for all the PO records
SELECT EBELN
EBELP
ZEKKN
VGABE
GJAHR
BELNR
BUZEI
FROM EKBE
INTO TABLE IT_EKBE
FOR ALL ENTRIES IN IT_EKPO
WHERE EBELN = IT_EKPO-EBELN
AND EBELP = IT_EKPO-EBELP
AND VGABE = '2'.
*
and STBLG = space.
IF SY-SUBRC = 0.
SORT IT_EKBE BY BELNR GJAHR.
*-- Fetch the vendor details based on table IT_EKBE internal table
SELECT BELNR
GJAHR
BLDAT
BUDAT
XBLNR
LIFNR
RMWWR
WMWST1
XRECH
STBLG
FROM RBKP
INTO TABLE IT_RBKP
FOR ALL ENTRIES IN IT_EKBE
WHERE BELNR = IT_EKBE-BELNR
AND GJAHR = IT_EKBE-GJAHR.
IF SY-SUBRC = 0.
SORT IT_RBKP BY BELNR GJAHR.
ENDIF.
ENDIF.
*-- Sort PO History documents based on PO # and PO Item
SORT IT_EKBE BY EBELN EBELP.
*-- Copy the PO History documents into IT_EKBE_TEMP internal table
IT_EKBE_TEMP[] = IT_EKBE[].
*-- Delete PO History documents from IT_EKBE_TEMP internal table
*
comparing with IT_RBKP where (STBLG) Reversal document number
*
is initial
LOOP AT IT_EKBE_TEMP INTO WA_EKBE_TEMP.
LV_TABIX = SY-TABIX.
READ TABLE IT_RBKP INTO WA_RBKP WITH KEY BELNR = WA_EKBE_TEMP-BELNR
GJAHR = WA_EKBE_TEMP-GJAHR
*
XRECH = SPACE
STBLG = SPACE.
IF SY-SUBRC <> 0.
DELETE IT_EKBE_TEMP INDEX LV_TABIX.
ENDIF.
CLEAR: WA_EKBE_TEMP, WA_RBKP.
ENDLOOP.
ENDFORM.
" F_GET_VENDOR
*&---------------------------------------------------------------------*
*&
Form F_PROCESS_MIRO
*&---------------------------------------------------------------------*
*
Process MIRO
*----------------------------------------------------------------------*
FORM F_PROCESS_MIRO .
DATA:
lv_itemno
TYPE i,
lv_tabix
type sy-index,
lc_check(1)
TYPE c VALUE 'X',
V_FILL_ITEM,
lv_rbkp_bldat type sy-datum.
clear : it_itemdata, it_accountingdata, IT_CRMEMO_MIRO, IT_CRMEMO_MR8M.
refresh : it_itemdata, it_accountingdata, IT_CRMEMO_MIRO, IT_CRMEMO_MR8M.
*-- Copy all the CR Memo Docs and delete order reason not in S_AUGRU
IT_CRMEMO_MR8M[] = IT_CRMEMO[].
*-- Delete Reversal postings which are not in S_AUGRU
DELETE IT_CRMEMO_MR8M WHERE AUGRU IN S_AUGRU.
*-- Delete Reversal postings where AEDAT is initial
DELETE IT_CRMEMO_MR8M where aedat is initial.
*-- Delete order reason which are not in S_AUGRU
DELETE IT_CRMEMO WHERE AUGRU NOT IN S_AUGRU.
*-- Loop through the credit memo request records
LOOP AT IT_CRMEMO INTO WA_CRMEMO.
lv_tabix = sy-tabix.
*-- If credit memo request change date is not initial then
*
send change date (AEDAT) to lv_rbkp_bldat
if not WA_CRMEMO-aedat is initial.
lv_rbkp_bldat = WA_CRMEMO-aedat.
else.
*-- If credit memo request change date is initial then
*
send create date (ERDAT) to lv_rbkp_bldat
lv_rbkp_bldat = WA_CRMEMO-erdat.
endif.
READ TABLE IT_ORDERS INTO WA_ORDERS WITH KEY VBELN = WA_CRMEMO-VBELN
POSNN = WA_CRMEMO-POSNR.
IF SY-SUBRC = 0.
READ TABLE IT_PO INTO WA_PO WITH KEY VBELV = WA_ORDERS-VBELV
POSNV = WA_ORDERS-POSNV.
IF SY-SUBRC = 0.
READ TABLE IT_EKPO INTO WA_EKPO WITH KEY EBELN = WA_PO-VBELN
EBELP = WA_PO-POSNN.
IF SY-SUBRC = 0.
*-- Read IT_EKBE_TEMP internal table which contains records which are not
reversed
READ TABLE IT_EKBE_TEMP INTO WA_EKBE_TEMP WITH KEY EBELN = WA_EKPOEBELN
EBELP = WA_EKPOEBELP.
IF SY-SUBRC = 0.
*-- Read IT_RBKP internal table with XRECH (Indicator: post invoice) = 'X' ,
*
check for invoice records for the correspnding CR Memo records
READ TABLE IT_RBKP INTO WA_RBKP WITH KEY BELNR = WA_EKBE_TEMPBELNR
GJAHR = WA_EKBE_TEMPGJAHR
XRECH = C_X.
IF SY-SUBRC = 0.
*-- Read IT_RBKP internal table with XRECH (Indicator: post invoice) = SPACE,
*
and document date = CR Memo creation date
*
and reference document number = PO number
READ TABLE IT_RBKP INTO WA_RBKP_TMP WITH KEY BELNR =
WA_EKBE_TEMP-BELNR
GJAHR =
WA_EKBE_TEMP-GJAHR
BLDAT = WA_CRMEMO-
ERDAT
=
=
=
=
=
v_itemno.
WA_ekPO-ebeln.
WA_EKPO-EBELP.
WA_ekpo-mwskz.
WA_ekpo-TXJCD.
*-- Converting SAP amount to BAPI format by passing line item amount and
currency
PERFORM f_currency_amount_sap_to_bapi USING
WA_EKPO-waers
V_LINE_AMOUNT
CHANGING it_itemdataitem_amount .
V_CRMEMO_QTY ).
it_itemdata-quantity
it_itemdata-po_unit
APPEND it_itemdata.
= ( WA_CRMEMO-ZMENG *
= WA_EKPO-MEINS.
*-- At end of each credit memo request fill the header details of BAPI FM and
*-- post the BAPI
AT END OF VBELN.
read table it_crmemo into wa_crmemo index lv_tabix.
*-- Populate the document Header
*-- Getting the header data for invoice
x_docheader-invoice_ind = space.
x_docheader-doc_type
= c_blart.
x_docheader-doc_date
= lv_rbkp_bldat.
x_docheader-pstng_date
= lv_rbkp_bldat.
x_docheader-ref_doc_no
= WA_RBKP-XBLNR.
x_docheader-comp_code
= WA_CRMEMO-BUKRS_VF.
x_docheader-CURRENCY
= WA_CRMEMO-WAERK.
x_docheader-calc_tax_ind = lc_check.
*-- Logic to find the Tax %
v_tax_per = ( WA_RBKP-WMWST1 / ( WA_RBKP-RMWWR - WA_RBKP-WMWST1 ) ) *
100.
v_tax_amt = ( V_GROSSAMT * v_tax_per ) / 100.
V_GROSSAMT = ( V_GROSSAMT + v_tax_amt ).
x_docheader-gross_amount = V_GROSSAMT.
CLEAR:v_docnr, v_year1.
*-- Calling BAPI to create PO invoice document
CHECK NOT IT_ITEMDATA[] IS INITIAL.
CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
EXPORTING
headerdata
= x_docheader
IMPORTING
invoicedocnumber = v_docnr
fiscalyear
= v_year1
TABLES
itemdata
= it_itemdata[]
ACCOUNTingDATA
= it_ACCOUNTingDATA[]
*
GLACCOUNTDATA
=
*
taxdata
=
return
= it_return.
*-- Commit work
IF NOT v_docnr IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
*-- Move the data to Success Internal Table
wa_success-crmemo = wa_crmemo-vbeln.
wa_success-cmemo
= wa_cmemo-vbeln.
wa_success-orders = wa_orders-vbelv.
wa_success-po
= wa_po-vbeln.
wa_success-miro_no = v_docnr.
wa_success-text
= 'MIRO is Posted'.
append wa_success TO it_success.
clear wa_success.
*--
ENDIF.
Read the values in the table IT_RETURN.
CLEAR it_return.
READ TABLE it_return INDEX 1.
*
If message type is error then roll back the work
IF it_return-type = C_E.
*-- Roll back
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
*-- Move the data to Error Internal Table
wa_error-crmemo = wa_crmemo-vbeln.
wa_error-cmemo = wa_cmemo-vbeln.
wa_error-orders = wa_orders-vbelv.
wa_error-po
= wa_po-vbeln.
wa_error-text
= it_return-MESSAGE.
append wa_error TO it_error.
clear wa_error.
ENDIF.
refresh: it_return, it_itemdata, it_accountingdata.
clear: V_GROSSAMT, it_return, it_itemdata, wa_crmemo, wa_orders, wa_po,
wa_ekpo, WA_EKBE_TEMP, wa_rbkp, wa_rbkp_tmp, v_docnr, v_year1,
WA_SUCCESS,
WA_ERROR, it_accountingdata, v_tax_per, v_tax_amt, V_FILL_ITEM,
lv_rbkp_bldat.
ENDAT.
ENDLOOP.
ENDFORM.
" F_PROCESS_MIRO
*&---------------------------------------------------------------------*
*&
Form f_quantity_conv
*&---------------------------------------------------------------------*
*
Quantity Conversion
*----------------------------------------------------------------------*
FORM f_quantity_conv .
*-- Quantity Conversion (Get the Credit Memo Quantity by passing CMR unit per
one PO unit)
CLEAR: V_LINE_AMOUNT, V_CRMEMO_QTY.
call function 'MC_UNIT_CONVERSION'
EXPORTING
MATNR
= WA_CRMEMO-MATNR
nach_meins
= WA_EKPO-MEINS
von_meins
= WA_CRMEMO-ZIEME
IMPORTING
UMREF
= V_CRMEMO_QTY
EXCEPTIONS
CONVERSION_NOT_FOUND = 1
MATERIAL_NOT_FOUND
= 2
NACH_MEINS_MISSING
= 3
OVERFLOW
= 4
VON_MEINS_MISSING
= 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.
ELSE.
V_LINE_AMOUNT = ( V_CRMEMO_QTY
* WA_CRMEMO-ZMENG * WA_EKPO-peinh *
WA_EKPO-NETPR ).
V_GROSSAMT
= V_GROSSAMT + V_LINE_AMOUNT.
ENDIF.
ENDFORM.
" f_quantity_conv
*&---------------------------------------------------------------------*
*&
Form f_currency_amount_sap_to_bapi
*&---------------------------------------------------------------------*
*
SAP Amount to BAPI Amount
*----------------------------------------------------------------------*
FORM f_currency_amount_sap_to_bapi USING
p_waers
p_kbetr
CHANGING p_amt_doccur.
DATA : lv_waers LIKE tcurc-waers,
lv_sapamount LIKE bapicurr-bapicurr,
lv_bapi_amount LIKE bapicurr-bapicurr.
lv_waers = p_waers.
lv_sapamount = p_kbetr.
CALL FUNCTION 'CURRENCY_AMOUNT_SAP_TO_BAPI'
EXPORTING
currency
= lv_waers
sap_amount = lv_sapamount
IMPORTING
bapi_amount = lv_bapi_amount.
p_amt_doccur = lv_bapi_amount.
ENDFORM.
" f_currency_amount_sap_to_bapi
*&---------------------------------------------------------------------*
*&
Form f_display_report
*&---------------------------------------------------------------------*
*
Display Report
*----------------------------------------------------------------------*
FORM f_display_report .
*-- Success Report
IF NOT IT_SUCCESS[] IS INITIAL.
ULINE AT /1(129).
WRITE:/1 sy-vline, 'CR Memo',
19 sy-vline, 'Credit Memo',
39 sy-vline, 'Sales Order',
59 sy-vline, 'Purchase Order',
79 sy-vline, 'MIRO Number',
99 sy-vline, 'Text',
129 sy-vline.
ULINE AT /1(129).
LOOP AT it_success into wa_success.
WRITE:/1 sy-vline, wa_success-crmemo,
19 sy-vline, wa_success-cmemo,
39 sy-vline, wa_success-orders,
59 sy-vline, wa_success-po,
79 sy-vline, wa_success-miro_no,
99 sy-vline, wa_success-text,
129 sy-vline.
ENDLOOP.
ULINE AT /1(129).
SKIP 2.
ENDIF.
*-- Error Report
IF NOT IT_ERROR[] IS INITIAL.
ULINE AT /1(179).
WRITE:/1 sy-vline, 'CR Memo',
19 sy-vline, 'Credit Memo',
39 sy-vline, 'Sales Order',
59 sy-vline, 'Purchase Order',
79 sy-vline, 'Error Text',
179 sy-vline.
ULINE AT /1(179).
LOOP AT IT_ERROR into WA_ERROR.
WRITE:/1 sy-vline, WA_ERROR-crmemo,
19 sy-vline, WA_ERROR-cmemo,
39 sy-vline, WA_ERROR-orders,
59 sy-vline, WA_ERROR-po,
79 sy-vline, WA_ERROR-text,
179 sy-vline.
ENDLOOP.
ULINE AT /1(179).
ENDIF.
IF NOT IT_SUCCESS_MR8M[] IS INITIAL.
ULINE AT /1(129).
WRITE:/1 sy-vline, 'CR Memo',
19 sy-vline, 'Credit Memo',
39 sy-vline, 'Sales Order',
59 sy-vline, 'Purchase Order',
79 sy-vline, 'Reversal Posting No.',
99 sy-vline, 'Text',
129 sy-vline.
ULINE AT /1(129).
LOOP AT it_success_mr8m into wa_success_mr8m.
WRITE:/1 sy-vline, wa_success_mr8m-crmemo,
19 sy-vline, wa_success_mr8m-cmemo,
39 sy-vline, wa_success_mr8m-orders,
59 sy-vline, wa_success_mr8m-po,
79 sy-vline, wa_success_mr8m-miro_no,
99 sy-vline, wa_success_mr8m-text,
129 sy-vline.
ENDLOOP.
ULINE AT /1(129).
SKIP 2.
ENDIF.
*-- Error Report
IF NOT IT_ERROR_MR8M[] IS INITIAL.
ULINE AT /1(179).
WRITE:/1 sy-vline, 'CR Memo',
19 sy-vline, 'Credit Memo',
39 sy-vline, 'Sales Order',
59 sy-vline, 'Purchase Order',
79 sy-vline, 'Error Text',
179 sy-vline.
ULINE AT /1(179).
LOOP AT IT_ERROR_MR8M into WA_ERROR_MR8M.
WRITE:/1 sy-vline, WA_ERROR_MR8M-crmemo,
19 sy-vline, WA_ERROR_MR8M-cmemo,
39 sy-vline, WA_ERROR_MR8M-orders,
59 sy-vline, WA_ERROR_MR8M-po,
79 sy-vline, WA_ERROR_MR8M-text,
179 sy-vline.
ENDLOOP.
ULINE AT /1(179).
ENDIF.
ENDFORM.
" f_display_report
*&---------------------------------------------------------------------*
*&
Form F_PROCESS_MR8M
*&---------------------------------------------------------------------*
*
Process Reversal postings
*----------------------------------------------------------------------*
FORM F_PROCESS_MR8M .
clear: wa_CRMEMO_MR8M.
LOOP AT IT_CRMEMO_MR8M into WA_CRMEMO_MR8M.
read table it_cdpos into wa_cdpos with key OBJECTID = WA_CRMEMO_MR8M-VBELN.
if sy-subrc <> 0.
CONTINUE.
ELSE.
if wa_cdpos-value_old in s_augru.
READ TABLE IT_ORDERS INTO WA_ORDERS WITH KEY VBELN = wa_CRMEMO_MR8M-VBELN
POSNN = wa_CRMEMO_MR8M-POSNR.
IF SY-SUBRC = 0.
*
READ TABLE IT_CMEMO INTO WA_CMEMO WITH KEY VBELV = WA_ORDERS-VBELV
*
POSNV = WA_ORDERS-POSNV.
*
IF SY-SUBRC = 0.
READ TABLE IT_PO INTO WA_PO WITH KEY VBELV = WA_ORDERS-VBELV
POSNV = WA_ORDERS-POSNV.
IF SY-SUBRC = 0.
*
*
*
*
AEDAT
EBELN
*--
*--
*--
*--
IF SY-SUBRC = 0.
move: WA_RBKP-BELNR
TO X_REV_POST-INV_DOC_NO,
WA_RBKP-GJAHR
TO X_REV_POST-FISC_YEAR,
WA_RBKP-BUDAT
TO X_REV_POST-PSTNG_DATE.
IF WA_RBKP-BUDAT+4(2) = SY-DATUM+4(2).
X_REV_POST-REASON_REV = C_01.
ELSE.
X_REV_POST-REASON_REV = C_02.
ENDIF.
ENDIF.
ENDLOOP.
Call the FM for MIRO reversal
CALL FUNCTION 'BAPI_INCOMINGINVOICE_CANCEL'
EXPORTING
INVOICEDOCNUMBER
= X_REV_POST-INV_DOC_NO
FISCALYEAR
= X_REV_POST-FISC_YEAR
REASONREVERSAL
= X_REV_POST-REASON_REV
POSTINGDATE
= X_REV_POST-PSTNG_DATE
IMPORTING
INVOICEDOCNUMBER_REVERSAL = X_REV_POST-INV_DOC_NO
FISCALYEAR_REVERSAL
= X_REV_POST-FISC_YEAR
TABLES
RETURN
= it_return_mr8m.
Commit work
IF NOT X_REV_POST-INV_DOC_NO IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
Move the data to Success Internal Table
wa_success_mr8m-crmemo = wa_crmemo-vbeln.
wa_success_mr8m-cmemo
= wa_cmemo-vbeln.
wa_success_mr8m-orders = wa_orders-vbelv.
wa_success_mr8m-po
= wa_po-vbeln.
wa_success_mr8m-text
= 'MR8M Done'.
append wa_success_mr8m TO it_success_mr8m.
clear wa_success_mr8m.
ENDIF.
Read the values in the table IT_RETURN.
CLEAR it_return_mr8m.
READ TABLE it_return_mr8m INDEX 1.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
CLEAR: wa_error_mr8m, wa_SUCCESS_mr8m, X_REV_POST, wa_CRMEMO_MR8M,
wa_orders, wa_po, wa_ekpo, wa_ekbe, wa_rbkp, wa_cmemo.
REFRESH: IT_RETURN_MR8M.
endloop.
ENDFORM.
" F_PROCESS_MR8M
*&---------------------------------------------------------------------*
*&
Form F_spool_id
*&---------------------------------------------------------------------*
*
Create a new spool ID
*----------------------------------------------------------------------*
FORM F_spool_id .
*-- Create a new spool from the data in data_tab
*-- new-page line-size sy-linsz print on
new-page line-size 255 print on
destination 'LOCL'(p19) "<<== my printer
*-- receiver 'TJOSVOB'
cover text 'Spool title'(p20) " <<== Title or Spool req. name
list name 'List name'(p21)
list dataset 'List Dataset'(p22)
immediately ' '
" X means print now
keep in spool c_x
" X means keep spool
new list identification c_x
no dialog .
*-- Writing Report
*-- In this perform you will write the code for displaying the list
perform f_display_report.
*-- new-page print off
new-page print off.
ENDFORM.
" F_spool_id
*&---------------------------------------------------------------------*
*&
Form F_MAIL_LOGIC
*&---------------------------------------------------------------------*
*
Logic to send a mail for the given Email ID's
*----------------------------------------------------------------------*
FORM F_MAIL_LOGIC .
data : wa_tsp01sys type tsp01sys.
clear v_spono.
v_spono = sy-spono.
* v_attach_desc = sy-title.
*-- Convert the Spool ID into PDF format
perform f_pdf_conversion tables it_compressed_list
it_pdf_list
using v_spono.
*-- Send the Mail in PDF Format
perform f_send_mail.
ENDFORM.
" F_MAIL_LOGIC
*&---------------------------------------------------------------------*
*&
Form f_pdf_conversion
*&---------------------------------------------------------------------*
*
Read the spool and convert into PDF format
*----------------------------------------------------------------------*
*
-->P_ITAB_COMPRESSED_LIST text
*
-->P_ITAB_PDF_LIST text
*
-->P_V_SPONO text
*----------------------------------------------------------------------*
FORM f_pdf_conversion TABLES
it_compressed_list structure soli
it_pdf_list structure tline
using
lv_spooln type tsp01-rqident.
clear: it_compressed_list, it_pdf_list.
refresh: it_compressed_list, it_pdf_list.
*-- Call the FM "RSPO_RETURN_SPOOLJOB" to read the spool by passing the spool
number
call function 'RSPO_RETURN_SPOOLJOB'
exporting
rqident
= lv_spooln
desired_type
= v_type
importing
real_type
= v_type
tables
buffer
= it_compressed_list
buffer_pdf
= it_pdf_list
exceptions
no_such_job
= 1
job_contains_no_data = 2
selection_empty
= 3
no_permission
= 4
can_not_access
= 5
read_error
= 6
type_no_match
= 7
others
= 8.
if sy-subrc <> 0.
message I000 with 'Error in spool reading'(017).
endif.
*-- If the List type is ALI call the FM "CONVERT_ABAPSPOOLJOB_2_PDF"
*
to convert list into PDF Format
if v_type = c_ali.
" for List it is ALI
call function 'CONVERT_ABAPSPOOLJOB_2_PDF'
exporting
src_spoolid
= lv_spooln
tables
pdf
= it_pdf
exceptions
err_no_abap_spooljob
= 1
err_no_spooljob
= 2
err_no_permission
= 3
err_conv_not_possible
= 4
err_bad_destdevice
= 5
user_cancelled
= 6
err_spoolerror
= 7
err_temseerror
= 8
err_btcjob_open_failed
= 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11
others
= 12.
if sy-subrc <> 0.
message e000
with'Error in convertion of list into PDF format'(018).
endif.
*-- Logic to convert the given format into 255 character format in IT_PDF
describe table it_pdf lines v_lines.
describe field it_pdf length v_lineslen IN character MODE.
describe field it_temp length v_mimelen IN character MODE.
LOOP AT it_pdf.
v_tabix = sy-tabix.
MOVE it_pdf TO v_temp+v_offset.
IF v_tabix = v_lines.
v_lineslen = strlen( it_pdf ).
ENDIF.
v_offset = v_offset + v_lineslen.
IF v_offset GE v_mimelen.
CLEAR it_temp.
it_temp = v_temp(v_mimelen).
APPEND it_temp.
SHIFT v_temp BY v_mimelen PLACES.
v_offset = v_offset - v_mimelen.
ENDIF.
IF v_tabix = v_lines.
IF v_offset GT 0.
CLEAR it_temp.
it_temp = v_temp(v_offset).
APPEND it_temp.
ENDIF.
ENDIF.
ENDLOOP.
LOOP AT it_temp.
it_mime(255) = it_temp-line.
APPEND it_mime.
ENDLOOP.
*-- Final Data to send to EMail
it_html[] = it_mime[].
endif.
ENDFORM.
" f_pdf_conversion
*&---------------------------------------------------------------------*
*&
Form f_send_mail
*&---------------------------------------------------------------------*
*
Send EMail Logic
*----------------------------------------------------------------------*
FORM f_send_mail .
data : wa_tsp01sys type tsp01sys.
*-- Populate Mail Id's
WA_RECLIST-REC_TYPE = P_MODE.
WA_RECLIST-EXPRESS = C_X.
*-- Loop through the Emial select options
LOOP AT S_EMAIL INTO X_EMAIL.
WA_RECLIST-RECEIVER = X_EMAIL-LOW.
*-- append receiver table
APPEND WA_RECLIST TO IT_RECLIST.
ENDLOOP.
*-- If receiver table is not initial
CHECK IT_RECLIST[] IS NOT INITIAL.
*--To check Mail ID's internal table should not be Empty.
*--populate document attributes
*-- Mail subject line
CLEAR: X_DOC_CHNG.
X_DOC_CHNG-OBJ_NAME = 'HEADING'.
CONCATENATE 'Automatic Vendor Dedit Postings'(005)
SY-DATUM
INTO X_DOC_CHNG-OBJ_DESCR SEPARATED BY SPACE.
*-- Mail body
CONCATENATE 'Automatic Vendor Dedit Postings'(005)
' is attached.'(006)
INTO WA_OBJTXT SEPARATED BY SPACE.
APPEND WA_OBJTXT TO IT_OBJTXT.
*-- Append Date and Time into Body of email.
MOVE 'File is generated on'(007)
TO V_INFO.
V_TIME = SY-UZEIT.
CONCATENATE V_TIME+0(2)
V_TIME+2(2)
V_TIME+4(2)
INTO
V_TIME2 SEPARATED BY ':'.
CONCATENATE SY-DATUM+4(2)
'/'
SY-DATUM+6(2)
'/'
SY-DATUM+0(4)
INTO V_DATE2.
CONCATENATE V_INFO
V_DATE2
'At'
V_TIME2
INTO V_INFO
SEPARATED BY SPACE.
WA_OBJTXT = V_INFO.
APPEND WA_OBJTXT TO IT_OBJTXT.
*-- Document size
CLEAR : V_TABLE_LINES.
DESCRIBE TABLE IT_OBJTXT LINES V_TABLE_LINES.
READ TABLE IT_OBJTXT INTO WA_OBJTXT INDEX V_TABLE_LINES .
X_DOC_CHNG-DOC_SIZE =
( V_TABLE_LINES - 1 ) * 255 + STRLEN( WA_OBJTXT ).
*-- Populate packing list for body text
WA_OBJPACK-HEAD_START = 1.
WA_OBJPACK-HEAD_NUM = 0.
WA_OBJPACK-BODY_START = 1.
WA_OBJPACK-BODY_NUM = V_TABLE_LINES.
WA_OBJPACK-DOC_TYPE = 'RAW'.
APPEND WA_OBJPACK TO IT_OBJPACK.
CLEAR WA_OBJPACK.
if v_type = c_ali.
loop at it_html.
wa_objbin-line = it_html-line.
APPEND WA_OBJBIN TO IT_OBJBIN.
CLEAR WA_OBJBIN.
endloop.
v_type = 'PDF'.
endif.
*-- Get total no.of lines of Object table(attachment)
CLEAR : V_TABLE_LINES.
DESCRIBE TABLE IT_OBJBIN LINES V_TABLE_LINES.
*-- Populate object header(attachment name)
WA_OBJHEAD = 'Automatic Vendor Dedit Postings log'(014).
APPEND WA_OBJHEAD TO IT_OBJHEAD.
CLEAR WA_OBJHEAD.
*-- Packing list for attachment
WA_OBJPACK-TRANSF_BIN
WA_OBJPACK-HEAD_START
WA_OBJPACK-HEAD_NUM =
WA_OBJPACK-BODY_START
WA_OBJPACK-BODY_NUM =
WA_OBJPACK-DOC_TYPE =
= C_X.
= 1.
1.
= 1.
V_TABLE_LINES .
v_type .
WA_OBJPACK-OBJ_NAME = 'Auto_Debit'.
WA_OBJPACK-OBJ_DESCR = 'attachment'.
WA_OBJPACK-DOC_SIZE = V_TABLE_LINES * 255.
APPEND WA_OBJPACK TO IT_OBJPACK.
CLEAR WA_OBJPACK.
*-- Sending the EMail document in given format
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA
= X_DOC_CHNG
PUT_IN_OUTBOX
= C_X
COMMIT_WORK
= C_X
TABLES
PACKING_LIST
= IT_OBJPACK
OBJECT_HEADER
= IT_OBJHEAD
CONTENTS_BIN
= IT_OBJBIN
CONTENTS_TXT
= IT_OBJTXT
RECEIVERS
= IT_RECLIST
EXCEPTIONS
TOO_MANY_RECEIVERS
= 1
DOCUMENT_NOT_SENT
= 2
DOCUMENT_TYPE_NOT_EXIST
= 3
OPERATION_NO_AUTHORIZATION = 4
PARAMETER_ERROR
= 5
X_ERROR
= 6
ENQUEUE_ERROR
= 7
OTHERS
= 8.
IF SY-SUBRC <> 0.
MESSAGE E000 WITH 'Error occurred in sending mail'(015).
ELSE.
*-- Wait upto 2 secounds
wait up to 2 seconds.
*-- Call the RSCONN01 (SAPconnect: Start Send Process)
SUBMIT RSCONN01 WITH MODE = 'INT'
*
WITH output = 'X'
AND RETURN.
PERFORM F_DISPLAY_SENT_MAIL_STATUS.
ENDIF.
* To delete the spool request
wa_tsp01sys-rqident = sy-spono.
call function 'RSPO_IDELETE_SPOOLREQ'
exporting
spoolreq = wa_tsp01sys.
if sy-subrc <> 0.
endif.
ENDFORM.
" f_send_mail
*&---------------------------------------------------------------------*
*&
Form F_DISPLAY_SENT_MAIL_STATUS
*&---------------------------------------------------------------------*
*
Display Mail Sent status to the user
*----------------------------------------------------------------------*
FORM F_DISPLAY_SENT_MAIL_STATUS .
ULINE AT /1(60).
WRITE :/ SY-VLINE,
'Mail sent Successfully to'(016)
COLOR 5 INTENSIFIED ON,
60 SY-VLINE.
LOOP AT S_EMAIL INTO X_EMAIL.
V_TABLE_LINES = STRLEN( X_EMAIL-LOW ).
MOVE X_EMAIL-LOW+0(V_TABLE_LINES) TO V_TEXT2.
WRITE :/ SY-VLINE,
2 SY-TABIX LEFT-JUSTIFIED,
5 ')',
V_TEXT2,
60 SY-VLINE.
ENDLOOP.
ULINE AT /1(60).
ENDFORM.
" F_DISPLAY_SENT_MAIL_STATUS
In this scenario, we would take an example of a material and develop an interactive report. Once
you click on require material no on the basic list, the corresponding material information on the
secondary list.
Following is a sample interactive report developed for our demo purpose:
REPORT zintractive
END OF str_makt.
DATA : wa_makt TYPE str_makt,
it_makt TYPE TABLE OF str_makt.
TYPES : BEGIN OF str_mara,
matnr TYPE mara-matnr,
ersda TYPE mara-ersda,
ernam TYPE mara-ernam,
laeda TYPE mara-laeda,
mtart TYPE mara-mtart,
matkl TYPE mara-matkl,
meins TYPE mara-meins,
END OF str_mara.
DATA : wa_mara TYPE str_mara,
it_mara TYPE TABLE OF str_mara.
TYPES : BEGIN OF str_final,
matnr TYPE mara-matnr,
ersda TYPE mara-ersda,
ernam TYPE mara-ernam,
laeda TYPE mara-laeda,
mtart TYPE mara-mtart,
matkl TYPE mara-matkl,
meins TYPE mara-meins,
lgort TYPE mard-lgort,
werks TYPE mard-werks,
END OF str_final.
DATA: wa_final TYPE str_final,
it_final TYPE TABLE OF str_final.
PARAMETERS : plant TYPE mard-werks,
stor LIKE mard-lgort.
SELECT matnr lgort werks
FROM mard
INTO TABLE it_mard
WHERE lgort = stor AND werks = plant.
.
SELECT matnr maktg
FROM makt
INTO TABLE it_makt FOR ALL ENTRIES IN it_mard
WHERE matnr = it_mard-matnr AND spras = 'E'.
SELECT matnr ersda ernam laeda mtart matkl meins
FROM mara
INTO TABLE it_mara FOR ALL ENTRIES IN it_makt
WHERE matnr = it_makt-matnr.
LOOP AT it_makt INTO wa_makt.
WRITE : /1 wa_makt-matnr COLOR 1,
40 wa_makt-maktg COLOR 2.
HIDE wa_makt-matnr.
ENDLOOP.
CLEAR wa_mard-matnr.
AT LINE-SELECTION.
REFRESH it_final.
CLEAR wa_final.
ULINE.
IF sy-lsind = 1.
WRITE : /1 'MATERIAL NO' COLOR 2,
20 'CREATION DATE' COLOR 3,
32 'PERSON CREATED',
50 'DATE OF LIST' ,
65 'MATERIALTYPE',
80 'MATGROUP' ,
90 'UNITOFMEASURE',
110 'STORLOCATION' COLOR 4,
130
'PLANT' COLOR 5.
ULINE.
ENDIF.
LOOP AT it_mara INTO wa_mara WHERE matnr = wa_makt-matnr.
wa_final-matnr = wa_mara-matnr.
wa_final-ersda = wa_mara-ersda.
wa_final-ernam = wa_mara-ernam.
wa_final-laeda = wa_mara-laeda.
wa_final-mtart = wa_mara-mtart.
wa_final-matkl = wa_mara-matkl.
wa_final-meins = wa_mara-meins.
READ TABLE it_mard INTO wa_mard WITH KEY matnr = wa_makt-matnr.
wa_final-lgort = wa_mard-lgort.
wa_final-werks = wa_mard-werks.
APPEND wa_final TO it_final.
ENDLOOP.
LOOP AT it_final INTO wa_final.
WRITE : /1 wa_final-matnr COLOR 2,
20 wa_final-ersda COLOR 3,
37 wa_final-ernam,
50 wa_final-laeda ,
70 wa_final-mtart ,
85 wa_final-matkl ,
95 wa_final-meins,
115
wa_final-lgort COLOR 4,
130
wa_final-werks COLOR 5.
ENDLOOP.
TOP-OF-PAGE.
WRITE : /1 'MATERIAL NO' COLOR 1,
40 'DISCRIPTION' COLOR 2.
ULINE .
Result
Enter the Plant and Storage Location
Double Click on require Material No which displays secondary list to corresponding material
information.
The result shown below
REQUIREMENT: Get the Plant and storage location from the user and to get the available materials in the particular
storage location and display in a report.
When the material number in the report is selected the material description and other complete details are
displayed in a new screen using interactive report.
STEPS FOLLOWED TO ACHIEVE THE GOAL:
Go to SE38 ABAP Editor create a new program.
A new screen shows the output based on the selected record achieving the interactive reporting.
*&----------------------------------------------------------------*
*& Report ZVikram_interactive
*
*&
*
*&----------------------------------------------------------------*
*& Published at SAPTechnical.COM
*
*&
*
*&----------------------------------------------------------------*
REPORT ZVikram_interactive NO STANDARD PAGE HEADING LINE-SIZE 255.
********** THE INITIALIZATION PART CREATING STRUCTURES*************
INITIALIZATION.
TYPES : BEGIN OF TY_MARD,
MATNR TYPE MARD-MATNR,
WERKS TYPE MARD-WERKS,
IF SY-SUBRC <> 0.
WRITE 'NO MASTER DATA'.
STOP.
ELSE.
SELECT MATNR SPRAS MAKTX
FROM MAKT
INTO TABLE I_MAKT
FOR ALL ENTRIES IN I_MARA
WHERE MATNR = I_MARA-MATNR AND SPRAS = 'E'.
ENDIF.
ENDIF.
*****READ FROM INTERNAL TABLE FOR OUTPUT ******************************
LOOP AT I_MARA INTO W_MARA.
AT FIRST.
WRITE : SY-ULINE(100),
/1 SY-VLINE,
25 'EXAMPLE INTERACTIVE REPORT',
100 SY-VLINE,
/ SY-ULINE(100),
/1 SY-VLINE,
2 'MATERIAL NUMBER' ,
20 SY-VLINE,
22 'CREATION DATE',
40 SY-VLINE,
42 'USER NAME',
60 SY-VLINE,
62 'MATERIAL TYPE',
80 SY-VLINE,
82 'MATERIAL GROUP',
100 SY-VLINE,
/ SY-ULINE(100).
ENDAT.
ON CHANGE OF W_MARA-MATNR.
READ TABLE I_MARD INTO W_MARD WITH KEY MATNR = W_MARA-MATNR.
ENDON.
WRITE :/1 SY-VLINE,
2 W_MARA-MATNR ,
20 SY-VLINE,
22 W_MARA-ERSDA,
40 SY-VLINE,
42 W_MARA-ERNAM,
60 SY-VLINE,
62 W_MARA-MTART,
80 SY-VLINE,
82 W_MARA-MATKL,
100 SY-VLINE.
HIDE W_MARA-MATNR.
CLEAR W_MARA-MATNR.
WRITE: / SY-ULINE(100).
ENDLOOP.
*****************END-OF-SELECTION.*************************************
END-OF-SELECTION.
****MOVING VALUES IN TO FINAL INTERNAL TABLE **************************
LOOP AT I_MARA INTO W_MARA.
ON CHANGE OF W_MARA-MATNR.
READ TABLE I_MAKT INTO W_MAKT WITH KEY MATNR = W_MARA-MATNR.
READ TABLE I_MARD INTO W_MARD WITH KEY MATNR = W_MARA-MATNR.
ENDON.
W_FINAL-MATNR =
W_FINAL-ERSDA =
W_FINAL-ERNAM =
W_FINAL-MTART =
W_FINAL-MATKL =
W_FINAL-WERKS =
W_FINAL-LGORT =
W_FINAL-SPRAS =
W_FINAL-MAKTX =
APPEND W_FINAL
W_MARA-MATNR.
W_MARA-ERSDA.
W_MARA-ERNAM.
W_MARA-MTART.
W_MARA-MATKL.
W_MARD-WERKS.
W_MARD-LGORT.
W_MAKT-SPRAS.
W_MAKT-MAKTX.
TO I_FINAL.
ENDLOOP.
********AT LINE-SELECTION EVENT TRIGERING INTERACTIVE REPORTING.*******
AT LINE-SELECTION.
CASE SY-LSIND.
WHEN 1.
**DISPLAY OUTPUT IN NEW SCREEN AT LINE SELECTION BY USER MOUSE CLICK **
WRITE: / W_MARA-MATNR COLOR 2.
READ TABLE I_FINAL INTO W_FINAL WITH KEY MATNR = W_MARA-MATNR SPRAS = 'EN'.
ULINE 1(200).
WRITE : /1 SY-VLINE,
75 'EXAMPLE INTERACTIVE REPORT',
200 SY-VLINE,
SY-ULINE(200),
/1 SY-VLINE,
2 'MATERIAL NUMBER' ,
20 SY-VLINE,
22 'CREATION DATE',
40 SY-VLINE,
42 'USER NAME',
60 SY-VLINE,
62 'MATERIAL TYPE',
80 SY-VLINE,
82 'MATERIAL GROUP',
100 SY-VLINE,
102 'PLANT NUMBER',
120 SY-VLINE,
122 'STORAG LOCATION',
140 SY-VLINE,
142 'LANGUAGE',
160 SY-VLINE,
162 'DESCRIPTION',
200 SY-VLINE,
/ SY-ULINE(200).
WRITE :/1 SY-VLINE,
2 W_FINAL-MATNR ,
20 SY-VLINE,
22 W_FINAL-ERSDA,
40 SY-VLINE,
42 W_FINAL-ERNAM,
60 SY-VLINE,
62 W_FINAL-MTART,
80 SY-VLINE,
82 W_FINAL-MATKL,
100 SY-VLINE,
102 W_FINAL-WERKS,
120 SY-VLINE,
122 W_FINAL-LGORT,
140 SY-VLINE,
142 W_FINAL-SPRAS,
160 SY-VLINE,
162 W_FINAL-MAKTX,
200 SY-VLINE,
/ SY-ULINE(200).
CLEAR W_MARA-MATNR.
ENDCASE.
Description
This is a demo application to download the data from the internal table of the application to a file in the
application server.
Step by Step Guidance.
Go to transaction SE38 to open ABAP editor and Type in the program name click the create button. Here
we have used ZDOWNLOAD_APPL_DEMO as the program name.
SOURCE CODE
REPORT ZDOWNLOAD_APPL_DEMO.
TYPES : BEGIN OF ST_DEMO,
REG_NO(10) TYPE C,
NAME(20) TYPE C,
ADDR(20) TYPE C,
END OF ST_DEMO.
DATA : WA_DEMO TYPE ST_DEMO,
IT_DEMO TYPE TABLE OF ST_DEMO,
L_FNAME TYPE STRING .
PARAMETERS: P_FNAME(128) TYPE C DEFAULT
OBLIGATORY.
L_FNAME = P_FNAME.
WA_DEMO-REG_NO = '100001'.
WA_DEMO-NAME = 'ANAND'.
'\usr\sap\SRI\SYS\src\DOWN.TXT'
WA_DEMO-ADDR = 'NAGARKOVIL'.
APPEND WA_DEMO TO IT_DEMO.
WA_DEMO-REG_NO = '100002'.
WA_DEMO-NAME = 'VIKRAM'.
WA_DEMO-ADDR = 'CHENNAI'.
APPEND WA_DEMO TO IT_DEMO.
OPEN DATASET L_FNAME FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
WRITE :5 'REG NUM',16 'NAME',37 'ADDRESS' .
LOOP AT IT_DEMO INTO WA_DEMO.
IF SY-SUBRC = 0.
TRANSFER WA_DEMO TO L_FNAME.
WRITE :/5 WA_DEMO-REG_NO,16 WA_DEMO-NAME,37 WA_DEMO-ADDR.
ENDIF.
ENDLOOP.
1.
2.
Give the function group name and short text. And click on Save.
3.
4.
Then open the transaction se80 and select the Function group from the drop down list. Enter the
function group name. Press Enter.
5.
6.
7.
8.
Now it will ask for the function group. Enter the function group and give the short text. Press Save.
9.
10. Click on the Import tab and enter the Parameter name, Type and Reference type of variables A and
B.
11. Click on Export tab and enter the Parameter name, Type and reference type of RES.
12. Click on Exceptions tab and enter the Exception and short text for that exception.
13. Now click on the Source code tab and write the following lines as shown bellow.
set_focus
titl
TABLES
data
opts
EXCEPTIONS
others
= 'X'
= 'Company Performances'
= it_performance
= it_opttable
= 1.
Report ZTEST.
DATA flag(1) TYPE c.
* SUBSCREEN 1
SELECTION-SCREEN BEGIN OF SCREEN 100 AS
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH
PARAMETERS: Field1(20) TYPE c,
Field2(20) TYPE c,
Field3(20) TYPE c.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN END OF SCREEN 100.
* SUBSCREEN 2
SELECTION-SCREEN BEGIN OF SCREEN 200 AS
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH
PARAMETERS: q1(20) TYPE c ,
q2(20) TYPE c ,
SUBSCREEN.
FRAME.
SUBSCREEN.
FRAME.
q3(20) TYPE c .
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN END OF SCREEN 200.
* STANDARD SELECTION SCREEN
SELECTION-SCREEN: BEGIN OF TABBED BLOCK mytab FOR 10 LINES,
TAB (20) button1 USER-COMMAND push1,
TAB (20) button2 USER-COMMAND push2,
END OF BLOCK mytab.
INITIALIZATION.
button1 = 'TAB1'.
button2 = 'TAB2'.
mytab-prog = sy-repid.
mytab-dynnr = 100.
mytab-activetab = 'BUTTON1'.
AT SELECTION-SCREEN.
CASE sy-dynnr.
WHEN 1000.
CASE sy-ucomm.
WHEN 'PUSH1'.
mytab-dynnr = 100.
mytab-activetab = 'BUTTON1'.
WHEN 'PUSH2'.
mytab-dynnr = 200.
mytab-activetab = 'BUTTON2'.
ENDCASE.
WHEN 100.
MESSAGE s888(sabapdocu) WITH text-040 sy-dynnr.
WHEN 200.
MESSAGE s888(sabapdocu) WITH text-050 sy-dynnr.
ENDCASE.
MODULE init_0100 OUTPUT.
LOOP AT SCREEN.
IF screen-group1 = 'MOD'.
CASE flag.
WHEN 'X'.
screen-input = '1'.
WHEN ' '.
screen-input = '0'.
ENDCASE.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDMODULE.
MODULE user_command_0100 INPUT.
MESSAGE s888(sabapdocu) WITH text-050 sy-dynnr.
CASE sy-ucomm.
WHEN 'TOGGLE'.
IF flag = ' '.
flag = 'X'.
ELSEIF flag = 'X'.
flag = ' '.
ENDIF.
ENDCASE.
ENDMODULE.
START-OF-SELECTION.
WRITE: / 'Field1:', Field1,'Q1:', q1,
/ 'Field2:', Field2,'Q2:', q2,
Output:
TAB1
TAB2
Introduction:
The purpose of this document is to briefly describe a development, which will dynamically retrieve data
from database tables, based upon user input. Here, table name can be specified by the use or which field
needs to be displayed can be put into selection screen, even which will be the restricting criteria, also can
be specified. The output will be displayed in simple report format.
Along with the report, it will also notify the user whether Primary / Secondary index is being used or not
during data selection.
In production system, there can be two ways of checking data from standard table / Custom table.
Conventional Method:
The following section will briefly describe what are the steps followed to check data using Conventional
method:
Step1:
Run transaction SE16 & put table name as selection criteria.
Step2:
Choose the fields which will be the selection criteria for data selection from settings > Fields for selection
Step3:
Report will be displayed in the following format:
Choose the desired output fields from Settings > Format list > Choose Fields.
Step4:
Number of entries in the table can also be checked using SE16 Transaction.
Step5:
Whether the data selection is done using primary / secondary index can also be checked using
transaction SE11 / ST05.
The
output
will
be
shown
in
the
below
format.
This program will display data in a single step execution. When we are trying to access live system from
remote location each step execution (Dialog step) is very time expensive. This program will reduce the
steps taken to display desired data. Also it will analyze the particular select statement is optimized or not
by specifying the Index.
Introduction
In the following document we will be discussing how to download our report output into excel in the same
format as in the SAP report output by using OLE concept.
To address an OLE Automation Server (e.g. EXCEL) from ABAP, the server must be registered with SAP.
ABAP keywords
ABAP keywords allow us to control the applications in the form of an OLE2 Automation Server from an
ABAP program:
The following ABAP key words control the applications:
1) CREATE OBJECT
This command generates an object of the class class.
Basic form: CREATE OBJECT obj class.
Addition: LANGUAGE langu - determines the language chosen for method and attribute names of the
object class. If no specification is made, English is the default.
This creates the instance for the automation object at the automation interface.
2) SET PROPERTY
This command sets the property prop of the object obj according to the contents of
object obj must be of type OLE2_OBJECT.
Before
starting
with
OLE,
include
type
pool
ole2
in
your
program.
Note that for each OLE object there has to be a variable holding handle data for that object. The type-pool
ole2 defines the handle variable data of the type ole2_object.For all the OLE automation programs
OLE2INCL include should be used.
STEP 1:
First step is to create OLE object for excel application.
CREATE OBJECT gh_excel 'EXCEL.APPLICATION'.
gh_excel is the object of type ole2_object.
STEP 2:
Now different properties of the excel object is to be set as per our requirement.
SET PROPERTY OF gh_excel visible = 0.
The excel sheet is not visible to the user while data transfer.
CALL METHOD OF gh_excel 'Workbooks'= gh_mapl.
This will call the method of excel Workbooks to get the control to object gh_mapl.
gh_mapl is the object of type ole2_object.
CALL METHOD OF gh_mapl 'Add'= gh_map.
It will create a new workbook.
Now create active sheets of excel.
CALL METHOD OF application 'Worksheets' = sheet
EXPORTING #1 = 1.
CALL METHOD OF sheet 'Activate'.
i j bold val.
column = j.
" fill_cell
PERFORM fill_cell USING 3 2 1 WA_OUTPUT-PEIOD. Transferring data to 3rd row and 2nd column.
PERFORM fill_cell USING 4 1 1 S. No.
PERFORM fill_cell USING 4 2 1 Customer Name. Transferring data to 4th row and 2nd column.
PERFORM fill_cell USING 4 3 1 Duration.
PERFORM fill_cell USING 4 4 1 Cost. Transferring data to 4th row and 4th column.
PERFORM fill_cell USING 4 5 1 Bill.
After filling the header part fill all the line item details in excel.
STEP 4:
In this scenario we want some columns to be merged in our excel output.
i.e. (column from A1 to E1, column from B1 to E1, etc..)
Now, for this first we select the range of cells. And then merge the range of cells.
CALL METHOD OF gh_excel RANGE = gh_rang NO FLUSH
EXPORTING #1 = A1
#2 = E1
CALL METHOD OF gh_range SELECT NO FLUSH.
SET PROPERTY OF gh_range MERGE = 1 no flush.
STEP 5:
Now format the excel according to the requirement.
Set
the
CALL METHOD OF wf_excel 'Range' = wf_cell1
EXPORTING
#1 = wf_cell_from1
#2 = wf_cell_to1.
range
Now
Format
the
range
of
cells
SET PROPERTY OF wf_cell1 'NumberFormat' = @. Here we are setting to this format.
NO FLUSH
here,
here
Suppose we want to change the color and width of any particular column.
CALL METHOD OF gh_excel Cells = e_cell
EXPORTING
#1 = 1
#2 = 3
GET PROPERTY OF e_cell 'Interior' = e_color.
SET PROPERTY OF e_color 'ColorIndex' = 35.
SET PROPERTY OF e_cell 'ColumnWidth' = 20.
Codes for different colors.
STEP 6:
At last free all the reserved OLE objects.
i.e. Free object column.
Free object gh_excel.
Now Save excel spreadsheet to particular filename and quit the excel application.
CALL METHOD OF sheet 'SaveAs'
Introduction:
It is a best practice to modularize our programs as much as we can for better programming. If we
want to check one particular module like subroutines, function modules or classes for bugs then
we can do it using ABAP Unit. ABAP Unit is a tool for unit testing of ABAP programs.
How to write these tests:
ABAP unit is based on ABAP objects. The global class CL_AUNIT_ASSERT contains methods
which can be used for testing .Tests are implemented in local classes. Inside the local class the
necessary method from the global class can be called for testing. These test classes can be written
inside the program for which the test is to be done. It will not affect our production code in
anyways.
Difference between Ordinary class and Test class:
Both the test class and test method should have FOR TESTING addition.
Ex:
CLASS mytest DEFINITION FOR TESTING.
PRIVATE SECTION.
METHODS mytest FOR TESTING.
ENDCLASS.
Methods in CL_AUNIT_ASSERT for Testing:
ASSERT_EQUALS
ASSERT_DIFFERS
ASSERT_BOUND
ASSERT_NOT_BOUND
ASSERT_INITIAL
ASSERT_NOT_INITIAL
ASSERT_CHAR_CP
ASSERT_CHAR_NP
ASSERT_EQUALS_F
FAIL
ABORT
- Actual result
EXP
- Expected Result
MSG
LEVEL
QUIT
TOL
Levels:
0 - Tolerable
1 - Critical
2 - Fatal
Class ( 2 )
Program ( 3 ) abandon execution of all test classes for the tested program.
Quit:
Tolerance:
If the tolerance limit specified is exceeded then error is shown.
Ex:
Actual result 24.
Expected Result 25.
Tolerance 0.9999.
Difference = Expected Result - Actual result.
=
>
tolerance.
Example Program:
Let us consider an example for ABAP unit test using the method ASSERT_EQUALS to check
the equality of two data objects. In this program, we have two methods divide and factorial in a
local class MATH. We want to test the factorial method. So we have created one class and one
method MYTEST for testing. In the test method implementation we have called the factorial
method and so the data object RESULT is populated. Now we are going to compare the actual
data object (RESULT) with the expected result. For that we are calling the ASSERT_EQUALS
from the global class passing the expected result.
*----------------------------------------------------------------------*
*
CLASS math DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS math DEFINITION.
PUBLIC SECTION.
METHODS divide
IMPORTING opr1
TYPE i
opr2
TYPE i
EXPORTING result TYPE f
RAISING
cx_sy_arithmetic_error.
METHODS factorial
IMPORTING n TYPE i
RETURNING value(fact) TYPE i.
ENDCLASS.
"math DEFINITION
*----------------------------------------------------------------------*
*
CLASS math IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS math IMPLEMENTATION.
METHOD divide.
result = opr2 / opr1.
ENDMETHOD.
"divide
METHOD factorial.
fact = 1.
IF n = 0.
RETURN.
ELSE.
DO n TIMES.
fact = fact * sy-index.
ENDDO.
ENDIF.
ENDMETHOD.
"factorial
ENDCLASS.
"math IMPLEMENTATION
START-OF-SELECTION.
DATA w_obj TYPE REF TO math.
DATA exc TYPE REF TO cx_sy_arithmetic_error.
DATA res TYPE f.
DATA result TYPE i.
DATA text TYPE string.
CREATE OBJECT w_obj.
TRY.
w_obj->divide( EXPORTING opr1 = 32 opr2 = 4
IMPORTING result = res ).
WRITE : res.
text = res.
CATCH cx_sy_arithmetic_error INTO exc.
text = exc->get_text( ).
MESSAGE text TYPE 'I'.
ENDTRY.
CREATE OBJECT w_obj.
COMPUTE result = w_obj->factorial( 4 ).
WRITE :/ 'The result for factorial is:',result.
*----------------------------------------------------------------------*
*
CLASS mytest DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS mytest DEFINITION "#AU Risk_Level Harmless
FOR TESTING. "#AU Duration Short
PRIVATE SECTION.
METHODS mytest FOR TESTING.
ENDCLASS.
"mytest DEFINITION
*----------------------------------------------------------------------*
*
CLASS mytest IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS mytest IMPLEMENTATION.
METHOD mytest.
CREATE OBJECT w_obj.
result = w_obj->factorial( 4 ).
cl_aunit_assert=>assert_equals( act
= result
exp
= '24'
msg
= 'Factorial Not calculated
Correctly'
level = '0'
quit
= '2'
tol
= '0.999'
).
ENDMETHOD.
"mytest
ENDCLASS.
"mytest IMPLEMENTATION
The task is displayed in a tree structure with a Program name, Class name and method name.
Both the expected and the actual results can be seen in the Unit test results. Also in the stack it
will be displaying the line number where the error occurred. By double clicking the line number
we can enter into the source code.
ABAP Unit results in Code Inspector:
We can see the ABAP unit results in code inspector. While creating the variant, check for the
ABAP unit in Dynamic check.
In the Code inspector results we can check for the ABAP unit errors, warnings and informations.
The checkpoints are the type of statements introduced in the SAP Web Application Server (SAP WebAS)
6.20 that is totally dedicated to ensuring program correctness and maintainability. This improves the
quality of software written in ABAP. These checks are transportable and can be transported .The
transaction that takes care of these checkpoints and the place where they are maintained is SAAB.
The Checkpoints now can be created for break-points and checkpoints and the two statements for this
are
1. Assertions
2. Break-points
The one which actually does not checks the errors but is used to log the data that u want is LOG-POINT.
To start with step by step explanation of the checkpoints we start first with the Assertions.
Assertions syntax as per the SAP Library that is to be used in the coding is as below:
ASSERT
[[ID
[FIELDS
field1
CONDITION] log_exp.
group
field2
[SUBKEY
table1
subkey]]
table2...]
Assertions are used as a high quality means of problem determination in the case of code failure.
Assertions are invoked at run time. They can be made active or inactive. Assertions can be left in code
when promoted to production with no impact to the code. They are only invoked if the checkpoint group is
activated.
The checkpoint groups can be activated through the transaction SAAB and that is referred by ID in the
programs with assert statements.
This is the transaction below SAAB where in the checkpoint group we can create the group ID.
Clicking on the create button below the Name we get to the below screen.
And similarly it can be done for specific Servers on clicking on the add Sign as below:
There
are three things that can be controlled with the checkgroups.
The breakpoints can be made active or inactive. Inactive then that particular statement will be ignored and
if break then in the program wherever the statement occurs the program gets into debugging.
The Statement as per the SAP Library that goes with this in the Program is as below
BREAK-POINT
| [log text] }.
[ID
groupID]
The below two options come with a pop-up having options as:
The
Break/Log: program is interrupted and starts the debugger / like LOG mode in background, batch
etc.
Break/Abort: program is interrupted and starts the debugger / like ABORT mode in background,
batch etc.
below
two
options
come
as
this...
Assertion RULES:
1. Exception handling should always be used to trap and handle failures. DO NOT use an assertion
in the place of exceptions.
2. Assertions should only be used on custom code rather than on standard codes.
3. When an assertion is invoked, it should create a log entry unless and until there is a compelling
reason to terminate with a run time error.
Here is a sample program where the LOG-Points and ASSERTIONS are used.
REPORT yh1316_test_checkgrp..
** Parameters Declarations
PARAMETERS:
p_carrid LIKE sflight-carrid.
*data : max type i.
*Types Declarations of sflight
TYPES : BEGIN OF type_s_sflight,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
fldate TYPE sflight-fldate,
price TYPE sflight-price,
max TYPE i,
END OF type_s_sflight.
*Field String Declarations for sflight
DATA: fs_sflight TYPE type_s_sflight.
*Internal table for Sflight Data
DATA : t_sflight LIKE
STANDARD
TABLE OF fs_sflight.
DATA yh1316_subkey TYPE char200.
IF p_carrid IS INITIAL.
SELECT carrid
connid
fldate
price
FROM sflight
INTO fs_sflight.
WRITE:
fs_sflight-connid,
fs_sflight-fldate,
fs_sflight-price.
/ fs_sflight-carrid,
'YH1316_2'
IF sy-dbcnt < 4.
APPEND fs_sflight TO t_sflight.
LOG-POINT ID yh1316_check SUBKEY 'LOG_POINT'
FIELDS p_carrid
t_sflight
fs_sflight-connid
fs_sflight-fldate
fs_sflight-max.
WRITE: / fs_sflight-carrid, fs_sflight-connid, fs_sflight-fldate,
fs_sflight-max.
ENDIF.
ENDSELECT.
ENDIF.
A variant is created for the Particular Checkgroup created. Variant can be created as a Local as well as at
a user level. Here it is created at the User Level.
There are four kind of object type for which a variant can be created as
1. Check Group
2. Program
3. Class
4. Function Group
And for particular Object type the Different options can be given for Breakpoint, Logpoint and Assert. The
Options for them are same as stated before in the Personal Activation screen for check group.
Now save the variant and then go back to the checkgroup for which we have created the variant. Dont
forget to activate the variant.
As above it is seen the Local variant is visible in the Variants tab the same way we can create a Global
variant also.
Now run the Program.
If the assertion condition is violated the listed logs are created for the assertion as we have selected the
log for assertion in the SAAB transaction in the Check Group.
The log will also be created for the LOG-POINT statement and the SUBKEY there defines the Key to
distinguish that the log has been created for which Assertion and checkpoint.
In the Log the data is segregated according to the two Hierarchies:1. Gropu/Subkey/Program/Procedure
2. Group/Program/Procedure/Subkey
The log seen is like this.
Double clicking on the Line where the Include line number is seen we can see the description of the log
as below.
As we have logged the table entries also double clicking on the table we can see the table entries too.
Coverage Analyzer is a very powerful runtime analysis tool provided by SAP that enables an ABAP
developer to monitor processing blocks such as reports, subroutines, function-modules and methods.
Powerful filtering system in Coverage Analyzer facilitates developer to enter the number of calls
separately according to periods, users and functional areas.
In a nut-shell; Coverage Analyzer is a function for monitoring the system-wide execution of ABAP
programs;
It enables the success of test activities to be assessed for quality checks.
It also provides an overview of the use of programs for development purposes.
Developer can use this tool to trace programs for development purpose and Quality Manager can use this
tool to check system performance for quality assurance.
It helps carry out a range of Administration Settings and the Monitoring Activity. Moreover it helps get
summarized information of number of program executions, number of runtime errors, number of program
resets. Fascinatingly, the results can be formatted separately according to user-group; each user-group
can contain any number of users under one test key.
Broadly, functions of Coverage Analyzer are classified into two;
1.
2.
Administration Settings
On/Off.
Test Groups.
Registrations.
Reset.
Settings.
Monitor.
Consistency Checks.
Display
Global.
Detail.
A simple exercise will help us easily understand Coverage Analyzer, rather simply going through
documentation.
In order to make use of Coverage Analyzer, user has to have an appropriate role. To check user
authorization;
Call up transaction SUIM (User Information System).
Expand Authorizations node.
Choose By Object and execute it (press F8).
Confirm
the
where-used
list
for
profiles
using
icon
or
Ctrl+Shift+F11.
Once user authorization is checked to have absolute access to SCOV (Coverage Analyzer) transaction;
user can proceed further. If a role is not assigned to a user, Basis consultant has to be consulted in this
regards.
In fact, a tip to be remembered is that Coverage Analyzer tool should be used on weekends or in the
evening, when all users and packages are on loose ends. Since backup server collects data from all the
servers including local and remote; system needs all packages and users to be in the passive mode.
Lets start up with a simple example to understand Coverage Analyzer in a better way:
STEP 1: Call up the transaction SCOV or navigate through SAP Easy Access->SAP Menu->Tools->ABAP
Workbench->Test->SCOV (Coverage Analyzer).
General Status of the system is shown on the right hand pane of the window;
Coverage Analyzer administration includes all of the functions required for carrying out settings and
checks.
Administration and Display nodes are shown on the left pane of the window.
STEP 2: Before the Coverage Analyzer being switched on, settings have to be maintained for backup
server and filters are to be set. Having not made settings for backup server, if Coverage Analyzer is
started, it simply throws out an information message to maintain background server for data collection.
So, Administration settings are to be done before starting up the Coverage Analyzer.
Expand Administration node, select Settings;
Settings function is used to set the parameters for the Global and Detail views, and to filter the programs
to be checked via the package.
In order to make settings, switch settings to Change Mode (Cntrl+F1).
Tip to remember: A program is regarded as tested if the following conditions are fulfilled;
Count1 Absolute Value >
0.
0.
Unicode Check
1.
0.
Count1 and RABAX1 indicate the number of programs executed and runtime errors since the Coverage
Analyzer was started.
Count2 and RABAX2 indicate the number of programs executed and runtime errors since the last reset.
Further, assign package to be used during analysis. When a package is pre-selected, the evaluation for
the Global view is only performed for this package. If this restriction is not applied, all of the programs are
included together with those from local packages ($*) and programs generated locally without
packages ( ).
If ABAP programs with a set Unicode flag are only to be traced by the Coverage Analyzer, then select
Unicode checkbox. Checking Unicode is to mark it as X, else leave it unattended.
Its optional to set the lights; lights provide a visual means of representing the status of the results for the
degree of coverage in the Global and Detail views.
Lights are set by default, which can be set according to developers way of analysis.
RED
0 LT 33 %
YELLOW
33 LT 66 %
GREEN66 LE 100%
Further, Monitor Settings have to be done, which includes setting Trace Level and Maximum Entries Log
and Maximum Entries Data Monitor.
There are 4 different trace levels (1-4), the higher the trace level, the more information is drawn for
debugging.
Tip: The values for Maximum Entries Log and Maximum Entries Data Monitor limit the lines displayed for
the General Log and Monitor Data Volumes in the monitor function.
The defaulted lines for log file are 100 and for data volume are 200.
Background server has to be specified, where precisely data is to be collected. Moreover, the period for
which background job has to be repeated is also to be specified.
The defaulted value for Data Collection: Period (Min) is 30 mins, which can be modified based on
developers way of analysis. In this case, current server is specified as Background server.
Further, Summarization function facilitates checking the same processing blocks in several systems
simultaneously.
Tip to remember: The results from the individual systems are local and those from the remote systems
are summarized.
Local Degree of coverage
LE
100%.
100%.
Desired RFC connections in Summarize coverage results can be specified; moreover period and start
time for summarize data can also be specified.
If the server is in switched-off mode exception shows RED signal, GREEN signifies server to be in
switched-on mode and YELLOW represents either RFC problem or database and shared memory
inconsistency.
In this case, well proceed without switching on Switch Automatic Recording On/Off.
The servers which are actually running are shown as flagged up.
STEP 4: Create Test-Groups; Test-Groups are made to summarize and display the results of the
Coverage Analyzer for a particular set of users under one generic key/heading.
Tip to remember: Test-groups should not be created more than 10. Moreover, only users assigned a role
with the authorization object S_COV_ADM are allowed to define group.
Two pre-defined Test-groups are always available;
ALL
Coverage results summarized for all test groups on the local system.
Select desired test-group for which users have to be assigned; in this case we assign SAPDEV02 as user
to test-group ZTST.
Tip: A test-group can contain any number of users, for example, all HR developers in one group. That
makes filtering pretty easy. Moreover, comparison of performance of test-groups can be done in Global
view.
STEP 6: An optional function to be done is Reset; explicitly this function is intended for situations in which
the results of the previous analyses are no longer required. It resets all the counters of the Coverage
Analyzer to 0 for all the programs of a selected group.
Further more, implicit reset is carried out automatically as soon as the flow or the data of a program
changes.
After successful reset, an information message is popped-up;
STEP 7: Consistency check has to be done for all the servers including remote ones, before proceeding
to actual analysis;
Check Status of All Servers checks whether the status in the shared memory matches the status in the
database.
Check Status of Background Jobs checks whether all the batch jobs of the Coverage Analyzer are
activated. If this is not the case, the batch jobs are all rescheduled by means of the Repair function.
Check Table Consistency (Long Runtime) may become inconsistent if the Coverage Analyzer fails on an
application server due to system error.
Repair function also bridges the gap between activating and generating a program.
So, in order to check inconsistencies, check the types of inconsistencies accordingly and Execute
Checks, and then choose monitor to check for the inconsistency messages,
GREEN indicates Information message, YELLOW indicates Warning message and RED indicates Error
message.
In the present case; no inconsistencies have been found while starting All Servers. In case, there arise
any warning or error messages, those problems are to be fixed and then select particular row of the
warning/error message and click Completed.
General Log gives general information, while Monitor Volume gives detailed information of started server.
Once the warning is attended, select the row and hit Completed, which will going to turn yellow signal to
green signal.
Tip: Every time inconsistencies are checked; General Log should be refreshed.
To select more than 1 message, keep Cntrl key pressed.
STEP 8: Display; gives coverage results at author or package level according to criteria you select under
Settings. Display gives high-level view.
Views can be based on Author or Package. ALL signifies all the authors on local system based on view
given and the COND (y/z test groups) signifies all the authors on both local and remote systems based on
view given. If Other view is selected as Package, then selection is done accordingly.
Note: Since Automatic Recordings were not switched on; percentage-based progress display over time
cannot be seen for selected SAPDEV02 author.
Normally, Display view gives Quality Managers to view the system, the following way;
Unicode:
This value indicates how many percent of the processing blocks have the Unicode flag set (the flag itself
is set per program)
Capacity Utilization:
This value is computed as the ratio of used processing blocks to loaded processing blocks to loaded
processing blocks.
Accumulated Executions (Percent)
This value indicates in percent how many processing blocks have been executed since the start of the
Coverage Analyzer.
Tested processing blocks (Percent)
This value indicates in percent how many processing blocks have been executed in the actual version
without runtime errors.
In the example above you can see that currently 98% of the processing blocks in the system belong to a
program that has the Unicode flag set, 26% have been executed since start of the coverage analyzer, 9%
have been executed in the active version without errors and the capacity utilization is 29%.
STEP 9: Exact Value Table can be viewed for author SAPDEV02; which displays number processing
blocks for author SAPDEV02 on timely manner.
Tip: Moreover, previous saved history can also be viewed for the specific user.
STEP 10: Details view; gives summarized and detailed results. Details give low-level view.
Strong filtering options allow user to select on what conditions results are to be displayed.
Conditions can be set for range of test-groups, packages and authors pertaining to those test-groups.
In the present example; test-group ZTST and Author SAPDEV02 is taken as single-value selection, which
gives results pertaining to specified criteria. Moreover, other filters can also be set and settings should be
done defining access via Package Object, Package and Author. Defaulted access-via is Program Object.
Note: Current Executions = Program units currently used / Total no. of Program units.
Capacity Utilization = No. of Program units currently used / Loaded Program units.
Conclusion: Likewise, many such program executions, runtime errors and program resets can be easily
traced using this powerful ABAP runtime analysis tool - Coverage Analyzer.
1)
2)
a)
b)
SAPFTPA (for running in Application server)(This is used for file transfer in background.
Code sample for developing FTP programs can be got from report program
a)
RSFTP002
b)
RSFTP007
c)
3)
RSFTP008
Sample code for getting customer details as tab delimited .TXT file in background.
*&---------------------------------------------------------------------*
*& Report ZCUSTOMER
*&
*&---------------------------------------------------------------------*
*&-Customer -All new/changed customer records created during the period.
*&---------------------------------------------------------------------*
*LedgerKey-------------Char(50)
*AccountName-----------Char(80)
*AccountReference -----Char(50)
*Address1 -------------Char(80)
*Address2 -------------Char(80)
*Town -----------------Char(50)
*County / State -------Char(50)
*Post Code / ZIP ------Char(20)
*Country---------------Char(2)
*AccountCurrencyCode --Char(3)
*ContactTelephone -----Char(20)
REPORT zcustomer.
TABLES: kna1,knb1.
TYPES: BEGIN OF st_customer,
ledgerkey TYPE char50,
name1 TYPE kna1-name1,
kunnr TYPE kna1-kunnr,
name2 TYPE kna1-name2,
stras TYPE kna1-stras,
ort01 TYPE kna1-ort01,
regio TYPE kna1-regio,
pstlz TYPE kna1-pstlz,
land1 TYPE kna1-land1,
waers TYPE knvv-waers,
telf1 TYPE kna1-telf1,
END OF st_customer.
TYPES : BEGIN OF st_cus,
ledgerkey(50) TYPE c, "LedgerKey
wrk_delim1
TYPE x ,
name1(80)
TYPE c, "AccountName
wrk_delim2
TYPE x ,
kunnr(50)
TYPE c, "AccountReference
wrk_delim3
TYPE x ,
name2(80)
TYPE c,
"Address1
wrk_delim4
TYPE x ,
stras(80)
TYPE c,
" Address2
wrk_delim5
TYPE x ,
ort01(50)
TYPE c,
" Town
wrk_delim6
TYPE x ,
regio(50)
TYPE c,
" County / State
wrk_delim7
TYPE x ,
pstlz(10)
TYPE c,
"Post Code / ZIP
wrk_delim8
TYPE x ,
land1(2)
TYPE c,
"Country
wrk_delim9
TYPE x ,
waers(3)
TYPE c,
"AccountCurrencyCode
wrk_delim10
TYPE x ,
telf1(20)
TYPE c,
"ContactTelephone
END OF st_cus .
DATA: wrk_file TYPE char200.
DATA: it_customer TYPE STANDARD TABLE OF st_customer,
wa_customer LIKE LINE OF it_customer.
DATA: it_dat TYPE STANDARD TABLE OF st_cus,
wa_dat LIKE LINE OF it_dat.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-001.
SELECT-OPTIONS:cust_no FOR kna1-kunnr,"customer no
com_code FOR knb1-bukrs,"company code
country FOR kna1-land1, "country
creat_on FOR kna1-erdat default sy-datum. "created or changed
on
SELECTION-SCREEN END OF BLOCK b2.
START-OF-SELECTION.
IF creat_on-high IS INITIAL.
creat_on-high = creat_on-low.
ENDIF.
CONCATENATE sy-mandt '_1_' creat_on-low '_' creat_on-high '_Cust.txt' INTO
wrk_file.
PERFORM customer_data_select.
"Customer Data File
PERFORM build_template_data.
PERFORM ftp_file_customer.
*&---------------------------------------------------------------------*
*&
Form CUSTOMER_DATA_SELECT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM customer_data_select .
SELECT a~name1 a~name2 a~kunnr a~stras a~ort01 a~regio a~pstlz a~land1
a~telf1
"Details of the Customer based on KNA1.
FROM kna1 AS a
INNER JOIN knb1 AS b ON a~kunnr = b~kunnr
INTO CORRESPONDING FIELDS OF TABLE it_customer
WHERE a~kunnr IN cust_no
AND ( ( a~erdat IN creat_on OR a~updat IN creat_on ) OR
( b~erdat IN creat_on OR b~updat IN creat_on ) )
AND a~land1 IN country
AND b~bukrs IN com_code.
IF sy-subrc = 0.
LOOP AT it_customer INTO wa_customer.
SELECT SINGLE waers FROM knvv INTO wa_customer-waers
WHERE kunnr = wa_customer-kunnr..
wa_customer-ledgerkey = '12345'.
MODIFY it_customer FROM wa_customer.
ENDLOOP.
ENDIF.
ENDFORM.
" CUSTOMER_DATA_SELECT
*&---------------------------------------------------------------------*
*&
Form BUILD_TEMPLATE_DATA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM build_template_data .
LOOP AT it_customer INTO wa_customer.
MOVE-CORRESPONDING wa_customer TO wa_dat.
wa_dat-wrk_delim1 = '09'. "for adding tab after each field
wa_dat-wrk_delim2 = '09'.
wa_dat-wrk_delim3 = '09'.
wa_dat-wrk_delim4 = '09'.
wa_dat-wrk_delim5 = '09'.
wa_dat-wrk_delim6 = '09'.
wa_dat-wrk_delim7 = '09'.
wa_dat-wrk_delim8 = '09'.
wa_dat-wrk_delim9 = '09'.
wa_dat-wrk_delim10 = '09'.
APPEND wa_dat TO it_dat.
ENDLOOP.
ENDFORM.
" BUILD_TEMPLATE_DATA
*&---------------------------------------------------------------------*
*&
Form FTP_FILE_CUSTOMER
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM ftp_file_customer .
DATA: l_user(30) TYPE c VALUE 'ZTEST', "user name of ftp server
l_pwd(30) TYPE c VALUE '1234', "password of ftp server
l_host(64) TYPE c VALUE '111.2.1.198', "ip address of FTP server
l_dest LIKE rfcdes-rfcdest VALUE 'SAPFTPA'."Background RFC
destination
DATA: w_hdl TYPE i,
c_key TYPE i VALUE 26101957,
l_slen TYPE i.
*HTTP_SCRAMBLE: used to scramble the password provided in a format recognized
by SAP.
SET EXTENDED CHECK OFF.
l_slen = STRLEN( l_pwd ).
CALL FUNCTION 'HTTP_SCRAMBLE'
EXPORTING
SOURCE
= l_pwd
sourcelen
= l_slen
key
= c_key
IMPORTING
destination = l_pwd.
* To Connect to the Server using FTP
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
user
= l_user
password
= l_pwd
host
= l_host
rfc_destination = l_dest
IMPORTING
handle
= w_hdl
EXCEPTIONS
OTHERS
= 1. .
*FTP_R3_TO_SERVER:used to transfer the internal table data as a file to other
system in the character mode.
CALL FUNCTION 'FTP_R3_TO_SERVER'
EXPORTING
handle
= w_hdl
fname
= wrk_file
"file path of destination system
character_mode = 'X'
TABLES
text
= it_dat
EXCEPTIONS
tcpip_error
= 1
command_error = 2
data_error
= 3
OTHERS
= 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
RAISING invalid_output_file.
ENDIF.
*FTP_DISCONNECT: This is used to disconnect the connection between SAP and
other system.
* To disconnect the FTP
CALL FUNCTION 'FTP_DISCONNECT'
EXPORTING
handle = w_hdl.
*RFC_CONNECTION_CLOSE:This is used to disconnect the RFC connection between
SAP and other system.
CALL FUNCTION 'RFC_CONNECTION_CLOSE'
EXPORTING
destination = l_dest
EXCEPTIONS
OTHERS
= 1.
ENDFORM.
" FTP_FILE_CUSTOMER
On running this report in background a file will be created in ftp server location.
This example shows how we can convert an XML file with many hierarchy levels to ABAP format.
Copy and paste the following code in notepad and save it as test.xml file.
Save the XML file which in desktop or some other path
<?xml version="1.0" encoding="UTF-8" ?>
<ZEU_MATMAS03>
<IDOC BEGIN="1">
<EDI_DC40 SEGMENT="1">
<DOCNUM>0000000000038491</DOCNUM>
<MESTYP>ZEU_MATMAS</MESTYP>
</EDI_DC40>
<E1MARAM SEGMENT="1">
<MSGFN>004</MSGFN>
<MATNR>000000000000010003</MATNR>
<E1MAKTM SEGMENT="1">
<MSGFN>005</MSGFN>
<SPRAS>E</SPRAS>
<MAKTX>promo pack normal</MAKTX>
<SPRAS_ISO>EN</SPRAS_ISO>
</E1MAKTM>
</E1MARAM>
</IDOC>
</ZEU_MATMAS03>
Here we can see that the root node is ZEU_MATMAS03 which is the main structure containing all other
structures.
It contains IDOC structure which in turn contains E1MARAM and EDI_DC40 structures within.
EDI_DC40 contains DOCNUM and MESTYP fields.
E1MARAM contains E1MAKTM structure and MSGFN and MATNR fields.
In SAP we have to create corresponding structures to store this data from XML to ABAP.The main
structure contains many deep structures.
So in ABAP dictionary we first create the structure ZIDOC_TEST which contains Structures ZEDIDC40
and Z1EMARAM_TEST1.
The structure ZE1MARAM_TEST1 contains the following fields MSGFN and MATNR.Also a deep
structure E1MAKTM.
E1MAKTM Structure is a standard dictionary structure we are using directly with the fields
MSGFN,SPRAS,MAKTX and SPRAS_ISO.
The following ABAP program converts the given input XML file to ABAP format.
TYPE-POOLS abap.
*Input file contents as string.XML file path where we saved the file. *Here it is saved in desktop.
*Input
file
CONSTANTS gs_file TYPE string
with
path
as
constant
VALUE 'C:\Documents and Settings\Administrator\Desktop\test1.xml'.
we
created
from
* Table and work areas for the data from the XML file
DATA: gt_zeu_matmas03 TYPE STANDARD TABLE OF ts_zeu_matmas03,
gs_zeu_matmas03 TYPE ts_zeu_matmas03.
* Result table that contains references
* of the internal tables to be filled
DATA: gt_result_xml TYPE abap_trans_resbind_tab,
gs_result_xml TYPE abap_trans_resbind.
* For error handling
DATA: gs_rif_ex TYPE REF TO cx_root,
gs_var_text TYPE string.
* Get the XML file from your client
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename
= gs_file
CHANGING
data_tab
= gt_itab
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
not_supported_by_gui = 17
error_no_gui
= 18
OTHERS
= 19.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
in
SE11
file
ENDIF.
* Fill the result table with a reference to the data table.
* Within the XSLT style
* "IDOC_GET".
</IDOC_GET>
</asx:values>
</asx:abap>
</xsl:template>
<xsl:template match="IDOC">
<item>
<IDOC>
<ZEDIDC40>
<MESTYP><xsl:value-of select="EDI_DC40/MESTYP"/></MESTYP>
<DOCNUM><xsl:value-of select="EDI_DC40/DOCNUM"/></DOCNUM>
</ZEDIDC40>
<ZE1MARAM_TEST1>
<MSGFN><xsl:value-of select="E1MARAM/MSGFN"/></MSGFN>
<MATNR><xsl:value-of select="E1MARAM/MATNR"/></MATNR>
<E1MAKTM>
<MSGFN><xsl:value-of select="E1MARAM/E1MAKTM/MSGFN"/></MSGFN>
<SPRAS><xsl:value-of select="E1MARAM/E1MAKTM/SPRAS"/></SPRAS>
<MAKTX><xsl:value-of select="E1MARAM/E1MAKTM/MAKTX"/></MAKTX>
<SPRAS_ISO><xsl:value-of
select="E1MARAM/E1MAKTM/SPRAS_ISO"/></SPRAS_ISO>
</E1MAKTM>
</ZE1MARAM_TEST1>
</IDOC>
</item>
</xsl:template>
</xsl:transform>
*Come back to ABAP editor and copy this code for error handling.
on
document
message
*all
fields
of
E1MAKTM
/ gs_zeu_matmas03-idoc-ze1maram_test1-e1maktm-msgfn,
/ gs_zeu_matmas03-idoc-ze1maram_test1-e1maktm-spras,
/ gs_zeu_matmas03-idoc-ze1maram_test1-e1maktm-maktx,
/ gs_zeu_matmas03-idoc-ze1maram_test1-e1maktm-spras_iso.
ENDLOOP.
ENDIF.
screen.
no
type
function
segment
We can see the values filled in the heirarchy structure of IDOC as follows:-
Execute the ABAP program and we get the file contents displayed as below.So we have converted the
given XML File to a structure and display the contents.
Dialog Programming
Table Control using Wizard in Module Pool Programming
By Venkatraman N, IBM
Pre-requisites:
The readers must be able to create a module pool program and they should be familiar with screen
programming.
Purpose of this tutorial:
This is to demonstrate the step by step tutorial of how to make use of table control with wizard, where the
developers effort to write code with table control without wizard is avoided.
Introduction:
Table control with wizard is the control provided by SAP, in which the users are not needed to code
separately for table control operations. It generates automatically system generated code for the following
table control operations.
1. Insertion
2. Deletion
3. Scrolling
4. First
5. Last
6. Next
7. Previous
8. Select
9. Select all
10. Deselect
11. Deselect all
Step 1: Create an internal table and work area, which we are going to deploy in table control.
Step 3: Go to the layout of the screen, where you can find the table control with wizard. Drag and drop the
table control with wizard to the layout of the screen.
Once you drag and drop the control a popup will appear.
Press Continue. In the next screen enter the table control name as TBC_9000 or your own name.
In the next screen you input the internal table and work area which has been created earlier.
Note: Before it is done, you must activate the page, in which you have declared the internal table and
work area. Then only this table control screen will take its properties.
The next screen will automatically retrieve the fields available in the internal table and show. We have to
select those fields, which and all should be displayed in table control.
If you have declared any character field for table control line selection, that should not be selected in this
screen.
Select the input/output attributes as Input control and give the field for selection of table control rows.
Select the multiple line selection.
Click on Continue. The table control with auto generated code will automatically be created.
This will automatically create PBO & PAI modules for table control operations.
Step 4: For testing this tutorial, write a simple query to populate the internal table of table control and test
the input controls associated with it.
Summary :
As a result of this tutorial, the user will be able to
4.
5.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
The following is our attempt to explain how to implement the text editor control on classic dynpros.
Text editor is displayed on screen using custom control. So we need a container for the custom control.
And text editor control is implemented using class CL_GUI_TEXTEDIT.
Our declaration part contains
DATA: LINE_LENGTH
EDITOR_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
TEXT_EDITOR
TYPE REF TO CL_GUI_TEXTEDIT,
TEXT
TYPE STRING.
Then call the screen (can be any number)
START-OF-SELECTION.
CALL SCREEN '100'.
Go to screen 100 by double clicking on '100'.
Create a custom control on screen with name TEXTEDIT.
EXPORTING
PARENT
= EDITOR_CONTAINER
WORDWRAP_MODE = CL_GUI_TEXTEDIT=>WORDWRAP_AT_FIXED_POSITION
WORDWRAP_POSITION
= LINE_LENGTH
WORDWRAP_TO_LINEBREAK_MODE = CL_GUI_TEXTEDIT=>TRUE.
You can hide the toolbar and as well as status bar for the text editor control.
CALL METHOD TEXT_EDITOR->SET_TOOLBAR_MODE
EXPORTING
TOOLBAR_MODE = CL_GUI_TEXTEDIT=>FALSE.
CALL METHOD TEXT_EDITOR->SET_STATUSBAR_MODE
EXPORTING
STATUSBAR_MODE = CL_GUI_TEXTEDIT=>FALSE.
Define and create a GUI Status in the PBO.
SET PF-STATUS 'STATUS_0100'.
Very minimum set of tool bar buttons defined in this example
In PAI of the screen 100, handle the save and other user commands.
CASE SY-UCOMM.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'SAVE'.
CALL METHOD TEXT_EDITOR->GET_TEXTSTREAM
*
EXPORTING
*
ONLY_WHEN_MODIFIED = CL_GUI_TEXTEDIT=>TRUE
IMPORTING
TEXT
= TEXT
*
IS_MODIFIED
=
EXCEPTIONS
ERROR_CNTL_CALL_METHOD = 1
NOT_SUPPORTED_BY_GUI = 2
OTHERS
= 3.
IF SY-SUBRC <> 0.
WORDWRAP_MODE
= CL_GUI_TEXTEDIT=>WORDWRAP_AT_FIXED_POSITION
WORDWRAP_POSITION
= LINE_LENGTH
WORDWRAP_TO_LINEBREAK_MODE = CL_GUI_TEXTEDIT=>TRUE.
*3)HIDE TOOLBAR AND STATUSBAR
CALL METHOD TEXT_EDITOR->SET_TOOLBAR_MODE
EXPORTING
TOOLBAR_MODE = CL_GUI_TEXTEDIT=>FALSE.
CALL METHOD TEXT_EDITOR->SET_STATUSBAR_MODE
EXPORTING
STATUSBAR_MODE = CL_GUI_TEXTEDIT=>FALSE.
ENDIF.
ENDMODULE.
" STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'SAVE'.
CALL METHOD TEXT_EDITOR->GET_TEXTSTREAM
*
EXPORTING
*
ONLY_WHEN_MODIFIED = CL_GUI_TEXTEDIT=>TRUE
IMPORTING
TEXT
= TEXT
*
IS_MODIFIED
=
EXCEPTIONS
ERROR_CNTL_CALL_METHOD = 1
NOT_SUPPORTED_BY_GUI = 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 METHOD CL_GUI_CFW=>FLUSH
EXCEPTIONS
CNTL_SYSTEM_ERROR = 1
CNTL_ERROR
=2
OTHERS
= 3.
MESSAGE TEXT TYPE 'I'.
ENDCASE.
ENDMODULE.
" USER_COMMAND_0100 INPUT
The final Screen shot of the editor:
Step 1: Upload picture into SAP using the transaction SE78. Test picture.
Step 3: In the PBO module of the screen, attach the following code. Please note that the object name is
winny, please pass your own object name to the method:
*&---------------------------------------------------------------------*
*&
Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE STATUS_9000 OUTPUT.
DATA: W_LINES TYPE I.
TYPES PICT_LINE(256) TYPE C.
DATA :
CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
EDITOR TYPE REF TO CL_GUI_TEXTEDIT,
PICTURE TYPE REF TO CL_GUI_PICTURE,
PICT_TAB TYPE TABLE OF PICT_LINE,
URL(255) TYPE C.
DATA: GRAPHIC_URL(255).
DATA: BEGIN OF GRAPHIC_TABLE OCCURS 0,
LINE(255) TYPE X,
END OF GRAPHIC_TABLE.
DATA: L_GRAPHIC_CONV TYPE I.
DATA: L_GRAPHIC_OFFS TYPE I.
DATA: GRAPHIC_SIZE TYPE I.
DATA: L_GRAPHIC_XSTR TYPE XSTRING.
.
CALL METHOD CL_GUI_CFW=>FLUSH.
CREATE OBJECT:
CONTAINER EXPORTING CONTAINER_NAME = 'PICTURE_CONTAINER',
PICTURE EXPORTING PARENT = CONTAINER.
CALL METHOD CL_SSF_XSF_UTILITIES=>GET_BDS_GRAPHIC_AS_BMP
EXPORTING
P_OBJECT
= 'GRAPHICS'
P_NAME
= 'WINNY'
P_ID
= 'BMAP'
P_BTYPE
= 'BCOL'
RECEIVING
P_BMP
= L_GRAPHIC_XSTR
* EXCEPTIONS
*
NOT_FOUND
= 1
*
INTERNAL_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.
GRAPHIC_SIZE = XSTRLEN( L_GRAPHIC_XSTR ).
L_GRAPHIC_CONV = GRAPHIC_SIZE.
L_GRAPHIC_OFFS = 0.
WHILE L_GRAPHIC_CONV > 255.
GRAPHIC_TABLE-LINE = L_GRAPHIC_XSTR+L_GRAPHIC_OFFS(255).
APPEND GRAPHIC_TABLE.
L_GRAPHIC_OFFS = L_GRAPHIC_OFFS + 255.
L_GRAPHIC_CONV = L_GRAPHIC_CONV - 255.
ENDWHILE.
GRAPHIC_TABLE-LINE = L_GRAPHIC_XSTR+L_GRAPHIC_OFFS(L_GRAPHIC_CONV).
APPEND GRAPHIC_TABLE.
CALL FUNCTION 'DP_CREATE_URL'
EXPORTING
TYPE
= 'IMAGE'
SUBTYPE = 'X-UNKNOWN'
SIZE
= GRAPHIC_SIZE
LIFETIME = 'T'
TABLES
DATA
= GRAPHIC_TABLE
CHANGING
URL
= URL.
CALL METHOD PICTURE->LOAD_PICTURE_FROM_URL
EXPORTING
URL = URL.
CALL METHOD PICTURE->SET_DISPLAY_MODE
EXPORTING
DISPLAY_MODE = PICTURE->DISPLAY_MODE_FIT_CENTER.
ENDMODULE.
" STATUS_9000 OUTPUT
Output:
SCREEN PAINTER:Screen painter is a tool in ABAP dev workbench used to create the screens using the
T-code SE51. In the screen painter, you can define the following interface elements with their
associated
attributes.
1.
Input/Output
Fields
2.
Field
Names
3.
Checkboxes
4.
Radio
Buttons
5.
Group
Boxes
6.
Sub
screens.
7. Pushbuttons with No Fixed Position
and others
STEP-BY-STEP DEMO FOR SCREEN PAINTER.
Following pop-up screen appears. Select the zdemo_screen_painter main program and click
on continue.
Click on yes.
Now come back to the transaction SE51. Select flow logic. Click in layout.
Screen painter window will be displayed like this. Here we will design the required screen fields.
Click on the middle icon
Select the required fields from MARA table from dictionary. Click on OK or continue.
After placing the required fields, you can view the below screen.
Select the pushbutton, drag and drop the button onto the screen.
Create the other required buttons in the same procedure mentioned above and assign the name, text,
and function code for each one.
******************************************************************
* TABLE DECLARATIONS.
******************************************************************
TABLES: MARA.
******************************************************************
* DATA DECLARATIONS.
*****************************************************************
DATA: MATNR TYPE MARA-MATNR,
ERSDA TYPE MARA-ERSDA,
ERNAM TYPE MARA-ERNAM,
MTART TYPE MARA-MTART,
MATKL TYPE MARA-MATKL,
DISPLAY TYPE C,
SAVE TYPE C,
DELETE TYPE C,
CLEAR TYPE C,
EXIT TYPE C,
OK_CODE LIKE SY-UCOMM.
*****************************************************************
* CALLING SCREEN.
*****************************************************************
CALL SCREEN 100.
*&--------------------------------------------------------------*
*&
Module STATUS_0100 OUTPUT
*&--------------------------------------------------------------*
*
text
*--------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
* SET PF-STATUS 'ZMENU'.
* SET TITLEBAR 'ZMENU_PAINTER'.
CASE SY-UCOMM.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'BACK'.
LEAVE PROGRAM.
WHEN 'DISPLAY'.
SELECT SINGLE ERSDA ERNAM MTART MATKL FROM MARA
INTO (MARA-ERSDA, MARA-ERNAM, MARA-MTART, MARA-MATKL)
WHERE MATNR = MARA-MATNR.
WHEN 'CLEAR'.
CLEAR MARA.
ENDCASE.
ENDMODULE.
" STATUS_0100 OUTPUT
Output:Enter Material number On Material Field. Click on Display.
Demo on Tabstrips
By Vikram Chellappa, Mouri Tech Solutions
In this document, we would work on creating a simple screen with a tabstrip on it.
Go to SE38 T-code.
Create a Z program.
or Press Ctrl+F7.
Create A Tab Strip and Sub screens and place Sub screen in the appropriate tab strip.
, CHECK, ACTIVATE
....Previous
Click on SAVE
, CHECK, ACTIVATE
Click on SAVE
, CHECK, ACTIVATE
, CHECK, ACTIVATE
*&---------------------------------------------------------------------*
*& Report Z_DB_TABLECONTROL
*
*&
*
*&---------------------------------------------------------------------*
*&
*
*&
*
*&---------------------------------------------------------------------*
REPORT Z_DB_TABLECONTROL.
TABLES: MARA.
CONTROLS MATERIAL TYPE TABLEVIEW USING SCREEN 130.
TYPES: BEGIN OF ST_MARA,
MATNR TYPE MARA-MATNR,
ERSDA TYPE MARA-ERSDA,
ERNAM TYPE MARA-ERNAM,
LAEDA TYPE MARA-LAEDA,
END OF ST_MARA.
DATA: IT_ST TYPE TABLE OF ST_MARA,
WA_ST TYPE ST_MARA,
IT_MARA TYPE MARA,
WA_MARA TYPE MARA,
OK_CODE LIKE SY-UCOMM.
CALL SCREEN 130.
*&---------------------------------------------------------------------*
*&
Module V1 INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE V1 INPUT.
CASE OK_CODE.
WHEN 'SAVE'.
WA_ST-MATNR = MARA-MATNR.
WA_ST-ERSDA = MARA-ERSDA.
WA_ST-ERNAM = MARA-ERNAM.
WA_ST-LAEDA = MARA-LAEDA.
MOVE-CORRESPONDING WA_ST TO WA_MARA.
INSERT INTO MARA VALUES WA_MARA.
WHEN 'DELETE'.
WA_ST-MATNR = MARA-MATNR.
WA_ST-ERSDA = MARA-ERSDA.
WA_ST-ERNAM = MARA-ERNAM.
WA_ST-LAEDA = MARA-LAEDA.
MOVE-CORRESPONDING WA_ST TO WA_MARA.
DELETE MARA FROM WA_MARA.
WHEN 'MODIFY'.
WA_ST-MATNR = MARA-MATNR.
WA_ST-ERSDA = MARA-ERSDA.
WA_ST-ERNAM = MARA-ERNAM.
WA_ST-LAEDA = MARA-LAEDA.
MOVE-CORRESPONDING WA_ST TO WA_MARA.
MODIFY MARA FROM WA_MARA.
ENDCASE.
ENDMODULE.
" V1 INPUT
*&---------------------------------------------------------------------*
*&
Module EXIT INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE EXIT INPUT.
IF OK_CODE = 'EXIT'.
LEAVE PROGRAM.
ENDIF.
ENDMODULE.
" EXIT INPUT
Create a screen by number 130 and provide the following attributes:
LAYOUT:
ELEMENT LIST:
FLOW LOGIC.
EXECUTE:
BEFORE
OUTPUT.
STATUS_0100.
AFTER
CANCEL
AT
The GUI status SCREEN100 has the functions BACK, EXIT, and CANCEL (all with type E).
Code
REPORT ZSURESH_TEST .
* Type declarations.....................
TYPES pict_line(256) TYPE c.
* data declarations......................
DATA :init,
INPUT.
EXIT-COMMAND.
ENDIF.
IMPORT pict_tab = pict_tab FROM DATABASE abtree(pi) ID 'ENJOY'.
CALL FUNCTION 'DP_CREATE_URL'
EXPORTING
type
= 'IMAGE'
subtype = 'GIF'
TABLES
data
= pict_tab
CHANGING
url
= url.
BDC Programming
How to do BDC without writing BDC program
By Vikram Chellappa, Mouri Tech Solutions
In this example, I have used the transaction VV31 (Create Output Condition Records - Billing) to do the
BDC.
1.
2.
The following popup screen gets populated, there you enter the Recording name and transaction for
which you wish to do the BDC (In this example it is VV31). Click Start recording button.
3.
In the Transaction, enter the mandatory field. In this case it is Output type (AUS1). Hit enter key.
4.
5.
6.
The following screen appears for more entry. Enter all the mandatory fields and click on save.
SAP
will
give
the
Recorded
program
as
shown
in
the
following
and save the file as word document file into the system.
screen
shot.
7.
8.
Now
open
the
newly
created
word
document
file.
Select/Highlight the first field in the word document for which for which BDC needs to done. (In this
case it is output type i.e. AUS1) and go to the menu path Insert Field
9.
A new screen will get populated and there you select the Merge Field option from the list box and
enter the Column Name (In this case the 1st column is output_type).
10. Now you can see in the word document that the highlighted field will get replaced with the column
name.
11.
Similarly you highlight the other fields for which we need to create the BDC and give the unique
column names for those fields.
12. Now you can see that all the required fields have been mapped with unique column names.
13. Now go the menu path Tools Letters and Mailings Mail Merge Wizard.
14. A mail merge wizard will gets opened in the right hand side.
15. Now open the excel file where which you have the data to do the BDC for transaction VV31. Check
that the column name in the word document is matching with the column name in the Excel file.
Switch to world document and Now Click Next: Start document link in the bottom of Mail Merge
wizard
20. It will open the popup for selecting the file (which is having data for BDC).
23. Select the work sheet of the Excel file where the actual data present. In this case it is Sheet1$ and
Click OK button.
24.
A new popup screen would appear with the data. Click OK button.
25.
26.
27.
Now you can see the first record got merged with the word document.
28.
29.
30.
A new popup will get triggered, there you select All radio button and click OK button.
31.
Now you can see the merge has been done in the word document and it will create the BDC
program for all the records in the Excel sheet. (In this case we had 10 records in excel sheet, hence
the merge has created 10 pages in the word document. One page for each record)
32.
Now Select the entire content in the word document (i.e. all the 10 pages) and copy it in a notepad
and save as separate TXT file.
33. Go to the SHDB transaction and select your recording and click Change button.
35. Once you click the Import button, a popup will come from there you select the file and click Transfer
button.
36. It will transfer the entire content to the SHDB. Now Save the changes. Click Back button.
37. Now click the Session button, in order to create a new session.
38.
The following popup will get triggered, there you enter the new session name and check the Keep
session check box and click Continue button.
39.
You will get the Success Message that Batch input session ZTST_GOK was created.
40.
Now go to the Transaction SM35 (Batch Input: Session Overview), there you select your Session
which you have created in Step # 38 (You can the status of your session will be New) and click
Process button.
41.
A small popup will get triggered, there you select the Background radio button and check the
Extended Log check box. Click Process button.
42.
You will get the success message 1 session(s) transferred to background processing.
43.
And you can also see the status of your session has been changed from New to In background.
44.
45.
You will taken to the another screen, there you can see status of the BDC.
46.
In our case, the status is Errors, to know the details further. Select the entry and click Analyze
session. It will display the status of all the records.
47.
In the above screen shot you can see the first two records were failed and others were processed.
The reason for the same is: For the first time when we used SHDB we created the first condition
record. Since this record is already there it failed in the second time. The same thing applies to the
second failure case.
Report ypriyatest.
TABLES:
bdcdata.
DATA:t_bdcdata LIKE
STANDARD TABLE
OF bdcdata.
PARAMETERS :
p_table(15) TYPE c.
DATA:
MSG LIKE BDCMSGCOLL,
T_MSG LIKE TABLE OF MSG,
MESSAGE(72) TYPE C.
PERFORM PROCESS.
*&--------------------------------------------------------------------*
*&
Form fill_screendata
*&--------------------------------------------------------------------form fill_screendata
using
value(p_0015)
value(p_0016).
BDCDATA-PROGRAM = P_0015.
BDCDATA-DYNPRO = P_0016.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA TO T_BDCDATA.
CLEAR BDCDATA.
endform.
" fill_screendata
*&--------------------------------------------------------------------*
*&
Form FILL_FIELD_DATA
*&--------------------------------------------------------------------form FILL_FIELD_DATA
using
value(p_0020)
value(p_0021).
BDCDATA-FNAM = P_0020.
BDCDATA-FVAL = P_0021.
APPEND BDCDATA TO T_BDCDATA.
CLEAR BDCDATA.
endform.
" FILL_FIELD_DATA
*&--------------------------------------------------------------------*
*&
Form PROCESS
*&--------------------------------------------------------------------form PROCESS .
**first screen
PERFORM fill_screendata
USING 'SAPMSRD0' '0102'.
PERFORM FILL_FIELD_DATA
USING 'RSRD1-TBMA' 'X'.
PERFORM FILL_FIELD_DATA
USING 'RSRD1-TBMA_VAL' p_table.
PERFORM FILL_FIELD_DATA
USING 'BDC_OKCODE' '=ADD'.
**second screen
PERFORM fill_screendata
USING 'SAPLSD41' '2200'.
PERFORM FILL_FIELD_DATA
USING 'DD02D-DDTEXT' 'Bdc Table'.
PERFORM FILL_FIELD_DATA
USING 'DD02D-CONTFLAG' 'A'.
PERFORM FILL_FIELD_DATA
USING 'DD02D-MAINFLAG' 'X'.
PERFORM FILL_FIELD_DATA
USING 'BDC_OKCODE' '=CHANGE_MAINTFLAG'.
PERFORM FILL_FIELD_DATA
Output
First Screen
Technical
Settings
By Venkatraman N, IBM
This method would be useful, when you dont have required datum in development client and when you
have same in testing client and you want to BDC recording with that datum.
Login to the Testing client where you will have data.
Go to transaction SHDB and press new recording.
As an instance, here we will try to modify vendors postal code of his address. So, give FK02 as the
transaction code to be executed and give recording name like ZRECORD.
Now it goes to Vendor master update screen. Opt a vendor and click the address checkbox and press
enter.
Now change the existing PIN code 700019 to 560076 and press save. It will take you to the recording
screen.
Now you cannot create a program with this recording information in testing client. So, import your
recording
information
to
one
presentation
server
file.
Press
import
button.
Then Go to SHDB transaction in development client and go to new recording. Give the recording name as
ZRECORDINGNEW and opt the same vendor master updation transaction code FK02.
In this case your development client should have at least one vendor. If not create it and input the vendor
in FK02 transaction and as you did earlier select the address checkbox.
It will show you the address information. You dont change anything in that and come back. Because this
is not the vendor to whom we are going to change his PIN Code.
Now it will show you the recording information. Delete all the recording information and press the import
button and browse bdc_recording file from the presentation server.
The previous recording information will loaded in to BDC recording and go back from the screen. It would
popup for saving the recording. Now save that recording.
Select the recording and press program button. It will popup for new program creation. Input the required
details and the expected BDC recording program will get created.
report ZVENDORUPDATE
no standard page heading line-size 255.
include bdcrecx1.
start-of-selection.
perform open_group.
perform bdc_dynpro
using 'SAPMF02K' '0106'.
perform bdc_field
using 'BDC_CURSOR'
'RF02K-LIFNR'.
perform bdc_field
using 'BDC_OKCODE'
'/00'.
perform bdc_field
using 'RF02K-LIFNR'
'B002568'.
perform bdc_field
using 'RF02K-D0110'
'X'.
perform bdc_dynpro
using 'SAPMF02K' '0110'.
perform bdc_field
using 'BDC_CURSOR'
'LFA1-PSTLZ'.
perform bdc_field
using 'BDC_OKCODE'
'=UPDA'.
perform bdc_field
using 'LFA1-NAME1'
'MURARI SHARAN SRIVASTAVA'.
perform bdc_field
using 'LFA1-SORTL'
'000568'.
perform bdc_field
using 'LFA1-STRAS'
'Brook House, Shakespeare Sarani'.
perform bdc_field
using 'LFA1-ORT01'
'Kolkatta'.
perform bdc_field
using 'LFA1-PSTLZ'
'560076'.
perform bdc_field
using 'LFA1-LAND1'
'IN'.
perform bdc_field
using 'LFA1-REGIO'
'25'.
perform bdc_field
using 'LFA1-SPRAS'
'EN'.
perform bdc_transaction using 'FK02'.
perform close_group.