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

Sap script - Incrementing Counter

Former Member
0 Likes
1,905

Hi all,

This is the code I have written in the main window of sap scrpt.

/: 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'

/: &ULINE(45)&

/: DEFINE &COUNTER& = 0

/: endif

This is the code for external subroutine z_v_script_sr.

REPORT Z_V_SCRIPT_SR.

FORM z_v_script TABLES IN_PAR STrUCTURE ITCSY

OUT_PAR STRUCTURE ITCSY.

data : cntr type i value -1.

data : ch(3) type c.

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.

MODIFY OUT_PAR INDEX SY-TABIX.

write : 'vijay'.

endform.

I do not understand where I am going wrong.If I debug the subroutine the value of counter is being changed to 1 but it is not reflected when I debug my script. Please explain me where I am going wrong.

Regards,

Varun

14 REPLIES 14
Read only

Former Member
0 Likes
1,514

Hi Varun,

Declare the cntr above the form after your report starement,not in the form.

REPORT Z_V_SCRIPT_SR.

<b>data : cntr type i value -1.</b>

FORM z_v_script TABLES IN_PAR STrUCTURE ITCSY

OUT_PAR STRUCTURE ITCSY.

Read only

0 Likes
1,514

Hi Phani,

I tried doing the sameway but still it doesn't work.

Regards,

Varun

Read only

0 Likes
1,514

Hi varun,

Can you declare the changing variable as some thing else,like declare it as v_counter,i mean it should be different from the passing variable.

Read only

0 Likes
1,514

Hi varun,

You can assign the value -1 in the form not in the declaration.

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,514

You counter must be held in global memory, otherwise it will always be the same. PUt the data statement at the top of your print program. Having it defined in the routine, means that everytime the routine is fired, it will be that value. In this case -1.

data : cntr type i value -1.

ALso, comment out the USING line in the SAPscript.

/: PERFORM Z_V_SCRIPT IN PROGRAM Z_V_SCRIPT_SR
<b>/* USING &COUNTER&</b>
/: CHANGING <b>&COUNTER&</b>
/: ENDPERFORM
/: IF &COUNTER& EQ '1'
/: &ULINE(45)&
/: DEFINE &COUNTER& = 0
/: endif

Also shouldn't the counter field be defined in the print program as well.

Is COUNTER defined in the print program?

Regards,

Rich Heilman

Read only

0 Likes
1,514

Hi ,

I made the declaration global by placing the data statement after the report statement. NOw when I try to execute the program it gives me a short dump saying

<b>"TABL_INVALID_INDEX".</b>

Regards,

Varun.

Read only

0 Likes
1,514

Hi Varun,

Your program will work just made one change as mentioned below :

Program :

data : ch(3) type c.

Changes the abovce to

data : ch(1) type c.

In SAP SCript Please change the following :

/: &ULINE(45)&

to (Please remove command paragraph)

  • &ULINE(45)&

don't make any other changes you program will work with that one change.

Lanka

Message was edited by: Lanka Murthy

Read only

0 Likes
1,514

That's because you did:


if sy-subrc = 0.
out_par-value = ch.
endif.

MODIFY OUT_PAR INDEX SY-TABIX.
write : 'vijay'.
endform

Try:

if sy-subrc = 0.
out_par-value = ch.
MODIFY OUT_PAR INDEX SY-TABIX.
endif.

write : 'vijay'.
endform

I don't like to sound like a broken record, but I think this would be alot easier handling the counter from the main program.

Rob

Read only

0 Likes
1,514

Hi Rich,

The counter is defined in the print program.

Regards,

Varun.

Read only

0 Likes
1,514

Hi Varun,

Your program will work just made one change as mentioned below :

Program :

data : ch(3) type c.

Changes the abovce to

data : ch(1) type c.

In SAP SCript Please change the following :

/: &ULINE(45)&

to (Please remove command paragraph)

  • &ULINE(45)&

don't make any other changes you program will work with that one change.

Lanka

Read only

0 Likes
1,514

Hi Rob,

Thanks Rob. As you said this is lot easier handling from the print program.Thank you very much for your suggestion.

Regards,

Varun.

Read only

0 Likes
1,514

Glad to help - if your question is answered, please close the thread.

Rob

Read only

Former Member
0 Likes
1,514

Hi,

You are using the COUNTER parameter for both USING and CHANGING of the perform statement. Since the parameters COUNTER used in USING , cannot be changed . It is should be used only in the subroutine but can not be changed. But Changing parameter can used and value also can be changed in inside subroutine. So , it is better to use two different variables in the perform statement .

Regards,

M.Saravanan

Read only

hymavathi_oruganti
Active Contributor
0 Likes
1,514

/:PERFORM Z_V_SCRIPT IN PROGRAM Z_V_SCRIPT_SR

/: USING &COUNTER&

in the place of USING, use CHANGING