<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Counter in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/counter/m-p/3845321#M924503</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree, I would think that's the right place Ben.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 22 May 2008 14:17:51 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-05-22T14:17:51Z</dc:date>
    <item>
      <title>Counter</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/counter/m-p/3845313#M924495</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The output file looks like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[_SSN__] [_State_+_Counter____] [__same_____] [__same_____] [__same_____] [__same_____].....&lt;/P&gt;&lt;P&gt;    1                       2                              3                     4                     5                      6            ....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there any logic that I can integrate in my program?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;full points will be awarded!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 May 2008 15:00:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/counter/m-p/3845313#M924495</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-21T15:00:55Z</dc:date>
    </item>
    <item>
      <title>Re: Counter</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/counter/m-p/3845314#M924496</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ben,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can have a internal table within an internal table.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This code has NOT been Tested and provided as an EXAMPLE of how to accomplish your goal.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
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.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You should note that the order of the state will be different for every person.  You'll need to come with with another table&lt;/P&gt;&lt;P&gt;that you can define what the state code and name are and print in the order that is within this table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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&lt;/P&gt;&lt;P&gt;where the state codes match and print in the column as appropiate.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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,&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Paul Chapman on May 21, 2008 12:15 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 May 2008 16:08:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/counter/m-p/3845314#M924496</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-21T16:08:06Z</dc:date>
    </item>
    <item>
      <title>Re: Counter</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/counter/m-p/3845315#M924497</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By the way, I'm reading State from TaxAU in tax table (cluster).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Really appreciate your next reply!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;REPORT test.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TABLES: pa0001, pa0002.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA:&lt;/P&gt;&lt;P&gt;  BEGIN OF itab OCCURS 0,&lt;/P&gt;&lt;P&gt;    ssn(9)          TYPE c,&lt;/P&gt;&lt;P&gt;    BEGIN OF counter OCCURS 0,&lt;/P&gt;&lt;P&gt;      state_code(2)   TYPE c,&lt;/P&gt;&lt;P&gt;      state_count     TYPE p,&lt;/P&gt;&lt;P&gt;    END OF counter,&lt;/P&gt;&lt;P&gt;  END of ITAB.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM pa0001.&lt;/P&gt;&lt;P&gt;  READ TABLE itab WITH KEY ssn = pa0002-perid&lt;/P&gt;&lt;P&gt;      TRANSPORTING NO FIELDS.&lt;/P&gt;&lt;P&gt;  IF sy-subrc = 0.&lt;/P&gt;&lt;P&gt;    LOOP AT itab WHERE ssn = pa0002-perid.&lt;/P&gt;&lt;P&gt;      READ TABLE counter WITH KEY state-code = pa0001-regio&lt;/P&gt;&lt;P&gt;        TRANSPORTING NO FIELDS.&lt;/P&gt;&lt;P&gt;      IF sy-subrc = 0.&lt;/P&gt;&lt;P&gt;        LOOP AT counter WHERE state-code = pa0001-regio.&lt;/P&gt;&lt;P&gt;          counter-state_count = counter-state_count + 1.&lt;/P&gt;&lt;P&gt;          MODIFY counter.&lt;/P&gt;&lt;P&gt;        ENDLOOP.&lt;/P&gt;&lt;P&gt;      ELSE.&lt;/P&gt;&lt;P&gt;        counter-state_code  = pa0001-regio.&lt;/P&gt;&lt;P&gt;        counter-state_count = 1.&lt;/P&gt;&lt;P&gt;        APPEND counter.&lt;/P&gt;&lt;P&gt;      ENDIF.&lt;/P&gt;&lt;P&gt;    ENDLOOP.&lt;/P&gt;&lt;P&gt;    MODIFY itab.&lt;/P&gt;&lt;P&gt;  ELSE.&lt;/P&gt;&lt;P&gt;    itab-ssn = pa0002-perid.&lt;/P&gt;&lt;P&gt;    counter-state_code  = pa0001-regio.&lt;/P&gt;&lt;P&gt;    counter-state_count = 1.&lt;/P&gt;&lt;P&gt;    APPEND counter.&lt;/P&gt;&lt;P&gt;    APPEND itab.&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 May 2008 16:29:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/counter/m-p/3845315#M924497</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-21T16:29:06Z</dc:date>
    </item>
    <item>
      <title>Re: Counter</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/counter/m-p/3845316#M924498</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;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 &lt;/P&gt;&lt;P&gt;HR here, so I can't test this stuff.  I have revamped it to some degree to resolve the table issues you're having.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This should help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
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.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 May 2008 16:41:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/counter/m-p/3845316#M924498</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-21T16:41:28Z</dc:date>
    </item>
    <item>
      <title>Re: Counter</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/counter/m-p/3845317#M924499</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For good or bad Ben, I go home today at 1pm EST to take my son to the airport.&lt;/P&gt;&lt;P&gt;I'll be back in the morning (6am) and will review this thread to see if you've resolved the problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best of luck&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 May 2008 17:01:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/counter/m-p/3845317#M924499</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-21T17:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: Counter</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/counter/m-p/3845318#M924500</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;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!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Ben Boman on May 21, 2008 10:19 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 May 2008 20:12:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/counter/m-p/3845318#M924500</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-21T20:12:13Z</dc:date>
    </item>
    <item>
      <title>Re: Counter</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/counter/m-p/3845319#M924501</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ben&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;This is more of a completed psuedo code to show the entire process.  Hope this makes things a little clearer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
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.

 &amp;amp;---------------------------------------------------------------------

   &amp;amp;      form  build_state_tab
 &amp;amp;---------------------------------------------------------------------

   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
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 May 2008 11:59:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/counter/m-p/3845319#M924501</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-22T11:59:53Z</dc:date>
    </item>
    <item>
      <title>Re: Counter</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/counter/m-p/3845320#M924502</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Paul, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is your part&lt;/P&gt;&lt;P&gt;SELECT code state_name INTO TABLE it_state&lt;/P&gt;&lt;P&gt;    FROM state_db.   " No idea where you can get the full table of these  This is an example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I guess I will take it from Tax table inside cluster, work area type PC22T.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Very helpful code part. THANKS!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Ben Boman on May 22, 2008 4:15 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 May 2008 14:15:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/counter/m-p/3845320#M924502</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-22T14:15:34Z</dc:date>
    </item>
    <item>
      <title>Re: Counter</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/counter/m-p/3845321#M924503</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree, I would think that's the right place Ben.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 May 2008 14:17:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/counter/m-p/3845321#M924503</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-22T14:17:51Z</dc:date>
    </item>
  </channel>
</rss>

