Google Search - Blog...........

ABAP - Top Of Page Center Using OOPS In ALV Report.

REPORT zalvtest.



*------------------------------------------------------------------------------

* tables

*------------------------------------------------------------------------------

TABLES vbak.



*------------------------------------------------------------------------------

* type pools

*------------------------------------------------------------------------------



TYPE-POOLS slis.



*------------------------------------------------------------------------------

* types and internal tables

*------------------------------------------------------------------------------



*Data Declaration

TYPES: BEGIN OF t_vbak,

vbeln TYPE vbak-vbeln,

erdat TYPE vbak-erdat,

ernam TYPE vbak-ernam,

audat TYPE vbak-audat,

vbtyp TYPE vbak-vbtyp,

netwr TYPE vbak-netwr,

vkorg TYPE vbak-vkorg,

vkgrp TYPE vbak-vkgrp,

END OF t_vbak.



DATA it_vbak TYPE STANDARD TABLE OF t_vbak INITIAL SIZE 0.



*ALV Data Declaration

DATA: fldcat TYPE slis_t_fieldcat_alv,



w_fldcat TYPE slis_fieldcat_alv,



gd_layout TYPE slis_layout_alv,



gd_repid TYPE sy-repid.



DATA: date1(10).



*------------------------------------------------------------------------------

* selection screen design

*------------------------------------------------------------------------------



SELECT-OPTIONS: vbeln FOR vbak-vbeln.



*------------------------------------------------------------------------------

* start of selection

*------------------------------------------------------------------------------



START-OF-SELECTION.



PERFORM data_retrieval.



PERFORM bld_fldcat.



PERFORM bld_layout.



PERFORM display_alv_report.



*------------------------------------------------------------------------------

* build catalog

*------------------------------------------------------------------------------

*Build Field Catalog for ALV Report

FORM bld_fldcat.



w_fldcat-fieldname = 'VBELN'.

w_fldcat-seltext_m = 'Sales_Document'.

w_fldcat-col_pos = 0.

w_fldcat-outputlen = 15.

w_fldcat-key = 'X'.

w_fldcat-icon = 'X'.

APPEND w_fldcat TO fldcat.

CLEAR w_fldcat.



w_fldcat-fieldname = 'ERDAT'.

w_fldcat-seltext_l = 'Record_Date_created'.

w_fldcat-col_pos = 1.

w_fldcat-key = 'X'.

APPEND w_fldcat TO fldcat.

CLEAR w_fldcat.



w_fldcat-fieldname = 'ERNAM'.

w_fldcat-seltext_l = 'Cteated_Person_Name'.

w_fldcat-col_pos = 2.

w_fldcat-emphasize = 'C011'.

APPEND w_fldcat TO fldcat.

CLEAR w_fldcat.



w_fldcat-fieldname = 'AUDAT'.

w_fldcat-seltext_m = 'Document_Date'.

w_fldcat-col_pos = 3.

w_fldcat-emphasize = 'C110'.

APPEND w_fldcat TO fldcat.

CLEAR w_fldcat.



w_fldcat-fieldname = 'VBTYP'.

w_fldcat-seltext_l = 'SDDocument_category'.

w_fldcat-col_pos = 4.

APPEND w_fldcat TO fldcat.

CLEAR w_fldcat.



w_fldcat-fieldname = 'NETWR'.

w_fldcat-seltext_l = 'Net_Value'.

w_fldcat-col_pos = 5.

w_fldcat-outputlen = 10.

w_fldcat-do_sum = 'X'.

w_fldcat-datatype = 'CURR'.

APPEND w_fldcat TO fldcat.

CLEAR w_fldcat.



w_fldcat-fieldname = 'VKORG'.

w_fldcat-seltext_l = 'Sales_Organization'.

w_fldcat-col_pos = 6.

APPEND w_fldcat TO fldcat.

CLEAR w_fldcat.



w_fldcat-fieldname = 'VKGRP'.

w_fldcat-seltext_m = 'Sales_Group'.

w_fldcat-col_pos = 7.

w_fldcat-emphasize = 'C801'.

APPEND w_fldcat TO fldcat.

CLEAR w_fldcat.



ENDFORM. "BLD_FLDCAT

*------------------------------------------------------------------------------

* display fatalog

*------------------------------------------------------------------------------

*Build Layout for ALV Grid Report



FORM bld_layout.

gd_layout-no_input = 'X'.

gd_layout-box_fieldname = 'VBELN'.

ENDFORM. "BLD_LAYOUT





*Display report using ALV grid



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_html_top_of_page = 'TOP_OF_PAGE_SPLIT'

it_fieldcat = fldcat[]

TABLES

t_outtab = it_vbak.



ENDFORM. "DISPLAY_ALV_REPORT

*------------------------------------------------------------------------------

* get data

*------------------------------------------------------------------------------

*Retrieve data from VBAK table and populate itab IT_VBAK

FORM data_retrieval.



SELECT vbeln

erdat

ernam

audat

vbtyp

netwr

vkorg

FROM vbak

INTO TABLE it_vbak

WHERE vbeln IN vbeln.

ENDFORM. "DATA_RETRIEVAL

*------------------------------------------------------------------------------

* build header for alv

*------------------------------------------------------------------------------



FORM top_of_page_split USING r_top TYPE REF TO cl_dd_document.



DATA: s_tab TYPE sdydo_text_table,



c_area TYPE REF TO cl_dd_area,



text TYPE sdydo_text_element.



TYPES: BEGIN OF tab_text,

text TYPE sdydo_text_element,

END OF tab_text.



DATA: i_text TYPE TABLE OF tab_text.

DATA: w_text TYPE tab_text.



CALL METHOD r_top->initialize_document.



CALL METHOD r_top->vertical_split

EXPORTING

split_area = r_top

split_width = '70%'

IMPORTING

right_area = c_area.



CONCATENATE sy-datum+4(2)

' / '

sy-datum+6(2)

' / '

sy-datum(4)

INTO date1.



CONCATENATE 'DATE'

date1

INTO w_text-text

SEPARATED BY ':'.

APPEND w_text TO i_text.



CONCATENATE 'time:' sy-uzeit INTO w_text .

APPEND w_text TO i_text.



CONCATENATE 'uesr:' sy-uname INTO w_text .

APPEND w_text TO i_text.



CONCATENATE 'local date:' sy-datlo INTO w_text .

APPEND w_text TO i_text.



CONCATENATE 'time zone:' sy-zonlo INTO w_text .

APPEND w_text TO i_text.





s_tab[] = i_text[].



CALL METHOD c_area->add_text

EXPORTING

text_table = s_tab

fix_lines = 'X'

sap_fontsize = cl_dd_document=>medium

sap_emphasis = cl_dd_document=>strong.



CALL METHOD r_top->add_gap

EXPORTING

width = 60.



text = 'THIS IS REPORT HEADING'.

CALL METHOD r_top->add_text

EXPORTING

text = text

sap_emphasis = 'STRONG'.



CALL METHOD r_top->new_line.



CALL METHOD r_top->add_gap

EXPORTING

width = 70.



text = 'THIS IS REPORT HEADING1'.

CALL METHOD r_top->add_text

EXPORTING

text = text

sap_emphasis = 'STRONG'.



CALL METHOD r_top->new_line.



CALL METHOD r_top->add_gap

EXPORTING

width = 80.



text = 'THIS IS REPORT HEADING2'.

CALL METHOD r_top->add_text

EXPORTING

text = text

sap_emphasis = 'STRONG'.





CALL METHOD r_top->new_line.



text = 'Report Subheading1'.

CALL METHOD r_top->add_text

EXPORTING

text = text

sap_emphasis = 'NORMAL'.



CALL METHOD r_top->new_line.



text = 'Report Subheading2'.

CALL METHOD r_top->add_text

EXPORTING

text = text

sap_emphasis = 'NORMAL'.



CALL METHOD r_top->new_line.



text = 'Report Subheading3'.

CALL METHOD r_top->add_text
EXPORTING
text = text
sap_emphasis = 'NORMAL'.
CALL METHOD r_top->new_line.
ENDFORM. "TOP_OF_PAGE_SPLIT




ABAP - Sample Program On Hiding Any Report Program.

REPORT zhidereport

NO STANDARD PAGE HEADING.



DATA: g_code(72) TYPE c OCCURS 0,

g_code1 LIKE LINE OF g_code,

g_code2(72) TYPE c OCCURS 0.



PARAMETERS: program LIKE sy-repid.



START-OF-SELECTION.



READ REPORT program INTO g_code.



IF sy-subrc NE 0.

MESSAGE e398(00) WITH 'Report' program 'not found.'.

* ATTENTION:

* READ REPORT on a hidden source code return SY-SUBRC=8 !!!

ENDIF.



READ TABLE g_code INDEX 1 INTO g_code1.



* append *special* 1st line to hide cource code

APPEND '*@#@@[SAP]' TO g_code2.

LOOP AT g_code INTO g_code1.

APPEND g_code1 TO g_code2.

ENDLOOP.



INSERT REPORT program FROM g_code2.

ABAP - Restrict Values For The F4 (Value On Request) Help.

report ztest .

PARAMETERS:p_matnr(18) TYPE c MODIF ID mid.

DATA:BEGIN OF itab OCCURS 0,
matnr TYPE matnr,
END OF itab.

AT SELECTION-SCREEN OUTPUT.

LOOP AT SCREEN .
IF screen-group1 EQ 'MID'.
screen-input = '0'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_matnr.

LOOP AT SCREEN .
IF screen-group1 EQ 'MID'.
screen-input = '1'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.

IF itab IS INITIAL.

itab-matnr = 'ABC123456788'.
APPEND itab.

itab-matnr = 'BCS123456788'.
APPEND itab.

itab-matnr = 'DFC123456788'.
APPEND itab.

itab-matnr = 'ASW123456788'.
APPEND itab.

ENDIF.


CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'MATNR'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'P_MATNR'
value_org = 'S'
TABLES
value_tab = itab.

LOOP AT SCREEN .
IF screen-group1 EQ 'MID'.
screen-input = '0'.
MODIFY SCREEN.
ENDIF.
endloop.


ALSO READ:

- Screen Field Validation Using Chain Endchain.

- Drop Down List Box In The Selection Screen.

- Creating Dynamic F4 (Value On Request) Help.

- Express Select-Options Values In SY-LANGU.

- F4 (Value On Request) For Files On Presentation Or Application Server.

ABAP - ALV With Page Numbers & Subtotals.

Here is the code for alv with page nos and subtotal.

If you click any one of the line it will displays the list .


report ztests .

* ALV

type-pools: slis.



*--------------------------------------------------------------------

* G L O B A L I N T E R N A L T A B L E S

*--------------------------------------------------------------------

data: gt_fieldcat type slis_t_fieldcat_alv,

gs_layout type slis_layout_alv,

gt_events type slis_t_event.

data: it_sort type slis_t_sortinfo_alv ,

wa_sort type slis_sortinfo_alv .

data: gs_print type slis_print_alv.



data: begin of it_sflight occurs 0,

carrid like sflight-carrid,

connid like sflight-connid,

fldate like sflight-fldate,

price like sflight-price,

planetype like sflight-planetype,

seatsmax like sflight-seatsmax,

seatsocc like sflight-seatsocc,

paymentsum like sflight-paymentsum,

end of it_sflight.



*DATA: GI_SFLIGHT LIKE STANDARD TABLE OF ST_SFLIGHT.

data: g_repid like sy-repid.

data: gt_list_top_of_page type slis_t_listheader.

data: v_total(5).



start-of-selection.

g_repid = sy-repid.



perform init_fieldcat using gt_fieldcat[].

perform build_eventtab using gt_events[].

perform build_comment using gt_list_top_of_page[].

perform get_data.

perform set_layout using gs_layout.



* SORTING

clear wa_sort.

wa_sort-fieldname = 'CARRID'.

wa_sort-up = 'X'.

wa_sort-group = '*'.

wa_sort-subtot = 'X'.

append wa_sort to it_sort.



clear wa_sort.

wa_sort-fieldname = 'CONNID'.

wa_sort-up = 'X'.

wa_sort-group = 'UL'.

wa_sort-subtot = 'X'.

append wa_sort to it_sort.



* DISPLAY LIST

call function 'REUSE_ALV_LIST_DISPLAY'

exporting

i_interface_check = ' '

i_callback_program = g_repid

i_callback_user_command = 'USER_COMMAND'

is_layout = gs_layout

it_fieldcat = gt_fieldcat[]

it_sort = it_sort[]

it_events = gt_events

is_print = gs_print

tables

t_outtab = it_sflight

exceptions

program_error = 1

others = 2.

if sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.





*&---------------------------------------------------------------------*

*& Form INIT_FIELDCAT

*&---------------------------------------------------------------------*

form init_fieldcat using p_gt_fieldcat type slis_t_fieldcat_alv.

data: ls_fieldcat type slis_fieldcat_alv,

l_index type sy-tabix.



data :rep like sy-repid.

rep = sy-repid.

call function 'REUSE_ALV_FIELDCATALOG_MERGE'

exporting

i_program_name = rep

i_internal_tabname = 'IT_SFLIGHT'

i_inclname = rep

changing

ct_fieldcat = gt_fieldcat

exceptions

inconsistent_interface = 1

program_error = 2

others = 3.

if sy-subrc <> 0.

message id sy-msgid type 'S' number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-subrc.

endif.

sort gt_fieldcat by col_pos.

loop at gt_fieldcat into ls_fieldcat.

l_index = sy-tabix.

if ls_fieldcat-fieldname = 'PRICE'.

ls_fieldcat-do_sum = 'X'.

ls_fieldcat-sp_group = 'X'.

modify gt_fieldcat from ls_fieldcat index l_index .

endif.

endloop.



endform. " INIT_FIELDCAT



*&---------------------------------------------------------------------*

*& Form BUILD_EVENTTAB

*&---------------------------------------------------------------------*

form build_eventtab using p_gt_events type slis_t_event.

data: ls_event type slis_alv_event.



clear ls_event.

ls_event-name = slis_ev_top_of_page.

ls_event-form = 'XTOP_OF_PAGE'.

append ls_event to p_gt_events.

clear ls_event.

ls_event-name = slis_ev_top_of_list.

ls_event-form = 'XTOP_OF_LIST'.

append ls_event to p_gt_events.

clear ls_event.

clear ls_event.

ls_event-name = slis_ev_end_of_page.

ls_event-form = 'XEND_OF_PAGE'.

append ls_event to p_gt_events.

ls_event-name = slis_ev_end_of_list.

ls_event-form = 'XEND_OF_LIST'.

append ls_event to p_gt_events.

clear ls_event.



endform. " BUILD_EVENTTAB



*&---------------------------------------------------------------------*

*& Form BUILD_COMMENT

*&---------------------------------------------------------------------*

form build_comment using p_gt_list_top_of_page type slis_t_listheader.

data: ls_line type slis_listheader.

ls_line-typ = 'H'." = Header, S = Selection, A = Action

ls_line-key = 'KEY'.

ls_line-info = 'INFO'.

append ls_line to p_gt_list_top_of_page.



endform. " BUILD_COMMENT





*&---------------------------------------------------------------------*

*& Form SELECTION

*&---------------------------------------------------------------------*

form get_data..

data: l_rows type i value 3.

* Read data from table SFLIGHT

select carrid

connid

fldate

price

planetype

seatsmax

seatsocc

paymentsum

from sflight

into table it_sflight.

** up to l_rows rows.

sort it_sflight.

endform. " SELECTION



*&---------------------------------------------------------------------*

*& Form SET_LAYOUT

*&---------------------------------------------------------------------*

form set_layout using p_gs_layout type slis_layout_alv.



* * P_GS_LAYOUT-F2CODE = P_F2CODE.

p_gs_layout-zebra = 'X'.

p_gs_layout-colwidth_optimize = 'X'.

p_gs_layout-no_input = 'X'.

p_gs_layout-no_colhead = space.

p_gs_layout-totals_text = 'Total Price'.

p_gs_layout-subtotals_text = 'Sub Total'.

p_gs_layout-totals_only = 'X'.

p_gs_layout-key_hotspot = 'X'.

p_gs_layout-detail_popup = 'X'.

p_gs_layout-no_subtotals = space.

p_gs_layout-expand_all = 'X'.

p_gs_layout-group_buttons = 'X'."space.

endform. " SET_LAYOUT



*---------------------------------------------------------------------*

* FORM XTOP_OF_PAGE *

*---------------------------------------------------------------------*

form xtop_of_page.

data : lv_page(5),

lv_text(20).

MOVE SY-PAGNO TO LV_PAGE.

write:/ 'X_TOP_OF_PAGE'.

.

endform. "xtop_of_page

*---------------------------------------------------------------------*

* FORM XTOP_OF_LIST *

*---------------------------------------------------------------------*

form xtop_of_list.

write:/ 'X_TOP_OF_LIST'.

endform. "xtop_of_list

*---------------------------------------------------------------------*

* FORM XEND_OF_PAGE *

*---------------------------------------------------------------------*

form xend_of_page.

write:/ 'X_END_OF_PAGE'.

endform. "xend_of_page

*---------------------------------------------------------------------*

* FORM XEND_OF_LIST *

*---------------------------------------------------------------------*

form xend_of_list.

write:/ 'X_END_OF_LIST'.

data : lv_page(5),

lv_text(20).

data : l_lines type i,

l_line type i.



clear v_total.



write sy-pagno to v_total left-justified.

* export v_total to memory id 'V_TOTAL'.

do sy-pagno times.

lv_page = sy-index.

concatenate 'Page' lv_page 'of' v_total

into lv_text separated by space.

if sy-index = 1.

read line 2 of page sy-index.

else.

read line 1 of page sy-index.



endif.

sy-lisel+60(20) = lv_text.

modify current line .

enddo.



endform. "xend_of_list



*---------------------------------------------------------------------*

* USER_COMMAND *

*---------------------------------------------------------------------*

form user_command using r_ucomm like sy-ucomm

rs_selfield type slis_selfield.



case r_ucomm.

when 'EXIT'.

leave to screen 0.

when '&IC1'.

data: text(256),text1(6),text2(5).

move rs_selfield-tabindex to text1.

move rs_selfield-sumindex to text2.

concatenate 'Double clicked on (field:'

rs_selfield-fieldname

'Value:'

rs_selfield-value

','

text1

','

text2

' ) '

into text

separated by space.



call function 'POPUP_TO_DISPLAY_TEXT'

exporting

textline1 = text.



endcase.

endform. "user_command

\

ALSO READ:

- Footer Functionality In ALV Reports.

- Calling One ALV From Other ALV Report Program.

- Capture Single & Multiple Row Selction In ALV Report Program.

- Coloring A Row & Column In ALV Display Using OOPS Concept.

..... Back To Index On ALV List/ Grid Display.

..... Back To MAIN INDEX.


ABAP - Download Data With A Delimiter.

Here is the simple coding for downloading any data with the specified delimiter given on the selection screen .





REPORT zdownload.



TABLES: mara.



TYPES: BEGIN OF ty_out,

line(150),

END OF ty_out,



BEGIN OF ty_mat,

matnr TYPE mara-matnr,

mtart TYPE mara-mtart,

mbrsh TYPE mara-mbrsh,

meins TYPE mara-meins,

END OF ty_mat.



DATA: it_out TYPE STANDARD TABLE OF ty_out WITH HEADER LINE,

it_mat TYPE STANDARD TABLE OF ty_mat WITH HEADER LINE.





SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE title.



SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 5(18) title1.

SELECT-OPTIONS: s_matnr FOR mara-matnr.

SELECTION-SCREEN POSITION 1 .

SELECTION-SCREEN END OF LINE .



SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 7(18) title2.

PARAMETERS: p_dlim TYPE c OBLIGATORY.

SELECTION-SCREEN POSITION 1 .

SELECTION-SCREEN END OF LINE .



SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 7(18) title3.

PARAMETERS: p_file TYPE rlgrap-filename.

SELECTION-SCREEN POSITION 1 .

SELECTION-SCREEN END OF LINE .





SELECTION-SCREEN END OF BLOCK b1.



INITIALIZATION .



title = 'enter the entries'.

title1 = 'material number'.

title2 = 'delimiter'.

title3 = 'file name'.



AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file .



CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

field_name = 'P_FILE'

IMPORTING

file_name = p_file.



START-OF-SELECTION.



**--Get the data from material table

SELECT matnr

mtart

mbrsh

meins

FROM mara

INTO TABLE it_mat

WHERE matnr IN s_matnr.

**--Prepare output file with specified delimit char

LOOP AT it_mat.

IF p_dlim = 'X'.

CONCATENATE it_mat-matnr

it_mat-mtart

it_mat-mbrsh

it_mat-meins

INTO it_out-line

SEPARATED BY cl_abap_char_utilities=>horizontal_tab.

ELSE.

CONCATENATE it_mat-matnr

it_mat-mtart

it_mat-mbrsh

it_mat-meins

INTO it_out-line

SEPARATED BY p_dlim.

ENDIF.

APPEND it_out.

CLEAR: it_out,

it_mat.

ENDLOOP.

**--Download the data



DATA: file TYPE string .



file = p_file .



CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = file

TABLES

data_tab = it_out

EXCEPTIONS

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

no_authority = 5

unknown_error = 6

header_not_allowed = 7

separator_not_allowed = 8

filesize_not_allowed = 9

header_too_long = 10

dp_error_create = 11

dp_error_send = 12

dp_error_write = 13

unknown_dp_error = 14

access_denied = 15

dp_out_of_memory = 16

disk_full = 17

dp_timeout = 18

file_not_found = 19

dataprovider_exception = 20

control_flush_error = 21

OTHERS = 22.

IF sy-subrc = 0.

WRITE:/ 'File downloaded successfully'.

ENDIF.

ABAP - Disable The User Password.

Here is the best example for disabling the users password . please let me know if there is any thing needed .





REPORT Zdisablepassword.



tables: usr02.



types: begin of ty_users .

include structure usr02 .

types: end of ty_users.



data: it_users type table of ty_users with header line .



select-options: s_users for usr02-bname.





start-of-selection.





select * from usr02

into table it_users

where bname in s_users.





loop at it_users.

it_users-codvn = 'X'.

clear it_users-bcode.

write:/1(35) sy-uline.

write: /1 sy-vline ,

2 'Deactivating ' color 7,

22 it_users-bname color 5,

35 sy-vline.

write:/1(35) sy-uline.

update usr02.



endloop .

ABAP - Report Program To Display Subtotals In Hierarchical Report.

REPORT zvenkat_alv_4_hierarchi_subtot.

"Types

TYPES:

BEGIN OF t_pa0001, "Header table type

pernr TYPE pa0001-pernr,

bukrs TYPE pa0001-bukrs,

werks TYPE pa0001-werks,

persg TYPE pa0001-persg,

persk TYPE pa0001-persk,

abkrs TYPE pa0001-abkrs,

expand TYPE c,

END OF t_pa0001,

BEGIN OF t_pa0008, "Item table

pernr TYPE pa0008-pernr,

lga01 TYPE pa0008-lga01,

bet01 TYPE pa0008-bet01,

END OF t_pa0008.

"Work areas

DATA:

w_pa0008 TYPE t_pa0008,

w_pa0001 TYPE t_pa0001.

"Internal tables

DATA:

i_pa0008 TYPE STANDARD TABLE OF t_pa0008,

i_pa0001 TYPE STANDARD TABLE OF t_pa0001.

*&---------------------------------------------------------------------*

" ALV Declarations

*----------------------------------------------------------------------*

" Types Pools

TYPE-POOLS:

slis.

" Types

TYPES:

t_fieldcat TYPE slis_fieldcat_alv,

t_events TYPE slis_alv_event,

t_layout TYPE slis_layout_alv,

t_sort TYPE slis_sortinfo_alv,

t_keyinfo TYPE slis_keyinfo_alv.

" Workareas

DATA:

w_fieldcat TYPE t_fieldcat,

w_events TYPE t_events,

w_sort TYPE t_sort,

w_layout TYPE t_layout,

w_keyinfo TYPE t_keyinfo.

" Internal Tables

DATA:

i_fieldcat TYPE STANDARD TABLE OF t_fieldcat,

i_events TYPE STANDARD TABLE OF t_events,

i_sort TYPE STANDARD TABLE OF t_sort.



START-OF-SELECTION.



PERFORM get_data.



END-OF-SELECTION.



PERFORM build_fieldcatalog. "Fieldcatalog

PERFORM build_events. "Events table

PERFORM build_sort_tab. "To sort table and get subtotal

PERFORM build_relation_structure. "Making relationship between header

* and Item table

PERFORM display_data.



*&---------------------------------------------------------------------*

*& Form get_data

*&---------------------------------------------------------------------*

FORM get_data.

DATA:l_0008 TYPE pa0008 OCCURS 0 WITH HEADER LINE.



SELECT *

FROM pa0001

INTO CORRESPONDING FIELDS OF TABLE i_pa0001

UP TO 50 ROWS

WHERE begda LE sy-datum

AND endda GE sy-datum.



IF i_pa0001[] IS NOT INITIAL.

SELECT pernr lga01 bet01

FROM pa0008

INTO CORRESPONDING FIELDS OF l_0008

FOR ALL ENTRIES IN i_pa0001

WHERE pernr = i_pa0001-pernr

AND begda LE sy-datum

AND endda GE sy-datum.



w_pa0008-pernr = l_0008-pernr.

w_pa0008-lga01 = l_0008-lga01.

w_pa0008-bet01 = l_0008-bet01.

APPEND w_pa0008 TO i_pa0008.

CLEAR w_pa0008.



w_pa0008-pernr = l_0008-pernr.

w_pa0008-lga01 = l_0008-lga02.

w_pa0008-bet01 = l_0008-bet02.

APPEND w_pa0008 TO i_pa0008.

CLEAR w_pa0008.



w_pa0008-pernr = l_0008-pernr.

w_pa0008-lga01 = l_0008-lga03.

w_pa0008-bet01 = l_0008-bet03.

APPEND w_pa0008 TO i_pa0008.

CLEAR w_pa0008.



w_pa0008-pernr = l_0008-pernr.

w_pa0008-lga01 = l_0008-lga04.

w_pa0008-bet01 = l_0008-bet04.

APPEND w_pa0008 TO i_pa0008.

CLEAR w_pa0008.



ENDSELECT.

ENDIF.



ENDFORM. "get_data

*&---------------------------------------------------------------------*

*& Form build_fieldcatalog

*&---------------------------------------------------------------------*

FORM build_fieldcatalog.

PERFORM build_fcat USING:

"Field Int.Table Text

'PERNR' 'I_PA0001' 'PERNR',

'BUKRS' 'I_PA0001' 'BUKRS',

'WERKS' 'I_PA0001' 'WERKS',

'PERSG' 'I_PA0001' 'PERSG',

'PERSK' 'I_PA0001' 'PERSK',

'ABKRS' 'I_PA0001' 'ABKRS',

'PERNR' 'I_PA0008' 'PERNR', "Remove this if u dont

*want in the item table as well as it is there in the header table

'LGA01' 'I_PA0008' 'LGA01',

'BET01' 'I_PA0008' 'BET01'.



ENDFORM. "build_fieldcatalog

*&---------------------------------------------------------------------*

*& Form build_events

*----------------------------------------------------------------------*

FORM build_events.

CLEAR:

w_events, i_events[].

w_events-name = 'TOP_OF_PAGE'.

w_events-form = 'TOP_OF_PAGE'.

APPEND w_events TO i_events.

CLEAR w_events.



ENDFORM. "build_events

*&---------------------------------------------------------------------*

*& Form build_relation_structure

*----------------------------------------------------------------------*

FORM build_relation_structure.



w_keyinfo-header01 = 'PERNR'.

w_keyinfo-item01 = 'PERNR'.



ENDFORM. "build_relation_structure

*&---------------------------------------------------------------------*

*& Form display_data

*----------------------------------------------------------------------*

FORM display_data.

DATA:

l_program TYPE sy-repid VALUE sy-repid.



CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'

EXPORTING

i_callback_program = l_program

it_fieldcat = i_fieldcat

it_events = i_events

it_sort = i_sort

i_tabname_header = 'I_PA0001'

i_tabname_item = 'I_PA0008'

is_keyinfo = w_keyinfo

TABLES

t_outtab_header = i_pa0001

t_outtab_item = i_pa0008.

IF sy-subrc NE 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. "display_data

*&---------------------------------------------------------------------*

*& Form build_fcat

*&---------------------------------------------------------------------*

FORM build_fcat USING l_field l_tab l_text.



w_fieldcat-fieldname = l_field.

w_fieldcat-tabname = l_tab.

w_fieldcat-seltext_m = l_text.

IF l_field = 'BET01'.

w_fieldcat-do_sum = 'X'.

ENDIF.

APPEND w_fieldcat TO i_fieldcat.

CLEAR w_fieldcat.



ENDFORM. " build_fcat



*&---------------------------------------------------------------------*

*& Form top_of_page

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

FORM top_of_page.



DATA :

i_header TYPE slis_t_listheader,

w_header LIKE LINE OF i_header.



DATA:l_date1 TYPE datum,

l_date2 TYPE datum.



w_header-typ = 'S'.

w_header-info = sy-title.

APPEND w_header TO i_header.

CLEAR w_header.



w_header-typ = 'H'.

w_header-info = sy-repid.

APPEND w_header TO i_header.

CLEAR w_header.



CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = i_header

i_logo = 'ENJOYSAP_LOGO'.



ENDFORM. "top_of_page

*&---------------------------------------------------------------------*

*& Form BUILD_sort_tab

*&---------------------------------------------------------------------*

FORM build_sort_tab .



CLEAR :i_sort[],w_sort.

w_sort-spos = 1.

w_sort-fieldname = 'PERNR'.

w_sort-tabname = 'I_PA0001'. "header table

w_sort-up = 'X'.

w_sort-subtot = 'X'.

APPEND w_sort TO i_sort.

CLEAR w_sort.

ENDFORM. " BUILD_sort_tab

ABAP - Creating The Listbox Using Macros.

Here is the simple for creating listbox with macros.

Please check it first and let me know if there is any thing needed .

REPORT Zmac_listbox.

TYPE-POOLS: VRM.

DEFINE LB_MACRO_KOART.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(31) &3.

PARAMETERS: &1 AS LISTBOX VISIBLE LENGTH &2 OBLIGATORY.

SELECTION-SCREEN END OF LINE.

END-OF-DEFINITION.

************************************************************************

* SELECTION-SCREEN *

************************************************************************

SELECTION-SCREEN BEGIN OF BLOCK S1 WITH FRAME TITLE TEXT-001.

LB_MACRO_KOART MYLIST(1) 5 COMMENT.

SELECTION-SCREEN END OF BLOCK S1.

************************************************************************

* AT SELECTION - SCREEN

************************************************************************

AT SELECTION-SCREEN OUTPUT.


PERFORM ADD_VALUES_TO_KOART.

COMMENT = 'Account type'.

*&---------------------------------------------------------------------*

* Fill the values in dropdownlistbox

*----------------------------------------------------------------------*

FORM ADD_VALUES_TO_KOART .

DATA: MY_LIST TYPE VRM_VALUES,

VALUE LIKE LINE OF MY_LIST.


DATA : BEGIN OF I_TAB OCCURS 0,

KOART TYPE C,

END OF I_TAB.

CLEAR I_TAB.

I_TAB-KOART = 'A'.

APPEND I_TAB.

CLEAR I_TAB.

I_TAB-KOART = 'D'.

APPEND I_TAB.

CLEAR I_TAB.


I_TAB-KOART = 'K'.

APPEND I_TAB.

CLEAR I_TAB.


I_TAB-KOART = 'M'.

APPEND I_TAB.

CLEAR I_TAB.


I_TAB-KOART = 'S'.

APPEND I_TAB.

CLEAR I_TAB.

*&---------------------------------------------------------------------*

*& Filling the list structure with values from MARA table

*&---------------------------------------------------------------------*

LOOP AT I_TAB.

VALUE-KEY = SY-TABIX.

VALUE-TEXT = I_TAB-KOART.

APPEND VALUE TO MY_LIST.

ENDLOOP.

*&---------------------------------------------------------------------*

*& Finally calling the function module to create the list box.

*&---------------------------------------------------------------------*

CALL FUNCTION 'VRM_SET_VALUES'

EXPORTING

ID = 'MYLIST'

VALUES = MY_LIST.

ENDFORM. " ADD_VALUES_TO_KOART



ALSO READ:

- Restrict Values For The F4 (Value On Request) Help.

- Screen Field Validation Using Chain Endchain.

- Drop Down List Box In The Selection Screen.

- Creating Dynamic F4 (Value On Request) Help.

- Express Select-Options Values In SY-LANGU.

ABAP - Determine Number Of Rows In An Internal Table At Runtime.

Report ztests .



DATA : BEGIN OF it_mara OCCURS 0,

matnr LIKE mara-matnr,

ersda LIKE mara-ersda,

meins like mara-meins,

END OF it_mara.



DATA : p(4) TYPE c.



FIELD-SYMBOLS: TYPE ANY.



FIELD-SYMBOLS: TYPE ANY.



ASSIGN it_mara TO .



DO.



ASSIGN COMPONENT sy-index OF STRUCTURE TO .



IF sy-subrc EQ 0.

p = p + 1.

ELSE.

EXIT.

ENDIF.

ENDDO.



WRITE : / p.

ABAP - Display All The Columns Of A Table In ALV Grid Using Class CL_SALV_TABLE.



Suppose I have an internal table of the length of the database table. Means suppose I have an internal table declared like this .

Data : it_mara type table of mara. (I am currently working with ecc6) .

Here in the mara table I have 220 fields , I want to show all the columns in the output . For this I am using class CL_SALV_TABLE .

this will work best with the higher version . generally it is not possible to display all fields , not all the fields but atleast nearly 80 fields in the alv display , but here it is possible to display all the fields .


REPORT ZALV_TEST.

data: it_mara type table of mara,

g_table type ref to cl_salv_table,

g_functions type ref to cl_salv_functions,

g_display type ref to cl_salv_display_settings.


start-of-selection.

Select * into table it_mara from mara up to 10 rows.


cl_salv_table=>factory( importing r_salv_table = g_table changing t_table = it_mara ).


g_functions = g_table->get_functions( ).

g_functions->set_all( abap_true ).


g_table->display( ).


After execution of the program I got 200 plus fields in the output .


ALSO READ:

- ALV With Page Numbers & Subtotals.

- Footer Functionality In ALV Reports.

- Calling One ALV From Other ALV Report Program.

- Capture Single & Multiple Row Selction In ALV Report Program.

..... Back To Index On ALV List/ Grid Display.

..... Back To MAIN INDEX.


Tips & Tricks Associated With SAP ABAP.

1) How to find the menu path for a given transaction code?

You can use the transaction code search_sap_menu to find the SAP MENU .

It is important to note that there is no transaction code available to find the path of the IMG transaction.

2) How to protect a program from the debugging ?

If you want to protect a program against debugging, you just have to set the STATUS = S in the attributes view of the main program.


3) What is the main problem with the date in BDC ?

If you are working with BDC suppose a call transaction method , and populate the BDCDATA table. It is important to see the format of the date fields , they are coming into the system .You should pass the DATE FIELDS of any transaction by formatting it as mm/dd/yyyy because if you pick this data from database it will be of the format 20030505 or something like that. Make sure You pass this value as character field.

Same is true for the "Rate Fields". Make sure you pass them as "Character Fields" by formatting them.

4) What are the available BDC function codes & how can I know them ?

Go to the program RSBDCCUA and run it for any platform say 'WN' for windows or MC for Mac and it will generate list of function codes .

5) What are some sample Direct input data transfer programs?

See these are the programs for the data transfer in the following areas

MM - for Material Master data - RMDATIND
FI - for Accounting Documents - RFBIBL00
PP - for Independent requirements - RM06IN00
CA - for Classification data - RCCLBI03


We need to download an internal table to the Presentation Server(local workstation). Whenever we run the program, the same file has to be saved as a separate file in sequential order. Ex: 0001.txt, 0002.txt etc.

6) Where can we store the last file number?

SAP has a table TVARV for storing the variants. A record may be created in TVARV for all the programs that require this kind of incremental records. For Ex: the record could be 100Zmm10001 MM sequence rec where first part consists of client code and the program being run. Client code is required because TVARV does not has a field for client code. The second part is the description indicating the purpose what the record is created. This entire string may be posted in the Name field (char - 30).The Type field ( char- 1) may be populated with P or S (Parameter or Selection)
Low field (char- 45) may be populated with '0001' when run first time and increment it by one in your program for downloading of the internal table.

7) How can we transport the standard text?

A: Refer note 3355 in OSS for a complete explanation. The SAPscript objects that should be transported must be written in a transport request.The entries are as follows:
R3TR FORM NAME (NAME = Name of the layout set)
R3TR STYL NAME (NAME = Name of the style)
R3TR TEXT OBJECT,NAME,ID,L
OBJECT = Text object,
NAME = Text name,
ID = Text ID,
L = Text language

If you want to transport a number of texts, you can use report RSTXTRAN to insert the individual text keys into a correction. The transport request must be entered and released via the transport system.

8) How to find what transactions a particular user was running for a given period in the past (Eg: from 1st of a month )?

You may use the transaction – STAT

ABAP - Report Program To Read Folders & Files In Application Server Directory.

Here is an example for reading all the folders and files in the application server directory . Please let me know if there is any thing needed .



REPORT ZREAD_APPL_FILE_DATA .



*--internal table for the file contents

DATA: BEGIN OF ITAB OCCURS 0,

REC(1000) TYPE C,

END OF ITAB.



DATA: WA(1000) TYPE C,

P_FILE TYPE LOCALFILE,

IT_FILE TYPE TABLE OF SALFLDIR WITH HEADER LINE.



PARAMETERS: P_PATH TYPE SALFILE-LONGNAME

DEFAULT 'F:\usr\sap\EC6\DVEBMGS00\data\'.



*----function module for reading files

* in a directory in the application server



CALL FUNCTION 'RZL_READ_DIR_LOCAL'

EXPORTING

NAME = P_PATH

TABLES

FILE_TBL = IT_FILE

EXCEPTIONS

ARGUMENT_ERROR = 1

NOT_FOUND = 2

OTHERS = 3.



*---here the internal table will have all the files in the directory

LOOP AT IT_FILE.

CONCATENATE P_PATH IT_FILE-NAME INTO P_FILE.

CLEAR ITAB.

REFRESH ITAB.

*--open the file in that directory

OPEN DATASET P_FILE FOR INPUT IN TEXT MODE ENCODING DEFAULT .

IF SY-SUBRC = 0.

*--read the contents in the file

DO.

READ DATASET P_FILE INTO WA.

IF SY-SUBRC NE 0.

EXIT.

ENDIF.

ITAB-REC = WA.

*---append the contents into an internal table

APPEND ITAB.

ENDDO.

ENDIF.

CLOSE DATASET P_FILE.

*----display the contents in the file

LOOP AT ITAB.

WRITE:/ ITAB.

ENDLOOP.

ENDLOOP.

ABAP - How To Find Which Field Is Used In Which table.

this can be done by using the transaction code SE15.

1) go to the transaction code se15
2) Select ABAP Dictionary
3) in this Select fields folder
4) then Click on table fields
5) Then you can enter the desired field name ( for example matnr )
6) Run OR press F8.

Here you will get a list containing the field and table name with where it is used .

or this can be done by using where used list .

1) go to transactin Code SE11( ABAP Dictionary)
2) enter the Data table name where-in the respective field (MATNR ) is used eg; MARA
3) Click the where -used list button
4) Check out the box(DB tables) Only .

ABAP - Fetch All The Database Table Entries Without Using T-Code SE11

This is for getting table entries of any table without going in to se11. In my testing server these is no data in some of the tables, due to which the we cant able to test the object efficiently. so client wants us to check the tables which are not having data . we cant go in to se11 and check every table which is empty . this is the coding for checking the table entries .



REPORT Zno_of_entries.



Data: entries type table of TAB512 with header line,

V_NUMBER TYPE SY-INDEX.



parameters: p_table like X030L-TABNAME.



CALL FUNCTION 'RFC_GET_TABLE_ENTRIES'

EXPORTING

table_name = p_table

IMPORTING

NUMBER_OF_ENTRIES = V_NUMBER

TABLES

entries = entries .





WRITE:/ 'no of entries in the table', p_table,' is:' ,V_NUMBER .





*--if the user wants to display the data in the table then

* go to this coding other wise no need .



Loop at entries.

Write: / entries+3(18).

endloop .

ABAP - Ways To Retreive The Deleted Report Program.

check in table VRSD if there is an entry with OBJTYPE = 'REPS' and OBJNAME = name of the deleted program.

If yes, then create a new program in SE80 with the exact same name and revert to the previous version using version management.

If the program is there in the table then you can create a new program with the same name , and activate it and get the older version of the program . this can be done only if you saved the program under a particular package only . There is no case in getting the programs which are saved under the local object once it got deleted.

ABAP - Get All The Obsolete Function Modules Or BAPI's From ECC6.0.

Go to transaction SE16

Enter the table name RODIR and press DISPLAY

Enter the object type as FUNC and the Obsolete field as 'X'.

Press EXECUTE.

Then you will get the list of obsolete function modules in ECC6.0

The obtained list is the obsolete function modules in the SAP system.

ABAP - Uploading Multiple Files At One Time.



There is a function module for this.. UPLOAD FILES to attach the multiple files .

Here is the sample coding for this …

report zmultiple_upload.
tables: t100,
hrp1000,
t77eo,
t778o,
hrp1500,
hrp1520.

*----internal table declarations

data: begin of msgtbl occurs 0.
include structure bdcmsgcoll.
data: end of msgtbl.

data: itab_1500 type hrp1500 occurs 0 with header line,
itab_1520 type hrp1520 occurs 0 with header line,
itab_1500_updt type hrp1500 occurs 0 with header line,
itab_1520_updt type hrp1520 occurs 0 with header line,
file_path_list like rlgrap occurs 1 with header line.

data: begin of wc_in1500 occurs 0,
mandt type hrp1500-mandt,
plvar type hrp1500-plvar,
otype type hrp1500-otype,
objid type hrp1500-objid,
end of wc_in1500.

data: begin of wc_in1520 occurs 0,
mandt type hrp1520-mandt,
plvar type hrp1520-plvar,
otype type hrp1520-otype,
objid type hrp1520-objid,
end of wc_in1520.

*-----variables declaration

data: wa_total_1500 type i,
wa_total_1520 type i,
wa_begda(10) type c,
dos_type type c.

*----selection screen design

parameters: file1500 like rlgrap-filename default 'C:\HRP1500.txt',
file1520 like rlgrap-filename default 'C:\HRP1520.txt',
testrun as checkbox default 'X' .


*---- start of selection

start-of-selection.

if file1500 cs ':' and sy-fdpos = 1.
dos_type = 'X'.

else.

clear dos_type.

endif.

file_path_list-filename = file1500.
append file_path_list.

call function 'UPLOAD_FILES'
exporting
i_filetype = 'ASC'
i_xpc = dos_type
tables
file_all = wc_in1500
tab_file = file_path_list .

if sy-subrc <> 0.
write: / 'FAILED TO UPLOAD DATA FILE. MESSAGE ID:', sy-msgid.
write: / sy-msgv1.
write: / sy-msgv2.
write: / sy-msgv3.
write: / sy-msgv4.
exit.
endif.

refresh file_path_list.

if file1520 cs ':' and sy-fdpos = 1.
dos_type = 'X'.

else.
clear dos_type.

endif.

file_path_list-filename = file1520.
append file_path_list.

call function 'UPLOAD_FILES'
exporting
i_filetype = 'ASC'
i_xpc = dos_type
tables
file_all = wc_in1520
tab_file = file_path_list .

if sy-subrc <> 0.
write: / 'FAILED TO UPLOAD DATA FILE. MESSAGE ID:', sy-msgid.
exit.
endif.


describe table wc_in1500 lines wa_total_1500.
describe table wc_in1520 lines wa_total_1520.

perform update1500.
perform update1520.

end-of-selection.

*&---------------------------------------------------------------------*
*& Form UPDATE1500
*----------------------------------------------------------------------*

form update1500.

loop at wc_in1500.
clear: itab_1500, itab_1500_updt.
write wc_in1500-plvar to itab_1500-plvar.
write wc_in1500-otype to itab_1500-otype.
write wc_in1500-objid to itab_1500-objid.

select single * from hrp1500
where plvar = itab_1500-plvar
and otype = itab_1500-otype
and objid = itab_1500-objid
and istat = itab_1500-istat
and begda = itab_1500-begda
and endda = itab_1500-endda.

if sy-subrc = 0.
move itab_1500 to itab_1500_updt.
append itab_1500_updt.

else.
append itab_1500.
endif.

endloop.

write: / wa_total_1500, 'RECORDS INPUT FROM FILE FOR HRP1500'.

if testrun ne 'X'.
insert hrp1500 from table itab_1500.
write: / sy-dbcnt, 'RECORDS INSERTED INTO HRP1500'.
update hrp1500 from table itab_1500_updt.
write: / sy-dbcnt, 'RECORDS UPDATED IN HRP1500'.
endif.

endform. " UPDATE1500

*&---------------------------------------------------------------------*
*& Form UPDATE1520
*----------------------------------------------------------------------*

form update1520.

loop at wc_in1520.
clear: itab_1520, itab_1520_updt.
write wc_in1520-plvar to itab_1520-plvar.
write wc_in1520-otype to itab_1520-otype.
write wc_in1520-objid to itab_1520-objid.

select single * from hrp1520
where plvar = itab_1520-plvar
and otype = itab_1520-otype
and objid = itab_1520-objid
and istat = itab_1520-istat
and begda = itab_1520-begda
and endda = itab_1520-endda.

if sy-subrc = 0.
move itab_1520 to itab_1520_updt.
append itab_1520_updt.

else.
append itab_1520.
endif.

endloop.

write: / wa_total_1520, 'RECORDS INPUT FROM FILE FOR HRP1520'.

if testrun ne 'X'.
update hrp1520 from table itab_1520_updt.
write: / sy-dbcnt, 'RECORDS UPDATED HRP1520'.
insert hrp1520 from table itab_1520.
write: / sy-dbcnt, 'RECORDS INSERTED INTO HRP1520'.
endif.

endform. " UPDATE1520



ALSO READ:

- Download A File With The Specified Delimit Character Dynamically.

- Download ABAP Source Code & TEXTPOOL To The Desktop.

- Downloading Programs Into A Folder In Presentation Server.

- Download SAP Data In XML Format.

- Download SAPScript Output To PDF File.


RETURN TO MAIN INDEX:

- Sample Programs On Uploading & Downloading Files.

- Sample Programs On HR ABAP.

- Sample Report Programs On ALV List/ Grid Display.

- Sample Programs On Selection Screen.

- Sample Programs On BDC.

.....Back To MAIN INDEX.



ABAP - ALV Subtotals In Different Blocks.

REPORT ztest_alv.



*---type pools

TYPE-POOLS: slis.



*---internal tables

DATA: BEGIN OF it_flight OCCURS 0,

pernr LIKE pa0008-pernr,

begda LIKE pa0008-begda,

endda LIKE pa0008-endda,

ansal LIKE pa0008-ansal,

lga01 LIKE pa0008-lga01,

bet01 LIKE pa0008-bet01,

END OF it_flight,



*--internal tables for alv

it_fieldcat TYPE slis_t_fieldcat_alv,

wa_fcat LIKE LINE OF it_fieldcat,

layout TYPE slis_layout_alv,

it_sort TYPE slis_t_sortinfo_alv,

wa_sort LIKE LINE OF it_sort.



*---start-of-selection .



START-OF-SELECTION.



CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = sy-repid

i_internal_tabname = 'IT_FLIGHT'

i_inclname = sy-repid

CHANGING

ct_fieldcat = it_fieldcat

EXCEPTIONS

inconsistent_interface = 1

program_error = 2.



*----get data

SELECT pernr

begda

endda

ansal

lga01

bet01

FROM pa0008

INTO CORRESPONDING FIELDS OF TABLE it_flight

UP TO 20 ROWS.

.

wa_fcat-do_sum = 'X'.

MODIFY it_fieldcat FROM wa_fcat TRANSPORTING do_sum

WHERE fieldname = 'BET01' .



wa_sort-fieldname = 'PERNR'.

wa_sort-group = '*'.

wa_sort-up = 'X'.

APPEND wa_sort TO it_sort.



wa_sort-fieldname = 'ANSAL'.

wa_sort-subtot = 'X'.

wa_sort-up = 'X'.

APPEND wa_sort TO it_sort.



CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

i_callback_program = sy-repid

is_layout = layout

it_fieldcat = it_fieldcat

it_sort = it_sort

TABLES

t_outtab = it_flight

EXCEPTIONS

program_error = 1.


ALSO READ:

- ALV With Page Numbers & Subtotals.

- Footer Functionality In ALV Reports.

- Calling One ALV From Other ALV Report Program.

- Capture Single & Multiple Row Selction In ALV Report Program.

..... Back To Index On ALV List/ Grid Display.

..... Back To MAIN INDEX.


ABAP - How To Add / Substract Dates, Months, Years To A Given Date.

report zdates.



parameters:p_date type sy-datum ,

p_days type T5A4A-DLYDY,

p_month type T5A4A-DLYMO,

p_year type T5A4A-DLYYR .

skip.



parameters:add type T5A4A-SPLIT radiobutton group g1 ,

sub type T5A4A-SPLIT radiobutton group g1.





data: calc_date type sy-datum,

days type T5A4A-DLYDY,

months type T5A4A-DLYMO,

years type T5A4A-DLYYR ,

sign type T5A4A-SPLIT .



if add = 'X'.

sign = '+'.

else.

sign = '-'.

endif .



CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'

EXPORTING

date = p_date

days = p_days

months = p_month

SIGNUM = sign

years = p_year

IMPORTING

CALC_DATE = CALC_DATE

.

write:/ calc_date .

ABAP - Report Program For Knowing The Default Domain Values.

Here is the simple coding for knowing the domain values for a particular domain.

This can be done by the function module GET_DOMAIN_VALUES .





REPORT zdaomain.

DATA: int_values_table TYPE dd07v OCCURS 0 WITH HEADER LINE.

CALL FUNCTION 'GET_DOMAIN_VALUES'

EXPORTING

domname = 'ACTIO' " Pass the domain name here

text = 'X'

TABLES

values_tab = int_values_table

EXCEPTIONS

no_values_found = 1

OTHERS = 2.



Loop at int_values_table .

write:/ int_values_table-DOMVALUE_L ,

int_values_table-ddtext.

endloop .

ABAP - Report Program To Activate Objects Using Function Module REPS_OBJECT_ACTIVATE.

Hi here is the good example to activate the objects (reports ) using the function module REPS_OBJECT_ACTIVATE





report zactivate.



parameters: p_object type E071-OBJ_NAME .



CALL FUNCTION 'REPS_OBJECT_ACTIVATE'

EXPORTING

object_name = p_object “ report name

OBJECT_TYPE = 'REPS' “ object type ---REPS for the report

EXCEPTIONS

NOT_EXECUTED = 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.



Using this we can activate more number of reports at a time .

ABAP - Deleting ABAP Programs Using Function Module 'RS_DELETE_PROGRAM' .

Hi here is the best example for deleting the program using the function modules.



REPORT zdelete.

parameters:p_prog type sy-repid .


CALL FUNCTION 'RS_DELETE_PROGRAM'

EXPORTING

program = p_prog

SUPPRESS_CHECKS = ' '

SUPPRESS_COMMIT = ' '

SUPPRESS_POPUP = ' '

MASS_DELETE_CALL = ' '

WITH_CUA = 'X'

WITH_DOCUMENTATION = 'X'

WITH_DYNPRO = 'X'

WITH_INCLUDES = ' '

WITH_TEXTPOOL = 'X'

WITH_VARIANTS = 'X'

SKIP_PROGRESS_IND = ' '

FORCE_DELETE_USED_INCLUDES = ' '

EXCEPTIONS

ENQUEUE_LOCK = 1

OBJECT_NOT_FOUND = 2

PERMISSION_FAILURE = 3

REJECT_DELETION = 4

OTHERS = 5

.

IF sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

Else.

Write:/ ‘the program’, p_prog , ‘ was deleted successfully ‘ .

ENDIF

HR ABAP - Get The List Of Employees With Experience.


Here I want to display the employees of a particular service (For Example: I want the get the list of employees those who are having experience between 5 to 6 years ) . For this I have developed a simple report which can able to display the same .

The coding for this is :

REPORT zservice .
*----------------------------------------------------------*
* tables
*----------------------------------------------------------*

TABLES: pernr,
pa0002,
pa0001.

*----------------------------------------------------------*
* info types
*----------------------------------------------------------*

INFOTYPES: 0002,
0001.

*----------------------------------------------------------*
* variables
*----------------------------------------------------------*

DATA: v_age TYPE d,
v_service TYPE d,
v_currentdate TYPE d,
v_currentdate1 TYPE d,
v_years TYPE d,
v_enddate TYPE d .

DATA:service TYPE char2 ,
diff TYPE char2 .

*----------------------------------------------------------*
* internal tables
*----------------------------------------------------------*

DATA: BEGIN OF itab OCCURS 0,
pernr LIKE pa0002-pernr,
begda LIKE pa0002-begda,
endda LIKE pa0002-endda,
nachn LIKE pa0002-nachn,
vorna LIKE pa0002-vorna,
gbdat LIKE pa0002-gbdat,
age TYPE d,
END OF itab.

DATA: BEGIN OF itab1 OCCURS 0,
pernr LIKE pa0001-pernr,
begda LIKE pa0001-begda,
endda LIKE pa0001-endda,
serv TYPE d,
END OF itab1 .

*----------------------------------------------------------*
* selection screen
*----------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME TITLE text-001.
SELECT-OPTIONS:s_pernr FOR pa0002-pernr .
SELECT-OPTIONS: s_serv FOR service OBLIGATORY.
SELECTION-SCREEN END OF BLOCK block1.

*----------------------------------------------------------*
* start of selection
*----------------------------------------------------------*

START-OF-SELECTION .

IF s_serv-high IS INITIAL.
diff = s_serv-low .
CONCATENATE '00' diff '0101' INTO v_currentdate.

ELSE.
diff = s_serv-high - s_serv-low .
CONCATENATE '00' s_serv-low '0101' INTO v_currentdate.

ENDIF.

PERFORM get_data1.
PERFORM get_data2.

*----------------------------------------------------------*
* tables
*----------------------------------------------------------*

END-OF-SELECTION.

IF itab[] IS INITIAL.
WRITE:/ 'NO EMPLOYEE WITH',
v_currentdate+2(2),
'YEARS OF SERVICE' COLOR 7 .
ENDIF.

PERFORM display_emplist.

*&---------------------------------------------------------------------*
*& Form get_data1
*----------------------------------------------------------------------*

FORM get_data1 .

SELECT pernr
begda
endda
vorna
nachn
gbdat
FROM pa0002
INTO CORRESPONDING FIELDS OF TABLE itab
WHERE pernr IN s_pernr
AND begda LE sy-datum
AND endda GE sy-datum .

LOOP AT itab .
itab-age = sy-datum - itab-gbdat .
MODIFY itab TRANSPORTING age .
ENDLOOP .

ENDFORM.

*&---------------------------------------------------------------------*
*& Form display_emplist
*----------------------------------------------------------------------*

FORM display_emplist .

LOOP AT itab1 .
READ TABLE itab WITH KEY pernr = itab1-pernr .

IF s_serv-high IS INITIAL .
IF itab1-serv+2(2) EQ s_serv-low .

WRITE:/1 itab-pernr,
15 itab1-begda ,
30 itab1-endda ,
45 itab-nachn,
65 itab-vorna,
85 itab-gbdat,
98 itab-age+2(2),
109 itab1-serv+2(2) .

ENDIF.

ELSE.
IF itab1-serv+2(2) GE s_serv-low AND itab1-serv+2(2) LE s_serv-high.

WRITE:/1 itab-pernr,
15 itab1-begda ,
30 itab1-endda ,
45 itab-nachn,
65 itab-vorna,
85 itab-gbdat,
98 itab-age+2(2),
109 itab1-serv+2(2) .

ENDIF.
ENDIF.

ENDLOOP.

ENDFORM.

*&---------------------------------------------------------------------*
*& Form get_data2
*----------------------------------------------------------------------*

FORM get_data2 .

SELECT pernr
begda
endda
FROM pa0001
INTO CORRESPONDING FIELDS OF TABLE itab1
FOR ALL ENTRIES IN itab
WHERE pernr = itab-pernr
AND begda LE sy-datum
AND endda GE sy-datum .

LOOP AT itab1 .
v_enddate = itab1-endda .
v_years = sy-datum - itab1-begda.

IF v_years GE v_currentdate AND v_enddate GE '99991231' .
itab1-serv = v_years .
MODIFY itab1 TRANSPORTING serv .
ENDIF .

ENDLOOP.

ENDFORM.

*&---------------------------------------------------------------------*
*& Form top of page
*----------------------------------------------------------------------*

TOP-OF-PAGE.
WRITE:/ 'Personnel no',
15 'join date' ,
30 'last date ',
45 'LAST NAME',
65 'FIRST NAME',
85 'DOB',
98 'EMP AGE',
109 'EMP SERVICE' .
ULINE.



ALSO READ:

- BADI HRECM00_BDG0001 - Upload Initial Budgets From Excel Sheet.

- Get Employee Picture In Selection Screen.

- Unified Access to All HR Infotypes.

- F4(Value On Request) For Organization Unit In HR Report Program.

- Employee Pay Scale Report Program.

.....Back To Sub-Index On HR ABAP.

.....Back To MAIN INDEX.


ABAP - Disapperaing SAPGUI For Some Defined Time & Then Bringing It Back Using 'SAPGUI_SET_PROPERTY'

Here is an example for disappearing the SAPGUI for some defined time , and then bringing the SAPGUI back .

REPORT ZSAPGUI .

START-OF-SELECTION.

*SAPGUI screen vanishes from user screen list

CALL FUNCTION 'SAPGUI_SET_PROPERTY'

DESTINATION 'SAPGUI'

EXPORTING

property = 'VISIBLE'

value = ' '

EXCEPTIONS

system_failure = 1

communication_failure = 2

OTHERS = 3.

* make disappering the sapgui for the below time

WAIT UP TO 10 SECONDS.

CALL FUNCTION 'TH_REDISPATCH'.

*wake up the SAPGUI screen

CALL FUNCTION 'SAPGUI_SET_PROPERTY'

DESTINATION 'SAPGUI'

EXPORTING

property = 'VISIBLE'

value = 'X'

EXCEPTIONS

system_failure = 1

communication_failure = 2

OTHERS = 3.

ABAP - Report Program To Display Contents Of IDOC Using Function Module IDOC_READ_COMPLETELY.

*----------------------------------------------------------------------*

* reprot name : ZDISPLAY *

* reprot date : 22/10/2008 *

* description : here is an example program for dislaying the contents *

* of given idoc in a report . if you check the check box *

* in the selection screen then it will download the data *

* into a spread sheet *

*----------------------------------------------------------------------*

REPORT zdisplay LINE-SIZE 275.





TYPE-POOLS : ledid.



DATA: struct_type TYPE ledid_struct_type ,

idoc_struct TYPE ledid_t_idoc_struct,

segments TYPE ledid_t_segment,

segment_struct TYPE ledid_t_segment_struct,

idoc_control LIKE edidc,

number_of_data_records LIKE sy-dbcnt,

number_of_status_records LIKE sy-dbcnt,



int_edids LIKE edids OCCURS 0 WITH HEADER LINE,

int_edidd LIKE edidd OCCURS 0 WITH HEADER LINE,

excel_tab(2000) OCCURS 0 WITH HEADER LINE.





PARAMETER: docnum LIKE edidc-docnum OBLIGATORY, ""Idoc Number

sap_rel LIKE sy-saprl DEFAULT sy-saprl OBLIGATORY,

pi_ver LIKE edi_verrec-version DEFAULT '3'

OBLIGATORY,

d_excel AS CHECKBOX DEFAULT 'X'. ""Download ?



START-OF-SELECTION.



PERFORM read_idoc.



PERFORM process_idoc.



IF d_excel = 'X'.

PERFORM download_to_excel.

ENDIF.



END-OF-SELECTION.



*&---------------------------------------------------------------------*

*& Form read_idoc

*----------------------------------------------------------------------*

FORM read_idoc.



CALL FUNCTION 'IDOC_READ_COMPLETELY'

EXPORTING

document_number = docnum

IMPORTING

idoc_control = idoc_control

number_of_data_records = number_of_data_records

number_of_status_records = number_of_status_records

TABLES

int_edids = int_edids

int_edidd = int_edidd

EXCEPTIONS

document_not_exist = 1

document_number_invalid = 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.



ENDFORM. "" read_idoc



*&---------------------------------------------------------------------*

*& Form process_idoc

*----------------------------------------------------------------------*

FORM process_idoc.



PERFORM read_idoc_structure.



PERFORM display_data_records.



ENDFORM. "" process_idoc



*&---------------------------------------------------------------------*

*& Form display_data_records

*----------------------------------------------------------------------*

FORM display_data_records.



DATA: pe_seg_header LIKE edi_sapi01,

segname LIKE edi_iapi12-segmenttyp,

prev_segname LIKE edi_iapi12-segmenttyp VALUE ' ',

pt_fields2 LIKE edi_iapi12 OCCURS 0 WITH HEADER LINE,

pt_fvalues2 LIKE edi_iapi14 OCCURS 0 WITH HEADER LINE,

byte_first TYPE i,

byte_last TYPE i,

field_val type char50,

tmp_str type char15,

tmp_str3 type char15,

seg_repeats TYPE i VALUE 0,

tmp_str2 type char15,

tab_cr(1) TYPE x VALUE '09',

tot_ctr TYPE i VALUE 0,

ctr TYPE i VALUE 0,

msg(40) TYPE c.



DATA: idoc_struct_wa TYPE ledid_idoc_struct.



SORT int_edidd BY segnum.



DESCRIBE TABLE int_edidd LINES tot_ctr.



LOOP AT int_edidd.



MOVE int_edidd-segnam TO segname.



CLEAR msg.



CONCATENATE 'Reading segment ' segname

INTO msg SEPARATED BY space.



IF tot_ctr <> 0.

ctr = ( 100 * sy-tabix ) / tot_ctr.

ENDIF.



CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

EXPORTING

percentage = ctr

text = msg.

ADD 1 TO seg_repeats.

CLEAR tmp_str2.

IF int_edidd-segnam <> prev_segname.

seg_repeats = 1.

CLEAR: pe_seg_header,

pt_fields2,

pt_fvalues2.



REFRESH: pt_fields2,

pt_fvalues2.



CALL FUNCTION 'SEGMENT_READ_COMPLETE'

EXPORTING

pi_segtyp = segname

pi_release = sap_rel

pi_version = pi_ver

IMPORTING

pe_header = pe_seg_header

TABLES

pt_fields = pt_fields2

pt_fvalues = pt_fvalues2

EXCEPTIONS

segment_unknown = 1

segment_structure_unknown = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.



prev_segname = int_edidd-segnam.



ENDIF.



READ TABLE idoc_struct INTO idoc_struct_wa WITH KEY

segment_type = int_edidd-segnam.



IF sy-subrc = 0.

IF idoc_struct_wa-syntax_attrib-mustfl = 'X'.

tmp_str = 'Mandatory'. ""Mandatory

ELSE.

tmp_str = 'Optional'. ""Optional

ENDIF.



IF idoc_struct_wa-segment_type_attrib-qualifier = 'X'.

tmp_str3 = 'Qualified'.

ELSE.

tmp_str3 = 'Non-Qualified'.

ENDIF.



SHIFT idoc_struct_wa-syntax_attrib-occmax

LEFT DELETING LEADING '0'.

MOVE seg_repeats TO tmp_str2.



CONDENSE: idoc_struct_wa-syntax_attrib-occmax, tmp_str2.



CONCATENATE tmp_str2 'of' idoc_struct_wa-syntax_attrib-occmax

INTO tmp_str2 SEPARATED BY space.



WRITE :/ idoc_struct_wa-segment_type,

tmp_str,

tmp_str3,

tmp_str2,

idoc_struct_wa-syntax_attrib-hlevel,

idoc_struct_wa-segment_type_attrib-plast,

idoc_struct_wa-segment_type_attrib-descrp.



IF d_excel = 'X'.

CONCATENATE 'Segment Name' tab_cr

'Mand / Opt ' tab_cr

'Qual / non-Qual' tab_cr

'Seq of Max' tab_cr

'Level' tab_cr

'Owner' tab_cr

'Description'

INTO excel_tab.

APPEND excel_tab.

CONCATENATE idoc_struct_wa-segment_type tab_cr

tmp_str tab_cr

tmp_str3 tab_cr

tmp_str2 tab_cr

idoc_struct_wa-syntax_attrib-hlevel tab_cr

idoc_struct_wa-segment_type_attrib-plast tab_cr

idoc_struct_wa-segment_type_attrib-descrp

INTO excel_tab.

APPEND excel_tab.

CONCATENATE tab_cr

'Field Nma' tab_cr

'Type' tab_cr

'Length' tab_cr

'Byte From' tab_cr

'Byte To' tab_cr

'Description' tab_cr

'Value' tab_cr

'Qualifier Meaning'

INTO excel_tab.

APPEND excel_tab.

ENDIF.

ENDIF.



SORT pt_fields2 BY field_pos.



byte_first = 0.



LOOP AT pt_fields2.

CLEAR: field_val.

byte_last = pt_fields2-extlen.

WRITE int_edidd-sdata+byte_first(byte_last) TO

field_val LEFT-JUSTIFIED.

SHIFT pt_fields2-extlen LEFT DELETING LEADING '0'.

SHIFT pt_fields2-byte_first LEFT DELETING LEADING '0'.

SHIFT pt_fields2-byte_last LEFT DELETING LEADING '0'.

WRITE:/ ' ', pt_fields2-fieldname,

pt_fields2-datatype,

pt_fields2-extlen,

pt_fields2-byte_first ,

pt_fields2-byte_last,

pt_fields2-descrp,

field_val.

READ TABLE pt_fvalues2 WITH KEY fieldname = pt_fields2-fieldname

fldvalue_l = field_val.

ADD byte_last TO byte_first.

IF sy-subrc = 0.

WRITE : pt_fvalues2-descrp.

ELSE.

CLEAR pt_fvalues2-descrp.

ENDIF.

IF d_excel = 'X'.

CONCATENATE tab_cr pt_fields2-fieldname tab_cr

pt_fields2-datatype tab_cr

pt_fields2-extlen tab_cr

pt_fields2-byte_first tab_cr

pt_fields2-byte_last tab_cr

pt_fields2-descrp tab_cr

field_val tab_cr

pt_fvalues2-descrp

INTO excel_tab.

APPEND excel_tab.

ENDIF.

ENDLOOP.

ENDLOOP.

ENDFORM. "" display_data_records



*&---------------------------------------------------------------------*

*& Form read_idoc_structure

*----------------------------------------------------------------------*

FORM read_idoc_structure.

DATA: idoctype TYPE ledid_idoctype.



IF NOT idoc_control-cimtyp IS INITIAL.

struct_type = 'E'. ""Extended

idoctype = idoc_control-cimtyp.

ELSE.

struct_type = 'B'. ""Basic

idoctype = idoc_control-idoctp.

ENDIF.



CALL FUNCTION 'IDOC_TYPE_COMPLETE_READ'

EXPORTING

release = sap_rel

struct_type = struct_type

idoctype = idoctype

version = pi_ver

TABLES

idoc_struct = idoc_struct

segments = segments

segment_struct = segment_struct

EXCEPTIONS

idoctype_unknown = 1

idocstruct_unknown = 2

segment_data_missing = 3

illegal_struct_type = 4

OTHERS = 5.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.



ENDFORM. "" read_idoc_structure



*&---------------------------------------------------------------------*

*& Form download_to_excel

*----------------------------------------------------------------------*

FORM download_to_excel.

DATA: name LIKE rlgrap-filename.



SHIFT docnum LEFT DELETING LEADING '0'.

CONCATENATE docnum '-' idoc_control-idoctp '.xls'

INTO name.



CALL FUNCTION 'RH_START_EXCEL_WITH_DATA'

EXPORTING

data_name = name

data_type = 'ASC'

wait = ' '

TABLES

data_tab = excel_tab

EXCEPTIONS

no_batch = 1

excel_not_installed = 2

wrong_version = 3

internal_error = 4

invalid_type = 5

cancelled = 6

download_error = 7

OTHERS = 8.

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. "" download_to_excel

ABAP - Interface Program To Create Required Number Of Jobs For A Given Path In The Application Server.

*-----------------------------------------------------------------------
* Here is an interface program to create the required no of jobs
* automatically with the given path in the application server by
* specifying filename no of files to be created and sites and
* article range
*-----------------------------------------------------------------------
REPORT zmio_manu_onhand_extr LINE-SIZE 180
LINE-COUNT 65
NO STANDARD PAGE HEADING
MESSAGE-ID zr.
*-----------------------------------------------------------------------
* database tables
*-----------------------------------------------------------------------

TABLES: t001w ,
mard .
*-----------------------------------------------------------------------
* variables
*-----------------------------------------------------------------------
DATA: g_lines LIKE sy-tabix,
g_read LIKE sy-tabix,
g_filename LIKE edi_path-pthnam,
g_records TYPE sy-tabix,
g_total_rec TYPE i,
g_fileno TYPE i,
v_records TYPE i,
v_fileno(3) TYPE c .
*-----------------------------------------------------------------------
* internal tables
*-----------------------------------------------------------------------
*---table for sites
TYPES: BEGIN OF ty_t001w ,
werks TYPE werks_d,
END OF ty_t001w.
*--types for plant store
TYPES:BEGIN OF ty_mard ,
matnr LIKE mard-matnr,
werks LIKE mard-werks,
lgort LIKE mard-lgort,
END OF ty_mard.
*---database tables
DATA: it_t001w TYPE STANDARD TABLE OF ty_t001w WITH HEADER LINE,
it_exp_t001w TYPE STANDARD TABLE OF ty_t001w WITH HEADER LINE,
it_mard TYPE STANDARD TABLE OF ty_mard WITH HEADER LINE .
*-----------------------------------------------------------------------
* selection screen
*-----------------------------------------------------------------------
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME .
SELECT-OPTIONS:s_matnr FOR mard-matnr, "articles
s_werks FOR t001w-werks. "plant
PARAMETERS: p_file1(45) TYPE c , "filename
p_numjob(3) TYPE n . "no of jobs to be created
SELECTION-SCREEN: END OF BLOCK b1.
*-----------------------------------------------------------------------
* ranges
*-----------------------------------------------------------------------
*--ranges for plant
RANGES: r_werks FOR t001w-werks.

*----------------------------------------------------------------------*
* AT SELECTION SCREEN
*----------------------------------------------------------------------*
AT SELECTION-SCREEN .
*---if there is no message raise a message to enter file name
IF p_file1 IS INITIAL.
MESSAGE i001 WITH 'Enter File Name'.
ENDIF.
*---if the no of jobs to be create field is initial raise a message to enter a value
IF p_numjob EQ space.
MESSAGE i001 WITH 'Enter a valid no of files to be created'.
ENDIF.
*-----------------------------------------------------------------------
* start of selection
*-----------------------------------------------------------------------

START-OF-SELECTION.
*---write the header of the output with filename and no of records downloaded
PERFORM header_name.
*--get the data for the plants
PERFORM get_data.
*--process the data for creating the file in application server
PERFORM process_data .

*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
FORM get_data .

REFRESH:it_t001w.
*---get data for plants
SELECT werks
FROM t001w
INTO TABLE it_t001w
WHERE werks IN s_werks.
IF NOT it_t001w[] IS INITIAL.
SORT it_t001w BY werks.
*---count the no of records from plant table
DESCRIBE TABLE it_t001w LINES g_lines.
ENDIF.

ENDFORM. " get_data
*&---------------------------------------------------------------------*
*& Form process_data
*&---------------------------------------------------------------------*
FORM process_data .

*---get the no of plant records per job
g_read = g_lines / p_numjob.
*---this is to avoid the short dump
IF g_read = 0.
g_read = 1.
ENDIF.

CLEAR g_lines.
g_lines = p_numjob.

*--processing of the job
DO.
*---if the number of jobs to be create is greate than one
IF g_lines > 1.
*---send some of the records to the first job to process
APPEND LINES OF it_t001w FROM 1 TO g_read TO it_exp_t001w.

REFRESH r_werks.
*---fill the records into the ranges to be processed for first job
PERFORM fill_range.
*---get the the file no
ADD 1 TO g_fileno.

v_fileno = g_fileno.

CONCATENATE p_file1 '\test' v_fileno INTO g_filename.
*---get the filename with path
CONDENSE g_filename NO-GAPS.
*---get the no articles from the plants selected in the ranes
PERFORM get_mard_data.

CLEAR: it_exp_t001w, it_exp_t001w[].
*---decrease the no of jobs by one
g_lines = g_lines - 1.
*---check for further processing
IF it_t001w[] IS INITIAL.
g_lines = 0.
ENDIF.
*---if the no of jobs to be created is one
ELSEIF g_lines = 1.
*---send all the records to one internal table
APPEND LINES OF it_t001w TO it_exp_t001w.

REFRESH r_werks.
*---get the records in ranges
PERFORM fill_range.
REFRESH IT_MARD.
PERFORM get_mard_data.
CLEAR: it_exp_t001w, it_exp_t001w[], it_t001w[].
*--check for further processing
CHECK it_t001w[] IS INITIAL.
EXIT.
ELSE.
CHECK it_t001w[] IS INITIAL.
EXIT.
ENDIF.
ENDDO.

ENDFORM. " process_data
*&---------------------------------------------------------------------*
*& Form get_mard_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text *----------------------------------------------------------------------* FORM get_mard_data . REFRESH: it_mard. SELECT matnr werks lgort FROM mard INTO TABLE it_mard FOR ALL ENTRIES IN it_t001w WHERE werks = it_t001w-werks. IF NOT it_mard[] IS INITIAL. SORT it_mard BY werks. *----write the file into application server PERFORM write_file. ENDIF. ENDFORM. " get_mard_data *&---------------------------------------------------------------------* *& Form write_file *&---------------------------------------------------------------------* FORM write_file . DATA: outrec(100) TYPE c. *---get the no of records from the mard table DESCRIBE TABLE it_mard LINES v_records. *---open file in appilication server to write these records OPEN DATASET g_filename FOR OUTPUT IN TEXT MODE ENCODING DEFAULT. IF sy-subrc NE 0. EXIT. ENDIF. LOOP AT it_mard. outrec+0(18) = it_mard-matnr. outrec+25(4) = it_mard-werks. outrec+40(16) = it_mard-lgort. TRANSFER outrec TO g_filename . ENDLOOP. *---write the file name and no of records downloaded PERFORM file_name. *---close the file in application server CLOSE DATASET g_filename. ENDFORM. " write_file *&---------------------------------------------------------------------* *& Form fill_range *&---------------------------------------------------------------------* FORM fill_range . LOOP AT it_exp_t001w. r_werks-low = it_exp_t001w-werks. r_werks-sign = 'I'. r_werks-option = 'EQ'. APPEND r_werks. ENDLOOP. DELETE it_t001w FROM 1 TO g_read. ENDFORM. " fill_range *&---------------------------------------------------------------------* *& Form header_name *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM header_name .
WRITE:/1(130) sy-uline .
WRITE:/1 sy-vline,
2 'CREATED FILENAME' COLOR 7,
62 sy-vline,
64 'NO OF SUCCESSFUL RECORDS IN THIS FILE ' COLOR 7 ,
130 sy-vline.
WRITE:/1(130) sy-uline .
ENDFORM. " header_name
*&---------------------------------------------------------------------*
*& Form FILE_NAME
*&---------------------------------------------------------------------*
FORM file_name .

WRITE:/1(130) sy-uline .

WRITE:/1 sy-vline,
2 g_filename,
62 sy-vline,
64 v_records,
130 sy-vline.

WRITE:/1(130) sy-uline .

ENDFORM. " FILE_NAME

ABAP - ICON'S, Symbols, Top Of Page, End Of Page In ALV Grid/List Display.

REPORT ysubalv.

*-------------------------------------------------------------------
* type-pools
*-------------------------------------------------------------------

TYPE-POOLS: slis.
*-------------------------------------------------------------------
* variables
*-------------------------------------------------------------------

* To pass name of the report in function module for ALV
DATA: v_repid LIKE sy-repid .

*-------------------------------------------------------------------
* internal table
*-------------------------------------------------------------------

* To pass the overall structure of the ALV report
DATA: struct_layout TYPE slis_layout_alv.
DATA: struct_layout1 TYPE slis_layout_alv.

* Internal table to capture various events in ALV
DATA : i_events TYPE slis_t_event.

* Table for catalog of the fields to be displayed
DATA: i_fieldcat TYPE slis_t_fieldcat_alv.
DATA : x_fieldcat TYPE slis_fieldcat_alv.

DATA: i_fieldcat1 TYPE slis_t_fieldcat_alv.
DATA : x_fieldcat1 TYPE slis_fieldcat_alv.

* Internal table to mention the sort sequence
DATA : it_sort TYPE slis_t_sortinfo_alv.
DATA : x_sort TYPE slis_sortinfo_alv.

* Internal table to display top of page
DATA : i_list_top_of_page TYPE slis_t_listheader.

* Structure to display variants
DATA : i_variant LIKE disvariant,
i_variant1 LIKE disvariant.

* Internal table to pass data
DATA: BEGIN OF i_tab OCCURS 0,
mblnr LIKE mseg-mblnr ,
matnr LIKE mseg-matnr,
maktg LIKE makt-maktg ,
charg LIKE mseg-charg ,
werks LIKE mseg-werks,
lgort LIKE mseg-lgort,
menge LIKE mseg-menge ,
meins LIKE mseg-meins ,
dmbtr LIKE mseg-dmbtr,
ebeln LIKE mseg-ebeln,
icn(4) TYPE c ,
sym(4) TYPE c ,
excpt(2) TYPE c ,
box(1),
END OF i_tab.

DATA : BEGIN OF i_doc OCCURS 0 .
INCLUDE STRUCTURE mseg.
DATA : END OF i_doc.

*-------------------------------------------------------------------
* selection screen
*-------------------------------------------------------------------

PARAMETERS : p_var LIKE disvariant-variant.
*-------------------------------------------------------------------
* initialization
*-------------------------------------------------------------------

INITIALIZATION.

v_repid = sy-repid.

* Display default variant
PERFORM sub_variant_init.
*-------------------------------------------------------------------
* at selection screen on field
*-------------------------------------------------------------------

AT SELECTION-SCREEN ON p_var.
* Once the user has entered variant, check about its existence
PERFORM sub_check_pvar.
*-------------------------------------------------------------------
* at selection screen value help for field
*-------------------------------------------------------------------

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_var.
* Display a list of various variants of the report when the
* user presses F4 key in the variant field
PERFORM sub_variant_f4.

*-------------------------------------------------------------------
* start of selection
*-------------------------------------------------------------------

START-OF-SELECTION.
* Prepare field catalog for the main report. State the name of
* the field , name of internal table , various formatting options etc
PERFORM sub_prepare_fieldcatalog.

* Fetches records from database into table i_tab to be passed as export
* parameter t_outtab in function module : REUSE_ALV_GRID_DISPLAY
PERFORM sub_select_record.

* Populate stat and icon columns of internal table i_tab with specific
* columns and symbols based on some logic for quantity and value fields.
PERFORM sub_modify_records.

* Defines the overall layout of the report
PERFORM sub_determine_alv_layout.

* Defines the sort sequence of the report
PERFORM sub_determine_sort_sequence.

* Defines the event table
PERFORM sub_eventtab_build USING i_events.

* Things to be written at the top of the page
PERFORM sub_comment_build USING i_list_top_of_page.

* Display the ALV list
PERFORM sub_show_alv_list.

*-------------------------------------------------------------------
* at line selection
*-------------------------------------------------------------------

AT LINE-SELECTION.

PERFORM sub_hotspot.


*&---------------------------------------------------------------------*
*& Form SUB_VARIANT_INIT
*&---------------------------------------------------------------------*
* Display default variant
*----------------------------------------------------------------------*
FORM sub_variant_init.
i_variant1-report = sy-repid.

* Search default variant for the report
CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
i_save = 'A'
CHANGING
cs_variant = i_variant1
EXCEPTIONS
not_found = 2.
* If default variant is found , use it as default.
* Else , use the variant LAYOUT1.
IF sy-subrc = 0.
p_var = i_variant1-variant.
ELSE.
p_var = 'LAYOUT1'.
ENDIF.

ENDFORM. " SUB_VARIANT_INIT

*&---------------------------------------------------------------------*
*& Form SUB_CHECK_PVAR
*&---------------------------------------------------------------------*
* Once the user has entered variant, check about its existence
*----------------------------------------------------------------------*
FORM sub_check_pvar.
* If the name of the variable is not blank, check about its existence
IF NOT p_var IS INITIAL.
CLEAR i_variant.
i_variant-report = sy-repid.
i_variant-variant = p_var.
CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
EXPORTING
i_save = 'A'
CHANGING
cs_variant = i_variant.
* If no such variant found , flash error message
IF sy-subrc NE 0 .
MESSAGE e398(00) WITH 'No such variant exists'.
ELSE.
* If variant exists , use the variant name to populate structure
* I_VARIANT1 which will be used for export parameter : IS_VARIANT
* in the function module : REUSE_ALV_GRID_DISPLAY
CLEAR i_variant1.
MOVE p_var TO i_variant1-variant.
MOVE sy-repid TO i_variant1-report.
ENDIF.
ELSE.
CLEAR i_variant.
ENDIF.
ENDFORM. " SUB_CHECK_PVAR

*&---------------------------------------------------------------------*
*& Form SUB_PREPARE_FIELDCATALOG
*&---------------------------------------------------------------------*
* Prepare field catalog for the main report. State the name of
* the field , name of internal table , various formatting options etc
*----------------------------------------------------------------------*
FORM sub_prepare_fieldcatalog.

* First field to appear in ALV list
x_fieldcat-col_pos = 1.
* Name of the internal table field
x_fieldcat-fieldname = 'SYM'.
* Name of the internal table
x_fieldcat-tabname = 'I_TAB'.
* Heading for the field
x_fieldcat-seltext_m = 'Stat'.
* The field is going to contain a symbol
x_fieldcat-symbol = 'X'.
* Append the specifications to the internal table for field catalog.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.


* Second field to appear in ALV list
x_fieldcat-col_pos = 2.
* Name of the field in the internal table
x_fieldcat-fieldname = 'MATNR'.
* Name of the internal table
x_fieldcat-tabname = 'I_TAB'.
* Heading for the column
x_fieldcat-seltext_m = 'MatItem'.
* It is going to be the key field.The color for this field is going to
* be different
x_fieldcat-key = 'X'.
x_fieldcat-key_sel = 'X'.
* Single click on the field will trigger double click event.Also, a hand
* will appear when the cursor navigates to the field
x_fieldcat-hotspot = 'X'.
* The column and those left to it will not scroll
x_fieldcat-fix_column = 'X'.
* F1 help will come as it is referenced to DDIC table
x_fieldcat-ref_tabname = 'MSEG'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.


x_fieldcat-col_pos = 3.
x_fieldcat-fieldname = 'MAKTG'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Description'.
* The field is centre(C for centre, R and L for left and
* right) justified
x_fieldcat-just = 'C'.
x_fieldcat-key = 'X'.
x_fieldcat-fix_column = 'X'.
* X_fieldcat-no_out = 'X'.
x_fieldcat-fix_column = 'X'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.


x_fieldcat-col_pos = 4.
x_fieldcat-fieldname = 'CHARG'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Batch'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.


x_fieldcat-col_pos = 5.
x_fieldcat-fieldname = 'EBELN'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Purchase Order'.
* The field will be colored differently(Cxyz)
x_fieldcat-emphasize = 'C511'.
* Initially the field will be hidden
x_fieldcat-no_out = 'X'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.


x_fieldcat-col_pos = 6.
x_fieldcat-fieldname = 'MBLNR'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Document no'.
x_fieldcat-emphasize = 'C711'.
x_fieldcat-no_out = 'X'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.


x_fieldcat-col_pos = 7.
x_fieldcat-fieldname = 'WERKS'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Plant'.
x_fieldcat-emphasize = 'C310'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.


x_fieldcat-col_pos = 8.
x_fieldcat-fieldname = 'LGORT'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'St.Loc'.
x_fieldcat-no_out = 'X'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.


x_fieldcat-col_pos = 9.
x_fieldcat-fieldname = 'MENGE'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Quantity'.
x_fieldcat-outputlen = 12.
* Summation is allowed for this field
x_fieldcat-do_sum = 'X'.
x_fieldcat-ref_tabname = 'MSEG'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.


x_fieldcat-col_pos = 10.
x_fieldcat-fieldname = 'ICN'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = ''.
x_fieldcat-outputlen = 2.
x_fieldcat-no_out = 'X'.
x_fieldcat-icon = 'X'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.

x_fieldcat-col_pos = 11.
x_fieldcat-fieldname = 'MEINS'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Unit'.
x_fieldcat-qfieldname = 'MEINS'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.

x_fieldcat-col_pos = 12.
x_fieldcat-fieldname = 'DMBTR'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Local curr'.
x_fieldcat-outputlen = 12.
x_fieldcat-inttype = 'P'.
x_fieldcat-just = 'R'.
x_fieldcat-do_sum = 'X'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.

x_fieldcat-col_pos = 13.
x_fieldcat-fieldname = 'EXCPT'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-no_out = 'X'.
x_fieldcat-outputlen = 3.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.


ENDFORM. " SUB_PREPARE_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form SUB_SELECT_RECORD
*&---------------------------------------------------------------------*
* Fetches records from database into table i_tab to be passed as export
* parameter t_outtab in function module : REUSE_ALV_GRID_DISPLAY
*----------------------------------------------------------------------*
FORM sub_select_record.
SELECT b~mblnr
a~matnr
a~maktg
b~charg
b~werks
b~lgort
b~menge
b~meins
b~dmbtr
b~ebeln
FROM makt AS a JOIN mseg AS b
ON ( a~matnr = b~matnr )
INTO TABLE i_tab
UP TO 300 ROWS
WHERE b~bwart = '101' .

ENDFORM. " SUB_SELECT_RECORD
*&---------------------------------------------------------------------*
*& Form SUB_MODIFY_RECORDS
*&---------------------------------------------------------------------*
* Populate stat and icon columns of internal table i_tab with specific
* columns and symbols based on some logic for quantity and value fields.
*----------------------------------------------------------------------*
FORM sub_modify_records.

LOOP AT i_tab.
IF i_tab-dmbtr GT 10000.
* Field icn of internal table is going to contain icon . For this column
*icon_allowed is set in the field catalog table. For various icons,see
* type pool
i_tab-icn = ' (1V)'.
MODIFY i_tab TRANSPORTING icn.
ENDIF.
IF i_tab-menge GT 50.
* Field icn of internal table is going to contain symbol . For this
* column symbol_allowed is set in the field catalog table. For various
* icons,see type pool
i_tab-sym = 'N'.
MODIFY i_tab TRANSPORTING sym.
ENDIF.

IF i_tab-werks NE 'SDC1'.
* This field will contain lights , traffic signals : red.yellow,green
* That this field will be used as a light will be specified in the
* column of structure STRUCT_LAYOUT.
i_tab-excpt = '1'.
MODIFY i_tab TRANSPORTING excpt.
ENDIF.
ENDLOOP.

ENDFORM. " SUB_MODIFY_RECORDS

*&---------------------------------------------------------------------*
*& Form SUB_DETERMINE_ALV_LAYOUT *
*&---------------------------------------------------------------------*
*& Defines the overall structure of the report layout *
*----------------------------------------------------------------------*
FORM sub_determine_alv_layout.
* Field EXCPT will show the light signal
struct_layout-lights_fieldname = 'EXCPT'.
* Field BOS of the internal table will act as pushbutton and will appear
* at the left of the grid display. User will press that to select a
* record
struct_layout-box_fieldname = 'BOX'.
struct_layout-totals_text = 'Totqty '.
struct_layout-zebra = 'X'.
struct_layout-confirmation_prompt = 'X'.
struct_layout-detail_titlebar = 'Details of Storing'.
struct_layout-no_sumchoice = 'X'.
struct_layout-totals_only = 'X'.
ENDFORM. " SUB_DETERMINE_ALV_LAYOUT
*&---------------------------------------------------------------------*
*& Form SUB_DETERMINE_SORT_SEQUENCE
*&---------------------------------------------------------------------*
* Defines the sort sequence of the report
*----------------------------------------------------------------------*
FORM sub_determine_sort_sequence.
x_sort-spos = 1. " Sort order
x_sort-fieldname = 'MATNR'.
x_sort-tabname = 'I_TAB'.
x_sort-up = 'X'.
x_sort-subtot = 'X'. " Sub total allowed

APPEND x_sort TO it_sort.
CLEAR x_sort.

ENDFORM. " SUB_DETERMINE_SORT_SEQUENCE
*&---------------------------------------------------------------------*
*& Form SUB_SHOW_ALV_LIST
*&---------------------------------------------------------------------*
* Shows ALV list in grid form
*----------------------------------------------------------------------*
FORM sub_show_alv_list.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* Name of the program
i_callback_program = v_repid
* title
i_grid_title = 'Details of Storing'
* calls subroutine : PF_STATUS_SET
i_callback_pf_status_set = 'PF_STATUS_SET'
* Calls subroutine : user_command
i_callback_user_command = 'USER_COMMAND'
* Overall structure of the report
is_layout = struct_layout
* Passes the field catg internal table
it_fieldcat = i_fieldcat
* Passws the sort sequence internal table
it_sort = it_sort
i_default = 'X'
i_save = 'A'
* Passes the internal table for variants
is_variant = i_variant1
* fetches different events into internal table i_events
it_events = i_events[]
TABLES
* Passes data table for ALV display
t_outtab = i_tab
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. " SUB_SHOW_ALV_LIST

*&---------------------------------------------------------------------*
*& Form set_status
*&---------------------------------------------------------------------*
* Form used to set the Custom pf-status of the List Display
*----------------------------------------------------------------------*
* rt_extab :
*----------------------------------------------------------------------*
FORM pf_status_set USING i_rt_extab TYPE slis_t_extab.
DATA : x_extab TYPE slis_extab.
x_extab-fcode = '&LFO'.
APPEND x_extab TO i_rt_extab.
* Pf-status STANDARD of program SAPLSALV is copied to ZSTANDARD of the
* current program and the pushbutton for Information (okcode=&LFO) is
* excluded
SET PF-STATUS 'ZSTANDARD' EXCLUDING i_rt_extab .

ENDFORM. "pf_status_set

*&---------------------------------------------------------------------*
*& Form user_command
*&---------------------------------------------------------------------*
* Form used to handle USER_COMMAND events
*----------------------------------------------------------------------*
* rf_ucomm: Function Code
* rs : Internal Table containing the selection information.
*----------------------------------------------------------------------*

FORM user_command USING rf_ucomm LIKE sy-ucomm
rs TYPE slis_selfield.
DATA : v_mblnr LIKE mseg-mblnr.
CASE rf_ucomm.

* A custom pushbutton for record deletion is set in the GUI status.
* When a record is selected , the field BOC for that record becomes 'X'.
* The records are traced and deleted and the fields are refreshed( rs
* of type slis_selfield is refreshed)
WHEN '&DEL'. "Print button clicked.
DELETE i_tab WHERE box = 'X'.
rs-refresh = 'X'.

* When the user selects a row and presses the Select pushbutton ( user
* defined ) from the application toolbar, the details of the document
* will be shown in another ALV list
WHEN '&SEL'.
PERFORM sub_select_document.

* set parameter id 'MBN' field i_tab-mblnr.
* call transaction 'MB03'.

* Ok code for double click is &IC1 for ALV report
WHEN '&IC1'.
PERFORM sub_hotspot.
ENDCASE.

ENDFORM. "user_command
*&---------------------------------------------------------------------*
*& Form SUB_HOTSPOT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text *----------------------------------------------------------------------*
FORM sub_hotspot.

MESSAGE i398(00) WITH 'Hello'.
ENDFORM. " SUB_HOTSPOT

*&---------------------------------------------------------------------*
*& Form SUB_VARIANT_F4
*&---------------------------------------------------------------------*
* Display a list of various variants of the report when the
* user presses F4 key in the variant field
*----------------------------------------------------------------------*
FORM sub_variant_f4.

i_variant-report = sy-repid.
* Utilising the name of the report , this function module will
* search for a list of variants and will fetch the selected one into
* the parameter field for variants

CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
is_variant = i_variant
i_save = 'A'
i_display_via_grid = 'X'

IMPORTING
es_variant = i_variant1

EXCEPTIONS
not_found = 1
program_error = 2
OTHERS = 3.

IF sy-subrc = 0.
p_var = i_variant1-variant.
ENDIF.
ENDFORM. " SUB_VARIANT_F4

*&---------------------------------------------------------------------*
*& Form SUB_SELECT_DOCUMENT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text *----------------------------------------------------------------------*
FORM sub_select_document.

DATA : v_lines TYPE i .

READ TABLE i_tab WITH KEY box = 'X'.
SELECT * FROM mseg INTO TABLE i_doc WHERE mblnr = i_tab-mblnr.

IF sy-subrc EQ 0 .
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = v_repid
i_internal_tabname = 'I_DOC'
i_structure_name = 'MSEG'
CHANGING
ct_fieldcat = i_fieldcat1
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.

CLEAR struct_layout1.
struct_layout1-colwidth_optimize = 'X'.
REFRESH it_sort.
CLEAR it_sort.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = v_repid
i_grid_title = 'Details of Document'
is_layout = struct_layout1
it_fieldcat = i_fieldcat1
i_structure_name = 'MSEG'
i_default = 'X'
i_save = 'A'
TABLES
t_outtab = i_doc
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.
ENDIF.
ENDFORM. " SUB_SELECT_DOCUMENT
*&---------------------------------------------------------------------*
*& Form SUB_COMMENT_BUILD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_I_LIST_TOP_OF_PAGE text
*----------------------------------------------------------------------*
FORM sub_comment_build USING i_top_of_page TYPE slis_t_listheader.
DATA: ls_line TYPE slis_listheader.

***Header
CLEAR ls_line.
ls_line-typ = 'H'.
* LS_LINE-KEY: not used for this type
ls_line-info = 'Heading list'.
APPEND ls_line TO i_top_of_page.

***Selection
CLEAR ls_line.
ls_line-typ = 'S'.
ls_line-key = 'Key 1'.
ls_line-info = 'Material '.
APPEND ls_line TO i_top_of_page.
ls_line-key = 'Key 2'.
ls_line-info = 'Document no'.
APPEND ls_line TO i_top_of_page.

***Action
CLEAR ls_line.

ENDFORM. " SUB_COMMENT_BUILD
*&---------------------------------------------------------------------*
*& Form SUB_EVENTTAB_BUILD
*&---------------------------------------------------------------------*
* Defines the event table
*----------------------------------------------------------------------*
FORM sub_eventtab_build USING l_events TYPE slis_t_event.
DATA: ls_event TYPE slis_alv_event.
* Get the different events of the ALV
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = l_events.
* Search the top of page events
READ TABLE l_events WITH KEY name = slis_ev_top_of_page INTO ls_event.
IF sy-subrc = 0.
MOVE 'TOP_OF_PAGE' TO ls_event-form.
APPEND ls_event TO l_events.
ENDIF.
ENDFORM. " SUB_EVENTTAB_BUILD

*---------------------------------------------------------------------*
* FORM TOP_OF_PAGE *
*---------------------------------------------------------------------*
* When TOP-OF-PAGE will be fired , this event will be called and it
* will use the contents of i_list_top_of_page for output in the header
*---------------------------------------------------------------------*
FORM top_of_page.
*
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
i_logo = 'ENJOYSAP_LOGO'
it_list_commentary = i_list_top_of_page.

ENDFORM. "top_of_page



ALSO READ:

- ALV Subtotals In Different Blocks.

- ALV With Page Numbers & Subtotals.

- Footer Functionality In ALV Reports.

- Calling One ALV From Other ALV Report Program.

..... Back To Index On ALV List/ Grid Display.

..... Back To MAIN INDEX.