Skip to Content

Adding a field to a line item table

Hi all,

I have a web dynpro application and have the following code for the checking the line item data of an accounting document

data: lo_nd_t_bseg         TYPE REF TO if_wd_context_node,
      lo_el_t_bseg         TYPE REF TO if_wd_context_element,
      lo_nd_tbseg          TYPE REF TO if_wd_context_node,
      lo_el_tbseg          TYPE REF TO if_wd_context_element,
      lt_el_tbseg          TYPE wdr_context_element_set,
      lv_bseg              TYPE bseg,
      lt_bseg              TYPE STANDARD TABLE OF bseg,
      wa_bseg              TYPE bseg,


LOOP AT lt_el_tbseg INTO lo_el_tbseg.
    lo_el_tbseg->get_static_attributes(
                           IMPORTING static_attributes = lv_bseg ).
  wa_document_header-bus_act     = 'RFBU'.
        wa_document_header-username    = sy-uname.
        wa_document_header-header_txt  = lv_bktxt.
        wa_document_header-comp_code   = 'UC'.
        wa_document_header-doc_date    = lv_budat.
        wa_document_header-pstng_date  = lv_bldat.

        lw_accountgl-itemno_acc     = lv_bseg-buzei.
        lw_accountgl-gl_account     = lv_bseg-saknr.
        lw_accountgl-bus_area       = lv_bseg-gsber.
        lw_accountgl-func_area      = lv_bseg-fkber.
        lw_accountgl-vendor_no      = lv_bseg-lifnr.
        lw_accountgl-costcenter     = lv_bseg-kostl.
        lw_accountgl-fund           = lv_bseg-geber.
        lw_accountgl-orderid        = lv_bseg-aufnr.
	lw_accountgl-func_area_long = lv_bseg-fkber.
        lw_accountgl-res_doc        = lv_bseg-kblnr.
        APPEND lw_accountgl TO i_accountgl.
      wa_bseg = lv_bseg.
      APPEND wa_bseg TO lt_bseg.
      CLEAR: wa_bseg, lv_bseg.
      ENDLOOP.
    lo_nd_t_bseg = wd_context->path_get_node( path = `ZPRELIMINARY_POSTING.CHANGING.T_BSEG` ).
* get element via lead selection
    lo_el_t_bseg = lo_nd_t_bseg->get_element( ).

    lo_nd_t_bseg->bind_table( lt_bseg ).

CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
      EXPORTING
        documentheader = wa_document_header
      TABLES
        accountgl      = i_accountgl
        return         = t_return.
    DESCRIBE TABLE lt_bseg LINES lv_lines.
    lv_lines = 10 - lv_lines.
    CLEAR wa_bseg.
*    clear w_txt20.

    DO lv_lines TIMES.
      APPEND wa_bseg TO lt_bseg.
    ENDDO.
    lo_nd_tbseg->bind_elements( lt_bseg ).

now there is a new requirement where I need to add another field to the line item table but that field is not a part of the table BSEG, actually it's SKAT-TXT20, so add this field I amde the following changes to the application.

I created a node gl_txt and added an attribute to it 'text', the cardinality for this is 1:1 and selection is 0:1. and I amde the follwoing changes to the above code:

I am having some issue with the space.... I am gonna put rest in my following reply to this

Edited by: rajatg on Jul 21, 2011 6:18 PM

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Jul 21, 2011 at 04:19 PM
    LOOP AT lt_el_tbseg INTO lo_el_tbseg.
        lo_el_tbseg->get_static_attributes(
                               IMPORTING static_attributes = lv_bseg ).
      
    select single txt20 from skat
                          into w_txt
                          where saknr = lv_bseg-saknr
                          and   SPRAS = 'EN'.
    
    lo_nd_gl_text = wd_context->get_child_node( name = wd_this->wdctx_gl_text ).
    
    *   @TODO handle non existant child
    *   IF lo_nd_gl_text IS INITIAL.
    *   ENDIF.
    
    *   get element via lead selection
        lo_el_gl_text = lo_nd_gl_text->get_element( ).
    
    *   @TODO handle not set lead selection
        IF lo_el_gl_text IS INITIAL.
        ENDIF.
    
    *   @TODO fill attribute
    *   lv_text = 1.
    
    *   set single attribute
        lo_el_gl_text->set_attribute(
          name =  `TEXT`
          value = w_txt ).
    
    wa_document_header-bus_act     = 'RFBU'.
            wa_document_header-username    = sy-uname.
            wa_document_header-header_txt  = lv_bktxt.
            wa_document_header-comp_code   = '001'.
            wa_document_header-doc_date    = lv_budat.
            wa_document_header-pstng_date  = lv_bldat.
    
            lw_accountgl-itemno_acc     = lv_bseg-buzei.
            lw_accountgl-gl_account     = lv_bseg-saknr.
            lw_accountgl-bus_area       = lv_bseg-gsber.
            lw_accountgl-func_area      = lv_bseg-fkber.
            lw_accountgl-vendor_no      = lv_bseg-lifnr.
            lw_accountgl-costcenter     = lv_bseg-kostl.
            lw_accountgl-fund           = lv_bseg-geber.
            lw_accountgl-orderid        = lv_bseg-aufnr.
    	lw_accountgl-func_area_long = lv_bseg-fkber.
            lw_accountgl-res_doc        = lv_bseg-kblnr.
            APPEND lw_accountgl TO i_accountgl.
          wa_bseg = lv_bseg.
          APPEND wa_bseg TO lt_bseg.
          CLEAR: wa_bseg, lv_bseg.
          ENDLOOP.
        lo_nd_t_bseg = wd_context->path_get_node( path = `ZPRELIMINARY_POSTING.CHANGING.T_BSEG` ).
    * get element via lead selection
        lo_el_t_bseg = lo_nd_t_bseg->get_element( ).
    
        lo_nd_t_bseg->bind_table( lt_bseg ).
    
    CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
          EXPORTING
            documentheader = wa_document_header
          TABLES
            accountgl      = i_accountgl
            return         = t_return.
        DESCRIBE TABLE lt_bseg LINES lv_lines.
        lv_lines = 10 - lv_lines.
        CLEAR wa_bseg.
    *    clear w_txt20.
    
        DO lv_lines TIMES.
          APPEND wa_bseg TO lt_bseg.
        ENDDO.
        lo_nd_tbseg->bind_elements( lt_bseg ).

    but now when I run my application and key in a g/l account numner and call the above code... the g/l text field get's filled for all the line items with teh same text ...i.e. the text for the g/l that i entered on the first line item.

    Can you please tell me how can I achieve this

    Thanks,

    Edited by: rajatg on Jul 21, 2011 6:19 PM

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Raja,

      Sorry i have not gone your complete code. As my understanding is correct you want to add one more field to line item table.

      Try like this... Loop line item table..

      Loop It to WA.

      wa-field = new-field.

      append. // if not works.

      or modify it to wa transporting new-field.

      endloop.

      By using above code new field will be added to same table.

      Cheers,

      Kris.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.