How do we define a sub-routine in a subroutine pool
How do we define a sub-routine in a subroutine pool and how do we call the same in an executable program
Hi
Go to SE38.Create a program and in the program type select Subroutine pool.Inside this u can code for teh various subroutines or forms.
For calling these forms these forms in ur main program refer below link:
<u>http://help.sap.com/saphelp_nw04/helpdata/en/9f/db999535c111d1829f0000e829fbfe/content.htm</u>
Sample code:
Below is the subroutine pool used in the creation of the SAP Script:
Program Name : Z689_SUBROUTINE
Date : 03/28/2007
Author : Sayee Manojnah Kasala
Description : This is the subroutine used for SAP Script,
Z689_SAPSCRIPT.It fetches customer details like
customer name & place
PROGRAM Z689_SUBROUTINE.
Form GET_LAND1
Fetches the country key
*& Form get_land1
text
-->INTABLE text
-->OUTTABLE text
FORM get_land1 TABLES intable STRUCTURE itcsy
outtable STRUCTURE itcsy.
DATA: v_kunnr LIKE kna1-kunnr,
v_land1 LIKE kna1-land1,
v_name1 LIKE kna1-name1.
READ TABLE intable INDEX 1.
v_kunnr = intable-value.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = v_kunnr
IMPORTING
output = v_kunnr.
IF sy-subrc = 0.
SELECT SINGLE land1
FROM kna1
INTO v_land1
WHERE kunnr = v_kunnr.
IF sy-subrc = 0.
READ TABLE outtable INDEX 1.
outtable-value = v_land1.
MODIFY outtable INDEX 1.
ENDIF.
SELECT SINGLE name1
FROM kna1
INTO v_name1
WHERE kunnr = v_kunnr.
IF sy-subrc = 0.
READ TABLE outtable INDEX 2.
outtable-value = v_name1.
MODIFY outtable INDEX 2.
ENDIF.
ENDIF.
CLEAR: intable,outtable.
ENDFORM. "get_land1
Form GET_LANDX
Fetches the Country Name
*& Form get_landx
text
-->INTABLE text
-->OUTTABLE text
FORM get_landx TABLES intable STRUCTURE itcsy
outtable STRUCTURE itcsy.
DATA: v_land1 LIKE kna1-land1,
v_landx LIKE t005t-landx.
READ TABLE intable INDEX 1.
v_land1 = intable-value.
IF sy-subrc = 0.
SELECT SINGLE landx
FROM t005t
INTO v_landx
WHERE land1 = v_land1 AND spras = 'E'.
IF sy-subrc = 0.
READ TABLE outtable INDEX 1.
outtable-value = v_landx.
MODIFY outtable INDEX 1.
ENDIF.
ENDIF.
CLEAR: intable,outtable.
ENDFORM. "get_landx
It can be called as follows:
PERFORM GET_LANDX IN PROGRAM Z689_SUBROUTINE
USING &V_LAND1&
CHANGING&V_LANDX&
ENDPERFORM.
Reward points if found useful.
Thanks
Vasudha
Message was edited by:
Vasudha L
Similar Messages
-
How do we write the sub routines in smart forms?
1) How do we write the sub routines in smart forms?
2) What is the form interface in smart forms?
3) Write down the path for writing for select queries in smart forms?
4) How do we put dynamic page break in smart forms?
5) in which system field contain the total page number of all forms in the currently processed print request in smart forms?
6) What is the name of function module used to calling smart forms?
1) What is the functionality of function module controal_form?
2) How do we print the system date in this format 15th Jan 2008 on scripts?
3) What r the various print modes available in scripts?
4) What is the tcode for text element?
5) How do we draw horizontal line in scripts?
6) How can we suppress the leading zeros for a field in scripts?
7) In which system field is used to print current no page in scripts?
Which f.m is used to reads text in sap scripts1) How do we write the sub routines in smart forms?
after opening form see global definitions
click on that there one tab called form routines inthat you can write subroutines logic.
You can call in program lines .
2) What is the form interface in smart forms?
It is an interface between program and form .
like function module we provide import,export,tables,exceptions
Based on import and export parameters form will display for us.
3) Write down the path for writing for select queries in smart forms?
On window give right click in that command->programlines
you can write all select statements.
4) How do we put dynamic page break in smart forms?
you can define break point using break-point<>. syntax.
5) in which system field contain the total page number of all forms in the currently processed print request in smart forms?
SFSY-PAGE
SFSY-JOBPAGES
6) What is the name of function module used to calling smart forms?
SSF_FUNCTION_MODULE_NAME
=================
1) What is the functionality of function module control_form?
This function module is used to insert SAPScript control commands like NEW-PAGE etc from whithin the ABAP program.
CALL FUNCTION 'CONTROL_FORM'
EXPORTING
COMMAND =
EXCEPTIONS
UNOPENED = 1
OTHERS = 3
IF SY-SUBRC NE 0.
MESSAGE ...
ENDIF.
2) How do we print the system date in this format 15th Jan 2008 on scripts?
Use SET DATE MASK to change format of date display.
3) What r the various print modes available in scripts?
4) What is the tcode for text element?
se91
5) How do we draw horizontal line in scripts?
&ULINE&
6) How can we suppress the leading zeros for a field in scripts?
&it_vbak-vbeln(Z)&
7) In which system field is used to print current no page in scripts?
&SYST-PAGE& of &SYST-FORMPAGES&
Which f.m is used to reads text in sap scripts
READ_TEXT functiomodule.
Reward points -
how can u call a sub-routine from other programmes?
Hi,
Start of Content Area
Naming Subroutines Locate the document in its SAP Library structure
With the PERFORM statement, you can call subroutines which are coded in the same ABAP program (internal calls), or subroutines which are coded in other ABAP programs (external calls).
You can also specify the name of the subroutine dynamically at runtime, and call subroutines from a list.
Internal Subroutine Calls
To call a subroutine defined in the same program, you need only specify its name in the PERFORM statement:
PERFORM subr [USING p1 p2... ]
[CHANGING p1 p2... ].
The internal subroutine can access all of the global data of the calling program.
Example
REPORT demo_mod_tech_perform_int.
DATA: num1 TYPE i,
num2 TYPE i,
sum TYPE i.
num1 = 2. num2 = 4.
PERFORM addit.
num1 = 7. num2 = 11.
PERFORM addit.
FORM addit.
sum = num1 + num2.
PERFORM out.
ENDFORM.
FORM out.
WRITE: / 'Sum of', num1, 'and', num2, 'is', sum.
ENDFORM.
This produces the following output:
Sum of 2 and 4 is 6
Sum of 7 and 11 is 18
In this example the subroutines addit and out are defined at the end of the program. addit is called by the program and out is called by addit. The subroutines have access to the global fields num1, num2 und sum.
External Subroutine Calls
The principal function of subroutines is for modularizing and structuring local programs. However, subroutines can also be called externally from other ABAP programs. In an extreme case, you might have an ABAP program that contained nothing but subroutines. These programs cannot run on their own, but are used by other ABAP programs as pools of external subroutines.
However, if you want to make a function available throughout the system, you should use function modules instead of external subroutines. You create function modules in the ABAP Workbench using the Function Builder. They are stored in a central library, and have a defined release procedure.
You can encapsulate functions and data in the attributes and methods of classes in ABAP Objects. For any requirements that exceed pure functions, you can use global classes instead of external subroutines.
When you call a subroutine externally, you must know the name of the program in which it is defined:
PERFORM subr(prog) [USING p1 p2... ]
[CHANGING p1 p2... ] [IF FOUND].
You specify the program name prog statically. You can use the IF FOUND option to prevent a runtime error from occurring if the program progdoes not contain a subroutine subr. In this case, the system simply ignores the PERFORM statement.
When you call an external subroutine, the system loads the whole of the program containing the subroutine into the internal session of the calling program (if it has not already been loaded). In order to save memory space, you should keep the number of subroutines called in different programs to a minimum.
Example
Suppose a program contains the following subroutine:
REPORT formpool.
FORM header.
WRITE: / 'Program started by', sy-uname,
/ 'on host', sy-host,
'date:', sy-datum, 'time:', sy-uzeit.
ULINE.
ENDFORM.
The subroutine can then be called from another program as follows:
REPORT demo_mod_tech_perform_ext.
PERFORM header(demo_mod_tech_formpool_1) IF FOUND.
In this example, no data is passed between the calling program and the subroutine.
Specifying Subroutines Dynamically
You can specify the name of a subroutine and, in the case of external calls, the name of the program in which it occurs, dynamically as follows:
PERFORM (fsubr)[IN PROGRAM (fprog)][USING p1 p2... ]
[CHANGING p1 p2... ]
[IF FOUND].
The names of the subroutine and the external program are the contents of the fields fsubr und fprogrespectively. By using the option IF FOUND, you can prevent a runtime error from being triggered if no subroutine with the name fsubr is found. If you omit the parentheses, this variant of the PERFORMstatement behaves like the static variant.
Example
Assume a program contains the following subroutines:
PROGRAM formpool.
FORM sub1.
WRITE: / 'Subroutine 1'.
ENDFORM.
FORM sub2.
WRITE: / 'Subroutine 2'.
ENDFORM.
Dynamic Subroutine Specification:
PROGRAM form_test.
DATA: progname(8) TYPE c VALUE 'FORMPOOL',
subrname(8) TYPE c.
subrname = 'SUB1'.
PERFORM (subrname) IN PROGRAM (progname) IF FOUND.
SUBRNAME = 'SUB2'.
PERFORM (subrname) IN PROGRAM (progname) IF FOUND.
This produces the following output:
Subroutine 1
Subroutine 2
The character field progname contains the name of the program, in which the subroutines are contained. The names of the subroutines are assigned to the character field subrname.
Calling Subroutines from a List
You can call a subroutine from a list as follows:
PERFORM idx OF subr1 subr2 ... subrn.
The system calls the subroutine specified in the subroutine list in position idx. You can only use this variant of the PERFORMstatement for internal subroutine calls, and only for subroutines without a parameter interface. The field idx can be a variable or a literal.
Example
REPORT demo_mod_tech_perform_list.
DO 2 TIMES.
PERFORM sy-index OF sub1 sub2.
ENDDO.
FORM sub1.
WRITE / 'Subroutine 1'.
ENDFORM.
FORM sub2.
WRITE / 'Subroutine 2'.
ENDFORM.
This produces the following output:
Subroutine 1
Subroutine 2
Regards,
Chandru -
How to define a Sub Type in IT0717
Hi Experts,
Currently working on Benefit point account.
could some one tell me how to define a Sub Type for IT717.
how do i configure.
Appreciate your response.
Regards
RajHi,
I have created the subtype in the table you specified.
But unable to see the created subtypes for IT552 in PA30.
Appreciate your further inputs.
Regards
Rajesh.N.S -
How to on Debugging Mode for T-Code F110 from Script in Sub routine Pool Pr
Hi Every one....
I have done SAP-Script for Payment Vocher for T-code F110 ..I have a Sub Routine Program where I have few Form statements which is called by SAP - Script using Perform Statements, But my problem is when I set a break point in Sub Routine pool program, the out put is issuing with out Debugger ...
Could any one plz suggest me wht to do???
Help ful answers will be rewarded....
Regards,
sgHi,
First see if the 'Perform' statement is getting triggered in Script. To put a breakpoint in any script ( even if you do not know the form name, that is the best part ) is se38---->RSTXDBUG --->F8 & execute your pgm/Transaction. The control will wait in the form-debugger.
I hope this helps,
Regards
Raju Chitale -
How do i make this a sub routine
I have a little script to drill down folders and add comments to every folder and ever file inside the parent folder. It works perfectly well when run but itself. This was based heavily on the script found by NovaScotian here http://discussions.apple.com/thread.jspa?messageID=2182916�
I basically want to make this script into a sub routine, and i have tried various methods and havent been able to make it work.
global the_comments
global each_item
global pete
global ddp
global ddp2
set ddp to {}
set ddp2 to {}
set theLetter to "s"
set newDroppedFiles to choose folder with multiple selections allowed
to drilldown(afolder)
tell application "Finder"
set file_list to files of a_folder
set folder_list to folders of a_folder
end tell
repeat with i in file_list
processDrilledDownFile(i)
tell application "Finder"
set comment of pete to text of the_comments
end tell
end repeat
repeat with i in folder_list
copy i to end of ddp2
drill_down(i)
end repeat
end drill_down
on processDrilledDownFile(a_file)
copy a_file to end of ddp
end processDrilledDownFile
set the_comments to (do shell script "/usr/bin/defaults read com.Rich.move " & theLetter & "Text")
repeat with each_item in newDroppedFiles
set pete to each_item
tell application "Finder"
set comment of each_item to text of the_comments
end tell
drill_down(pete)
end repeat
repeat with each_item in ddp
tell application "Finder"
set comment of each_item to text of the_comments
end tell
end repeat
repeat with each_item in ddp2
tell application "Finder"
set comment of each_item to text of the_comments
end tell
end repeat
regards
RichYour script already includes several subroutines, so the trick is separating those out first.
Essentially your script consists of three elements - global declarations, your own subroutines and a run handler. Since there's no explicit 'on run', everything that's not inside a subroutine becomes the run handler.
Therefore what you should do is strip out all the code that's not a global declaration or an existing handler and just wrap that in a new 'on subroutinename()... end subroutinename' block.
For sanity's sake I'd also add a specific run handler to bind it all together.
This means you'll end up with something like:
<pre class=command>global the_comments
global each_item
global pete
global ddp
global ddp2
on run
my myNiftySubroutine()
end run
to drilldown(afolder)
tell application "Finder"
set file_list to files of a_folder
set folder_list to folders of a_folder
end tell
repeat with i in file_list
processDrilledDownFile(i)
tell application "Finder"
set comment of pete to text of the_comments
end tell
end repeat
repeat with i in folder_list
copy i to end of ddp2
drill_down(i)
end repeat
end drill_down
on processDrilledDownFile(a_file)
copy a_file to end of ddp
end processDrilledDownFile
on myNiftySubroutine()
set ddp to {}
set ddp2 to {}
set theLetter to "s"
set newDroppedFiles to choose folder with multiple selections allowed
set the_comments to (do shell script "/usr/bin/defaults read com.Rich.move " & theLetter & "Text")
repeat with each_item in newDroppedFiles
set pete to each_item
tell application "Finder"
set comment of each_item to text of the_comments
end tell
drill_down(pete)
end repeat
repeat with each_item in ddp
tell application "Finder"
set comment of each_item to text of the_comments
end tell
end repeat
repeat with each_item in ddp2
tell application "Finder"
set comment of each_item to text of the_comments
end tell
end repeat
end myNiftySubroutine</pre>
There's just one other observation - most of the globals are not actually needed since you can just pass them as parameters to the subroutines.
I'm also not sure what the purpose of the script is - the upshot seems to be that you're setting the comment of items in the Finder, however, since you:
<pre class=command> set comment of pete to text of the_comments</pre>
and pete is a global pointing to the folder you're processing, surely this sets the comment of the folder x times, where x is the number of files in the folder - in other words if there are 100 files in the folder, you set the comment of the folder 100 times and don't touch the files themselves. Is that what you intend? -
How to include in the sub-menu a table specifies of the user - UDO
hi, forum
how to include in the sub-menu a table specifies of the user
I created a table '@ IA_RELAT' in User-Defined Obejcts but I don't know as including in the sub-menu that I created
it follows my code
Private Sub SBO_Application_MenuEvent(ByRef pVal As SAPbouiCOM.MenuEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.MenuEvent
If (pVal.MenuUID = "MySubMenu") And (pVal.BeforeAction = False) Then
Try
<u201DmyTableName->@IA_RELATu201D>
Catch
SBO_Application.MessageBox("The Form already exists")
End Try
End If
thank you
End SubHi David
Excuse me but I didn't find in MenuCreationParams Objects how to do this call of the table '@ IA_RELAT' created in User-Defined Obejcts
It follows my code
in AddMenuItems I set up the Menu and Submenu
in SBO_Application_MenuEvent it is where I am having difficulties of showing the table '@ IA_RELAT' created in User-Defined Obejcts
Thank you for any help
Private Sub AddMenuItems()
Dim oCreationPackage As SAPbouiCOM.MenuCreationParams
oCreationPackage = SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_MenuCreationParams)
oMenuItem = SBO_Application.Menus.Item("43520") 'moudles'
Dim sPath As String
sPath = Application.StartupPath
sPath = sPath.Remove(sPath.Length - 3, 3)
oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_POPUP
oCreationPackage.UniqueID = "MyMenu01"
oCreationPackage.String = "Standard cost"
oCreationPackage.Enabled = True
oCreationPackage.Image = sPath & "UI.bmp"
oCreationPackage.Position = 15
oMenus = oMenuItem.SubMenus
Try ' If the manu already exists this code will fail
oMenus.AddEx(oCreationPackage)
'// Get the menu collection of the newly added pop-up item
oMenuItem = SBO_Application.Menus.Item("MyMenu01")
oMenus = oMenuItem.SubMenus
'// Create s sub menu
oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_STRING
oCreationPackage.UniqueID = "MySubMenu"
oCreationPackage.String = "Auxiliary Table"
oMenus.AddEx(oCreationPackage)
Catch er As Exception ' Menu already exists
SBO_Application.MessageBox("Menu Already Exists")
End Try
End Sub
Private Sub SBO_Application_MenuEvent(ByRef pVal As SAPbouiCOM.MenuEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.MenuEvent
If (pVal.MenuUID = "MySubMenu") And (pVal.BeforeAction = False) Then
Try
SBO_Application.ActivateMenuItem(menus.Item(1).UID.IndexOf("@IA_RELAT"))
Catch
SBO_Application.MessageBox("error")
End Try
End If
End Sub -
Passing parametrs to Sub routines
Hi all,
Please tell me how to pass the Parameters as message number and message id for an SUB ROUTINE.If possible please give me the sample code.
Regards
Ajaydeclare
data : message_nm type sy-msgno,
sys_id type sy-repid.
simply write rthe oerform AS
perform sample_form using message_nm
sys_id
then in the form.
form sample_form using message_nm type sy-msgno
sys_id type sy-repid .
endform.
reward points if useful...
Edited by: Rudra Prasanna Mohapatra on Jun 25, 2008 1:41 PM -
Urgent!!!!Related To SUB-ROUTINES
Hi All,
I have 2 subroutines.My problem is that if a particular sub-routine is terminated in middle for any reason my second sub-routine should not get called.How can i know that?Please answer my question as soon as possible.
Useful answers will be rewarded with points.
Regards,
Chaitanya.
Message was edited by:
LEELA KRISHNA SAI CHAITANYAHi leela,
you can use one global variable for this as flag.
ex:
data flag type c.
perform sub1.
if flag = 'X'.
perform sub2.
endif.
form sub1.
if (condition yes).
flag = 'X'.
endif.
endform.
form sub2.
endform.
this will work well -
Smart forms not displaying result from sub routine
I am working on a smart form and need to display the description of the fabric code. Under Form Routines, I create a sub routine
FORM fcc_values USING gv_fabrictext.
which is supposed to store the description in gv_fabrictext. GV_FABRICTEXT has been declared in global data as char64. Then I call prior to displaying my table as
perform fcc_values using gv_fabrictext.
And then insert the field &gv_fabrictext& in cell but this does not display any result
I know for sure that this sub routine works as I have tested it separately as a test program. Any ideas?1. put break point at ssf_function madulename and check field value.
or
2 fm_name export parameter ur not mentioned
or
3 global variable not defined properly
go through above. still if u didnt get
need program where the problem to find.
Message was edited by:
Deepa KN -
How can we define custom error page in protal application
How can we define custom error page in protal application, like we define "jsp Error page " in JSPs
Hi,
Check these:
Customization of Portal Runtime Errors and portal standard error codes
http://help.sap.com/saphelp_nw04/helpdata/en/9a/e74d426332bd30e10000000a155106/frameset.htm
http://help.sap.com/saphelp_nw04/helpdata/en/ec/1273b2c413b2449e554eb7b910bce7/frameset.htm
Regards,
Praveen Gudapati -
Select statement in a sub routine(For Sapscript)
Hi,
M unable to write select statement for my reqirement in Sap-script in Sub routine.
My requirement is 1)"Your correspondent for quality" in main window of my form.
For dis rule is as below
"Get the 'changed by' value resord in table QCPR field AENDERER.For the same value found in tabe USR21 fiels BNAME,pick up the PERSUNUM value.For dis PERSUNUM value, found in ADRP feild NAME_TEXT the value for "Your Correspondent for Quality".
2) For this PERSUNUM value found in ADCP-TEL_NUMBER the vakue for "Ph".
3)For this PERSUNUM value found in ADCP-FAX_NUMBER the vakue for "FAX".
4For this PERSUNUM value found in ADR6-SMTP_ADDR the vakue for "EMAIL".
Please help me out it's urgent for me.I wil b waiting 4 ur reply.READ TABLE in_par WITH KEY 'QCPR-AENDERER'.
CHECK sy-subrc = 0.
MOVE in_par-value TO V_aenderer
. READ TABLE in_par WITH KEY 'USR21-BNAME.
CHECK sy-subrc = 0.
MOVE in_par-value TO V_bname
SELECT SINGLE persnumber addrnumber
INTO wa_usr21-persnumber wa_usr21-addrnumber
FROM usr21
WHERE bname = V_bname
and <b>check field for this</b> = V_aenderer.
CHECK sy-subrc = 0.
SELECT SINGLE tel_number fax_number
INTO adcp-tel_number adcp-fax_number
FROM adcp
WHERE addrnumber = usr21-addrnumber
AND persnumber = usr21-persnumber.
CHECK sy-subrc = 0.
READ TABLE out_par WITH KEY 'ADCP-TEL_NUMBER'.
CHECK sy-subrc = 0.
out_par-value = adcp-tel_number.
MODIFY out_par INDEX sy-tabix.
READ TABLE out_par WITH KEY 'ADCP-FAX_NUMBER'.
CHECK sy-subrc = 0.
out_par-value = adcp-fax_number.
MODIFY out_par INDEX sy-tabix.
SELECT SINGLE smtp_addr
INTO adr6-smtp_addr
FROM adr6
WHERE addrnumber = usr21-addrnumber
AND persnumber = usr21-persnumber.
READ TABLE out_par WITH KEY 'ADR6-SMTP_ADDR'.
CHECK sy-subrc = 0.
out_par-value = adr6-smtp_addr.
MODIFY out_par INDEX sy-tabix.
Regards -
How can I define Double Click Processing in SAP Query ?
The first question is : How Can I define drill-down for SAP Query report ?
The second one : How can I program Double Click in SAP Query report for Different columns like ALV Grid processing ?you can attach a repot or at tcode etc in an SAP query using report assignment in SQ01 but as far as i remember you cannot attach multiple reports.
regards,
khusro habib -
How do I define javascript global variables to use across windows
I have a number of web pages. I have javascript for each page. I need to share some data across the web pages. How do I define javascript variables that can be accessed from multiple web pages?
Use SugarSync.
-
How can I create a sub-iTunes account for a teen?
how can I create a sub-iTunes account for a teen?
I need to separate our music libraries but still keep it under control from the main account (mine).iOS 5 & iCloud Tips: Sharing an Apple ID With Your Family
Maybe you are looking for
-
How to avoid roundtrip to server on value select in dropdown box in ALV cel
Dear Experts, I have WD ALV table where user edits values in the cels using dropdown by key element. Then after edit he saves whole table. When value is changed in dropdown box the roundtrip to server occurs and it takes noticable time for every cell
-
How do I get rid of Startnow and Bing on my tool bar. I don't want to use them
I want to remove Startnow and bing from my firefox tool bar. I am using dogpile.
-
When I first got my Power Mac G5, I was able to create and read data DVDs to back things up. Lately, when I put a data DVD into the drive, no icon shows up and I can't access any of the information I've saved. What should I do? Rob
-
GL : Display report FAGLL03
Dear Experts, Report Path : FI Accounting >> Gen Ledger >> Account >> FAGLL03 (Display Line Items) I have selected a Balance Sheet Account's Payable GL. in this GL display line items, i have saved a selected a few preffered fields, as wanted by the c
-
Dear Experts, In June we had retired several assets from company (xxx is not used anymore and does not have depreciation posted any longer) and when we reconcile the G/L to the Asset Module, there is an out of balance in g/l acct 0720 0000 (Accum. De