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: 

FI_ReportDevelopment

Nawazuddin
Explorer
0 Kudos

Dear Experts,

I developed this repot,but in output the all debit and credit values or not comming in standard table of sap BSEG it is showing all values can any body help me how to get all regards.

Thaks is advance.

*&---------------------------------------------------------------------*
*& Report  ZSTMTCUST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

report  zstmtcust no standard page heading
line-size 130.

tables : bkpf,bseg.

types : begin of ty_final,
        bukrs type bkpf-bukrs,
        belnr type bkpf-belnr,
        gjahr type bkpf-gjahr,
        blart type bkpf-blart,
        budat type bkpf-budat,
*       WAERS TYPE BKPF-WAERS,
        buzei type bseg-buzei,
        shkzg type bseg-shkzg,
        kunnr type bseg-kunnr,
        sgtxt type bseg-sgtxt,
        zuonr type bseg-zuonr,
        dmbtr type bseg-dmbtr,
*       dmbtr_h type bseg-dmbtr,
        name1 type kna1-name1,
        stras type kna1-stras,
        land1 type kna1-land1,
        ort01 type kna1-ort01,
        ltext type t003t-ltext,
        end of ty_final.


   types : begin of ty_bkpf,
           bukrs type bkpf-bukrs,
           belnr type bkpf-belnr,
           gjahr type bkpf-gjahr,
           blart type bkpf-blart,
           budat type bkpf-budat,
           waers type bkpf-waers,
           end of ty_bkpf.


   types : begin of ty_bseg,
           bukrs type bseg-bukrs,
           belnr type bseg-belnr,
           buzei type bseg-buzei,
           shkzg type bseg-shkzg,
           kunnr type bseg-kunnr,
           sgtxt type bseg-sgtxt,
           zuonr type bseg-zuonr,
           dmbtr type bseg-dmbtr,
           end of ty_bseg.

types : begin of ty_kna1,
        kunnr type kna1-kunnr,
        name1 type kna1-name1,
        stras type kna1-stras,
        land1 type kna1-land1,
        ort01 type kna1-ort01,
        end of ty_kna1.

types : begin of ty_t003t,
       blart type t003t-blart,
       ltext type t003t-ltext,
       end of ty_t003t.

types : begin of ty_bsis,
        belnr type bsis-belnr,
        pswbt type bsis-pswbt,
        end of ty_bsis.


   data : t_bkpf type standard table of ty_bkpf initial size 1,
          w_bkpf type ty_bkpf.

   data : t_bseg type standard table of ty_bseg initial size 1,
          w_bseg type ty_bseg.

   data : t_final type standard table of ty_final initial size 1,
           w_final type ty_final.

  data : t_kna1 type standard table of ty_kna1 initial size 1,
         w_kna1 type ty_kna1.

data : t_t003t type standard table of ty_t003t initial size 1,
         w_t003t type ty_t003t.


data : t_bsis type standard table of ty_bsis initial size 1,
         w_bsis type ty_bsis.



  data : bal   type p decimals 2,
         opbal type p decimals 2,
         db    type p decimals 2,
         cr    type p decimals 2.
         bal   = 0.
         opbal = 0.
         db    = 0.
         cr    = 0.

select-options :    ccode  for bkpf-bukrs default '0002',
*                    DOCNO  FOR BKPF-BELNR,
                    year   for bkpf-gjahr default '2009',
                    custno for bseg-kunnr default 'c-00049',
                    posdt  for bkpf-budat.

select bukrs
       belnr
       gjahr
       blart
       budat
       waers
       from bkpf into table t_bkpf
       where bukrs  in  ccode
*       AND BELNR IN DOCNO
       and gjahr in year
       and budat in posdt
       and waers = 'SAR'
       and bldat in posdt.

check t_bkpf is not initial.
 select   bukrs
          belnr
          buzei
          shkzg
          sgtxt
          zuonr
          kunnr
          dmbtr
          from bseg into table t_bseg
          for all entries in  t_bkpf
          where  bukrs = t_bkpf-bukrs
          and BELNR = T_BKPF-BELNR
          and kunnr in custno.

check t_bseg is not initial.
select kunnr
       name1
       stras
       land1
       ort01
       from
       kna1
       into table t_kna1
       for all entries in t_bseg
       where kunnr = t_bseg-kunnr.

check t_bseg is not initial.
 select blart
        ltext
        from
        t003t
        into table t_t003t
        for all entries in t_bkpf
        where blart = t_bkpf-blart
        and spras = 'E'.

*check t_bkpf is not initial.
*       select  belnr
*               dmbtr
*               from
*               bsis
*               into table t_bsis
*               for all entries in t_bkpf
*               where belnr = t_bkpf-belnr.

loop at t_bkpf into w_bkpf.
read table t_bseg into w_bseg with key belnr = w_bkpf-belnr.
read table t_kna1 into w_kna1 with key kunnr = w_bseg-kunnr.
read table t_t003t into w_t003t with key  blart = w_bkpf-blart.

w_final-bukrs = w_bkpf-bukrs.
w_final-belnr = w_bkpf-belnr.
*w_final-blart = w_bkpf-blart.
w_final-budat = w_bkpf-budat.
*W_FINAL-WAERS = W_BKPF-WAERS.
w_final-shkzg = w_bseg-shkzg.
w_final-buzei = w_bseg-buzei.
w_final-kunnr = w_bseg-kunnr.
w_final-sgtxt = w_bseg-sgtxt.
w_final-zuonr = w_bseg-zuonr.
w_final-dmbtr = w_bseg-dmbtr  / 1000.
*W_FINAL-dmbtr_h = W_bseg-dmbtr  / 1000.
w_final-name1 = w_kna1-name1.
w_final-stras = w_kna1-stras.
w_final-land1 = w_kna1-land1.
w_final-ort01 = w_kna1-ort01.
w_final-ltext = w_t003t-ltext.
append w_final to t_final.
delete adjacent duplicates from t_final comparing dmbtr.
endloop.
clear w_final.
*lOOP AT T_FINAL INTO W_FINAL.
*   if w_final-SHKZG  eq 'S'.
*       db = w_final-dmbtr.
*  elseif w_final-SHKZG eq  'H'.
*      cr = w_final-dmbtr.
*     endif.
*endloop.
*clear w_final.

sort by t_final.

loop at t_final into w_final.

 if w_final-shkzg eq 'S'." and w_final-buzei eq 002.
 if sy-subrc = 0.
    db  =  w_final-dmbtr." + w_bseg-dmbtr.
    bal =  bal + db.

         write : /05 w_final-zuonr,
                  20 w_final-ltext,
                  45 w_final-budat,
                  58 w_final-belnr,
                  70 w_final-sgtxt,
                  95 db.
 endif.
 endif.
 if w_final-shkzg  eq 'H'." and w_final-buzei eq 001.
 if sy-subrc = 0.
    cr =  w_final-dmbtr." + w_bseg-dmbtr.
         write : /05 w_final-zuonr,
                  20 w_final-ltext,
                  45 w_final-budat,
                  58 w_final-belnr,
                  70 w_final-sgtxt,
                  110 cr.
 endif.
 endif.
*endif.
*        AT last.
*        SUM.
*        uline /100(20).
*        WRITE: /85 'TOTAL:',100 bal.
*        uline /100(20).
*        ENDAT.
endloop.
clear w_final.

top-of-page.
      write : 40  'CUSTOMER STATEMENTS'.
      uline /40(25).
      write :/05 'CoCode      :',ccode-low.
      write :/05 'Customer No :',custno-low, 'To:', custno-high,
              30 'Customer Name :',w_final-name1,
             /30 'Street        :',w_final-stras,
             /30 'City          :',w_final-ort01,w_final-land1.

      write :/05 'Postingdate :',posdt-low, 'To:', posdt-high.
      uline.

      write : /05 'AsstNumber',
               20 'DocumentType',
               45 'PostingDATE',
               58 'DOCUMENTNO',
               70 'Description',
*               60
*               80 'CUSTNO',
*               90 'CURRANCY',
               107 'AMOUNT'.
               uline /02(120).

Edited by: Julius Bussche on Jan 19, 2009 11:34 AM

Please use meaningfull subject titles and code tags

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

It's not clear what u need to print, anyway u should consider in BSEG-DMBTR is the amount in local currency and BSEG-WRBTR is the amount in document currency: I suppose u need to get the value of WRBTR.

A document could be several customer items, so u should use a LOOP instead of READ statament in order to get BSEG data:

Loop at t_bkpf into w_bkpf.
*read table t_bseg into w_bseg with key belnr = w_bkpf-belnr.
  read table t_t003t into w_t003t with key  blart = w_bkpf-blart.
  LOOP AT T_BSEG WHERE BUKRS = W_BKPF-BUKRS
                                    AND BELNR = W_BKPF-BELNR
                                    AND GJAHR = W_BKPF-GJAHR.

       read table t_kna1 into w_kna1 with key kunnr = w_bseg-kunnr.

U should considere the sign of the amount:

IF T_BSEG-SHKZG = 'H'.
   T_BSEG-WRBTR = - T_BSEG-WRBTR.
ENDIF.

Max

4 REPLIES 4

Former Member
0 Kudos

Hi

It's not clear what u need to print, anyway u should consider in BSEG-DMBTR is the amount in local currency and BSEG-WRBTR is the amount in document currency: I suppose u need to get the value of WRBTR.

A document could be several customer items, so u should use a LOOP instead of READ statament in order to get BSEG data:

Loop at t_bkpf into w_bkpf.
*read table t_bseg into w_bseg with key belnr = w_bkpf-belnr.
  read table t_t003t into w_t003t with key  blart = w_bkpf-blart.
  LOOP AT T_BSEG WHERE BUKRS = W_BKPF-BUKRS
                                    AND BELNR = W_BKPF-BELNR
                                    AND GJAHR = W_BKPF-GJAHR.

       read table t_kna1 into w_kna1 with key kunnr = w_bseg-kunnr.

U should considere the sign of the amount:

IF T_BSEG-SHKZG = 'H'.
   T_BSEG-WRBTR = - T_BSEG-WRBTR.
ENDIF.

Max

0 Kudos

Dear Max,

Actully i need to print all the debit and credit values in my report as per s_alr_87012240 statement for customer report showing 6 credit values and 4 debit values but in my report only one debit values and 4 credit values comming this is my problem. i need to develop report for statement for customers.

Thanks.

Mohammed.

0 Kudos

Hi

Are u using the sam posting period for both query (your report and the std trx s_alr_87012240)?

Your select should be:

* Get header data
select bukrs belnr gjahr blart budat waers
    from bkpf into table t_bkpf
       where bukrs  in  ccode
       and gjahr in year
       and budat in posdt.
* Get item data 
check t_bkpf is not initial.
 select   bukrs belnr buzei shkzg sgtxt zuonr kunnr dmbtr
     from bseg into table t_bseg
        for all entries in  t_bkpf
          where bukrs     = t_bkpf-bukrs
             and BELNR  = T_BKPF-BELNR
             AND GJAHR = T_BKPF-GJAHR
             AND KOART = 'D'
             and kunnr in custno.

Max

Edited by: max bianchi on Jan 19, 2009 12:34 PM

Former Member
0 Kudos

Hi,

First check following

1. Whether ur selection statement fetch all the values based on ur requirements or not?

2. Has ur internal table all the records before displaying it.

Thanks.