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: 

Variable in standard text in SAPScript

Former Member
0 Kudos

Hi all.

I have created a standard text in transaction SO10: 'Z_MSG_IMPUESTO'

*Spanish law require us to apply the &D_IVA& tax when the equipment remains in the country*

And D_IVA is a variable which I have to fill in program. I have put the next code in program:

  DATA:
  lt_text TYPE STANDARD TABLE OF tline,
  D_IVA TYPE char3.

    CALL FUNCTION 'READ_TEXT'
    EXPORTING
      id       = 'ST'
      language = nast-spras
      name     = 'Z_MSG_IMPUESTO'
      object   = 'TEXT'
    TABLES
      lines    = lt_text.

* Se informa la variable que hay en el texto

  d_iva = komvd-kbetr / 10.
  concatenate d_iva komvd-koein into d_iva.

  REPLACE ALL OCCURRENCES OF '&D_IVA&' IN TABLE lt_text WITH D_IVA.

  CALL FUNCTION 'WRITE_FORM'
    EXPORTING
      window  = 'MENSAJE'
      element = 'MSG_IVA'.

I have tried with functions 'TEXT_SYMBOL_REPLACE' and 'REPLACE_TEXTSYMBOL' to fill the variable but they don't work.

In program, table lt_text is right and &D_IVA& is substituted by 16%, but when I call  to element of form, in the form 16% doesn't appear.

Is code OK? Am I doing something wrong? Could you  help me?

Thanks a lot.

Marta.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Marta,

when creating standard texts with variables (&D_IVA& in your case) for SapScripts you can use the following approach:

  1. Define the standard text in SO10 as you did (text containing a variable &D_IVA&)
  2. Create a subroutine pool in SE80 with subroutines to be called from SAPScript - create routine there called ie GET_TAX:
    FORM GET_TAX TABLES it_in1 STRUCTURE itcsy
                        it_out1 STRUCTURE itcsy.
      DATA: l_kbetr like komvd-kbetr,
            l_iva(15) type c.

      FIELD-SYMBOLS: <f_out> TYPE itcsy.

      l_kbetr = komvd-kbetr / 10.
      concatenate l_kbetr komvd-koein into l_iva.

    * Write data to first output variable 
      READ TABLE it_out1 ASSIGNING <f_out> INDEX 1.
      IF sy-subrc EQ 0.
        <f_out>-value = l_iva.
      ENDIF.
    ENDFORM.
  3. In SAPScript write something to the following:
    /* Note that SAPScript defined variable &D_IVA& has the same name as in
    /* Standard text (important!!!). This ensures the text retrieved in SAPScript
    /* will automatically replace the variable in standard text
    /: DEFINE &D_IVA& = ' '
    /: PERFORM GET_TAX IN PROGRAM <YOUR_SUBROUTINE_POOL>
    /: CHANGING &D_IVA&
    /: ENDPERFORM
    /: INCLUDE &YOUR_STANDARD_TEXT& OBJECT TEXT ID Z01 LANGUAGE EN


Please let me know (and reward me with points) if this solution worked for you

1 REPLY 1

Former Member
0 Kudos

Hi Marta,

when creating standard texts with variables (&D_IVA& in your case) for SapScripts you can use the following approach:

  1. Define the standard text in SO10 as you did (text containing a variable &D_IVA&)
  2. Create a subroutine pool in SE80 with subroutines to be called from SAPScript - create routine there called ie GET_TAX:
    FORM GET_TAX TABLES it_in1 STRUCTURE itcsy
                        it_out1 STRUCTURE itcsy.
      DATA: l_kbetr like komvd-kbetr,
            l_iva(15) type c.

      FIELD-SYMBOLS: <f_out> TYPE itcsy.

      l_kbetr = komvd-kbetr / 10.
      concatenate l_kbetr komvd-koein into l_iva.

    * Write data to first output variable 
      READ TABLE it_out1 ASSIGNING <f_out> INDEX 1.
      IF sy-subrc EQ 0.
        <f_out>-value = l_iva.
      ENDIF.
    ENDFORM.
  3. In SAPScript write something to the following:
    /* Note that SAPScript defined variable &D_IVA& has the same name as in
    /* Standard text (important!!!). This ensures the text retrieved in SAPScript
    /* will automatically replace the variable in standard text
    /: DEFINE &D_IVA& = ' '
    /: PERFORM GET_TAX IN PROGRAM <YOUR_SUBROUTINE_POOL>
    /: CHANGING &D_IVA&
    /: ENDPERFORM
    /: INCLUDE &YOUR_STANDARD_TEXT& OBJECT TEXT ID Z01 LANGUAGE EN


Please let me know (and reward me with points) if this solution worked for you