cancel
Showing results for 
Search instead for 
Did you mean: 

sapscript (urgent)

Former Member
0 Kudos

Hi gurus,

i hv a requirement to copy a standard standard script which uses a standard print program to a z program.

i have to select some addtional data and print it in addtion to the standard.

can anyone tell me how to add qurries in script itself.

points will be rewarded to all helpful answers.

regards,

rahul

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member196280
Active Contributor
0 Kudos

If you want to retrive additional fields without modify the driver program... you can use sub-routines inside your SAPscripts.

Go through this example

Ex.

/: PERFORM <Subroutine name> IN PROGRAM <subroutine prog name>

/:USING &<field name>&

/:CHANGING &<field name1&

/:ENDPERFORM

Then create subroutine pool program and you have to write the code.

FORM ><subroutine name> tables int_cond structure itcsy

outt_cond structure itcsy.

data : value(20), value1(20). "do your own declarations

Read int_cond table index 1.

value = int_cond-value.

value1 = value1 + value.

Read outt_cond table index 1.

outt_cond-value = value1.

Modify outt_cond index 1.

ENDFORM.

Just rough idea given above.

Regards,

SaiRam

Former Member
0 Kudos

Hi

welcome to SDN forum.

see the doc for copying the std script and doing changes

There are some Standard Sap Scripts in SAP. We cant directly execute them in scripts we have to use some T-codes and by giving some input to the required fields we can see the output printform.

I will show one example. There are some Standard Sap Scripts such as MEDRUCK which is a standard Sap Script for Purchase Order and RVINVOICE01 for billing and so on...

To see oupt of MEDRUCK go to T-code ME9F give purchase order number and execute select one number and click on dislplay messages button on application tool bar you can find the print form of MEDRUCK.

You cannot change the Standard Sap Scripts but you can use Standard Sap Scripts and Copy them to userdefined Script and can make changes to them and replace standard Sap Script with usedefind script.

Ex: Go to SE71,

on menu bar u find Utilities->copy from Client. click on it u ll find new screen showing

Form name:

Source Clinet:

Target Form:

give Form name as usedefined form name EX: ZFORM1

Source client as 000 and

Target form as MEDRUCK.

execute.

Now, the standard from MEDRUCK is copyied to your form ZFORM1.

NOW, go to SE71 and give form name as ZFORM1 and do some changes to the form such as adding logo any thing. save and Activate.

Now, you have done changes to the Form ZFORM1 and u have to replace your form with standard SAP Script.

Go to NACE Transaction.

on Applications select EF for purchase order and click Output types button on application tool bar.

now select NEU as output types dobule click on Processing Routines.

now click on Change option on application tool bar and on right side u find MEDRUCK in form place replace MEDRUCK with ZFORM1 and SAVE.

go back twice and now go to T-code ME9F give the purchase order number and execute and select one option and click on display messges button .

you will find the changes that you have done in ZFORM1. so we cant chage the standard Sap Scripts by copying the Standard Sap Scripts we can chage and replace with our forms.

To get the external data into the script from external tables you can use PERFORM subroutines and display the data

see the sample code

How to call a subroutine form SAPscripts

The Form :

/:PERFORM CDE_CENT IN PROGRAM ZKRPMM_PERFORM_Z1MEDRUCK

/:USING &EKKO-EBELN&

/:CHANGING &CDECENT&

/:ENDPERFORM

The report :

REPORT zkrpmm_perform_z1medruck .

DATA : BEGIN OF it_input_table OCCURS 10.

INCLUDE STRUCTURE itcsy.

DATA : END OF it_input_table.

  • déclaration de la table output_table contenant les

variables exportées

DATA : BEGIN OF it_output_table OCCURS 0.

INCLUDE STRUCTURE itcsy.

DATA : END OF it_output_table.

DATA : w_ebeln LIKE ekko-ebeln,

  • w_vbeln LIKE vbak-vbeln,

w_zcdffa LIKE vbak-zcdffa.

*----


*

  • FORM CDE_CENT

*

*----


*

FORM cde_cent TABLES input output.

it_input_table[] = input[].

it_output_table[] = output[].

READ TABLE it_input_table INDEX 1.

MOVE it_input_table-value TO w_ebeln.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = w_ebeln

IMPORTING

output = w_ebeln.

SELECT SINGLE zcdffa FROM ekko

INTO w_zcdffa

WHERE ebeln = w_ebeln.

it_output_table-name = 'CDECENT'.

MOVE w_zcdffa TO it_output_table-value.

MODIFY it_output_table INDEX 1.

output[] = it_output_table[].

ENDFORM.

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

REPORT ZMPO1 .

form get_freight tables in_par structure itcsy out_par structure itcsy.

tables: ekko,konv,t685t.

data: begin of itab occurs 0,

ebeln like ekko-ebeln,

knumv like ekko-knumv,

end of itab.

data: begin of itab1 occurs 0,

knumv like konv-knumv,

kposn like konv-kposn,

kschl like konv-kschl,

kbetr like konv-kbetr,

waers like konv-waers,

kwert like konv-kwert,

end of itab1.

data: begin of iout occurs 0,

kschl like konv-kschl,

vtext like t685t-vtext,

kbetr like konv-kbetr,

kwert like konv-kwert,

end of iout.

data v_po like ekko-ebeln.

read table in_par with key 'EKKO-EBELN'.

if sy-subrc = 0.

v_po = in_par-value.

select

ebeln

knumv

from ekko

into table itab

where ebeln = v_po.

if sy-subrc = 0.

loop at itab.

select

knumv

kposn

kschl

kbetr

waers

kwert

into table itab1

from konv

where knumv = itab-knumv and

kappl = 'M'.

endloop.

loop at itab1.

if itab1-kposn <> 0.

select single * from t685t

where kschl = itab1-kschl

and kappl = 'M'

and spras = 'EN'.

iout-vtext = t685t-vtext.

iout-kschl = itab1-kschl.

iout-kbetr = itab1-kbetr.

iout-kwert = itab1-kwert.

append iout.

clear iout.

endif.

endloop.

sort itab1 by kposn.

loop at iout.

sort iout by kschl.

if ( iout-kschl eq 'GSDC' OR

iout-kschl eq 'GSFR' OR

iout-kschl eq 'GSIR' ).

at end of kschl.

read table iout index sy-tabix.

sum.

  • write:/ iout-kschl,iout-vtext,iout-kwert.

out_par-name = 'A1'.

out_par-value = iout-vtext.

append out_par.

out_par-name = 'A2'.

out_par-value = iout-kwert.

append out_par.

endat.

endif.

endloop.

endif.

endif.

endform.

  • IN THE FORM I AM WRITING THIS CODE.

/:DEFINE &A1& = ' '

/:DEFINE &A2& = ' '

/:PERFORM GET_FREIGHT IN PROGRAM ZMFORM_PO1

/:USING &EKKO-EBELN&

/:CHANGING &A1&

/:CHANGING &A2&

/:ENDPERFORM

  • &A1&

  • &A2&

This Code is to be written in the PO form under ADDRESS window.

-

-


/:DEFINE &A1& = ' '

/:DEFINE &A2& = ' '

/:DEFINE &A3& = ' '

/:DEFINE &A4& = ' '

/:DEFINE &A5& = ' '

/:DEFINE &A6& = ' '

/:PERFORM GET_VENDOR IN PROGRAM ZMFORM_PO

/:USING &EKKO-EBELN&

/:CHANGING &A1&

/:CHANGING &A2&

/:CHANGING &A3&

/:CHANGING &A4&

/:CHANGING &A5&

/:CHANGING &A6&

/:ENDPERFORM

  • &A1&

  • &A2&

  • &A3&

  • &A4&

  • &A5&

  • &A6&

Reward points for useful Answers

Regards

Anji

Former Member
0 Kudos

Hi rahul,

What you can do is… add a perform in your sap script which refers to another program.

Then create a form in a separate program and add any piece of code in this new program.

You can also declare variables in your script.

Refer to the following sample code.

In the script


/: DEFINE &V_L_EKNAM& = ''
/: PERFORM GET_BUYER_NAME IN PROGRAM Z_GET_BUYER_DETAILS
/: USING &VIQMEL-BKGRP&
/: CHANGING &V_L_EKNAM&
/: &V_L_EKNAM&

In the program Z_GET_BUYER_DETAILS create a form GET_BUYER_NAME like done below.

*&---------------------------------------------------------------------*
*&      Form  GET_BUYER_NAME
*&---------------------------------------------------------------------*
*       Get the name of purchasing group
*----------------------------------------------------------------------*
*      -->P_IT_INTAB   STRUCTURE  itcsy
*      -->P_IT_OUTTAB  STRUCTURE  itcsy
*----------------------------------------------------------------------*
FORM get_buyer_name  TABLES p_it_intab STRUCTURE itcsy
                            p_it_outtab STRUCTURE itcsy.

* read the table containing values passed from the script with respect
* to purchasing group
  DATA : wa_l_intab TYPE itcsy,
         wa_l_outtab TYPE itcsy.

  CLEAR wa_l_intab.
* read in table to get the value of purchasing group
  SORT p_it_intab BY name.
  READ TABLE p_it_intab INTO wa_l_intab
                        WITH KEY name = 'VIQMEL-BKGRP'
                        BINARY SEARCH.
  IF sy-subrc = 0.
* assign purchasing group to a variable v_ekgrp.
    v_ekgrp =  wa_l_intab-value.
  ENDIF.

  CLEAR v_eknam.

*select the name of purchasing group from T024 table
  SELECT eknam up to 1 rows
               FROM t024
               INTO v_eknam
               WHERE ekgrp = v_ekgrp.
  ENDSELECT.

* assign the telephone number to changing parameter V_L_EKTEL of script
  LOOP AT p_it_outtab INTO wa_l_outtab
                      WHERE name = 'V_L_EKNAM'.
    wa_l_outtab-value = v_eknam.
    MODIFY p_it_outtab FROM wa_l_outtab INDEX sy-tabix.

  ENDLOOP.


p_it_intab , p_it_outtab are of structure type itcsy, you have to use them like this only to get the parameters used in perform.

Hope it solves your problem.

Regards,

Gaurav

<b>Reward points if helpful</b>