ALV Report in SAP ABAP
SAP ALV (ABAP LIST VIEWERS)
ALV is used to display the output with predefined functionalities. Such as
1. Sort the list in ascending order
2. Sort the list in descending order
3. Totals
4. Filtering
5. Down the list
6. Send as attachment
7. Word processing
8. Excel sheet
9. Change the layout
10. Graphics
11. Print previews.
SAP AVL is introduced from 4.6C version onwards. ALV is used to display the data from internal table only.
Steps to work with ALV Report: -
1. Declare the final data internal table (which data we want to display) and implement the retrieving logic.
2. Prepare the field catalog (about the display fields) i.e.
1. Filed name
2. Column position
3. Column Heading
4. Colour
5. Hotspot……..
3. Call the ‘REUSE_ALV_GRID_DISPLAY’ function module.
(OR)
CALL THE ‘RESUE_ALV_LIST_DISPLAY’ function module.
Note: – REUSE_ALV_GIRD_DISPLAY is the function module which is used to
display the output in a grid format.
REUSE_ALV_LIST_DISPLAY is the function module which is used to display the output in a list format.
The input for the above two functions modules are two internal tables.
1. Data internal table
2. Field Catalog internal table
FILLING THE FIELD CATALOG
If we are working with all the fields from any data base table/structure then we no need to prepare the fields catalog. We simply pass the database name /structure name as i_structure_name.
Manually filling the field catalog
REUSE_ALV_FIELDCATALOG_MERGE function
Some of the fields in field catalog internal table: -
1. Field name -> Name of the displayed field
2. Col_Pos -> Column position
3. Seltext_S
Seltext_M Column heading
Seltext_L
4. Emphasize -> Colour
5. Output length -> Length of the output field
6. Hotspot -> Hand Symbol
7. Edit -> Change mode
8. No-zero -> Remove the leading zeros
9. No-sign -> Remove the leading sign
10. No-out -> Hide the display field
11. Do-sum -> Calculate the total
12. Checkbox -> Checkbox
Note: – In slis, we have one type i.e. SLIS_T_FIELDCAT_ALV which contains all the fields related to
field catalog internal table. So we simply declare our internal table by referring this.
Slis is the type group which contains all the types related to ALV in SAP ABAP.
Note: – When ever we are referring any type under any type group then we must include the type group
name by using “type-pools” keyword.
Object: Display the all sales documents header details by using ALV Report.
*Declare final data internal table
Data IT_VBAK like table of VBAK.
*Filling the data internal table.
Select * from VBAK into table IT_VBAK.
*Display output
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
I_STRUCTURE_NAME = ‘VBAK’
TABLES
T_OUTTAB = IT_VBAK.
Note: – Here the function module picks the column headings from the data element of each field in the table
and also display the fields in the similar order of the fields in the table.
Object: Based on the given purchasing document number to display the purchasing document numbers, document dates and vendor numbers by using ALV Report and also display the purchasing document number with green color, document date with hotspot.
Type-pools slis.
TABLES EKKO.
SELECT-OPTIONS S_EBELN FOR EKKO-EBELN.
* Declare the data internal table.
Types: Begin of ty_ekko,
Ebeln type ekko-ebeln,
Bedat type ekko-bedat,
Lifnr type ekko-lifnr,
End of ty_ekko.
Data it_ekko type table of ty_ekko.
* Filling the data internal table.
Select ebeln Bedat lifnr from ekko into table it_ekko where ebeln in s_ebeln.
* Declaring the field catalog.
Data: it_fcat type SLIS_T_FIELDCAT_ALV,
Wa_fcat like line of it_fcat.
* Filling the field catalog
WA_FCAT-FIELDNAME = ‘EBELN’.
WA_FCAT-COL_POS = ‘1’.
WA_FCAT-SELTEXT_M = ‘PUR.DOC’.
WA_FCAT-EMPHASIZE = ‘C510’.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-FIELDNAME = ‘BEDAT’.
WA_FCAT-COL_POS = ‘2’.
WA_FCAT-SELTEXT_M = ‘DOC.DT’.
WA_FCAT-HOTSPOT = ‘X’.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-FIELDNAME = ‘LIFNR’.
WA_FCAT-COL_POS = ‘3’.
WA_FCAT-SELTEXT_M = ‘VENDOR’.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
* Display the output
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
It_fieldcat = it_fcat
TABLES
T_outtab = it_ekko.
Object : Based on the given company codes to display the company codes,company
names, customer numbers and recon account by using ALV report in SAP ABAP. And also display the
company codes with yellow color and customer numbers with
blue color and hide the Recon account.
REPORT ZBBST_SWIN_O_ALV1.
TYPE-POOLS SLIS.
TABLES T001.
SELECT-OPTIONS S_BUKRS FOR T001-BUKRS.
*Declare the data internal table
TYPES : BEGIN OF TY_FINAL,
BUKRS TYPE T001-BUKRS,
BUTXT TYPE T001-BUTXT,
KUNNR TYPE KNB1-KUNNR,
AKONT TYPE KNB1-AKONT,
END OF TY_FINAL.
DATA IT_FINAL TYPE TABLE OF TY_FINAL.
*Filling the data internal table
SELECT T001~BUKRS T001~BUTXT KNB1~KUNNR KNB1~AKONT
INTO TABLE IT_FINAL FROM T001 INNER JOIN KNB1 ON
T001~BUKRS = KNB1~BUKRS WHERE T001~BUKRS IN S_BUKRS.
*Declare the fieldcatalog
DATA : IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FCAT LIKE LINE OF IT_FCAT.
*Filling the fieldcat
WA_FCAT-FIELDNAME = ‘BUKRS’.
WA_FCAT-COL_POS = ‘1’.
WA_FCAT-SELTEXT_M = ‘Cocd’.
WA_FCAT-EMPHASIZE = ‘C310’.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-FIELDNAME = ‘BUTXT’.
WA_FCAT-COL_POS = ‘2’.
WA_FCAT-SELTEXT_M = ‘Company name’.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-FIELDNAME = ‘KUNNR’.
WA_FCAT-COL_POS = ‘3’.
WA_FCAT-SELTEXT_M = ‘Customer’.
WA_FCAT-EMPHASIZE = ‘C410’.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-FIELDNAME = ‘AKONT’.
WA_FCAT-COL_POS = ‘4’.
WA_FCAT-SELTEXT_M = ‘Recon acc’.
WA_FCAT-NO_OUT = ‘X’.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
*Display the output
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
IT_FIELDCAT = IT_FCAT
TABLES
T_OUTTAB = IT_FINAL.
Some of the fields in layout work area:
1.Colwidth_optimize –>Compress the displayed fields(Active = ‘X’) 2.Zebra ————– >Alternative color(Active = ‘X’)
3.Info_fieldname —– >Color field
Note : In SLIS,we have one type i.e SLIS_LAYOUT_ALV which contains above fiels, so we declare our layout workarea by refering SLIS_LAYOUT_ALV.
Steps to work with row colour: –
1. Declare the one additional colour field in the data IT, which is char and length 4.
2. Fill the data IT based on given input.
3. Modify the colour field based on the requirement.
4. Pass the colour field name into layout WA (info_field name).
5. Fill the field catalog (not colour field)
6. Display output
Object: Based on the given sales document nos,to display the sales document numbers, item numbers, quantity, unit of measurement, net value by using ALV in SAP ABAP & also display the line item details in red colour if the netvalue is above 12000.
REPORT ZBB_SSW_M_ALV3. TYPE-POOLS SLIS.
TABLES VBAP.
SELECT-OPTIONS S_VBELN FOR VBAP-VBELN.
*Declare one additional color field in the data internal table
TYPES : BEGIN OF TY_VBAP,
VBELN TYPE VBAP-VBELN, POSNR TYPE VBAP-POSNR, KWMENG TYPE VBAP-KWMENG, MEINS TYPE VBAP-MEINS, NETWR TYPE VBAP-NETWR, COL(4) TYPE C,
END OF TY_VBAP.
DATA WA_VBAP TYPE TY_VBAP.
DATA IT_VBAP TYPE TABLE OF TY_VBAP.
*Filling the data internal table based on given input
SELECT VBELN POSNR KWMENG MEINS NETWR FROM VBAP INTO TABLE IT_VBAP WHERE VBELN IN S_VBELN.
*Modify the color field WA_VBAP-COL = ‘C610’.
MODIFY IT_VBAP FROM WA_VBAP TRANSPORTING COL WHERE NETWR > 12000.
*Declare the layout workarea
DATA WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
*Pass the color fieldname into layout workarea WA_LAYOUT-INFO_FIELDNAME = ‘COL’.
*for compress
WA_LAYOUT-COLWIDTH_OPTIMIZE = ‘X’.
*for alternative color WA_LAYOUT-ZEBRA = ‘X’.
*Declare the fieldcatalog internal table
DATA IT_FCAT TYPE SLIS_T_FIELDCAT_ALV. DATA WA_FCAT LIKE LINE OF IT_FCAT.
*Filling the fieldcatalog
WA_FCAT-FIELDNAME = ‘VBELN’. WA_FCAT-COL_POS = ‘1’.
WA_FCAT-SELTEXT_M = ‘Sales.doc’. WA_FCAT-NO_ZERO = ‘X’.
APPEND WA_FCAT TO IT_FCAT. CLEAR WA_FCAT.
WA_FCAT-FIELDNAME = ‘POSNR’. WA_FCAT-COL_POS = ‘2’.
WA_FCAT-SELTEXT_M = ‘Item’. APPEND WA_FCAT TO IT_FCAT. CLEAR WA_FCAT.
WA_FCAT-FIELDNAME = ‘KWMENG’. WA_FCAT-COL_POS = ‘3’.
WA_FCAT-SELTEXT_M = ‘Quantity’. APPEND WA_FCAT TO IT_FCAT. CLEAR WA_FCAT.
WA_FCAT-FIELDNAME = ‘MEINS’. WA_FCAT-COL_POS = ‘4’.
WA_FCAT-SELTEXT_M = ‘Uom’. APPEND WA_FCAT TO IT_FCAT. CLEAR WA_FCAT.
WA_FCAT-FIELDNAME = ‘NETWR’. WA_FCAT-COL_POS = ‘5’.
WA_FCAT-SELTEXT_M = ‘Net value’. WA_FCAT-DO_SUM = ‘X’.
APPEND WA_FCAT TO IT_FCAT. CLEAR WA_FCAT.
*Display the output
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’ EXPORTING
IS_LAYOUT = WA_LAYOUT IT_FIELDCAT = IT_FCAT TABLES
t_outtab = IT_VBAP.
EVENTS IN ALV REPORT IN SAP ABAP
In ALV, events are handle through ‘sub-routines’ (form, endform)
1. Top_of_page
2. Top_of_list
3. End_of_page
4. End_of_list
5. User_command
6. Pf_status_set
Top_of_page: –
It’s an event which is triggered at the top of each page.
Top_of_list: –
It’s an event which is triggered at the top of displayed output list.
End_of_page: –
It’s an event which is triggered at the end of each page.
End_of_list: –
It’s an event which is triggered at the end of displayed output list.
User_command: –
It’s an event which is triggered at the time of user clicks on any record of any list as well as any menu item.
This event acts like both at line-selection & at user-command.
Pf_status_set: –
It’s an event which is triggered at the time of attaching our GUI to the program.
When ever we are working with events then we must declare an event internal table which contains 2 fields.
Note: – In slis we have one type I.e. slis_t_event which contains the above fields. So we simply declare the internal table by referring slis_t_event.
Blocked ALV:
Blocked ALV is used to display the output in a block wise.
Steps to work with blocked ALV:
1. Initialize the blocked alv by using ‘REUSE_ALV_BLOCK_LIST_INIT’ Function module The input for the above function module is current program name (sy-cprog)
2. Attach the each data internal table to the blocked alv by using ‘REUSE_ALV_BLOCK_LIST_APPEND’ Function module The input for the above function module is
(i) Data internal table (ii)Fieldcatalog internal table
(iii)Event internal table(Empty also ok) (iv)Layout workarea(Empty also ok)
Repeat the same step 2 For each data internal table
3. Display the output by using ‘REUSE_ALV_BLOCK_LIST_DISPLAY’ Function module.
Object : Based on the given Purchase document numbers to display the purchase document header details (EBELN,BEDAT,LIFNR) and sales document item details (EBELN, EBELP,MENGE, MEINS,NETPR) By using blocked alv.
REPORT ZBBST_M_ALV5.
TYPE-POOLS SLIS.
TABLES EKKO.
SELECT-OPTIONS S_EBELN FOR EKKO-EBELN.
*Declare the data internal tables
TYPES : BEGIN OF TY_EKKO,
EBELN TYPE EKKO-EBELN,
BEDAT TYPE EKKO-BEDAT,
LIFNR TYPE EKKO-LIFNR,
END OF TY_EKKO.
DATA IT_EKKO TYPE TABLE OF TY_EKKO.
TYPES : BEGIN OF TY_EKPO,
EBELN TYPE EKPO-EBELN,
EBELP TYPE EKPO-EBELP,
MENGE TYPE EKPO-MENGE,
MEINS TYPE EKPO-MEINS,
NETPR TYPE EKPO-NETPR,
END OF TY_EKPO.
DATA IT_EKPO TYPE TABLE OF TY_EKPO.
*Filling the data internal table
SELECT EBELN BEDAT LIFNR FROM EKKO INTO TABLE IT_EKKO
WHERE EBELN IN S_EBELN.
SELECT EBELN EBELP MENGE MEINS NETPR FROM EKPO INTO TABLE IT_EKPO
WHERE EBELN IN S_EBELN.
*Declare the fieldcatalog internal tables
DATA : IT_FCAT1 TYPE SLIS_T_FIELDCAT_ALV,
WA_FCAT1 LIKE LINE OF IT_FCAT1.
DATA : IT_FCAT2 TYPE SLIS_T_FIELDCAT_ALV,
WA_FCAT2 LIKE LINE OF IT_FCAT2.
*Filling the fieldcatalog
*First fieldcatalog
WA_FCAT1-FIELDNAME = ‘EBELN’.
WA_FCAT1-COL_POS = ‘1’.
WA_FCAT1-SELTEXT_M = ‘Pur.doc’.
APPEND WA_FCAT1 TO IT_FCAT1.
CLEAR WA_FCAT1.
WA_FCAT1-FIELDNAME = ‘BEDAT’.
WA_FCAT1-COL_POS = ‘2’.
WA_FCAT1-SELTEXT_M = ‘Doc.date’.
APPEND WA_FCAT1 TO IT_FCAT1.
CLEAR WA_FCAT1.
WA_FCAT1-FIELDNAME = ‘LIFNR’.
WA_FCAT1-COL_POS = ‘3’.
WA_FCAT1-SELTEXT_M = ‘Vendor’.
APPEND WA_FCAT1 TO IT_FCAT1.
CLEAR WA_FCAT1.
*second fieldcatalog
WA_FCAT2-FIELDNAME = ‘EBELN’.
WA_FCAT2-COL_POS = ‘1’.
WA_FCAT2-SELTEXT_M = ‘Pur.doc’.
APPEND WA_FCAT2 TO IT_FCAT2.
CLEAR WA_FCAT2.
WA_FCAT2-FIELDNAME = ‘EBELP’.
WA_FCAT2-COL_POS = ‘2’.
WA_FCAT2-SELTEXT_M = ‘Item’.
APPEND WA_FCAT2 TO IT_FCAT2.
CLEAR WA_FCAT2.
WA_FCAT2-FIELDNAME = ‘MENGE’.
WA_FCAT2-COL_POS = ‘3’.
WA_FCAT2-SELTEXT_M = ‘Quantity’.
APPEND WA_FCAT2 TO IT_FCAT2.
CLEAR WA_FCAT2.
WA_FCAT2-FIELDNAME = ‘MEINS’.
WA_FCAT2-COL_POS = ‘4’.
WA_FCAT2-SELTEXT_M = ‘Uom’.
APPEND WA_FCAT2 TO IT_FCAT2.
CLEAR WA_FCAT2.
WA_FCAT2-FIELDNAME = ‘NETPR’.
WA_FCAT2-COL_POS = ‘5’.
WA_FCAT2-SELTEXT_M = ‘Net price’.
APPEND WA_FCAT2 TO IT_FCAT2.
CLEAR WA_FCAT2.
*Declare the layout workareas
DATA : WA_LAYOUT1 TYPE SLIS_LAYOUT_ALV,
WA_LAYOUT2 TYPE SLIS_LAYOUT_ALV.
*Declare the event internal tables
DATA : IT_EVENT1 TYPE SLIS_T_EVENT,
IT_EVENT2 TYPE SLIS_T_EVENT.
*Initialize the blocked alv
CALL FUNCTION ‘REUSE_ALV_BLOCK_LIST_INIT’
EXPORTING
I_CALLBACK_PROGRAM = ‘ZSPRAO_O_ALV4’.
*Append the data internal tables to blocked alv
CALL FUNCTION ‘REUSE_ALV_BLOCK_LIST_APPEND’
EXPORTING
IS_LAYOUT = WA_LAYOUT1
IT_FIELDCAT = IT_FCAT1
I_TABNAME = ‘IT_EKKO’
IT_EVENTS = IT_EVENT1
TABLES
T_OUTTAB = IT_EKKO.
CALL FUNCTION ‘REUSE_ALV_BLOCK_LIST_APPEND’
EXPORTING
IS_LAYOUT = WA_LAYOUT2
IT_FIELDCAT = IT_FCAT2
I_TABNAME = ‘IT_EKPO’
IT_EVENTS = IT_EVENT2
TABLES
T_OUTTAB = IT_EKPO.
*Display the output by using blocked ALV
CALL FUNCTION ‘REUSE_ALV_BLOCK_LIST_DISPLAY’.
Object : Based on the given pur.doc numbers to display the pur.doc numbers document dates and vendor numbers by using alv and also display the logo in top_of_page and also display heading as ‘BBS Technologies’.
REPORT ZBBST_S_ALV09.
TYPE-POOLS SLIS.
TABLES LFA1.
SELECT-OPTIONS S_LIFNR FOR LFA1-LIFNR.
*Declare the data internal table
TYPES : BEGIN OF TY_LFA1,
LIFNR TYPE LFA1-LIFNR,
NAME1 TYPE LFA1-NAME1,
ORT01 TYPE LFA1-ORT01,
END OF TY_LFA1.
DATA IT_LFA1 TYPE TABLE OF TY_LFA1.
*Filling the data internal table
Select LIFNR NAME1 ORT01 From LFA1 INTO TABLE IT_LFA1 where LIFNR in S_LIFNR.
*Declare the fieldcatalog internal table
DATA : IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FCAT LIKE LINE OF IT_FCAT.
*Filling the fieldcatalog
WA_FCAT-FIELDNAME = ‘LIFNR’.
WA_FCAT-COL_POS = ‘1’.
WA_FCAT-SELTEXT_M = ‘Vendor .no’.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-FIELDNAME = ‘NAME1’.
WA_FCAT-COL_POS = ‘2’.
WA_FCAT-SELTEXT_M = ‘Vendor name’.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-FIELDNAME = ‘ORT01’.
WA_FCAT-COL_POS = ‘3’.
WA_FCAT-SELTEXT_M = ‘Vendor City’.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
*Declare the event internal table
DATA : IT_EVENT TYPE SLIS_T_EVENT,
WA_EVENT LIKE LINE OF IT_EVENT.
*Filling the event internal table
WA_EVENT-NAME = ‘TOP_OF_PAGE’.
WA_EVENT-FORM = ‘XYZ’.
APPEND WA_EVENT TO IT_EVENT.
WA_EVENT-NAME = ‘END_OF_LIST’.
WA_EVENT-FORM = ‘ABC’.
APPEND WA_EVENT TO IT_EVENT.
*Display output
CALL FUNCTION ‘REUSE_ALV_LIST_DISPLAY’
EXPORTING
I_CALLBACK_PROGRAM = SY-CPROG
IT_FIELDCAT = IT_FCAT
IT_EVENTS = IT_EVENT
TABLES
t_outtab = IT_LFA1.
FORM XYZ.
WRITE ‘BBST Technologies’.
write :/ ‘these are vendor details’.
ENDFORM.
FORM ABC.
write :/ ‘Swindon,UK-38’.
ENDFORM.
Object: Based on the given vendor numbers,to display to display thevendor po details (LIFNR,NAME1,EBELN,BEDAT) by using ALV report and also display the TOP_OF_LIST as ‘ Sprao technologies’ and Top_of_page as ‘These are vendor po details’.
REPORT ZBBST_TEC_k_ALV9.
TYPE-POOLS SLIS.
TABLES LFA1.
SELECT-OPTIONS S_LIFNR FOR LFA1-LIFNR.
*Declare the data internal table
TYPES : BEGIN OF TY_FINAL,
LIFNR TYPE LFA1-LIFNR,
NAME1 TYPE LFA1-NAME1,
EBELN TYPE EKKO-EBELN,
BEDAT TYPE EKKO-BEDAT,
END OF TY_FINAL.
DATA IT_FINAL TYPE TABLE OF TY_FINAL.
*Filling the data internal table
SELECT LFA1~LIFNR LFA1~NAME1 EKKO~EBELN EKKO~BEDAT INTO TABLE IT_FINAL
FROM LFA1 INNER JOIN EKKO ON LFA1~LIFNR = EKKO~LIFNR
WHERE LFA1~LIFNR IN S_LIFNR.
*Declare the fieldcatalog
DATA : IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FCAT LIKE LINE OF IT_FCAT.
*Filling the fieldcatalog
WA_FCAT-FIELDNAME = ‘LIFNR’.
WA_FCAT-COL_POS = ‘1’.
WA_FCAT-SELTEXT_M = ‘Vendor’.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-FIELDNAME = ‘NAME1’.
WA_FCAT-COL_POS = ‘2’.
WA_FCAT-SELTEXT_M = ‘Ven.Name’.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-FIELDNAME = ‘EBELN’.
WA_FCAT-COL_POS = ‘3’.
WA_FCAT-SELTEXT_M = ‘Pur.doc’.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-FIELDNAME = ‘BEDAT’.
WA_FCAT-COL_POS = ‘4’.
*WA_FCAT-SELTEXT_M = ‘Doc.date’.
WA_FCAT-REF_TABNAME = ‘EKKO’.
WA_FCAT-REF_FIELDNAME = ‘BEDAT’.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
*Declare the event internal table
DATA : IT_EVENT TYPE SLIS_T_EVENT,
WA_EVENT LIKE LINE OF IT_EVENT.
*Filling the event internal table
WA_EVENT-NAME = ‘TOP_OF_LIST’.
WA_EVENT-FORM = ‘XYZ’. “perform xyz
APPEND WA_EVENT TO IT_EVENT.
WA_EVENT-NAME = ‘TOP_OF_PAGE’.
WA_EVENT-FORM = ‘ABC’. “PERFORM ABC
APPEND WA_EVENT TO IT_EVENT.
*Declare the layout workarea
DATA WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
*Filling the layout workarea
WA_LAYOUT-COLWIDTH_OPTIMIZE = ‘X’.
WA_LAYOUT-ZEBRA = ‘X’.
*Display the output
CALL FUNCTION ‘REUSE_ALV_LIST_DISPLAY’
EXPORTING
I_CALLBACK_PROGRAM = ‘ZSPRAO_7PM_O_ALV5’
IS_LAYOUT = WA_LAYOUT
IT_FIELDCAT = IT_FCAT
IT_EVENTS = IT_EVENT
TABLES
T_OUTTAB = IT_FINAL.
FORM XYZ.
WRITE ‘BBSR Technologies’.
ENDFORM.
FORM ABC.
WRITE / ‘These are vendor po details’.
ENDFORM.
Note : ‘REUSE_ALV_FIELDCATALOG_MERGE’ is the function module
which is used to prepare the fieldcatalog internal table.
The input for the above function module is:
1.Data internal table workarea
2.Program name, in where data internal table workarea is declared
3.Fieldcatalog internal table
4.Program name, in where fieldcatalog internal table is declared
Note : SY-CPROG is the system variable,which contains current program name/ call back program name.
Whenever we working with merge function module,then must consider following things:
1.We never declare the data internal table by using TYPES keyword
2.We never declare the data internal table fields by refering type keyword
we always use like keyword
EX:
BUKRS TYPE T001-BUKRS (X)
BUKRS LIKE T001-BUKRS.
3.We must maintain the code up to 72 column.
Object: Based on the given customer numbers to display the customer numbers,customer names and cities by using ALV and also fill the fieldcatalog by using merge function module.
REPORT ZBBSRT_O_ALV10.
TYPE-POOLS SLIS.
TABLES KNA1.
SELECT-OPTIONS S_KUNNR FOR KNA1-KUNNR.
*Declare the data internal table
DATA : BEGIN OF WA_KNA1,
KUNNR LIKE KNA1-KUNNR,
NAME1 LIKE KNA1-NAME1,
ORT01 LIKE KNA1-ORT01,
END OF WA_KNA1.
DATA IT_KNA1 LIKE TABLE OF WA_KNA1.
*Filling the data internal table
SELECT KUNNR NAME1 ORT01 FROM KNA1 INTO TABLE IT_KNA1
WHERE KUNNR IN S_KUNNR.
*Declare the fieldcatalog
DATA IT_FCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA WA_FCAT LIKE LINE OF IT_FCAT.
*Filling the fieldcatalog
CALL FUNCTION ‘REUSE_ALV_FIELDCATALOG_MERGE’
EXPORTING
I_PROGRAM_NAME = ‘ZSPRAO_O_ALV8’
I_INTERNAL_TABNAME = ‘WA_KNA1’
I_INCLNAME = ‘ZSPRAO_O_ALV8’
CHANGING
CT_FIELDCAT = IT_FCAT.
*Display output
CALL FUNCTION ‘REUSE_ALV_LIST_DISPLAY’
EXPORTING
IT_FIELDCAT = IT_FCAT
TABLES
T_OUTTAB = IT_KNA1.