cancel
Showing results for 
Search instead for 
Did you mean: 

Get and Set data in context

Former Member
0 Kudos

Hello Everyone,

I am new to Webdynpro ABAP world. I have got a requirement where I need to get data from a value node "Document" created by me and Assign the values to three different nodes during runtime on Action of a Button. My context structure is as follows. Please help me by giving some code for my requirement. I would appreciate your help.

-


Context Structure----


Context

---DocumentHeader(Model Node)

---AccountGL(Model Node)

---AccountPayable(Model Node)

---CurrencyAmount(Model Node)

---Document(Value Node)

-


AMT_DOCCUR(Value Attribute)

-


Costcenter(Value Attribute)

-


GL_Account(Value Attribute)

-


Header_Txt(Value Attribute)

-


Ref_Doc_No(Value Attribute)

-


Vendor_No(Value Attribute)

The "Document" node is bound to a Table in "Main_Document" view and the document table is filled with data during runtime. I want to get the values of the attributes from Document node and assign them to other Model nodes that are bound to a BAPI.

Please help me with some code to acheive this requirement. I would appreciate your help.

I hope you can understand my requirement. Please do let me know if my explanation is not clear and I will try to explain in more detail.

Regards,

Gopal.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

If i understood it correct then u want to read all the records of DOCUMENT node and then bind the values to other Model Nodes.

1. To get all the elements of DOCUMENT node.

data lo_nd_document type ref to if_wd_context_node.

data lo_el_document type ref to if_wd_context_element.

data lt_el_document type wdr_context_element_set.

data ls_document type wd_this->element_document.

data lt_document type wd_this->elements_document.

get a ref to the document node

lo_nd_document = wd_this->get_child_node( name = wd_this->wdctx_document ).

lt_el_document = lo_nd_document->get_elements().

loop at lt_el_document into ls_el_document.

lo_el_document->get_static_attributes(

importing

static_attributes = ls_document ).

append ls_document to lt_document.

endloop.

at the end of this loop u will have all the elements of document node.

2. bind the values to other model node.

if the other model node has the same context structure as document then u can use lt_document directly to bind it to them

else you need to get the table and line type of other nodes and then fill them using the values from lt_document.

finally after u have ur table ready u can bind then to the node using bind_table method.

get the reference of the node u want to bind data to and then use

lo_nd_model->bind_table ( lt_model_table ).

I hope this helps.

Thanks,

Abhishek

Former Member
0 Kudos

Hi Gopal,

You can proceed as abhishek suggested. I think we can make this code more simple as below.

data lo_nd_document type ref to if_wd_context_node.

data lt_el_document type wdr_context_element_set.

data lt_document type wd_this->elements_document.

"get a ref to the document node

lo_nd_document = wd_this->get_child_node( name = wd_this->wdctx_document ).

lt_el_document = lo_nd_document->get_elements().

lt_el_document->get_static_attributes_table(

importing

table = lt_document ).

If you have similar attributes in the other Model Nodes, you can do Move-Corresponding from lt_document to DocumentHeader or AccountGL or AmountPayable or CurrenyAmount.

Now you can proceed with your BAPI.

I think this will help you.

Regards,

Raju J

Former Member
0 Kudos

Hi Abhishek,

Thanks a lot for your reply. My context is as follows:-

-


Context Structure----


Context

---DocumentHeader(Model Node)

-


Header_Txt(Model Attribute)

-


Ref_Doc_No(Model Attribute)

---AccountGL(Model Node)

-


GL_Account(Model Attribute)

-


Costcenter(Model Attribute)

---AccountPayable(Model Node)

-


Vendor_no(Model Attribute)

---CurrencyAmount(Model Node)

-


AMT_DOCCUR(Model Attribute)

---Document(Value Node)

-


AMT_DOCCUR(Value Attribute)

-


Costcenter(Value Attribute)

-


GL_Account(Value Attribute)

-


Header_Txt(Value Attribute)

-


Ref_Doc_No(Value Attribute)

-


Vendor_No(Value Attribute)

Now, as I explained before, the Document node and its attributes are created by me in the View Context and a table UI Element is bound to this table node. At runtime the table is filled and when we click on a button the attribute values from the Document node should be "set" to the corresponding Model nodes which are binded to the Component Controller Context (i.e BAPI). Please let me know about this. I am new to ABAP, so I am having little difficulty. I greatly appreciate your help.

Meanwhile, when I am trying to use your code it is showing the following error message

"GET_CHILD_NODE" is unknown or PROTECTED or PRIVATE.

Regards,

Gopal.

Edited by: Gopal on Sep 1, 2009 11:26 AM

Former Member
0 Kudos

Hi,

Why donot use the code wizard to set the attribute value.

You will get the generated code right.

or

DATA:

lr_doc type ref to if_wd_context_node,

lr_bapi type ref to if_wd_context_node,

lr_element type ref to if_wd_context_element.

lr_bapi = wd_context->get_child_node ( name = 'BAPI_S' ).

if lr_bapi is not initial.

lr_doc = lr_bapi->get_child_node( name = 'DOCUMENT ').

if lr_doc is not initial.

lr_element = lr_doc->get_element( index = 1). "Pass the correct index numeber

if cardinality of DOCUMENT node is 0:N or 1:N.

lr_element->set_attribute

name = 'VAL'

value = '10'.

endif.

endif.

Regards,

Lekha.

Former Member
0 Kudos

Hi Lekha,

Thanks a lot for your suggestion. Well, as I said, I am very new to ABAP and I am a WD Java developer trying to use WD ABAP for a special functionality. So, I am a bit strugling with it. Apologies for you forum members for any inconvenience. I will try your code and will get back to you soon.

Regards,

Gopal.

Former Member
0 Kudos

Hi,

We are here to help you.

Just try to use the code wizard, choose SET radiobutton and place the cursor on wich you want to set the value.

Code wil be generated.

Former Member
0 Kudos

Hi Lekha,

I tried using the code wizard to get/set the attibutes and got the following code automatically. Could you suggest me about what is the code I need to add to the following code to meet my requirements. I would greatly appreciate your help.


method ONACTIONPOSTDOCUMENT .

    DATA lo_nd_document TYPE REF TO if_wd_context_node.
    DATA lo_el_document TYPE REF TO if_wd_context_element.
    DATA ls_document TYPE wd_this->element_document.
*   navigate from <CONTEXT> to <DOCUMENT> via lead selection
    lo_nd_document = wd_context->get_child_node( name = wd_this->wdctx_document ).

*   @TODO handle not set lead selection
    IF lo_nd_document IS INITIAL.
    ENDIF.

*   get element via lead selection
    lo_el_document = lo_nd_document->get_element(  ).

*   @TODO handle not set lead selection
    IF lo_el_document IS INITIAL.
    ENDIF.

*   get all declared attributes
    lo_el_document->get_static_attributes(
      IMPORTING
        static_attributes = ls_document ).
endmethod.

Meanwhile, I did not find any SET Radiobutton in the Code Wizard. I cna only see "READ Node/Attribute" radiobutton. Where can I find the SET Radiobutton?

Regards,

Gopal.

Edited by: Gopal on Sep 1, 2009 12:09 PM

Former Member
0 Kudos

Hi,

Hope you might have this code in the button handler as you specified.

SET radiobutton is available in latest version of Netweaver.

What is the cardinality of the DOCUMENT node.

method ONACTIONPOSTDOCUMENT .
 
    DATA lo_nd_document TYPE REF TO if_wd_context_node.
    DATA lo_el_document TYPE REF TO if_wd_context_element.
    DATA ls_document TYPE wd_this->element_document.
*   navigate from <CONTEXT> to <DOCUMENT> via lead selection
    lo_nd_document = wd_context->get_child_node( name = wd_this->wdctx_document ).
 
*   @TODO handle not set lead selection
    IF lo_nd_document IS  not INITIAL.
*   get element via lead selection
    lo_el_document = lo_nd_document->get_element(  ). "If caridnality if 1:1 this works fine else error is thrown
    ENDIF. 

*   @TODO handle not set lead selection
    IF lo_el_document IS not INITIAL.

*GOTO PATTERN BUTTON, ABAP OBJECTS->GIVE THE INSTANCE NAME AS 
* LO_EL_DOCUMENT
*CLASS-IF_WD_CONTEXT_ELEMENT
*SET_ATTRIBUTE

    lo_el_document->set_attribute(
        name = `AMT_DOCCUR`      "Attribute name that you want to set
        value = lv_doccur ).  "Declare variable  


*   get all declared attributes
    lo_el_document->get_static_attributes(
      IMPORTING
        static_attributes = ls_document ).  "This is not required.
    ENDIF.

endmethod.

Former Member
0 Kudos

Hi Lekha,

The Document node is bind to a Table UI Element and its cardinality is 0..n. The Document table might have "n" no. of rows which will be decided at runtime. I need to get each attribute value of each row and set the values to the attributes in the other nodes as mentioned in the context of my previous post. Please have a look at my context.

-


Context Structure----


Context

---Document(Value Node)

-


AMT_DOCCUR(Value Attribute)

-


Costcenter(Value Attribute)

-


GL_Account(Value Attribute)

-


Header_Txt(Value Attribute)

-


Ref_Doc_No(Value Attribute)

-


Vendor_No(Value Attribute)

---DocumentHeader(Model Node)

-


Header_Txt(Model Attribute)

-


Ref_Doc_No(Model Attribute)

---AccountGL(Model Node)

-


GL_Account(Model Attribute)

-


Costcenter(Model Attribute)

---AccountPayable(Model Node)

-


Vendor_no(Model Attribute)

---CurrencyAmount(Model Node)

-


AMT_DOCCUR(Model Attribute)

I need to get the value from Document node and set it the attributes in nodes "DocumentHeader", "AccountGL", "AccountPayable", "CurrencyAmount" for every row in the table.

Do you understand my requirement. Please, do let me know if you need any more explanation I would appreciate your help.

Regards,

Gopal.

Former Member
0 Kudos

Hi, You can use the following code to read the contents of the Document node

DATA lo_nd_document TYPE REF TO if_wd_context_node.
 DATA lt_document TYPE wd_this->elements_document.

*   navigate from <CONTEXT> to <DOCUMENT> via lead selection
    lo_nd_document = wd_context->get_child_node( name = wd_this->wdctx_document ).
 
* get the contents of  the document node in an internal table
    lo_nd_document->get_static_attributes_table(  importing table = lt_documents ).
Now loop at this internal table lt_documents and fill the rest of your nodes. Regards, Radhika.

Former Member
0 Kudos

Hi Radhika,

Thanks for your reply.

Now, once I get the contents of the "Document" node into the "lt_documents" variable of your code how do I set the value of attribute "Vendor_no" of the "AccountPayable(Model Node)" node with the value of "Vendor_no" attribute of the "Document(Value Node)" node.

Can you give me the code for Looping at the internal table and filling the rest of the nodes please. I would greatly appreciate your help.

Regards,

Gopal.

Edited by: Gopal on Sep 1, 2009 12:55 PM

Former Member
0 Kudos

Hi, I am assuming that all your nodes have cardinality 0:n or 1:n. Append the following code;

data: nd_AccountPayable type ref to if_wd_context_node.
data: lt_AccountPayable type wd_context->elements_AccountPayable.
data: ls_AccountPayable type wd_context->element_AccountPayable.

loop at lt_documents into ls_documents.
ls_AccountPayable-Vendor_no = ls_documents-Vendor_no.
append ls_AccountPayable to lt_AccountPayable.
"similarty fill other internal tables
endloop.

" now bind the data to nodes.
nd_AccountPayable = wd_context->get_child_node( 'ACCOUNTPAYABLE'  ).
nd_AccountPayable->bind_table( lt_AccountPayable ).
Radhika.

Former Member
0 Kudos

Hi Radhika,

Thanks a lot for the code. Would this code work if the "Document" node has got more than one rows i.e., because the Document node is bound to a Table UI Element and the number of rows will only be decided at runtime.

Once again thank you very much for your help.

Regards,

Gopal.

Former Member
0 Kudos

That is what i said earlier that this code will work only if the the cardinality of all the nodes is 0:n. 0:n cardinality is generally used in cases where we have multiple records. Check this link for info on Cardinality [http://help.sap.com/saphelp_erp2005/helpdata/EN/7a/787e40417c6d1de10000000a1550b0/content.htm] Let me know if you have any questions. Regards, Radhika.

Former Member
0 Kudos

Hi Radhika,

Thanks for your reply. Yes every node is of cardinality 0..n apart from "DocumentHeader" which is 1..1.

My scenario is as follows:-

I need to get the values from each row of the Document table and fill them in to the corresponding attributes of the other nodes. Then after each row, I should execute the "BAPI_ACC_DOCUMENT_POST" BAPI. After the first row, the control should go to the second row of the "Document" table and then fill the corresponding nodes freshly and then execute the BAPI again.

Now, I have a special requirement within this again. The "AMT_DOCCUR" attribute should be filled twice in the "CurrencyAmount" node.

I hope you understand my requirement. I am sorry if I am asking too many questions. I am new to ABAP and I have done this requirement in WD JAVA and needed some special functinality which is available in WD ABAP.

Thanks very much for your support and help again.

Regards,

Gopal.

Former Member
0 Kudos

Hi,

Is DocumentHeader(Model Node) has cardinality 1:1.

Have you got the 2 tables one for header and one for item.

How are you passing the header fields( User input).

First get the values of DOCUMENTHEADER as it is 1:1 carindlaity use the code wizard

which returns the record using the GET_STATIC_ATTRIBUTES

Pass this to the BAPI method.

I guess the document table is bound to the DOCUMENT(value node) right

and for this TABLE UI element is designed.

Implement the event OnLEADSELECT for this table.

In this you will have to read the node again to get the leadselection record.

Pass this to the BAPI method.

Now for each selection, the BAPI mehtod gets called.

How is Layout designed.

Regards,

Lekha.

Edited by: Lekha on Sep 1, 2009 5:29 PM

Former Member
0 Kudos

Hi Lekha,

The UI will only have one Table UI Element which is bind to the "Document" node. This node contains all the attributes that need to be filled by the user. Then I need to fill the DocumentHeader node at runtime. In the BAPI "DOCUMENTHEADER" is an IMPORTING component and the rest of my nodes belong to the tables tab.

DocumentHeader has a cardinality 1..1

Say for example, the user enters 5 rows in the table. Then, we need to execute the BAPI 5 times. i.e., everytime after each row. So that 5 documents gets created for 5 different rows.

regards,

Gopal.

Edited by: Gopal on Sep 1, 2009 2:04 PM

Former Member
0 Kudos

Hi, If i understand your requirements correctly, your are creating nodes DOCUMENTHEADER, ACCOUNTPAYABLE, etc just to pass it to the BAPI and for each run this data will be refreshed with the new entry in the Documents node. If what i understand is correct, you do not require to create nodes for DOCUMENTHEADER, ACCOUNTPAYABLE, etc Just declare the internal tables in your code and fill it and pass it to the BAPI. If you want an entry twice. write the append statement twice. Radhika.

Former Member
0 Kudos

Try using the following code.

Data: ls_documentheader type DOCUMENTHEADER,
      lt_accountpayable type table of BAPIACAP09.
      ls_accountpayable type BAPIACAP09.
      lt_currencyamount type table of BAPIACCR09,
      ls_currencyamount type BAPIACCR09.

" once you have read the data from documnets node ( i have given code in previous reply )
loop at lt_documents into ls_documents.

" header data
ls_documentheader-HEADER_TXT = ls_documents-fieldname.

" accounts payable data
ls_accountpayable-vendor_no = ls_documents-vendor_no.
append ls_accountpayable to lt_accountpayable.

" Currency items
ls_currencyamount-AMT_DOCCUR = ls_documents-feildname
append ls_currencyamount to lt_currencyamount.
" if you wnat to the same entry twice
append ls_currencyamount to lt_currencyamount.

" similarly fill all required tables to be passed to the BAPI.
" Once tables are filled call the BAPI and passed required tables

" Use BAPI_COMMIT work after calling the BAPI.

" Now refresh all the tables before the next recoed
refresh: lt_accountpayable,lt_accountpayable.
clear:ls_documentheader,ls_accountpayable,ls_accountpayable.

" Note: Be careful, donot refresh lt_documents
endloop.
Hope this helps! Regards, Radhika.

Former Member
0 Kudos

Hi Radhika,

Thats a great help.


" Currency items
ls_currencyamount-AMT_DOCCUR = ls_documents-feildname
append ls_currencyamount to lt_currencyamount.
" if you wnat to the same entry twice
append ls_currencyamount to lt_currencyamount.

Within the above code, I want the AMT_DOCCUR entry twice but, the second entry should be the negative value of "AMT_DOCCUR" value that the user enters. Is this possible?

Regards,

Gopal.

Former Member
0 Kudos

" Currency items
ls_currencyamount-AMT_DOCCUR = ls_documents-feildname
append ls_currencyamount to lt_currencyamount.

" negation entry (multiply by -1 )
clear append ls_currencyamount.
ls_currencyamount-AMT_DOCCUR = ls_documents-feildname * -1.
append ls_currencyamount to lt_currencyamount.
Regards, Radhika.

Former Member
0 Kudos

Hi Radhika,


loop at lt_documents into ls_documents.

I am getting a error saying ls_documents is unknown. How should I declare the ls_documents variable?

Sorry for this simple question. As I said I am very new to ABAP.

Regards,

Gopal.

Former Member
0 Kudos

Hi,

When you read the node-> you will get this variable being decalred.

or

declare the ls_documents of the type the BAPI expects.

Former Member
0 Kudos

Hi Lekha,

My entire code is as follows. Please advise me where and how should I declare the "ls_documents" variable. I would appreciate your help.


method ONACTIONPOSTDOCUMENT .

  DATA lo_nd_document TYPE REF TO if_wd_context_node.
  DATA lt_documents TYPE wd_this->elements_document.

*   navigate from <CONTEXT> to <DOCUMENT> via lead selection
  lo_nd_document = wd_context->get_child_node( name = wd_this->wdctx_document ).

* get the contents of  the document node in an internal table
  lo_nd_document->get_static_attributes_table(  importing table = lt_documents ).

  Data: ls_documentheader type BAPIACHE09,
        lt_accountpayable type table of BAPIACAP09,
        ls_accountpayable type BAPIACAP09,
        lt_accountGL type table of BAPIACGL09,
        ls_accountGL type BAPIACGL09,
        lt_currencyamount type table of BAPIACCR09,
        ls_currencyamount type BAPIACCR09.

  loop at lt_documents into ls_documents.

* header data
    ls_documentheader-HEADER_TXT = ls_documents-HEADER_TXT.
    ls_documentheader-Ref_Doc_No = ls_documents-Ref_Doc_No.

* accounts payable data
    ls_accountpayable-vendor_no = ls_documents-vendor_no.
    append ls_accountpayable to lt_accountpayable.

* account GL data
    ls_accountGL-GL_Account = ls_documents-GL_Account.
    ls_accountGL-Costcenter = ls_documents-Costcenter.
    append ls_accountGL to lt_accountGL.

* Currency items
    ls_currencyamount-AMT_DOCCUR = ls_documents-feildname
    append ls_currencyamount to lt_currencyamount.

    clear append ls_currencyamount.
    ls_currencyamount-AMT_DOCCUR = ls_documents-feildname * -1.
    append ls_currencyamount to lt_currencyamount.

    DATA lo_COMPONENTCONTROLLER TYPE REF TO IG_COMPONENTCONTROLLER .
    lo_COMPONENTCONTROLLER =   wd_this->get_componentcontroller_ctr( ).

    lo_componentcontroller->execute_bapi_acc_document_post(
    ).
    DATA lo_COMPONENTCONTROLLER TYPE REF TO IG_COMPONENTCONTROLLER .
    lo_COMPONENTCONTROLLER =   wd_this->get_componentcontroller_ctr( ).

    lo_componentcontroller->execute_bapi_transaction_commi(
    ).

* Refresh all the tables before the next recoed
    refresh: lt_accountpayable,lt_accountpayable.
    clear:ls_documentheader,ls_accountpayable,ls_accountpayable.

  endloop.
endmethod.

Edited by: Gopal on Sep 1, 2009 3:47 PM

Former Member
0 Kudos
Declare,
  DATA ls_documents TYPE wd_this->element_document.
Former Member
0 Kudos

Hi Radhika,

I have given the code in the "onActionPostDocument" method and tried to execute the application. but, it is not working when I give the input values into and execute the application.

I tired to debug the application and saw that, within the code the values from the context of the View controller are not getting transferred to the controller context. Because, in the code we have mapped the values to the Tables but not to the context nodes. Do, you understand what I mean? I think the problem is at the following lines of code.


Data: 
lt_documentheader type table of BAPIACHE09
lt_accountpayable type table of BAPIACAP09,
lt_accountGL type table of BAPIACGL09,
lt_currencyamount type table of BAPIACCR09.

within the code, we have not mentioned any where that we are assiging the values to a node e.g "AccountGL".

we are assigining the values to the internal table instead of assigning them to the context node!!!!

Please let me know if you can understand where we are going wrong. I would appreciate your help.

Regards,

Gopal.

Edited by: Gopal on Sep 1, 2009 6:38 PM

Edited by: Gopal on Sep 2, 2009 10:32 AM

Former Member
0 Kudos

Hi Radhika/Lekha,

Can you please help me with my problem as mentioned in my earlier post. I would appreciate your help.

Regards,

Gopal.

Edited by: Gopal on Sep 2, 2009 10:22 AM

Former Member
0 Kudos

Hi Gopal,

After you have the data in the internal tables you need to bind them to the respective nodes using the BIND_TABLE stattement.

Regards,

Lekha.

Former Member
0 Kudos

Hi Lekha,

Thanks for your prompt reply. The following is my code, could you please tell me, how do I give the BIND_TABLE statement as I am new to ABAP. I would appreciate your help.


method ONACTIONPOSTDOCUMENT .
 
  DATA lo_nd_document TYPE REF TO if_wd_context_node.
  DATA lt_documents TYPE wd_this->elements_document.
 
*   navigate from <CONTEXT> to <DOCUMENT> via lead selection
  lo_nd_document = wd_context->get_child_node( name = wd_this->wdctx_document ).
 
* get the contents of  the document node in an internal table
  lo_nd_document->get_static_attributes_table(  importing table = lt_documents ).
 
  Data: ls_documentheader type BAPIACHE09,
        lt_accountpayable type table of BAPIACAP09,
        ls_accountpayable type BAPIACAP09,
        lt_accountGL type table of BAPIACGL09,
        ls_accountGL type BAPIACGL09,
        lt_currencyamount type table of BAPIACCR09,
        ls_currencyamount type BAPIACCR09.
 
  loop at lt_documents into ls_documents.
 
* header data
    ls_documentheader-HEADER_TXT = ls_documents-HEADER_TXT.
    ls_documentheader-Ref_Doc_No = ls_documents-Ref_Doc_No.
 
* accounts payable data
    ls_accountpayable-vendor_no = ls_documents-vendor_no.
    append ls_accountpayable to lt_accountpayable.
 
* account GL data
    ls_accountGL-GL_Account = ls_documents-GL_Account.
    ls_accountGL-Costcenter = ls_documents-Costcenter.
    append ls_accountGL to lt_accountGL.
 
* Currency items
    ls_currencyamount-AMT_DOCCUR = ls_documents-feildname
    append ls_currencyamount to lt_currencyamount.
 
    clear append ls_currencyamount.
    ls_currencyamount-AMT_DOCCUR = ls_documents-feildname * -1.
    append ls_currencyamount to lt_currencyamount.
 
    DATA lo_COMPONENTCONTROLLER TYPE REF TO IG_COMPONENTCONTROLLER .
    lo_COMPONENTCONTROLLER =   wd_this->get_componentcontroller_ctr( ).
 
    lo_componentcontroller->execute_bapi_acc_document_post(
    ).
    DATA lo_COMPONENTCONTROLLER TYPE REF TO IG_COMPONENTCONTROLLER .
    lo_COMPONENTCONTROLLER =   wd_this->get_componentcontroller_ctr( ).
 
    lo_componentcontroller->execute_bapi_transaction_commi(
    ).
 
* Refresh all the tables before the next recoed
    refresh: lt_accountpayable,lt_accountpayable.
    clear:ls_documentheader,ls_accountpayable,ls_accountpayable.
 
  endloop.
endmethod.

Regards

Gopal.

Former Member
0 Kudos

---AccountGL(Model Node) - table lt_accountgl should be bound to this.

---AccountPayable(Model Node)- lt_account_payaable

---CurrencyAmount(Model Node)-lt_cuurency_amt

As per your code, read the above nodes and bind the tables to respective nodes.

method ONACTIONPOSTDOCUMENT .
 
  DATA lo_nd_document TYPE REF TO if_wd_context_node.
  DATA lt_documents TYPE wd_this->elements_document.
 

  DATA lo_nd_accountgl TYPE REF TO if_wd_context_node.


*   navigate from <CONTEXT> to <DOCUMENT> via lead selection
  lo_nd_document = wd_context->get_child_node( name = wd_this->wdctx_document ).
  lo_nd_accountgl = wd_context->get_child_node( name = wd_this->wdctx_accountgl ).---acountGL node
 
* get the contents of  the document node in an internal table
  lo_nd_document->get_static_attributes_table(  importing table = lt_documents ).
 
  Data: ls_documentheader type BAPIACHE09,
        lt_accountpayable type table of BAPIACAP09,
        ls_accountpayable type BAPIACAP09,
        lt_accountGL type table of BAPIACGL09,
        ls_accountGL type BAPIACGL09,
        lt_currencyamount type table of BAPIACCR09,
        ls_currencyamount type BAPIACCR09.
 
  loop at lt_documents into ls_documents.
 
* header data
    ls_documentheader-HEADER_TXT = ls_documents-HEADER_TXT.
    ls_documentheader-Ref_Doc_No = ls_documents-Ref_Doc_No.
 
* accounts payable data
    ls_accountpayable-vendor_no = ls_documents-vendor_no.
    append ls_accountpayable to lt_accountpayable.
 
* account GL data
    ls_accountGL-GL_Account = ls_documents-GL_Account.
    ls_accountGL-Costcenter = ls_documents-Costcenter.
    append ls_accountGL to lt_accountGL.
 
lo_nd_accountgl->bind_table( lt_accountgl ).  -----------Similarly do for other 2 nodes.

.

  • Currency items

ls_currencyamount-AMT_DOCCUR = ls_documents-feildname

append ls_currencyamount to lt_currencyamount.

clear append ls_currencyamount.

ls_currencyamount-AMT_DOCCUR = ls_documents-feildname * -1.

append ls_currencyamount to lt_currencyamount.

DATA lo_COMPONENTCONTROLLER TYPE REF TO IG_COMPONENTCONTROLLER .

lo_COMPONENTCONTROLLER = wd_this->get_componentcontroller_ctr( ).

lo_componentcontroller->execute_bapi_acc_document_post(

).

DATA lo_COMPONENTCONTROLLER TYPE REF TO IG_COMPONENTCONTROLLER .

lo_COMPONENTCONTROLLER = wd_this->get_componentcontroller_ctr( ).

lo_componentcontroller->execute_bapi_transaction_commi(

).

  • Refresh all the tables before the next recoed

refresh: lt_accountpayable,lt_accountpayable.

clear:ls_documentheader,ls_accountpayable,ls_accountpayable.

endloop.

endmethod

Edited by: Lekha on Sep 2, 2009 2:34 PM

Former Member
0 Kudos

Thanks Lekha. I'll try that and will let you know about it.

Regards,

Gopal.

Former Member
0 Kudos

You can see the changes ACCOUNTGL node is bound to a table....As the code is not clearly pasted..Pls check in detail.

Former Member
0 Kudos

Hi Lekha,

How do I bind the data of the Header to the "documentheader" component. Because, it is of cardinality 1..1 and it is not a table I cannot do the following step, isn't it?


append ls_documentheader to lt_documentheader.

And if I give the above statement and give the below statement as you said it is throwing an exception saying the cardinality of the documentheader is violated and cannot add element to the node.


lo_nd_documentheader>bind_table( lt_documentheader).

i.e How do I bind the data if the data is not in an internal table and the cardinality of the node is 1..1??

Do you understand what I mean? please let me know if you need more clarification. I greatly appreciate your help.

Regards,

Gopal Yarlagadda.

Edited by: Gopal on Sep 2, 2009 11:33 AM

Former Member
0 Kudos

Are the nodes that I specied above(accountgl, currency amount)...are under the document header or under the root context.

If they are under the document header, are they the attributes/subnodes under it.

The tables accountgl, currencyamont should be bound to which nodes.....

Document, document header 2 are there right.

Former Member
0 Kudos
lo_nd_documentheader>set_static_attributes( exporting static_attributes = ls_documentheader )
Former Member
0 Kudos

Hi Radhika/Lekha,

I thank you very much for your help and support. Now, when I debug the application I can see the values getting transferred in to the context of the component controller, which is very good.

But, I have got another new issue with this application. When I run the application, it opens the browser and the only UI Element I have is a table as shown in the following screenshot. My rpobelm is,

http://i26.tinypic.com/rm00ht.jpg

"By default it is adding 10 rows and if I use only 2 or 3 rows, when the program is reading the context at runtime it is reading all the rows instead of stoping after the last row I entered". In WD java, I had the same situation and I resolved it by giving a condition at the begining of the loop to check for "null" in every row. So, if a particular row is null it would not go into the loop".

Is there any way that we can add a condition into the loop to check if the row is empty?

Please let me know if you need more clarification. I appreciate your help.

Regards,

Gopal.

Former Member
0 Kudos

Yes you can add a WHERE condition in the LOOP statement. if you have any key field that will always be filled then you can code as follows;

LOOP AT  lt_documents INTO ls_documents WHERE field1 IS NOT INITIAL.

 ENDLOOP.
But can you debug and find out at which point are these 10 rows getting appended ? How are you filling this table control? Radhika

Former Member
0 Kudos

Hi Radhika,

Thanks for your help. That piece of code helped me. Is there any way I can put a condition to check any field of the particular row is "NULL" and it throws an error message prompting the user to enter the values in that field?

Can you also tell me how to hardcode an inputfield value?

Regards,

Gopal Yarlagadda.

Former Member
0 Kudos

Hi,


DATA: lt_eleset type WDR_CONTEXT_ELEMENT_SET,
ls_eleset type ref to if_wd_context_element.

lt_eleset = lo_nd_document_header->get_elements.

loop at lt_eleset into ls_eleset. 

ls_eleset->get_statitc_attributes
importing
static_attributes = ls_document


if ls_document-account is initial.
*Instantiate message mansger

lr_msg_mgr->report_attribute_error_message  

attribute_name = 'ACCOUNT'
element = ls_eleset
msg = 'Cannot be Initial'

endif.

endloop.

Regards,

Lekha.

Edited by: Lekha on Sep 2, 2009 6:58 PM

Former Member
0 Kudos

Lekha,

Could also tell me how to hardcode an inputfield or a table column in my case?

Regards,

Gopal Yarlagadda.

Former Member
0 Kudos

Could also tell me how to hardcode an inputfield or a table column in my case?
Do you mean that you want to bydefault display some value in the Input field or a row in a table ? Regards, Radhika.

Former Member
0 Kudos

Hi,

In the TABLE for any column,

While looping the table you can hardcode the values right.

Or

For input field which is not a part of table then,

That Input field to bound to context attribute then

use the

wd_context->set_attribute->

name = 'NUM'

value = 10.

For which columns you want to set the values.

Or

If you want some mandatory feature to be implemented you can as well do it.

Regards,

Lekha.

Former Member
0 Kudos

Hi Radhika,

Yes I want to display a default value in the inputfield of a row of a table. I know, there is a property of the context attribute "Default Value" where you can specify the default value. I tried giving the default values in that property of the context attributes. but, it is not showing default values when we load the view as shown in the below screenshot.

http://i26.tinypic.com/rm00ht.jpg

I want to default few fields in the table!

Do you why this is happening?

Thanks for your help!

Regards,

Gopal Yarlagadda.

Edited by: Gopal on Sep 2, 2009 3:55 PM

Former Member
0 Kudos

LOOP AT lt_documents INTO ls_documents.

ls_documents-account = '10'. "For ex: if this account column is Input field then

modify lt_documents from ls_documents idnex sy-tabix.

ENDLOOP.

Bind the table to node.

Former Member
0 Kudos

Hi Lekha,

I want the default values as soon as the view loads. So, I need to set the attributes in WDDOINIT method I think Could you tell me how to code the attribute by default?

Former Member
0 Kudos

Hi,

In the table columns for Inout fields you want the default values right.

Where are you Binding the table.

In the WDODOINIT, where you can loop the table and fill the values for those columns and bind the table again.

Regards,

Lekha.

Former Member
0 Kudos

Hi Gopal,

I am assuming all these nodes are part of the same context.

If that is the case and the data is coming at runtime from a table.

Why do you need a value node?

Can't you bind the Model nodes directly with the required table columns.

Please clarify the requirement.

Excuse me if I have understood incorrectly.

Regards,

Sumit

Former Member
0 Kudos

Hi Sumit,

Thanks a lot for your reply. As I mentioned in my previous post, I got to fill different attributes from different nodes in a single Tabke UI Element. So, I created a node and attributes of same type of the model Attributes and then during runtime I want to get the attributes from the document node and then assign them to corresponding attributes in model nodes coming from a BAPI. I hope you can understand my requirement. Please let me know if you need more clarification.

Regards,

Gopal.