Rounding of a field in Internal table

Hi ,
I have a quantity field(menge)  in an internal table( i_tab) . In a loop at the internal table(i_tab) , I want to round off the quantity to x decimal places . 'x' will be different for each record , depending on some logic.
Through what syntax do I achieve this ?
Regards,
Sujata

HI,
Using the write statment, you can write the addition  DECIMALS d
<b>Effect</b>
d specifies the number of decimal places for a number field (type I , P or F ) in d . If this value is smaller than the number of decimal places in the number, the number is rounded. If the value is greater, the number is padded with zeros.
Since accuracy with floating point arithmetic is up to about 15 decimal places (see ABAP/4 number types ), up to 17 digits are output with floating point numbers (type F ). (In some circumstances, 17 digits are needed to differentiate between two neighboring floating point numbers.) If the output length is not sufficient, as many decimal places as possible are output. Negative DECIMALS specifications are treated as DECIMALS 0 .
<b>Example</b>
Effect of different DECIMALS specifications:
DATA: X TYPE P DECIMALS 3 VALUE '1.267',
      Y TYPE F            VALUE '125.456E2'.
WRITE: /X DECIMALS 0,  "output: 1
       /X DECIMALS 2,  "output: 1.27
       /X DECIMALS 5,  "output: 1.26700
       /Y DECIMALS 1,  "output: 1.3E+04
       /Y DECIMALS 5,  "output: 1.25456E+04
       /Y DECIMALS 20. "output: 1.25456000000000E+04
<b>and also you can use ROUND</b>
<b>Effect</b>
Scaled output of a field of type P .
The decimal point is first moved r places to the left ( r > 0) or to the right ( r < 0); this is the same as dividing with the appropriate exponent 10** r . The value determined in this way is output with the valid number of digits before and after the decimal point. If the decimal point is moved to the left, the number is rounded.
For further information about the interaction between the formatting options CURRENCY and DECIMALS , see the notes below.
&ABAP-EXAMPLE& Effect of different ROUND specifications:
DATA: X TYPE P DECIMALS 2 VALUE '12493.97'.
WRITE: /X ROUND -2,   "output: 1,249,397.00
       /X ROUND  0,   "output:    12,493,97
       /X ROUND  2,   "output:       124.94
       /X ROUND  5,   "output:         0.12
So, in your Loop, use the WRITE TO statment to move the internal table data with the perfect decimal places for each single field in the loop
Regards
Sudheer

Similar Messages

  • How to handle field symbols internal table values?

    HI all,
              I declared field string as below.The below code is working fine.
    Data : ITAB TYPE STANDARD TABLE OF YAPOPLN, (Custom table).
              wa_itab like line of ITAB.
    field-symbol : <fs> type ITAB.
    ASSIGN PARAM TO <FS>
    LOOP AT <FS> INTO WA_ITAB.
    WRITE:/ 'ABC'.
    ENDLOOP.
    But my requirement is that I dont want all the fields of the table YAPOPLN.My output contains only 2 fields of the table YAPOPLN,which contains total 4 fields.According to my requirement only 2 fields will be getting into one parameter PARAM(this is function module parameter,which is from ALV classes) from the user entered output,which contains only 2 fields.So the above code is not working properly because wa_itab contains 4 fields and giving short dump.
    If I am declaring the internal table with the required fields(only 2 fields) and referring that internal table to field symbol <FS>
    Data : BEGIN OF ITAB1 OCCURS 0,
             FIELD1 LIKE YAPOPLN-FIELD1,
             FIELD2 LIKE YAPOPLN-FIELD2,
             END OF ITAB1.
    field-symbol : <fs> LIKE ITAB1 OR  <FS> TYPE ANY.
    DATA :WA_ITAB1 LIKE LINE OF ITAB1.
    ASSIGN PARAM TO <FS>
    LOOP AT <FS> INTO WA_ITAB.
    WRITE:/ 'ABC'.
    ENDLOOP.
    But when I am compiling this code i am getting the below error.I am gettting the same below error when even <FS> is also declared as <FS> TYPE ANY.
    .'FS' is not an internal table or defined in TABLES.
    Can anyone help me in this regard?
    Thanks,
    Balaji

    Hello,
    Try this way:
    If both the type of internal tables are same then you can directly assign dynamic internal table to static internal table.
    itab = <itab>.
    Suppose you have field symbol internal table <itab> which is different in structure from ITAB.
    Now, you can create <wa> as follow:
    FIELD-SYMBOLS <wa>.
    DATA wa TYPE REF TO DATA.
    CREATE DATA wa TYPE LINE OF <itab>.
    ASSIGN wa->* to <wa>.
    This way your work area is read.
    Using [ASSIGN COMPONENT|http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb3923358411d1829f0000e829fbfe/content.htm] syntax you can read required component of <wa>.
    Finally you can use that value to load static internal table.
    You can also refer to my thread on [Dynamic table|Re: Creating Dynamic table].
    Hope this helps!
    Thanks,
    Augustin.
    Edited by: Augustarian on Aug 20, 2009 10:06 AM

  • How to move field symbol internal table to internal table with header line?

    Dear all,
    hi...hereby i would like to ask how i can move field symbol internal table to a internal table?
    as i know field symbol internal table is without header line..
    so, may i know how to do this....to move field symbol internal table to internal table which consist of header line and field and record will same as field symbol internal table...in additional, my field symbol internal table is dynamic table mean everytime will have flexible columns..?
    Please advise...
    Thanks
    Regard,
    ToToRo.
    Edited by: @ToToRo@ on Aug 20, 2009 6:16 AM

    Hello,
    Try this way:
    If both the type of internal tables are same then you can directly assign dynamic internal table to static internal table.
    itab = <itab>.
    Suppose you have field symbol internal table <itab> which is different in structure from ITAB.
    Now, you can create <wa> as follow:
    FIELD-SYMBOLS <wa>.
    DATA wa TYPE REF TO DATA.
    CREATE DATA wa TYPE LINE OF <itab>.
    ASSIGN wa->* to <wa>.
    This way your work area is read.
    Using [ASSIGN COMPONENT|http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb3923358411d1829f0000e829fbfe/content.htm] syntax you can read required component of <wa>.
    Finally you can use that value to load static internal table.
    You can also refer to my thread on [Dynamic table|Re: Creating Dynamic table].
    Hope this helps!
    Thanks,
    Augustin.
    Edited by: Augustarian on Aug 20, 2009 10:06 AM

  • How To select maximum Value in a specifieid field in internal table.

    How To select maximum Value in a specifieid field in internal table?

    Step : 1
    Sort itab by <Field1> descending.
    Just sort the internal table by the field.
    STEP: 2
    Then read the table at index 1.
    Read table itab index 1.               
    ITAB-FIELD = MAX .                  " Max field will come in the first row of the internal table.
    Regards,
    Gurpreet

  • Assign function code to a field in internal table

    Hi all,
    Can we assign a function code to one field in internal table so that we can use it as an user command in list display.
    For ex:
    data : begin of itab occurs 0,
              check(1) type C,
              num type I,
             end of itab.
    I am preparing a list display using WRITE statements.
    I'ld like to update the checked value of check box as soon as the user selects a  check box. So I would like to assign a function code to this check box. Then I can use AT user-command.

    Hi,
    dinesh's apporach is not bad, but
    1. the structure' name cannot be part of the component
    2. you need to make sure the component-name always is in upper case.
    Try adapting the following code:
    data: begin of wa_test,
              field01 type string,
              field02 type string,
              field03 type string,
           end of wa_test.
    data:  l_fieldname  type string,
           l_counter    type string.
    field-symbols: <testc> type string.
    do 3 times.
      l_counter = sy-index.
      concatenate 'field0' l_counter into l_fieldname.
      translate l_fieldname to upper case.
      assign component l_fieldname of structure wa_test to <testc>.
      if <testc> is assigned.
        <testc> = 'any value'.
      endif.
    enddo.
    write / wa_test-field01.
    best regards

  • How to add the contents of a field of internal table.

    Hello Everybody,
    How to sum up the individual field from a internal table. Like i have a internal table that has menge field , I need to sum up the menge field for each matnr..
    exm : for each matnr there are 5 menge entries, I need to add all the menge fields and shud be put against the matnr .
    Thanks,

    Hi Khaleel,
    One more option is using the "collect" statement.....
    imagine in the internal table itab..we have 2 fields only..
    MATNR,MENGE,
    we have 2 internal tables itab1 and itab2...
    loop at itab1.
    collect itab1 to itab2.
    endloop.
    Action performed is ...for the same MATNR...menge gets added and saved as a single record...When matnr changes...new record is Appended
    another case is we have 3 fields in internal table
    MATNR,UNIT,MENGE
    imagine we hane the records
    Material1 KG  100
    Material1 LT   20
    Material1 LT   200
    MAterial2 KG 100
    in this case...the output will be
    Material1 KG 100
    Material1 LT  220
    MAterial2 KG 100
    Reason is that the fields before the addable value is checked for similarity..
    here field UNIT is also checked and also MATNR before adding up....
    Hope it gave you some alternative idea to proceed with....
    Reward if helpful
    Regards
    Byju

  • Read contents of changing fields from internal table

    Hi Folks,
    Please help me in my query below:
    Consider there is a Z-table with two fields TABNAM and FIELD having values KNA1 and NAME1 respectively.
    In my report I have fetched entries for customers from KNA1. Now based on the field from Z-table I want to populate a variable suppose V_FREE_VAR with the value from KNA1 table.
    Here V_FREE_VAR is of CHAR200 so that it accomodate all types of values from KNA1.
    The value of Z-table FIELD can change daily i.e next day the value may be PSTLZ.
    So how can I read the particular field from internal table as the field to be read is dynamic.
    Note: using case is not feasible.
    Thanks in advance.
    Regards,
    Shardul

    @Hartmut P
    As Rob said i want to get the value of the field from internal table. the code is something like this.
    I_KNA1 contains records for customers.
    Suppose values of Z-table are in internal table I_TEMP_TABLE.
    Entries in I_TEMP_TABLE are as follows
    TABNAME      FIELDNAME
    KNA1                 NAME1
    The value of FIELNAME in Z-table can be changed
    Loop at I_TEMP_TABLE into WA_TEMP_TABLE.
    Read I_KNA1 into WA_KNA1 with key KUNNR = '0001002234'.
    IF SY-SUBRC EQ 0.
       CASE WA_TEMP_TABLE-FIELDNAME.
            WHEN 'NAME1'.
                 V_VAR = WA_KNA1-NAME1.
             WHEN 'PSTLZ'
                  V_VAR = WA_KNA1-PSTLZ.
    ENDIF.
    But using case is not appropriate as KNA1 contains 176 fields.

  • Fields in internal table

    Hi,
      How to get number of fields in an internal table?
      Please send a solution.
    Thanks & Regards,
    Vani.

    Hi,
    you can find the number of columns and their order using
    the <b>'REUSE_ALV_FIELDCATALOG_MERGE'</b>
    call function 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
       I_PROGRAM_NAME               = sy-repid
       I_INTERNAL_TABNAME           = 'ITAB'
       I_INCLNAME                   = sy-repid
      changing
        ct_fieldcat                  = IT_FIELDCAT
    EXCEPTIONS
       INCONSISTENT_INTERFACE       = 1
       PROGRAM_ERROR                = 2
       OTHERS                       = 3
    if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif
    now describe your fieldcat . and find no of columns.
    and their order also..
    Regards
    vijay

  • Updation of blank field in internal table

    Hi,
      I want to update the blank businees area field with the header item of that particular business area belnr.
    i am sending you the updation of business area code plz find out where rhe error and rectify please.
    points given
    REPORT zfir_vendorwise_grir_balances NO STANDARD PAGE HEADING
                            LINE-SIZE 142
                            LINE-COUNT 65.
    TABLES: bsis,bkpf,bseg,ekko,lfa1.
    TYPE-POOLS: slis.
    CONSTANTS:
    gc_formname_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE'.
    DATA: gt_fieldcat TYPE slis_t_fieldcat_alv,
          gs_layout   TYPE slis_layout_alv ,
          gs_print    TYPE slis_print_alv,
          gt_sort     TYPE slis_t_sortinfo_alv ,
          gt_filter   TYPE slis_t_filter_alv,
          gt_sp_group TYPE slis_t_sp_group_alv,
          gt_alv_graphics TYPE dtc_t_tc,
          gt_excluding  TYPE slis_t_extab ,
          gt_events   TYPE slis_t_event .
    DATA: g_repid LIKE sy-repid.
    DATA: gt_list_top_of_page TYPE slis_t_listheader.
    DATA:       g_boxnam TYPE slis_fieldname VALUE  'BOX',
                p_f2code LIKE sy-ucomm       VALUE  '&ETA',
                p_lignam TYPE slis_fieldname VALUE  'LIGHTS',
                g_save(1) TYPE c,
                g_default(1) TYPE c,
                g_exit(1) TYPE c,
                gx_variant LIKE disvariant,
                g_variant LIKE disvariant.
    DATA : g_user_command(30) VALUE 'USER_COMMAND'.
    DATA : g_status_set(30)  VALUE 'PF_STATUS_SET'.
    DATA: BEGIN OF it_final OCCURS 0,
          awkey TYPE awkey,
          grir(10) TYPE c,
          bukrs LIKE bsis-bukrs,
          hkont LIKE bsis-hkont,
          gjahr LIKE bsis-gjahr,
          belnr LIKE bsis-belnr,
          budat LIKE bsis-budat,
          waers LIKE bsis-waers,
          xblnr LIKE bsis-xblnr,
          blart LIKE bkpf-blart,
          buzei like bseg-buzei,
          bschl LIKE bseg-bschl,
          shkzg LIKE bseg-shkzg,
          gsber LIKE bseg-gsber,
          dmbtr LIKE bseg-dmbtr,
          wrbtr LIKE bsis-wrbtr,
          sgtxt LIKE bseg-sgtxt,
          ebeln LIKE bseg-ebeln,
          lifnr LIKE ekko-lifnr,
          ps_psp_pnr LIKE ekkn-ps_psp_pnr,
          name1 LIKE addr1_data-name1,
          END OF it_final.
    DATA : it_po LIKE it_final OCCURS 0 WITH HEADER LINE.
    DATA : it_ebeln LIKE it_final OCCURS 0 WITH HEADER LINE.
    DATA : it_awkey LIKE it_final OCCURS 0 WITH HEADER LINE.
    DATA : wa_final LIKE LINE OF it_final.
    DATA : BEGIN OF it_lifnr OCCURS 0,
            ebeln TYPE ebeln,
            lifnr TYPE lifnr,
    END OF it_lifnr.
    DATA : BEGIN OF it_name1 OCCURS 0,
            lifnr TYPE lifnr,
            name1 TYPE name1,
    END OF it_name1.
    DATA : hmin TYPE bseg-hkont.
    DATA : hmax TYPE bseg-hkont.
    DATA: idx TYPE sy-tabix.
    DATA:  temp_gsber TYPE bseg-gsber.
    DATA:  temp_ebeln TYPE bseg-ebeln.
    DATA : temp_gjahr TYPE bseg-gjahr.
    DATA : temp_belnr TYPE bseg-belnr.
    DATA : temp_lifnr TYPE bseg-lifnr.
    *DEFINING THE SELECTION-CRITERIA.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
    PARAMETERS: p_bukrs LIKE skb1-bukrs OBLIGATORY.
    SELECT-OPTIONS: s_gsber FOR bseg-gsber OBLIGATORY.
    SELECT-OPTIONS: s_hkont FOR bseg-hkont OBLIGATORY.
    PARAMETERS: p_lifnr LIKE ekko-lifnr.
    PARAMETERS: p_budat LIKE bkpf-budat OBLIGATORY.
    SELECTION-SCREEN END OF BLOCK b1.
    AT SELECTION-SCREEN ON s_hkont.
      CHECK s_hkont-low LT 250301 OR s_hkont-high GT 250500.
      MESSAGE e000(zm) WITH 'PLEASE SELECT A GRIR CLEARING ACCOUNT BETWEEN'
                            '250301 AND 250500'.
    *INITIALIZATION.
    INITIALIZATION.
      g_repid = sy-repid.
    *START-OF-SELECTION.
    START-OF-SELECTION.
      PERFORM select_data.
      PERFORM display_data.
      PERFORM list_display.
    *&      Form  select_data
          text
    -->  p1        text
    <--  p2        text
    FORM select_data .
    *selecting open item details
      SELECT bukrs  hkont  gjahr   belnr buzei
             budat  waers  xblnr   blart
             bschl  shkzg  gsber   dmbtr
             wrbtr  sgtxt
         FROM bsis
            INTO CORRESPONDING FIELDS OF TABLE it_final
            WHERE bukrs EQ p_bukrs
                  AND hkont BETWEEN  '0000250301' AND  '0000250500'
                  AND budat LE p_budat AND ( blart EQ 'WE' OR
                                             blart EQ 'RE' OR
                                             blart EQ 'SA' OR
                                             blart EQ 'EI').
    *selecting closed/cleared item details
      SELECT bukrs  hkont gjahr belnr buzei budat
             waers  xblnr blart bschl shkzg
             gsber  dmbtr wrbtr sgtxt
         FROM bsas
            APPENDING CORRESPONDING FIELDS OF TABLE it_final
            WHERE bukrs EQ p_bukrs
            AND hkont BETWEEN '0000250301' AND  '0000250500'
            AND budat LE p_budat
            AND blart IN ('WE', 'RE','SA','EI')
            AND augdt GE p_budat.
      SORT it_final BY belnr gsber DESCENDING.
      CLEAR: temp_belnr, temp_gsber.
    update blank business areas
    LOOP AT it_final .
    IF temp_gsber IN s_gsber AND it_final-belnr = temp_belnr.
         IF it_final-gsber = ' '.
           it_final-gsber = temp_gsber.
         ENDIF.
       ENDIF.
    if it_final-gsber eq space or it_final-gsber in s_gsber.
         wa_final-gsber = it_final-gsber.
         wa_final-belnr = it_final-belnr.
         modify it_final from wa_final transporting gsber.
    else.
         wa_final-gsber = it_final-gsber.
         wa_final-belnr = it_final-belnr.
         modify it_final from wa_final transporting gsber.
    endif.
    *clear wa_final.
    endloop.
    LOOP AT it_final.
       IF temp_gsber IN s_gsber AND it_final-belnr = temp_belnr.
         IF it_final-gsber = ' '.
           it_final-gsber = temp_gsber.
         ENDIF.
         IF it_final-lifnr = ' '.
           it_final-lifnr = temp_lifnr.
         ENDIF.
         IF it_final-belnr = ' '.
           it_final-belnr = temp_belnr.
         ENDIF.
       ENDIF.
       IF it_final-gsber EQ space OR it_final-gsber IN s_gsber.
         CLEAR: temp_belnr, temp_gsber,temp_lifnr.
         temp_belnr = it_final-belnr.
         temp_gsber = it_final-gsber.
         temp_lifnr = it_final-lifnr.
       ELSE.
         CLEAR : temp_belnr, temp_gsber,temp_lifnr.
       ENDIF.
       MODIFY it_final TRANSPORTING gsber.
    ENDLOOP.
      sort it_final by belnr buzei.
    loop at it_final.
    on change of it_final-belnr.
    clear temp_belnr.
    clear temp_gsber.
    clear temp_lifnr.
    temp_belnr = it_final-belnr.
    temp_gsber = it_final-gsber.
    temp_lifnr = it_final-lifnr.
    endon.
    if it_final-gsber is initial.
      it_final-gsber = temp_gsber.
    *modify it_final transporting gsber.
    endif.
    if it_final-lifnr is initial.
      it_final-lifnr = temp_lifnr.
    *modify it_final transporting lifnr.
    endif.
    modify it_final transporting gsber lifnr where belnr = temp_belnr.
    endloop.
    *deleting entries which are not as per input parameter for business area
    DELETE it_final WHERE  gsber NOT IN s_gsber .
    loop at it_final.
      if s_gsber-low ne '' and s_gsber-high ne ''.
      delete it_final where gsber not in s_gsber.
    elseif s_gsber-low ne '' and s_gsber-high eq ''.
    delete it_final  where gsber ne s_gsber-low.
    endif.
    endloop.
    *initialising internal tables
      it_awkey[] = it_final[].
      it_po[] = it_final[].
      it_ebeln[] = it_final[].
      IF it_final[] IS NOT INITIAL.
    *selecting purchase doc details
        SELECT bukrs  hkont  gjahr   belnr
                       bschl  shkzg  gsber   dmbtr
             wrbtr  sgtxt ebeln
               FROM bseg  INTO CORRESPONDING FIELDS OF TABLE it_ebeln
               FOR ALL ENTRIES IN it_final
                WHERE bukrs = p_bukrs
                  AND belnr = it_final-belnr
                  AND gjahr = it_final-gjahr
                  AND hkont = it_final-hkont.
    *selecting the GR/IR number from BKPF
        SELECT  bukrs    gjahr   belnr
             budat  waers  xblnr   blart
             awkey
            FROM bkpf
          INTO CORRESPONDING FIELDS OF  TABLE it_awkey
              FOR ALL ENTRIES IN it_final
        WHERE bukrs EQ it_final-bukrs
              AND gjahr EQ it_final-gjahr
              AND belnr EQ it_final-belnr.
      ENDIF.
      IF it_ebeln[] IS NOT INITIAL.
    *selecting WBS element
        SELECT   ebeln  gsber
              ps_psp_pnr
          FROM ekkn
          INTO CORRESPONDING FIELDS OF TABLE it_po
          FOR ALL ENTRIES IN it_ebeln
          WHERE ebeln = it_ebeln-ebeln.
    *selecting vendor
        SELECT bukrs ebeln lifnr
          FROM ekko
          INTO CORRESPONDING FIELDS OF TABLE it_lifnr
          FOR ALL ENTRIES IN it_ebeln
          WHERE ebeln = it_ebeln-ebeln.
      ENDIF.
      IF it_lifnr[] IS NOT INITIAL.
    *selecting vendor name
        SELECT lifnr name1
            FROM lfa1
            INTO CORRESPONDING FIELDS OF  TABLE  it_name1
            FOR ALL ENTRIES IN it_lifnr
            WHERE lifnr EQ it_lifnr-lifnr.
      ENDIF.
      LOOP AT it_final.
        idx = sy-tabix.
    *retrieving purchase doc
        READ TABLE it_ebeln WITH KEY belnr = it_final-belnr
                                     gjahr = it_final-gjahr
                                     hkont = it_final-hkont.
        IF sy-subrc EQ 0.
          READ TABLE it_final INDEX idx.
          it_final-ebeln = it_ebeln-ebeln.
          MODIFY it_final INDEX sy-tabix.
        ENDIF.
    *retrieving WBS element
        READ TABLE it_po WITH KEY ebeln = it_final-ebeln.
        IF sy-subrc EQ 0.
          READ TABLE it_final INDEX idx.
          it_final-ps_psp_pnr = it_po-ps_psp_pnr.
          MODIFY it_final INDEX sy-tabix.
        ENDIF.
    calculating amount based on debit/credit
        IF it_final-shkzg = 'H'.
          it_final-dmbtr = 0 - it_final-dmbtr.
          it_final-wrbtr = 0 - it_final-wrbtr.
        ENDIF.
        MODIFY it_final INDEX idx.
      ENDLOOP.
      CLEAR idx.
      SORT it_final BY belnr ebeln DESCENDING.
    *updating blank purchase doc numbers
      CLEAR: temp_belnr, temp_ebeln,temp_gjahr.
      DATA: w_idx LIKE sy-tabix.
      LOOP AT it_final.
        w_idx = sy-tabix.
    *updating blank purchase docs
        IF it_final-gjahr = temp_gjahr AND it_final-belnr = temp_belnr.
          IF it_final-ebeln = ' '.
            it_final-ebeln = temp_ebeln.
          ENDIF.
        ENDIF.
        IF it_final-ebeln NE ' ' .
          CLEAR: temp_belnr, temp_ebeln, temp_gjahr.
          temp_belnr = it_final-belnr.
          temp_ebeln = it_final-ebeln.
          temp_gjahr = it_final-gjahr.
        ELSE.
          CLEAR : temp_belnr, temp_ebeln, temp_gjahr.
        ENDIF.
        MODIFY it_final TRANSPORTING ebeln.
    *retrieving vendor
        READ TABLE it_lifnr WITH KEY ebeln = it_final-ebeln.
        IF sy-subrc EQ 0.
          READ TABLE it_final INDEX w_idx.
          it_final-lifnr = it_lifnr-lifnr.
          MODIFY it_final INDEX sy-tabix.
        ENDIF.
    *retrieving GRIR number
        READ TABLE it_awkey WITH KEY belnr = it_final-belnr
                                     gjahr = it_final-gjahr
                                     bukrs = it_final-bukrs.
        IF sy-subrc EQ 0.
          READ TABLE it_final INDEX w_idx.
          it_final-awkey = it_awkey-awkey.
          MODIFY it_final INDEX sy-tabix.
        ENDIF.
    *retrieving vendor name
        READ TABLE it_name1 WITH KEY lifnr = it_final-lifnr.
        IF sy-subrc EQ 0.
          READ TABLE it_final INDEX w_idx.
          it_final-name1 = it_name1-name1..
          MODIFY it_final INDEX sy-tabix.
        ENDIF.
      ENDLOOP.
    *deleting entries which are not per input parameters
      DELETE it_final WHERE hkont NOT IN s_hkont.
      IF p_lifnr NE ' '.
        DELETE it_final WHERE lifnr NE p_lifnr.
      ENDIF.
    for selecting the grir number which is the first 10 digits of reference key and
    selecting vendor name
      LOOP AT it_final.
        MOVE it_final-awkey+0(10) TO it_final-grir.
        MODIFY it_final INDEX sy-tabix.
      ENDLOOP.
      SORT it_final BY hkont belnr.
    deleting entries where purchase doc is blank.
      DELETE it_final WHERE ebeln EQ ' '.
    ENDFORM.                    " select_data
    *&      Form  build_fieldcat
          text
    -->  p1        text
    <--  p2        text
    FORM e01_fieldcat_init  USING gt_fieldcat TYPE slis_t_fieldcat_alv.
      DATA: ls_fieldcat TYPE slis_fieldcat_alv.
      DATA: gs_sort TYPE slis_sortinfo_alv.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname    = 'HKONT'.
      ls_fieldcat-tabname    = 'IT_FINAL'.
      ls_fieldcat-col_pos      = '1'.
      ls_fieldcat-seltext_l    = 'ACCOUNT'.
      APPEND ls_fieldcat TO gt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname    = 'BSCHL'.
      ls_fieldcat-tabname    = 'IT_FINAL'.
      ls_fieldcat-col_pos      = '2'.
      ls_fieldcat-seltext_l    = 'POSTING KEY'.
      APPEND ls_fieldcat TO gt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname    = 'BLART'.
      ls_fieldcat-tabname    = 'IT_FINAL'.
      ls_fieldcat-col_pos      = '3'.
      ls_fieldcat-seltext_l    = 'DOC TYPE'.
      APPEND ls_fieldcat TO gt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname    = 'BELNR'.
      ls_fieldcat-tabname    = 'IT_FINAL'.
      ls_fieldcat-col_pos      = '4'.
      ls_fieldcat-seltext_l    = 'DOC NUMBER'.
      ls_fieldcat-hotspot(1)   = 'X'.
      APPEND ls_fieldcat TO gt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname    = 'BUDAT'.
      ls_fieldcat-tabname    = 'IT_FINAL'.
      ls_fieldcat-col_pos      = '5'.
      ls_fieldcat-seltext_l    = 'POSTING DATE'.
      APPEND ls_fieldcat TO gt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname    = 'XBLNR'.
      ls_fieldcat-tabname    = 'IT_FINAL'.
      ls_fieldcat-col_pos      = '6'.
      ls_fieldcat-seltext_l    = 'REF. DOC NO'.
      APPEND ls_fieldcat TO gt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname    = 'EBELN'.
      ls_fieldcat-tabname    = 'IT_FINAL'.
      ls_fieldcat-col_pos      = '7'.
      ls_fieldcat-seltext_l    = 'PURCHASE DOC NO'.
      ls_fieldcat-hotspot(1)   = 'X'.
      APPEND ls_fieldcat TO gt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname    = 'GSBER'.
      ls_fieldcat-tabname    = 'IT_FINAL'.
      ls_fieldcat-col_pos      = '8'.
      ls_fieldcat-seltext_l    = 'BUSINESS AREA'.
      APPEND ls_fieldcat TO gt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname    = 'DMBTR'.
      ls_fieldcat-tabname    = 'IT_FINAL'.
      ls_fieldcat-col_pos      = '9'.
      ls_fieldcat-seltext_l    = 'AMOUNT(LC)'.
      APPEND ls_fieldcat TO gt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname    = 'WRBTR'.
      ls_fieldcat-tabname    = 'IT_FINAL'.
      ls_fieldcat-col_pos      = '10'.
      ls_fieldcat-seltext_l    = 'AMOUNT(DC)'.
      APPEND ls_fieldcat TO gt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname    = 'WAERS'.
      ls_fieldcat-tabname    = 'IT_FINAL'.
      ls_fieldcat-col_pos      = '11'.
      ls_fieldcat-seltext_l    = 'CURRENCY'.
      APPEND ls_fieldcat TO gt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname    = 'GJAHR'.
      ls_fieldcat-tabname    = 'IT_FINAL'.
      ls_fieldcat-col_pos      = '14'.
      ls_fieldcat-seltext_l    = 'Fiscal year'.
      APPEND ls_fieldcat TO gt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname    = 'GRIR'.
      ls_fieldcat-tabname    = 'IT_FINAL'.
      ls_fieldcat-col_pos      = '14'.
      ls_fieldcat-seltext_l    = 'GR/IR Number'.
      APPEND ls_fieldcat TO gt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname    = 'LIFNR'.
      ls_fieldcat-tabname    = 'IT_FINAL'.
      ls_fieldcat-col_pos      = '12'.
      ls_fieldcat-seltext_l    = 'VENDOR NO'.
      APPEND ls_fieldcat TO gt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname    = 'PS_PSP_PNR'.
      ls_fieldcat-tabname    = 'IT_FINAL'.
      ls_fieldcat-col_pos      = '13'.
      ls_fieldcat-seltext_l    = 'WBS Element'.
      APPEND ls_fieldcat TO gt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname    = 'NAME1'.
      ls_fieldcat-tabname    = 'IT_FINAL'.
      ls_fieldcat-col_pos      = '14'.
      ls_fieldcat-seltext_l    = 'VENDOR NAME'.
      APPEND ls_fieldcat TO gt_fieldcat.
    ENDFORM.                    " build_fieldcat
    *&      Form  LIST_DISPLAY
          text
    -->  p1        text
    <--  p2        text
    FORM list_display .
      gs_layout-colwidth_optimize(1)  = 'X'.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_background_id         = 'ALV_BACKGROUND'
          i_callback_program      = g_repid
          i_callback_user_command = 'USER_COMMAND'
          i_structure_name        = 'IT_FINAL'
          is_layout               = gs_layout
          it_fieldcat             = gt_fieldcat[]
          it_special_groups       = gt_sp_group[]
          it_sort                 = gt_sort[]
          it_filter               = gt_filter[]
          i_save                  = g_save
          is_variant              = g_variant
          it_events               = gt_events[]
          is_print                = gs_print
          it_alv_graphics         = gt_alv_graphics[]
          it_excluding            = gt_excluding
        TABLES
          t_outtab                = it_final.
    ENDFORM.                    " LIST_DISPLAY
    *&      Form  USER_COMMAND
    FORM user_command USING i_ucomm  LIKE sy-ucomm
                            is_selfield TYPE slis_selfield.     "#EC CALLED
      CASE i_ucomm.
        WHEN '&IC1'.                        " Pick(Double-click)
          CASE is_selfield-fieldname.
            WHEN 'BELNR'.
              CLEAR it_final.
              READ TABLE it_final INDEX is_selfield-tabindex.
              IF sy-subrc EQ 0.
              FI Document number
                SET PARAMETER ID 'BLN' FIELD it_final-belnr.
              Display Document
                CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
              ENDIF.
            WHEN 'EBELN'.
              CLEAR it_final.
              READ TABLE it_final INDEX is_selfield-tabindex.
              IF sy-subrc EQ 0.
              PO number
                IF it_final-ebeln NE ' '.
                  SET PARAMETER ID 'BES' FIELD it_final-ebeln.
              Display Document
                  CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
                ENDIF.
              ENDIF.
          ENDCASE.
      ENDCASE.
    ENDFORM.                    "user_command
    *&      Form  display_data
          text
    -->  p1        text
    <--  p2        text
    FORM display_data .
      g_repid = sy-repid.
      PERFORM e01_fieldcat_init  USING gt_fieldcat[].
      PERFORM eventtab_build CHANGING gt_events.
      PERFORM e04_comment_build USING gt_list_top_of_page[].
    ENDFORM.                    " display_data
    *&      Form  eventtab_build
          text
         <--P_GT_EVENTS  text
    FORM eventtab_build CHANGING lt_events TYPE slis_t_event.
      CONSTANTS:
        gc_formname_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE'.
      DATA: ls_event TYPE slis_alv_event.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type = 0
        IMPORTING
          et_events   = lt_events.
      READ TABLE lt_events WITH KEY name = slis_ev_top_of_page
      INTO ls_event.
      IF sy-subrc = 0.
        MOVE gc_formname_top_of_page TO ls_event-form.
        APPEND ls_event TO lt_events.
      ENDIF.
    ENDFORM.                    " eventtab_build
    *&      Form  e04_comment_build
          text
         -->P_GT_LIST_TOP_OF_PAGE[]  text
    FORM e04_comment_build  USING e04_lt_top_of_page TYPE slis_t_listheader.
      DATA : v_time(10) TYPE c.
      DATA: ls_line TYPE slis_listheader.
      DATA : v_text(50) TYPE c.
      DATA : v_date_low(10)  TYPE c,
             v_date_high(10)  TYPE c.
      CONCATENATE 'GR/IR Report' ' '
      INTO v_text SEPARATED BY space.
      CLEAR ls_line.
      ls_line-typ  = 'H'.
      ls_line-info = v_text.
      APPEND ls_line TO e04_lt_top_of_page.
    ENDFORM.                    " e04_comment_build
    *&      Form  top_of_page
          text
    FORM top_of_page.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary = gt_list_top_of_page.
    ENDFORM   .                    "TOP_OF_PAGE
    regards,
    Amit teja
    Message was edited by: amit teja
    Message was edited by: amit teja
    Message was edited by: amit teja

    Hello,
    <b>Sort it_final by belnr.</b>
    loop at it_final.
    on change of it_final-belnr.
    clear temp_gsber.
    clear temp_lifnr.
    <b>temp_belnr = it_final-belnr.</b>
    temp_gsber = it_final-gsber.
    temp_lifnr = it_final-lifnr.
    if it_final-gsber eq ' '.
    it_final-gsber = temp_gsber.
    endif.
    if it_final-lifnr eq ' '.
    it_final-lifnr = temp_lifnr.
    endif.
    modify it_final transporting gsber lifnr where <b>belnr = temp_belnr</b>.
    <b>endon.</b>
    endloop.
    Regards,
    Naimesh

  • Reading the data from field symbol internal table //

    Hi,
    There are 2 internal tables defined as Fieldsymbols (type any) and I need to retrive data from second internal table based on a field value in first internal table.
    Let's assue the name internal table 1 is <it_itab1>, 2nd internal table name is <it_itab2> and the work areas are <wa_itab1> and <wa_itab2>.
    The existing logic :
    LOOP at <it_itab1> ASSIGNING <wa_itab1>.
      ASSIGN COMPONENT 'XYZ' OF STRUCTURE <wa_itab1> TO l_field6.
      LOOP AT <it_itab2> ASSIGNING <wa_itab2>.
        ASSIGN COMPONENT 'XYZ' OF STRUCTURE <wa_itab2> TO <p_field7>.
        IF <p_field7> = l_field6.
    do the required business.
        ELSE.
          *     do the required business.
        ENDIF.
      ENDLOOP.
    ENDLOOP.
    The requirement of reading second internal table was achieved by putting loop on the internal table but its giving considerable effect on performance !!
    Is there any way to use READ statement in my case OR any way of putting WHERE condition on loop statement of second internal table ??
    Thank you !!

    Use the below Logic.
    Loop at Itab1 into wa_itab1.
        Loop at itab2 into wa_itab2 where p_field7 = wa_itab1-xyz or I_field6.
    do the required business.
        endloop.
        Loop at itab2 into wa_itab2 where p_field7 <> wa_itab1-xyz or I_field6.
    do the required business.
        endloop.
    endloop.
    Hope it is useful...

  • How to delete duplicates of some specific fields in internal table

    i am having internal table of it_ekko.
    in that i am having some data of PO no, Line Item,IR value and IR qty......
    i am having data like below.
    PO                        Line Item   IR Value    IR QTY 
    200310051          0010         1500           4500
    200310051          0010        1500           4500
    200310052         0010           0                   0
    200310052          0010       0               0
    now where ever IR value and IR qty is present i wanted that to display only once against that PO and line item
    i wanted like below
    PO                        Line Item   IR Value    IR QTY 
    200310051          0010         1500           4500
    200310051          0010            0              0
    200310052         0010             0                0
    200310052          0010            0               0
    Field names for IR value and IR Qty are Menge2 and dmbtr2.
    How to do that.........
    I cant use
    Delete adjacent duplicates of it_ekko by ebeln = wa_ekko-ebeln and
                                                                          ebelp = wa_ekko-ebelp.
    because i wanted that po and same line items , how many times it is like that only.....
    in it_ekko table i only wanted to delete duplicates of menge2 and dmbtr2.
    Pls suggest the code

    sort itab by po item ascending.
    loop at itab into wa.
    at new wa-item.
    if wa-qty1 ne 0 and wa-qty2 ne 0.
    move wa to wa_final.
    append wa_final to i_final.
    endat.
    endloop.
    or
    loop at itab into wa.
    at new wa-item.
    if wa-qty1 ne 0 and wa-qty2 ne 0.
    write wa.
    endat.
    endloop.
    make sure that the qty1 and qty2 is not character type , then in control statement it will replaced by *.

  • How to add one more field in Internal table

    Hi Experts
    i have declared an internal table
    DATA: lt_viqmel_iflos TYPE TABLE OF viqmel_iflos.
    viqmel_iflos is a Standared SAP Table,
    Now i want to add one more Text field in the internal table only, how to add in program. any one plz help.
    <REMOVED BY MODERATOR>
    Mohana
    Edited by: Alvaro Tejada Galindo on Feb 7, 2008 10:09 AM

    you can put this:
    types: begin of t_table_viqmel_iflos,
    include structure of viqmel_iflos,
    new_field type xxxx.
    types: end of viqmel_iflos.
    DATA: lt_viqmel_iflos TYPE TABLE OF t_table_viqmel_iflos.
    Luck.

  • Urgent problem: grouping by fields of internal table

    Hi friend,
    i have a urgent problem and i hope that you can help me out:
    i have an internal table containing data, and i sorted it by 3 fields.
    now what i want to do is kind of grouping that means that all the lines that are the same should be written into another internal table like this:
    A
    A
    B
    B
    B
    C
    D
    would give me:
    A                       1
    A                       1
    B                       2
    B                       2
    B                       2
    C                       3
    D                       4
    How could i do this ( especially avoiding nested loops ? ) Is there a handy trick to do this efficiently ?
    thank you, i will give points immediately,
    Clemens

    Hello,
    The field position is important for the fields that are using in the control break statements..Also SORT internal table is required.
    http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb381a358411d1829f0000e829fbfe/content.htm
    DATA: BEGIN OF ITAB OCCURS 0,
    MATNR TYPE MATNR,
    WERKS TYPE WERKS_D,
    VALUE TYPE NETPR,
    END OF ITAB.
    ITAB-MATNR = 'ABC'.
    ITAB-WERKS = '0100'.
    ITAB-VALUE = '10.00'.
    APPEND ITAB.
    ITAB-MATNR = '1ABC'.
    ITAB-WERKS = '0100'.
    ITAB-VALUE = '10.00'.
    APPEND ITAB.
    SORT ITAB BY MATNR WERKS.
    LOOP AT ITAB.
    AT FIRST.
      WRITE : 'AT FIRST'.
    ENDAT.
    AT NEW MATNR.
      WRITE : 'AT NEW MATERIAL NUMBER'.
    ENDAT.
    AT END OF MATNR.
      SUM.
      WRITE: / ITAB-MATNR, 'MATERIAL TOTAL - ', ITAB-VALUE.
    ENDAT.
    AT END OF WERKS.
      SUM.
      WRITE: / ITAB-WERKS, 'PLANT TOTAL - ', ITAB-VALUE.
    ENDAT.
    AT LAST.
      WRITE : 'AT LAST'.
    ENDAT.
    ENDLOOP.
    Regards,
    Deepu.K

  • Length of value of c field in internal table

    Hi experts,
    how do I find out the lenght of the value which is an CHARACTER field in an internal table.
    I get a .XLS file from the customer. To check where the real entries starts I need to know the length of one field in the internal table.
    How do I do this?
    I tried it with DESCRIBE, but it doesn't work because the c field is interpreted hexadecimal.
    Example:
    all fields in my table are c(30), the value in one column is max. 3 letters. I want to find out the row where the entry in this field is 3 letters long.
    Edited by: Heiko Kany on Sep 3, 2008 8:49 AM

    Hi Heiko,
    You can find the length using the STRLEN function as given below;
    DATA : ipstr TYPE string.
    DATA : len TYPE i VALUE 0.
    ipstr = 'Sample String'.
    len = STRLEN( ipstr )
    After execution len will contain 13.
    Regards
    Karthik D

  • How can i know the number of lines in field-symbol internal table

    how can i know the number of lines in field-symbol internal table

    Hi,
    If your field symbol has been defined as an internal table :
    Use std describe as
    Data: l type i.
    describe <fs> lines l.
    'l' will contain the number of lines as needed.
    FYI
    The size of this storage area in a field symbols depends on the number of table lines which is not fixed, but determined dynamically at runtime.
    Regards,
    Amit

Maybe you are looking for

  • Creating a site for mobile devices

    Good morning, I have a number of questions relating to the creation of a site for mobile devices. My client has given me the assignment to re-design his current website, and to also create a sub-site suitable for mobiles. I have spent a number of hou

  • ALSA works, but only with one application at a time.

    Hello, Before I continue my post, I would like to say that I have read this section on the wiki: https://wiki.archlinux.org/index.php/AL - ack_Issues It asks the user to edit /etc/asound.conf (which does not exist) in order to comment out a few lines

  • Camera Plus Pro no longer works on OS 7.   Updated to latest version but App will not open.

    The program appears to open, and just when you would expect the shutter to appear and reveal the subject, the program simply closes.  Is anyone else having this problem?

  • Address bar no longer works with manually entered URLs

    Four days ago the address bar stopped working. I am accustomed to manually entering many URLs and hitting 'enter' but although I can still enter URLs as normal, the 'enter' button does not load the relevant page, nor does the green arrow at the end o

  • Last active time of a session

    Oracle 9i. OEM can show (session pero session) the timestamp, each session issued its last activity. How can I know that (last timestamp session activity) using simple SQL statement?