Application Development and Automation 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: 
Read only

In sap script i am getting same value two times?

former_member209120
Active Contributor
0 Likes
5,043

In sap script i am getting same value two times?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
4,550

Hi Ramesh,

You can use text element for that particular window.

You can't use text element the first record will be printed twice.

you can create text element in script,in that window  for ex:

/E  Te

&FS_EKPO-NETPR&,,&FS_EKPO-MATNR&,,&FS_EKPO-LGORT&,,&FS_EKPO-WEKRS&

call function 'WRITE_FORM'

        exporting

  ELEMENT                        =  ' TE'

*   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.

Answer is correct,please allot me points.

Regards,

Manohar Reddy

In sap script i am getting same value two times?

23 REPLIES 23
Read only

arindam_m
Active Contributor
0 Likes
4,550

Hi,

Please elaborate with the window code that is doing this. Also my suggestion is to debug your script by Activating debugger in SE71. You can see the line item being processed.

Cheers,

Arindam

Read only

Former Member
0 Likes
4,550

Hi,

The problem may be in the coding I think first line items details are printed correctly.

1.May be you have used the printing variables two times,

2.Inside loop according to some conditions the values will print,condition satisfied in two places or check the IF... ELSE statements used correctly.

Because,If all the conditions failed they will write this item printing conditions in final ELSE part may be your code will satisfies there also.

Go to SE71->Utilities from file menu,Click , Activate debuger and check it or share that overall loop lines of coding.Hope it is useful,Thanks for understanding.

Regards,

Ravi Shankar L

Read only

satyabrata_sahoo3
Contributor
0 Likes
4,550

Debug and check your what data your internal table passing to the Script.. 

Read only

Former Member
0 Likes
4,550

If its happening only for that order number, probably your internal table is containing duplicate entries. Confirm that that record (order No. 12096) is present only once in your internal table.

Read only

0 Likes
4,550

Hi Susmitha,

In my inter table i am not getting any duplicate entries, but in output i am getting duplicate values for first row, I am sharing my code for your reference

*********Declaration part.
tables : kna1.

select-options : s_kunnr for kna1-kunnr.

*******internal table & work area declaration

data : it_kna1 type table of kna1,
        wa_kna1 type kna1,
        it_vbak type table of vbak,
        wa_vbak type vbak.

data : w_tot type vbak-netwr.

*************Start of selection.

start-of-selection.

   perform get_kna1_data.

   perform get_vbak_data.

***************end of selection.

end-of-selection.

   perform start_script.

   perform write_to_script.

   perform close_script.




*&---------------------------------------------------------------------*
*&      Form  get_kna1_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form get_kna1_data .

   select * from kna1 into table it_kna1 where kunnr in s_kunnr.

   if sy-subrc ne 0.

     message 'No Records found for the given selection' type 'I'.
     leave list-processing.

   endif.

endform.                    " get_kna1_data
*&---------------------------------------------------------------------*
*&      Form  get_vbak_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form get_vbak_data .

   select * from vbak into table it_vbak for all entries in it_kna1 where kunnr eq it_kna1-kunnr.

endform.                    " get_vbak_data
*&---------------------------------------------------------------------*
*&      Form  start_script
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form start_script .

   call function 'OPEN_FORM'
    exporting
*   APPLICATION                       = 'TX'
*   ARCHIVE_INDEX                     =
*   ARCHIVE_PARAMS                    =
*   DEVICE                            = 'PRINTER'
*   DIALOG                            = 'X'
      form                              = 'YRAMSCRIPT'
*   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.

endform.                    " start_script
*&---------------------------------------------------------------------*
*&      Form  write_to_script
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form write_to_script .

   clear wa_kna1.
   loop at it_kna1 into wa_kna1.

     clear w_tot.

     call function 'START_FORM'
      exporting
*   ARCHIVE_INDEX          =
        form                   = 'YRAMSCRIPT'
*   LANGUAGE               = ' '
*   STARTPAGE              = ' '
*   PROGRAM                = ' '
*   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                         = 'ADDRESS'
* 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.


     loop at it_vbak into wa_vbak where kunnr eq wa_kna1-kunnr.


       w_tot = w_tot + wa_vbak-netwr.



       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
*   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.

     endloop.

     call function 'END_FORM'
* IMPORTING
*   RESULT                         =
* EXCEPTIONS
*   UNOPENED                       = 1
*   BAD_PAGEFORMAT_FOR_PRINT       = 2
*   SPOOL_ERROR                    = 3
*   CODEPAGE                       = 4
*   OTHERS                         = 5
               .
     if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
     endif.



   endloop.

endform.                    " write_to_script
*&---------------------------------------------------------------------*
*&      Form  close_script
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form close_script .


   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.

endform.                    " close_script

Regards,

Ramesh.T

Read only

0 Likes
4,550

Hi,

Please use debug option for sapscript to understand your code. Use program RSTXDBUG or u have option in utilities - activate debugger.

Cheers,

Arindam

Read only

0 Likes
4,550

Try clearing all work areas

*----------------------------------------------------------------------*
form write_to_script .

   clear : wa_kna1, wa_vbak.

Read only

0 Likes
4,550

Can you show a screen shot of your script editor also?

I still have the feeling that there are two entries in the vbak table for the same sold to party (Kunnr) with the same order number (aufnr)

Insert this statement.

sort i_vbak by kunnr aufnr.

Then debug at this  point to see the entries in i_vbak.

(And if there are more than one entries and it is not desirable to output them you can use the following statement after the sort statement.

delete adjacent duplicates from i_vbak. )

Read only

0 Likes
4,550

Now my output like this, no improvement

Read only

0 Likes
4,547

Read only

0 Likes
4,547

So just clear WA_VBAK after print.

beyond this you have nothing to do anything.

Read only

0 Likes
4,547

Hi,

clearing wa_vbak should solve the issue. Is this code written only in this window or in any other window.

Regards,

Swarna

Read only

Former Member
0 Likes
4,547

Hi,

your internal table contains duplicate values.

You can use

1) sort <internal table>

then

2) delete adjacent duplicate from <internal table>

then after pass to script.

Regards

Avirat Patel

Read only

0 Likes
4,547

Hi Aviral,

I checked internal table there is  no duplicate values in it.

Read only

0 Likes
4,547

Hi,

Clearing your work area wa_vbak,w_tot should help.

Cheers,

Arindam

Read only

Former Member
0 Likes
4,547

Hi ramesh,

Try to clear all the Work areas used, sort and delete the adjacent duplicates of an itab then check.

Regards,

Satish.

Read only

Former Member
0 Likes
4,551

Hi Ramesh,

You can use text element for that particular window.

You can't use text element the first record will be printed twice.

you can create text element in script,in that window  for ex:

/E  Te

&FS_EKPO-NETPR&,,&FS_EKPO-MATNR&,,&FS_EKPO-LGORT&,,&FS_EKPO-WEKRS&

call function 'WRITE_FORM'

        exporting

  ELEMENT                        =  ' TE'

*   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.

Answer is correct,please allot me points.

Regards,

Manohar Reddy

Read only

0 Likes
4,547

Hi Manohar,

Your answer is correct, now it is working.

Good, keep it up.

Thank You,

Ramesh.T

Read only

0 Likes
4,547

Dear Manohar,

Can you explain, we we need to use this element in scripts, what is its use.

Regards,

Ramesh.T

Read only

0 Likes
4,547

Hi Ramesh,

Explanation about Text element:-

Text Element:

            Text element is the name given to the black of elements in the page window. The text element name is followed by /E.

            If we pass text element name in the WRITE_FORM function module then WRITE_FORM transfers the data from driver program to all the statements which are defined under text element.

Read only

0 Likes
4,547

Hi Ramesh,

The /E in the tag column is used to identify the text as a text element Windows

Read only

0 Likes
4,547

This message was moderated.

Read only

Former Member
0 Likes
4,547

This message was moderated.