Application Development and Automation 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: 
Read only

subroutine

Former Member
0 Likes
1,073

what is the use of subroutine pool in scripts?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
978

Hi,

Its an Abap prog of type sub routine pool, it is used for calculating certain variables, eg DUE date for an Invoice. You pass the values from the form thru ITCSY structure intot he prgram.

Regards,

Bhaskar

4 REPLIES 4
Read only

Former Member
0 Likes
979

Hi,

Its an Abap prog of type sub routine pool, it is used for calculating certain variables, eg DUE date for an Invoice. You pass the values from the form thru ITCSY structure intot he prgram.

Regards,

Bhaskar

Read only

Former Member
0 Likes
978

Hi Kaladhar,

check this.

Subroutine Pools

Subroutine pools, as the name implies, were created to contain selections of subroutines that can be called externally from other programs. Before release 6.10, this was the only way subroutine pools could be used. But besides subroutines, subroutine pools can also contain local classes and interfaces. As of release 6.10, you can connect transaction codes to methods. Therefore, you can now also call subroutine pools via transaction codes. This is the closest to a Java program you can get in ABAP: a subroutine pool with a class containing a method – say – main connected to a transaction code.

Subroutine pools are created using the ABAP Editor and are introduced with the PROGRAM statement. They may not contain any screens of their own, and with the exception of the LOAD-OF-PROGRAM event block they may only use subroutines as processing blocks. Subroutine pools are loaded by externally calling their subroutines from within other ABAP programs.

DATA: CODE(72) OCCURS 10,

PROG(8), MSG(120), LIN(3), WRD(10), OFF(3).

APPEND 'PROGRAM SUBPOOL.'

TO CODE.

APPEND 'FORM DYN1.'

TO CODE.

APPEND

'WRITE / ''Hello, I am the temporary subroutine DYN1!''.'

TO CODE.

APPEND 'ENDFORM.'

TO CODE.

APPEND 'FORM DYN2.'

TO CODE.

APPEND

'WRIT / ''Hello, I am the temporary subroutine DYN2!''.'

TO CODE.

APPEND 'ENDFORM.'

TO CODE.

GENERATE SUBROUTINE POOL CODE NAME PROG

MESSAGE MSG

LINE LIN

WORD WRD

OFFSET OFF.

IF SY-SUBRC <> 0.

WRITE: / 'Error during generation in line', LIN,

/ MSG,

/ 'Word:', WRD, 'at offset', OFF.

ELSE.

WRITE: / 'The name of the subroutine pool is', PROG.

SKIP 2.

PERFORM DYN1 IN PROGRAM (PROG).

SKIP 2.

PERFORM DYN2 IN PROGRAM (PROG).

ENDIF.

In this program, a subroutine pool containing two subroutines is placed into table CODE. Note that the temporary program must contain a REPORT or PROGRAM statement. Statement GENERATE SUBROUTINE POOL generates the temporary program.

A generation error occurred since the WRITE statement has been misspelled in the second subroutine, DYN2. After that line has been revised:

APPEND

'WRITE / ''Hello, I am the temporary subroutine DYN2!''.'

TO CODE.

Generation was successful. The internal program name is displayed. Then, the subroutines of the subroutine pool are called. Note that you do not need to know the program name to call the subroutines.

Also check this.

How to call a subroutine form SAPscripts

The Form :

/:PERFORM CDE_CENT IN PROGRAM ZKRPMM_PERFORM_Z1MEDRUCK

/:USING &EKKO-EBELN&

/:CHANGING &CDECENT&

/:ENDPERFORM

The report :

REPORT zkrpmm_perform_z1medruck .

DATA : BEGIN OF it_input_table OCCURS 10.

INCLUDE STRUCTURE itcsy.

DATA : END OF it_input_table.

  • déclaration de la table output_table contenant les

variables exportées

DATA : BEGIN OF it_output_table OCCURS 0.

INCLUDE STRUCTURE itcsy.

DATA : END OF it_output_table.

DATA : w_ebeln LIKE ekko-ebeln,

  • w_vbeln LIKE vbak-vbeln,

w_zcdffa LIKE vbak-zcdffa.

*----


*

  • FORM CDE_CENT

*

*----


*

FORM cde_cent TABLES input output.

it_input_table[] = input[].

it_output_table[] = output[].

READ TABLE it_input_table INDEX 1.

MOVE it_input_table-value TO w_ebeln.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = w_ebeln

IMPORTING

output = w_ebeln.

SELECT SINGLE zcdffa FROM ekko

INTO w_zcdffa

WHERE ebeln = w_ebeln.

it_output_table-name = 'CDECENT'.

MOVE w_zcdffa TO it_output_table-value.

MODIFY it_output_table INDEX 1.

output[] = it_output_table[].

ENDFORM.

*************************************************************************

/: PERFORM

/: USING &INVAR1&

/: USING &INVAR2&

......

/: CHANGING &OUTVAR1&

/: CHANGING &OUTVAR2&

......

/: ENDPERFORM

INVAR1 and INVAR2 are variable symbols and may be of any of the four SAPscript symbol types.

OUTVAR1 and OUTVAR2 are local text symbols and must therefore be character strings.

Example:

In script form

/: PERFORM READ_TEXTS IN PROGRAM 'Z08M1_FORM_EKFORM1'

/: USING &EKKO-EKORG&

/: USING &EKPO-WERKS&

/: USING &EKKO-EKGRP&

/: USING &EKKO-BSTYP&

/: CHANGING &COMPNAME&

/: CHANGING &SENDADR&

/: CHANGING &INVCADR&

/: CHANGING &COMPADR&

/: CHANGING &COVERLTR&

/: CHANGING &SHIPADR&

/: CHANGING &REMINDER&

/: CHANGING &REJECTION&

/: CHANGING &POSTADR&

/: CHANGING &LOGO&

/: ENDPERFORM

In program

*----


*

  • FORM Read_texts - To extract the standard texts from the table *

*----


*

FORM READ_TEXTS TABLES IN_PAR STRUCTURE ITCSY

OUT_PAR STRUCTURE ITCSY.

DATA : L_EKORG TYPE EKORG,

L_WERKS TYPE WERKS_D,

L_BSTYP TYPE BSTYP,

L_EKGRP TYPE BKGRP.

READ TABLE IN_PAR WITH KEY 'EKKO-EKORG' .

CHECK SY-SUBRC = 0.

L_EKORG = IN_PAR-VALUE.

READ TABLE IN_PAR WITH KEY 'EKPO-WERKS' .

CHECK SY-SUBRC = 0.

L_WERKS = IN_PAR-VALUE.

READ TABLE IN_PAR WITH KEY 'EKKO-EKGRP' .

CHECK SY-SUBRC = 0.

L_EKGRP = IN_PAR-VALUE.

READ TABLE IN_PAR WITH KEY 'EKKO-BSTYP' .

CHECK SY-SUBRC = 0.

L_BSTYP = IN_PAR-VALUE.

CLEAR Z08M1_ORG_TEXTS.

SELECT SINGLE * FROM Z08M1_ORG_TEXTS WHERE EKORG = L_EKORG

AND WERKS = L_WERKS

AND EKGRP = L_EKGRP

AND BSTYP = L_BSTYP.

IF SY-SUBRC NE 0.

SELECT SINGLE * FROM Z08M1_ORG_TEXTS WHERE EKORG = L_EKORG

AND WERKS = L_WERKS

AND EKGRP = L_EKGRP

AND BSTYP = SPACE.

ENDIF.

READ TABLE OUT_PAR WITH KEY 'COMPNAME'.

OUT_PAR-VALUE = Z08M1_ORG_TEXTS-TXT_COMP.

MODIFY OUT_PAR INDEX SY-TABIX.

READ TABLE OUT_PAR WITH KEY 'SENDADR'.

OUT_PAR-VALUE = Z08M1_ORG_TEXTS-TXT_ADRS.

MODIFY OUT_PAR INDEX SY-TABIX.

READ TABLE OUT_PAR WITH KEY 'INVCADR'.

OUT_PAR-VALUE = Z08M1_ORG_TEXTS-TXT_INVC.

MODIFY OUT_PAR INDEX SY-TABIX.

READ TABLE OUT_PAR WITH KEY 'COMPADR'.

OUT_PAR-VALUE = Z08M1_ORG_TEXTS-TXT_CPAD.

MODIFY OUT_PAR INDEX SY-TABIX.

READ TABLE OUT_PAR WITH KEY 'COVERLTR'.

OUT_PAR-VALUE = Z08M1_ORG_TEXTS-TXT_COVR.

MODIFY OUT_PAR INDEX SY-TABIX.

READ TABLE OUT_PAR WITH KEY 'SHIPADR'.

OUT_PAR-VALUE = Z08M1_ORG_TEXTS-TXT_SHIP.

MODIFY OUT_PAR INDEX SY-TABIX.

READ TABLE OUT_PAR WITH KEY 'REMINDER'.

OUT_PAR-VALUE = Z08M1_ORG_TEXTS-TXT_RMDR.

MODIFY OUT_PAR INDEX SY-TABIX.

READ TABLE OUT_PAR WITH KEY 'REJECTION'.

OUT_PAR-VALUE = Z08M1_ORG_TEXTS-TXT_RJCT.

MODIFY OUT_PAR INDEX SY-TABIX.

READ TABLE OUT_PAR WITH KEY 'POSTADR'.

OUT_PAR-VALUE = Z08M1_ORG_TEXTS-TXT_POST.

MODIFY OUT_PAR INDEX SY-TABIX.

READ TABLE OUT_PAR WITH KEY 'LOGO'.

OUT_PAR-VALUE = Z08M1_ORG_TEXTS-TXT_LOGO.

MODIFY OUT_PAR INDEX SY-TABIX.

ENDFORM.

*************************************************************************

REPORT ZMPO1 .

form get_freight tables in_par structure itcsy out_par structure itcsy.

tables: ekko,konv,t685t.

data: begin of itab occurs 0,

ebeln like ekko-ebeln,

knumv like ekko-knumv,

end of itab.

data: begin of itab1 occurs 0,

knumv like konv-knumv,

kposn like konv-kposn,

kschl like konv-kschl,

kbetr like konv-kbetr,

waers like konv-waers,

kwert like konv-kwert,

end of itab1.

data: begin of iout occurs 0,

kschl like konv-kschl,

vtext like t685t-vtext,

kbetr like konv-kbetr,

kwert like konv-kwert,

end of iout.

data v_po like ekko-ebeln.

read table in_par with key 'EKKO-EBELN'.

if sy-subrc = 0.

v_po = in_par-value.

select

ebeln

knumv

from ekko

into table itab

where ebeln = v_po.

if sy-subrc = 0.

loop at itab.

select

knumv

kposn

kschl

kbetr

waers

kwert

into table itab1

from konv

where knumv = itab-knumv and

kappl = 'M'.

endloop.

loop at itab1.

if itab1-kposn <> 0.

select single * from t685t

where kschl = itab1-kschl

and kappl = 'M'

and spras = 'EN'.

iout-vtext = t685t-vtext.

iout-kschl = itab1-kschl.

iout-kbetr = itab1-kbetr.

iout-kwert = itab1-kwert.

append iout.

clear iout.

endif.

endloop.

sort itab1 by kposn.

loop at iout.

sort iout by kschl.

if ( iout-kschl eq 'GSDC' OR

iout-kschl eq 'GSFR' OR

iout-kschl eq 'GSIR' ).

at end of kschl.

read table iout index sy-tabix.

sum.

  • write:/ iout-kschl,iout-vtext,iout-kwert.

out_par-name = 'A1'.

out_par-value = iout-vtext.

append out_par.

out_par-name = 'A2'.

out_par-value = iout-kwert.

append out_par.

endat.

endif.

endloop.

endif.

endif.

endform.

  • IN THE FORM I AM WRITING THIS CODE.

/:DEFINE &A1& = ' '

/:DEFINE &A2& = ' '

/:PERFORM GET_FREIGHT IN PROGRAM ZMFORM_PO1

/:USING &EKKO-EBELN&

/:CHANGING &A1&

/:CHANGING &A2&

/:ENDPERFORM

  • &A1&

  • &A2&

This Code is to be written in the PO form under ADDRESS window.

-

-


/:DEFINE &A1& = ' '

/:DEFINE &A2& = ' '

/:DEFINE &A3& = ' '

/:DEFINE &A4& = ' '

/:DEFINE &A5& = ' '

/:DEFINE &A6& = ' '

/:PERFORM GET_VENDOR IN PROGRAM ZMFORM_PO

/:USING &EKKO-EBELN&

/:CHANGING &A1&

/:CHANGING &A2&

/:CHANGING &A3&

/:CHANGING &A4&

/:CHANGING &A5&

/:CHANGING &A6&

/:ENDPERFORM

  • &A1&

  • &A2&

  • &A3&

  • &A4&

  • &A5&

  • &A6&

cheers,

Hema.

Read only

Former Member
0 Likes
978

hi

good

Subroutine Pools

Subroutine pools are created using the ABAP Editor and are introduced with the PROGRAM statement. They may not contain any screens of their own, and with the exception of the LOAD-OF-PROGRAM event block they may only use subroutines as processing blocks. Subroutine pools are loaded by externally calling their subroutines from within other ABAP programs

check this

code

Hi

*You have to call sub routine from script like this.

/: PERFORM DATE_FORMAT IN PROGRAM &SY-REPID&

/: USING &RM06P-LFDAT&

/: USING &PEKKO-LFDAT&

/: CHANGING &VALUE_OLD&

/: CHANGING &VALUE_NEW&

/: ENDPERFORM

*In print program write code.

FORM date_format TABLES in_tab STRUCTURE itcsy

out_tab STRUCTURE itcsy.

DATA : date TYPE char10.

DATA : date2 TYPE char10.

DATA : l_dmbtr TYPE char10.

READ TABLE in_tab WITH KEY 'RM06P-LFDAT'.

IF sy-subrc = 0.

"Your code goes here

CLEAR l_dmbtr.

ENDIF.

READ TABLE in_tab WITH KEY 'PEKKO-LFDAT'.

IF sy-subrc = 0.

l_dmbtr = in_tab-value.

"Your code goes here

CLEAR l_dmbtr.

ENDIF.

READ TABLE out_tab WITH KEY 'VALUE_NEW'.

IF sy-subrc EQ 0.

out_tab-value = date2.

MODIFY out_tab INDEX sy-tabix.

ENDIF.

READ TABLE out_tab WITH KEY 'VALUE_OLD'.

IF sy-subrc = 0.

out_tab-value = l_dmbtr.

MODIFY out_tab INDEX sy-tabix.

ENDIF.

ENDFORM. "DATE_FORMAT

[/code]

thanks

mrutyun^

Read only

Former Member
0 Likes
978

Hi,

Subroutines are used to modularize your program structure for better readability and function flow.

You can use the PERFORM command to call an ABAP subroutine (form) from any program,

Syntax in a form window:

/: PERFORM <form> IN PROGRAM <prog>

/: USING &INVAR1&

/: USING &INVAR2&

......

/: CHANGING &OUTVAR1&

/: CHANGING &OUTVAR2&

......

/: ENDPERFORM

The ABAP subroutine called via the command line stated above must be defined in the ABAP report prog as follows:

FORM <form> TABLES IN_TAB STRUCTURE ITCSY

OUT_TAB STRUCTURE ITCSY.

...

ENDFORM.

The values of the SAPscript symbols passed with /: USING... are now stored in the internal table IN_TAB . Note that the system passes the values as character string to the subroutine, since the field Field VALUE in structure ITCSY has the domain TDSYMVALUE (CHAR 80).

The internal table OUT_TAB contains names and values of the CHANGING parameters

in the PERFORM statement.

U will have an option called 'Copy from client' in se71.

To maintain Translations for the STANDARD TEXTS u no need to go to SE63.. instead in SO10... u can give the same name with different languages

suppose u have z_test_tex in language EN.

u want to translate it to DE.. then

goto SO10> enter the name z_test_tex , Language 'DE'..->then press Create> enter whatever u want...

u can use the same name in script-->but u need to mention the Language...

based on the Language u have given, system will take the text.

Hope it helps

Regards,

Chandru