DECODE function to validate date value and sort the records

Hi Friends,
I am looking for some query which can give me the required output,
I need to do this using SQL query only and I have tried using the MIN() and MAX() functions it was working fine with limited data, now after inserting the last record(in the below table) which has date for start_range and end_range in(mm/dd/yyyy hh24:mi:ss) format.
Because the data type is VARCHAR2 if I am using the MIN() function it is sorting as a string value, hence the min date is incorrect. I tried using validating the value to date or non date and tried to using MIN() and MAX() functions using the DECODE function, I am getting this error "ORA-01840: input value not long enough for date format".
select table_name,
DECODE(substr(START_RANGE,3,1)||substr(START_RANGE,6,1)||substr(START_RANGE,11,1)||substr(START_RANGE,14,1)||substr(START_RANGE,17,1),'// ::',
to_char(min(to_date(start_range,'mm/dd/yyyy hh24:mi:ss')),'MM/DD/YYYY HH24:MI:SS'),min(start_range)) MIN_RUNS_START_RANGE,
DECODE(substr(END_RANGE,3,1)||substr(A.END_RANGE,6,1)||substr(END_RANGE,11,1)||substr(END_RANGE,14,1)||substr(END_RANGE,17,1),'// ::',
to_char(max(to_date(END_RANGE,'mm/dd/yyyy hh24:mi:ss')),'MM/DD/YYYY HH24:MI:SS'),max(END_RANGE)) MAX_RUNS_END_RANGE
from MY_TABLE
GROUP BY table_name,
(substr(START_RANGE,3,1)||substr(START_RANGE,6,1)||substr(START_RANGE,11,1)||substr(START_RANGE,14,1)||substr(START_RANGE,17,1)),
(substr(END_RANGE,3,1)||substr(END_RANGE,6,1)||substr(END_RANGE,11,1)||substr(END_RANGE,14,1)||substr(END_RANGE,17,1))
Can sombody please advise what is the best way I can query this data with the required output.
The following are the source table and records and the out put records using the sql query.
MY_TABLE
TABLE_NAME(VARCHAR2),START_RANGE(VARCHAR2),END_RANGE(VARCHAR2)
TABLE1,1000,10000
TABLE2,ABCD,EEEE
TABLE3,01/12/2010 00:00:00,12/31/2010 23:59:59
TABLE1,10001,20000
TABLE2,EEEF,GGGG
TABLE3,01/01/2011 00:00:00,01/31/2011 23:59:59
OUTPUT :
TABLE_NAME,MIN(START_RANGE),MAX(END_RANGE)
TABLE1,1000,20000
TABLE2,ABCD,GGGG
TABLE3,01/12/2010 00:00:00,01/31/2011 23:59:59
Thanks
Kalycs

i also think this is a very bad table design ...
but if you are not able to change it, you could split the select (date and non-date data) and combine the result with UNION like this:
with t as
SELECT 'TABLE1' table_name,'1000' start_range,'10000' end_range FROM dual UNION
SELECT 'TABLE2','ABCD','EEEE' FROM dual UNION
SELECT 'TABLE3','01/12/2010 00:00:00','12/31/2010 23:59:59' FROM dual UNION
SELECT 'TABLE1','10001','20000' FROM dual UNION
SELECT 'TABLE2','EEEF','GGGG' FROM dual UNION
SELECT 'TABLE3','01/01/2011 00:00:00','01/31/2011 23:59:59' FROM dual
SELECT table_name,
       TO_CHAR(MIN(TO_DATE(start_range, 'MM/DD/YYYY HH24:MI:SS')), 'MM/DD/YYYY HH24:MI:SS'),
       TO_CHAR(MAX(TO_DATE(end_range, 'MM/DD/YYYY HH24:MI:SS')), 'MM/DD/YYYY HH24:MI:SS')
FROM t
WHERE start_range LIKE '%/%/%:%:%'
GROUP BY table_name
UNION
SELECT table_name,
       MIN(start_range),
       MAX(end_range)
FROM t
WHERE start_range NOT LIKE '%/%/%:%:%'
GROUP BY
    table_name;
TABLE_ MIN_VALUE           MAX_VALUE
TABLE1 1000                20000
TABLE2 ABCD                GGGG
TABLE3 01/12/2010 00:00:00 01/31/2011 23:59:59

Similar Messages

  • How to insert the Formatted date value and insert into the database

    Hi All,
    I am having requirement of inserting the date value in to the datbase. I'm already getting the value from file as MM-DD-YYYY. Getting exception while transforming the values through the transform activity. I'm using format fate function but it is inserting null value in to the database.
    Any help from anyone would bve appreciated.
    Thanks,
    CH

    Hi,
    your input date format is fixed right? So, in the transform you can split each your date, which is in 'MM-DD-YYYY' format ... extract day, month, year.
    After that ... just put these values in order acording to the format of 'xsd:date' data type which is '[-]CCYY-MM-DDZ'.
    XPath function 'xp20:format-dateTime()' works only with 'xsd:dateTime' data type, which has format '[-]CCYY-MM-DDThh:mm:ssZ'.
    So, in your case it could be:
    <xsl:variable name="day" select="substring($inputDate,4,2)"/>
    <xsl:variable name="month" select="substring($inputDate,1,2)"/>
    <xsl:variable name="day" select="substring($inputDate,7,4)"/>
    <xsl:variable name="outputDate">
    <xsl:value-of select="$year"/>
    <xsl:text>-</xsl:text>
    <xsl:value-of select="$month"/>
    <xsl:text>-</xsl:text>
    <xsl:value-of select="$day"/>
    </xsl:variable>
    Regards,
    Martin.

  • Dsiplay data values and data lables in a stacked column chart

    Hi All
    Is there a way to display data values and data labels in a stacked column chart. Mouse over or display of labels in legends wont help. It has to be in the chart .
    Regards,
    anshul

    Hi Anshul,
    You can display either data value or data label in a stacked column chart by checking the Data Label Displaying Mode option under Format Chart->Data Values.
    You can also do the same by checking the same option under Format chart->Area Display->Data Values.
    I dont think you would be able to display both in a column chart whereas you would be able to do it in a pie chart.
    Hope this helps.
    Regards
    Sri Harsha

  • I have prepared a personal budget and sorted the planned expenses by month, but the months are out of order. How do I correct?

    I have prepared a personal budget and sorted the planned expenses by month, but they are out of order. How do I correct?

    David,
    You've got to give us something to go on here. At least post a screen shot so we can see how your data is arranged. I suspect that you may have named the months with text strings rather than as actual Date values, so when you sort they are in alphabetical order rather than date order.
    Jerry

  • How to retrieve the procedure value and pass the value to a form field

    How to retrieve the procedure value and pass the value to a form field?

    Set property for the field and the value is the actual procedure/function.
    Cheers

  • This field contains duplicate values. Remove all duplicate values and try the operation again.

    Greetings Everyone,
    I am getting the follow up errors: "This field contains duplicate values. Remove all duplicate values and try the operation again."
    when I tried to make the field "Claim Number" from the list in site collection library. See the screen below:
    1- I selected on the "List" and I clicked on the list name
    "Claim Tracking Report"
    2- After I clicked on the list name then I went to the ribbon and selected list setting to choose Enforce Unique for the Field Column
    "Claim Number"
    3- Then I went down and selected
    "Yes" to Enforced the Unique for the Field Column "Claim Number".
    4- Then after I clicked "Yes" I got the error
    "Sorry, something went wrong. This field contains duplicate values. Remove all duplicate values and try the operation again."  But I don't have any duplicates values Items, because I had them removed before I tried
    to Enforce the field column values to Unique. Can someone help or provide me a suggestions on how I can solve this issue please. Thank you
    FYI: I am using a Nintex Workflow

    Hope this is a list, how many total items are there?
    Please try to open this list as access(link in IE) and run this query in access
    SELECT Claim.[Claim Number], Count(*) AS Expr1
    FROM Claim
    GROUP BY Claim.[Claim Number]
    HAVING (((Count(*))>1));
    Hope it will show something! if this does not show you dups then better to create a separate list and migrate items after configuring unique column.
    Please 'propose as answer' if it helped you, also 'vote helpful' if you like this reply.

  • Comparing two internal tables and deleting the record not present in second

    Hi All,
    I have a internal table itaba with PERNR as primary key and various other columns (1000 records) and table B with PERNR as primary key and 800 records.
    Now what is the best way to compare these two and delete the record from table A when its corresponding record is not present in table B?
    Thanks and Regards,
    Mohan

    HI SIR
    u trained us in accenture
    Hi all
    when ever m running this session in SM35 , M getting error as :
    "LEAVE TO TRANSACTION" MARA-BISMT is not allow
    in batch input
    REPORT YASEC_BDC_NIK_SESSION
    no standard page heading
    message-id zmm
    line-count 65
    line-size 150.
    tables : mara.
    *Top includr program
    INCLUDE YNEW_MAIN_TOP.
    *include yasec_bdc_nik_session_top.
    ***********selection screen *******************
    selection-screen begin of block b1 with frame title text-001.
    selection-screen skip.
    PARAMETERS: p_ifile(128) TYPE c .
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
    PARAMETERS: rad1 TYPE c RADIOBUTTON GROUP 1 USER-COMMAND gr1,
    rad2 TYPE c RADIOBUTTON GROUP 1 .
    SELECTION-SCREEN SKIP.
    PARAMETERS: p_sess TYPE c.
    SELECTION-SCREEN END OF BLOCK b2.
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN END OF BLOCK b1.
    Subroutine call***************************
    INCLUDE YNEW_MAIN_F01.
    *include yasec_bdc_nik_session_f01.
    *********At selection event triggered *************
    at selection-screen on value-request for p_ifile.
    To get F4 help for the input file path
    PERFORM f_f4_input_file.
    AT SELECTION-SCREEN ON p_ifile.
    To validate and upload the input file
    PERFORM f_load_file.
    AT SELECTION-SCREEN ON p_sess.
    To validate the Number of Sessions field
    IF rad2 IS NOT INITIAL AND sy-ucomm EQ c_onli.
    PERFORM f_check_sessions.
    ENDIF.
    ***********Start of selection *******************
    start-of-selection.
    *To process BDC
    PERFORM f_process_bdc.
    TOP OF PAGE
    TOP-OF-PAGE.
    Writes the report heading and for displaying line number.
    PERFORM f_report_header.
    TYPES : BEGIN OF t_final,
    matnr(50) TYPE c,
    bismt(18) type c,
    end of t_final.
    TYPES: BEGIN OF t_fdata,
    data(256) TYPE c,
    END OF t_fdata.
    TYPES: BEGIN OF t_error,
    message(100) TYPE c,
    END OF t_error.
    *Internal table declarations
    *Internal table to load the data from the file that is changed throgh BDC
    DATA : i_final TYPE STANDARD TABLE OF t_final,
    wa_final TYPE t_final.
    *Internal table to store the error messages
    DATA : i_error TYPE STANDARD TABLE OF t_error,
    wa_error TYPE t_error.
    *Internal table to load the raw data
    DATA : i_fdata TYPE STANDARD TABLE OF t_fdata,
    wa_fdata TYPE t_fdata.
    *Internal table to store records of BDC
    DATA : i_bdcdata TYPE STANDARD TABLE OF bdcdata INITIAL SIZE 0,
    wa_bdcdata TYPE bdcdata.
    Internal table to store BDC messages
    DATA: i_bdcmsgcoll TYPE STANDARD TABLE OF bdcmsgcoll INITIAL SIZE 0,
    wa_bdcmsgcoll TYPE bdcmsgcoll.
    VARIABLE DECLARATIONS
    DATA: v_ifile TYPE string,
    v_input TYPE i,
    c_delimiter TYPE c VALUE 'X',
    v_mode TYPE c VALUE 'A',
    v_sessions TYPE i.
    CONSTANTS
    CONSTANTS : c_flagx TYPE c VALUE 'X',
    c_slash TYPE c VALUE '/',
    c_onli(4) TYPE c VALUE 'ONLI',
    c_vl02(4) TYPE c VALUE 'VL02',
    c_s TYPE c VALUE 'A'.
    FORM f_f4_input_file .
    CALL FUNCTION 'F4_FILENAME'
    EXPORTING
    program_name = syst-cprog
    dynpro_number = syst-dynnr
    IMPORTING
    file_name = p_ifile.
    ENDFORM. " f_f4_input_file
    *& Form f_load_file
    FORM f_load_file .
    v_ifile = p_ifile.
    CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
    filename = v_ifile
    filetype = 'ASC'
    has_field_separator = 'X'
    TABLES
    data_tab = i_fdata
    EXCEPTIONS
    file_open_error = 1
    file_read_error = 2
    no_batch = 3
    gui_refuse_filetransfer = 4
    invalid_type = 5
    no_authority = 6
    unknown_error = 7
    bad_data_format = 8
    header_not_allowed = 9
    separator_not_allowed = 10
    header_too_long = 11
    unknown_dp_error = 12
    access_denied = 13
    dp_out_of_memory = 14
    disk_full = 15
    dp_timeout = 16
    OTHERS = 17.
    IF sy-subrc <> 0.
    *Text-103-Input file does not exist.
    MESSAGE e000 WITH text-103 .
    ELSEIF NOT i_fdata IS INITIAL.
    DELETE i_fdata WHERE data = space.
    DESCRIBE TABLE i_fdata LINES v_input.
    ENDIF.
    IF v_input EQ 0.
    Text-104 - Input file is empty.
    MESSAGE e000 WITH text-104 .
    ENDIF.
    ENDFORM. " f_load_file
    *& Form f_check_sessions
    FORM f_check_sessions .
    IF p_sess IS INITIAL.
    MESSAGE e000 WITH text-106.
    ELSE.
    v_sessions = v_input DIV p_sess.
    ENDIF.
    ENDFORM. " f_check_sessions
    *& Form f_process_bdc
    text
    FORM f_process_bdc.
    LOOP AT i_fdata INTO wa_fdata.
    SPLIT wa_fdata AT cl_abap_char_utilities=>horizontal_tab
    INTO wa_final-matnr
    wa_final-bismt.
    APPEND wa_final TO i_final.
    CLEAR wa_fdata.
    ENDLOOP.
    IF rad1 = c_flagx.
    PERFORM f_passbdc_vl02.
    ELSEIF rad2 = c_flagx.
    PERFORM f_sessions_vl02.
    ENDIF.
    ENDFORM. "f_process_bdc
    To populate the Screen information
    p_program Program Name
    p_dynpro Screen Number
    FORM bdc_dynpro USING p_program TYPE any
    p_dynpro TYPE any.
    CLEAR wa_bdcdata.
    Populate the BDC structure with the Screen Information.
    Move the Program name PROGRAM
    wa_bdcdata-program = p_program.
    Move the Screen Number DYNPRO
    wa_bdcdata-dynpro = p_dynpro.
    Indicate the beginning of a new screen
    wa_bdcdata-dynbegin = c_flagx.
    APPEND wa_bdcdata TO i_bdcdata.
    ENDFORM. "f_bdc_dynpro
    *& Form f_passbdc_vl02
    text
    FORM f_passbdc_vl02.
    DATA: l_lines_im TYPE i.
    SORT i_final BY matnr ASCENDING.
    CLEAR wa_final.
    LOOP AT i_final INTO wa_final.
    CLEAR: i_bdcmsgcoll[],
    wa_bdcmsgcoll,
    wa_bdcdata.
    CLEAR: i_bdcdata[].
    perform bdc_dynpro using 'SAPLMGMM' '0060'.
    perform bdc_field using 'BDC_CURSOR'
    'RMMG1-MATNR'.
    perform bdc_field using 'BDC_OKCODE'
    '/00'.
    perform bdc_field using 'RMMG1-MATNR'
    wa_final-matnr.
    perform bdc_dynpro using 'SAPLMGMM' '0070'.
    perform bdc_field using 'BDC_CURSOR'
    'MSICHTAUSW-DYTXT(01)'.
    perform bdc_field using 'BDC_OKCODE'
    '=ENTR'.
    perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
    'X'.
    perform bdc_dynpro using 'SAPLMGMM' '4004'.
    perform bdc_field using 'BDC_OKCODE'
    '/00'.
    perform bdc_field using 'BDC_CURSOR'
    'MARA-BISMT'.
    perform bdc_field using 'MARA-BISMT'
    wa_final-bismt.
    perform bdc_dynpro using 'SAPLSPO1' '0300'.
    perform bdc_field using 'BDC_OKCODE'
    '=YES'.
    perform bdc_transaction using 'MM02'.
    perform bdc_dynpro using 'SAPLMGMM' '0060'.
    perform bdc_field using 'BDC_CURSOR'
    'RMMG1-MATNR'.
    perform bdc_field using 'BDC_OKCODE'
    '/00'.
    perform bdc_dynpro using 'SAPLMGMM' '0070'.
    perform bdc_field using 'BDC_CURSOR'
    'MSICHTAUSW-DYTXT(01)'.
    perform bdc_field using 'BDC_OKCODE'
    '=ENTR'.
    perform bdc_dynpro using 'SAPLMGMM' '4004'.
    perform bdc_field using 'BDC_OKCODE'
    '/00'.
    perform bdc_field using 'BDC_CURSOR'
    'RMMG1-MATNR'.
    perform bdc_dynpro using 'SAPLSPO1' '0300'.
    perform bdc_field using 'BDC_OKCODE'
    '=YES'.
    perform bdc_transaction using 'MM03'.
    CALL TRANSACTION 'MM02' USING i_bdcdata
    MODE v_mode
    UPDATE c_s
    MESSAGES INTO i_bdcmsgcoll.
    If error occurred in call transaction 'VA02' then stores all
    information of failed records into internal table i_error_im.
    IF sy-subrc NE 0.
    DESCRIBE TABLE i_bdcmsgcoll LINES l_lines_im.
    CLEAR wa_bdcmsgcoll.
    READ TABLE i_bdcmsgcoll INTO wa_bdcmsgcoll INDEX l_lines_im.
    To capture success and error messages in BDC.
    CALL FUNCTION 'FORMAT_MESSAGE' "#EC *
    EXPORTING
    id = wa_bdcmsgcoll-msgid
    lang = wa_bdcmsgcoll-msgspra
    no = wa_bdcmsgcoll-msgnr
    v1 = wa_bdcmsgcoll-msgv1
    v2 = wa_bdcmsgcoll-msgv2
    v3 = wa_bdcmsgcoll-msgv3
    v4 = wa_bdcmsgcoll-msgv4
    IMPORTING
    msg = wa_error-message
    EXCEPTIONS
    not_found = 1
    OTHERS = 2.
    IF sy-subrc <> 0.
    ENDIF.
    ELSE.
    WRITE: text-111 COLOR 7.
    ENDIF.
    CLEAR: wa_final.
    REFRESH i_bdcdata.
    ENDLOOP.
    ENDFORM. "f_passbdc_va02
    *& Form bdc_field
    text
    -->P_FNAM text
    -->P_FVAL text
    FORM bdc_field USING p_fnam TYPE any
    p_fval TYPE any.
    CLEAR wa_bdcdata.
    Populate the Field Name
    wa_bdcdata-fnam = p_fnam.
    Populate the field value
    wa_bdcdata-fval = p_fval.
    APPEND wa_bdcdata TO i_bdcdata.
    ENDFORM. "f_bdc_field
    *& Form f_sessions_vl02
    text
    FORM f_sessions_vl02 .
    DATA: l_sindex TYPE sy-tabix VALUE 1,
    l_eindex TYPE sy-tabix,
    l_flag TYPE c VALUE space.
    l_eindex = v_input.
    SORT i_final BY matnr ASCENDING.
    DO p_sess TIMES.
    CALL FUNCTION 'BDC_OPEN_GROUP'
    EXPORTING
    client = sy-mandt
    group = 'Y_VL02_NIK'
    user = sy-uname
    keep = c_flagx
    EXCEPTIONS
    client_invalid = 1
    destination_invalid = 2
    group_invalid = 3
    group_is_locked = 4
    holddate_invalid = 5
    internal_error = 6
    queue_error = 7
    running = 8
    system_lock_error = 9
    user_invalid = 10
    OTHERS = 11.
    IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    CLEAR wa_final.
    CLEAR: i_bdcdata[].
    LOOP AT i_final INTO wa_final FROM l_sindex TO l_eindex .
    IF l_flag = v_sessions.
    CLEAR l_flag.
    EXIT.
    ENDIF.
    l_flag = l_flag + 1.
    CLEAR: i_bdcdata[].
    perform bdc_dynpro using 'SAPLMGMM' '0060'.
    perform bdc_field using 'BDC_CURSOR'
    'RMMG1-MATNR'.
    perform bdc_field using 'BDC_OKCODE'
    '/00'.
    perform bdc_field using 'RMMG1-MATNR'
    wa_final-matnr.
    perform bdc_dynpro using 'SAPLMGMM' '0070'.
    perform bdc_field using 'BDC_CURSOR'
    'MSICHTAUSW-DYTXT(01)'.
    perform bdc_field using 'BDC_OKCODE'
    '=ENTR'.
    perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
    'X'.
    perform bdc_dynpro using 'SAPLMGMM' '4004'.
    perform bdc_field using 'BDC_OKCODE'
    '/00'.
    perform bdc_field using 'BDC_CURSOR'
    'MARA-BISMT'.
    perform bdc_field using 'MARA-BISMT'
    wa_final-bismt.
    perform bdc_dynpro using 'SAPLSPO1' '0300'.
    perform bdc_field using 'BDC_OKCODE'
    '=YES'.
    perform bdc_transaction using 'MM02'.
    perform bdc_dynpro using 'SAPLMGMM' '0060'.
    perform bdc_field using 'BDC_CURSOR'
    'RMMG1-MATNR'.
    perform bdc_field using 'BDC_OKCODE'
    '/00'.
    perform bdc_dynpro using 'SAPLMGMM' '0070'.
    perform bdc_field using 'BDC_CURSOR'
    'MSICHTAUSW-DYTXT(01)'.
    perform bdc_field using 'BDC_OKCODE'
    '=ENTR'.
    perform bdc_dynpro using 'SAPLMGMM' '4004'.
    perform bdc_field using 'BDC_OKCODE'
    '/00'.
    perform bdc_field using 'BDC_CURSOR'
    'RMMG1-MATNR'.
    perform bdc_dynpro using 'SAPLSPO1' '0300'.
    perform bdc_field using 'BDC_OKCODE'
    '=YES'.
    perform bdc_transaction using 'MM03'.
    l_sindex = l_sindex + 1.
    ENDLOOP.
    CALL FUNCTION 'BDC_CLOSE_GROUP'
    EXCEPTIONS
    not_open = 1
    queue_error = 2
    OTHERS = 3.
    IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    ENDDO.
    ENDFORM. " f_sessions_vl02
    *& Form f_report_header
    FORM f_report_header .
    FORMAT COLOR COL_HEADING INTENSIFIED ON.
    ULINE.
    text-201 - Company: Carrier
    text-102- Batch Data Communication.
    text-202 - System: SAP
    WRITE: /1 sy-vline,
    3 text-201,
    50 text-102,
    100 text-202,
    AT sy-linsz sy-vline.
    text-203 - Program:
    text-204 - Date/Time:
    WRITE: /1 sy-vline,
    3 text-203, sy-repid ,
    100 text-204,sy-datum ,c_slash, sy-uzeit,
    AT sy-linsz sy-vline.
    text-205 - User ID:
    text-206 - Page:
    WRITE: /1 sy-vline,
    3 text-205, sy-uname,
    100 text-206, sy-pagno,
    AT sy-linsz sy-vline.
    FORMAT COLOR OFF.
    ULINE.
    ENDFORM. " f_report_header
    FORM bdc_transaction USING tcode.
    CALL FUNCTION 'BDC_INSERT'
    EXPORTING
    tcode = tcode
    TABLES
    dynprotab = i_bdcdata
    EXCEPTIONS
    internal_error = 1
    not_open = 2
    queue_error = 3
    tcode_invalid = 4
    printing_invalid = 5
    posting_invalid = 6
    OTHERS = 7.
    IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ELSE.
    WRITE: / text-109 ,wa_final-matnr,
    text-110 .
    ENDIF.
    ENDFORM. "bdc_transaction

  • Problem in sorting the records

    Hi All,
    I have to sort some records based on a key. If the key field is optional then how to sort the records. For example consider the follwing records.
    <row>
          <name>jaya</name>
          <address>hyd</address>
          <material>d</material>
          <units>4</units>
          <price>6</price>
    </row>
      <row>
          <address>ss</address>
          <material>wd</material>
          <units>7</units>
          <price>9</price>
       </row>
    <row>
          <name>radha</name>
          <address>pune</address>
          <material>g</material>
          <units>9</units>
          <price>3</price>
    </row>
    Here name field is used as a key in sorting the records. in the second record name field does'nt exists. All the records that doesnt have the name field shud come on the top and the rest with name field shud come sorted.
    Can anyone please helpout how to solve this problem??

    Jhansi,
    Did u solved the issue? The scenario is lil bit complicated, please consider my below suggestion, if you haven't achieved your results.
    I must really thankful to Michal and all my SDN friends,who guided me to use the logic-using multiple Mapping program in one Interface mapping.
    /people/michal.krawczyk2/blog/2005/11/01/xi-xml-node-into-a-string-with-graphical-mapping
    Ok, let us come to the logic.
    For your problem we need to use two mapping programs.
    <b>Mapping Program 1</b>
    http://www.flickr.com/photo_zoom.gne?id=897495319&size=o
    <b>Mapping Program 2</b>
    http://www.flickr.com/photo_zoom.gne?id=897495327&size=o
    http://www.flickr.com/photo_zoom.gne?id=897495341&size=o
    <b>UDF1 - Testing</b>
    http://www.flickr.com/photo_zoom.gne?id=897495429&size=o
    String temp;
    for(int i=0;i<Name.length;i++)
    for(int j=i1;j<Name.length;j+)
    if(Name<b>[</b>i<b>]</b>.compareToIgnoreCase(Name[j])>0)
               temp = Name<b>[</b>i<b>]</b>;
                Name<b>[</b>i<b>]</b>= Name[j];
                Name[j]=temp;
    for(int i=0;i<Name.length;i++)
    if(Name<b>[</b>i<b>]</b>.equals("0"))
    result.addSuppress();
    result.addContextChange();
    else
    result.addValue(""Name<b>[</b>i<b>]</b>"");
    result.addContextChange();
    <b>UDF 2 - Testin1</b>
    http://www.flickr.com/photo_zoom.gne?id=897495437&size=o
    String temp,temp1;
    for(int i=0;i<Name.length;i++)
    for(int j=i1;j<Name.length;j+)
    if(Name<b>[</b>i<b>]</b>.compareToIgnoreCase(Name[j])>0)
               temp = Name<b>[</b>i<b>]</b>;
                Name<b>[</b>i<b>]</b>= Name[j];
                Name[j]=temp;
          temp = Values<b>[</b>i<b>]</b>;
                Values<b>[</b>i<b>]</b>= Values[j];
                Values[j]=temp;
    for(int i=0;i<Values.length;i++)
    result.addValue(""Values<b>[</b>i<b>]</b>"");
    result.addContextChange();
    <b>Interface Mapping</b>
    http://www.flickr.com/photo_zoom.gne?id=897495361&size=o
    <b>Finally -Results:</b>
    http://www.flickr.com/photo_zoom.gne?id=897498639&size=o (My Data)
    http://www.flickr.com/photo_zoom.gne?id=897498659&size=o (Your Data)
    I hope it helps you!!!!
    I don't know whether this is the correct way or any other simplest way to do so. Also I request our friends to feedback their inpute regarding this logic.
    Jhansi,if you have any doubts in achieving the same, kindly reply back.
    Best regards,
    raj.

  • Want to sort the records based on non-base table item

    I have a multi-record block and I am trying to sort the data based on nbt item
    I have a table called X which has x_type,x_code fields.
    The table on which the block is created is Y. the table Y has x_type and y_desc as its fields
    form layout is like below .the x_type is key field on which I have to query the records
    and x_code is a non-base item in the form.I want to sort the records by X_code.
    x_code y_desc
    A     xyz
    c par
    B     lmn
    my pre-query has this code
    select x_type from y
    where
    x_type := x_type;
    post-query has this code
    select x_code from x
    where x_type = :x_type;     
    It works fine in Enter-Queryand execute query mode. but when I am sorting the records on
    nbt item x_code by SET-BLOCK-PROPERTY it doesn't do any thing

    Hi Tony ,
    I have created a function and in Pre-Query & have add this
    SET_BLOCK_PROPERTY('b1', ORDER_BY, 'fn_get_code(x_type)');
    and the function created is as below
    Function fn_get_code (p_x_type in varchar2) return varchar2 is
    v_code varchar2(40);
    begin
    select x_code into v_code
    from X, Y
    where X.x_type = Y.x_type
    and y.x_type = p_x_type
    return v_code;
    end;
    when I run the form and execute query it comes up with the error message
    FRM-40505 and when I pressed display error it shows
    SQL Statement error:
    SELECT ROWID,X_TYPE,X_CODE
    FROM Y order by fn_get_code(x_type)
    Error:
    "ORA-00904: "FN_GET_code": invalid identifier"
    Is it that I need to create a function on the database?. As I have created function
    in program unit section

  • How to update and insert the records without using Table_comparison and Map_operation?

    How to update and insert the records without using Table_comparison and Map_operation?

    Use either join or MERGE see this Inserting, Updating, and Deleting Data by Using MERGE

  • Sorting the Records MDM JAVA

    Hi,
              I am using RetrieveRecordsByIdCommand to retrieve the records from MDM. I want to sort the records based on MDM ID.  I tried with SortDefinition which will be passed to the ResultDefinition, but it is not working. Please tell me any other way to sort the records based on a particular field values.
    Thanks,
    Sreenivasulu Thimmanapalli.

    Hi Sreenivasulu Thimmanapalli.
    Also, please check if the field to sort is with Sort-Index set to Normal. In your case, it could be set to None currently
    To confirm
    --Go to MDM Console, Select the Table > Select the Field (that you are trying to sort-on).
    --Look at Field Detail panel, the Sort Index properties should be set to Normal.
    -Wing
    Edited by: Wing Kee Chui on Jan 14, 2009 9:57 PM

  • Can we split and fetch the records in Database Adapter

    Hi,
    I designed a Database Adapter to fetch the records from oracle Database. Some time, the Database Adapter need to fetch around 5000, or 10,000 records in single shot. In that case my BPEL process is choking and getting error as
    java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf(Arrays.java:2882) at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
    Could someone help me to resolve this?
    In Database Adapter can we split and fetch the records, if number of records more then 1000.
    ex. First 100 rec as one set and next 100 as 2nd set like this.
    Thank you.

    You can send the records as batches useing the debatching feature of db adapter. Refer documentation for implementation details.

  • I called 888 442 4551 and when the recording told me to press any number its not working,

    I called 888 442 4551 and when the recording ask me to press any number on dial pad its not working, means I can not make any choices,,,

    No, Apple does not support downgrading iOS. Never has.
    Start with a reset: Simultaneously hold down the Home and On buttons until the device shuts down. Ignore the off slider if it appears. Once shut down is complete, if it doesn't restart on it own, turn the device back on using the On button. In some cases it also helps to double click the Home button and close all apps BEFORE doing the reset.
    If that doesn't work, you may need do a full restore.

  • Validate the XML tag value and display the Binding data in XDP

    Hi,
    I am new to Adobe Life Cycle.... and i am working on the following requirement and XML file is enclosed...
    1. Need to validate the XML value of <pp> with condition
    2. Basing on the value of <pp>, need to display the <ct> values in text field
    If i simply bind, it takes the values from top of array and display..
    Please suggest how to restrict the binding values basing on the condition.
    Thanks
    Madhu

    Hi Paul,
    Thank you for quick respose.
    The solution which you have give me not excatly looking for.... working for the solution in alternative methods...
    Regards
    madhu

  • Function to "Fill" Data Values

    Hello,
    I have a requirement where the user will enter a paritcular data value on the data form for an intersection. This will be at a parent level. Once they enter it I need to fill in the SAME value for all of its children.
    I am unable to find a function that I could use to FILL in the same value. Can anyone suggest me how can this be achieved?
    Thank you.
    ~ Adella

    I have this requirement in my current app: Users can enter leaf level data or parent level data at multiple levels. As I hate/fear/loathe the concept of target versions, what I did was programmatically create _input members as follows:
    Parent1
    |_Parent1_input
    |_ChildA
    |__ChildA_input
    |__Grandchild1
    |__Grandchild2
    |__Grandchild3
    |_ChildB
    |__ChildB_input
    |__Grandchild4
    |_Parent2
    |__Parent2_input
    etc.
    I did this for five generations and then threw attribute dimensions (five separate ones) against each one of the generations of the _input.  In turn that drives the allocation input forms. And to make it just that little bit more convoluted, I created special versions to contain each one of the levels. There is method to this madness.
    What I could then do is aggregate up each level input (remember, only Parent or Child or whatever could show up on the form and could thus get a total for all pool numbers without impacting the other input data. Then users (and managers who override numbers , sometimes) can run simple percent of total allocations against the parent member of the _input member with code that looks like this:
         FIX("Working")
         /*     Aggregate Product     */
         FIX("Prod4Alloc")  /*Version*/
              AGG("Product") ;
         ENDFIX
         FIX("Working")
              FIX(@REMOVE(@RELATIVE(@MBRPARENT([varGlblProduct]), 0), @LIST(@ATTRIBUTE("Prod5Yes"), @ATTRIBUTE("Prod4Yes"), @ATTRIBUTE("Prod3Yes"))))
                   FIX("AllocExp")
                        SET CREATEBLOCKONEQ ON ;
                        "Budget" = ("Sales" / @ANCESTVAL("Product", -2, "Sales")) *
                                            @ANCESTVAL("Product", -2, "AllocateThis"->"PL4Alloc") ;
                   ENDFIX
              ENDFIX
              AGG("Product") ;
         ENDFIXThe way that FIX works is it goes after the parent of the member in the page dropdown and then excludes any of the _input members by using attributes.  @MBRPARENT is key here because you can stick that in a FIX -- @PARENT has been around forever but was unusable in FIXes.  Within the FIX it's a simple percent of parent allocation.  I use @ANCESTVAL to get me the right number of levels up and yes I need separate BRs -- I should really stick them ito a macro and drive it off of a parameter.  That's it -- slightly confusing but it works really well.
    An alternative is to use the @ALLOCATE function and then drive the amount, range, etc. through a RTP but that was way to labor intensive for the users (not for me obviously) and I couldn't hold on to the data value in my app's context and that bugged me to no end.
    As I read the above, it seems like sort of a complicated approach but really it isn't and it's quite fast. The code above is POC stuff so no, I don't really use members called "AllocateThis".
    Regards,
    Cameron Lackpour
    Edited by: CL on Oct 3, 2011 5:13 PM
    You could easily change the code above to simply agg up to the parent and then instead of spreading as percent of parent just assign the parent value.

Maybe you are looking for