2007 Sep 05 11:10 AM
what are the main events that are used in an ALV report?
Reagards,
swathi.
2007 Sep 05 11:12 AM
Hi..swathi..
USER_COMMAND
TOP_OF_PAGE
END_OF_PAGE
TOP_OF_LIST
END_OF_LIST
reward if Helpful
2007 Sep 05 11:14 AM
Check link
http://www.sapbrainsonline.com/TUTORIALS/TECHNICAL/ALV_tutorial.html
Adding function to existing toolbar in ALV Grid
This section helps in adding functionality to already existing functions in the ALV output Grid.
1. Using Function Module REUSE_ALV_GRID_DISPLAY.
2. Using Object Oriented ABAP.
Both these methods are explained briefly.
Using Function Module REUSE_ALV_GRID_DISPLAY
1. First step is to copy the STANDARD GUI status of the standard program SAPLKKBL using SE90 transaction.
Fig 1.1 SE90 Transaction
2. Execute the transaction and the next screen will show the STANDARD GUI status with a checkbox corresponding to it. Select the checkbox and click on GUI STATUS  Copy.
Fig 1.2 Copying of Standard GUI
3. The third step is to enter the Z Program and the name of the GUI status which will be the copy of the STANDARD one and click on COPY button. Now a GUI status will be created for the Program you have entered.
Fig 1.3 Creation of GUI for Custom Program
4. We can edit the status to add new icons like refresh and other functionality which we need. This will also bring in the standard SAP ALV functionality such as sorting/subtotaling etc.... In this Program we have added a REFRESH Icon to the ALV List.
Fig 1.4 Including Function in Copied GUI
5. The output ALV List is shown below with the REFRESH Icon that was added to it.
Fig 1.5 ALV Grid Output Display with Included Icon
6. In order to add the functionality of the Icon added, we pass the status YICON when we call the 'REUSE_ALV_GRID_DISPLAY' along with the callback_user_command USER_COMMAND_REF.
DATA: ws_title TYPE lvc_title, Grid Title
wa_layout TYPE slis_layout_alv. Grid Layout
DATA: i_fieldcat TYPE slis_t_fieldcat_alv. Grid Fieldcat
*---I_FINAL is an internal table which contains the values to be
*---displayed in the ALV Grid
*----
Display ALV GRID
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'SET_PF_STATUS'
i_callback_user_command = 'USER_COMMAND_REF'
i_grid_title = ws_title
is_layout = wa_layout
it_fieldcat = i_fieldcat
TABLES
t_outtab = i_final[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*----
Form set_pf_status.
FORM set_pf_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'YICON'.
ENDFORM. " set_pf_status
*----
Form user_command_ref.
FORM user_command_ref USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
DATA: lws_okcode TYPE sy-ucomm.
IF r_ucomm EQ REFH.
MESSAGE i001(zfin) with You clicked Refresh button.
ENDIF.
CLEAR lws_okcode.
lws_okcode = sy-ucomm.
*----
BACK
CASE lws_okcode.
WHEN '&F03'.
SET SCREEN 0.
LEAVE SCREEN.
ENDCASE.
ENDFORM. " user_command_ref
Using Object Oriented ABAP
In the OOPS concept, the adding of the icon and functionality to the Toolbar of the ALV Grid is different from the Function Module method.
In order to add our functionality to the existing ALV Toolbar, we utilize two ALV Grid events. We use the event toolbar to add the button and the event user_command to implement the function.
In the method handling the toolbar event the button to be included in the ALV Grid is defined by filling a structure and appending to the table attribute mt_toolbar. In the ALV Grid, to display the Icon added we must call the method set_toolbar_interactive.
----
Class Definition *
----
CLASS lcl_alv_grid_display DEFINITION.
PUBLIC SECTION.
METHODS:
*----
To set the User command
handle_ucomm FOR EVENT user_command
OF cl_gui_alv_grid
IMPORTING e_ucomm,
*----
To add refresh Icon
handle_toolbar FOR EVENT toolbar
OF cl_gui_alv_grid
IMPORTING e_object e_interactive.
ENDCLASS. "lcl_alv_grid_display DEFINITION
----
Class Implementation *
----
CLASS lcl_alv_grid_display IMPLEMENTATION.
METHOD handle_ucomm.
IF e_ucomm = 'REFH'.
MESSAGE i001(zfin) with You clicked Refresh button.
ENDIF.
ENDMETHOD. "handle_ucomm
*----
To include refresh button
METHOD handle_toolbar.
PERFORM handle_toolbar USING e_object e_interactive.
ENDMETHOD. "handle_toolbar
ENDCLASS. "lcl_alv_grid_display IMPLEMENTATION
&----
*& Form handle_toolbar
&----
text
----
-->P_E_OBJECT text
----
FORM handle_toolbar USING p_e_object TYPE REF TO
cl_alv_event_toolbar_set
p_e_interactive TYPE c.
DATA: lwa_button TYPE stb_button.
*----
Add refresh button
CLEAR lwa_button.
lwa_button-butn_type = '0'.
lwa_button-function = 'REFH'.
lwa_button-icon = icon_refresh.
lwa_button-quickinfo = Refresh.
lwa_button-disabled = space.
APPEND lwa_button TO p_e_object->mt_toolbar.
ENDFORM. " handle_toolbar
In order to register the event handler methods to the standard ALV Grid, Command SET HANDLER:
*----
Set Event Handlers
SET HANDLER wcl_event_receiver->handle_ucomm
wcl_event_receiver->handle_toolbar
FOR wcl_alv_grid_disp.
The output ALV Grid is shown below with the REFRESH Icon that was added to it.
Fig 1.6 ALV Grid Output Display with Included Icon
Customer Enhancement of BAPIs
What is BAPI?
SAP defines BAPI as Business Application Programming Interfaces (BAPIs) enable access to SAP functions across formal, stable and dialog-free interfaces. These interfaces can be used by external applications developed by customers and complementary software partners as well as by other SAP applications. BAPIs can be called like other function modules and BAPIs have a return table which will be filled up when any kind of message have been triggered inside the BAPI interface. This will avert the abrupt termination of SAP transaction.
Two methods
There are two methods available for enhancing the existing BAPIs.
1. Extension parameters at the BAPI interface
2. Business Add-Ins (BAdIs)
Here only the first method is explained.
Why we need to enhance BAPI?
When a standard table has been enhanced to contain new Z fields, the existing BAPI will not populate data into these Z fields when the standard table is updated. For example, a standard table FKKVKP (contract account table) is enhanced by adding few Z fields to meet customer requirement. Whenever a Contract account is created using t-code CAA1, these Z fields will be populated in the table FKKVKP from the screen input.
But the existing BAPI, BAPI_ISUACCOUNT_CREATEFROMDATA will not update these Z fields since the tables parameter TCONTRACTACCOUNTDATA of Structure BAPIISUVKP will not have the Z fields. Hence we need to use the Extension parameters EXTENSIONIN of Structure BAPIPAREX for passing values to the Z fields.
How to use these Extension parameters?
The extension parameters serve as a container in which all the customer enhancements are passed to the BAPI. The extension parameters are always based on the BAPIPAREX structure.
The data is transferred in one table. The format of the data records in this table is determined by the BAPIPAREX structure. This structure contains multiple data record fields
(VALUEPART1, VALUEPART2, ...) and one field for the name of the help structure (STRUCTURE). Since the data for each data record is written to the corresponding data record fields in parts one after the other, a help structure is required for interpreting the data.
Fig 2.1 Structure of BAPIPAREX
Find out whether we have extension parameters for the BAPI using the t-code BAPI. For our example, there is an extension table parameter available for FKKVKP as BAPI_TE_FKKVKP.
How to append our Z fields to extension table?
Execute the t-code SE11 (ABAP dictionary) and into the structure BAPI_TE_FKKVKP. And add the Z fields into a Z append structure by clicking on the Append Structures button.
Fig 2.2 Structure of Include BAPI_TE_FKKVKP for FKKVKP
Fig 2.3 Naming Custom Append Structure
Add all the Z fields of the table FKKVKP.
Fig 2.4 Adding Custom Fields into Append Structure
Activate the append structure and return back to BAPI_TE_FKKVKP. It should look alike the screen below.
Fig 2.5 Final structure of BAPI_TE_FKKVKP
How to pass values for the append structure into the BAPI?
Now we have successfully enhanced the BAPI to include the new Z fields of the table FKKVKP. We have to pass data to this BAPI from our application program such that the FKKVKP holds data for the Z fields.
*-----Data declarations
DATA: w_partner TYPE bapibppara-partner,
w_vkont TYPE bapicapara-account,
w_cacateg TYPE bapicapara-contr_acc_catg,
wa_bapi_return TYPE bapiret2,
wa_catab TYPE bapiisuvkp,
i_catab TYPE STANDARD TABLE OF bapiisuvkp,
wa_bapi_te_fkkvkp TYPE bapi_te_fkkvkp,
wa_extensionin TYPE bapiparex,
i_extensionin TYPE STANDARD TABLE OF bapiparex.
*-----Before this step, we will fill up data for all the fields of FKKVKP
APPEND wa_catab TO i_catab.
*-----Fill data to the extension structure BAPI_TE_FKKVKP
MOVE w_partner TO wa_bapi_te_fkkvkp-gpart.
MOVE 1 TO wa_bapi_te_fkkvkp-zzfiach.
MOVE X TO wa_bapi_te_fkkvkp-zzoutsflg.
*-----Move the extension structure to BAPI extension parameters
MOVE wa_bapi_te_fkkvkp TO wa_extensionin-valuepart1.
MOVE BAPI_TE_FKKVKP TO wa_extensionin-structure.
APPEND wa_extensionin TO i_extensionin.
*----Call BAPI
CALL FUNCTION 'BAPI_ISUACCOUNT_CREATEFROMDATA'
EXPORTING
partner = w_partner
contractaccountcategory = w_cacateg
IMPORTING
return = wa_bapi_return
contract_account = w_new_vkont
TABLES
tcontractaccountdata = i_catab
extensionin = i_extensionin.
*----Call BAPI Commit work
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = space
IMPORTING
return = wa_bapi_return.
In the above code, we move data for the Z fields to the extension structure BAPI_TE_FKKVKP. As we already learnt that the format of the data records in this table is determined by the BAPIPAREX structure.
The name of the structure BAPI_TE_FKKVKP is passed to the BAPIPAREX-STRUCTURE. And the data is moved directly to the VALUEPART1 field. We append this data to the internal table I_EXTENSIONIN and pass it to the BAPI interface.
Note
To find out the extension structure available for the required BAPI interface, you can use t-code BAPI as well as the documentation of the BAPI interface.
As we have EXTENSTIONIN parameter, some of the BAPIs allow us to have the EXTENSIONOUT parameters, the data returned after BAPI interface execution.
More info
http://help.sap.com/saphelp_47x200/helpdata/en/3e/0e1089c24611d1ad09080009b0fb56/frameset.htm
SAP Script
This section helps to print a number of documents using a single script. For example here we discuss a scenario to print 3 documents. The first document was a Covering Letter where the content of the document was within a single page. The second document was a Quotation Letter where the contents would be varying to several pages based on the customer requirement. The third document would be Customer Acceptance Letter where the contents would be displayed within a single page.
We have to create 4 pages defining PAGE1 as Covering Letter, PAGE3 as Acceptance Letter, PAGE2 as Quotation Letter and PAGE4 was an Interim PAGE being used along with Quotation Letter. Whenever the contents of the Quotation Letter (PAGE2) exceed the page limit it should automatically shift to PAGE4 to print the overflowing details. For this we need to declare the next page for PAGE2 as PAGE4.
Fig 3.1 Page Declaration
We have to create MAIN Windows in each of the 3 pages (PAGE2, PAGE3 and PAGE4). We cannot create separate MAIN Windows whereas we have created 3 instances of the MAIN Window (MAIN 00, MAIN 01 and MAIN 02).
PAGE2: MAIN 00
Fig 3.2 MAIN Window for PAGE2
PAGE4: MAIN 01
Fig 3.3 Instance of MAIN Window for PAGE4
PAGE3: MAIN 02
Fig 3.4 Instance of MAIN Window for PAGE3
We have to create several Text Elements to display the data. SAP defines Text elements are related to a window, that is, a print program can call for each window only those text elements that exist in this window. When the data to be displayed in the MAIN 00 Window of PAGE2 exceeds the page limit, it automatically shifts to MAIN 01 Window of PAGE4. Suppose the data exceeds the MAIN 01 of PAGE4, it automatically creates new pages and writes the remaining content. Based on the content of the Quotation Letter details the number of pages would be dynamically varying and the entire content would be printed across several pages that were created.
Fig 3.5 Text elements in MAIN window
*----
Writing the Text element M00 of PAGE2
ws_element_name = 'M00'. Text element
ws_window_name = 'MAIN'. Window name
PERFORM write_form USING ws_element_name ws_window_name.
*----
Writing the Text element M06 of PAGE2
ws_element_name = 'M06'. Text element
ws_window_name = 'MAIN'. Window name
PERFORM write_form USING ws_element_name ws_window_name.
*----
Subroutine calling Function Module WRITE_FORM
FORM write_form USING p_element_name p_window_name.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
element = p_element_name
window = p_window_name
EXCEPTIONS
element = 1
function = 2
type = 3
unopened = 4
unstarted = 5
window = 6
bad_pageformat_for_print = 7
spool_error = 8
codepage = 9
OTHERS = 10.
IF sy-subrc <> 0.
MESSAGE e004(zswqc).
ENDIF.
ENDFORM. " write_form
Triggering PAGE3 (Acceptance Letter) from PAGE2
Using NEW-PAGE command, we can force a page break at any point. The text after this command is written on a new page. The form feed is independent of any conditions. The command now outputs the current page.
When the content of the PAGE2 (Quotation Letter) details are printed, we call the PAGE3 (Acceptance Letter) using the NEW-PAGE PAGE3.
Fig 3.6 Using NEW-PAGE command
The content of the text elements are displayed in PAGE3 (Acceptance Letter).
Note
As soon as a MAIN window is full, SAP Script automatically triggers a page break and continues to output the remaining text in the main window of the subsequent page. Page windows of type MAIN have the same width throughout the form.
Address number Creation
This section helps to create an address number in SAP. We need to provide the details of the address (name, street, house number, City, postal code) and can also provide the communication data (telephone number and fax number). Before proceeding, we need to know what all the tables that get involved here. There are three address types, namely, Company addresses, Personal addresses and Workplace addresses. Here we are considering about how to create the Company addresses.
ADRC Address table (Stores organization name and postal address)
ADRP Personal data (used for address type 2 personal addresses)
ADCP Assignment of persons to addresses (workplace data)
Prerequisites
1) You need to identify an address group. The address group is an attribute of an address or a person that must be specified by the application as a filter for almost all operations. Address group are stored in table TSAD7.
2) Registering the application in the table TSADRV. This table stores the where-used list of the addresses and data dictionary information.
Fig 4.1 Entry in TSADRV table
3) Address handle. As long as an application does not save an address to the database, the application refers to an address handle. This handle identifies an address in the local memory that is currently being entered.
Creating the address
There are two function modules available to maintain addresses. ADDR_INSERT can be used to insert an address which contains organization name, street, post code, city and region. If
we need to maintain telephone number or fax number for the same address number, the function module ADDR_COMM_MAINTAIN has to be used. Other wise, we can directly use the function module ADDR_MAINTAIN_COMPLETE to create an address with all address details along with telephone and fax numbers. Here, we discuss how to create an address using ADDR_MAINTAIN_COMPLETE.
Filling up all the address and communication details
This function module uses a deep structure SZADR_ADDR1_COMPLETE of type pools SZADR. The organization address should be passed in the table ADDR1_TAB, the telephone number in the table ADTEL_TAB and fax number in the table ADFAX_TAB.
TYPE-POOLS szadr.
DATA: ws_updflag TYPE szad_field-updateflag,
wa_addr_complete TYPE szadr_addr1_complete,
wa_addr_complete_out TYPE szadr_addr1_complete,
ws_addrgroup TYPE adrg-addr_group,
ws_retcode TYPE szad_field-returncode.
DATA: i_errortab TYPE STANDARD TABLE OF addr_error.
DATA: i_addr1_tab TYPE szadr_addr1_line OCCURS 0,
wa_addr1_tab TYPE szadr_addr1_line,
i_adtel_tab TYPE szadr_adtel_line OCCURS 0,
wa_adtel_tab TYPE szadr_adtel_line,
i_adfax_tab TYPE szadr_adfax_line OCCURS 0,
wa_adfax_tab TYPE szadr_adfax_line.
*We are creating an address; the UPDATEFLAG should be I (Insert mode).
ws_updflag = 'I'.
*Address group considered as CA01 (Customizing address)
ws_addrgroup = 'CA01'.
*Address handle. The control is fully with ABAP Developer
wa_addr_complete-addrhandle = 'ADR'.
*Filling up the Organization address details
CLEAR wa_addr1_tab.
wa_addr1_tab-data-date_from = sy-datum.
wa_addr1_tab-data-name1 = 'James Enterprises'.
wa_addr1_tab-data-city1 = 'London'.
wa_addr1_tab-data-street = 'Manchester St'.
wa_addr1_tab-data-house_num1 = '112'.
wa_addr1_tab-data-post_code1 = 'WC2N 6QA'.
wa_addr1_tab-data-region = 'BAN'.
wa_addr1_tab-data-country = 'GB'.
APPEND wa_addr1_tab TO i_addr1_tab.
*Filling up the Telephone number details
CLEAR wa_adtel_tab.
wa_adtel_tab-date_from = sy-datum.
wa_adtel_tab-adtel-consnumber = '1'.
wa_adtel_tab-adtel-country = 'GB'.
wa_adtel_tab-adtel-flgdefault = 'X'.
wa_adtel_tab-adtel-tel_number = '+442072571368'.
APPEND wa_adtel_tab TO i_adtel_tab.
*Filling up the Fax number details
CLEAR wa_adfax_tab.
wa_adfax_tab-date_from = sy-datum.
wa_adfax_tab-adfax-consnumber = '1'.
wa_adfax_tab-adfax-country = 'GB'.
wa_adfax_tab-adfax-flgdefault = 'X'.
wa_adfax_tab-adfax-fax_number = '2072571368'.
APPEND wa_adfax_tab TO i_adfax_tab.
*Move the internal tables to final complex structure
MOVE i_addr1_tab[] TO wa_addr_complete-addr1_tab.
MOVE i_adtel_tab[] TO wa_addr_complete-adtel_tab.
MOVE i_adfax_tab[] TO wa_addr_complete-adfax_tab.
*Call the function module. It creates the Address and returns the final address *in ADDR1_COMPLETE_OUT with the address handle. The address is still not yet *stored in database but in local memory referred with address handle.
CALL FUNCTION 'ADDR_MAINTAIN_COMPLETE'
EXPORTING
updateflag = ws_updflag
addr1_complete = wa_addr_complete
address_group = ws_addrgroup
substitute_all_comm_data = 'X'
check_address = 'X'
consider_consnumber_for_insert = ' '
IMPORTING
returncode = ws_retcode
addr1_complete_out = wa_addr_complete_out
TABLES
error_table = i_errortab
EXCEPTIONS
parameter_error = 1
address_not_exist = 2
handle_exist = 3
internal_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Get the address number using the address handle
The ADDR_MAINTAIN_COMPLETE returns the final address structure along with the address handle. The address number is still not yet generated. We have to use the function module ADDR_NUMBER_GET to generate the address number.
Address reference specifies where the address number will be used. This function module checks whether the same entry is maintained in the TSADRV and the address group is maintained in TSAD7.
DATA: wa_addr_ref TYPE addr_ref.
*Fill the address reference; the where-used list of address number
CLEAR wa_addr_ref.
wa_addr_ref-appl_table = 'ZFDDHIST'.
wa_addr_ref-appl_field = 'ZADDRN'.
wa_addr_ref-appl_key+0(3) = sy-mandt.
wa_addr_ref-addr_group = 'CA01'.
wa_addr_ref-owner = space.
*Generate the address number
CALL FUNCTION 'ADDR_NUMBER_GET'
EXPORTING
address_handle = wa_addr_complete_out-addrhandle
address_reference = wa_addr_ref
owner = space
IMPORTING
address_number = wa_addr_complete_out-addrnumber
EXCEPTIONS
address_handle_not_exist = 1
internal_error = 2
parameter_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.
ENDIF.
Store the Address in the database
Still now, we have successfully created an address handle with the organization address and communication numbers. Then, we assigned the address handle to a newly created address number. Still the whole data is in local memory and not stored in the database. The function module ADDR_MEMORY_SAVE stores the entire local memory on the database.
CALL FUNCTION 'ADDR_MEMORY_SAVE'
EXPORTING
execute_in_update_task = space
EXCEPTIONS
address_number_missing = 1
person_number_missing = 2
internal_error = 3
database_error = 4
reference_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.
ENDIF.
Note
The generated address number can be read from WA_ADDR_COMPLETE_OUT-ADDRNUMBER. Note that we need to use all the three function modules in order to successfully create an address number with the address details. After creating an address number, you can check for that address number in ADRC, ADR2 and ADR3 tables.
More info
You can find more information on this section at http://help.sap.com/saphelp_46c/helpdata/en/c8/13b237b9a9a968e10000009b38f8cf/frameset.htm
Word wrap of Long Text from SAP
This section explains briefly how to copy longtext from SAP and display in Script. Longtext introduced by SAP can hold more than one line of text. Longtext will be displayed using the SAP Textedit control. The longtext can be accessed using Function Module READ_TEXT and saved using Function Module SAVE_TEXT.
When Longtext is read from Function Module READ_TEXT the text that is returned will be in the same order as we have saved.
Fig 5.1 Long text in t-code VA22
When we display the longtext in Script, it will display as we have saved using Function Module SAVE_TEXT.
Output before the word wrap of LONGTEXT
Fig 5.2 Long text output in SAP Script before Word Wrap
The above longtext displayed in the SAP Script is not up to the entire width of the window. In order to adjust the retrieved longtext to the width of the window, the following code would help.
Code for word wrap
DATA: ws_id1 TYPE THEAD-TDID, Text id in Long text
ws_lang LIKE thead-tdspras, Language - English
ws_obj LIKE thead-tdobject, Text Name
ws_name1 LIKE thead-tdname. Sales document item
*--I_POSNR is an internal table which holds Sales document item numbers
DATA: BEGIN OF i_posnr OCCURS 0,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
END OF i_posnr.
*--I_LINES Internal Table to hold long text before Word Wrap
DATA: BEGIN OF i_lines OCCURS 0.
INCLUDE STRUCTURE tline.
DATA: END OF i_lines .
*--I_LINES1 - Internal Table to hold long text after Word Wrap
DATA: BEGIN OF i_lines1 OCCURS 0.
INCLUDE STRUCTURE tline.
DATA: count(3) TYPE c,
END OF i_lines1 .
*--I_WRAP Internal Table to hold Wrapped long text
DATA: BEGIN OF i_wrap OCCURS 0,
text(2500),
END OF i_wrap.
*-----Select from VBAP for item number
SELECT vbeln
posnr
FROM vbap
INTO TABLE i_posnr
WHERE vbeln = ws_vbeln.
*-----Count the Number of Sales Document Items
DESCRIBE TABLE i_posnr LINES ws_line.
ws_id1 = 'ZSW5'.
ws_lang = 'EN'.
ws_obj = 'VBBP'.
LOOP AT i_posnr.
CONCATENATE ws_vbeln i_posnr-posnr INTO ws_name1.
*-----Retrieve the LONGTEXT for the selected object
CALL FUNCTION 'READ_TEXT'
EXPORTING
client = sy-mandt
id = ws_id1
language = ws_lang
name = ws_name1
object = ws_obj
TABLES
lines = i_lines
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7.
IF sy-subrc = 0.
*------Count the number of Long text lines
DESCRIBE TABLE i_lines LINES ws_lines1.
CONDENSE ws_lines1.
IF ws_lines1 GT '1'.
PERFORM word_wrap.
ENDIF.
*-------If there are multiple Sales Document Items the Long Text of each
*-------Sales document Item is associated with Sequential Nos. 1, 2, ....
IF ws_line GT '1'.
n = n + 1.
READ TABLE i_lines INTO wa_lines1 INDEX 1.
i_lines1-tdline = wa_lines1-tdline.
CONCATENATE n '.' INTO ws_count2.
i_lines1-count = ws_count2.
APPEND i_lines1.
APPEND LINES OF i_lines FROM 2 TO i_lines1.
APPEND INITIAL LINE TO i_lines1.
ELSE.
APPEND LINES OF i_lines TO i_lines1.
ENDIF.
CLEAR: wa_lines1,
ws_lines1,
i_lines,
ws_count.
REFRESH i_lines.
ENDIF.
ENDLOOP.
*-----Subroutine for LONGTEXT Word wrap
FORM word_wrap_sp .
LOOP AT i_lines.
IF i_lines-tdformat = '*' AND i_lines-tdline = ''.
APPEND INITIAL LINE TO i_wrap.
CONTINUE.
ENDIF.
ws_count = sy-tabix + 1.
READ TABLE i_lines INDEX ws_count INTO wa_lines.
IF wa_lines-tdformat = '*' OR sy-subrc NE 0.
CONCATENATE ws_tdtext i_lines-tdline INTO ws_tdtext SEPARATED BY
space.
i_wrap-text = ws_tdtext+1(2499).
APPEND i_wrap.
CLEAR ws_tdtext.
ELSE.
CONCATENATE ws_tdtext i_lines-tdline INTO ws_tdtext SEPARATED BY
space.
IF wa_lines-tdformat = '*'.
APPEND i_wrap.
CLEAR ws_tdtext.
ENDIF.
ENDIF.
ENDLOOP.
CLEAR: i_lines.
REFRESH: i_lines.
LOOP AT i_wrap.
IF i_wrap-text IS INITIAL.
APPEND i_lines.
REFRESH lines.
ENDIF.
*-----The function module splits the long text based on the output length
CALL FUNCTION 'RKD_WORD_WRAP'
EXPORTING
textline = i_wrap-text
delimiter = ' '
outputlen = 95
TABLES
out_lines = lines.
LOOP AT lines.
i_lines-tdline = lines.
APPEND i_lines.
ENDLOOP.
CLEAR: lines.
REFRESH lines.
CLEAR: i_lines.
ENDLOOP.
CLEAR: i_wrap,i_lines, lines.
REFRESH: i_wrap, lines.
ENDFORM. " word_wrap
Output after the word wrap of LONGTEXT
Fig 5.3 Long text output in SAP Script after Word Wrap
Decimal Notation based on User profile settings
If the user has a different decimal notation and thousand separators, then we need to show the figures in the reports according to the SAP user profile settings. The user profile settings can be modified using transaction code SU01. Consider the user is of different country and has the decimal notation as comma (e.g. 150,00), then the user might want the amount or quantity field values to be displayed in the same format in all your reports.
User profile details are stored in the table USR01. The field denoting the decimal notation is DCPFM. The allowed values in this field are as below:
X Decimal point is period: N,NNN.NN
Decimal point is comma: N.NNN,NN
Y Decimal point is N NNN NNN,NN
This can be achieved in two ways. One is using WRITE TO statement. The other is using TRANSLATE and REPLACE statement.
Using WRITE TO
This statement is used to write the source field contents to the target field based on the source field data type and user decimal notations.
DATA: W_P_AMOUNT TYPE P DECIMALS 2 VALUE 10000.00,
W_C_AMOUNT(20) TYPE C.
*using Move statement
MOVE W_P_AMOUNT TO W_C_AMOUNT.
WRITE:/ using MOVE = , W_C_AMOUNT.
*using Write To statement
CLEAR W_C_AMOUNT.
WRITE W_P_AMOUNT TO W_C_AMOUNT.
WRITE:/ using WRITE TO= , W_C_AMOUNT.
Output
Fig 6.1 Output of MOVE and WRITE TO statements
MOVE statement will move the exact content of source field (W_P_AMOUNT) to the target field (W_C_AMOUNT). WRITE TO statement will copy the content of source field to the target based on the source field data type and user decimal notations.
Using TRANSLATE
Consider you are picking an amount field value from a SAP table, for example BSEG-DMBTR. The value would be assigned to the variable exactly as it is from the database and not based on the user profile settings. To change that amount value based on the user profile settings, we use the TRANSLATE statement with the option USING. This will check for the occurrences for the search character and replaces it with the next character.
TABLES USR01.
DATA WA_USR01 TYPE USR01.
DATA: W_P_AMOUNT TYPE BSEG-DMBTR,
W_C_AMOUNT(20) TYPE C.
SELECT SINGLE DMBTR
FROM BSEG
INTO W_P_AMOUNT
WHERE BELNR EQ '0100000000'.
IF SY-SUBRC NE 0.
ENDIF.
SELECT SINGLE *
FROM USR01
INTO WA_USR01
WHERE BNAME EQ SY-UNAME.
IF SY-SUBRC NE 0.
*-- user profile data not found
ENDIF.
MOVE W_P_AMOUNT TO W_C_AMOUNT.
WRITE:/ 'before TRANSLATE=', W_C_AMOUNT.
*check the decimal notation flag
IF WA_USR01-DCPFM EQ ' '.
TRANSLATE W_C_AMOUNT USING ', '.
CONDENSE W_C_AMOUNT NO-GAPS.
REPLACE '.' WITH ',' INTO W_C_AMOUNT.
ELSEIF WA_USR01-DCPFM EQ 'Y'.
TRANSLATE W_C_AMOUNT USING ', '.
ENDIF.
WRITE:/ 'after TRANSLATE=', W_C_AMOUNT.
Here the TRANSLATE statement searches for thousand separators i.e., comma character in this case and replaces it with the next character, i.e. blank. CONDENSE statement with NO-GAPS option will remove all the blank spaces in between and the REPLACE statement is to change the decimal notation from period to comma.
Output
Fig 6.2 Output before and after TRANSLATE statements
Note
This part of code will be helpful when we write the BDC programs. If you have any quantity field or amount field to be filled up in the transaction, then the BDC program will stop or will raise an error as Enter a numeric value since the amount value filled by the BDC program has different decimal notation when compared to the user profile.
Avoiding short dumps using CATCH ENDCATCH
Consider you have written code for a scenario where in you assign a numeric value to character value and have to assign the character value back to the numeric variable after some calculations. There might be chances of BCD overflow or some form of conversion error or any arithmetic errors which results in abnormal termination (short dump) of your program. There is a way to avoid such dumps and you can write code such that your program will halt in normal way or report any error in finding any occurrence of dump.
This can be done using CATCH SYSTEM-EXCEPTIONS ENDCATCH statement.
CATCH SYSTEM-EXCEPTIONS <exc1> = <n1> <excn> = <nm>.
.
ENDCATCH.
Catchable runtime errors are grouped into ERROR classes. For example, BCD_OVERFLOW, BCD_ZERODIVIDE are grouped under ARITHMETIC_ERRORS class. Your code (doing calculations) will be written inside the CATCH ENDCATCH block and when an exception exc1 rises, the exception is assigned with the corresponding n1 value and the n1 value will be assigned to SY-SUBRC. Then in your program, outside the ENDCATCH statement, you can check for the SY-SUBRC value and can raise an error message.
Sample Program
REPORT ysakex1.
DATA: num_val(2) TYPE p,
int_val TYPE i.
CONSTANTS: c_val TYPE i VALUE '900'.
START-OF-SELECTION.
CATCH SYSTEM-EXCEPTIONS compute_bcd_overflow = 3 "exception name
conversion_errors = 5. "error class
Raises COMPUTE_BCD_OVERFLOW exception
MOVE '100' TO num_val.
num_val = num_val + c_val.
WRITE:/ 'Numeric value = ', num_val.
Raises CONVT_NO_NUMBER exception
MOVE 'ab' TO int_val.
WRITE:/ 'Integer value = ', int_val.
ENDCATCH.
IF sy-subrc EQ 3.
WRITE:/ 'BCD Overflow Dump averted'.
ENDIF.
IF sy-subrc EQ 5.
WRITE:/ 'Conversion Error Dump averted'.
ENDIF.
In the above program, once the COMPUTE_BCD_OVERFLOW error arises, the control jumps to ENDCATCH and wont proceed to execute the rest of the statements inside the CATCH block. Hence you will always get the BCD_OVERFLOW error in the sample program. To check for the CONVT_NO_NUMBER error, just comment only the num_val = num_val + c_val statement.
The number 3 and 5 are assigned to an direct run-time error and to an error class respectively. While using an error class, you can handle all the runtime errors assigned to that error class and hence the same sy-subrc code would be returned if any error of that class raised inside CATCH block.
Output
Fig 7.1 Catching BCD_OVERFLOW dump
Comment the statement num_val = num_val + c_val. Then CONVT_NO_NUMBER runtime error arises.
Fig 7.2 Catching CONVT_NO_NUMBER dump
Reward if useful...
2007 Sep 05 11:17 AM
hi ,
check these important events ...
1.SLIS_PRINT_ALV.
2. SLIS_T_LISTHEADER.
3. SLIS_T_EVENT.
4. SLIS_T_SORTINFO_ALV.
5. SLIS_T_LAYOUT_ALV.
6. SLIS_T_FIELDCAT_ALV.
for more details ..check this link..
Refer
http://www.sap-basis-abap.com/abap/events-in-alv-and-their-fm.htm
Regards
2007 Sep 05 11:21 AM
Hi swathi,
Common Events:
1. Intialization:
This is the first event will be trigerred among all the events. In this event you will assigning values to variables.
For eg: if you want to display comments on the selection -screen.
v1 = 'HAI'. and write this variable in the at selection screen then HAI will be displayed in the selection screen.
2. At Selection-screen OUTPUT.
This is triggered before displaying the selection screen. It's just like PBO in Module pool.
3. At Selection-screen.
This event is triggered when the before leaving the selection screen.
4. Start-of-selection.
this is default event trigerred for every executable program. Here you can do all the retrival logic.
5. End-of-selection:
This event is triggered after the start-of-selection. to display the contents on the report.
Classical report events:
1.Top-of-page: Every time a new page is triggered. Mainly this is used for header of the report.
2. End-of-page : every time the list data reaches the footer region of the page.
Interactive report events.
top of page during line selection : top of page event for secondary list.
1. At line-selection : evey time user dbl-clicks(F2) on the list data.
2. At pF<key> :function key from F5 to F12 to perform interactive action on the lis
3. At user-command: to assign the function code for the button on the report.
It's just like PAI of the Module pool program.
Also Check This Link..
http://www.sap-img.com/abap/events-related-to-reporting.htm
Regards,
Kumar.