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

Sub routine in SAP Script.

aaruljothi
Participant
0 Likes
1,105

Hi Experts,

I have a standard SAP program that calls a standard SAP script.

I need to introduce a sub-routine from the SAP script which will reside inside a custom program sending a workarea into it and getting back another workarea with a different structure from the first and then use the resultant workarea in the SAP script to display the results.

This is done since it doesn't need a change in the SAP standard program. Anyway my SAP script will undergo a change which i can afford.

For example consider the following :

<b>This is my code bit in the program calling an element in the SAP script.</b>

CALL FUNCTION 'WRITE_FORM'

EXPORTING

element = <selement>

window = <swindow>

function = <sfunction>

EXCEPTIONS

element = 01

function = 02

type = 03

unopened = 04

unstarted = 05

window = 06.

<b>The Element in the SAP script is as follows:</b>

/E <selement>

T4 &struc1-field1& &struc1-field2& &struc1-field3&

Instead of the above I need to send the struc1 to a sub-routine and then get back another structure

<b>Something like this.</b>

/E <selement>

: perform <subroutine_name> using struc1 struc2

T4 &struc2-field1& &struc2-field2& &struc2-field3&

&struc2-field4&

<i>note : struc1 and struc2 are of different structures

The sub routine will reside in the custom program</i>

Now my question is, where to define my structure stru2(whether in the custom program or in the Standard program).

Is there any other way to implement the same without disturbing the SAP standard program?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,062

Hi Arul,

1. The points system seems to be working/active now.

2. U may pls award appropriate points.

Thanks in advance.

regards,

amit m.

11 REPLIES 11
Read only

Former Member
0 Likes
1,062

YOu can use the define statement to declare your variables in the text elements editor itself.

eg:

/: DEFINE &BARCODE& := '&SPACE(12)&'

/* DEFINE &BARCV& := '&KARTE-BARCV&' (REMOVED FOR INUSE BARCODE)

/: DEFINE &BARC6& := '&KARTE-BARC6&'

/: PERFORM GET_BARCODE IN PROGRAM ZVXR0076

/* USING &BARCV&

/: USING &BARC6&

/: CHANGING &BARCODE&

/: ENDPERFORM

Regards,

Ravi

Read only

0 Likes
1,062

Thanks Ravi,

But these are single values can I pass a structure and get back structure where both the structures are of different types?

Read only

0 Likes
1,062

HI Jothi,

May be what you can try is to define a variable of sufficient length and then take offset from that structure to get differen fields in that long field.

eg DEFINE &structure& := '&SPACE(50)&'

or use as many variable as the nimber of fields in that structure.

Regards,

Ravi

Read only

Former Member
0 Likes
1,062

Hi arul,

1. while calling subroutines from sapscripts,

there is a special technique,

which has got its own limitations.

2.

FORM abc

TABLES

in_tab STRUCTURE itcsy

out_tab STRUCTURE itcsy.

ENDFORM.

3. The perform in se38 program should be of the

above format only.

4. We cannot pass internal tables.

5. Rather we need to pass

VARIABLE NAME

VARIABLE VALUE

(see the structure of itcsy in se11)

6. In this form, we have to read

the internal table in_tab

to capture the variable name and its value.

7. Similary, to return the values,

we have to put one record (for each variable)

in out_tab.

regards,

amit m.

Read only

0 Likes
1,062

Hi Amit,

Your answers seems to be feasible. I have a couple of clarrifications to be made.

1. How should my perform statement look like in the SAP script.

2. How should I use the fields in the resultant structure in the SAP script.

Read only

0 Likes
1,062

Hi again,

1. How should my perform statement look like in the SAP script.

PERFORM ROUTINNAME IN PROGRAM ZPROG

USING &ITAB-F1&

USING &ITAB-F2&

USING &ITAB-F3&

CHANGING

USING &F4&

USING &F5&

ENDPERFORM.

2. How should I use the fields in the resultant structure in the SAP script.

Just use the variable name

&F4&

(u can give any name and use it back)

regards,

amit m.

Read only

0 Likes
1,062

Hi Amit,

My second doubt is clarrified now.

But I cannot understand your answer to teh first.

1. should F4 and F5 be declared somewhere?

and

2. why there are "USING" pharses(2) after the "CHANGING"

Regards,

Arul Jothi.

Read only

0 Likes
1,062

Hi again,

1. should F4 and F5 be declared somewhere?

Not necessary.

In fact, not required.

Just give ANY Variable name.

2. why there are "USING" pharses(2) after the "CHANGING"

Well, thats not required.

In fact, do not use it. Its wrong !

regards,

amit m.

Read only

0 Likes
1,062

Hi Amit,

Thanks a lot for your patient reply.

I am tring to reward you points but I cannot see the radio buttons along side of your reply.

what should I do now.

Arul Jothi.

Read only

0 Likes
1,062

Hi again,

1. Probably the points system may not

be working, temporarily.

2. If it get working again,

at that point u may reward the points.

Thanks in advance.

regards,

amit m.

Read only

Former Member
0 Likes
1,063

Hi Arul,

1. The points system seems to be working/active now.

2. U may pls award appropriate points.

Thanks in advance.

regards,

amit m.