cancel
Showing results for 
Search instead for 
Did you mean: 

Program in SAPSCRIPT

Former Member
0 Kudos

Hi all,

Could someone tells me whether I can write program in SAPSCRIPT.

For example I would like to write a SELECT statement in SAPSCRIPT.


DATA: GV_NAME1 LIKE ADRC-NAME1.
SELECT SINGLE NAME1 INTO GV_NAME1 FROM ADRC
WHERE ADDRNUMBER = '0000000104'.

Please advice. Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

No you cannot write a select statement in script. You can however use subroutines in a script.

Vishwa.

Former Member
0 Kudos

I only know IF statement is allowed in SAPSCRIPT.

Former Member
0 Kudos

Check this link:

Along with IF statements, you can write PERFORM statements also,.

VIshwa.

Former Member
0 Kudos

Hi Vishwa,

Thanks for your replies. I have tried to call a form thru SAPSCRIPT, however it is not working.

Have you tried it?

former_member585060
Active Contributor
0 Kudos

Hi,

Use

/:      PERORM form_sub IN PROGRAM zfom  
       /:       USING &FIELD1&
       /:       CHANGING &FIELD2&
       /:       ENDFORM

now create a Program type M in SE38 with name zform

write your code

https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/callingasub-routineinSAP+scripts

search SCN you will find many treads regarding subroutines in SAPSCRIPTS

Regards

Bala Krishna

Edited by: Bala Krishna on Feb 6, 2009 1:37 PM

Former Member
0 Kudos

can u show the code which u wrote to call a perform.

also insert a breakpoint in the form which u hv written in the program(which is of type subroutine pool).

it will let u know if perform is being called or not.

debugging will solve ur problem so debud ur script too.

кu03B1ятu03B9к

Answers (6)

Answers (6)

Former Member
0 Kudos

HI,

If you want to print the address in your form it is not necessary to go with the select statement in the scripts

you have an option provided by SAP


/: ADDRESS
* &addrnumber&     "----> pass the value of the address number from your program
/: ENDADDRESS

for further reference check the link:

[http://help.sap.com/saphelp_nw04/helpdata/en/d1/803238454211d189710000e8322d00/frameset.htm]

Former Member
0 Kudos

No, you cannot write the select query in the script but you can do this in the print program and then in the script define the place where u want to print the address and write it as

/: address

&addrnumber&

/: endaddress

Former Member
0 Kudos

Hi,

You cannot write a program in form, Only If statements are used .You can select teh fields in driver program and you can declare that field string as text element in form.

Ex:

Work area is <w_a>

you declare in form

/: w_a

  • <fields>

You can get the values in driver program

Regards,

Rajani

former_member585060
Active Contributor
0 Kudos
/: DEFINE gv_name1 = 'AAAAAAAAA'.
/: PERFORM adrc_name IN PROGRAM zfrom
/: USING &ADRC-ADDRNUMBER&      " this field should have relation to get value fron ADRC table
/: CHANGING &GV_NAME1&
/: ENDFORM

in ZFORM program


FORM adrc_name TABLES intable STRUCTURE itcsy
                      outtable STRUCTURE itcsy.
  
DATA: w_adrnumber like ADRC-ADDRNUMBER,
           w_name1 like ADRC-NAME1.

  READ TABLE intable INDEX 1.
  w_adrnumber = intable-value.
  
 SELECT SINGLE name1 INTO w_name1 FROM adrc
WHERE addrnumber = w_adrnumber.
    
IF sy-subrc = 0.
      READ TABLE outtable INDEX 1.
      outtable-value = w-name11.
      MODIFY outtable INDEX 1.
    ENDIF.
    
  ENDFORM.                                                    "adrc_name
Former Member
0 Kudos

hi

You can not write SELECT statements in sap script , you can only write IF-ENDIF statements to only print text elements.

you have to write seperate calling program for sap script where you can use PERFORM statement to transfer data to programs and program data into SAP script without having to change your print program.

e.g code in sap script

/: PERFORM GET_DATA IN PROGRAM ZLSV_SCRPFM_RG00 (CAlling program name)

/:USING &MARA-MATNR& (material number)

/:CHANGING &G_MATNR& (TExt element)

/:ENDPERFORM

e.g code in Z program

FORM GET_DATA TABLES input_table STRUCTURE itcsy

output_table STRUCTURE itcsy.

DATA : l_matnr TYPE mara-matnr,

l_symbol TYPE C.

REFRESH output_table.

CLEAR output_table.

LOOP AT input_table.

CASE input_table-name.

WHEN 'MARA-MATNR'.

l_matnr = input_table-value.

ENDCASE.

ENDLOOP.

SELECT matnr INTO l_matnr

FROM mara

UP TO 1 ROWS

WHERE matnr = l_matnr

ENDSELECT.

IF syst-subrc EQ 0.

MOVE 'MARA-MATNR' TO output_table-name.

MOVE l_matnr TO output_table-value.

APPEND output_table.

CLEAR output_table.

ENDIF.

ENDFORM.

Here you can write your logic in Zprogram and get value of matnr from program and print this value in sap script and using &G_MATNR& command in script.

Former Member
0 Kudos

Hi,

you can use if ...endif.

better write a program with subroutine for

GV_NAME1 LIKE ADRC-NAME1.

SELECT SINGLE NAME1 INTO GV_NAME1 FROM ADRC

WHERE ADDRNUMBER = '0000000104'.

Then in the script,make use of perform...endperform in the text editor.