Powered By

Free XML Skins for Blogger

Powered by Blogger

Thursday, February 12, 2009

Vb codes (or VBA macro code) for access SAP, and run one RFC

I am looking for, Vb codes (or VBA macro code) for access SAP, and run one RFC .

Does anyone have example VB to SAP code?

Hakan

I can give you some code, but not sure it will work for you. When you ( or the help desk ) installs the SAP GUI, you can also install the SAP RFC development kit, if you do this you will have in your c:\program files\SAP??? ( in my case C:\Program Files\SAP620 ) a folder with a .frm extension
( in my case C:\Program Files\SAP620 \SAPGUI\rfcsdk\ccsamp\RFCSamp.VB\RFCsamp.frm )

From there you can start then, because you also need the vbp file and the vbw file in order to really make it work. If you just need the code, then here you go :

Option Explicit

Private Sub Command1_Click()
'Dim Foo As RFCSampObj ' Due to an acknowledged problem in MTS
Dim Foo As Object ' we Dim Foo as Object instead of as RFCSampObj
Dim searchterm As String
Dim custlist As Recordset

Set Foo = CreateObject("RFCSampObj.RFCSampObj.1")
Foo.Destination = "IDES"
'Foo.Client = "800"
'Foo.Language = "E"
'Foo.UserID = "test"
'Foo.Password = "pw"

If Not Foo Is Nothing Then
searchterm = Text1.Text
'Unfortunately RFC_CUSTOMER_GET does not convert
' a SPACE selction into a * so we do it here....
If IsEmpty(searchterm) Then searchterm = "*"

On Error Resume Next
Call Foo.GetCustList(searchterm, "", custlist)

If Err.Number = 0 Then
If Not custlist Is Nothing Then
custlist.MoveFirst
While Not custlist.EOF
Debug.Print "------------------"
Debug.Print "custlist.Fields(name1) " &
custlist.Fields("NAME1")
Debug.Print "custlist.Fields(stras) " &
custlist.Fields("STRAS")
Debug.Print "custlist.Fields(ort01) " &
custlist.Fields("ORT01")
Debug.Print "custlist.Fields(pstlz) " &
custlist.Fields("PSTLZ")
Debug.Print "custlist.Fields(telf1) " &
custlist.Fields("TELF1")
Debug.Print "custlist.Fields(telfx) " &
custlist.Fields("TELFX")
custlist.MoveNext
Wend
Else
Debug.Print "ERROR: custlist is Nothing"
End If
Else
Debug.Print "ERROR" & Err.Description
MsgBox Err.Description, vbCritical, "Error:"

End If
Else
Debug.Print "Foo is nothing"
MsgBox "Foo is nothing"
End If

End Sub

Private Sub Command2_Click()

'Dim Foo As RFCSampObj ' Due to an acknowledged problem in MTS
Dim Foo As Object ' we Dim Foo as Object instead of as RFCSampObj

Dim rs As Recordset
Dim HeaderIn As Recordset
Dim ItemsIn As Recordset
Dim Partners As Recordset
Dim OrderNumber As String
Dim BapiReturn As Recordset
Dim SoldTo As Recordset
Dim ShipTo As Recordset
Dim Payer As Recordset
Dim ItemsOut As Recordset

'Input tables can be crafted in two different ways:
' - either using the DimAsXXXX method which returns a fully
' described but empty Recordset.
' - or using the AdvancedDataFactory to craft up a disconnected
' Recordset.
' An example of the later is shown with the Partners Table
' the remaining input tables are crafted with the dim as.
Dim adf As Object
' Describe the shape of a disconnected recordset

Dim vrsShape(1)
Dim vrsParvw(3)
Dim vrsKunnr(3)

vrsParvw(0) = "PARTN_ROLE"
vrsParvw(1) = CInt(8)
vrsParvw(2) = CInt(2)
vrsParvw(3) = False

vrsKunnr(0) = "PARTN_NUMB"
vrsKunnr(1) = CInt(8)
vrsKunnr(2) = CInt(10)
vrsKunnr(3) = False

vrsShape(0) = vrsParvw
vrsShape(1) = vrsKunnr

' Create a disconnected recordset to pass as an input

Set adf = CreateObject("RDSServer.DataFactory")
If adf Is Nothing Then
MsgBox "ADF == NOTGHING"
End If
Set Partners = adf.CreateRecordSet(vrsShape)

Set Foo = CreateObject("RFCSampObj.RFCSampObj.1")
If Not Foo Is Nothing Then

' Get an empty recordset which will be used as input in
CreateOrder call

Call Foo.DimHeader(HeaderIn)
HeaderIn.AddNew
HeaderIn.Fields("DOC_TYPE") = "TA"
HeaderIn.Fields("SALES_ORG") = "1000"
HeaderIn.Fields("DISTR_CHAN") = "10"
HeaderIn.Fields("DIVISION") = "00"
HeaderIn.Fields("PURCH_NO") = "SM-1177-3"
HeaderIn.Fields("INCOTERMS1") = "CPT"
HeaderIn.Fields("INCOTERMS2") = "Hamburg"
HeaderIn.Fields("PMNTTRMS") = "ZB01"
HeaderIn.Update

Call Foo.DimItems(ItemsIn)
ItemsIn.AddNew
ItemsIn.Fields("MATERIAL") = "R-1120"
ItemsIn.Fields("PLANT") = "1200"
ItemsIn.Fields("REQ_QTY") = 2000
ItemsIn.Update

Partners.AddNew
Partners.Fields("PARTN_ROLE") = "AG"
Partners.Fields("PARTN_NUMB") = "0000001177"
Partners.Update

'set logon information
Foo.Destination = "IDES"
'Foo.Client = "800"
'Foo.Language = "E"
'Foo.UserID = "test"
'Foo.Password = "pw"

Call Foo.OrderCreate(HeaderIn, _
ItemsIn, _
Partners, _
OrderNumber, _
SoldTo, _
ShipTo, _
Payer, _
ItemsOut, _
BapiReturn)
Debug.Print "OrderNumber" & OrderNumber
If BapiReturn Is Nothing Then
MsgBox "BapiReturn is Nothing"
Else
BapiReturn.MoveFirst
Debug.Print "BapiReturn.Type...." & BapiReturn.Fields("TYPE")
Debug.Print "BapiReturn.Code...." & BapiReturn.Fields("CODE")
Debug.Print "BapiReturn.Message." & BapiReturn.Fields
("MESSAGE")
Debug.Print "BapiReturn.LogNo..." & BapiReturn.Fields
("LOG_NO")
Debug.Print "BapiReturn.LogMsgNo" & BapiReturn.Fields
("LOG_MSG_NO")
End If
Else
MsgBox "Foo is nothing"
End If

End Sub


Private Sub Command3_Click()

'Dim Foo As RFCSampObj ' Due to an acknowledged problem in MTS
Dim Foo As Object ' we Dim Foo as Object instead of as RFCSampObj

Dim SalesOrders As Recordset
Dim BapiReturn As Recordset

Set Foo = CreateObject("RFCSampObj.RFCSampObj.1")

If Not Foo Is Nothing Then

'set logon information
Foo.Destination = "IDES"
'Foo.Client = "800"
'Foo.Language = "E"
'Foo.UserID = "test"
'Foo.Password = "pw"


On Error Resume Next
Call Foo.GetCustomerOrders(CustomerNumber.Text, _
SalesOrg.Text, _
, , , , _
BapiReturn, _
SalesOrders)

If Err.Number = 0 Then
If Not SalesOrders Is Nothing Then
SalesOrders.MoveFirst
While Not SalesOrders.EOF
Debug.Print "------------------"
Debug.Print "SalesOrders.Fields(SD_DOC).... " &
SalesOrders.Fields("SD_DOC")
Debug.Print "SalesOrders.Fields(ITM_NUMBER) " &
SalesOrders.Fields("ITM_NUMBER")
Debug.Print "SalesOrders.Fields(MATERIAL).. " &
SalesOrders.Fields("MATERIAL")
Debug.Print "SalesOrders.Fields(REQ_QTY)... " &
SalesOrders.Fields("REQ_QTY")
Debug.Print "SalesOrders.Fields(NAME)...... " &
SalesOrders.Fields("NAME")
Debug.Print "SalesOrders.Fields(NET_VALUE). " &
SalesOrders.Fields("NET_VALUE")
Debug.Print "SalesOrders.Fields(PURCH_NO).. " &
SalesOrders.Fields("PURCH_NO")
SalesOrders.MoveNext
Wend
Else
Debug.Print "ERROR: SalesOrders is Nothing"
End If
If BapiReturn Is Nothing Then
MsgBox "BapiReturn is Nothing"
Else
BapiReturn.MoveFirst
Debug.Print "BapiReturn.Type...." & BapiReturn.Fields
("TYPE")
Debug.Print "BapiReturn.Code...." & BapiReturn.Fields
("CODE")
Debug.Print "BapiReturn.Message." & BapiReturn.Fields
("MESSAGE")
Debug.Print "BapiReturn.LogNo..." & BapiReturn.Fields
("LOG_NO")
Debug.Print "BapiReturn.LogMsgNo" & BapiReturn.Fields
("LOG_MSG_NO")
End If
Else
Debug.Print "ERROR"
MsgBox Err.Description, vbCritical, "Error:"

End If
Else
MsgBox "Foo is nothing"
End If

End Sub

An Introduction to SAP

SAP was founded in 1972 in Walldorf, Germany. It stands for Systems, Applications and Products in Data Processing. Over the years, it has grown and evolved to become the world premier provider of client/server business solutions for which it is so well known today. The SAP R/3 enterprise application suite for open client/server systems has established a new standards for providing business information management solutions.

SAP product are consider excellent but not perfect. The main problems with software product is that it can never be perfect.

The main advantage of using SAP as your company ERP system is that SAP have a very high level of integration among its individual applications which guarantee consistency of data throughout the system and the company itself.

In a standard SAP project system, it is divided into three environments, Development, Quality Assurance and Production.

The development system is where most of the implementation work takes place. The quality assurance system is where all the final testing is conducted before moving the transports to the production environment. The production system is where all the daily business activities occur. It is also the client that all the end users use to perform their daily job functions.

To all company, the production system should only contains transport that have passed all the tests.

SAP is a table drive customization software. It allows businesses to make rapid changes in their business requirements with a common set of programs. User-exits are provided for business to add in additional source code. Tools such as screen variants are provided to let you set fields attributes whether to hide, display and make them mandatory fields.

This is what makes ERP system and SAP in particular so flexible. The table driven customization are driving the program functionality instead of those old fashioned hard-coded programs. Therefore, new and changed business requirements can be quickly implemented and tested in the system.

Many other business application software have seen this table driven customization advantage and are now changing their application software based on this table customizing concept.

In order to minimized your upgrading costs, the standard programs and tables should not be changed as far as possible. The main purpose of using a standard business application software like SAP is to reduced the amount of time and money spend on developing and testing all the programs. Therefore, most companies will try to utilized the available tools provided by SAP.

sap abap program for Upload Logo for REUSE_ALV_COMMENTARY_WRITE

For those who wish to upload and use a picture in your ALV abap reports.

Steps for uploading Logo :-:
1. Goto the transaction OAER
2. Enter the class name as 'PICTURES'
3. Enter the class type as 'OT'
4. Enter the object key as the name of the logo you wish to give
5. Execute
6. Then in the new screen select Standard doc. types in bottom window
Click on the Screen icon
Now, it will ask for the file path where you have to upload the logo
7. Now you can use this logo in REUSE_ALV_COMMENTARY_WRITE

or

Import Logo and Background Picture for Reporting

In this step, you can import a customer-specific logo and a background picture into the R/3 System. These will be displayed in the header area of reports in HR Funds and Position Management.

From the SPRO:
HR Funds and Position Management --> Dialog Control --> Customize Reporting Interface --> Import Logo and Background Picture for Reporting.

Activities
1. Enter the Name of your logo/background picture as an object key in the initial screen.
2. Make sure that the class name is PICTURES, and the class type is OT.
3. Choose Execute.
4. Double-click the document type Picture on the Create tab page. A dialog box will appear in which you can enter the path in which the logo/background picture can be found.
5. Enter the path and choose Open. The logo will be uploaded into the current R/3 System. If the logo/background picture is to be transported into other systems as well, choose Transport.
6. Return to the initial screen and repeat the procedure after having entered the Name of your background picture as an object key.

Please note that the logo/background picture can only be displayed in ALV-based reports with an HTML header. Manually programmed reports such as business distribution plans are not based on the ALV.

If you have selected several initial objects, ALV-based reports in HR Funds and Position Management will automatically use a hiearchical-sequential display. A logo is not displayed here either. Note also that the logo cannot be printed (see print preview in program).

Make sure that the logo does not exceed a height of 100 pixels because it would mean that the header of the report will be scrollable.

What is SLIS in sap abap ALV

SLIS is the type library for ALV grid.

If you'll use the ALV you have to add TYPE-POOLS : SLIS. command at the beginning of your code.

Consider these :
slis_t_fieldcat_alv is containing "_t_"
It means that it is an internal table and slis_fieldcat_alv is header line of that.

Here is a practical example for alv grid :
Just think that you have an internal table named 'ITAB' to show.

Step1 : First add these lines to your code :
TYPE-POOLS : SLIS.

DATA ALV_PROG_NAME LIKE SY-REPID.
ALV_PROG_NAME = SY-REPID.

DATA : ALV_ITAB_NAME(30),
L_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
ALV_ITAB_NAME = 'ITAB'. "!!Write here the name of your internal table

Step 2 : Add these two function :
The first function is filling the fieldcat L_FIELDCAT that you described, second is showing it on the screen.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = ALV_PROG_NAME
I_INTERNAL_TABNAME = ALV_ITAB_NAME
* I_STRUCTURE_NAME =
* I_CLIENT_NEVER_DISPLAY = 'X'
I_INCLNAME = ALV_PROG_NAME
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
CHANGING
CT_FIELDCAT = L_FIELDCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = ALV_PROG_NAME
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
IT_FIELDCAT = L_FIELDCAT
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IT_ALV_GRAPHICS =
* IT_ADD_FIELDCAT =
* IT_HYPERLINK =
* I_HTML_HEIGHT_TOP =
* I_HTML_HEIGHT_END =
* IT_EXCEPT_QINFO =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = ITAB[] "Write here the name of your internal table + []
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF. *-- Bulent

How to Refresh ALV List/Grid once it is displayed?

This mean to say that if you have a 'refresh' push button in your gui status, every time you press the button, the list should get refreshed.

In ALV, to refresh the table you have to call the method "refresh_table_display".

It has the syntax very similar to creating the table.

It has two parameters. In the first one, you can mention if you want to refresh only the data (the icons are not refreshed)

or

if you want to refresh only the icons around the grid (the data is not refreshed - this option is mostly not used in day to day applications).

the synatx is :-

call method grid (name of grid )->refresh_table_display

exporting

IS_STABLE = (THIS IS FOR DATA REFRESHING)

I_SOFT_REFRESH = (THIS IS FOR ICON REFRESHING).

sap abap ALV 'Classic' Creating User/Global Layout Variants

You are working with the ALV "Classic" function module REUSE_ALV_LIST_DISPLAY.

Reading the documentation for the function module, it seems there is a way to save an ALV layout variant as "user-specific" and/or "global". But unfortunately, you either can only save "globals" (with the '/' as first character of the layout name) or "user-specific".

You have tried the I_SAVE parameter as 'U' and can only save "user-specific". You tried I_SAVE as 'X' and can only save "global". You tried I_SAVE as 'A', but only can only save as "user-specific". The odd thing is, on the Save Layout pop-up dialog the User-Specific checkbox is always "greyed-out", but has a check (for 'U' and 'A') or is checkless (for 'X').

Can "user" and "global" layout variants be saved together from same program with I_SAVE as 'A'?

Why is the User-Specific checkbox on the Save Layout pop-up always "greyed-out"?

You have the following EXPORTING parameters in my function module:
I_DEFAULT = 'X'
I_SAVE = 'A' "<=== this is to be global & user IS_VARIANT = VARIANT

VARIANT has the program's name in the REPORT field.


The "user-specific saving" needs a special authorization:
Authority-check object 'S_ALV_LAYO' id 'ACTVT' field '23', you can
avoid this authorization with IS_LAYOUT-NO_AUTHOR = 'X

How to use ALV for Hierarchical Lists

Can anyone tell me how to use ALV for hierarchical lists using the function code REUSE_ALV_HIERSEQ_LIST_DISPLAY?

Swarna

Hello, there are some nice examples in SAP which use this function module, so you might want to check them out ( where used etc. )

In essence, this is a call in one of my ABAPs

  CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
i_interface_check = 'I'
i_callback_program = gv_repid
* i_callback_pf_status_set = 'STATUS_DATA'
i_callback_user_command = 'COMMAND_DATA'
* is_layout = gs_layout
it_fieldcat = gt_fieldcat
i_default = ' '
i_save = 'A'
i_tabname_header = v_headers_itable
i_tabname_item = v_items_itable
i_structure_name_header = v_headers_table
i_structure_name_item = v_items_table
is_keyinfo = gs_keyinfo
i_bypassing_buffer = 'X'
TABLES
t_outtab_header = i_headers
* t_outtab_item = i_result
t_outtab_item = i_report
EXCEPTIONS
program_error = 1
OTHERS = 2.

The field cat creation worked like this :
FORM fieldcat.

DATA: ls_fieldcat TYPE slis_fieldcat_alv.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_internal_tabname = v_items_itable
i_structure_name = v_items_table
CHANGING
ct_fieldcat = gt_fieldcat.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_internal_tabname = v_headers_itable
i_structure_name = v_headers_table
CHANGING
ct_fieldcat = gt_fieldcat.

ENDFORM.


and of course you need to tell the thing what is key and item

gs_keyinfo-header01 = 'PA'.
gs_keyinfo-item01 = 'PA'.
gs_keyinfo-item02 = 'SAPDOC'.
PERFORM fieldcat.
I hope this helps you and not confuse you,
Cheers.

sap abap program for Sample ALV: Heading in ALV

report zus_alv_demo_grid .

tables: ekko.
type-pools: slis.

types: begin of t_ekko,
ebeln type ekpo-ebeln,
ebelp type ekpo-ebelp,
statu type ekpo-statu,
aedat type ekpo-aedat,
matnr type ekpo-matnr,
menge type ekpo-menge,
meins type ekpo-meins,
netpr type ekpo-netpr,
peinh type ekpo-peinh,
line_color(4) type c, "Used to store row color
end of t_ekko.

data: it_ekko type standard table of t_ekko initial size 0,
wa_ekko type t_ekko.

*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,

gd_tab_group type slis_t_sp_group_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid.

* Data declaration for EVENT and PRINT PARAMETER.
data: gt_events type slis_t_event,
gd_prntparams type slis_print_alv.

* data declaration for sorting.
data : it_sortcat type slis_sortinfo_alv occurs 1,
wa_sort like line of it_sortcat.
data : i_list_comments type slis_t_listheader.

start-of-selection.
perform data_retrieval.
* perform user_command.
perform build_fieldcatalog.
perform build_layout.
perform build_events.
perform build_print_params.
perform build_sortcat.
perform display_alv_report.

end-of-selection.

*TOP-OF-PAGE.
* PERFORM top-of-page.

end-of-page.
*&----------------------------------------------------------
*& Form build_fieldcatalog
*&----------------------------------------------------------
* text
*-----------------------------------------------------------
* --> p1 text
* <-- p2 text
*-----------------------------------------------------------
form build_fieldcatalog.

fieldcatalog-fieldname = 'EBELN'.
fieldcatalog-seltext_m = 'Purchase Order'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.


fieldcatalog-fieldname = 'EBELP'.
fieldcatalog-seltext_m = 'PO Item'.
fieldcatalog-col_pos = 1.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.


fieldcatalog-fieldname = 'STATU'.
fieldcatalog-seltext_m = 'Status'.
fieldcatalog-col_pos = 2.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'AEDAT'.
fieldcatalog-seltext_m = 'Item change date'.
fieldcatalog-col_pos = 3.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Material Number'.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'MENGE'.
fieldcatalog-seltext_m = 'PO quantity'.
fieldcatalog-col_pos = 5.
fieldcatalog-do_sum = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'MEINS'.
fieldcatalog-seltext_m = 'Order Unit'.
fieldcatalog-col_pos = 6.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'NETPR'.
fieldcatalog-seltext_m = 'Net Price'.
fieldcatalog-col_pos = 7.
fieldcatalog-outputlen = 15.
fieldcatalog-datatype = 'CURR'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.


fieldcatalog-fieldname = 'PEINH'.
fieldcatalog-seltext_m = 'Price Unit'.
fieldcatalog-col_pos = 8.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

endform. " build_fieldcatalog
*&----------------------------------------------------------
*& Form build_layout
*&----------------------------------------------------------
* text
*-----------------------------------------------------------
* --> p1 text
* <-- p2 text
*-----------------------------------------------------------
form build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'(201).

* Set layout field for row attributes(i.e. color)
gd_layout-info_fieldname = 'LINE_COLOR'.
* gd_layout-totals_only = 'X'.
* gd_layout-f2code = 'DISP'. "Sets fcode for
*when double
* "click(press f2)*
* gd_layout-group_change_edit = 'X'.
* gd_layout-header_text = 'helllllo'.
endform. " build_layout
*&----------------------------------------------------------
*& Form data_retrieval
*&----------------------------------------------------------
* text
*-----------------------------------------------------------
* --> p1 text
* <-- p2 text
*-----------------------------------------------------------
form data_retrieval.
data: ld_color(1) type c.

select ebeln ebelp statu aedat matnr menge meins netpr
peinh from ekpo into table it_ekko.
*Populate field with color attributes
loop at it_ekko into wa_ekko.
* Populate color variable with colour properties
* Char 1 = C (This is a color property)
* Char 2 = 3 (Color codes: 1 - 7)
* Char 3 = Intensified on/off ( 1 or 0 )
* Char 4 = Inverse display on/off ( 1 or 0 )
* i.e. wa_ekko-line_color = 'C410'
ld_color = ld_color + 1.
* Only 7 colours so need to reset color value
if ld_color = 8.
ld_color = 1.
endif.
concatenate 'C' ld_color '10' into wa_ekko-line_color.
* wa_ekko-line_color = 'C410'.
modify it_ekko from wa_ekko.
endloop.

endform. " data_retrieval
*&----------------------------------------------------------
*& Form display_alv_report
*&----------------------------------------------------------
* text
*-----------------------------------------------------------
* --> p1 text
* <-- p2 text
*-----------------------------------------------------------
form display_alv_report.
gd_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
is_layout = gd_layout
i_callback_top_of_page = 'TOP-OF-PAGE'
i_callback_user_command = 'USER_COMMAND'
i_callback_pf_status_set = 'SET_PF_STATUS'
it_event = gt_events
is_print = gd_prntparams
it_fieldcat = fieldcatalog[]
it_sort = it_sortcat
i_save = 'X'
tables
t_outtab = it_ekko
exceptions
program_error = 1
others = 2.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. " DISPLAY_ALV_REPORT
*&----------------------------------------------------------
*& Form user_command
*&----------------------------------------------------------
* text
*-----------------------------------------------------------
* --> p1 text
* <-- p2 text
*-----------------------------------------------------------
*&----------------------------------------------------------
*& Form top-of-page
*&----------------------------------------------------------
* text
*-----------------------------------------------------------
* --> p1 text
* <-- p2 text
*-----------------------------------------------------------
form top-of-page.
*ALV Header declarations
data: t_header type slis_t_listheader,
wa_header type slis_listheader,
t_line like wa_header-info,
ld_lines type i,
ld_linesc(10) type c.

* Title
wa_header-typ = 'H'.
wa_header-info = 'EKKO Table Report'.
append wa_header to t_header.
clear wa_header.

* Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
concatenate sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) into wa_header-info."todays date
append wa_header to t_header.
clear: wa_header.

* Total No. of Records Selected
describe table it_ekko lines ld_lines.
ld_linesc = ld_lines.

concatenate 'Total No. of Records Selected: ' ld_linesc
into t_line separated by space.

wa_header-typ = 'A'.
wa_header-info = t_line.
append wa_header to t_header.
clear: wa_header, t_line.

call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = t_header
i_logo = 'GANESH_LOGO'.



endform. " top-of-page

*---------------------------------------------------------------------*
* FORM user_command *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> R_UCOMM *
* --> RS_SELFIELD *
*---------------------------------------------------------------------*
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
case r_ucomm.

when '&IC1'.
if rs_selfield-fieldname = 'EBELN'.
read table it_ekko into wa_ekko index rs_selfield-tabindex.
set parameter id 'BES' field wa_ekko-ebeln.
call transaction 'ME23N' and skip first screen.
endif.
when 'ULHAS'.
if rs_selfield-fieldname = 'EBELN'.
read table it_ekko into wa_ekko index rs_selfield-tabindex.
set parameter id 'BES' field wa_ekko-ebeln.
call transaction 'ME23N' and skip first screen.
endif.

endcase.

endform.

*---------------------------------------------------------------------*
* FORM set_pf_status *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> RT_EXTAB *
*---------------------------------------------------------------------*
form set_pf_status using rt_extab type slis_t_extab.
set pf-status 'ZNEWSTATUS'.
endform.
*&---------------------------------------------------------------------*
*& Form build_events
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form build_events.
data: ls_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = gt_events[]
* EXCEPTIONS
* LIST_TYPE_WRONG = 1
* OTHERS = 2
.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
read table gt_events with key name = slis_ev_end_of_page
into ls_event.
if sy-subrc = 0.
move 'END_OF_PAGE' to ls_event-form.
append ls_event to gt_events.
endif.

read table gt_events with key name = slis_ev_end_of_list
into ls_event.
if sy-subrc = 0.
move 'END_OF_LIST' to ls_event-form.
append ls_event to gt_events.
endif.
endform. " build_events
*&---------------------------------------------------------------------*
*& Form build_print_params
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form build_print_params.
gd_prntparams-reserve_lines = '3'. "Lines reserved for footer
gd_prntparams-no_coverpage = 'X'.
endform. " build_print_params

*---------------------------------------------------------------------*
* FORM END_OF_PAGE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form end_of_page.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
write: sy-uline(50).
skip. write:/40 'Page:', sy-pagno .
endform.

*---------------------------------------------------------------------*
* FORM END_OF_LIST *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form end_of_list.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
skip. write:/40 'Page:', sy-pagno .
endform.
*&---------------------------------------------------------------------*
*& Form build_sortcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form build_sortcat.
wa_sort-spos = 1.
wa_sort-fieldname = 'EBELN'.
append wa_sort to it_sortcat.

wa_sort-spos = 2.
wa_sort-fieldname = 'EBELP'.
append wa_sort to it_sortcat.

endform. " build_sortcat

sap abap program for Test ALV Display With Header & Footer

*Program to Test ALV Display With Header & Footer.
*&---------------------------------------------------------------------*
*& Report ZRJR02 *
*&---------------------------------------------------------------------*
REPORT ZRJR02 .

*Table declaration.
TABLES:ZEMP_MST,ZDEPT_MST,ZDESG_MST,ZSL_TXN.

*Varriable declaration.
TYPE-POOLS SLIS.
DATA : POS TYPE I.
DATA REPID LIKE SY-REPID.

DATA : F1 TYPE SLIS_T_FIELDCAT_ALV,
F2 TYPE SLIS_FIELDCAT_ALV,
L_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA L_POS TYPE I VALUE 1. "position of the column
DATA GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
*DATA GT_SORT TYPE SLIS_T_SORTINFO_ALV.

data: GT_EVENTS TYPE SLIS_T_EVENT,
FS_EVENTCAT LIKE LINE OF GT_EVENTs.

*Internal table declaration.
*DATA BEGIN OF IT_SORT OCCURS 5.
* INCLUDE TYPE SLIS_SORTINFO_ALV.
*DATA END OF IT_SORT.

DATA:BEGIN OF ITAB OCCURS 0,
ZEMPNO LIKE ZEMP_MST-ZEMPNO,
ZEMPNAME LIKE ZEMP_MST-ZEMPNAME,
ZDEPTCD LIKE ZEMP_MST-ZDEPTCD,
ZDEPTNAME LIKE ZDEPT_MST-ZDEPTNAME,
ZDESGCD LIKE ZEMP_MST-ZDESGCD,
ZDESGNAME LIKE ZDESG_MST-ZDESGNAME,
END OF ITAB.
REFRESH ITAB.CLEAR ITAB.

START-OF-SELECTION.

SELECT A~ZEMPNO A~ZEMPNAME A~ZDEPTCD B~ZDEPTNAME A~ZDESGCD C~ZDESGNAME
FROM ZEMP_MST AS A
INNER JOIN ZDEPT_MST AS B
ON A~ZDEPTCD EQ B~ZDEPTCD
INNER JOIN ZDESG_MST AS C
ON A~ZDESGCD EQ C~ZDESGCD
INTO CORRESPONDING FIELDS OF TABLE ITAB.
IF SY-SUBRC <> 0.
MESSAGE E899(M3) WITH 'No records'.
ENDIF.

perform f_build_eventcat.
PERFORM LAYOUT.

END-OF-SELECTION.

*&---------------------------------------------------------------------*
*& Form LAYOUT
*&---------------------------------------------------------------------*
FORM LAYOUT .
PERFORM FCAT USING 'ZEMPNO' 'ITAB' '' 'Emp.No.' 'ZEMPNO' 'ZEMP_MST' ''.
PERFORM FCAT USING 'ZEMPNAME' 'ITAB' '' 'Emp. Name' 'ZEMPNAME' 'ZEMP_MST' ''.
PERFORM FCAT USING 'ZDEPTCD' 'ITAB' '' 'Dept.Code' 'ZDEPTCD' 'ZEMP_MST' ''.
PERFORM FCAT USING 'ZDEPTNAME' 'ITAB' '' 'Dept.Name' 'ZDEPTNAME' 'ZDEPT_MST' ''.
PERFORM FCAT USING 'ZDESGCD' 'ITAB' '' 'Desg.Code' 'ZDESGCD' 'ZEMP_MST' ''.
PERFORM FCAT USING 'ZDESGNAME' 'ITAB' '' 'Desg.Name' 'ZDESGNAME' 'ZDESG_MST' ''.

* PERFORM LSORT USING 'ZEMPNO' 'IDATA' ''.
* PERFORM LSORT USING 'ZEMPNAME' 'IDATA' ''.

* MOVE IT_SORT[] TO GT_SORT[].

REPID = SY-REPID.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = REPID
IT_FIELDCAT = F1
* IT_SORT = GT_SORT
I_SAVE = 'X'
IT_EVENTS = GT_EVENTS[]

TABLES
T_OUTTAB = ITAB.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " LAYOUT


*&---------------------------------------------------------------------*
*& Form FCAT
*&---------------------------------------------------------------------*
FORM FCAT USING P_FIELD P_TABLE P_SUM P_TEXT P_RFIELD P_RTABLE P_DISP.
ADD 1 TO POS.
F2-COL_POS = POS.
F2-FIELDNAME = P_FIELD.
F2-TABNAME = P_TABLE.
F2-SELTEXT_L = P_TEXT.
F2-REF_FIELDNAME = P_RFIELD.
F2-REF_TABNAME = P_RTABLE.
F2-DO_SUM = P_SUM.
F2-NO_OUT = P_DISP.
APPEND F2 TO F1.
CLEAR F2.
ENDFORM. " FCAT

*&---------------------------------------------------------------------*
*& Form LSORT
*&---------------------------------------------------------------------*
*FORM LSORT USING P_FIELD P_TABLE P_UP.
* ADD 1 TO L_POS.
* IT_SORT-SPOS = L_POS.
* IT_SORT-FIELDNAME = P_FIELD.
* IT_SORT-TABNAME = P_TABLE.
* IT_SORT-UP = P_UP.
* APPEND IT_SORT.
*ENDFORM. " LSORT
*-------------
FORM F_BUILD_EVENTCAT .
CLEAR: GT_EVENTS. REFRESH: GT_EVENTS.

CLEAR: FS_EVENTCAT.
FS_EVENTCAT-NAME = 'TOP_OF_PAGE'.
FS_EVENTCAT-FORM = 'F_REPORT_HEADER_ALV'.
APPEND FS_EVENTCAT TO GT_EVENTS.


CLEAR: FS_EVENTCAT.
FS_EVENTCAT-NAME = 'END_OF_LIST'.
FS_EVENTCAT-FORM = 'F_WRITE_SUMMARY'.
APPEND FS_EVENTCAT TO GT_EVENTS.

ENDFORM. " F_BUILD_EVENTCAT

FORM F_REPORT_HEADER_ALV.
CALL FUNCTION 'Z_YHEAD_PRINT'
EXPORTING
TITLE1 = 'XYZ Limited'
TITLE2 = 'Employee Master'
TITLE3 = 'Created on '
COLOR = 'X'
.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form F_WRITE_SUMMARY
*&---------------------------------------------------------------------*
* Write summary before exit
*----------------------------------------------------------------------*
FORM F_WRITE_SUMMARY .

write:/ 'Welcome to XYZ Limited'.
write:/ 'This is a test program to display Report in ALV Format'.

Sample programs on sap abap ALV Grid

report zbnstest.
************************************************************************
* TABLES AND DATA DECLARATION.
************************************************************************
*TABLES: mara,makt.",marc.
data syrepid like sy-repid.
data sydatum(10). " LIKE sy-datum.
data sypagno(3) type n.

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

************************************************************************
* INTERNAL TABLE DECLARATION.
************************************************************************
* INTERNAL TABLE TO HOLD THE VALUES FROM THE MARA TABLE
data: begin of t_mara occurs 0,
matnr like mara-matnr,
meins like mara-meins,
mtart like mara-mtart,
matkl like mara-matkl,

end of t_mara.

* INTERNAL TABLE TO HOLD THE CONTENTS FROM THE EKKO TABLE
data : begin of t_marc occurs 0,
matnr like mara-matnr,
werks like marc-werks,
minbe like marc-minbe.
data: end of t_marc.

* INTERNAL TABLE TO HOLD THE VALUES FROM MAKT TABLE.
data : begin of t_makt occurs 0,
matnr like mara-matnr,
maktx like makt-maktx,
spras like makt-spras,
end of t_makt.

* INTERNAL TABLE WHICH ACTUALLY MERGES ALL THE OTHER INTERNAL TABLES.
data: begin of itab1 occurs 0,
matnr like mara-matnr,
meins like mara-meins,
maktx like makt-maktx,
spras like makt-spras,
werks like marc-werks,
minbe like marc-minbe,
end of itab1.

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

* DECLARING THE EVENTTABLE INTERNL TABLE FOR USING EVENTS LIKE
* TOP-OF-PAGE ETC.
data : eventstab type slis_t_event with header line.

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

* STRUCTURE TO PASS THE COLOR ATTRIBUTES FOR DISPLAY.
data : colorstruct type slis_coltypes.
************************************************************************
* INITIALIZATION. *
************************************************************************
initialization.
syrepid = sy-repid.
sypagno = sy-pagno.
clear fieldcatalog.

************************************************************************
* START-OF-SELECTION. *
************************************************************************
start-of-selection.
* SUBROUTINE TO POPULATE THE COLORSTRUCT
perform fill_colorstruct using colorstruct.
* SUBROUTINE TO POPULATE THE FIELDS OF THE FIELD CATALOGUE
perform populate_fieldcatalog.
* SUBROUTINE TO SELECT DATA FROM VARIOUS TABLES AND POPULATE IT IN THE
* INTERNAL TABLE.
perform selectdata_and_sort.
* SUBROUTINE TO POPULATE THE LAYOUT STRUCTURE.
perform populate_layout using fieldlayout.
* SUBROUTINE TO CALL THE FUNCTION MERGE TO ENSURE PROPER DISPLAY.
perform merge_fieldcatalog.
* SUBROUTINE TO POPULATE THE EVENTSTAB.
perform fill_eventstab tables eventstab.
* SUBROUTINE TO POPULATE THE HEADING TABLES.
perform fill_headingtable tables heading using 'HEADING'.
perform fill_headingtable tables heading1 using 'HEADING1'.
perform fill_headingtable tables heading2 using 'HEADING2'.
perform fill_headingtable tables heading3 using 'HEADING3'.
perform fill_headingtable tables heading4 using 'HEADING4'.
perform fill_headingtable tables heading5 using 'HEADING5'.
perform fill_headingtable tables heading6 using 'HEADING6'.
perform fill_headingtable tables heading7 using 'HEADING7'.
perform fill_headingtable tables heading8 using 'HEADING8'.

* SUBROUTINE TO DISPLAY THE LIST.
perform display_alv_list.

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

*---------------------------------------------------------------------*
* FORM FILL_FIELDS_OF_FIELDCATALOG *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> FIELDCATALOG *
* --> P_TABNAME *
* --> P_FIELDNAME *
* --> P_KEY *
* --> P_KEY *
*---------------------------------------------------------------------*
form fill_fields_of_fieldcatalog tables fieldcatalog
structure fieldcatalog
using p_tabname
p_fieldname
p_key.
* p_no_out.
fieldcatalog-tabname = p_tabname.
fieldcatalog-fieldname = p_fieldname.
fieldcatalog-key = p_key.
fieldcatalog-emphasize = '1234'.
*fieldcatalog-no_out = p_no_out.
append fieldcatalog.
endform. " FILL_FIELDSOFFIELDCATALOG

*---------------------------------------------------------------------*
* FORM POPULATE_LAYOUT *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> FIELDLAYOUT *
*---------------------------------------------------------------------*
form populate_layout using fieldlayout type slis_layout_alv.
fieldlayout-f2code = '&ETA' .
fieldlayout-zebra = 'X'.
* FOR THE WINDOW TITLE.
fieldlayout-window_titlebar = 'ALV with Events'.

fieldlayout-colwidth_optimize = 'X'.
fieldlayout-no_vline = ' '.
*fieldlayout-no_input = 'X'.
fieldlayout-confirmation_prompt = ''.
fieldlayout-key_hotspot = 'X'.
* This removes the column headings if the flag is set to 'X'
fieldlayout-no_colhead = ' '.
*fieldlayout-hotspot_fieldname = 'MAKTX'.
fieldlayout-detail_popup = 'X'.
* fieldlayout-coltab_fieldname = 'X'.
endform. " POPULATE_LAYOUT

*---------------------------------------------------------------------*
* FORM SELECTDATA_AND_SORT *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form selectdata_and_sort.
select matnr meins mtart matkl from mara
into corresponding fields of t_mara
up to 500 rows .

select matnr maktx spras from makt
into corresponding fields of t_makt
where matnr = t_mara-matnr and
spras = sy-langu.

select matnr werks minbe from marc
into corresponding fields of t_marc
where matnr = t_mara-matnr.
append t_marc.
endselect.
append t_makt.
endselect.
append t_mara.
endselect.
perform populate_itab1.
sort itab1 by matnr.
endform. " SELECTDATA_AND_SORT

*---------------------------------------------------------------------*
* FORM MERGE_FIELDCATALOG *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form merge_fieldcatalog.
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name = syrepid
i_internal_tabname = 'ITAB1'
* i_structure_name = 'COLORSTRUCT'
* I_CLIENT_NEVER_DISPLAY = 'X'
i_inclname = syrepid
changing
ct_fieldcat = fieldcatalog[]
exceptions
inconsistent_interface = 1
program_error = 2
others = 3.
endform. " MERGE_FIELDCATALOG

* IN THIS FUNCTION THE MINIMUM PARAMETERS THAT WE NEED TO PASS IS AS
* FOLLOWS:-
* i_callback_program --> CALLING PROGRAM NAME
* i_structure_name --> STRUCTURE NAME.
* is_layout --> LAYOUT NAME.
* it_fieldcat ---> BODY OF THE FIELD CATALOGUE INTERNAL TABLE
form display_alv_list.
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
* I_INTERFACE_CHECK = ' '
i_callback_program = syrepid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
i_structure_name = 'ITAB1'
is_layout = fieldlayout
it_fieldcat = fieldcatalog[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* THE FOLLOWING PARAMETER IS SET AS 'A' INORDER TO DISPLAY THE STANDARD
* TOOL BAR
i_save = 'A'
* IS_VARIANT = ' '
it_events = eventstab[]
* IT_EVENT_EXIT =
* IS_PRINT =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
tables
t_outtab = itab1
exceptions
program_error = 1
others = 2.
endform. " DISPLAY_ALV_LIST
*&---------------------------------------------------------------------*
*& Form POPULATE_ITAB1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form populate_itab1.
loop at t_mara.
loop at t_makt where matnr = t_mara-matnr.
loop at t_marc where matnr = t_mara-matnr.
move-corresponding t_mara to itab1.
move-corresponding t_makt to itab1.
move-corresponding t_marc to itab1.
append itab1.
endloop.
endloop.
endloop.
endform. " POPULATE_ITAB1
*&---------------------------------------------------------------------*
*& Form FILL_EVENTSTAB
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_EVENTSTAB text *
*----------------------------------------------------------------------*
form fill_eventstab tables p_eventstab structure eventstab.
* WHEN THE FOLLOWING FUNCTION IS CALLED THE SYSTEM POPULATES THE
* INTERNAL TABLE EVENTSTAB WITH A LIST OF EVENTS NAME.
* AS SHOWN BELOW WHEN USING I_LIST_TYPE = 0 THE FUNCTION RETURNS 14
* EVENTS NAME.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = p_eventstab[]
exceptions
list_type_wrong = 1
others = 2.

* BY CALLING THE ABOVE FUNCTION WE FIRST POPULATE THE EVENTSTAB WITH
* THE PREDEFINED EVENTS AND THEN WE MOVE THE FORM NAME AS SHOWN BELOW.
* WE ASSIGN A FORM NAME TO THE EVENT AS REQUIRED BY THE USER.
* FORM NAME CAN BE ANYTHING.THE PERFORM STATEMENT FOR THIS FORM
* IS DYNAMICALY CALLED.

read table p_eventstab with key name = slis_ev_top_of_page.
if sy-subrc = 0 .
move 'TOP_OF_PAGE' to p_eventstab-form.
append p_eventstab.
endif.

read table p_eventstab with key name = slis_ev_top_of_coverpage.
if sy-subrc = 0 .
move 'TOP_OF_COVERPAGE' to p_eventstab-form.
append p_eventstab.
endif.

read table p_eventstab with key name = slis_ev_end_of_coverpage .
if sy-subrc = 0 .
move 'END_OF_COVERPAGE' to p_eventstab-form.
append p_eventstab.
endif.

read table p_eventstab with key name = slis_ev_foreign_top_of_page.
if sy-subrc = 0 .
move 'FOREIGN_TOP_OF_PAGE' to p_eventstab-form.
append p_eventstab.
endif.

read table p_eventstab with key name = slis_ev_foreign_end_of_page.
if sy-subrc = 0 .
move 'FOREIGN_END_OF_PAGE' to p_eventstab-form.
append p_eventstab.
endif.

read table p_eventstab with key name = slis_ev_list_modify.
if sy-subrc = 0 .
move 'LIST_MODIFY' to p_eventstab-form.
append p_eventstab.
endif.

read table p_eventstab with key name = slis_ev_top_of_list.
if sy-subrc = 0 .
move 'TOP_OF_LIST' to p_eventstab-form.
append p_eventstab.
endif.

read table p_eventstab with key name = slis_ev_end_of_page.
if sy-subrc = 0 .
move 'END_OF_PAGE' to p_eventstab-form.
append p_eventstab.
endif.

read table p_eventstab with key name = slis_ev_end_of_list .
if sy-subrc = 0 .
move 'END_OF_LIST' to p_eventstab-form.
append p_eventstab.
endif.
endform. " FILL_EVENTSTAB
*&---------------------------------------------------------------------*
*& Form FILL_HEADINGTABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_HEADING text *
*----------------------------------------------------------------------*
form fill_headingtable tables p_heading structure heading
using tablename.
case tablename.
when 'HEADING'.
p_heading-typ = 'H'.
concatenate
' REPORT NAME:-' syrepid
' ABB Industry Pte Ltd' into p_heading-info.
append p_heading.
write sy-datum using edit mask '__/__/____' to sydatum.

concatenate
' DATE:-' sydatum ' USER: ' sy-uname 'PAGE NO:' sypagno
into p_heading-info.
append p_heading.
when 'HEADING1'.
p_heading-typ = 'H'.
p_heading-info = 'TOP-OF-COVER-PAGE'.
append p_heading.
when 'HEADING2'.
p_heading-typ = 'H'.
p_heading-info = 'END-OF-COVER-PAGE'.
append p_heading.
when 'HEADING3'.
p_heading-typ = 'H'.
p_heading-info = 'FOREIGN-TOP-OF-PAGE'.
append p_heading.
when 'HEADING4'.
p_heading-typ = 'H'.
p_heading-info = 'FOREIGN-END-OF-PAGE'.
append p_heading.
* WHEN 'HEADING5'.
* P_HEADING-TYP = 'H'.
* P_HEADING-INFO = 'LIST-MODIFY'.
* APPEND P_HEADING.
when 'HEADING6'.
p_heading-typ = 'H'.
p_heading-info = 'END-OF-PAGE'.
append p_heading.
when 'HEADING7'.
p_heading-typ = 'H'.
p_heading-info = 'END-OF-LIST'.
append p_heading.
when 'HEADING8'.
p_heading-typ = 'H'.
p_heading-info = 'TOP-OF-LIST'.
append p_heading.
endcase.
endform. " FILL_HEADINGTABLE

*---------------------------------------------------------------------*
* FORM TOP_OF_PAGE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form top_of_page.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = heading[]
exceptions
others = 1.
endform.
*&---------------------------------------------------------------------*
*& Form FILL_COLORSTRUCT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_COLORSTRUCT text *
*----------------------------------------------------------------------*
form fill_colorstruct using p_colorstruct type slis_coltypes .
p_colorstruct-heacolfir-col = 6.
p_colorstruct-heacolfir-int = 1.
p_colorstruct-heacolfir-inv = 1.
endform. " FILL_COLORSTRUCT

*---------------------------------------------------------------------*
* FORM TOP_OF_COVERPAGE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form top_of_coverpage.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = heading1[]
exceptions
others = 1.
endform.

*---------------------------------------------------------------------*
* FORM END_OF_COVERPAGE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form end_of_coverpage.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = heading2[]
exceptions
others = 1.
endform.

*---------------------------------------------------------------------*
* FORM FOREIGN_TOP_OF_PAGE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form foreign_top_of_page.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = heading3[]
exceptions
others = 1.

endform.

*---------------------------------------------------------------------*
* FORM FOREIGN_END_OF_PAGE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form foreign_end_of_page.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = heading4[]
exceptions
others = 1.
endform.

*---------------------------------------------------------------------*
* FORM LIST_MODIFY *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
*FORM LIST_MODIFY.
* CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
* EXPORTING
* IT_LIST_COMMENTARY = HEADING5[]
* EXCEPTIONS
* OTHERS = 1.
*ENDFORM.

*---------------------------------------------------------------------*
* FORM END_OF_PAGE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form end_of_page.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = heading6[]
exceptions
others = 1.
endform.

*---------------------------------------------------------------------*
* FORM END_OF_LIST *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form end_of_list.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = heading7[]
exceptions
others = 1.
endform.

*---------------------------------------------------------------------*
* FORM TOP_OF_LIST *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form top_of_list.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = heading8[]
exceptions
others = 1.
endform.

*--- End of Program

what is abap REUSE_ALV_GRID_DISPLAY Functions Example

I am using "REUSE_ALV_GRID_DISPLAY" to display Report in ALV.
I have to show System Date and Time at the end of Report so I caught Event "END_OF_PAGE" in IT_EVENTS and modified IT_EVENTS field FORM with "F100_TOP_OF_PAGE", but I am not able to see the Date and Time in the END OF PAGE

I wrote follwoing ocde so please suggest me necessary changes

*&---------------------------------------------------------------------*
*& Form f100-end_of_page
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*

FORM f100-end_of_page.
clear: wa_listheader, it_end_listheader, it_end_listheader[].
concatenate 'Date' sy-datum into w_date separated by space.

wa_listheader-key = ''.
wa_listheader-typ = 'S'.
wa_listheader-info = 'Date'.

append wa_listheader to it_end_listheader.

clear: wa_listheader.

concatenate 'Time' sy-uzeit into w_date separated by space.

wa_listheader-key = ''.
wa_listheader-typ = 'S'.
wa_listheader-info = 'Time'.

append wa_listheader to it_end_listheader.

clear: wa_listheader.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = it_end_listheader[]
* I_LOGO =
* I_END_OF_LIST_GRID =
.

ENDFORM. " f100-end_of_page

-----------------------------------

In grid display there will be no end_of_page and no end_of_list.
You have show in top_of_page itself.
Otherwise use list display instead of grid.

Suresh Avutu

-----------------------------------

These steps have to be carried out...

DATA: gc_formname_top_of_page TYPE slis_formname
VALUE 'TOP_OF_PAGE'.
DATA: gc_formname_end_of_page TYPE slis_formname
VALUE 'END_OF_PAGE'.

DATA: gt_list_top_of_page TYPE slis_t_listheader.
DATA: gt_list_end_of_page TYPE slis_t_listheader.

------------------
PERFORM e03_eventtab_build USING gt_event[].
PERFORM e04_comment_build USING
gt_list_top_of_page[].
PERFORM e06_comment_build USING
gt_list_end_of_page[].
PERFORM list_alv_display.
-------------------------
FORM list_alv_display .

gt_event-name = slis_ev_top_of_list.
gt_event-form = 'TOP_OF_PAGE'.
APPEND gt_event.

gt_event-name = slis_ev_end_of_list.
gt_event-form = 'END_OF_PAGE'.
APPEND gt_event.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
i_bypassing_buffer = 'X'
i_buffer_active = ' '
i_callback_program = ....
---------------------------------------
FORM end_of_page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
i_logo = ''
it_list_commentary = gt_list_end_of_page
I_END_OF_LIST_GRID = 1.

ENDFORM. "END_OF_PAGE
------------------------------------------
FORM e06_comment_build
USING e06_lt_end_of_page TYPE slis_t_listheader.
DATA: ls_line TYPE slis_listheader.
DATA: yl_uname(60).

< here u can concatenate system date and time to
yl_uname>

CLEAR ls_line.
ls_line-typ = 'S'.
ls_line-info = yl_uname.
APPEND ls_line TO e06_lt_end_of_page.

endform. "e06_comment_build

Suman Tyagi



An Example:

REPORT ZALV_GRID.

TABLES :vbap.
type-pools : slis.
data i_events TYPE slis_t_event.
DATA : my_alv TYPE REF TO cl_gui_alv_grid.
TYPES : BEGIN OF itab,
vbeln LIKE vbap-vbeln,
arktx LIKE vbap-arktx,
END OF itab.
TYPES : itab1 TYPE TABLE OF itab.
DATA : display TYPE itab1.
DATA : fcat TYPE SLIS_T_FIELDCAT_ALV.
DATA : wa LIKE LINE OF FCAT.
DATA WA1 LIKE VBAP.
DATA: container TYPE REF TO cl_gui_custom_container.
data report_id like sy-repid.

SELECT-OPTIONS s_vbeln FOR vbap-vbeln.
report_id = sy-repid.

SELECT * FROM vbap INTO CORRESPONDING FIELDS OF TABLE display WHERE
vbeln IN s_vbeln.

wa-fieldname = 'VBELN'.
wa-tabname = 'VBAP'.
wa-key = 'X'.
WA-HOTSPOT = 'X'.
wa-text_fieldname = 'Doc no.'.
APPEND wa TO fcat.
CLEAR wa.
wa-fieldname = 'ARKTX'.
wa-tabname = 'VBAP'.
wa-text_fieldname = 'Item Text'.
APPEND wa TO fcat.

PERFORM f0650_build_event USING 'USER_COMMAND'
'F0750_USER_COMMAND'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY '
EXPORTING

I_CALLBACK_PROGRAM = report_id

IT_FIELDCAT = FCAT
IT_EVENTS = i_events
TABLES
t_outtab = DISPLAY
.

FORM f0650_build_event USING value(w_c_event_name)
value(w_c_event_form).

DATA: f0650_wa_event TYPE slis_alv_event.

CLEAR f0650_wa_event.
f0650_wa_event-name = w_c_event_name.
f0650_wa_event-form = w_c_event_form.
APPEND f0650_wa_event TO i_events.

ENDFORM.
FORM f0750_user_command USING w_ucomm TYPE sy-ucomm

w_selfield TYPE slis_selfield.

CASE w_ucomm.
WHEN '&IC1'.

READ TABLE DISPLAY INTO WA1 INDEX w_selfield-tabindex.
* MESSAGE E000 WITH
* ' You have no authorization to view the report'.
call transaction 'SE11'.

ENDCASE.
ENDFORM.

*** End of Program

Display a Secondary List using ALV Grid

To display a secondary list when you click on one of the row items in an alv grid. The secondary list should also be an alv.

Try out this code. You will have to make a structure ZSTR same as the output internal table.

REPORT ZTEST_REP1 .

TABLES : MARA,
BHDGD,
zstr.

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

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

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

* Internal table for fields catalouge
I_FIELDCAT TYPE LVC_T_FCAT WITH HEADER LINE,
* i_fieldcat2 type lvc_t_fcat with header line,

* Internal table for cursor position
I_GT_SELROWS TYPE LVC_T_ROW .

DATA : WA_MARA LIKE I_MARA,
WA_GRIDROW LIKE LVC_S_ROW,
WA_GRIDCOL LIKE LVC_S_COL.

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

* w_container1 type ref to cl_gui_custom_container,

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

*---------------------------------------------------------------------*
* Definition:
*---------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER DEFINITION.

PUBLIC SECTION.
METHODS:
HANDLE_TOP_OF_PAGE
FOR EVENT PRINT_TOP_OF_PAGE OF CL_GUI_ALV_GRID,
HANDLE_DOUBLE_CLICK
FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW E_COLUMN.
ENDCLASS.

*---------------------------------------------------------------------*
* CLASS LCL_EVENT_RECEIVER IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
METHOD HANDLE_TOP_OF_PAGE.
PERFORM F_GET_HEADER.
ENDMETHOD. "handle_top_of_page

METHOD HANDLE_DOUBLE_CLICK.

* The event DOUBLE_CLICK provides parameters for row and column
* of the click. We use row parameter to select a line of the
* corresponding internal table.

* read selected row from internal table
READ TABLE I_MARA INDEX E_ROW-INDEX INTO WA_MARA.
IF SY-SUBRC <> 0.
* message i001. " Cursor position not correct.
ELSE.
* call dialog screen and display the details
call screen 200 starting at 10 5.
ENDIF.

ENDMETHOD. "handle_double_click

ENDCLASS.

*-----------------------------------------------------------------------
* start-of-selection.
*-----------------------------------------------------------------------
START-OF-SELECTION.

SELECT MATNR ERNAM FROM MARA INTO TABLE I_MARA.

*----------------------------------------------------------------------
* End-of-Selection.
*----------------------------------------------------------------------
END-OF-SELECTION.

* Start of ALV part.
W_REPID = SY-REPID.
W_VARIANT-REPORT = W_REPID.
W_SAVE = C_SAVE.
W_CONT_MAIN = W_CONT_MAIN.
W_GS_LAYOUT = W_GS_LAYOUT.
W_GS_PRINT = W_GS_PRINT.
I_FIELDCAT = I_FIELDCAT.
CALL SCREEN 100.

*&---------------------------------------------------------------------*
*& Form f_get_header
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM F_GET_HEADER.

DATA: L_LINE1 LIKE BHDGD-LINE1,
L_LINE2 LIKE BHDGD-LINE2.
CONSTANTS LC_SPACE VALUE ' '.
DATA: L_F1(7), L_F2(11), L_F3(9), L_F4(6), L_F5(11), L_F6(4), L_F7(8),
L_F8(4),L_F9(10), L_F11(11), L_F12(24), L_F13(4),
L_F14(3).

* take the values of line1 and line2 into two new variables, otherwise
* after coming back to the first screen from the print preview, the
* header shows the condensed lines

L_LINE1 = BHDGD-LINE1.
L_LINE2 = BHDGD-LINE2.

CONDENSE L_LINE1.
CONDENSE L_LINE2.

*split the lines to display the whole lines within the
*stipulated report-width
SPLIT L_LINE1 AT LC_SPACE INTO L_F1 L_F2 L_F3 L_F4 L_F5 L_F6 L_F7 L_F8
L_F9 .

SPLIT L_LINE2 AT LC_SPACE INTO L_F11 L_F12 L_F13 L_F14.
L_F14 = SY-PAGNO.
WRITE:/1 L_F1, 9 L_F2, 40 L_F3, 50 L_F4, 57 L_F5, 88 L_F6, 93 L_F7 ,
103 L_F8 , 108 L_F9 .
WRITE:/1 L_F11, 40 TEXT-012, 78 L_F12, 103 L_F13, 108 L_F14.

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

ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM .
WHEN C_EXIT OR C_BACK OR C_CANC.
IF NOT W_CONTAINER IS INITIAL.
CALL METHOD W_CONTAINER->FREE.
ENDIF.

LEAVE TO SCREEN 0.

WHEN C_PGTOP.
WA_GRIDROW-INDEX = 1.

WHEN C_PGUP.
IF WA_GRIDROW-INDEX <= 15.
WA_GRIDROW-INDEX = 1.
ELSE.
WA_GRIDROW-INDEX = WA_GRIDROW-INDEX - 15.
ENDIF.

WHEN C_PGDN.
PERFORM F_GET_NO_ROWS.
W_TEMP_VAL = W_LN - WA_GRIDROW-INDEX.
IF W_TEMP_VAL < 15.
WA_GRIDROW-INDEX = W_LN.
ELSE.
WA_GRIDROW-INDEX = WA_GRIDROW-INDEX + 15.
ENDIF.

WHEN C_PGEND.
PERFORM F_GET_NO_ROWS.
WA_GRIDROW-INDEX = W_LN.

ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form f_get_no_rows
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM F_GET_NO_ROWS.

DESCRIBE TABLE I_MARA LINES W_LN.

ENDFORM. " f_get_no_rows
*&---------------------------------------------------------------------*
*& Module DISPLAY_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE DISPLAY_0100 OUTPUT.

IF NOT WA_GRIDROW IS INITIAL
AND NOT WA_GRIDCOL IS INITIAL.

CALL METHOD W_GRID->SET_SCROLL_INFO_VIA_ID
EXPORTING
IS_ROW_INFO = WA_GRIDROW
IS_COL_INFO = WA_GRIDCOL .

CALL METHOD W_GRID->SET_CURRENT_CELL_VIA_ID
EXPORTING
IS_ROW_ID = WA_GRIDROW
IS_COLUMN_ID = WA_GRIDCOL .

ENDIF.

CALL METHOD W_GRID->GET_SCROLL_INFO_VIA_ID
IMPORTING
ES_ROW_INFO = WA_GRIDROW
ES_COL_INFO = WA_GRIDCOL .

CALL METHOD W_GRID->GET_SELECTED_ROWS
IMPORTING
ET_INDEX_ROWS = I_GT_SELROWS[].

* Build the fieldcat according to structure
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'ZSTR'
CHANGING
CT_FIELDCAT = I_FIELDCAT[].

LOOP AT I_FIELDCAT.
W_INDEX = SY-TABIX.
CASE I_FIELDCAT-FIELDNAME.

WHEN 'MATNR'.
I_FIELDCAT-SCRTEXT_S = 'MATNR'.
I_FIELDCAT-KEY = ' '.
I_FIELDCAT-COL_POS = '1'.

WHEN 'ERNAM'.
I_FIELDCAT-SCRTEXT_S = 'ERDAT'.
I_FIELDCAT-OUTPUTLEN = '18'.
I_FIELDCAT-COL_POS = '2'.

ENDCASE.
MODIFY I_FIELDCAT INDEX W_INDEX.

ENDLOOP.

READ TABLE I_FIELDCAT INDEX 1 .

IF W_CALL = 1.

PERFORM F_STD_HEADER.

CALL METHOD W_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_VARIANT = W_VARIANT
I_SAVE = W_SAVE
CHANGING
IT_OUTTAB = I_MARA[]
IT_FIELDCATALOG = I_FIELDCAT[]
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
OTHERS = 3.

IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
EXIT.
ENDIF.

CREATE OBJECT W_EVENT_REC.
SET HANDLER W_EVENT_REC->HANDLE_TOP_OF_PAGE FOR W_GRID.
CREATE OBJECT W_EVENT_REC.
SET HANDLER W_EVENT_REC->HANDLE_DOUBLE_CLICK FOR W_GRID.
W_FLAG = C_RESET.

CALL METHOD CL_GUI_CONTROL=>SET_FOCUS EXPORTING CONTROL = W_GRID.
W_CALL = 0.
ENDIF.

ENDMODULE. " DISPLAY_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Form f_std_header
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM F_STD_HEADER.

ENDFORM. " f_std_header
*&---------------------------------------------------------------------*
*& Module DYNPRONR_CHECK_500 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE DYNPRONR_CHECK_500 OUTPUT.
* if w_dynpronr is initial.
* w_dynpronr = '0100'.
* endif.

ENDMODULE. " DYNPRONR_CHECK_500 OUTPUT
*&---------------------------------------------------------------------*
*& Module create_objects_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE create_objects_0100 OUTPUT.
check w_container is initial .
create object w_container
exporting
container_name = 'CC'.
create object w_grid
exporting
i_parent = w_container.
w_flag = c_set.
w_flag = w_flag.
ENDMODULE. " create_objects_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0200 OUTPUT.
SET PF-STATUS 'ST20'.
SET TITLEBAR '200'.
zstr-matnr = wa_mara-matnr.
zstr-ernam = wa_mara-ernam.

ENDMODULE. " STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0200 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0200 INPUT.
move ok_code to w_ok_code.
clear ok_code.
case w_ok_code.
when c_back or c_exit or c_canc.
leave to screen 0.
endcase.
clear w_ok_code.
ENDMODULE. " USER_COMMAND_0200 INPUT

*-- End of Program

sap abap program for Line Color in ALV Example

An example of using linecolor (ALV).

Here you have a good example of coloring rows, columns and specific cells in alvs. It comes in an example of how to use hashed tables.

For coloured rows and cols check gp_bymat
for coloured specific rows uncheck gp_bymat.
HTH.
Horacio
ps: code:
report zuseofhashedtables.
************************************************************************
** Program: ZUseOfHashedTables **
************************************************************************
** Author: Horacio Zapettini **
** **
** Versions: 4.6b - 4.6c **
************************************************************************
** Notes: **
** this program shows how we can use hashed tables to improve **
** the responce time. **
** It shows, **
** 1. how to declare hashed tables **
** 2. a cache-like technique to improve access to master data **
** 3. how to collect data using hashed tables **
** 4. how to avoid deletions of unwanted data **
************************************************************************
** Results: the test we run read about 31000 rows from mkpf, 150000 **
** rows from mseg, 500 rows from makt and 400 from lfa1. **
** it filled ht_lst with 24500 rows and displayed them in **
** alv grid format. **
** **
** It took about 65 secodns to perform this task (first time **
** we run it when all the db buffers are empty. **
** **
** The same program with standard tables needed 140 seconds **
** to run with the same recordset and with buffers filled in **
** **
** A simmilar test over more than a million rows
************************************************************************
** Objetive: show a list that consists of all the material movements **
** '101' - '901' for a certain range of dates in mkpf-budat. **
** the columns to be displayed are: **
** mkpf-budat, **
** mkpf-mblnr, **
** mseg-lifnr, **
** lfa1-name1, **
** mkpf-xblnr, **
** mseg-zeile **
** mseg-charg, **
** mseg-matnr, **
** makt-maktx, **
** mseg-erfmg, **
** mseg-erfme. **
** or show a sumary list by matnr - menge **
** **
** You'll have to create a pf-status called vista - **
** See form set_pf_status for details **
************************************************************************

** tables used -
tables: mkpf,
mseg,
lfa1,
makt.

** global hashed tables used
*
data: begin of wa_mkpf, "header
mblnr like mkpf-mblnr,
mjahr like mkpf-mjahr,
budat like mkpf-budat,
xblnr like mkpf-xblnr,
end of wa_mkpf.
data: ht_mkpf like hashed table of wa_mkpf
with unique key mblnr mjahr
with header line.
data: st_mkpf like standard table of wa_mkpf
with header line.

*
data: begin of wa_mseg, " line items
mblnr like mseg-mblnr,
mjahr like mseg-mjahr,
zeile like mseg-zeile,
bwart like mseg-bwart,
charg like mseg-charg,
matnr like mseg-matnr,
lifnr like mseg-lifnr,
erfmg like mseg-erfmg,
erfme like mseg-erfme,
end of wa_mseg.
data ht_mseg like hashed table of wa_mseg
with unique key mblnr mjahr zeile
with header line.
data st_mseg like standard table of wa_mseg
with header line.


** cache structure for lfa1 records
data: begin of wa_lfa1,
lifnr like lfa1-lifnr,
name1 like lfa1-name1,
end of wa_lfa1.
data ht_lfa1 like hashed table of wa_lfa1
with unique key lifnr
with header line.

** cache structure for material related data
data: begin of wa_material,
matnr like makt-matnr,
maktx like makt-maktx,
end of wa_material.
data: ht_material like hashed table of wa_material
with unique key matnr
with header line.

** result table
data: begin of wa_lst, "
budat like mkpf-budat,
mblnr like mseg-mblnr,
lifnr like mseg-lifnr,
name1 like lfa1-name1,
xblnr like mkpf-xblnr,
zeile like mseg-zeile,
charg like mseg-charg,
matnr like mseg-matnr,
maktx like makt-maktx,
erfmg like mseg-erfmg,
erfme like mseg-erfme,
mjahr like mseg-mjahr,
end of wa_lst.

data: ht_lst like hashed table of wa_lst
with unique key mblnr mjahr zeile
with header line.

data: begin of wa_lst1, " sumary by material
matnr like mseg-matnr,
maktx like makt-maktx,
erfmg like mseg-erfmg,
erfme like mseg-erfme,
color_line(4) TYPE c, " Line color
color_cell TYPE lvc_t_scol, " Cell color
celltab type LVC_T_STYL,
end of wa_lst1.

data: ht_lst1 like hashed table of wa_lst1
with unique key matnr
with header line.

** structures for alv grid display.
** itabs
type-pools: slis.

data: it_lst like standard table of wa_lst with header line,
it_fieldcat_lst type slis_t_fieldcat_alv with header line,
it_sort_lst type slis_t_sortinfo_alv,
it_lst1 like standard table of wa_lst1 with header line,
it_fieldcat_lst1 type slis_t_fieldcat_alv with header line,
it_sort_lst1 type slis_t_sortinfo_alv.
** structures
data: wa_sort type slis_sortinfo_alv,
ls_layout type slis_layout_alv.
** color management.
DATA : wa_color TYPE lvc_s_scol.
* Internal table for color management.
DATA : it_color TYPE TABLE OF lvc_s_scol.

* itab for input enabling.
DATA: lt_celltab TYPE lvc_t_styl. "


** global varialbes

data: g_lines type i.

data: g_repid like sy-repid,
ok_code like sy-ucomm.

** selection-screen

"text: Dates:
select-options: so_budat for mkpf-budat default sy-datum.
"text: Material numbers.
select-options: so_matnr for mseg-matnr.
selection-screen uline.
selection-screen skip 1.
"Text: show summary by material.
parameters: gp_bymat as checkbox default ''.
parameters: gp_hier as checkbox default 'X'.
start-of-selection.
perform get_data.
perform show_data.

end-of-selection.


*---------------------------------------------------------------------*
* FORM get_data *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form get_data.
select mblnr mjahr budat xblnr
into table ht_mkpf
from mkpf
where budat in so_budat. " make use of std index.
** have we retrieved data from mkpf?
describe table ht_mkpf lines g_lines.
if g_lines > 0.
** if true then retrieve all related records from mseg.
** Doing this way we make sure that the access is by primary key
** of mseg.
** The reason is that is faster to filter them in memory
** than to allow the db server to do it.
select mblnr mjahr zeile bwart charg
matnr lifnr erfmg erfme
into table ht_mseg
from mseg
for all entries in ht_mkpf
where mblnr = ht_mkpf-mblnr
and mjahr = ht_mkpf-mjahr.
endif.

** fill t_lst or t_lst1 according to user's choice.
if gp_bymat = ' '.
perform fill_ht_lst.
else.
perform fill_ht_lst1.
endif.
endform.

form fill_ht_lst.
refresh ht_lst.
** Example: how to discard unwanted data in an efficient way.
loop at ht_mseg.
* filter unwanted data
check ht_mseg-bwart = '101' or ht_mseg-bwart = '901'.
check ht_mseg-matnr in so_matnr.
* read header line.
read table ht_mkpf with table key mblnr = ht_mseg-mblnr
mjahr = ht_mseg-mjahr.
clear ht_lst.
* * note : this may be faster if you specify field by field.
move-corresponding ht_mkpf to ht_lst.
move-corresponding ht_mseg to ht_lst.

perform read_lfa1 using ht_mseg-lifnr changing ht_lst-name1.
perform read_material using ht_mseg-matnr changing ht_lst-maktx.
insert table ht_lst.
endloop.
endform.

form fill_ht_lst1.
data: colorear.
refresh ht_lst1.
** Example: how to discard unwanted data in an efficient way.
** hot to simulate a collect in a faster way
loop at ht_mseg.
* filter unwanted data
check ht_mseg-bwart = '101' or ht_mseg-bwart = '901'.
check ht_mseg-matnr in so_matnr.
* * note : this may be faster if you specify field by field.

read table ht_lst1 with table key matnr = ht_mseg-matnr
transporting erfmg.
if sy-subrc <> 0. " if matnr doesn't exist in sumary table
" insert a new record
clear ht_lst1.
ht_lst1-matnr = ht_mseg-matnr.
perform read_material using ht_mseg-matnr changing ht_lst1-maktx.
ht_lst1-erfmg = ht_mseg-erfmg.
ht_lst1-erfme = ht_mseg-erfme.
if colorear = ''.
colorear = 'X'.
refresh it_color.
ht_lst1-color_cell[] = it_color[].
MOVE 'C410' TO ht_lst1-color_line.
else.
colorear = ' '.
refresh it_color. clear it_color.
MOVE 'MATNR' TO wa_color-fname.
MOVE '6' TO wa_color-color-col.
MOVE '1' TO wa_color-color-int.
MOVE '1' TO wa_color-color-inv.
APPEND wa_color TO it_color.
MOVE 'MAKTX' TO wa_color-fname.
MOVE '3' TO wa_color-color-col.
MOVE '1' TO wa_color-color-int.
MOVE '1' TO wa_color-color-inv.
APPEND wa_color TO it_color.

MOVE 'ERFMG' TO wa_color-fname.
MOVE '5' TO wa_color-color-col.
MOVE '1' TO wa_color-color-int.
MOVE '1' TO wa_color-color-inv.

APPEND wa_color TO it_color.
ht_lst1-color_cell[] = it_color[].

clear ht_lst1-color_line.

endif.

insert table ht_lst1.
else." a record was found.
" collect erfmg. To do so, fill in the unique key and add
" the numeric fields.
ht_lst1-matnr = ht_mseg-matnr.
add ht_mseg-erfmg to ht_lst1-erfmg.
modify table ht_lst1 transporting erfmg.
endif.
endloop.
endform.

** implementation of cache for lfa1.
form read_lfa1 using p_lifnr changing p_name1.
read table ht_lfa1 with table key lifnr = p_lifnr
transporting name1.
if sy-subrc <> 0.
clear ht_lfa1.
ht_lfa1-lifnr = p_lifnr.
select single name1
into ht_lfa1-name1
from lfa1
where lifnr = p_lifnr.
if sy-subrc <> 0. ht_lfa1-name1 = 'n/a in lfa1'. endif.
insert table ht_lfa1.
endif.
p_name1 = ht_lfa1-name1.
endform.

** implementation of cache for material data
form read_material using p_matnr changing p_maktx.
read table ht_material with table key matnr = p_matnr
transporting maktx.
if sy-subrc <> 0.
ht_material-matnr = p_matnr.
select single maktx into ht_material-maktx
from makt
where spras = sy-langu
and matnr = p_matnr.
if sy-subrc <> 0. ht_material-maktx = 'n/a in makt'. endif.
insert table ht_material.
endif.
p_maktx = ht_material-maktx.
endform.
form show_data.
if gp_hier = 'X'. "no anda.
* perform show_hierarchicalALV.
else.
if gp_bymat = ' '.
perform show_ht_lst.
else.
perform show_ht_lst1.
endif.
endif.
endform.
form show_hierarchicalALV.
st_mkpf[] = ht_mkpf[].
st_mseg[] = ht_mseg[].
call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
* exporting
* I_INTERFACE_CHECK = ' '
* I_CALLBACK_PROGRAM =
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* IS_LAYOUT =
* IT_FIELDCAT =
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* i_tabname_header =
* i_tabname_item =
* I_STRUCTURE_NAME_HEADER =
* I_STRUCTURE_NAME_ITEM =
* is_keyinfo =
* IS_PRINT =
* IS_REPREP_ID =
* I_BUFFER_ACTIVE =
* I_BYPASSING_BUFFER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
tables
t_outtab_header = st_mkpf
t_outtab_item = st_mseg
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.

endform.
form show_ht_lst.
"needed because the FM can't use a hashed table.
it_lst[] = ht_lst[].

perform fill_layout using 'full display'
changing ls_layout.

perform fill_columns_lst.
* perform sort_lst.
g_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = g_repid
i_callback_pf_status_set = 'SET_PF_STATUS'
is_layout = ls_layout
it_fieldcat = it_fieldcat_lst[]
* it_sort = it_sort_lst
tables
t_outtab = it_lst
exceptions
program_error = 1
others = 2.

endform.
form show_ht_lst1.
"needed because the FM can't use a hashed table.
it_lst1[] = ht_lst1[].

perform fill_layout using 'Sumary by matnr'
changing ls_layout.

perform fill_columns_lst1.
* perform sort_lst.
g_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = g_repid
i_callback_pf_status_set = 'SET_PF_STATUS'
is_layout = ls_layout
it_fieldcat = it_fieldcat_lst1[]
* it_sort = it_sort_lst
tables
t_outtab = it_lst1
exceptions
program_error = 1
others = 2.

endform.

form fill_layout using p_window_titlebar
changing cs_layo type slis_layout_alv.
clear cs_layo.
cs_layo-window_titlebar = p_window_titlebar.
cs_layo-edit = 'X'.
cs_layo-edit_mode = space.
MOVE 'COLOR_LINE' TO cs_layo-info_fieldname.

* Field that identify cell color in inetrnal table
MOVE 'COLOR_CELL' TO cs_layo-coltab_fieldname.
* move 'CELLTAB' TO cs_layo-stylefname.


endform. " armar_layout_stock

form set_pf_status using rt_extab type slis_t_extab.
** create a new status
** and then select extras -> adjust template -> listviewer
set pf-status 'VISTA'.
endform. "set_pf_status
define add_lst.
clear it_fieldcat_lst.
it_fieldcat_lst-fieldname = &1.
it_fieldcat_lst-outputlen = &2.
it_fieldcat_lst-ddictxt = 'L'.
it_fieldcat_lst-seltext_l = &1.
it_fieldcat_lst-seltext_m = &1.
it_fieldcat_lst-seltext_m = &1.
if &1 = 'MATNR'.
it_fieldcat_lst-emphasize = 'C111'.
endif.
append it_fieldcat_lst.
end-of-definition.
define add_lst1.
clear it_fieldcat_lst.
it_fieldcat_lst1-fieldname = &1.
it_fieldcat_lst1-outputlen = &2.
it_fieldcat_lst1-ddictxt = 'L'.
it_fieldcat_lst1-seltext_l = &1.
it_fieldcat_lst1-seltext_m = &1.
it_fieldcat_lst1-seltext_m = &1.
append it_fieldcat_lst1.
end-of-definition.

form fill_columns_lst.
* set columns for output.

refresh it_fieldcat_lst.
*
add_lst 'BUDAT' 10.
add_lst 'MBLNR' 10.
add_lst 'LIFNR' 10.
add_lst 'NAME1' 35.
add_lst 'XBLNR' 15.
add_lst 'ZEILE' 5.
add_lst 'CHARG' 10.
add_lst 'MATNR' 18.
add_lst 'MAKTX' 30.
add_lst 'ERFMG' 17.
add_lst 'ERFME' 5.
add_lst 'MJAHR' 4.
endform.
form fill_columns_lst1.
* set columns for output.

refresh it_fieldcat_lst1.

add_lst1 'MATNR' 18.
add_lst1 'MAKTX' 30.
add_lst1 'ERFMG' 17.
add_lst1 'ERFME' 5..
endform.

Horacio Zapettini

--------------------------------
Program to Calculate FI Opening Balance

How to find the Opening balance for a given period in FI Module for a Particular GL A/c.


I was calculated opening balance, code is below maybe it will be helpful.

*find period.
CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
EXPORTING
i_date = s_budat-low
i_periv = i_tab-periv "'K4'
IMPORTING
e_buper = v_donem
e_gjahr = v_gjahr
EXCEPTIONS
input_false = 1
t009_notfound = 2
t009b_notfound = 3
OTHERS = 4.
*calc opening balance hesabý
SELECT * FROM knc1 WHERE kunnr = i_tab-kunnr
AND bukrs = i_tab-bukrs " s_bukrs
AND gjahr EQ v_gjahr.

v_dnm = v_donem.
* opening balance first calc > old year ,
WHILE v_dnm > 1.
v_dnm = v_dnm - 1.
CONCATENATE 'knc1-um' v_dnm 's' INTO v_field_name_borc.
CONCATENATE 'knc1-um' v_dnm 'h' INTO v_field_name_alacak.
ASSIGN (v_field_name_borc) TO .
ASSIGN (v_field_name_alacak) TO .
i_tab-dmbtr_s = i_tab-dmbtr_s + ( ). " borc
i_tab-dmbtr_h = i_tab-dmbtr_h + ( ). " borc
ENDWHILE.

*opening balance last calc> old
* add days which is from selected date-low month
IF v_donem > 1.
v_dnm = v_donem - 1.
ELSE.
v_dnm = v_donem.
ENDIF.

SELECT SINGLE * FROM t009b WHERE periv = i_tab-periv "'K4'
AND bdatj = s_budat-low+0(4)
AND poper = v_dnm.

t009b-butag = t009b-butag + 1.
IF s_budat-low+6(2) NE t009b-butag.
v_date_high = s_budat-low - 1.
IF v_donem = 1.
v_date_low = s_budat-low.
v_date_low+4(4) = '0101'.
ELSE.
CONCATENATE t009b-bdatj t009b-bumon t009b-butag INTO
v_date_low.
ENDIF.
SELECT * FROM bsad WHERE bukrs EQ i_tab-bukrs "IN s_bukrs
AND kunnr = i_tab-kunnr
AND budat BETWEEN v_date_low AND
v_date_high
AND umskz = space
AND blart IN s_blart.

IF bsad-shkzg = 'S'.
i_tab-dmbtr_s = i_tab-dmbtr_s + ( bsad-dmbtr ).
ELSEIF bsad-shkzg = 'H'.
i_tab-dmbtr_h = i_tab-dmbtr_h + ( bsad-dmbtr ).
ENDIF.
ENDSELECT.
SELECT * FROM bsid WHERE bukrs EQ i_tab-bukrs "IN s_bukrs
AND kunnr = i_tab-kunnr
AND budat BETWEEN v_date_low AND
v_date_high
AND umskz = space
AND blart IN s_blart.
* AND gsber IN gsber.
IF bsid-shkzg = 'S'.
i_tab-dmbtr_s = i_tab-dmbtr_s + ( bsid-dmbtr ).
ELSEIF bsid-shkzg = 'H'.
i_tab-dmbtr_h = i_tab-dmbtr_h + ( bsid-dmbtr ).
ENDIF.
ENDSELECT.
ENDIF.
"opening balance ( þirket bazlý )z1 degeri
i_tab-z1 = i_tab-z1 + ( knc1-umsav + i_tab-dmbtr_s - i_tab-dmbtr_h ).
* for israel
i_tab-dmbtril_s = i_tab-dmbtr_s .
i_tab-dmbtril_h = i_tab-dmbtr_h .
ENDSELECT.

Archives