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: 

SAP Script : Problem on At end of <field> & Control_form

0 Kudos

Hi,

   i am new to ABAP i am writing a simple program on SAP Script.My program successfully executed but after printing the lat records it will display on empty form

Ex :  my input  :   90005178   to   90005179

it having two records now i want to display 90005178 in fist page and  second page 90005179  it is displaying but along with these two pages one more page will be printed

                            any one can tell me where i can did the mistake..........Please

Code:

START-OF-SELECTION.

   SELECT VBELN
          POSNR
          MATNR
          FKIMG
          VRKME
          NETWR FROM VBRP INTO TABLE IT_VBRP
     WHERE VBELN in S_VBELN.

   IF SY-SUBRC <> 0.
     MESSAGE 'INVOICE NO. DOES NOT EXIST' TYPE 'I'.
     LEAVE LIST-PROCESSING.
   ENDIF.
if sy-subrc = 0.
   CALL FUNCTION 'OPEN_FORM'
     EXPORTING
       FORM                        = 'ZDEMO_INVOICE'
       LANGUAGE                    = SY-LANGU
     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 IT_VBRP IS NOT INITIAL.
     LOOP AT IT_VBRP INTO WA_VBRP.

       IF WA_VBRP-FKIMG <> 0.
         UP = WA_VBRP-NETWR / WA_VBRP-FKIMG.
       ELSE.
         UP = 0.
       ENDIF.

       subtot = subtot + wa_vbrp-netwr.

       CALL FUNCTION 'WRITE_FORM'
         EXPORTING
           ELEMENT                  = 'E1'
           WINDOW                   = 'MAIN'
         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.

       AT END OF VBELN.

         CALL FUNCTION 'CONTROL_FORM'
           EXPORTING
             COMMAND   = 'NEW-PAGE'
           EXCEPTIONS
             UNOPENED  = 1
             UNSTARTED = 2
             OTHERS    = 3.

         clear subtot.
       ENDAT.

     ENDLOOP.
   ENDIF.

    CALL FUNCTION 'CLOSE_FORM'
     EXCEPTIONS
       UNOPENED                 = 1
       BAD_PAGEFORMAT_FOR_PRINT = 2
       SEND_ERROR               = 3
       SPOOL_ERROR              = 4
       CODEPAGE                 = 5
       OTHERS                   = 6.
   IF SY-SUBRC <> 0.

   ENDIF.
   endif.

1 ACCEPTED SOLUTION

prajeshdesai
Contributor
0 Kudos

Add below to skip calling CONTROL_FORM for last iteration of loop.


AT LAST.

     CONTINUE.

ENDAT.

Above will skip followed by (below) code.


AT END OF VBELN.

       

          CALL FUNCTION 'CONTROL_FORM'

            EXPORTING

              COMMAND   = 'NEW-PAGE MAIN'

            EXCEPTIONS

              UNOPENED  = 1

              UNSTARTED = 2

              OTHERS    = 3.

          clear subtot.

ENDAT.

Hope this helps..

18 REPLIES 18

Former Member
0 Kudos

hi,

i think the problem with your code is at CALL FUNCTION 'CONTROL_FORM' level.

As you dont want additional page but according to the control_form routine, it will generate one additional new-page as the result of last record execution.


write the logic for restricting the creation of next page creation at the time of last record execution.


Reward points if it is helpful.


Thanks and regards,

Sagar

0 Kudos

Thank you but my requirement i don't want to print the last page if you don't mine can you tell me how to restrict that.

former_member194965
Active Participant
0 Kudos

Hi,

Problem with CONTROL_FORM, As you write that call the form at last sales document record. So that it gives you empty pages after last record.

Hope it might be helpful.

Regards,

E.Ananthachari.

prajeshdesai
Contributor
0 Kudos

Add below to skip calling CONTROL_FORM for last iteration of loop.


AT LAST.

     CONTINUE.

ENDAT.

Above will skip followed by (below) code.


AT END OF VBELN.

       

          CALL FUNCTION 'CONTROL_FORM'

            EXPORTING

              COMMAND   = 'NEW-PAGE MAIN'

            EXCEPTIONS

              UNOPENED  = 1

              UNSTARTED = 2

              OTHERS    = 3.

          clear subtot.

ENDAT.

Hope this helps..

0 Kudos

Hi Prajesh,

  Thank you...its working but i am getting invoice should be stars instead of stars print the Invoice number  like 90005179

0 Kudos

Dear Praveen,

        Check whether the invoice no getting filled in AT END or AT NEW event properly .

Pass that invoice no to you structure before these events.

0 Kudos

Hi

0 Kudos

Hi,

Try to copy  VBELN to another variable which coming from WA_VBRP and then use;


<New variable> = WA_VBRP-VBELN.

AT END OF <New variable>.


Please check and do let us know.

Hope this will work for you.

Regards,

Nikhil

0 Kudos

I simply done below,

Please look at your scripting,

It's working for me.

0 Kudos

Hi Prajesh

Input   :             

Result :

                    first Page

                       second page  {  Invoice number :  90005179   is not printing }

0 Kudos

Check your internal table data before WRITE_FORM fm.

0 Kudos

HI

START-OF-SELECTION.

SELECT VBELN
        POSNR
        MATNR
        FKIMG
        VRKME
        NETWR
FROM VBRP INTO TABLE IT_VBRP
WHERE VBELN in S_VBELN.

IF SY-SUBRC <> 0.
  
MESSAGE 'INVOICE NO. DOES NOT EXIST' TYPE 'I'.
  
LEAVE LIST-PROCESSING.
ENDIF.


CALL FUNCTION 'OPEN_FORM'
EXPORTING
FORM          'ZDEMO_INVOICE1'
LANGUAGE SY-LANGU.


LOOP AT IT_VBRP INTO WA_VBRP.

IF WA_VBRP-FKIMG <> 0.
UP = WA_VBRP-NETWR / WA_VBRP-FKIMG.
ELSE.
UP = 0.
ENDIF.

subtot
= subtot + wa_vbrp-netwr.

CALL FUNCTION 'WRITE_FORM'
EXPORTING
    ELEMENT
= 'E1'
   
WINDOW  = 'MAIN  .

at last.
CONTINUE.
endat.

AT end of vbeln.
CALL FUNCTION 'CONTROL_FORM'
EXPORTING
command
= 'NEW-WINDOW'.

clear subtot.
ENDAT.

ENDLOOP.

CALL FUNCTION 'CLOSE_FORM'


Form Designing in Script

Main window


Header window

Test data :

90005178 record printing successfully  and main window data also printing

90005179  :- -   invoice number am getting  ********  and main window data is printing


0 Kudos

Try below,


DATA: LV_VBELN TYPE VBRP-VBELN.

......

  IF IT_VBRP IS NOT INITIAL.

      LOOP AT IT_VBRP INTO WA_VBRP.

       LV_VBELN = WA_VBRP-VBELN.


......

Use LV_VBELN in your script.


/=   VBELN: &LV_VBELN&

Hope this helps.

0 Kudos

Hi Prajesh Desai,


    Thank you .....you done a grate help to me

                              thank you

nikhil_kalawade
Explorer
0 Kudos

Hi Praveen,

I hope you read my first suggestion for your **** issue.

Regards,

Nikhil

0 Kudos

Hi Praveen,

Please ignore earlier message. It was written before Prajesh's reply.

Regards,

Nikhil

0 Kudos

Hi nikhil

   your suggestions also helpful to me but First MR.Prajesh Desai comment only i can solve my issue 90% .then after i am facing new problem that  is invoice number is not printing in my last page.


But in your post you told me


data:gv_vbeln type vbrp-vbeln.


<New variable> = WA_VBRP-VBELN.

     gv_vbeln



0 Kudos

Hi Praveen,

I was writing comment but i left the window due to other work in between Prajesh replied and I agree that was perfect answer given by Prajesh. When I sent comment and refreshed window then I saw Prajesh message so I clarified to igonre instead of deleting message.

Anyway thanks for replying and Prajesh for guidelines.

p.s. error due to we need to define as a components not as single variable. Sorry for confusion.

Regards,

Nikhil