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

Dynamic Query

Former Member
0 Likes
652

Hello, I have a query about internal tables. I have an internal tables as follows.

ZROW CHARAC       CHARVAL
1           MATERIAL      100
1           CALYEAR       2013
1           CALMONTH      12
1           AMOUNT       200
2           MATERIAL      200
2           CALYEAR       2013
2           CALMONTH      10
2           AMOUNT       200

I have another internal table which is like this:
Material CalYear  CalMonth Amount


What I want to do is use Row number as my key and insert material, calyear, calmonth and amount data in material, calyear, calmonth, amount columns in the second internal table which is possible but the problem i have is to make my ZROW field dynamic. There is a possibility that I may have 1000 rows or 2000 or 2500 rows so i can't do some thing like this.

LOOP AT IT1 INTO WA1.
      IF WA1-ZROW = '0000'.

        MOVE:   WA1-MATERIAL TO WA2-MATERIAL,
                WA1-CALYEAR     TO WA2-CALYEAR.

I am trying to see if there is a way i can make my zrow dynamic and keep counting up. once it reaches the end of internal table then it should stop.

Please let me know.

1 ACCEPTED SOLUTION
Read only

RaymondGiuseppi
Active Contributor
0 Likes
617

Try a dynamic code like

LOOP AT itab1 ASSIGNING <record1>.
   AT NEW zrow.
     APPEND INITIAL LINE TO itab2 ASSIGNING <record2>.
   ENDAT.
   TRY.
       ASSIGN COMPONENT <record1>-charac OF STRUCTURE <record2> TO <field>.
       <field> = <record1>-value.
     CATCH cx_sy_assign_cast_illegal_cast, cx_sy_assign_cast_unknown_type, cx_sy_assign_out_of_range.
       " ...
     CATCH cx_sy_conversion_no_number cx_sy_conversion_overflow cx_sy_move_cast_erro.
       " ...
   ENDTRY.
ENDLOOP.

Where FIELD-SYMBOLS <record1> is typed with your actual itab1 structure and <record2> and <field> can be ANY TYPE.


Regards,

Raymond

3 REPLIES 3
Read only

RaymondGiuseppi
Active Contributor
0 Likes
618

Try a dynamic code like

LOOP AT itab1 ASSIGNING <record1>.
   AT NEW zrow.
     APPEND INITIAL LINE TO itab2 ASSIGNING <record2>.
   ENDAT.
   TRY.
       ASSIGN COMPONENT <record1>-charac OF STRUCTURE <record2> TO <field>.
       <field> = <record1>-value.
     CATCH cx_sy_assign_cast_illegal_cast, cx_sy_assign_cast_unknown_type, cx_sy_assign_out_of_range.
       " ...
     CATCH cx_sy_conversion_no_number cx_sy_conversion_overflow cx_sy_move_cast_erro.
       " ...
   ENDTRY.
ENDLOOP.

Where FIELD-SYMBOLS <record1> is typed with your actual itab1 structure and <record2> and <field> can be ANY TYPE.


Regards,

Raymond

Read only

0 Likes
617

Raymond, thank you sir. how do i declare these field symbols?

Please let me know.

Thanks.

Read only

0 Likes
617

For <record1> use a FIELD-SYMBOLS <record1> TYPE same type than itab1.

For <record2> and <field> use TYPE ANY.

Regards,
Raymond