05-01-2016 1:23 PM
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.
05-02-2016 7:08 AM
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..
05-02-2016 5:03 AM
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
05-02-2016 6:30 AM
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.
05-02-2016 5:40 AM
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.
05-02-2016 7:08 AM
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..
05-02-2016 7:31 AM
Hi Prajesh,
Thank you...its working but i am getting invoice should be stars instead of stars print the Invoice number like 90005179
05-02-2016 7:38 AM
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.
05-02-2016 7:51 AM
First page invoice number will be printing properly and in next page it is not printing once check the sample code in above post's
In input filed values : 90005178 to 90005179
in first page
Invoice Number : 9000178
Second page
Invoice Number :***********
05-02-2016 7:56 AM
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
05-02-2016 9:51 AM
I simply done below,
Please look at your scripting,
It's working for me.
05-02-2016 10:22 AM
Hi Prajesh
Input :
Result :
first Page
second page { Invoice number : 90005179 is not printing }
05-02-2016 12:30 PM
05-04-2016 4:29 AM
this is code i am written
*************************************************************************
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
05-04-2016 5:06 AM
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.
05-04-2016 5:12 AM
Hi Prajesh Desai,
Thank you .....you done a grate help to me
thank you
05-04-2016 5:24 AM
Hi Praveen,
I hope you read my first suggestion for your **** issue.
Regards,
Nikhil
05-04-2016 5:37 AM
Hi Praveen,
Please ignore earlier message. It was written before Prajesh's reply.
Regards,
Nikhil
05-04-2016 5:48 AM
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
05-04-2016 6:29 AM
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