Sort a tableview column containing a date

This is my second request to find more info on handling dates javafx2, no replies to the first so am trying again.
I am a relative "newby" to java, FX2 has so many compelling features I really want to use it.
Displaying and sorting on dates seems like such a fundamental requirement that I am surprised that I can't find any examples anywhere on handing dates in a tableview.
This would be so easy to do in Cocoa with the "date formatter" so apologies if I am missing something obvious.
If I use a formatted date the column sorts on the text not on the actual date.
eg. starting with
06/01/2012
08/01/2011
07/01/2012
sorting ascending gives
06/01/2012
07/01/2012
08/01/2011
and descending
08/01/2011
07/01/2012
06/01/2012
both wrong!
Same issue if I use a calendar in the cells.
Hope the answer is not to have a separate column for day, month and year.

Hi wornish,
TableView sort can be customized as per our needs. A sample example of Date is given here:
Currently Let's suppose that you are displaying data of "Date" in String form using SimpleDateFormat class.
TableView<Date> view = new TableView<Date>();
TableColumn<Date,String> col = new TableColumn<Date,String>("Date");
col.setComparator(new Comparator<String>(){
     @Override
     public int compare(String t, String t1) {
        try{
          SimpleDateFormat format =new SimpleDateFormat("MM-dd-YYYY");
          Date d1 =format.parse(t);               
          Date d2 = format.parse(t1);
          return Long.compare(d1.getTime(),d2.getTime());
        }catch(ParseException p){
             p.printStackTrace();
        return -1;
col.setCellValueFactory(new Callback<CellDataFeatures<Date, String>, ObservableValue<String>>() {
     @Override
     public ObservableValue<String> call(CellDataFeatures<Date, String> param) {
          SimpleDateFormat format = new SimpleDateFormat("MM-dd-YYYY");
          return new SimpleObjectProperty(format.format(param.getValue()));
        Thanks
Narayan

Similar Messages

  • How to use script to show how many columns contain no data

    I have a requirement. There is a source which is excel file, from this excel file we need to load data in staging table. There are 5 mandatory columns those should not be null. We have used 'No Data Check' for this. The logic is if any of the above mentioned 5 columns  do not contain any record the record will be moved to without data. Up to this it is fine. Now the requirement is to show which column/columns does/do not contain data. We have used a script for this purpose as:
    res=' '
    res=input1[0]+'  :Failed due to null values in mandatory columns';
    input1[1]=res;
    output1=res;
    But this is showing message as 'Failed due to null values in mandatory columns', which is a generic message. We need to show which column/columns does/do not contain value as 'Failed due to null values in mandatory column columnA, columnB, columnC'. Can anyone help me in this regard. Any kind of help is appreciated.

    You could use the variable inputname1, which holds an array of the input attribute names to the script processor. For example:
    var result = "";
    var first = true;
    for (i = 1; i < input1.length; i++) {
      if (input1[i] == null || input1[i] == "") {
        if (first) {
          first = false;
        } else {
          result += ", ";
        result += inputname1[i];
    if (result.length > 0) {
      result = "Failed due to null values in the following mandatory columns: " + result;
    output1 = result;
    Regards,
    Nick

  • Sorting by Multiple Columns in Numbers 3.0

    The new Numbers 3.0 update has moved some stuff around I need, and can not find. 
    Where is "Reorganize"?  The ability to sort multiple by columns.  (e.g. Sort Ascending Column A, THEN Column B, THEN Column C)
    mf

    this didn't work for me - i have item, then price, then checkbox. using the formula just gave an amalgamation of the three cells.
    Hi Saqib,
    The very idea of the workaround is to give an amalgamation, more often called "concatenation", and then just sort on the column containing the concatenated "string."
    As you've discovered, the =A&C&B formula only works if A,C, and B are all text. If you've got numbers in the mix then you have to pad them with leading zeros for them to sort as you want. That's easily done.
    Let's say C is a number and A and B are strings. You could put somethng like this in column D:
    =A&RIGHT("0000"&C,4)&B
    It's certainly not convenient to have to add a new column and put in a formula. But this is not *that* difficult as a workaround until the day multcolumn sort is added back in.
    SG

  • Sorting table view columns

    Hi ,
    In my application i want to sort specific tableview columns.When i am keeping Sort="server" .Now the hand point showing sort on every column.I wanted to restrict this to specific column.If you have information can you give how exactly sort option will work when sort by server and sort by application.
    Any weblogs available on sorting of tableview columns.
    Regards
    Usman

    Hi Usman,
    you can do this either with a tableview iterator or with the extension htmlb:tableviewcolumn.
    With the iterator you can change the behaviour of your columns in the method IF_HTMLB_TABLEVIEW_ITERATOR~GET_COLUMN_DEFINITIONS. The attribute P_COLUMN_DEFINITIONS is of type TABLEVIEWCONTROLTAB. With this attribute you can check "SORT" for a special column.
    With the extension htmlb:tableviewcolumn you can use the attribute SORT.
    Hoping this helps.
    Regards,
    Rainer

  • Conditional formating if the cell contains any date

    Hi,
    In my excel sheet i have one column containing only date (US format) or else they are blank. I want to format the cells containing date to Red color. How do i do it
    Please help

    If you mean the font colour, just format the cells to have red font.
    So I guess you mean interior colour.
    You haven't said which version of Excel - it always helps.
    For Excel 2003, for example, select the cells then
    Format > Conditional Formatting > Cell Value Is > Greater Than: 0 > Format > Patterns > Red
    For Excel 2007 or 2010, Home > Conditional Formatting > Highlight Cells Rules  > Greater Than > 0 with Light red fill
    Bill Manville. Excel MVP, Oxford, England. www.manville.org.uk

  • Functionality to dynamically sort tableview columns

    Has anybody successfully tried sorting columns of a tableview component by clicking on its header? I need to sort a column containing dates in mm/dd/yyyy format. Please share your hints or code. BR, Maulin

    Hi,
    Here is the code, no support included :-):
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.Vector;
    import com.sapportals.htmlb.table.DefaultTableViewModel;
    public class SortTableModel extends DefaultTableViewModel implements Comparator {
         protected int currCol;
         protected Vector ascendCol; // this vector stores the state (ascending or descending) of each column
         protected Integer one = new Integer(1);
         protected Integer minusOne = new Integer(-1);
         public SortTableModel() {
              super();
              ascendCol = new Vector();
         public SortTableModel(Vector vec) {
              super(vec);
              ascendCol = new Vector();
         public SortTableModel(Vector vec, Vector vec2, int numberOfColumns) {
              super(vec, vec2);
              ascendCol = new Vector();
              setSortOrder(numberOfColumns);
    This method is the implementation of the Comparator interface.
    It is used for sorting the rows
         public int compare(Object v1, Object v2) {
              // the comparison is between 2 vectors, each representing a row
              // the comparison is done between 2 objects from the different rows that are in the column that is being sorted
              int ascending = ((Integer)ascendCol.get(currCol)).intValue();
              if (v1 == null && v2 == null) {
                   return 0;
              } else if (v2 == null) { // Define null less than everything.
                   return 1 * ascending;
              } else if (v1 == null) {
                   return -1 * ascending;
              Object o1 = ((Vector)v1).get(currCol);
              Object o2 = ((Vector)v2).get(currCol);
              // If both values are null, return 0.
              if (o1 == null && o2 == null) {
                   return 0;
              } else if (o2 == null) { // Define null less than everything.
                   return 1 * ascending;
              } else if (o1 == null) {
                   return -1 * ascending;
              if (o1 instanceof Number && o2 instanceof Number) {
                   Number n1 = (Number)o1;
                   double d1 = n1.doubleValue();
                   Number n2 = (Number)o2;
                   double d2 = n2.doubleValue();
                   if (d1 == d2) {
                        return 0;
                   } else if (d1 > d2) {
                        return 1 * ascending;
                   } else {
                        return -1 * ascending;
              } else if (o1 instanceof Boolean && o2 instanceof Boolean) {
                   Boolean bool1 = (Boolean)o1;
                   boolean b1 = bool1.booleanValue();
                   Boolean bool2 = (Boolean)o2;
                   boolean b2 = bool2.booleanValue();
                   if (b1 == b2) {
                        return 0;
                   } else if (b1) {
                        return 1 * ascending;
                   } else {
                        return -1 * ascending;
              } else {
                   // default case
                   if (o1 instanceof Comparable && o2 instanceof Comparable) {
                        Comparable c1 = (Comparable)o1;
                        Comparable c2 = (Comparable)o2; // superflous cast, no need for it!
                        try {
                             return c1.compareTo(c2) * ascending;
                        } catch (ClassCastException cce) {
                             // forget it... we'll deal with them like 2 normal objects below.
                   String s1 = o1.toString();
                   String s2 = o2.toString();
                   return s1.compareTo(s2) * ascending;
    This method sorts the rows using Java's Collections class.
    After sorting, it changes the state of the column -
    if the column was ascending, its new state is descending, and vice versa.
         public void sort() {
              Collections.sort(dataVector, this);
              Integer val = (Integer)ascendCol.get(currCol);
              ascendCol.remove(currCol);
              if (val.equals(one)) // change the state of the column
                   ascendCol.add(currCol, minusOne);
              else
                   ascendCol.add(currCol, one);
         public void sortByColumn(int column) {
              this.currCol = column;
              sort();
         public void setSortOrder(int numberOfColumns) {
              for (int i = 0; i < numberOfColumns; i++) {
                   ascendCol.add(one);

  • Sort a tableview on a column

    Hi Experts,
    My question is I want to sort the tableview in the sales order screen containing the items based on a column.Now what standard has provided is that u can only sort on Item no or the Product and not on other fields which are not the key fields.How do I sort on any other column present in the table except the key columns.
    Thanks,
    Ashish.
    P.S.: I am working in SAP CRM 2007

    Hi,
    It can be definitely done like this.
      TRY.
          me->typed_context->CONTEXT NODE->collection_wrapper->sort( iv_attr_name
                                                                                    = 'XXX'
                                                                        iv_sort_order    = 'A' ).
          CATCH cx_crm_cic_parameter_error.
    ENDTRY.
    But the place where it is implemeted is important as some methods like DO_PREPARE_OUTPUT get triggered for all the Server Events.
    I prefer doing it in DO_INIT_CONTEXT rather than ON_NEW_FOCUS as it may not exist for some views and DO_INIT_CONTEXT  triggers only once by default.
    Regards,
    Masood Imrani S.

  • How can i open a PDF bank statement in numbers so that the rows and columns contain properly aligned data from statement?

    how can i open a PDF bank statement in "numbers" so that the rows and columns contain properly aligned data from statement?

    Numbers can store pdfs pages or clippings but does not directly open pdf files.  To get the bank statement into Numbers as a table I would open the bank statment in Preview (or Skim) or some pdf viewer.
    Then hold the option key while selecting a column of data.
    Then copy
    Then switch to numbers and paste the column into a table
    Then repeat for the other columns in the pdf document
    It would be easier (in my opinion) to download the QFX or CSV version from your bank

  • Can data be sorted by multiple columns in numbers version 3

    Since upgrading Numbers to version 3 (now 3.0.1) I have been unable to sort data in spreadsheets using multiple columns.  Anyone found a solution?
    Regards
    kurrajong60

    Here's a simple example. Say you want this sorted first by Region then by Name then by Amount.
    So if you set up a sort index column with a simple formula and all you have to do is this (two clicks):
    Giving you this:
    Of course you could do it as I think Hiroto is suggesting and manually sort first by column B, then sort by C, then sort by A.
    But that's a lot of trouble and it's easy to confuse the order so you end up having to start over again.
    SG

  • How to enforce always sorting on a column in a TableView?

    Hello,
    I have a requirement to always sort on a column in a TableView.
    So basically, I need a TableColumn's SortType go from Ascending to Descending and back to Ascedning when user clicks on a column header repeatedly.
    I guess that means making sure a TableView's SortOrder list is not empty. Am I right?
    I tried to listen to SortOrder list changes like below:
    tableView.getSortOrder().addListener(new ListChangeListener<TableColumn<String, ?>>() {
         @Override
         public void onChanged(final javafx.collections.ListChangeListener.Change<? extends TableColumn<String, ?>> arg0) {
    if (tableView.getSortOrder().size() > 0) {
                   // fine. nothing to do
              else {
    // add the removed column back
    Is this the right approach?
    I'm not sure how to use arg0 and add the removed column back.
    Can people with experience in this area provide some sample code?
    Thanks.

    The solution I came up with was to save the last column added to the SortOrder list to a map.
    Whenever the SortOrder list becomes empty, I add the last saved column back to the SortOrder list.
    That seems work.
    Edited by: 925616 on Aug 3, 2012 3:33 PM
    Edited by: 925616 on Aug 3, 2012 3:33 PM

  • Error changing data type to date in column containing blanks

    I am pulling data from an OLAP cube into PowerPivot. My data set contains several date columns wich are formatted as YYYY-MM-DD string values. After successfully importing the data, I am trying to set the data type of these columns to date.
    Apparently, when the column contains blank values, the conversion fails:
    The following system error occurred:  Type mismatch. Datatype conversion failed for [Table: 'SO fact table', Column: 'Shipping Date LastDateDate', Value: ''].
    When the column contains no blanks, the conversion succeeds.
    Would anyone have an idea for working around this issue ?
    Is there some MDX magic that I could use in my query in order to cast blank dates to something that PowerPivot would accept to convert, or to make the conversion to the date format right at the source ? 

    Hello,
    I did a quick test with data from Excel sheet formatted as text containing ISO date values with one blank value, in Power Pivot I then changed it to type "Date" and it works without an issue; so it must have an other reason:
    You can try to use the
    DAX function "DateValue" to convert the values
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • Data Grid - issues resizing width of columns and with data refresh and sort

    SQLDeveloper 1215 on Windows XP professional
    Database : various 9.2
    In the table data tab there are a few minor issues our developers have highlighted.
    1) There seems to be a minimum column width in the data display. This restricts flexibility in reviewing the data, esp. where the data length is less than the minimum column width.
    2) If a column is resized or the column order is changed and a refresh or a new filter is applied then the columns are restored to their original position and size making it frustrating to run more than one query via the GUI.
    3) There is no quick sort option by clicking on the column heading which would be useful.

    I am still seeing this minimum column width in SQL Developer production (v1467) and I haven't seen any other posts relating to this. I have seen this all of the grids that I have looked at, including all of the grid based sub-tabs for the Object tabs (ie Columns, Data, Indexes, Constraints, etc) and the SQL Worksheet results tab.
    It is very obvious with the Column Name and Data Type columns of the Table Columns tab - the Column Name column can be shrunk to truncate values but the Data Type column can only be shrunk to about the twice the width of the widest value.
    Can anyone in development provide any comments about why we have this minimum width and how the minimum width is actually calculated?

  • Check the column data contains alphanumeric data

    I want to retrieve the column data from the table if the column data contains alphanumeric data
    Ex: select column1 from table1 where column1 contains alphanumeric data.column1 is declared as varchar2.
    Is the any function defined to check for alphanumerics in sql query?
    Thanks!!

    Like this ?
    SQL>
    SQL>  WITH Sample_Data AS (SELECT '3874' col FROM DUAL UNION ALL
      2                        SELECT '74' col FROM DUAL UNION ALL
      3                        SELECT '123' col FROM DUAL UNION ALL
      4                        SELECT '22FRE' col FROM DUAL UNION ALL
      5                        SELECT 'ABCD' col FROM DUAL UNION ALL
      6                        SELECT 'AB33FRE' col FROM DUAL
      7                         )
      8   SELECT col from Sample_data
      9    WHERE REGEXP_LIKE(col,'[[:alpha:]]')
    10    AND REGEXP_INSTR(col,'[0-9]')>0;
    COL
    22FRE
    AB33FRE
    SQL>

  • Query to sort a column containing alphanumeric values

    Hi,
    I have a table whose column contains ALPHANUMERIC values. The column is of type VARCHAR(1).
    I tried many queries (using UNION) to fetch records in Alphabets first and Numbers as last
    I.e. A-Z should come first and then 0-9 values.
    Please do the needful
    Regards,
    Mradul

    I.e. A-Z should come first and then 0-9 values.Edit: Whoops, I forgot the ascii values for numbers were lower.
    WITH t AS
    (SELECT '0' c FROM DUAL
      UNION
    SELECT '9' c FROM DUAL
      UNION
    SELECT 'A' c FROM DUAL
      UNION
    SELECT 'B' c FROM DUAL
    SELECT c
      FROM t
    ORDER BY TRANSLATE( UPPER(c)
                       , 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
                       , 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
         , TRANSLATE( UPPER(c)
                    , '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
                    , '0123456789'
    C
    A
    B
    0
    9Message was edited by:
    vg

  • Alv list contains no data

    I am working with a custom table zscs_record.
    data is being fetched in the perform upload_workarea.
    but the list contains no data.
    there might be any problem with the display_log.
    if anybody plz can find where is the mistake full points will be rewarded.
    just copy the program and execute it.
    REPORT yreport1 LINE-SIZE 260
    NO STANDARD PAGE HEADING
    MESSAGE-ID zsc_supply_chain.
              T Y P E -  P O O L S                           *
    TYPE-POOLS: SLIS.
          C o n s t a n t    V A R I A B L E S                  *
    CONSTANTS: c_e                TYPE  char1        VALUE  'E',
               c_a                TYPE  char1        VALUE  'A',
               c_s                TYPE  char1        VALUE  'S',
               c_x                TYPE  char1        VALUE  'X',
               c_dynpro_0201(4)   TYPE  c            VALUE  '0201',
               c_prognam(12)      TYPE  c            VALUE  'SAPRCKM_MR22',
               c_dynpro_1000(4)   TYPE  c            VALUE  '1000',
               c_dynpro_0120(4)   TYPE  c            VALUE  '0120',
               c_okcode(10)       TYPE  c            VALUE  'BDC_OKCODE',
               c_entr(5)          TYPE  c            VALUE  '=ENTR',
               c_dummy(6)         TYPE  c            VALUE  '=DUMMY',
               c_down(5)          TYPE  c            VALUE  '=DOWN',
               c_save(5)          TYPE  c            VALUE  '=SAVE',
               c_back(5)          TYPE  c            VALUE  '=BACK',
               c_onli(5)          TYPE  c            VALUE  '=ONLI',
               c_ee(3)            TYPE  c            VALUE  '/EE',
               c_one              TYPE  ckml_kongr   VALUE  '1'   ,
               c_bkpf(4)          TYPE  c            VALUE  'BKPF',
               c_wfp              TYPE  bukrs        VALUE  'WFP',
               c_sa               TYPE  blart        VALUE  'SA',
               c_ags              TYPE  ktosl        VALUE  'AGS',
               c_usd              TYPE  waers_iso    VALUE  'USD',
               c_budat(14)        TYPE  c            VALUE  'MR21HEAD-BUDAT',
               c_bukrs(14)        TYPE  c            VALUE  'MR21HEAD-BUKRS',
               c_werks(14)        TYPE  c            VALUE  'MR21HEAD-WERKS',
               c_xblnr(14)        TYPE  c            VALUE  'MR21HEAD-XBLNR',
               c_kongr(14)        TYPE  c            VALUE  'CKMLKONT-KONGR',
               c_bktxt(14)        TYPE  c            VALUE  'MR21HEAD-BKTXT',
               c_mr22             TYPE  tstc-tcode   VALUE  'MR22',
               c_f13              TYPE  tstc-tcode   VALUE  'F.13',
               c_n(1)             TYPE  c            VALUE  'N',
               c_bag              TYPE  char9        VALUE  '%Bagging%',
               c_ltsh             TYPE  char12       VALUE  '%LTSH%Clear%',
               c_trnsf            TYPE  char30       VALUE  '%Transformation%Clear%',
               c_ste              TYPE  char20       VALUE  '%Stevedoring%Clear%',
               c_mat              TYPE  char30       VALUE  '%Material%Revaluation',
               c_mat1             TYPE  char8        VALUE  'MATERIAL',
               c_rev              TYPE  char10       VALUE  'REVOLUTION',
               c_tabname          TYPE  tabname      VALUE  'ZSCT_RECORD',
               c_prognam3(7)      TYPE  c            VALUE  'SAPF124',
               c_prognam4(8)      TYPE  c            VALUE  'SAPMSSY0',
               c_cursor(10)       TYPE  c            VALUE  'BDC_CURSOR',
               c_konts_low(9)     TYPE  c            VALUE  'KONTS-LOW',
               c_bukrx_low(9)     TYPE  c            VALUE  'BUKRX-LOW',
               c_saknr(7)         TYPE  c            VALUE  'X_SAKNR',
               c_augdt(5)         TYPE  c            VALUE  'AUGDT',
               c_testl(5)         TYPE  c            VALUE  'TESTL',
               c_xausbel(7)       TYPE  c            VALUE  'XAUSBEL',
               c_xnausbel(8)      TYPE  c            VALUE  'XNAUSBEL',
               c_fehler(8)        TYPE  c            VALUE  'X_FEHLER',
               c_mr21(23)         TYPE  c            VALUE  'MR21HEAD-SCREEN_VARIANT',
               c_lagmat(18)       TYPE  c            VALUE  'LAGERMATERIAL_0250',
               c_psp(30)          TYPE  c            VALUE  'PSP-ELEMENT - OHNE BWKEY_0250',
               c_ckmatnr(20)      TYPE  c            VALUE  'CKI_MR22_0250-MATNR(',
               c_ckzuumb(20)      TYPE  c            VALUE  'CKI_MR22_0250-ZUUMB(',
               c_ckpspnr(20)      TYPE  c            VALUE  'CKI_MR22_0250-PSPNR(',
               c_ckbwkey(20)      TYPE  c            VALUE  'CKI_MR22_0250-BWKEY(',
               c_sp(1)            TYPE  c            VALUE  ')',
               c_shkzg1           TYPE  shkzg        VALUE 'H',
               c_shkzg2           TYPE  shkzg        VALUE 'S',
    *For ALV column positions
            c_col_pos1            TYPE            sycucol             VALUE '01',
            c_col_pos2            TYPE            sycucol             VALUE '02',
            c_col_pos3            TYPE            sycucol             VALUE '03',
            c_col_pos4            TYPE            sycucol             VALUE '04',
            c_col_pos5            TYPE            sycucol             VALUE '05',
            c_col_pos6            TYPE            sycucol             VALUE '06',
            c_col_pos7            TYPE            sycucol             VALUE '07',
            c_col_pos8            TYPE            sycucol             VALUE '08',
            c_col_pos9            TYPE            sycucol             VALUE '09',
            c_col_pos10           TYPE            sycucol             VALUE '10',
            c_col_pos11           TYPE            sycucol             VALUE '11',
            c_col_pos12           TYPE            sycucol             VALUE '12',
            c_col_pos13           TYPE            sycucol             VALUE '13',
            c_col_pos14           TYPE            sycucol             VALUE '14',
            c_col_pos15           TYPE            sycucol             VALUE '15',
    *For ALV Field Names of final Table
            c_fld_recid           TYPE            slis_fieldname      VALUE  'RECID',          "Record ID number
            c_fld_kongr           TYPE            slis_fieldname      VALUE  'KONGR',          "Reason code
            c_fld_hkont           TYPE            slis_fieldname      VALUE  'HKONT',          "GL Account
            c_fld_projk           TYPE            slis_fieldname      VALUE  'PROJK',          "Project code
            c_fld_werks           TYPE            slis_fieldname      VALUE  'WERKS',          "Plant
            c_fld_matnr           TYPE            slis_fieldname      VALUE  'MATNR',          "Commodity
            c_fld_zcptp           TYPE            slis_fieldname      VALUE  'ZCPTP',          "Cose portion to be posted
            c_fld_zerrf           TYPE            slis_fieldname      VALUE  'ZERRF',          "Success flag
            c_fld_zerrc           TYPE            slis_fieldname      VALUE  'ZERRC',          "Error code
            c_fld_zertx           TYPE            slis_fieldname      VALUE  'ZERTX',          "Error txt
            c_fld_hkont1          TYPE            slis_fieldname      VALUE  'HKONT',
            c_fld_opbal           TYPE            slis_fieldname      VALUE  'OPBAL',
            c_fld_exp             TYPE            slis_fieldname      VALUE  'EXP',
            c_fld_cap             TYPE            slis_fieldname      VALUE  'CAP',
            c_fld_err             TYPE            slis_fieldname      VALUE  'ERR',
            c_table               TYPE            slis_tabname        VALUE  'i_log_disp'.
    *T Y P E S                                                            *
    *Structure for uploading the data for further processing
    TYPES: BEGIN OF t_zscs_record ,
               recid      TYPE zderecid,                       "Record id number
               zerrf      TYPE zdeerrf,                        "Processed \ not processed flag - FLAG X Success Blank
               cpudt      TYPE cpudt,                          "Day On Which Accounting Document Was Entered
               kongr      TYPE ckml_kongr,                     "Account Assignment Reason
               hkont      TYPE hkont,                          "General Ledger Account
               projk      TYPE char30,                          "WBS Element
               werks      TYPE werks_d,                        "Plant
               matnr      TYPE matnr,                          "Material Number
               zcptp      TYPE zdecptp,                        "cost portion to be posted
               belnr      TYPE belnr_d,                        "Accounting Document Number
               zerrc      TYPE zdeerrc,                        "Error code
               zertx      TYPE zdeertx,                        "Error text
               set        TYPE numc2,
           END OF t_zscs_record ,
    *Structre for modified WBS element
           BEGIN OF t_zscs_record_m ,
               recid      TYPE zderecid,                       "Record id number
               zerrf      TYPE zdeerrf,                        "Processed \ not processed flag - FLAG X Success Blank
               cpudt      TYPE cpudt,                          "Day On Which Accounting Document Was Entered
               kongr      TYPE ckml_kongr,                     "Account Assignment Reason
               hkont      TYPE hkont,                          "General Ledger Account
               projk      TYPE char24,
               werks      TYPE werks_d,                        "Plant
               matnr      TYPE matnr,                          "Material Number
               zcptp      TYPE zdecptp,                        "cost portion to be posted
               belnr      TYPE belnr_d,                        "Accounting Document Number
               zerrc      TYPE zdeerrc,                        "Error code
               zertx      TYPE zdeertx,                        "Error text
               set        TYPE numc2,
           END OF t_zscs_record_m,
    *Structure for retrieving data from custom table ZSCT_AUTOINV
           BEGIN OF t_zsct_autoinv,
               saknr      TYPE saknr,                          "G/L Account Number
               fipos      TYPE fm_fipex,                       "Commitment Item
               geber      TYPE bp_geber,                       "Fund
               saknr_off  TYPE saknr,                          "G/L Account Number
               fipos_off  TYPE fm_fipex,                       "Commitment Item
           END OF t_zsct_autoinv,
    *Structure for retrieving data from database table FMBDT
           BEGIN OF t_fmbdt,
               rldnr      TYPE rldnr,                          "Ledger
               rrcty      TYPE rrcty,                          "Record Type
               rvers      TYPE versn,                          "Version
               ryear      TYPE gjahr,                          "Fiscal Year
               robjnr     TYPE gobjnr_r,                       "Object number for objects (account assignment elements)
               cobjnr     TYPE gobjnr_c,                       "Object number for transaction attributes
               sobjnr     TYPE gobjnr_s,                       "Object number for partner objects (accnt assignmnt elements)
               rtcur      TYPE rtcur,                          "Currency Key
               drcrk      TYPE shkzg,                          "Debit/Credit Indicator
               rpmax      TYPE rpmax,                          "period
               rfund      TYPE fm_fund,                        "Fund
               rfundsctr  TYPE fistl,                          "Funds Center
               rmeasure   TYPE fm_measure,                     "Funded Program
           END OF t_fmbdt,
    *Structure for retrieveing data from table SKAT
           BEGIN OF t_skat,
               spras      TYPE spras,                          "Language Key
               ktopl      TYPE ktopl,                          "Chart of Accounts
               saknr      TYPE saknr,                          "G/L Account Number
               txt50      TYPE txt50_skat,                     "G/L Account Long Text
           END OF  t_skat,
    *Structure for tracking the errors occured during document posting
    *through standard BAPI
           BEGIN OF t_error_bapi,
               number     TYPE symsgno,
               message    TYPE bapi_msg,
               recid      TYPE zderecid,
               set        TYPE numc2,
           END OF t_error_bapi,
    *Structure for tracking the success occured during document posting
    *through standard BAPI
           BEGIN OF t_suc_bapi,
               belnr      TYPE belnr_d,
               message    TYPE bapi_msg,
               recid      TYPE zderecid,
               set        TYPE numc2,
           END OF t_suc_bapi,
    *Structure for tracking the errors occured during document posting
    *through MR22 transaction code
            BEGIN OF t_error_bdc,
               recid      TYPE zderecid,                       "Record id number
               number     TYPE symsgno,
               message    TYPE bapi_msg,
               set        TYPE numc2,
           END OF t_error_bdc,
    *Structure for tracking the document no. occured during successful posting
    *through MR22 transaction code
             BEGIN OF t_suc_bdc,
               recid      TYPE zderecid,                       "Record id number
               var        TYPE sy-msgv1,
               message    TYPE bapi_msg,
               set        TYPE numc2,
             END OF t_suc_bdc,
             BEGIN OF t_log_disp,
             recid      TYPE  zderecid,                       "Record id number
             kongr      TYPE  ckml_kongr,                     "Account Assignment Reason
             hkont      TYPE  hkont,                          "General Ledger Account
             projk      TYPE  char30,                         "WBS Element
             werks      TYPE  werks_d,                        "Plant
             matnr      TYPE  matnr,                          "Material Number
             zcptp      TYPE  zdecptp,                        "cost portion to be posted
             zerrf      TYPE  zdeerrf,                        "Processed \ not processed flag - FLAG X Success Blank
             zerrc      TYPE  zdeerrc,                        "Error code
             zertx      TYPE  zdeertx,                        "Error text
             hkont1     TYPE  hkont,
             opbal      TYPE  dmbtr,
             exp        TYPE  dmbtr,
             cap        TYPE  dmbtr,
             err        TYPE  dmbtr,
             END OF  t_log_disp.
    *Field symbols declared for BAPIRET2
    FIELD-SYMBOLS: <fs_return> TYPE bapiret2.
          G l o b a l   W O R K A R E A S                                     *
    DATA: w_zscs_record     TYPE t_zscs_record,
          w_zscs_record_mod TYPE t_zscs_record,
          w_fmbdt           TYPE t_fmbdt,
          w_bapi            TYPE t_zscs_record,
          w_bdc             TYPE t_zscs_record,
          w_temp            TYPE t_zscs_record,                 "#EC NEEDED
          w_bapiheader      TYPE bapiache09,
          w_return          TYPE bapiret2,
          w_accoutgl        TYPE bapiacgl09,
          w_currency        TYPE bapiaccr09,
          w_bdcdata         TYPE bdcdata,
          w_messtab         TYPE bdcmsgcoll,
          w_error_bapi      TYPE t_error_bapi,
          w_suc_bapi        TYPE t_suc_bapi,
          w_error_bdc       TYPE t_error_bdc,
          w_suc_bdc         TYPE t_suc_bdc,
          w_fieldcatalog    TYPE slis_fieldcat_alv,           "Workarea for populating fieldcatalog
          w_log_disp        TYPE t_log_disp.
            I n t e r n a l   T a b l e s                                     *
    DATA: i_zscs_record     TYPE  STANDARD TABLE OF t_zscs_record,
          i_zscs_record1    TYPE  STANDARD TABLE OF t_zscs_record,
          i_bapi            TYPE  STANDARD TABLE OF t_zscs_record,
          i_bdc             TYPE  STANDARD TABLE OF t_zscs_record,
          i_fmbdt           TYPE  STANDARD TABLE OF t_fmbdt,
          i_accoutgl        TYPE  STANDARD TABLE OF bapiacgl09,
          i_currency        TYPE  STANDARD TABLE OF bapiaccr09,
          i_return          TYPE  STANDARD TABLE OF bapiret2,
          i_bdcdata         TYPE  STANDARD TABLE OF bdcdata INITIAL SIZE 0,
          i_messtab         TYPE  STANDARD TABLE OF bdcmsgcoll INITIAL SIZE 0,
          i_bdcdata1        TYPE  STANDARD TABLE OF bdcdata INITIAL SIZE 0,
          i_messtab1        TYPE  STANDARD TABLE OF bdcmsgcoll INITIAL SIZE 0,"#EC NEEDED
          i_autoinv         TYPE  STANDARD TABLE OF t_zsct_autoinv,
          i_autoinv1        TYPE  STANDARD TABLE OF t_zsct_autoinv,
          i_error_bapi      TYPE  STANDARD TABLE OF t_error_bapi,
          i_suc_bapi        TYPE  STANDARD TABLE OF t_suc_bapi,
          i_error_bdc       TYPE  STANDARD TABLE OF t_error_bdc,
          i_suc_bdc         TYPE  STANDARD TABLE OF t_suc_bdc,
          i_fieldcatalog    TYPE  slis_t_fieldcat_alv,
          i_log_disp        TYPE STANDARD TABLE OF t_log_disp.              "internal table for final log display
          G l o b a l   V A R I A B L E S                                     *
    DATA: v_rec          TYPE      string,
          v_rec1         TYPE      string,
          v_count        TYPE      numc2    VALUE 1,
          v_flag         TYPE      char1,                                "#EC NEEDED
          v_subrc        TYPE      sysubrc,
          v_objkey       TYPE      awkey,
          v_amt          TYPE      zdecptp,
          v_txt50        TYPE      txt50_skat,
          v_pspid        TYPE      ps_pspid,                             "#EC NEEDED
          v_totexppe     TYPE      zdecptp,
          v_totcapit     TYPE      zdecptp,
          v_toterror     TYPE      zdecptp,
          v_todmbtr      TYPE      dmbtr,
          v_repid        TYPE      sy-repid.
          S E L E C T I O N - S C R E E N   D E F I N I T I O N          *
                     S E L E C T I O N - S C R E E N                     *
    *Begin of inv selection block
    SELECTION-SCREEN BEGIN OF BLOCK inv WITH FRAME TITLE text-001.
    PARAMETERS: p_pstdat  TYPE budat DEFAULT sy-datum,                               "Posting Date
                p_rtmode AS CHECKBOX DEFAULT c_x,                                    "Run in test mode
                p_prsall RADIOBUTTON GROUP rad DEFAULT 'X' USER-COMMAND com,         "Process All
                p_cstcpt RADIOBUTTON GROUP rad,                                      "Process cost to be capitalized
                p_cstexp RADIOBUTTON GROUP rad,                                      "Process cost to be expensed
                p_exauto AS CHECKBOX.                                                "Execute Automatic Clearing
    SELECTION-SCREEN END OF BLOCK inv.
    *End of inv selection block
           I N I T I A L I Z A T I O N                                        *
    INITIALIZATION.
    Subroutine for clearing the memory space
      PERFORM clear_memory.                                                          "To clear the memory space.
           A T   S E L E C T I O N - S C R E E N  O U T P U T                 *
    AT SELECTION-SCREEN OUTPUT.
    For checking the Clearing program through transaction code F.13 only
    when user selects the radio button Process All
      IF p_prsall = c_x.                                           "Process All
        p_exauto = c_x.                                            "Execute Automatic Clearing
      ELSE.
        p_exauto = ' '.                                            "Execute Automatic Clearing
      ENDIF.
      MODIFY SCREEN.
                              START OF SELECTION              *
    START-OF-SELECTION.
    Subroutine for uploading data from custom database table
    ZSCT_RECORD based on the condition selected by user
      PERFORM upload_workarea.
                              END OF SELECTION                 *
    END-OF-SELECTION.
    Subroutine for populating the respective internal tables
    for posting the documents either through standard BAPI or MR22 transaction code
      PERFORM populate_bapi_bdc.
      IF NOT i_bapi[] IS INITIAL.
    Subroutine for posting documents through standard BAPI
        PERFORM post_bapi.
      ENDIF.
    IF NOT i_bdc[] IS INITIAL.
    Subroutine for posting documents through MR22 transaction code
        PERFORM call_transaction_mr22.
      ENDIF.
    Subroutine for automatic clearing
      IF p_exauto = c_x.
        PERFORM clear_f13.
      ENDIF.
    IF ( ( i_error_bapi IS NOT INITIAL ) OR ( i_error_bdc IS NOT INITIAL ) ).
    Subroutine for displaying the log file
      PERFORM display_log.
    ENDIF.
      PERFORM FINAL_list.
    *&      Form  CLEAR_MEMORY
          text
    form CLEAR_MEMORY.
    Refreshing the global internal tables
      REFRESH: i_zscs_record,
               i_zscs_record1,
               i_bapi,
               i_bdc,
               i_fmbdt,
               i_accoutgl,
               i_currency,
               i_return,
               i_bdcdata,
               i_messtab,
               i_bdcdata1,
               i_messtab1,
               i_autoinv,
               i_error_bapi,
               i_suc_bapi,
               i_error_bdc,
               i_suc_bdc.
    Clearing the global work areas
      CLEAR:   w_zscs_record,
               w_zscs_record_mod,
               w_fmbdt,
               w_bapi,
               w_bdc,
               w_temp,
               w_bapiheader,
               w_return,
               w_accoutgl,
               w_currency,
               w_bdcdata,
               w_messtab,
               w_error_bapi,
               w_suc_bapi,
               w_error_bdc,
               w_suc_bdc,
    *Clearing the global variables
               v_rec,
               v_rec1,
               v_flag,
               v_subrc,
               v_objkey,
               v_amt,
               v_pspid.
    endform.                    " CLEAR_MEMORY
    *&      Form  UPLOAD_WORKAREA
       Subroutine for uploading data from custom database table          *
          ZSCT_RECORD based on the condition selected by user            *
    form UPLOAD_WORKAREA .
      IF p_prsall = c_x.
    Selecting the non processed data from table ZSCT_RECORD
        SELECT  recid                                       "#EC CI_NOFIRST         "Record id number
                zerrf                                                               "Processed\not processed flag
                cpudt                                                               "Day On Which Accounting Document Was Entered
                kongr                                                               "Account Assignment Reason
                hkont                                                               "General Ledger Account
                projk                                                               "WBS Element
                werks                                                               "Plant
                matnr                                                               "Material Number
                zcptp                                                               "cost portion to be posted
                belnr                                                               "Accounting Document Number
                zerrc                                                               "Error code
                zertx                                                               "Error text
        FROM zsct_record
        INTO TABLE i_zscs_record
        WHERE zerrf NE space
        AND cpudt = '20081022'.
        IF sy-subrc NE 0.
          MESSAGE  text-021 TYPE 'I'.
          LEAVE LIST-PROCESSING.
        ENDIF.
      ELSEIF p_cstcpt = c_x.
    Selecting the non processed data from table ZSCT_RECORD
        SELECT  recid                                       "#EC CI_NOFIRST
                zerrf
                cpudt
                kongr
                hkont
                projk
                werks
                matnr
                zcptp
                belnr
                zerrc
                zertx
        FROM zsct_record
        INTO TABLE i_zscs_record
        WHERE zerrf NE space
        AND   kongr <> c_e.
        IF sy-subrc NE 0.
          MESSAGE  text-021 TYPE 'I'.
          LEAVE LIST-PROCESSING.
        ENDIF.
      ELSEIF p_cstexp = c_x.
    Selecting the non processed data from table ZSCT_RECORD
        SELECT  recid                                        "#EC CI_NOFIRST
                zerrf
                cpudt
                kongr
                hkont
                projk
                werks
                matnr
                zcptp
                belnr
                zerrc
                zertx
        FROM zsct_record
        INTO TABLE i_zscs_record
        WHERE zerrf NE space
        AND   kongr EQ c_e.
        IF sy-subrc NE 0.
          MESSAGE  text-021 TYPE 'I'.
          LEAVE LIST-PROCESSING.
        ENDIF.
      ENDIF.
      IF sy-subrc = 0.
    Sort the internal table by record id
        SORT i_zscs_record BY recid.
      ENDIF.
    endform.                    " UPLOAD_WORKAREA
    *&      Form  POPULATE_BAPI_BDC                   *
    Subroutine for posting documents through standard BAPI   *
    FORM populate_bapi_bdc.
      DATA: v_tabix TYPE sy-tabix.
    Sort the data retrieved from ZSCT_RECORD by KONGR,HKONT & PROJK
      SORT i_zscs_record BY kongr hkont projk.
      IF NOT i_zscs_record IS INITIAL.
        LOOP AT i_zscs_record INTO w_zscs_record_mod.
          v_tabix = sy-tabix.
      Check if the record id is initial
          IF NOT w_zscs_record_mod-recid IS INITIAL.
            CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
              EXPORTING
                input  = w_zscs_record_mod-recid
              IMPORTING
                output = w_zscs_record-recid.
          ENDIF.
      Check if the reason code is initial
          IF NOT w_zscs_record_mod-kongr IS INITIAL.
            CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
              EXPORTING
                input  = w_zscs_record_mod-kongr
              IMPORTING
                output = w_zscs_record-kongr.
          ENDIF.
      Assign the values
          w_zscs_record-hkont = w_zscs_record_mod-hkont.
          CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT'
            EXPORTING
              input  = w_zscs_record_mod-projk
            IMPORTING
              output = w_zscs_record-projk.
          w_zscs_record-werks = w_zscs_record_mod-werks.
          w_zscs_record-matnr = w_zscs_record_mod-matnr.
          w_zscs_record-zcptp = w_zscs_record_mod-zcptp.
          w_zscs_record-cpudt = w_zscs_record_mod-cpudt.
      Concatenate  KONGR,HKONT & PROJK value to make an unique combination to populate the separete
      internal table relevant for posting through BAPI and MR22 transaction
          CONCATENATE w_zscs_record-kongr w_zscs_record-hkont w_zscs_record-projk INTO v_rec.
          IF v_tabix NE 1.
            IF v_rec1 = v_rec.
              v_count = v_count.                                "#EC NEEDED
            ELSE.
              v_count = v_count + 1.
            ENDIF.
          ENDIF.
      Populate the set number into the two different internal table
      relevant for posting through BAPI and MR22 transaction
          w_zscs_record-set = v_count.
      If the KONGR (Reason code) value is equal to 'E' then the
      posting will be occur through standard BAPI
          IF w_zscs_record-kongr = c_e.
            APPEND w_zscs_record TO i_bapi.
      If the KONGR (Reason code) value is not equal to 'E' then the
      posting will be occur through MR22 transaction code
          ELSEIF w_zscs_record-kongr NE c_e.
            APPEND w_zscs_record TO i_bdc.
          ENDIF.
          v_rec1 = v_rec.
      Clear the memory
          CLEAR: w_zscs_record,
                 v_rec.
        ENDLOOP.
      ENDIF.
    endform.                    " POPULATE_BAPI_BDC
    *&      Form  POST_BAPI
          text
    form POST_BAPI .
    Local structre declaration
      TYPES:
          Structre for populating record id
            BEGIN OF lt_recid,
              recid TYPE zderecid,
             END OF   lt_recid,
           Structre for table PRPS
             BEGIN OF lt_prps,
              pspnr      TYPE ps_intnr,           "WBS Element
              posid      TYPE ps_posid,           "Work Breakdown Structure Element (WBS Element)
              pgsbr      TYPE ps_pgsbr,           "Business area for WBS element
              func_area  TYPE fkber,              "Functional Area
             END OF lt_prps .
    Local data declaration
      DATA: lw_bapi    TYPE t_zscs_record,
            lw_bapi1   TYPE t_zscs_record,
            lw_recid   TYPE lt_recid,
            li_recid   TYPE STANDARD TABLE OF lt_recid,         "#EC NEEDED
            li_prps    TYPE STANDARD TABLE OF lt_prps,
            lw_prps    TYPE lt_prps,
            li_temp    TYPE STANDARD TABLE OF t_zscs_record,
            li_temp1   TYPE STANDARD TABLE OF t_zscs_record,
            li_bapi    TYPE STANDARD TABLE OF t_zscs_record,
            li_bapi_m  TYPE STANDARD TABLE OF t_zscs_record_m,
            lw_bapi_m  TYPE t_zscs_record_m,
            li_skat    TYPE STANDARD TABLE OF t_skat,
            li_skat1   TYPE STANDARD TABLE OF t_skat,
            li_skat2   TYPE STANDARD TABLE OF t_skat,
            lw_temp    TYPE t_zscs_record,
            li_autoinv TYPE STANDARD TABLE OF t_zsct_autoinv,
            lw_autoinv TYPE t_zsct_autoinv,
            lv_count   TYPE numc10,
            lw_skat    TYPE t_skat,
            lw_skat1   TYPE t_skat,                             "#EC NEEDED
            lw_skat2   TYPE t_skat,                             "#EC NEEDED
            lv_count1  TYPE numc10,
            lw_index   TYPE sy-index.
    Assigning the I_BAPI data to a local internal table
      li_temp[] = i_bapi[].
      li_bapi[] = i_bapi[].
      li_temp1[] = i_bapi[].
    Sort the internal table by SET
      SORT i_bapi BY set.
    Sort the internal table LI_TEMP by SET
      SORT li_temp BY set.
    Delete adjacent duplicates from LI_TEMP compring SET
      DELETE ADJACENT DUPLICATES FROM li_temp COMPARING set.
    Sort the internal table LI_TEMP1 by PROJK
      SORT li_temp1 BY projk.
    Delete adjacent duplicates from LI_TEMP1 compring PROJK
      DELETE ADJACENT DUPLICATES FROM li_temp1 COMPARING projk.
    Sort the internal table LI_BAPI by HKONT
      SORT li_bapi BY hkont.
    Delete adjacent duplicates from LI_BAPI compring HKONT
      DELETE ADJACENT DUPLICATES FROM li_bapi COMPARING hkont.
    Check if the li_bapi is initial or not
      IF NOT li_bapi[] IS INITIAL.
    Retrieve the text information from database table SKAT
    for all the G/L Account relevant to LTSH Overland Clearing Account/
    Transformation Clearing / Stevedoring Clearing Account / Bagging Clearing Account
        SELECT  spras                                     "#EC CI_SGLSELECT
                ktopl
                saknr
                txt50
          FROM skat
          INTO TABLE li_skat
          FOR ALL ENTRIES IN li_bapi
          WHERE spras = c_e
          AND   saknr = li_bapi-hkont
           AND ( txt50 LIKE c_bag
             OR  txt50 LIKE c_ltsh
             OR  txt50 LIKE c_trnsf
             OR  txt50 LIKE c_ste
             OR  txt50 LIKE c_mat ).
        IF sy-subrc EQ 0.
          SORT li_skat1 BY saknr.
        ENDIF.
    Spiliting the internal table with respect to the TXT50
        LOOP AT li_skat INTO lw_skat.
          v_txt50 = lw_skat-txt50.
          TRANSLATE v_txt50 TO UPPER CASE.                    "#EC SYNTCHAR
          IF v_txt50 CS c_mat1 AND
             v_txt50 CS c_rev.
         Internal table regaring all the G/L Account relevant to Material revolution Account
            APPEND lw_skat TO li_skat2.
          ELSE.
         Internal table regaring all the G/L Account relevant to LTSH Overland Clearing Account/
         Transformation Clearing / Stevedoring Clearing Account / Bagging Clearing Account
            APPEND lw_skat TO li_skat1.
          ENDIF.
          CLEAR: lw_skat,
                 v_txt50.
        ENDLOOP.
        REFRESH: li_skat.
      Retrieve required data from custom table ZSCT_AUTOINV
        SELECT saknr
               fipos
               geber
               saknr_off
               fipos_off
          FROM zsct_autoinv
          INTO TABLE li_autoinv
           FOR ALL ENTRIES IN li_bapi
           WHERE saknr = li_bapi-hkont.
        IF sy-subrc = 0.
      Sort li_autoinv by GEBER
          i_autoinv1 = li_autoinv.
          SORT li_autoinv BY geber.
      Delete adjacent duplicates from li_autoinv comparing GEBER
          DELETE ADJACENT DUPLICATES FROM li_autoinv COMPARING geber.
        ENDIF.
        IF NOT li_autoinv[] IS INITIAL.
      Retrieve required data from database table FMBDT
          SELECT  rldnr
                  rrcty
                  rvers
                  ryear
                  robjnr
                  cobjnr
                  sobjnr
                  rtcur
                  drcrk
                  rpmax
                  rfund
                  rfundsctr
                  rmeasure
            FROM fmbdt                                      "#EC CI_NOFIRST
          INTO TABLE i_fmbdt
          FOR ALL ENTRIES IN li_autoinv
          WHERE ryear = p_pstdat+0(4)
          AND   rfund = li_autoinv-geber.
        ENDIF.
        IF sy-subrc = 0.
          SORT i_fmbdt BY rfund.
        ENDIF.
      ENDIF.
    Populate the internal table with the modified WBS element
    value for further processing
      LOOP AT i_bapi INTO w_bapi.
        lw_bapi_m-recid = w_bapi-recid.
        lw_bapi_m-zerrf = w_bapi-zerrf.
        lw_bapi_m-cpudt = w_bapi-cpudt.
        lw_bapi_m-kongr = w_bapi-kongr.
        lw_bapi_m-hkont = w_bapi-hkont.
        lw_bapi_m-projk = w_bapi-projk.
        lw_bapi_m-werks = w_bapi-werks.
        lw_bapi_m-matnr = w_bapi-matnr.
        lw_bapi_m-zcptp = w_bapi-zcptp.
        lw_bapi_m-belnr = w_bapi-belnr.
        lw_bapi_m-zerrc = w_bapi-zerrc.
        lw_bapi_m-zertx = w_bapi-zertx.
        lw_bapi_m-set   = w_bapi-set.
        APPEND lw_bapi_m TO li_bapi_m.
        CLEAR: lw_bapi_m.
      ENDLOOP.
    Sort LI_BAPI_M by WBS element
      SORT li_bapi_m BY projk.
    Delete adjacent duplicates from LI_BAPI_M comparing WBS element
      DELETE ADJACENT DUPLICATES FROM li_bapi_m COMPARING projk.
    Check if LI_BAPI_M is initial
      IF NOT li_bapi_m[] IS INITIAL.
    Retrieve the required data from table PRPS for all the
    WBS element
        SELECT  pspnr
                posid
                pgsbr
                func_area
           FROM prps
           INTO TABLE li_prps
           FOR ALL ENTRIES IN li_bapi_m
           WHERE posid = li_bapi_m-projk.
        IF sy-subrc = 0.
          SORT li_prps BY posid.
        ENDIF.
      ENDIF.
      lw_index = 1.
      LOOP AT li_temp INTO lw_temp.
        w_temp = lw_temp.
      clearing workares
        CLEAR: w_bapiheader,
               lv_count,
               v_amt.
    ****Populating the BAPIHEADER*******
      Reference Transaction
        w_bapiheader-bus_act    = c_bkpf.
      User Name
        w_bapiheader-username   = sy-uname.
      Document Header Text
        w_bapiheader-header_txt = text-020.
      Company Code
        w_bapiheader-comp_code  = c_wfp.
      Document Date in the Document
        w_bapiheader-doc_date   = p_pstdat.
      Posting Date in the Document
        w_bapiheader-pstng_date = p_pstdat.
      Fiscal Year
        w_bapiheader-fisc_year  = p_pstdat+0(4).
      Fiscal Period
        w_bapiheader-fis_period = p_pstdat+4(2).
      Document Type
        w_bapiheader-doc_type   = c_sa.
      Reference Document Number
        w_bapiheader-ref_doc_no = sy-datum.
      Initialize the counter
        lv_count = 1.
        lv_count1 = 1.
        LOOP AT i_bapi INTO lw_bapi FROM lw_index.
          IF lw_temp-set NE lw_bapi-set.
            lw_index = sy-tabix.
            EXIT.
          ELSE.
            lw_bapi1 = lw_bapi.
            CLEAR: v_pspid.
            READ TABLE li_prps INTO lw_prps WITH KEY posid = lw_bapi-projk BINARY SEARCH.
            IF sy-subrc = 0.
              w_accoutgl-bus_area    = lw_prps-pgsbr.
              w_accoutgl-func_area   = lw_prps-func_area.
            ENDIF.
    *****Populating the internal table regarding G/L account item***********
            w_accoutgl-itemno_acc  = lv_count.
            w_accoutgl-acct_key    = c_ags.
            w_accoutgl-acct_type   = c_s.
            w_accoutgl-grant_nbr   = text-019.
            w_accoutgl-wbs_element = lw_bapi-projk.
            READ TABLE i_autoinv1  INTO lw_autoinv WITH KEY saknr = lw_bapi-hkont.
            IF sy-subrc = 0.
          Get the information for the G/L accounts relevant for LTSH OVERland Clearing account or
          Transformation Clearing Account Stevedoring Clearing Account or Bagging Clearing Account
              READ TABLE li_skat1 INTO lw_skat1 WITH KEY saknr = lw_autoinv-saknr BINARY SEARCH.
              IF sy-subrc = 0.
                w_accoutgl-gl_account  = lw_bapi-hkont.
                IF NOT lw_autoinv-fipos EQ space.
                  CALL FUNCTION 'CONVERSION_EXIT_FMCIS_INPUT'
                    EXPORTING
                      input  = lw_autoinv-fipos
                    IMPORTING
                      output = w_accoutgl-cmmt_item.
                ELSE.
                  w_accoutgl-cmmt_item   = lw_autoinv-saknr.
                ENDIF.
                w_currency-amt_doccur   =  lw_bapi-zcptp * ( -1 ).
              ENDIF.

    Debug. and find the problem . since you are not using the standadrd tables , they are custom tables. so try to find the reason using debugging. may be you don't have data which satisfies the selection criteria.

Maybe you are looking for