Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Internal table manipulation.....?

Former Member
0 Likes
890

Experts,

Thanks for all the help in building the logic for me in the previous post...Now I have a internal table in which i have four columns: <b>Comp_code Doc_no Fis_year Ledger</b>

the internal table is filled with data like:


Comp_code              Doc_no           Fis_year           Ledger
1001           7000000345                 2007                  L1
1001           7000000345                 2007                  L2
1001           7000000345                 2007                  L3
1001           7000000467                2007                  L1
1001           7000000467                 2007                  L2
1001           7000000467                 2007                  L3

Now i want the data to be present in internal table in this format:


Comp_code              Doc_no           Fis_year           Ledger
1001           7000000345                 2007                  L1
                                                                         L2    
                                                                         L3
2000           7000000467                 2007              L1
                                                                          L2
                                                                          L3

How can i do this...the code for the internal table with this data is as follows:


select bukrs belnr gjahr from BKPF into TABLE t_parked_docs where blart = 'SY'
                                                              and cpudt eq DATE_OF_ENTRY
                                                              and ppnam IS NOT NULL.
  if sy-subrc  = 0.

    select bukrs belnr gjahr from BKPF into table t_posted_docs
                                      for all entries in t_parked_docs
                                      where BUKRS = t_parked_docs-v_comp_code and
                                      BELNR = t_parked_docs-v_doc_no and
                                      GJAHR = t_parked_docs-v_fiscal_year and
                                      BSTAT = ''.

    loop at t_posted_docs into wa_posted_docs.

      select distinct rldnr from faglflexa into (wa_posted_docs-v_ledger)
                                                            where rbukrs = wa_posted_docs-v_comp_code
                                                            and docnr = wa_posted_docs-v_doc_no
                                                            and ryear = wa_posted_docs-v_fiscal_year.
        APPEND wa_posted_docs to t_docs_posted_with_ledger.

      endselect.


    endloop.

Kindly give some suggestions.....

Cheers:

Sam

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
865

Hi,

Sorry..One small change..


DATA: ITAB_FINAL LIKE TABLE OF itab.
DATA: v_ledger LIKE wa-ledger.
DATA: wa_tmp LIKE wa.
 
LOOP AT itab INTO wa.
 
*********** NEW CHANGE
* Move the values to a temporary structure.
  wa_tmp = wa.
*********** NEW CHANGE.

* Move the ledger value to a temporary variable.
  v_ledger = wa-ledger.
 
  AT NEW fis_year.
 
* Move the values to final internal table.
     APPEND wa_tmp TO itab_final.  " Changed here..
 
* Process the next record.
     CONTINUE.
  ENDAT.
 
 
* Clear the structure and just move the ledger.
  CLEAR: wa.
 
  wa-ledger = v_ledger.
 
  APPEND wa TO itab_final.
 
 
ENDLOOP.
 
* Now ITAB_FINAL will have all the values..

Thanks

Naren

9 REPLIES 9
Read only

Former Member
0 Likes
865

Hey Sam,

Didnt this work??

loop at t_docs_posted_with_ledger into wa_posted_docs.

idx = sy-tabix.

wa_posted_docs1 = wa_posted_docs. " Temperory Work Area

if lv_belnr = wa_posted_docs-v_doc_no and sy-tabix ne 1.

clear: wa_posted_docs-v_comp_code, wa_posted_docs-v_doc_no, wa_posted_docs-v_fiscal_year.

modify t_docs_posted_with_ledger INDEX idx transporting wa_posted_docs.

endif.

lv_belnr = wa_posted_docs1-v_doc_no.

endloop.

Read only

0 Likes
865

No Sri...It did not...it is clearing all the values....just leaving the first value...let me try again....

and what is lv_belnr...?

Thanks

Sam

Message was edited by:

Sam williams

Read only

0 Likes
865

hmm...just tweak it a lil..it should work...may be you an debug and see...i am not sure abt the exact field names you have.

Basically the logic i tried is

Loop at itab into wa.

idx = sy-tabix.

*transfer entries into temperory wa.

wa1 = wa.

if lv_belnr = wa-belnr and idx ne 1.

clear wa, except the ledger field.

modify itab index idx transporting wa.

endif.

lv_belnr = wa1-belnr.

endloop.

You can play with it...

Sri

Read only

0 Likes
865

lv_belnr is a variable to store belnr or doc number.

Read only

0 Likes
865

Hey sri,

Thanks for the reply buddy...

Let me tweak with it a little and then will let u know....

ANywayz really want to thak u for ur immediate replies....will definitely let u know...

Thanks

Sam

Read only

Former Member
0 Likes
865

Hi,

Try this..


* create another internal table with the same structure as your data internal table.
* 
DATA: ITAB_FINAL LIKE TABLE OF itab.
DATA: v_ledger LIKE wa-ledger.

LOOP AT itab INTO wa.

* Move the ledger value to a temporary variable.
  v_ledger = wa-ledger.

  AT NEW fis_year.

* Move the values to final internal table.
     APPEND wa TO itab_final.

* Process the next record.
     CONTINUE.
  ENDAT.


* Clear the structure and just move the ledger.
  CLEAR: wa.

  wa-ledger = v_ledger.

  APPEND wa TO itab_final.


ENDLOOP.

* Now ITAB_FINAL will have all the values..

Thanks

Naren

Read only

0 Likes
865

Hi narendara,

thanks for the reply....it worls upto an extent but it doesnt get the ledger for the first time it runs...i mean it is able to get the ledger L2 and L3 but not L1 which is the first row....

Can i try somethin else...

Thanks

Sam

Read only

Former Member
0 Likes
866

Hi,

Sorry..One small change..


DATA: ITAB_FINAL LIKE TABLE OF itab.
DATA: v_ledger LIKE wa-ledger.
DATA: wa_tmp LIKE wa.
 
LOOP AT itab INTO wa.
 
*********** NEW CHANGE
* Move the values to a temporary structure.
  wa_tmp = wa.
*********** NEW CHANGE.

* Move the ledger value to a temporary variable.
  v_ledger = wa-ledger.
 
  AT NEW fis_year.
 
* Move the values to final internal table.
     APPEND wa_tmp TO itab_final.  " Changed here..
 
* Process the next record.
     CONTINUE.
  ENDAT.
 
 
* Clear the structure and just move the ledger.
  CLEAR: wa.
 
  wa-ledger = v_ledger.
 
  APPEND wa TO itab_final.
 
 
ENDLOOP.
 
* Now ITAB_FINAL will have all the values..

Thanks

Naren

Read only

0 Likes
865

Narendara,

It worked for me....i think it shud be fine now...thanks buddy....i am closing this thread for now but will always come back in case of queries....