SAP Virtual/Onsite Trainings

Document Categories:

What's New?

Contribute?

Sample Specs

What's Hot?

Web Dynpro for ABAP Tutorials 


Join the Mailing List
Enter name and email address below:
Name:
Email:
Subscribe  Unsubscribe 

Creation of Variants in Module Pool Program

...Previous

21. Below have mentioned the coding to be used for the scenario.

*&---------------------------------------------------------------------*
*& Module Pool       ZD_VARIANT_MODULE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

PROGRAM  ZD_VARIANT_MODULE.
TABLES: MARA.

DATA: OK_CODE TYPE SY-UCOMM,
      G_VARIANT1 
TYPE RSVAR-VARIANT,
      G_USER_VARI 
TYPE RSVAR-VARIANT,
      G_VARI_REPORT 
TYPE RSVAR-REPORT,
      G_SEL_VAR 
TYPE RSVAR-VARIANT,
      G_SEL_VARTXT 
TYPE RSVAR-VTEXT,
      G_REPORT 
TYPE RSVAR-REPORT,
      G_VAREXISTS 
TYPE C.


SELECTION-
SCREEN BEGIN OF SCREEN 901 AS SUBSCREEN.
SELECTION-
SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001"Input
SELECT-OPTIONS: S_MATNR FOR MARA-MATNR. "Material Number
SELECTION-
SCREEN SKIP.
PARAMETERS: P_REC TYPE CHAR4 DEFAULT '1000'"Max. No. of Records
SELECTION-
SCREEN END OF BLOCK B1.
SELECTION-
SCREEN END OF SCREEN 901.

SELECTION-
SCREEN BEGIN OF SCREEN 902 AS SUBSCREEN.
SELECTION-
SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-001.
PARAMETERS: P_NAME TYPE RSVAR-VARIANT, P_MEAN TYPE RSVAR-VTEXT.
SELECTION-
SCREEN END OF BLOCK B2.
SELECTION-
SCREEN END OF SCREEN 902.
*&---------------------------------------------------------------------*
*&      Module  STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_9000 OUTPUT.
  
SET PF-STATUS 'ZGUI_9000'.
  
SET TITLEBAR 'ZTITLE_900'.

ENDMODULE.                 " STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_9000 INPUT.
  
CLEAR OK_CODE.
  OK_CODE = SY-UCOMM.
  
CASE OK_CODE.
    
WHEN 'SAVE'.
      
CLEAR: P_NAME, P_MEAN.
      
CALL SCREEN 9001 STARTING AT 10 5.
    
WHEN 'VARIANT'.
      
PERFORM LOAD_VARIANT.
      
IF SY-UCOMM EQ 'CANC'.
        
MESSAGE 'Variant operation terminated' TYPE 'S' DISPLAY LIKE 'E'.
      
ELSE.
        
MESSAGE 'Variant selected' TYPE 'S'.
      
ENDIF.
      
CALL SCREEN 9000.
    
WHEN OTHERS.
      
LEAVE TO SCREEN 9000.
  
ENDCASE.
ENDMODULE.                 " USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*&      Module  STATUS_9001  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_9001 OUTPUT.
  
SET PF-STATUS 'ZGUI_9001'.
*  SET TITLEBAR 'xxx'.

ENDMODULE.                 " STATUS_9001  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9001  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_9001 INPUT.
  
IF NOT P_NAME IS INITIAL.
    OK_CODE = 
'OK'.
  
ELSE.
    OK_CODE = 
'CANCEL'.
  
ENDIF.
  
CASE OK_CODE.
    
WHEN 'OK'.
      
IF NOT P_NAME IS INITIAL.
        
PERFORM SAVE_VARIANT.
        
MESSAGE 'Variant has been saved' TYPE 'S'.
      
ENDIF.
    
WHEN 'CANCEL'.
      
MESSAGE '"Variant Not saved.' TYPE 'S' DISPLAY LIKE 'E'.
  
ENDCASE.
  
CALL SCREEN 9000.
ENDMODULE.                 " USER_COMMAND_9001  INPUT

*&---------------------------------------------------------------------*
*&  Form  SAVE_VARIANT
*&---------------------------------------------------------------------*
*  Routine to Save the variant
*----------------------------------------------------------------------*
form SAVE_VARIANT .
  
DATABEGIN OF rsparams_tab OCCURS 10.
            
INCLUDE STRUCTURE rsparams.
  
DATAEND OF rsparams_tab.
  
DATABEGIN OF varid_tab.
  
INCLUDE STRUCTURE varid.
  
DATAEND OF varid_tab.
  
DATABEGIN OF varit_tab OCCURS 2.
            
INCLUDE STRUCTURE varit.
  
DATAEND OF varit_tab.
  
DATA: rc  TYPE syst-subrc.
* Tabellen initialisieren
  
CLEAR: varid_tab.
  
REFRESH varit_tab.
  
REFRESH rsparams_tab.
*fill VARID structure - variant description
  varid_tab-
report  = 'ZD_VARIANT_MODULE'.
  varid_tab-variant = p_name.
  varid_tab-environmnt   = 
'A'.
  varit_tab-mandt   = sy-mandt.
  varit_tab-langu   = sy-langu.
  varit_tab-
report  = varid_tab-report.
  varit_tab-variant = varid_tab-variant.
  varit_tab-vtext   = p_mean.
  
APPEND varit_tab.
*fill RSPARAMS structure - Selektionswerte; variant contents
  
LOOP AT s_matnr.
   rsparams_tab-selname = 
'S_MATNR'.
   rsparams_tab-kind    = 
'S'.
   rsparams_tab-
sign    = s_matnr-sign.
   rsparams_tab-option  = s_matnr-option.
   rsparams_tab-low     = s_matnr-low.
   rsparams_tab-high    = s_matnr-high.
   
APPEND rsparams_tab.
   
ENDLOOP.

  rsparams_tab-selname = 
'P_REC'.
  rsparams_tab-kind  = 
'P'.
  rsparams_tab-
sign  = 'I'.
  rsparams_tab-option  = 
'EQ'.
  rsparams_tab-low  = p_rec.
  rsparams_tab-high  = 
' '.
  
APPEND rsparams_tab.
*Check variant
  
CALL FUNCTION 'RS_VARIANT_EXISTS'
  
EXPORTING
   
report  = varid_tab-report
   variant = varid_tab-variant
  
IMPORTING
   r_c  = rc
  
EXCEPTIONS
   not_authorized  = 
01
   no_report  = 
02
   report_not_existent = 
03
   report_not_supplied = 
04.

IF sy-subrc <> 0.
  
MESSAGE e001(VL) WITH text-e22 DISPLAY LIKE 'S'.
ENDIF.

  
IF rc = 0.                    " Variante existiert
    
CALL FUNCTION 'RS_CHANGE_CREATED_VARIANT'
      
EXPORTING
       curr_report      = varid_tab-
report
       curr_variant     = varid_tab-variant
       vari_desc        = varid_tab
      
TABLES
       vari_contents    = rsparams_tab
       vari_text        = varit_tab
      
EXCEPTIONS
       illegal_report_or_variant = 
01
       illegal_variantname       = 
02
       not_authorized            = 
03
       not_executed              = 
04
       report_not_existent       = 
05
       report_not_supplied       = 
06
       variant_doesnt_exist      = 
07
       variant_locked            = 
08
       selections_no_match       = 
09.
  
ELSE.
     
CALL FUNCTION 'RS_CREATE_VARIANT'
     
EXPORTING
          curr_report   = varid_tab-
report
          curr_variant  = varid_tab-variant
          vari_desc     = varid_tab
     
TABLES
          vari_contents   = rsparams_tab
          vari_text       = varit_tab
     
EXCEPTIONS
          illegal_report_or_variant = 
01
          illegal_variantname   = 
02
          not_authorized        = 
03
          not_executed          = 
04
          report_not_existent   = 
05
          report_not_supplied   = 
06
          variant_exists        = 
07
          variant_locked        = 
08.
ENDIF.
  rc = sy-subrc.
endform.           " SAVE_VARIANT

form LOAD_VARIANT .
   
PERFORM choose_variant CHANGING g_sel_var.
     
IF g_sel_var NE space.
       
CALL FUNCTION 'RS_SUPPORT_SELECTIONS'
          
EXPORTING
          
report      =         sy-repid
           variant     =         g_sel_var
      
EXCEPTIONS
             variant_not_existent = 
1
             variant_obsolete     = 
2
             
OTHERS               = 3.
            
ENDIF.
endform.                    " LOAD_VARIANT

form CHOOSE_VARIANT  changing fp_sel_var.
  
CALL FUNCTION 'RS_VARIANT_CATALOG'
    
EXPORTING
      
report               = sy-repid
      masked               = 
'X'
    
IMPORTING
      sel_variant          = fp_sel_var
      sel_variant_text     = g_sel_vartxt
    
EXCEPTIONS
      no_report            = 
1
      report_not_existent  = 
2
      report_not_supplied  = 
3
      no_variants          = 
4
      no_variant_selected  = 
5
      variant_not_existent = 
6
      
OTHERS               = 7.
endform.                    " CHOOSE_VARIANT

Output:

On clicking the save button

Message is triggered “Variant is saved”

ON clicking the variant button  

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image