‎2008 May 21 4:00 PM
Hi guys,
I'm trying to set up a program that create many buckets to the output files, 1st bucket will stay the same for employee with their personal info like SSN, from 2nd bucket, it will occur many times if that person has many tax type.
The output file looks like this
[_SSN__] [_State_+_Counter____] [__same_____] [__same_____] [__same_____] [__same_____].....
1 2 3 4 5 6 ....
So, for the 2nd bucket, if the work state is Virginia, it will show VA and counter number is 1, in 3rd bucket, if that employee work in California also, the counter should be 2.
Is there any logic that I can integrate in my program?
full points will be awarded!
‎2008 May 21 5:08 PM
Ben,
You can have a internal table within an internal table.
This code has NOT been Tested and provided as an EXAMPLE of how to accomplish your goal.
TABLES: pa0001, pa0002.
DATA:
BEGIN OF itab OCCURS 0,
ssn(9) TYPE c,
BEGIN OF counter OCCURS 0,
state_code(2) TYPE c,
state_count TYPE p,
END OF counter,
END of ITAB.
SELECT * FROM pa0001.
READ TABLE itab WITH KEY ssn = pa0001-ssn
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
LOOP AT itab WHERE ssn = pa0001-ssn.
READ TABLE itab-counter WITH KEY state-code = pa0001-regio
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
LOOP AT itab-counter WHERE state-code = pa0001-regio.
itab-counter-state_count = itab-counter-state_count + 1.
MODIFY itab-counter.
ENDLOOP.
ELSE.
itab-counter-state_code = pa0001-regio.
itab-counter-state_count = 1.
APPEND itab-counter.
ENDIF.
ENDLOOP.
MODIFY itab.
ELSE.
itab-ssn = pa0001-ssn.
itab-counter-state_code = pa0001-regio.
itab-counter-state_count = 1.
APPEND itab-counter.
APPEND itab.
ENDIF.
ENDSELECT.
You should note that the order of the state will be different for every person. You'll need to come with with another table
that you can define what the state code and name are and print in the order that is within this table.
As you are printing each row of ITAB, you can then LOOP thru the state table and within that loop. read the ITAB-COUNTER table
where the state codes match and print in the column as appropiate.
Another option would be as you create each line of ITAB, you also fill ITAB-COUNTER table with the other table with code and counter,
initializing the entire ITAB-COUNTER table from the state code/name table. This would make every row of ITAB with the same columns in the ITAB-COUNTER table.
Edited by: Paul Chapman on May 21, 2008 12:15 PM
‎2008 May 21 5:08 PM
Ben,
You can have a internal table within an internal table.
This code has NOT been Tested and provided as an EXAMPLE of how to accomplish your goal.
TABLES: pa0001, pa0002.
DATA:
BEGIN OF itab OCCURS 0,
ssn(9) TYPE c,
BEGIN OF counter OCCURS 0,
state_code(2) TYPE c,
state_count TYPE p,
END OF counter,
END of ITAB.
SELECT * FROM pa0001.
READ TABLE itab WITH KEY ssn = pa0001-ssn
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
LOOP AT itab WHERE ssn = pa0001-ssn.
READ TABLE itab-counter WITH KEY state-code = pa0001-regio
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
LOOP AT itab-counter WHERE state-code = pa0001-regio.
itab-counter-state_count = itab-counter-state_count + 1.
MODIFY itab-counter.
ENDLOOP.
ELSE.
itab-counter-state_code = pa0001-regio.
itab-counter-state_count = 1.
APPEND itab-counter.
ENDIF.
ENDLOOP.
MODIFY itab.
ELSE.
itab-ssn = pa0001-ssn.
itab-counter-state_code = pa0001-regio.
itab-counter-state_count = 1.
APPEND itab-counter.
APPEND itab.
ENDIF.
ENDSELECT.
You should note that the order of the state will be different for every person. You'll need to come with with another table
that you can define what the state code and name are and print in the order that is within this table.
As you are printing each row of ITAB, you can then LOOP thru the state table and within that loop. read the ITAB-COUNTER table
where the state codes match and print in the column as appropiate.
Another option would be as you create each line of ITAB, you also fill ITAB-COUNTER table with the other table with code and counter,
initializing the entire ITAB-COUNTER table from the state code/name table. This would make every row of ITAB with the same columns in the ITAB-COUNTER table.
Edited by: Paul Chapman on May 21, 2008 12:15 PM
‎2008 May 21 5:29 PM
Thanks for your prompt reply, I tried to debug the codes to make it run but it's still saying Counter table is not valid.
By the way, I'm reading State from TaxAU in tax table (cluster).
Really appreciate your next reply!
REPORT test.
TABLES: pa0001, pa0002.
DATA:
BEGIN OF itab OCCURS 0,
ssn(9) TYPE c,
BEGIN OF counter OCCURS 0,
state_code(2) TYPE c,
state_count TYPE p,
END OF counter,
END of ITAB.
SELECT * FROM pa0001.
READ TABLE itab WITH KEY ssn = pa0002-perid
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
LOOP AT itab WHERE ssn = pa0002-perid.
READ TABLE counter WITH KEY state-code = pa0001-regio
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
LOOP AT counter WHERE state-code = pa0001-regio.
counter-state_count = counter-state_count + 1.
MODIFY counter.
ENDLOOP.
ELSE.
counter-state_code = pa0001-regio.
counter-state_count = 1.
APPEND counter.
ENDIF.
ENDLOOP.
MODIFY itab.
ELSE.
itab-ssn = pa0002-perid.
counter-state_code = pa0001-regio.
counter-state_count = 1.
APPEND counter.
APPEND itab.
ENDIF.
ENDSELECT.
‎2008 May 21 5:41 PM
Ok.. as I mentioned, I don't have access to the same tables you have. I remember pa000# tables from previous jobs, but we don't run
HR here, so I can't test this stuff. I have revamped it to some degree to resolve the table issues you're having.
This should help.
TABLES: pa0001, pa0002.
DATA:
BEGIN OF counter_rec,
state_code(2) TYPE c,
state_count TYPE p,
END OF counter_rec.
DATA:
BEGIN OF itab OCCURS 0,
ssn(9) TYPE c,
counter LIKE STANDARD TABLE OF counter_rec,
END OF itab.
SELECT * FROM pa0001.
READ TABLE itab WITH KEY ssn = pa0001-ssn
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
LOOP AT itab WHERE ssn = pa0001-ssn.
READ TABLE itab-counter WITH KEY state-code = pa0001-regio
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
LOOP AT itab-counter INTO counter_rec
WHERE state_code = pa0001-regio.
counter_rec-state_count = counter_rec-state_count + 1.
MODIFY itab-counter FROM counter_rec.
ENDLOOP.
ELSE.
counter_rec-state_code = pa0001-regio.
counter_rec-state_count = 1.
APPEND counter_rec TO itab-counter.
ENDIF.
ENDLOOP.
MODIFY itab.
ELSE.
itab-ssn = pa0001-ssn.
counter_rec-state_code = pa0001-regio.
counter_rec-state_count = 1.
APPEND counter_rec TO itab-counter.
APPEND itab.
ENDIF.
ENDSELECT.
‎2008 May 21 6:01 PM
For good or bad Ben, I go home today at 1pm EST to take my son to the airport.
I'll be back in the morning (6am) and will review this thread to see if you've resolved the problem.
Best of luck
Paul
‎2008 May 21 9:12 PM
Paul, you're so kind, I'm working on many things including configuration job on wagetypes, this is another step forward, I will reply on this thread when I find something on this. Thanks!
Edited by: Ben Boman on May 21, 2008 10:19 PM
‎2008 May 22 12:59 PM
Ben
This is more of a completed psuedo code to show the entire process. Hope this makes things a little clearer.
TABLES: pa0001, pa0002.
DATA:
BEGIN OF state_rec,
code(2) TYPE c,
name(15) TYPE c,
END OF state_rec,
it_state LIKE STANDARD TABLE OF state_rec.
DATA:
BEGIN OF counter_rec,
state_code(2) TYPE c,
state_count TYPE p,
END OF counter_rec.
DATA:
BEGIN OF itab OCCURS 0,
ssn(9) TYPE c,
counter LIKE STANDARD TABLE OF counter_rec,
END OF itab.
TOP-OF-PAGE.
DATA: col TYPE i.
col = 15.
WRITE:/1 'SSN'.
LOOP AT it_state INTO state_rec.
WRITE AT col state_rec-name.
col = col + 15.
ENDLOOP.
START-OF-SELECTION.
*
PERFORM build_state_tab.
*
SELECT * FROM pa0002.
READ TABLE itab WITH KEY ssn = pa0002-perid
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
LOOP AT itab WHERE ssn = pa0002-perid.
READ TABLE itab-counter WITH KEY state-code = pa0002-regio
* pa0002-regio should be changed to wherever you are are getting
* your state code
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
LOOP AT itab-counter INTO counter_rec
WHERE state_code = pa0002-regio.
counter_rec-state_count = counter_rec-state_count + 1.
MODIFY itab-counter FROM counter_rec.
ENDLOOP.
ELSE.
counter_rec-state_code = pa0002-regio.
* pa0002-regio should be changed to wherever you are are getting
* your state code
counter_rec-state_count = 1.
APPEND counter_rec TO itab-counter.
ENDIF.
ENDLOOP.
MODIFY itab.
ELSE.
itab-ssn = pa0002-perid.
counter_rec-state_code = pa0002-regio.
* pa0002-regio should be changed to wherever you are are getting
* your state code
counter_rec-state_count = 1.
APPEND counter_rec TO itab-counter.
APPEND itab.
ENDIF.
ENDSELECT.
LOOP AT itab.
WRITE:/ itab-ssn UNDER 'SSN'.
LOOP AT it_state INTO state_rec.
READ TABLE itab-counter INTO counter_rec
WITH KEY state_code = state_rec-code.
IF sy-subrc EQ 0.
WRITE counter_rec-state_count UNDER state_rec-name. " I'm hoping these UNDER statements work here
ELSE.
WRITE 0 UNDER state_rec-name.
ENDIF.
ENDLOOP.
ENDLOOP.
&---------------------------------------------------------------------
& form build_state_tab
&---------------------------------------------------------------------
form build_state_tab.
REFRESH it_state.
SELECT code state_name INTO TABLE it_state
FROM state_db. " No idea where you can get the full table of these This is an example.
* I used this to check logic for headings.
* state_rec-code = 'AK'.
* state_rec-name = 'Alaska'.
* APPEND state_rec TO it_state.
* state_rec-code = 'AL'.
* state_rec-name = 'Alabama'.
* APPEND state_rec TO it_state.
* state_rec-code = 'AR'.
* state_rec-name = 'Arkansas'.
* APPEND state_rec TO it_state.
* state_rec-code = 'AZ'.
* state_rec-name = 'Arizona'.
* APPEND state_rec TO it_state.
* Now, you need to order this table in the order you want your columns
* displayed when you write your report.
ENDFORM. " build_state_tab
‎2008 May 22 3:15 PM
Paul,
This is your part
SELECT code state_name INTO TABLE it_state
FROM state_db. " No idea where you can get the full table of these This is an example.
I guess I will take it from Tax table inside cluster, work area type PC22T.
Very helpful code part. THANKS!
Edited by: Ben Boman on May 22, 2008 4:15 PM
‎2008 May 22 3:17 PM