Application Development 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: 

Field value with variable

Former Member
0 Kudos
221

Hi All,

I don't know whether I am correct or not. If it is possible then please guide me with the below issue.

READ TABLE lt_test1 INTO ls_test1 WITH KEY ls_intern-col.

ls_test-( 'ls_test1-desc' ) = ls_intern-value.


Here my field name is stored in another internal table. How my query is how to write the 2nd line. How it will work.


Please give me some suggestion.


Thanks,

Satya


1 ACCEPTED SOLUTION

raymond_giuseppi
Active Contributor
0 Kudos
161

Did you look for ASSIGN COMPONENT statement and FIELD-SYMBOLS during your initial training

Regards,

Raymond

7 REPLIES 7

raymond_giuseppi
Active Contributor
0 Kudos
162

Did you look for ASSIGN COMPONENT statement and FIELD-SYMBOLS during your initial training

Regards,

Raymond

0 Kudos
161

Nice reply 

Raymond is giving you a big hint, you don't need to provide detailed structures etc of your internal tables.

Of course,  don't forget to 'UnAssign' and always check 'If Assigned' .....

Regards

Rich

Former Member
0 Kudos
161

Hi All,

Here is the full code, and the excel file is in attachment.

REPORT  ZINT_TABLE_EXCEL_DYNAMIC.

TABLES :vbak,vbap.

DATA lv_file LIKE rlgrap-filename VALUE 'C:\Users\satya\Desktop\Test.xlsx'.

DATA :lt_intern TYPE STANDARD TABLE OF  alsmex_tabline,

       ls_intern LIKE LINE OF lt_intern,

        new_table type ref to data.

data: it_fldcat type lvc_t_fcat,

       wa_it_fldcat type lvc_s_fcat.

break sathya.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

   EXPORTING

     filename                      = lv_file

     i_begin_col                   = '1'

     i_begin_row                   = '1'

     i_end_col                     = '20'

     i_end_row                     = '999'

   TABLES

     intern                        = lt_intern

  EXCEPTIONS

    INCONSISTENT_PARAMETERS       = 1

    UPLOAD_OLE                    = 2

    OTHERS                        = 3

           .

IF sy-subrc <> 0.

* Implement suitable error handling here

ENDIF.

TYPES :BEGIN OF ts_test,

        vbeln TYPE vbap-vbeln,

        posnr TYPE vbap-posnr,

        sold TYPE vbak-kunnr,

       END OF ts_test,

       BEGIN OF ts_test1,

        field TYPE char20,

        desc  TYPE char10,

        pos    TYPE i,

       END OF ts_test1.

  DATA :lt_test TYPE TABLE OF ts_test,

        ls_test TYPE ts_test,

        lt_test1 TYPE TABLE OF ts_test1,

        ls_test1 TYPE ts_test1.

LOOP at lt_intern into ls_intern WHERE row eq 1.

     CONDENSE ls_intern-value.

     CASE ls_intern-value.

       WHEN 'Sales Doc.'.

         ls_test1-field = 'Sales Doc.'.

         ls_test1-pos   = ls_intern-col.

         ls_test1-desc  = 'VBELN'.

         APPEND ls_test1 to lt_test1.

       WHEN 'Item'.

         ls_test1-field = 'Item'.

         ls_test1-pos   = ls_intern-col.

         ls_test1-desc  = 'POSNR'.

         APPEND ls_test1 to lt_test1.

       WHEN 'Sold-To Party'.

         ls_test1-field = 'Sold-To Party'.

         ls_test1-pos   = ls_intern-col.

         ls_test1-desc  = 'SOLD'.

         APPEND ls_test1 to lt_test1.

       WHEN OTHERS.

     ENDCASE.

CLEAR :ls_test1, ls_intern.

ENDLOOP.

LOOP AT lt_intern into ls_intern WHERE row NE 1 .

   REad TABLE lt_test1 INTO ls_test1 WITH KEY ls_intern-col.

   ls_test-( 'ls_test1-desc' ) = ls_intern-value.

ENDLOOP.


Please check and let me know the next step.


Thanks,

Satya


Former Member
0 Kudos
161

Can anyone give me the brief idea about this example.

Its urgent. Thanks...

0 Kudos
161

What is the endresult you want ? An ALV list ?

You could make your life easier if you define ls_test with a name and value pair

e.g.: ls_test-fieldname, ls_test-fieldvalue. But it all depends on what you are trying to achieve as endresult.

0 Kudos
161

I want to display only 3 column from the excel file but we dont know the columns are in which position in excel.

Thanks,

Satya

0 Kudos
161

<sigh>.

There are some errors in the relevant portion of code which means that it will not compile,  but essentially you do this:


Loop At Lt_Intern

     Into ls_Intern Where Row Ne 1 .

     Read Table Lt_Test1 Into Ls_Test1 With Key Key_Field = Ls_Intern-Col.

     Assign Component ls_Test1-Desc

         Of Structure ls_Test

         To <f_Field_Symbol>.

     If <f_Field_Symbol> Is Assigned.

        <f_Field_Symbol> = ls_Intern-Value.

        UnAssign <f_Field_Symbol>.

     EndIf.

Endloop.

For example you attempt to assign the value to ls_test,  but ls_test is just a structure and from what I can see of your code is not read from any table,  nor is it saved back into any table.

Secondly,  when using LOOP At, or READ Table using the ASSIGNING clause rather than the INTO clause.  Any updates to the work area are then updated in the table immediately.

Rich