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: 

Query about field manipulation in forms

Former Member
0 Kudos

Hi,

I have a form printing an invoice having

1) VAT amount (A)

2)Total invoice amount including VAT (B)

I want to add one more field to it, which will also print the amount without VAT (C).

I.e. c = b - a.

how can i do that in the FORM or my print program ? If i create a local variable in the print program and populate it, how do i call that from the FORM ? Please help.

Thanks & Regards

Hrishi

1 ACCEPTED SOLUTION

former_member480923
Active Contributor
0 Kudos

write a perform routine in the SAPScript where you need to pass the following:

define: &w_vatc& := &w_vata&.

perform sub_calculate_valtc in program zprog_script

using &w_vata&

&w_vatb&

changing &w_vatc&

endperform.

and in the perform routine in the Zprogram do the relavent calculations

Hope That Helps

Anirban M.

8 REPLIES 8

former_member480923
Active Contributor
0 Kudos

write a perform routine in the SAPScript where you need to pass the following:

define: &w_vatc& := &w_vata&.

perform sub_calculate_valtc in program zprog_script

using &w_vata&

&w_vatb&

changing &w_vatc&

endperform.

and in the perform routine in the Zprogram do the relavent calculations

Hope That Helps

Anirban M.

0 Kudos

Can you pls provide some example

0 Kudos

Here is the program::

*&---------------------------------------------------------------------*
*& Report  ZTEST_PRG3
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

report  ztest_prg3.

*WRITE: 'This is the Submitted Program'.


data: w_lgort type lgort_d,
      w_werks type werks_d.


parameters: p_matnr type matnr obligatory.

select single lgort werks from mard
       into (w_lgort, w_werks)
       where matnr = p_matnr.

check sy-subrc = 0.

call function 'OPEN_FORM'
 exporting
   application                       = 'TX'
   device                            = 'PRINTER'
   form                              = 'ZZTEST_FORM1'
   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 'WRITE_FORM'
 exporting
   element                        = 'ADDR'
   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
*   CODEPAGE                       = 9
*   OTHERS                         = 10
          .
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 '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
          .
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.


*&---------------------------------------------------------------------*
*&      Form  ZTEST_CALC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->INTAB      text
*      -->OUTTAB     text
*----------------------------------------------------------------------*
form ztest_calc tables intab structure itcsy
                      outtab structure itcsy.

  data: w_werks type werks_d,
        w_lgort type lgort_d,
        w_lgobe type lgobe.

** READ THE INTAB.
  read table intab with key name = 'W_WERKS'.

  if sy-subrc = 0.
    w_werks = intab-value.
    read table intab with key name = 'W_LGORT'.
    if sy-subrc = 0.
      w_lgort = intab-value.
      select single lgobe from t001l into w_lgobe
                          where werks = w_werks
                            and lgort = w_lgort.

      if sy-subrc = 0.
        outtab-value = w_lgobe.
        modify outtab index 1 transporting value.
      endif.

    endif.
  endif.




endform.                    "ZTEST_CALC

and here is what i wroye inside the Form routine:

 	DEFINE &W_LGOBE& = &MARD-LGOBE&.
 	BOX WIDTH '17.5' CM HEIGHT '10' CM FRAME 10 TW INTENSITY 15
 	PERFORM ZTEST_CALC IN PROGRAM ZTEST_PRG3
 	                             USING &W_WERKS&
 	                             USING &W_LGORT&
 	                          CHANGING &W_LGOBE&
 	ENDPERFORM.
 	&W_LGOBE&

Hope That Helps

Anirban M.

0 Kudos

Thanks Anirban,

this is what i have written in print prog.

form cal tables intab structure itcsy

outtab structure itcsy.

data: EXCL_VAT type KOMK-FKWRT.

data: w_fkwrt type komk-fkwrt.

data: w_kwert type KOMVD-KWERT.

    • READ THE INTAB.

read table intab with key name = 'KOMVD-KWERT'.

if sy-subrc = 0.

w_kwert = intab-value.

read table intab with key name = 'komk-fkwrt'.

if sy-subrc = 0.

w_fkwrt = intab-value.

EXCL_VAT = W_FKWRT - W_KWERT.

outtab-value = EXCL_VAT.

modify outtab index 1 transporting value.

endif.

endif.

endform.

and this is what i have written in form.

DEFINE &EXCL_VAT& = &KOMK-FKWRT&

PERFORM CAL IN PROGRAM ZSDARVADIN01

USING &KOMVD-KWERT&

USING &KOMK-FKWRT&

CHANGING &EXCL_VAT&

ENDFORM

AMOUNT EXLUSIVE VAT,, &EXCL_VAT&

this does not work ! it prints komk-fkwrt as excl_vat.

i need excl_vat as EXCL_VAT = W_FKWRT - W_KWERT.

Pls help. Thanks in advance

Regards

Hrishi

0 Kudos

Please do the small change:

DEFINE &EXCL_VAT& := &KOMK-FKWRT

Hope That Helps

Anirban M.

0 Kudos

Hi Anirban,

It still doesnt work. now, Its not printing anything at all. I could find what the problem is. In this code :

40 EXCL_VAT = komk-fkwrt - komvd-kwert.

41 READ TABLE outtab INDEX 1.

42 outtab-value = EXCL_VAT.

43 MODIFY outtab INDEX 1.

endform.

If i debug, excl_vat will have the correct value.

But outtab-value will have prev. routine return value till line 42. After line 42 it will go blank.

What can be the reason that it is not copying the value of excl_vat ??

Please help.

Thanks a lot

Hrishi

0 Kudos

The reason is quite simple:

EXCL_VAT is a quantity field and the value field in ITCSY is a Character field, ( sooory i mssed it last time..) so please change in the following manner.

write EXCL_VAT to outtab-value. 
condense outtab-value. 

Hope That Helps

Anirban M.

0 Kudos

You are the MAN !!!!! 10/10.. problem solved !

Thanks Anirban !