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: 

ABAP Code to Select Invoices from VBRP

former_member355038
Participant
0 Kudos

Hi

I have the following code to summrise the invoice total by

 

Z_VBRP_NETWR_TOT =

IF Z_VBRP = 'X'.
select sum( NETWR ) sum( FKIMG ) from VBRP
into (Z_VBRP_NETWR_TOT, Z_VBRP_FKIMG_TOT)
where
AUBEL = VBAP-VBELN
and
AUPOS = VBAP-POSNR
and
SHKZG = ' '.

ENDIF.

The problem I have is when a proforma invoice and normal invoice is issued then the values are doubled, we just want to report on 1 invoice and not both, I checked the VBRK table and the difference between the 2 is field VGTYP. Therefore I added in the a AND statement before the ENDIF statement : and VGTYP = ‘J’.

This is ok when there are 2 invoices eg field VGTYP = "C" or "J" but when there is only 1 type "C" I want the program to sum all the as per the above code, is there ELSE statement I should use?

thanks

Joe

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Joe,

Through the field VGTYP, you can control the outcome behavior.

So for your requirement, add field VGTYP = 'C' in your WHERE condition of your SELECT statement.

So your SELECT statement,

select sum( NETWR ) sum( FKIMG ) from VBRP

into (Z_VBRP_NETWR_TOT, Z_VBRP_FKIMG_TOT)

where

AUBEL = VBAP-VBELN

and

AUPOS = VBAP-POSNR

and

SHKZG = ' '

AND

VGTYP EQ 'C'.

This is what i have understood your requirement.

With Regards

Syed

5 REPLIES 5

Former Member
0 Kudos

Hi Joe,

Through the field VGTYP, you can control the outcome behavior.

So for your requirement, add field VGTYP = 'C' in your WHERE condition of your SELECT statement.

So your SELECT statement,

select sum( NETWR ) sum( FKIMG ) from VBRP

into (Z_VBRP_NETWR_TOT, Z_VBRP_FKIMG_TOT)

where

AUBEL = VBAP-VBELN

and

AUPOS = VBAP-POSNR

and

SHKZG = ' '

AND

VGTYP EQ 'C'.

This is what i have understood your requirement.

With Regards

Syed

0 Kudos

Hi Syed,

Thanks for the response, I have added the statement:

AND

VGTYP EQ 'C'.

But there are 2 cases which need to be covered:

1. Where there are 2 lines for the same order 1 has VGTYP 'C' and 'J' in this case the 'C' should be summed and the other one ignored.

2.  Where there is only 1 line for the order 1  and the VGTYP = 'J' and this should be summed.

How do I code for both cases?

thanks

Joe

Former Member
0 Kudos

Hi Joe,

try to do the following steps:

*1 First of all define a internal table and structure with the following four fields:

TYPES: BEGIN OF TYPE TY_INV_DAT,

               AUBEL TYPE VBRP-AUBEL,

               AUPOS TYPE VBRP-AUPOS,

               NETWR TYPE VBRP-NETWR,

               FKIMG TYPE VBRP-FKIMG

             END OF TYPE LT_INV_DATA,

          

             TY_T_INV_DAT TYPE STANDARD TABLE OF TY_INV_DAT.

DATA: LT_INV_DATA TYPE TY_T_INV_DAT,

          LS_INV_DATA TYPE TY_INV_DAT.

*2. Select and store the data in the internal table.(I think that this kind of selection will improver also the performance of your coding)

select AUBEL AUPOS NETWR  FKIMG  from VBRP

into table lt_inv_data

where  AUBEL = VBAP-VBELN

    and  AUPOS = VBAP-POSNR

    and  SHKZG = space.

if sy-subrc  = 0.

*3 proceed to delete the duplicate entries.

SORT LT_INV_DATA BY AUBEL ASCENDING AUPOS ASCENDING.

DELETE ADJACENT DUPLICATES FROM LT_INV_DATA COMPARING AUBEL AUPOS.

*  summarize table amounts/quantities.

  clear:  Z_VBRP_NETWR_TOT, Z_VBRP_FKIMG_TOT.

  loop at lt_inv_data into ls_inv_data.

   add ls_inv_data-NETWR to Z_VBRP_NETWR_TOT.

   add ls_inv_data-FKIMG to Z_VBRP_FKIMG_TOT.

  endloop.

endif.

Regards,

Marc.

raymond_giuseppi
Active Contributor
0 Kudos

Try to use table VBFA with selection thru (JOIN allowed)

  • SELECT FROM vbfa WHERE vbtyp_n = 'M' AND vbelv = ...
  • SELECT FROM vbrp WHERE vbeln = vbfa-vbeln AND posnr = vbfa-posnn

Regards,

Raymond

0 Kudos

Hi Raymond,

Using table VBFA sounds perfect but where in the current code would I add in your 2 lines?

Current code:

Z_VBRP_NETWR_TOT =

IF Z_VBRP = 'X'.
select sum( NETWR ) sum( FKIMG ) from VBRP
into (Z_VBRP_NETWR_TOT, Z_VBRP_FKIMG_TOT)
where
AUBEL = VBAP-VBELN
and
AUPOS = VBAP-POSNR
and
SHKZG = ' '.

ENDIF.