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: 

how to pass external program to sap script

Former Member
0 Kudos
334

how to pass external program to sap script

4 REPLIES 4

Former Member
0 Kudos
86

Use like :

/: PERFORM (PERFORMNAME) IN PROGRAM (SE38 PROGRAM NAME)
/: USING VAR1
/: USING VAR2.
/: CHANGING OUTPUT
/: ENDPERFORM


CALL FORM ROUTINE IN SE38

FORM NAME tables in_tab structure itcsy
out_tab structure itcsy.


USE YOUR CODE HERE.
ENDFORM.

Reward Points if it is helpful

Thanks
VAsanth

Former Member
0 Kudos
86

Hi

You have to call that report in script. To call a report in script use the following syntax

 /:   PERFORM CHEQUE_JNTVENT IN PROGRAM ZFISP0002
/:   USING &BKPF-BELNR&
/:   USING &BSEG-GJAHR&
/:   USING &BSEG-BUKRS&
/:   CHANGING &W_CHECT&
/:   CHANGING &W_HBKID&
/*   CHANGING &W_COMP_DESC&
/:   ENDPERFORM
/*   ENDIF

<u><b>Calling a report in script</b></u>

CALL FUNCTION 'OPEN_FORM'
* EXPORTING
*   APPLICATION                       = 'TX'
*   ARCHIVE_INDEX                     =
*   ARCHIVE_PARAMS                    =
*   DEVICE                            = 'PRINTER'
*   DIALOG                            = 'X'
*   FORM                              = 'ZSCRIPT1'
*   LANGUAGE                          = SY-LANGU
*   OPTIONS                           =
*   MAIL_SENDER                       =
*   MAIL_RECIPIENT                    =
*   MAIL_APPL_OBJECT                  =
*   RAW_DATA_INTERFACE                = '*'
*   SPONUMIV                          =
* IMPORTING
*   LANGUAGE                          =
*   NEW_ARCHIVE_PARAMS                =
*   RESULT                            =
 EXCEPTIONS
   CANCELED                          = 1
   DEVICE                            = 2
   FORM                              = 3
   OPTIONS                           = 4
   UNCLOSED                          = 5
   MAIL_OPTIONS                      = 6
   ARCHIVE_ERROR                     = 7
   INVALID_FAX_NUMBER                = 8
   MORE_PARAMS_NEEDED_IN_BATCH       = 9
   SPOOL_ERROR                       = 10
   CODEPAGE                          = 11
   OTHERS                            = 12
          .
IF SY-SUBRC <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CALL FUNCTION 'START_FORM'
EXPORTING
*   ARCHIVE_INDEX          =
   FORM                   = 'ZFORM1'
*   LANGUAGE               = ' '
*   STARTPAGE              = 'X'
   PROGRAM                = 'ZSCRIPT1'
*   MAIL_APPL_OBJECT       =
* IMPORTING
*   LANGUAGE               =
* EXCEPTIONS
*   FORM                   = 1
*   FORMAT                 = 2
*   UNENDED                = 3
*   UNOPENED               = 4
*   UNUSED                 = 5
*   SPOOL_ERROR            = 6
*   CODEPAGE               = 7
*   OTHERS                 = 8
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CALL FUNCTION 'WRITE_FORM'
 EXPORTING
*   ELEMENT                        = ' '
*   FUNCTION                       = 'SET'
*   TYPE                           = 'BODY'
   WINDOW                         = 'HEADER'
* IMPORTING
*   PENDING_LINES                  =
 EXCEPTIONS
   ELEMENT                        = 1
   FUNCTION                       = 2
   TYPE                           = 3
   UNOPENED                       = 4
   UNSTARTED                      = 5
   WINDOW                         = 6
   BAD_PAGEFORMAT_FOR_PRINT       = 7
   SPOOL_ERROR                    = 8
   OTHERS                         = 9
          .
IF SY-SUBRC <> 0.
write:/ 'ERROR IN HEADER'.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CALL FUNCTION 'WRITE_FORM'
 EXPORTING
*   ELEMENT                        = ' '
*   FUNCTION                       = 'SET'
*   TYPE                           = 'BODY'
   WINDOW                         = 'MAIN'
* IMPORTING
*   PENDING_LINES                  =
 EXCEPTIONS
   ELEMENT                        = 1
   FUNCTION                       = 2
   TYPE                           = 3
   UNOPENED                       = 4
   UNSTARTED                      = 5
   WINDOW                         = 6
   BAD_PAGEFORMAT_FOR_PRINT       = 7
   SPOOL_ERROR                    = 8
   OTHERS                         = 9
          .
IF SY-SUBRC <> 0.
write:/ 'ERROR IN HEADER'.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CALL FUNCTION 'WRITE_FORM'
 EXPORTING
*   ELEMENT                        = ' '
*   FUNCTION                       = 'SET'
*   TYPE                           = 'BODY'
   WINDOW                         = 'FOOTER'
* IMPORTING
*   PENDING_LINES                  =
 EXCEPTIONS
   ELEMENT                        = 1
   FUNCTION                       = 2
   TYPE                           = 3
   UNOPENED                       = 4
   UNSTARTED                      = 5
   WINDOW                         = 6
   BAD_PAGEFORMAT_FOR_PRINT       = 7
   SPOOL_ERROR                    = 8
   OTHERS                         = 9
          .
IF SY-SUBRC <> 0.
write:/ 'ERROR IN HEADER'.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CALL FUNCTION 'END_FORM'
* IMPORTING
*   RESULT                         =
* EXCEPTIONS
*   UNOPENED                       = 1
*   BAD_PAGEFORMAT_FOR_PRINT       = 2
*   SPOOL_ERROR                    = 3
*   CODEPAGE                       = 4
*   OTHERS                         = 5
          .

CALL FUNCTION 'CLOSE_FORM'
* IMPORTING
*   RESULT                         =
*   RDI_RESULT                     =
* TABLES
*   OTFDATA                        =
* EXCEPTIONS
*   UNOPENED                       = 1
*   BAD_PAGEFORMAT_FOR_PRINT       = 2
*   SEND_ERROR                     = 3
*   SPOOL_ERROR                    = 4
*   CODEPAGE                       = 5
*   OTHERS                         = 6
          .

Open_form => It assign the form and printer, It should be first.

Start_form => It start Writing mode. You can use write_form in loop to write more than one lines befor End_form.

End_form => It end writing mode of current page and will require to start again through Start_form.

Close_form=> it end the Form. After this you can not start again for created file.

Reward all helpfull answers

Regards

Pavan

Former Member
0 Kudos
86

Hi,

Try this :

Use PERFORM from SAPSCRIPT

/: PERFORM BIN_LOCATION IN PROGRAM Z_SAPSCRIPT_PERFORMS

/: USING &RESBD-MATNR&

/: USING &CAUFVD-IWERK&

/: USING &RESBD-LGORT&

/: CHANGING &MARD-LGPBE&

/: ENDPERFORM

-


REPORT z_sapscript_performs.

*----


  • SUBROUTINES FOR CALLING FROM SAPSCRIPTS

*----


FORM bin_location TABLES in_tab STRUCTURE itcsy

out_tab STRUCTURE itcsy.

*----


  • get default bin location from MARD for this material/plant/storage *

  • location

*----


DATA: l_matnr TYPE matnr, "material

l_werks TYPE werks, "plant

l_lgort TYPE lgort, "storage location

l_lgpbe TYPE lgpbe. "bin location

  • Get first parameter in input table.

READ TABLE in_tab INDEX 1.

WRITE in_tab-value TO l_matnr .

  • Get second parameter in input table

READ TABLE in_tab INDEX 2.

MOVE in_tab-value TO l_werks.

  • Get third parameter in input table

READ TABLE in_tab INDEX 3.

MOVE in_tab-value TO l_lgort.

  • read bin location

SELECT SINGLE lgpbe INTO l_lgpbe FROM mard

WHERE matnr = l_matnr

AND werks = l_werks

AND lgort = l_lgort.

IF l_LGPBE IS INITIAL.

l_LGPBE = 'NONE'.

ENDIF.

  • read & update only parameter in output table

READ TABLE out_tab INDEX 1.

out_tab-value = l_lgpbe.

MODIFY out_tab INDEX 1.

ENDFORM.

<b>Reward points</b>

Regards

Former Member
0 Kudos
86

You can use the PERFORM command to call an ABAP subroutine (form) from any program, subject to the normal ABAP runtime authorization checking. You can use such calls to subroutines for carrying out calculations, for obtaining data from the database that is needed at display or print time, for formatting data, and so on.

PERFORM commands, like all control commands, are executed when a document is formatted for display or printing. Communication between a subroutine that you call and the document is by way of symbols whose values are set in the subroutine.


Example :

From within a SAPscript form, a subroutine GET_BARCODE in the ABAP program QCJPERFO is called. Then the simple barcode contained there (‘First page’, ‘Next page’, ‘Last page’) is printed as local variable symbol.

Definition in the SAPscript form:


/: PERFORM GET_BARCODE IN PROGRAM QCJPERFO
/: USING &PAGE&
/: USING &NEXTPAGE&
/: CHANGING &BARCODE&
/: ENDPERFORM
/

/ &BARCODE&


Coding of the calling ABAP program:

REPORT QCJPERFO.


FORM GET_BARCODE TABLES IN_PAR STUCTURE ITCSY
OUT_PAR STRUCTURE ITCSY.

DATA: PAGNUM LIKE SY-TABIX, "page number 
NEXTPAGE LIKE SY-TABIX. "number of next page

READ TABLE IN_PAR WITH KEY ‘PAGE’.
CHECK SY-SUBRC = 0.
PAGNUM = IN_PAR-VALUE.

READ TABLE IN_PAR WITH KEY ‘NEXTPAGE’.
CHECK SY-SUBRC = 0.
NEXTPAGE = IN_PAR-VALUE.

READ TABLE IN_PAR WITH KEY ‘BARCODE’.
CHECK SY-SUBRC = 0.
IF PAGNUM = 1.
OUT_PAR-VALUE = ‘|’. "First page 
ELSE.
OUT_PAR-VALUE = ‘||’. "Next page 
ENDIF.

IF NEXTPAGE = 0.
OUT_PAR-VALUE+2 = ‘L’. "Flag: last page
ENDIF.

MODIFY OUT_PAR INDEX SY-TABIX. 

ENDFORM.

reward points if it is usefull....

Girish