Column Header for Select AS kind of query

Hi,
I wish to write a csv file by using the odisqlunload function. I have wrote the funtion as :
OdiSqlUnload "-FILE=#FILE_PATH/#FILE_NAME" "-DRIVER=<%=odiRef.getInfo("SRC_JAVA_DRIVER")%>" "-URL=<%=odiRef.getInfo("SRC_JAVA_URL")%>" "-USER=<%=odiRef.getInfo("SRC_USER_NAME")%>" "-PASS=<%=odiRef.getInfo("SRC_ENCODED_PASS")%>" "-FILE_FORMAT=VARIABLE" "-FIELD_SEP=," "-ROW_SEP=\r\n" "-DATE_FORMAT=yyyy/MM/dd HH:mm:ss" "-CHARSET_ENCODING=ISO8859_1" "-XML_CHARSET_ENCODING=ISO-8859-1" "-FETCH_SIZE=1000" "-QUERY=SELECT RPAD(CI_FT_GL.GL_ACCT, 31, ' '),LPAD(CASE WHEN CI_FT.CURRENCY_CD != CI_FT_GL_EXT.DIVISION_CURCY_CD THEN sum(CI_FT_GL_EXT.DIVISION_AMT) ELSE sum(CI_FT_GL.AMOUNT) END,17,' '),' ',RPAD(CI_DST_CD_CHAR.CHAR_VAL, 25, ' '),RPAD(CI_DST_CD_CHAR.DST_ID, 8, ' '),'RMB ',' ',RPAD(to_char(sysdate, 'YYYYMMDD'), 8, ' ') FROM CI_DST_CD_CHAR CI_DST_CD_CHAR,CI_FT CI_FT,CI_FT_GL CI_FT_GL,CI_FT_GL_EXT CI_FT_GL_EXT where (CI_FT.FT_ID = CI_FT_GL.FT_ID) AND (CI_FT_GL.FT_ID = CI_FT_GL_EXT.FT_ID(+)) AND CI_FT_GL.GL_SEQ_NBR = CI_FT_GL_EXT.GL_SEQ_NBR(+) AND (CI_FT_GL.DST_ID = CI_DST_CD_CHAR.DST_ID) AND (CI_DST_CD_CHAR.CHAR_TYPE_CD = 'DTLREF1') AND (trim(CI_FT_GL.GL_ACCT) is not null) AND (CI_FT.XFER_TO_GL_DT is null) AND (CI_FT.GL_DISTRIB_STATUS in ('G','M')) AND (trunc(CI_FT.SCHED_DISTRIB_DT) <= trunc(sysdate)) AND CI_FT.CIS_DIVISION = '#DIVISION' GROUP BY CI_FT_GL.GL_ACCT,CI_DST_CD_CHAR.CHAR_VAL,CI_DST_CD_CHAR.DST_ID,CI_FT.CURRENCY_CD,CI_FT_GL_EXT.DIVISION_CURCY_CD"
Then i used a jython code to generate headers. Bcoz the OdiSqlUnload does not generate headers. But the jython code is not useful when we have sql statements lik 'Select AS' :
SELECT RPAD(CI_FT_GL.GL_ACCT, 31, ' ') AS GL_ACCT,
LPAD(CASE WHEN CI_FT.CURRENCY_CD != CI_FT_GL_EXT.DIVISION_CURCY_CD THEN sum(CI_FT_GL_EXT.DIVISION_AMT) ELSE sum(CI_FT_GL.AMOUNT) END,17,' ') AS GL_AMOUNT,
My Jython code is:
import string
import java.sql as sql
import java.lang as lang
import re
sourceConnection = odiRef.getJDBCConnection("SRC")
output_write=open('d:/Bijal/output1.csv','r+')
myStmt = sourceConnection.createStatement()
my_query = "SELECT RPAD(CI_FT_GL.GL_ACCT, 31, ' ') AS GL_ACCT,
LPAD(CASE WHEN CI_FT.CURRENCY_CD != CI_FT_GL_EXT.DIVISION_CURCY_CD THEN sum(CI_FT_GL_EXT.DIVISION_AMT) ELSE sum(CI_FT_GL.AMOUNT) END,17,' ') AS GL_AMOUNT,
' ' AS BLANK1,
RPAD(CI_DST_CD_CHAR.CHAR_VAL, 25, ' ')AS DESCR,
RPAD(CI_DST_CD_CHAR.DST_ID, 8, ' ')AS DST_ID,
'RMB ' Currency_Cd,
' ' AS BLANK2,
RPAD(to_char(sysdate, 'YYYYMMDD'), 8, ' ') AS DT_OF_TXN
FROM CI_DST_CD_CHAR CI_DST_CD_CHAR,CI_FT CI_FT,CI_FT_GL CI_FT_GL,CI_FT_GL_EXT CI_FT_GL_EXT
where (CI_FT.FT_ID = CI_FT_GL.FT_ID) AND (CI_FT_GL.FT_ID = CI_FT_GL_EXT.FT_ID(+)) AND
CI_FT_GL.GL_SEQ_NBR = CI_FT_GL_EXT.GL_SEQ_NBR(+) AND (CI_FT_GL.DST_ID = CI_DST_CD_CHAR.DST_ID)
AND (CI_DST_CD_CHAR.CHAR_TYPE_CD = 'DTLREF1') AND (trim(CI_FT_GL.GL_ACCT) is not null)
AND (CI_FT.XFER_TO_GL_DT is null) AND (CI_FT.GL_DISTRIB_STATUS in ('G','M')) AND
(trunc(CI_FT.SCHED_DISTRIB_DT) <= trunc(sysdate)) AND CI_FT.CIS_DIVISION = 'MF'
GROUP BY CI_FT_GL.GL_ACCT,
CI_DST_CD_CHAR.CHAR_VAL,
CI_DST_CD_CHAR.DST_ID,
CI_FT.CURRENCY_CD,
CI_FT_GL_EXT.DIVISION_CURCY_CD"
my_query=my_query.upper()
if string.find(my_query, '*') > 0:
myRs = myStmt.executeQuery(my_query)
md=myRs.getMetaData()
collect=[]
i=1
while (i <= md.getColumnCount()):
collect.append(md.getColumnName(i))
i += 1
header=','.join(map(string.strip, collect))
elif string.find(my_query,'||') > 0:
header = my_query[7:string.find(my_query, 'FROM')].replace("||','||",',')
else:
header = my_query[7:string.find(my_query, 'FROM')]
print header
old=output_write.read()
output_write.seek(0)
output_write.write (header+'\n'+old)
sourceConnection.close()
output_write.close()
But it does not populate for Select As statements and throws error lik:
'mismatched character \'\\n\' expecting \'"\'', ('<string>', 8, 62, 'my_query = "SELECT RPAD(CI_FT_GL.GL_ACCT, 31, \' \') AS GL_ACCT,\n'))
Plz help me get headers in my output file :)

Solution1:
Still you can achieve this by using sys_connect_by_path ( if you know the use of it) to generate header. below link can help with another approach.
http://www.business-intelligence-quotient.com/?p=546
Solution2:
You need to create one file (header= true )with interface as suggested by sutirtha. Then you can copy (odifilecopy) this file to another directory with dynamic name (inside variable) and dynamic path. In this interface keep the truncate option to true so that everytime data wont be appended to the end of file. After reversing the file change the column name Manually from C1 to your ACTUAL_COL_NAME in file. Because ODI always generate the column names using C1,C2,C3 ....
The only risk in second approach is that if someone will delete the file then you will get error. For this you need to create a temp table in ODI with all column-name (header in file). then using above jython code or sys_connect_by_path (select * from temp_table), you can generate the header easily. Now this file will be generated dynamically and can be used by the interface. So even if someone will delete the file you can generate it during run time.
Thanks.

Similar Messages

  • How to display a Column Header for the characteristic Text column

    Hi All
    Our users want me to provide for a column header for the characteristic text.
    Here is what I mean
    I am reporting 0plant in the rows as key and Text. In the column on Plant Key the column header says Plant but there is no column header for the plant text.
    Eq:
    Plant                                                        Amount
    IE00         Initiator Plant                               244
    IE01         Initiator Plant NJ                          890
    Our users in the plant text column want a dummy column header to be displayed. SInce they download the data from the BW report to Excel and use pivot reporting. How can I introduce a column header for the texts.
    Thanks
    Karen

    Hi Karen,
    I am not sure if this is possible, although Users can ask anything :).
    In Planning we used to predefine cell headings via Macros and creating dummy cells in between.  I am not sure if a similar scenario can work here.
    By default this is not possible in Reports.  In BEx workbooks, you could probably try with Macros.
    Another easy option is to bring the data in the Cube as another field or create a nav. attribute in the master for text and use it as a nav. attr. in the Cube and put it in your Query row alongside.
    -Aby

  • Putting the Header for Text part in the query properties.........

    Hi,
    I am displaying the Key and text for the characteristic.....
    Is it possible that I can put some column heading for the text part...
    Like if I display 0Material (key and text), I can display the column heading for the text part
    as "Material Descripion"
    Is it possible.......? Please let me know
    Thanks , Jeetu

    I dont think it is possible the way you are thinking. However, if you have Material description in the data target (MAKTX) then you can use this in the separate column in the report.
    Thanks..
    Shambhu

  • How To avoid column heading for only total line in ALV list Display

    Hi,
    How To avoid column heading for only total line in ALV list Display.

    Hi,
    to change colunm header field catlog is built
    look at the example below
    Changing column text headers
    use this to change, hide, or alter the ALV columns
    CLEAR: gt_fcat.
    READ TABLE gt_fcat WITH KEY fieldname = 'TEXT1' " ***
    *TEXT1 is your field name
       ASSIGNING <gtfcat>.
    IF sy-subrc = 0.
       <gtfcat>-coltext   = 'Date Type'.
       <gtfcat>-no_out    = ' '.
       <gtfcat>-tooltip   = 'Date Type Text from IT0019'.
       <gtfcat>-seltext   = 'IT0019'.
    keep seltext to '' if u want to hide
    ENDIF.
    regards
    austin

  • JTable - One Column Heading for Two Columns

    Can you adjust the default JTable to have one column heading for two columns of data? Is there a simple span command? I've looked at the api for JTable and JTableHeader and didn't see anything, is there something I'm missing? Any help would be appreciated.

    What i am trying to accomplish is have column 'E' span 2 columns.
    This is my code thus far, however it give the error from my pryor message. I am pretty sure it is because I'm using and Object[][] and a String[] instead of Vectors. What corrections do I need to make in order for my goal of:
    [ A ][ B ][ C ][ D ][ E  ][ F ][ G ]
    [ 1 ][ 2 ][ 3 ][ 4 ][5][6][ 7 ][ 8 ]
    Object[][] data = new Object[ROWS][COLUMNS];
    String[] columnNames = {"A","B","C","D","E","E","F","G"};
    table = new JTable(data, columnNames);
    table.setBackground(Color.white);
    table.addKeyListener(this);
    DefaultTableCellRenderer d = new DefaultTableCellRenderer();
    d.setHorizontalAlignment(JLabel.CENTER);
    table.setDefaultRenderer(table.getColumnClass(0),d);
    for (int i = 0; i < table.getColumnCount(); i++){
    TableColumn aColumn = header.getColumnModel().getColumn(i);
    TableCellRenderer renderer = aColumn.getHeaderRenderer();
    if (renderer == null) {
    renderer = new DefaultTableCellRenderer(){
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column){
    JTableHeader header = table.getTableHeader();
    if (header != null) {
    setForeground(header.getForeground());
    setBackground(header.getBackground());
    setFont(header.getFont());
    setHorizontalAlignment(JLabel.CENTER);
    setText((value == null) ? "" : value.toString());
    setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    return this;
    aColumn.setHeaderRenderer(renderer);

  • Times ten not showing the column alias as column header in select query.

    Hi All,
    I am trying to execute following queries on TimesTen database 11.2.2.2.0.
    SELECT ROWNUMBER,
    floor((to_date(TO_CHAR(SYSDATE,'YYYY-MM-DD hh24:mi:ss'), 'YYYY-MM-DD hh24:mi:ss')-to_date(TO_CHAR(starttime,'YYYY-MM-DD hh24:mi:ss'), 'YYYY-MM-DD hh24:mi:ss'))*24)
    || 'h '
    || mod(floor((to_date(TO_CHAR(SYSDATE,'YYYY-MM-DD hh24:mi:ss'), 'YYYY-MM-DD hh24:mi:ss')-to_date(TO_CHAR(starttime,'YYYY-MM-DD hh24:mi:ss'), 'YYYY-MM-DD hh24:mi:ss'))*24*60),60)
    || 'm '
    || mod(floor((to_date(TO_CHAR(SYSDATE,'YYYY-MM-DD hh24:mi:ss'), 'YYYY-MM-DD hh24:mi:ss')-to_date(TO_CHAR(starttime,'YYYY-MM-DD hh24:mi:ss'), 'YYYY-MM-DD hh24:mi:ss'))*24*60*60),60)
    || 's' TIME_DIFFERENCE
    FROM
    (SELECT ROW_NUMBER() OVER (ORDER BY USERIDENTITY DESC) ROWNUMBER,
    u.*
    FROM TBLMCORESESSIONS u
    WHERE 1=1
    ) B
    WHERE ROWNUMBER BETWEEN 1 AND 5
    and I am getting the follwing output.
    ROWNUMBER,
    < 1, 8h 52m 34s >
    < 2, 8h 54m 24s >
    < 3, 8h 54m 13s >
    < 4, 8h 55m 6s >
    < 5, 8h 54m 40s >
    The issue is I should get TIME_DIFFERENCE as column header but it is not showing TIME_DIFFERENCE as the column header & it is calculating the value just fine .
    & if same query I execute on oracle 11g database every thing works fine.
    please suggest me something that column header is must.
    or suggest me any other for query
    Edited by: hiaditya04 on Apr 24, 2012 11:05 AM

    Hi,
    It is similar to bug which is raised in Timesten 11.2.2.2.. BUG 13896607 - COLUMN NAME MISSING FROM A VIEW IN TIMESTEN 11.2.2.2 . If you have MOS access then you can view about this bug. The bug is going to be fix in the future release. The bug basically indicates that we are not displaying the column name properly when select list contains complex expressions. The column itself can be accessed and values are displayed correctly.
    Regarding your issue "column TIME_DIFFERENCE not found" , I would suggest you to access the column by position, not by name like below
    I believe you are trying to access your column like below
    resultset.getString(“TIME_DIFFERENCE”)
    Instead of this you can use : -- resultset.getString(2) ( this position should based on the position of the column you are using in the query)
    Hope this helps.
    Regards
    Rajesh

  • Multiple column heading for sql that returns single column

    Hi All,
    I have just started using APEX and my apex version is 3.2.0.00.27.
    We have a report that displays the output from a query similar to the below one. We are using borderless template and removed the "before each row" and "after each row" values to allow the output displayed in table format.
    Now we wanted to include heading for each column displayed in table. We wanted to include headings from a derived value, Example for column1 , heading need to display the sysdate and column2 heading should be sysdate-1 and so on.  But the column attribute tab is having only one column My_rep. Not sure how to se pl/sql type column heading in this case. Could someone please help me to achieve this?
    Please let me know if I have missed to provide any other details. Thanks in advance.
    select '<tr>
        <td>' || column1    || '</td>' ||
        <td>' || column2    || '</td>' ||
        <td>' || column3    || '</td>' ||
        <td>' || column4    || '</td>' ||
        || '</tr>' My_rep
    from mytable

    22335813-cfb0-46c4-9bef-b61a46f0de67 wrote:
    Please update your forum profile with a real handle instead of "22335813-cfb0-46c4-9bef-b61a46f0de67"
    I have just started using APEX and my apex version is 3.2.0.00.27.
    Upgrading from this unsupported version to the current 4.2 release is recommended.
    When you post a question, always include the following information in addition to the full APEX version number:
    Full database version, edition and host OS
    Web server architecture (EPG, OHS or APEX listener), server platform, and host OS
    Browser(s)/version(s) used
    UI/Theme
    Templates
    Region type (making particular distinction as to whether a "report" is a standard report, an interactive report, or in fact an "updateable report" (i.e. a tabular form)
    With APEX we're also fortunate to have a great resource in apex.oracle.com where we can reproduce and share problems. Reproducing things there is the best way to troubleshoot most issues, especially those relating to layout and visual formatting. To get a detailed answer then it's appropriate for the questioner to take on a significant part of the effort by reproducing the problem on apex.oracle.com before asking for assistance with specific issues, which can then be seen at first hand in a real APEX environment.
    we wanted to get a report in Apex with the below format. and we wanted to change background color of each cell depends on the combination of code||status
    Heading        sysdate             sysdate-1              sysdate-2                              ...(sysdate-30
    ======        ======          ========               =======
    name         code||status                                   code||status
    name                                  code||status
    we are using the below query to get this table format. But heading is the issue we are facing now
    select '<tr>
        <td>' || name    || '</td>' ||
        '<td style=background-color:' || case when sysdate0='0C' then 'Green' when sysdate0='0I' then 'Red'     when (substr(sysdate0,1,1)!='0' and substr(sysdate0,1,1)='I') then 'Orange'  else 'Yellow' end || '>  &nbsp'  || sysdate0 || '  &nbsp</td>'  ||
        || '</tr>' repcolumn
    from
      (select
            a.name,
            max(decode(trunc(a.ardate),trunc(sysdate), a.code||a.STATUS , '' ))   sysdate0,
            max(decode(trunc(a.ardate),trunc(sysdate-30), a.code||a.STATUS , '' )) sysdate30
    from
            mytab a
    where
            a.ardate>=sysdate-30
    group by a.name)
    See Re: Matrix report for a custom report template-based solution to a similar problem, with dynamically generated column headings.

  • Check box  in ALV Header for selection

    Hi,
    I'm working on ALV in ABAP web dynpro. We have a requirement to check some rows and based on the selection a FM should be executed.
    I've used checkbox in the column for selection. Is there anyway to use a check box (or any element)  in the column header and use that to select all.
    I checked the ALV column header class documentation but didnt find anything that allows UI elements in header.
    Any workaround to tackle this?
    Thank you,
    Vasu

    Hi Thomas,
    I've already done that (in toolbar).  Checking if there is some hidden option that I missed to do this. Looks like there isn't

  • How can I use a column header to select columns in a JTable?

    Hello,
    I've been working for ages on this, but I still can't come up with a suitable solution. What I want to be able to do is select a column header from a JTable, which in turn would select the corresponding column in my JTable. I cant seem to do this with a mouse listener, and I can't see how to toggle the buttons of the header either.
    Any help would be gratefully appreciated.
    Mike

    I have both row and columns selected depending on what you do in the JTable. Here's my code:
    where you init your JTable add:
    addressTable = new JTable(addressTableModel, addressTableColumnModel);
    JTableHeader th = addressTable.getTableHeader();
    th.addMouseListener(new tableHeaderMouseAdapter(addressTable));
    addressTable.getSelectionModel().addListSelectionListener(new selectionListener(addressTable));
    addressTable.setColumnSelectionAllowed(true);
    tableHeaderMouseAdapter looks like this (it should look familiar):
    private class tableMouseAdapter extends MouseAdapter
         private JTable tableView;
         public tableMouseAdapter(JTable newTableView)
              tableView = newTableView;
         public void mouseClicked(MouseEvent e)
              int selectedRow = tableView.getSelectedRow();
              if ((e.getClickCount() == 1) && (selectedRow != -1))
                   tableView.clearSelection();
                   tableView.setRowSelectionInterval(selectedRow, selectedRow);
                   tableView.setColumnSelectionInterval(0, tableView.getColumnModel().getColumnCount() - 1);
    selectionListener looks like this:
    private class selectionListener implements ListSelectionListener
         private JTable tableView;
         private boolean changingSelection;
         public selectionListener(JTable newTableView)
              tableView = newTableView;
              changingSelection = false;
         public void valueChanged(ListSelectionEvent e)
              if ((!changingSelection) && (tableView.getSelectedColumnCount() < tableView.getColumnCount()) && (tableView.getSelectedRowCount() < tableView.getRowCount()))
                   changingSelection = true;
                   int selectedRow = tableView.getSelectedRow();
                   if (selectedRow >= 0)
                        tableView.clearSelection();
                        tableView.setRowSelectionInterval(selectedRow, selectedRow);
                   tableView.setColumnSelectionInterval(0, tableView.getColumnModel().getColumnCount() - 1);
                   changingSelection = false;
    I'm sure there is a better way to do this, but it's the first thing I could get to work.
    disclamer:
    Use this code at your own risk. I make no claims about this code whatsoever.

  • Removing columns heading for a perticular page in ALV list display

    Dear All,
    For last page of my ALV list display i need to remove columns heading (Strictly for single page only).
    Kindly help me with possible solution.
    I am triggering page break by  using group attribute in the sort catalogue.(  l_v_sortcat-group     = '* '. )
    Best Regards
    Ravishekar Thallapally

    if u can catch the page number,
    while building fieldcat, put the condition
    if sy-page = (page number)
    ls_fielcact-fieldname = fieldname.
    ls_fieldcat-tech = 'X'.
    LS_FIELDCAT-NO_OUT = 'x'.
    modify lt_fielcat from ls_fieldcat.
    but how r u catching page number?? can u pls tell
    endif.
    Message was edited by: Hymavathi Oruganti

  • Converting Column Header to Rows Value in SQL Query

    Dear Guys,find blew the table from A1_30 to YetToDue columns. I need from A1_30 to A356 columns convert into row values and that values column head name like Abstract. A1_30 A31_60 A61_90 A91_120 A121_180A181_365A365 BalArr NoOfLoanLoanOS YetToDue
    0 0 0 101 0 0 0 909 66730 909 3637
    0 40 0 0 0 0 0 1818 66681 1818 3637
    0 56 0 0 0 0 0 1818 70210 1818 5455
    0 0 66 0 0 0 0 909 73735 909 7273
    0 35 0 0 0 0 0 2727 73327 2727 7273
    0 0 66 0 0 0 0 909 73353 909 7273
    0 40 0 0 0 0 0 909 66778 909 3637
    0 40 0 0 0 0 0 1818 66744 1818 3637
    0 0 0 101 0 0 0 909 66787 909 3637
    0 40 0 0 0 0 0 1818 66671 1818 3637
    0 56 0 0 0 0 0 1818 70201 1818 5455
    0 56 0 0 0 0 0 1818 70204 1818 5455
    0 0 66 0 0 0 0 909 73331 909 7273
    0 40 0 0 0 0 0 1818 66726 1818 3637
    0 40 0 0 0 0 0 2727 66798 2727 3637
    0 40 0 0 0 0 0 909 66676 909 3637
    0 40 0 0 0 0 0 1818 66685 1818 3637
    0 56 0 0 0 0 0 1818 70209 1818 5455
    0 57 0 0 0 0 0 1818 70226 1818 5455
    0 35 0 0 0 0 0 2727 73762 2727 7273
    0 0 66 0 0 0 0 909 73333 909 7273
    0 40 0 0 0 0 0 1818 66759 1818 3637
    0 40 0 0 0 0 0 882 66597 882 8826
    0 40 0 0 0 0 0 2727 66789 2727 3637
    0 40 0 0 0 0 0 2646 66609 2646 8826
    0 40 0 0 0 0 0 2646 66641 2646 8826
    0 57 0 0 0 0 0 1818 70193 1818 5455
    0 56 0 0 0 0 0 1818 70202 1818 5455
    0 35 0 0 0 0 0 2727 73757 2727 7273
    0 0 66 0 0 0 0 909 73345 909
    7273
    I expecting the results:
    Abstract BalArr NoOfLoan LoanOS YetToDue
    A0_30 0 0 0 0
    A31_60 45261 1579445 45261 122852
    A61_90 4545 367097 4545 36365
    A91_120 1818 133517 1818 7274
    A121_180 0 0 0 0
    A181_365 0 0 0 0
    A365 0 0 0 0
    pls help I really appreciate ..

    Dear Partrck Hurst.I have facing struggle with my store procedure , It work very slow performance when i pass the entryPlease go through my store procedure and let me advice if i wrote the script wrongly .ALTER PROCEDURE [dbo].[MFDB_GenerateDCBCollection]
    @i_BranchId INT,
    @i_SHGId INT,
    @p_SHGMemberId INT,
    @i_LoanNumber INT,
    @i_DayOpenDate DATETIME,
    @o_ErrorStatus INT Output
    ) AS
    --WITH ENCRYPTION AS
    DECLARE @p_DayOpenDate AS DATETIME
    DECLARE @p_BranchId AS INT
    DECLARE @D_FromDate AS DATE
    DECLARE @D_ToDate AS DATE
    DECLARE @E_ToDate AS DATE
    DECLARE @p_RecordCounter AS INT
    DECLARE @p_RecordCount AS INT
    DECLARE @p_TempCollectionId AS INT
    DECLARE @p_TempStateId AS INT
    DECLARE @p_TempRegionId AS INT
    DECLARE @p_TempBranchId AS INT
    DECLARE @p_TempSHGId AS INT
    DECLARE @p_TempSHGName AS VARCHAR(75)
    DECLARE @p_TempSHGMemberId AS INT
    DECLARE @p_TempMemberId AS INT
    DECLARE @p_TempMemberName AS VARCHAR(75)
    DECLARE @p_TempVillageName AS VARCHAR(100)
    DECLARE @p_TempPanchayatName AS VARCHAR(100)
    DECLARE @p_TempPanchayatId AS INT
    DECLARE @p_TempVillageId AS INT
    DECLARE @p_TempInstNumber AS INT
    DECLARE @p_TempLoanNumber AS INT
    DECLARE @p_TempDisbursedDate AS DATE
    DECLARE @p_TempStatus AS INT
    DECLARE @p_TempLoanSchemeId AS INT
    DECLARE @p_TempLCategoryId AS INT
    DECLARE @p_TempLActivityId AS INT
    DECLARE @p_TempLActSpecId AS INT
    DECLARE @p_TempLoanAmount AS NUMERIC(18,2)
    DECLARE @p_TempApprovalStatus AS INT
    DECLARE @p_TempFundingAgencyId AS INT
    DECLARE @p_TempOpenBalPrin AS NUMERIC(18,2)
    DECLARE @p_TempOpenBalInt AS NUMERIC(18,2)
    DECLARE @p_TempStdPrin AS NUMERIC(18,2)
    DECLARE @p_TempStdInt AS NUMERIC(18,2)
    DECLARE @p_TempCollPrin AS NUMERIC(18,2)
    DECLARE @p_TempCollInt AS NUMERIC(18,2)
    DECLARE @p_TempAdvancePrin AS NUMERIC(18,2)
    DECLARE @p_TempAdvanceInt AS NUMERIC(18,2)
    DECLARE @p_TempArrearPrin AS NUMERIC(18,2)
    DECLARE @p_TempArrearInt AS NUMERIC(18,2)
    DECLARE @p_TempBalancePrin AS NUMERIC(18,2)
    DECLARE @p_TempBalanceInt AS NUMERIC(18,2)
    DECLARE @p_TempDemandDate AS DATE
    DECLARE @p_TempCollectionDate AS DATE
    DECLARE @p_TempLStatus AS INT
    DECLARE @p_TempLSourceId AS INT
    DECLARE @p_TempVoucherName AS VARCHAR(75)
    DECLARE @p_TempInsurance AS NUMERIC(18,2)
    DECLARE @p_TempUpFrontFess AS NUMERIC(18,2)
    DECLARE @p_TempDocumentFees AS NUMERIC(18,2)
    DECLARE @p_TotalInterest AS NUMERIC(18,2)
    DECLARE @i_Month AS INT = 1
    DECLARE @p_Year AS INT = 2015
    DECLARE @i_SHGMemberId AS INT
    BEGIN TRANSACTION DCBGenerated
    BEGIN
    Set @o_ErrorStatus = 0
    SELECT @D_FromDate = DATEADD(MONTH, @i_Month - 1, DATEADD(YEAR, @p_Year - 1900, 0)) --as [START DATE]
    SELECT @D_ToDate = DATEADD(MONTH, @i_Month, DATEADD(YEAR, @p_Year - 1900, -1)) --as [EMD DATE]
    SELECT @i_SHGMemberId = MFDB_SHGMemberId FROM MFDB_SHGMEMBER_MASTER WHERE MFDB_SHGId = @i_SHGId AND MFDB_MemberId = @p_SHGMemberId
    SELECT @p_TempVillageName = MFDB_VillageName,
    @p_TempVillageId = MFDB_VillageId ,
    @p_TempPanchayatId = MFDB_PanchayatId ,
    @p_TempPanchayatName = MFDB_PanchayatName
    FROM MFDB_SHG_MASTER WHERE MFDB_SHGId = @i_SHGId
    /* Drop and Create TempCollection Table. This table has all installments for a given member */
    CREATE TABLE #TEMPDCBCOLLECTION
    [MFDB_LedgerNumber] [int] IDENTITY(1,1) NOT NULL,
    [MFDB_StateId] [int] NOT NULL,
    [MFDB_RegionId] [int] NOT NULL,
    [MFDB_BranchId] [int] NOT NULL,
    [MFDB_SHGId] [int] NOT NULL,
    [MFDB_SHGName] [varchar](75) NOT NULL,
    [MFDB_ShgMemberId] [int] NOT NULL,
    [MFDB_MemberName] [varchar](50) NOT NULL,
    [MFDB_LoanNumber] [int] NOT NULL,
    [MFDB_LoanAmount] [int] NOT NULL
    ) ON [PRIMARY]
    /* Drop and Create TempCollection Table. This table has all installments for a given member */
    ;WITH CTE_1 AS
    SELECT CT.MFDB_StateId AS StateId,
    CT.MFDB_RegionId AS RegionId,
    CT.MFDB_BranchId AS BranchId,
    CT.MFDB_SHGId AS ShgId,
    SM.MFDB_SHGName AS ShgName,
    CT.MFDB_SHGMemberId AS SHGMemberId,
    SMM.MFDB_MemberName AS MemberName,
    CT.MFDB_LoanNumber AS LoanNumber,
    LM.MFDB_LoanAmount AS LoanAmount
    FROM dbo.MFDB_COLLECTION_TXN CT
    LEFT JOIN dbo.MFDB_COLLECTION_AUDIT CA
    On CT.MFDB_SHGId = CA.MFDB_SHGId
    And CT.MFDB_MemberId = CA.MFDB_MemberId
    And CT.MFDB_LoanNumber = CA.MFDB_LoanNumber
    And CT.MFDB_CollectionId = CA.MFDB_CollectionId
    And CT.MFDB_LSourceId = CA.MFDB_LSourceId
    INNER JOIN dbo.MFDB_SHG_MASTER SM
    On CT.MFDB_SHGId = SM.MFDB_SHGId
    INNER JOIN dbo.MFDB_SHGMEMBER_MASTER SMM
    On CT.MFDB_SHGId = SMM.MFDB_SHGId
    And CT.MFDB_SHGMemberId = SMM.MFDB_SHGMemberId
    INNER JOIN dbo.MFDB_LOANAPPLICATION_MASTER LM
    ON LM.MFDB_SHGId = CT.MFDB_SHGId
    AND LM.MFDB_ShgMemberId = CT.MFDB_ShgMemberId
    AND LM.MFDB_LoanNumber = CT.MFDB_LoanNumber
    Where DATEDIFF(DAY,MFDB_CollectionDate,@i_DayOpenDate) = 0
    And CT.MFDB_CollectionAmount > 0
    And CT.MFDB_CollApprovedBy IS NULL
    AND CT.MFDB_BranchId = @i_BranchId
    AND CT.MFDB_SHGId = @i_SHGId
    AND CT.MFDB_ShgMemberId = @i_SHGMemberId
    AND CT.MFDB_LoanNumber = @i_LoanNumber
    CTE_2 AS
    SELECT DISTINCT
    StateId,
    RegionId,
    BranchId,
    ShgId,
    ShgName,
    SHGMemberId,
    MemberName,
    LoanNumber,
    LoanAmount
    FROM CTE_1
    INSERT INTO #TEMPDCBCOLLECTION ([MFDB_StateId],[MFDB_RegionId],[MFDB_BranchId],[MFDB_SHGId],[MFDB_SHGName],[MFDB_ShgMemberId],[MFDB_MemberName],[MFDB_LoanNumber],[MFDB_LoanAmount])
    SELECT StateId,
    RegionId,
    BranchId,
    ShgId,
    ShgName,
    SHGMemberId,
    MemberName,
    LoanNumber,
    LoanAmount
    FROM CTE_2
    DECLARE DCBMonthCursor CURSOR FOR
    SELECT [MFDB_StateId],
    [MFDB_RegionId],
    [MFDB_BranchId],
    [MFDB_SHGId],
    [MFDB_SHGName],
    [MFDB_ShgMemberId],
    [MFDB_MemberName],
    [MFDB_LoanNumber],
    [MFDB_LoanAmount]
    FROM #TEMPDCBCOLLECTION
    OPEN DCBMonthCursor
    FETCH NEXT FROM DCBMonthCursor
    INTO @p_TempStateId ,
    @p_TempRegionId ,
    @p_TempBranchId ,
    @p_TempSHGId ,
    @p_TempSHGName ,
    @p_TempSHGMemberId ,
    @p_TempMemberName ,
    @p_TempLoanNumber ,
    @p_TempLoanAmount
    WHILE (@@FETCH_STATUS = 0)
    BEGIN
    Set @p_TotalInterest = 0
    Select @p_TotalInterest = SUM(MFDB_StdInterest) From MFDB_LOAN_DISBURSEMENT Where MFDB_SHGId = @p_TempSHGId And MFDB_ShgMemberId = @p_TempSHGMemberId And MFDB_LoanNumber = @p_TempLoanNumber
    ;With
    CTE_1 AS
    SELECT LM.MFDB_StateId AS StateId ,
    LM.MFDB_RegionId AS RegionId,
    LM.MFDB_BranchId AS BranchId,
    LM.MFDB_SHGId AS SHGId,
    SM.MFDB_SHGName AS SHGName,
    LM.MFDB_ShgMemberId AS SHGMemId,
    LM.MFDB_MemberName AS MemberName,
    SM.MFDB_VillageId AS VillageId,
    LM.MFDB_LoanNumber AS LoanNo,
    LM.MFDB_LoanAmount AS LoanAmount,
    LM.MFDB_DisburseDate AS DisbursedDate,
    ISNULL((SELECT LD.MFDB_DemandDate
    FROM dbo.MFDB_LOAN_DISBURSEMENT LD
    Where LD.MFDB_SHGId = LM.MFDB_SHGId
    And LD.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    And LD.MFDB_LoanNumber = LM.MFDB_LoanNumber
    And DATEDIFF(DAY,LD.MFDB_DemandDate,@i_DayOpenDate) = 0
    And LD.MFDB_ApprovalStatus = 1 ),NULL) AS DemandDate,
    ISNULL((SELECT TOP 1 CT.MFDB_CollectionDate
    FROM dbo.MFDB_COLLECTION_TXN CT
    Inner Join dbo.MFDB_COLLECTION_AUDIT CA
    On CT.MFDB_SHGId = CA.MFDB_SHGId
    And CT.MFDB_ShgMemberId = CA.MFDB_ShgMemberId
    And CT.MFDB_LoanNumber = CA.MFDB_LoanNumber
    And CT.MFDB_LSourceId = CA.MFDB_LSourceId
    And CT.MFDB_CollectionId = CA.MFDB_CollectionId
    WHERE CT.MFDB_SHGId = LM.MFDB_SHGId
    AND CT.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    AND CT.MFDB_LoanNumber = LM.MFDB_LoanNumber
    And DATEDIFF(DAY,CT.MFDB_CollectionDate,@i_DayOpenDate) = 0
    ORDER BY CA.MFDB_CollectionId DESC),NULL) AS CollectionDate,
    ISNULL((SELECT TOP 1 CA.MFDB_InstallmentNumber
    FROM dbo.MFDB_COLLECTION_AUDIT CA
    Inner Join dbo.MFDB_COLLECTION_TXN CT
    On CT.MFDB_SHGId = CA.MFDB_SHGId
    And CT.MFDB_ShgMemberId = CA.MFDB_ShgMemberId
    And CT.MFDB_LoanNumber = CA.MFDB_LoanNumber
    And CT.MFDB_LSourceId = CA.MFDB_LSourceId
    And CT.MFDB_CollectionId = CA.MFDB_CollectionId
    WHERE CA.MFDB_SHGId = LM.MFDB_SHGId
    AND CA.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    AND CA.MFDB_LoanNumber = LM.MFDB_LoanNumber
    And DATEDIFF(DAY,CT.MFDB_CollectionDate,@i_DayOpenDate) = 0
    ORDER BY CA.MFDB_CollectionId DESC),
    ISNULL((SELECT LD.MFDB_InstallmentNumber
    FROM dbo.MFDB_LOAN_DISBURSEMENT LD
    Where LD.MFDB_SHGId = LM.MFDB_SHGId
    And LD.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    And LD.MFDB_LoanNumber = LM.MFDB_LoanNumber
    And DATEDIFF(DAY,LD.MFDB_DemandDate,@i_DayOpenDate) = 0
    And LD.MFDB_ApprovalStatus = 1 ),0)) AS IntallNo,
    ISNULL(CAST((SELECT TOP 1 NR.MFDB_BalancePrincipal
    FROM dbo.MFDB_NEW_DCB_REPORT NR
    WHERE NR.MFDB_SHGId = LM.MFDB_SHGId
    AND NR.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    AND NR.MFDB_LoanNumber = LM.MFDB_LoanNumber
    ORDER BY NR.MFDB_LedgerNumber DESC) AS NUMERIC(18,0)),0) AS ArrPrincipal,
    ISNULL(CAST((SELECT TOP 1 NR.MFDB_BalanceInterest
    FROM dbo.MFDB_NEW_DCB_REPORT NR
    WHERE NR.MFDB_SHGId = LM.MFDB_SHGId
    AND NR.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    AND NR.MFDB_LoanNumber = LM.MFDB_LoanNumber
    ORDER BY NR.MFDB_LedgerNumber DESC) AS NUMERIC(18,0)),0) AS ArrInterest,
    0 AS CurrDemandPrin,
    0 AS CurrDemandInt,
    ISNULL((SELECT CAST(SUM(ISNULL(CA.MFDB_CollectedPrincipal,0) +
    ISNULL(CA.MFDB_AdvancePrincipal,0) +
    ISNULL(CA.MFDB_ArrearPrincipal,0)) AS NUMERIC(18,0))
    FROM dbo.MFDB_COLLECTION_AUDIT CA
    Inner Join dbo.MFDB_COLLECTION_TXN CT
    On CT.MFDB_SHGId = CA.MFDB_SHGId
    And CT.MFDB_ShgMemberId = CA.MFDB_ShgMemberId
    And CT.MFDB_LoanNumber = CA.MFDB_LoanNumber
    And CT.MFDB_LSourceId = CA.MFDB_LSourceId
    And CT.MFDB_CollectionId = CA.MFDB_CollectionId
    WHERE CA.MFDB_SHGId = LM.MFDB_SHGId
    AND CA.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    AND CA.MFDB_LoanNumber = LM.MFDB_LoanNumber
    And DATEDIFF(DAY,CT.MFDB_CollectionDate,@i_DayOpenDate) = 0
    ),0) AS CurrCollPri,
    ISNULL((SELECT CAST(SUM(ISNULL(CA.MFDB_CollectedInterest,0) +
    ISNULL(CA.MFDB_AdvanceInterest,0) +
    ISNULL(CA.MFDB_ArrearInterest,0)) AS NUMERIC(18,0))
    FROM dbo.MFDB_COLLECTION_AUDIT CA
    Inner Join dbo.MFDB_COLLECTION_TXN CT
    On CT.MFDB_SHGId = CA.MFDB_SHGId
    And CT.MFDB_ShgMemberId = CA.MFDB_ShgMemberId
    And CT.MFDB_LoanNumber = CA.MFDB_LoanNumber
    And CT.MFDB_LSourceId = CA.MFDB_LSourceId
    And CT.MFDB_CollectionId = CA.MFDB_CollectionId
    WHERE CA.MFDB_SHGId = LM.MFDB_SHGId
    AND CA.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    AND CA.MFDB_LoanNumber = LM.MFDB_LoanNumber
    And DATEDIFF(DAY,CT.MFDB_CollectionDate,@i_DayOpenDate) = 0
    ),0) AS CurrCollInt,
    ISNULL(CAST((SELECT TOP 1 NR.MFDB_AdvCBPrincipal
    FROM dbo.MFDB_NEW_DCB_REPORT NR
    WHERE NR.MFDB_SHGId = LM.MFDB_SHGId
    AND NR.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    AND NR.MFDB_LoanNumber = LM.MFDB_LoanNumber
    ORDER BY NR.MFDB_LedgerNumber DESC) AS NUMERIC(18,0)),0) AS AdvOBPri,
    ISNULL(CAST((SELECT TOP 1 NR.MFDB_AdvCBInterest
    FROM dbo.MFDB_NEW_DCB_REPORT NR
    WHERE NR.MFDB_SHGId = LM.MFDB_SHGId
    AND NR.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    AND NR.MFDB_LoanNumber = LM.MFDB_LoanNumber
    ORDER BY NR.MFDB_LedgerNumber DESC) AS NUMERIC(18,0)),0) AS AdvOBInt,
    0 AS AdvCBPri,
    0 AS AdvCBInt,
    0 AS BalancePri,
    0 AS BalanceInt,
    ISNULL((SELECT CAST(SUM(ISNULL(CA.MFDB_CollectedPrincipal,0) +
    ISNULL(CA.MFDB_AdvancePrincipal,0) +
    ISNULL(CA.MFDB_ArrearPrincipal,0)) AS NUMERIC(18,0))
    FROM dbo.MFDB_COLLECTION_AUDIT CA
    Inner Join dbo.MFDB_COLLECTION_TXN CT
    On CT.MFDB_SHGId = CA.MFDB_SHGId
    And CT.MFDB_ShgMemberId = CA.MFDB_ShgMemberId
    And CT.MFDB_LoanNumber = CA.MFDB_LoanNumber
    And CT.MFDB_LSourceId = CA.MFDB_LSourceId
    And CT.MFDB_CollectionId = CA.MFDB_CollectionId
    WHERE CA.MFDB_SHGId = LM.MFDB_SHGId
    AND CA.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    AND CA.MFDB_LoanNumber = LM.MFDB_LoanNumber
    And DATEDIFF(DAY,CT.MFDB_CollectionDate,@i_DayOpenDate) >= 0
    ),0) AS OS_Pri,
    ISNULL((SELECT CAST(SUM(ISNULL(CA.MFDB_CollectedInterest,0) +
    ISNULL(CA.MFDB_AdvanceInterest,0) +
    ISNULL(CA.MFDB_ArrearInterest,0)) AS NUMERIC(18,0))
    FROM dbo.MFDB_COLLECTION_AUDIT CA
    Inner Join dbo.MFDB_COLLECTION_TXN CT
    On CT.MFDB_SHGId = CA.MFDB_SHGId
    And CT.MFDB_ShgMemberId = CA.MFDB_ShgMemberId
    And CT.MFDB_LoanNumber = CA.MFDB_LoanNumber
    And CT.MFDB_LSourceId = CA.MFDB_LSourceId
    And CT.MFDB_CollectionId = CA.MFDB_CollectionId
    WHERE CA.MFDB_SHGId = LM.MFDB_SHGId
    AND CA.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    AND CA.MFDB_LoanNumber = LM.MFDB_LoanNumber
    And DATEDIFF(DAY,CT.MFDB_CollectionDate,@i_DayOpenDate) >= 0
    ),0) AS OS_Int,
    0 AS RepaymentPercentage,
    LM.MFDB_LoanSchemeId AS LoanProduct,
    LM.MFDB_LActivityId AS LoanActivity,
    LM.MFDB_LActSpecId AS LoanSubActivity,
    LM.MFDB_FundingAgencyId AS FundAgencyId,
    LM.MFDB_LSourceId AS SourceId
    FROM dbo.MFDB_LOANAPPLICATION_MASTER LM
    Left Join dbo.MFDB_SHG_MASTER SM
    On SM.MFDB_ShgId = LM.MFDB_ShgId
    WHERE LM.MFDB_ApprovalStatus= 3
    AND LM.MFDB_DisburseDate IS NOT NULL
    AND LM.MFDB_StateId = @p_TempStateId
    AND LM.MFDB_RegionId = @p_TempRegionId
    AND LM.MFDB_BranchId = @p_TempBranchId
    AND LM.MFDB_SHGId = @p_TempSHGId
    AND LM.MFDB_ShgMemberId = @p_TempSHGMemberId
    AND LM.MFDB_LoanNumber = @p_TempLoanNumber
    CTE_2 AS
    SELECT StateId, RegionId, BranchId, SHGId, SHGName, SHGMemId, MemberName, VillageId , LoanNo, LoanAmount, DisbursedDate,DemandDate, CollectionDate, IntallNo,
    ArrPrincipal,
    ArrInterest,
    CurrDemandPrin,
    CurrDemandInt,
    ISNULL(ISNULL(ArrPrincipal,0) + ISNULL(CurrDemandPrin,0),0) AS TotDemandPri,
    ISNULL(ISNULL(ArrInterest,0) + ISNULL(CurrDemandInt,0),0) AS TotDemandInt,
    AdvOBPri,
    AdvOBInt,
    CurrCollPri,
    CurrCollInt,
    AdvCBPri,
    AdvCBInt,
    BalancePri,
    BalanceInt,
    ISNULL(ISNULL(LoanAmount,0) - ISNULL(OS_Pri,0),0) AS OS_Pri,
    ISNULL(ISNULL(@p_TotalInterest,0) - ISNULL(OS_Int,0),0) OS_Int,
    CONVERT(INT,RepaymentPercentage) AS RepaymentPercentage,
    LoanProduct,
    LoanActivity,
    LoanSubActivity,
    FundAgencyId,
    SourceId
    FROM CTE_1
    CTE_3 AS
    SELECT StateId, RegionId, BranchId, SHGId, SHGName, SHGMemId, MemberName, VillageId , LoanNo, LoanAmount, DisbursedDate,DemandDate, CollectionDate, IntallNo,
    ArrPrincipal,
    ArrInterest,
    CurrDemandPrin,
    CurrDemandInt,
    TotDemandPri,
    TotDemandInt,
    CASE WHEN AdvOBPri < 0 THEN AdvOBPri * -1 ELSE AdvOBPri END AS AdvOBPri,
    CASE WHEN AdvOBInt < 0 THEN AdvOBInt * -1 ELSE AdvOBInt END AS AdvOBInt,
    CurrCollPri,
    CurrCollInt,
    CASE WHEN ISNULL(TotDemandPri,0) = 0 THEN ISNULL((CurrCollPri + AdvOBPri),0)
    WHEN ISNULL(TotDemandPri,0) > 0 AND ISNULL(CurrCollPri + AdvOBPri,0) > ISNULL(TotDemandPri,0) THEN ISNULL(ISNULL(CurrCollPri + AdvOBPri,0) - ISNULL(TotDemandPri,0),0)
    WHEN ISNULL(TotDemandPri,0) > 0 AND ISNULL(CurrCollPri + AdvOBPri,0) < ISNULL(TotDemandPri,0) THEN 0
    WHEN ISNULL(CurrCollPri + AdvOBPri,0) = ISNULL(TotDemandPri,0) THEN 0
    ELSE 0 END AS AdvCBPri,
    CASE WHEN ISNULL(TotDemandInt,0) = 0 THEN ISNULL((CurrCollInt + AdvOBInt),0)
    WHEN ISNULL(TotDemandInt,0) > 0 AND ISNULL(CurrCollInt + AdvOBInt,0) > ISNULL(TotDemandInt,0) THEN ISNULL(ISNULL(CurrCollInt + AdvOBInt,0) - ISNULL(TotDemandInt,0),0)
    WHEN ISNULL(TotDemandInt,0) > 0 AND ISNULL(CurrCollInt + AdvOBInt,0) < ISNULL(TotDemandInt,0) THEN 0
    WHEN ISNULL(CurrCollInt + AdvOBInt,0) = ISNULL(TotDemandInt,0) THEN 0
    ELSE 0 END AS AdvCBInt,
    0 AS BalancePri,
    0 AS BalanceInt,
    OS_Pri,
    OS_Int,
    0 AS Repayment,
    LoanProduct,
    LoanActivity,
    LoanSubActivity,
    FundAgencyId,
    SourceId,
    CONVERT(CHAR(3), @i_DayOpenDate, 0) + ' - ' + RIGHT(CONVERT(CHAR(4), YEAR(@i_DayOpenDate)),2) AS Months
    FROM CTE_2
    INSERT INTO dbo.MFDB_NEW_DCB_REPORT
    ( [MFDB_TxnDate]
    ,[MFDB_StateId]
    ,[MFDB_RegionId]
    ,[MFDB_BranchId]
    ,[MFDB_SHGId]
    ,[MFDB_SHGName]
    ,[MFDB_ShgMemberId]
    ,[MFDB_MemberName]
    ,[MFDB_VillageId]
    ,[MFDB_LoanNumber]
    ,[MFDB_LoanAmount]
    ,[MFDB_DisbursedDate]
    ,[MFDB_DemandDate]
    ,[MFDB_CollectionDate]
    ,[MFDB_InstallmentNumber]
    ,[MFDB_ArrearPrincipal]
    ,[MFDB_ArrearInterest]
    ,[MFDB_DemandPrincipal]
    ,[MFDB_DemandInterest]
    ,[MFDB_TotDemandPrincipal]
    ,[MFDB_TotDemandInterest]
    ,[MFDB_AdvOBPrincipal]
    ,[MFDB_AdvOBInterest]
    ,[MFDB_CollectedPrincipal]
    ,[MFDB_CollectedInterest]
    ,[MFDB_AdvCBPrincipal]
    ,[MFDB_AdvCBInterest]
    ,[MFDB_BalancePrincipal]
    ,[MFDB_BalanceInterest]
    ,[MFDB_OS_Pri]
    ,[MFDB_OS_Int]
    ,[MFDB_RepaymentPercentage]
    ,[MFDB_LoanSchemeId]
    ,[MFDB_LActivityId]
    ,[MFDB_LActSpecId]
    ,[MFDB_FundAgencyId]
    ,[MFDB_LSourceId]
    ,[MFDB_Months]
    ,[MFDB_PanchayatId]
    ,[MFDB_PanchayatName]
    ,[MFDB_VillageName]
    SELECT @i_DayOpenDate ,StateId, RegionId, BranchId, SHGId, SHGName, SHGMemId, MemberName, VillageId , LoanNo, LoanAmount, DisbursedDate,DemandDate,CollectionDate,IntallNo,
    ArrPrincipal,ArrInterest,CurrDemandPrin,CurrDemandInt,TotDemandPri,TotDemandInt,AdvOBPri,AdvOBInt,CurrCollPri,CurrCollInt,
    CASE WHEN AdvCBPri < 0 THEN 0 ELSE AdvCBPri END,
    CASE WHEN AdvCBInt < 0 THEN 0 ELSE AdvCBInt END,
    CASE WHEN ISNULL(TotDemandPri,0) = 0 THEN 0
    WHEN ISNULL(TotDemandPri,0) > 0 AND ISNULL(CurrCollPri + AdvOBPri,0) > ISNULL(TotDemandPri,0) THEN 0
    WHEN ISNULL(TotDemandPri,0) > 0 AND ISNULL(CurrCollPri + AdvOBPri,0) < ISNULL(TotDemandPri,0) THEN ABS(ISNULL(ISNULL(CurrCollPri + AdvOBPri,0) - ISNULL(TotDemandPri,0),0) * -1)
    WHEN ISNULL(CurrCollPri + AdvOBPri,0) = ISNULL(TotDemandPri,0) THEN 0
    ELSE 0 END AS BalancePri,
    CASE WHEN ISNULL(TotDemandInt,0) = 0 THEN 0
    WHEN ISNULL(TotDemandInt,0) > 0 AND ISNULL(CurrCollInt + AdvOBInt,0) > ISNULL(TotDemandInt,0) THEN 0
    WHEN ISNULL(TotDemandInt,0) > 0 AND ISNULL(CurrCollInt + AdvOBInt,0) < ISNULL(TotDemandInt,0) THEN ABS(ISNULL(ISNULL(CurrCollInt + AdvOBInt,0) - ISNULL(TotDemandInt,0),0) * -1)
    WHEN ISNULL(CurrCollInt + AdvOBInt,0) = ISNULL(TotDemandInt,0) THEN 0
    ELSE 0 END AS BalanceInt,
    OS_Pri,
    OS_Int,
    0 AS Repayment,
    LoanProduct,LoanActivity,LoanSubActivity,FundAgencyId,SourceId,Months,@p_TempPanchayatId,@p_TempPanchayatName,@p_TempVillageName
    FROM CTE_3
    If @@Error != 0
    Begin
    Set @o_ErrorStatus = 1
    ROLLBACK TRANSACTION DCBGenerated
    RETURN
    End
    FETCH NEXT FROM DCBMonthCursor
    INTO @p_TempStateId ,
    @p_TempRegionId ,
    @p_TempBranchId ,
    @p_TempSHGId ,
    @p_TempSHGName ,
    @p_TempSHGMemberId ,
    @p_TempMemberName ,
    @p_TempLoanNumber ,
    @p_TempLoanAmount
    END
    CLOSE DCBMonthCursor
    DEALLOCATE DCBMonthCursor
    DELETE FROM #TEMPDCBCOLLECTION
    If @@Error != 0
    Begin
    Set @o_ErrorStatus = 1
    ROLLBACK TRANSACTION DCBGenerated
    RETURN
    End
    END
    COMMIT TRANSACTION DCBGenerated

  • How to give column heading for detailed list

    hi,
    we can get column-heading of basic list by text-element provided.
    but what are ways of giving column heading in detailed list ?

    HI,
    Based on the SY-LSIND value, you can have a different heading.
    top-of-page at line-selection.
    case sy-lsind.
    when 1.
    write:/ 'Heading for first list'.
    when 2.
    write:/ 'Heading for second list'.
    when 3.
    write:/ 'Heading for third list'.
    endcase.
    please see the link below it might help you
    http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/dba2eb35c111d1829f0000e829fbfe/content.htm
    *******please reward points if the information is helpful to you*************

  • Column header for file append ?

    My output txt file is getting appended eachtime. If i need to have my column header, everytime the data is appended the header is added as new line as well. I use parameter 'Data.addHeaderLine = 1' on my FCC.
    Current:
    H1                H2                  H3      
    8810             0000054270    0000166909 
    H1                H2                  H3
    5410         0000054072    A1857276
    Actual
    H1                H2                  H3
    8810             0000054270    0000166909 
    5410         0000054072    A1857276

    How is your outbound message structured ?
    Are these two messages which are getting appended on the receiving end. If it is, check the receiver file adapter, which has options to create a new file than appending to existing file.

  • Displaying dates as column headers for BEx Query

    Hi all,
    I have to display dates in sequence as descriptions for 15 columns based on the keyed in date in Bex Query Analyser. I'm able to display date as column heading for one column using text variable with replacement path.I could not able to increment date for other descriptions.Could you please help me to solve this issue.
    Ex: Input Date 05/09/2007 then in the out put column headers should be 0509 0609    0709   ............ 1909
    These are only column headers, values for the columns are quantities calculated using formulas.
    It is urgent.
    Thanks in advance.
    Regards,
    Mandadi.

    hi mandadi,
    if u want dates as headers only then u should use a text variable .
    as a rule u can not set off set for text variable so u create restricted key figure with date restricted and set off set.
    now u use this rkf to populate the text variable using replacement path.
    text variable can use replacement path for replacing from any variable and characteristics.
    bye

  • Single heading for Multiple columns in ALV

    Hi Experts,
          I need to display a common column heading for multiple columns in my ALV Grid Display output. I am giving the sample output here.
    MATNR...WERKS..| Unrestricted Stock|....|Stock in transfer        |....|Stock in Quality|.
    ............................| CAT | SAP  | Differe| .. |  CAT   |  SAP  | Diff   | .. | CAT   |  SAP  | Diff  |
    As I shown above, for 3 columns CAT, SAP, and for Difference, I need to get "Unrestricted Stock" as column heading... and so on...
    Pl. suggest me on this.
    Thanks in Advance
    Ramakrishna

    Hello Ramki,
    NOT POSSIBLE IN ALV AT ALL :-((
    You have to use classical report using WRITE stmts for this.
    If your client does not want to lose ALV functionalities, then you can try something like.
    Unrestricted Stock-SAP | Unrestricted Stock-CRM | Unrestricted Stock-Diff. Stock ... and so on !!!
    BR,
    Suhas
    Edited by: Suhas Saha on Jan 21, 2009 3:00 PM

Maybe you are looking for

  • Implementing BADI MD_ADD_COL_EZPS for MD04 custom column

    Hi there, I'm using BADI MD_ADD_COL_EZPS to display 3 new buttons and three new columns in MD04. For each line item that is displayed, the custom column is filled, after the button is hit -This works fine. My Question is: Is there any way to limit th

  • Can not create printer with my own ppd file

    I have a printer model that is not covered in Solaris Print Manager. I downloaded a foomatic-PPD file. Followed the steps (from Solaris 10 administration guide) to add printer. (lpfilter -f $ name -F $ filter didn't succeed, so I manually did lpfilte

  • IMac display monitor problems, left side darkens and flickers

    I have an iMac with 2.7 GHz Intel Core i5, 16 GB 1333 MHz DDR3,  AMD Radeon HD 6770M 512 MB running Mac OS X Lion 10.7.5 (11G63). The last year the left side of the monitor was flickering intermittingly. I didnt think much of it. Then in July, one bi

  • Issue with Internet Explorer on Lumia 920 Windows ...

    The built-in Internet Explorer browser can't handle drop-down menus. On touch, the options are shown, the menu rolls out, but when lifting finger, it rolls back instantly so you can't make a choice. If trying to move finger to the sub-menu, the entir

  • To position the cursor

    How to position the cursor at next item if i choose kod_kat_pkj = '2' then the cursor will go(jump to) to kod_ngra ( state) Begin --Job categories      begin           select initcap(nama)           into :lmd_pmk_pkj.kod_kat_pkjn_d           from lmd