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: 

RFC_ABAP_INSTALL_AND_RUN

Former Member
0 Kudos

Hi Experts,

I have a program "XXX". i want to display the output of Program "XXX" in Tables parameter "WRITES" of FM RFC_ABAP_INSTALL_AND RUN.

Can anyone explain me detaily with some example.

Thanks,

Silviya T

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

what this function module does is takes the source code and installs it on a remote system and brings back the output via an internal table. One thing is that the remote systemm must be "open" in order for this to work



report  zrich_0001.

data: source type table of progtab with header line,
      output type table of listzeile with header line.

* Add the source code for the report program ZRICH_0002
source = 'report zrich_0002.'.
append source.
source = 'write:/ ''This is the output''.'.
append source.


* now install it on remote system and run it.
call function 'RFC_ABAP_INSTALL_AND_RUN'
    DESTINATION 'NSP'
  tables
    program            = source
    writes             = output
          .

* write out the output from the program
loop at output.
  write:/ output.
endloop.


Regards,

Rich Heilman

10 REPLIES 10

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

what this function module does is takes the source code and installs it on a remote system and brings back the output via an internal table. One thing is that the remote systemm must be "open" in order for this to work



report  zrich_0001.

data: source type table of progtab with header line,
      output type table of listzeile with header line.

* Add the source code for the report program ZRICH_0002
source = 'report zrich_0002.'.
append source.
source = 'write:/ ''This is the output''.'.
append source.


* now install it on remote system and run it.
call function 'RFC_ABAP_INSTALL_AND_RUN'
    DESTINATION 'NSP'
  tables
    program            = source
    writes             = output
          .

* write out the output from the program
loop at output.
  write:/ output.
endloop.


Regards,

Rich Heilman

0 Kudos

Hi Rich,

1.In Destination name what should i have to give?

program "XXX" has selection-screen. It retrives the data based on slection-screen value. without inputting the data in selection-screen i am not getting output from my program.

2.can we get the output If i pass this program to tables parameter of RFC_ABAP_INSTALL_AND_RUN ?

3.can you explain me how this following program works? for what purpose we can use this program?

data: begin of t_input occurs 0, " input file (source code)

data(72),

end of t_input,

t_output like LISTZEILE occurs 0 with header line. "output file.

data: message like SY-MSGV1.

PARAMETERS: P_FILE1 LIKE RLGRAP-FILENAME

OBLIGATORY DEFAULT 'C:\input.txt', " Input file

P_FILE2 LIKE RLGRAP-FILENAME

OBLIGATORY DEFAULT 'C:\output.txt'. " Output file

  • Upload source code

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

  • CODEPAGE = ' '

FILENAME = p_file1

FILETYPE = 'ASC'

  • HEADLEN = ' '

  • LINE_EXIT = ' '

  • TRUNCLEN = ' '

  • USER_FORM = ' '

  • USER_PROG = ' '

TABLES

DATA_TAB = t_input

EXCEPTIONS

CONVERSION_ERROR = 1

FILE_OPEN_ERROR = 2

FILE_READ_ERROR = 3

INVALID_TABLE_WIDTH = 4

INVALID_TYPE = 5

NO_BATCH = 6

UNKNOWN_ERROR = 7

OTHERS = 8.

IF SY-SUBRC NE 0.

WRITE: / 'Input file could not be opened', 'Exception', SY-SUBRC.

EXIT.

ENDIF.

  • execute the source code

CALL FUNCTION 'RFC_ABAP_INSTALL_AND_RUN'

EXPORTING

MODE = 'F'

PROGRAMNAME = '<<RFC1>>'

IMPORTING

ERRORMESSAGE = message

TABLES

PROGRAM = t_input

WRITES = t_output

.

  • error message entered into output file.

if message ne ' '.

t_output-zeile = message.

append t_output.

endif.

  • download output

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

FILENAME = p_file2

FILETYPE = 'ASC'

MODE = ' '

TABLES

DATA_TAB = t_output

EXCEPTIONS

FILE_OPEN_ERROR = 01

FILE_WRITE_ERROR = 02

INVALID_FILESIZE = 03

INVALID_TABLE_WIDTH = 04

INVALID_TYPE = 05

NO_BATCH = 06

UNKNOWN_ERROR = 07.

IF SY-SUBRC NE 0.

MESSAGE w472(GL).

ENDIF.

0 Kudos

I've added a parameter to my sample program above. It will work, but you will need to default the parameter value as I've done here.



report  zrich_0001.



data: source type table of progtab with header line,
      output type table of listzeile with header line.

* Add the source code for the report program ZRICH_0002
source = 'report zrich_0002.'.
append source.
<b>source = 'parameters: p_check type c default ''X''.'.</b>
append source.
source = 'write:/ ''This is the output''.'.
append source.
<b>source = 'write:/ p_check.'.</b>
append source.



* now install it on remote system and run it.
call function 'RFC_ABAP_INSTALL_AND_RUN'
  destination 'NSP'
  tables
    program = source
    writes  = output.

* write out the output from the program
loop at output.
  write:/ output.
endloop.

The program that you have there appears to upload a text file containing source code for a progam, it then installs it and runs it and downloads the output of the program. What this does, is saves you from enter the source code directly as I've done in my sample program. Notice that I am writing the code and adding it to the source table inside the program.

Please remember to award points for any helpful answers . Thanks.

Regards,

Rich Heilman

0 Kudos

Also, the value of Destination should be the name of the RFC destination. You setup this connection via SM59. If you are not trying to jump to another system to run your program, then you don't need this piece of code. Just comment out that line.

REgards,

Rich Heilman

0 Kudos

Hi Rich,

What is destination name 'NSP'?

what destination name i have to give or can i give same NSP?

Thanks,

Silviya T

0 Kudos

Hi Rich,

I am trying to jump to another system to run the program. how can i setup this connection via SM59?

Can you explain me detaily with sequence steps?

Thanks,

Silviya T

0 Kudos

The destination NSP is actually my sneak preview Netweaver 2004s installation.

You need to setup a RFC connection to your remote machine. Go to transaction SM59.

Depending on your release, this may look a little different than what I describe.

Click the "ABAP Connections" node of the tree.

Click the create icon.

Give a name.

Give a description.

Under techinal settings tab, In the target host, enter IP address and system number.

Under logon/security tab, enter the logon credentials.

You can use "Current User" if applicable.

Click save.

Click connection test. If you are getting reflection, then you are done. RFC connection is good.

Then you can use the destination extension when calling the function module.

Remember in order for this to work, the remote system MUST be "open". Meaning that you must be allow to create programs in that system.

Regards,

Rich Heilman

0 Kudos

Hi Rich,

I have problem in using this FM.

I tried the example you mentioned over here and it works fine.

Now I have situation .

I have one table of entries in program 1 which I have to send to program 2 in selecting records in the DB table.

I tried using the literals of the program 1 in program 2 which is not working...

You can have a look in below:

This is the program 2.

ls_source = 'report zget_aufk.'.

append ls_source to lt_source.

ls_source = 'data: it_aufk like aufk occurs 0 with header line.'.

append ls_source to lt_source.

ls_source = 'ranges : r_aufnr for aufk-aufnr.' .

append ls_source to lt_source.

ls_source = 'select * from aufk into table it_aufk where (lt_sel_tab).'.

append ls_source to lt_source.

ls_source = 'loop at it_aufk.'.

append ls_source to lt_source.

ls_source = 'write:/ it_aufk-aufnr it_aufk-AUART it_aufk-AUTYP it_aufk-REFNR it_aufk-ERDAT it_aufk-BUKRS it_aufk-WERKS.'.

append ls_source to lt_source.

ls_source = 'endloop.'.

append ls_source to lt_source.

and lt_sel_tab is being build in program 1 as below :

loop at lt_order1 into ls_order1.

if sy-tabix <= 1000.

if sy-tabix = 1.

concatenate text-001 ls_order1-ordno '''' into

ls_sel_tab-ZEILE .

append ls_sel_tab to lt_sel_tab.

else.

concatenate text-002 ls_order1-ordno '''' into

ls_sel_tab-ZEILE.

append ls_sel_tab to lt_sel_tab.

endif.

else.

exit.

endif.

endloop.

Let me know if you have any suggestions for this.How do you retrieve DB records on particular selection ( which you can not hard code ) , it has to be dynamic selection.

Thanks,

Savitha

Former Member
0 Kudos

This fm runs an ABAP program that is stored in the table PROGRAM when the MODE = 'F'. Table WRITES contains the ouput of the program. Allows you to run a program without having the source code in the target system.

Also check if this link helps

http://www.kabai.com/abaps/z68.htm

Message was edited by: Ashish Gundawar

former_member583013
Active Contributor
0 Kudos

It may sound silly...But the only thing you need to do...I left blank the <b>MODE</b> parameter. It worked for me -;)

Greetings,

Blag.