Thursday, October 30, 2008

some example programs on the reports

How to deal with reports

Here I am giving the simple program for creating a sample application .

Program1 .
Simple calculator

1 .Here in this step I am able to create the output in the same screen only .

report .

parameters:input1 type i,
input2 type i .

selection-screen skip 3.

parameters:output type i.

initialization.

input1 = 10 .
input2 = 20 .
output = input1 + input2 .

2. here I want to create the output in the result screen .

report .

parameters:input1 type i,
input2 type i .

selection-screen skip 3.

data:output type i.



start-of-selection .

output = input1 + input2 .


write:/ output .

Selection-screen reports

How to inactive some parameters fields

report .


parameters:p_name(20) type c ,
p_check as checkbox .


at selection-screen output .

loop at screen .

if p_check = 'X'.

if screen-name = 'P_NAME'.
screen-active = 0.
modify screen.
endif.
if screen-name = '%_P_NAME_%_APP_%-TEXT'.
screen-active = 0.
modify screen.
endif.
endif.
endloop.


How to disable some fields based on input

PROGRAM1

report .


parameters:p_name(20) type c ,
p_age(4) type c.


at selection-screen output .

loop at screen .

if not p_age is initial ..

if screen-name = 'P_NAME' OR
screen-name = '%_P_NAME_%_APP_%-TEXT'.
screen-input = 0.
modify screen.
endif.
elseif p_name is NOT initial .

if screen-name = 'P_AGE' OR
screen-name = '%_P_AGE_%_APP_%-TEXT'.
screen-input = 0.
modify screen.
endif.

endif.
endloop.

PROGRAM2

REPORT Ztests.

tables:mara .

select-options: s_matnr for mara-matnr ,
s_mtart for mara-mtart .


at selection-screen output .

loop at screen .

if not S_MATNR is initial ..

if screen-name = 'S_MTART-LOW' OR screen-name = 'S_MTART-HIGH'.
screen-input = 0.
modify screen.
endif.
elseif S_MTART is NOT initial .

if screen-name = 'S_MATNR-LOW' OR screen-name = 'S_MATNR-HIGH' .
screen-input = 0.
modify screen.
endif.
endif.
endloop.


How to create the password program

report .


Parameters: p_name like sy-uname,
p_pas like sy-uname lower case.

AT SELECTION-SCREEN OUTPUT.
loop at screen.
if screen-name eq 'P_PAS'.
move: 1 to screen-invisible.
modify screen.
endif.
endloop.

START-OF-SELECTION .

IF P_NAME = 'VENKAT' and
p_pas = 'venkat'.

write:/ 'you are successful'.
endif.


Calling another screen and displaying the results

REPORT Ztests.


SELECTION-SCREEN BEGIN OF SCREEN 500 AS WINDOW TITLE title.
Parameters: p_name like sy-uname,
p_pas like sy-uname lower case.
SELECTION-SCREEN skip 1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(70) text-001.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF SCREEN 500.
title = 'HAI LOGIN PLEASE'.
CALL SELECTION-SCREEN '0500' STARTING AT 10 10 ending at 70 14.



AT SELECTION-SCREEN OUTPUT.
loop at screen.
check screen-name eq 'P_PAS'.
move: 1 to screen-invisible.
modify screen.
endloop.

start-of-selection.

if p_pas = 'venkat'.
write:/ 'this is working'.
endif.

Automatic changing of screen .

Report ztests .

PARAMETERS show_all AS CHECKBOX USER-COMMAND flag.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS: p1(10) TYPE c,
p2(10) TYPE c,
p3(10) TYPE c.
SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME.
PARAMETERS: p4(10) TYPE c MODIF ID bl2,
p5(10) TYPE c MODIF ID bl2,
p6(10) TYPE c MODIF ID bl2.
SELECTION-SCREEN END OF BLOCK b2.

AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF show_all <> 'X' AND
screen-group1 = 'BL2'.
screen-active = '0'.
ENDIF.
MODIFY SCREEN.
ENDLOOP.

Working with radio button

REPORT Ztests.

selection-screen begin of block b1 with frame title text-001.
SELECTION-SCREEN ULINE /1(50).
selection-screen begin of line.
selection-screen position 13 .
PARAMETERS: r1 RADIOBUTTON GROUP rad1.
selection-screen comment 15(12) text-002 .
selection-screen end of line.

selection-screen begin of line.
selection-screen position 13 .
PARAMETERS: r2 RADIOBUTTON GROUP rad1.
selection-screen comment 15(12) text-003 .
selection-screen end of line.

selection-screen begin of line.
selection-screen position 13 .
PARAMETERS: r3 RADIOBUTTON GROUP rad1.
selection-screen comment 15(12) text-004 .
selection-screen end of line.

SELECTION-SCREEN ULINE /1(50).

selection-screen end of block b1 .


AT SELECTION-SCREEN OUTPUT.

LOOP AT SCREEN.
IF screen-group1 = 'MG1'.
screen-intensified = '1'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.

start-of-selection .

if r1 = 'X'.

write:/ 'you clicked the radiobutton1'.
elseif r2 = 'X' .
write:/ 'you clicked the radiobutton2'.

elseif r3 = 'X'.
write:/ 'you clicked the radiobutton3'.
endif.


Changing the screen fields based on the selection of radiobutton


report .
TABLES sscrfields.

PARAMETERS: p_r1 RADIOBUTTON GROUP grp1 USER-COMMAND us DEFAULT 'X',
p_r2 RADIOBUTTON GROUP grp1.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.

PARAMETERS: p_mat TYPE mara-matnr MODIF ID id1,
p_ven TYPE lfa1-lifnr MODIF ID id2
.
SELECTION-SCREEN END OF BLOCK b1.

AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
CASE screen-group1.
WHEN 'ID1'.
IF p_r1 = 'X'.
screen-active = 1.
ELSE.
screen-active = 0.
ENDIF.
WHEN 'ID2'.
IF p_r2 = 'X'.
screen-active = 1.
ELSE.
screen-active = 0.
ENDIF.
ENDCASE.
MODIFY SCREEN.
ENDLOOP.

AT SELECTION-SCREEN ON p_mat.

CHECK sscrfields-ucomm NE 'US'.
IF p_mat IS INITIAL.
MESSAGE e000(00) WITH 'mat is required'.
ENDIF.

Changing screens on selection screen .

REPORT ZSELECTIONSCREEN001.
tables:mara,
marc,
mard,
sscrfields.

data: begin of it_mara occurs 0,
matnr like mara-matnr,
meins like mara-meins,
mtart like mara-mtart,
pstat like mara-pstat,
ernam like mara-ernam,
end of it_mara.

selection-screen begin of screen 100 as subscreen.
selection-screen begin of block b1 with frame title text-001.
select-options:matno for mara-matnr.
selection-screen end of block b1.
selection-screen end of screen 100.

selection-screen begin of screen 200 as subscreen.
selection-screen begin of block b2 with frame title text-002.
select-options:industry for mara-meins.
selection-screen end of block b2.
selection-screen end of screen 200.

selection-screen begin of screen 300 as subscreen.
selection-screen begin of block b3 with frame title text-003.
select-options:mattype for mara-mtart.
selection-screen end of block b3.
selection-screen end of screen 300.

SELECTION-SCREEN: FUNCTION KEY 1,
FUNCTION KEY 2.

SELECTION-SCREEN: BEGIN OF TABBED BLOCK SUB FOR 15 LINES,
END OF BLOCK SUB.


initialization.

SSCRFIELDS-FUNCTXT_01 = '@0D@'.
SSCRFIELDS-FUNCTXT_02 = '@0E@'.
SUB-PROG = SY-REPID.
SUB-DYNNR = 100.

AT SELECTION-SCREEN.
CASE SY-DYNNR.

WHEN 100.
IF SSCRFIELDS-UCOMM = 'FC01'.
SUB-DYNNR = 300.
ELSEIF SSCRFIELDS-UCOMM = 'FC02'.
SUB-DYNNR = 200.
ENDIF.

WHEN 200.
IF SSCRFIELDS-UCOMM = 'FC01'.
SUB-DYNNR = 100.
ELSEIF SSCRFIELDS-UCOMM = 'FC02'.
SUB-DYNNR = 300.
ENDIF.

WHEN 300.
IF SSCRFIELDS-UCOMM = 'FC01'.
SUB-DYNNR = 200.
ELSEIF SSCRFIELDS-UCOMM = 'FC02'.
SUB-DYNNR = 100.
ENDIF.
ENDCASE.

Selection screen design example
REPORT ZVENKATTEST0.
TABLES:MARA.
SELECT-OPTIONS:S_TEST1 FOR MARA-MATNR MODIF ID M1 ,
S_TEST2 FOR MARA-MEINS MODIF ID M2 .
PARAMETERS:P_RAD1 RADIOBUTTON GROUP G1 USER-COMMAND UC1 DEFAULT 'X',
P_RAD2 RADIOBUTTON GROUP G1 ,
P_RAD3 RADIOBUTTON GROUP G1 .


AT SELECTION-SCREEN OUTPUT .

LOOP AT SCREEN.
IF P_RAD1 = 'X'.
IF SCREEN-NAME = 'S_TEST1-LOW' .
SCREEN-INPUT = '0'.
MODIFY SCREEN.
ENDIF.
IF SCREEN-NAME = 'S_TEST1-HIGH' .
SCREEN-INPUT = '0'.
MODIFY SCREEN.
ENDIF.

IF SCREEN-NAME = 'S_TEST2-LOW' .
SCREEN-INPUT = '0'.
MODIFY SCREEN.
ENDIF.
IF SCREEN-NAME = 'S_TEST2-HIGH' .
SCREEN-INPUT = '0'.
MODIFY SCREEN.
ENDIF.
ENDIF.
IF P_RAD2 = 'X'.
IF SCREEN-NAME = 'S_TEST1-LOW' .
SCREEN-INPUT = '0'.
MODIFY SCREEN.
ENDIF.
IF SCREEN-NAME = 'S_TEST1-HIGH' .
SCREEN-INPUT = '0'.
MODIFY SCREEN.
ENDIF.
ENDIF.
IF P_RAD3 = 'X'.

IF SCREEN-NAME = 'S_TEST2-LOW' .
SCREEN-INPUT = '0'.
MODIFY SCREEN.
ENDIF.
IF SCREEN-NAME = 'S_TEST2-HIGH' .
SCREEN-INPUT = '0'.
MODIFY SCREEN.
ENDIF.
ENDIF.

ENDLOOP.

Multiple selection screen .

REPORT ZDYNAMIC_PROGRAM.

PARAMETERS: rb1 RADIOBUTTON GROUP ab MODIF ID bl2,
rb2 RADIOBUTTON GROUP ab MODIF ID bl2.

SELECTION-SCREEN BEGIN OF SCREEN 100.

parameter p_val1 type char10.

SELECTION-SCREEN END OF SCREEN 100.

SELECTION-SCREEN BEGIN OF SCREEN 200.

parameter p_val2 type char10.

SELECTION-SCREEN END OF SCREEN 200.

AT SELECTION-SCREEN.

if rb1 = 'X'.
call selection-screen 100.
else.
call selection-screen 200.
endif.


selection screen to restrict options

REPORT ZRESTRICT_SELOPT.

* Include type pool SSCR
TYPE-POOLS sscr.

TABLES: EKPO.

* Selection-screen
select-options : so_ebeln for ekpo-ebeln,
so_ebelp for ekpo-ebelp.

* Variables for populating restriction data
DATA: gd_restrict TYPE sscr_restrict. "structure containing 2 tables
DATA: gd_optlist TYPE sscr_opt_list, "header line for table 1
gd_ass TYPE sscr_ass. "header line for table 2

*INITIALIZATION.
INITIALIZATION.

* Restrict SO_EBELN to only except EQ, BT and NE.
gd_optlist-name = 'KEY1'. "Can be anything
gd_optlist-options-eq = 'X'.
gd_optlist-options-bt = 'X'.
gd_optlist-options-ne = 'X'.
APPEND gd_optlist TO gd_restrict-opt_list_tab.
clear: gd_optlist.

gd_ass-kind = 'S'.
gd_ass-name = 'SO_EBELN'.
gd_ass-sg_main = 'I'.
gd_ass-sg_addy = SPACE.
gd_ass-op_main = 'KEY1'. "Must be same as above
APPEND gd_ass TO gd_restrict-ass_tab.
clear: gd_ass.

* Restrict SO_EBELP to only except CP, GE, LT.
gd_optlist-name = 'KEY2'. "Can be anything
gd_optlist-options-cp = 'X'.
gd_optlist-options-ge = 'X'.
gd_optlist-options-lt = 'X'.
APPEND gd_optlist TO gd_restrict-opt_list_tab.
clear: gd_optlist.

gd_ass-kind = 'S'.
gd_ass-name = 'SO_EBELP'.
gd_ass-sg_main = 'I'.
gd_ass-sg_addy = SPACE.
gd_ass-op_main = 'KEY2'. "Must be same as above
APPEND gd_ass TO gd_restrict-ass_tab.
clear: gd_ass.

CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
EXPORTING
* PROGRAM =
restriction = gd_restrict
* DB = ' '
EXCEPTIONS
TOO_LATE = 1
REPEATED = 2
SELOPT_WITHOUT_OPTIONS = 3
SELOPT_WITHOUT_SIGNS = 4
INVALID_SIGN = 5
EMPTY_OPTION_LIST = 6
INVALID_KIND = 7
REPEATED_KIND_A = 8
OTHERS = 9.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

inserting deleteing updating values from work area


F4 help for the date
report message-id zmsf.

DATA:
l_select_date LIKE workflds-gkday,
l_select_week LIKE scal-week.

* pop up calendar.
CALL FUNCTION 'F4_DATE'
EXPORTING
date_for_first_month = sy-datum
IMPORTING
select_date = l_select_date
select_week = l_select_week
EXCEPTIONS
calendar_buffer_not_loadable = 1
date_after_range = 2
date_before_range = 3
date_invalid = 4
factory_calendar_not_found = 5
holiday_calendar_not_found = 6
parameter_conflict = 7
OTHERS = 8.
IF sy-subrc <> 0.
EXIT.
ENDIF.


* Validate date - An invalid date is caused by using the cancel
* button on the calendar
CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
EXPORTING
date = l_select_date
EXCEPTIONS
plausibility_check_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
* User has cancelled the calendar
EXIT.
ENDIF.

F4 help for fields from the ztable

*--create a z table with fields pernr like pa0002-pernr
* vorna like pa0002-vorna
* nachn like pa0002-nachn
* and create entries for the table

report message-id zmsf.

tables:zzz000000 ,DFIES.

DATA: BEGIN OF itab OCCURS 0,
pernr like pa0002-pernr,
vorna like pa0002-vorna,
nachn like pa0002-nachn,
END OF itab.

DATA : LT_FIELDS TYPE TABLE OF DFIES,
LS_FIELD TYPE DFIES.

PARAMETER: pernr LIKE pa0002-pernr .


AT SELECTION-SCREEN ON VALUE-REQUEST FOR pernr.

select pernr
vorna
nachn
from zzz000000
into table itab .

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
RETFIELD = 'PERNR'
DYNPPROG = sy-cprog
DYNPNR = sy-dynnr
DYNPROFIELD = 'PERNR'
VALUE_ORG = 'S'
TABLES
VALUE_TAB = itab
FIELD_TAB = LT_FIELDS .


start-of-selection.

select pernr
vorna
nachn
from zzz000000
into table itab
where pernr = pernr.

loop at itab.
write:/ itab-pernr,
itab-vorna,
itab-nachn.
endloop.


F4 help for the month


report ztest.
tables: t247 , DFIES.

parameters:p_month LIKE T247-MNR.

data: begin of itab occurs 0,
mnr like t247-mnr,
ktx like t247-ktx,
end of itab .

DATA : LT_FIELDS TYPE TABLE OF DFIES,
LS_FIELD TYPE DFIES.

at selection-screen on value-request for p_month.
select MNR
KTX
from t247 into corresponding fields of table itab
where spras = 'EN'.

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
RETFIELD = 'P_MONTH'
DYNPPROG = sy-cprog
DYNPNR = sy-dynnr
DYNPROFIELD = 'MNR'
VALUE_ORG = 'S'
TABLES
VALUE_TAB = itab
FIELD_TAB = LT_FIELDS .

f4 help to display more fields

REPORT Z_F4_FIELD.
tables : mara.
parameters :
p_matnr type mara-matnr,
p_plant type marc-werks.
data : begin of itab_help occurs 0,
matnr type mara-matnr,
werks type marc-werks,
end of itab_help.
data : it_rettab type standard table of DDSHRETVAL with header line.
DATA: dynfld_tab LIKE dselc OCCURS 100 WITH HEADER LINE.
DATA: lt_dynpfields LIKE dynpread OCCURS 0 WITH HEADER LINE.
data: t_dynpro_field type table of dynpread with header line.

data : v_matnr type mara-matnr.
DATA: T_FIELD LIKE DFIES OCCURS 0 WITH HEADER LINE.

at selection-screen on value-request for p_matnr.
*
t_field-tabname = 'mara'.
t_field-fieldname = 'matnr'.
append t_field.
t_field-tabname = 'marc'.
t_field-fieldname = 'werks'.
append t_field.

select matnr werks
from marc into table itab_help
up to 20 rows.


REFRESH dynfld_tab.
CLEAR dynfld_tab.
dynfld_tab-fldname = 'F0001'.
dynfld_tab-dyfldname = 'mara-MATNR'.
APPEND dynfld_tab.
CLEAR dynfld_tab.
dynfld_tab-fldname = 'F0002'.
dynfld_tab-dyfldname = 'marc-WERKS'.
APPEND dynfld_tab.
CLEAR dynfld_tab.
CLEAR it_rettab.
REFRESH it_rettab.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
RETFIELD = 'MATNR'
DYNPPROG = 'ZKEERTHI_F4'
DYNPNR = SY-DYNNR
DYNPROFIELD = 'MARA-MATNR'
VALUE_ORG = 'S'
TABLES
VALUE_TAB = itab_help
RETURN_TAB = IT_RETTAB
DYNPFLD_MAPPING = dynfld_tab.

IF NOT IT_RETTAB[] IS INITIAL.
LOOP AT IT_RETTAB WHERE fieldname = 'F0001'.
lt_dynpfields-fieldname = 'P_MATNR'.
lt_dynpfields-fieldvalue = IT_RETTAB-fieldval.
append lt_dynpfields.

ENDLOOP.

LOOP AT IT_RETTAB WHERE fieldname = 'F0002'.
lt_dynpfields-fieldname = 'P_PLANT'.
lt_dynpfields-fieldvalue = IT_RETTAB-fieldval.
append lt_dynpfields.
ENDLOOP.
ENDIF.

CALL FUNCTION 'DYNP_VALUES_UPDATE'
EXPORTING
DYNAME = sy-cprog
DYNUMB = sy-dynnr
TABLES
DYNPFIELDS = lt_dynpfields
.


LIST BOX1

report zTEST.

type-pools : vrm.
data : param type vrm_id,
values type vrm_values,
value like line of values.

parameters : p_name(10) as listbox visible length 10.

at selection-screen output.

param = 'P_NAME'.
value-key = '1'.
value-text = 'NAME1'.
append value to values.

value-key = '2'.
value-text = 'NAME2'.
append value to values.

value-key = '3'.
value-text = 'NAME3'.
append value to values.

call function 'VRM_SET_VALUES'
exporting
id = param
values = values .


start-of-selection.
write: / 'PARAMETER:', p_name.




different pop ups in the reports

popup1 .

REPORT Zpopup.

data:answer(10) .

CALL FUNCTION 'POPUP_TO_DECIDE_WITH_MESSAGE'
EXPORTING
DEFAULTOPTION = '1'
diagnosetext1 = 'this is text1'
DIAGNOSETEXT2 = 'this is text2 '
DIAGNOSETEXT3 = 'this is text3 '
textline1 = 'this is test4'
TEXTLINE2 = 'this is text5 '
TEXTLINE3 = 'this is text6 '
text_option1 = 'YES'
text_option2 = 'NO'
ICON_TEXT_OPTION1 = 'icon_okay'
ICON_TEXT_OPTION2 = 'icon_cancel'
titel = 'this is test title'
START_COLUMN = 25
START_ROW = 6
*----for the display of cancel button do like this.
CANCEL_DISPLAY = ' '
IMPORTING
ANSWER = ANSWER
.

if answer = '1' .
write:/ 'his is yes'.
else.
write:/ 'this is no'.
endif.

Popup2 .

report zreport123 line-size 80
line-count 65(3)
message-id z_msg_class
no standard page heading.

*------------------DECLARING THE STANDARD TABLES---------------------*
tables : ekko, "PURCHASE ORDER : HEADER
ekpo. "PURCHASE ORDER : ITEM

*------------------DECLARING THE INTERNAL TABLE----------------------*
data : begin of it_ekko occurs 2,
ebeln like ekko-ebeln, "PURCHASE ORDER NUMBER
bukrs like ekko-bukrs, "COMPANY CODE
bsart like ekko-bsart, "PURCHASING DOCUMENT TYPE
lifnr like ekko-lifnr, "VENDOR
spras like ekko-spras, "LANGUAGE KEY
zterm like ekko-zterm, "PAYMENT TERMS KEY
end of it_ekko.

data : begin of it_ekpo occurs 2,
ebeln like ekpo-ebeln, "PURCHASE ORDER NUMBER
ebelp like ekpo-ebelp, "PURCHASE ORDER NUMBER
werks like ekpo-werks, "PLANT
matnr like ekpo-matnr, "MATERIAL NUMBER
matkl like ekpo-matkl, "MATERIAL GROUP
end of it_ekpo.

data: it_ebeln like ekko-ebeln occurs 0 with header line.

*DATA: it_ebeln_high LIKE ekko-ebeln OCCURS 0 WITH HEADER LINE.

data: p_ebeln type i.

*------------------Declaring the selection screen--------------------*

selection-screen begin of block blk1 with frame title text-001.

select-options : s_ebeln for ekko-ebeln.

parameter : p_limit type i.

selection-screen end of block blk1.


*--------------------------------------------------------------------*
* Validation for number of records to be printed *
*--------------------------------------------------------------------*

*AT SELECTION-SCREEN ON p_limit.
* IF p_limit IS INITIAL.
* MESSAGE e011.
* ENDIF.


* IF p_limit GT sy-linct.
* MESSAGE e010.
* ENDIF.


*----------------------------------------------------------------------*
* Search help for purchase document number (s_ebeln-low) *
*----------------------------------------------------------------------*

at selection-screen on value-request for s_ebeln-low.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = s_ebeln-low
importing
output = s_ebeln-low.

perform form_search_help.

if sy-subrc <> 0.
case sy-subrc.
when 2.
leave to screen 1000.
endcase.
else.
loop at it_ebeln.
if sy-tabix = p_ebeln.
s_ebeln-low = it_ebeln.
exit.
endif.
endloop.
endif.

*----------------------------------------------------------------------*
* Search help for purchase document number (s_ebeln-high) *
*----------------------------------------------------------------------*

at selection-screen on value-request for s_ebeln-high.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = s_ebeln-high
importing
output = s_ebeln-high.

perform form_search_help.

if sy-subrc <> 0.
case sy-subrc.
when 2.
leave to screen 1000.
endcase.
else.
loop at it_ebeln.
if sy-tabix = p_ebeln.
s_ebeln-high = it_ebeln.
exit.
endif.
endloop.
endif.

*----------------------------------------------------------------------*
* Start-of-selection event *
*----------------------------------------------------------------------*

start-of-selection.

*----------------------To attach a user interface----------------------*
set pf-status '0010'.

*---------To fetch the data for the basic list-------------------------*
select ebeln "PURCHASE ORDER NUMBER
bukrs "COMPANY CODE
bsart "PURCHASING DOCUMENT TYPE
lifnr "VENDOR
spras "LANGUAGE KEY
zterm "PAYMENT TERMS KEY
up to p_limit rows
into table it_ekko from ekko
where ebeln in s_ebeln.

refresh it_ekpo.

*---------To fetch the data for the secondary list-----------------------*

if it_ekpo is initial.

select ebeln "PURCHASE ORDER NUMBER
ebelp "PURCHASING DOCUMENT TYPE
werks "PLANT
matnr "MATERIAL NUMBER
matkl "MATERIAL GROUP
from ekpo into table it_ekpo for all entries in it_ekko
where ebeln eq it_ekko-ebeln.

endif.

*----------------------------------------------------------------------*
* End-of-selection event *
*----------------------------------------------------------------------*

end-of-selection.


*---------To display the data for the basic list-----------------------*
format color 4 intensified off.
loop at it_ekko.
write :/ sy-vline, it_ekko-ebeln under text-002, 18 sy-vline,
"PURCHASE ORDER NUMBER
it_ekko-bukrs under text-003, 27 sy-vline,
"COMPANY CODE
it_ekko-bsart under text-004, 38 sy-vline,
"PURCHASING DOCUMENT TYPE
it_ekko-lifnr under text-005, 50 sy-vline,
"VENDOR
it_ekko-spras under text-006, 62 sy-vline,
"LANGUAGE KEY
it_ekko-zterm under text-007, 80 sy-vline.
"PAYMENT TERMS KEY

hide : it_ekko-ebeln.
endloop.
write :/ sy-uline(80).

*----------------------------------------------------------------------*
* To generate the detailed lists *
*----------------------------------------------------------------------*

at line-selection.
case sy-lsind.
when 1.
set pf-status '0011'.

*---------To display the data for the secondary list-----------------------*
window starting at 10 10
ending at 90 30.
format color 5 intensified off.
loop at it_ekpo where ebeln = it_ekko-ebeln .
write :/ sy-vline, it_ekpo-ebeln under text-002, 15 sy-vline,
"PURCHASE ORDER NUMBER
it_ekpo-ebelp under text-008, 30 sy-vline,
"PO ITEM NUMBER
it_ekpo-werks under text-009, 45 sy-vline,
"PLANT
it_ekpo-matnr under text-010, 60 sy-vline,
"MATERIAL NUMBER
it_ekpo-matkl under text-011, 80 sy-vline.
"MATERIAL GROUP
endloop.

write :/ sy-uline(80).

endcase.

case sy-ucomm.
when 'EXIT' or 'CANC' or 'BACK'.
leave to screen 0.
endcase.

*----------------------------------------------------------------------*
* At user-command event *
*----------------------------------------------------------------------*

at user-command.
case sy-ucomm.
when 'SELE' or 'LIST1'.
if sy-lsind = 1.
set pf-status '0011'.

*---------To display the data for the secondary list-----------------------*

window starting at 10 10
ending at 90 30.
format color 5 intensified off.

loop at it_ekpo where ebeln = it_ekko-ebeln .
write :/ sy-vline, it_ekpo-ebeln under text-002, 15 sy-vline, "PURCHASE ORDER NUMBER
it_ekpo-ebelp under text-008, 30 sy-vline, "PO ITEM NUMBER
it_ekpo-werks under text-009, 45 sy-vline, "PLANT
it_ekpo-matnr under text-010, 60 sy-vline, "MATERIAL NUMBER
it_ekpo-matkl under text-011, 80 sy-vline. "MATERIAL GROUP

endloop.

write :/ sy-uline(80).
endif.

endcase.

case sy-ucomm.
when 'EXIT' or 'CANC' or 'BACK'.
leave to screen 0.

endcase.

*----------------------------------------------------------------------*
* Top-of-page for basic list *
*----------------------------------------------------------------------*

top-of-page.

format color 3 intensified off.

write :/ sy-uline(80).
write :/ sy-vline,
03 sy-repid,
60 text-015,
sy-uname,
80 sy-vline.
write :/ sy-vline, 03 sy-datum,
35 text-012,
60 text-014,
sy-pagno,
80 sy-vline.
write :/ sy-uline(80).
write :/ sy-vline, text-002, 18 sy-vline, "PURCHASE ORDER NUMBER
text-003, 27 sy-vline, "COMPANY CODE
text-004, 38 sy-vline, "PURCHASING DOCUMENT TYPE
text-005, 50 sy-vline, "VENDOR
text-006, 62 sy-vline, "LANGUAGE KEY
text-007, 80 sy-vline. "PAYMENT TERMS KEY
write :/ sy-uline(80).

*----------------------------------------------------------------------*
* Top-of-page for secondary list *
*----------------------------------------------------------------------*

top-of-page during line-selection.
format color 2 intensified off.
window starting at 10 10
ending at 90 30.
write :/ sy-uline(80).
write :/ sy-vline,
03 sy-repid,
60 text-015,
sy-uname,
80 sy-vline.

write :/ sy-vline,
03 sy-datum,
35 text-013,
60 text-014,
sy-pagno,
80 sy-vline.

write :/ sy-uline(80).

write :/ sy-vline, text-014, 15 sy-vline, "PURCHASE ORDER NUMBER
text-008, 30 sy-vline, "PO ITEM NUMBER
text-009, 45 sy-vline, "PLANT
text-010, 60 sy-vline, "MATERIAL NUMBER
text-011, 80 sy-vline. "MATERIAL GROUP

write :/ sy-uline(80).

*----------------------------------------------------------------------*
* End-of-page event *
*----------------------------------------------------------------------*

end-of-page.
write :/ sy-vline,
03 text-016,
p_limit,
60 text-014,
sy-pagno,
80 sy-vline.
write:/ sy-uline(80).
*--------------------------------------------------------------------------------------
form form_search_help .

refresh it_ebeln.
clear it_ebeln.
clear p_ebeln.

select ebeln from ekko into table it_ebeln.

call function 'POPUP_WITH_TABLE_DISPLAY'
exporting
endpos_col = 21
endpos_row = 35
startpos_col = 12
startpos_row = 1
titletext = text-012
importing
choise = p_ebeln
tables
valuetab = it_ebeln
exceptions
break_off = 1
others = 2.
endform. "form_search_help

popup3.

REPORT Zpopup.

data:answer(10) .


CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
EXPORTING
DEFAULTOPTION = 'Y'
textline1 = 'YES'
TEXTLINE2 = 'NO'
titel = 'are you want to execute this'
START_COLUMN = 25
START_ROW = 6
CANCEL_DISPLAY = ' '
*---if you want to display the cancel button put X in above
IMPORTING
ANSWER = ANSWER .

if answer = 'J' .
write:/ 'his is yes'.
else.
write:/ 'this is no'.
endif.

Popup4

REPORT Zpopup.

data: SELECTED_MONTH type ISELLIST-MONTH .


CALL FUNCTION 'POPUP_TO_SELECT_MONTH'
EXPORTING
actual_month = '200808'
IMPORTING
SELECTED_MONTH = SELECTED_MONTH .

write:/ 'month is:' , selected_month+4(2) ,
'year is :' , selected_month+0(4) .

Popup5

REPORT Zpopup.

data:answer(10) .

CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTING
TITEL = 'this is title '
textline1 = 'this is the test line'
TEXTLINE2 = ' '
START_COLUMN = 25
START_ROW = 6 .

Popup6

REPORT Zpopup.

data:answer(10) .

CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_MESSAGE'
EXPORTING
DEFAULTOPTION = 'Y'
diagnosetext1 = 'this is for the test'
DIAGNOSETEXT2 = ' '
DIAGNOSETEXT3 = ' '
textline1 = 'are you want to delete it'
TEXTLINE2 = ' '
titel = 'this is the test pop up'
START_COLUMN = 25
START_ROW = 6
*----for the display of cancel button do like this.
CANCEL_DISPLAY = ' '
IMPORTING
ANSWER = ANSWER
.

if answer = 'J' .
write:/ 'his is yes'.
else.
write:/ 'this is no'.
endif.

Popup7

REPORT Zpopup.


data: begin of itab occurs 0,
name(10) type c,
age type i ,
salary type i,
end of itab ,
CHOISE type sy-tabix.

itab-name = 'venkat01'.
append itab .

itab-name = 'venkat01'.
itab-age = 10 .
itab-salary = 1000.
append itab .

itab-name = 'venkat02'.
itab-age = 20 .
itab-salary = 2000.
append itab .

itab-name = 'venkat03'.
itab-age = 30 .
itab-salary = 3000.
append itab .

itab-name = 'venkat04'.
itab-age = 40 .
itab-salary = 4000.
append itab .

CALL FUNCTION 'POPUP_WITH_TABLE_DISPLAY'
EXPORTING
endpos_col = 30
endpos_row = 11
startpos_col = 10
startpos_row = 6
titletext = 'titletext'
IMPORTING
CHOISE = CHOISE
TABLES
valuetab = itab
EXCEPTIONS
BREAK_OFF = 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.

Popup8

REPORT Zpopup.

data:answer(10) .

CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_VALUE'
EXPORTING
DEFAULTOPTION = 'Y'
objectvalue = '10000000'
TEXT_AFTER = 'this is after the value '
text_before = 'this is before the value '
titel = ' this is test title'
START_COLUMN = 25
START_ROW = 6
*----for the display of cancel button do like this.
CANCEL_DISPLAY = ' '
IMPORTING
ANSWER = ANSWER
EXCEPTIONS
TEXT_TOO_LONG = 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.


if answer = 'J' .
write:/ 'his is yes'.
else.
write:/ 'this is no'.
endif.

Popup9

REPORT zPopup.

data:answer(10) .

CALL FUNCTION 'POPUP_TO_DECIDE'
EXPORTING
DEFAULTOPTION = '1'
textline1 = 'this is text1'
TEXTLINE2 = 'this is text2'
TEXTLINE3 = 'this is text3'
text_option1 = 'YES'
text_option2 = 'NO'
ICON_TEXT_OPTION1 = 'icon_okay'
ICON_TEXT_OPTION2 = 'icon_cancel '
titel = 'this is test title'
START_COLUMN = 25
START_ROW = 6
*----for the display of cancel button do like this.
CANCEL_DISPLAY = ' '
IMPORTING
ANSWER = ANSWER
.
if answer = 'J' .
write:/ 'his is yes'.
else.
write:/ 'this is no'.
endif.


Colors in reports

report .

data: i type c .

data : begin of it_data occurs 0,
data(10),
end of it_data.

it_data-data = 'ABC'.
append it_data.

it_data-data = 'ABC1'.
append it_data.
it_data-data = 'ABC2'.
append it_data.
it_data-data = 'ABC3'.
append it_data.
it_data-data = 'ABC4'.
append it_data.
it_data-data = 'ABC5'.
append it_data.
it_data-data = 'ABC6'.
append it_data.
it_data-data = 'ABC7'.
append it_data.
it_data-data = 'ABC8'.
append it_data.
it_data-data = 'ABC9'.
append it_data.
it_data-data = 'ABC0'.
append it_data.
it_data-data = 'ABC11'.
append it_data.
it_data-data = 'ABC12'.
append it_data.
it_data-data = 'ABC22'.
append it_data.



loop at it_data.

i = i + 1.

case i.

when 1.
write:/ it_data-data color 1 .

when 2.
write:/ it_data-data color 2 .
when 3.
write:/ it_data-data color 3 .
when 4.
write:/ it_data-data color 4 .
when 5.
write:/ it_data-data color 5 .
when 6.
write:/ it_data-data color 6 .

when 7.
write:/ it_data-data color 7 .
clear : i.


endcAse.


endloop .


how to modify data in an internal table


report .

types: begin of itab ,
test type c ,
test2 type c,
end of itab .

types: begin of itab1 ,
test type c ,
test1 type i,
test2 type c,
end of itab1 .

data: wa_itab type itab ,
it_itab type table of itab with header line,
wa_itab1 type itab1 ,
it_itab1 type table of itab1 with header line.



wa_itab-test = 'A'.
wa_itab-test2 = 'a'.

append wa_itab to it_itab .
append it_itab .

it_itab-test = 'B'.
it_itab-test2 = 'b'.

append wa_itab to it_itab .
append it_itab .

it_itab-test = 'C'.
it_itab-test2 = 'c'.

append wa_itab to it_itab .
append it_itab .

it_itab-test = 'D'.
it_itab-test2 = 'd'.

append wa_itab to it_itab .
append it_itab .

wa_itab1-test1 = 1.
wa_itab1-test2 = 'a'.

append wa_itab1 to it_itab1 .
append it_itab1 .

wa_itab1-test1 = 2.
wa_itab1-test2 = 'b'.

append wa_itab1 to it_itab1 .
append it_itab1 .

wa_itab1-test1 = 3.
wa_itab1-test2 = 'c'.

append wa_itab1 to it_itab1 .
append it_itab1 .

wa_itab1-test1 = 4.
wa_itab1-test2 = 'd'.

append wa_itab1 to it_itab1 .
append it_itab1 .

loop at it_itab into wa_itab.
read table it_itab1 into wa_itab1 with key test2 = wa_itab-test2 .
move-corresponding wa_itab to wa_itab1.
modify it_itab1 from wa_itab1 index sy-tabix.
endloop .

loop at it_itab1.
if not it_itab1-test is initial.
write:/ it_itab1-test,
it_itab1-test1,
it_itab1-test2.
endif.
endloop.


program with select statements


select some fields from table

report.

tables: mara .

*---internal table declarations

types: begin of ty,
matnr type mara-matnr,
meins type mara-meins,
mtart type mara-mtart,
end of ty .

data: itab type table of ty with header line .


*--selection screen .
select-options: s_matnr for mara-matnr .

*--start of selection

start-of-selection .

select matnr
meins
mtart
from mara
into table itab
where matnr in s_matnr .

if sy-subrc eq 0 .
loop at itab .
write:/ itab-matnr,
itab-meins,
itab-mtart .
endloop.
endif .

selecting all fields from table (select star)

report .


tables:mara .

*---internal table declarations

types: begin of ty.
include structure mara .
types: end of ty .

data: itab type table of ty with header line .


*--selection screen .
select-options: s_matnr for mara-matnr .

*--start of selection

start-of-selection .

select *
from mara
into table itab
where matnr in s_matnr .

if sy-subrc eq 0 .
loop at itab .
write:/ itab-matnr,
itab-meins,
itab-mtart,
itab-mbrsh,
itab-matkl.
endloop.
endif .

select single record

report .


tables:mara .

*---internal table declarations
types: begin of ty,
matnr type mara-matnr,
meins type mara-meins,
mtart type mara-mtart,
end of ty .

data: itab type table of ty with header line .

*--selection screen .
parameters: p_matnr like mara-matnr .

*--start of selection

start-of-selection .

select single matnr
meins
mtart
from mara
into itab
where matnr = p_matnr .

if sy-subrc eq 0 .
write:/ itab-matnr,
itab-meins,
itab-mtart.
endif .


select up to n rows

report .


tables:mara .

*---internal table declarations
types: begin of ty,
matnr type mara-matnr,
meins type mara-meins,
mtart type mara-mtart,
end of ty .

data: itab type table of ty with header line .

parameters:no type i .

*--start of selection

start-of-selection .

select matnr
meins
mtart
from mara
into table itab
up to no rows .

if sy-subrc eq 0 .
loop at itab .
write:/ itab-matnr,
itab-meins,
itab-mtart.
endloop.
endif .


for all entries


report .


tables:mara .

*---internal table declarations
types: begin of ty_mara,
matnr type mara-matnr,
meins type mara-meins,
mtart type mara-mtart,
end of ty_mara .

types: begin of ty_marc,
matnr type mara-matnr,
werks type marc-werks,
end of ty_marc .

data: it_mara type table of ty_mara with header line ,
it_marc type table of ty_marc with header line .

select-options:s_matnr for mara-matnr .

*--start of selection

start-of-selection .

select matnr
meins
mtart
from mara
into table it_mara
where matnr in s_matnr .

if sy-subrc eq 0 .
select matnr
werks
from marc
into table it_marc
for all entries in it_mara
where matnr = it_mara-matnr .

endif .

loop at it_mara .
write:/ it_mara-matnr,
it_mara-meins,
it_mara-mtart.
read table it_marc with key matnr = it_mara-matnr .
write: it_marc-werks.
endloop.

joins

*---simple join program
report ztest.

tables:mara,marc,mard.

data:begin of itab occurs 0,
matnr like mara-matnr,
mtart like mara-mtart,
meins like mara-meins,
werks like marc-werks,
pstat like marc-pstat,
labst like mard-labst,
lgort like mard-lgort,
maktx like makt-maktx,
end of itab.


select-options:s_matnr for mara-matnr.

start-of-selection.
select a~matnr
a~mtart
a~meins
b~werks
b~pstat
c~lgort
c~labst
into corresponding fields of table itab
from mara as a inner join marc as b on a~matnr = b~matnr
inner join mard as c on a~matnr = c~matnr
and b~werks = c~werks
where a~matnr in s_matnr.

if sy-subrc = 0.

loop at itab.

select single maktx
from makt
into itab-maktx
where matnr = itab-matnr.
modify itab.

write:/ itab-matnr,
itab-mtart,
itab-meins,
itab-werks,
itab-pstat,
itab-lgort,
itab-labst,
itab-maktx.

endloop.

endif.

Interactive reports

REPORT ZINTERACTIVE05 .

start-of-selection.

do 4 times.
write:/35 'this is the basic list' color 7.
enddo .

at line-selection.

case: sy-lsind.
when 1.
write:/35 'this is first screen' color 3.
when 2 .
write:/35 'this is second screen' color 1.
when 3.
write:/35 'this is third screen' color 2.
when 4.
write:/35 'this is 4th screen' color 2.

when 5.
write:/35 'this is 5th screen' color 2.

when 6.
write:/35 'this is 6th screen' color 2.

when 7.
write:/35 'this is 7th screen' color 2.

when 8.
write:/35 'this is 8th screen' color 2.

when 9.
write:/35 'this is 9th screen' color 2.

when 10.
write:/35 'this is 10th screen' color 2.

when 11.
write:/35 'this is 11th screen' color 2.

when 12.
write:/35 'this is 12th screen' color 2.
when 13.
write:/35 'this is 13th screen' color 2.

when 14.
write:/35 'this is 14th screen' color 2.

when 15.
write:/35 'this is 15th screen' color 2.

when 16.
write:/35 'this is 16th screen' color 2.

when 17.
write:/35 'this is 17th screen' color 2.

when 18.
write:/35 'this is 18th screen' color 2.

when 19.
write:/35 'this is 19th screen' color 2.
when 20.
write:/35 'this is 20th screen' color 2.


endcase.

Interactive report using hide statement

REPORT ZINTERACTIVE09 .

DATA: BEGIN OF WA_T001,
BUKRS TYPE T001-BUKRS,
BUTXT TYPE T001-BUTXT,
ORT01 TYPE T001-ORT01,
LAND1 TYPE T001-LAND1,
WAERS TYPE T001-WAERS,
END OF WA_T001.

DATA: IT_T001 LIKE STANDARD TABLE OF WA_T001.

DATA: V_BUKRS TYPE BUKRS.

*&------------------------------------------------
*CUSTOMER MASTER DATA
*&------------------------------------------------
DATA: BEGIN OF WA_CUSTOMER,
KUNNR TYPE KUNNR,
BUKRS TYPE BUKRS,
AKONT TYPE AKONT,
END OF WA_CUSTOMER.

DATA: IT_CUSTOMER LIKE STANDARD TABLE OF WA_CUSTOMER.

*&------------------------------------------------
*DESIGNING OF SELECTION SCREEN
*&------------------------------------------------

SELECT-OPTIONS: S_BUKRS FOR V_BUKRS.

START-OF-SELECTION.

SELECT BUKRS
BUTXT
ORT01
LAND1
WAERS
FROM T001
INTO TABLE IT_T001
WHERE BUKRS IN S_BUKRS.
END-OF-SELECTION.

IF NOT IT_T001 IS INITIAL.
WRITE:/5 'COM.CODE', 15 'TEXT', 45 'CITY', 70 'COUNTRY'.
ULINE.

LOOP AT IT_T001 INTO WA_T001.

WRITE:/5 WA_T001-BUKRS,
15 WA_T001-BUTXT,
45 WA_T001-ORT01,
70 WA_T001-LAND1.

HIDE: WA_T001-BUKRS,
WA_T001-BUTXT,
WA_T001-ORT01,
WA_T001-LAND1.

CLEAR WA_T001.
ENDLOOP.
ENDIF.

AT LINE-SELECTION.
CASE SY-LSIND.
WHEN 1.
*&------------------------------------------------------
*RETRIEVE ALL THE CSTOMERS FOR THE SELECTED COMPANY CODE
*&------------------------------------------------------
SELECT KUNNR
BUKRS
AKONT
INTO TABLE IT_CUSTOMER
FROM KNB1 WHERE BUKRS = WA_T001-BUKRS.
*&------------------------------------------------------
*DISPLAY THE DATA
*&------------------------------------------------------

IF NOT IT_CUSTOMER IS INITIAL.
WRITE:/5 'COM.CODE', 15 'CUSTOMER', 30 'RECON ACC'.
ULINE.
LOOP AT IT_CUSTOMER INTO WA_CUSTOMER.
WRITE:/5 WA_CUSTOMER-BUKRS,
15 WA_CUSTOMER-KUNNR,
30 WA_CUSTOMER-AKONT.
CLEAR WA_CUSTOMER.
endloop.
ELSE.

WRITE:/ 'NO FURTHER DETAILS FOUND FOR THE SELECTED COMPANY CODE'.
ENDIF.
ENDCASE. .

Interactive report using get cursor
REPORT z_interactive_rep.

TYPES : BEGIN OF str_sflight,
carrid TYPE sflight-carrid,
carrname TYPE scarr-carrname,
url TYPE scarr-url,
END OF str_sflight.

DATA : it_sflight TYPE str_sflight OCCURS 0 with header line,
wa_sflight LIKE LINE OF it_sflight.

TYPES : BEGIN OF str_car,
carrid TYPE sflight-carrid,
END OF str_car.


DATA : itab TYPE str_car OCCURS 0 with header line,
wa_itab like line of itab.

DATA : fnam(20),
var(20).
*-- top of page
TOP-OF-PAGE.

PERFORM top_of_page.

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

PERFORM FETCH_CARRID.

*--at line selection
AT LINE-SELECTION.

case sy-lsind.
when 1.

if itab[] is not initial.
get cursor field fnam value var.

SELECT carrid
carrname
url
INTO TABLE it_sflight
FROM scarr
where carrid = var.
endif.
perform top_of_page.

LOOP AT it_sflight where carrid = var.
WRITE : 5 it_sflight-carrid,
15 it_sflight-carrname,
60 it_sflight-url.
ENDLOOP.
endcase.
*-----------------------------------------------------------------------
*text
*-----------------------------------------------------------------------
FORM FETCH_CARRID.
SELECT DISTINCT
carrid
FROM sflight
INTO TABLE itab.
LOOP AT itab." into wa_itab.
WRITE :/5 itab-carrid.
ENDLOOP.
ENdFORM.

*&---------------------------------------------------------------------*
*& Form top_of_page
*----------------------------------------------------------------------*
FORM top_of_page.
WRITE : /1 sy-vline,
5 'AIRLINE CODE' COLOR COL_BACKGROUND,
20 sy-vline,
25 'AIRLINE NAME' COLOR COL_BACKGROUND,
40 sy-vline,
45 'FARE' COLOR COL_BACKGROUND,
60 sy-vline,
65 'URL' COLOR COL_BACKGROUND,
80 sy-vline.
ULINE at 1(50) .
SKIP 2.
ENDFORM. "top_of_page

Interactive report using check box
REPORT ZINTERACTIVEREPORT01 .

tables:pa0002,pa0008.

types :begin of ty_pa0002 ,
pernr like pa0002-pernr,
begda like pa0002-begda,
endda like pa0002-endda,
vorna like pa0002-vorna,
nachn like pa0002-nachn,
end of ty_pa0002.

types :begin of ty_final,
c type c ,
pernr like pa0002-pernr,
begda like pa0002-begda,
endda like pa0002-endda,
vorna like pa0002-vorna,
nachn like pa0002-nachn,
end of ty_final.

types : begin of ty_pa0008 ,
pernr like pa0008-pernr,
begda like pa0008-begda,
endda like pa0008-endda,
preas like pa0008-preas,
ansal like pa0008-ansal,
lga01 like pa0008-lga01,
bet01 like pa0008-bet01,
end of ty_pa0008 .

DATA: V_PERNR LIKE PA0002-PERNR.

data: it_pa0002 type ty_pa0002 occurs 0 with header line,
it_pa0008 type ty_pa0008 occurs 0 with header line,
it_final type ty_final occurs 0 with header line.

selection-screen begin of block b1 with frame .
selection-screen begin of block b2 with frame title text-001 .
select-options:s_pernr for pa0002-pernr.
selection-screen end of block b2.
selection-screen end of block b1.
start-of-selection.

set pf-status 'GET'.

perform get_data.

end-of-selection.

at user-command.

case SY-UCOMM.
when 'DATA'.
set pf-status 'GET'.
WRITE:/1(93) SY-ULINE.
FORMAT COLOR 5.
WRITE:/1 SY-VLINE,
2 'PERSONNELNO',
10 SY-VLINE,
11 'START DATE',
21 SY-VLINE,
22 'END DATE',
32 SY-VLINE,
33 'ANNUAL SALARY',
48 SY-VLINE,
49 'REASON',
54 SY-VLINE,
55 'WAGE',
60 SY-VLINE,
75 'AMOUNT',
93 SY-VLINE.
FORMAT COLOR OFF.
WRITE:/1(93) SY-ULINE.
DO .
READ LINE SY-INDEX.
if sy-subrc ne 0.
exit.
endif.
CLEAR V_PERNR.
CLEAR IT_PA0008.
IF SY-LISEL+1(1) = 'X'.
V_PERNR = SY-LISEL+4(8).
SELECT PERNR
BEGDA
ENDDA
PREAS
ANSAL
LGA01
BET01
FROM PA0008
INTO TABLE IT_PA0008
WHERE PERNR = V_PERNR.
IF NOT IT_PA0008[] IS INITIAL.
LOOP AT IT_PA0008.
WRITE:/1 SY-VLINE,
2 IT_PA0008-PERNR,
10 SY-VLINE,
11 IT_PA0008-BEGDA,
21 SY-VLINE,
22 IT_PA0008-ENDDA,
32 SY-VLINE,
33 IT_PA0008-ANSAL,
48 SY-VLINE,
49 IT_PA0008-PREAS,
54 SY-VLINE,
55 IT_PA0008-LGA01,
60 SY-VLINE,
75 IT_PA0008-BET01,
93 SY-VLINE .
ENDLOOP.
ENDIF.
ENDIF.
ENDDO.
ENDCASE.
WRITE:/1(93) SY-ULINE.
*&---------------------------------------------------------------------*
*& Form get_data
*----------------------------------------------------------------------*
FORM get_data .
select pernr
begda
endda
vorna
nachn
from pa0002
into table it_pa0002
where pernr in s_pernr.
if not it_pa0002[] is initial.
sort it_pa0002 by pernr.
endif.
loop at it_pa0002.
it_final-pernr = it_pa0002-pernr.
it_final-begda = it_pa0002-begda.
it_final-endda = it_pa0002-endda.
it_final-vorna = it_pa0002-vorna.
it_final-nachn = it_pa0002-nachn.
append it_final.
clear it_final.
endloop.
format color col_heading.
write:/1(94) sy-uline.
write:/1 sy-vline,
2 'C',
3 sy-vline,
4 'Personnel no',
12 sy-vline,
13 'Start date',
23 sy-vline,
24 'End date',
34 sy-vline,
35 'First Name' ,
73 sy-vline,
74 'Last Name',
94 sy-vline.
format color off.



write:/1(94) sy-uline.
loop at it_final.
write:/1 sy-vline,
2 it_final-c as checkbox,
3 sy-vline,
4 it_final-pernr,
12 sy-vline,
13 it_final-begda,
23 sy-vline,
24 it_final-endda,
34 sy-vline,
35 it_final-vorna ,
73 sy-vline,
74 it_final-nachn,
94 sy-vline.
endloop.
write:/1(94) sy-uline.
ENDFORM. " get_data

Interactive report with check box

REPORT ZINTERACTIVE08 .
tables: pa0002, pa0008.
Data: begin of itab occurs 0,
check type c,
pernr like pa0002-pernr,
begda like pa0002-begda,
endda like pa0002-endda,
vorna like pa0002-vorna,
GESCH like pa0002-gesch,
GBDAT like pa0002-gbdat,
end of itab.

Data: Begin of itab1 occurs 0,
pernr like pa0008-pernr,
subty like pa0008-subty,
trfar like pa0008-trfar,
waers like pa0008-waers,
vglta like pa0008-vglta,
end of itab1.

data: wa like line of itab.
data: v_pernr like pa0008-pernr.

select-options: s_pernr for pa0002-pernr.

start-of-selection.

set pf-status 'BPAY'.

select pernr
begda
endda
vorna
gesch
gbdat
from pa0002
into corresponding fields of table itab
where pernr in s_pernr.

if sy-subrc = 0.

loop at itab.
write:/ itab-check as checkbox,
itab-pernr,
itab-begda,
itab-endda,
itab-vorna,
itab-gesch,
itab-gbdat.
hide: itab-check.
endloop.
endif.

at user-command.
case: sy-ucomm.
when 'BPAY'.
do.
read line sy-index.
if sy-subrc ne 0.
exit.
endif.

if sy-lisel+0(1) = 'X'.
v_pernr = sy-lisel+2(8).

select pernr
subty
trfar
waers
vglta
from pa0008
into table itab1
where pernr = v_pernr.

loop at itab1.
write:/ itab1-pernr,
itab1-subty,
itab1-trfar,
itab1-waers,
itab1-vglta.
endloop.
clear v_pernr.
endif.
enddo.
endcase.

Double clicking event
Here is the simple code for the interactive up to 4 levels .

REPORT ZINTERACTIVEREPORT05 .
*-----for the test give the material no as 11501,11502 in ecc5.0
tables:mara .

data:begin of itab occurs 0,
matnr like mara-matnr,
meins like mara-matnr,
mtart like mara-mtart,
mbrsh like mara-mbrsh,
end of itab .

data: begin of itab1 occurs 0,
matnr like mara-matnr,
werks like marc-werks,
pstat like marc-pstat,
end of itab1 .

data: begin of itab2 occurs 0,
matnr like mara-matnr,
werks like marc-werks,
lgort like mard-lgort,
end of itab2 .

data: begin of itab3 occurs 0,
EBELN like ekpo-ebeln,
EBELP like ekpo-ebelp,
matnr like ekpo-matnr,
BUKRS like ekpo-bukrs,
WERKS like ekpo-werks,
LGORT like ekpo-lgort,
end of itab3 .

select-options:s_matnr for mara-matnr .


select matnr
meins
mtart
mbrsh
from mara
into table itab
where matnr in s_matnr .

write:/1(80) sy-uline .
write:/1 sy-vline,
2 'material no',
30 sy-vline,
31 'unit of measure',
45 sy-vline,
46 'material type',
60 sy-vline,
61 'industry sector',
80 sy-vline .
write:/1(80) sy-uline .
if sy-subrc = 0.
loop at itab .
write:/1 sy-vline,
2 itab-matnr,
30 sy-vline,
31 itab-meins,
45 sy-vline,
46 itab-mtart,
60 sy-vline,
61 itab-mbrsh,
80 sy-vline .
hide: itab-matnr .
endloop.
endif .
write:/1(80) sy-uline .

at line-selection .

case sy-lsind .
when 1.

select matnr
werks
pstat
from marc
into table itab1
where matnr = itab-matnr .

write:/20(51) sy-uline .
write:/20 sy-vline,
21 'material number',
40 sy-vline,
41 'plant',
50 sy-vline,
51 'status',
70 sy-vline .
write:/20(51) sy-uline .

loop at itab1 .

write:/20 sy-vline,
21 itab1-matnr,
40 sy-vline,
41 itab1-werks,
50 sy-vline,
51 itab1-pstat,
70 sy-vline .
hide: itab1-matnr,
itab1-werks.
endloop.
write:/20(51) sy-uline .

when 2 .

select matnr
werks
lgort
from mard
into table itab2
where matnr = itab1-matnr
and werks = itab1-werks .

write:/20(51) sy-uline .
write:/20 sy-vline ,
21 'material no',
40 sy-vline,
41 'plant',
50 sy-vline,
51 'storage location',
70 sy-vline .
write:/20(51) sy-uline .
if sy-subrc = 0.
loop at itab2 .

write:/20 sy-vline ,
21 itab2-matnr,
40 sy-vline,
41 itab2-werks,
50 sy-vline,
51 itab2-lgort,
70 sy-vline .
hide: itab2-matnr ,
itab2-lgort.
endloop.
endif.
write:/20(51) sy-uline .

when 3 .

select EBELN
EBELP
matnr
BUKRS
WERKS
LGORT
from ekpo
into table itab3
where matnr = itab2-matnr
and lgort = itab2-lgort .

write:/1(91) sy-uline .
write:/1 sy-vline ,
2 'purchase order',
20 sy-vline,
21 'item',
35 sy-vline,
36 'material no',
55 sy-vline,
56 'Company Code',
65 sy-vline,
66 'Plant',
77 sy-vline ,
78 'Storage Loc',
91 sy-vline .


if sy-subrc = 0.
loop at itab3.
write:/1(91) sy-uline .
write:/1 sy-vline ,
2 itab3-ebeln,
20 sy-vline,
21 itab3-ebelp,
35 sy-vline,
36 itab3-matnr,
55 sy-vline,
56 itab3-bukrs,
65 sy-vline,
66 itab3-werks,
77 sy-vline ,
78 itab3-lgort,
91 sy-vline .
endloop.
endif.
write:/1(91) sy-uline .
endcase .


using of at new ,at end of commands

REPORT ZR_A1 NO STANDARD PAGE HEADING.

*Tables declarations*
TABLES: VBAK, VBAP.

*Variable declarations*
DATA: C1 TYPE C.

*Internal Table declarations**
DATA: BEGIN OF IT_VBAK OCCURS 0,
VBELN LIKE VBAK-VBELN,
VKORG LIKE VBAK-VKORG,
VTWEG LIKE VBAK-VTWEG,
SPART LIKE VBAK-SPART,
END OF IT_VBAK.

DATA: BEGIN OF IT_VBAP OCCURS 0,
VBELN LIKE VBAP-VBELN,
POSNR LIKE VBAP-POSNR,
MATNR LIKE VBAP-MATNR,
NETWR LIKE VBAP-NETWR,
BRGEW LIKE VBAP-BRGEW,
NTGEW LIKE VBAP-NTGEW,
END OF IT_VBAP.

DATA: BEGIN OF IT_FINAL OCCURS 0,
VBELN LIKE VBAK-VBELN,
VKORG LIKE VBAK-VKORG,
VTWEG LIKE VBAK-VTWEG,
SPART LIKE VBAK-SPART,
POSNR LIKE VBAP-POSNR,
MATNR LIKE VBAP-MATNR,
NETWR LIKE VBAP-NETWR,
BRGEW LIKE VBAP-BRGEW,
NTGEW LIKE VBAP-NTGEW,
END OF IT_FINAL.

*Selection-screen design*
SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-R01.
SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN.
SELECTION-SCREEN: END OF BLOCK B1.

TOP-OF-PAGE.
FORMAT INTENSIFIED ON COLOR 5.
WRITE:/7 'LIST TO DISPLAY SALES ITEM INFO'.

START-OF-SELECTION.

*Populating it_vbak table*
SELECT VBELN
VKORG
VTWEG
SPART
FROM VBAK
INTO TABLE IT_VBAK
WHERE VBELN IN S_VBELN.
*populating it_vbap table*
IF NOT IT_VBAK[] IS INITIAL.
SELECT VBELN
POSNR
MATNR
NETWR
BRGEW
NTGEW
FROM VBAP
INTO TABLE IT_VBAP
FOR ALL ENTRIES IN IT_VBAK
WHERE VBELN = IT_VBAK-VBELN.
ENDIF.
*populating the final list*
LOOP AT IT_VBAP.
READ TABLE IT_VBAK WITH KEY VBELN = IT_VBAP-VBELN.
IF SY-SUBRC = 0.
MOVE: IT_VBAK-VBELN TO IT_FINAL-VBELN,
IT_VBAK-VKORG TO IT_FINAL-VKORG,
IT_VBAK-VTWEG TO IT_FINAL-VTWEG,
IT_VBAK-SPART TO IT_FINAL-SPART,
IT_VBAP-POSNR TO IT_FINAL-POSNR,
IT_VBAP-MATNR TO IT_FINAL-MATNR,
IT_VBAP-NETWR TO IT_FINAL-NETWR,
IT_VBAP-BRGEW TO IT_FINAL-BRGEW,
IT_VBAP-NTGEW TO IT_FINAL-NTGEW.
APPEND IT_FINAL.
ENDIF.
ENDLOOP.
SORT IT_FINAL BY VBELN.
LOOP AT IT_FINAL.
AT FIRST.
FORMAT INTENSIFIED ON COLOR 1.
WRITE:/35 'SALES DOCUMENT ITEM LIST'.
ULINE AT (100).
FORMAT INTENSIFIED ON COLOR 5.
WRITE:/ SY-VLINE,
2 'SALES.DOCU.NO',
13 'ITEM',
21 'MATERIAL',
50 'NET-VAL',
65 'GROSS-WT',
82 'NET-WT',
100 SY-VLINE.
ENDAT.
FORMAT INTENSIFIED ON COLOR 2.
WRITE:/ SY-VLINE,
2 C1 AS CHECKBOX,
5 IT_FINAL-VBELN,
13 IT_FINAL-POSNR,
21 IT_FINAL-MATNR,
41 IT_FINAL-NETWR,
56 IT_FINAL-BRGEW,
71 IT_FINAL-NTGEW,
100 SY-VLINE.

AT END OF VBELN.
SUM.
FORMAT INTENSIFIED ON COLOR 3.
WRITE:/ SY-VLINE,
30 'SUB-TOTAL:',
41 IT_FINAL-NETWR,
56 IT_FINAL-BRGEW,
71 IT_FINAL-NTGEW.
WRITE:/100 SY-VLINE.
ENDAT.

AT LAST.
SUM.
FORMAT INTENSIFIED ON COLOR 6.
WRITE:/ SY-VLINE,
30 'GRAND-TOTAL:',
41 IT_FINAL-NETWR,
56 IT_FINAL-BRGEW,
71 IT_FINAL-NTGEW.
WRITE:/100 SY-VLINE.
ENDAT.
ENDLOOP

No comments: