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: 

Get invoice related information for selected sales order

0 Kudos

I need to enhance the program to get Invoice related information for selected sales orders and display against each sales item Invoice Billing date and Billing qty .

please correct the code. i didnt get correct invoice number.

TYPE-POOLS SLIS.

TABLES : VBAP , VBRK , VBFA.


TYPES : BEGIN OF TY_VBAP,
VBELN TYPE VBAP-VBELN,
KWMENG TYPE VBAP-KWMENG,
FKDAT TYPE VBRK-FKDAT,
VBELV TYPE VBELN_VON,
VBTYP_N TYPE VBTYP_N,
END OF TY_VBAP.



DATA : IT_VBAP TYPE TABLE OF TY_VBAP .
DATA : WA_VBAP TYPE TY_VBAP .

DATA : IT_FCAT TYPE SLIS_T_FIELDCAT_ALV .
DATA : WA_FCAT LIKE LINE OF IT_FCAT .


SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS : SO_VBELN FOR VBAP-VBELN.
SELECTION-SCREEN END OF BLOCK B1.




START-OF-SELECTION.

WA_FCAT-COL_POS = '1' .
WA_FCAT-FIELDNAME = 'VBELN' .
WA_FCAT-TABNAME = 'IT_VBAP' .
WA_FCAT-SELTEXT_M = 'Sales Order' .
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_FCAT .


WA_FCAT-COL_POS = '2' .
WA_FCAT-FIELDNAME = 'KWMENG' .
WA_FCAT-TABNAME = 'IT_VBAP' .
WA_FCAT-SELTEXT_M = 'Billing Quantity' .
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_FCAT .


WA_FCAT-COL_POS = '3' .
WA_FCAT-FIELDNAME = 'FKDAT' .
WA_FCAT-TABNAME = 'IT_VBAP' .
WA_FCAT-SELTEXT_M = 'Billing Date' .
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_FCAT .

WA_FCAT-COL_POS = '4' .
WA_FCAT-FIELDNAME = 'VBELV' .
WA_FCAT-TABNAME = 'IT_VBAP' .
WA_FCAT-SELTEXT_M = 'INVOICE NUMBER' .
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_FCAT .


PERFORM GET_DATA.
PERFORM DISPLAY_DATA.
FORM GET_DATA .


SELECT A~VBELN
A~KWMENG
B~FKDAT
C~VBELV
C~VBELN


FROM VBRK AS B INNER JOIN VBFA AS C ON B~VBELN = C~VBELN
INNER JOIN VBAP AS A ON A~VBELN = C~VBELV
INTO TABLE IT_VBAP
WHERE A~VBELN IN SO_VBELN AND
C~VBELV = A~VBELN AND
VBTYP_N = 'M'.


ENDFORM.



FORM DISPLAY_DATA .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IT_FIELDCAT = IT_FCAT
TABLES
T_OUTTAB = IT_VBAP.



ENDFORM.

2 REPLIES 2

Jelena
Active Contributor
0 Kudos

There are many things to be improved in the program.

1) Procedural development (using FORM / PERFORM) is no longer recommended and instead we should use objects. See Clean ABAP.

2) REUSE_ALV... function modules should no longer be used either (unless you're writing this code in a very old system). Instead, we can use SALV or SALV with IDA in HANA systems.

3) Don't use unreadable aliases (AS A) in SELECT. We can simply refer to the table names (VBRK~.... VBRP~...), aliases needed when we are JOINing the same table more then once or when the table name is too long / ambiguous. I had trouble understanding SELECT statement in this code and it seems it created more confusion for yourself as well.

I think you have wrong criteria in SELECT, see if you can spot the problem easier after it's rewritten to be more clear:

SELECT VBAP~VBELN
VBAP~KWMENG
VBRK~FKDAT
VBFA~VBELV
VBFA~VBELN
FROM VBRK JOIN VBFA ON VBRK~VBELN = VBFA~VBELN
JOIN VBAP ON VBAP~VBELN = VBFA~VBELV
INTO TABLE IT_VBAP
WHERE VBAP~VBELN IN SO_VBELN AND
VBFA~VBELV = VBAP~VBELN AND
VBFA~VBTYP_N = 'M'.

If you have a problem with JOINs, a good idea is to separate them into separate SELECTs and see which part is off. But in this case I think if you analyze the data vs selection criteria, you'll spot an error easily.

Edit: 4) The functional design of this program is wrong though. VBFA table is at line item level, so you need to use VBRP / VBAP via VBFA and include line items (POSNR) as well.

ranjith9596
Discoverer
0 Kudos

Please try below simple steps.

  1. Pass Sales Order number to 'SD_DOCUMENT_FLOW_GET' FM to get document flow of the sales order and get the invoice number.(You will even get Return Order Details in this FM)
  2. Then pass Invoice number to 'LB_BIL_INV_OUTP_READ_PRTDATA' FM to get all the invoice related details.

This is very simple steps to get the Invoice details. Hope this will help you.

Regards,

Ranjith M R.