Monday, June 30, 2008

ALV in SAP

ALV - ( ABAP LIST VIEWER / Application List viewer)

is a control which we can use to increase the readability and the functionality of reports in SAP.
it allows user to select the columns that they want to display or hide, for sorting, arrange the order of the columns, group by function where user can sort and group the similar data, and get the total column by column , etc...

its also make the developers life more easier. They have to get the relevent data acording to the selection criteria and pass it to a relevent ALV function ( most of the time its 'REUSE_ALV_GRID_DISPLAY' ) with the correct parameters. Then the function will be handle all the other functions such as sorting, sub totaling etc...

how to use ALV to display a simple report in SAP using ABAP.

*Required Declarations.

DATA: l_alv TYPE REF TO cl_gui_alv_grid.
DATA : formatter TYPE i VALUE 0.
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
gd_layout TYPE slis_layout_alv,
gd_repid LIKE sy-repid,
gt_sort TYPE slis_t_sortinfo_alv,
gt_events TYPE slis_t_event,
gd_prntparams TYPE slis_print_alv.

*displaying ALV

DEFINE m_fieldcat.
ls_fieldcat-col_pos = 0.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = &2.
ls_fieldcat-do_sum = &3.
ls_fieldcat-reptext_ddic = &4.
append ls_fieldcat to lt_fieldcat.
clear ls_fieldcat.
END-OF-DEFINITION.

DEFINE m_sort.
add 1 to ls_sort-spos.
ls_sort-fieldname = &1.
ls_sort-up = 'X'.
ls_sort-subtot = &2.
ls_sort-expa = &3.
append ls_sort to lt_sort.
END-OF-DEFINITION.

DATA:
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
lt_sort TYPE slis_t_sortinfo_alv,
ls_sort TYPE slis_sortinfo_alv,
ls_layout TYPE slis_layout_alv,
ls_title TYPE slis_layout_alv_spec1,
lt_sp_group TYPE slis_t_sp_group_alv,
ls_col TYPE slis_layout_alv_spec,
ls_sp_group TYPE slis_sp_group_alv.

m_fieldcat 'CO_CODE' '' '' 'Country Code' .
m_fieldcat 'COUNTRY' '' '' 'Country' .
m_fieldcat '' ' ' '' '

this is the field catelogue that you declare before. you have to pass the correcr parameter .
(DEFINE m_fieldcat.......................)


m_sort 'CO_CODE' 'X' ' ' .
m_sort 'FF_CODE' 'X' ' ' .

if you want to sort it at the first time its displaying, define the fields that you want to sort.
this is optional. and this the m_sort that we defined eirlier.
(DEFINE m_sort............................)


gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'(256).
gd_layout-coltab_fieldname = 'CELL_COLOUR'.
* perform build_events.
gd_prntparams-reserve_lines = '4'. "Lines reserved for footer
gd_prntparams-no_coverpage = 'X'.
gd_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = gd_repid
is_layout = gd_layout
it_fieldcat = lt_fieldcat[]
i_grid_title = ''
it_sort = lt_sort
it_events = gt_events
is_print = gd_prntparams
TABLES
t_outtab = <>
EXCEPTIONS
program_error = 1
OTHERS = 2.


this will show the final ALV .
you need to change the field names and the itab name of the above code.

this is an example code...


*&---------------------------------------------------------------------*
*& Report ZTESTMARA
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZTESTMARA.
tables : MARA.
DATA : BEGIN OF itabrec occurs 0.
INCLUDE STRUCTURE mara.
DATA : END OF itabrec.
************ ALV declarations****************
DATA: l_alv TYPE REF TO cl_gui_alv_grid.
DATA : formatter TYPE i VALUE 0.
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH
HEADER LINE,
gd_layout TYPE slis_layout_alv,
gd_repid LIKE sy-repid,
gt_sort TYPE slis_t_sortinfo_alv,
gt_events TYPE slis_t_event,
gd_prntparams TYPE slis_print_alv.
*********************************************
** Selection options..**********************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS tmatnr FOR mara-matnr .
SELECTION-SCREEN END OF BLOCK b1.
********************************************************
*** Program logic****************************
perform getData.
perform showALV.
*********************************************
*&---------------------------------------------------------------------*
*& Form getData
*&---------------------------------------------------------------------*
* get the data from MARA
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form getData .
select * from mara into table itabrec where
matnr in tmatnr.
endform. " getData
*&---------------------------------------------------------------------*
*& Form showALV
*&---------------------------------------------------------------------*
* Display ALV
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form showALV .

DEFINE m_fieldcat.
ls_fieldcat-col_pos = 0.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = &2.
ls_fieldcat-do_sum = &3.
ls_fieldcat-reptext_ddic = &4.
append ls_fieldcat to lt_fieldcat.
clear ls_fieldcat.
END-OF-DEFINITION.

DEFINE m_sort.
add 1 to ls_sort-spos.
ls_sort-fieldname = &1.
ls_sort-up = 'X'.
ls_sort-subtot = &2.
ls_sort-expa = &3.
append ls_sort to lt_sort.
END-OF-DEFINITION.

DATA:
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
lt_sort TYPE slis_t_sortinfo_alv,
ls_sort TYPE slis_sortinfo_alv,
ls_layout TYPE slis_layout_alv,
ls_title TYPE slis_layout_alv_spec1,
lt_sp_group TYPE slis_t_sp_group_alv,
ls_col TYPE slis_layout_alv_spec,
ls_sp_group TYPE slis_sp_group_alv.

m_fieldcat 'MATNR' '' '' 'Material Number' .
m_fieldcat 'MEINS' '' '' 'Base Unit of Measure' .

m_sort 'MATNR' 'X' ' ' .
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'(256).
gd_layout-coltab_fieldname = 'CELL_COLOUR'.
* perform build_events.
gd_prntparams-reserve_lines = '4'. "Lines reserved for footer
gd_prntparams-no_coverpage = 'X'.
gd_repid = sy-repid.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = gd_repid
is_layout = gd_layout
it_fieldcat = lt_fieldcat[]
i_grid_title = 'Materials....'
* i_save = 'A'
it_sort = lt_sort
it_events = gt_events
is_print = gd_prntparams
TABLES
t_outtab = itabrec
EXCEPTIONS
program_error = 1
OTHERS = 2.

endform. " showALV


**** make sure that you have typed the field names in capital letters , when you defined the field catalogue and sorting catalogue...

Friday, February 29, 2008

Using Apache and IIS for hosting in the same machine

Today both the IIS and Apahe are 2 leading servers in the world. but unfortunately Apache is not supporting for asp where IIS support for both asp and PHP (not by default but we can configure with PHP instaltions). But still there are some issues where I faced when i try to use MySQL with PHP in IIS. There for its better to use IIS for ASP and Apache for PHP.

In this case we should install both IIS and Apache in the same PC(If we have more than one computer then there wont be any issue.we can install IIS in one machine and Apache in other machine.) .
when we host a website in a server the server should run on port 80. Otherwise the user have to type the port number as well in order to access the website. But we know that we cant use one port for 2 applications. There for we can configure only one server to run on port 80. But in our case we have 2 servers run on the same machine (i.e. IIS and Apache). and both servers should be accessible from the outside without typing the port number.

By doing the followings we can achieve this task.
1. Install Apache in the server and configure it to use port 80.(by default its using port 80, so no need to configure it).
2. Configure it for php support.
* if you using XAMP or WAMP kind of a software then you do not need to configure for PHP. its all configured and we can use it without any changes.
3. Install IIS and add the website that you want to host in IIS.
4. Right click on the newly created website and go to properties
5. Change the port number to some other port number (Not 80).
6. Start the website by click on the Start Icon in the tool bar.

7. Open your browser and check weather the site can be accessed with the url and the port.
e.g 85 is the port number.
http://localhost:85

8. Open the httpd.conf. uncomment the following lines by removing '#'

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule rewrite_module modules/mod_rewrite.so

This will enable proxy support of Apache and we can use Apache for redirection and etc...

9. then go to # Virtual hosts in httpd.conf ( if you use XAMPP then it will be as follows
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
which means the virtual host configurations will be in a file call httpd-vhosts.conf in conf/extra. you have to open that file)

then add the following lines.

Namevirtualhost *:80


ServerName your url here
ProxyRequests off
ProxyPass / http://your ip here:new port/
ProxyPassReverse / http://your ip here:new port/


e.g

Namevirtualhost *:80


ServerName www.myserver.com
ProxyRequests off
ProxyPass / http://87.106.76.47:8080/
ProxyPassReverse / http://87.106.76.47:8080/


10. start the Apache. ( after any modification, you have to restart Apache.)

10. open your browser and type the URL without the port number. Thats it you can see your ASP page.

How it works.
all the incoming requests through port 80 will be handled by Apache. Then it will check the virtual host list and will handover to the relevant server to handle other transactions. all the connection will be handled by the Apache. IIS wont listen to Port 80.

Thursday, February 28, 2008

Unexpected Error 0x8ffe2740 in IIS 5.1

If you are using IIS 5.1 on XP and if you get an error when you try to start the default website saying that "Unexpected Error 0x8ffe2740 Occurred", which means you have a port conflict with some other software in your system. Most of the time this can be some other server software such as Apache. But in my case it was "Skype". skype is using port 80 and 443 as alternatives for incoming connections.

so if you want to use both IIS and Skype at the same time change the port settings of the skype or change the port settings of the iis. but the port 80 is the default port for any webserver such as IIS , Apache. there for its better to change the port settings of the Skype.

Saturday, February 9, 2008

About me

Name :Bhashitha Jayawardhane N.W.J.L
Address : No 23, 7th lane, Colombo road, padukka.
email : bashi003j@gmail.com ; bashi003j@yahoo.com