SUBMIT – Pass parameters to Program

By | Last Updated on March 27, 2014 | 156,407

Code snippet to show different ways to pass parameters from main program to submitted program using ABAP SUBMIT statement.

Program to be Submitted

 
REPORT ztest_np_2.
 
DATA: v_erdat TYPE vbak-erdat.
DATA: v_auart TYPE vbak-auart.
 
SELECT-OPTIONS: s_erdat FOR v_erdat,
                s_auart FOR v_auart.
 
START-OF-SELECTION.
  DATA: lv_line TYPE i.
  lv_line = lines( s_erdat ).
  WRITE: / 'S_ERDAT', lv_line.
 
  lv_line = lines( s_auart ).
  WRITE: / 'S_AUART', lv_line.
 

Program Common Part

 
DATA: v_erdat TYPE vbak-erdat.
SELECT-OPTIONS: so_date FOR v_erdat.
 
START-OF-SELECTION.
 

Passing data using SELECTION-TABLE

 
  DATA: lt_seltab  TYPE TABLE OF rsparams,
        ls_seltab  LIKE LINE OF lt_seltab.
 
  LOOP AT so_date.
    ls_seltab-selname = 'S_ERDAT'.          " Name of parameter on submitted program
    ls_seltab-kind    = 'S'.
    ls_seltab-sign    = so_date-sign.
    ls_seltab-option  = so_date-option.
    ls_seltab-low     = so_date-low.
    ls_seltab-high    = so_date-high.
    APPEND ls_seltab TO lt_seltab.
  ENDLOOP.
 
  ls_seltab-selname = 'S_AUART'.
  ls_seltab-kind    = 'S'.
  ls_seltab-sign    = 'I'.
  ls_seltab-option  = 'EQ'.
  ls_seltab-low     = 'OR'.
  APPEND ls_seltab TO lt_seltab.
 
  SUBMIT ztest_np_2
    WITH SELECTION-TABLE lt_seltab
    AND RETURN.
 

Passing Parameters Directly

 
*==== Passing Parameters directly
  SUBMIT ztest_np_2
    WITH s_erdat IN so_date
    WITH s_auart EQ 'OR' SIGN 'I'
    AND RETURN.
 

Passing parameters from Variant

 
*==== Passing parameters from Variant
  " DEFAULT is the variant on the program ZTEST_NP_2
  SUBMIT ztest_np_2
    USING SELECTION-SET 'DEFAULT'
    AND RETURN.
 

Passing parameters with generated variant

 
*==== Passing parameters with generated variant
  DATA:  ls_varid       TYPE          varid,
         lt_varit       TYPE TABLE OF varit,
         ls_varit       TYPE          varit.
 
  DATA: lt_seltab  TYPE TABLE OF rsparams,
        ls_seltab  LIKE LINE OF lt_seltab.
 
* Populate the selection table
  LOOP AT so_date.
    ls_seltab-selname = 'S_ERDAT'.          " Name of parameter on submitted program
    ls_seltab-kind    = 'S'.
    ls_seltab-sign    = so_date-sign.
    ls_seltab-option  = so_date-option.
    ls_seltab-low     = so_date-low.
    ls_seltab-high    = so_date-high.
    APPEND ls_seltab TO lt_seltab.
  ENDLOOP.
 
  ls_seltab-selname = 'S_AUART'.
  ls_seltab-kind    = 'S'.
  ls_seltab-sign    = 'I'.
  ls_seltab-option  = 'EQ'.
  ls_seltab-low     = 'OR'.
  APPEND ls_seltab TO lt_seltab.
 
* Populate the Variant Directory
  ls_varid-report  = 'ZTEST_NP_2'.
  ls_varid-variant = sy-datum && sy-uzeit && sy-uname.
  ls_varid-ename   = sy-uname.
  ls_varid-edat    = sy-datlo.
 
* Populate the Variant texts table
  ls_varit-langu   = sy-langu.
  ls_varit-report  = ls_varid-report.
  ls_varit-variant = ls_varid-variant.
  ls_varit-vtext   = 'Generated Variant'.
  APPEND ls_varit TO lt_varit.
 
  CALL FUNCTION 'RS_CREATE_VARIANT'
    EXPORTING
      curr_report               = ls_varid-report
      curr_variant              = ls_varid-variant
      vari_desc                 = ls_varid
    TABLES
      vari_contents             = lt_seltab
      vari_text                 = lt_varit
    EXCEPTIONS
      illegal_report_or_variant = 1
      illegal_variantname       = 2
      not_authorized            = 3
      not_executed              = 4
      report_not_existent       = 5
      report_not_supplied       = 6
      variant_exists            = 7
      variant_locked            = 8
      OTHERS                    = 9.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
 
  SUBMIT ztest_np_2
    USING SELECTION-SET ls_varid-variant
    AND RETURN.
 

More on Selection Screen Parameters in SUBMIT

Do you have a Code Snippet which you want to share, Submit Code Snippet here

Share It!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{274 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 274 articles.

Load comments

1 Comment

  • Asustainer

    Hi Naimesh,

    Thanks, Good example.

    Regards,
    A Sustainer

Comments on this Post are now closed. If you have something important to share, you can always contact me.