What is aging report or aging query

hi
  i am suresh,
        what is aging report or aging query.
        can any one tell.

Hello Suresh,
Based on the business requirements you design the inventory aging report. Here are few scenarios:
1) Technical Name: 0IC_C03_Q0021
Use
This query displays the inventory aging for selected materials per week and calendar year, and is used in the KPI monitor.
2) Technical Name: 0IC_C01_Q0009
Use
The percentage of total gross inventory (based on value) covered by expected demand within a specific time bucket.
3)
With this picking strategy the system proposes the oldest quant in the storage type as the quant that should be transferred.
The system generally calculates the "age" (length of time in storage) of a quant on the basis of the goods receipt posting date from the Inventory Management (IM) application component. The system automatically sets the goods receipt date in the quant and in the transfer requirement for every goods receipt posting in IM. When the transfer order is created, this date is copied over to the quant record of the destination storage bin.
You can accept the goods receipt date that the system sets or you can enter a different date. Regardless of whether the system proposes the goods receipt date or you enter a different date, the date is used to calculate the age of the quant. This date influences the sorting sequence for each material.
Prerequisites
When you define the storage type record to use this strategy, enter f in the Picking strategy field.
you can find more details in Help.sap.com which fields needs to used etc.
Hope this helps,
Bye,
Naga.
Message was edited by: Naga Timmaraju

Similar Messages

  • Vendor aging report ,customer aging report

    hi to all
    can u pls what is vendor aging report . what is the purpose of it . can u pls some theoritical description
    i will definitely reward points pls its urgent  pls tell if there r any standard reports exists for theese . pls give some custom reports on theese  with coding.
      and for customer aging also
    pls.................

    Hi,
    Check the Vendor against report code:
    REPORT zvender_os NO STANDARD PAGE HEADING
    LINE-SIZE 132
    LINE-COUNT 65.
    Tables
    TABLES: bsik, "open items (A/C: Secondary Index for Customers)
    lfa1, "customer master
    lfb1,
    rf140, "temp stru (Work Fields for Corrence(SAPF140*))
    bsak, "cleared items (A/c Secnd Index for Cust(Clrms))
    skat.
    constants and variables
    TYPE-POOLS: slis.
    DATA: fieldcat TYPE slis_t_fieldcat_alv,
    fieldcat1 TYPE slis_t_fieldcat_alv,
    fieldcat_ln TYPE slis_fieldcat_alv,
    layout_in TYPE slis_layout_alv,
    layout_in1 TYPE slis_layout_alv,
    sortcat TYPE slis_t_sortinfo_alv,
    sortcat1 TYPE slis_t_sortinfo_alv,
    sortcat_ln LIKE LINE OF sortcat,
    eventcat1 TYPE slis_t_event,
    eventcat TYPE slis_t_event,
    eventcat_ln LIKE LINE OF eventcat,
    col_pos TYPE i.
    DATA: targ_month(2) TYPE n, "0001
    targ_year(4) TYPE n, "0001
    targ_mth_abs TYPE p, "0001
    doc_month(2) TYPE n, "0001
    doc_year(4) TYPE n, "0001
    doc_mth_abs TYPE p, "0001
    mth_result TYPE p, "0001
    doc_days TYPE p,
    targ_days TYPE p,
    addl_days TYPE p,
    ext_days TYPE p,
    v_days(3) TYPE c,
    v_kkber LIKE knkk-kkber.
    DATA:
    BEGIN OF inrec OCCURS 1000, "0001
    lifnr LIKE bsik-lifnr,
    belnr LIKE bsik-belnr,
    gjahr LIKE bsik-gjahr,
    bldat LIKE bsik-bldat,
    xblnr LIKE bsik-xblnr,
    blart LIKE bsik-blart,
    sgtxt LIKE bsik-sgtxt,
    shkzg LIKE bsik-shkzg,
    dmbtr LIKE bsik-dmbtr,
    zfbdt LIKE bsik-zfbdt,
    zbd1t LIKE bsik-zbd1t,
    zbd2t LIKE bsik-zbd2t,
    zbd3t LIKE bsik-zbd3t,
    zuonr LIKE bsik-zuonr,
    END OF inrec.
    DATA:
    BEGIN OF inrect OCCURS 1000, "0001
    lifnr LIKE bsik-lifnr,
    belnr LIKE bsik-belnr,
    gjahr LIKE bsik-gjahr,
    bldat LIKE bsik-bldat,
    xblnr LIKE bsik-xblnr,
    blart LIKE bsik-blart,
    sgtxt LIKE bsik-sgtxt,
    shkzg LIKE bsik-shkzg,
    dmbtr LIKE bsik-dmbtr,
    zfbdt LIKE bsik-zfbdt,
    zbd1t LIKE bsik-zbd1t,
    zbd2t LIKE bsik-zbd2t,
    zbd3t LIKE bsik-zbd3t,
    zuonr LIKE bsik-zuonr,
    END OF inrect,
    BEGIN OF t_item OCCURS 1000, " 0001
    lifnr LIKE bsik-lifnr,
    belnr LIKE bsik-belnr,
    gjahr LIKE bsik-gjahr,
    bldat LIKE bsik-bldat,
    xblnr LIKE bsik-xblnr,
    blart LIKE bsik-blart,
    sgtxt LIKE bsik-sgtxt,
    zfbdt LIKE bsik-zfbdt,
    dmbtr LIKE bsik-dmbtr,
    days(3) TYPE c,
    zuonr LIKE bsik-zuonr,
    END OF t_item,
    t_line LIKE t_item OCCURS 1000 WITH HEADER LINE, " 0001
    BEGIN OF itab OCCURS 1000,
    lifnr LIKE lfa1-lifnr,
    total LIKE bsik-dmbtr,
    zfuture LIKE bsik-dmbtr,
    zcurrent LIKE bsik-dmbtr,
    crbal LIKE bsik-dmbtr,
    30days LIKE bsik-dmbtr,
    60days LIKE bsik-dmbtr,
    90days LIKE bsik-dmbtr,
    99days LIKE bsik-dmbtr,
    120days LIKE bsik-dmbtr,
    180days LIKE bsik-dmbtr,
    365days LIKE bsik-dmbtr,
    bzirk LIKE knvv-bzirk,
    vkbur LIKE knvv-vkbur,
    vwerk LIKE knvv-vwerk,
    vkgrp LIKE knvv-vkgrp,
    klimk LIKE knkk-klimk,
    cashd LIKE knkk-cashd,
    grupp LIKE knkk-grupp,
    erdat LIKE lfa1-erdat,
    name1 LIKE lfa1-name1,
    name2 LIKE lfa1-name2,
    stras LIKE lfa1-stras,
    ort01 LIKE lfa1-ort01,
    telf1 LIKE lfa1-telf1,
    psort(10),
    sperr LIKE lfa1-sperr,
    totsal LIKE bsik-dmbtr,
    txt50 LIKE skat-txt50,
    gsber LIKE bsik-gsber,
    END OF itab.
    DATA: sel_tab TYPE TABLE OF rsparams WITH HEADER LINE,
    p_debit(1) TYPE c,
    p_credit(1) TYPE c.
    DATA: t_variant LIKE disvariant OCCURS 0 WITH HEADER LINE.
    parameters and select-options
    SELECTION-SCREEN BEGIN OF BLOCK blck0 WITH FRAME TITLE text-002.
    PARAMETERS: stida LIKE sy-datum DEFAULT sy-datum OBLIGATORY,
    p_bukrs LIKE t001-bukrs DEFAULT 'PIIL' MEMORY ID buk
    OBLIGATORY.
    P_BUKRS LIKE T001-BUKRS DEFAULT 'CC01' OBLIGATORY. "0003
    SELECT-OPTIONS: s_lifnr FOR bsik-lifnr ,
    s_vkbur FOR knvv-vkbur,
    s_vkgrp FOR knvv-vkgrp,
    s_bzirk FOR knvv-bzirk,
    s_konda FOR knvv-konda,
    s_kdgrp FOR knvv-kdgrp NO-DISPLAY ,
    s_kvgr2 FOR knvv-kvgr2 NO-DISPLAY ,
    s_kkber FOR knkk-kkber NO-DISPLAY ,
    s_grupp FOR knkk-grupp NO-DISPLAY ,
    s_ctlpc FOR knkk-ctlpc,
    s_akont FOR lfb1-akont,
    s_gsber FOR bsik-gsber.
    PARAMETERS: p_future AS CHECKBOX DEFAULT 'X'.
    SELECTION-SCREEN END OF BLOCK blck0.
    SELECTION-SCREEN BEGIN OF BLOCK blck1 WITH FRAME TITLE text-002.
    PARAMETERS: p_abs RADIOBUTTON GROUP zrad,
    p_due RADIOBUTTON GROUP zrad DEFAULT 'X'.
    SELECTION-SCREEN END OF BLOCK blck1.
    *SELECTION-SCREEN BEGIN OF BLOCK blck2 WITH FRAME TITLE text-003.
    *PARAMETERS: c_run RADIOBUTTON GROUP zrac DEFAULT 'X',
    c_blk RADIOBUTTON GROUP zrac,
    c_all RADIOBUTTON GROUP zrac.
    *SELECTION-SCREEN END OF BLOCK blck2.
    *SELECTION-SCREEN BEGIN OF BLOCK blck3 WITH FRAME TITLE text-004.
    *PARAMETERS: p_debit AS CHECKBOX DEFAULT 'X' ,
    p_credit AS CHECKBOX DEFAULT 'X' NO-DISPLAY,
    *selection-screen end of block blck3.
    start-of-selection.
    START-OF-SELECTION.
    PERFORM BUILD_EVENTCAT.
    p_debit = 'X'.
    p_credit = 'X'.
    PERFORM get_customer_invoices.
    filter records based on selection criteria
    PERFORM filter_records.
    END-OF-SELECTION.
    PERFORM add_sort_field.
    PERFORM modify_field.
    PERFORM write_report.
    *& Form FILTER_RECORDS
    To collect all the required data from DB and store them in
    internal table.
    --> p1 text
    <-- p2 text
    FORM filter_records.
    delete records based on selection criteria
    LOOP AT itab.
    SELECT vkbur vkgrp vwerk erdat konda kdgrp bzirk kvgr2
    INTO (itab-vkbur, itab-vkgrp, itab-vwerk, knvv-erdat,
    knvv-konda, knvv-kdgrp,itab-bzirk,knvv-kvgr2)
    FROM knvv WHERE lifnr = itab-lifnr
    ORDER BY erdat DESCENDING.
    AKS :- Not Required for PI
    CASE itab-vkbur.
    WHEN 'SA1'.
    itab-vkbur = 'SF25'.
    WHEN 'QLD1'.
    itab-vkbur = 'SF23'.
    WHEN 'WA1'.
    itab-vkbur = 'SF26'.
    ENDCASE.
    AKS.
    EXIT.
    ENDSELECT.
    IF itab-vkbur IN s_vkbur AND
    itab-vkgrp IN s_vkgrp AND
    knvv-konda IN s_konda AND
    knvv-kdgrp IN s_kdgrp AND
    itab-bzirk IN s_bzirk AND
    knvv-kvgr2 IN s_kvgr2.
    ELSE.
    DELETE itab.
    CONTINUE.
    ENDIF.
    SELECT SINGLE klimk grupp cashd
    INTO (itab-klimk, itab-grupp, itab-cashd)
    FROM knkk WHERE lifnr = itab-lifnr
    AND kkber IN s_kkber
    AND ctlpc IN s_ctlpc
    AND grupp IN s_grupp.
    IF SY-SUBRC NE 0.
    DELETE ITAB.
    CONTINUE.
    ENDIF.
    SELECT SINGLE skat~txt50
    INTO (itab-txt50)
    FROM lfb1 INNER JOIN skat
    ON lfb1akont EQ skatsaknr
    WHERE lfb1~lifnr = itab-lifnr
    AND lfb1~akont IN s_akont
    AND skat~spras EQ 'EN'.
    IF sy-subrc NE 0.
    DELETE itab.
    CONTINUE.
    ENDIF.
    SELECT SINGLE name1 name2 telf1 erdat stras ort01 sperr
    INTO (itab-name1, itab-name2, itab-telf1,
    itab-erdat, itab-stras, itab-ort01, itab-sperr )
    FROM lfa1
    WHERE lifnr = itab-lifnr
    IF sy-subrc NE 0 .
    DELETE itab.
    CONTINUE.
    ENDIF.
    AKS For Filteration of Customer base on Block Area.
    IF c_all NE 'X'.
    IF c_run EQ 'X' AND itab-sperr EQ 'X'.
    DELETE itab.
    CONTINUE.
    ELSE.
    IF c_blk EQ 'X' AND itab-sperr NE 'X'.
    DELETE itab.
    CONTINUE.
    ENDIF.
    ENDIF.
    ENDIF.
    MODIFY itab.
    ENDLOOP.
    ENDFORM. " FILTER_RECORDS
    *& Form GET_CUSTOMER_INVOICES
    text
    --> p1 text
    <-- p2 text
    FORM get_customer_invoices.
    DATA:ztotcre LIKE bsik-dmbtr.
    DATA:ztotsal LIKE bsik-dmbtr.
    DATA: fsdate LIKE sy-datum.
    DATA: l_perio(4) TYPE c.
    MOVE stida TO rf140-stida.
    MOVE rf140-stida+4(2) TO targ_month.
    MOVE rf140-stida+0(4) TO targ_year.
    MOVE rf140-stida+6(2) TO targ_days.
    targ_mth_abs = ( targ_year * 12 ) + targ_month.
    CALL FUNCTION 'ZGET_PERIOD_FROM_DATE'
    EXPORTING
    i_date = stida
    IMPORTING
    e_perio = l_perio.
    CONCATENATE l_perio '0401' INTO fsdate.
    select open items.
    IF p_due EQ 'X'.
    SELECT lifnr belnr gjahr bldat xblnr blart sgtxt " 0001
    shkzg dmbtr zfbdt zbd1t zbd2t zbd3t
    zuonr
    FROM bsik INTO TABLE inrect
    WHERE bukrs = p_bukrs
    AND budat LE stida
    AND lifnr IN s_lifnr
    AND gsber IN s_gsber
    AND umskz NE 'T'
    AND umskz NE 'F'
    AND umskz NE 'R'
    AND umskz NE 'P'
    AND umskz NE 'J'
    AND umskz NE 'L'.
    LOOP AT INREC.
    IF INREC-SHKZG = 'H'.
    INREC-DMBTR = INREC-DMBTR * -1.
    ENDIF.
    MOVE-CORRESPONDING INREC TO T_ITEM. " 0001
    PERFORM COLLECT_INVOICE USING INREC-lifnr INREC-DMBTR
    INREC-ZFBDT INREC-ZBD1T
    INREC-ZBD2T INREC-ZBD3T.
    APPEND T_ITEM.
    CLEAR T_ITEM.
    ENDLOOP.
    LOOP AT inrect.
    inrec-lifnr = inrect-lifnr.
    inrec-belnr = inrect-belnr.
    inrec-gjahr = inrect-gjahr.
    inrec-bldat = inrect-bldat.
    inrec-xblnr = inrect-xblnr.
    inrec-blart = inrect-blart.
    inrec-sgtxt = inrect-sgtxt.
    inrec-shkzg = inrect-shkzg.
    inrec-dmbtr = inrect-dmbtr.
    CALL FUNCTION 'NJ_CAL_DATE_IN_INTERVAL'
    EXPORTING
    date = inrect-zfbdt
    days = inrect-zbd1t
    months = 00
    signum = '+'
    years = 00
    IMPORTING
    calc_date = inrec-zfbdt.
    inrec-zbd1t = inrect-zbd1t.
    inrec-zbd2t = inrect-zbd2t.
    inrec-zbd3t = inrect-zbd3t.
    inrec-zuonr = inrect-zuonr.
    APPEND inrec.
    CLEAR inrec.
    ENDLOOP.
    ELSE.
    SELECT lifnr belnr gjahr bldat xblnr blart sgtxt " 0001
    shkzg dmbtr zfbdt zbd1t zbd2t zbd3t
    zuonr
    FROM bsik INTO TABLE inrec
    WHERE bukrs = p_bukrs
    AND budat LE stida
    AND lifnr IN s_lifnr
    AND gsber IN s_gsber
    AND umskz NE 'T'
    AND umskz NE 'F'
    AND umskz NE 'R'
    AND umskz NE 'P'
    AND umskz NE 'J'
    AND umskz NE 'L'.
    ENDIF.
    SORT inrec BY lifnr shkzg zfbdt .
    LOOP AT inrec.
    AT NEW lifnr.
    For Customers Credit Balance Transaction to be display in Report
    End of Credit Balance
    ztotcre = 0.
    ztotsal = 0.
    ENDAT.
    IF inrec-shkzg = 'H'.
    inrec-dmbtr = inrec-dmbtr * -1.
    ztotcre = ztotcre + inrec-dmbtr.
    ELSE.
    IF inrec-blart = 'RV'.
    IF inrec-bldat GE fsdate.
    ztotsal = ztotsal + inrec-dmbtr.
    ENDIF.
    ENDIF.
    ztotcre = ztotcre + inrec-dmbtr.
    endif.
    IF p_debit EQ 'X'.
    IF ztotcre > 0.
    MOVE-CORRESPONDING inrec TO t_item. " 0001
    PERFORM collect_invoice USING inrec-lifnr ztotcre
    inrec-zfbdt inrec-zbd1t
    inrec-zbd2t inrec-zbd3t
    ztotsal.
    APPEND t_item.
    CLEAR t_item.
    ztotcre = 0.
    ztotsal = 0.
    ENDIF.
    ENDIF.
    ENDIF.
    IF p_credit EQ 'X'.
    AT END OF lifnr.
    IF ztotcre < 0.
    MOVE-CORRESPONDING inrec TO t_item. " 0001
    PERFORM collect_invoice USING inrec-lifnr ztotcre
    inrec-zfbdt inrec-zbd1t
    inrec-zbd2t inrec-zbd3t
    ztotsal.
    APPEND t_item.
    CLEAR t_item.
    ztotcre = 0.
    ztotsal = 0.
    APPEND t_item.
    CLEAR t_item.
    ENDIF.
    ENDAT.
    ENDIF.
    ENDLOOP.
    select cleared items
    IF p_due EQ 'X'.
    REFRESH inrect. CLEAR inrect.
    SELECT lifnr belnr gjahr bldat xblnr blart sgtxt
    shkzg dmbtr zfbdt zbd1t zbd2t zbd3t
    zuonr
    FROM bsak INTO TABLE inrect
    WHERE bukrs = p_bukrs
    AND budat LE stida
    AND augdt > stida
    AND lifnr IN s_lifnr
    AND gsber IN s_gsber
    REFRESH inrec. CLEAR inrec.
    LOOP AT inrect.
    inrec-lifnr = inrect-lifnr.
    inrec-belnr = inrect-belnr.
    inrec-gjahr = inrect-gjahr.
    inrec-bldat = inrect-bldat.
    inrec-xblnr = inrect-xblnr.
    inrec-blart = inrect-blart.
    inrec-sgtxt = inrect-sgtxt.
    inrec-shkzg = inrect-shkzg.
    inrec-dmbtr = inrect-dmbtr.
    CALL FUNCTION 'NJ_CAL_DATE_IN_INTERVAL'
    EXPORTING
    date = inrect-zfbdt
    days = inrect-zbd1t
    months = 00
    signum = '+'
    years = 00
    IMPORTING
    calc_date = inrec-zfbdt.
    inrec-zbd1t = inrect-zbd1t.
    inrec-zbd2t = inrect-zbd2t.
    inrec-zbd3t = inrect-zbd3t.
    inrec-zuonr = inrect-zuonr.
    APPEND inrec.
    CLEAR inrec.
    ENDLOOP.
    ELSE.
    REFRESH inrec. CLEAR inrec.
    SELECT lifnr belnr gjahr bldat xblnr blart sgtxt
    shkzg dmbtr zfbdt zbd1t zbd2t zbd3t
    zuonr
    FROM bsak INTO TABLE inrec
    WHERE bukrs = p_bukrs
    AND budat LE stida
    AND augdt > stida
    AND lifnr IN s_lifnr
    AND gsber IN s_gsber
    ENDIF.
    SORT inrec BY lifnr shkzg zfbdt .
    LOOP AT inrec.
    AT NEW lifnr.
    ztotcre = 0.
    ztotsal = 0.
    ENDAT.
    IF inrec-shkzg = 'H'.
    inrec-dmbtr = inrec-dmbtr * -1.
    ztotcre = ztotcre + inrec-dmbtr.
    ELSE.
    IF inrec-blart = 'RV'.
    IF inrec-bldat GE fsdate.
    ztotsal = ztotsal + inrec-dmbtr.
    ENDIF.
    ENDIF.
    ztotcre = ztotcre + inrec-dmbtr.
    endif.
    IF p_debit EQ 'X'.
    IF ztotcre > 0.
    MOVE-CORRESPONDING inrec TO t_item. " 0001
    PERFORM collect_invoice USING inrec-lifnr ztotcre
    inrec-zfbdt inrec-zbd1t
    inrec-zbd2t inrec-zbd3t
    ztotsal.
    APPEND t_item.
    CLEAR t_item.
    ztotcre = 0.
    ztotsal = 0.
    ENDIF.
    ENDIF.
    ENDIF.
    IF p_credit EQ 'X'.
    AT END OF lifnr.
    IF ztotcre < 0.
    MOVE-CORRESPONDING inrec TO t_item. " 0001
    PERFORM collect_invoice USING inrec-lifnr ztotcre
    inrec-zfbdt inrec-zbd1t
    inrec-zbd2t inrec-zbd3t
    ztotsal.
    APPEND t_item.
    CLEAR t_item.
    ztotcre = 0.
    ztotsal = 0.
    APPEND t_item.
    CLEAR t_item.
    ENDIF.
    ENDAT. " 0001
    ENDIF.
    ENDLOOP.
    ENDFORM. " GET_CUSTOMER_INVOICES
    *& Form COLLECT_INVOICE
    text
    -->P_bsik_lifnr text
    -->P_bsik_DMBTR text
    -->P_bsik_ZFBDT text
    -->P_bsik_ZFBDT1 text
    -->P_bsik_ZFBDT2 text
    -->P_bsik_ZFBDT3 text
    FORM collect_invoice USING pp_lifnr
    pp_dmbtr
    pp_zfbdt
    pp_zbd1t
    pp_zbd2t
    pp_zbd3t
    pp_ztotsal.
    doc_month = pp_zfbdt+4(2).
    doc_year = pp_zfbdt+0(4).
    doc_mth_abs = ( doc_year * 12 ) + doc_month.
    mth_result = ( targ_mth_abs - doc_mth_abs ).
    logic given by Mr. Ashok Singhvi
    doc_days = pp_zfbdt+6(2).
    addl_days = ( doc_days - targ_days ).
    IF addl_days <= 0.
    ADD 1 TO mth_result.
    ENDIF.
    IF NOT pp_zbd3t IS INITIAL.
    MOVE pp_zbd3t TO ext_days.
    ELSEIF NOT pp_zbd2t IS INITIAL.
    MOVE pp_zbd2t TO ext_days.
    ELSEIF NOT pp_zbd1t IS INITIAL.
    MOVE pp_zbd1t TO ext_days.
    ELSE.
    CLEAR ext_days.
    ENDIF.
    CHECK with Andrew whether this is working or not
    if extended payment terms exist, subtract no of mths from mth_result
    IF NOT ext_days IS INITIAL.
    CASE ext_days.
    WHEN 30.
    SUBTRACT 1 FROM mth_result.
    WHEN 60.
    SUBTRACT 2 FROM mth_result.
    WHEN 90.
    SUBTRACT 3 FROM mth_result.
    WHEN 120.
    SUBTRACT 4 FROM mth_result.
    ENDCASE.
    ENDIF.
    change to key date
    IF pp_dmbtr > 0.
    IF p_future = 'X'. " 0001
    IF mth_result <= 0.
    itab-zcurrent = pp_dmbtr.
    t_item-days = 'CUR'.
    ELSEIF mth_result = 1.
    itab-30days = pp_dmbtr.
    t_item-days = '30D'.
    ELSEIF mth_result = 2.
    itab-60days = pp_dmbtr.
    t_item-days = '60D'.
    ELSEIF mth_result = 3.
    itab-90days = pp_dmbtr.
    t_item-days = '90D'.
    ELSEIF mth_result > 3 AND mth_result <= 4 .
    itab-99days = pp_dmbtr.
    t_item-days = '99D'.
    ELSEIF mth_result > 4 AND mth_result <= 6 .
    itab-120days = pp_dmbtr.
    t_item-days = '120D'.
    ELSEIF mth_result > 6 AND mth_result <= 12 .
    itab-180days = pp_dmbtr.
    t_item-days = '180D'.
    ELSEIF mth_result > 12 .
    itab-365days = pp_dmbtr.
    t_item-days = '365D'.
    ENDIF.
    ELSE.
    IF mth_result < 0.
    itab-zfuture = pp_dmbtr.
    t_item-days = 'FUT'.
    ELSEIF mth_result = 0.
    itab-zcurrent = pp_dmbtr.
    t_item-days = 'CUR'.
    ELSEIF mth_result = 1.
    itab-30days = pp_dmbtr.
    t_item-days = '30D'.
    ELSEIF mth_result = 2.
    itab-60days = pp_dmbtr.
    t_item-days = '60D'.
    ELSEIF mth_result = 3.
    itab-90days = pp_dmbtr.
    t_item-days = '90D'.
    ELSEIF mth_result > 3 AND mth_result <= 4 .
    itab-99days = pp_dmbtr.
    t_item-days = '99D'.
    ELSEIF mth_result > 4 AND mth_result <= 6 .
    itab-120days = pp_dmbtr.
    t_item-days = '120D'.
    ELSEIF mth_result > 6 AND mth_result <= 12 .
    itab-180days = pp_dmbtr.
    t_item-days = '180D'.
    ELSEIF mth_result > 12 .
    itab-365days = pp_dmbtr.
    t_item-days = '365D'.
    ENDIF.
    ENDIF. " 0001
    itab-crbal = 0.
    itab-total = pp_dmbtr.
    ELSE.
    IF p_future = 'X'. " 0001
    IF mth_result <= 0.
    itab-zcurrent = pp_dmbtr.
    t_item-days = 'CUR'.
    ELSEIF mth_result = 1.
    itab-30days = pp_dmbtr.
    t_item-days = '30D'.
    ELSEIF mth_result = 2.
    itab-60days = pp_dmbtr.
    t_item-days = '60D'.
    ELSEIF mth_result = 3.
    itab-90days = pp_dmbtr.
    t_item-days = '90D'.
    ELSEIF mth_result > 3 AND mth_result <= 4 .
    itab-99days = pp_dmbtr.
    t_item-days = '99D'.
    ELSEIF mth_result > 4 AND mth_result <= 6 .
    itab-120days = pp_dmbtr.
    t_item-days = '120D'.
    ELSEIF mth_result > 6 AND mth_result <= 12 .
    itab-180days = pp_dmbtr.
    t_item-days = '180D'.
    ELSEIF mth_result > 12 .
    itab-365days = pp_dmbtr.
    t_item-days = '365D'.
    ENDIF.
    ELSE.
    IF mth_result < 0.
    itab-zfuture = pp_dmbtr.
    t_item-days = 'FUT'.
    ELSEIF mth_result = 0.
    itab-zcurrent = pp_dmbtr.
    t_item-days = 'CUR'.
    ELSEIF mth_result = 1.
    itab-30days = pp_dmbtr.
    t_item-days = '30D'.
    ELSEIF mth_result = 2.
    itab-60days = pp_dmbtr.
    t_item-days = '60D'.
    ELSEIF mth_result = 3.
    itab-90days = pp_dmbtr.
    t_item-days = '90D'.
    ELSEIF mth_result > 3 AND mth_result <= 4 .
    itab-99days = pp_dmbtr.
    t_item-days = '99D'.
    ELSEIF mth_result > 4 AND mth_result <= 6 .
    itab-120days = pp_dmbtr.
    t_item-days = '120D'.
    ELSEIF mth_result > 6 AND mth_result <= 12 .
    itab-180days = pp_dmbtr.
    t_item-days = '180D'.
    ELSEIF mth_result > 12 .
    itab-365days = pp_dmbtr.
    t_item-days = '365D'.
    ENDIF.
    ENDIF. " 0001
    itab-total = pp_dmbtr.
    itab-crbal = 0.
    ENDIF.
    itab-lifnr = pp_lifnr.
    itab-totsal = pp_ztotsal.
    COLLECT itab.
    CLEAR itab.
    ENDFORM. " COLLECT_INVOICE
    *& Form ADD_SORT_FIELD
    text
    --> p1 text
    <-- p2 text
    FORM add_sort_field.
    DATA: l_amount(9) TYPE n.
    IF p_future = 'X'.
    LOOP AT itab.
    l_amount = 999999999.
    IF itab-365days > 0.
    l_amount = l_amount - itab-365days.
    CONCATENATE 'A' l_amount INTO itab-psort.
    ELSEIF itab-180days > 0.
    l_amount = l_amount - itab-180days.
    CONCATENATE 'B' l_amount INTO itab-psort.
    ELSEIF itab-120days > 0.
    l_amount = l_amount - itab-120days.
    CONCATENATE 'C' l_amount INTO itab-psort.
    ELSEIF itab-99days > 0.
    l_amount = l_amount - itab-99days.
    CONCATENATE 'D' l_amount INTO itab-psort.
    ELSEIF itab-90days > 0.
    l_amount = l_amount - itab-90days.
    CONCATENATE 'E' l_amount INTO itab-psort.
    ELSEIF itab-60days > 0.
    l_amount = l_amount - itab-60days.
    CONCATENATE 'F' l_amount INTO itab-psort.
    ELSEIF itab-30days > 0.
    l_amount = l_amount - itab-30days.
    CONCATENATE 'G' l_amount INTO itab-psort.
    ELSEIF itab-zcurrent > 0.
    l_amount = l_amount - itab-zcurrent.
    CONCATENATE 'H' l_amount INTO itab-psort.
    ELSEif itab-zfuture > 0.
    L_AMOUNT = L_AMOUNT - ITAB-zfuture.
    CONCATENATE 'F' L_AMOUNT INTO ITAB-PSORT.
    ELSE.
    l_amount = ABS( itab-total ).
    CONCATENATE 'I' l_amount INTO itab-psort.
    ENDIF.
    MODIFY itab.
    ENDLOOP.
    ELSE.
    LOOP AT itab.
    l_amount = 999999999.
    IF itab-365days > 0.
    l_amount = l_amount - itab-365days.
    CONCATENATE 'A' l_amount INTO itab-psort.
    ELSEIF itab-180days > 0.
    l_amount = l_amount - itab-180days.
    CONCATENATE 'B' l_amount INTO itab-psort.
    ELSEIF itab-120days > 0.
    l_amount = l_amount - itab-120days.
    CONCATENATE 'C' l_amount INTO itab-psort.
    ELSEIF itab-99days > 0.
    l_amount = l_amount - itab-99days.
    CONCATENATE 'D' l_amount INTO itab-psort.
    ELSEIF itab-90days > 0.
    l_amount = l_amount - itab-90days.
    CONCATENATE 'E' l_amount INTO itab-psort.
    ELSEIF itab-60days > 0.
    l_amount = l_amount - itab-60days.
    CONCATENATE 'F' l_amount INTO itab-psort.
    ELSEIF itab-30days > 0.
    l_amount = l_amount - itab-30days.
    CONCATENATE 'G' l_amount INTO itab-psort.
    ELSEIF itab-zcurrent > 0.
    l_amount = l_amount - itab-zcurrent.
    CONCATENATE 'H' l_amount INTO itab-psort.
    ELSEIF itab-zfuture > 0.
    l_amount = l_amount - itab-zfuture.
    CONCATENATE 'I' l_amount INTO itab-psort.
    ELSE.
    l_amount = ABS( itab-total ).
    CONCATENATE 'J' l_amount INTO itab-psort.
    ENDIF.
    MODIFY itab.
    ENDLOOP.
    ENDIF.
    ENDFORM. " ADD_SORT_FIELD
    *& Form WRITE_REPORT
    text
    --> p1 text
    <-- p2 text
    FORM write_report.
    PERFORM build_fieldcat.
    PERFORM build_sortcat.
    PERFORM build_eventcat.
    PERFORM build_layout.
    PERFORM start_list_viewer.
    ENDFORM. " WRITE_REPORT
    *& Form BUILD_FIELDCAT
    text
    --> p1 text
    <-- p2 text
    FORM build_fieldcat.
    lifnr
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'lfa1'.
    fieldcat_ln-fieldname = 'LIFNR'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-emphasize = 'C41'.
    APPEND fieldcat_ln TO fieldcat.
    Name1
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'lfa1'.
    fieldcat_ln-fieldname = 'NAME1'.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-seltext_l = 'Name'.
    APPEND fieldcat_ln TO fieldcat.
    City Details
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'lfa1'.
    fieldcat_ln-fieldname = 'ORT01'.
    fieldcat_ln-seltext_l = 'City'.
    fieldcat_ln-col_pos = col_pos.
    APPEND fieldcat_ln TO fieldcat.
    Credit Limit
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'KNKK'.
    fieldcat_ln-fieldname = 'KLIMK'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-emphasize = 'C41'.
    APPEND fieldcat_ln TO fieldcat.
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'DMBTR'.
    fieldcat_ln-fieldname = 'CRBAL'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-seltext_l = 'Cr. Bal.'.
    fieldcat_ln-seltext_m = 'Cr. Bal.'.
    fieldcat_ln-seltext_s = 'Cr. Bal.'.
    APPEND fieldcat_ln TO fieldcat.
    Total Amount
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-fieldname = 'TOTAL'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-seltext_l = 'Out.St.Amt.'.
    fieldcat_ln-seltext_m = 'Out.St.Amt.'.
    fieldcat_ln-seltext_s = 'Out.St.Amt.'.
    fieldcat_ln-ref_tabname = 'zbsik'.
    fieldcat_ln-ref_fieldname = 'ZDMBTR'.
    APPEND fieldcat_ln TO fieldcat.
    IF p_future NE 'X'.
    Future
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'DMBTR'.
    fieldcat_ln-fieldname = 'ZFUTURE'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-seltext_l = 'Future Due'.
    fieldcat_ln-seltext_m = 'Future Due'.
    fieldcat_ln-seltext_s = 'Future Due'.
    APPEND fieldcat_ln TO fieldcat.
    ENDIF.
    Current
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'DMBTR'.
    fieldcat_ln-fieldname = 'ZCURRENT'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-seltext_l = 'Normal Due'.
    fieldcat_ln-seltext_m = 'Normal Due'.
    fieldcat_ln-seltext_s = 'Normal Due'.
    APPEND fieldcat_ln TO fieldcat.
    30 Days
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'DMBTR'.
    fieldcat_ln-fieldname = '30DAYS'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-seltext_l = '0-30 Days'.
    fieldcat_ln-seltext_m = '0-30 Days'.
    fieldcat_ln-seltext_s = '0-30 Days'.
    APPEND fieldcat_ln TO fieldcat.
    60 Days
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'DMBTR'.
    fieldcat_ln-fieldname = '60DAYS'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-seltext_l = '31-60 Days'.
    fieldcat_ln-seltext_m = '31-60 Days'.
    fieldcat_ln-seltext_s = '31-60 Days'.
    APPEND fieldcat_ln TO fieldcat.
    90 Days
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'DMBTR'.
    fieldcat_ln-fieldname = '90DAYS'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-seltext_l = '61-90 Days'.
    fieldcat_ln-seltext_m = '61-90 Days'.
    fieldcat_ln-seltext_s = '61-90 Days'.
    APPEND fieldcat_ln TO fieldcat.
    99 Days
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'DMBTR'.
    fieldcat_ln-fieldname = '99DAYS'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-seltext_l = '91-120 Days'.
    fieldcat_ln-seltext_m = '91-120 Days'.
    fieldcat_ln-seltext_s = '91-120 Days'.
    APPEND fieldcat_ln TO fieldcat.
    *120Days
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'DMBTR'.
    fieldcat_ln-fieldname = '120DAYS'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-seltext_l = '121-180 Days'.
    fieldcat_ln-seltext_m = '121-180 Days'.
    fieldcat_ln-seltext_s = '121-180 Days'.
    APPEND fieldcat_ln TO fieldcat.
    *180 Days
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'DMBTR'.
    fieldcat_ln-fieldname = '180DAYS'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-seltext_l = '181-365 Days'.
    fieldcat_ln-seltext_m = '181-365 Days'.
    fieldcat_ln-seltext_s = '181-365 Days'.
    APPEND fieldcat_ln TO fieldcat.
    *365 Days
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'DMBTR'.
    fieldcat_ln-fieldname = '365DAYS'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-seltext_l = '>365 Days'.
    fieldcat_ln-seltext_m = '>365 Days'.
    fieldcat_ln-seltext_s = '>365 Days'.
    APPEND fieldcat_ln TO fieldcat.
    Last Payment Date
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'KNKK'.
    fieldcat_ln-fieldname = 'CASHD'.
    fieldcat_ln-col_pos = col_pos.
    APPEND fieldcat_ln TO fieldcat.
    Street Name
    ADD 1 TO COL_POS.
    CLEAR FIELDCAT_LN.
    FIELDCAT_LN-REF_TABNAME = 'lfa1'.
    FIELDCAT_LN-FIELDNAME = 'STRAS'.
    FIELDCAT_LN-COL_POS = COL_POS.
    APPEND FIELDCAT_LN TO FIELDCAT.
    Telephone
    ADD 1 TO COL_POS.
    CLEAR FIELDCAT_LN.
    FIELDCAT_LN-REF_TABNAME = 'lfa1'.
    FIELDCAT_LN-FIELDNAME = 'TELF1'.
    FIELDCAT_LN-COL_POS = COL_POS.
    APPEND FIELDCAT_LN TO FIELDCAT.
    Credit Group
    ADD 1 TO COL_POS.
    CLEAR FIELDCAT_LN.
    FIELDCAT_LN-REF_TABNAME = 'KNKK'.
    FIELDCAT_LN-FIELDNAME = 'GRUPP'.
    FIELDCAT_LN-COL_POS = COL_POS.
    APPEND FIELDCAT_LN TO FIELDCAT.
    *Sales District
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'KNVV'.
    fieldcat_ln-fieldname = 'BZIRK'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-seltext_l = 'S_Distt'.
    fieldcat_ln-seltext_m = 'S_Distt'.
    fieldcat_ln-seltext_s = 'S_Distt'.
    APPEND fieldcat_ln TO fieldcat.
    Sales Office
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'KNVV'.
    fieldcat_ln-fieldname = 'VKBUR'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-seltext_l = 'S_Off'.
    fieldcat_ln-seltext_m = 'S_Off'.
    fieldcat_ln-seltext_s = 'S_Off'.
    APPEND fieldcat_ln TO fieldcat.
    Cust Creat Date
    ADD 1 TO COL_POS.
    CLEAR FIELDCAT_LN.
    FIELDCAT_LN-REF_TABNAME = 'lfa1'.
    FIELDCAT_LN-FIELDNAME = 'ERDAT'.
    FIELDCAT_LN-COL_POS = COL_POS.
    APPEND FIELDCAT_LN TO FIELDCAT.
    Del Plant
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'KNVV'.
    fieldcat_ln-fieldname = 'VWERK'.
    fieldcat_ln-col_pos = col_pos.
    APPEND fieldcat_ln TO fieldcat.
    Sales Group
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'KNVV'.
    fieldcat_ln-fieldname = 'VKGRP'.
    fieldcat_ln-col_pos = col_pos.
    APPEND fieldcat_ln TO fieldcat.
    Sort Criteria
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'lifnr'.
    fieldcat_ln-fieldname = 'PSORT'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-seltext_l = 'Sort Field'.
    fieldcat_ln-seltext_m = 'Sort Field'.
    fieldcat_ln-seltext_s = 'Sort Field'.
    APPEND fieldcat_ln TO fieldcat.
    Sales of Customer
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'DMBTR'.
    fieldcat_ln-fieldname = 'TOTSAL'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-seltext_l = 'Total Sales'.
    fieldcat_ln-seltext_m = 'Total Sales'.
    fieldcat_ln-seltext_s = 'Total Sales'.
    APPEND fieldcat_ln TO fieldcat.
    ENDFORM. " BUILD_FIELDCAT
    *& Form BUILD_SORTCAT
    text
    --> p1 text
    <-- p2 text
    FORM build_sortcat.
    SORTCAT_LN-SPOS = '1'.
    sortcat_ln-spos = '2'. " 0001
    sortcat_ln-fieldname = 'PSORT'.
    sortcat_ln-up = 'X'. " 0001
    sortcat_ln-subtot = 'X'.
    APPEND sortcat_ln TO sortcat.
    CLEAR sortcat_ln.
    SORTCAT_LN-SPOS = '2'.
    SORTCAT_LN-FIELDNAME = 'lifnr'.
    sortcat_ln-spos = '1'. " 0001
    sortcat_ln-fieldname = 'NAME1'. " 0001
    sortcat_ln-up = 'X'.
    APPEND sortcat_ln TO sortcat.
    ENDFORM. " BUILD_SORTCAT
    *& Form BUILD_EVENTCAT
    text
    --> p1 text
    <-- p2 text
    FORM build_eventcat.
    eventcat_ln-name = 'TOP_OF_PAGE'.
    eventcat_ln-form = 'PAGE_HEADER'.
    APPEND eventcat_ln TO eventcat.
    ENDFORM. " BUILD_EVENTCAT
    *& Form BUILD_LAYOUT
    text
    --> p1 text
    <-- p2 text
    FORM build_layout.
    layout_in-colwidth_optimize = 'X'.
    layout_in-no_hotspot = 'X'.
    layout_in-zebra = 'X'.
    layout_in-get_selinfos = 'X'.
    ENDFORM. " BUILD_LAYOUT
    *& Form START_LIST_VIEWER
    text
    --> p1 text
    <-- p2 text
    FORM start_list_viewer.
    DATA: pgm LIKE sy-repid.
    pgm = sy-repid.
    if t_variant[] is initial.
    t_variant-report = pgm.
    t_variant-variant = '/ATB'.
    t_variant-TEXT = '/ATB'.
    t_variant-DEPENDVARS = 'S'.
    append t_variant.
    clear t_variant.
    endif.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    i_callback_program = pgm
    i_callback_user_command = 'USER_COMMAND'
    it_fieldcat = fieldcat
    it_sort = sortcat
    is_layout = layout_in
    i_save = 'A'
    IS_VARIANT = t_variant
    it_events = eventcat
    TABLES
    t_outtab = itab
    EXCEPTIONS
    OTHERS = 2.
    ENDFORM. " START_LIST_VIEWER
    FORM user_command USING ucomm LIKE sy-ucomm
    selfield TYPE slis_selfield.
    DATA l_lifnr(10) TYPE n.
    READ TABLE itab INDEX selfield-tabindex.
    CHECK sy-subrc = 0.
    CASE ucomm.
    WHEN '&IC1'.
    CASE selfield-sel_tab_field.
    WHEN 'ITAB-LIFNR'.
    SET PARAMETER ID 'LIF' FIELD itab-lifnr.
    SET PARAMETER ID 'BUK' FIELD p_bukrs.
    IF itab-lifnr CO '0123456789 '.
    l_lifnr = itab-lifnr.
    itab-lifnr = l_lifnr.
    ENDIF.
    SELECT SINGLE kkber INTO knkk-kkber
    FROM knkk WHERE lifnr = itab-lifnr.
    IF sy-subrc EQ 0.
    v_kkber = knkk-kkber.
    ELSE.
    CLEAR v_kkber.
    ENDIF.
    REFRESH sel_tab[].
    MOVE: 'lifnr' TO sel_tab-selname,
    'P' TO sel_tab-kind, " PARAMETER
    itab-lifnr TO sel_tab-low.
    APPEND sel_tab.
    CLEAR sel_tab.
    MOVE: 'KKBER' TO sel_tab-selname,
    'P' TO sel_tab-kind, " PARAMETER
    v_kkber TO sel_tab-low.
    APPEND sel_tab.
    CLEAR sel_tab.
    SUBMIT rfdkli41
    USING SELECTION-SET 'VAR1'
    WITH SELECTION-TABLE sel_tab
    AND RETURN.
    CALL TRANSACTION 'XK03' AND SKIP FIRST SCREEN.
    WHEN 'ITAB-ZCURRENT'. " 0001
    v_days = 'CUR'.
    PERFORM display_line_item_level.
    WHEN 'ITAB-ZFUTURE'.
    v_days = 'FUT'.
    PERFORM display_line_item_level.
    WHEN 'ITAB-30DAYS'.
    v_days = '30D'.
    PERFORM display_line_item_level.
    WHEN 'ITAB-60DAYS'.
    v_days = '60D'.
    PERFORM display_line_item_level.
    WHEN 'ITAB-90DAYS'.
    v_days = '90D'.
    PERFORM display_line_item_level.
    WHEN 'ITAB-99DAYS'.
    v_days = '99D'.
    PERFORM display_line_item_level.
    WHEN 'ITAB-120DAYS'.
    v_days = '120D'.
    PERFORM display_line_item_level.
    WHEN 'ITAB-180DAYS'.
    v_days = '180D'.
    PERFORM display_line_item_level.
    WHEN 'ITAB-365DAYS'.
    v_days = '365D'.
    PERFORM display_line_item_level.
    WHEN 'ITAB-TOTAL'.
    v_days = ' '.
    PERFORM display_line_item_level. " 0001
    ENDCASE.
    ENDCASE.
    ENDFORM. "USER_COMMAND
    PAGE_HEADER
    FORM page_header.
    WRITE:/115 'Time:', sy-timlo.
    WRITE: /115 'Date:', sy-datum.
    WRITE: /52 'Customer Outstanding Agewise ', "0002
    115 'Page:', sy-pagno.
    SKIP.
    IF p_abs EQ 'X'.
    WRITE: /52 'Vendor Outstanding Agewise (Absolute Aging)',
    115 'Page:', sy-pagno.
    ELSE.
    WRITE: /52 'Vendor Outstanding Agewise (Due Date Aging)',
    115 'Page:', sy-pagno.
    ENDIF.
    SKIP.
    ULINE /(132).
    WRITE: /02 'Open Items as of:', stida.
    IF NOT s_vkgrp[] IS INITIAL.
    IF s_vkgrp-high IS INITIAL.
    WRITE: 52 'Sales Group :',s_vkgrp-low.
    ELSE.
    WRITE: 52 'Sales Group :',s_vkgrp-low,'to',s_vkgrp-high.
    ENDIF.
    ELSE.
    WRITE: 52 'Sales Group : All'.
    ENDIF.
    IF NOT s_grupp[] IS INITIAL.
    IF s_grupp-high IS INITIAL.
    WRITE: 107 'Credit group :',s_grupp-low.
    ELSE.
    WRITE: 107 'Credit group :',s_grupp-low,' to',s_grupp-high.
    ENDIF.
    ELSE.
    WRITE: 107 'Credit Group : All'.
    ENDIF.
    WRITE: /02 'Comapany Code :', p_bukrs.
    IF NOT s_konda[] IS INITIAL.
    IF s_konda-high IS INITIAL.
    WRITE: 52 'Price group :',s_konda-low.
    ELSE.
    WRITE: 52 'Price group :',s_konda-low,' to',s_konda-high.
    ENDIF.
    ELSE.
    WRITE: 52 'Price Group : All'.
    ENDIF.
    IF NOT s_ctlpc[] IS INITIAL.
    IF s_ctlpc-high IS INITIAL.
    WRITE: 107 'Risk category:',s_ctlpc-low.
    ELSE.
    WRITE: 107 'Risk category:',s_ctlpc-low,' to',s_ctlpc-high.
    ENDIF.
    ELSE.
    WRITE: 107 'Risk category: All'.
    ENDIF.
    IF NOT s_vkbur[] IS INITIAL.
    IF s_vkbur-high IS INITIAL.
    WRITE:/02 'Sales Office :',s_vkbur-low.
    ELSE.
    WRITE:/02 'Sales Office :',s_vkbur-low,' to',s_vkbur-high.
    ENDIF.
    ELSE.
    WRITE:/02 'Sales Office : All'.
    ENDIF.
    IF NOT s_kdgrp[] IS INITIAL.
    IF s_kdgrp-high IS INITIAL.
    WRITE: 52 'Customer group :',s_kdgrp-low.
    ELSE.
    WRITE: 52 'Customer group :',s_kdgrp-low,' to',s_kdgrp-high.
    ENDIF.
    ELSE.
    WRITE: 52 'Customer group : All'.
    ENDIF.
    IF NOT s_ktokd[] IS INITIAL.
    IF s_ktokd-high IS INITIAL.
    WRITE: 107 'Account Group:',s_ktokd-low.
    ELSE.
    WRITE: 107 'Account Group:',s_ktokd-low,' to',s_ktokd-high.
    ENDIF.
    ELSE.
    WRITE: 107 'Account Group: All'.
    ENDIF.
    IF NOT s_lifnr[] IS INITIAL.
    IF s_lifnr-high IS INITIAL.
    WRITE: /02 'Vendor No :',s_lifnr-low.
    ELSE.
    WRITE: /02 'Vendor No :',s_lifnr-low,' to',s_lifnr-high.
    ENDIF.
    ELSE.
    WRITE: /02 'Vendor No : All'.
    ENDIF.
    IF NOT s_kkber[] IS INITIAL.
    IF s_kkber-high IS INITIAL.
    WRITE: 52 'Credit Control Area:',s_kkber-low.
    ELSE.
    WRITE: 52 'Credit Control Area:',s_kkber-low,' to',s_kkber-high.

  • Function module usage in vendor ageing report for ageing calculation

    hi everybody there
    as i have to calculate the vendor ageing
    which is nothing but
    AGEING = Currentdate - BLINE date
    so for this i have coded as follows and use the function module but couldn't get the result .it is alwayas showing 0 means ageing  is o but it is not like that
    parameter:p_date1 type dats.
    call function 'days_between_two_dates'
    exporting
    i_datum_bis = p_date1
    i_datum_von = itab-zfbdt
    importing
    e_tag = itab-ageing
    exceptions
    days_method_not_defined =1
    others = 2.
    so what is the bug in it.

    hi,
    <b>declare ur internal table field , of type BSIK-ZFBDT or sy-datum
    thats the only thing u want to do.
    the other parameter is sy-datum</b>
    <b>data: field like BSIK-ZFBDT.</b>
    DATA:lv_diff TYPE i.
    CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'
    EXPORTING
    <b>i_datum_bis = sy-datum
    i_datum_von =  field</b>
    IMPORTING
    e_tage = <b>lv_diff</b>
    EXCEPTIONS
    days_method_not_defined = 1
    OTHERS = 2.
    IF sy-subrc = 0.
    WRITE:/ <b>lv_diff</b>.
    ENDIF.
    nw it will work.
    rgds'

  • AP aging Report with Aging Period as parameter

    HI all ,
    It's required from me to make AP aging period report with parameters including Aging periods as parameter so that the user will have list of value with the aging periods avaialable & he should choose from them .
    Based on that
    the columns with the period starting & ending periods will be varied (dynamic) up on the period chosen .
    The required is to get the invoice amount under each related column ............ is that possible & if yes please just guide me with the idea as the many ideas that i got is calculating the amounts with the period as statically behavior ...
    Thanks alot

    is there something missing in my requirments

  • What is Ageing report?

    Hi,
    Can anybody explain me what is Inventory ageing report,vendor ageing report?
    Pls explain in detail.
    Thanks in advance.
    Regards
    Gitesh

    hi,
    It show the details abt all those material which are not used from long time.....
    If its used ie. if any GR, GI or transfers then the material is supposed to be active...But if not used from long long time then it is supposed as DEAD material...
    But if any material which was moved/used etc before a specific period, then falls under slow moving items..
    All these reports are based on the period you specify for the material...
    Regards
    Priyanka.P

  • AR AGING REPORT. Why 'BalDueDeb' minus 'BalDueCred' not same as Balance?

    Dear All,
    I am trying to build SQL which mimics the AR Aging Report in SAP B1 8.8. Reason is to add additional fields needed by Management. I get the SAME TOTAL as Ageing, but when I run my query, I can't get the same no. of rows as Aging.
    Aging has 700 rows (NOT display reconciled transactions), and my aim is to get the same no. of rows.
    Case I: When I use: WHERE (T0.BalDueDeb - T0.BalDueCred) != 0
    I get 816 rows. All zero balances are eliminated, but it seems that some transactions which have been reconciled appear in my report as outstanding debits and also credits. This is why it has more rows than Aging, although total is correct.
    Case II: When I use: WHERE Balance !=0
    I get 5026 rows. Many rows show zero balances. I don't understand why they are not eliminated. I thought the 2 commands were equivalent.
    But the good news is that when I export to Excel and delete all those zero rows, I get exactly 700 rows, same as Aging!
    Same total, same no. of rows!
    If anybody could help me complete my query, I can continue. How can I eliminate these rows having zero balances? Where have I gone wrong?
    Thanks a lot.
    Leon Lai
    =========================================================================================
    SELECT distinct
    T1.CardCode,
    T1.CardName,
    T0.RefDate,
    CASE 
               WHEN T0.TransType=13 THEN 'IN'
               WHEN T0.TransType=14 THEN 'CN'
               WHEN T0.TransType=30 THEN 'JE'
               WHEN T0.TransType=24 THEN 'RC'
               WHEN T0.TransType=46 THEN 'PS'
               ELSE 'Error ! ! ! !'
    END AS 'Document Type',
    T0.Ref1 'Document Number',
    CASE 
               WHEN T0.TransType=13 THEN 'IN' + T0.Ref1
               WHEN T0.TransType=14 THEN 'CN' + T0.Ref1
               WHEN T0.TransType=30 THEN 'JE' + T0.Ref1
               WHEN T0.TransType=24 THEN 'RC' + T0.Ref1
               WHEN T0.TransType=46 THEN 'PS' + T0.Ref1
               ELSE 'Error ! ! ! !'
    END AS 'Concat',
    T0.Account,
    T0.Line_ID AS 'Row',
    T0.BalDueDeb,
    T0.BalDueCred,
    T0.TransId AS 'Id JDT1',
    (T0.BalDueDeb- T0.BalDueCred) AS 'Balance'
    FROM JDT1 T0 inner join ocrd t1 on t0.Shortname = t1.CardCode
    WHERE T1.CardType = 'C'
    PROBLEM IS HERE--??????????????--
    --and (T0.BalDueDeb - T0.BalDueCred) != 0       
    and Balance != 0
    -- The query gives different results depending on which of the above lines is run. Why?
    PROBLEM IS HERE--??????????????--
    ORDER BY T1.CardCode, T0.RefDate, T0.Ref1

    Dear Gordon,
    Thanks for your reply, and sorry for the incomplete reply which went beyond my control.
    Here are my results using WHERE (T0.BalDueDeb - T0.BalDueCred) !=0
    I have compared Aging Report with SQL Query.
    Doc Type  Aging Rows         Aging Total     SQL Rows    SQL Total*
    CN            57        -214,315.34     57        -214,315.34
    IN           452       4,741,436.41     452       4,741,436.41
    JE           134         202,209.56     267         201,584.56
    PS            12         107,652.40     18         121,352.40
    RC             4        -107,168.04     10        -120,243.04
               659       4,729,815.00     804        4,729,815.00
    The results are messy, time consuming to generate and investigate. Too much for newbee!
    The main differences lie in JE; about x2 rows in SQL Query.
    This may be due to rows that have reconciled in Aging, but appear in SQL Query.
    I have also prepared a list of Doc. Nos where there are differences, but too lengthy.
    TO Help you understand what's happening the foll. remarks may help:
    (1) The T0.Ref1 'Document Number' is empty for all JE. However, for other Doc types, these exist and agree with Aging.
    (2) Although 'Document Number' is empty for JE, there is a column Ref1 which does give a reference which agrees with Aging
    (3) A specific document always has 1 row in Aging, but may have several rows in my query
    (4) I do not know why using:  WHERE Balance !=0 works, but it does give a near perfect result. Why not use this as starting point? After deleting all the zero rows which it cannot delete, I GET EXACTLY the same result as SAP B1 8.8 Report 'Aged Analysis of Debtors'. Same no. of rows, Same total. How to delete these zeros in SQL?
    (5) In SAP B1 forum, it seems many persons still cannot arrive at the official Aging. I maybe near the correct solution, but no idea why it works.
    (6) I am continuing the struggle - maybe I need to put a sub query to eliminate the zeros first?
    Thanks
    Leon Lai

  • Columns out of order in ageing report

    Hello,
    When running the 'Customer Receivables Ageing' Report the ageing columns are not in the order they should be. For example:
    The columns should be in this order:
    Customer Code  |  Customer Name  |  Balance Due  |  Future Remit  |  0- 30  |  31-60  |  61-90  |  91-120  |  120+  |  Doubtful Debt
    Instead it is showing in this order - which is wrong:
    Future Remit  |  0-30  |  Customer Name  |  120+  |  31-60  |  61-90  |  91-120  | Customer Code  |  Doubtful Debt  |  Balance Due
    I have located a similar instance on the SAP notes but this refers to their being a possible two instances of this report open. This is not the case. I have had the user log out of SAP and log back in as well as having them restart their pc - both to no avail.
    Would anyone else have any suggestions?
    Regards,
    Juan

    Hello Juan -
    contact SAP Support or Partner immediately - we had the similar situation a logn time ago and someone at SAP had to apply a fix.   I never heard what caused it...
    Take care - Zal

  • Inventory Ageing report required

    Hi SAP Experts
    I want to create an inventory ageing report which is based on FIFO valuation method and will be at company level.
    It should display time intervals like 0-30, 30-60, 60-90 etc but these intervals can be dynamic means we can change these time intervals as per our convenience. I am working on SAP 2007B PL22.
    Waiting for your valuable inputs.
    Regards
    Ashish

    Hi,
    There are loads of threads talking about the same issue. You have to dig in and find the correct query yourself which suits your requirement.
    Check following threads :
    inventory aging report
    Inventory Aging
    Query for Inventory Report
    Kind Regards,
    Jitin
    SAP Business One Forum Team

  • Required Standard Vendor ageing report

    Hi FI Experts,
    I am SD Person, i have required Vendor ageing report, where we were see the vendor's due & non due out standing in mass up to perticular period.
    Please help me.
    Regards
    BK GAIKWAD

    Hi,
       Check with the following links.
    Need standrad program for vendor aging report
    Vendor Aging Report
    Regards,
    Radhika.

  • Inventory Ageing report

    Hi
    I require Inventory (raw material) ageing report. Ageing date must be calculated from date of goods receipt.
    For example:
    I have 100 units of Raw Material A.
    Goods receipts date were as follows:
    30 units: 1st April 2009
    45 units: 1st July 2009
    25 units: 1st September 2009
    So inventory aging as on 30th September must be:
    (days calculated from GR date to 30th Sept)
    0 - 30 Days --> 25 units
    31 - 60 Days --> 45 units
    61 - 90 Days --> 30 units
    Let me know TCode from where i can get the inventory ageing as mentioned above or let me know the TCodes / Tables which be helpful for developing report.

    Hi,
    Check teh Standard Reports:
    MC.9 - INVCO: Material Analysis Selection, Stock
    MC.B - INVCO: Material Analysis Selection, Turnover
    MC40 - INVCO: ABC Analysis of Usage Values
    MC44 - INVCO:Analysis of Inventory Turnover
    MC49 - INVCO: Mean Stock Values
    MC50 - INVCO: Analysis of Dead Stock
    Regards,
    Kishore K

  • Adding the Document Total to Detailed Liabilities Aging Report

    Hi,
    On the Detailed Liabilities Aging Report(Vendor Aging), I would like to add the Document Total from AP Invoice. How can I link to the AP invoice table(OPCH).
    Thanks
    Krishnan

    Hi Krishnan,
    This PLD is hard coded report.  You don't have any options to link to other fields in the report.  If you need that info on the report, you need to create your own.
    Thanks,
    Gordon

  • AR Aging Report does not change with Posting, Due, and Document selections

    It appears to me that when you run the AR Aging report with the same date ranges in each of the date selection fields, Posting, Due and Doument, you do not get a different display of aging buckets.  Does this report always display data based on Due Date?

    Hi Bill,
    When you run the AR Aging report change "Age by" option and check aging buckets are changing or not it has to change.
    Thanks,
    Sachin

  • Inventory Stock Aging Report

    Hi All.
    I need Inventory Stock Quantity wise aging report from sap b1 sp 00 pl 47 .
    0-30, 31-60,61-90 and above 90
    Regards,
    Haider

    Check below link tooo
    Re: Stock Aging report in SAP Business One
    Re: Inventory Aging Report
    Stock Aging Report
    and this toooo
    SELECT distinct T0.ITEMCODE, T1.itemName,T0.ONHAND as 'Total Qty', T1.ManBtchNum,T1.ManSerNum,
    CASE WHEN Datediff (day,T1.LastPurDat, Getdate ()) <45 THEN T0.ONHAND END '<45 Days (Qty)',
    CASE WHEN Datediff (day,T1.LastPurDat, Getdate ()) <45 THEN T0.ONHAND * T0.Avgprice END  '<45 Days (Value)',
    CASE WHEN Datediff (day,T1.LastPurDat, Getdate ())>45 AND Datediff (day,T1.LastPurDat, Getdate ()) <90 THEN T0.ONHAND END '<45 T0 90 Days (Qty)',
    CASE WHEN Datediff (day,T1.LastPurDat, Getdate ())>45 AND Datediff (day,T1.LastPurDat, Getdate ()) <90 THEN T0.ONHAND * T0.Avgprice END  '<45 T0 90 Days (Value)',
    CASE WHEN Datediff (day,T1.LastPurDat, Getdate ()) >90 THEN T0.ONHAND END '>90 Days (Qty)',
    CASE WHEN Datediff (day,T1.LastPurDat, Getdate ())>90 THEN T0.ONHAND * T0.Avgprice END  '>90 Days (Value)'
    FROM OITW T0 INNER JOIN OITM T1 ON T0.ITEMCODE = T1.ITEMCODE
    INNER JOIN OITB T2 ON T1.ITMSGRPCOD=T2.ITMSGRPCOD
    left join ibt1 t3 on t3.itemcode = t0.whscode
    WHERE T0.ONHAND >0 AND T0.WhsCode = '[%0]' AND T2.ItmsGrpNam ='[%1]'

  • Query for Customer Receivables Aging Report

    What is the query to the Customer Receivables Aging Report? I cannot seem to reproduce the same results that SAP has in my Crystal Report.
    Thanks

    To reproduce it by query would not be an easy job.  Crystal Report is a better tool for report.
    Thanks,
    Gordon

  • Can using query create aging report for GL Account

    Hi all expert,
    I have a challenge scenario which customer request print out aging report for the following GL Account.
    This is not a business partner account. However, customer want display like aging report.
    30 days aging report for the following GL accounts by projects:-
         i)     WIP (Work In Progress) account
         ii)     Accrued Revenue account
         iii)     Accrued Cost account
    Examples:
                            Current Balance       30 day   60 day  90 day   120 day
    Account  WIP         10000               2000        3000      5000     0
    Any idea or example given? If yes, can you provide a query here?
    Regards,
    Eric Tan

    Hi Eric
    In standard SAP Business One this is difficult as the reports are 2 dimensional. To achieve this you will need to write multiple select statements into a temporary table and then select the final result from the temp table. Here is a sample for you to test:
    USE [*DATABASE_NAME*]
    GO
    /****** Object:  StoredProcedure [dbo].[REPORT_NAME]    Script Date: 04/24/2009 13:17:21 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE proc [dbo].[*REPORT_NAME*]
    as
    set nocount on
    begin
    DECLARE @Day_no varchar(2)
    DECLARE @Month_no varchar(2)
    DECLARE @Year_no varchar(4)
    DECLARE @Start_Date Datetime
    SET @Day_no = DAY(GetDate())
    SET @Month_no = MONTH(GetDate())
    SET @Year_no = YEAR(GetDate())
    SET @Start_Date = @Year_No + '/' + @Month_no + '/' + @Day_no --  + '/' + @Year_No
    IF OBJECT_ID(N'tempdb..#CRDAGEING', N'U') IS NOT NULL
    drop table #CRDAGEING
    SELECT T0.[CardCode] AS [CardCode], T0.[CardName] AS [CardName], -T0.[Balance] AS [Balance], CAST(0 AS MONEY) AS [Current], CAST(0 AS MONEY) AS [1Week], CAST(0 AS MONEY) AS [2Weeks], CAST(0 AS MONEY) AS [3Weeks], CAST(0 AS MONEY) AS [4Weeks], CAST(0 AS MONEY) AS [5Weeks], CAST(0 AS MONEY) AS [6Weeks], CAST(0 AS MONEY) AS [Over6Weeks], CAST(0 AS MONEY) AS [Avg3Months], CAST (0 AS MONEY) AS [Onhand] INTO #CRDAGEING FROM OCRD T0 WHERE T0.[CardType] = 'S' -- and T0.[CardCode] <> '' --and T0.[DocDate] >= @FromDate AND T0.[DocDate] <= @ToDate
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0, 0, 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] <= @Start_Date GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0, 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] >= DATEADD(DAY,1,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,8,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,8,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,15,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,15,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,22,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,22,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,29,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,29,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,36,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, 0, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,36,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,43,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, 0, 0, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,43,@Start_Date)  GROUP BY T1.[ShortName]
    SELECT SR.[CardCode], MAX(SR.[CardName]), SUM(SR.[Balance]) AS [BalanceOwing], SUM(SR.[Current]) AS [Current], SUM(SR.[1Week]) AS [1Week], SUM(SR.[2Weeks]) AS [2Weeks], SUM(SR.[3Weeks]) AS [3Weeks], SUM(SR.[4Weeks]) AS [4Weeks], SUM(SR.[5Weeks]) AS [5Weeks], SUM(SR.[6Weeks]) AS [6Weeks], SUM(SR.[Over6Weeks]) AS [Over6Weeks] FROM dbo.#CRDAGEING SR GROUP BY SR.[CardCode] ORDER BY SR.[CardCode]
    END
    Go to Microsoft SQL Studio manager and select your company database. Then expand the list and select Programmability > Stored Procedures. Right click on Stored Procedures and select New Stored Procedure. Copy the above code over the code in the edit window and change the database name as well as report name. Then select Execute to create the stored procedure. If you make changes, remember to change the word CREATE to ALTER (with other words CREATE for the first execute, and ALTER thereafter). Then in SAP Business One create a new query and leave everything blank. Click on execute and select the pencil to change to edit mode. Remove the words SELECT and type in EXEC REPORT_NAME (change the REPORT_NAME to the name you used in SQL). Then execute again and the results will be displayed in SAP Business One.
    Let me know if you get stuck. Remember the above is an example and will need to be changed to use your tables and fields as required. The basic idea is to move across by one column with each select statement. So for example the first select statement does the CURRENT column, the second one the 30DAYS column, and so on.
    Kind regards
    Peter Juby

Maybe you are looking for

  • Legend displacement/mix-up in Time Scatter Chart

    Hello, we have applied Java patch 11 on BW 7.0, but we have a major problem with a Time Scatter chart we are unable to solve. Data are displayed correctly on the chart itself, but the legend (names are taken from the query visualized by the chart) is

  • G4-dual + G4-dual connection

    I have a G4-dual processor and now have another one available. Can I? if so, How can I connect the 2 G4 computers together to get the max processing output from the 2 G4-Dual? Both have latest Tiger OS. I remembering using the firewire connection. Th

  • Dynamic parameters in function module

    Hi. I need to write a program that can call various different function modules based on what the user inputs. For example, if the user chooses "BAPI_USER_GET_DETAIL" I need to then call that function module. There is a list of about 30 functions they

  • ISE, WLC: web auth, blocking user account

    Hello! We are implementing BYOD concept with ISE (1.1.4) and WLC 5508 (7.4.100). On WLC there is SSID(WLAN) with MAC filtering without L2 security. For authentication user is redirected to the ISE Guest Portal. Credentials are created at the ISE spon

  • APD Join Transformation Error

    Hello, I am attempting to do a join transformation in APD.  I am joining query results with a flat file with an inner join.  I am joining on one field that resides in the query and the flat file.  I am getting the following error: Analysis process mu