Skip to Content
0
Former Member
Jan 16, 2009 at 06:40 AM

Data is not coming right for few Document nos.

23 Views

Hi All,

I have a problem in my report that in 10-12 records, data not picking the values against Document Number...means from where i pick the lifnr, there a few records not showing related information...

I tell u in detail..

I pick Document Number from BSIK table, Purchasing Doc. No, with ref. to Document Number...Vendor Code with Purchasing Ref. and Vendor Name with Ref. to Vendor Code...

But in some document we have not maintain Purchasing document no. against Document Number...

So we cann't display Vendor Code and name...

This is the problem...

Now i have a link between Document Number and Vendor Code without Purchasing Document No...in BSEG table...

But what will the condition with my existing query on BSEG...please tell me....

My Code is---

REPORT  zak_form_c4 NO STANDARD PAGE HEADING LINE-SIZE 125  .

TABLES : bsik,bkpf,bseg,j_1imovend,lfa1,t001,t005u,bsak,ekko,bsis, ekkn, anla, anlc.

TYPE-POOLS : slis.

DATA : BEGIN OF itab OCCURS 0,
       belnr LIKE bsik-belnr, "Document number
       buzei LIKE bseg-buzei, "line item
       hkont LIKE bseg-hkont, "Gl account
       mwskz LIKE bseg-mwskz, "Tax Code
       dmbtr LIKE bseg-dmbtr, "Amount
       ebeln LIKE bseg-ebeln, "Purchasing Document
       ebelp LIKE bseg-ebelp, "line item nbr
       hwbas LIKE bseg-hwbas, "Base amount
       shkzg LIKE bseg-shkzg, "Debit/Credit code

       gjahr LIKE bsik-gjahr, "Fiscal Year
       bldat LIKE bsik-bldat, "Document Date
       budat LIKE bsik-budat, "Posting Date
       lifnr LIKE bsik-lifnr, "Vendor number

       xblnr LIKE mkpf-xblnr, "Ven invoice nbr

       name1(25),                                           "name1
       ort01 LIKE lfa1-ort01, "City
       j_1ilstno LIKE j_1imovend-j_1ilstno, " Vendor tin nbr

       regio LIKE lfa1-regio, "Region Code
       bezei LIKE t005u-bezei, "Region desc

       dmbtr1 LIKE bseg-dmbtr, "Amount
       hwbas1 LIKE bseg-hwbas, "Base amount
END OF itab.

DATA:
v_bldat TYPE bldat,
v_budat TYPE budat,
v_lifnr TYPE lifnr,
v_name1 TYPE name1,
v_ebeln TYPE ebeln,
v_mwskz TYPE mwskz,
v_dmbtr TYPE dmbtr,
v_hwbas TYPE hwbas,
v_xblnr TYPE xblnr.

DATA : BEGIN OF itab1 OCCURS 0.
        INCLUDE STRUCTURE itab.
DATA:END OF itab1.

DATA : BEGIN OF itab2 OCCURS 0.
        INCLUDE STRUCTURE itab.
DATA : END OF itab2.

DATA : itab3 LIKE STANDARD TABLE OF itab2 WITH HEADER LINE.

***********************************Purchase order history
DATA:   BEGIN OF bet OCCURS 50.
        INCLUDE STRUCTURE ekbe.
DATA:   END OF bet.
DATA:   BEGIN OF bzt OCCURS 50.
        INCLUDE STRUCTURE ekbz.
DATA:   END OF bzt.
DATA:   BEGIN OF betz OCCURS 50.
        INCLUDE STRUCTURE ekbez.
DATA:   END OF betz.
DATA:   BEGIN OF bets OCCURS 50.
        INCLUDE STRUCTURE ekbes.
DATA:   END OF bets.
DATA:   BEGIN OF xekbnk OCCURS 10.
        INCLUDE STRUCTURE ekbnk.
DATA:   END OF xekbnk.


************************************************************************
DATA : w_container TYPE scrfname VALUE 'CL_GRID',
       w_cprog TYPE lvc_s_layo,
       g_repid LIKE sy-repid,
       w_save TYPE c,
       w_exit TYPE c,
       cl_grid TYPE REF TO cl_gui_alv_grid,
       cl_custom_container TYPE REF TO cl_gui_custom_container,
       it_fld_catalog TYPE slis_t_fieldcat_alv,
       wa_fld_catalog TYPE slis_t_fieldcat_alv WITH HEADER LINE ,
       layout TYPE slis_layout_alv,
       col_pos  LIKE sy-cucol ,
       alvfc TYPE slis_t_fieldcat_alv.

************************************************************************

SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS       :  hkont LIKE bseg-hkont OBLIGATORY. "GL Code

*SELECT-OPTIONS   : hkont FOR bseg-hkont .
SELECT-OPTIONS   : belnr FOR bsik-belnr .
SELECT-OPTIONS   : gjahr FOR bsik-gjahr .
SELECT-OPTIONS   : bldat FOR bsik-bldat.
SELECT-OPTIONS   : budat FOR bsik-budat.
SELECTION-SCREEN : END OF BLOCK b1.

************************************************************************
PERFORM fill_catalog1 USING:

'HKONT'    'ITAB2'    'G/L Code' ,
'BELNR'    'ITAB2'    'Document Number',
'GJAHR'    'ITAB2'    'Year',
'BLDAT'    'ITAB2'    'Doc. date' ,
'BUDAT'    'ITAB2'    'Posting Date',
'LIFNR'    'ITAB2'    'Vendor',
'NAME1'    'ITAB2'    'Name',
'EBELN'    'ITAB2'    'Purchasing Document',
'MWSKZ'    'ITAB2'    'Tax Code',
'HWBAS'    'ITAB2'    'Base Amount',
'DMBTR'    'ITAB2'    'Tax Amount',
'XBLNR'    'ITAB2'    'Vendor Inv. No.'.

*********************************************************************************************

SELECT DISTINCT hkont belnr gjahr bldat budat INTO CORRESPONDING FIELDS OF TABLE itab
                  FROM bsis
                  WHERE bukrs = '1000'
                  AND hkont = hkont
                  AND belnr IN belnr
                  AND gjahr IN gjahr
                  AND bldat IN bldat
                  AND budat IN budat.

SORT itab BY belnr.

LOOP AT itab.


  SELECT * FROM bseg WHERE belnr = itab-belnr AND gjahr = itab-gjahr
                                               AND bukrs = '1000'
                                               AND ( ebeln <> ' ' OR hkont = hkont ).

    IF sy-subrc = 0.
      itab-buzei = bseg-buzei.
      itab-mwskz = bseg-mwskz.
      IF bseg-ebeln <> ' '.
        itab-ebeln = bseg-ebeln.
        itab-ebelp = bseg-ebelp.
        MODIFY itab.
      ENDIF.

      IF bseg-hkont = hkont.
        itab-shkzg = bseg-shkzg.
        itab-hwbas = bseg-hwbas.
        itab-dmbtr = bseg-dmbtr.
*
        IF itab-shkzg = 'H'.
          itab-dmbtr = itab-dmbtr * ( -1 ).
        ENDIF.
*
        MOVE-CORRESPONDING itab TO itab2.
        APPEND itab2.
      ENDIF.
    ENDIF.
  ENDSELECT.
ENDLOOP.

LOOP AT itab2.

  SELECT SINGLE * FROM ekko WHERE ebeln = itab2-ebeln.
  IF sy-subrc = 0.
    itab2-lifnr = ekko-lifnr.
  ENDIF.

  CALL FUNCTION 'ME_READ_HISTORY'
    EXPORTING
      ebeln  = itab2-ebeln
      ebelp  = itab2-ebelp
      webre  = 'X'
    TABLES
      xekbe  = bet
      xekbz  = bzt
      xekbes = bets
      xekbez = betz
      xekbnk = xekbnk.

  itab2-xblnr = bet-xblnr.

  SELECT SINGLE * FROM lfa1 WHERE lifnr = itab2-lifnr.

  itab2-name1 = lfa1-name1.
  itab2-ort01 = lfa1-ort01.
  itab2-regio = lfa1-regio.

  SELECT SINGLE * FROM t005u WHERE bland = itab2-regio
                              AND spras = 'EN'
                              AND land1 = 'IN'.

  itab2-bezei = t005u-bezei.

  SELECT SINGLE * FROM  j_1imovend WHERE lifnr = itab2-lifnr.

  IF sy-subrc = 0 .
    itab2-j_1ilstno = j_1imovend-j_1ilstno.  " Vendor tin nbr
  ENDIF.

  MODIFY itab2.
ENDLOOP.

SORT itab2 BY belnr.

LOOP AT itab2.
  v_dmbtr = v_dmbtr + itab2-dmbtr.
  v_hwbas = v_hwbas + itab2-hwbas.
  v_bldat = itab2-bldat.
  v_budat = itab2-budat.
  v_lifnr = itab2-lifnr.
  v_name1 = itab2-name1.
  v_ebeln = itab2-ebeln.
  v_mwskz = itab2-mwskz.
  v_xblnr = itab2-xblnr.

  AT END OF belnr.
    itab2-bldat = v_bldat.
    itab2-budat = v_budat.
    itab2-lifnr = v_lifnr.
    itab2-name1 = v_name1.
    itab2-ebeln = v_ebeln.
    itab2-mwskz = v_mwskz.
    itab2-dmbtr = v_dmbtr.
    itab2-hwbas = v_hwbas.
    itab2-xblnr = v_xblnr.

    APPEND itab2 TO itab3.
    CLEAR: itab2, v_dmbtr, v_hwbas, v_bldat, v_budat, v_lifnr, v_name1, v_ebeln, v_mwskz, v_xblnr.
  ENDAT.

ENDLOOP.

************************************************************************************
layout-zebra = 'X' .
layout-colwidth_optimize(1) = 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    i_callback_program = 'ZAK_FORM_C4'
    is_layout          = layout
    it_fieldcat        = it_fld_catalog
    i_default          = 'X'
    i_save             = 'A'
  TABLES
    t_outtab           = itab3
  EXCEPTIONS
    program_error      = 1
    OTHERS             = 2.
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

*&---------------------------------------------------------------------*
*&      Form  FILL_CATALOG1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_FIELDNAME  text
*      -->P_REF_TABLE  text
*      -->P_SCRTEXT    text
*----------------------------------------------------------------------*
FORM fill_catalog1  USING   p_fieldname TYPE any
                            p_ref_table TYPE any
                            p_scrtext   TYPE any.
  CLEAR : wa_fld_catalog.
  wa_fld_catalog-fieldname  = p_fieldname.
  wa_fld_catalog-tabname    = p_ref_table.
  wa_fld_catalog-seltext_s  = p_scrtext.
  wa_fld_catalog-seltext_m  = p_scrtext.
  wa_fld_catalog-seltext_l  = p_scrtext.
*  wa_fld_catalog-datatype = 'CURR'.
  wa_fld_catalog-outputlen = 20.

  APPEND wa_fld_catalog TO it_fld_catalog.

ENDFORM.                    " fill_catalog1.

Plz help....

Edited by: Prince Kumar on Jan 16, 2009 12:29 PM

Edited by: Vijay Babu Dudla on Jan 16, 2009 4:27 AM