Application Development 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: 

Calling subroutine program from script

Former Member
0 Kudos

Hi,

I am calling a subrouting program from a script. Actually i should pass a parameter to the form and need to get back a internal table values. It's going to dump when i execute the script, saying too many parameters specified with perform. Please find my coding below

Script:

/: BREAK-POINT.

/* Define Variables

/: DEFINE &INVAR1& = '0000271151'.

/: DEFINE &OUTVAR1& = ' '

/: DEFINE &MATTOT& = ' '

/: DEFINE &VAMTTOT& = ' '

/: DEFINE &VTAXTOT& = ' '

/: DEFINE &TAXSA& = ' '

/: DEFINE &PLANT& = ' '

/: DEFINE &FMATTOT& = ' '

/: DEFINE &FVAMTTOT& = ' '

/: DEFINE &FVTAXTOT& = ' '

/: DEFINE &FTAXSA& = ' '

/: DEFINE &NUM& = '1'

/: DEFINE &GT_CONS_LST_F& = ''

/E CALL THE ROUTINE

/: PERFORM FETCH_CONSIGN_DATA IN PROGRAM ZMM_CONSIGN_SUBROUTINE_POOL

/: USING &INVAR1&

/: TABLES &GT_CONS_LST_F&

/: ENDPERFORM.

Program:

PROGRAM ZMM_CONSIGN_SUBROUTINE_POOL.

&----


*& Form fetch_consign_data

&----


  • text

----


  • --> in_tab text

  • <-- out_tab text

----


*FORM fetch_consign_data TABLES in_tab STRUCTURE itcsy

  • out_tab STRUCTURE itcsy.

FORM fetch_consign_data USING invar1 TYPE ELIFN

TABLES gt_cons_lst_f.

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

  • tables *

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

TABLES: RKWA,

T001W,

MAKT,

MARD,

BSEG.

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

  • T Y P E S *

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

types: begin of it_cons_list,

werks type RKWA-WERKS,

name1 type T001W-NAME1,

matnr type RKWA-MATNR,

maktx type MAKT-MAKTX,

bstmg type RKWA-BSTMG,

bwaer type RKWA-Bwaer,

wrbtr type RKWA-WRBTR,

curr type RKWA-BSTME,

klabs type MARD-KLABS,

taxsa type RKWA-WRBTR,

taxpv type RKWA-WRBTR,

totpv type RKWA-WRBTR,

end of it_cons_list.

types: begin of it_plant_desc,

werks type RKWA-WERKS,

name1 type T001W-NAME1,

end of it_plant_desc.

types: begin of it_mat_desc,

matnr type RKWA-MATNR,

maktx type MAKT-MAKTX,

klabs type MARD-KLABS,

end of it_mat_desc.

types: begin of it_gnrl_det,

werks type RKWA-WERKS,

matnr type RKWA-MATNR,

bstmg type RKWA-BSTMG,

wrbtr type RKWA-WRBTR,

end of it_gnrl_det.

types: begin of it_bseg_det,

matnr type BSEG-MATNR,

wrbtr type BSEG-WRBTR,

end of it_bseg_det.

DATA: gt_cons_list TYPE STANDARD TABLE OF it_cons_list,

gt_plant_desc TYPE STANDARD TABLE OF it_plant_desc,

gt_mat_desc TYPE STANDARD TABLE OF it_mat_desc,

gt_gnrl_det TYPE STANDARD TABLE OF it_gnrl_det,

gt_cons_list_f TYPE STANDARD TABLE OF it_cons_list with header line,

gt_bseg_det TYPE STANDARD TABLE OF it_bseg_det,

  • gt_cons_lst_f TYPE STANDARD TABLE OF it_cons_list with header line,

w_cons_temp TYPE it_cons_list,

w_bseg_temp TYPE it_bseg_det,

w_plant_desc TYPE it_plant_desc,

w_mat_desc TYPE it_mat_desc,

i_text TYPE STANDARD TABLE OF tline INITIAL SIZE 0,

w_header LIKE thead,

w_text TYPE tline,

l_isqnt like RKWA-BSTMG,

l_matamt like RKWA-WRBTR.

CONSTANTS: c_par TYPE char2 VALUE ',,'. " Sign for tabs

  • Select Plant & material details for the vendor

SELECT werks matnr bstmg wrbtr bwaer

FROM rkwa

INTO CORRESPONDING FIELDS OF TABLE gt_cons_list

  • WHERE lifnr EQ '0000271151'.

WHERE mjahr EQ '2008'.

  • Select Plant & Material description

SELECT werks name1

FROM t001w

INTO CORRESPONDING FIELDS OF TABLE gt_plant_desc

FOR ALL ENTRIES IN gt_cons_list

WHERE werks EQ gt_cons_list-werks.

SELECT amatnr amaktx b~klabs

INTO CORRESPONDING FIELDS OF TABLE gt_mat_desc

FROM ( MAKT as a join MARD as b

ON amatnr EQ bmatnr )

FOR ALL ENTRIES IN gt_cons_list

WHERE a~matnr EQ gt_cons_list-matnr.

  • Get UOM & on-hand values

LOOP AT gt_cons_list INTO w_cons_temp.

LOOP AT gt_plant_desc INTO w_plant_desc.

IF w_plant_desc-werks EQ w_cons_temp-werks.

MOVE w_plant_desc-name1 TO w_cons_temp-name1.

MODIFY gt_cons_list FROM w_cons_temp.

ENDIF.

ENDLOOP.

ENDLOOP.

CLEAR w_cons_temp.

LOOP AT gt_cons_list INTO w_cons_temp.

LOOP AT gt_mat_desc INTO w_mat_desc.

IF w_mat_desc-matnr EQ w_cons_temp-matnr.

MOVE:

w_mat_desc-maktx TO w_cons_temp-maktx,

w_mat_desc-klabs TO w_cons_temp-klabs.

MODIFY gt_cons_list FROM w_cons_temp.

ENDIF.

ENDLOOP.

ENDLOOP.

  • Calcualte tax paid to vendor & total paid to vendor

SELECT MATNR WRBTR

INTO CORRESPONDING FIELDS OF TABLE gt_bseg_det

FROM BSEG

FOR ALL ENTRIES IN gt_cons_list

WHERE MATNR EQ gt_cons_list-MATNR

AND WERKS EQ gt_cons_list-WERKS.

  • "AND LIFNR EQ gt_cons_list-

LOOP AT gt_cons_list INTO w_cons_temp.

LOOP AT gt_bseg_det INTO w_bseg_temp.

w_cons_temp-taxpv = w_bseg_temp-wrbtr - w_cons_temp-wrbtr.

w_cons_temp-totpv = w_cons_temp-wrbtr + w_cons_temp-taxpv.

MODIFY gt_cons_list FROM w_cons_temp.

ENDLOOP.

ENDLOOP.

  • Calculate total issued quantity & material amt as per vendor/plant/material no

LOOP AT gt_cons_list INTO w_cons_temp.

COLLECT w_cons_temp INTO gt_cons_list_f.

CLEAR w_cons_temp.

ENDLOOP.

gt_cons_lst_f = gt_cons_list_f.

10 REPLIES 10

Former Member
0 Kudos

Hi,

In the program the FORM should have the following parameters.

FORM <form> TABLES IN_TAB STRUCTURE ITCSY

OUT_TAB STRUCTURE ITCSY.

ENDFORM.

Check the link for more details.

http://help.sap.com/saphelp_40b/helpdata/en/d1/803279454211d189710000e8322d00/content.htm

Thanks

Naren

0 Kudos

Thanks naren. Actually this will work for single values, but whether it will work if i want to get it as an internal table. I need to do some subtotals inside the form while displaying the values in the main screen.

Format will be something like this..

Material Desc issues quant UOM MaterialAmt Curr

PlantOM11 OwensCorning

R99 MaterialR99 39 EA 214 USD

CH MaterialCH 8 EA 34 USD

Plant Tot 248 USD

0 Kudos

Hi,

It will work for all ...Single Values & Internal Tables....

0 Kudos

Thanks Ajay.

whether we can pass the export value of type other than ITCSY ?

Actually i created one structure for my internal table and try to export it of that type,

but it went to dump.

0 Kudos

Hi,

Actually i have to get multiple line items and print it in the main window, so from my print program i am calling a subroutine, there i am looping the internal table and calling the function module 'Write_form' inside it, but still i am not getting the values in the main window.

Please find my code below:

Script:

/: DEFINE &INVAR1& = '0000271151'.

/: PERFORM FETCH_CONSIGN_DATA IN PROGRAM ZMM_CONSIGN_SUBROUTINE_POOL

/: USING &INVAR1&

/: CHANGING &PLANTNO&

/: ENDPERFORM.

IA Plant &w_cons_temp-werks& ,, &w_cons_temp-name1&

&w_cons_temp-matnr&,,&w_cons_temp-maktx&,,&w_cons_temp-bstmg&,,

Subroutine:

After getting the internal table values, i try to pass it to script by looping it

CALL FUNCTION 'OPEN_FORM'

EXPORTING

  • APPLICATION = 'TX'

  • ARCHIVE_INDEX =

  • ARCHIVE_PARAMS =

DEVICE = 'PRINTER'

DIALOG = ''

FORM = 'YMM_CONSIGN'

LANGUAGE = SY-LANGU

  • OPTIONS =

  • MAIL_SENDER =

  • MAIL_RECIPIENT =

  • MAIL_APPL_OBJECT =

  • RAW_DATA_INTERFACE = '*'

  • SPONUMIV =

  • IMPORTING

  • LANGUAGE =

  • NEW_ARCHIVE_PARAMS =

  • RESULT =

EXCEPTIONS

CANCELED = 1

DEVICE = 2

FORM = 3

OPTIONS = 4

UNCLOSED = 5

MAIL_OPTIONS = 6

ARCHIVE_ERROR = 7

INVALID_FAX_NUMBER = 8

MORE_PARAMS_NEEDED_IN_BATCH = 9

SPOOL_ERROR = 10

CODEPAGE = 11

OTHERS = 12

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

*CALL FUNCTION 'START_FORM'

  • EXPORTING

    • ARCHIVE_INDEX =

  • FORM = 'YMM_CONSIGN'

  • LANGUAGE = SY-LANGU

    • STARTPAGE = ' '

    • PROGRAM = ' '

    • MAIL_APPL_OBJECT =

    • IMPORTING

    • LANGUAGE =

  • EXCEPTIONS

  • FORM = 1

  • FORMAT = 2

  • UNENDED = 3

  • UNOPENED = 4

  • UNUSED = 5

  • SPOOL_ERROR = 6

  • CODEPAGE = 7

  • OTHERS = 8

  • .

*IF SY-SUBRC <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

*ENDIF.

LOOP AT gt_cons_lst_f INTO w_cons_temp.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

  • FUNCTION = 'SET'

  • TYPE = 'BODY'

WINDOW = 'MAIN'

ELEMENT = 'TABLE'

  • IMPORTING

  • PENDING_LINES =

EXCEPTIONS

ELEMENT = 1

FUNCTION = 2

TYPE = 3

UNOPENED = 4

UNSTARTED = 5

WINDOW = 6

BAD_PAGEFORMAT_FOR_PRINT = 7

SPOOL_ERROR = 8

CODEPAGE = 9

OTHERS = 10

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDLOOP.

CALL FUNCTION 'CLOSE_FORM'

  • IMPORTING

  • RESULT =

  • RDI_RESULT =

  • TABLES

  • OTFDATA =

  • EXCEPTIONS

  • UNOPENED = 1

  • BAD_PAGEFORMAT_FOR_PRINT = 2

  • SEND_ERROR = 3

  • SPOOL_ERROR = 4

  • CODEPAGE = 5

  • OTHERS = 6

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

0 Kudos

Hi Arun,

Why dont you declare a global variable in the driver program . and while calling the element in the main window use that variable which holds the value and pass it on to the SAP Script when all line items are printed.

0 Kudos

thanks Chidanand.

My driver program is a standard one. I copied the exisitng script and doing the changes.

Moreover some consignment needs to be created for testing, so

i hardcoded the value in the scriipt & pass the value to the subroutine program and trying to get some line items which needs to be printed in main window.

One more doubt, i am calling a subroutine from a script, again in the subroutine i am calling the same script using 'Wrtite_back' function module' for printing the line items. Is there anything wrong in doing this way?

0 Kudos

One more query...

Actually i am using a script that is not assigned to any driver program.

I am calling a subroutine program from the script.

In the subroutine i am calling the function module 'Write_form' within a loop to print line item

items in the script, but i am not able to get the values in the script.

One of my colleague told me that we can get the line item values in the script only if the driver program is active. Is it true??

Former Member
0 Kudos

Hi,

In the program

FORM <form> TABLES IN_TAB STRUCTURE ITCSY
<IN_TAB> STRUCTURE ITCSY
<OUT_TAB> STRUCTURE ITCSY

DATA: <PARA1> TYPE <TYPE>,   "Import values
           <PARA2> TYPE <TYPE>,   "Export values

<PARA1> = <IN_TAB>
"here write the required code to modify the values and to send to subroutine and put taht values in <PARA2>.

finally to send data to subroutine, write
<OUT_TAB> = <PARA2>
.

<form> is subroutine called from the script editor.

<in_tab> is used to call parameters from subroutine

<out_tab> is used to export parameters to subroutine

Regards,

Dhanunjaya Reddy

Former Member
0 Kudos

When calling abap program in sapscript, all value in using term will be stored in one intenal table and also changing parameter. And you can't passed internal table in sapscript. see below.

*In form

PERFORM FORM IN

/: PERFORM ALAMATAG IN PROGRAM ZXXXXX

/: USING &IVBDKR-VBELN&

/: Changing &YYY&

/: &TLP&

*in ABAP

FORM ALAMATAG TABLES CO_USE STRUCTURE CO_SET_TYPE

CO_SET STRUCTURE CO_SET_TYPE.

*Get using parameter

READ TABLE CO_USE WITH KEY NAME = 'VBDKR-VBELN'.

IF SY-SUBRC EQ 0.

MOVE CO_USE-VALUE TO NIV.

ENDIF.

*Store Changing parameter

LOOP AT CO_SET.

IF CO_SET-NAME EQ 'YYY'.

MOVE YYY TO CO_SET-VALUE.

MODIFY CO_SET.

ENDIF.

IF CO_SET-NAME EQ 'TLP'.

MOVE TLP TO CO_SET-VALUE.

MODIFY CO_SET.

ENDIF.

ENDLOOP.

ENDFORM.