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

Sapscript External Subroutine

Former Member
0 Likes
1,414

Hi all,

While caling the external subroutine from sapscript

1) what should be the data type of using and changing parameters.

2) Can't I write the perform statement as

/: perform <form> in program <prog>

/: changing &outparam&

/: endperform.

3)MODIFY OUT_PAR INDEX SY-TABIX.

what does the above statement mean. It is taken from sap documentation.

The form definition is :

FORM <form> TABLES OUT_TAB STRUCTURE ITCSY.

I defined a variable num of type i in print program.

I used in changing parameter in external subroutine.

But when I debug the script and program the value of num is not updated.

Regards,

Varun

13 REPLIES 13
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,363

I assume that this is related to . Did these answers not help?

Regards,

Rich Heilman

Read only

0 Likes
1,363

<i>1) what should be the data type of using and changing parameters.</i>

There is no data type in the USING and CHANGING inside the sapscript. They must be defined as you have done in the print program, STRUCTURE ITCSY.

<i>2) Can't I write the perform statement as

/: perform <form> in program <prog>

/: changing &outparam&

/: endperform.</i>

Yes, this is how to right it.

<i>3)MODIFY OUT_PAR INDEX SY-TABIX.</i>

This means that it is modify the row of OUT_PAR. The row is = whatever sy-tabix is at the time.

Read only

0 Likes
1,363

Hi Rich,

I tried all the ways mentioned in that thread but still I am not able to resolve the issue.They all suggested me different ways but the method involving external subroutine did not work. I am just trying to achieve it using external subroutine.

Regards,

Varun.

Read only

0 Likes
1,363

Hi Varun,

your issue is not yet resolved.

In your external routine program Please define your "CH" as mentioned below.

<u>data : ch(1) type c.</u>

Your code :

REPORT Z_V_SCRIPT_SR.

FORM z_v_script TABLES IN_PAR STrUCTURE ITCSY

OUT_PAR STRUCTURE ITCSY.

data : cntr type i value -1.

<u>data : ch(3) type c.</u>

read table in_par with key 'COUNTER'.

if sy-subrc = 0.

cntr = in_par-value.

endif.

cntr = cntr + 1.

ch = cntr.

read table out_par with key 'COUNTER'.

if sy-subrc = 0.

out_par-value = ch.

endif.

Script Code :

/: BOX FRAME 10 TW

/E MAIN

p3 &spaces(3)&&itab-carrid& &spaces(35)& &itab-connid&

= &spaces(25)&&itab-fldate&

/: PERFORM Z_V_SCRIPT IN PROGRAM Z_V_SCRIPT_SR

/: USING &COUNTER&

/: CHANGING &COUNTER&

/: ENDPERFORM

/: IF &COUNTER& EQ '1'

<u>/: &ULINE(45)&</u>/

: DEFINE &COUNTER& = 0

/: endif

Change <u>/: &ULINE(45)&</u>/ to PD &ULINE(45)&.

PD : paragraph format or default use '*'.

I have tested with your earlier code and it is working.

Lanka

Message was edited by: Lanka Murthy

Read only

0 Likes
1,363

Lanka, is really pushing for you to do as suggested. I'm not really sure about it because what if your counter goes more than 9, CH will not be big enough to hold 10. This really isn't as difficult as we are making it seem. I usually try to stay away from having PERFORMs in my sapscript. I like to handle everything in one place, meaning the print program. I would suggest trying to implement your counter in the print program and remove the PERFORM from the sapscript. If not, we can struggle thru this.

Regards,

Rich Heilman

Read only

0 Likes
1,363

Have you defined....

data : cntr type i value -1.

outside of the form, somewhere in the top of the program. If not, this field will never be more than 0. The reason for this is because having defined it in the PERFORM, it is local, therefore everytime you call the FORM, it will be starting from -1. In the FORM, when you add 1 to it, it will be 0, never more.

Regards,

Rich Heilman

Read only

0 Likes
1,363

Hi ,

Rich Apologies for that. I just want to convey that Varun's code is OK to use.

It is a common practice that to use external routine (By using and Changing) in SAP script.

Yes You are correct if the Counter is more than 10 it wont work. But in his code he is checking IF Counter EQ 1.

I thought he will always check COUNTER EQ 1.

Lanka

Read only

0 Likes
1,363

Lanka, I agree totally. I was just concern about the 1 character field.

Varun, when debugging is the value being set to "1"? If it will always be "1", then try as Lanka has suggested and make it as 1 character field. There may be a problem when the sapscript is looking for "1" and the value is coming as "SPACE SPACE 1" or something like that. Not really sure since I have not debugged it myself.

Regards,

Rich Heilman

Message was edited by: Rich Heilman

Read only

0 Likes
1,363

Hi Rich ,

Please see Varun's code he is moving Numeric to CH(3) . I think this may be storing in CH.

Example : If Counter is 1 and moved to CH.

It stored in CH as " space space 1".

When in Script if you are using

IF &COUNTER& (Here Counter is of type "CH" ) EQ '1' --This statement is failing.

As Rich correctly mentioned

-- No need to define data type "CH".

Just change the counter and pass it to OUT_TAB. This will work.

data : cntr type i value -1.

read table in_par with key 'COUNTER'.

if sy-subrc = 0.

cntr = in_par-value.

endif.

cntr = cntr + 1.

read table out_par with key 'COUNTER'.

out_par-value = cntr.

Modiffy OUT_PAR index sy-tabix.

Correct me if I am wrong.

Lanka

Read only

0 Likes
1,363

Can I join in too?

How about this...

In your SAPscript layout set

ABOVE all of the TEXT ELEMENTs in the MAIN window

/: DEFINE &COUNTER& = 0

In the section of SAPscript where you need to increment

/: PERFORM Z_V_SCRIPT IN PROGRAM Z_V_SCRIPT_SR

/: USING &COUNTER&

/: CHANGING &COUNTER&

/: ENDPERFORM

/: IF &COUNTER& = '001'

/ &ULINE(45)&

/: DEFINE &COUNTER& = 0

/: ENDIF

In the ABAP...

FORM Z_V_SCRIPT tables table_in structure itcsy

table_out structure itcsy.

Data: lv_counter(3) type n.

READ TABLE TABLE_IN WITH KEY NAME = 'COUNTER'.

CHECK SY-SUBRC = 0.

LV_COUNTER = TABLE_IN-VALUE.

LV_COUNTER = LV_COUNTER + '1'.

READ TABLE TABLE_OUT WITH KEY NAME = 'COUNTER'.

CHECK SY-SUBRC = 0.

TABLE_OUT-VALUE = LV_COUNTER.

SHIFT TABLE_OUT-VALUE LEFT DELETING LEADING SPACE.

MODIFY TABLE_OUT INDEX SY-TABIX.

ENDFORM.

... though I have no idea why you want to increment a counter by 1 and then set it to 0 again.

Read only

0 Likes
1,363

Thanks for joining Norman, I did assume that the DEFINE statement was somewhere in the script. Again, I'm not really familiar about PERFORMs in sapscripts, but I was thinking that the DEFINE statement should be present? is this correct assumption?

Lanka, I was thinking the same in my eariler post, you can't see that I was mentioning the SPACE SPACE 1 very good because it goes from 1 line to the next.

Regards,

Rich Heilman

Read only

0 Likes
1,363

Thanks for Norman for Joining.

Rich and my self suggesting as Change the counter from IN_TAB and use the same in OUT_TAB.

Lanka

Read only

0 Likes
1,363

You don't really have to specify the DEFINE first. If it's not there, it will pass a space in the first PERFORM call. I usually define variables for PERFORMs in MAIN above the text elements to initialize them. If you don't and are printing multiple copies of the form, the variable could get held from one copy to another.

When I've had problems like this, it was usually related to leading spaces when the value gets passed back to the layout set.