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

Call FORM from SAP Script not working ?!

Former Member
0 Likes
3,817

Hi guys

I have to work on an SAP Script and I need to fill a variable with data from database table. I searched on the internet and found out that I can create a program, in it I can create an FORM and from SAP Script I can PERFORM the form. And I did this but it shows me an Error:

Short text

     Too many parameters specified with Perform

Error Analysis

     "... This routine contains 2 formal parameters, but the current call contains 4 actual parameters."


The report that I've created is this:

REPORT z_sapscript_forms.

FORM get_text_0014 USING l_lgart TYPE pa-lgart

                                CHANGING l_text TYPE t511t-lgtext.

SELECT SINGLE lgtxt FROM t511t INTO l_text WHERE lgart = l_lgart.

ENDFORM.

And here is how I call the from from the SAP Script:

PERFORM GET_TEXT_0014 IN PROGRAM Z_SAPSCRIPT_FORMS

USING &LGART0014&

CHANGING &LGTXT0014&

ENDPERFORM

What is the problem here ? I don't give in SAP script 4 parameters?? I give 2 parameters but it doesn't work ??


Can someone help me with this ?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,908

Hi,

Use the following code:

FORM get_text_0014 TABLES  in_tab STRUCTURE itcsy

                                  out_tab STRUCTURE itcsy.

  READ TABLE in_tab WITH KEY name = 'LGART0014'.

  if sy-subrc eq 0.

    MOVE in_tab-value  TO v_lgart.

    SELECT SINGLE lgtxt FROM t511t INTO l_text WHERE lgart = v_lgart.

    if sy-subrc eq 0.

      MOVE'LGTXT0014' TO out_tab-name,

              l_text TO out_tab-value.

      APPEND out_tab.

    endif.

  endif.

ENDFORM.                    "get_text_0014

Regards

Sajid

16 REPLIES 16
Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
2,908

Hi Taly

The definition of subroutine pool is wrong. Please find below screen shot highlighting how to do

Nabheet

Read only

Former Member
0 Likes
2,909

Hi,

Use the following code:

FORM get_text_0014 TABLES  in_tab STRUCTURE itcsy

                                  out_tab STRUCTURE itcsy.

  READ TABLE in_tab WITH KEY name = 'LGART0014'.

  if sy-subrc eq 0.

    MOVE in_tab-value  TO v_lgart.

    SELECT SINGLE lgtxt FROM t511t INTO l_text WHERE lgart = v_lgart.

    if sy-subrc eq 0.

      MOVE'LGTXT0014' TO out_tab-name,

              l_text TO out_tab-value.

      APPEND out_tab.

    endif.

  endif.

ENDFORM.                    "get_text_0014

Regards

Sajid

Read only

0 Likes
2,908

Hi Sajid.

I wanted to ask you, now that we have these two Tables as parameters... how should I call it from SAP Script? What parameters should I give?

Read only

0 Likes
2,908

Hi Taly

If you look at the screen shot.. It clearly mentions how to call it from SAP script. You define the variable first and then do a perform as shown

Nabheet

Read only

0 Likes
2,908

I saw the picture that you uploaded... I added the parameters &PAGE& and &NEXTPAGE& and the dump isn't appearing anymore.

With the code that Sajid gave me, and the parameters that I have added (like in your images) the dump isn't showing anymore but the problem is that the LGTXT0014 still has no value assigned to it when I execute the SAP script in PRINT PREVIEW.

Do you have any idea why ?

Read only

0 Likes
2,908

Put a break point inside the subroutine. Are you updating back the OUTDATA with variable name and its values..? Please attaach your sample code of script and sub routine

Nabheet

Read only

0 Likes
2,908

Hi,

The way you are calling the form is correct.

As Nabheet suggested, Debug it and you can find the issue.

Regards
Sajid

Read only

0 Likes
2,908

I am putting a break point into the subroutine but when I click on Print Preview it doesn't go into it... don't know why .

Here is my code of the subroutine;

FORM get_text TABLES in_par STRUCTURE itcsy

                                     out_par STRUCTURE itcsy.

DATA: l_text TYPE t512t-lgtxt,

  l_lgart TYPE pa0014-LGART.

READ TABLE in_par WITH KEY name = 'LGART0014'.

  if sy-subrc eq 0.

       MOVE in_par-value TO l_lgart.

  SELECT SINGLE lgtxt FROM t512T INTO l_text WHERE lgart = l_lgart.

      

          if sy-subrc eq 0.

            MOVE: 'LGTXT0014' TO out_par-name,

                      l_text TO out_par-value.

                      APPEND out_par.

            endif.

  endif.

ENDFORM.

Read only

0 Likes
2,908

Tally

You have different development and testing client..? if yess did you do an SCC1 for sapscript. Seconldly just do a refresh OUT_PAR as it will have variable name before appending the values

Nabheet

Read only

0 Likes
2,908

Hi,

In SE71, Utilities -> Activate Debugger.

Regards

Sajid

Read only

0 Likes
2,908

Nabheet... sorry I wasn't here and couldn't reply to you.

I am developing and testing in the same Client. Now I tested the Form if it works, I gave manually the data to the in_par Table and it returned me the result that I want.

But the only problem is, why doesn't &LGTXT0014& in SAP script take the value given from the subroutine ?

Read only

0 Likes
2,908

In debugging does it fill OUT_PAR table..? Please attach the code of your subroutine call in SAP Script

Nabheet

Read only

0 Likes
2,908

I can't debug the subroutine I just can debug the SAP Script as Sajid said by Enabling the Debugger in SE71.

Here is the code how I call the subroutine in SAP script:

PERFORM GET_TEXT IN PROGRAM Z_SAPSCRIPT_FORMS

USING &PAGE&

USING &NEXTPAGE&

CHANGING &LGTXT0014&

ENDPERFORM

Read only

0 Likes
2,908

Hi,

Also Put a Break Point in the Program Z_SAPSCRIPT_FORMS.

Regards

Sajid

Read only

0 Likes
2,908

Nabheet... I can debug it now... i was logged in one place in English and in the other one in German .

The OUT_PAR Table returns only the Name of the Variable not it's Value.

I tried manually to add in the OUT_PAR table:  NAME: LGTXT0014, VALUE: 'some text'. After the execution it didn't show anything.

Read only

Former Member
0 Likes
2,908

Hi Taly,

In your calling Z program just change the definition of i_lgart and i_text type itcsy.

Here type you defined won't be dictionary structure when you are calling subroutine from SAPSCRIPT.

Thanks and Regards

Srimanta