Summation in internal tables

Hi,
I have an internal table, that stores values on order and line level along with qty. e.g.
Doc No  Line   Sch.line       Qty
101     1       1             200
101     1       2             100
102     1       1             400
102     1       2              50
102     2       1              25
i want to store it as :
Doc no     Line          qty
101         1              300
102         1              450
102         2               25
i want to put these values in another internal table on a document no level. Can you give me the code or sample for it.
Thanks
Laura.
Message was edited by:  Laura. Change in requirement.
        laura s

HI,
This will work... i am sorting on docno and item ..
At end will work on a combination of document number and item in this case...  you check it out
i have check it out with the program..
REPORT ztestprg.
DATA : BEGIN OF itab OCCURS 0,
      id(3) type c,
       cust(10) TYPE c,
       item(10) TYPE c,
       volume  TYPE i,
       percent TYPE p DECIMALS 2,
       END OF itab.
DATA : BEGIN OF jtab OCCURS 0,
      id(3) type c,
       cust(10) TYPE c,
       item(10) TYPE c,
       volume  TYPE i,
       percent TYPE p DECIMALS 2,
       END OF jtab.
*itab-id = 'U01'.
itab-cust = 1000.
itab-item = 1.
itab-volume = 200.
APPEND itab.
*itab-id = 'U01'.
itab-cust = 1000.
itab-item = 1..
itab-volume = 200.
APPEND itab.
*itab-id = 'U02'.
itab-cust = 1000.
itab-item = 2.
itab-volume = 200.
APPEND itab.
*itab-id = 'U02'.
itab-cust = 1000.
itab-item = 2.
itab-volume = 200.
APPEND itab.
*itab-id = 'U03'.
itab-cust = 2000.
itab-item = 2.
itab-volume = 200.
APPEND itab.
START-OF-SELECTION.
  SORT itab BY cust item.
  LOOP AT itab.
    AT END OF item.
      SUM.
      WRITE :/ itab-cust,itab-item,itab-volume.
    ENDAT.
  ENDLOOP.
Thanks
mahesh

Similar Messages

  • Summation of internal tables

    Hi,
      I need to sum these two internal tables and collect it.
    Suggest some ideas.
      LOOP AT IT_STK_COL.
        WRITE : / IT_STK_COL-MATNR,
                  IT_STK_COL-WERKS,
                  IT_STK_COL-LGORT,
                  IT_STK_COL-MENGE,
                  IT_STK_COL-MEINS.
      ENDLOOP.
    Result of first internal table
          BBB           LAB     TF             345.832  MT
             BBB           MAN    MAN             7.290  MT
             BBB           LAB     OK       73,129.679  MT
      LOOP AT IT_COL.
        WRITE : / IT_COL-MATNR,
                  IT_COL-WERKS,
                  IT_COL-LGORT,
                  IT_COL-MENGE,
                  IT_COL-MEINS.
      ENDLOOP.
    Result of second internal table
    BBB            LAB  TF             56.274  MT
    BBB           COC  COC         3,027.782  MT

    as per my understaing you want singlr result like
    BBB           LAB     TF             402.106  MT
    BBB           MAN    MAN             7.290  MT
    BBB           LAB     OK        73,129.679  MT
    BBB           COC    COC         3,027.782  MT
    so
    this will work fine
    loop at IT_STK_COL into wa_STK_COL .
    collect wa_STK_COL  into IT_COL.
    endloop.
    Edited by: Alpesh on Jun 9, 2009 6:16 PM

  • Adding a column in an internal table

    Hi,
    I want to know how to add different rows of a  column in an internal table.
    My code :
    Declaration Part-----
    types : begin of imchb,
            clabs like mchb-clabs,
            cumlm like mchb-cumlm,
            cinsm like mchb-cinsm,
            tot_val_stock type p decimals 3,
            pm_percent type p decimals 6,
            end of imchb.
    data : int_inv type standard table of imchb with header line,
           wa_inv like line of int_inv.
    Then I do few calculations and display it in the column pm_percent.
    Now I want to sum this column.
    Summation---
    loop
    at int_inv into wa_inv.
    at end of pm_percent.
    sum.
    endat.
    endloop.
    write :/ wa_inv-pm_percent.
    However , wa_inv-pm_percent only gives me the value of the last row of the column.
    Kindly suggest .

    Hi,
    Please try this code:
    loop at int_inv into wa_inv.
        lv_count = lv_count + 1.
        AT END OF posnr.   <------- The field you want to sum..
          gs_total-posnr      = wa_inv-posnr.
          gs_total-cov_total  = lv_count.
          APPEND gs_total TO gt_total.
          CLEAR : gs_total,
                  lv_count,
                  wa_inv.
        ENDAT.
      ENDLOOP.

  • Summarizing records in a internal table

    hi
    what is meant by summarizing records in an internal table
    vamsi

    HI
    please go through this:
    u will get some idea.
    Appending Summarized Lines
    The following statement allows you to summate entries in an internal table:
    COLLECT <wa> INTO <itab>.
    <itab> must have a flat line type, and all of the fields that are not part of the table key must have
    a numeric type (F, I, or P). You specify the line that you want to add in a work area that is
    compatible with the line type.
    When the line is inserted, the system checks whether there is already a table entry that matches
    the key. If there is no corresponding entry already in the table, the COLLECT statement has the
    same effect as inserting the new line [Page 282]. If an entry with the same key already exists, the
    COLLECT statement does not append a new line, but adds the contents of the numeric fields in
    the work area to the contents of the numeric fields in the existing entry.
    You should only use the COLLECT statement if you want to create summarized tables. If you
    use other statements to insert table entries, you may end up with duplicate entries.
    Lines are added to internal tables as follows:
      Standard tables
    If the COLLECT statement is the first statement to fill the standard table, the system
    creates a temporary hash administration that identifies existing entries in the table. The
    hash administration is retained until another statement changes the contents of key fields
    or changes the sequence of the lines in the internal table. After this, the system finds
    existing entries using a linear search. The runtime for this operation increases in linear
    relation to the number of existing table entries. The system field SY-TABIX contains the
    index of the line inserted or modified in the COLLECT statement.
      Sorted tables
    The system uses a binary search to locate existing lines. The runtime for the operation
    increases logarithmically with the number of existing lines. The system field SY-TABIX
    contains the index of the line inserted or modified in the COLLECT statement.
      Hashed tables
    The system finds existing lines using the hash algorithm of the internal table. After the
    COLLECT statement, the system field SY-TABIX has the value 0, since hashed tables
    have no linear index.
    Example
    DATA: BEGIN OF LINE,
    COL1(3) TYPE C,
    COL2(2) TYPE N,
    COL3 TYPE I,
    END OF LINE.
    DATA ITAB LIKE SORTED TABLE OF LINE
    WITH NON-UNIQUE KEY COL1 COL2.
    BC - ABAP Programming SAP AG
    Appending Summarized Lines
    286 April 2001
    LINE-COL1 = 'abc'. LINE-COL2 = '12'. LINE-COL3 = 3.
    COLLECT LINE INTO ITAB.
    WRITE / SY-TABIX.
    LINE-COL1 = 'def'. LINE-COL2 = '34'. LINE-COL3 = 5.
    COLLECT LINE INTO ITAB.
    WRITE / SY-TABIX.
    LINE-COL1 = 'abc'. LINE-COL2 = '12'. LINE-COL3 = 7.
    COLLECT LINE INTO ITAB.
    WRITE / SY-TABIX.
    LOOP AT ITAB INTO LINE.
    WRITE: / LINE-COL1, LINE-COL2, LINE-COL3.
    ENDLOOP.
    Thanks
    Shiva

  • Summarizing entries of the Internal table

    Hi All Experts!!
    I have problem regarding summarizing of the entries of the internal table.I want the amount field of the entries be summed based on 3  fields of table rkst skst rkstar.It means that summation be carried out if the set of these 3  fields are same.If there is different set new entry will be created.
    Here I want to summarize itab gt_yrepost2.
      LOOP AT gt_yrepost2 INTO gwa_yrepost2.
        sum_amount = sum_amount + gwa_yrepost2-amount
    be summed for repeating sets of 3 fields*****
          lwa_sum_yrepost2-amount = sum_amount.
          lwa_sum_yrepost2-kokrs = gwa_yrepost2-kokrs.
          lwa_sum_yrepost2-belnr = gwa_yrepost2-belnr.
          lwa_sum_yrepost2-buzei = gwa_yrepost2-buzei.
          lwa_sum_yrepost2-kstar = gwa_yrepost2-kstar.
          lwa_sum_yrepost2-bukrs = gwa_yrepost2-bukrs.
          lwa_sum_yrepost2-pbukrs = gwa_yrepost2-pbukrs.
          lwa_sum_yrepost2-tcurr = gwa_yrepost2-tcurr.
          lwa_sum_yrepost2-skst = gwa_yrepost2-skst."field1
          lwa_sum_yrepost2-rkst = gwa_yrepost2-rkst."field2
          lwa_sum_yrepost2-rkstar = gwa_yrepost2-rkstar."field3
          lwa_sum_yrepost2-txt = gwa_yrepost2-txt.
          APPEND lwa_sum_yrepost2 TO gt_sum_yrepost2.
    It means that if there is change in set of key fields new entry will be created. Else the entries will be summed to a single entry.In this example gt_sum_yrepost2 contained the summed(summarized) entries.
    The positive thing here is that if for one set of these fields the other values will be same.Hence other fields will take value of any of the repeating entries(with repeated set).
    Please help in this regards..
    Thanks in Advance....
    Prabhas.
    Edited by: PRABHAS jha on Jan 25, 2008 4:34 PM

    Hi Prabhas ,
    You could use Collect statement instead of Append.
    Thanks
    Rekha

  • Update & Insert into Internal table

    Dear Abapers,
    Is it possible to update a entry in the internal table if exists, otherwise inserts a new one.
    I think MODIFY <Internal Table> will not insert new one if the matching entry is not there.
    MODIFY <database_table> have this facility.
    Thanks in advance,
    Satish

    Hi,
    i dont know what type of fields u r having but about collect statement i am correct
    The following special statement allows you to summate entries in an internal table:
    COLLECT wa INTO itab.
    itab must have a flat line type, and all of the fields that are not part of the table key must have a numeric type (f, i, p). You specify the line wathat you want to add as a work area that is compatible with the line type of itab.
    When the line is inserted, the system checks whether there is already a table entry that matches the key. If there is no corresponding entry already in the table, the COLLECT statement has the same effect as inserting the new line. If an entry with the same key already exists, the COLLECT statement does not append a new line, but adds the contents of the numeric fields in the work area to the contents of the numeric fields in the existing entry.
    REPORT demo_int_tables_COLLECT .
    DATA: BEGIN OF line,
    col1(3) TYPE c,
    col2(2) TYPE n,
    col3 TYPE i,
    END OF line.
    DATA itab LIKE SORTED TABLE OF line
    WITH NON-UNIQUE KEY col1 col2.
    line-col1 = 'abc'. line-col2 = '12'. line-col3 = 3.
    COLLECT line INTO itab.
    WRITE / sy-tabix.
    line-col1 = 'def'. line-col2 = '34'. line-col3 = 5.
    COLLECT line INTO itab.
    WRITE / sy-tabix.
    line-col1 = 'abc'. line-col2 = '12'. line-col3 = 7.
    COLLECT line INTO itab.
    WRITE / sy-tabix.
    LOOP AT itab INTO line.
    WRITE: / line-col1, line-col2, line-col3.
    ENDLOOP.
    The list output is:
    1
    2
    1
    abc 12 10
    def 34 5
    The example fills a sorted table. The first two COLLECT statements work like normal insertion statements. In the third COLLECTstatement, the first line of itab is modified.
    Regards

  • Issue In internal table data population in the o/p

    Dear Guru , I have encountered an issue for which i am not able to findout the logic  . I have an internal table through which i am populating the below data for detail report format :->
    Plant     Material Number          Storage Loc     Movement Type          Avg Days
    019     0820B0073          MOD3          101               space
    019     0820B0073          MOD3          101               space
    019     0820B0073          MOD3          101               space
    019     0820B0073          MOD3          101               space
    019     0820B0073          MOD3          101               space
    020     0820B0074          MOD4          101               space
    020     0820B0074          MOD4          101               2
    020     0820B0074          MOD4          101               3
    The requirment is like this the summary report should show o/p like below addition of all the rows with respect to plant , material, storage location and movement type :-
    Plant     Material Number          Storage Loc     Movement Type          Avg Days
    019     0820B0073          MOD3          101               space
    020     0820B0074          MOD4          101               5
    but when i am adding it with respect to plant, material, storage location and movement type the o/p i am getting is like below
    Plant     Material Number          Storage Loc     Movement Type          Avg Days
    019     0820B0073          MOD3          101               0
    020     0820B0074          MOD4          101               5
    becasue addition of 5 spaces ( Avg Days )of plant 019 is coming as ZERO --> 0
    so Guru what logic i should use to get the proper o/p,..I have Used Following logic to perform summation with respect to plant, material , storage loc and movement type.
    CLEAR: wa_mkpf_mseg, w_werks, w_matnr, w_lgort, w_bwart.
    LOOP AT t_mkpf_mseg INTO wa_mkpf_mseg.   
    IF wa_mkpf_mseg-werks EQ w_werks AND wa_mkpf_mseg-matnr EQ w_matnr AND wa_mkpf_mseg-lgort EQ w_lgort AND wa_mkpf_mseg-bwart EQ w_bwart.
          CLEAR: wa_p_coi.
          READ TABLE t_p_coi INTO wa_p_coi WITH KEY werks = wa_mkpf_mseg-werks matnr = wa_mkpf_mseg-matnr lgort = wa_mkpf_mseg-lgort bwart = wa_mkpf_mseg-bwart.
         IF sy-subrc = 0.
         wa_p_coi-Avg Days    = wa_p_coi-Avg Days   + wa_mkpf_mseg-Avg Days.
         MODIFY t_p_coi FROM wa_p_coi TRANSPORTING Avg Days   .
         CLEAR: wa_p_coi, wa_p_coi.
         endif.
    ELSE.
          wa_p_coi-werks                     = wa_mkpf_mseg-werks.
          wa_p_coi-matnr                     = wa_mkpf_mseg-matnr.
          wa_p_coi-bwart                   = wa_mkpf_mseg-bwart.
          wa_p_coi-lgort                     = wa_mkpf_mseg-lgort.
          wa_p_coi-Avg Days                  = wa_mkpf_mseg-Avg Days   .
         APPEND wa_p_coi TO t_p_coi.
               CLEAR: wa_p_coi.
    ENDIF.
        w_werks = wa_mkpf_mseg-werks.
        w_matnr = wa_mkpf_mseg-matnr.
        w_lgort = wa_mkpf_mseg-lgort.
        w_bwart = wa_mkpf_mseg-bwart.
       CLEAR: wa_mkpf_mseg.
      ENDLOOP.

    The soln what i found after working out
    CLEAR: wa_mkpf_mseg, w_werks, w_matnr, w_lgort, w_bwart.
    LOOP AT t_mkpf_mseg INTO wa_mkpf_mseg.
    IF wa_mkpf_mseg-werks EQ w_werks AND wa_mkpf_mseg-matnr EQ w_matnr AND wa_mkpf_mseg-lgort EQ w_lgort AND wa_mkpf_mseg-bwart EQ w_bwart.
    CLEAR: wa_p_coi.
    READ TABLE t_p_coi INTO wa_p_coi WITH KEY werks = wa_mkpf_mseg-werks matnr = wa_mkpf_mseg-matnr lgort = wa_mkpf_mseg-lgort bwart = wa_mkpf_mseg-bwart.
    IF sy-subrc = 0.
    if wa_p_coi-Avg Days  = ' ' and wa_mkpf_mseg-Avg Days = ' '.
    wa_p_coi-Avg Days = ' '.
    ELSE
    wa_p_coi-Avg Days = wa_p_coi-Avg Days + wa_mkpf_mseg-Avg Days.
    Endif.
    MODIFY t_p_coi FROM wa_p_coi TRANSPORTING Avg Days .
    CLEAR: wa_p_coi, wa_p_coi.
    endif.
    ELSE.
    wa_p_coi-werks = wa_mkpf_mseg-werks.
    wa_p_coi-matnr = wa_mkpf_mseg-matnr.
    wa_p_coi-bwart = wa_mkpf_mseg-bwart.
    wa_p_coi-lgort = wa_mkpf_mseg-lgort.
    wa_p_coi-Avg Days = wa_mkpf_mseg-Avg Days .
    APPEND wa_p_coi TO t_p_coi.
    CLEAR: wa_p_coi.
    ENDIF.
    w_werks = wa_mkpf_mseg-werks.
    w_matnr = wa_mkpf_mseg-matnr.
    w_lgort = wa_mkpf_mseg-lgort.
    w_bwart = wa_mkpf_mseg-bwart.
    CLEAR: wa_mkpf_mseg.
    ENDLOOP.

  • Division of internal table records

    Dear all
    How can I observe that how many record my internal table got record and how can I divide into by lines
    for ex.
              SELECT SINGLE pvprs FROM ckmlcr INTO sum_pvprs-pvprs
                WHERE poper EQ s_poper AND
                   kalnr = itab2-kalnr AND
                   bdatj = itab2-bdatj AND
                   curtp = itab2-curtp.
              IF sy-subrc = 0.
                APPEND sum_pvprs.
    I want to get arithmetic range of this sum_pvprs-pvprs
    Actually I want to get number of lines and their summations
    pvprs1= 10 pvprs=20 pvprs=30 and then
    after I got this results 102030 = 60 /3 =20 I need this operation.
    All the best
    Message was edited by: yusuf tunay çilesiz

    I am not sure what do you mean by arithmetic range...if you mean min and max numbers you can use the below logic.
    SELECT SINGLE pvprs FROM ckmlcr INTO sum_pvprs-pvprs
    WHERE poper EQ s_poper AND
    kalnr = itab2-kalnr AND
    bdatj = itab2-bdatj AND
    curtp = itab2-curtp.
    IF sy-subrc = 0.
    APPEND sum_pvprs.
    1. you can simply sort the sum_pvprs internal table...on pvprs first ascending and than descending to get the min and max numbers by reading the first record of the internal table.
    REad table sum_pvprs index 1.
    2. you can have two variables lmin and lmax and initialise the same before you append statement.
    if sum_pvprs-pvprs > lmax.
      lmax  = sum_pvprs-pvprs.
    endif.
    if sum_pvprs-pvprs < lmin.
      lmin  = sum_pvprs-pvprs.
    endif.
    <u><b>Sum and Average.</b></u>
    SELECT SINGLE pvprs FROM ckmlcr INTO sum_pvprs-pvprs
    WHERE poper EQ s_poper AND
    kalnr = itab2-kalnr AND
    bdatj = itab2-bdatj AND
    curtp = itab2-curtp.
    IF sy-subrc = 0.
    <b>l_sum = sum_pvprs-pvprs + l_sum.</b>
    APPEND sum_pvprs.
    ENDSELECT.
    <b>DESCRIBE TABLE sum_pvprs LINES lrec.
    lavg = l_sum / lrec.</b>
    Message was edited by: Anurag Bankley

  • Logic in updating a internal table...

    Hello,
    I have a internal table having values as follows:
    I_TAB[]:
    Doc-num..........Item-num.........amount........Doc-type
    456..............01................4.26.................................
    456..............02...............345.89..............................
    456..............03..............-45.39................................
    763...........and so on
    After I loop at I_TAB[] is the sum of total amount > 0, the value in doc-type should get updated with 'PX' and if negative the, Doc-type should get updated with 'NX' for all the three records in internal table for whose amount were used in calculating net amount.
    How can I achieve this ?
    Regards,
    Rajesh.

    Hello,
    When you populate the internal table, also populate another internal table with fields document number and amount. Use collect statement to populate the new internal table. i.e by using collect statement you will have only 1 record for the document number and the amount will have summation of all the line items for that document number.
    When you loop at itab, just read the new internal table based on the document number. That way you will know whether the total amount is greater than 0 or negative.
    Based on this you can update the document type.
    Hope this helps.
    Thanks,
    Sushil Joshi

  • Sum on a internal table

    Hi All,
    I have internal table like this.
    Field1      Field2       Field3
    a                 1                   5.000
    b                 1                   5.000
    b                 1                   3.000
    b                 1                   10.000
    b                 1                   10.000
    b                 2                   15.000
    c               1                   10.000
    c               2                   10.000
    Now i have to sum field3 based on field1 and field2 i.e My Output will be like this.
    Field1        Field2               Field3
    a                   1                   5.000
    b                   1                   28.000
    b                   2                   15.000
    c                   1                   10.000
    c                   2                   10.000.
    Please suggest some solution as I guess this output is not possible thru At end of or at new.
    We can get the desired output using on change of but the summation is not possible thru on change of.
    Thanks and regards
    Nazmul Azad

    Hi,
    Please refer the below program:
    data : var(20) type c,
    var1(20) type c,
    var2(20) type c.
    data : begin of itab occurs 0,
    f1 type c,
    f2 type i,
    f3 type i,
    end of itab.
    itab-f1 = 'a'.
    itab-f2 = '1'.
    itab-f3 = '5'.
    append itab.
    clear itab.
    itab-f1 = 'b'.
    itab-f2 = '1'.
    itab-f3 = '5'.
    append itab.
    clear itab.
    itab-f1 = 'b'.
    itab-f2 = '1'.
    itab-f3 = '3'.
    append itab.
    clear itab.
    itab-f1 = 'b'.
    itab-f2 = '1'.
    itab-f3 = '10'.
    append itab.
    clear itab.
    itab-f1 = 'b'.
    itab-f2 = '2'.
    itab-f3 = '15'.
    append itab.
    clear itab.
    itab-f1 = 'c'.
    itab-f2 = '1'.
    itab-f3 = '10'.
    append itab.
    clear itab.
    itab-f1 = 'c'.
    itab-f2 = '2'.
    itab-f3 = '10'.
    append itab.
    clear itab.
    //Sorted based on field1 and field2 and used At new
      sort itab by f1 f2.
    loop at itab.
    at new f2.
       sum.
    endat.
    endloop.
    Best Regards,
    Sumana

  • How to select and sum  internal table records

    Dear Friends
    I kindly ask you if we have select statement
       if s_mtart = 'z003'
          select single pvprs from ckmlcr into ckmlcr-pvprs
    where poper EQ s_poper and
          kalnr = itab2-kalnr  and
          bdatj = itab2-bdatj and
          curtp = itab2-curtp.
    like this how can I calculate how many record it got and I want to get summation of this field(pvprs).And for all poper's must contain.
      Please  Let me remind you my itab is already open I didn't put any thing for this situation

    it seems to be you written this SELECT in a loop. if so,
    instead of pushing the values into ckmlcr-pvprs ,create an internal table
    data : begin of itab,
         pvprs  type ckmlcr-pvprs ,
        end of itab.
    then just after that SELECT SINGLE,
    select single pvprs from ckmlcr <b>into ITAB-pvprs</b>
    where poper EQ s_poper and
    kalnr = itab2-kalnr and
    bdatj = itab2-bdatj and
    curtp = itab2-curtp.
    IF SY-SUBRC = 0.
      APPEND ITAB.
    here either you can use APPEND OR COLLECT.
    If you use COLLECT,all the values will get summed up and final sum will be in the table ITAB-pvprs.
    ENDIF.
    After all loops your itab will have the totals.
    DESCRIBE TABLE ITAB LINES V_LINES.
    V_LINES Will have total no of lines.
    Regards
    srikanth

  • ALV reprot With four internal tables

    Hi all,
    Could any one please tell what is function module we have to use for displaying four internal tables in a single ALV REPORT.
    Thanks & regards
    Vardhan

    This is the code for displaying ALV using containers.. u need to create 4 containers in one screen and need to display data...
    I would suggest you to get all the data into one internal table and display.. for more clarity u can give diff colors for diff table data using field catalog..
                                        *& Report  ZTRPSD110                                                   *
                                        * TITLE: Statement of Export Report for Tata Tetley                    *
                                        * PURPOSE:Statement of Export Report for Tata Tetley                   *
                                        * A. Start-of-selection:                                               *
                                        * 1. In get_billing_data using the selection screen parameters get the *
                                        *     billing data from billing header(VBAK) and Item (VBAP)           *
                                        * 2.  Get the SHIP-TO partner data from VBPA using Customer number as  *
                                        *     one condition and store in it_vbpa_sh
                                        * 9.  Popultae the ALV display table
                                        * B. End-of-selection:
                                        *    Call screen 9000 and display data in ALV
                                        REPORT  ztrps110  MESSAGE-ID zttl  LINE-SIZE 130.
                                                                                    TABLES: vbrk.
                                                                                    * CONSTANTS
                                        CONSTANTS :
                                        c_x(1)        TYPE c VALUE 'X',
                                        c_zxto        TYPE vbak-auart VALUE 'ZXTO',
                                        c_e           TYPE spras VALUE 'E',
                                        c_000000      TYPE posnr VALUE '000000',
                                        c_ship_to     TYPE parvw VALUE 'WE'.      "Ship To Party
                                                                                    * Table Types
                                        TYPES: BEGIN OF ty_vbrk_vbrp,
                                        vbeln TYPE vbrk-vbeln,    "Billing doc
                                        posnr TYPE vbrp-posnr,    "Billing item
                                        aubel TYPE vbrp-aubel,    "Sales order
                                        waerk TYPE vbrk-waerk,    "Doc currency
                                        mvgr1 TYPE vbrp-mvgr1,    "Material group 1
                                        mvgr3 TYPE vbrp-mvgr3,    "Material group 3
                                        mvgr4 TYPE vbrp-mvgr4,    "Material group 4
                                        matnr TYPE vbrp-matnr,    "Material no
                                        ntgew TYPE vbrp-ntgew,    "Net wt
                                        gewei TYPE vbrp-gewei,    "Wt unit
                                        kzwi1 TYPE vbrp-kzwi1,                             "Subtotal 1
                                        kursk TYPE vbrp-kursk,    "Exchange rate
                                        END   OF ty_vbrk_vbrp.
                                                                                    TYPES: BEGIN OF ty_data,
                                        land1 TYPE vbpa-land1,
                                        landx TYPE t005t-landx,
                                        mvgr3 TYPE vbrp-mvgr3,
                                        mvgr4 TYPE vbrp-mvgr4,
                                        bezei3 TYPE tvm3t-bezei,
                                        bezei4 TYPE tvm4t-bezei,
                                        ntgew_tea_bag TYPE vbrp-ntgew,
                                        ntgew_pkt_tea TYPE vbrp-ntgew,
                                        ntgew_bulk_tea TYPE vbrp-ntgew,
                                        kzwi1_tea_bag TYPE vbrp-kzwi1,    "Subtotal 1 Tea Bag
                                        kzwi1_pkt_tea TYPE vbrp-kzwi1,    "Subtotal 1 Pkt Tea
                                        kzwi1_bulk_tea TYPE vbrp-kzwi1,   "Subtotal 1 Bulk Tea
                                        ntgew_tot TYPE vbrp-ntgew,
                                        kzwi1_tot TYPE vbrp-kzwi1,
                                        line_color(4) TYPE c,  "For line color
                                        END OF ty_data.
                                        TYPES: BEGIN OF ty_vbpa,
                                        vbeln TYPE vbpa-vbeln,
                                        land1 TYPE vbpa-land1,
                                        END OF ty_vbpa.
                                        TYPES: BEGIN OF ty_t005t,
                                        land1 TYPE t005t-land1,
                                        landx TYPE t005t-landx,
                                        END OF ty_t005t.
                                        TYPES: BEGIN OF ty_tvm3t,
                                        mvgr3 TYPE tvm3-mvgr3,
                                        bezei TYPE tvm3t-bezei,
                                        END OF ty_tvm3t.
                                        TYPES: BEGIN OF ty_tvm4t,
                                        mvgr4 TYPE tvm4-mvgr4,
                                        bezei TYPE tvm4t-bezei,
                                        END OF ty_tvm4t.
                                                                                    DATA: it_vbrk_vbrp TYPE STANDARD TABLE OF ty_vbrk_vbrp,
                                        wa_vbrk_vbrp TYPE ty_vbrk_vbrp,
                                        it_vbpa TYPE STANDARD TABLE OF ty_vbpa,
                                        wa_vbpa TYPE ty_vbpa,
                                        it_data TYPE STANDARD TABLE OF ty_data,
                                        wa_data TYPE ty_data,
                                        it_t005t TYPE STANDARD TABLE OF ty_t005t,
                                        wa_t005t TYPE ty_t005t,
                                        it_tvm3t TYPE STANDARD TABLE OF ty_tvm3t,
                                        wa_tvm3t TYPE ty_tvm3t,
                                        it_tvm4t TYPE STANDARD TABLE OF ty_tvm4t,
                                        wa_tvm4t TYPE ty_tvm4t.
                                                                                    * Global data for grand total
                                        DATA:
                                        w_tot_ntgew_tea_bag TYPE vbrp-ntgew,
                                        w_tot_ntgew_pkt_tea TYPE vbrp-ntgew,
                                        w_tot_ntgew_bulk_tea TYPE vbrp-ntgew,
                                        w_tot_ntgew_tot TYPE vbrp-ntgew,
                                        w_tot_kzwi1_tea_bag TYPE vbrp-kzwi1,
                                        w_tot_kzwi1_pkt_tea TYPE vbrp-kzwi1,
                                        w_tot_kzwi1_bulk_tea TYPE vbrp-kzwi1,
                                        w_tot_kzwi1_tot TYPE vbrp-kzwi1.
                                                                                    * Global data definitions for ALV
                                        DATA :
                                        * ALV Grid container
                                        w_alv_container TYPE REF TO cl_gui_custom_container,
                                        * ALV Grid
                                        w_alv_grid      TYPE REF TO cl_gui_alv_grid,
                                        w_layo          TYPE        lvc_s_layo,     "For layout
                                        wt_fieldcat     TYPE        lvc_t_fcat,     "For field catalog
                                        okcode          TYPE         okcode,        "OK Code
                                        w_to(2)         TYPE         c,
                                        w_title         TYPE        string.
                                        *-------------- START OF SELECTION SCREEN ----------------------------*
                                        SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
                                        * Billing Date
                                        SELECT-OPTIONS: s_fkdat FOR vbrk-fkdat MEMORY ID vf OBLIGATORY NO-EXTENSION.
                                        SELECTION-SCREEN:SKIP 1.
                                        SELECTION-SCREEN: END OF BLOCK b1.
                                        *-------------- END OF SELECTION SCREEN ------------------------------*
                                                                                    *-------------   EVENT START-OF-SELECTION  -------------------------------*
                                        START-OF-SELECTION.
                                                                                    * Get billing data from Delivery header(VBRK) and item (VBRP)
                                        PERFORM get_billing_data.
                                        * Get ship-to country
                                        PERFORM get_ship_to_data.
                                        * Get material group description 3
                                        PERFORM get_material_group_3.
                                        * Get material group description 4
                                        PERFORM get_material_group_4.
                                        * Form the ALV Grid title
                                        PERFORM form_title.
                                        * Process data
                                        PERFORM process_data.
                                        * Populate text descriptions
                                        PERFORM populate_description.
                                                                                    *-------------   EVENT END-OF-SELECTION  -------------------------------*
                                        END-OF-SELECTION.
                                        * Set the text to when date high is there
                                        IF NOT s_fkdat-high IS INITIAL.
                                        w_to = 'to'(c16).
                                        ENDIF.
                                        * Call the scren 9000 for ALV Display
                                        CALL SCREEN 9000.
                                        *&      Form  get_billing_data
                                        * Get billing data from Delivery header(VBRK) and item (VBRP)
                                        * & store in internal table it_vbrk_vbrp
                                        FORM get_billing_data .
                                        REFRESH: it_vbrk_vbrp.
                                                                                    * Select Billing data by joining VBRK & VBRP and store in it_vbrk_vbrp
                                        SELECT a~vbeln
                                        b~posnr
                                        b~aubel
                                        a~waerk
                                        b~mvgr1
                                        b~mvgr3
                                        b~mvgr4
                                        b~matnr
                                        b~ntgew
                                        b~gewei
                                        b~kzwi1
                                        b~kursk
                                        FROM vbrk AS a INNER JOIN vbrp AS b
                                        ON a~vbeln = b~vbeln
                                        INTO TABLE it_vbrk_vbrp
                                        WHERE a~fkdat IN s_fkdat
                                        * Consider only non-deleted document
                                        AND fksto = space
                                        * Billing doc type should be ZXTB
                                        AND fkart = 'ZXTB'
                                        AND pstyv = c_zxto.
                                        IF sy-subrc <> 0.
                                        MESSAGE i999(zttl) WITH 'No data is there'(m06).
                                        LEAVE LIST-PROCESSING.
                                        ENDIF.
                                        ENDFORM.                    " get_billing_data
                                        *&      Form  get_ship_to_data
                                        * Get Ship-To party data
                                        FORM get_ship_to_data .
                                        DATA: l_it_vbpa TYPE STANDARD TABLE OF ty_vbpa.
                                        REFRESH: it_vbpa, it_t005t.
                                        IF NOT it_vbrk_vbrp[] IS INITIAL.
                                        SELECT vbeln
                                        land1
                                        FROM vbpa
                                        INTO TABLE it_vbpa
                                        FOR ALL ENTRIES IN it_vbrk_vbrp
                                        WHERE vbeln = it_vbrk_vbrp-aubel
                                        AND posnr = c_000000
                                        AND parvw = c_ship_to.
                                        IF sy-subrc <> 0.
                                        MESSAGE i999(zttl) WITH 'Exporter country not maintained'(m02).
                                        LEAVE LIST-PROCESSING.
                                        ELSE.
                                        SORT it_vbpa BY vbeln.
                                        * Create an unique and sorted driver table
                                        l_it_vbpa[] = it_vbpa[].
                                        SORT l_it_vbpa BY land1.
                                        DELETE ADJACENT DUPLICATES FROM l_it_vbpa COMPARING land1.
                                        IF NOT l_it_vbpa[] IS INITIAL.
                                        * Get the country description from T005t table
                                        SELECT land1
                                        landx
                                        FROM t005t
                                        INTO TABLE it_t005t
                                        FOR ALL ENTRIES IN l_it_vbpa
                                        WHERE spras = c_e
                                        AND  land1 = l_it_vbpa-land1.
                                        IF sy-subrc = 0.
                                        SORT it_t005t BY land1.
                                        ENDIF.
                                        ENDIF.
                                        ENDIF.
                                        ENDIF.
                                        ENDFORM.                    " get_ship_to_data
                                        *&      Form  get_material_group_3
                                        * Get material group 3
                                        FORM get_material_group_3 .
                                        DATA: l_it_vbrk_vbrp TYPE STANDARD TABLE OF ty_vbrk_vbrp.
                                        REFRESH: it_tvm3t.
                                        * Create an unique and sorted driver table
                                        l_it_vbrk_vbrp[] = it_vbrk_vbrp[].
                                        SORT l_it_vbrk_vbrp BY mvgr3.
                                        DELETE ADJACENT DUPLICATES FROM l_it_vbrk_vbrp COMPARING mvgr3.
                                        IF NOT l_it_vbrk_vbrp[] IS INITIAL.
                                        SELECT mvgr3
                                        bezei
                                        FROM tvm3t
                                        INTO TABLE it_tvm3t
                                        FOR ALL ENTRIES IN l_it_vbrk_vbrp
                                        WHERE mvgr3 = l_it_vbrk_vbrp-mvgr3.
                                        IF sy-subrc = 0.
                                        SORT it_tvm3t BY mvgr3.
                                        ENDIF.
                                        ENDIF.
                                        ENDFORM.                    " get_material_group_3
                                        *&      Form  get_material_group_4
                                        * Get material group 4
                                        FORM get_material_group_4 .
                                        DATA: l_it_vbrk_vbrp TYPE STANDARD TABLE OF ty_vbrk_vbrp.
                                        REFRESH: it_tvm4t.
                                        * Create an unique and sorted driver table
                                        l_it_vbrk_vbrp[] = it_vbrk_vbrp[].
                                        SORT l_it_vbrk_vbrp BY mvgr4.
                                        DELETE ADJACENT DUPLICATES FROM l_it_vbrk_vbrp COMPARING mvgr4.
                                        IF NOT l_it_vbrk_vbrp[] IS INITIAL.
                                        SELECT mvgr4
                                        bezei
                                        FROM tvm4t
                                        INTO TABLE it_tvm4t
                                             FOR ALL ENTRIES IN l_it_vbrk_vbrp
                                             WHERE mvgr4 = l_it_vbrk_vbrp-mvgr4.
                                             IF sy-subrc = 0.
                                               SORT it_tvm4t BY mvgr4.
                                             ENDIF.
                                           ENDIF.
                                        ENDFORM.                    " get_material_group_4
                                        *&      Form  process_data
                                        * Process the data and do summation and populate final display table
                                        FORM process_data .
                                                                                    LOOP AT it_vbrk_vbrp INTO wa_vbrk_vbrp.
                                             CLEAR: wa_data, wa_vbpa.
                                             READ TABLE it_vbpa INTO wa_vbpa WITH KEY
                                                                          vbeln = wa_vbrk_vbrp-aubel
                                                                          BINARY SEARCH.
                                             IF sy-subrc = 0.
                                               wa_data-land1 = wa_vbpa-land1.
                                             ENDIF.
                                                                                    wa_data-mvgr3 = wa_vbrk_vbrp-mvgr3.
                                             wa_data-mvgr4 = wa_vbrk_vbrp-mvgr4.
                                                                                    * Do an unit conversion of the quamtity
                                             CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'
                                               EXPORTING
                                                 input                      = wa_vbrk_vbrp-ntgew
                                        *      NO_TYPE_CHECK              = 'X'
                                        *      ROUND_SIGN                 = ' '
                                                unit_in                    = wa_vbrk_vbrp-gewei
                                                unit_out                   = 'TO' "Metric tonn
                                              IMPORTING
                                                output                     = wa_vbrk_vbrp-ntgew
                                              EXCEPTIONS
                                                conversion_not_found       = 1
                                                division_by_zero           = 2
                                                input_invalid              = 3
                                                output_invalid             = 4
                                                overflow                   = 5
                                                type_invalid               = 6
                                                units_missing              = 7
                                                unit_in_not_found          = 8
                                                unit_out_not_found         = 9
                                                OTHERS                     = 10.
                                             IF sy-subrc <> 0.
                                               wa_vbrk_vbrp-ntgew = wa_vbrk_vbrp-ntgew.
                                             ENDIF.
                                        * Convert the currency from Customer currency to local
                                        * currency by multiplying with kursk
                                             wa_vbrk_vbrp-kzwi1 =  wa_vbrk_vbrp-kzwi1 * wa_vbrk_vbrp-kursk.
                                        * Convert the amount to Lacks by dividing with 100000
                                            wa_vbrk_vbrp-kzwi1 = wa_vbrk_vbrp-kzwi1 / 100000.       "DV1K905028
                                        * When MVGR1 is between A to F use the amount as TEA_BAG
                                             IF wa_vbrk_vbrp-mvgr1 BETWEEN 'A' AND 'F'.
                                               wa_data-ntgew_tea_bag = wa_vbrk_vbrp-ntgew.
                                               wa_data-kzwi1_tea_bag = wa_vbrk_vbrp-kzwi1.
                                             ENDIF.
                                        * When MVGR1 is between G to L use the amount as TEA_BAG
                                             IF wa_vbrk_vbrp-mvgr1 BETWEEN 'G' AND 'L'.
                                               wa_data-ntgew_pkt_tea = wa_vbrk_vbrp-ntgew.
                                               wa_data-kzwi1_pkt_tea = wa_vbrk_vbrp-kzwi1.
                                             ENDIF.
                                        * When MVGR1 is between G to L use the amount as TEA_BAG
                                             IF wa_vbrk_vbrp-mvgr1 = 'M'.
                                               wa_data-ntgew_bulk_tea = wa_vbrk_vbrp-ntgew.
                                               wa_data-kzwi1_bulk_tea = wa_vbrk_vbrp-kzwi1.
                                             ENDIF.
                                                                                    COLLECT wa_data INTO it_data.
                                           ENDLOOP.
                                        ENDFORM.                    " process_data
                                        *&      Form  populate_description
                                        * Populate the description fields
                                        FORM populate_description .
                                           LOOP AT it_data INTO wa_data.
                                             CLEAR: wa_t005t.
                                             READ TABLE it_t005t INTO wa_t005t WITH KEY land1 = wa_data-land1
                                                                                    BINARY SEARCH.
                                             IF sy-subrc = 0.
                                               wa_data-landx = wa_t005t-landx.
                                             ENDIF.
                                        * Read description of Material group 3
                                             CLEAR wa_tvm3t.
                                             READ TABLE it_tvm3t INTO wa_tvm3t WITH KEY
                                                                      mvgr3 = wa_data-mvgr3
                                                                      BINARY SEARCH.
                                             IF sy-subrc = 0.
                                               wa_data-bezei3 = wa_tvm3t-bezei.
                                             ENDIF.
                                        * Read description of Material group 4
                                             CLEAR wa_tvm4t.
                                             READ TABLE it_tvm4t INTO wa_tvm4t WITH KEY
                                                                      mvgr4 = wa_data-mvgr4
                                                                      BINARY SEARCH.
                                             IF sy-subrc = 0.
                                               wa_data-bezei4 = wa_tvm4t-bezei.
                                             ENDIF.
                                        * Get the grand totals
                                             wa_data-ntgew_tot = wa_data-ntgew_tea_bag
                                                      + wa_data-ntgew_pkt_tea
                                                      + wa_data-ntgew_bulk_tea.
                                                                                    wa_data-kzwi1_tot = wa_data-kzwi1_tea_bag
                                                      + wa_data-kzwi1_pkt_tea
                                                      + wa_data-kzwi1_bulk_tea.
                                                                                    MODIFY it_data FROM wa_data TRANSPORTING landx
                                                                                    bezei3
                                                                                    bezei4
                                                                                    ntgew_tot
                                                                                    kzwi1_tot.
                                        * Summattion of grand totals
                                             w_tot_ntgew_tea_bag  = w_tot_ntgew_tea_bag  + wa_data-ntgew_tea_bag.
                                             w_tot_ntgew_pkt_tea  = w_tot_ntgew_pkt_tea  + wa_data-ntgew_pkt_tea.
                                             w_tot_ntgew_bulk_tea  = w_tot_ntgew_bulk_tea  + wa_data-ntgew_bulk_tea.
                                             w_tot_ntgew_tot  = w_tot_ntgew_tot  + wa_data-ntgew_tot.
                                                                                    w_tot_kzwi1_tea_bag  = w_tot_kzwi1_tea_bag  + wa_data-kzwi1_tea_bag.
                                             w_tot_kzwi1_pkt_tea  = w_tot_kzwi1_pkt_tea  + wa_data-kzwi1_pkt_tea.
                                             w_tot_kzwi1_bulk_tea  = w_tot_kzwi1_bulk_tea  + wa_data-kzwi1_bulk_tea.
                                             w_tot_kzwi1_tot  = w_tot_kzwi1_tot  + wa_data-kzwi1_tot.
                                                                                    ENDLOOP.
                                        * Append a grand Total row at the end
                                           CLEAR wa_data.
                                           wa_data-landx = 'Grand Total:'.
                                           wa_data-ntgew_tea_bag = w_tot_ntgew_tea_bag.
                                           wa_data-ntgew_pkt_tea = w_tot_ntgew_pkt_tea.
                                           wa_data-ntgew_bulk_tea = w_tot_ntgew_bulk_tea.
                                           wa_data-ntgew_tot = w_tot_ntgew_tot.
                                           wa_data-kzwi1_tea_bag = w_tot_kzwi1_tea_bag.
                                           wa_data-kzwi1_pkt_tea = w_tot_kzwi1_pkt_tea.
                                           wa_data-kzwi1_bulk_tea = w_tot_kzwi1_bulk_tea.
                                           wa_data-kzwi1_tot = w_tot_kzwi1_tot.
                                           wa_data-line_color    = 'C310'.
                                           APPEND wa_data TO it_data.
                                        ENDFORM.                    " populate_description
                                        *&      Module  STATUS_9000  OUTPUT
                                        * Initialise PF-STATUS and title
                                        MODULE status_9000 OUTPUT.
                                           SET PF-STATUS 'MAIN9000'.
                                           SET TITLEBAR 'TITLE_9000'.
                                        ENDMODULE.                 " STATUS_9000  OUTPUT
                                        *&      Module  initialize_9000  OUTPUT
                                        *       text
                                        MODULE initialize_9000 OUTPUT.
                                        * Call the ALV grid to display data
                                           PERFORM display_alv_grid.
                                        ENDMODULE.                 " initialize_9000  OUTPUT
                                        *&      Module  USER_COMMAND_9000  INPUT
                                        * Module to handle User Command
                                        MODULE user_command_9000 INPUT.
                                           CASE okcode.
                                             WHEN 'BACK'.
                                               SET SCREEN 0.
                                               CLEAR okcode.
                                               LEAVE SCREEN.
                                             WHEN 'CANCEL'.
                                               SET SCREEN 0.
                                               CLEAR okcode.
                                               LEAVE SCREEN.
                                             WHEN 'EXIT'.
                                               CLEAR okcode.
                                               LEAVE PROGRAM.
                                             WHEN OTHERS.
                                           ENDCASE.
                                        ENDMODULE.                 " USER_COMMAND_9000  INPUT
                                        *&      Form  display_alv_grid
                                        * Display the data in ALV Grid
                                        FORM display_alv_grid .
                                           IF w_alv_container IS INITIAL.
                                        * Create the alv container object
                                             CREATE OBJECT w_alv_container
                                               EXPORTING
                                                 container_name = 'ALV_GRID'
                                               EXCEPTIONS
                                                   cntl_error                  = 1
                                                   cntl_system_error           = 2
                                                   create_error                = 3
                                                   lifetime_error              = 4
                                                   lifetime_dynpro_dynpro_link = 5
                                                   OTHERS                      = 6.
                                             IF sy-subrc <> 0.
                                               MESSAGE e999(zttl) WITH 'Problem in ALV display'(t04).
                                             ENDIF.
                                        * Create the ALV grid object. The parent is the ALV container
                                             CREATE OBJECT w_alv_grid
                                               EXPORTING
                                                 i_parent = w_alv_container
                                               EXCEPTIONS
                                                 error_cntl_create = 1
                                                 error_cntl_init   = 2
                                                 error_cntl_link   = 3
                                                 error_dp_create   = 4
                                                 OTHERS            = 5.
                                                                                    IF sy-subrc <> 0.
                                               MESSAGE e999(zttl) WITH 'Problem in ALV display'(t04).
                                             ENDIF.
                                        * This subrotine creates the field catalog and
                                        * store in internal table lt_fieldcat
                                             PERFORM prepare_fieldcat CHANGING wt_fieldcat.
                                                                                    * Layout design
                                             w_layo-no_toolbar = ''.
                                        * Not to allow totaling feature
                                             w_layo-no_totline = c_x.
                                        * Report title
                                        *    w_layo-grid_title = text-004.
                                             w_layo-grid_title = w_title.
                                                                                    w_layo-zebra      = c_x.    "Alternating line color (striped)
                                             w_layo-cwidth_opt = c_x.    "Optimize column width
                                             w_layo-sel_mode   = 'A'.    "Selection Mode
                                        * Name of the color field
                                             w_layo-info_fname = 'LINE_COLOR'."For row color
                                        * Call the method to display the data in ALV grid
                                             CALL METHOD w_alv_grid->set_table_for_first_display
                                               EXPORTING
                                                 i_save                        = 'A'
                                                 is_layout                     = w_layo
                                               CHANGING
                                                 it_outtab                     = it_data[]
                                                 it_fieldcatalog               = wt_fieldcat
                                               EXCEPTIONS
                                                 invalid_parameter_combination = 1
                                                 program_error                 = 2
                                                 too_many_lines                = 3
                                                 OTHERS                        = 4.
                                                                                    IF sy-subrc <> 0.
                                               MESSAGE e999(zttl) WITH text-t04.
                                             ENDIF.
                                           ELSE.
                                        * If the container & grid object is alreadt there reuse them
                                             CALL METHOD w_alv_grid->refresh_table_display
                                               EXCEPTIONS
                                                 finished = 1
                                                 OTHERS   = 2.
                                             IF sy-subrc <> 0.
                                               MESSAGE e999(zttl) WITH text-t04.
                                             ENDIF.
                                           ENDIF.
                                           IF okcode = 'CANCEL'.
                                             EXIT.
                                           ENDIF.
                                        ENDFORM.                    " display_alv_grid
                                        *&      Form  prepare_fieldcat
                 

  • Sy-tabix for internal table in smartform

    Hi friends,
    How to capture the sy-tabix value for the entries in an internal table which has been looped into the loop of table node of a smartform?? I need to print something immedaitely after the end of the table
    For every record the value of sy-tabix is showing 1 !!
    Advance Thanks
    Aadarsh

    Hi Aadarsh,
    Give ur sy-tabix at the end of the loop.
    loop at itab.
    //table node populations.
    endloop.
    give a seperate loop for this.
    loop at itab.
    sy-tabix.
    endloop
    get the total no and print it after the table.
    If u r using do loop then give sy-index.
    Hope tihs helps u,
    Regards,
    Nagarajan.
    Message was edited by: Nagarajan Kumarappan

  • Regarding Exporting and Importing internal table

    Hello Experts,
    I have two programs:
    1) Main program: It create batch jobs through open_job,submit and close job.Giving sub program as SUBMIT.
    I am using Export IT to memory id 'MID' to export internal table data to sap memory in the subprogram.
    The data will be processed in the subprogram and exporting data to sap memory.I need this data in the main program(And using import to get the data,but it is not working).
    Importing IT1 from memory id 'MID' to import the table data in the main program after completing the job(SUBMIT SUBPROGRAM AND RETURN).
    Importing is not getting data to internal table.
    Can you please suggest something to solve this issue.
    Thank you.
    Regards,
    Anand.

    Hi,
    This is the code i am using.
    DO g_f_packets TIMES.
    * Start Immediately
           IF NOT p_imm IS INITIAL .
             g_flg_start = 'X'.
           ENDIF.
           g_f_jobname = 'KZDO_INHERIT'.
           g_f_jobno = g_f_jobno + '001'.
           CONCATENATE g_f_jobname g_f_strtdate g_f_jobno INTO g_f_jobname
                                                  SEPARATED BY '_'.
           CONDENSE g_f_jobname NO-GAPS.
           p_psize1 = p_psize1 + p_psize.
           p_psize2 = p_psize1 - p_psize + 1.
           IF p_psize2 IS INITIAL.
             p_psize2  = 1.
           ENDIF.
           g_f_spname = 'MID'.
           g_f_spid = g_f_spid + '001'.
           CONDENSE g_f_spid NO-GAPS.
           CONCATENATE g_f_spname  g_f_spid INTO g_f_spname.
           CONDENSE g_f_spname NO-GAPS.
    * ... (1) Job creating...
           CALL FUNCTION 'JOB_OPEN'
             EXPORTING
               jobname          = g_f_jobname
             IMPORTING
               jobcount         = g_f_jobcount
             EXCEPTIONS
               cant_create_job  = 1
               invalid_job_data = 2
               jobname_missing  = 3
               OTHERS           = 4.
           IF sy-subrc <> 0.
             MESSAGE e469(9j) WITH g_f_jobname.
           ENDIF.
    * (2)Report start under job name
           SUBMIT (g_c_prog_kzdo)
                  WITH p_lgreg EQ p_lgreg
                  WITH s_grvsy IN s_grvsy
                  WITH s_prvsy IN s_prvsy
                  WITH s_prdat IN s_prdat
                  WITH s_datab IN s_datab
                  WITH p1      EQ p1
                  WITH p3      EQ p3
                  WITH p4      EQ p4
                  WITH p_mailid EQ g_f_mailid
                  WITH p_psize EQ p_psize
                  WITH p_psize1 EQ p_psize1
                  WITH p_psize2 EQ p_psize2
                  WITH spid     EQ g_f_spid
                  TO SAP-SPOOL WITHOUT SPOOL DYNPRO
                  VIA JOB g_f_jobname NUMBER g_f_jobcount AND RETURN.
    *(3)Job closed when starts Immediately
           IF NOT p_imm IS INITIAL.
             IF sy-index LE g_f_nojob.
               CALL FUNCTION 'JOB_CLOSE'
                 EXPORTING
                   jobcount             = g_f_jobcount
                   jobname              = g_f_jobname
                   strtimmed            = g_flg_start
                 EXCEPTIONS
                   cant_start_immediate = 1
                   invalid_startdate    = 2
                   jobname_missing      = 3
                   job_close_failed     = 4
                   job_nosteps          = 5
                   job_notex            = 6
                   lock_failed          = 7
                   OTHERS               = 8.
               gs_jobsts-jobcount = g_f_jobcount.
               gs_jobsts-jobname  = g_f_jobname.
               gs_jobsts-spname   = g_f_spname.
               APPEND gs_jobsts to gt_jobsts.
             ELSEIF sy-index GT g_f_nojob.
               CLEAR g_f_flg.
               DO.                         " Wiating untill any job completion
                 LOOP AT gt_jobsts into gs_jobsts.
                   CLEAR g_f_status.
                   CALL FUNCTION 'BP_JOB_STATUS_GET'
                     EXPORTING
                       JOBCOUNT                         = gs_jobsts-jobcount
                       JOBNAME                          = gs_jobsts-jobname
                    IMPORTING
                       STATUS                           = g_f_status
    *            HAS_CHILD                        =
    *          EXCEPTIONS
    *            JOB_DOESNT_EXIST                 = 1
    *            UNKNOWN_ERROR                    = 2
    *            PARENT_CHILD_INCONSISTENCY       = 3
    *            OTHERS                           = 4
                   g_f_mid = gs_jobsts-spname.
                   IF g_f_status = 'F'.
                     IMPORT gt_final FROM MEMORY ID g_f_mid .
                     FREE MEMORY ID gs_jobsts-spname.
                     APPEND LINES OF gt_final to gt_final1.
                     REFRESH gt_prlist.
                     CALL FUNCTION 'JOB_CLOSE'
                       EXPORTING
                         jobcount             = g_f_jobcount
                         jobname              = g_f_jobname
                         strtimmed            = g_flg_start
                       EXCEPTIONS
                         cant_start_immediate = 1
                         invalid_startdate    = 2
                         jobname_missing      = 3
                         job_close_failed     = 4
                         job_nosteps          = 5
                         job_notex            = 6
                         lock_failed          = 7
                         OTHERS               = 8.
                     IF sy-subrc = 0.
                       g_f_flg = 'X'.
                       gs_jobsts1-jobcount = g_f_jobcount.
                       gs_jobsts1-jobname  = g_f_jobname.
                       gs_jobsts1-spname   = g_f_spname.
                       APPEND gs_jobsts1 TO gt_jobsts.
                       DELETE TABLE gt_jobsts FROM gs_jobsts.
                       EXIT.
                     ENDIF.
                   ENDIF.
                 ENDLOOP.
                 IF g_f_flg = 'X'.
                   CLEAR g_f_flg.
                   EXIT.
                 ENDIF.
               ENDDO.
             ENDIF.
           ENDIF.
           IF sy-subrc <> 0.
             MESSAGE e539(scpr) WITH g_f_jobname.
           ENDIF.
           COMMIT WORK .
         ENDDO.

  • How to select the data from a Maintainance View into an internal table

    Hi All,
    Can anybody tell me how to select the data from a Maintainance View into an internal table.
    Thanks,
    srinivas.

    HI,
    You can not retrieve data from A mentenance view.
    For detail check this link,
    http://help.sap.com/saphelp_nw2004s/helpdata/en/cf/21ed2d446011d189700000e8322d00/content.htm
    Regards,
    Anirban

Maybe you are looking for