Skip to Content
Author's profile photo Sneha Santhanakrishnan

ABAP Code for providing dynamic name for Report to the Query based on input values

Introduction: ABAP Program to derive dynamic report name based on input variable values of a Query

Requirement: Need Dynamic Query Description based on the input variable values

Example:

When ZP_VAR1 = Australia, ZP_VAR2 = Sydney & Fiscal year  = 2012

Then Report name should display as Australia  Sydney 2012

Program code:

WHEN “Mention the text variable give in the Query description”

** Defining Variables

data : Var1(n),   *corresponding input variable in query = ZP_VAR1*

       Var2(n),        *corresponding input variable in query = ZP_VAR2*

       Var3(n),        *corresponding input variable in query = ZP_VAR3*

       Var4(n),        *corresponding input variable in query = ZP_VAR4*

       fyear(n),       *corresponding input variable in  query  = 0P_FPER1*

       title(n).

**Code to read the value stored in the variable to the Query Description

read table i_t_var_range INTO s_t_var_range with key vnam = ‘ZP_VAR1’ .

if s_t_var_range-LOW is not initial .

Var1  = s_t_var_range-LOW.

endif.

clear s_t_var_range-LOW.

read table i_t_var_range INTO s_t_var_range with key vnam = ‘ZP_VAR2’ .

if s_t_var_range-LOW is not initial .

Var2  = s_t_var_range-LOW.

endif.

clear s_t_var_range-LOW.

read table i_t_var_range INTO s_t_var_range with key vnam = ‘ZP_VAR3’.

if s_t_var_range-LOW is not initial .

Var2  = s_t_var_range-LOW.

endif.

clear s_t_var_range-LOW.

read table i_t_var_range INTO s_t_var_range with key vnam = ‘ZP_VAR4’ .

if s_t_var_range-LOW is not initial .

Var4 = s_t_var_range-LOW.

endif.

clear s_t_var_range-LOW.

read table i_t_var_range INTO s_t_var_range with key vnam = ‘0P_FPER1’ .

if s_t_var_range-LOW is not initial .

fyear = s_t_var_range-LOW.

endif.

clear s_t_var_range-LOW.

concatenate Var1  Var2  Var3  Var4 ” fyear into title  separated by space.

CLEAR: L_S_RANGE.

L_S_RANGE-SIGN    = ‘I’.

L_S_RANGE-OPT     = ‘EQ’.

L_S_RANGE-LOW     = title.

APPEND L_S_RANGE TO E_T_RANGE.

CLEAR L_S_RANGE.

ENDCASE.

Assigned Tags

      5 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Suman Chakravarthy K
      Suman Chakravarthy K

      Hi Sneha,

      Your code is good. But a little introduction and conclusion will give a good response to your blog.

      Regards,

      Suman

      Author's profile photo Sneha Santhanakrishnan
      Sneha Santhanakrishnan
      Blog Post Author

      Thanks Suman for your inputs... I have added some details.. Hope its helpful for others.. 🙂

      Author's profile photo Kamal Mehta
      Kamal Mehta

      Hi Sneha ,

      Thanks for sharing this.

      You have given the code to be written in CMOD. Right.

      Can you please add the details regarding where its being called in Query Designer.

      Regards

      Kamal

      Author's profile photo Anshu Lilhori
      Anshu Lilhori

      Hi Sneha,

      Just a thought process the same can be achieved by make use of text variable with replacement path at query description.

      Anyways thanks for sharing the code.

      Regards,

      AL

      Author's profile photo Former Member
      Former Member

      Hi Sneha,

      Thanks for code logic, but yes as Anshu Lilhori we can achive by text variable as replacement path...