ADO Performance vs OO4O Performance

I have managed to get OO4O to outperform ADO in returning a resultset. I have not managed to get OO4O to outperform ADO in executing a PLSQL Procedure. I will place my vb code below. Right now my ADO code is performing 8 times faster than my OO4O code.
Chris
Dim dsess As OraSession
Dim dbase As OraDatabase
Dim dParams As OraParameters
Dim p_return As String
'Create the OraSession Object.
Set dsess = CreateObject("OracleInProcServer.XOraSession")
'Create the OraDatabase Object by opening a connection to Oracle.
Set dbase = dsess.OpenDatabase(tnsString, loginString, 4)
Set dParams = dbase.Parameters
dParams.Add "P_RETURN_TX", P_RETURN_TX, ORAPARM_OUTPUT, 1
dParams.Add "P_START_NO", 1, ORAPARM_INPUT, 2
dParams.Add "P_COUNT_NO", 10, ORAPARM_INPUT, 2
dParams.Add "P_USER_LOGON_TX", USER_LOGON, ORAPARM_INPUT, 1
dParams("P_RETURN_TX").MinimumSize = 10000
dbase.ExecuteSQL ("Begin TOPS_PCK.LIST(:P_RETURN_TX, :P_START_NO, :P_COUNT_NO, :P_USER_LOGON_TX); end;")
p_return = dParams("P_RETURN_TX").Value
dParams.Remove "P_RETURN_TX"
dParams.Remove "P_START_NO"
dParams.Remove "P_COUNT_NO"
dParams.Remove "P_USER_LOGON_TX"
dbase.Close
Set dbase = Nothing
Set dsess = Nothing
getSP = p_return

Does the ratio hold true if you include only the procedure call and eliminate the COM invocation and intialization code (in other words remove the database and session initialization code)?
I imagine the overhead to initialize OO4O might be more.

Similar Messages

  • ORACLE OBJECTS FOR OLE(OO4O) PERFORMANCE TUNING

    제품 : ORACLE SERVER
    작성날짜 : 1997-10-10
    ODBC의 경우는 Block단위로 data를 Query하는데 비해 OLE의 경우는 한번에 전체
    의 자료를 가져다가 Temporary storage space에 넣게 됩니다.
    그래서 튜닝을 위해서는
    Windows 3.1의 경우는 c:/windows/oraole.ini
    WIN95의 경우는 HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\OO4O
    parameters를 수정해야 합니다.
    만일 위의 File이 없는 경우는 모든 변수가 Default로 설정된 경우이므로 인스톨
    된 Help를 자세히 읽어보고 적용을 해야합니다.
    FetchLimit이 가장 큰 영향을 끼치는 파라미터로, 일반적으로 이 값이 클수록
    속도가 빨라지게 됩니다. 다음은 관련 자료입니다.
    Tuning and Customization
    A number of working parameters of Oracle Objects for OLE can be
    customized. Access to these parameters is provided through the Oracle
    initialization file, by default named ORAOLE.INI.
    Each entry currently available in that file is described below. The location
    of the ORAOLE.INI file is specified by the ORAOLE environment variable.
    Note that this variable should specify a full pathname to the Oracle
    initialization file, which is not necessarily named ORAOLE.INI. If this
    environment variable is not set, or does not specify a valid file entry, then
    Oracle Objects for OLE looks for a file named ORAOLE.INI in the Windows
    directory. If this file does not exist, all of the default values
    listed will apply.
    You can customize the following sections of the ORAOLE.INI file:
    [Cache Parameters]
    A cache consisting of temporary data files is created to manage amounts
    of data too large to be maintained exclusively in memory. This cache
    is needed primarily for dynaset objects, where, for example, a single
    LONG RAW column can contain more data than exists in physical
    (and virtual) emory.
    The default values have been chosen for simple test cases, running on a machine
    with limited Windows resources. Tuning with respect to your machine and
    applications is recommended.
    Note that the values specified below are for a single cache, and that a separate
    cache is allocated for each object that requires one. For example, if
    your application contains three dynaset objects, three independent data
    caches are constructed, each using resources as described below.
    SliceSize = 256 (default)
    This entry specifies the minimum number of bytes used to store a piece
    of data in the cache. Items smaller than this value are allocated the
    full SliceSize bytes for storage; items larger than this value are
    allocated an integral multiple of this space value. An example of an
    item to be stored is a field value of a dynaset.
    PerBlock = 16 (default)
    This entry specifies the number of Slices (described in the preceding
    entry) that are stored in a single block. A block is the minimum unit
    of memory or disk allocation used within the cache. Blocks are read
    from and written to the disk cache temporary file in their entirety. Assuming a SliceSize of 256 and a PerBlock value of 16, then the block
    size is 256 * 16 = 4096 bytes.
    CacheBlocks = 20 (default)
    This entry specifies the maximum number of blocks held in memory at any
    one time. As data is added to the cache, the number of used blocks
    grows until the value of CacheBlocks is reached. Previous blocks are
    swapped from memory to the cache temporary disk file to make room for
    more blocks. The blocks are swapped based upon recent usage. The total
    amount of memory used by the cache is calculated as the product of
    (SliceSize * PerBlock * CacheBlocks).
    Recommended Values: You may need to experiment to find optimal cache parameter
    values for your applications and machine environment. Here are some guidelines
    to keep in mind when selecting different values:
    The larger the (SliceSize * PerBlock) value, the more disk I/O is
    required for swapping individual blocks. The smaller the (SliceSize * PerBlock) value, the
    more likely it is that blocks will need to be swapped to or from disk.
    The larger the CacheBlocks value, the more memory is required, but the
    less likely it is that Swapping will be required.
    A reasonable experiment for determining optimal performance might
    proceed as follows:
    Keep the SliceSize >= 128 and vary PerBlock to give a range of block
    sizes from 1K through 8K.
    Vary the CacheBlocks value based upon available memory. Set it high
    enough to avoid disk I/O, but not so high that Windows begins swapping
    memory to disk.
    Gradually decrease the CacheBlocks value until performance degrades or
    you are satisfied with the memory usage. If performance drops off,
    increase the CacheBlocks value once again as needed to restore
    performance.
    [Fetch Parameters]
    FetchLimit = 20 (default)
    This entry specifies the number of elements of the array into which data
    is fetched from Oracle. If you change this value, all fetched values
    are immediately placed into the cache, and all data is retrieved from
    the cache. Therefore, you should create cache parameters such that all
    of the data in the fetch arrays can fit into cache memory. Otherwise,
    inefficiencies may result.
    Increasing the FetchLimit value reduces the number of fetches (calls
    to the database) calls and possibly the amount of network traffic.
    However, with each fetch, more rows must be processed before user
    operations can be performed. Increasing the FetchLimit increases
    memory requirements as well.
    FetchSize = 4096 (default)
    This entry specifies the size, in bytes, of the buffer (string) used for
    retrieved data. This buffer is used whenever a long or long raw column
    is initially retrieved.
    [General]
    TempFileDirectory = [Path]
    This entry provides one method for specifying disk drive and directory
    location for the temporary cache files. The files are created in the
    first legal directory path given by:
    1.The drive and directory specified by the TMP environment variable
    (this method takes precedence over all others);
    2.The drive and directory specified by this entry (TempFileDirectory)
    in the [general] section of the ORAOLE.INI file;
    3.The drive and directory specified by the TEMP environment variable; or
    4.The current working drive and directory.
    HelpFile = [Path and File Name]
    This entry specifies the full path (drive/path/filename) of the Oracle Objects
    for OLE help file as needed by the Oracle Data Control. If this entry cannot
    be located, the file ORACLEO.HLP is assumed to be in the directory where
    ORADC.VBX is located
    (normally \WINDOWS\SYSTEM).

    제품 : ORACLE SERVER
    작성날짜 : 1997-10-10
    ODBC의 경우는 Block단위로 data를 Query하는데 비해 OLE의 경우는 한번에 전체
    의 자료를 가져다가 Temporary storage space에 넣게 됩니다.
    그래서 튜닝을 위해서는
    Windows 3.1의 경우는 c:/windows/oraole.ini
    WIN95의 경우는 HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\OO4O
    parameters를 수정해야 합니다.
    만일 위의 File이 없는 경우는 모든 변수가 Default로 설정된 경우이므로 인스톨
    된 Help를 자세히 읽어보고 적용을 해야합니다.
    FetchLimit이 가장 큰 영향을 끼치는 파라미터로, 일반적으로 이 값이 클수록
    속도가 빨라지게 됩니다. 다음은 관련 자료입니다.
    Tuning and Customization
    A number of working parameters of Oracle Objects for OLE can be
    customized. Access to these parameters is provided through the Oracle
    initialization file, by default named ORAOLE.INI.
    Each entry currently available in that file is described below. The location
    of the ORAOLE.INI file is specified by the ORAOLE environment variable.
    Note that this variable should specify a full pathname to the Oracle
    initialization file, which is not necessarily named ORAOLE.INI. If this
    environment variable is not set, or does not specify a valid file entry, then
    Oracle Objects for OLE looks for a file named ORAOLE.INI in the Windows
    directory. If this file does not exist, all of the default values
    listed will apply.
    You can customize the following sections of the ORAOLE.INI file:
    [Cache Parameters]
    A cache consisting of temporary data files is created to manage amounts
    of data too large to be maintained exclusively in memory. This cache
    is needed primarily for dynaset objects, where, for example, a single
    LONG RAW column can contain more data than exists in physical
    (and virtual) emory.
    The default values have been chosen for simple test cases, running on a machine
    with limited Windows resources. Tuning with respect to your machine and
    applications is recommended.
    Note that the values specified below are for a single cache, and that a separate
    cache is allocated for each object that requires one. For example, if
    your application contains three dynaset objects, three independent data
    caches are constructed, each using resources as described below.
    SliceSize = 256 (default)
    This entry specifies the minimum number of bytes used to store a piece
    of data in the cache. Items smaller than this value are allocated the
    full SliceSize bytes for storage; items larger than this value are
    allocated an integral multiple of this space value. An example of an
    item to be stored is a field value of a dynaset.
    PerBlock = 16 (default)
    This entry specifies the number of Slices (described in the preceding
    entry) that are stored in a single block. A block is the minimum unit
    of memory or disk allocation used within the cache. Blocks are read
    from and written to the disk cache temporary file in their entirety. Assuming a SliceSize of 256 and a PerBlock value of 16, then the block
    size is 256 * 16 = 4096 bytes.
    CacheBlocks = 20 (default)
    This entry specifies the maximum number of blocks held in memory at any
    one time. As data is added to the cache, the number of used blocks
    grows until the value of CacheBlocks is reached. Previous blocks are
    swapped from memory to the cache temporary disk file to make room for
    more blocks. The blocks are swapped based upon recent usage. The total
    amount of memory used by the cache is calculated as the product of
    (SliceSize * PerBlock * CacheBlocks).
    Recommended Values: You may need to experiment to find optimal cache parameter
    values for your applications and machine environment. Here are some guidelines
    to keep in mind when selecting different values:
    The larger the (SliceSize * PerBlock) value, the more disk I/O is
    required for swapping individual blocks. The smaller the (SliceSize * PerBlock) value, the
    more likely it is that blocks will need to be swapped to or from disk.
    The larger the CacheBlocks value, the more memory is required, but the
    less likely it is that Swapping will be required.
    A reasonable experiment for determining optimal performance might
    proceed as follows:
    Keep the SliceSize >= 128 and vary PerBlock to give a range of block
    sizes from 1K through 8K.
    Vary the CacheBlocks value based upon available memory. Set it high
    enough to avoid disk I/O, but not so high that Windows begins swapping
    memory to disk.
    Gradually decrease the CacheBlocks value until performance degrades or
    you are satisfied with the memory usage. If performance drops off,
    increase the CacheBlocks value once again as needed to restore
    performance.
    [Fetch Parameters]
    FetchLimit = 20 (default)
    This entry specifies the number of elements of the array into which data
    is fetched from Oracle. If you change this value, all fetched values
    are immediately placed into the cache, and all data is retrieved from
    the cache. Therefore, you should create cache parameters such that all
    of the data in the fetch arrays can fit into cache memory. Otherwise,
    inefficiencies may result.
    Increasing the FetchLimit value reduces the number of fetches (calls
    to the database) calls and possibly the amount of network traffic.
    However, with each fetch, more rows must be processed before user
    operations can be performed. Increasing the FetchLimit increases
    memory requirements as well.
    FetchSize = 4096 (default)
    This entry specifies the size, in bytes, of the buffer (string) used for
    retrieved data. This buffer is used whenever a long or long raw column
    is initially retrieved.
    [General]
    TempFileDirectory = [Path]
    This entry provides one method for specifying disk drive and directory
    location for the temporary cache files. The files are created in the
    first legal directory path given by:
    1.The drive and directory specified by the TMP environment variable
    (this method takes precedence over all others);
    2.The drive and directory specified by this entry (TempFileDirectory)
    in the [general] section of the ORAOLE.INI file;
    3.The drive and directory specified by the TEMP environment variable; or
    4.The current working drive and directory.
    HelpFile = [Path and File Name]
    This entry specifies the full path (drive/path/filename) of the Oracle Objects
    for OLE help file as needed by the Oracle Data Control. If this entry cannot
    be located, the file ORACLEO.HLP is assumed to be in the directory where
    ORADC.VBX is located
    (normally \WINDOWS\SYSTEM).

  • Performance monitor - System performance does not start work?

    When I right click it to start it does nothing, and I can't stop it either by right clicking it.

    Hi,
    Please use the following method to start the performance monitor.
    1. Click Start, click in the Start Search box, type perfmon, and press ENTER.
    2. In the navigation tree, expand Monitoring Tools, and then click Performance Monitor.
    If any error message received, please let me know.
    Niki Han
    TechNet Community Support

  • Profile Performance in LabVIEWvs Performance meter in Vision Assistant: Doesn't match

    Hi everyone,
    I faced a strange problem about performance timing between these two measurements.
    Here is my test
    -used inbuilt example provided by labview in vision assistant-Bracket example-Uses two pattern matches, one edge detection algorithm and two calipers(one for calculating midpoint and other for finding angle between three points.
    -When i ran the script provided by NI for the same in vision assistnat it took average inspection time of 12.45ms(even this also varies from 12-13ms:my guess is this little variation might be due to my cpu/processing load).
    -Then i converted the script to vi and i used profile performance in labview and surprisingly it is showing way more than expected like almost ~300ms(In the beginning thought it is beacuse of all rotated search etc..but none of them make sense to me here).
    Now my questions are
    -Are the algorithms used in both tools are same? (I thought they are same)
    -IMAQ read image and vision info is taking more than 100ms in labview, which doesn't count for vision assistant. why?( thought the template image might be loaded to cache am i right?)
    -What about IMAQ read file(doesn't count for vision assistant?? In labview it takes around 15ms)
    -Same for pattern match in vision assitant it takes around 3ms(this is also not consistant) in labview it takes almost 3times (around 15ms)
    -Is this bug or am i missing somethings or this is how it is expected?
    Please find attachments below.
    -Vision Assistant-v12-Build 20120605072143
    -Labview-12.0f3
    Thanks
    uday,
    Please Mark the solution as accepted if your problem is solved and help author by clicking on kudoes
    Certified LabVIEW Associate Developer (CLAD) Using LV13
    Attachments:
    Performance_test.zip ‏546 KB

    Hmm Bruce, Thanks again for reply.
    -When i first read your reply, i was ok. But after reading it multiple times, i came to know that you didn't check my code and explanation first.
    -I have added code and screenshot of Profile in both VA and LabVIEW.
    In both Vision Assistant and Labview
    -I am loading image only once.
    Accounted in Labview but not in VA, because it is already in cache, But time to put the image into cache?
    I do understand that, when we are capturing the image live from camera things are completely different.
    -Loading template image multiple times??
    This is where i was very much confused. Beacuase i didn't even think of it. I am well aware of that task.
    -Run Setup Match Pattern once?
    Sorry, so far i haven't seen any example which does pattern match for multiple images has Setup Match Pattern everytime. But it is negligible time i wouldn't mind.
    -Loading images for processing and loading diffferent template for each image?
    You are completely mistaken here and i don't see that how it is related to my specific question.
    Briefly explaining you again
    -I open an image both in LabVIEW and VA.
    -Create two pattern match steps. and Calipers(Negligible)
    -The pattern match step in VA shows me longest time of 4.65 ms where as IMAQ Match pattern showed me 15.6 ms.
    -I am convinced about IMAQ Read and vision info timing, because it will account only in the initial phase when running for multiple image inspection.
    But i am running for only once, then Vision assistant should show that time also isn't it?
    -I do understand that, Labview has lot more features on paralell execution and many things than Vision Assistant.
    -Yeah that time about 100ms to 10ms i completely agree. I take Vision Assistant profile timing as the ideal values( correct me if i am wrong).
    -I like the last line especially, You cannot compare the speeds of the two methods.
     Please let me know if i am thinking in complete stupid way or at least some thing in right path.
    Thanks
    uday,
    Please Mark the solution as accepted if your problem is solved and help author by clicking on kudoes
    Certified LabVIEW Associate Developer (CLAD) Using LV13

  • MSS - Team - Performance Management - Maintain Performance Documents

    Hi,
    When I click on the Maintain Performance Documents the page opens and shows only one iView - 'Status Overview'.  As I understand it, this page is supposed to have two iViews on it, but the other iView 'Performance Management Document' is missing.  So I can see my list of employees, but when I click on them, nothing happens.  Anyone else run into this problem?

    Hello Kenneth,
    As sujan said is right, When you click on Maintain performance Document it opens Status Overview Iview
    its display list of employees , initial if you have no appraisal its display blank cell  In preparation colume,
    if you have  appraisal it display Performance Maintain Document iView(BSP) is App - HAP_DOCUMENT with all list of option for approval.
    You can also create appraisal in Create Appraisal Document in ESS.
    Please points if helpful.
    Please close thread if problem solved
    Thankyou
    Regards
    Vijai

  • Bad performance!, Bad performance!

    Hi!
    Query1 and the queries of the inline views of query2 separate are about 1 sec response-time, but when i try to get multiple value into one collumn with SYS_CONNECT_BY_PATH than the response-time is >18 minutes(didn't finish the query). Query1 is my original query with good performance and query2 is what i have tried with the multiple values in one collumn. I have tried to get rid of the group by in the third inline view and have tried to combine the second and third view but that didn't work. I also don't know if the second query will give me the right results. The results of query1 and the inline_views of query2 seems to be accurate though.
    Can anybody help me with tuning this query?
    QUERY1:
    SELECT DISTINCT inline_view.u_plot_number AS Research_Group,
           inline_view.external_reference AS Parental_Line,
           inline_view.u_box_code AS Box,
           inline_view.description AS Test,
            CASE WHEN inline_view_finalresult.ResultCount < 8
                THEN null
                ELSE CASE WHEN inline_view_finalresult.ResultDistinct > 1
                          THEN 'spl'
                          ELSE inline_view_finalresult.ResultFinal
                     END
           END AS Result
    FROM ( SELECT DISTINCT sdg.sdg_id,
                  sample.sample_id,
                  test_template.test_template_id,
                  sample_user.u_plot_number,
                  sdg.external_reference,
                  sample_user.u_box_code,
                  test.description
           FROM sdg,sdg_user,sample,sample_user,aliquot,test,test_template
           WHERE sdg.sdg_id = sdg_user.sdg_id
              AND sdg.sdg_id = sample.sdg_id
              AND sample.sample_id = sample_user.sample_id
              AND aliquot.sample_id = sample.sample_id
              AND test.aliquot_id = aliquot.aliquot_id
              AND test_template.test_template_id = test.test_template_id
              AND sdg.sdg_id BETWEEN 559 ANd 566
         ) inline_view,
         ( SELECT DISTINCT u_finalresult_user.u_sdg_id,
                  u_finalresult_user.u_calculated_result,
                  u_finalresult_user.u_overruled_result,
                  u_finalresult_user.u_sample_id,
                  u_finalresult_user.u_test_template_id,
                     COUNT(NVL(u_finalresult_user.u_overruled_result,u_finalresult_user.u_calculated_result))
                        OVER (PARTITION BY CONCAT(u_finalresult_user.u_sdg_id,u_finalresult_user.u_test_template_id)) AS ResultCount,
                       COUNT(DISTINCT NVL(u_finalresult_user.u_overruled_result,u_finalresult_user.u_calculated_result))
                           OVER (PARTITION BY CONCAT(u_finalresult_user.u_sdg_id,u_finalresult_user.u_test_template_id)) AS ResultDistinct,
                      NVL(u_finalresult_user.u_overruled_result,u_finalresult_user.u_calculated_result) as Resultfinal,
                     ROW_NUMBER()
                        OVER (PARTITION BY CONCAT(u_finalresult_user.u_sdg_id,u_finalresult_user.u_test_template_id)
                         ORDER BY u_finalresult_user.u_sdg_id,u_finalresult_user.u_test_template_id ) AS Ranking
            FROM u_finalresult_user
           WHERE u_finalresult_user.u_requested = 'T'
               AND NVL(u_finalresult_user.u_overruled_result,u_finalresult_user.u_calculated_result) <> 'X'
         ) inline_view_finalresult
    WHERE inline_view.sample_id = inline_view_finalresult.u_sample_id (+)
       AND inline_view.test_template_id = inline_view_finalresult.u_test_template_id (+)
       AND inline_view_finalresult.Ranking =1
    ORDER BY inline_view.description,inline_view.u_box_codeQUERY2:
    SELECT DISTINCT inline_view.u_plot_number AS Research_Group,
           inline_view.external_reference AS Parental_Line,
           inline_view.u_box_code AS Box,
           inline_view.description AS Test,
          CASE WHEN inline_view_finalresult.ResultCount < 8
                THEN null
                ELSE CASE WHEN inline_view_finalresult.ResultDistinct > 1
                          THEN 'spl'
                          ELSE inline_view_finalresult.ResultFinal
                     END
          END AS Result,
          CASE WHEN LEVEL >=2
               THEN SUBSTR(SYS_CONNECT_BY_PATH(ValCount,','),2)
          END AS Spl
    FROM ( SELECT DISTINCT sdg.sdg_id,
                  sample.sample_id,
                  test_template.test_template_id,
                  sample_user.u_plot_number,
                  sdg.external_reference,
                  sample_user.u_box_code,
                  test.description
           FROM sdg,sdg_user,sample,sample_user,aliquot,test,test_template
           WHERE sdg.sdg_id = sdg_user.sdg_id
              AND sdg.sdg_id = sample.sdg_id
              AND sample.sample_id = sample_user.sample_id
              AND aliquot.sample_id = sample.sample_id
              AND test.aliquot_id = aliquot.aliquot_id
              AND test_template.test_template_id = test.test_template_id
              AND sdg.sdg_id BETWEEN 559 ANd 566
         ) inline_view,
         ( SELECT DISTINCT u_finalresult_user.u_sdg_id,
                  u_finalresult_user.u_calculated_result,
                  u_finalresult_user.u_overruled_result,
                  u_finalresult_user.u_sample_id,
                  u_finalresult_user.u_test_template_id,
               COUNT(NVL(u_finalresult_user.u_overruled_result,u_finalresult_user.u_calculated_result))
                     OVER (PARTITION BY CONCAT(u_finalresult_user.u_sdg_id,u_finalresult_user.u_test_template_id)) AS ResultCount,orumID=75, Hi!
    Query1 and the queries of the inline views of query2 separate are about 1 sec response-time, but when i try to get multiple value into one collumn with SYS_CONNECT_BY_PATH than the response-time is >18 minutes(didn't finish the query). Query1 is my original query with good performance and query2 is what i have tried with the multiple values in one collumn. I have tried to get rid of the group by in the third inline view and have tried to combine the second and third view but that didn't work. I also don't know if the second query will give me the right results. The results of query1 and the inline_views of query2 seems to be accurate though.
    Can anybody help me with tuning this query?
    QUERY1:
    [pre]
    SELECT DISTINCT inline_view.u_plot_number AS Research_Group,
           inline_view.external_reference AS Parental_Line,
           inline_view.u_box_code AS Box,
           inline_view.description AS Test,
            CASE WHEN inline_view_finalresult.ResultCount < 8
                THEN null
                ELSE CASE WHEN inline_view_finalresult.ResultDistinct > 1
                          THEN 'spl'
                          ELSE inline_view_finalresult.ResultFinal
                     END
           END AS Result
    FROM ( SELECT DISTINCT sdg.sdg_id,
                  sample.sample_id,
                  test_template.test_template_id,
                  sample_user.u_plot_number,
                  sdg.external_reference,
                  sample_user.u_box_code,
                  test.description
           FROM sdg,sdg_user,sample,sample_user,aliquot,test,test_template
           WHERE sdg.sdg_id = sdg_user.sdg_id
              AND sdg.sdg_id = sample.sdg_id
              AND sample.sample_id = sample_user.sample_id
              AND aliquot.sample_id = sample.sample_id
              AND test.aliquot_id = aliquot.aliquot_id
              AND test_template.test_template_id = test.test_template_id
              AND sdg.sdg_id BETWEEN 559 ANd 566
         ) inline_view,
         ( SELECT DISTINCT u_finalresult_user.u_sdg_id,
                  u_finalresult_user.u_calculated_result,
                  u_finalresult_user.u_overruled_result,
                  u_finalresult_user.u_sample_id,
                  u_finalresult_user.u_test_template_id,
                     COUNT(NVL(u_finalresult_user.u_overruled_result,u_finalresult_user.u_calculated_result))
                        OVER (PARTITION BY CONCAT(u_finalresult_user.u_sdg_id,u_finalresult_user.u_test_template_id))                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Something did go wrong in the previous post so this is the whole message
    Hi!
    Query1 and the queries of the inline views of query2 separate are about 1 sec response-time, but when i try to get multiple value into one collumn with SYS_CONNECT_BY_PATH than the response-time is >18 minutes(didn't finish the query). Query1 is my original query with good performance and query2 is what i have tried with the multiple values in one collumn. I have tried to get rid of the group by in the third inline view and have tried to combine the second and third view but that didn't work. I also don't know if the second query will give me the right results. The results of query1 and the inline_views of query2 seems to be accurate though.
    Can anybody help me with tuning this query?
    QUERY1:
    SELECT DISTINCT inline_view.u_plot_number AS Research_Group,
           inline_view.external_reference AS Parental_Line,
           inline_view.u_box_code AS Box,
           inline_view.description AS Test,
            CASE WHEN inline_view_finalresult.ResultCount < 8
                THEN null
                ELSE CASE WHEN inline_view_finalresult.ResultDistinct > 1
                          THEN 'spl'
                          ELSE inline_view_finalresult.ResultFinal
                     END
           END AS Result
    FROM ( SELECT DISTINCT sdg.sdg_id,
                  sample.sample_id,
                  test_template.test_template_id,
                  sample_user.u_plot_number,
                  sdg.external_reference,
                  sample_user.u_box_code,
                  test.description
           FROM sdg,sdg_user,sample,sample_user,aliquot,test,test_template
           WHERE sdg.sdg_id = sdg_user.sdg_id
              AND sdg.sdg_id = sample.sdg_id
              AND sample.sample_id = sample_user.sample_id
              AND aliquot.sample_id = sample.sample_id
              AND test.aliquot_id = aliquot.aliquot_id
              AND test_template.test_template_id = test.test_template_id
              AND sdg.sdg_id BETWEEN 559 ANd 566
         ) inline_view,
         ( SELECT DISTINCT u_finalresult_user.u_sdg_id,
                  u_finalresult_user.u_calculated_result,
                  u_finalresult_user.u_overruled_result,
                  u_finalresult_user.u_sample_id,
                  u_finalresult_user.u_test_template_id,
                     COUNT(NVL(u_finalresult_user.u_overruled_result,u_finalresult_user.u_calculated_result))
                        OVER (PARTITION BY CONCAT(u_finalresult_user.u_sdg_id,u_finalresult_user.u_test_template_id)) AS ResultCount,
                       COUNT(DISTINCT NVL(u_finalresult_user.u_overruled_result,u_finalresult_user.u_calculated_result))
                           OVER (PARTITION BY CONCAT(u_finalresult_user.u_sdg_id,u_finalresult_user.u_test_template_id)) AS ResultDistinct,
                      NVL(u_finalresult_user.u_overruled_result,u_finalresult_user.u_calculated_result) as Resultfinal,
                     ROW_NUMBER()
                        OVER (PARTITION BY CONCAT(u_finalresult_user.u_sdg_id,u_finalresult_user.u_test_template_id)
                         ORDER BY u_finalresult_user.u_sdg_id,u_finalresult_user.u_test_template_id ) AS Ranking
            FROM u_finalresult_user
           WHERE u_finalresult_user.u_requested = 'T'
               AND NVL(u_finalresult_user.u_overruled_result,u_finalresult_user.u_calculated_result) <> 'X'
         ) inline_view_finalresult
    WHERE inline_view.sample_id = inline_view_finalresult.u_sample_id (+)
       AND inline_view.test_template_id = inline_view_finalresult.u_test_template_id (+)
       AND inline_view_finalresult.Ranking =1
    ORDER BY inline_view.description,inline_view.u_box_codeQUERY2:
    SELECT DISTINCT inline_view.u_plot_number AS Research_Group,
           inline_view.external_reference AS Parental_Line,
           inline_view.u_box_code AS Box,
           inline_view.description AS Test,
          CASE WHEN inline_view_finalresult.ResultCount < 8
                THEN null
                ELSE CASE WHEN inline_view_finalresult.ResultDistinct > 1
                          THEN 'spl'
                          ELSE inline_view_finalresult.ResultFinal
                     END
          END AS Result,
          CASE WHEN LEVEL >=2
               THEN SUBSTR(SYS_CONNECT_BY_PATH(ValCount,','),2)
          END AS Spl
    FROM ( SELECT DISTINCT sdg.sdg_id,
                  sample.sample_id,
                  test_template.test_template_id,
                  sample_user.u_plot_number,
                  sdg.external_reference,
                  sample_user.u_box_code,
                  test.description
           FROM sdg,sdg_user,sample,sample_user,aliquot,test,test_template
           WHERE sdg.sdg_id = sdg_user.sdg_id
              AND sdg.sdg_id = sample.sdg_id
              AND sample.sample_id = sample_user.sample_id
              AND aliquot.sample_id = sample.sample_id
              AND test.aliquot_id = aliquot.aliquot_id
              AND test_template.test_template_id = test.test_template_id
              AND sdg.sdg_id BETWEEN 559 ANd 566
         ) inline_view,
         ( SELECT DISTINCT u_finalresult_user.u_sdg_id,
                  u_finalresult_user.u_calculated_result,
                  u_finalresult_user.u_overruled_result,
                  u_finalresult_user.u_sample_id,
                  u_finalresult_user.u_test_template_id,
               COUNT(NVL(u_finalresult_user.u_overruled_result,u_finalresult_user.u_calculated_result))
                     OVER (PARTITION BY CONCAT(u_finalresult_user.u_sdg_id,u_finalresult_user.u_test_template_id)) AS ResultCount,
                  COUNT(DISTINCT NVL(u_finalresult_user.u_overruled_result,u_finalresult_user.u_calculated_result))
                    OVER (PARTITION BY CONCAT(u_finalresult_user.u_sdg_id,u_finalresult_user.u_test_template_id)) AS ResultDistinct,
                  NVL(u_finalresult_user.u_overruled_result,u_finalresult_user.u_calculated_result) as Resultfinal,
               ROW_NUMBER()
                  OVER (PARTITION BY CONCAT(u_finalresult_user.u_sdg_id,u_finalresult_user.u_test_template_id)
                 ORDER BY u_finalresult_user.u_sdg_id,u_finalresult_user.u_test_template_id ) AS Ranking
          FROM u_finalresult_user
           WHERE u_finalresult_user.u_requested = 'T'
             AND NVL(u_finalresult_user.u_overruled_result,u_finalresult_user.u_calculated_result) != 'X'
         ) inline_view_finalresult,
        ( SELECT CONCAT(u_finalresult_user.u_sdg_id,u_finalresult_user.u_test_template_id),
                  NVL(u_finalresult_user.u_overruled_result,u_finalresult_user.u_calculated_result),
               TO_CHAR(COUNT(*)) || 'x' || NVL(u_finalresult_user.u_overruled_result,u_finalresult_user.u_calculated_result) As ValCount,
               ROW_NUMBER()
                  OVER (PARTITION BY CONCAT(u_finalresult_user.u_sdg_id,u_finalresult_user.u_test_template_id)
                    ORDER BY COUNT(*) DESC, NVL(u_finalresult_user.u_overruled_result,u_finalresult_user.u_calculated_result)) AS Rank,
               COUNT(*)
                  OVER (PARTITION BY CONCAT(u_finalresult_user.u_sdg_id,u_finalresult_user.u_test_template_id)) AS MaxLevel  
          FROM u_finalresult_user
          WHERE u_finalresult_user.u_requested = 'T'
            AND NVL(u_finalresult_user.u_overruled_result,u_finalresult_user.u_calculated_result) != 'X'
          GROUP BY CONCAT(u_finalresult_user.u_sdg_id,u_finalresult_user.u_test_template_id),NVL(u_finalresult_user.u_overruled_result,u_finalresult_user.u_calculated_result)
    WHERE inline_view.sample_id = inline_view_finalresult.u_sample_id (+)
       AND inline_view.test_template_id = inline_view_finalresult.u_test_template_id (+)
       AND inline_view_finalresult.Ranking =1
       AND LEVEL = MaxLevel
         START WITH rank = 1 CONNECT BY
         PRIOR inline_view_finalresult.u_sdg_id = inline_view_finalresult.u_sdg_id
         AND PRIOR inline_view_finalresult.u_test_template_id = inline_view_finalresult.u_test_template_id
         AND PRIOR Rank = Rank - 1

  • Multicast performance and Unicast performance on same switch

    Hi ,
    I have a question about multicast performance.
    As I know, the switch performance are depends on switch fabric bandwidth and packet forward efficiency..
    For example.
    In our case is CAT4506-E with SUP7-E.
    The switch fabric per slot is 48G and total PPS for IPv4 is 250mpps.
    Is this for Uni cast and multicast?
    The only difference between them is routing table entries?

    Alessandro Ilardo wrote:
    Hi there,
    a colleague of mine raised some doubts on installing Oracle database 11.2 on the same host server where multiple Virtual Box guest instances are running.
    He pointed that threads allocation and consequently performance could be unbalanced.
    Database server is not for production but it must supply its services for about 20 enterprise applications, so I do not expect to serve thousands of requests but definitely complex queries.
    Considering these points, does it make sense what he's said?
    Where can I find more information about Oracle DB 11.2 threads allocation?
    thanks in advance
    The host server is a DELL with two sockets Intel® Xeon® E5520, 2.26Ghz, 8M Cache, 5.86 GT/s QPI, Turbo, HT, 1066MHz Max Memory
    RAM
    RAM 24GB Memory for 2 CPUs, DDR3, 1333MHz
    (12x2GB Dual Ranked UDIMMs)
    OS RedHat 5.3If I understand what you are saying, then as far as the OS is concerned, the oracle rdbms is just another application alongside a virtual machine (or several virtual machines) process. I can't see where there should be any inherent conflict between them, except of course all processes running on any computer are competing for finite hardware resources. Typically you'd want the database server to be dedicated to running the database.

  • When bapi perform, user exit perform or not

    Hi,
    TCODE VA01,
    i am going to use BAPI(SD_SALESDOCUMENT_CREATE) in order to create or change sales order .
    but  there is user exit on VA01, so i want to know if user-exit execute or not  when i use BAPI on abap code.
    thanks
    venjamin.

    Hi,
    As far as i remember bapi will execute the user exit as once i tried to call the bapi in the user exit and in turn the bapi called back the user exit again. at that i used the same said bapi "SD_SALES_DOCUMENT_CREATE". and hence i changed my code accordingly
    Regards
    Satya

  • Serious Performance Problems in ABAP Reports

    Hi All,
    We are developing ABAP reports for SAP IS-U/CCS Modules and facing Performance issues.Whole scenario is given below.Please suggest some solution.
    1. Total No. Of Business Partners = 1500000
    2. Reports Selection Criteria are of two types:
         a) GSBER(Business Area) - Selection for atleast 200000 Business Partners
         b) Cokey(Division)     - Selection for around 1000 to 50000 Business Partners
    3. For implementing our reports logic we have to access several tables all of which are very large.They are :
         Table Name     No. of records (Appx)          
         DBERCHV               20000000
         DBERCHZ1              20000000
         DBERDLB               20000000
         DFKKKO                20000000
         DFKKOP                20000000
         EANLH                  4000000
         ERCH                  10000000
         ERCHC                 10000000
         ETTIFN                30000000
         EVER                   1500000
         FKKVKP                 1500000
         TECOKT                     500     
         TGSBT                       12
    4. Due to large no. of records we are facing problems at two levels:
         a) OpenSQL Statement is taking too much time for data selection
         b) Since large no. of records are selected Corresponding loops and data processing also takes much time
    5. We have tried almost all ABAP Performance optimization techniques such as using Index, SQL optimization techniques,Read Table Optimization, Loop Statement Optimization etc. but there is not much improvement.
    6. For example one of our Reports "R15" takes around 1500 seconds for 1000 Business Partners.
    Its Code is attached below:
    <b>a) ZISU_SCHL_LTR15_BAPI - Program which schedules actual R15 report in background</b>
    *& Report  ZISU_SCHL_LTR15_BAPI                                        *
    *& Developed By : Piyusha Kirwai                                       *
    *& Date         : 02/12/2005                                           *
    *& Purpose      : To Schedule the LT R 15 prog in background and store
    *& the File for Manual R-15 into server.
    REPORT  ZISU_SCHL_LTR15_BAPI  NO STANDARD PAGE HEADING.
    TABLES ZEVERFKKVKP.
    DATA:  DYFIELDS LIKE DYNPREAD OCCURS 0 WITH HEADER LINE.
    DATA: IT_TAB TYPE FILETABLE,
          GD_SUBRC TYPE I.
    DATA: LV_GSBER TYPE TGSBT-GSBER.
    RANGES R_COKEY FOR ZEVERFKKVKP-COKEY.
    DATA: BEGIN OF GT_TECOKT OCCURS 100,
            COKEY TYPE TECOKT-COKEY,
            LTEXT TYPE TECOKT-LTEXT,
          END   OF GT_TECOKT,
          BEGIN OF GT_TE422 OCCURS 100,
            TERMSCHL TYPE TE422-TERMSCHL,
            TERMTEXT TYPE TE422-TERMTEXT,
          END   OF GT_TE422.
    DATA: BEGIN OF GWA_MANUAL_DATA,
            COL_1(5)        TYPE C,
            COL_2(10)       TYPE C,
            COL_3(40)       TYPE C,
            COL_4(40)       TYPE C,
            COL_5(10)       TYPE C,
            COL_6(19)       TYPE C,
            COL_7(19)       TYPE C,
            COL_8(19)       TYPE C,
            COL_9(19)       TYPE C,
            COL_10(19)      TYPE C,
            COL_11(19)      TYPE C,
            COL_12(10)      TYPE C,
            COL_13(19)      TYPE C,
            COL_14(19)      TYPE C,
            COL_15(19)      TYPE C,
            COL_16(19)      TYPE C,
            COL_17(19)      TYPE C,
            COL_18(19)      TYPE C,
          END   OF GWA_MANUAL_DATA,
          GT_MANUAL_DATA LIKE GWA_MANUAL_DATA OCCURS 0,
          GT_INTERN_DATA TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
    *&-----FOR UPLOADING FILE TO SERVER------------------------------------*
    DATA: LV_SERVER_FILE_PREFIX(60) TYPE C.
    DATA: LV_SERVER_DATAFILE_NAME(60) TYPE C.
    DATA: LV_SERVER_ERRFILE_NAME(60) TYPE C.
    DATA: ENDT LIKE SY-UZEIT,
          ENDD LIKE SY-DATUM,
          JOBCOUNT TYPE TBTCJOB-JOBCOUNT.
    SELECTION-SCREEN BEGIN OF BLOCK 001 WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS: SO_GSBER FOR ZEVERFKKVKP-GSBER OBLIGATORY,
                    SO_COKEY FOR ZEVERFKKVKP-COKEY OBLIGATORY,
                    SO_MRU   FOR ZEVERFKKVKP-ABLEINH.
    PARAMETERS:     P_BMNTH(7) TYPE C OBLIGATORY.
    SELECT-OPTIONS: SO_GPART FOR ZEVERFKKVKP-GPART.
    SELECTION-SCREEN END  OF BLOCK 001.
    SELECTION-SCREEN BEGIN OF BLOCK 002 WITH FRAME TITLE TEXT-003.
    PARAMETERS:  P_COMPUT RADIOBUTTON GROUP R15,
                 P_INCLUD RADIOBUTTON GROUP R15,
                 P_FILE  TYPE  RLGRAP-FILENAME MODIF ID ACT.
    SELECTION-SCREEN END   OF BLOCK 002.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 2(83) TEXT-004.
    SELECTION-SCREEN END   OF LINE.
    *SELECTION-SCREEN BEGIN OF LINE.
    *  SELECTION-SCREEN COMMENT 8(40) TEXT-005.
    *SELECTION-SCREEN END   OF LINE.
    SELECTION-SCREEN BEGIN OF BLOCK 003 WITH FRAME TITLE TEXT-002.
    PARAMETERS   P_SCHL TYPE C AS CHECKBOX.
    PARAMETERS : P_IMMED RADIOBUTTON GROUP SCH ,
                 P_DT_TM  RADIOBUTTON GROUP SCH,
                 P_DATE TYPE SY-DATUM MODIF ID SHL,
                 P_TIME TYPE SY-UZEIT MODIF ID SHL.
    SELECTION-SCREEN END   OF BLOCK 003.
    AT SELECTION-SCREEN.
    AT SELECTION-SCREEN ON SO_GSBER.
      IF NOT SO_GSBER-LOW IS INITIAL.
        SELECT SINGLE GSBER FROM TGSBT INTO LV_GSBER
          WHERE GSBER = SO_GSBER-LOW.
        IF SY-SUBRC <> 0.
          MESSAGE E007(ZISU).
        ENDIF.
      ENDIF.
      IF NOT SO_GSBER-HIGH IS INITIAL .
        SELECT SINGLE GSBER FROM TGSBT INTO LV_GSBER
          WHERE GSBER = SO_GSBER-HIGH.
        IF SY-SUBRC <> 0.
          MESSAGE E007(ZISU).
        ENDIF.
      ENDIF.
    AT SELECTION-SCREEN ON P_BMNTH.
    **check the validity of Billing month format and for valid billing month
      IF P_BMNTH CO '0123456789/'.
        IF P_BMNTH CP '++++/++'.
          IF P_BMNTH+5(2) > 12.
            MESSAGE E002(ZISU) WITH 'from'.
          ENDIF.
    ** current year is less than year entered
          IF SY-DATUM(4) < P_BMNTH(4).
            MESSAGE E003(ZISU) WITH 'from'.
          ELSEIF SY-DATUM(4) = P_BMNTH(4).
    ** month in future
            IF SY-DATUM+4(2) < P_BMNTH+5(2).
              MESSAGE E004(ZISU) WITH 'from'.
            ENDIF.
          ENDIF.
        ELSE.
          MESSAGE E001(ZISU) WITH 'from'.
        ENDIF.
      ELSE.
    **  entry have some invalid char
        MESSAGE E010(ZISU).
      ENDIF.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR SO_COKEY-LOW.
    **for geting the CO account assigment key of the entered Business area
      CLEAR: DYFIELDS[], DYFIELDS.
      PERFORM DIVISON_DATA_GET CHANGING SO_COKEY-LOW.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR SO_COKEY-HIGH.
    **for geting the CO account assigment key of the entered Business area
      CLEAR: DYFIELDS[], DYFIELDS.
      PERFORM DIVISON_DATA_GET CHANGING SO_COKEY-HIGH.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR SO_MRU-LOW.
      CLEAR: DYFIELDS[], DYFIELDS.
      PERFORM MRU_DATA_GET CHANGING SO_MRU-LOW.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR SO_MRU-HIGH.
      CLEAR: DYFIELDS[], DYFIELDS.
      PERFORM MRU_DATA_GET CHANGING SO_MRU-HIGH.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
      REFRESH: IT_TAB.
    **Opens File Open Dialog Box for selecting input file.
      CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
        EXPORTING
          WINDOW_TITLE     = 'Select File'
          DEFAULT_FILENAME = '*.xls'
          MULTISELECTION   = ' '
        CHANGING
          FILE_TABLE       = IT_TAB
          RC               = GD_SUBRC.
      LOOP AT IT_TAB INTO P_FILE.
    *    so_fpath-sign = 'I'.
    *    so_fpath-option = 'EQ'.
    *    append so_fpath.
      ENDLOOP.
    AT SELECTION-SCREEN OUTPUT.
      LOOP AT SCREEN.
        IF SCREEN-GROUP1 = 'ACT'.
          IF P_INCLUD = ' '.
            SCREEN-INPUT = '0'.
          ELSE.
            SCREEN-INPUT = '1'.
          ENDIF.
        ENDIF.
        IF SCREEN-GROUP1 = 'SHL'.
          IF P_DT_TM = 'X'.
            SCREEN-INPUT = '1'.
          ELSE.
            SCREEN-INPUT = '0'.
          ENDIF.
        ENDIF.
        MODIFY SCREEN.
      ENDLOOP.
    INITIALIZATION.
      P_DATE = SY-DATUM.
      P_TIME = SY-UZEIT + 180.
    START-OF-SELECTION.
      IF P_INCLUD = 'X' AND P_FILE IS INITIAL.
        MESSAGE 'Enter the Manual R-15 File' TYPE 'E'.
      ENDIF.
    *  IF P_INCLUD = 'X'.
    *    PERFORM UPLOAD_EXCEL_FILE.
    *    CONCATENATE 'R15' SY-DATUM '-' SY-UZEIT INTO LV_SERVER_FILE_PREFIX.
    *    CONCATENATE LV_SERVER_FILE_PREFIX '-' 'LT.TMP' INTO
    *    LV_SERVER_DATAFILE_NAME.
    *    OPEN DATASET LV_SERVER_DATAFILE_NAME
    *      FOR OUTPUT
    *      IN TEXT MODE
    *      ENCODING DEFAULT.
    *    LOOP AT GT_MANUAL_DATA INTO GWA_MANUAL_DATA.
    *      IF ( GWA_MANUAL_DATA-COL_6 CN '0123456789 '
    *      AND GWA_MANUAL_DATA-COL_7 CN '0123456789 '
    *      AND GWA_MANUAL_DATA-COL_8 CN '0123456789 '
    *      AND GWA_MANUAL_DATA-COL_9 CN '0123456789 '
    *      AND GWA_MANUAL_DATA-COL_10 CN '0123456789 '
    *      AND GWA_MANUAL_DATA-COL_11 CN '0123456789 '
    *      AND GWA_MANUAL_DATA-COL_13 CN '0123456789 '
    *      AND GWA_MANUAL_DATA-COL_14 CN '0123456789 '
    *      AND GWA_MANUAL_DATA-COL_15 CN '0123456789 '
    *      AND GWA_MANUAL_DATA-COL_16 CN '0123456789 '
    *      AND GWA_MANUAL_DATA-COL_17 CN '0123456789 '
    *      AND GWA_MANUAL_DATA-COL_18 CN '0123456789 ' ).
    *        MESSAGE 'Character Data in Numerical Field' TYPE 'E'.
    *      ENDIF.
    *      TRANSFER GWA_MANUAL_DATA TO LV_SERVER_DATAFILE_NAME.
    *    ENDLOOP.
    *    CLOSE DATASET LV_SERVER_DATAFILE_NAME.
    *  ENDIF.  "  P_INCLUD = 'X'.
      IF P_SCHL = 'X'.
        IF P_IMMED = 'X'.
          CALL FUNCTION 'C14B_ADD_TIME'
            EXPORTING
              I_STARTTIME = SY-UZEIT
              I_STARTDATE = SY-DATUM
              I_ADDTIME   = '000010'
            IMPORTING
              E_ENDTIME   = ENDT
              E_ENDDATE   = ENDD.
        ELSEIF P_DT_TM = 'X'.
          ENDD = P_DATE.
          ENDT = P_TIME.
        ENDIF.
        CALL FUNCTION 'JOB_OPEN'
          EXPORTING
    *     DELANFREP              = ' '
    *     JOBGROUP               = ' '
            JOBNAME                = 'R15JOB'
    *      SDLSTRTDT              = ENDD
    *      SDLSTRTTM              = ENDT
    *     JOBCLASS               =
         IMPORTING
           JOBCOUNT               = JOBCOUNT
    *   CHANGING
    *     RET                    =
    *   EXCEPTIONS
    *     CANT_CREATE_JOB        = 1
    *     INVALID_JOB_DATA       = 2
    *     JOBNAME_MISSING        = 3
    *     OTHERS                 = 4
        IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
        IF P_INCLUD = 'X'.
          PERFORM UPLOAD_EXCEL_FILE.
         CONCATENATE 'R15' SY-DATUM '-' SY-UZEIT INTO LV_SERVER_FILE_PREFIX.
          CONCATENATE LV_SERVER_FILE_PREFIX '-' JOBCOUNT 'LT.TMP' INTO
          LV_SERVER_DATAFILE_NAME.
          CONDENSE LV_SERVER_DATAFILE_NAME.
          OPEN DATASET LV_SERVER_DATAFILE_NAME
            FOR OUTPUT
            IN TEXT MODE
            ENCODING DEFAULT.
          IF SY-SUBRC NE 0.
            MESSAGE 'Error in Creating File on Server' TYPE 'E'.
          ENDIF.
          LOOP AT GT_MANUAL_DATA INTO GWA_MANUAL_DATA.
            IF ( GWA_MANUAL_DATA-COL_6 CN '0123456789 '
            AND GWA_MANUAL_DATA-COL_7 CN '0123456789 '
            AND GWA_MANUAL_DATA-COL_8 CN '0123456789 '
            AND GWA_MANUAL_DATA-COL_9 CN '0123456789 '
            AND GWA_MANUAL_DATA-COL_10 CN '0123456789 '
            AND GWA_MANUAL_DATA-COL_11 CN '0123456789 '
            AND GWA_MANUAL_DATA-COL_13 CN '0123456789 '
            AND GWA_MANUAL_DATA-COL_14 CN '0123456789 '
            AND GWA_MANUAL_DATA-COL_15 CN '0123456789 '
            AND GWA_MANUAL_DATA-COL_16 CN '0123456789 '
            AND GWA_MANUAL_DATA-COL_17 CN '0123456789 '
            AND GWA_MANUAL_DATA-COL_18 CN '0123456789 ' ).
              MESSAGE 'Character Data in Numerical Field' TYPE 'E'.
            ENDIF.
            TRANSFER GWA_MANUAL_DATA TO LV_SERVER_DATAFILE_NAME.
          ENDLOOP.
          CLOSE DATASET LV_SERVER_DATAFILE_NAME.
          IF SY-SUBRC NE 0.
            MESSAGE 'Error in Creating File on Server' TYPE 'E'.
          ENDIF.
        ENDIF.  "  P_INCLUD = 'X'.
        SUBMIT ZISU_LTR15_TUNE
          WITH SO_GSBER IN SO_GSBER
          WITH SO_COKEY IN SO_COKEY
          WITH SO_MRU   IN SO_MRU
          WITH SO_GPART IN SO_GPART
          WITH P_BMNTH  =  P_BMNTH
          WITH P_COMPUT = P_COMPUT
          WITH P_INCLUD = P_INCLUD
          WITH P_FILE   = LV_SERVER_DATAFILE_NAME
          USER SY-UNAME VIA JOB 'R15JOB' NUMBER JOBCOUNT AND RETURN.
        CALL FUNCTION 'JOB_CLOSE'
          EXPORTING
    *   AT_OPMODE                         = ' '
    *   AT_OPMODE_PERIODIC                = ' '
    *   CALENDAR_ID                       = ' '
    *   EVENT_ID                          = ' '
    *   EVENT_PARAM                       = ' '
    *   EVENT_PERIODIC                    = ' '
            JOBCOUNT                          = JOBCOUNT
            JOBNAME                           = 'R15JOB'
    *   LASTSTRTDT                        = NO_DATE
    *   LASTSTRTTM                        = NO_TIME
    *   PRDDAYS                           = 0
    *   PRDHOURS                          = 0
    *   PRDMINS                           = 0
    *   PRDMONTHS                         = 0
    *   PRDWEEKS                          = 0
    *   PREDJOB_CHECKSTAT                 = ' '
    *   PRED_JOBCOUNT                     = ' '
    *   PRED_JOBNAME                      = ' '
            SDLSTRTDT                         = ENDD
            SDLSTRTTM                         = ENDT
    *   STARTDATE_RESTRICTION             = BTC_PROCESS_ALWAYS
            STRTIMMED                         = P_IMMED
    *   TARGETSYSTEM                      = ' '
    *   START_ON_WORKDAY_NOT_BEFORE       = SY-DATUM
    *   START_ON_WORKDAY_NR               = 0
    *   WORKDAY_COUNT_DIRECTION           = 0
    *   RECIPIENT_OBJ                     =
    *   TARGETSERVER                      = ' '
    *   DONT_RELEASE                      = ' '
    *   TARGETGROUP                       = ' '
    *   DIRECT_START                      =
    * IMPORTING
    *   JOB_WAS_RELEASED                  =
    * CHANGING
    *   RET                               =
    * EXCEPTIONS
    *   CANT_START_IMMEDIATE              = 1
    *   INVALID_STARTDATE                 = 2
    *   JOBNAME_MISSING                   = 3
    *   JOB_CLOSE_FAILED                  = 4
    *   JOB_NOSTEPS                       = 5
    *   JOB_NOTEX                         = 6
    *   LOCK_FAILED                       = 7
    *   INVALID_TARGET                    = 8
    *   OTHERS                            = 9
        IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
      ELSE.  " IF NOT TO RUN IN BACKGROUND
        IF P_INCLUD = 'X'.
          PERFORM UPLOAD_EXCEL_FILE.
         CONCATENATE 'R15' SY-DATUM '-' SY-UZEIT INTO LV_SERVER_FILE_PREFIX.
          CONCATENATE LV_SERVER_FILE_PREFIX '-' 'LT.TMP' INTO
          LV_SERVER_DATAFILE_NAME.
          CONDENSE LV_SERVER_DATAFILE_NAME.
          OPEN DATASET LV_SERVER_DATAFILE_NAME
            FOR OUTPUT
            IN TEXT MODE
            ENCODING DEFAULT.
          IF SY-SUBRC NE 0.
            MESSAGE 'Error in Creating File on Server' TYPE 'E'.
          ENDIF.
          LOOP AT GT_MANUAL_DATA INTO GWA_MANUAL_DATA.
            IF ( GWA_MANUAL_DATA-COL_6 CN '0123456789 '
            AND GWA_MANUAL_DATA-COL_7 CN '0123456789 '
            AND GWA_MANUAL_DATA-COL_8 CN '0123456789 '
            AND GWA_MANUAL_DATA-COL_9 CN '0123456789 '
            AND GWA_MANUAL_DATA-COL_10 CN '0123456789 '
            AND GWA_MANUAL_DATA-COL_11 CN '0123456789 '
            AND GWA_MANUAL_DATA-COL_13 CN '0123456789 '
            AND GWA_MANUAL_DATA-COL_14 CN '0123456789 '
            AND GWA_MANUAL_DATA-COL_15 CN '0123456789 '
            AND GWA_MANUAL_DATA-COL_16 CN '0123456789 '
            AND GWA_MANUAL_DATA-COL_17 CN '0123456789 '
            AND GWA_MANUAL_DATA-COL_18 CN '0123456789 ' ).
              MESSAGE 'Character Data in Numerical Field' TYPE 'E'.
            ENDIF.
            TRANSFER GWA_MANUAL_DATA TO LV_SERVER_DATAFILE_NAME.
          ENDLOOP.
          CLOSE DATASET LV_SERVER_DATAFILE_NAME.
          IF SY-SUBRC NE 0.
            MESSAGE 'Error in Creating File on Server' TYPE 'E'.
          ENDIF.
        ENDIF.  "  P_INCLUD = 'X'.
        IF NOT SY-BATCH IS INITIAL.
          SUBMIT ZISU_LTR15_TUNE
            WITH SO_GSBER IN SO_GSBER
            WITH SO_COKEY IN SO_COKEY
            WITH SO_MRU   IN SO_MRU
            WITH SO_GPART IN SO_GPART
            WITH P_BMNTH  =  P_BMNTH
            WITH P_COMPUT = P_COMPUT
            WITH P_INCLUD = P_INCLUD
            WITH P_FILE   = LV_SERVER_DATAFILE_NAME
            TO SAP-SPOOL WITHOUT SPOOL DYNPRO.
        ELSE.
          SUBMIT ZISU_LTR15_TUNE
            WITH SO_GSBER IN SO_GSBER
            WITH SO_COKEY IN SO_COKEY
            WITH SO_MRU   IN SO_MRU
            WITH SO_GPART IN SO_GPART
            WITH P_BMNTH  =  P_BMNTH
            WITH P_COMPUT = P_COMPUT
            WITH P_INCLUD = P_INCLUD
            WITH P_FILE   = LV_SERVER_DATAFILE_NAME.
        ENDIF.
      ENDIF.
    *&      Form  divison_data_get
    *       text
    *      <--P_SO_COKEY_LOW  text
    FORM DIVISON_DATA_GET  CHANGING P_SO_COKEY_LOW.
    **to get the search help for division
      DATA : LV_LINES TYPE SY-TFILL,
            LT_RETURN_TAB LIKE DDSHRETVAL OCCURS 0, " with header line.
            LWA_RETURN_TAB LIKE DDSHRETVAL.
      DATA: LV_COKEY TYPE ZEVERFKKVKP-COKEY.
    **according to the Business area entered]
    *  break csebdev1.
      REFRESH R_COKEY[].
      DESCRIBE TABLE SO_GSBER LINES LV_LINES.
    **  when user has neither pressed the enter key nor selected the values
    **using search help
      IF LV_LINES = 0.
    *  loop at so_gsber.
        CLEAR R_COKEY.
    *    if so_gsber-high is initial.
    *    break csebdev1.
        DYFIELDS-FIELDNAME = 'SO_GSBER-LOW'.
        APPEND DYFIELDS.
        CALL FUNCTION 'DYNP_VALUES_READ'
          EXPORTING
            DYNAME     = SY-CPROG
            DYNUMB     = SY-DYNNR
          TABLES
            DYNPFIELDS = DYFIELDS.
    *      r_cokey-sign = 'I'.
    *      r_cokey-option = 'CP'.
    *r_cokey-low = so_gsber-low+0(2).
        CONCATENATE DYFIELDS-FIELDVALUE+0(2) '*' INTO R_COKEY-LOW.
    *    elseif not so_gsber-high is initial.
        DYFIELDS-FIELDNAME = 'SO_GSBER-HIGH'.
        APPEND DYFIELDS.
        CALL FUNCTION 'DYNP_VALUES_READ'
          EXPORTING
            DYNAME     = SY-CPROG
            DYNUMB     = SY-DYNNR
          TABLES
            DYNPFIELDS = DYFIELDS.
        IF NOT DYFIELDS-FIELDVALUE IS INITIAL.
          CONCATENATE DYFIELDS-FIELDVALUE+0(2) '99999999' INTO R_COKEY-HIGH.
        ENDIF.
    *    endif.
        IF NOT R_COKEY-HIGH IS INITIAL.
          R_COKEY-SIGN = 'I'.
          R_COKEY-OPTION = 'BT'.
        ELSEIF R_COKEY-HIGH IS INITIAL.
          R_COKEY-SIGN = 'I'.
          R_COKEY-OPTION = 'CP'.
        ENDIF.
        APPEND R_COKEY.
      ENDIF.
    *  endloop.
    *  APPEND DYFIELDS.
      IF LV_LINES > 0.
    *    break-point.
        IF NOT SO_GSBER[] IS INITIAL.
          LOOP AT SO_GSBER.
    *        r_cokey-sign = 'I'.
    *        r_cokey-option = 'CP'.
    *r_cokey-low = so_gsber-low+0(2).
            CONCATENATE SO_GSBER-LOW+0(2) '*' INTO R_COKEY-LOW.
            IF NOT SO_GSBER-HIGH IS INITIAL.
              CONCATENATE SO_GSBER-HIGH+0(2) '99999999' INTO R_COKEY-HIGH.
            ENDIF.
            IF NOT R_COKEY-HIGH IS INITIAL.
              R_COKEY-SIGN = 'I'.
              R_COKEY-OPTION = 'BT'.
            ELSEIF R_COKEY-HIGH IS INITIAL.
              R_COKEY-SIGN = 'I'.
              R_COKEY-OPTION = 'CP'.
            ENDIF.
            APPEND R_COKEY TO R_COKEY.
          ENDLOOP.
        ENDIF.
      ENDIF.
      IF NOT R_COKEY[] IS INITIAL.
    * break csebdev1.
        REFRESH GT_TECOKT[].
        SELECT COKEY LTEXT
        FROM TECOKT
        INTO TABLE GT_TECOKT
        WHERE COKEY IN R_COKEY AND SPRAS = 'EN'.
    *    %_HINTS ORACLE '("TECOKT","TECOKT~1")'.
      ENDIF.
    **now call the search help
      CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
        EXPORTING
    *   DDIC_STRUCTURE         = ' '
          RETFIELD               = 'COKEY'
    *   PVALKEY                = ' '
    *   DYNPPROG               = ' '
    *   DYNPNR                 = ' '
    *   DYNPROFIELD            = ' '
    *   STEPL                  = 0
         WINDOW_TITLE           = 'Division'
         VALUE                  = DYFIELDS-FIELDVALUE
         VALUE_ORG              = 'S'
    *   MULTIPLE_CHOICE        = ' '
    *   DISPLAY                = ' '
    *   CALLBACK_PROGRAM       = ' '
    *   CALLBACK_FORM          = ' '
    *   MARK_TAB               =
    * IMPORTING
    *   USER_RESET             =
        TABLES
          VALUE_TAB              = GT_TECOKT
    *   FIELD_TAB              =
         RETURN_TAB             = LT_RETURN_TAB
    *   DYNPFLD_MAPPING        =
    * EXCEPTIONS
    *   PARAMETER_ERROR        = 1
    *   NO_VALUES_FOUND        = 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.
      READ TABLE LT_RETURN_TAB INTO LWA_RETURN_TAB INDEX 1.
      LV_COKEY = LWA_RETURN_TAB-FIELDVAL.
    *break csebdev1.
    ENDFORM.                    " divison_data_get
    *&      Form  upload_excel_file
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM UPLOAD_EXCEL_FILE .
      DATA: LV_INDEX TYPE I.
      FIELD-SYMBOLS <VAL> TYPE ANY.
      CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
        EXPORTING
          FILENAME                = P_FILE
          I_BEGIN_COL             = 1
          I_BEGIN_ROW             = 8
          I_END_COL               = 18
          I_END_ROW               = 94
        TABLES
          INTERN                  = GT_INTERN_DATA
        EXCEPTIONS
          INCONSISTENT_PARAMETERS = 1
          UPLOAD_OLE              = 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.
      IF NOT GT_INTERN_DATA[] IS INITIAL.
        SORT GT_INTERN_DATA BY ROW COL.
        LOOP AT GT_INTERN_DATA.
          MOVE GT_INTERN_DATA-COL TO LV_INDEX.
          ASSIGN COMPONENT LV_INDEX OF STRUCTURE GWA_MANUAL_DATA TO <VAL>.
          MOVE GT_INTERN_DATA-VALUE TO <VAL>.
          AT END OF ROW.
            APPEND GWA_MANUAL_DATA TO GT_MANUAL_DATA.
            CLEAR GWA_MANUAL_DATA.
          ENDAT.
        ENDLOOP.
      ENDIF.
    ENDFORM.                    " upload_excel_file
    *&      Form  MRU_DATA_GET
    *       text
    *      <--P_SO_MRU_LOW  text
    FORM MRU_DATA_GET  CHANGING LV_MRU.
    **to get the search help for Group
      DATA : LV_LINES TYPE SY-TFILL,
            LT_RETURN_TAB LIKE DDSHRETVAL OCCURS 0,
            LWA_RETURN_TAB LIKE DDSHRETVAL.
    *        lv_mru_p(3) type c.
      RANGES  R_MRU FOR EANLH-ABLEINH.
    **according to the Business area entered
    **  break csebdev1.
      REFRESH R_MRU[].
      DESCRIBE TABLE SO_GSBER LINES LV_LINES.
    **  when user has neither pressed the enter key nor selected the values
    **using search help
      IF LV_LINES = 0.
        CLEAR R_MRU[].
        DYFIELDS-FIELDNAME = 'SO_GSBER-LOW'.
        APPEND DYFIELDS.
        CALL FUNCTION 'DYNP_VALUES_READ'
          EXPORTING
            DYNAME     = SY-CPROG
            DYNUMB     = SY-DYNNR
          TABLES
            DYNPFIELDS = DYFIELDS.
        CONCATENATE DYFIELDS-FIELDVALUE+0(2) '*' INTO R_MRU-LOW.
        DYFIELDS-FIELDNAME = 'SO_GSBER-HIGH'.
        APPEND DYFIELDS.
        CALL FUNCTION 'DYNP_VALUES_READ'
          EXPORTING
            DYNAME     = SY-CPROG
            DYNUMB     = SY-DYNNR
          TABLES
            DYNPFIELDS = DYFIELDS.
        IF NOT DYFIELDS-FIELDVALUE IS INITIAL.
          CONCATENATE DYFIELDS-FIELDVALUE+0(2) '99999999' INTO R_MRU-HIGH.
        ENDIF.
        IF NOT R_MRU-HIGH IS INITIAL.
          R_MRU-SIGN   = 'I'.
          R_MRU-OPTION = 'BT'.
        ELSEIF R_MRU-HIGH IS INITIAL.
          R_MRU-SIGN   = 'I'.
          R_MRU-OPTION = 'CP'.
        ENDIF.
        APPEND R_MRU.
      ENDIF. " end lv_lines =0
      IF LV_LINES > 0.
        IF NOT SO_GSBER[] IS INITIAL.
          LOOP AT SO_GSBER.
            CONCATENATE SO_GSBER-LOW+0(2) '*' INTO R_MRU-LOW.
            IF NOT SO_GSBER-HIGH IS INITIAL.
              CONCATENATE SO_GSBER-HIGH+0(2) '99999999' INTO R_MRU-HIGH.
            ENDIF.
            IF R_MRU-HIGH IS INITIAL.
              R_MRU-SIGN   = 'I'.
              R_MRU-OPTION = 'CP'.
            ELSEIF NOT R_MRU-HIGH IS INITIAL.
              R_MRU-SIGN   = 'I'.
              R_MRU-OPTION = 'BT'.
            ENDIF.
            APPEND R_MRU.
          ENDLOOP.
        ENDIF. " end so_GSBER[]
      ENDIF. " end lv_lines > 0
      IF NOT R_MRU[] IS INITIAL.
    * break csebdev1.
        REFRESH GT_TE422[].
        SELECT TERMSCHL TERMTEXT FROM TE422 INTO CORRESPONDING FIELDS OF
    TABLE GT_TE422 WHERE TERMSCHL IN R_MRU .
      ENDIF.
    **now call the search help
      CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
        EXPORTING
    *   DDIC_STRUCTURE         = ' '
          RETFIELD               = 'TERMSCHL'
    *   PVALKEY                = ' '
    *   DYNPPROG               = ' '
    *   DYNPNR                 = ' '
    *   DYNPROFIELD            = ' '
    *   STEPL                  = 0
         WINDOW_TITLE           = 'Group'
         VALUE                  = DYFIELDS-FIELDVALUE
         VALUE_ORG              = 'S'
    *   MULTIPLE_CHOICE        = ' '
    *   DISPLAY                = ' '
    *   CALLBACK_PROGRAM       = ' '
    *   CALLBACK_FORM          = ' '
    *   MARK_TAB               =
    * IMPORTING
    *   USER_RESET             =
        TABLES
          VALUE_TAB              = GT_TE422
    *   FIELD_TAB              =
         RETURN_TAB             = LT_RETURN_TAB
    *   DYNPFLD_MAPPING        =
    * EXCEPTIONS
    *   PARAMETER_ERROR        = 1
    *   NO_VALUES_FOUND        = 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.
      READ TABLE LT_RETURN_TAB INTO LWA_RETURN_TAB INDEX 1.
      LV_MRU = LWA_RETURN_TAB-FIELDVAL.
    ENDFORM.                    " MRU_DATA_GET
    <b>b) ZISU_LTR15_TUNE - Actual R15 report</b>
    *& Report  ZISU_LTR15_TUNE                                             *
    REPORT  ZISU_LTR15_TUNE NO STANDARD PAGE HEADING  MESSAGE-ID ZISU
    LINE-SIZE 250 LINE-COUNT 65.
    **Tables
    TABLES :  EVER,
              FKKVKP,
              EANLH.
    SELECTION-SCREEN BEGIN OF BLOCK SELECTION
                              WITH FRAME TITLE TEXT-001 . "no intervals.
    SELECT-OPTIONS: SO_GSBER FOR EVER-GSBER OBLIGATORY,
                    SO_COKEY FOR EVER-COKEY,
                    SO_MRU   FOR EANLH-ABLEINH.
    PARAMETERS:     P_BMNTH(7) TYPE C OBLIGATORY.
    PARAMETERS:     P_CONT TYPE EVER-VERTRAG.
    SELECT-OPTIONS: SO_GPART FOR FKKVKP-GPART.
    SELECTION-SCREEN END OF BLOCK SELECTION.
    SELECTION-SCREEN BEGIN OF BLOCK PROCESS WITH FRAME.
    PARAMETERS:     P_COMPUT RADIOBUTTON GROUP R15.
    PARAMETERS:     P_INCLUD RADIOBUTTON GROUP R15,
                    P_FILE(60) TYPE C.
    SELECTION-SCREEN END OF BLOCK PROCESS.
    *              Start of Type declaration
    TYPES: BEGIN OF ST_TB024 ,
            IND_SECTOR TYPE TB024-IND_SECTOR,
            TEXTLONG TYPE TB024-TEXTLONG,
          END   OF ST_TB024,
          BEGIN OF ST_TECOKT,
            COKEY TYPE TECOKT-COKEY,
            LTEXT TYPE TECOKT-LTEXT,
          END   OF ST_TECOKT,
          BEGIN OF ST_TGSBT,
            GSBER   TYPE TGSBT-GSBER,
            GTEXT   TYPE TGSBT-GTEXT,
          END   OF ST_TGSBT,
          BEGIN OF ST_TE422,
            TERMSCHL  TYPE TE422-TERMSCHL,
            TERMTEXT  TYPE TE422-TERMTEXT,
          END   OF ST_TE422.
    *              Start of data declaration
    DATA: IT_TAB TYPE FILETABLE,
          GD_SUBRC TYPE I.
    DATA : GT_TB024 TYPE STANDARD TABLE OF ST_TB024 WITH HEADER LINE
             INITIAL SIZE 0,
           GT_TECOKT TYPE STANDARD TABLE OF ST_TECOKT
             WITH HEADER LINE,
          GT_TGSBT TYPE SORTED TABLE OF ST_TGSBT
          WITH UNIQUE KEY GSBER WITH HEADER LINE,
          GT_TE422 TYPE TABLE OF ST_TE422 WITH HEADER LINE INITIAL SIZE 0,
          BEGIN OF GWA_EVER,
            VKONT    TYPE EVER-VKONTO,
            ANLAGE   TYPE EVER-ANLAGE,
            ABRSPERR TYPE EVER-ABRSPERR,
          END   OF GWA_EVER,
          GT_EVER LIKE TABLE OF GWA_EVER INITIAL SIZE 0,
          BEGIN OF GWA_EANLH,
          ANLAGE     TYPE EANLH-ANLAGE,
          BRANCHE    TYPE EANLH-BRANCHE,
          END   OF GWA_EANLH,
          GT_EANLH LIKE TABLE OF GWA_EANLH INITIAL SIZE 0,
          BEGIN OF GWA_FKKVKP,
            VKONT   TYPE FKKVKP-VKONT,
            KTOKL   TYPE FKKVKP-KTOKL,
          END   OF GWA_FKKVKP,
          GT_FKKVKP LIKE TABLE OF GWA_FKKVKP INITIAL SIZE 0,
          BEGIN OF GWA_EVER_EANLH_FKKVKP,
            VKONT   TYPE FKKVKP-VKONT,
            ANLAGE   TYPE EVER-ANLAGE,
            ABRSPERR TYPE EVER-ABRSPERR,
            BRANCHE  TYPE EANLH-BRANCHE,
            KTOKL    TYPE FKKVKP-KTOKL,
          END OF GWA_EVER_EANLH_FKKVKP,
          GT_EVER_EANLH_FKKVKP LIKE TABLE OF GWA_EVER_EANLH_FKKVKP
            INITIAL SIZE 0,
          GT_EVER_EANLH_FKKVKP_INACT LIKE STANDARD TABLE OF
            GWA_EVER_EANLH_FKKVKP INITIAL SIZE 0,
          BEGIN OF GWA_ERCH,
            BELNR      TYPE ERCH-BELNR,
            VKONT      TYPE ERCH-VKONT,
          END OF GWA_ERCH,
          GT_ERCH LIKE TABLE OF GWA_ERCH INITIAL SIZE 0,
          BEGIN OF GWA_PRINTDOC,
            OPBEL    TYPE ERDK-OPBEL,
            GPART    TYPE ERDK-PARTNER,
            VKONT    TYPE ERDK-VKONT,
            BUDAT    TYPE ERDK-BUDAT,
            FAEDN    TYPE ERDK-FAEDN,
          END   OF GWA_PRINTDOC,
          GT_PRINTDOC LIKE TABLE OF GWA_PRINTDOC INITIAL SIZE 0,
          BEGIN OF GWA_DBERCHZ1,
            BELNR      TYPE DBERCHZ1-BELNR,
            EIN01      TYPE DBERCHZ1-EIN01,
            V_ABRMENGE TYPE DBERCHZ1-V_ABRMENGE,
          END OF GWA_DBERCHZ1,
          GT_DBERCHZ1 LIKE TABLE OF GWA_DBERCHZ1 INITIAL SIZE 0,
          BEGIN OF GWA_ERCHC,
            BELNR     TYPE ERCHC-BELNR,
            OPBEL     TYPE ERCHC-OPBEL,
            BUDAT     TYPE ERCHC-BUDAT,
          END   OF GWA_ERCHC,
          GT_ERCHC LIKE TABLE OF GWA_ERCHC INITIAL SIZE 0,
    * arrears for inactive consumers.
          BEGIN OF GWA_DFKKOP_INACTIVE_ARR,
              OPBEL       TYPE DFKKOP-OPBEL,
              VKONT       TYPE DFKKOP-VKONT,
              BETRH       TYPE DFKKOP-BETRH,
          END OF GWA_DFKKOP_INACTIVE_ARR,
          GT_DFKKOP_INACTIVE_ARR LIKE TABLE OF GWA_DFKKOP_INACTIVE_ARR
            INITIAL SIZE 0,
          BEGIN OF GWA_ETTIFN,
            ANLAGE    TYPE ETTIFN-ANLAGE,
            OPERAND   TYPE ETTIFN-OPERAND,
            WERT1     TYPE ETTIFN-WERT1,
          END OF GWA_ETTIFN,
          GT_ETTIFN LIKE SORTED TABLE OF GWA_ETTIFN
            WITH NON-UNIQUE KEY ANLAGE OPERAND INITIAL SIZE 0,
          BEGIN OF GWA_DBERDLB,
            PRINTDOC     TYPE DBERDLB-PRINTDOC,
            BILLDOC      TYPE DBERDLB-BILLDOC,
            BILLDOCLINE  TYPE DBERDLB-BILLDOCLINE,
            NETTOBTR     TYPE DBERDLB-NETTOBTR,
          END OF GWA_DBERDLB,
          GT_DBERDLB LIKE TABLE OF GWA_DBERDLB INITIAL SIZE 0,
          BEGIN OF GWA_DBERCHZ1_BILL,
            BELNR       TYPE DBERCHZ1-BELNR,
            BELZEILE    TYPE DBERCHZ1-BELZEILE,
            TVORG       TYPE DBERCHZ1-TVORG,
          END   OF GWA_DBERCHZ1_BILL,
          GT_DBERCHZ1_BILL LIKE TABLE OF GWA_DBERCHZ1_BILL INITIAL SIZE 0,
          BEGIN OF GWA_BILLDOC,
            PRINTDOC TYPE ERDK-OPBEL,
            BILLDOC TYPE DBERDLB-BILLDOC,
          END OF GWA_BILLDOC,
          GT_BILLDOC LIKE TABLE OF GWA_BILLDOC INITIAL SIZE 0,
          BEGIN OF GWA_DBERCHV,
            BELNR    TYPE DBERCHV-BELNR,
            OPERAND  TYPE DBERCHV-OPERAND,
            EZ_ABRMENGE TYPE DBERCHV-EZ_ABRMENGE,
            ABLESGR  TYPE DBERCHV-ABLESGR,
            ABLESGRV TYPE DBERCHV-ABLESGRV,
          END OF GWA_DBERCHV,
          GT_DBERCHV LIKE TABLE OF GWA_DBERCHV INITIAL SIZE 0,
          BEGIN OF GWA_DFKKOP_ARREAR,
            OPBEL     TYPE DFKKOP-OPBEL,
            VKONT     TYPE DFKKOP-VKONT,
            HVORG     TYPE DFKKOP-HVORG,
            TVORG     TYPE DFKKOP-TVORG,
            BUDAT     TYPE DFKKOP-BUDAT,
            BETRH     TYPE DFKKOP-BETRH,
            AUGDT     TYPE DFKKOP-AUGDT,
            XBLNR     TYPE DFKKOP-XBLNR,
          END OF GWA_DFKKOP_ARREAR,
          GT_DFKKOP_ARREAR LIKE TABLE OF GWA_DFKKOP_ARREAR INITIAL SIZE 0,
          BEGIN OF GWA_MASTER_DATA,
            SLNO(4)      TYPE C,
            IND_SECTOR   TYPE TB024-IND_SECTOR,
            TEXTLONG     TYPE TB024-TEXTLONG,
            AC_CODE      TYPE TFK033D-FUN01,
          END   OF GWA_MASTER_DATA,
          GT_MASTER_DATA LIKE TABLE OF GWA_MASTER_DATA INITIAL SIZE 0,
    **      internal table for final prepared data
          BEGIN OF GWA_FINAL_DATA,
              SLNO(4) TYPE C,
              IND_SECTOR      TYPE TB024-IND_SECTOR, " for testing
              INDUSTRY        TYPE TB024-TEXTLONG,
              AC_CODE         TYPE TFK033D-FUN01,
    *    *for urban partners
              UPARTNER        TYPE I , "(6) type n,
              UBAD_METER      TYPE I, "(4) type n,
              UINACTIVE       TYPE I,
              ULOAD(8)        TYPE P DECIMALS 2,
              UUNITS(8)       TYPE P DECIMALS 2,
              UDEMANDS(8)     TYPE P DECIMALS 2,
              UARREARS(8)     TYPE P DECIMALS 2, "FKKMAKO-Msalm,
              UINACT_ARR(8)   TYPE P DECIMALS 2,
              BLANK(10)       TYPE C,
    *    *for rural partners
              RPARTNER        TYPE I , "(6) type n,
              RBAD_METER      TYPE I , "(4) type n,
              RINACTIVE       TYPE I,
              RLOAD(8)        TYPE P DECIMALS 2,
              RUNITS(8)       TYPE P DECIMALS 2,
              RDEMANDS(8)     TYPE P DECIMALS 2,
              RARREARS(8)     TYPE P DECIMALS 2,
              RINACT_ARR(8)   TYPE P DECIMALS 2,
          END OF GWA_FINAL_DATA,
          GT_FINAL_DATA LIKE TABLE OF GWA_FINAL_DATA INITIAL SIZE 0,
          BEGIN OF GWA_MANUAL_DATA,
            COL_1(5)        TYPE C,
            COL_2(10)       TYPE C,
            COL_3(40)       TYPE C,
            COL_4(40)       TYPE C,
            COL_5(10)       TYPE C,
            COL_6(19)       TYPE C,
            COL_7(19)       TYPE C,
            COL_8(19)       TYPE C,
            COL_9(19)       TYPE C,
            COL_10(19)      TYPE C,
            COL_11(19)      TYPE C,
            COL_12(10)      TYPE C,
            COL_13(19)      TYPE C,
            COL_14(19)      TYPE C,
            COL_15(19)      TYPE C,
            COL_16(19)      TYPE C,
            COL_17(19)      TYPE C,
            COL_18(19)      TYPE C,
          END   OF GWA_MANUAL_DATA,
          GT_MANUAL_DATA LIKE TABLE OF GWA_MANUAL_DATA INITIAL SIZE 0.
    ** Variables for grand total of all heads.
    DATA : GV_T_UPART        TYPE I,
           GV_T_RPART        TYPE I,
           GV_T_RINACTIVE    TYPE I,
           GV_T_UINACTIVE    TYPE I,
           GV_UDEF_MTR       TYPE I,
           GV_RDEF_MTR       TYPE I,
           GV_UCON_LOAD(16)  TYPE P DECIMALS 2,
           GV_RCON_LOAD(16)  TYPE P DECIMALS 2,
           GV_UUNITS(16)     TYPE P DECIMALS 2,
           GV_RUNITS(16)     TYPE P DECIMALS 2,
           GV_UDEMAND(16)    TYPE P DECIMALS 2,
           GV_RDEMAND(16)    TYPE P DECIMALS 2,
           GV_UARREAR(16)    TYPE P DECIMALS 2,
           GV_RARREAR(16)    TYPE P DECIMALS 2,
           GV_UINACT_ARR(16) TYPE P DECIMALS 2,
           GV_RINACT_ARR(16) TYPE P DECIMALS 2,
           GV_U_SD_DMD(16)       TYPE P DECIMALS 2,
           GV_R_SD_DMD(16)       TYPE P DECIMALS 2,
           GV_U_SD_ARR(16)       TYPE P DECIMALS 2,
           GV_R_SD_ARR(16)       TYPE P DECIMALS 2,
           GV_UR_PART         TYPE I,
           GV_UR_DEF_MTR      TYPE I,
           GV_UR_CON_LOAD(16) TYPE P DECIMALS 2,
           GV_UR_UNITS(16)    TYPE P DECIMALS 2,
           GV_UR_DEMAND(16)   TYPE P DECIMALS 2,
           GV_UR_ARREARS(16)  TYPE P DECIMALS 2,
           GV_LOWDATE         TYPE SY-DATUM,
           GV_HIGHDATE        TYPE SY-DATUM,
           GV_YEAR   LIKE DBERCHV-EZ_ABRMENGE,
           GV_MONTH  LIKE DBERCHZ1-V_ABRMENGE,
           GV_MNTH_NAME TYPE T247-KTX.
    DATA:
    **total meter rent
          GV_UTOTMETERRENT TYPE P LENGTH 16 DECIMALS 2,
          GV_RTOTMETERRENT TYPE P LENGTH 16 DECIMALS 2,
    **for total surcharge
          GV_UTOTSURCHRG TYPE P LENGTH 16 DECIMALS 2, "dberdlb-nettobtr,
          GV_RTOTSURCHRG TYPE P LENGTH 16 DECIMALS 2, "dberdlb-nettobtr,
    **for total ED
          GV_UTOTED TYPE P LENGTH 16 DECIMALS 2, "dberdlb-nettobtr,
          GV_RTOTED TYPE P LENGTH 16 DECIMALS 2, "dberdlb-nettobtr,
    **for total ED Cess
          GV_UTOTEDCESS TYPE P LENGTH 16 DECIMALS 2, "dberdlb-nettobtr,
          GV_RTOTEDCESS TYPE P LENGTH 16 DECIMALS 2, "dberdlb-nettobtr,
    **for total other misc rev
          GV_UTOTMISCREV  TYPE P LENGTH 16 DECIMALS 2,
          GV_RTOTMISCREV TYPE P LENGTH 16 DECIMALS 2,
    **for total ED of Free agricultural pump
          GV_RTOTEDAGRI TYPE P LENGTH 16 DECIMALS 2,
          GV_UTOTEDAGRI TYPE P LENGTH 16 DECIMALS 2,
    **for ED cess of Free agriculture pump
          GV_RTOTCESSAGRI TYPE P LENGTH 16 DECIMALS 2,
          GV_UTOTCESSAGRI TYPE P LENGTH 16 DECIMALS 2,
    ***data for selection screen data validation
          GV_GSBER TYPE EVER-GSBER,
          GV_COKEY TYPE EVER-COKEY,
          DYFIELDS LIKE DYNPREAD OCCURS 0 WITH HEADER LINE,
          GT_INTERN_DATA TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
    RANGES: R_COKEY FOR TECOKT-COKEY.
    AT SELECTION-SCREEN.
    AT SELECTION-SCREEN ON SO_GSBER.
      IF NOT SO_GSBER-LOW IS INITIAL.
        SELECT SINGLE GSBER FROM TGSBT INTO GT_TGSBT-GSBER WHERE
        GSBER = SO_GSBER-LOW.
        IF SY-SUBRC <> 0.
          MESSAGE E007.
        ENDIF.
      ENDIF.
      IF NOT SO_GSBER-HIGH IS INITIAL .
        SELECT SINGLE GSBER FROM TGSBT INTO GT_TGSBT-GSBER WHERE
        GSBER = SO_GSBER-HIGH.
        IF SY-SUBRC <> 0.
          MESSAGE E007.
        ENDIF.
      ENDIF.
    AT SELECTION-SCREEN ON P_BMNTH.
    **check the validity of Billing month format and for valid billing month
      IF P_BMNTH CO '0123456789/'.
        IF P_BMNTH CP '++++/++'.
          IF P_BMNTH+5(2) > 12.
            MESSAGE E002 WITH 'from'.
          ENDIF.
    ** current year is less than year entered
          IF SY-DATUM(4) < P_BMNTH(4).
            MESSAGE E003 WITH 'from'.
          ELSEIF SY-DATUM(4) = P_BMNTH(4).
    ** month in future
            IF SY-DATUM+4(2) < P_BMNTH+5(2).
              MESSAGE E004 WITH 'from'.
            ENDIF.
          ENDIF.
        ELSE.
          MESSAGE E001 WITH 'from'.
        ENDIF.
      ELSE.
    **  entry have some invalid char
        MESSAGE E010.
      ENDIF.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR SO_COKEY-LOW.
    **for geting the CO account assigment key of the entered Business area
      CLEAR: DYFIELDS[], DYFIELDS.
      PERFORM DIVISON_DATA_GET CHANGING SO_COKEY-LOW.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR SO_COKEY-HIGH.
      CLEAR: DYFIELDS[], DYFIELDS.
      PERFORM DIVISON_DATA_GET CHANGING SO_COKEY-HIGH.
    *AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
    *  REFRESH: IT_TAB.
    ***Opens File Open Dialog Box for selecting input file.
    *  CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
    *    EXPORTING
    *      WINDOW_TITLE     = 'Select File'
    *      DEFAULT_FILENAME = '*.xls'
    *      MULTISELECTION   = ' '
    *    CHANGING
    *      FILE_TABLE       = IT_TAB
    *      RC               = GD_SUBRC.
    *  LOOP AT IT_TAB INTO P_FILE.
    **    so_fpath-sign = 'I'.
    **    so_fpath-option = 'EQ'.
    **    append so_fpath.
    *  ENDLOOP.
    AT SELECTION-SCREEN OUTPUT.
      LOOP AT SCREEN.
        IF SCREEN-GROUP1 = 'ACT'.
          IF P_INCLUD = ' '.
            SCREEN-INPUT = '0'.
          ELSE.
            SCREEN-INPUT = '1'.
          ENDIF.
        ENDIF.
        MODIFY SCREEN.
      ENDLOOP.
    *              End of Selection screen processing
    TOP-OF-PAGE.
      DATA : LV_TEXT(70) TYPE C.
      FORMAT INTENSIFIED OFF.
      WRITE:/50 'CHHATTISGARH STATE ELECTRICITY BOARD',
            /42 'R-15 REPORT FOR LT CONSUMERS FOR THE MONTH OF',
                 GV_MNTH_NAME NO-GAP,'-' NO-GAP, P_BMNTH(4) NO-GAP,
            180 'PAGE-NO. -', SY-PAGNO LEFT-JUSTIFIED.
      SKIP.
      WRITE:/2 'RAO', 15 ':'.
      LOOP AT GT_TGSBT WHERE GSBER IN SO_GSBER.
        IF STRLEN( LV_TEXT ) > 60.
          WRITE: 16 LV_TEXT, / ''.
          CLEAR LV_TEXT.
        ENDIF.
        CONCATENATE LV_TEXT GT_TGSBT-GSBER '-' GT_TGSBT-GTEXT
          INTO LV_TEXT SEPARATED BY SPACE.
      ENDLOOP.
      WRITE: 16 LV_TEXT.
      CLEAR LV_TEXT.
      WRITE: /2 'Division',15 ':'.
      LOOP AT GT_TECOKT.
        IF STRLEN( LV_TEXT ) > 60.
          WRITE: 16 LV_TEXT, /.
          CLEAR LV_TEXT.
        ENDIF.
        CONCATENATE LV_TEXT GT_TECOKT-COKEY '-' GT_TECOKT-LTEXT
          INTO LV_TEXT SEPARATED BY SPACE.
      ENDLOOP.
      WRITE: 16 LV_TEXT.
      CLEAR LV_TEXT.
      WRITE: /2 'Group',15 ':'.
      LOOP AT GT_TE422 .
        IF STRLEN( LV_TEXT ) > 60.
          WRITE: 16 LV_TEXT, /.
          CLEAR LV_TEXT.
        ENDIF.
        CONCATENATE LV_TEXT GT_TE422-TERMSCHL '-' GT_TE422-TERMTEXT
          INTO LV_TEXT SEPARATED BY SPACE.
      ENDLOOP.
      WRITE: 16 LV_TEXT.
      CLEAR LV_TEXT.
    **legends
    *  write :/ text-028, 15 ':',16 text-029.
    **now write the headings on every page
      SET LEFT SCROLL-BOUNDARY COLUMN 50.
      FORMAT COLOR 1 ON.
      WRITE :/1(244) SY-ULINE.
      WRITE :/1 SY-VLINE,6 SY-VLINE,50 SY-VLINE, 58 SY-VLINE, 59
                '<----------------------------------',
                'U R B A N   A R E A',
                '----------------------------------->'.
      WRITE : 151 SY-VLINE, 152
                  '<----------------------------------',
                  'R U R A L   A R E A',
                  '----------------------------------->',
              244 SY-VLINE.
      WRITE :/1 SY-VLINE,
              2 'Slno',
              6 SY-VLINE,
              7 'Revenue Category',
              50 SY-VLINE,
              51 'A/C',
              58 SY-VLINE,
              59 'Cons-',
              67 SY-VLINE,
              68 'Deff',
              75 SY-VLINE,
              76 'Conn',
              89 SY-VLINE,
              90 'Sold',
              108 SY-VLINE,
              109 'Demand',
              129 SY-VLINE,
              130 'Previous',
              151 SY-VLINE,
              152 'Cons-',
              160 SY-VLINE,
              161 'Deff',
              168 SY-VLINE,
              169 'Conn',
              182 SY-VLINE,
              183 'Sold',
              201 SY-VLINE,
              202 'Demand',
              222 SY-VLINE,
              223 'Previous',
              244 SY-VLINE.
      WRITE :/1 SY-VLINE,
              6 SY-VLINE,
              50 SY-VLINE,
              51 'Code',
              58 SY-VLINE,
              59 'umers',
              67 SY-VLINE,
              68 'mtrs',
              75 SY-VLINE,
              76 'Load-KW',
              89 SY-VLINE,
              90 'Units',
              108 SY-VLINE,
              129 SY-VLINE,
              130 'Arrear',
              151 SY-VLINE,
              152 'umers',
              160 SY-VLINE,
              161 'mtrs',
              168 SY-VLINE,
              169 'Load-KW',
              182 SY-VLINE,
              183 'Units',
              201 SY-VLINE,
              222 SY-VLINE,
              223 'Arrear',
              244 SY-VLINE.
      WRITE :/1(244) SY-ULINE.
      SET LEFT SCROLL-BOUNDARY COLUMN 59.
    *              Start of Data Selection
    START-OF-SELECTION.
      SELECT GSBER GTEXT INTO TABLE GT_TGSBT FROM TGSBT
        WHERE SPRAS = SY-LANGU.
      SELECT IND_SECTOR TEXTLONG INTO TABLE GT_TB024
        FROM TB024 WHERE SPRAS = SY-LANGU
                     AND ( ( IND_SECTOR >= '01' AND IND_SECTOR <= '55' )
                      OR ( IND_SECTOR = '57' OR IND_SECTOR = '58'
                      OR IND_SECTOR = '94' ) ).
      SELECT SINGLE KTX INTO GV_MNTH_NAME FROM T247
       WHERE MNR = P_BMNTH+5(2) AND SPRAS = SY-LANGU.
    ***master data selection
      PERFORM CONSUMER_DATA_SELECTION.
    *&--Get Meter Status Connected Load & MF for each installation
      PERFORM OPERAND_DATA_SELECTION.
    *&--Get the Demand corresponding to each Print documents selected
      PERFORM BILLING_DATA_SELECTION.
    *&--Get the arrears corresponding to each Print document selected
      PERFORM ARREAR_DATA_SELECTION.
    *&--To include Mannual R-15 into computerized R-15.
      IF P_INCLUD = 'X'.
        OPEN DATASET P_FILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.
        DO.
          READ DATASET P_FILE INTO GWA_MANUAL_DATA.
          IF SY-SUBRC <> 0.
            EXIT.
          ELSE.
            APPEND GWA_MANUAL_DATA TO GT_MANUAL_DATA.
          ENDIF.
        ENDDO.
        CLOSE DATASET P_FILE.
        DELETE DATASET P_FILE.
      ENDIF.
    END-OF-SELECTION.
    *              End of data Selection
    *            Start of Data Processing
      PERFORM FINAL_TABLE_PREPARE.
      PERFORM FINAL_OUTPUT_PREPARE.
      PERFORM FINAL_OUTPUT_DISPLAY.
    *              End of Data Processing
      PERFORM FREE_MEMORY.
    *&      Form  master_data_selection
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM CONSUMER_DATA_SELECTION .
      DATA: LV_MAX_DAYS TYPE I,
            LV_LAST_DAY(2) TYPE C,
            LV_IMONTH TYPE I,
            LV_IYEAR TYPE I,
            LV_BMNTH TYPE ZERDK_ERCHC-V_ABRMENGE,
            LV_BYEAR TYPE ZERDK_ERCHC-EZ_ABRMENGE,
    *&----Temporary tables for global internal tables.
            LT_DBERCHZ1_TEMP LIKE TABLE OF GWA_DBERCHZ1,
            LWA_DBERCHZ1_TEMP LIKE GWA_DBERCHZ1,
            LT_ERCH LIKE TABLE OF GWA_ERCH,
            LWA_ERCH LIKE GWA_ERCH,
            LT_EVER LIKE TABLE OF GWA_EVER.
    *DATA: lt_ever_fkkvkp like gwa_ever_eanlh_fkkvkp occurs 0.
      LV_IMONTH = P_BMNTH+5(2).
      LV_IYEAR  = P_BMNTH(4).
      LV_BMNTH  = P_BMNTH+5(2).
      LV_BYEAR  = P_BMNTH(4).
      CALL FUNCTION 'RTP_US_API_MAX_DAYS_IN_MONTH'
        EXPORTING
          I_DATE_MONTH = LV_IMONTH
          I_DATE_YEAR  = LV_IYEAR
        IMPORTING
          E_MAX_DAYS   = LV_MAX_DAYS.
      LV_LAST_DAY = LV_MAX_DAYS.
      CONCATENATE P_BMNTH(4) P_BMNTH+5(2)  LV_LAST_DAY INTO GV_HIGHDATE.
      IF SO_GPART[] IS INITIAL.
        SELECT VKONTO ANLAGE ABRSPERR
        INTO TABLE GT_EVER
        FROM EVER
        WHERE GSBER IN SO_GSBER
          AND COKEY IN SO_COKEY
          AND   BUKRS = 'CSEB'
          AND   SPARTE = '01'
          AND   KOFIZ  = '02'.
    **get installation no from contract data and check biling class in eanlh
        IF GT_EVER[] IS INITIAL.
    MESSAGE 'No Business Partner exist for entered selection data' TYPE 'A'.
        ENDIF.
        IF NOT GT_EVER[] IS INITIAL.
          SELECT VKONT KTOKL INTO TABLE GT_FKKVKP
            FROM FKKVKP
            FOR ALL ENTRIES IN GT_EVER
            WHERE VKONT = GT_EVER-VKONT
            AND   GPART IN SO_GPART.
          IF GT_FKKVKP[] IS INITIAL.
         MESSAGE 'No Business Partner exist for entered Selection' TYPE 'A'.
          ENDIF.
        ENDIF.
      ELSE.
        SELECT VKONT KTOKL INTO TABLE GT_FKKVKP
          FROM FKKVKP
          WHERE GPART IN SO_GPART.
        IF NOT GT_FKKVKP[] IS INITIAL.
          SELECT VKONTO ANLAGE INTO TABLE GT_EVER
            FROM EVER
            FOR ALL ENTRIES IN GT_FKKVKP
            WHERE VKONTO  EQ GT_FKKVKP-VKONT
              AND GSBER   IN SO_GSBER
              AND COKEY   IN SO_COKEY
              AND BUKRS   EQ 'CSEB'
              AND SPARTE  EQ '01'
              AND KOFIZ   EQ '02'.
        ENDIF.
      ENDIF.
      IF GT_EVER[] IS INITIAL AND GT_FKKVKP[] IS INITIAL.
        MESSAGE 'No Business Partner exist for entered Selection' TYPE 'A'.
      ENDIF.
      SELECT ANLAGE BRANCHE INTO TABLE GT_EANLH
        FROM EANLH
        FOR ALL ENTRIES IN GT_EVER
        WHERE ANLAGE EQ GT_EVER-ANLAGE
        AND   ABLEINH IN SO_MRU
        AND   AKLASSE EQ'0002'
        AND   AB <= GV_HIGHDATE
        AND   BIS => GV_HIGHDATE.
      IF GT_EANLH[] IS INITIAL.
        MESSAGE 'No Business Partner exist for entered Selection' TYPE 'A'.
      ENDIF.
      SORT : GT_EVER BY VKONT ANLAGE,
             GT_FKKVKP BY VKONT,
             GT_EANLH BY ANLAGE.
      LOOP AT GT_EANLH INTO GWA_EANLH.
        READ TABLE GT_EVER INTO GWA_EVER WITH KEY ANLAGE = GWA_EANLH-ANLAGE.
        IF SY-SUBRC = 0.
          READ TABLE GT_FKKVKP INTO GWA_FKKVKP
            WITH KEY VKONT = GWA_EVER-VKONT.
          IF SY-SUBRC = 0.
            GWA_EVER_EANLH_FKKVKP-VKONT = GWA_EVER-VKONT.
            GWA_EVER_EANLH_FKKVKP-ANLAGE = GWA_EVER-ANLAGE.
            GWA_EVER_EANLH_FKKVKP-ABRSPERR = GWA_EVER-ABRSPERR.
            GWA_EVER_EANLH_FKKVKP-BRANCHE  = GWA_EANLH-BRANCHE.
            GWA_EVER_EANLH_FKKVKP-KTOKL    = GWA_FKKVKP-KTOKL.
            APPEND GWA_EVER_EANLH_FKKVKP TO GT_EVER_EANLH_FKKVKP.
            CLEAR GWA_EVER_EANLH_FKKVKP.
          ENDIF.
        ENDIF.
      ENDLOOP.
      IF GT_EVER_EANLH_FKKVKP[] IS INITIAL.
        MESSAGE 'No Business Partner exist for Selection Data' TYPE 'A'.
      ENDIF.
    *&----get all the billdocuments for the busines partner's contract
    *&----account
      SELECT BELNR VKONT INTO TABLE GT_ERCH
        FROM ERCH
        FOR ALL ENTRIES IN GT_EVER_EANLH_FKKVKP
        WHERE VKONT EQ GT_EVER_EANLH_FKKVKP-VKONT.
    *&----get the BILL MONTH & BILL YEAR FOR THE BILLDOCUMENTS.
      IF NOT GT_ERCH[] IS INITIAL.
        SELECT BELNR EIN01 V_ABRMENGE INTO TABLE GT_DBERCHZ1
          FROM DBERCHZ1
          FOR ALL ENTRIES IN GT_ERCH
          WHERE BELNR EQ GT_ERCH-BELNR
            AND AKLASSE = '0002'
            AND ( ( EIN01 = 'BILL_MNTH1'
            AND V_ABRMENGE = P_BMNTH+5(2) )
            OR ( EIN01 = 'BILL_YEAR1'
            AND V_ABRMENGE = P_BMNTH(4) ) ).
    *&---- GET THOSE BILL DOCUMENTS WHICH ARE FOR THE ENTERED BILL MONTH
        IF NOT GT_DBERCHZ1[] IS INITIAL.
          LOOP AT GT_DBERCHZ1 INTO GWA_DBERCHZ1 WHERE EIN01 = 'BILL_MNTH1'
                                              AND V_ABRMENGE = P_BMNTH+5(2).
            READ TABLE GT_DBERCHZ1 INTO LWA_DBERCHZ1_TEMP
            WITH KEY BELNR = GWA_DBERCHZ1-BELNR EIN01 = 'BILL_YEAR1'
            V_ABRMENGE = P_BMNTH(4).
            IF SY-SUBRC = 0.
              APPEND LWA_DBERCHZ1_TEMP TO LT_DBERCHZ1_TEMP.
              CLEAR: LWA_DBERCHZ1_TEMP.
            ENDIF.
          ENDLOOP.
          GT_DBERCHZ1[] = LT_DBERCHZ1_TEMP[].
        ENDIF.
      ENDIF.
    *&---NOW FIND THE PRINT DOCUMENTS FOR THE SELECTED BILLDOCUMENTS.
      IF NOT GT_DBERCHZ1[] IS INITIAL.
        SELECT BELNR OPBEL BUDAT FROM ERCHC
          INTO TABLE GT_ERCHC
          FOR ALL ENTRIES IN GT_DBERCHZ1
          WHERE BELNR = GT_DBERCHZ1-BELNR
            AND INTOPBEL EQ SPACE
            AND SIMULATED EQ SPACE
            AND INVOICED EQ 'X'.
      ENDIF.
      IF NOT GT_ERCHC[] IS INITIAL.
        LOOP AT GT_ERCHC INTO GWA_ERCHC.
          READ TABLE GT_ERCH INTO GWA_ERCH WITH KEY BELNR = GWA_ERCHC-BELNR.
          IF SY-SUBRC = 0.
            APPEND GWA_ERCH TO LT_ERCH.
            CLEAR GWA_ERCH.
          ENDIF.
          CLEAR GWA_ERCHC.
        ENDLOOP.
      ENDIF.
      GT_ERCH[] = LT_ERCH[].
      FREE: LT_ERCH, LT_DBERCHZ1_TEMP,LWA_DBERCHZ1_TEMP.
      LOOP AT GT_EVER_EANLH_FKKVKP INTO GWA_EVER_EANLH_FKKVKP.
    *  READ TABLE gt_erdk_erchc INTO gwa_erdk_erchc
    *  WITH KEY vkont = gwa_ever_eanlh_fkkvkp-vkont.
        READ TABLE GT_ERCH INTO GWA_ERCH
          WITH KEY VKONT = GWA_EVER_EANLH_FKKVKP-VKONT.
        IF SY-SUBRC <> 0.
          IF GWA_EVER_EANLH_FKKVKP-ABRSPERR = SPACE.
            GWA_EVER_EANLH_FKKVKP-ABRSPERR = '01'.
            MODIFY GT_EVER_EANLH_FKKVKP FROM GWA_EVER_EANLH_FKKVKP
              TRANSPORTING ABRSPERR.
            APPEND GWA_EVER_EANLH_FKKVKP TO GT_EVER_EANLH_FKKVKP_INACT.
          ENDIF.
        ELSE.
          IF GWA_EVER_EANLH_FKKVKP-ABRSPERR <> SPACE.
            GWA_EVER_EANLH_FKKVKP-ABRSPERR = SPACE.
            MODIFY GT_EVER_EANLH_FKKVKP FROM GWA_EVER_EANLH_FKKVKP
              TRANSPORTING ABRSPERR.
          ENDIF.
        ENDIF.
        CLEAR GWA_ERCH.
      ENDLOOP.
      REFRESH GT_TECOKT[].
      IF NOT SO_COKEY[] IS INITIAL.
        SELECT COKEY LTEXT INTO TABLE GT_TECOKT
        FROM TECOKT
        WHERE COKEY IN SO_COKEY
          AND SPRAS = SY-LANGU .
    *    %_HINTS ORACLE '("TECOKT","TECOKT~1")'.
      ENDIF.
      IF NOT SO_MRU[] IS INITIAL.
        SELECT TERMSCHL TERMTEXT INTO TABLE GT_TE422
          FROM TE422
          WHERE TERMSCHL IN SO_MRU.
      ENDIF.
    *FREE lt_ever_fkkvkp[].
    ENDFORM.                    " consumer_data_selection
    *&      Form  Operand_data_selection
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM OPERAND_DATA_SELECTION .
      DATA: LT_EVER_EANLH_FKKVKP_ACT LIKE TABLE OF GWA_EVER_EANLH_FKKVKP.
    *  SORT gt_ever_eanlh_fkkvkp BY vkont.
      CHECK NOT GT_EVER_EANLH_FKKVKP[] IS INITIAL.
    **now depending upon the billing month check the time slice date
    **the last date of the billing month or the range of billing month
    *should fall in between the time slice of the installation
    ** billing month to is space
    **now select operands for processed installation
      LT_EVER_EANLH_FKKVKP_ACT[] = GT_EVER_EANLH_FKKVKP[].
      DELETE LT_EVER_EANLH_FKKVKP_ACT WHERE ABRSPERR NE SPACE.
      IF NOT LT_EVER_EANLH_FKKVKP_ACT[] IS INITIAL.
        SELECT ANLAGE OPERAND WERT1
        FROM ETTIFN
        INTO TABLE GT_ETTIFN
        FOR ALL ENTRIES IN LT_EVER_EANLH_FKKVKP_ACT
        WHERE ANLAGE = LT_EVER_EANLH_FKKVKP_ACT-ANLAGE
          AND OPERAND IN ('MTR_STS','CONN_LOAD','LOAD_CODE','KWH_MF')
          AND ( AB <= GV_HIGHDATE AND BIS >= GV_HIGHDATE ).
    *    %_HINTS ORACLE '("ETTIFN","ETTIFN~003")'.
      ENDIF.
    ENDFORM.                    " Operand_data_selection
    *&      Form  billing_data_selection
    *&------------------------------

    Hi,
    Please do run time analysis as Rob correctly mentioned or do SQL trace(ST05) to find where the program is consuming more time.
    Lanka

  • Performance Example

    Last week, there was a question posted to the forum asking about how to retrieve multiple records from an internal table without using a loop…endloop construct. I posted an answer showing how it could be done using a binary search followed by indexed reads on the table. I wrote a small program which illustrates this point. I’ve posted the code below, but in a nutshell, what it does is select a number of FI document headers and line items from BKPF and BSEG. The select statement from BSEG is very inefficient. I did it that way for a reason, so please don’t give me any grief over it. It then reads all records from both tables using a nested loop. Finally it reads all records from both tables using the method I proposed. It keeps track of the number of records and time taken for each operation.
        I ran the program twice in our QA environment – once selecting a small amount of data and again selecting a moderate amount. The outputs are:
    First run -
    Time for unindexed select: 00:08:31  
        Number of BKPF entries:      1,892
        Number of BSEG entries:      5,777
    Time for nested loop: 00:00:05       
        Number of BKPF reads:      1,892 
        Number of BSEG reads:      5,777 
    Time for indexed loop: 00:00:00      
        Number of BKPF reads:      1,892 
        Number of BSEG reads:      5,777 
    Second run –
    Time for unindexed select: 00:17:31  
        Number of BKPF entries:     24,148
        Number of BSEG entries:     84,358
    Time for nested loop: 00:23:44       
        Number of BKPF reads:     24,148 
        Number of BSEG reads:     84,358 
    Time for indexed loop: 00:00:00      
        Number of BKPF reads:     24,148 
        Number of BSEG reads:     84,358 
        So what can we conclude? In the first case, a gain in time of five seconds is not much, but in a dialogue program, it might be worthwhile. But in the second case the other method gains over twenty minutes. This would allow a program that has to run in the background to run in the foreground. The most striking thing to me though, is the fact that the nested loop takes substantially longer than an extremely inefficient select statement.
        The select screen for the program is quite standard. The amount of data returned is determined by whatever the user enters and the programmer really has no control over it. So I’m suggesting that if you can’t guarantee that the amount of data is small, then you really ought to use the indexed read method.
        Also note that the first select statement returns 5,777 rows from BSEG and takes 08:31 to run and the second one returns 84,358 rows and takes 17:31. The second one retrieves almost 15 times as much data but takes only about twice as long to execute. The two runs of the program were on separate evenings when there shouldn’t be any load, so buffering and workload shouldn’t be issues.
        So, my final conclusion is: when tuning a program that you know will return a small amount of data, tune the select statement and don’t worry too much about loops; however, if the program may return a large amount of data, avoid nested loops.
    Code follows:
    REPORT ztest.
    TABLES: bkpf, bseg.
    SELECT-OPTIONS: s_bukrs FOR bseg-bukrs MEMORY ID buk OBLIGATORY,
                    s_gjahr FOR bseg-gjahr MEMORY ID gjr OBLIGATORY,
                    s_lifnr FOR bseg-lifnr MEMORY ID lif OBLIGATORY.
    DATA: BEGIN OF bkpf_int OCCURS 0.
            INCLUDE STRUCTURE bkpf.
    DATA: END   OF bkpf_int.
    DATA: BEGIN OF bseg_int OCCURS 0.
            INCLUDE STRUCTURE bseg.
    DATA: END   OF bseg_int.
    DATA: start_time   LIKE sy-uzeit,
          end_time     LIKE sy-uzeit,
          difference   LIKE sy-uzeit,
          bkpf_entries LIKE sy-tabix,
          bseg_entries LIKE sy-tabix,
          bkpf_reads   LIKE sy-tabix,
          bseg_reads   LIKE sy-tabix.
    START-OF-SELECTION.
      PERFORM unindexed_select.
      PERFORM nested_loop.
      PERFORM indexed_loop.
    *&      Form  unindexed_select
    FORM unindexed_select.
      GET TIME FIELD start_time.
      SELECT * FROM bseg INTO TABLE bseg_int
        WHERE  bukrs IN s_bukrs
        AND    gjahr IN s_gjahr
        AND    lifnr IN s_lifnr.
      SELECT * FROM bkpf INTO TABLE bkpf_int
        FOR ALL ENTRIES IN bseg_int
        WHERE bukrs = bseg_int-bukrs
        AND   belnr = bseg_int-belnr
        AND   gjahr = bseg_int-gjahr
        AND   bstat = space.
      CLEAR   bseg_int.
      REFRESH bseg_int.
      SELECT * FROM bseg INTO TABLE bseg_int
        FOR ALL ENTRIES IN bkpf_int
        WHERE bukrs = bkpf_int-bukrs
        AND   belnr = bkpf_int-belnr
        AND   gjahr = bkpf_int-gjahr.
      GET TIME FIELD end_time.
      difference = end_time - start_time.
      DESCRIBE TABLE bkpf_int LINES bkpf_entries.
      DESCRIBE TABLE bseg_int LINES bseg_entries.
      WRITE: /001 'Time for unindexed select:', difference,
             /005 'Number of BKPF entries:', bkpf_entries,
             /005 'Number of BSEG entries:', bseg_entries.
    ENDFORM.                    " unindexed_select
    *&      Form  nested_loop
    FORM nested_loop.
      GET TIME FIELD start_time.
      LOOP AT bkpf_int.
        bkpf_reads = bkpf_reads + 1.
        LOOP AT bseg_int WHERE
          bukrs = bkpf_int-bukrs AND
          belnr = bkpf_int-belnr AND
          gjahr = bkpf_int-gjahr.
          bseg_reads = bseg_reads + 1.
        ENDLOOP.
      ENDLOOP.
      GET TIME FIELD end_time.
      difference = end_time - start_time.
      WRITE: /001 'Time for nested loop:', difference,
             /005 'Number of BKPF reads:', bkpf_reads,
             /005 'Number of BSEG reads:', bseg_reads.
    ENDFORM.                    " nested_loop
    *&      Form  indexed_loop
    *       text
    FORM indexed_loop.
      DATA: bkpf_index LIKE sy-tabix,
            bseg_index LIKE sy-tabix.
      CLEAR: bkpf_reads,
             bseg_reads.
      GET TIME FIELD start_time.
      SORT: bkpf_int BY bukrs belnr gjahr,
            bseg_int BY bukrs belnr gjahr.
      LOOP AT bkpf_int.
        READ TABLE bseg_int WITH KEY
          bukrs = bkpf_int-bukrs
          belnr = bkpf_int-belnr
          gjahr = bkpf_int-gjahr
          BINARY SEARCH.
        bkpf_reads = bkpf_reads + 1.
        bseg_index = sy-tabix.
        WHILE sy-subrc = 0.
          bseg_index = bseg_index + 1.
          bseg_reads = bseg_reads + 1.
          READ TABLE bseg_int INDEX bseg_index.
          IF bseg_int-bukrs <> bkpf_int-bukrs OR
             bseg_int-belnr <> bkpf_int-belnr OR
             bseg_int-gjahr <> bkpf_int-gjahr.
            sy-subrc = 99.
          ELSE.
          ENDIF.
        ENDWHILE.
      ENDLOOP.
      GET TIME FIELD end_time.
      difference = end_time - start_time.
      WRITE: /001 'Time for indexed loop:', difference,
             /005 'Number of BKPF reads:', bkpf_reads,
             /005 'Number of BSEG reads:', bseg_reads.
    ENDFORM.                    " indexed_loop

    Hi, something in additional.
    Can anyone explain why the two ways has a so definitely difference in performance, in the ABAP runtime analyze view.
    In my opinion, maybe binary read is a short quick action in the memory. On the opposite side, when do nested loop, the runtime will need many swap memory action as it need to keep the status info of external loop, that will cost a lost in performance.
    That's the supposition of mine. Really hope anyone can explain the reason under the phenomena.
    thanks

  • RE: PERFORMANCE

    REPORT ZCHECK .
    *&                      TABLES/VIEWS
    TABLES: mseg,
            ser03,
            objk,
           zprealert,
            vbrk,
            vbrp,
            zinftsalecntrl,
            vbfa.
    *&                VARIABLES/STRUCTURES/INTERNAL TABLES
    DATA: BEGIN OF it_mseg OCCURS 0,
            mblnr     LIKE mseg-mblnr,
            mjahr     LIKE mseg-mjahr,
            zeile     LIKE mseg-zeile,
          END OF it_mseg.
    DATA: BEGIN OF it_ser03 OCCURS 0,
            obknr     LIKE ser03-obknr,
            mblnr     LIKE ser03-mblnr,
            zeile     LIKE ser03-zeile,
            bwart     LIKE ser03-bwart,
            charge    LIKE ser03-charge,
            datum     LIKE ser03-datum,
            werk      LIKE ser03-werk,
            lagerort  LIKE ser03-lagerort,
          END OF it_ser03.
    DATA: BEGIN OF it_objk OCCURS 0,
            obknr LIKE objk-obknr,
            sernr LIKE objk-sernr,
            matnr LIKE objk-matnr,
          END OF it_objk.
    DATA: BEGIN OF it_alert OCCURS 0,
            rsnno LIKE zprealert-rsnno,
    ***kdamle-27102004-start
            status LIKE zprealert-status,
    ***kdamle-27102004-end
          END OF it_alert.
    DATA: BEGIN OF it_vbrk OCCURS 0,
            vbeln LIKE vbrk-vbeln,
            fkdat LIKE vbrk-fkdat,
            fkart LIKE vbrk-fkart,
            vkorg LIKE vbrk-vkorg,
            vtweg LIKE vbrk-vtweg,
            spart LIKE vbrk-spart,
            fksto LIKE vbrk-fksto,
          END OF it_vbrk.
    DATA: BEGIN OF it_vbrp OCCURS 0,
            vbeln LIKE vbrp-vbeln,
            matnr LIKE vbrp-matnr,
            charg LIKE vbrp-charg,
          END OF it_vbrp.
    DATA: BEGIN OF it_inftsale OCCURS 0,
            delivery    LIKE zinftsalecntrl-delivery,
            billingdoc  LIKE zinftsalecntrl-billingdoc,
          END OF it_inftsale.
    DATA: BEGIN OF it_vbfa OCCURS 0,
            vbelv LIKE vbfa-vbelv,
            vbeln LIKE vbfa-vbeln,
          END OF it_vbfa.
    DATA: BEGIN OF it_vbfa_1 OCCURS 0,
            vbelv   LIKE vbfa-vbelv,
            vbeln   LIKE vbfa-vbeln,
            vbtyp_v LIKE vbfa-vbtyp_v,
    ***kdamle-19052005-start
            vbtyp_n LIKE vbfa-vbtyp_n,
    ***kdamle-19052005-end
          END OF it_vbfa_1.
    DATA: BEGIN OF it_vbfa_2 OCCURS 0,
            vbelv   LIKE vbfa-vbelv,
            vbeln   LIKE vbfa-vbeln,
            vbtyp_n LIKE vbfa-vbtyp_n,
    ***kdamle-19052005-start
            plmin   LIKE vbfa-plmin,
    ***kdamle-19052005-end
          END OF it_vbfa_2.
    DATA: BEGIN OF it_out OCCURS 0,
            rsnno     LIKE zprealert-rsnno,
            matnr     LIKE objk-matnr,
            charg     LIKE ser03-charge,
            bwart     LIKE ser03-bwart,
            mblnr     LIKE ser03-mblnr,
            vbeln     LIKE vbrk-vbeln,
            datum     LIKE ser03-datum,
            zeile     LIKE ser03-zeile,
            werk      LIKE ser03-werk,
            lagerort  LIKE ser03-lagerort,
            fkdat     LIKE vbrk-fkdat,
            fkart     LIKE vbrk-fkart,
            vkorg     LIKE vbrk-vkorg,
            vtweg     LIKE vbrk-vtweg,
            spart     LIKE vbrk-spart,
    ***kdamle-27102004-start
            status    LIKE zprealert-status,
    ***kdamle-27102004-end
          END OF it_out.
    ***kdamle-05.10.2004-start
    *display table as per o/p file structure
    DATA: BEGIN OF it_disp OCCURS 0,
            rsnno     LIKE zprealert-rsnno,
            matnr     LIKE objk-matnr,
            charg     LIKE ser03-charge,
            bwart     LIKE ser03-bwart,
            mblnr     LIKE ser03-mblnr,
            zeile     LIKE ser03-zeile,
            werk      LIKE ser03-werk,
            lagerort  LIKE ser03-lagerort,
            datum     LIKE ser03-datum,
            vbeln     LIKE vbrk-vbeln,
            fkdat     LIKE vbrk-fkdat,
            fkart     LIKE vbrk-fkart,
            vkorg     LIKE vbrk-vkorg,
            vtweg     LIKE vbrk-vtweg,
            spart     LIKE vbrk-spart,
          END OF it_disp.
    DATA : BEGIN OF it_formatted OCCURS 0,
            record(140),
           END OF it_formatted.
    DATA: BEGIN OF it_dwn OCCURS 0,
            text1(15),
            text2(15),
            text3(15),
            text4(15),
            text5(15),
          END OF it_dwn.
    *This table will contain uploaded mblnr or vbeln data
    *in foreground, it will contain either mblnr or vbeln.
    *in backround, it will first contain data uploaded from users machine
    *and loaded on the application server.
    *Then it is erased and filled with data which is read from application
    *server since data from users machine cannot be read in background
    DATA: BEGIN OF it_up OCCURS 0,
    ***kdamle-24052005-start
    *positions swapped for vbeln and mblnr
            vbeln LIKE vbrk-vbeln,
            mblnr LIKE ser03-mblnr,
    ***kdamle-24052005-end
          END OF it_up.
    ***kdamle-05.10.2004-end
    DATA : it_alv LIKE STANDARD TABLE OF it_out.
    DATA: cntnr TYPE REF TO cl_gui_custom_container,
          grid TYPE REF TO cl_gui_alv_grid.
    DATA: gt_fieldcat  TYPE slis_t_fieldcat_alv,
          s_fieldcat   LIKE LINE OF gt_fieldcat,
          alv_layout   TYPE slis_layout_alv.
    DATA: ls_alv_event TYPE slis_alv_event,
          i_alv_event  TYPE slis_t_event.
    DATA: gt_list_top_of_page   TYPE slis_t_listheader,
          infotxt               TYPE slis_listheader-info.
    DATA: g_variant LIKE disvariant VALUE 'ZPPSALE',
          gx_variant LIKE disvariant.
    DATA: lin TYPE i.
    DATA: wkey LIKE vbfa-vbtyp_v.
    DATA: v_datum LIKE sy-datum,
          v_uzeit LIKE sy-uzeit.
    ***kdamle-05.10.2004-start
    CONSTANTS: hex(1) TYPE x VALUE '09',   "tab
               app_path TYPE rlgrap-filename
               VALUE '/bdcusers/mmdata/'.
    DATA: fnam LIKE rlgrap-filename,
          l_path(100),
          flag(1),
          txt(500).
    DATA: fnam1 LIKE rlgrap-filename.
    DATA : BEGIN OF iline OCCURS 0,
             line(4000),
           END OF iline.
    DATA : BEGIN OF i_tty OCCURS 0,
            line(300),
           END OF i_tty.
    *required for pushbutton info
    DATA: g_answer     TYPE c,
          g_lines_tab  TYPE popuptext OCCURS 0
          WITH HEADER LINE.
    DATA: v_flagmtl,
          v_flaginv.
    ***kdamle-05.10.2004-end
    ***kdamle-08122004-start
    DATA: v_msgtxt(150).
    ***kdamle-08122004-end
    *&                      SELECTION SCREEN
    SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS: s_vbeln FOR vbrk-vbeln.
    SELECT-OPTIONS: s_mblnr FOR ser03-mblnr.
    SELECTION-SCREEN END OF BLOCK blk1.
    SELECTION-SCREEN SKIP 1.
    ***kdamle-05.10.2004-start
    SELECTION-SCREEN BEGIN OF BLOCK blk2 WITH FRAME TITLE text-007.
    PARAMETERS: p_ufname LIKE rlgrap-filename.
    *pushbuttons to give info and download file format
    SELECTION-SCREEN: PUSHBUTTON /1(7)   help USER-COMMAND info,
                      PUSHBUTTON  33(25) down USER-COMMAND down.
    SELECTION-SCREEN END OF BLOCK blk2.
    SELECTION-SCREEN BEGIN OF BLOCK blk3 WITH FRAME TITLE text-002.
    PARAMETERS: S_VAR LIKE DISVARIANT-VARIANT.
    *SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
    PARAMETERS: p_r1 RADIOBUTTON GROUP rbg1 DEFAULT 'X' USER-COMMAND ucomm,
                s_var LIKE disvariant-variant MODIF ID pr1.
    PARAMETERS: p_r2 RADIOBUTTON GROUP rbg1,
                p_fname LIKE rlgrap-filename MODIF ID pr2.
    PARAMETERS: p_r3 RADIOBUTTON GROUP rbg1,
                p_lfname LIKE rlgrap-filename MODIF ID pr3,
                p_fname1 LIKE rlgrap-filename MODIF ID pr4.
    SELECTION-SCREEN END OF BLOCK blk3.
    SELECTION-SCREEN BEGIN OF BLOCK blk4 WITH FRAME TITLE text-003.
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN COMMENT 1(75) text-004 MODIF ID pr5.
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN COMMENT 1(75) text-005 MODIF ID pr6.
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN COMMENT 1(75) text-006 MODIF ID pr7.
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN END OF BLOCK blk4.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
      PERFORM get_file.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname1.
      PERFORM get_lfile.
    ***kdamle-05.10.2004-start
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_ufname.
      PERFORM get_ufile.
    ***kdamle-05.10.2004-end
    *&               AT SELECTION SCREEN OUTPUT
    ***kdamle-05.10.2004-start
    AT SELECTION-SCREEN OUTPUT.
      LOOP AT SCREEN.
        IF p_r1 = 'X'.
          IF screen-group1 = 'PR1'.
            screen-input     = '1'.
            screen-output    = '1'.
            screen-invisible = '0'.
          ELSEIF screen-group1 = 'PR2'.
            screen-input     = '0'.
            screen-output    = '0'.
            screen-invisible = '1'.
          ELSEIF screen-group1 = 'PR3'.
            screen-input     = '0'.
            screen-output    = '0'.
            screen-invisible = '1'.
          ELSEIF screen-group1 = 'PR4'.
            screen-input     = '0'.
            screen-output    = '0'.
            screen-invisible = '1'.
          ELSEIF screen-group1 = 'PR5'.
            screen-input     = '0'.
            screen-output    = '0'.
            screen-invisible = '1'.
          ELSEIF screen-group1 = 'PR6'.
            screen-input     = '0'.
            screen-output    = '0'.
            screen-invisible = '1'.
          ELSEIF screen-group1 = 'PR7'.
            screen-input     = '0'.
            screen-output    = '0'.
            screen-invisible = '1'.
          ENDIF.
        ELSEIF p_r2 = 'X'.
          IF screen-group1 = 'PR1'.
            screen-input     = '0'.
            screen-output    = '0'.
            screen-invisible = '1'.
          ELSEIF screen-group1 = 'PR2'.
            screen-input     = '1'.
            screen-output    = '1'.
            screen-invisible = '0'.
          ELSEIF screen-group1 = 'PR3'.
            screen-input     = '0'.
            screen-output    = '0'.
            screen-invisible = '1'.
          ELSEIF screen-group1 = 'PR4'.
            screen-input     = '0'.
            screen-output    = '0'.
            screen-invisible = '1'.
          ELSEIF screen-group1 = 'PR5'.
            screen-input     = '1'.
            screen-output    = '1'.
            screen-invisible = '0'.
          ELSEIF screen-group1 = 'PR6'.
            screen-input     = '1'.
            screen-output    = '1'.
            screen-invisible = '0'.
          ELSEIF screen-group1 = 'PR7'.
            screen-input     = '0'.
            screen-output    = '0'.
            screen-invisible = '1'.
          ENDIF.
        ELSEIF p_r3 = 'X'.
          IF screen-group1 = 'PR1'.
            screen-input     = '0'.
            screen-output    = '0'.
            screen-invisible = '1'.
          ELSEIF screen-group1 = 'PR2'.
            screen-input     = '0'.
            screen-output    = '0'.
            screen-invisible = '1'.
          ELSEIF screen-group1 = 'PR3'.
            screen-input     = '1'.
            screen-output    = '1'.
            screen-invisible = '0'.
          ELSEIF screen-group1 = 'PR4'.
            screen-input     = '1'.
            screen-output    = '1'.
            screen-invisible = '0'.
          ELSEIF screen-group1 = 'PR5'.
            screen-input     = '0'.
            screen-output    = '0'.
            screen-invisible = '1'.
          ELSEIF screen-group1 = 'PR6'.
            screen-input     = '0'.
            screen-output    = '0'.
            screen-invisible = '1'.
          ELSEIF screen-group1 = 'PR7'.
            screen-input     = '1'.
            screen-output    = '1'.
            screen-invisible = '0'.
          ENDIF.
        ENDIF.
        MODIFY SCREEN.
      ENDLOOP.
    *&                      INITIALIZATION
    INITIALIZATION.
      MOVE '@0S@' TO help.
      MOVE '@49@ Upload File Format' TO down.
      PERFORM fill_infotext.
    ***kdamle-05.10.2004-end
    *&                      AT SELECTION SCREEN
    AT SELECTION-SCREEN.
      IF sy-ucomm = 'ONLI'
    ***kdamle-08122004-start
          AND p_r3 NE 'X'.
    ***kdamle-08122004-end
        IF NOT s_vbeln IS INITIAL
          AND NOT s_mblnr IS INITIAL
          AND NOT p_ufname IS INITIAL.
          MESSAGE e000(yw) WITH
            'Enter Either Mat. Doc. Or Inv. No. Or Upload File'.
        ELSEIF s_vbeln IS INITIAL
              AND s_mblnr IS INITIAL
              AND p_ufname IS INITIAL.
          MESSAGE e000(yw) WITH
            'Enter Either Mat. Doc. Or Inv. No. Or Upload File'.
        ENDIF.
        IF NOT s_mblnr IS INITIAL AND NOT p_ufname IS INITIAL.
          MESSAGE e000(yw) WITH
            'Enter Either Material Doc. Or Upload file name'.
        ELSEIF NOT s_vbeln IS INITIAL AND NOT p_ufname IS INITIAL.
          MESSAGE e000(yw) WITH
            'Enter Either Invoice No. Or Upload file name'.
        ENDIF.
      ENDIF.
    ***kdamle-05.10.2004-start
    IF sscrfields-ucomm = 'INFO'.
      IF sy-ucomm = 'INFO'.
        CALL FUNCTION 'DD_POPUP_WITH_INFOTEXT'
             EXPORTING
                  titel        = 'Text File Format'
                  start_column = 10
                  start_row    = 12
                  end_column   = 85
                  end_row      = 22
                  infoflag     = ' '
             IMPORTING
                  answer       = g_answer
             TABLES
                  lines        = g_lines_tab.
    ELSEIF sscrfields-ucomm = 'DOWN'.
      ELSEIF sy-ucomm = 'DOWN'.
        PERFORM fill_idwn.
      ENDIF.
      IF sy-ucomm = 'ONLI'.
        IF p_r2 = 'X'.
          IF p_fname IS INITIAL.
            SET CURSOR FIELD 'P_FNAME'.
            MESSAGE e000(yw) WITH 'Please Enter Download File Name'.
          ENDIF.
        ENDIF.
        IF p_r3 = 'X'.
          IF p_lfname = space.
            SET CURSOR FIELD 'P_LFNAME'.
            MESSAGE e000(yw) WITH 'FileName on Server cannot be empty'.
          ENDIF.
          IF p_fname1 = space.
            SET CURSOR FIELD 'P_FNAME1'.
            MESSAGE e000(yw) WITH 'Local FileName cannot be empty'.
          ENDIF.
        ENDIF.
      ELSEIF sy-ucomm = 'SJOB'.
        IF p_r2 = 'X'.
          IF p_fname IS INITIAL.
            SET CURSOR FIELD 'P_FNAME'.
            MESSAGE e000(yw) WITH 'Please Enter Download File Name'.
          ENDIF.
          IF p_fname CA ':' OR p_fname CA '/'  OR p_fname CA '\'.
            SET CURSOR FIELD 'P_FNAME'.
            MESSAGE e000(yw) WITH 'Enter only File Name for Background job'.
          ENDIF.
        ENDIF.
        IF p_r3 = 'X'.
          MESSAGE e000(yw) WITH
              'This option cannot be executed in Background mode'.
        ENDIF.
      ENDIF.
      IF p_fname CA '*'.
        MESSAGE e000(yw) WITH '* (star) not allowed in Filename'.
      ENDIF.
      IF sy-ucomm = 'ONLI' AND NOT p_ufname IS INITIAL.
    *in foreground processing directly read input file from users machine
        PERFORM upload_file TABLES it_up.
      ELSEIF sy-ucomm = 'SJOB' AND NOT p_ufname IS INITIAL.
    *download the file read input file from users machine onto the
    *application server first as it cannot be read during background
    *processing
        PERFORM download_to_app_server.
      ENDIF.
    ***kdamle-05.10.2004-end
    *&               AT SELECTION SCREEN ON VALUE REQUEST
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_var.
      PERFORM select_variant.
    *&                      START OF SELECTION
    START-OF-SELECTION.
    ***kdamle-05.10.2004-start
      IF sy-batch = 'X'.
        CLEAR it_up.
        CLEAR it_up[].
        PERFORM upload_app_server.
        READ TABLE it_up INDEX 1.
      ENDIF.
      IF p_r3 = 'X'.
        PERFORM create_local_file.
        EXIT.
      ENDIF.
      IF NOT s_mblnr IS INITIAL.
        SELECT mblnr mjahr zeile FROM mseg
                               INTO CORRESPONDING FIELDS OF TABLE it_mseg
                                 WHERE mblnr IN s_mblnr
                                   AND xauto NE 'X'.
        IF sy-subrc NE 0.
          MESSAGE s000(yw) WITH 'No Data Found'.
          STOP.
        ENDIF.
        PERFORM get_data_from_mtl.
      ELSEIF NOT p_ufname IS INITIAL AND NOT it_up-mblnr IS INITIAL.
        v_flagmtl = 'X'.
        IF NOT it_up[] IS INITIAL.
          SORT it_up BY mblnr.
          SELECT mblnr mjahr zeile FROM mseg
            INTO CORRESPONDING FIELDS OF TABLE it_mseg
            FOR ALL ENTRIES IN it_up
            WHERE mblnr = it_up-mblnr
              AND xauto NE 'X'.
        ENDIF.
        PERFORM get_data_from_mtl.
      ELSEIF NOT s_vbeln IS INITIAL.
        SELECT vbeln fkdat fkart vkorg vtweg spart FROM vbrk
                           INTO CORRESPONDING FIELDS OF TABLE it_vbrk
                               WHERE vbeln IN s_vbeln.
        IF sy-subrc NE 0.
          MESSAGE s000(yw) WITH 'No Data Found'.
          STOP.
        ENDIF.
        PERFORM get_data_from_inv.
      ELSEIF NOT p_ufname IS INITIAL AND NOT it_up-vbeln IS INITIAL.
        v_flaginv = 'X'.
        IF NOT it_up[] IS INITIAL.
          SORT it_up BY vbeln.
          SELECT vbeln fkdat fkart vkorg vtweg spart FROM vbrk
            INTO CORRESPONDING FIELDS OF TABLE it_vbrk
            FOR ALL ENTRIES IN it_up
            WHERE vbeln = it_up-vbeln.
        ENDIF.
        PERFORM get_data_from_inv.
      ENDIF.
    ***kdamle-05.10.2004-end
    *&                      END OF SELECTION
    END-OF-SELECTION.
    ***kdamle-05.10.2004-start
      IF NOT s_mblnr IS INITIAL OR v_flagmtl = 'X'.
    ***kdamle-05.10.2004-end
        CHECK NOT it_mseg[] IS INITIAL.
        PERFORM populate_output_1.
    ***kdamle-05.10.2004-start
      ELSEIF NOT s_vbeln IS INITIAL OR v_flaginv = 'X'.
    ***kdamle-05.10.2004-end
        PERFORM populate_output_2.
      ENDIF.
    ***kdamle-05.10.2004-start
      IF p_r1 = 'X'.
    ***kdamle-05.10.2004-end
        DESCRIBE TABLE it_out LINES lin.
        IF lin > 0.
          PERFORM create_f_catalog_0100.
          PERFORM set_defaults_grid.
          SET TITLEBAR 'DOC' WITH '[count ='
                                  lin
          CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
               EXPORTING
                    i_callback_program = 'ZDOC_SRLST'
                    is_layout          = alv_layout
                    it_fieldcat        = gt_fieldcat
                    i_default          = 'X'
                    i_save             = 'A'
                    is_variant         = g_variant
               TABLES
                    t_outtab           = it_out.
        ELSE.
          MESSAGE s000(yw) WITH 'No Data Selected'.
        ENDIF.
    ***kdamle-05.10.2004-start
      ELSEIF p_r2 = 'X'.
        PERFORM create_disp_table.
        IF sy-batch = space.
          PERFORM online_download.
        ELSE.
          PERFORM download_data.
        ENDIF.
      ENDIF.
    ***kdamle-05.10.2004-end
    *&      Form  POPULATE_OUTPUT_1
    FORM populate_output_1.
    SORT IT_SER03  BY MBLNR.
      SORT it_vbfa_1 BY vbeln.
      SORT it_vbfa_2 BY vbelv.
      SORT it_vbrk   BY vbeln.
      SORT it_objk   BY obknr.
      SORT it_alert  BY rsnno.
      LOOP AT it_ser03.
        it_out-charg     = it_ser03-charge.
        it_out-bwart     = it_ser03-bwart.
        it_out-zeile     = it_ser03-zeile.
        it_out-mblnr     = it_ser03-mblnr.
        it_out-datum     = it_ser03-datum.
        it_out-werk      = it_ser03-werk.
        it_out-lagerort  = it_ser03-lagerort.
        IF it_ser03-bwart = '601' OR it_ser03-bwart = '602'.
          wkey = 'J'.
        ELSE.
          wkey = 'T'.
        ENDIF.
        CLEAR it_vbfa_1.
        READ TABLE it_vbfa_1
                   WITH KEY vbeln   = it_ser03-mblnr
                            vbtyp_v = wkey.
        IF sy-subrc EQ 0.
          IF it_ser03-bwart = '601' OR it_ser03-bwart = '602'.
            wkey = 'M'.
          ELSE.
            wkey = 'O'.
          ENDIF.
          CLEAR it_vbfa_2.
          READ TABLE it_vbfa_2
                     WITH KEY vbelv   = it_vbfa_1-vbelv
                              vbtyp_n = wkey.
          IF sy-subrc EQ 0.
            CLEAR it_vbrk.
            READ TABLE it_vbrk
                       WITH KEY vbeln = it_vbfa_2-vbeln
                       BINARY SEARCH.
            it_out-vbeln = it_vbrk-vbeln.
            it_out-fkdat = it_vbrk-fkdat.
            it_out-fkart = it_vbrk-fkart.
            it_out-vkorg = it_vbrk-vkorg.
            it_out-vtweg = it_vbrk-vtweg.
            it_out-spart = it_vbrk-spart.
          ENDIF.
        ENDIF.
        READ TABLE it_objk
                   WITH KEY obknr = it_ser03-obknr
                   BINARY SEARCH.
        IF sy-subrc EQ 0.
          LOOP AT it_objk WHERE obknr = it_ser03-obknr.
            it_out-matnr = it_objk-matnr.
            READ TABLE it_alert
                       WITH KEY rsnno = it_objk-sernr
                       BINARY SEARCH.
            IF sy-subrc EQ 0.
              it_out-rsnno = it_alert-rsnno.
    ***kdamle-27102004-start
              it_out-status = it_alert-status.
    ***kdamle-27102004-end
              APPEND it_out.
              CLEAR: it_alert, it_objk.
            ELSE.
              APPEND it_out.
              CLEAR: it_objk.
            ENDIF.
          ENDLOOP.
        ELSE.
          APPEND it_out.
          CLEAR: it_objk, it_ser03,
                 it_out.
        ENDIF.
      ENDLOOP.
      REFRESH: it_ser03, it_objk, it_alert.
    ENDFORM.                    " POPULATE_OUTPUT_1
    *&      Form  POPULATE_OUTPUT_2
    FORM populate_output_2.
      SORT it_vbrp   BY vbeln.
      SORT it_vbfa_1 BY vbeln.
      SORT it_vbfa_2 BY vbelv.
      SORT it_ser03  BY mblnr.
      SORT it_objk   BY obknr.
      SORT it_alert  BY rsnno.
      LOOP AT it_vbrk.
        it_out-vbeln = it_vbrk-vbeln.
        it_out-fkdat = it_vbrk-fkdat.
        it_out-fkart = it_vbrk-fkart.
        it_out-vkorg = it_vbrk-vkorg.
        it_out-vtweg = it_vbrk-vtweg.
        it_out-spart = it_vbrk-spart.
        READ TABLE it_vbrp
                   WITH KEY vbeln = it_vbrk-vbeln.
    ***kdamle-19042005-start
       it_out-charg = it_vbrp-charg.
       it_out-matnr = it_vbrp-matnr.
    ***kdamle-19042005-end
        READ TABLE it_vbfa_1
                   WITH KEY vbeln = it_vbrk-vbeln
                   BINARY SEARCH.
        IF sy-subrc EQ 0.
          LOOP AT it_vbfa_1 WHERE vbeln = it_vbrk-vbeln.
            READ TABLE it_vbfa_2
                       WITH KEY vbelv = it_vbfa_1-vbelv
                       BINARY SEARCH.
            IF sy-subrc EQ 0.
              LOOP AT it_vbfa_2 WHERE vbelv = it_vbfa_1-vbelv.
                READ TABLE it_ser03
                           WITH KEY mblnr = it_vbfa_2-vbeln
                           BINARY SEARCH.
                IF sy-subrc EQ 0.
                  LOOP AT it_ser03 WHERE mblnr = it_vbfa_2-vbeln.
                    it_out-bwart     = it_ser03-bwart.
                    it_out-zeile     = it_ser03-zeile.
                    it_out-mblnr     = it_ser03-mblnr.
                    it_out-datum     = it_ser03-datum.
                    it_out-werk      = it_ser03-werk.
                    it_out-lagerort  = it_ser03-lagerort.
    ***kdamle-19042005-start
                    it_out-charg     = it_ser03-charge.
    ***kdamle-19042005-end
                    READ TABLE it_objk
                               WITH KEY obknr = it_ser03-obknr
                               BINARY SEARCH.
                    IF sy-subrc EQ 0.
                      LOOP AT it_objk WHERE obknr = it_ser03-obknr.
    ***kdamle-19042005-start
                        it_out-matnr = it_objk-matnr.
    ***kdamle-19042005-end
                        READ TABLE it_alert
                                   WITH KEY rsnno = it_objk-sernr
                                   BINARY SEARCH.
                        IF sy-subrc EQ 0.
                          it_out-rsnno = it_alert-rsnno.
                          APPEND it_out.
                          CLEAR: it_alert, it_objk.
                        ELSE.
                          APPEND it_out.
                          CLEAR: it_objk.
                        ENDIF.
                      ENDLOOP.
                    ELSE.
                      APPEND it_out.
                      CLEAR: it_objk, it_ser03, it_out.
                    ENDIF.
                  ENDLOOP.
                  CLEAR: it_ser03, it_objk, it_alert.
                ELSE.
                  APPEND it_out.
                ENDIF.
              ENDLOOP.
            ELSE.
              APPEND it_out.
            ENDIF.
          ENDLOOP.
        ELSE.
          APPEND it_out.
        ENDIF.
      ENDLOOP.
    ENDFORM.                    " POPULATE_OUTPUT_2
    *&      FORM  CREATE_F_CATALOG_0100
    FORM create_f_catalog_0100.
      REFRESH gt_fieldcat.
      CLEAR s_fieldcat.
      s_fieldcat-fieldname = 'RSNNO'.
      s_fieldcat-ref_tabname = 'ZPREALERT'.
      s_fieldcat-ref_fieldname = 'RSNNO'.
      s_fieldcat-ddictxt = 'L'.
      s_fieldcat-seltext_l = s_fieldcat-seltext_m = s_fieldcat-seltext_s =
                             'RSN No.'.
      s_fieldcat-outputlen = '20'.
      s_fieldcat-fix_column = 'X'.
      s_fieldcat-key = 'X'.
      s_fieldcat-tabname = 'IT_OUT'.
      APPEND s_fieldcat TO gt_fieldcat.
      CLEAR s_fieldcat.
      s_fieldcat-fieldname = 'MATNR'.
      s_fieldcat-ref_tabname = 'OBJK'.
      s_fieldcat-ref_fieldname = 'MATNR'.
      s_fieldcat-ddictxt = 'L'.
      s_fieldcat-seltext_l = s_fieldcat-seltext_m = s_fieldcat-seltext_s =
                             'Material'.
      s_fieldcat-outputlen = '20'.
      s_fieldcat-tabname = 'IT_OUT'.
      APPEND s_fieldcat TO gt_fieldcat.
      CLEAR s_fieldcat.
      s_fieldcat-fieldname = 'CHARG'.
      s_fieldcat-ref_tabname = 'SER03'.
      s_fieldcat-ref_fieldname = 'CHARG'.
      s_fieldcat-ddictxt = 'L'.
      s_fieldcat-seltext_l = s_fieldcat-seltext_m = s_fieldcat-seltext_s =
                             'Batch'.
      s_fieldcat-outputlen = '10'.
      s_fieldcat-tabname = 'IT_OUT'.
      APPEND s_fieldcat TO gt_fieldcat.
      CLEAR s_fieldcat.
      s_fieldcat-fieldname = 'BWART'.
      s_fieldcat-ref_tabname = 'SER03'.
      s_fieldcat-ref_fieldname = 'BWART'.
      s_fieldcat-ddictxt = 'L'.
      s_fieldcat-seltext_l = s_fieldcat-seltext_m = s_fieldcat-seltext_s =
                             'Movement'.
      s_fieldcat-outputlen = '10'.
      s_fieldcat-tabname = 'IT_OUT'.
      APPEND s_fieldcat TO gt_fieldcat.
      CLEAR s_fieldcat.
      s_fieldcat-fieldname = 'MBLNR'.
      s_fieldcat-ref_tabname = 'SER03'.
      s_fieldcat-ref_fieldname = 'MBLNR'.
      s_fieldcat-ddictxt = 'L'.
      s_fieldcat-seltext_l = s_fieldcat-seltext_m = s_fieldcat-seltext_s =
                             'Mat Doc'.
      s_fieldcat-outputlen = '10'.
      s_fieldcat-emphasize = 'X'.
      s_fieldcat-tabname = 'IT_OUT'.
      APPEND s_fieldcat TO gt_fieldcat.
      CLEAR s_fieldcat.
      s_fieldcat-fieldname = 'ZEILE'.
      s_fieldcat-ref_tabname = 'SER03'.
      s_fieldcat-ref_fieldname = 'ZEILE'.
      s_fieldcat-ddictxt = 'L'.
      s_fieldcat-seltext_l = s_fieldcat-seltext_m = s_fieldcat-seltext_s =
                             'Item'.
      s_fieldcat-outputlen = '10'.
      s_fieldcat-tabname = 'IT_OUT'.
      APPEND s_fieldcat TO gt_fieldcat.
      CLEAR s_fieldcat.
      s_fieldcat-fieldname = 'WERK'.
      s_fieldcat-ref_tabname = 'SER03'.
      s_fieldcat-ref_fieldname = 'WERK'.
      s_fieldcat-ddictxt = 'L'.
      s_fieldcat-seltext_l = s_fieldcat-seltext_m = s_fieldcat-seltext_s =
                             'Plant'.
      s_fieldcat-outputlen = '10'.
      s_fieldcat-tabname = 'IT_OUT'.
      APPEND s_fieldcat TO gt_fieldcat.
      CLEAR s_fieldcat.
      s_fieldcat-fieldname = 'LAGERORT'.
      s_fieldcat-ref_tabname = 'SER03'.
      s_fieldcat-ref_fieldname = 'LAGERORT'.
      s_fieldcat-ddictxt = 'L'.
      s_fieldcat-seltext_l = s_fieldcat-seltext_m = s_fieldcat-seltext_s =
                             'SLoc'.
      s_fieldcat-outputlen = '10'.
      s_fieldcat-tabname = 'IT_OUT'.
      APPEND s_fieldcat TO gt_fieldcat.
      CLEAR s_fieldcat.
      s_fieldcat-fieldname = 'DATUM'.
      s_fieldcat-ref_tabname = 'SER03'.
      s_fieldcat-ref_fieldname = 'DATUM'.
      s_fieldcat-ddictxt = 'L'.
      s_fieldcat-seltext_l = s_fieldcat-seltext_m = s_fieldcat-seltext_s =
                             'Doc Date'.
      s_fieldcat-outputlen = '10'.
      s_fieldcat-tabname = 'IT_OUT'.
      APPEND s_fieldcat TO gt_fieldcat.
      CLEAR s_fieldcat.
      s_fieldcat-fieldname = 'VBELN'.
      s_fieldcat-ref_tabname = 'VBRK'.
      s_fieldcat-ref_fieldname = 'VBELN'.
      s_fieldcat-ddictxt = 'L'.
      s_fieldcat-seltext_l = s_fieldcat-seltext_m = s_fieldcat-seltext_s =
                             'Invoice'.
      s_fieldcat-outputlen = '10'.
      s_fieldcat-tabname = 'IT_OUT'.
      APPEND s_fieldcat TO gt_fieldcat.
      CLEAR s_fieldcat.
      s_fieldcat-fieldname = 'FKDAT'.
      s_fieldcat-ref_tabname = 'VBRK'.
      s_fieldcat-ref_fieldname = 'FKDAT'.
      s_fieldcat-ddictxt = 'L'.
      s_fieldcat-seltext_l = s_fieldcat-seltext_m = s_fieldcat-seltext_s =
                             'Inv Date'.
      s_fieldcat-outputlen = '10'.
      s_fieldcat-tabname = 'IT_OUT'.
      APPEND s_fieldcat TO gt_fieldcat.
      CLEAR s_fieldcat.
      s_fieldcat-fieldname = 'FKART'.
      s_fieldcat-ref_tabname = 'VBRK'.
      s_fieldcat-ref_fieldname = 'FKART'.
      s_fieldcat-ddictxt = 'L'.
      s_fieldcat-seltext_l = s_fieldcat-seltext_m = s_fieldcat-seltext_s =
                             'Inv Type'.
      s_fieldcat-outputlen = '10'.
      s_fieldcat-tabname = 'IT_OUT'.
      APPEND s_fieldcat TO gt_fieldcat.
      CLEAR s_fieldcat.
      s_fieldcat-fieldname = 'VKORG'.
      s_fieldcat-ref_tabname = 'VBRK'.
      s_fieldcat-ref_fieldname = 'VKORG'.
      s_fieldcat-ddictxt = 'L'.
      s_fieldcat-seltext_l = s_fieldcat-seltext_m = s_fieldcat-seltext_s =
                             'S.Org'.
      s_fieldcat-outputlen = '10'.
      s_fieldcat-tabname = 'IT_OUT'.
      APPEND s_fieldcat TO gt_fieldcat.
      CLEAR s_fieldcat.
      s_fieldcat-fieldname = 'VTWEG'.
      s_fieldcat-ref_tabname = 'VBRK'.
      s_fieldcat-ref_fieldname = 'VTWEG'.
      s_fieldcat-ddictxt = 'L'.
      s_fieldcat-seltext_l = s_fieldcat-seltext_m = s_fieldcat-seltext_s =
                             'D.Chnl'.
      s_fieldcat-outputlen = '10'.
      s_fieldcat-tabname = 'IT_OUT'.
      APPEND s_fieldcat TO gt_fieldcat.
      CLEAR s_fieldcat.
      s_fieldcat-fieldname = 'SPART'.
      s_fieldcat-ref_tabname = 'VBRK'.
      s_fieldcat-ref_fieldname = 'SPART'.
      s_fieldcat-ddictxt = 'L'.
      s_fieldcat-seltext_l = s_fieldcat-seltext_m = s_fieldcat-seltext_s =
                             'Div'.
      s_fieldcat-outputlen = '10'.
      s_fieldcat-tabname = 'IT_OUT'.
      APPEND s_fieldcat TO gt_fieldcat.
      CLEAR s_fieldcat.
    ***kdamle-27102004-start
      s_fieldcat-fieldname = 'STATUS'.
      s_fieldcat-ref_tabname = 'ZPREALERT'.
      s_fieldcat-ref_fieldname = 'STATUS'.
      s_fieldcat-ddictxt = 'L'.
      s_fieldcat-seltext_l = s_fieldcat-seltext_m = s_fieldcat-seltext_s =
                             'P Sts'.
      s_fieldcat-outputlen = '10'.
      s_fieldcat-tabname = 'IT_OUT'.
      APPEND s_fieldcat TO gt_fieldcat.
      CLEAR s_fieldcat.
    ***kdamle-27102004-end
    ENDFORM.
    *&      Form  SET_DEFAULTS_GRID
    FORM set_defaults_grid.
      alv_layout-colwidth_optimize = 'X'.
      alv_layout-zebra = 'X'.
    ENDFORM.                    " SET_DEFAULTS_GRID
    *&      Form  SELECT_VARIANT
    FORM select_variant.
      DATA: g_exit(1) TYPE c,
            g_save(1) TYPE c.
      CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
           EXPORTING
                is_variant = g_variant
                i_save     = 'A'
           IMPORTING
                es_variant = g_variant
           EXCEPTIONS
                not_found  = 2.
      IF sy-subrc EQ 0.
        s_var = g_variant-variant.
      ELSE.
        MESSAGE s000(yw) WITH 'No Variant Found'.
      ENDIF.
    ENDFORM.                    " SELECT_VARIANT
    *&      Form  DISP_TOP_OF_PAGE
    FORM disp_top_of_page.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
           EXPORTING
                it_list_commentary = gt_list_top_of_page.
    ENDFORM.                    " DISP_TOP_OF_PAGE
    *&      Form  FILL_ALV_EVENTS
    FORM fill_alv_events.
      DATA: ls_line TYPE slis_listheader.
      ls_alv_event-name = 'TOP_OF_PAGE'.
      ls_alv_event-form = 'DISP_TOP_OF_PAGE'.
      APPEND ls_alv_event TO i_alv_event.
      CLEAR: ls_alv_event,
             ls_line.
      ls_line-typ  = 'A'.
      ls_line-info = infotxt.
      APPEND ls_line TO gt_list_top_of_page.
    ENDFORM.                    " FILL_ALV_EVENTS
    *&      Form  GET_FILE
          text
    -->  p1        text
    <--  p2        text
    FORM get_file.
      CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
           EXPORTING
                program_name = 'ZDOC_SRLST'
                field_name   = p_fname
                mask         = '.'
           CHANGING
                file_name    = p_fname.
      IF sy-subrc <> 0.
        MESSAGE e000(yw) WITH 'Error Uploading File' p_fname.
      ENDIF.
    ENDFORM.                    " GET_FILE
    *&      Form  GET_LFILE
          text
    -->  p1        text
    <--  p2        text
    FORM get_lfile.
      CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
           EXPORTING
                program_name = 'ZDOC_SRLST'
                field_name   = p_fname1
                mask         = '.'
           CHANGING
                file_name    = p_fname1.
      IF sy-subrc <> 0.
        MESSAGE e000(yw) WITH 'Error Uploading File' p_fname1.
      ENDIF.
    ENDFORM.                    " GET_LFILE
    *&      Form  CREATE_LOCAL_FILE
          text
    -->  p1        text
    <--  p2        text
    FORM create_local_file.
      IF p_lfname IS INITIAL  OR p_fname1 IS INITIAL.
        MESSAGE i000(yw) WITH 'File Name on Server and Local File Name '
                              ' are mandatory.'.
        STOP.
      ENDIF.
      CONCATENATE app_path p_lfname INTO l_path.
      CONDENSE l_path NO-GAPS.
      OPEN DATASET l_path FOR INPUT IN TEXT MODE.
      IF sy-subrc NE 0.
        MESSAGE i000(yw) WITH 'File' p_lfname 'does not exist'.
        STOP.
      ENDIF.
      DO.
        CLEAR : iline.
        READ DATASET l_path INTO iline.
        IF sy-subrc = 0.
          APPEND iline.
        ELSE.
          EXIT.
        ENDIF.
      ENDDO.
      CLOSE DATASET l_path.
      CALL FUNCTION 'WS_DOWNLOAD'
          EXPORTING
            BIN_FILESIZE            = ' '
            CODEPAGE                = ' '
              filename                =  p_fname1
               filetype                = 'DAT'
            ITEM                    = ' '
            MODE                    = ' '
            WK1_N_FORMAT            = ' '
            WK1_N_SIZE              = ' '
            WK1_T_FORMAT            = ' '
            WK1_T_SIZE              = ' '
            FILEMASK_MASK           = ' '
            FILEMASK_TEXT           = ' '
            FILETYPE_NO_CHANGE      = ' '
            FILEMASK_ALL            = ' '
            FILETYPE_NO_SHOW        = ' '
            SILENT                  = 'S'
            COL_SELECT              = ' '
            COL_SELECTMASK          = ' '
            NO_AUTH_CHECK           = ' '
       IMPORTING
            ACT_FILENAME            =
            ACT_FILETYPE            =
            FILESIZE                =
            CANCEL                  =
           TABLES
                data_tab                = iline
            FIELDNAMES              =
          EXCEPTIONS
               invalid_filesize        = 1
               invalid_table_width     = 2
               invalid_type            = 3
               no_batch                = 4
               unknown_error           = 5
               gui_refuse_filetransfer = 6
            CUSTOMER_ERROR          = 7
               OTHERS                  = 8
      IF sy-subrc EQ 0.
    ***kdamle-08122004-start
        CONCATENATE 'File ' p_fname1
                              ' Downloaded Successfully'
          INTO v_msgtxt SEPARATED BY space.
        MESSAGE s000(yw) WITH v_msgtxt+0(50)
                              v_msgtxt+50(50).
    ***kdamle-08122004-end
    Delete processed file from App Server.
        IF sy-subrc EQ 0.
          CONCATENATE 'rm' l_path
              INTO txt SEPARATED BY space.
          CALL 'SYSTEM' ID 'COMMAND' FIELD txt
                        ID 'TAB'     FIELD i_tty[].
        ENDIF.
      ENDIF.
    ENDFORM.                    " CREATE_LOCAL_FILE
    *&      Form  ONLINE_DOWNLOAD
          text
    -->  p1        text
    <--  p2        text
    FORM online_download.
      CALL FUNCTION 'WS_DOWNLOAD' "#nc
           EXPORTING
                filename = p_fname
                filetype = 'ASC'
           TABLES
                data_tab = it_formatted.
      IF sy-subrc EQ 0.
        MESSAGE s016(yw) WITH 'File '
                              p_fname
                              ' Downloaded Successfully'.
      ELSE.
        MESSAGE i000(yw) WITH 'Error Downloading File'
                              p_fname.
      ENDIF.
    ENDFORM.                    " ONLINE_DOWNLOAD
    *&      Form  DOWNLOAD_DATA
          text
    -->  p1        text
    <--  p2        text
    FORM download_data.
    *TRANSFERRING THE DATA TO THE FILE ON THE APPLICATION SERVER
      CONCATENATE app_path p_fname INTO fnam SEPARATED BY space.
      CONDENSE fnam NO-GAPS.
      IF fnam IS INITIAL.
        MESSAGE e000(yw) WITH 'Please Enter Download File Name'.
      ENDIF.
      OPEN DATASET fnam FOR OUTPUT IN TEXT MODE.
      IF sy-subrc = 0.
        LOOP AT it_formatted.
          TRANSFER it_formatted TO fnam.
        ENDLOOP.
        CLOSE DATASET fnam.
        IF sy-subrc = 0.
          MESSAGE s016(yw) WITH 'File '
                                fnam+0(50)
                                fnam+50(50)
                                ' Downloaded Successfully'.
        ELSE.
          MESSAGE i000(yw) WITH

    1)     AVOID SELECT *                                                          
    2)     USE WHERE WITH AS MANY EQ AND RESTRICT DATA RETRIEVAL             
    3)     AVOID SELECTS FROM THE SAME TABLE                                        
    4)     USE BINARY SEARCH WHEN READING FROM INTERNAL TABLES                      
    5)     CHECK IF INTERNAL TABLE IS SORTED BEFORE READING WITH BINARY SRCH       
    6)     FETCH REQUIRED FIELDS USING TRANSPORTING WHEN READING INTERNAL TABLES    
    7)     USE AS MANY PRIMARY AND SECONDARY INDEXES WHEN RETRIEVING DATA           
    8)     USE SELECT SINGLE INSTEAD OF UP TO 1 ROWS                                
    9)     USE BYPASSING BUFFER FOR ONE TIME USE TABLES                         
    10)     USE INSERT <DBTAB> FROM TABLE <ITAB1> INSTEAD OF INSERT INTO <DBTAB>     
    11)     USE WITH KEY WHEN READING FROM AN INTERNAL TAB                           
    12)     SPECIFY KEYS WHEN SORTING AN INTERNAL TABLE                             
    13)     HAVE TYPE DECLARATIONS FOR PARAMETERS PASSED IN SUBROUTINES            
    14)     HAVE TYPE DECLARATIONS FOR FIELD-SYMBOLS                          
    15)     USE WHILE ... ENDWHILE INSTEAD OF DO ... ENDDO                          
    16)     DO NOT USE CHECK CONSTRUCT WITHIN LOOP ... ENDLOOP.    
    17)     DO NOT USE CHECK CONSTRUCT WITHIN SELECT ... ENDSELECT   
    18)     USE CASE STATEMENT INSTEAD OF IF ... ELSEIF ... ENDIF                  
    19)     AVOID USING ORDER BY IN SELECT STATEMENTS. USE SORT BY INSTEAD           
    20)     REMOVE BREAK-POINT FROM THE CODE                                         
    21)     DO NOT USE AT EVENTS IN LOOP...ENDLOOP HAVING FROM OR TO OR WHERE CON  
    22)     DO NOT USE ON CHANGE OF EVENTS IN SELECT...ENDSELECT                     
    23)     DO NOT USE ON CHANGE OF EVENTS IN LOOP ... ENDLOOP                       
    24)     USE %_HINTS IN THE WHERE CLAUSE TO SPECIFY THE INDEX TO BE USED.         
    25)     AVOID USING NESTED SELECTS         
    26)     USE GET <DTABLE> FIELDS F1 F2 F3 ... INSTEAD OF ONLY GET <DTABLE>        
    27)     USE MODIFY <DTABLE> FROM <ITAB> INSTEAD OF WITHIN A LOOP                 
    28)     USE UPDATE <DTABLE> FROM <ITAB> INSTEAD OF WITHIN A LOOP                 
    29)     USE INSERT <DTABLE> FROM <ITAB> INSTEAD OF WITHIN A LOOP                 
    30)     USE DELETE <DTABLE> FROM <ITAB> INSTEAD OF WITHIN A LOOP                 
    31)     AVOID SELECT FROM CLUSTER AND POOL TABLES

  • Vendor performance analysis report

    Hi all,
    requirement to create an ALV report for vendor performance analysis...  wat r d tables n feilds which are to be used fr this... any help is appreciated..

    Refer the links -
    vendor performance report !!!
    vendor performance report
    vendor performance report
    I need standard vendor performance report

  • What are the main tables using in vendor performance report.

    what are the main tables using in vendor performance report.
    how many select statements are in ABAP reports.

    Refer the links -
    vendor performance report !!!
    vendor performance report
    vendor performance report
    I need standard vendor performance report
    Regards,
    Amit
    Reward all helpful replies.

  • Perform - syntax

    Hi ,
        Iam trying to write an extractor for open and closed items ie form BSAD and BSID .
    So i have written the logic .when i tryed to modularise the code .the function module is not acteping the perform statment
    Ie when i tryed to put the logic in to a perfoem its giving a syntax error like
    "Field "E_T_DATA" is unknown. It is neither in one of the specified          
    tables nor defined by a "DATA" statement . . . . . . . . . .     "     
    can you please provide me a solution for this .
    Thanks ,
    Sriram.

    Hi ,
      As you have asked for below i have attached the code .
    PERFORM FETCH_BSID .
    *PERFORM FETCH_BSAD TABLES E_T_DATA.
    this are the two perform iam trying to create just to moduralize the code .it it showing an error like .E_T_DATA is not defined which is the final extract structure .
    ""Local Interface:
    *"  IMPORTING
    *"     VALUE(I_REQUNR) TYPE  SRSC_S_IF_SIMPLE-REQUNR
    *"     VALUE(I_DSOURCE) TYPE  SRSC_S_IF_SIMPLE-DSOURCE OPTIONAL
    *"     VALUE(I_MAXSIZE) TYPE  SRSC_S_IF_SIMPLE-MAXSIZE OPTIONAL
    *"     VALUE(I_INITFLAG) TYPE  SRSC_S_IF_SIMPLE-INITFLAG OPTIONAL
    *"     VALUE(I_READ_ONLY) TYPE  SRSC_S_IF_SIMPLE-READONLY OPTIONAL
    *"     VALUE(I_REMOTE_CALL) TYPE  SBIWA_FLAG DEFAULT SBIWA_C_FLAG_OFF
    *"  TABLES
    *"      I_T_SELECT TYPE  SRSC_S_IF_SIMPLE-T_SELECT OPTIONAL
    *"      I_T_FIELDS TYPE  SRSC_S_IF_SIMPLE-T_FIELDS OPTIONAL
    *"      E_T_DATA TYPE  ZBIAR_EXTRACTOR_AR1 OPTIONAL
    *"  EXCEPTIONS
    *"      NO_MORE_DATA
    *"      ERROR_PASSED_TO_MESS_HANDLER
    *& Function Module  : Z01_FBIWI_AR_EXTRACTOR                               *
    *& Title            : Extractor Industrial - AR                            *
    *& Programmer       : TSHANKAR                                             *
    *& Date             : 16/11/2007                                           *
    *& Transaction      :                                                      *
    *& Description      : This extractor fetches data fetches data from        *
                        tables BSID ,BSAD, KNVP,Z02TOTC_AR_DOC_H for closed  *
                         and open item and populate into final extract       *
                         structure FOR CLOSED                                *
    Modification Log:                                                        *
    Date      Author       Corr. #      Description                          *
    mm/dd/yy  SAPLOGONNAM  xxxxxxxxxx   Initial program development          *
              TSHANKAR                  Changes made to the application      *
                                        path                                 *
    **DATA DECLERATION
    Maximum number of lines for DB table
      STATICS: S_S_IF TYPE SRSC_S_IF_SIMPLE,
    counter
               S_COUNTER_DATAPAKID LIKE SY-TABIX,
    Cursor
               S_CURSOR TYPE CURSOR,
               S_CURSOR1 TYPE CURSOR.
    DATA : FLAG_BSID TYPE I VALUE 0.
    Initialization mode (first call by SAPI) or data transfer mode
    (following calls) ?
      IF I_INITFLAG = SBIWA_C_FLAG_ON.
        APPEND LINES OF I_T_SELECT TO S_S_IF-T_SELECT.
    Fill parameter buffer for data extraction calls
        S_S_IF-REQUNR    = I_REQUNR.
        S_S_IF-DSOURCE = I_DSOURCE.
        S_S_IF-MAXSIZE   = I_MAXSIZE.
    Fill field list table for an optimized select statement
    (in case that there is no 1:1 relation between InfoSource fields
    and database table fields this may be far from beeing trivial)
        APPEND LINES OF I_T_FIELDS TO S_S_IF-T_FIELDS.
      ELSE.           "Initialization mode or data extraction ?
    Data transfer: First Call      OPEN CURSOR + FETCH
                   Following Calls FETCH only
    First data package -> OPEN CURSOR
        IF S_COUNTER_DATAPAKID = 0.
    Fill range tables BW will only pass down simple selection criteria
    of the type SIGN = 'I' and OPTION = 'EQ' or OPTION = 'BT'.
          LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'BUKRS'.
            MOVE-CORRESPONDING L_S_SELECT TO R_BUKRS.
            APPEND R_BUKRS.
          ENDLOOP.
          LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'KUNNR'.
            MOVE-CORRESPONDING L_S_SELECT TO R_KUNNR.
            APPEND R_KUNNR.
          ENDLOOP.
          LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'GJAHR'.
            MOVE-CORRESPONDING L_S_SELECT TO R_GJAHR.
            APPEND R_GJAHR.
          ENDLOOP.
          LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'CPUDT'.
            MOVE-CORRESPONDING L_S_SELECT TO R_CPUDT.
            APPEND R_CPUDT.
            ENDLOOP.
    Determine number of database records to be read per FETCH statement
    from input parameter I_MAXSIZE. If there is a one to one relation
    between DataSource table lines and database entries, this is trivial.
    In other cases, it may be impossible and some estimated value has to
    be determined.
            OPEN CURSOR WITH HOLD S_CURSOR FOR
                  SELECT MANDT KUNNR WRBTR XREF3 BUKRS BELNR GJAHR BUZEI WAERS BLDAT
                         BUDAT BLART XBLNR SHKZG DMBTR GSBER ZFBDT ZLSCH ZUONR ZTERM
                         KIDNO XREF1 XREF2 SGTXT MABER HKONT PRCTR KOSTL AUFNR PROJK
                         VBUND
                          FROM BSID WHERE  BUKRS IN R_BUKRS AND KUNNR IN R_KUNNR AND
                                                            GJAHR IN R_GJAHR AND
                                                            CPUDT IN R_CPUDT .
              OPEN CURSOR WITH HOLD S_CURSOR1 FOR
                  SELECT MANDT KUNNR WRBTR XREF3 BUKRS BELNR GJAHR BUZEI WAERS BLDAT
                         BUDAT BLART XBLNR SHKZG DMBTR GSBER ZFBDT ZLSCH ZUONR ZTERM
                         KIDNO XREF1 XREF2 SGTXT MABER HKONT PRCTR KOSTL AUFNR PROJK
                         VBUND
                          FROM BSAD WHERE  BUKRS IN R_BUKRS AND KUNNR IN R_KUNNR AND
                                                            GJAHR IN R_GJAHR AND
                                                            CPUDT IN R_CPUDT .
          ENDIF.               "First data package ?
    Fetch records into interface table.
          FETCH NEXT CURSOR S_CURSOR
                     APPENDING CORRESPONDING FIELDS
                     OF TABLE IT_BSID
                     PACKAGE SIZE S_S_IF-MAXSIZE.
         FETCH NEXT CURSOR S_CURSOR1
                    APPENDING CORRESPONDING FIELDS
                    OF TABLE IT_BSAD
                    PACKAGE SIZE S_S_IF-MAXSIZE.
          IF SY-SUBRC <> 0.
            CLOSE CURSOR S_CURSOR.
            RAISE NO_MORE_DATA.
          ENDIF.
          S_COUNTER_DATAPAKID = S_COUNTER_DATAPAKID + 1.
        ENDIF.                  "Initialization mode or data extraction ?
    PERFORM FETCH_BSID .
    *PERFORM FETCH_BSAD TABLES E_T_DATA.
    *FORM FETCH_BSID TABLES P_E_T_DATA type  ZBIAR_EXTRACTOR_AR2.
          SORT IT_BSID BY KUNNR BUKRS GJAHR .
       CHECK  NOT IT_BSID[] IS INITIAL .
       PERFORM FILL_Z02TOTC_AR_DOC_H.
       PERFORM FILL_KNVP.
       LOOP AT IT_BSID .
         READ TABLE IT_Z02TOTC_AR_DOC_H WITH KEY BELNR = IT_BSID-BELNR
                                                 BUKRS = IT_BSID-BUKRS
                                                 GJAHR = IT_BSID-GJAHR
                                                 BUZEI = IT_BSID-BUZEI.
         LOOP AT IT_Z02TOTC_AR_DOC_H FROM SY-TABIX.
           IF SY-SUBRC IS INITIAL .
             IF IT_Z02TOTC_AR_DOC_H-BELNR <> IT_BSID-BELNR
              OR IT_Z02TOTC_AR_DOC_H-BUKRS <> IT_BSID-BUKRS
              OR IT_Z02TOTC_AR_DOC_H-GJAHR <> IT_BSID-GJAHR.
              OR IT_Z02TOTC_AR_DOC_H-BUZEI <> IT_BSID-BUZEI.
               EXIT .
             ENDIF .
             READ TABLE IT_KNVP WITH KEY KUNNR = IT_BSID-KUNNR
                                         VKORG = IT_BSID-BUKRS.
             IF SY-SUBRC IS INITIAL.
               MOVE-CORRESPONDING IT_KNVP TO E_T_DATA.
               MOVE-CORRESPONDING IT_Z02TOTC_AR_DOC_H TO E_T_DATA.
               MOVE-CORRESPONDING IT_BSID TO E_T_DATA.
               APPEND E_T_DATA.
             ENDIF .
           ENDIF.
         ENDLOOP .
       ENDLOOP .
    *FREE : IT_BSID ,IT_Z02TOTC_AR_DOC_H ,IT_KNVP.
    *ENDFORM.
      ENDFUNCTION.  " End of Function Z01_FBIWI_AR_EXTRACTOR
    **form for fetching cleared entries
    *FORM FETCH_BSAD using  P_E_T_DATA LIKE ZBIAR_EXTRACTOR_AR2
                   changing e_t_data type p_e_t_data.
          SORT IT_BSAD BY KUNNR BUKRS GJAHR .
       CHECK  NOT IT_BSAD[] IS INITIAL .
       PERFORM FILL_Z02TOTC_AR_DOC_H_BSAD.
       PERFORM FILL_KNVP_BSAD.
       LOOP AT IT_BSAD .
         READ TABLE IT_Z02TOTC_AR_DOC_H_BSAD WITH KEY BELNR = IT_BSAD-BELNR
                                                      BUKRS = IT_BSAD-BUKRS
                                                      GJAHR = IT_BSAD-GJAHR
                                                      BUZEI = IT_BSAD-BUZEI.
         LOOP AT IT_Z02TOTC_AR_DOC_H_BSAD FROM SY-TABIX.
           IF SY-SUBRC IS INITIAL .
             IF IT_Z02TOTC_AR_DOC_H_BSAD-BELNR <> IT_BSAD-BELNR
              OR IT_Z02TOTC_AR_DOC_H_BSAD-BUKRS <> IT_BSAD-BUKRS
              OR IT_Z02TOTC_AR_DOC_H_BSAD-GJAHR <> IT_BSAD-GJAHR.
              OR IT_Z02TOTC_AR_DOC_H-BUZEI <> IT_BSID-BUZEI.
               EXIT .
             ENDIF .
             READ TABLE IT_KNVP_BSAD WITH KEY KUNNR = IT_BSAD-KUNNR
                                              VKORG = IT_BSAD-BUKRS.
             IF SY-SUBRC IS INITIAL.
               MOVE-CORRESPONDING IT_KNVP_BSAD TO P_E_T_DATA.
               MOVE-CORRESPONDING IT_Z02TOTC_AR_DOC_H_BSAD TO P_E_T_DATA.
               MOVE-CORRESPONDING IT_BSAD TO P_E_T_DATA.
               APPEND P_E_T_DATA.
             ENDIF .
           ENDIF.
         ENDLOOP .
       ENDLOOP .
    *FREE : IT_BSAD ,IT_Z02TOTC_AR_DOC_H ,IT_KNVP.

  • Performance Issue For Opening And Closing Balance In FBL1N/3N/5N

    Dear experts,
                        I Am Having Requirement to Bring Opening And Closing Balance In FBL1N, FBL3N, FBL5N.
    For This requirement I Used BADI : FI_ITEMS_CH_DATA~CHANGE_ITEMS, below is my Code For FBL1N, And I've Done the same For 3N/5N...With Related BAPI
    *   IF SY-TCODE = 'FBL1N'.
    *    LOOP AT ct_items INTO gs_items.
    *      CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
    *        EXPORTING
    *          date      = gs_items-budat
    *          days      = '01'
    *          months    = '00'
    *          signum    = '-'
    *          years     = '00'
    *        IMPORTING
    *          calc_date = lv_date.
    *      CALL FUNCTION 'BAPI_AP_ACC_GETKEYDATEBALANCE'
    *        EXPORTING
    *          companycode        = gs_items-bukrs
    *          vendor             = gs_items-konto
    *          keydate            = lv_date
    **   BALANCESPGLI       = ' '
    **   NOTEDITEMS         = ' '
    ** IMPORTING
    **   RETURN             =
    *        TABLES
    *          keybalance         =  lv_obal.
    *      CALL FUNCTION 'BAPI_AP_ACC_GETKEYDATEBALANCE'
    *        EXPORTING
    *          companycode        = gs_items-bukrs
    *          vendor             = gs_items-konto
    *          keydate            = gs_items-budat
    **   BALANCESPGLI       = ' '
    **   NOTEDITEMS         = ' '
    ** IMPORTING
    **   RETURN             =
    *        TABLES
    *          keybalance         = lv_cbal
    *      READ TABLE lv_cbal INTO gs_cbal INDEX 1.
    *      gs_items-cbal = gs_cbal-lc_bal.
    *      READ TABLE lv_obal INTO gs_obal INDEX 1.
    *      gs_items-obal = gs_obal-lc_bal.
    *      MODIFY ct_items FROM gs_items TRANSPORTING obal cbal.
    *      CLEAR: gs_items,gs_obal,gs_cbal.
    *    ENDLOOP.
    *   ENDIF.
    So, Above Code Causing Me the Performance Issue, Kindly Suggest Me the Solution..
    Regards,
    uday.

    Hi Uday,
    I am sending you the code i used for the creation a Zreport based on FBL5N. Please check if it can of any help.
    *& Report  ZFBL5N                                                      *
    REPORT  zfbl5n_new  .
    TABLES : bsid,knc1,lfc1.
    TYPE-POOLS: slis.
    TYPES: BEGIN OF ty_bsid,
              bukrs TYPE bsid-bukrs,
              kunnr TYPE bsid-kunnr,
              belnr TYPE bsid-belnr,
              buzei TYPE bsid-buzei,
              bldat TYPE bsid-bldat,
              blart TYPE bsid-blart,
              bschl TYPE bsid-bschl,
              shkzg TYPE bsid-shkzg,
              dmbtr TYPE bsid-dmbtr,
              augdt TYPE bsid-augdt,
              augbl TYPE bsid-augbl,
              zuonr TYPE bsid-zuonr,
              sgtxt TYPE bsid-sgtxt,
              zfbdt TYPE bsid-zfbdt,
              zterm TYPE bsid-zterm,
              zbd1t TYPE bsid-zbd1t,
              zbd2t TYPE bsid-zbd2t,
              zbd3t TYPE bsid-zbd3t,
              kkber TYPE bsid-kkber,
              bstat TYPE bsid-bstat,
              umskz TYPE bsid-umskz,
            END OF ty_bsid.
    TYPES: BEGIN OF ty_bsik,
             bukrs TYPE bsik-bukrs,
              lifnr TYPE bsik-lifnr,
              belnr TYPE bsik-belnr,
              buzei TYPE bsik-buzei,
              bldat TYPE bsik-bldat,
              blart TYPE bsik-blart,
              bschl TYPE bsik-bschl,
              shkzg TYPE bsik-shkzg,
              dmbtr TYPE bsik-dmbtr,
              augdt TYPE bsik-augdt,
              augbl TYPE bsik-augbl,
              zuonr TYPE bsik-zuonr,
              sgtxt TYPE bsik-sgtxt,
               zfbdt TYPE bsik-zfbdt,
    *         KKBER TYPE bsik-kkber,
              zterm TYPE bsik-zterm,
               zbd1t TYPE bsik-zbd1t,
              zbd2t TYPE bsik-zbd2t,
              zbd3t TYPE bsik-zbd3t,
              bstat TYPE bsid-bstat,
              umskz TYPE bsid-umskz,
            END OF ty_bsik.
    TYPES: BEGIN OF ty_final,
              belnr TYPE bsid-belnr,
    *         buzei TYPE bsak-buzei,
              bldat TYPE bsid-bldat,
              blart TYPE bsid-blart,
              chq TYPE bsid-zuonr,
              debit TYPE bsid-dmbtr,
              credit TYPE bsid-dmbtr,
              txt TYPE bsid-sgtxt,
              date TYPE bsid-zfbdt,
              kkber TYPE bsid-kkber,
              zterm TYPE bsid-zterm,
              augbl TYPE bsid-augbl,
              augdt TYPE bsid-augdt,
              flag TYPE c,
            END OF ty_final.
    TYPES : BEGIN OF gs_openbal,
              bukrs TYPE bapi3007_2-comp_code,
              kunnr TYPE bapi3007_2-customer,
              dmbtr TYPE bapi3007_2-lc_amount,
             END OF gs_openbal.
    DATA: it_bsid TYPE STANDARD TABLE OF ty_bsid,
           it_bsik TYPE STANDARD TABLE OF ty_bsik,
           it_final TYPE STANDARD TABLE OF ty_final.
    DATA: wa_bsid TYPE ty_bsid,
           wa_bsik TYPE ty_bsik,
           wa_final TYPE ty_final.
    DATA: w_days TYPE t5a4a-dlydy,
           w_month TYPE t5a4a-dlymo,
           w_year TYPE t5a4a-dlyyr,
           w_date TYPE p0001-begda,
           w_name1 TYPE kna1-name1,
           w_ort01 TYPE kna1-ort01,
           w_lifnr TYPE kna1-lifnr,
           w_dmbtr1 TYPE bsid-dmbtr,
           w_dmbtr2 TYPE bsid-dmbtr,
           w_dmbtr3 TYPE bsad-dmbtr,
           w_dmbtr4 TYPE bsad-dmbtr,
           w_opbal TYPE bsid-dmbtr,
           w_credit TYPE bsik-dmbtr,
           w_debit TYPE bsik-dmbtr,
           w_clobal TYPE bsik-dmbtr,
           w_credit1 TYPE bsik-dmbtr,
           w_debit1 TYPE bsik-dmbtr,
           w_clobal1 TYPE bsik-dmbtr.
    DATA: ld_yrper LIKE rwcoom-fiscper,
           kunnr LIKE kna1-kunnr,
           x_norm TYPE c,
           x_park,
           x_apar,
           x_merk,
           ok_code(4),
           wa_x001 LIKE x001,
           return LIKE bapireturn,
           line_count LIKE sy-loopc,
           number_of_records TYPE i,
           xindex LIKE sy-tabix,
           open LIKE knc1-um01s,
           temp(20),
           close LIKE knc1-um01s,
           gjahr LIKE bsid-gjahr,
           period LIKE bkpf-monat,
           f(1),
           v_char(2),
           closec(20),
           openc(20),
           debit LIKE bapi3007_2-lc_amount,
           credit LIKE debit.
    DATA : v_dmbtr LIKE bsid-dmbtr.
    *DATA : tot_debit LIKE t_ar-debit,
    *       tot_credit LIKE t_ar-credit.
    DATA : t_kna1 LIKE kna1 OCCURS 1  WITH HEADER LINE,
            t_knb1 LIKE knb1 OCCURS 10 WITH HEADER LINE.
    DATA ibsid LIKE bsid OCCURS 0 WITH HEADER LINE.
    DATA ibsad LIKE bsad OCCURS 0 WITH HEADER LINE.
    DATA ibsik LIKE bsik OCCURS 0 WITH HEADER LINE.
    DATA ibsak LIKE bsak OCCURS 0 WITH HEADER LINE.
    DATA : it_fieldcat_alv   TYPE slis_t_fieldcat_alv,
            wa_fieldcat_alv     TYPE slis_fieldcat_alv,
            is_layout_alv  TYPE slis_layout_alv,
            wa_layout_alv  TYPE slis_layout_alv,
            it_list_top_of_page TYPE slis_t_listheader,
            it_events TYPE slis_t_event,
            wa_events TYPE LINE OF slis_t_event.
    DATA : BEGIN OF ibukrs OCCURS 0,
               bukrs LIKE t001-bukrs,
              END OF ibukrs.
    DATA : BEGIN OF ikunnr1 OCCURS 0,
              kunnr LIKE knc1-kunnr,
             END OF ikunnr1.
    DATA : BEGIN OF ikunnr OCCURS 0,
               kunnr LIKE knc1-kunnr,
               bukrs LIKE t001-bukrs,
               lifnr LIKE lfc1-lifnr,
              END OF ikunnr.
    DATA: it_sort TYPE slis_t_sortinfo_alv,
           wa_sort TYPE slis_sortinfo_alv.
    DATA:    r_bschl TYPE RANGE OF bschl,
              wa_bschl LIKE LINE OF r_bschl.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
    PARAMETERS : p_kunnr TYPE bsid-kunnr OBLIGATORY,
                  p_bukrs TYPE bsid-bukrs OBLIGATORY.
    SELECT-OPTIONS: so_budat FOR bsid-budat .
    SELECTION-SCREEN END OF BLOCK b1.
    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
    PARAMETERS : p_normal AS CHECKBOX,
                  p_spl    AS CHECKBOX,
                  p_vendor AS CHECKBOX.
    SELECTION-SCREEN END OF BLOCK b2.
    PERFORM get_data.
    PERFORM process_data.
    *PERFORM calculate_openbal. " Commented by anish
    PERFORM calculate_open_bal.
    PERFORM calculate_closing_bal.
    PERFORM build_catalog_sort USING it_sort.
    PERFORM reuse_alv_events_get .
    PERFORM display_data.
    *&      Form  GET_DATA
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM get_data .
       SELECT bukrs kunnr belnr buzei bldat blart bschl shkzg dmbtr augdt augbl zuonr sgtxt zfbdt zterm zbd1t zbd2t zbd3t kkber
         bstat umskz FROM bsid
         INTO TABLE it_bsid
         WHERE bukrs = p_bukrs
          AND kunnr = p_kunnr
          AND budat IN so_budat.
       SELECT bukrs kunnr belnr buzei bldat blart bschl shkzg dmbtr augdt augbl zuonr sgtxt zfbdt zterm zbd1t zbd2t zbd3t kkber
        bstat umskz FROM bsad
        APPENDING TABLE it_bsid
        WHERE bukrs = p_bukrs
         AND kunnr = p_kunnr
         AND budat IN so_budat.
       SELECT SINGLE name1 ort01 lifnr FROM kna1
         INTO (w_name1 , w_ort01 , w_lifnr)
         WHERE kunnr = p_kunnr.
       IF p_vendor IS NOT INITIAL.
         SELECT bukrs lifnr belnr buzei bldat blart bschl shkzg dmbtr augdt augbl zuonr sgtxt zfbdt zterm zbd1t zbd2t zbd3t
         bstat umskz   FROM bsik
         APPENDING TABLE it_bsik
         WHERE bukrs = p_bukrs
           AND lifnr = w_lifnr
           AND budat IN so_budat.
         SELECT bukrs lifnr belnr buzei bldat blart bschl shkzg dmbtr augdt augbl zuonr sgtxt zfbdt zterm zbd1t zbd2t zbd3t
         bstat umskz  FROM bsak
        APPENDING TABLE it_bsik
        WHERE bukrs = p_bukrs
          AND lifnr = w_lifnr
          AND budat IN so_budat.
       ENDIF.
       SORT it_bsid BY bschl.
       DELETE  it_bsid WHERE bschl = '04'.
       DELETE  it_bsid WHERE bschl = '07'.
       DELETE  it_bsid WHERE bschl = '17'.
       DELETE  it_bsid WHERE bschl = '34'.
       DELETE  it_bsid WHERE bschl = '27'.
       DELETE  it_bsid WHERE bschl = '37'.
       SORT it_bsik BY bschl.
       DELETE  it_bsik WHERE bschl = '04'.
       DELETE  it_bsik WHERE bschl = '07'.
       DELETE  it_bsik WHERE bschl = '17'.
       DELETE  it_bsik WHERE bschl = '34'.
       DELETE  it_bsik WHERE bschl = '27'.
       DELETE  it_bsik WHERE bschl = '37'.
    ENDFORM.                    " GET_DATA
    *&      Form  PROCESS_DATA
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM process_data .
       DATA:okay       TYPE c VALUE space.
       w_month = '00'.
       w_year = '00'.
       SORT it_bsid BY bldat .
       LOOP AT it_bsid INTO wa_bsid.
         PERFORM check_item_ok  USING p_normal
                                      p_spl
                                      p_vendor
    *                               x_park
                                      wa_bsid
                                CHANGING okay.
         CHECK okay = 'X'.
         wa_final-belnr = wa_bsid-belnr.
         wa_final-bldat = wa_bsid-bldat.
         wa_final-blart = wa_bsid-blart.
         wa_final-txt = wa_bsid-sgtxt.
         wa_final-kkber = wa_bsid-kkber.
         wa_final-zterm = wa_bsid-zterm.
         wa_final-augbl = wa_bsid-augbl.
         wa_final-augdt = wa_bsid-augdt.
         wa_final-flag = 'C'.
         IF wa_bsid-blart = 'DZ'.
           wa_final-chq = wa_bsid-zuonr.
         ENDIF.
         IF wa_bsid-shkzg = 'S'.
           wa_final-debit = wa_bsid-dmbtr.
         ELSEIF wa_bsid-shkzg = 'H'.
           wa_final-credit = wa_bsid-dmbtr.
         ENDIF.
         w_credit = w_credit + wa_final-credit.
         w_debit = w_debit + wa_final-debit.
    ****** Net due  date
         IF wa_bsid-zbd1t IS NOT INITIAL.
           w_days = wa_bsid-zbd1t.
         ELSEIF wa_bsid-zbd2t IS NOT INITIAL.
           w_days = wa_bsid-zbd2t.
         ELSEIF wa_bsid-zbd3t IS NOT INITIAL.
           w_days = wa_bsid-zbd3t.
         ENDIF.
         IF w_days IS INITIAL.
           wa_final-date = wa_bsid-zfbdt.
         ELSE.
           CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
             EXPORTING
               date      = wa_bsid-zfbdt
               days      = w_days
               months    = w_month
               signum    = '+'
               years     = w_year
             IMPORTING
               calc_date = w_date.
           wa_final-date = w_date.
         ENDIF.
         APPEND wa_final TO it_final.
         CLEAR: w_days , w_date , wa_final .
       ENDLOOP.
       IF it_bsik IS NOT INITIAL.
         CLEAR: w_days , w_date.
         SORT it_bsik BY bldat.
         LOOP AT it_bsik INTO wa_bsik.
           wa_final-belnr = wa_bsik-belnr.
           wa_final-bldat = wa_bsik-bldat.
           wa_final-blart = wa_bsik-blart.
           wa_final-txt = wa_bsik-sgtxt.
    *    wa_final-kkber = wa_bsik-kkber.
           wa_final-zterm = wa_bsik-zterm.
           wa_final-augbl = wa_bsik-augbl.
           wa_final-augdt = wa_bsik-augdt.
           wa_final-flag = 'V'.
           IF wa_bsik-blart = 'DZ'.
             wa_final-chq = wa_bsik-zuonr.
           ENDIF.
           IF wa_bsik-shkzg = 'S'.
             wa_final-debit = wa_bsik-dmbtr.
           ELSEIF wa_bsik-shkzg = 'H'.
             wa_final-credit = wa_bsik-dmbtr.
           ENDIF.
           w_credit1 = w_credit1 + wa_final-credit.
           w_debit1 = w_debit1 + wa_final-debit.
    *******  Net Due date
           IF wa_bsik-zbd1t IS NOT INITIAL.
             w_days = wa_bsik-zbd1t.
           ELSEIF wa_bsik-zbd2t IS NOT INITIAL.
             w_days = wa_bsik-zbd2t.
           ELSEIF wa_bsik-zbd3t IS NOT INITIAL.
             w_days = wa_bsik-zbd3t.
           ENDIF.
           IF w_days IS INITIAL.
             wa_final-date = wa_bsik-zfbdt.
           ELSE.
             CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
               EXPORTING
                 date      = wa_bsik-zfbdt
                 days      = w_days
                 months    = w_month
                 signum    = '+'
                 years     = w_year
               IMPORTING
                 calc_date = w_date.
           ENDIF.
           wa_final-date = w_date.
           APPEND wa_final TO it_final.
           CLEAR: wa_final.
         ENDLOOP.
       ENDIF.
    ENDFORM.                    " PROCESS_DATA
    *&      Form  DISPLAY_DATA
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM display_data .
       wa_fieldcat_alv-fieldname = 'BELNR'.
       wa_fieldcat_alv-tabname = 'IT_FINAL'.
       wa_fieldcat_alv-seltext_l = text-003.
       wa_fieldcat_alv-outputlen = '11'.
       APPEND wa_fieldcat_alv TO it_fieldcat_alv.
       CLEAR wa_fieldcat_alv.
       wa_fieldcat_alv-fieldname = 'BLDAT'.
       wa_fieldcat_alv-tabname = 'IT_FINAL'.
       wa_fieldcat_alv-seltext_l = text-004.
       wa_fieldcat_alv-outputlen = '13'.
       APPEND wa_fieldcat_alv TO it_fieldcat_alv.
       CLEAR wa_fieldcat_alv.
       wa_fieldcat_alv-fieldname = 'BLART'.
       wa_fieldcat_alv-tabname = 'IT_FINAL'.
       wa_fieldcat_alv-seltext_l = text-005.
       wa_fieldcat_alv-outputlen = '02'.
       APPEND wa_fieldcat_alv TO it_fieldcat_alv.
       CLEAR wa_fieldcat_alv.
       wa_fieldcat_alv-fieldname = 'CHQ'.
       wa_fieldcat_alv-tabname = 'IT_FINAL'.
       wa_fieldcat_alv-seltext_l = text-006.
       wa_fieldcat_alv-outputlen = '09'.
       APPEND wa_fieldcat_alv TO it_fieldcat_alv.
       CLEAR wa_fieldcat_alv.
       wa_fieldcat_alv-fieldname = 'DEBIT'.
       wa_fieldcat_alv-tabname = 'IT_FINAL'.
       wa_fieldcat_alv-seltext_l = text-007.
       wa_fieldcat_alv-outputlen = '15'.
       wa_fieldcat_alv-do_sum = 'X'.
       APPEND wa_fieldcat_alv TO it_fieldcat_alv.
       CLEAR wa_fieldcat_alv.
       wa_fieldcat_alv-fieldname = 'CREDIT'.
       wa_fieldcat_alv-tabname = 'IT_FINAL'.
       wa_fieldcat_alv-seltext_l = text-008.
       wa_fieldcat_alv-outputlen = '15'.
       wa_fieldcat_alv-do_sum = 'X'.
       APPEND wa_fieldcat_alv TO it_fieldcat_alv.
       CLEAR wa_fieldcat_alv.
       wa_fieldcat_alv-fieldname = 'TXT'.
       wa_fieldcat_alv-tabname = 'IT_FINAL'.
       wa_fieldcat_alv-seltext_l = text-009.
       wa_fieldcat_alv-outputlen = '50'.
       APPEND wa_fieldcat_alv TO it_fieldcat_alv.
       CLEAR wa_fieldcat_alv.
       wa_fieldcat_alv-fieldname = 'DATE'.
       wa_fieldcat_alv-tabname = 'IT_FINAL'.
       wa_fieldcat_alv-seltext_l = text-010.
       wa_fieldcat_alv-outputlen = '12'.
       APPEND wa_fieldcat_alv TO it_fieldcat_alv.
       CLEAR wa_fieldcat_alv.
       wa_fieldcat_alv-fieldname = 'KKBER'.
       wa_fieldcat_alv-tabname = 'IT_FINAL'.
       wa_fieldcat_alv-seltext_l = text-011.
       wa_fieldcat_alv-outputlen = '04'.
       APPEND wa_fieldcat_alv TO it_fieldcat_alv.
       CLEAR wa_fieldcat_alv.
       wa_fieldcat_alv-fieldname = 'ZTERM'.
       wa_fieldcat_alv-tabname = 'IT_FINAL'.
       wa_fieldcat_alv-seltext_l = text-012.
       wa_fieldcat_alv-outputlen = '13'.
       APPEND wa_fieldcat_alv TO it_fieldcat_alv.
       CLEAR wa_fieldcat_alv.
       wa_fieldcat_alv-fieldname = 'AUGBL'.
       wa_fieldcat_alv-tabname = 'IT_FINAL'.
       wa_fieldcat_alv-seltext_l = text-013.
       wa_fieldcat_alv-outputlen = '15'.
       APPEND wa_fieldcat_alv TO it_fieldcat_alv.
       CLEAR wa_fieldcat_alv.
       wa_fieldcat_alv-fieldname = 'AUGDT'.
       wa_fieldcat_alv-tabname = 'IT_FINAL'.
       wa_fieldcat_alv-seltext_l = text-014.
       wa_fieldcat_alv-outputlen = '17'.
       APPEND wa_fieldcat_alv TO it_fieldcat_alv.
       CLEAR wa_fieldcat_alv.
       wa_fieldcat_alv-fieldname = 'FLAG'.
       wa_fieldcat_alv-tabname = 'IT_FINAL'.
       wa_fieldcat_alv-tech = 'X'.
       APPEND wa_fieldcat_alv TO it_fieldcat_alv.
       CLEAR wa_fieldcat_alv.
       CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
        EXPORTING
          i_callback_program             = sy-repid
          is_layout                      = wa_layout_alv
          it_fieldcat                    = it_fieldcat_alv
    *   IT_EXCLUDING                   =
    *   IT_SPECIAL_GROUPS              =
          it_sort                        = it_sort
          it_events                      = it_events
          i_save                            = 'A'
         TABLES
           t_outtab                       = it_final
        EXCEPTIONS
          program_error                  = 1
          OTHERS                         = 2
       IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
       ENDIF.
    *  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    *    EXPORTING
    *      i_callback_program                = sy-repid
    *     i_callback_top_of_page            = 'TOP_OF_PAGE'
    *      is_layout                         = wa_layout_alv
    *      it_fieldcat                       = it_fieldcat_alv
    *      it_sort                           = it_sort
    ***   I_DEFAULT                         = 'X'
    **      i_save                            = 'A'
    ***   IT_EVENTS                         =
    *     TABLES
    *       t_outtab                          = it_final
    *    EXCEPTIONS
    *      program_error                     = 1
    *      OTHERS                            = 2
    *  IF sy-subrc <> 0.
    *** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    ***         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    *  ENDIF.
    ENDFORM.                    " DISPLAY_DATA
    *&      Form  TOP_OF_PAGE
    *       Header at top of page.
    FORM top_of_page.
       SKIP 1.
       WRITE: AT 35 'Account Statement from' , so_budat-low , 'to' , so_budat-high.
       SKIP 2.
       WRITE: AT /5 'CUSTOMER:' , p_kunnr.
       WRITE: AT 35 'Name:' , w_name1.
       WRITE: AT /5 'Company:' , p_bukrs.
       WRITE: AT 35 'City:' , w_ort01.
       SKIP 1.
       WRITE: AT /5 'Opening Balance as on' , so_budat-low , '   ' ,  w_opbal LEFT-JUSTIFIED.
       SKIP 2.
    ENDFORM.                    "TOP_OF_PAGE
    *&      Form  END_OF_PAGE
    *       Footer at End of page.
    FORM end_of_page.
       SKIP 2.
       IF so_budat-high IS NOT INITIAL.
         WRITE: AT 5 'Closing Balance as on' , so_budat-high , '   ' ,  w_clobal LEFT-JUSTIFIED.
       ELSE.
         WRITE: AT 5 'Closing Balance  ' , w_clobal LEFT-JUSTIFIED.
       ENDIF.
    ENDFORM.                    "end_of_page
    *&      Form  CALCULATE_OPENBAL
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM calculate_openbal .
       DATA:v_gjahr       TYPE bsid-gjahr.
       DATA: v_period LIKE  t009b-poper,v_monat LIKE t001-periv.
       CALL FUNCTION 'FI_PERIOD_DETERMINE'
              EXPORTING
                   i_budat        = so_budat-low
                   i_bukrs        = p_bukrs
    *           I_PERIV        = ' '
    *           I_GJAHR        = 0000
    *           I_MONAT        = 00
    *           X_XMO16        = ' '
              IMPORTING
                   e_gjahr        = v_gjahr
    *            e_monat        = v_monat
                   e_poper        = v_period.
       IF sy-subrc NE 0.
       ENDIF.
       DATA: f_date LIKE sy-datum.
       CALL FUNCTION 'FIRST_DAY_IN_PERIOD_GET'
         EXPORTING
           i_gjahr  = v_gjahr
           i_monmit = 00
           i_periv  = 'V3'
           i_poper  = v_period
         IMPORTING
           e_date   = f_date.
       period = v_period - 1.
       gjahr = v_gjahr.
       DATA wa_kna1 LIKE kna1.
       CALL FUNCTION 'READ_KNA1'
         EXPORTING
           xkunnr         = p_kunnr
         IMPORTING
           xkna1          = wa_kna1
         EXCEPTIONS
           key_incomplete = 1
           not_authorized = 2
           not_found      = 3
           OTHERS         = 4.
       IF sy-subrc <> 0.
         MESSAGE w023(zwww).
         CALL SCREEN 0010.
       ENDIF.
       MOVE-CORRESPONDING wa_kna1 TO t_kna1.
       APPEND t_kna1.
       SELECT kunnr FROM kna1 INTO TABLE ikunnr1
         WHERE kunnr = p_kunnr.
       SELECT bukrs FROM t001 INTO TABLE ibukrs
        FOR ALL ENTRIES IN t_knb1
        WHERE bukrs = t_knb1-bukrs.
       LOOP AT ikunnr1.
         LOOP AT ibukrs.
           ikunnr-kunnr = ikunnr1-kunnr.
           ikunnr-bukrs = ibukrs-bukrs.
           READ TABLE t_kna1 WITH  KEY kunnr = ikunnr1-kunnr.
           ikunnr-lifnr = t_kna1-lifnr.
           APPEND ikunnr.
         ENDLOOP.
       ENDLOOP.
       DELETE ikunnr WHERE bukrs NE p_bukrs.
       LOOP AT ikunnr.
         CLEAR: knc1,lfc1,f.
         IF NOT ( ikunnr-kunnr IS INITIAL ) AND NOT ( p_vendor IS INITIAL ).
           SELECT SINGLE * FROM lfc1
                  WHERE gjahr = gjahr AND bukrs = ikunnr-bukrs
                                      AND lifnr = ikunnr-lifnr.
         ENDIF.
         SELECT SINGLE * FROM knc1
           WHERE gjahr = gjahr AND bukrs = p_bukrs
                 AND kunnr = p_kunnr.
         IF sy-subrc = 0.
           CASE period .
             WHEN 12.
               open = knc1-umsav +
               knc1-um01s - knc1-um01h + knc1-um02s - knc1-um02h +
               knc1-um03s - knc1-um03h + knc1-um04s - knc1-um04h +
               knc1-um05s - knc1-um05h + knc1-um06s - knc1-um06h +
               knc1-um07s - knc1-um07h + knc1-um08s - knc1-um08h +
               knc1-um09s - knc1-um09h + knc1-um10s - knc1-um10h +
               knc1-um11s - knc1-um11h + knc1-um12s - knc1-um12h.
               IF NOT ( lfc1 IS INITIAL ).
                 open = open + lfc1-umsav +
                 lfc1-um01s - lfc1-um01h + lfc1-um02s - lfc1-um02h +
                 lfc1-um03s - lfc1-um03h + lfc1-um04s - lfc1-um04h +
                 lfc1-um05s - lfc1-um05h + lfc1-um06s - lfc1-um06h +
                 lfc1-um07s - lfc1-um07h + lfc1-um08s - lfc1-um08h +
                 lfc1-um09s - lfc1-um09h + lfc1-um10s - lfc1-um10h +
                 lfc1-um11s - lfc1-um11h + lfc1-um12s - lfc1-um12h.
               ENDIF.
             WHEN 11.
               open = knc1-umsav +
               knc1-um01s - knc1-um01h + knc1-um02s - knc1-um02h +
               knc1-um03s - knc1-um03h + knc1-um04s - knc1-um04h +
               knc1-um05s - knc1-um05h + knc1-um06s - knc1-um06h +
               knc1-um07s - knc1-um07h + knc1-um08s - knc1-um08h +
               knc1-um09s - knc1-um09h + knc1-um10s - knc1-um10h +
               knc1-um11s - knc1-um11h.
               IF NOT ( lfc1 IS INITIAL ) .
                 open = open + lfc1-umsav +
                 lfc1-um01s - lfc1-um01h + lfc1-um02s - lfc1-um02h +
                 lfc1-um03s - lfc1-um03h + lfc1-um04s - lfc1-um04h +
                 lfc1-um05s - lfc1-um05h + lfc1-um06s - lfc1-um06h +
                 lfc1-um07s - lfc1-um07h + lfc1-um08s - lfc1-um08h +
                 lfc1-um09s - lfc1-um09h + lfc1-um10s - lfc1-um10h +
                 lfc1-um11s - lfc1-um11h.
               ENDIF.
             WHEN 10.
               open = knc1-umsav +
               knc1-um01s - knc1-um01h + knc1-um02s - knc1-um02h +
               knc1-um03s - knc1-um03h + knc1-um04s - knc1-um04h +
               knc1-um05s - knc1-um05h + knc1-um06s - knc1-um06h +
               knc1-um07s - knc1-um07h + knc1-um08s - knc1-um08h +
               knc1-um09s - knc1-um09h + knc1-um10s - knc1-um10h .
               IF NOT ( lfc1 IS INITIAL ) .
                 open = open + lfc1-umsav +
                 lfc1-um01s - lfc1-um01h + lfc1-um02s - lfc1-um02h +
                 lfc1-um03s - lfc1-um03h + lfc1-um04s - lfc1-um04h +
                 lfc1-um05s - lfc1-um05h + lfc1-um06s - lfc1-um06h +
                 lfc1-um07s - lfc1-um07h + lfc1-um08s - lfc1-um08h +
                 lfc1-um09s - lfc1-um09h + lfc1-um10s - lfc1-um10h.
               ENDIF.
             WHEN 9.
               open = knc1-umsav +
               knc1-um01s - knc1-um01h + knc1-um02s - knc1-um02h +
               knc1-um03s - knc1-um03h + knc1-um04s - knc1-um04h +
               knc1-um05s - knc1-um05h + knc1-um06s - knc1-um06h +
               knc1-um07s - knc1-um07h + knc1-um08s - knc1-um08h +
               knc1-um09s - knc1-um09h .
               IF NOT ( lfc1 IS INITIAL ) .
                 open = open + lfc1-umsav +
                 lfc1-um01s - lfc1-um01h + lfc1-um02s - lfc1-um02h +
                 lfc1-um03s - lfc1-um03h + lfc1-um04s - lfc1-um04h +
                 lfc1-um05s - lfc1-um05h + lfc1-um06s - lfc1-um06h +
                 lfc1-um07s - lfc1-um07h + lfc1-um08s - lfc1-um08h +
                 lfc1-um09s - lfc1-um09h.
               ENDIF.
             WHEN 8.
               open = knc1-umsav +
               knc1-um01s - knc1-um01h + knc1-um02s - knc1-um02h +
               knc1-um03s - knc1-um03h + knc1-um04s - knc1-um04h +
               knc1-um05s - knc1-um05h + knc1-um06s - knc1-um06h +
               knc1-um07s - knc1-um07h + knc1-um08s - knc1-um08h.
               IF NOT ( lfc1 IS INITIAL ) .
                 open = open + lfc1-umsav +
                 lfc1-um01s - lfc1-um01h + lfc1-um02s - lfc1-um02h +
                 lfc1-um03s - lfc1-um03h + lfc1-um04s - lfc1-um04h +
                 lfc1-um05s - lfc1-um05h + lfc1-um06s - lfc1-um06h +
                 lfc1-um07s - lfc1-um07h + lfc1-um08s - lfc1-um08h .
               ENDIF.
             WHEN 7.
               open = knc1-umsav +
               knc1-um01s - knc1-um01h + knc1-um02s - knc1-um02h +
               knc1-um03s - knc1-um03h + knc1-um04s - knc1-um04h +
               knc1-um05s - knc1-um05h + knc1-um06s - knc1-um06h +
               knc1-um07s - knc1-um07h .
               IF NOT ( lfc1 IS INITIAL ) .
                 open = open + lfc1-umsav +
                 lfc1-um01s - lfc1-um01h + lfc1-um02s - lfc1-um02h +
                 lfc1-um03s - lfc1-um03h + lfc1-um04s - lfc1-um04h +
                 lfc1-um05s - lfc1-um

Maybe you are looking for