cancel
Showing results for 
Search instead for 
Did you mean: 

Calling subroutine from SAP Script

Former Member
0 Kudos

Hi Experts,

I wan to call a subroutine from SAP Script. My window has the content

/: PERFORM DISPLAY IN ZPROG

/: ENDPERFORM

/ &v_value&

My program is like

Report ZPROG.

Data : v_value type string.

Form display.

v_value = 'VENKAT'.

Endform.

But I am not gettting the value 'VENKAT' in my SAP script preview.

Kindly help me out

Thanks and regards,

Venkat.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

it works like following:


PERFORM YTEXT_PRINT IN PROGRAM Y_LAENGE_EMATN
USING &LTAK-TANUM&
USING &LTAK-LGNUM&
USING &VBLKK-VBELN&
USING &VBLKP-POSNR&
USING &LTAP-WERKS&
CHANGING &TA_QUITTED&
CHANGING &YTDNAME&
CHANGING &PRINT_LINE&


form YTEXT_PRINT     TABLES in_tab  STRUCTURE itcsy
                            out_tab STRUCTURE itcsy.

  data: lv_tanum      type ltak-tanum,
        lv_lgnum      type ltak-lgnum,
        lv_kquit      type ltak-kquit,
        lv_vbeln      type vbeln,
        lv_posnr      type posnr,
        lv_print_line type xfeld,
        lv_werks      type werks_d.

  read table in_tab
  with key name = 'LTAK-TANUM'.
  if sy-subrc = 0.
    lv_tanum = in_tab-value.
  endif.

  read table in_tab
  with key name = 'LTAK-LGNUM'.
  if sy-subrc = 0.
    lv_lgnum = in_tab-value.
  endif.

  read table in_tab
  with key name = 'VBLKK-VBELN'.
  if sy-subrc = 0.
    lv_vbeln = in_tab-value.
  endif.

  read table in_tab
  with key name = 'VBLKP-POSNR'.
  if sy-subrc = 0.
    lv_posnr = in_tab-value.
  endif.

  read table in_tab
  with key name = 'LTAP-WERKS'.
  if sy-subrc = 0.
    lv_werks = in_tab-value.
  endif.

  select single kquit
  from   ltak
  into   lv_kquit
  where  lgnum = lv_lgnum
  and    tanum = lv_tanum.

  select single print_line
  from   YSD_PRINT_CHARG
  into   lv_print_line
  where  werks = lv_werks.

  read table out_tab
  with key name = 'TA_QUITTED'.
  if sy-subrc = 0.
    out_tab-value = lv_kquit.
    modify out_tab index sy-tabix.
  endif.

  read table out_tab
  with key name = 'YTDNAME'.
  if sy-subrc = 0.
    concatenate lv_vbeln lv_posnr into out_tab-value.
    modify out_tab index sy-tabix.
  endif.

  read table out_tab
  with key name = 'PRINT_LINE'.
  if sy-subrc = 0.
    out_tab-value = lv_print_line.
    modify out_tab index sy-tabix.
  endif.
endform.

Edited by: Florian Kemmer on Sep 2, 2010 7:41 AM

Former Member
0 Kudos

Hi Florian,

Earlier I had called the subroutine like

/: PERFORM DISPLAY IN PROGRAM ZPROG

/: ENDPERFORM

It was showing a dump "No arguments are 0. Whereas I am passing 4 arguments. Later I removed that keyword "PROGRAM" from my perform statement.

Now it doesn't give dump. But the value doesn't come. ZPROG is my driver program only. So, the &v_value& will be visible in my SAP Script form. v_value is a global variable. So, I no need to pass as an argument.

Kindly help me out.

Thanks and regards,

Venkatraman.N,

+91-9008662000.

arul_murugan
Active Participant
0 Kudos

Hi,

In SAP script , if you want to change any values through the subroutine, first u need to pass the variable to the subroutine other wise it will know which variable u want to change.

see the example code for your requirement.

/: PERFORM DISPLAY IN PROGRAM ZPROG

/: USING &V_VALUE&

/: CHANGING &V_VALUE&

/: ENDFORM

  • &V_VALUE&

In the subroutine.

form DISPLAY TABLES in_tab STRUCTURE itcsy

out_tab STRUCTURE itcsy.

read table out_tab with key name = 'V_VALUE'.

if sy-subrc = 0.

out_tab-value = 'PRINT'.

modify out_tab index sy-tabix.

endif.

endform.

Thanks

Arul

Subhankar
Active Contributor
0 Kudos

Hi Venkat,

When you call subroutine from SAP Script editor you need to pass value by USING and CHANGING statement.

Suppose you have ADRNR then you want the details. the in the USING statement pass ADRNR and the other fields which you want to retrieve from this ADRNR, pass it as CHANGING parameters. Inside the the perform it passing two internal tables one is for USING and another for CHANGING parameters.

For details check the sample code.

/: PERFORM SUB_GET_EMAIL_ADDR IN PROGRAM Z_SPRN_POOL_FORM0094_SCR2074

/: USING &V_EMAIL&

/: USING &V_WR_LINE&

/: CHANGING &V_MAIL_1&

/: CHANGING &V_MAIL_2&

/: ENDPERFORM

Z1 ,,&V_HTNM-MFRPN&,,&SY-VLINE& &V_MAIL_1& ,, ,, ,, ,, ,,

form sub_get_email_addr tables p_i_in_tab structure itcsy " USING parameter

p_i_out_tab structure itcsy. " Changing PARAMETER

data: l_email type char70,

l_email1 type char35,

l_email2 type char35,

l_wrap_cont type i,

l_wa_in_tab type itcsy,

l_wa_out_tab type itcsy.

  • Reading the Input parameters from the input table of the subroutine

read table p_i_in_tab into l_wa_in_tab

with key name = 'V_EMAIL'.

if sy-subrc = 0.

l_email = l_wa_in_tab-value.

endif.

read table p_i_in_tab into l_wa_in_tab

with key name = 'V_WR_LINE'.

if sy-subrc = 0.

l_wrap_cont = l_wa_in_tab-value.

endif.

call function 'RKD_WORD_WRAP'

exporting

textline = l_email

outputlen = l_wrap_cont

importing

out_line1 = l_email1

out_line2 = l_email2

exceptions

outputlen_too_large = 1

others = 2.

if sy-subrc = 0.

  • Populate Email Address

read table p_i_out_tab into l_wa_out_tab

with key name = 'V_MAIL_1'.

if sy-subrc = 0.

l_wa_out_tab-value = l_email1.

modify p_i_out_tab index sy-tabix from l_wa_out_tab

transporting value.

clear l_wa_out_tab.

endif.

read table p_i_out_tab into l_wa_out_tab

with key name = 'V_MAIL_2'.

if sy-subrc = 0.

l_wa_out_tab-value = l_email2.

modify p_i_out_tab index sy-tabix from l_wa_out_tab

transporting value.

clear l_wa_out_tab.

endif.

endif.

endform. "SUB_GET_EMAIL_ADDR