Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Abap Dynamic Variable

Hallo!

I would be grateful for any advice.

I need to check 80 columns and I want to turn it into 80 lines.

Can this be done dynamically?

Thank you in advance

LOOP AT SOURCE_PACKAGE ASSIGNING <source_fields>.

      IF <source_fields>-zzabrsn001 <> ''.

        RESULT_FIELDS-/bic/zrvk_mita = <source_fields>-objid.

        RESULT_FIELDS-/bic/zrvk_abre = <source_fields>-zzabrsn001.

        APPEND RESULT_FIELDS TO RESULT_PACKAGE.

        CLEAR RESULT_FIELDS.

      ENDIF.

      IF <source_fields>-zzabrsn002 <> ''.

        RESULT_FIELDS-/bic/zrvk_mita = <source_fields>-objid.

        RESULT_FIELDS-/bic/zrvk_abre = <source_fields>-zzabrsn002.

        APPEND RESULT_FIELDS TO RESULT_PACKAGE.

        CLEAR RESULT_FIELDS.

      ENDIF.

      IF <source_fields>-zzabrsn003 <> ''.

        RESULT_FIELDS-/bic/zrvk_mita = <source_fields>-objid.

        RESULT_FIELDS-/bic/zrvk_abre = <source_fields>-zzabrsn003.

        APPEND RESULT_FIELDS TO RESULT_PACKAGE.

        CLEAR RESULT_FIELDS.

      ENDIF.

      IF <source_fields>-zzabrsn004 <> ''.

        RESULT_FIELDS-/bic/zrvk_mita = <source_fields>-objid.

        RESULT_FIELDS-/bic/zrvk_abre = <source_fields>-zzabrsn004.

        APPEND RESULT_FIELDS TO RESULT_PACKAGE.

        CLEAR RESULT_FIELDS.

      ENDIF.

     ...

     ...

     IF <source_fields>-zzabrsn080 <> ''.

        RESULT_FIELDS-/bic/zrvk_mita = <source_fields>-objid.

        RESULT_FIELDS-/bic/zrvk_abre = <source_fields>-zzabrsn080.

        APPEND RESULT_FIELDS TO RESULT_PACKAGE.

        CLEAR RESULT_FIELDS.

      ENDIF.

    ENDLOOP.

replied

Hi Alexey,

Use the statement ASSING COMPONENT of STRUCTURE To ....

Show an example:

   LOOP AT table into wa_table.

     DO 80 TIMES.

         ASSIGN COMPONENT sy-index of STRUCTURE wa_table to <fs>.

         if sy-subrc eq 0.

           "do the stuff <fs> contains the n-index field

         endif.

      Enddo.

   endloop.


Hope it helps,

regards

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question