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

Assign statement does not work...

aris_hidalgo
Contributor
0 Likes
2,989

Hello Experts, 

I am trying to pass the value of a field to a field-symbol but it does not work.
Please check my code below:

TYPES: BEGIN OF t_itab_name,
            itab_name TYPE char30,
           END OF t_itab_name.

DATA: lt_itab_name  TYPE STANDARD TABLE OF t_itab_name,
      wa_itab_name  LIKE LINE OF lt_itab_name.

FIELD-SYMBOLS: <fs_itab> TYPE table.

REFRESH lt_itab_name.
    DEFINE m_fill_itab_name.
      wa_itab_name-itab_name  = &1.
      append wa_itab_name to lt_itab_name.
      clear wa_itab_name.
    END-OF-DEFINITION.

    m_fill_itab_name 'ZSD_OUTPUT_ACQ'.
    m_fill_itab_name 'ZSD_OUTPUT_RET'.
    m_fill_itab_name 'ZSD_OUTPUT_NET'.

LOOP AT lt_itab_name INTO wa_itab_name.
      TRY.
          ASSIGN (wa_itab_name-itab_name) TO <fs_itab>.
        CATCH cx_sy_assign_cast_illegal_cast
              cx_sy_assign_cast_unknown_type
              cx_sy_assign_out_of_range.
      ENDTRY.
ENDLOOP.

Hope you can help me guys. Thank you and take care!
1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,148

Hi,

Plz code this way:

FIELD-SYMBOLS: <fs_itab> type char30.

thanx.

15 REPLIES 15
Read only

Former Member
0 Likes
2,148

instead of statment

ASSIGN (wa_itab_name-itab_name) TO <fs_itab>.

Write

Assign wa_itab to <fs_itab>.

Also while defining the type of <fs_itab>

FIELD-SYMBOLS: <fs_itab> TYPE t_itab_name.

it should work now.

Read only

0 Likes
2,148

Hi Bikas,

I cannot declare my field-symbols as the same type as my itab because I need to pass the value from the field-symbol to a FM parameter that has a TYPE TABLE.

Read only

Former Member
0 Likes
2,148

Hi,

Please use below code:

TYPES: BEGIN OF t_itab_name,

itab_name TYPE char30,

END OF t_itab_name.

DATA: lt_itab_name TYPE STANDARD TABLE OF t_itab_name,

wa_itab_name LIKE LINE OF lt_itab_name.

FIELD-SYMBOLS: <fs_itab> type char30.

REFRESH lt_itab_name.

DEFINE m_fill_itab_name.

wa_itab_name-itab_name = &1.

append wa_itab_name to lt_itab_name.

clear wa_itab_name.

END-OF-DEFINITION.

m_fill_itab_name 'ZSD_OUTPUT_ACQ'.

m_fill_itab_name 'ZSD_OUTPUT_RET'.

m_fill_itab_name 'ZSD_OUTPUT_NET'.

LOOP AT lt_itab_name INTO wa_itab_name.

TRY.

ASSIGN wa_itab_name-itab_name TO <fs_itab>.

CATCH cx_sy_assign_cast_illegal_cast

cx_sy_assign_cast_unknown_type

cx_sy_assign_out_of_range.

ENDTRY.

ENDLOOP.

Regards

Jana

Read only

Former Member
0 Likes
2,149

Hi,

Plz code this way:

FIELD-SYMBOLS: <fs_itab> type char30.

thanx.

Read only

0 Likes
2,148

Hi Guys,

Like I said earlier, I cannot declare my field-symbols as type CHAR30 or like my itab because the value from the field-symbol will be passed to an FM parameter that has a TYPE OF TABLE.

So thats why I declared it as TABLE. Below is the complete code:


*&---------------------------------------------------------------------*
*&  Include           ZINC_ASSET_ACQ_DIS_ALV_ROUTINE
*&---------------------------------------------------------------------*

TYPE-POOLS: slis,
            abap.

*----------------------------------------------------------------------*
*       CLASS lcl_alv_routines DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_alv_routines DEFINITION.
  PUBLIC SECTION.
    METHODS: display_data,
             build_fieldcat
               IMPORTING
                 im_table_name TYPE table.

  PROTECTED SECTION.
    DATA: gt_fieldcat TYPE slis_t_fieldcat_alv,
          wa_fieldcat TYPE slis_fieldcat_alv.

  PRIVATE SECTION.
    TYPES: BEGIN OF t_itab_name,
            itab_name TYPE char30,
           END OF t_itab_name.

    DATA: lt_output_acq TYPE STANDARD TABLE OF zsd_output_acq,"#EC NEEDED
          lt_output_ret TYPE STANDARD TABLE OF zsd_output_acq,"#EC NEEDED
          lt_output_net TYPE STANDARD TABLE OF zsd_output_net,"#EC NEEDED
          lt_itab_name  TYPE STANDARD TABLE OF t_itab_name,
          wa_itab_name  LIKE LINE OF lt_itab_name.

ENDCLASS.                    "lcl_alv_routines DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_alv_routines IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_alv_routines IMPLEMENTATION.
* METHOD display_data
  METHOD display_data.
    FIELD-SYMBOLS: <fs_itab> TYPE table.

    REFRESH lt_itab_name.
    DEFINE m_fill_itab_name.
      wa_itab_name-itab_name  = &1.
      append wa_itab_name to lt_itab_name.
      clear wa_itab_name.
    END-OF-DEFINITION.

    m_fill_itab_name 'ZSD_OUTPUT_ACQ'.
    m_fill_itab_name 'ZSD_OUTPUT_RET'.
    m_fill_itab_name 'ZSD_OUTPUT_NET'.

*   Initialize ALV
    CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
      EXPORTING
        i_callback_program = sy-repid.
*        I_CALLBACK_PF_STATUS_SET       = ' '
*        I_CALLBACK_USER_COMMAND        = ' '
*        IT_EXCLUDING                   =

    LOOP AT lt_itab_name INTO wa_itab_name.
      TRY.
          ASSIGN (wa_itab_name-itab_name) TO <fs_itab>.
        CATCH cx_sy_assign_cast_illegal_cast
              cx_sy_assign_cast_unknown_type
              cx_sy_assign_out_of_range.
      ENDTRY.
      me->build_fieldcat(
            EXPORTING
              im_table_name = <fs_itab> ).
    ENDLOOP.
  ENDMETHOD.                    "display_data

* METHOD build_fieldcat
  METHOD build_fieldcat.
    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
     EXPORTING
       i_program_name               = sy-repid
*       I_INTERNAL_TABNAME           =
       i_structure_name             = im_table_name
*       I_CLIENT_NEVER_DISPLAY       = 'X'
*       I_INCLNAME                   =
*       I_BYPASSING_BUFFER           =
*       I_BUFFER_ACTIVE              =
      CHANGING
        ct_fieldcat                  = gt_fieldcat
     EXCEPTIONS
       inconsistent_interface       = 1
       program_error                = 2
       OTHERS                       = 3.

    IF sy-subrc <> 0.
*      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
*              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.

  ENDMETHOD.                    "build_fieldcat
ENDCLASS.                    "lcl_alv_routines IMPLEMENTATION

Read only

0 Likes
2,148

as I said above, ZSD_... is not declared as internal table, that is the problem. The line:

lt_output_acq TYPE STANDARD TABLE OF zsd_output_acq

indicates that it is type, which is not sufficient for the ASSIGN

Read only

0 Likes
2,148

Hi,

You have to declare type char30 and declare another varaible as Table and pass to that varaible , Second varaible pass to FM.

Regards

Jana

Read only

0 Likes
2,148

Hi Guys,

Those are custom tables that someone created that I need to use for fieldcatalog.

Read only

0 Likes
2,148

just put a breakpoint on the ASSIGN statement and check how ZSD_OUTPUT_ACQ (and the other two) looks like during runtime. Looking at the code, it does not look like an internal table

Read only

0 Likes
2,148

Hi Eric,

Those are custom tables created in SE11 that I need to use as reference for the structure of my fieldcatalog so that is why I am passing it to the parameter 'i_structure_name' of FM 'REUSE_ALV_FIELDCATALOG_MERGE'.

Read only

0 Likes
2,148

Hi

Try using this way :

FIE

LD-SYMBOLS: <fs_itab> TYPE ANY table

thanx.

Read only

0 Likes
2,148

OK, I see. But in this case you don't need the ASSIGN. You just pass the name of the table to the FM REUSE_ALV_FIELDCATALOGE_MERGE as you did. You can comment the line with ASSIGN (and everything else which belongs to it)

Read only

JozsefSzikszai
Active Contributor
0 Likes
2,148

hi,

I think the problem is that the internal tables ('ZSD_OUTPUT_ACQ' and the other two), are not defined in the program, so you want to assign a field symbol to non existing objects.

hope this helps (some)

ec

Read only

Former Member
0 Likes
2,148

hi,

check my code in

https://wiki.sdn.sap.com/wiki/x/_oCtAg

your prob will be solved, I hope.

Regards,

Anirban

Read only

dev_parbutteea
Active Contributor
0 Likes
2,148

Hi,

to what do 'ZSD_OUTPUT_ACQ', 'ZSD_OUTPUT_RET', 'ZSD_OUTPUT_NET' refer??

the assign will only work if these are available at runtime..

Regards