Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Initialization in SAP Query

Former Member
0 Kudos

Hi,

I have created a SAP query with MSEG as one of the tables. I am using MATNR of MSEG.

I need to initialize the values of material before query is executed. Filter is based on one of the Characteristic which can not be done using variants. I could see there is an option to write code in dirrerent events of Report e.g. Initialization, Start-Of-Selection.

I selected the required materials in an internal tables in INITIALIZATION event. How can i pass these materials as default in Select-Option of MSEG-MATNR.

Any pointers will be highly appreciated.

Regards

Ashish

3 REPLIES 3

Sandra_Rossi
Active Contributor
0 Kudos

In the infoset, you will find the selection-screen field NAMES in the SELECTIONS tab, at left of the CODE tab. Use the NAME of the field you want to default in the code of the INITIALIZATION event. Example : if your field has name XX and its type is selection criteria ("SelCrit"), if you want to default it to values AAA or BBB, then add this code:


XX-sign = 'I'.
XX-option = 'EQ'.
XX-low = 'AAA'.
APPEND XX.
XX-low = 'BBB'.
APPEND XX.

Former Member
0 Kudos

Hi,

If you are working in T.Code :SQVI, then it is not possible.

If you are working with SQ01, SQ02., You can do this in SQ02.

Through Menu Option there, use GOTO --> Code -->

Here you can create some code and intitilize the value for material.

Regds,

ANil

0 Kudos

Hi,

Try the code below:

*---Authorization for Company code entered by the users.
*---This code will restrict users to see data for company
*---codes which they are not authorized to.

*---Select all the company codes based upon selection entered by the
*---user

 SELECT bukrs
   FROM t001
   INTO TABLE li_bukrs
  WHERE bukrs IN z_bukrs.


 IF sy-subrc EQ 0.

*---Clear Screen variable for Company code
   CLEAR z_bukrs.
   REFRESH z_bukrs.

*---Filter and prepare Select options for Company code table to be
*---passed to query. Table will only have values of company codes he is
*---authorized to for display.

   LOOP AT li_bukrs INTO lwa_bukrs.

     AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
                       ID 'BUKRS' FIELD lwa_bukrs
                       ID 'ACTVT' FIELD '03'.

     IF sy-subrc = 0.
       z_bukrs-sign = 'I'.
       z_bukrs-option = 'EQ'.
       z_bukrs-low = lwa_bukrs.
       z_bukrs-high = space.
       APPEND z_bukrs.
     ELSE.
       lv_flag = 'X'.
     ENDIF.

   ENDLOOP.
*---Give warning message to the user in case he is not authorized to see
*---data for all the company codes that he has entered.

   IF lv_flag = 'X'.
     MESSAGE ID 'ZF_MSS_FNG' TYPE 'W' NUMBER '015'.
   ENDIF.

 ENDIF.

Just make sure that Z_BUKRS field is available in selection tab.

Also, declare below mentioned variables in INITIALIZATION.

DATA: li_bukrs TYPE TABLE OF bukrs,
       lwa_bukrs TYPE bukrs,
       lv_flag TYPE c.

KR Jaideep,