Skip to Content
-1

alv report user command

Mar 23, 2017 at 07:31 AM

106

avatar image
Former Member

Hello everyone !

i have a report zstd_rate n a customized ztable zstdrate.

when the user exceutes the alv report , data gets saved into the ztable.

now i want that when user executes the report after data is saved, data should be first fetched from the customised ztable 'ZSTDRATE' & if not found there then from the master table 'MBEW'.

How to achieve this ?

10 |10000 characters needed characters left characters exceeded
Former Member

Below is my code. where can i put the code for the above mentioned query ?

FORM GET_DATA .

if p_metal = 'X'.

SELECT a~matnr a~meins b~maktx FROM marc AS c INNER JOIN mara AS a ON c~matnr = a~matnr INNER JOIN makt AS b ON a~matnr = b~matnr
INTO CORRESPONDING FIELDS OF TABLE it_mara WHERE werks ='RIH1' AND ( mtart = 'FERT' or mtart = 'HALB') AND a~lvorm ne 'X'.

ELSEIF p_zin = 'X'.

SELECT a~matnr a~meins b~maktx FROM marc AS c INNER JOIN mara AS a ON c~matnr = a~matnr INNER JOIN makt AS b ON a~matnr = b~matnr
INTO CORRESPONDING FIELDS OF TABLE it_mara WHERE ( werks ='RIH2' or werks = 'RIH4' OR werks = 'RIN1' OR werks = 'RIN2') AND ( mtart = 'FERT' or mtart = 'HALB') AND a~lvorm ne 'X'.

endif.

DELETE it_mara WHERE matnr+7(2) eq '08'.

LOOP AT it_mara INTO wa_mara.

IF p_metal = 'X'.
"for RIH1
SELECT SINGLE stprs FROM mbew INTO wa_mara-v_h1 WHERE matnr = wa_mara-matnr AND BWKEY = 'RIH1'.

ELSEIF p_zin = 'X'.

"for RIH2
SELECT SINGLE stprs FROM mbew INTO wa_mara-v_h2 WHERE matnr = wa_mara-matnr AND BWKEY = 'RIH2'.

"for RIH4
SELECT SINGLE stprs FROM mbew INTO wa_mara-v_h4 WHERE matnr = wa_mara-matnr AND bwkey = 'RIH4'.

"for RIN1
SELECT SINGLE stprs FROM mbew INTO wa_mara-v_n1 WHERE matnr = wa_mara-matnr AND bwkey = 'RIN1'.

"for RIN2
SELECT SINGLE stprs FROM mbew INTO wa_mara-v_n2 WHERE matnr = wa_mara-matnr AND bwkey = 'RIN2'.

ENDIF.

modify it_mara FROM wa_mara.

endloop.
*ENDSELECT.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BUILD_FIELDCATALOG .

fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_l = 'Material Number'.
fieldcatalog-no_zero = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'MAKTX'.
fieldcatalog-seltext_l = 'Material Description'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'MEINS'.
fieldcatalog-seltext_l = 'Unit Of Measure'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

IF p_metal = 'X'.

fieldcatalog-fieldname = 'V_H1'.
fieldcatalog-seltext_l = 'Existing Rate (RIH1)'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'V_MH1'.
fieldcatalog-seltext_l = 'Month Rate(RIH1)'.
fieldcatalog-edit = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
ENDIF.

IF p_zin = 'X'.

fieldcatalog-fieldname = 'V_H2'.
fieldcatalog-seltext_l = 'Existing Rate (RIH2)'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'V_MH2'.
fieldcatalog-seltext_l = 'Month Rate(RIH2)'.
fieldcatalog-edit = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'V_H4'.
fieldcatalog-seltext_l = 'Existing Rate (RIH4)'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'V_MH4'.
fieldcatalog-seltext_l = 'Month Rate(RIH4)'.
fieldcatalog-edit = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'V_N1'.
fieldcatalog-seltext_l = 'Existing Rate (RIN1)'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'V_MN1'.
fieldcatalog-seltext_l = 'Month Rate(RIN1)'.
fieldcatalog-edit = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'V_N2'.
fieldcatalog-seltext_l = 'Existing Rate (RIN2)'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'V_MN2'.
fieldcatalog-seltext_l = 'Month Rate(RIN2)'.
fieldcatalog-edit = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.


ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SHOW_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SHOW_DATA .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING

I_CALLBACK_PROGRAM = 'ZSTD_RATE'
I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
IT_FIELDCAT = fieldcatalog[]

I_DEFAULT = 'X'
I_SAVE = 'U'

TABLES
T_OUTTAB = it_mara
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

ENDFORM.

*&---------------------------------------------------------------------*
*& Form TOP_OF_PAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM TOP_OF_PAGE .

DATA: lt_top_of_page type slis_t_listheader.
DATA : ls_line type slis_listheader,
v_cocd TYPE string,
v_month TYPE string,
v_year TYPE string.
* v_div TYPE string.
* v_dt TYPE string.

ls_line-typ = 'H'.
ls_line-info = 'Monthly Standard Rate Entry Report'.
append ls_line to lt_top_of_page.

ls_line-typ = 'A'.
CONCATENATE 'Company Code :' p_co_cd INTO v_cocd.
ls_line-info = v_cocd.
append ls_line to lt_top_of_page.

ls_line-typ = 'A'.
CONCATENATE 'Month :' p_month INTO v_month.
ls_line-info = v_month.
append ls_line to lt_top_of_page.

ls_line-typ = 'A'.
CONCATENATE 'Year :' p_year INTO v_year.
ls_line-info = v_year.
append ls_line to lt_top_of_page.

*ls_line-typ = 'S'.
*CONCATENATE 'Division :' p_div INTO v_div.
*ls_line-info = v_div.
*append ls_line to lt_top_of_page.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = lt_top_of_page.


ENDFORM.

*&---------------------------------------------------------------------*
*& Form SAVE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SAVE_DATA .

loop at it_mara into wa_mara.
clear : wstdrate.

wstdrate-matnr = wa_mara-matnr.
wstdrate-v_h1 = wa_mara-v_h1.
wstdrate-v_mh1 = wa_mara-v_mh1.
wstdrate-v_h2 = wa_mara-v_h2.
wstdrate-v_mh2 = wa_mara-v_mh2.
wstdrate-v_h4 = wa_mara-v_h4.
wstdrate-v_mh4 = wa_mara-v_mh4.
wstdrate-v_n1 = wa_mara-v_n1.
wstdrate-v_mn1 = wa_mara-v_mn1.
wstdrate-v_n2 = wa_mara-v_n2.
wstdrate-v_mn2 = wa_mara-v_mn2.
wstdrate-p_month = p_month.
wstdrate-p_year = p_year.

modify zstdrate from wstdrate.
endloop.
commit work.
ENDFORM.

0
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Richard Harper Mar 23, 2017 at 08:06 AM
0

You say 'executes the report'. Do you mean clicks the Online button at the parameter screen to display the report, or presses a button on the ALV grid ?

Also, what type of grid is it / An Object ALV or one using the function module REUSE_ALV_GRID_DISPLAY ?

The actual code to read the table and if that fails read a second table is easy. It depends where you want to put it.

Rich

Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

by executes i mean when user clicks the online button at the parameter screen to display the report.

im using the function module REUSE_ALV_GRID_DISPLAY.

0

Then it's quite easy. Where you populate the data table for the grid read the MBEW data into a seperate itab. If that read fails, read your custom data. then merge whichever of those two tables were populated into the display table.

Rich

0
vamsilakshman pendurti Mar 23, 2017 at 08:39 AM
0

Hi,

Before saving the data first check whether data is available or not with the statement SELECT SINGLE.

Check the SY-SUBRC value,if it fails then fetch the data from where ever u want and save that data into your ZTABLE.


Thanks,

Vamc.

Share
10 |10000 characters needed characters left characters exceeded