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: 

Call sapscript form from an OO class method? Part II

0 Kudos

Lorenzo Nicora posted in the Forum: and solved his problem with smartforms. I’m with the same problem, but I can’t change to smartforms.

I tried to use static data in the sapscrit (&lcl_class=>my_data&) but with this I’m instantiate a new object and the variable are empty, and with the object like (&obj=>my_data&) the sapscript don’t recognize the variable.

So, I do the same question that Lorenzo did: “Do you know How can I pass the data to a form from a OO class method?”

7 REPLIES 7

franois_henrotte
Active Contributor
0 Kudos

Try to use

PERFORM provide_object IN PROGRAM <prog> CHANGING &LCL_CLASS&

and in your program

FORM provide_object CHANGING io_obj TYPE REF TO object.

io_obj ?= my_instance.

ENDFORM.

then you should be able to access to attributes of your instance...

0 Kudos

It was a good tip but it didn't solve my problem, I tried to use:

In the program:


DATA obj TYPE REF TO lcl_grupo_atividade.
CREATE OBJECT obj.
CALL METHOD obj->main.

FORM provide_object1 CHANGING ch_obj TYPE REF TO lcl_grupo_atividade.

ch_obj = obj. “I don’t need to use widening cast here, the scope is the same

ENDFORM.

In the SAPscript

/: PERFORM PROVIDE_OBJECT1 IN PROGRAM ZPWTSOAC100

/: CHANGING &CH_OBJ&.

/: PERFORM

  • ,,EMPRESA2,,: &CH_OBJ->V_EMRPE&

The error:


Símbolo CH_OBJ->V_EMRPE desconh.

I tried “CH_OBJ=>V_EMRPE” too, and this variable is in the public scope, but the error was the same

Do you have any other suggestion?

0 Kudos

Hi,

can you maybe post some more code of your class/program ??

0 Kudos

OK then it will be a bit more "hand-made"

you have to create a form routine that you will call from the SAPScript

this form routine has one incoming parameters: name of attribute and one changing parameter : value

according to attribute name, you return the value that you get from the class

sorry but I don't see any other way...

0 Kudos

<b>PROGRAM</b>

CLASS lcl_grupo_atividade DEFINITION.

...

ENDCLASS.

CLASS lcl_grupo_atividade IMPLEMENTATION.

...

ENDCLASS.

START-OF-SELECTION.

DATA obj TYPE REF TO lcl_grupo_atividade.

CREATE OBJECT obj.

CALL METHOD obj->main.

FORM provide_main TABLES itab STRUCTURE itcsy

...........................................otab STRUCTURE itcsy.

MOVE 'SS_TRANSACAO' TO otab-name.

MOVE obj->ss_transacao TO otab-value.

MODIFY otab INDEX 1.

MOVE 'SS_DESCRICAO' TO otab-name.

MOVE obj->ss_descricao TO otab-value.

MODIFY otab INDEX 2.

ENDFORM.

<b>SAPSCRIPT:</b>

/E MAIN

/* BOX FRAME 30 TW

/: PERFORM PROVIDE_MAIN IN PROGRAM ZPWTSOAC100

/: CHANGING &SS_TRANSACAO&

/: CHANGING &SS_DESCRICAO&

/: ENDPERFORM

P2 ,,&ss_transacao&,,&ss_descricao&

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

I code in this way, its works… but, I think that have a better way, because I had to use public variables and code a FORM outside of my class.

What do you think? Do you think exist another way to do that?

By the way, thanks for the help, I can’t find that without you.

0 Kudos

Hi Bruno,

im not a SAP Script specialist, but i uderstand it like this: the SAPScript processor needs for technical reasons a form to communicate with the program.

My opinion is: Because of this you need a form, but the form does not to have any functionality, it have to be only the "Interface" of your business logic for the SAPSCRIPT processor.

The form could be something like that:



FORM provide_main TABLES itab STRUCTURE itcsy 
.........................otab STRUCTURE itcsy.
CALL METHOD obj->provide_main
                   CHANGING
                    ch_itab = itab[]
                    ch_otab = otab[].
ENDFORM. 

So do you have no logic outside your OO modeled business logic. Just a form that encapsulate your public method provide_main.

Can i explane my view?

Regards,

Gianpietro

0 Kudos

Thanks Gianpietro, it’s a good idea.