Skip to Content

This blog decscribes the method to automate the change of ‘ready for Input’ variable in a report during broadcast.

Requirement:

Create a report for the showing  division wise daily sales for past three months. The months are calculated based on the user input.

This report is also to be broadcasted with the value of the calmonth variable as the current month. The value of the month should change dynamically in subsequent months.

Analysis:

While creating Broadcast settings , I assigned the value of the current month to the clamonth variable. This worked fine, however, every month I had to manually change the value of the variable to the current month. I wanted to automate this, so that the value of the current month is populated into the variable without my intervention.

Solution:

The broadcast settings are stored in a table  RSRD_SETT_NODE_A. The table has the follwing structure:

/wp-content/uploads/2013/04/table_201698.png  

  This table has a entry for every broadcast setting and it is here that the value of the variables are also stored. The idea is that if we can soemhow change the value of the variables here via a program, we can get the value of the variables as per our requirement.

Following is the program:


REPORT  Z_BROADCST.* Declaring VariablesDATA : lv_input_str TYPE STRING,
lv_output_str
TYPE STRING,
lv_ind
like sy-tabix,
lv_out_tab_ind
like sy-tabix,
lv_out_str_len
like sy-tabix,
count(2)
type c,
lv_indx
like sy-tabix,
lv_indmax
like sy-tabix,
varo(2)
type c,
lv_var1
TYPE STRING,
lv_brdcst
type string.
* Declaring structures
TYPES:
begin of t_param,
objnm
TYPE c LENGTH 40,
varnm
TYPE c LENGTH 40,
param_nm
TYPE string,
param_val
TYPE string,end of t_param,
* Structure for Input parametersbegin of t_broad_param,
broadcst
type string,
varnm
TYPE string,
varv
TYPE string,
varvh
TYPE string,sign TYPE string,
opt
TYPE string,
varvext
type string,
varvexth
type string,end of t_broad_param,
* Structure for storing the parameter name and values from broadcast settingsbegin of lt_param,
param_nm
type string,
param_val
type string,end of lt_param,
*structure fro storing the parameter stringbegin of t_result,
result
TYPE c LENGTH 100,end of t_result.
* Declaring Internal tablesDATA : t_result_value TYPE STANDARD TABLE OF t_result,
wa_result_value
TYPE t_result,
t_param_value
TYPE STANDARD TABLE OF t_param,
wa_param_value
TYPE t_param,
lt_param_value
TYPE STANDARD TABLE OF lt_param,
w_param_value
TYPE lt_param,
t_rsrd
TYPE STANDARD TABLE OF RSRD_SETT_NODE_A,
wa_rsrd
TYPE RSRD_SETT_NODE_A,
wa_broadcast
type t_broad_param.
* Input parameters Declarationparameters : Setting type c length 20,
varname
type c length 20,
varval_l
type c length 20,
varval_h
type c length 20,sign type c length 20,
option
type c length 20,
varva_el
type c length 20,
varva_eh
type c length 20.*Upd_mod(1) type c.
* Assigning variable values
lv_ind =
1.
lv_brdcst = Setting.
wa_broadcast-broadcst = Setting.
wa_broadcast-varnm = varname.
wa_broadcast-varv = varval_l.
wa_broadcast-varvh = varval_h.
wa_broadcast-sign = sign.
wa_broadcast-opt = option.
wa_broadcast-varvext = varva_el.
wa_broadcast-varvexth = varva_eh.
*Select Broadcast Settings parametersselect * from rsrd_sett_node_a into table t_rsrdwhere setting_id = lv_brdcstand id = ‘PR_VARIABLE_STRING’and objvers = ‘A’.describe table t_rsrd lines lv_indmax.
*get the variable values and its parameters into a variableloop at t_rsrd into wa_rsrd.concatenate lv_input_str wa_rsrd-value into lv_input_str.
endloop.*Split the parameters into an internal table as rowsSPLIT lv_input_str AT ‘&’ INTO TABLE t_result_value IN CHARACTER MODE.*Split the parameters into an internal table as columnsLOOP AT t_result_value INTO wa_result_value.SPLIT wa_result_value-result AT ‘=’ INTO w_param_value-param_nm w_param_value-param_val.
append w_param_value to lt_param_value.
endloop.*If upd_mod ne ‘X’.* Loop at the variable that needs to be changed by reading the parameters from teh broadcast settingsread table lt_param_value into w_param_valuewith key param_val = wa_broadcast-varnm.if sy-subrc eq 0.count = w_param_value-param_nm+9.SHIFT count LEFT DELETING LEADING ‘0’.if wa_broadcast-opt eq .
*  *update different parameters using the varo as indicator
varo =
‘L’.concatenate ‘VAR_VALUE_’ count into lv_var1.perform change.
varo =
‘EL’.concatenate ‘VAR_VALUE_EXT_’ count into lv_var1.perform change.
else.
varo =
‘L’.concatenate ‘VAR_VALUE_LOW_’ count into lv_var1.perform change.
varo =
‘EL’.concatenate ‘VAR_VALUE_LOW_EXT_’ count into lv_var1.perform change.
varo =
‘H’.concatenate ‘VAR_VALUE_HIGH_’ count into lv_var1.perform change.
varo =
‘EH’.concatenate ‘VAR_VALUE_HIGH_EXT_’ count into lv_var1.perform change.
varo =
‘O’.concatenate ‘VAR_OPERATOR_’ count into lv_var1.perform change.
endif.
varo =
‘S’.concatenate ‘VAR_SIGN_’ count into lv_var1.perform change.
endif.describe table lt_param_value lines lv_indx.Loop at lt_param_value into w_param_value.if lv_indx = sy-tabix.concatenate lv_output_str w_param_value-param_nm ‘=’ w_param_value-param_val into lv_output_str.
else.concatenate lv_output_str w_param_value-param_nm ‘=’ w_param_value-param_val ‘&’ into lv_output_str.
endif.
endloop.
lv_out_str_len =
0.
lv_out_tab_ind =
0.loop at t_rsrd into wa_rsrd.

  if sy-tabix eq lv_indmax.
wa_rsrd-value = lv_output_str+lv_out_str_len.
else.
wa_rsrd-value = lv_output_str+lv_out_str_len(255).
endif.modify t_rsrd from wa_rsrd transporting value where SETTING_ID = lv_brdcst AND ID = ‘PR_VARIABLE_STRING’and OBJVERS = ‘A’ and RSR_INDEX = lv_out_tab_ind.
.MODIFY RSRD_SETT_NODE_A FROM table t_rsrd.
lv_out_str_len = sy-tabix *
255.
lv_out_tab_ind = sy-tabix *
1000.
endloop.*generate status messageif sy-subrc eq 0.MESSAGE ‘Success’ TYPE ‘S’.
else.MESSAGE ‘Failed’ TYPE ‘E’.
endif.*else.*Write ‘Settings parameters’.*perform varup.*endif.
*&———————————————————————**& Form change*&———————————————————————** text*———————————————————————-** Update variable values in internal tableform change.read table lt_param_value into w_param_valuewith key param_nm = lv_var1.
lv_ind = sy-tabix.if sy-subrc eq 0.if varo = ‘L’ AND wa_broadcast-varv <> .
w_param_value-param_val = wa_broadcast-varv.perform varchange.elseif varo = ‘H’ AND wa_broadcast-varvh <> .
w_param_value-param_val = wa_broadcast-varvh.perform varchange.elseif varo = ‘O’ AND wa_broadcast-opt <> .
w_param_value-param_val = wa_broadcast-opt.perform varchange.elseif varo = ‘S’ AND wa_broadcast-sign <> .
w_param_value-param_val = wa_broadcast-sign.perform varchange.elseif varo = ‘EL’ AND wa_broadcast-varvext <> .
w_param_value-param_val = wa_broadcast-varvext.perform varchange.elseif varo = ‘EH’ AND wa_broadcast-varvexth <> .
w_param_value-param_val = wa_broadcast-varvexth.perform varchange.
endif.
endif.
endform.
“change
*&———————————————————————**& Form varchange*&———————————————————————** text*———————————————————————-** Update variable values in broadcst settingsform varchange.SHIFT w_param_value-param_val LEFT DELETING LEADING ‘0’.modify lt_param_value index lv_ind from w_param_value transporting param_val.
endform.
“varchange

*&———————————————————————**& Form readvar*&———————————————————————** text*———————————————————————-** read parameter values from broadcast settingsform readvar.read table lt_param_value into w_param_valuewith key param_nm = lv_var1.if sy-subrc eq 0.if varo = ‘L’.
wa_broadcast-varv = w_param_value-param_val.elseif varo = ‘H’.
wa_broadcast-varvh = w_param_value-param_val.elseif varo = ‘S’.
wa_broadcast-sign = w_param_value-param_val.elseif varo = ‘O’.
wa_broadcast-opt = w_param_value-param_val.elseif varo = ‘EL’.
wa_broadcast-varvext = w_param_value-param_val.elseif varo = ‘EH’.
wa_broadcast-varvexth = w_param_value-param_val.
endif.
endif.
endform.
“readvar

This is a general program and the selection screen asks for the following:

SETTING: name of the setting from the tabke RSRD_SETT_NODE_A.

VARNAME: name of the variable used in the query.

VARVAL_L: Variable value( supply the new value which is to be changed).

VARVAL_H: Upper limit of the variable, this can be used only if the variabke is of the type ‘Interval’.

SIGN: Valid only if the varible is of the type ‘Interval’.

OPTION:This is also valid only for the variables of type interval.

VARVA_EL: This is a special field used by broadcaster for the time related variables. In those variables, the ‘.’ is replaced by ‘%2e’. Eg: of the value is 03.2012. It actually is tored in the table 03%2e2012.

VARVA_EL: This is also same as VARVA_EL but is used for the upper limit.

This is a generic program which will change the value of the variable  for the broadcast setting  provided in the selection screen. 

To accomplish the same in a process chain, we can write a function mudule and call it in the process chain.The function module should contain the logic to calculate the value of the variable and pass it on to this program. In the next step of the process chain this program should be added. Once this program runs, the value gets updated in the table. In the third step, the report can be broadcasted.

For Eg:

the following function supplies the value for the parameters of the above program.  In this function module, I have placed a logic to get the current month :

Data : mnth type c length 6,
Pst_mnth type c length 9.
mnth = sy-datum(6).
concatenate mnth+4(2) ‘%2e’ mnth(4) into Pst_mnth.
Submit Z_BROADCAST with SETTING = ‘test’
with VARNAME = ‘ TESTMONTH ‘
with VARVAL_L = mnth
with VARVAL_H =
with SIGN =
with OPTION =
with VARVA_EL = Pst_mnth
with VARVA_EH = .

This FM should be placed before the program in the process chain.

Order in the process chain:

Start-> FM( this will supply the required parameters to the program)-> Program( this will update the table of the broadcast setting and update the value of the variable)->Broadcast of the report.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply